]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODTagCreator.cxx
Modifications in AliESDMuonTrack:
[u/mrichter/AliRoot.git] / STEER / AliAODTagCreator.cxx
CommitLineData
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
46ClassImp(AliAODTagCreator)
47
48
49//______________________________________________________________________________
50 AliAODTagCreator::AliAODTagCreator() :
51 AliTagCreator() {
52 //==============Default constructor for a AliAODTagCreator================
53}
54
55//______________________________________________________________________________
56AliAODTagCreator::~AliAODTagCreator() {
57//================Default destructor for a AliAODTagCreator===================
58}
59
60//______________________________________________________________________________
61Bool_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");
7ee67d2a 82 CreateTag(f,guid,md5,turl,size,counter);
a1069ee1 83 f->Close();
84 delete f;
85 counter += 1;
86 }//grid result loop
87
88 return kTRUE;
89}
90
91//______________________________________________________________________________
92Bool_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//______________________________________________________________________________
126Bool_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");
7ee67d2a 141 CreateTag(f,esdfile,counter);
a1069ee1 142 f->Close();
143 delete f;
144
145 counter += 1;
146 }
147
148 return kTRUE;
149}
150
151//__________________________________________________________________________
152void 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
a1069ee1 340 char fileName[256];
341 sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root",
342 tag->GetRunId(),fFirstEvent,lastEvent );
343 AliInfo(Form("writing tags to file %s", fileName));
344 AliDebug(1, Form("writing tags to file %s", fileName));
345
346 TFile* ftag = TFile::Open(fileName, "recreate");
347 ftag->cd();
7ee67d2a 348 ttag.Fill();
349 tag->Clear();
a1069ee1 350 ttag.Write();
351 ftag->Close();
352 file->cd();
353 file->Close();
354}
355
356//_____________________________________________________________________________
5b8d5d69 357void AliAODTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) {
a1069ee1 358 //private method that creates tag files
359 TString fguid = guid;
360 TString fmd5 = md5;
361 TString fturl = turl;
a1069ee1 362
5b8d5d69 363 //private method that creates tag files
a1069ee1 364 Float_t fLowPtCut = 1.0;
365 Float_t fHighPtCut = 3.0;
366 Float_t fVeryHighPtCut = 10.0;
5b8d5d69 367 ////////////
368 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
a1069ee1 369
370 // Creates the tags for all the events in a given AOD file
a1069ee1 371 Int_t ntrack;
372 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
373 Int_t nPos, nNeg, nNeutr;
5b8d5d69 374 Int_t nKinks, nV0s, nCascades;
a1069ee1 375 Int_t nK0s, nNeutrons, nPi0s, nGamas;
376 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
377 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
378 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
379 Float_t maxPt = .0, meanPt = .0, totalP = .0;
a1069ee1 380
381 AliRunTag *tag = new AliRunTag();
a1069ee1 382 TTree ttag("T","A Tree with event tags");
383 TBranch * btag = ttag.Branch("AliTAG", &tag);
384 btag->SetCompressionLevel(9);
385
5b8d5d69 386 //reading the esd tag file
387
388 TChain *oldTagTree = new TChain("T");
389 const char * tagPattern = "ESD.tag";
390 // Open the working directory
391 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
392 const char * name = 0x0;
393 // Add all files matching *pattern* to the chain
394 while((name = gSystem->GetDirEntry(dirp))) {
395 if (strstr(name,tagPattern)) oldTagTree->Add(name);
396 }//directory loop
397 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
a1069ee1 398
5b8d5d69 399 //reading the esd tag file
400 AliRunTag *oldtag = new AliRunTag();
401 TString tagFilename;
402 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
403 oldTagTree->GetEntry(0);
404 tag->CopyStandardContent(oldtag);
405 const TClonesArray *evTagList = oldtag->GetEventTags();
a1069ee1 406
5b8d5d69 407 AliInfo(Form("Creating the AOD tags......."));
408
409 if (!file || !file->IsOpen()) {
410 AliError(Form("opening failed"));
411 delete file;
412 return ;
413 }
414 TTree *aodTree = (TTree*)file->Get("aodTree");
415 AliAODEvent *aod = new AliAODEvent();
416 aod->ReadFromTree(aodTree);
417 Int_t firstEvent = 0, lastEvent = 0;
418 lastEvent = (Int_t)aodTree->GetEntries();
419
420 // loop over events
421 Int_t nEvents = aodTree->GetEntries();
422 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
423 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
a1069ee1 424 ntrack = 0;
5b8d5d69 425 nPos = 0; nNeg = 0; nNeutr =0;
426 nKinks = 0; nV0s = 0; nCascades = 0;
427 nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0;
428 nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0;
429 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
430 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
431 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
432 maxPt = .0; meanPt = .0; totalP = .0;
433
434 // read events
435 aodTree->GetEvent(iEventNumber);
436 // set pointers
437 aod->GetStdContent();
438
439 Int_t nTracks = aod->GetNTracks();
440 // loop over vertices
441 Int_t nVtxs = aod->GetNVertices();
442 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
443 AliAODVertex *vertex = aod->GetVertex(nVtx);
444 if(vertex->GetType() == 1) nKinks += 1;
445 if(vertex->GetType() == 2) nV0s += 1;
446 if(vertex->GetType() == 3) nCascades += 1;
447 }
448 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
449 AliAODTrack *track = aod->GetTrack(nTr);
450
451 Double_t fPt = track->Pt();
a1069ee1 452 if(fPt > maxPt) maxPt = fPt;
5b8d5d69 453 if(track->Charge() > 0) {
a1069ee1 454 nPos++;
455 if(fPt > fLowPtCut) nCh1GeV++;
456 if(fPt > fHighPtCut) nCh3GeV++;
457 if(fPt > fVeryHighPtCut) nCh10GeV++;
458 }
5b8d5d69 459 if(track->Charge() < 0) {
a1069ee1 460 nNeg++;
461 if(fPt > fLowPtCut) nCh1GeV++;
462 if(fPt > fHighPtCut) nCh3GeV++;
463 if(fPt > fVeryHighPtCut) nCh10GeV++;
464 }
5b8d5d69 465 if(track->Charge() == 0) nNeutr++;
a1069ee1 466 //PID
5b8d5d69 467 const Double32_t *prob = track->PID();
a1069ee1 468 Double_t rcc = 0.0;
469 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
470 if(rcc == 0.0) continue;
5b8d5d69 471 //Bayes' formula
472 Double_t w[10];
a1069ee1 473 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
5b8d5d69 474
a1069ee1 475 //protons
476 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
477 //kaons
478 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
479 //pions
5b8d5d69 480 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
481 //muons
482 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
483 nMuons++;
484 if(fPt > fLowPtCut) nMu1GeV++;
485 if(fPt > fHighPtCut) nMu3GeV++;
486 if(fPt > fVeryHighPtCut) nMu10GeV++;
487 }
488 //electrons
a1069ee1 489 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
490 nElectrons++;
491 if(fPt > fLowPtCut) nEl1GeV++;
492 if(fPt > fHighPtCut) nEl3GeV++;
493 if(fPt > fVeryHighPtCut) nEl10GeV++;
a1069ee1 494 }
5b8d5d69 495
496 totalP += track->P();
497 meanPt += fPt;
498 ntrack++;
499 }//track loop
500 // Fill the event tags
501 if(ntrack != 0)
502 meanPt = meanPt/ntrack;
a1069ee1 503
504 evTag->SetEventId(iEventNumber+1);
505 evTag->SetGUID(fguid);
506 evTag->SetMD5(fmd5);
507 evTag->SetTURL(fturl);
508 evTag->SetSize(size);
5b8d5d69 509
510 evTag->SetNumOfTracks(nTracks);
a1069ee1 511 evTag->SetNumOfPosTracks(nPos);
512 evTag->SetNumOfNegTracks(nNeg);
513 evTag->SetNumOfNeutrTracks(nNeutr);
5b8d5d69 514
515 evTag->SetNumOfV0s(nV0s);
516 evTag->SetNumOfCascades(nCascades);
517 evTag->SetNumOfKinks(nKinks);
518
a1069ee1 519 evTag->SetNumOfProtons(nProtons);
520 evTag->SetNumOfKaons(nKaons);
521 evTag->SetNumOfPions(nPions);
522 evTag->SetNumOfMuons(nMuons);
523 evTag->SetNumOfElectrons(nElectrons);
524 evTag->SetNumOfPhotons(nGamas);
525 evTag->SetNumOfPi0s(nPi0s);
526 evTag->SetNumOfNeutrons(nNeutrons);
527 evTag->SetNumOfKaon0s(nK0s);
5b8d5d69 528
a1069ee1 529 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
530 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
531 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
532 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
533 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
534 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
535 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
536 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
537 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
5b8d5d69 538
a1069ee1 539 evTag->SetTotalMomentum(totalP);
540 evTag->SetMeanPt(meanPt);
541 evTag->SetMaxPt(maxPt);
a1069ee1 542 tag->AddEventTag(*evTag);
543 }//event loop
7ee67d2a 544
5b8d5d69 545 TString localFileName = "Run"; localFileName += tag->GetRunId();
546 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_";
547 localFileName += lastEvent; localFileName += "."; localFileName += Counter;
548 localFileName += ".AOD.tag.root";
a1069ee1 549
550 TString fileName;
5b8d5d69 551
a1069ee1 552 if(fStorage == 0) {
5b8d5d69 553 fileName = localFileName.Data();
554 AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data()));
a1069ee1 555 }
556 else if(fStorage == 1) {
557 TString alienLocation = "/alien";
558 alienLocation += gGrid->Pwd();
559 alienLocation += fgridpath.Data();
560 alienLocation += "/";
561 alienLocation += localFileName;
562 alienLocation += "?se=";
563 alienLocation += fSE.Data();
564 fileName = alienLocation.Data();
5b8d5d69 565 AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data()));
a1069ee1 566 }
567
568 TFile* ftag = TFile::Open(fileName, "recreate");
569 ftag->cd();
7ee67d2a 570 ttag.Fill();
571 tag->Clear();
a1069ee1 572 ttag.Write();
573 ftag->Close();
5b8d5d69 574}
575
a1069ee1 576
577//_____________________________________________________________________________
5b8d5d69 578void AliAODTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) {
a1069ee1 579 //private method that creates tag files
a1069ee1 580 Float_t fLowPtCut = 1.0;
581 Float_t fHighPtCut = 3.0;
582 Float_t fVeryHighPtCut = 10.0;
583 ////////////
5b8d5d69 584
585 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
586
587 // Creates the tags for all the events in a given AOD file
a1069ee1 588 Int_t ntrack;
589 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
590 Int_t nPos, nNeg, nNeutr;
5b8d5d69 591 Int_t nKinks, nV0s, nCascades;
a1069ee1 592 Int_t nK0s, nNeutrons, nPi0s, nGamas;
593 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
594 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
595 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
596 Float_t maxPt = .0, meanPt = .0, totalP = .0;
a1069ee1 597
598 AliRunTag *tag = new AliRunTag();
a1069ee1 599 TTree ttag("T","A Tree with event tags");
600 TBranch * btag = ttag.Branch("AliTAG", &tag);
601 btag->SetCompressionLevel(9);
a1069ee1 602
5b8d5d69 603 //reading the esd tag file
604 TChain *oldTagTree = new TChain("T");
605 const char * tagPattern = "ESD.tag";
606 // Open the working directory
607 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
608 const char * name = 0x0;
609 // Add all files matching *pattern* to the chain
610 while((name = gSystem->GetDirEntry(dirp))) {
611 if (strstr(name,tagPattern)) oldTagTree->Add(name);
612 }//directory loop
613 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
614
615 //reading the esd tag file
616 AliRunTag *oldtag = new AliRunTag();
617 TString tagFilename;
618 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
619 oldTagTree->GetEntry(0);
620 tag->CopyStandardContent(oldtag);
621 const TClonesArray *evTagList = oldtag->GetEventTags();
622
623 AliInfo(Form("Creating the AOD tags......."));
624
625 if (!file || !file->IsOpen()) {
626 AliError(Form("opening failed"));
627 delete file;
628 return ;
629 }
630 TTree *aodTree = (TTree*)file->Get("aodTree");
631 AliAODEvent *aod = new AliAODEvent();
632 aod->ReadFromTree(aodTree);
633 Int_t firstEvent = 0, lastEvent = 0;
634 lastEvent = (Int_t)aodTree->GetEntries();
635
636 // loop over events
637 Int_t nEvents = aodTree->GetEntries();
638 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
639 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
a1069ee1 640 ntrack = 0;
5b8d5d69 641 nPos = 0; nNeg = 0; nNeutr =0;
642 nKinks = 0; nV0s = 0; nCascades = 0;
643 nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0;
644 nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0;
645 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
646 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
647 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
648 maxPt = .0; meanPt = .0; totalP = .0;
649
650 // read events
651 aodTree->GetEvent(iEventNumber);
a1069ee1 652
5b8d5d69 653 // set pointers
654 aod->GetStdContent();
655
656 Int_t nTracks = aod->GetNTracks();
657 // loop over vertices
658 Int_t nVtxs = aod->GetNVertices();
659 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
660 // print track info
661 AliAODVertex *vertex = aod->GetVertex(nVtx);
662 if(vertex->GetType() == 1) nKinks += 1;
663 if(vertex->GetType() == 2) nV0s += 1;
664 if(vertex->GetType() == 3) nCascades += 1;
665 }
666 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
667 AliAODTrack *track = aod->GetTrack(nTr);
a1069ee1 668
5b8d5d69 669 Double_t fPt = track->Pt();
a1069ee1 670 if(fPt > maxPt) maxPt = fPt;
5b8d5d69 671 if(track->Charge() > 0) {
672 nPos++;
673 if(fPt > fLowPtCut) nCh1GeV++;
674 if(fPt > fHighPtCut) nCh3GeV++;
675 if(fPt > fVeryHighPtCut) nCh10GeV++;
a1069ee1 676 }
5b8d5d69 677 if(track->Charge() < 0) {
678 nNeg++;
679 if(fPt > fLowPtCut) nCh1GeV++;
680 if(fPt > fHighPtCut) nCh3GeV++;
681 if(fPt > fVeryHighPtCut) nCh10GeV++;
a1069ee1 682 }
5b8d5d69 683 if(track->Charge() == 0) nNeutr++;
684
a1069ee1 685 //PID
5b8d5d69 686 const Double32_t *prob = track->PID();
a1069ee1 687 Double_t rcc = 0.0;
688 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
689 if(rcc == 0.0) continue;
690 //Bayes' formula
5b8d5d69 691 Double_t w[10];
a1069ee1 692 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
693
694 //protons
695 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
696 //kaons
697 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
698 //pions
699 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
5b8d5d69 700 //muons
701 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
702 nMuons++;
703 if(fPt > fLowPtCut) nMu1GeV++;
704 if(fPt > fHighPtCut) nMu3GeV++;
705 if(fPt > fVeryHighPtCut) nMu10GeV++;
706 }
a1069ee1 707 //electrons
708 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
5b8d5d69 709 nElectrons++;
710 if(fPt > fLowPtCut) nEl1GeV++;
711 if(fPt > fHighPtCut) nEl3GeV++;
712 if(fPt > fVeryHighPtCut) nEl10GeV++;
a1069ee1 713 }
5b8d5d69 714
715 totalP += track->P();
716 meanPt += fPt;
717 ntrack++;
718 }//track loop
a1069ee1 719 // Fill the event tags
5b8d5d69 720 if(ntrack != 0)
721 meanPt = meanPt/ntrack;
722
a1069ee1 723 evTag->SetEventId(iEventNumber+1);
724 evTag->SetPath(filepath);
5b8d5d69 725
726 evTag->SetNumOfTracks(nTracks);
a1069ee1 727 evTag->SetNumOfPosTracks(nPos);
728 evTag->SetNumOfNegTracks(nNeg);
729 evTag->SetNumOfNeutrTracks(nNeutr);
730
5b8d5d69 731 evTag->SetNumOfV0s(nV0s);
732 evTag->SetNumOfCascades(nCascades);
733 evTag->SetNumOfKinks(nKinks);
a1069ee1 734
735 evTag->SetNumOfProtons(nProtons);
736 evTag->SetNumOfKaons(nKaons);
737 evTag->SetNumOfPions(nPions);
738 evTag->SetNumOfMuons(nMuons);
739 evTag->SetNumOfElectrons(nElectrons);
740 evTag->SetNumOfPhotons(nGamas);
741 evTag->SetNumOfPi0s(nPi0s);
742 evTag->SetNumOfNeutrons(nNeutrons);
743 evTag->SetNumOfKaon0s(nK0s);
744
745 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
746 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
747 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
748 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
749 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
750 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
751 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
752 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
753 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
754
a1069ee1 755 evTag->SetTotalMomentum(totalP);
756 evTag->SetMeanPt(meanPt);
757 evTag->SetMaxPt(maxPt);
a1069ee1 758 tag->AddEventTag(*evTag);
5b8d5d69 759 }//event loop
760
a1069ee1 761 TString localFileName = "Run"; localFileName += tag->GetRunId();
5b8d5d69 762 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_";
763 localFileName += lastEvent; localFileName += "."; localFileName += Counter;
764 localFileName += ".AOD.tag.root";
a1069ee1 765
766 TString fileName;
767
768 if(fStorage == 0) {
769 fileName = localFileName.Data();
5b8d5d69 770 AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data()));
a1069ee1 771 }
772 else if(fStorage == 1) {
773 TString alienLocation = "/alien";
774 alienLocation += gGrid->Pwd();
775 alienLocation += fgridpath.Data();
776 alienLocation += "/";
777 alienLocation += localFileName;
778 alienLocation += "?se=";
779 alienLocation += fSE.Data();
780 fileName = alienLocation.Data();
5b8d5d69 781 AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data()));
a1069ee1 782 }
783
784 TFile* ftag = TFile::Open(fileName, "recreate");
785 ftag->cd();
7ee67d2a 786 ttag.Fill();
787 tag->Clear();
a1069ee1 788 ttag.Write();
789 ftag->Close();
5b8d5d69 790}
a1069ee1 791