+
+//_________________________________________________________________________
+void AliEPSelectionTask::SetOADBandPeriod()
+{
+ TString oadbfilename;
+
+ if (fRunNumber >= 136851 && fRunNumber <= 139515) // LHC10h
+ {fPeriod = "LHC10h";
+ if (!fUserphidist) { // if it's already set and custom class is required, we use the one provided by the user
+
+ if (fAnalysisInput.CompareTo("AOD")==0){
+ oadbfilename = (Form("%s/COMMON/EVENTPLANE/data/epphidist.aod.root", AliAnalysisManager::GetOADBPath()));
+ } else if (fAnalysisInput.CompareTo("ESD")==0){
+ oadbfilename = (Form("%s/COMMON/EVENTPLANE/data/epphidist.root", AliAnalysisManager::GetOADBPath()));
+ }
+
+ TFile foadb(oadbfilename);
+ if(!foadb.IsOpen()) AliFatal(Form("Cannot open OADB file %s", oadbfilename.Data()));
+
+ AliInfo("Using Standard OADB");
+ fEPContainer = (AliOADBContainer*) foadb.Get("epphidist");
+ if (!fEPContainer) AliFatal("Cannot fetch OADB container for EP selection");
+ foadb.Close();
+ }
+ }
+
+ if (fRunNumber >= 166529 && fRunNumber <= 170593) // LHC11h
+ {fPeriod = "LHC11h";
+ if (!fUserphidist) {
+ // if it's already set and custom class is required, we use the one provided by the user
+
+ oadbfilename = (Form("%s/COMMON/EVENTPLANE/data/epphidist2011.root", AliAnalysisManager::GetOADBPath()));
+ TFile *foadb = TFile::Open(oadbfilename);
+ if(!foadb->IsOpen()) AliFatal(Form("Cannot open OADB file %s", oadbfilename.Data()));
+
+ AliInfo("Using Standard OADB");
+ fSparseDist = (THnSparse*) foadb->Get("Default");
+ if (!fSparseDist) AliFatal("Cannot fetch OADB container for EP selection");
+ foadb->Close();
+ if(!fHruns){
+ fHruns = (TH1F*)fSparseDist->Projection(0); //projection on run axis;
+ fHruns->SetName("runsHisto");
+ }
+ }
+ }
+}
+
+//_________________________________________________________________________
+TH1F* AliEPSelectionTask::SelectPhiDist(AliVTrack *track)
+{
+ if (fPeriod.CompareTo("LHC10h")==0 || fUserphidist) return fPhiDist[0];
+ else if(fPeriod.CompareTo("LHC11h")==0)
+ {
+ if (track->Charge() < 0)
+ {
+ if(track->Eta() < 0.) return fPhiDist[0];
+ else if (track->Eta() > 0.) return fPhiDist[2];
+ }
+ else if (track->Charge() > 0)
+ {
+ if(track->Eta() < 0.) return fPhiDist[1];
+ else if (track->Eta() > 0.) return fPhiDist[3];
+ }
+
+ }
+ return 0;
+}
+
+TObjArray* AliEPSelectionTask::GetTracksForLHC11h(AliESDEvent* esd)
+{
+ // Need to do this hack beacuse only this type of TPC only tracks in AOD is available and one type of Phi-weights is used
+ TObjArray *acctracks = new TObjArray();
+ acctracks->SetOwner(kTRUE);
+
+ const AliESDVertex *vtxSPD = esd->GetPrimaryVertexSPD();
+
+ Float_t ptlow = 0;
+ Float_t ptup = 0;
+ Float_t etalow = 0;
+ Float_t etaup = 0;
+ fESDtrackCuts->GetPtRange(ptlow,ptup);
+ fESDtrackCuts->GetEtaRange(etalow,etaup);
+
+ Double_t pDCA[3] = { 0. }; // momentum at DCA
+ Double_t rDCA[3] = { 0. }; // position at DCA
+ Float_t dDCA[2] = {0.}; // DCA to the vertex d and z
+ Float_t cDCA[3] = {0.}; // covariance of impact parameters
+
+
+
+ for (Int_t i = 0; i < esd->GetNumberOfTracks() ; i++){
+
+ AliESDtrack* esdTrack = esd->GetTrack(i); //carefull do not modify it othwise need to work with a copy
+ //
+ // Track selection
+ if (!fESDtrackCuts->AcceptTrack(esdTrack)) continue;
+
+ // create a tpc only tracl
+ AliESDtrack *track = AliESDtrackCuts::GetTPCOnlyTrack(const_cast<AliESDEvent*>(esd),esdTrack->GetID());
+ if(!track) continue;
+
+ if(track->Pt()>0.)
+ {
+ // only constrain tracks above threshold
+ AliExternalTrackParam exParam;
+ // take the B-field from the ESD, no 3D fieldMap available at this point
+ Bool_t relate = false;
+ relate = track->RelateToVertexTPC(vtxSPD,esd->GetMagneticField(),kVeryBig,&exParam);
+ if(!relate){
+ delete track;
+ continue;
+ }
+ // fetch the track parameters at the DCA (unconstraint)
+ if(track->GetTPCInnerParam()){
+ track->GetTPCInnerParam()->GetPxPyPz(pDCA);
+ track->GetTPCInnerParam()->GetXYZ(rDCA);
+ }
+ // get the DCA to the vertex:
+ track->GetImpactParametersTPC(dDCA,cDCA);
+ // set the constrained parameters to the track
+ track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());
+ }
+
+
+ Float_t eta = track->Eta();
+ Float_t pT = track->Pt();
+
+ if(pT < ptlow || pT > ptup || eta < etalow || eta > etaup){
+ delete track;
+ continue;
+ }
+
+ acctracks->Add(track);
+ }
+
+
+ return acctracks;
+
+}
+