4 // Script to calculate PtvsEta correction map using the CorrectionMatrix2D class.
7 makeCorrectionPtEta(Char_t* dataDir, Int_t nRuns=20) {
11 //gSystem->Load("/home/poghos/CERN2006/pp/esdTrackCuts/libESDtrackQuality.so");
12 gSystem->Load("libPWG0base");
13 gSystem->Load("libCorrectionMatrix2D.so");
14 // ########################################################
15 // selection of esd tracks
16 AliESDtrackCuts* esdTrackCuts = new AliESDtrackCuts();
17 esdTrackCuts->DefineHistograms(1);
18 esdTrackCuts->SetMinNClustersTPC(50);
19 esdTrackCuts->SetMaxChi2PerClusterTPC(3.5);
20 esdTrackCuts->SetMaxCovDiagonalElements(2,2,0.5,0.5,2);
21 esdTrackCuts->SetRequireTPCRefit(kTRUE);
22 esdTrackCuts->SetMinNsigmaToVertex(3);
23 esdTrackCuts->SetAcceptKingDaughters(kFALSE);
24 AliLog::SetClassDebugLevel("AliESDtrackCuts",1);
25 AliLog::SetClassDebugLevel("ESDtrackQualityCuts",1);
27 // ########################################################
28 // definition of PtEta correction object
29 CorrectionMatrix2D* PtEtaMap = new CorrectionMatrix2D("CorrectionMatrix2");
30 PtEtaMap->SetHist("PtEta",80,0.,10.,120,-2.,2.);
31 //Float_t x[]={-20., -15., -5., 0., 6., 20.};
32 //Float_t y[]={-6. , -3., -1., 2., 3., 6. };
33 //PtEtaMap->SetHist("PtEta",5,x,5,y);
34 PtEtaMap->SetHistTitle("p_{t}","#eta");
37 // ########################################################
40 sprintf(execDir,gSystem->pwd());
41 TSystemDirectory* baseDir = new TSystemDirectory(".",dataDir);
42 TList* dirList = baseDir->GetListOfFiles();
43 Int_t nDirs = dirList->GetEntries();
44 // go back to the dir where this script is executed
47 // ########################################################
48 // definition of used pointers
54 // ########################################################
56 Int_t nRunCounter = 0;
57 for (Int_t r=0; r<nDirs; r++) {
59 TSystemFile* presentDir = (TSystemFile*)dirList->At(r);
60 if (!presentDir || !presentDir->IsDirectory())
62 // check that the files are there
63 TString currentDataDir;
64 currentDataDir.Form("%s/%s",dataDir, presentDir->GetName());
65 cout << "Processing directory " << currentDataDir.Data() << endl;
66 if ((!gSystem->Which(currentDataDir,"galice.root")) ||
67 (!gSystem->Which(currentDataDir,"AliESDs.root")))
70 if (nRunCounter++ >= nRuns)
73 cout << "run #" << nRunCounter << endl;
75 // #########################################################
76 // setup galice and runloader
78 delete gAlice->GetRunLoader();
83 sprintf(str,"%s/galice.root",currentDataDir.Data());
84 AliRunLoader* runLoader = AliRunLoader::Open(str);
86 runLoader->LoadgAlice();
87 gAlice = runLoader->GetAliRun();
88 runLoader->LoadKinematics();
89 runLoader->LoadHeader();
92 // #########################################################
93 // open esd file and get the tree
95 sprintf(str,"%s/AliESDs.root",currentDataDir.Data());
96 // close it first to avoid memory leak
98 if (esdFile->IsOpen())
101 esdFile = TFile::Open(str);
102 esdTree = (TTree*)esdFile->Get("esdTree");
105 esdBranch = esdTree->GetBranch("ESD");
106 esdBranch->SetAddress(&esd);
110 // ########################################################
112 AliTracker::SetFieldMap(gAlice->Field(),kTRUE); // kTRUE means uniform magnetic field
113 //AliKalmanTrack::SetConvConst(1000/0.299792458/5.);
115 // ########################################################
116 // getting number of events
117 Int_t nEvents = (Int_t)runLoader->GetNumberOfEvents();
118 Int_t nESDEvents = esdBranch->GetEntries();
120 if (nEvents!=nESDEvents) {
121 cout << " Different number of events from runloader and esdtree!!!" << nEvents << " / " << nESDEvents << endl;
124 // ########################################################
125 // loop over number of events
126 cout << " looping over events..." << endl;
127 for(Int_t i=0; i<nEvents; i++) {
129 esdBranch->GetEntry(i);
130 runLoader->GetEvent(i);
132 // ########################################################
133 // get the EDS vertex
134 AliESDVertex* vtxESD = esd->GetVertex();
140 vtx_res[0] = vtxESD->GetXRes();
141 vtx_res[1] = vtxESD->GetYRes();
142 vtx_res[2] = vtxESD->GetZRes();
144 // the vertex should be reconstructed
145 if (strcmp(vtxESD->GetName(),"default")==0)
148 // the resolution should be reasonable???
149 if (vtx_res[2]==0 || vtx_res[2]>0.1)
152 // ########################################################
153 // loop over mc particles
154 AliStack* particleStack = runLoader->Stack();
155 Int_t nPrim = particleStack->GetNprimary();
157 for (Int_t i_mc=0; i_mc<nPrim; i_mc++) {
159 TParticle* part = particleStack->Particle(i_mc);
160 if (!part || strcmp(part->GetName(),"XXX")==0)
163 TParticlePDG* pdgPart = part->GetPDG();
165 Bool_t prim = kFALSE;
166 // check if it's a primary particle - is there a better way ???
167 if ((part->GetFirstDaughter() >= nPrim) || (part->GetFirstDaughter()==-1)) {
168 if (TMath::Abs(pdgPart->PdgCode())>10 && pdgPart->PdgCode()!=21 && strcmp(pdgPart->ParticleClass(),"Unknown")!=0)
174 if (pdgPart->Charge()==0)
178 PtEtaMap->FillGene(part->Pt(), part->Eta());
180 }// end of mc particle
182 // ########################################################
183 // loop over esd tracks
184 Int_t nTracks = esd->GetNumberOfTracks();
185 for (Int_t t=0; t<nTracks; t++) {
186 AliESDtrack* esdTrack = esd->GetTrack(t);
188 // cut the esd track?
189 if (!esdTrackCuts->AcceptTrack(esdTrack))
193 if(!esdTrack->GetPxPyPz(Ptr0)) continue;
194 fTrP= new TVector3(Ptr0);
196 PtEtaMap->FillMeas(fTrP->Pt(), fTrP->Eta());
198 } // end of track loop
199 } // end of event loop
204 TFile* fout = new TFile("PtEtaCorrectionMap.root","RECREATE");
206 esdTrackCuts->SaveHistograms("EsdTrackCuts");
207 PtEtaMap->SaveHistograms();