]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/dNdEta/makeCorrection.C
fixed the way the event bias selection is done
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / makeCorrection.C
CommitLineData
75ec0f41 1//
2// Script to make correction maps for dndeta measurements using the
3// dNdEtaCorrection class.
4//
5
6makeCorrection(Char_t* dataDir, Int_t nRuns=20) {
7
8 Char_t str[256];
9
745e836a 10 gSystem->Load("../libPWG0base.so");
75ec0f41 11
12 // ########################################################
13 // selection of esd tracks
745e836a 14 AliESDtrackCuts* esdTrackCuts = new AliESDtrackCuts();
75ec0f41 15 esdTrackCuts->DefineHistograms(1);
16
17 esdTrackCuts->SetMinNClustersTPC(50);
18 esdTrackCuts->SetMaxChi2PerClusterTPC(3.5);
19 esdTrackCuts->SetMaxCovDiagonalElements(2,2,0.5,0.5,2);
20 esdTrackCuts->SetRequireTPCRefit(kTRUE);
21
22 esdTrackCuts->SetMinNsigmaToVertex(3);
23 esdTrackCuts->SetAcceptKingDaughters(kFALSE);
24
745e836a 25 AliLog::SetClassDebugLevel("AliESDtrackCuts",1);
75ec0f41 26
27 // ########################################################
28 // definition of dNdEta correction object
29
30 dNdEtaCorrection* dNdEtaMap = new dNdEtaCorrection();
31
32 // ########################################################
33 // get the data dir
34 Char_t execDir[256];
35 sprintf(execDir,gSystem->pwd());
36 TSystemDirectory* baseDir = new TSystemDirectory(".",dataDir);
37 TList* dirList = baseDir->GetListOfFiles();
38 Int_t nDirs = dirList->GetEntries();
39 // go back to the dir where this script is executed
40 gSystem->cd(execDir);
41
42 // ########################################################
43 // definition of used pointers
44 TFile* esdFile;
45 TTree* esdTree;
46 TBranch* esdBranch;
47
48 AliESD* esd =0;
49
50 // ########################################################
51 // loop over runs
52 Int_t nRunCounter = 0;
53 for (Int_t r=0; r<nDirs; r++) {
54
55 TSystemFile* presentDir = (TSystemFile*)dirList->At(r);
56 if (!presentDir || !presentDir->IsDirectory())
57 continue;
58 // check that the files are there
59 TString currentDataDir;
60 currentDataDir.Form("%s/%s",dataDir, presentDir->GetName());
61 cout << "Processing directory " << currentDataDir.Data() << endl;
62 if ((!gSystem->Which(currentDataDir,"galice.root")) ||
63 (!gSystem->Which(currentDataDir,"AliESDs.root")))
64 continue;
65
66 if (nRunCounter++ >= nRuns)
67 break;
68
69 cout << "run #" << nRunCounter << endl;
70
71 // #########################################################
72 // setup galice and runloader
73 if (gAlice) {
74 delete gAlice->GetRunLoader();
75 delete gAlice;
76 gAlice=0;
77 }
78
79 sprintf(str,"%s/galice.root",currentDataDir.Data());
80 AliRunLoader* runLoader = AliRunLoader::Open(str);
81
82 runLoader->LoadgAlice();
83 gAlice = runLoader->GetAliRun();
84 runLoader->LoadKinematics();
85 runLoader->LoadHeader();
86
87 // #########################################################
88 // open esd file and get the tree
89
90 sprintf(str,"%s/AliESDs.root",currentDataDir.Data());
91 // close it first to avoid memory leak
92 if (esdFile)
93 if (esdFile->IsOpen())
94 esdFile->Close();
95
96 esdFile = TFile::Open(str);
97 esdTree = (TTree*)esdFile->Get("esdTree");
98 if (!esdTree)
99 continue;
100 esdBranch = esdTree->GetBranch("ESD");
101 esdBranch->SetAddress(&esd);
102 if (!esdBranch)
103 continue;
104
105 // ########################################################
106 // Magnetic field
107 AliTracker::SetFieldMap(gAlice->Field(),kTRUE); // kTRUE means uniform magnetic field
108 //AliKalmanTrack::SetConvConst(1000/0.299792458/5.);
109
110 // ########################################################
111 // getting number of events
112 Int_t nEvents = (Int_t)runLoader->GetNumberOfEvents();
113 Int_t nESDEvents = esdBranch->GetEntries();
114
115 if (nEvents!=nESDEvents) {
116 cout << " Different number of events from runloader and esdtree!!!" << nEvents << " / " << nESDEvents << endl;
117 return;
118 }
119 // ########################################################
120 // loop over number of events
121 cout << " looping over events..." << endl;
122 for(Int_t i=0; i<nEvents; i++) {
123
124 esdBranch->GetEntry(i);
125 runLoader->GetEvent(i);
126
127 // ########################################################
128 // get the EDS vertex
129 AliESDVertex* vtxESD = esd->GetVertex();
130
131 Double_t vtx[3];
132 Double_t vtx_res[3];
133 vtxESD->GetXYZ(vtx);
134
135 vtx_res[0] = vtxESD->GetXRes();
136 vtx_res[1] = vtxESD->GetYRes();
137 vtx_res[2] = vtxESD->GetZRes();
138
745e836a 139 Bool_t goodEvent = kTRUE;
140
75ec0f41 141 // the vertex should be reconstructed
142 if (strcmp(vtxESD->GetName(),"default")==0)
745e836a 143 goodEvent = kFALSE;
75ec0f41 144
145 // the resolution should be reasonable???
745e836a 146 if (vtx_res[2]==0 || vtx_res[2]>0.01)
147 goodEvent = kFALSE;
75ec0f41 148
149 // ########################################################
150 // get the MC vertex
151 AliGenPythiaEventHeader* genHeader =
152 (AliGenPythiaEventHeader*)runLoader->GetHeader()->GenEventHeader();
153
154 TArrayF vtxMC(3);
155 genHeader->PrimaryVertex(vtxMC);
156 Double_t vtx[3];
157 vtx[0] = vtxMC[0];
158 vtx[1] = vtxMC[1];
159 vtx[2] = vtxMC[2];
160
75ec0f41 161 // ########################################################
162 // loop over mc particles
163 AliStack* particleStack = runLoader->Stack();
164 Int_t nPrim = particleStack->GetNprimary();
165
166 for (Int_t i_mc=0; i_mc<nPrim; i_mc++) {
167
168 TParticle* part = particleStack->Particle(i_mc);
169 if (!part || strcmp(part->GetName(),"XXX")==0)
170 continue;
171
172 TParticlePDG* pdgPart = part->GetPDG();
173
174 Bool_t prim = kFALSE;
175 // check if it's a primary particle - is there a better way ???
176 if ((part->GetFirstDaughter() >= nPrim) || (part->GetFirstDaughter()==-1)) {
177 if (TMath::Abs(pdgPart->PdgCode())>10 && pdgPart->PdgCode()!=21 && strcmp(pdgPart->ParticleClass(),"Unknown")!=0)
178 prim = kTRUE;
179 }
180 if (!prim)
181 continue;
182
183 if (pdgPart->Charge()==0)
184 continue;
185
186 Float_t eta = part->Eta();
187
745e836a 188 if (prim) {
189 dNdEtaMap->FillParticleAllEvents(vtx[2], eta);
190
191 if (goodEvent)
192 dNdEtaMap->FillParticleWhenGoodEvent(vtx[2], eta);
193 }
75ec0f41 194
195 }// end of mc particle
196
745e836a 197 if (!goodEvent)
198 continue;
199
75ec0f41 200 // ########################################################
201 // loop over esd tracks
202 Int_t nTracks = esd->GetNumberOfTracks();
203 for (Int_t t=0; t<nTracks; t++) {
204 AliESDtrack* esdTrack = esd->GetTrack(t);
205
206 // cut the esd track?
207 if (!esdTrackCuts->AcceptTrack(esdTrack))
208 continue;
209
210 AliTPCtrack* tpcTrack = new AliTPCtrack(*esdTrack);
211 if (tpcTrack->GetAlpha()==0) {
212 cout << " Warning esd track alpha = 0" << endl;
213 continue;
214 }
215
216 Float_t theta = tpcTrack->Theta();
217 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
218
219 // using the eta of the mc particle
220 Int_t label = TMath::Abs(esdTrack->GetLabel());
221 if (label<0) {
222 cout << " cannot find corresponding mc part !!! " << label << endl;
223 continue;
224 }
225 TParticle* mcPart = particleStack->Particle(label);
226 eta = mcPart->Eta();
227
745e836a 228 dNdEtaMap->FillParticleWhenMeasuredTrack(vtx[2], eta);
75ec0f41 229
230 } // end of track loop
231 } // end of event loop
232 } // end of run loop
233
234 dNdEtaMap->Finish();
235
236 TFile* fout = new TFile("correction_map.root","RECREATE");
237
238 esdTrackCuts->SaveHistograms("esd_track_cuts");
239 dNdEtaMap->SaveHistograms();
240
241 fout->Write();
242 fout->Close();
243
244 dNdEtaMap->DrawHistograms();
245
246}