]>
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() : | |
103d3fba | 51 | AliTagCreator(), fChain(new TChain("aodTree")) { |
a1069ee1 | 52 | //==============Default constructor for a AliAODTagCreator================ |
53 | } | |
54 | ||
55 | //______________________________________________________________________________ | |
56 | AliAODTagCreator::~AliAODTagCreator() { | |
57 | //================Default destructor for a AliAODTagCreator=================== | |
103d3fba | 58 | delete fChain; |
a1069ee1 | 59 | } |
60 | ||
61 | //______________________________________________________________________________ | |
62 | Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) { | |
63 | // Reads the entry of the TGridResult and creates the tags | |
64 | Int_t nEntries = fresult->GetEntries(); | |
65 | ||
103d3fba | 66 | TString alienUrl; |
67 | const char* guid; | |
68 | const char* md5; | |
69 | const char* turl; | |
70 | Long64_t size = -1; | |
71 | ||
72 | Int_t counter = 0; | |
73 | for(Int_t i = 0; i < nEntries; i++) { | |
74 | alienUrl = fresult->GetKey(i,"turl"); | |
75 | guid = fresult->GetKey(i,"guid"); | |
76 | if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size")); | |
77 | md5 = fresult->GetKey(i,"md5"); | |
78 | turl = fresult->GetKey(i,"turl"); | |
79 | if(md5 && !strlen(guid)) md5 = 0; | |
80 | if(guid && !strlen(guid)) guid = 0; | |
81 | ||
82 | fChain->Add(alienUrl); | |
83 | //fGUIDList->Add(new TObjString(guid)); | |
84 | //fMD5List->Add(new TObjString(md5)); | |
85 | //fTURLList->Add(new TObjString(turl)); | |
86 | ||
87 | //TFile *f = TFile::Open(alienUrl,"READ"); | |
88 | //CreateTag(f,guid,md5,turl,size,counter); | |
89 | //f->Close(); | |
90 | //delete f; | |
91 | counter += 1; | |
92 | }//grid result loop | |
93 | ||
94 | AliInfo(Form("AOD chain created.......")); | |
95 | AliInfo(Form("Chain entries: %d",fChain->GetEntries())); | |
96 | CreateTag(fChain,"grid"); | |
97 | ||
98 | return kTRUE; | |
99 | } | |
100 | ||
101 | //______________________________________________________________________________ | |
102 | /*Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) { | |
103 | // Reads the entry of the TGridResult and creates the tags | |
104 | Int_t nEntries = fresult->GetEntries(); | |
105 | ||
a1069ee1 | 106 | TString alienUrl; |
107 | const char *guid; | |
108 | const char *md5; | |
109 | const char *turl; | |
110 | Long64_t size = -1; | |
111 | ||
112 | Int_t counter = 0; | |
113 | for(Int_t i = 0; i < nEntries; i++) { | |
114 | alienUrl = fresult->GetKey(i,"turl"); | |
115 | guid = fresult->GetKey(i,"guid"); | |
116 | if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size")); | |
117 | md5 = fresult->GetKey(i,"md5"); | |
118 | turl = fresult->GetKey(i,"turl"); | |
119 | if(md5 && !strlen(guid)) md5 = 0; | |
120 | if(guid && !strlen(guid)) guid = 0; | |
121 | ||
122 | TFile *f = TFile::Open(alienUrl,"READ"); | |
7ee67d2a | 123 | CreateTag(f,guid,md5,turl,size,counter); |
a1069ee1 | 124 | f->Close(); |
125 | delete f; | |
126 | counter += 1; | |
127 | }//grid result loop | |
128 | ||
129 | return kTRUE; | |
103d3fba | 130 | }*/ |
a1069ee1 | 131 | |
132 | //______________________________________________________________________________ | |
133 | Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) { | |
103d3fba | 134 | // Checks the different subdirs of the given local path and in the |
135 | // case where it finds an AliESDs.root file it creates the tags | |
136 | ||
137 | void *dira = gSystem->OpenDirectory(localpath); | |
138 | Char_t fPath[256]; | |
139 | const char * dirname = 0x0; | |
140 | const char * filename = 0x0; | |
141 | const char * pattern = "AliAODs.root"; | |
142 | ||
143 | Int_t counter = 0; | |
144 | while((dirname = gSystem->GetDirEntry(dira))) { | |
145 | sprintf(fPath,"%s/%s",localpath,dirname); | |
146 | void *dirb = gSystem->OpenDirectory(fPath); | |
147 | while((filename = gSystem->GetDirEntry(dirb))) { | |
148 | if(strstr(filename,pattern)) { | |
149 | TString fESDFileName; | |
150 | fESDFileName = fPath; | |
151 | fESDFileName += "/"; | |
152 | fESDFileName += pattern; | |
153 | ||
154 | fChain->Add(fESDFileName); | |
155 | ||
156 | //TFile *f = TFile::Open(fESDFileName,"READ"); | |
157 | //CreateTag(f,fESDFileName,counter); | |
158 | //f->Close(); | |
159 | //delete f; | |
160 | ||
161 | counter += 1; | |
162 | }//pattern check | |
163 | }//child directory's entry loop | |
164 | }//parent directory's entry loop | |
165 | ||
166 | AliInfo(Form("AOD chain created.......")); | |
167 | AliInfo(Form("Chain entries: %d",fChain->GetEntries())); | |
168 | CreateTag(fChain,"local"); | |
169 | ||
170 | return kTRUE; | |
171 | } | |
172 | ||
173 | //______________________________________________________________________________ | |
174 | /*Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) { | |
a1069ee1 | 175 | // Checks the different subdirs of the given local path and in the |
176 | // case where it finds an AliAODs.root file it creates the tags | |
177 | ||
178 | void *dira = gSystem->OpenDirectory(localpath); | |
179 | Char_t fPath[256]; | |
180 | const char * dirname = 0x0; | |
181 | const char * filename = 0x0; | |
5b8d5d69 | 182 | const char * pattern = "AliAOD.root"; |
a1069ee1 | 183 | |
184 | Int_t counter = 0; | |
185 | while((dirname = gSystem->GetDirEntry(dira))) { | |
186 | sprintf(fPath,"%s/%s",localpath,dirname); | |
187 | void *dirb = gSystem->OpenDirectory(fPath); | |
188 | while((filename = gSystem->GetDirEntry(dirb))) { | |
189 | if(strstr(filename,pattern)) { | |
190 | TString fAODFileName; | |
191 | fAODFileName = fPath; | |
192 | fAODFileName += "/"; | |
193 | fAODFileName += pattern; | |
194 | TFile *f = TFile::Open(fAODFileName,"READ"); | |
5b8d5d69 | 195 | CreateTag(f,fAODFileName,counter); |
196 | f->Close(); | |
a1069ee1 | 197 | delete f; |
198 | ||
199 | counter += 1; | |
200 | }//pattern check | |
201 | }//child directory's entry loop | |
202 | }//parent directory's entry loop | |
203 | ||
204 | return kTRUE; | |
103d3fba | 205 | }*/ |
206 | ||
a1069ee1 | 207 | |
208 | //______________________________________________________________________________ | |
209 | Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) { | |
103d3fba | 210 | // Temporary solution for CAF: Takes as an input the ascii file that |
211 | // lists the ESDs stored in the SE of the CAF and creates the tags. | |
212 | ||
213 | // Open the input stream | |
214 | ifstream in; | |
215 | in.open(filename); | |
216 | ||
217 | Int_t counter = 0; | |
218 | TString esdfile; | |
219 | // Read the input list of files and add them to the chain | |
220 | while(in.good()) { | |
221 | in >> esdfile; | |
222 | if (!esdfile.Contains("root")) continue; // protection | |
223 | ||
224 | fChain->Add(esdfile); | |
225 | ||
226 | //TFile *f = TFile::Open(esdfile,"READ"); | |
227 | //CreateTag(f,esdfile,counter); | |
228 | //f->Close(); | |
229 | //delete f; | |
230 | ||
231 | counter += 1; | |
232 | } | |
233 | ||
234 | AliInfo(Form("AOD chain created.......")); | |
235 | AliInfo(Form("Chain entries: %d",fChain->GetEntries())); | |
236 | CreateTag(fChain,"proof"); | |
237 | ||
238 | return kTRUE; | |
239 | } | |
240 | ||
241 | //______________________________________________________________________________ | |
242 | /*Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) { | |
a1069ee1 | 243 | // Temporary solution for CAF: Takes as an input the ascii file that |
244 | // lists the AODs stored in the SE of the CAF and creates the tags. | |
245 | ||
246 | // Open the input stream | |
247 | ifstream in; | |
248 | in.open(filename); | |
249 | ||
250 | Int_t counter = 0; | |
251 | TString esdfile; | |
252 | // Read the input list of files and add them to the chain | |
253 | while(in.good()) { | |
254 | in >> esdfile; | |
255 | if (!esdfile.Contains("root")) continue; // protection | |
256 | TFile *f = TFile::Open(esdfile,"READ"); | |
7ee67d2a | 257 | CreateTag(f,esdfile,counter); |
a1069ee1 | 258 | f->Close(); |
259 | delete f; | |
260 | ||
261 | counter += 1; | |
262 | } | |
263 | ||
264 | return kTRUE; | |
103d3fba | 265 | }*/ |
a1069ee1 | 266 | |
267 | //__________________________________________________________________________ | |
268 | void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent) { | |
269 | //creates tag files for AODs | |
270 | ||
271 | Float_t fLowPtCut = 1.0; | |
272 | Float_t fHighPtCut = 3.0; | |
273 | Float_t fVeryHighPtCut = 10.0; | |
274 | //////////// | |
275 | ||
276 | Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.}; | |
277 | ||
278 | // Creates the tags for all the events in a given AOD file | |
279 | Int_t ntrack; | |
280 | Int_t nProtons, nKaons, nPions, nMuons, nElectrons; | |
281 | Int_t nPos, nNeg, nNeutr; | |
282 | Int_t nKinks, nV0s, nCascades; | |
283 | Int_t nK0s, nNeutrons, nPi0s, nGamas; | |
284 | Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
285 | Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
286 | Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
287 | Float_t maxPt = .0, meanPt = .0, totalP = .0; | |
288 | ||
289 | AliRunTag *tag = new AliRunTag(); | |
290 | TTree ttag("T","A Tree with event tags"); | |
291 | TBranch * btag = ttag.Branch("AliTAG", &tag); | |
292 | btag->SetCompressionLevel(9); | |
293 | ||
294 | //reading the esd tag file | |
295 | TChain *oldTagTree = new TChain("T"); | |
296 | const char * tagPattern = "ESD.tag"; | |
297 | // Open the working directory | |
298 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
299 | const char * name = 0x0; | |
300 | // Add all files matching *pattern* to the chain | |
301 | while((name = gSystem->GetDirEntry(dirp))) { | |
302 | if (strstr(name,tagPattern)) oldTagTree->Add(name); | |
303 | }//directory loop | |
304 | AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries())); | |
305 | ||
306 | //reading the esd tag file | |
307 | AliRunTag *oldtag = new AliRunTag(); | |
308 | TString tagFilename; | |
309 | oldTagTree->SetBranchAddress("AliTAG",&oldtag); | |
310 | oldTagTree->GetEntry(0); | |
311 | tag->CopyStandardContent(oldtag); | |
312 | const TClonesArray *evTagList = oldtag->GetEventTags(); | |
313 | ||
314 | AliInfo(Form("Creating the AOD tags.......")); | |
315 | ||
316 | TFile *file = TFile::Open("AliAOD.root"); | |
317 | if (!file || !file->IsOpen()) { | |
318 | AliError(Form("opening failed")); | |
319 | delete file; | |
320 | return ; | |
321 | } | |
322 | TTree *aodTree = (TTree*)file->Get("aodTree"); | |
323 | AliAODEvent *aod = new AliAODEvent(); | |
324 | aod->ReadFromTree(aodTree); | |
325 | ||
326 | Int_t lastEvent = 0; | |
327 | if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries(); | |
328 | else lastEvent = fLastEvent; | |
329 | ||
330 | // loop over events | |
331 | Int_t nEvents = aodTree->GetEntries(); | |
332 | for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { | |
333 | AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber); | |
334 | ntrack = 0; | |
335 | nPos = 0; nNeg = 0; nNeutr =0; | |
336 | nKinks = 0; nV0s = 0; nCascades = 0; | |
337 | nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0; | |
338 | nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0; | |
339 | nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0; | |
340 | nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0; | |
341 | nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0; | |
342 | maxPt = .0; meanPt = .0; totalP = .0; | |
343 | ||
344 | // read events | |
345 | aodTree->GetEvent(iEventNumber); | |
346 | ||
347 | // set pointers | |
348 | aod->GetStdContent(); | |
349 | ||
350 | Int_t nTracks = aod->GetNTracks(); | |
351 | // loop over vertices | |
352 | Int_t nVtxs = aod->GetNVertices(); | |
353 | for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { | |
354 | // print track info | |
355 | AliAODVertex *vertex = aod->GetVertex(nVtx); | |
356 | if(vertex->GetType() == 1) nKinks += 1; | |
357 | if(vertex->GetType() == 2) nV0s += 1; | |
358 | if(vertex->GetType() == 3) nCascades += 1; | |
359 | } | |
360 | for (Int_t nTr = 0; nTr < nTracks; nTr++) { | |
361 | AliAODTrack *track = aod->GetTrack(nTr); | |
362 | ||
363 | Double_t fPt = track->Pt(); | |
364 | if(fPt > maxPt) maxPt = fPt; | |
365 | if(track->Charge() > 0) { | |
366 | nPos++; | |
367 | if(fPt > fLowPtCut) nCh1GeV++; | |
368 | if(fPt > fHighPtCut) nCh3GeV++; | |
369 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
370 | } | |
371 | if(track->Charge() < 0) { | |
372 | nNeg++; | |
373 | if(fPt > fLowPtCut) nCh1GeV++; | |
374 | if(fPt > fHighPtCut) nCh3GeV++; | |
375 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
376 | } | |
377 | if(track->Charge() == 0) nNeutr++; | |
378 | ||
379 | //PID | |
380 | const Double32_t *prob = track->PID(); | |
381 | Double_t rcc = 0.0; | |
382 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i]; | |
383 | if(rcc == 0.0) continue; | |
384 | //Bayes' formula | |
385 | Double_t w[10]; | |
386 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc; | |
387 | ||
388 | //protons | |
389 | if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++; | |
390 | //kaons | |
391 | if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++; | |
392 | //pions | |
393 | if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; | |
394 | //muons | |
395 | if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) { | |
396 | nMuons++; | |
397 | if(fPt > fLowPtCut) nMu1GeV++; | |
398 | if(fPt > fHighPtCut) nMu3GeV++; | |
399 | if(fPt > fVeryHighPtCut) nMu10GeV++; | |
400 | } | |
401 | //electrons | |
402 | if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) { | |
403 | nElectrons++; | |
404 | if(fPt > fLowPtCut) nEl1GeV++; | |
405 | if(fPt > fHighPtCut) nEl3GeV++; | |
406 | if(fPt > fVeryHighPtCut) nEl10GeV++; | |
407 | } | |
408 | ||
409 | totalP += track->P(); | |
410 | meanPt += fPt; | |
411 | ntrack++; | |
412 | }//track loop | |
413 | // Fill the event tags | |
414 | if(ntrack != 0) | |
415 | meanPt = meanPt/ntrack; | |
416 | ||
417 | evTag->SetEventId(iEventNumber+1); | |
418 | ||
419 | evTag->SetNumOfTracks(nTracks); | |
420 | evTag->SetNumOfPosTracks(nPos); | |
421 | evTag->SetNumOfNegTracks(nNeg); | |
422 | evTag->SetNumOfNeutrTracks(nNeutr); | |
423 | ||
424 | evTag->SetNumOfV0s(nV0s); | |
425 | evTag->SetNumOfCascades(nCascades); | |
426 | evTag->SetNumOfKinks(nKinks); | |
427 | ||
428 | evTag->SetNumOfProtons(nProtons); | |
429 | evTag->SetNumOfKaons(nKaons); | |
430 | evTag->SetNumOfPions(nPions); | |
431 | evTag->SetNumOfMuons(nMuons); | |
432 | evTag->SetNumOfElectrons(nElectrons); | |
433 | evTag->SetNumOfPhotons(nGamas); | |
434 | evTag->SetNumOfPi0s(nPi0s); | |
435 | evTag->SetNumOfNeutrons(nNeutrons); | |
436 | evTag->SetNumOfKaon0s(nK0s); | |
437 | ||
438 | evTag->SetNumOfChargedAbove1GeV(nCh1GeV); | |
439 | evTag->SetNumOfChargedAbove3GeV(nCh3GeV); | |
440 | evTag->SetNumOfChargedAbove10GeV(nCh10GeV); | |
441 | evTag->SetNumOfMuonsAbove1GeV(nMu1GeV); | |
442 | evTag->SetNumOfMuonsAbove3GeV(nMu3GeV); | |
443 | evTag->SetNumOfMuonsAbove10GeV(nMu10GeV); | |
444 | evTag->SetNumOfElectronsAbove1GeV(nEl1GeV); | |
445 | evTag->SetNumOfElectronsAbove3GeV(nEl3GeV); | |
446 | evTag->SetNumOfElectronsAbove10GeV(nEl10GeV); | |
447 | ||
448 | evTag->SetTotalMomentum(totalP); | |
449 | evTag->SetMeanPt(meanPt); | |
450 | evTag->SetMaxPt(maxPt); | |
451 | tag->AddEventTag(*evTag); | |
452 | }//event loop | |
453 | if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries(); | |
454 | else lastEvent = fLastEvent; | |
455 | ||
a1069ee1 | 456 | char fileName[256]; |
457 | sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root", | |
458 | tag->GetRunId(),fFirstEvent,lastEvent ); | |
459 | AliInfo(Form("writing tags to file %s", fileName)); | |
460 | AliDebug(1, Form("writing tags to file %s", fileName)); | |
461 | ||
462 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
463 | ftag->cd(); | |
7ee67d2a | 464 | ttag.Fill(); |
465 | tag->Clear(); | |
a1069ee1 | 466 | ttag.Write(); |
467 | ftag->Close(); | |
468 | file->cd(); | |
469 | file->Close(); | |
470 | } | |
471 | ||
103d3fba | 472 | //_____________________________________________________________________________ |
473 | void AliAODTagCreator::CreateTag(TChain* fChain, const char *type) { | |
474 | //private method that creates tag files | |
475 | TString fSession = type; | |
476 | //Int_t iCounter = 0; | |
477 | TString fguid, fmd5, fturl; | |
478 | TString fTempGuid = 0; | |
479 | ||
480 | //private method that creates tag files | |
481 | Float_t fLowPtCut = 1.0; | |
482 | Float_t fHighPtCut = 3.0; | |
483 | Float_t fVeryHighPtCut = 10.0; | |
484 | //////////// | |
485 | Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.}; | |
486 | ||
487 | // Creates the tags for all the events in a given AOD file | |
488 | Int_t ntrack; | |
489 | Int_t nProtons, nKaons, nPions, nMuons, nElectrons; | |
490 | Int_t nPos, nNeg, nNeutr; | |
491 | Int_t nKinks, nV0s, nCascades; | |
492 | Int_t nK0s, nNeutrons, nPi0s, nGamas; | |
493 | Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
494 | Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
495 | Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
496 | Float_t maxPt = .0, meanPt = .0, totalP = .0; | |
497 | ||
498 | AliRunTag *tag = new AliRunTag(); | |
499 | TTree ttag("T","A Tree with event tags"); | |
500 | TBranch * btag = ttag.Branch("AliTAG", &tag); | |
501 | btag->SetCompressionLevel(9); | |
502 | ||
503 | //reading the esd tag file | |
504 | ||
505 | TChain *oldTagTree = new TChain("T"); | |
506 | const char * tagPattern = "ESD.tag"; | |
507 | // Open the working directory | |
508 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
509 | const char * name = 0x0; | |
510 | // Add all files matching *pattern* to the chain | |
511 | while((name = gSystem->GetDirEntry(dirp))) { | |
512 | if (strstr(name,tagPattern)) oldTagTree->Add(name); | |
513 | }//directory loop | |
514 | AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries())); | |
515 | ||
516 | //reading the esd tag file | |
517 | AliRunTag *oldtag = new AliRunTag(); | |
518 | TString tagFilename; | |
519 | oldTagTree->SetBranchAddress("AliTAG",&oldtag); | |
520 | oldTagTree->GetEntry(0); | |
521 | tag->CopyStandardContent(oldtag); | |
522 | const TClonesArray *evTagList = oldtag->GetEventTags(); | |
523 | ||
524 | AliInfo(Form("Creating the AOD tags.......")); | |
525 | ||
526 | /*if (!file || !file->IsOpen()) { | |
527 | AliError(Form("opening failed")); | |
528 | delete file; | |
529 | return ; | |
530 | } | |
531 | TTree *aodTree = (TTree*)file->Get("aodTree");*/ | |
532 | AliAODEvent *aod = new AliAODEvent(); | |
533 | aod->ReadFromTree(fChain); | |
534 | Int_t firstEvent = 0, lastEvent = 0; | |
535 | //lastEvent = (Int_t)aodTree->GetEntries(); | |
536 | ||
537 | // loop over events | |
538 | Int_t nEvents = fChain->GetEntries(); | |
539 | for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { | |
540 | AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber); | |
541 | ntrack = 0; | |
542 | nPos = 0; nNeg = 0; nNeutr =0; | |
543 | nKinks = 0; nV0s = 0; nCascades = 0; | |
544 | nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0; | |
545 | nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0; | |
546 | nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0; | |
547 | nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0; | |
548 | nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0; | |
549 | maxPt = .0; meanPt = .0; totalP = .0; | |
550 | ||
551 | // read events | |
552 | fChain->GetEntry(iEventNumber); | |
553 | TFile *f = fChain->GetFile(); | |
554 | const TUrl *url = f->GetEndpointUrl(); | |
555 | fguid = f->GetUUID().AsString(); | |
556 | if(fSession == "grid") { | |
557 | TString fturltemp = "alien://"; fturltemp += url->GetFile(); | |
558 | fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5); | |
559 | } | |
560 | else fturl = url->GetFile(); | |
561 | ||
562 | // set pointers | |
563 | aod->GetStdContent(); | |
564 | ||
565 | Int_t nTracks = aod->GetNTracks(); | |
566 | // loop over vertices | |
567 | Int_t nVtxs = aod->GetNVertices(); | |
568 | for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { | |
569 | AliAODVertex *vertex = aod->GetVertex(nVtx); | |
570 | if(vertex->GetType() == 1) nKinks += 1; | |
571 | if(vertex->GetType() == 2) nV0s += 1; | |
572 | if(vertex->GetType() == 3) nCascades += 1; | |
573 | } | |
574 | for (Int_t nTr = 0; nTr < nTracks; nTr++) { | |
575 | AliAODTrack *track = aod->GetTrack(nTr); | |
576 | ||
577 | Double_t fPt = track->Pt(); | |
578 | if(fPt > maxPt) maxPt = fPt; | |
579 | if(track->Charge() > 0) { | |
580 | nPos++; | |
581 | if(fPt > fLowPtCut) nCh1GeV++; | |
582 | if(fPt > fHighPtCut) nCh3GeV++; | |
583 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
584 | } | |
585 | if(track->Charge() < 0) { | |
586 | nNeg++; | |
587 | if(fPt > fLowPtCut) nCh1GeV++; | |
588 | if(fPt > fHighPtCut) nCh3GeV++; | |
589 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
590 | } | |
591 | if(track->Charge() == 0) nNeutr++; | |
592 | //PID | |
593 | const Double32_t *prob = track->PID(); | |
594 | Double_t rcc = 0.0; | |
595 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i]; | |
596 | if(rcc == 0.0) continue; | |
597 | //Bayes' formula | |
598 | Double_t w[10]; | |
599 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc; | |
600 | ||
601 | //protons | |
602 | if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++; | |
603 | //kaons | |
604 | if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++; | |
605 | //pions | |
606 | if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; | |
607 | //muons | |
608 | if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) { | |
609 | nMuons++; | |
610 | if(fPt > fLowPtCut) nMu1GeV++; | |
611 | if(fPt > fHighPtCut) nMu3GeV++; | |
612 | if(fPt > fVeryHighPtCut) nMu10GeV++; | |
613 | } | |
614 | //electrons | |
615 | if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) { | |
616 | nElectrons++; | |
617 | if(fPt > fLowPtCut) nEl1GeV++; | |
618 | if(fPt > fHighPtCut) nEl3GeV++; | |
619 | if(fPt > fVeryHighPtCut) nEl10GeV++; | |
620 | } | |
621 | ||
622 | totalP += track->P(); | |
623 | meanPt += fPt; | |
624 | ntrack++; | |
625 | }//track loop | |
626 | // Fill the event tags | |
627 | if(ntrack != 0) | |
628 | meanPt = meanPt/ntrack; | |
629 | ||
630 | evTag->SetEventId(iEventNumber+1); | |
631 | evTag->SetGUID(fguid); | |
632 | if(fSession == "grid") { | |
633 | evTag->SetMD5(0); | |
634 | evTag->SetTURL(fturl); | |
635 | evTag->SetSize(0); | |
636 | } | |
637 | else evTag->SetPath(fturl); | |
638 | ||
639 | evTag->SetNumOfTracks(nTracks); | |
640 | evTag->SetNumOfPosTracks(nPos); | |
641 | evTag->SetNumOfNegTracks(nNeg); | |
642 | evTag->SetNumOfNeutrTracks(nNeutr); | |
643 | ||
644 | evTag->SetNumOfV0s(nV0s); | |
645 | evTag->SetNumOfCascades(nCascades); | |
646 | evTag->SetNumOfKinks(nKinks); | |
647 | ||
648 | evTag->SetNumOfProtons(nProtons); | |
649 | evTag->SetNumOfKaons(nKaons); | |
650 | evTag->SetNumOfPions(nPions); | |
651 | evTag->SetNumOfMuons(nMuons); | |
652 | evTag->SetNumOfElectrons(nElectrons); | |
653 | evTag->SetNumOfPhotons(nGamas); | |
654 | evTag->SetNumOfPi0s(nPi0s); | |
655 | evTag->SetNumOfNeutrons(nNeutrons); | |
656 | evTag->SetNumOfKaon0s(nK0s); | |
657 | ||
658 | evTag->SetNumOfChargedAbove1GeV(nCh1GeV); | |
659 | evTag->SetNumOfChargedAbove3GeV(nCh3GeV); | |
660 | evTag->SetNumOfChargedAbove10GeV(nCh10GeV); | |
661 | evTag->SetNumOfMuonsAbove1GeV(nMu1GeV); | |
662 | evTag->SetNumOfMuonsAbove3GeV(nMu3GeV); | |
663 | evTag->SetNumOfMuonsAbove10GeV(nMu10GeV); | |
664 | evTag->SetNumOfElectronsAbove1GeV(nEl1GeV); | |
665 | evTag->SetNumOfElectronsAbove3GeV(nEl3GeV); | |
666 | evTag->SetNumOfElectronsAbove10GeV(nEl10GeV); | |
667 | ||
668 | evTag->SetTotalMomentum(totalP); | |
669 | evTag->SetMeanPt(meanPt); | |
670 | evTag->SetMaxPt(maxPt); | |
671 | tag->AddEventTag(*evTag); | |
672 | ||
673 | if(fguid != fTempGuid) { | |
674 | fTempGuid = fguid; | |
675 | ttag.Fill(); | |
676 | tag->Clear(""); | |
677 | } | |
678 | }//event loop | |
679 | lastEvent = fChain->GetEntries(); | |
680 | ||
681 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
682 | localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; | |
683 | localFileName += lastEvent; //localFileName += "."; localFileName += Counter; | |
684 | localFileName += ".AOD.tag.root"; | |
685 | ||
686 | TString fileName; | |
687 | ||
688 | if(fStorage == 0) { | |
689 | fileName = localFileName.Data(); | |
690 | AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data())); | |
691 | } | |
692 | else if(fStorage == 1) { | |
693 | TString alienLocation = "/alien"; | |
694 | alienLocation += gGrid->Pwd(); | |
695 | alienLocation += fgridpath.Data(); | |
696 | alienLocation += "/"; | |
697 | alienLocation += localFileName; | |
698 | alienLocation += "?se="; | |
699 | alienLocation += fSE.Data(); | |
700 | fileName = alienLocation.Data(); | |
701 | AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data())); | |
702 | } | |
703 | ||
704 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
705 | ftag->cd(); | |
706 | //ttag.Fill(); | |
707 | tag->Clear(); | |
708 | ttag.Write(); | |
709 | ftag->Close(); | |
710 | } | |
711 | ||
a1069ee1 | 712 | //_____________________________________________________________________________ |
5b8d5d69 | 713 | void AliAODTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) { |
a1069ee1 | 714 | //private method that creates tag files |
715 | TString fguid = guid; | |
716 | TString fmd5 = md5; | |
717 | TString fturl = turl; | |
a1069ee1 | 718 | |
5b8d5d69 | 719 | //private method that creates tag files |
a1069ee1 | 720 | Float_t fLowPtCut = 1.0; |
721 | Float_t fHighPtCut = 3.0; | |
722 | Float_t fVeryHighPtCut = 10.0; | |
5b8d5d69 | 723 | //////////// |
724 | Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.}; | |
a1069ee1 | 725 | |
726 | // Creates the tags for all the events in a given AOD file | |
a1069ee1 | 727 | Int_t ntrack; |
728 | Int_t nProtons, nKaons, nPions, nMuons, nElectrons; | |
729 | Int_t nPos, nNeg, nNeutr; | |
5b8d5d69 | 730 | Int_t nKinks, nV0s, nCascades; |
a1069ee1 | 731 | Int_t nK0s, nNeutrons, nPi0s, nGamas; |
732 | Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
733 | Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
734 | Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
735 | Float_t maxPt = .0, meanPt = .0, totalP = .0; | |
a1069ee1 | 736 | |
737 | AliRunTag *tag = new AliRunTag(); | |
a1069ee1 | 738 | TTree ttag("T","A Tree with event tags"); |
739 | TBranch * btag = ttag.Branch("AliTAG", &tag); | |
740 | btag->SetCompressionLevel(9); | |
741 | ||
5b8d5d69 | 742 | //reading the esd tag file |
743 | ||
744 | TChain *oldTagTree = new TChain("T"); | |
745 | const char * tagPattern = "ESD.tag"; | |
746 | // Open the working directory | |
747 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
748 | const char * name = 0x0; | |
749 | // Add all files matching *pattern* to the chain | |
750 | while((name = gSystem->GetDirEntry(dirp))) { | |
751 | if (strstr(name,tagPattern)) oldTagTree->Add(name); | |
752 | }//directory loop | |
753 | AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries())); | |
a1069ee1 | 754 | |
5b8d5d69 | 755 | //reading the esd tag file |
756 | AliRunTag *oldtag = new AliRunTag(); | |
757 | TString tagFilename; | |
758 | oldTagTree->SetBranchAddress("AliTAG",&oldtag); | |
759 | oldTagTree->GetEntry(0); | |
760 | tag->CopyStandardContent(oldtag); | |
761 | const TClonesArray *evTagList = oldtag->GetEventTags(); | |
a1069ee1 | 762 | |
5b8d5d69 | 763 | AliInfo(Form("Creating the AOD tags.......")); |
764 | ||
765 | if (!file || !file->IsOpen()) { | |
766 | AliError(Form("opening failed")); | |
767 | delete file; | |
768 | return ; | |
769 | } | |
770 | TTree *aodTree = (TTree*)file->Get("aodTree"); | |
771 | AliAODEvent *aod = new AliAODEvent(); | |
772 | aod->ReadFromTree(aodTree); | |
773 | Int_t firstEvent = 0, lastEvent = 0; | |
774 | lastEvent = (Int_t)aodTree->GetEntries(); | |
775 | ||
776 | // loop over events | |
777 | Int_t nEvents = aodTree->GetEntries(); | |
778 | for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { | |
779 | AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber); | |
a1069ee1 | 780 | ntrack = 0; |
5b8d5d69 | 781 | nPos = 0; nNeg = 0; nNeutr =0; |
782 | nKinks = 0; nV0s = 0; nCascades = 0; | |
783 | nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0; | |
784 | nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0; | |
785 | nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0; | |
786 | nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0; | |
787 | nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0; | |
788 | maxPt = .0; meanPt = .0; totalP = .0; | |
789 | ||
790 | // read events | |
791 | aodTree->GetEvent(iEventNumber); | |
792 | // set pointers | |
793 | aod->GetStdContent(); | |
794 | ||
795 | Int_t nTracks = aod->GetNTracks(); | |
796 | // loop over vertices | |
797 | Int_t nVtxs = aod->GetNVertices(); | |
798 | for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { | |
799 | AliAODVertex *vertex = aod->GetVertex(nVtx); | |
800 | if(vertex->GetType() == 1) nKinks += 1; | |
801 | if(vertex->GetType() == 2) nV0s += 1; | |
802 | if(vertex->GetType() == 3) nCascades += 1; | |
803 | } | |
804 | for (Int_t nTr = 0; nTr < nTracks; nTr++) { | |
805 | AliAODTrack *track = aod->GetTrack(nTr); | |
806 | ||
807 | Double_t fPt = track->Pt(); | |
a1069ee1 | 808 | if(fPt > maxPt) maxPt = fPt; |
5b8d5d69 | 809 | if(track->Charge() > 0) { |
a1069ee1 | 810 | nPos++; |
811 | if(fPt > fLowPtCut) nCh1GeV++; | |
812 | if(fPt > fHighPtCut) nCh3GeV++; | |
813 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
814 | } | |
5b8d5d69 | 815 | if(track->Charge() < 0) { |
a1069ee1 | 816 | nNeg++; |
817 | if(fPt > fLowPtCut) nCh1GeV++; | |
818 | if(fPt > fHighPtCut) nCh3GeV++; | |
819 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
820 | } | |
5b8d5d69 | 821 | if(track->Charge() == 0) nNeutr++; |
a1069ee1 | 822 | //PID |
5b8d5d69 | 823 | const Double32_t *prob = track->PID(); |
a1069ee1 | 824 | Double_t rcc = 0.0; |
825 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i]; | |
826 | if(rcc == 0.0) continue; | |
5b8d5d69 | 827 | //Bayes' formula |
828 | Double_t w[10]; | |
a1069ee1 | 829 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc; |
5b8d5d69 | 830 | |
a1069ee1 | 831 | //protons |
832 | if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++; | |
833 | //kaons | |
834 | if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++; | |
835 | //pions | |
5b8d5d69 | 836 | if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; |
837 | //muons | |
838 | if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) { | |
839 | nMuons++; | |
840 | if(fPt > fLowPtCut) nMu1GeV++; | |
841 | if(fPt > fHighPtCut) nMu3GeV++; | |
842 | if(fPt > fVeryHighPtCut) nMu10GeV++; | |
843 | } | |
844 | //electrons | |
a1069ee1 | 845 | if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) { |
846 | nElectrons++; | |
847 | if(fPt > fLowPtCut) nEl1GeV++; | |
848 | if(fPt > fHighPtCut) nEl3GeV++; | |
849 | if(fPt > fVeryHighPtCut) nEl10GeV++; | |
a1069ee1 | 850 | } |
5b8d5d69 | 851 | |
852 | totalP += track->P(); | |
853 | meanPt += fPt; | |
854 | ntrack++; | |
855 | }//track loop | |
856 | // Fill the event tags | |
857 | if(ntrack != 0) | |
858 | meanPt = meanPt/ntrack; | |
a1069ee1 | 859 | |
860 | evTag->SetEventId(iEventNumber+1); | |
861 | evTag->SetGUID(fguid); | |
862 | evTag->SetMD5(fmd5); | |
863 | evTag->SetTURL(fturl); | |
864 | evTag->SetSize(size); | |
5b8d5d69 | 865 | |
866 | evTag->SetNumOfTracks(nTracks); | |
a1069ee1 | 867 | evTag->SetNumOfPosTracks(nPos); |
868 | evTag->SetNumOfNegTracks(nNeg); | |
869 | evTag->SetNumOfNeutrTracks(nNeutr); | |
5b8d5d69 | 870 | |
871 | evTag->SetNumOfV0s(nV0s); | |
872 | evTag->SetNumOfCascades(nCascades); | |
873 | evTag->SetNumOfKinks(nKinks); | |
874 | ||
a1069ee1 | 875 | evTag->SetNumOfProtons(nProtons); |
876 | evTag->SetNumOfKaons(nKaons); | |
877 | evTag->SetNumOfPions(nPions); | |
878 | evTag->SetNumOfMuons(nMuons); | |
879 | evTag->SetNumOfElectrons(nElectrons); | |
880 | evTag->SetNumOfPhotons(nGamas); | |
881 | evTag->SetNumOfPi0s(nPi0s); | |
882 | evTag->SetNumOfNeutrons(nNeutrons); | |
883 | evTag->SetNumOfKaon0s(nK0s); | |
5b8d5d69 | 884 | |
a1069ee1 | 885 | evTag->SetNumOfChargedAbove1GeV(nCh1GeV); |
886 | evTag->SetNumOfChargedAbove3GeV(nCh3GeV); | |
887 | evTag->SetNumOfChargedAbove10GeV(nCh10GeV); | |
888 | evTag->SetNumOfMuonsAbove1GeV(nMu1GeV); | |
889 | evTag->SetNumOfMuonsAbove3GeV(nMu3GeV); | |
890 | evTag->SetNumOfMuonsAbove10GeV(nMu10GeV); | |
891 | evTag->SetNumOfElectronsAbove1GeV(nEl1GeV); | |
892 | evTag->SetNumOfElectronsAbove3GeV(nEl3GeV); | |
893 | evTag->SetNumOfElectronsAbove10GeV(nEl10GeV); | |
5b8d5d69 | 894 | |
a1069ee1 | 895 | evTag->SetTotalMomentum(totalP); |
896 | evTag->SetMeanPt(meanPt); | |
897 | evTag->SetMaxPt(maxPt); | |
a1069ee1 | 898 | tag->AddEventTag(*evTag); |
899 | }//event loop | |
7ee67d2a | 900 | |
5b8d5d69 | 901 | TString localFileName = "Run"; localFileName += tag->GetRunId(); |
902 | localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; | |
903 | localFileName += lastEvent; localFileName += "."; localFileName += Counter; | |
904 | localFileName += ".AOD.tag.root"; | |
a1069ee1 | 905 | |
906 | TString fileName; | |
5b8d5d69 | 907 | |
a1069ee1 | 908 | if(fStorage == 0) { |
5b8d5d69 | 909 | fileName = localFileName.Data(); |
910 | AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data())); | |
a1069ee1 | 911 | } |
912 | else if(fStorage == 1) { | |
913 | TString alienLocation = "/alien"; | |
914 | alienLocation += gGrid->Pwd(); | |
915 | alienLocation += fgridpath.Data(); | |
916 | alienLocation += "/"; | |
917 | alienLocation += localFileName; | |
918 | alienLocation += "?se="; | |
919 | alienLocation += fSE.Data(); | |
920 | fileName = alienLocation.Data(); | |
5b8d5d69 | 921 | AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data())); |
a1069ee1 | 922 | } |
923 | ||
924 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
925 | ftag->cd(); | |
7ee67d2a | 926 | ttag.Fill(); |
927 | tag->Clear(); | |
a1069ee1 | 928 | ttag.Write(); |
929 | ftag->Close(); | |
5b8d5d69 | 930 | } |
931 | ||
a1069ee1 | 932 | |
933 | //_____________________________________________________________________________ | |
5b8d5d69 | 934 | void AliAODTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) { |
a1069ee1 | 935 | //private method that creates tag files |
a1069ee1 | 936 | Float_t fLowPtCut = 1.0; |
937 | Float_t fHighPtCut = 3.0; | |
938 | Float_t fVeryHighPtCut = 10.0; | |
939 | //////////// | |
5b8d5d69 | 940 | |
941 | Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.}; | |
942 | ||
943 | // Creates the tags for all the events in a given AOD file | |
a1069ee1 | 944 | Int_t ntrack; |
945 | Int_t nProtons, nKaons, nPions, nMuons, nElectrons; | |
946 | Int_t nPos, nNeg, nNeutr; | |
5b8d5d69 | 947 | Int_t nKinks, nV0s, nCascades; |
a1069ee1 | 948 | Int_t nK0s, nNeutrons, nPi0s, nGamas; |
949 | Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
950 | Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
951 | Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
952 | Float_t maxPt = .0, meanPt = .0, totalP = .0; | |
a1069ee1 | 953 | |
954 | AliRunTag *tag = new AliRunTag(); | |
a1069ee1 | 955 | TTree ttag("T","A Tree with event tags"); |
956 | TBranch * btag = ttag.Branch("AliTAG", &tag); | |
957 | btag->SetCompressionLevel(9); | |
a1069ee1 | 958 | |
5b8d5d69 | 959 | //reading the esd tag file |
960 | TChain *oldTagTree = new TChain("T"); | |
961 | const char * tagPattern = "ESD.tag"; | |
962 | // Open the working directory | |
963 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
964 | const char * name = 0x0; | |
965 | // Add all files matching *pattern* to the chain | |
966 | while((name = gSystem->GetDirEntry(dirp))) { | |
967 | if (strstr(name,tagPattern)) oldTagTree->Add(name); | |
968 | }//directory loop | |
969 | AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries())); | |
970 | ||
971 | //reading the esd tag file | |
972 | AliRunTag *oldtag = new AliRunTag(); | |
973 | TString tagFilename; | |
974 | oldTagTree->SetBranchAddress("AliTAG",&oldtag); | |
975 | oldTagTree->GetEntry(0); | |
976 | tag->CopyStandardContent(oldtag); | |
977 | const TClonesArray *evTagList = oldtag->GetEventTags(); | |
978 | ||
979 | AliInfo(Form("Creating the AOD tags.......")); | |
980 | ||
981 | if (!file || !file->IsOpen()) { | |
982 | AliError(Form("opening failed")); | |
983 | delete file; | |
984 | return ; | |
985 | } | |
986 | TTree *aodTree = (TTree*)file->Get("aodTree"); | |
987 | AliAODEvent *aod = new AliAODEvent(); | |
988 | aod->ReadFromTree(aodTree); | |
989 | Int_t firstEvent = 0, lastEvent = 0; | |
990 | lastEvent = (Int_t)aodTree->GetEntries(); | |
991 | ||
992 | // loop over events | |
993 | Int_t nEvents = aodTree->GetEntries(); | |
994 | for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) { | |
995 | AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber); | |
a1069ee1 | 996 | ntrack = 0; |
5b8d5d69 | 997 | nPos = 0; nNeg = 0; nNeutr =0; |
998 | nKinks = 0; nV0s = 0; nCascades = 0; | |
999 | nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0; | |
1000 | nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0; | |
1001 | nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0; | |
1002 | nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0; | |
1003 | nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0; | |
1004 | maxPt = .0; meanPt = .0; totalP = .0; | |
1005 | ||
1006 | // read events | |
1007 | aodTree->GetEvent(iEventNumber); | |
a1069ee1 | 1008 | |
5b8d5d69 | 1009 | // set pointers |
1010 | aod->GetStdContent(); | |
1011 | ||
1012 | Int_t nTracks = aod->GetNTracks(); | |
1013 | // loop over vertices | |
1014 | Int_t nVtxs = aod->GetNVertices(); | |
1015 | for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) { | |
1016 | // print track info | |
1017 | AliAODVertex *vertex = aod->GetVertex(nVtx); | |
1018 | if(vertex->GetType() == 1) nKinks += 1; | |
1019 | if(vertex->GetType() == 2) nV0s += 1; | |
1020 | if(vertex->GetType() == 3) nCascades += 1; | |
1021 | } | |
1022 | for (Int_t nTr = 0; nTr < nTracks; nTr++) { | |
1023 | AliAODTrack *track = aod->GetTrack(nTr); | |
a1069ee1 | 1024 | |
5b8d5d69 | 1025 | Double_t fPt = track->Pt(); |
a1069ee1 | 1026 | if(fPt > maxPt) maxPt = fPt; |
5b8d5d69 | 1027 | if(track->Charge() > 0) { |
1028 | nPos++; | |
1029 | if(fPt > fLowPtCut) nCh1GeV++; | |
1030 | if(fPt > fHighPtCut) nCh3GeV++; | |
1031 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
a1069ee1 | 1032 | } |
5b8d5d69 | 1033 | if(track->Charge() < 0) { |
1034 | nNeg++; | |
1035 | if(fPt > fLowPtCut) nCh1GeV++; | |
1036 | if(fPt > fHighPtCut) nCh3GeV++; | |
1037 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
a1069ee1 | 1038 | } |
5b8d5d69 | 1039 | if(track->Charge() == 0) nNeutr++; |
1040 | ||
a1069ee1 | 1041 | //PID |
5b8d5d69 | 1042 | const Double32_t *prob = track->PID(); |
a1069ee1 | 1043 | Double_t rcc = 0.0; |
1044 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i]; | |
1045 | if(rcc == 0.0) continue; | |
1046 | //Bayes' formula | |
5b8d5d69 | 1047 | Double_t w[10]; |
a1069ee1 | 1048 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc; |
1049 | ||
1050 | //protons | |
1051 | if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++; | |
1052 | //kaons | |
1053 | if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++; | |
1054 | //pions | |
1055 | if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; | |
5b8d5d69 | 1056 | //muons |
1057 | if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) { | |
1058 | nMuons++; | |
1059 | if(fPt > fLowPtCut) nMu1GeV++; | |
1060 | if(fPt > fHighPtCut) nMu3GeV++; | |
1061 | if(fPt > fVeryHighPtCut) nMu10GeV++; | |
1062 | } | |
a1069ee1 | 1063 | //electrons |
1064 | if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) { | |
5b8d5d69 | 1065 | nElectrons++; |
1066 | if(fPt > fLowPtCut) nEl1GeV++; | |
1067 | if(fPt > fHighPtCut) nEl3GeV++; | |
1068 | if(fPt > fVeryHighPtCut) nEl10GeV++; | |
a1069ee1 | 1069 | } |
5b8d5d69 | 1070 | |
1071 | totalP += track->P(); | |
1072 | meanPt += fPt; | |
1073 | ntrack++; | |
1074 | }//track loop | |
a1069ee1 | 1075 | // Fill the event tags |
5b8d5d69 | 1076 | if(ntrack != 0) |
1077 | meanPt = meanPt/ntrack; | |
1078 | ||
a1069ee1 | 1079 | evTag->SetEventId(iEventNumber+1); |
1080 | evTag->SetPath(filepath); | |
5b8d5d69 | 1081 | |
1082 | evTag->SetNumOfTracks(nTracks); | |
a1069ee1 | 1083 | evTag->SetNumOfPosTracks(nPos); |
1084 | evTag->SetNumOfNegTracks(nNeg); | |
1085 | evTag->SetNumOfNeutrTracks(nNeutr); | |
1086 | ||
5b8d5d69 | 1087 | evTag->SetNumOfV0s(nV0s); |
1088 | evTag->SetNumOfCascades(nCascades); | |
1089 | evTag->SetNumOfKinks(nKinks); | |
a1069ee1 | 1090 | |
1091 | evTag->SetNumOfProtons(nProtons); | |
1092 | evTag->SetNumOfKaons(nKaons); | |
1093 | evTag->SetNumOfPions(nPions); | |
1094 | evTag->SetNumOfMuons(nMuons); | |
1095 | evTag->SetNumOfElectrons(nElectrons); | |
1096 | evTag->SetNumOfPhotons(nGamas); | |
1097 | evTag->SetNumOfPi0s(nPi0s); | |
1098 | evTag->SetNumOfNeutrons(nNeutrons); | |
1099 | evTag->SetNumOfKaon0s(nK0s); | |
1100 | ||
1101 | evTag->SetNumOfChargedAbove1GeV(nCh1GeV); | |
1102 | evTag->SetNumOfChargedAbove3GeV(nCh3GeV); | |
1103 | evTag->SetNumOfChargedAbove10GeV(nCh10GeV); | |
1104 | evTag->SetNumOfMuonsAbove1GeV(nMu1GeV); | |
1105 | evTag->SetNumOfMuonsAbove3GeV(nMu3GeV); | |
1106 | evTag->SetNumOfMuonsAbove10GeV(nMu10GeV); | |
1107 | evTag->SetNumOfElectronsAbove1GeV(nEl1GeV); | |
1108 | evTag->SetNumOfElectronsAbove3GeV(nEl3GeV); | |
1109 | evTag->SetNumOfElectronsAbove10GeV(nEl10GeV); | |
1110 | ||
a1069ee1 | 1111 | evTag->SetTotalMomentum(totalP); |
1112 | evTag->SetMeanPt(meanPt); | |
1113 | evTag->SetMaxPt(maxPt); | |
a1069ee1 | 1114 | tag->AddEventTag(*evTag); |
5b8d5d69 | 1115 | }//event loop |
1116 | ||
a1069ee1 | 1117 | TString localFileName = "Run"; localFileName += tag->GetRunId(); |
5b8d5d69 | 1118 | localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; |
1119 | localFileName += lastEvent; localFileName += "."; localFileName += Counter; | |
1120 | localFileName += ".AOD.tag.root"; | |
a1069ee1 | 1121 | |
1122 | TString fileName; | |
1123 | ||
1124 | if(fStorage == 0) { | |
1125 | fileName = localFileName.Data(); | |
5b8d5d69 | 1126 | AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data())); |
a1069ee1 | 1127 | } |
1128 | else if(fStorage == 1) { | |
1129 | TString alienLocation = "/alien"; | |
1130 | alienLocation += gGrid->Pwd(); | |
1131 | alienLocation += fgridpath.Data(); | |
1132 | alienLocation += "/"; | |
1133 | alienLocation += localFileName; | |
1134 | alienLocation += "?se="; | |
1135 | alienLocation += fSE.Data(); | |
1136 | fileName = alienLocation.Data(); | |
5b8d5d69 | 1137 | AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data())); |
a1069ee1 | 1138 | } |
1139 | ||
1140 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
1141 | ftag->cd(); | |
7ee67d2a | 1142 | ttag.Fill(); |
1143 | tag->Clear(); | |
a1069ee1 | 1144 | ttag.Write(); |
1145 | ftag->Close(); | |
5b8d5d69 | 1146 | } |
a1069ee1 | 1147 |