]>
Commit | Line | Data |
---|---|---|
a1069ee1 | 1 | /************************************************************************** |
2 | * Author: Panos Christakoglou. * | |
3 | * Contributors are mentioned in the code where appropriate. * | |
4 | * * | |
5 | * Permission to use, copy, modify and distribute this software and its * | |
6 | * documentation strictly for non-commercial purposes is hereby granted * | |
7 | * without fee, provided that the above copyright notice appears in all * | |
8 | * copies and that both the copyright notice and this permission notice * | |
9 | * appear in the supporting documentation. The authors make no claims * | |
10 | * about the suitability of this software for any purpose. It is * | |
11 | * provided "as is" without express or implied warranty. * | |
12 | **************************************************************************/ | |
13 | ||
14 | /* $Id$ */ | |
15 | ||
16 | //----------------------------------------------------------------- | |
17 | // AliAODTagCreator class | |
18 | // This is the class to deal with the tag creation (post process) | |
19 | // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch | |
20 | //----------------------------------------------------------------- | |
21 | ||
22 | //ROOT | |
23 | #include <Riostream.h> | |
24 | #include <TFile.h> | |
25 | #include <TString.h> | |
26 | #include <TTree.h> | |
27 | #include <TSystem.h> | |
28 | #include <TChain.h> | |
29 | #include <TLorentzVector.h> | |
30 | ||
31 | //ROOT-AliEn | |
32 | #include <TGrid.h> | |
33 | #include <TGridResult.h> | |
34 | ||
35 | //AliRoot | |
36 | #include "AliRunTag.h" | |
37 | #include "AliEventTag.h" | |
38 | #include "AliPID.h" | |
a1069ee1 | 39 | #include "AliAODEvent.h" |
40 | #include "AliAODVertex.h" | |
41 | #include "AliLog.h" | |
42 | ||
43 | #include "AliAODTagCreator.h" | |
44 | ||
45 | ||
46 | ClassImp(AliAODTagCreator) | |
47 | ||
48 | ||
49 | //______________________________________________________________________________ | |
50 | AliAODTagCreator::AliAODTagCreator() : | |
51 | AliTagCreator() { | |
52 | //==============Default constructor for a AliAODTagCreator================ | |
53 | } | |
54 | ||
55 | //______________________________________________________________________________ | |
56 | AliAODTagCreator::~AliAODTagCreator() { | |
57 | //================Default destructor for a AliAODTagCreator=================== | |
58 | } | |
59 | ||
60 | //______________________________________________________________________________ | |
61 | Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) { | |
62 | // Reads the entry of the TGridResult and creates the tags | |
63 | Int_t nEntries = fresult->GetEntries(); | |
64 | ||
65 | TString alienUrl; | |
66 | const char *guid; | |
67 | const char *md5; | |
68 | const char *turl; | |
69 | Long64_t size = -1; | |
70 | ||
71 | Int_t counter = 0; | |
72 | for(Int_t i = 0; i < nEntries; i++) { | |
73 | alienUrl = fresult->GetKey(i,"turl"); | |
74 | guid = fresult->GetKey(i,"guid"); | |
75 | if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size")); | |
76 | md5 = fresult->GetKey(i,"md5"); | |
77 | turl = fresult->GetKey(i,"turl"); | |
78 | if(md5 && !strlen(guid)) md5 = 0; | |
79 | if(guid && !strlen(guid)) guid = 0; | |
80 | ||
81 | TFile *f = TFile::Open(alienUrl,"READ"); | |
82 | //CreateTag(f,guid,md5,turl,size,counter); | |
83 | f->Close(); | |
84 | delete f; | |
85 | counter += 1; | |
86 | }//grid result loop | |
87 | ||
88 | return kTRUE; | |
89 | } | |
90 | ||
91 | //______________________________________________________________________________ | |
92 | Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) { | |
93 | // Checks the different subdirs of the given local path and in the | |
94 | // case where it finds an AliAODs.root file it creates the tags | |
95 | ||
96 | void *dira = gSystem->OpenDirectory(localpath); | |
97 | Char_t fPath[256]; | |
98 | const char * dirname = 0x0; | |
99 | const char * filename = 0x0; | |
5b8d5d69 | 100 | const char * pattern = "AliAOD.root"; |
a1069ee1 | 101 | |
102 | Int_t counter = 0; | |
103 | while((dirname = gSystem->GetDirEntry(dira))) { | |
104 | sprintf(fPath,"%s/%s",localpath,dirname); | |
105 | void *dirb = gSystem->OpenDirectory(fPath); | |
106 | while((filename = gSystem->GetDirEntry(dirb))) { | |
107 | if(strstr(filename,pattern)) { | |
108 | TString fAODFileName; | |
109 | fAODFileName = fPath; | |
110 | fAODFileName += "/"; | |
111 | fAODFileName += pattern; | |
112 | TFile *f = TFile::Open(fAODFileName,"READ"); | |
5b8d5d69 | 113 | CreateTag(f,fAODFileName,counter); |
114 | f->Close(); | |
a1069ee1 | 115 | delete f; |
116 | ||
117 | counter += 1; | |
118 | }//pattern check | |
119 | }//child directory's entry loop | |
120 | }//parent directory's entry loop | |
121 | ||
122 | return kTRUE; | |
123 | } | |
124 | ||
125 | //______________________________________________________________________________ | |
126 | Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) { | |
127 | // Temporary solution for CAF: Takes as an input the ascii file that | |
128 | // lists the AODs stored in the SE of the CAF and creates the tags. | |
129 | ||
130 | // Open the input stream | |
131 | ifstream in; | |
132 | in.open(filename); | |
133 | ||
134 | Int_t counter = 0; | |
135 | TString esdfile; | |
136 | // Read the input list of files and add them to the chain | |
137 | while(in.good()) { | |
138 | in >> esdfile; | |
139 | if (!esdfile.Contains("root")) continue; // protection | |
140 | TFile *f = TFile::Open(esdfile,"READ"); | |
141 | //CreateTag(f,esdfile,counter); | |
142 | f->Close(); | |
143 | delete f; | |
144 | ||
145 | counter += 1; | |
146 | } | |
147 | ||
148 | return kTRUE; | |
149 | } | |
150 | ||
151 | //__________________________________________________________________________ | |
152 | void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent) { | |
153 | //creates tag files for AODs | |
154 | ||
155 | Float_t fLowPtCut = 1.0; | |
156 | Float_t fHighPtCut = 3.0; | |
157 | Float_t fVeryHighPtCut = 10.0; | |
158 | //////////// | |
159 | ||
160 | Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.}; | |
161 | ||
162 | // Creates the tags for all the events in a given AOD file | |
163 | Int_t ntrack; | |
164 | Int_t nProtons, nKaons, nPions, nMuons, nElectrons; | |
165 | Int_t nPos, nNeg, nNeutr; | |
166 | Int_t nKinks, nV0s, nCascades; | |
167 | Int_t nK0s, nNeutrons, nPi0s, nGamas; | |
168 | Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
169 | Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
170 | Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
171 | Float_t maxPt = .0, meanPt = .0, totalP = .0; | |
172 | ||
173 | AliRunTag *tag = new AliRunTag(); | |
174 | TTree ttag("T","A Tree with event tags"); | |
175 | TBranch * btag = ttag.Branch("AliTAG", &tag); | |
176 | btag->SetCompressionLevel(9); | |
177 | ||
178 | //reading the esd tag file | |
179 | TChain *oldTagTree = new TChain("T"); | |
180 | const char * tagPattern = "ESD.tag"; | |
181 | // Open the working directory | |
182 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
183 | const char * name = 0x0; | |
184 | // Add all files matching *pattern* to the chain | |
185 | while((name = gSystem->GetDirEntry(dirp))) { | |
186 | if (strstr(name,tagPattern)) oldTagTree->Add(name); | |
187 | }//directory loop | |
188 | AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries())); | |
189 | ||
190 | //reading the esd tag file | |
191 | AliRunTag *oldtag = new AliRunTag(); | |
192 | TString tagFilename; | |
193 | oldTagTree->SetBranchAddress("AliTAG",&oldtag); | |
194 | oldTagTree->GetEntry(0); | |
195 | tag->CopyStandardContent(oldtag); | |
196 | const TClonesArray *evTagList = oldtag->GetEventTags(); | |
197 | ||
198 | AliInfo(Form("Creating the AOD tags.......")); | |
199 | ||
200 | TFile *file = TFile::Open("AliAOD.root"); | |
201 | if (!file || !file->IsOpen()) { | |
202 | AliError(Form("opening failed")); | |
203 | delete file; | |
204 | return ; | |
205 | } | |
206 | TTree *aodTree = (TTree*)file->Get("aodTree"); | |
207 | AliAODEvent *aod = new AliAODEvent(); | |
208 | aod->ReadFromTree(aodTree); | |
209 | ||
210 | Int_t lastEvent = 0; | |
211 | if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries(); | |
212 | else lastEvent = fLastEvent; | |
213 | ||
214 | // loop over events | |
215 | Int_t nEvents = aodTree->GetEntries(); | |
216 | for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { | |
217 | AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber); | |
218 | ntrack = 0; | |
219 | nPos = 0; nNeg = 0; nNeutr =0; | |
220 | nKinks = 0; nV0s = 0; nCascades = 0; | |
221 | nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0; | |
222 | nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0; | |
223 | nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0; | |
224 | nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0; | |
225 | nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0; | |
226 | maxPt = .0; meanPt = .0; totalP = .0; | |
227 | ||
228 | // read events | |
229 | aodTree->GetEvent(iEventNumber); | |
230 | ||
231 | // set pointers | |
232 | aod->GetStdContent(); | |
233 | ||
234 | Int_t nTracks = aod->GetNTracks(); | |
235 | // loop over vertices | |
236 | Int_t nVtxs = aod->GetNVertices(); | |
237 | for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { | |
238 | // print track info | |
239 | AliAODVertex *vertex = aod->GetVertex(nVtx); | |
240 | if(vertex->GetType() == 1) nKinks += 1; | |
241 | if(vertex->GetType() == 2) nV0s += 1; | |
242 | if(vertex->GetType() == 3) nCascades += 1; | |
243 | } | |
244 | for (Int_t nTr = 0; nTr < nTracks; nTr++) { | |
245 | AliAODTrack *track = aod->GetTrack(nTr); | |
246 | ||
247 | Double_t fPt = track->Pt(); | |
248 | if(fPt > maxPt) maxPt = fPt; | |
249 | if(track->Charge() > 0) { | |
250 | nPos++; | |
251 | if(fPt > fLowPtCut) nCh1GeV++; | |
252 | if(fPt > fHighPtCut) nCh3GeV++; | |
253 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
254 | } | |
255 | if(track->Charge() < 0) { | |
256 | nNeg++; | |
257 | if(fPt > fLowPtCut) nCh1GeV++; | |
258 | if(fPt > fHighPtCut) nCh3GeV++; | |
259 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
260 | } | |
261 | if(track->Charge() == 0) nNeutr++; | |
262 | ||
263 | //PID | |
264 | const Double32_t *prob = track->PID(); | |
265 | Double_t rcc = 0.0; | |
266 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i]; | |
267 | if(rcc == 0.0) continue; | |
268 | //Bayes' formula | |
269 | Double_t w[10]; | |
270 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc; | |
271 | ||
272 | //protons | |
273 | if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++; | |
274 | //kaons | |
275 | if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++; | |
276 | //pions | |
277 | if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; | |
278 | //muons | |
279 | if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) { | |
280 | nMuons++; | |
281 | if(fPt > fLowPtCut) nMu1GeV++; | |
282 | if(fPt > fHighPtCut) nMu3GeV++; | |
283 | if(fPt > fVeryHighPtCut) nMu10GeV++; | |
284 | } | |
285 | //electrons | |
286 | if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) { | |
287 | nElectrons++; | |
288 | if(fPt > fLowPtCut) nEl1GeV++; | |
289 | if(fPt > fHighPtCut) nEl3GeV++; | |
290 | if(fPt > fVeryHighPtCut) nEl10GeV++; | |
291 | } | |
292 | ||
293 | totalP += track->P(); | |
294 | meanPt += fPt; | |
295 | ntrack++; | |
296 | }//track loop | |
297 | // Fill the event tags | |
298 | if(ntrack != 0) | |
299 | meanPt = meanPt/ntrack; | |
300 | ||
301 | evTag->SetEventId(iEventNumber+1); | |
302 | ||
303 | evTag->SetNumOfTracks(nTracks); | |
304 | evTag->SetNumOfPosTracks(nPos); | |
305 | evTag->SetNumOfNegTracks(nNeg); | |
306 | evTag->SetNumOfNeutrTracks(nNeutr); | |
307 | ||
308 | evTag->SetNumOfV0s(nV0s); | |
309 | evTag->SetNumOfCascades(nCascades); | |
310 | evTag->SetNumOfKinks(nKinks); | |
311 | ||
312 | evTag->SetNumOfProtons(nProtons); | |
313 | evTag->SetNumOfKaons(nKaons); | |
314 | evTag->SetNumOfPions(nPions); | |
315 | evTag->SetNumOfMuons(nMuons); | |
316 | evTag->SetNumOfElectrons(nElectrons); | |
317 | evTag->SetNumOfPhotons(nGamas); | |
318 | evTag->SetNumOfPi0s(nPi0s); | |
319 | evTag->SetNumOfNeutrons(nNeutrons); | |
320 | evTag->SetNumOfKaon0s(nK0s); | |
321 | ||
322 | evTag->SetNumOfChargedAbove1GeV(nCh1GeV); | |
323 | evTag->SetNumOfChargedAbove3GeV(nCh3GeV); | |
324 | evTag->SetNumOfChargedAbove10GeV(nCh10GeV); | |
325 | evTag->SetNumOfMuonsAbove1GeV(nMu1GeV); | |
326 | evTag->SetNumOfMuonsAbove3GeV(nMu3GeV); | |
327 | evTag->SetNumOfMuonsAbove10GeV(nMu10GeV); | |
328 | evTag->SetNumOfElectronsAbove1GeV(nEl1GeV); | |
329 | evTag->SetNumOfElectronsAbove3GeV(nEl3GeV); | |
330 | evTag->SetNumOfElectronsAbove10GeV(nEl10GeV); | |
331 | ||
332 | evTag->SetTotalMomentum(totalP); | |
333 | evTag->SetMeanPt(meanPt); | |
334 | evTag->SetMaxPt(maxPt); | |
335 | tag->AddEventTag(*evTag); | |
336 | }//event loop | |
337 | if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries(); | |
338 | else lastEvent = fLastEvent; | |
339 | ||
340 | ttag.Fill(); | |
341 | tag->Clear(); | |
342 | ||
343 | char fileName[256]; | |
344 | sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root", | |
345 | tag->GetRunId(),fFirstEvent,lastEvent ); | |
346 | AliInfo(Form("writing tags to file %s", fileName)); | |
347 | AliDebug(1, Form("writing tags to file %s", fileName)); | |
348 | ||
349 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
350 | ftag->cd(); | |
351 | ttag.Write(); | |
352 | ftag->Close(); | |
353 | file->cd(); | |
354 | file->Close(); | |
355 | } | |
356 | ||
357 | //_____________________________________________________________________________ | |
5b8d5d69 | 358 | void AliAODTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) { |
a1069ee1 | 359 | //private method that creates tag files |
360 | TString fguid = guid; | |
361 | TString fmd5 = md5; | |
362 | TString fturl = turl; | |
a1069ee1 | 363 | |
5b8d5d69 | 364 | //private method that creates tag files |
a1069ee1 | 365 | Float_t fLowPtCut = 1.0; |
366 | Float_t fHighPtCut = 3.0; | |
367 | Float_t fVeryHighPtCut = 10.0; | |
5b8d5d69 | 368 | //////////// |
369 | Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.}; | |
a1069ee1 | 370 | |
371 | // Creates the tags for all the events in a given AOD file | |
a1069ee1 | 372 | Int_t ntrack; |
373 | Int_t nProtons, nKaons, nPions, nMuons, nElectrons; | |
374 | Int_t nPos, nNeg, nNeutr; | |
5b8d5d69 | 375 | Int_t nKinks, nV0s, nCascades; |
a1069ee1 | 376 | Int_t nK0s, nNeutrons, nPi0s, nGamas; |
377 | Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
378 | Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
379 | Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
380 | Float_t maxPt = .0, meanPt = .0, totalP = .0; | |
a1069ee1 | 381 | |
382 | AliRunTag *tag = new AliRunTag(); | |
a1069ee1 | 383 | TTree ttag("T","A Tree with event tags"); |
384 | TBranch * btag = ttag.Branch("AliTAG", &tag); | |
385 | btag->SetCompressionLevel(9); | |
386 | ||
5b8d5d69 | 387 | //reading the esd tag file |
388 | ||
389 | TChain *oldTagTree = new TChain("T"); | |
390 | const char * tagPattern = "ESD.tag"; | |
391 | // Open the working directory | |
392 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
393 | const char * name = 0x0; | |
394 | // Add all files matching *pattern* to the chain | |
395 | while((name = gSystem->GetDirEntry(dirp))) { | |
396 | if (strstr(name,tagPattern)) oldTagTree->Add(name); | |
397 | }//directory loop | |
398 | AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries())); | |
a1069ee1 | 399 | |
5b8d5d69 | 400 | //reading the esd tag file |
401 | AliRunTag *oldtag = new AliRunTag(); | |
402 | TString tagFilename; | |
403 | oldTagTree->SetBranchAddress("AliTAG",&oldtag); | |
404 | oldTagTree->GetEntry(0); | |
405 | tag->CopyStandardContent(oldtag); | |
406 | const TClonesArray *evTagList = oldtag->GetEventTags(); | |
a1069ee1 | 407 | |
5b8d5d69 | 408 | AliInfo(Form("Creating the AOD tags.......")); |
409 | ||
410 | if (!file || !file->IsOpen()) { | |
411 | AliError(Form("opening failed")); | |
412 | delete file; | |
413 | return ; | |
414 | } | |
415 | TTree *aodTree = (TTree*)file->Get("aodTree"); | |
416 | AliAODEvent *aod = new AliAODEvent(); | |
417 | aod->ReadFromTree(aodTree); | |
418 | Int_t firstEvent = 0, lastEvent = 0; | |
419 | lastEvent = (Int_t)aodTree->GetEntries(); | |
420 | ||
421 | // loop over events | |
422 | Int_t nEvents = aodTree->GetEntries(); | |
423 | for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { | |
424 | AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber); | |
a1069ee1 | 425 | ntrack = 0; |
5b8d5d69 | 426 | nPos = 0; nNeg = 0; nNeutr =0; |
427 | nKinks = 0; nV0s = 0; nCascades = 0; | |
428 | nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0; | |
429 | nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0; | |
430 | nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0; | |
431 | nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0; | |
432 | nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0; | |
433 | maxPt = .0; meanPt = .0; totalP = .0; | |
434 | ||
435 | // read events | |
436 | aodTree->GetEvent(iEventNumber); | |
437 | // set pointers | |
438 | aod->GetStdContent(); | |
439 | ||
440 | Int_t nTracks = aod->GetNTracks(); | |
441 | // loop over vertices | |
442 | Int_t nVtxs = aod->GetNVertices(); | |
443 | for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { | |
444 | AliAODVertex *vertex = aod->GetVertex(nVtx); | |
445 | if(vertex->GetType() == 1) nKinks += 1; | |
446 | if(vertex->GetType() == 2) nV0s += 1; | |
447 | if(vertex->GetType() == 3) nCascades += 1; | |
448 | } | |
449 | for (Int_t nTr = 0; nTr < nTracks; nTr++) { | |
450 | AliAODTrack *track = aod->GetTrack(nTr); | |
451 | ||
452 | Double_t fPt = track->Pt(); | |
a1069ee1 | 453 | if(fPt > maxPt) maxPt = fPt; |
5b8d5d69 | 454 | if(track->Charge() > 0) { |
a1069ee1 | 455 | nPos++; |
456 | if(fPt > fLowPtCut) nCh1GeV++; | |
457 | if(fPt > fHighPtCut) nCh3GeV++; | |
458 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
459 | } | |
5b8d5d69 | 460 | if(track->Charge() < 0) { |
a1069ee1 | 461 | nNeg++; |
462 | if(fPt > fLowPtCut) nCh1GeV++; | |
463 | if(fPt > fHighPtCut) nCh3GeV++; | |
464 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
465 | } | |
5b8d5d69 | 466 | if(track->Charge() == 0) nNeutr++; |
a1069ee1 | 467 | //PID |
5b8d5d69 | 468 | const Double32_t *prob = track->PID(); |
a1069ee1 | 469 | Double_t rcc = 0.0; |
470 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i]; | |
471 | if(rcc == 0.0) continue; | |
5b8d5d69 | 472 | //Bayes' formula |
473 | Double_t w[10]; | |
a1069ee1 | 474 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc; |
5b8d5d69 | 475 | |
a1069ee1 | 476 | //protons |
477 | if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++; | |
478 | //kaons | |
479 | if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++; | |
480 | //pions | |
5b8d5d69 | 481 | if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; |
482 | //muons | |
483 | if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) { | |
484 | nMuons++; | |
485 | if(fPt > fLowPtCut) nMu1GeV++; | |
486 | if(fPt > fHighPtCut) nMu3GeV++; | |
487 | if(fPt > fVeryHighPtCut) nMu10GeV++; | |
488 | } | |
489 | //electrons | |
a1069ee1 | 490 | if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) { |
491 | nElectrons++; | |
492 | if(fPt > fLowPtCut) nEl1GeV++; | |
493 | if(fPt > fHighPtCut) nEl3GeV++; | |
494 | if(fPt > fVeryHighPtCut) nEl10GeV++; | |
a1069ee1 | 495 | } |
5b8d5d69 | 496 | |
497 | totalP += track->P(); | |
498 | meanPt += fPt; | |
499 | ntrack++; | |
500 | }//track loop | |
501 | // Fill the event tags | |
502 | if(ntrack != 0) | |
503 | meanPt = meanPt/ntrack; | |
a1069ee1 | 504 | |
505 | evTag->SetEventId(iEventNumber+1); | |
506 | evTag->SetGUID(fguid); | |
507 | evTag->SetMD5(fmd5); | |
508 | evTag->SetTURL(fturl); | |
509 | evTag->SetSize(size); | |
5b8d5d69 | 510 | |
511 | evTag->SetNumOfTracks(nTracks); | |
a1069ee1 | 512 | evTag->SetNumOfPosTracks(nPos); |
513 | evTag->SetNumOfNegTracks(nNeg); | |
514 | evTag->SetNumOfNeutrTracks(nNeutr); | |
5b8d5d69 | 515 | |
516 | evTag->SetNumOfV0s(nV0s); | |
517 | evTag->SetNumOfCascades(nCascades); | |
518 | evTag->SetNumOfKinks(nKinks); | |
519 | ||
a1069ee1 | 520 | evTag->SetNumOfProtons(nProtons); |
521 | evTag->SetNumOfKaons(nKaons); | |
522 | evTag->SetNumOfPions(nPions); | |
523 | evTag->SetNumOfMuons(nMuons); | |
524 | evTag->SetNumOfElectrons(nElectrons); | |
525 | evTag->SetNumOfPhotons(nGamas); | |
526 | evTag->SetNumOfPi0s(nPi0s); | |
527 | evTag->SetNumOfNeutrons(nNeutrons); | |
528 | evTag->SetNumOfKaon0s(nK0s); | |
5b8d5d69 | 529 | |
a1069ee1 | 530 | evTag->SetNumOfChargedAbove1GeV(nCh1GeV); |
531 | evTag->SetNumOfChargedAbove3GeV(nCh3GeV); | |
532 | evTag->SetNumOfChargedAbove10GeV(nCh10GeV); | |
533 | evTag->SetNumOfMuonsAbove1GeV(nMu1GeV); | |
534 | evTag->SetNumOfMuonsAbove3GeV(nMu3GeV); | |
535 | evTag->SetNumOfMuonsAbove10GeV(nMu10GeV); | |
536 | evTag->SetNumOfElectronsAbove1GeV(nEl1GeV); | |
537 | evTag->SetNumOfElectronsAbove3GeV(nEl3GeV); | |
538 | evTag->SetNumOfElectronsAbove10GeV(nEl10GeV); | |
5b8d5d69 | 539 | |
a1069ee1 | 540 | evTag->SetTotalMomentum(totalP); |
541 | evTag->SetMeanPt(meanPt); | |
542 | evTag->SetMaxPt(maxPt); | |
a1069ee1 | 543 | tag->AddEventTag(*evTag); |
544 | }//event loop | |
a1069ee1 | 545 | |
546 | ttag.Fill(); | |
547 | tag->Clear(); | |
5b8d5d69 | 548 | |
549 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
550 | localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; | |
551 | localFileName += lastEvent; localFileName += "."; localFileName += Counter; | |
552 | localFileName += ".AOD.tag.root"; | |
a1069ee1 | 553 | |
554 | TString fileName; | |
5b8d5d69 | 555 | |
a1069ee1 | 556 | if(fStorage == 0) { |
5b8d5d69 | 557 | fileName = localFileName.Data(); |
558 | AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data())); | |
a1069ee1 | 559 | } |
560 | else if(fStorage == 1) { | |
561 | TString alienLocation = "/alien"; | |
562 | alienLocation += gGrid->Pwd(); | |
563 | alienLocation += fgridpath.Data(); | |
564 | alienLocation += "/"; | |
565 | alienLocation += localFileName; | |
566 | alienLocation += "?se="; | |
567 | alienLocation += fSE.Data(); | |
568 | fileName = alienLocation.Data(); | |
5b8d5d69 | 569 | AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data())); |
a1069ee1 | 570 | } |
571 | ||
572 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
573 | ftag->cd(); | |
574 | ttag.Write(); | |
575 | ftag->Close(); | |
5b8d5d69 | 576 | } |
577 | ||
a1069ee1 | 578 | |
579 | //_____________________________________________________________________________ | |
5b8d5d69 | 580 | void AliAODTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) { |
a1069ee1 | 581 | //private method that creates tag files |
a1069ee1 | 582 | Float_t fLowPtCut = 1.0; |
583 | Float_t fHighPtCut = 3.0; | |
584 | Float_t fVeryHighPtCut = 10.0; | |
585 | //////////// | |
5b8d5d69 | 586 | |
587 | Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.}; | |
588 | ||
589 | // Creates the tags for all the events in a given AOD file | |
a1069ee1 | 590 | Int_t ntrack; |
591 | Int_t nProtons, nKaons, nPions, nMuons, nElectrons; | |
592 | Int_t nPos, nNeg, nNeutr; | |
5b8d5d69 | 593 | Int_t nKinks, nV0s, nCascades; |
a1069ee1 | 594 | Int_t nK0s, nNeutrons, nPi0s, nGamas; |
595 | Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
596 | Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
597 | Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
598 | Float_t maxPt = .0, meanPt = .0, totalP = .0; | |
a1069ee1 | 599 | |
600 | AliRunTag *tag = new AliRunTag(); | |
a1069ee1 | 601 | TTree ttag("T","A Tree with event tags"); |
602 | TBranch * btag = ttag.Branch("AliTAG", &tag); | |
603 | btag->SetCompressionLevel(9); | |
a1069ee1 | 604 | |
5b8d5d69 | 605 | //reading the esd tag file |
606 | TChain *oldTagTree = new TChain("T"); | |
607 | const char * tagPattern = "ESD.tag"; | |
608 | // Open the working directory | |
609 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
610 | const char * name = 0x0; | |
611 | // Add all files matching *pattern* to the chain | |
612 | while((name = gSystem->GetDirEntry(dirp))) { | |
613 | if (strstr(name,tagPattern)) oldTagTree->Add(name); | |
614 | }//directory loop | |
615 | AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries())); | |
616 | ||
617 | //reading the esd tag file | |
618 | AliRunTag *oldtag = new AliRunTag(); | |
619 | TString tagFilename; | |
620 | oldTagTree->SetBranchAddress("AliTAG",&oldtag); | |
621 | oldTagTree->GetEntry(0); | |
622 | tag->CopyStandardContent(oldtag); | |
623 | const TClonesArray *evTagList = oldtag->GetEventTags(); | |
624 | ||
625 | AliInfo(Form("Creating the AOD tags.......")); | |
626 | ||
627 | if (!file || !file->IsOpen()) { | |
628 | AliError(Form("opening failed")); | |
629 | delete file; | |
630 | return ; | |
631 | } | |
632 | TTree *aodTree = (TTree*)file->Get("aodTree"); | |
633 | AliAODEvent *aod = new AliAODEvent(); | |
634 | aod->ReadFromTree(aodTree); | |
635 | Int_t firstEvent = 0, lastEvent = 0; | |
636 | lastEvent = (Int_t)aodTree->GetEntries(); | |
637 | ||
638 | // loop over events | |
639 | Int_t nEvents = aodTree->GetEntries(); | |
640 | for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { | |
641 | AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber); | |
a1069ee1 | 642 | ntrack = 0; |
5b8d5d69 | 643 | nPos = 0; nNeg = 0; nNeutr =0; |
644 | nKinks = 0; nV0s = 0; nCascades = 0; | |
645 | nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0; | |
646 | nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0; | |
647 | nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0; | |
648 | nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0; | |
649 | nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0; | |
650 | maxPt = .0; meanPt = .0; totalP = .0; | |
651 | ||
652 | // read events | |
653 | aodTree->GetEvent(iEventNumber); | |
a1069ee1 | 654 | |
5b8d5d69 | 655 | // set pointers |
656 | aod->GetStdContent(); | |
657 | ||
658 | Int_t nTracks = aod->GetNTracks(); | |
659 | // loop over vertices | |
660 | Int_t nVtxs = aod->GetNVertices(); | |
661 | for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { | |
662 | // print track info | |
663 | AliAODVertex *vertex = aod->GetVertex(nVtx); | |
664 | if(vertex->GetType() == 1) nKinks += 1; | |
665 | if(vertex->GetType() == 2) nV0s += 1; | |
666 | if(vertex->GetType() == 3) nCascades += 1; | |
667 | } | |
668 | for (Int_t nTr = 0; nTr < nTracks; nTr++) { | |
669 | AliAODTrack *track = aod->GetTrack(nTr); | |
a1069ee1 | 670 | |
5b8d5d69 | 671 | Double_t fPt = track->Pt(); |
a1069ee1 | 672 | if(fPt > maxPt) maxPt = fPt; |
5b8d5d69 | 673 | if(track->Charge() > 0) { |
674 | nPos++; | |
675 | if(fPt > fLowPtCut) nCh1GeV++; | |
676 | if(fPt > fHighPtCut) nCh3GeV++; | |
677 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
a1069ee1 | 678 | } |
5b8d5d69 | 679 | if(track->Charge() < 0) { |
680 | nNeg++; | |
681 | if(fPt > fLowPtCut) nCh1GeV++; | |
682 | if(fPt > fHighPtCut) nCh3GeV++; | |
683 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
a1069ee1 | 684 | } |
5b8d5d69 | 685 | if(track->Charge() == 0) nNeutr++; |
686 | ||
a1069ee1 | 687 | //PID |
5b8d5d69 | 688 | const Double32_t *prob = track->PID(); |
a1069ee1 | 689 | Double_t rcc = 0.0; |
690 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i]; | |
691 | if(rcc == 0.0) continue; | |
692 | //Bayes' formula | |
5b8d5d69 | 693 | Double_t w[10]; |
a1069ee1 | 694 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc; |
695 | ||
696 | //protons | |
697 | if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++; | |
698 | //kaons | |
699 | if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++; | |
700 | //pions | |
701 | if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; | |
5b8d5d69 | 702 | //muons |
703 | if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) { | |
704 | nMuons++; | |
705 | if(fPt > fLowPtCut) nMu1GeV++; | |
706 | if(fPt > fHighPtCut) nMu3GeV++; | |
707 | if(fPt > fVeryHighPtCut) nMu10GeV++; | |
708 | } | |
a1069ee1 | 709 | //electrons |
710 | if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) { | |
5b8d5d69 | 711 | nElectrons++; |
712 | if(fPt > fLowPtCut) nEl1GeV++; | |
713 | if(fPt > fHighPtCut) nEl3GeV++; | |
714 | if(fPt > fVeryHighPtCut) nEl10GeV++; | |
a1069ee1 | 715 | } |
5b8d5d69 | 716 | |
717 | totalP += track->P(); | |
718 | meanPt += fPt; | |
719 | ntrack++; | |
720 | }//track loop | |
a1069ee1 | 721 | // Fill the event tags |
5b8d5d69 | 722 | if(ntrack != 0) |
723 | meanPt = meanPt/ntrack; | |
724 | ||
a1069ee1 | 725 | evTag->SetEventId(iEventNumber+1); |
726 | evTag->SetPath(filepath); | |
5b8d5d69 | 727 | |
728 | evTag->SetNumOfTracks(nTracks); | |
a1069ee1 | 729 | evTag->SetNumOfPosTracks(nPos); |
730 | evTag->SetNumOfNegTracks(nNeg); | |
731 | evTag->SetNumOfNeutrTracks(nNeutr); | |
732 | ||
5b8d5d69 | 733 | evTag->SetNumOfV0s(nV0s); |
734 | evTag->SetNumOfCascades(nCascades); | |
735 | evTag->SetNumOfKinks(nKinks); | |
a1069ee1 | 736 | |
737 | evTag->SetNumOfProtons(nProtons); | |
738 | evTag->SetNumOfKaons(nKaons); | |
739 | evTag->SetNumOfPions(nPions); | |
740 | evTag->SetNumOfMuons(nMuons); | |
741 | evTag->SetNumOfElectrons(nElectrons); | |
742 | evTag->SetNumOfPhotons(nGamas); | |
743 | evTag->SetNumOfPi0s(nPi0s); | |
744 | evTag->SetNumOfNeutrons(nNeutrons); | |
745 | evTag->SetNumOfKaon0s(nK0s); | |
746 | ||
747 | evTag->SetNumOfChargedAbove1GeV(nCh1GeV); | |
748 | evTag->SetNumOfChargedAbove3GeV(nCh3GeV); | |
749 | evTag->SetNumOfChargedAbove10GeV(nCh10GeV); | |
750 | evTag->SetNumOfMuonsAbove1GeV(nMu1GeV); | |
751 | evTag->SetNumOfMuonsAbove3GeV(nMu3GeV); | |
752 | evTag->SetNumOfMuonsAbove10GeV(nMu10GeV); | |
753 | evTag->SetNumOfElectronsAbove1GeV(nEl1GeV); | |
754 | evTag->SetNumOfElectronsAbove3GeV(nEl3GeV); | |
755 | evTag->SetNumOfElectronsAbove10GeV(nEl10GeV); | |
756 | ||
a1069ee1 | 757 | evTag->SetTotalMomentum(totalP); |
758 | evTag->SetMeanPt(meanPt); | |
759 | evTag->SetMaxPt(maxPt); | |
a1069ee1 | 760 | tag->AddEventTag(*evTag); |
5b8d5d69 | 761 | }//event loop |
762 | ||
a1069ee1 | 763 | ttag.Fill(); |
764 | tag->Clear(); | |
765 | ||
766 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
5b8d5d69 | 767 | localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; |
768 | localFileName += lastEvent; localFileName += "."; localFileName += Counter; | |
769 | localFileName += ".AOD.tag.root"; | |
a1069ee1 | 770 | |
771 | TString fileName; | |
772 | ||
773 | if(fStorage == 0) { | |
774 | fileName = localFileName.Data(); | |
5b8d5d69 | 775 | AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data())); |
a1069ee1 | 776 | } |
777 | else if(fStorage == 1) { | |
778 | TString alienLocation = "/alien"; | |
779 | alienLocation += gGrid->Pwd(); | |
780 | alienLocation += fgridpath.Data(); | |
781 | alienLocation += "/"; | |
782 | alienLocation += localFileName; | |
783 | alienLocation += "?se="; | |
784 | alienLocation += fSE.Data(); | |
785 | fileName = alienLocation.Data(); | |
5b8d5d69 | 786 | AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data())); |
a1069ee1 | 787 | } |
788 | ||
789 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
790 | ftag->cd(); | |
791 | ttag.Write(); | |
792 | ftag->Close(); | |
5b8d5d69 | 793 | } |
a1069ee1 | 794 |