1 /**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //-----------------------------------------------------------------
23 #include <Riostream.h>
29 #include <TLorentzVector.h>
33 #include <TGridResult.h>
36 #include "AliRunTag.h"
37 #include "AliEventTag.h"
39 #include "AliAODEvent.h"
40 #include "AliAODVertex.h"
43 #include "AliAODTagCreator.h"
46 ClassImp(AliAODTagCreator)
49 //______________________________________________________________________________
50 AliAODTagCreator::AliAODTagCreator() :
51 AliTagCreator(), fChain(new TChain("aodTree")) {
52 //==============Default constructor for a AliAODTagCreator================
55 //______________________________________________________________________________
56 AliAODTagCreator::~AliAODTagCreator() {
57 //================Default destructor for a AliAODTagCreator===================
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();
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;
82 fChain->Add(alienUrl);
83 //fGUIDList->Add(new TObjString(guid));
84 //fMD5List->Add(new TObjString(md5));
85 //fTURLList->Add(new TObjString(turl));
87 //TFile *f = TFile::Open(alienUrl,"READ");
88 //CreateTag(f,guid,md5,turl,size,counter);
94 AliInfo(Form("AOD chain created......."));
95 AliInfo(Form("Chain entries: %d",fChain->GetEntries()));
96 CreateTag(fChain,"grid");
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();
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;
122 TFile *f = TFile::Open(alienUrl,"READ");
123 CreateTag(f,guid,md5,turl,size,counter);
132 //______________________________________________________________________________
133 Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) {
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
137 void *dira = gSystem->OpenDirectory(localpath);
139 const char * dirname = 0x0;
140 const char * filename = 0x0;
141 const char * pattern = "AliAODs.root";
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;
152 fESDFileName += pattern;
154 fChain->Add(fESDFileName);
156 //TFile *f = TFile::Open(fESDFileName,"READ");
157 //CreateTag(f,fESDFileName,counter);
163 }//child directory's entry loop
164 }//parent directory's entry loop
166 AliInfo(Form("AOD chain created......."));
167 AliInfo(Form("Chain entries: %d",fChain->GetEntries()));
168 CreateTag(fChain,"local");
173 //______________________________________________________________________________
174 /*Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) {
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
178 void *dira = gSystem->OpenDirectory(localpath);
180 const char * dirname = 0x0;
181 const char * filename = 0x0;
182 const char * pattern = "AliAOD.root";
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;
193 fAODFileName += pattern;
194 TFile *f = TFile::Open(fAODFileName,"READ");
195 CreateTag(f,fAODFileName,counter);
201 }//child directory's entry loop
202 }//parent directory's entry loop
208 //______________________________________________________________________________
209 Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) {
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.
213 // Open the input stream
219 // Read the input list of files and add them to the chain
222 if (!esdfile.Contains("root")) continue; // protection
224 fChain->Add(esdfile);
226 //TFile *f = TFile::Open(esdfile,"READ");
227 //CreateTag(f,esdfile,counter);
234 AliInfo(Form("AOD chain created......."));
235 AliInfo(Form("Chain entries: %d",fChain->GetEntries()));
236 CreateTag(fChain,"proof");
241 //______________________________________________________________________________
242 /*Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) {
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.
246 // Open the input stream
252 // Read the input list of files and add them to the chain
255 if (!esdfile.Contains("root")) continue; // protection
256 TFile *f = TFile::Open(esdfile,"READ");
257 CreateTag(f,esdfile,counter);
267 //__________________________________________________________________________
268 void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent) {
269 //creates tag files for AODs
271 Float_t fLowPtCut = 1.0;
272 Float_t fHighPtCut = 3.0;
273 Float_t fVeryHighPtCut = 10.0;
276 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
278 // Creates the tags for all the events in a given AOD file
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;
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);
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);
304 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
306 //reading the esd tag file
307 AliRunTag *oldtag = new AliRunTag();
309 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
310 oldTagTree->GetEntry(0);
311 tag->CopyStandardContent(oldtag);
312 const TClonesArray *evTagList = oldtag->GetEventTags();
314 AliInfo(Form("Creating the AOD tags......."));
316 TFile *file = TFile::Open("AliAOD.root");
317 if (!file || !file->IsOpen()) {
318 AliError(Form("opening failed"));
322 TTree *aodTree = (TTree*)file->Get("aodTree");
323 AliAODEvent *aod = new AliAODEvent();
324 aod->ReadFromTree(aodTree);
327 if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries();
328 else lastEvent = fLastEvent;
331 Int_t nEvents = aodTree->GetEntries();
332 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
333 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
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;
345 aodTree->GetEvent(iEventNumber);
348 aod->GetStdContent();
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++) {
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;
360 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
361 AliAODTrack *track = aod->GetTrack(nTr);
363 Double_t fPt = track->Pt();
364 if(fPt > maxPt) maxPt = fPt;
365 if(track->Charge() > 0) {
367 if(fPt > fLowPtCut) nCh1GeV++;
368 if(fPt > fHighPtCut) nCh3GeV++;
369 if(fPt > fVeryHighPtCut) nCh10GeV++;
371 if(track->Charge() < 0) {
373 if(fPt > fLowPtCut) nCh1GeV++;
374 if(fPt > fHighPtCut) nCh3GeV++;
375 if(fPt > fVeryHighPtCut) nCh10GeV++;
377 if(track->Charge() == 0) nNeutr++;
380 const Double32_t *prob = track->PID();
382 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
383 if(rcc == 0.0) continue;
386 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
389 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
391 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
393 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
395 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
397 if(fPt > fLowPtCut) nMu1GeV++;
398 if(fPt > fHighPtCut) nMu3GeV++;
399 if(fPt > fVeryHighPtCut) nMu10GeV++;
402 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
404 if(fPt > fLowPtCut) nEl1GeV++;
405 if(fPt > fHighPtCut) nEl3GeV++;
406 if(fPt > fVeryHighPtCut) nEl10GeV++;
409 totalP += track->P();
413 // Fill the event tags
415 meanPt = meanPt/ntrack;
417 evTag->SetEventId(iEventNumber+1);
419 evTag->SetNumOfTracks(nTracks);
420 evTag->SetNumOfPosTracks(nPos);
421 evTag->SetNumOfNegTracks(nNeg);
422 evTag->SetNumOfNeutrTracks(nNeutr);
424 evTag->SetNumOfV0s(nV0s);
425 evTag->SetNumOfCascades(nCascades);
426 evTag->SetNumOfKinks(nKinks);
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);
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);
448 evTag->SetTotalMomentum(totalP);
449 evTag->SetMeanPt(meanPt);
450 evTag->SetMaxPt(maxPt);
451 tag->AddEventTag(*evTag);
453 if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries();
454 else lastEvent = fLastEvent;
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));
462 TFile* ftag = TFile::Open(fileName, "recreate");
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;
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;
485 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
487 // Creates the tags for all the events in a given AOD file
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;
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);
503 //reading the esd tag file
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);
514 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
516 //reading the esd tag file
517 AliRunTag *oldtag = new AliRunTag();
519 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
520 oldTagTree->GetEntry(0);
521 tag->CopyStandardContent(oldtag);
522 const TClonesArray *evTagList = oldtag->GetEventTags();
524 AliInfo(Form("Creating the AOD tags......."));
526 /*if (!file || !file->IsOpen()) {
527 AliError(Form("opening failed"));
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();
538 Int_t nEvents = fChain->GetEntries();
539 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
540 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
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;
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);
560 else fturl = url->GetFile();
563 aod->GetStdContent();
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;
574 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
575 AliAODTrack *track = aod->GetTrack(nTr);
577 Double_t fPt = track->Pt();
578 if(fPt > maxPt) maxPt = fPt;
579 if(track->Charge() > 0) {
581 if(fPt > fLowPtCut) nCh1GeV++;
582 if(fPt > fHighPtCut) nCh3GeV++;
583 if(fPt > fVeryHighPtCut) nCh10GeV++;
585 if(track->Charge() < 0) {
587 if(fPt > fLowPtCut) nCh1GeV++;
588 if(fPt > fHighPtCut) nCh3GeV++;
589 if(fPt > fVeryHighPtCut) nCh10GeV++;
591 if(track->Charge() == 0) nNeutr++;
593 const Double32_t *prob = track->PID();
595 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
596 if(rcc == 0.0) continue;
599 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
602 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
604 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
606 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
608 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
610 if(fPt > fLowPtCut) nMu1GeV++;
611 if(fPt > fHighPtCut) nMu3GeV++;
612 if(fPt > fVeryHighPtCut) nMu10GeV++;
615 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
617 if(fPt > fLowPtCut) nEl1GeV++;
618 if(fPt > fHighPtCut) nEl3GeV++;
619 if(fPt > fVeryHighPtCut) nEl10GeV++;
622 totalP += track->P();
626 // Fill the event tags
628 meanPt = meanPt/ntrack;
630 evTag->SetEventId(iEventNumber+1);
631 evTag->SetGUID(fguid);
632 if(fSession == "grid") {
634 evTag->SetTURL(fturl);
637 else evTag->SetPath(fturl);
639 evTag->SetNumOfTracks(nTracks);
640 evTag->SetNumOfPosTracks(nPos);
641 evTag->SetNumOfNegTracks(nNeg);
642 evTag->SetNumOfNeutrTracks(nNeutr);
644 evTag->SetNumOfV0s(nV0s);
645 evTag->SetNumOfCascades(nCascades);
646 evTag->SetNumOfKinks(nKinks);
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);
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);
668 evTag->SetTotalMomentum(totalP);
669 evTag->SetMeanPt(meanPt);
670 evTag->SetMaxPt(maxPt);
671 tag->AddEventTag(*evTag);
673 if(fguid != fTempGuid) {
679 lastEvent = fChain->GetEntries();
681 TString localFileName = "Run"; localFileName += tag->GetRunId();
682 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_";
683 localFileName += lastEvent; //localFileName += "."; localFileName += Counter;
684 localFileName += ".AOD.tag.root";
689 fileName = localFileName.Data();
690 AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data()));
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()));
704 TFile* ftag = TFile::Open(fileName, "recreate");
712 //_____________________________________________________________________________
713 void AliAODTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) {
714 //private method that creates tag files
715 TString fguid = guid;
717 TString fturl = turl;
719 //private method that creates tag files
720 Float_t fLowPtCut = 1.0;
721 Float_t fHighPtCut = 3.0;
722 Float_t fVeryHighPtCut = 10.0;
724 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
726 // Creates the tags for all the events in a given AOD file
728 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
729 Int_t nPos, nNeg, nNeutr;
730 Int_t nKinks, nV0s, nCascades;
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;
737 AliRunTag *tag = new AliRunTag();
738 TTree ttag("T","A Tree with event tags");
739 TBranch * btag = ttag.Branch("AliTAG", &tag);
740 btag->SetCompressionLevel(9);
742 //reading the esd tag file
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);
753 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
755 //reading the esd tag file
756 AliRunTag *oldtag = new AliRunTag();
758 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
759 oldTagTree->GetEntry(0);
760 tag->CopyStandardContent(oldtag);
761 const TClonesArray *evTagList = oldtag->GetEventTags();
763 AliInfo(Form("Creating the AOD tags......."));
765 if (!file || !file->IsOpen()) {
766 AliError(Form("opening failed"));
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();
777 Int_t nEvents = aodTree->GetEntries();
778 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
779 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
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;
791 aodTree->GetEvent(iEventNumber);
793 aod->GetStdContent();
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;
804 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
805 AliAODTrack *track = aod->GetTrack(nTr);
807 Double_t fPt = track->Pt();
808 if(fPt > maxPt) maxPt = fPt;
809 if(track->Charge() > 0) {
811 if(fPt > fLowPtCut) nCh1GeV++;
812 if(fPt > fHighPtCut) nCh3GeV++;
813 if(fPt > fVeryHighPtCut) nCh10GeV++;
815 if(track->Charge() < 0) {
817 if(fPt > fLowPtCut) nCh1GeV++;
818 if(fPt > fHighPtCut) nCh3GeV++;
819 if(fPt > fVeryHighPtCut) nCh10GeV++;
821 if(track->Charge() == 0) nNeutr++;
823 const Double32_t *prob = track->PID();
825 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
826 if(rcc == 0.0) continue;
829 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
832 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
834 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
836 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
838 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
840 if(fPt > fLowPtCut) nMu1GeV++;
841 if(fPt > fHighPtCut) nMu3GeV++;
842 if(fPt > fVeryHighPtCut) nMu10GeV++;
845 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
847 if(fPt > fLowPtCut) nEl1GeV++;
848 if(fPt > fHighPtCut) nEl3GeV++;
849 if(fPt > fVeryHighPtCut) nEl10GeV++;
852 totalP += track->P();
856 // Fill the event tags
858 meanPt = meanPt/ntrack;
860 evTag->SetEventId(iEventNumber+1);
861 evTag->SetGUID(fguid);
863 evTag->SetTURL(fturl);
864 evTag->SetSize(size);
866 evTag->SetNumOfTracks(nTracks);
867 evTag->SetNumOfPosTracks(nPos);
868 evTag->SetNumOfNegTracks(nNeg);
869 evTag->SetNumOfNeutrTracks(nNeutr);
871 evTag->SetNumOfV0s(nV0s);
872 evTag->SetNumOfCascades(nCascades);
873 evTag->SetNumOfKinks(nKinks);
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);
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);
895 evTag->SetTotalMomentum(totalP);
896 evTag->SetMeanPt(meanPt);
897 evTag->SetMaxPt(maxPt);
898 tag->AddEventTag(*evTag);
901 TString localFileName = "Run"; localFileName += tag->GetRunId();
902 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_";
903 localFileName += lastEvent; localFileName += "."; localFileName += Counter;
904 localFileName += ".AOD.tag.root";
909 fileName = localFileName.Data();
910 AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data()));
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();
921 AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data()));
924 TFile* ftag = TFile::Open(fileName, "recreate");
933 //_____________________________________________________________________________
934 void AliAODTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) {
935 //private method that creates tag files
936 Float_t fLowPtCut = 1.0;
937 Float_t fHighPtCut = 3.0;
938 Float_t fVeryHighPtCut = 10.0;
941 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
943 // Creates the tags for all the events in a given AOD file
945 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
946 Int_t nPos, nNeg, nNeutr;
947 Int_t nKinks, nV0s, nCascades;
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;
954 AliRunTag *tag = new AliRunTag();
955 TTree ttag("T","A Tree with event tags");
956 TBranch * btag = ttag.Branch("AliTAG", &tag);
957 btag->SetCompressionLevel(9);
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);
969 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
971 //reading the esd tag file
972 AliRunTag *oldtag = new AliRunTag();
974 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
975 oldTagTree->GetEntry(0);
976 tag->CopyStandardContent(oldtag);
977 const TClonesArray *evTagList = oldtag->GetEventTags();
979 AliInfo(Form("Creating the AOD tags......."));
981 if (!file || !file->IsOpen()) {
982 AliError(Form("opening failed"));
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();
993 Int_t nEvents = aodTree->GetEntries();
994 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
995 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
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;
1007 aodTree->GetEvent(iEventNumber);
1010 aod->GetStdContent();
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++) {
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;
1022 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
1023 AliAODTrack *track = aod->GetTrack(nTr);
1025 Double_t fPt = track->Pt();
1026 if(fPt > maxPt) maxPt = fPt;
1027 if(track->Charge() > 0) {
1029 if(fPt > fLowPtCut) nCh1GeV++;
1030 if(fPt > fHighPtCut) nCh3GeV++;
1031 if(fPt > fVeryHighPtCut) nCh10GeV++;
1033 if(track->Charge() < 0) {
1035 if(fPt > fLowPtCut) nCh1GeV++;
1036 if(fPt > fHighPtCut) nCh3GeV++;
1037 if(fPt > fVeryHighPtCut) nCh10GeV++;
1039 if(track->Charge() == 0) nNeutr++;
1042 const Double32_t *prob = track->PID();
1044 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
1045 if(rcc == 0.0) continue;
1048 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
1051 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
1053 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
1055 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
1057 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
1059 if(fPt > fLowPtCut) nMu1GeV++;
1060 if(fPt > fHighPtCut) nMu3GeV++;
1061 if(fPt > fVeryHighPtCut) nMu10GeV++;
1064 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
1066 if(fPt > fLowPtCut) nEl1GeV++;
1067 if(fPt > fHighPtCut) nEl3GeV++;
1068 if(fPt > fVeryHighPtCut) nEl10GeV++;
1071 totalP += track->P();
1075 // Fill the event tags
1077 meanPt = meanPt/ntrack;
1079 evTag->SetEventId(iEventNumber+1);
1080 evTag->SetPath(filepath);
1082 evTag->SetNumOfTracks(nTracks);
1083 evTag->SetNumOfPosTracks(nPos);
1084 evTag->SetNumOfNegTracks(nNeg);
1085 evTag->SetNumOfNeutrTracks(nNeutr);
1087 evTag->SetNumOfV0s(nV0s);
1088 evTag->SetNumOfCascades(nCascades);
1089 evTag->SetNumOfKinks(nKinks);
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);
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);
1111 evTag->SetTotalMomentum(totalP);
1112 evTag->SetMeanPt(meanPt);
1113 evTag->SetMaxPt(maxPt);
1114 tag->AddEventTag(*evTag);
1117 TString localFileName = "Run"; localFileName += tag->GetRunId();
1118 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_";
1119 localFileName += lastEvent; localFileName += "."; localFileName += Counter;
1120 localFileName += ".AOD.tag.root";
1125 fileName = localFileName.Data();
1126 AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data()));
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();
1137 AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data()));
1140 TFile* ftag = TFile::Open(fileName, "recreate");