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::ReadLocalCollection(const char *localpath) {
103 // Checks the different subdirs of the given local path and in the
104 // case where it finds an AliESDs.root file it creates the tags
106 void *dira = gSystem->OpenDirectory(localpath);
108 const char * dirname = 0x0;
109 const char * filename = 0x0;
110 const char * pattern = "AliAODs.root";
113 while((dirname = gSystem->GetDirEntry(dira))) {
114 sprintf(fPath,"%s/%s",localpath,dirname);
115 void *dirb = gSystem->OpenDirectory(fPath);
116 while((filename = gSystem->GetDirEntry(dirb))) {
117 if(strstr(filename,pattern)) {
118 TString fESDFileName;
119 fESDFileName = fPath;
121 fESDFileName += pattern;
123 fChain->Add(fESDFileName);
125 //TFile *f = TFile::Open(fESDFileName,"READ");
126 //CreateTag(f,fESDFileName,counter);
132 }//child directory's entry loop
133 }//parent directory's entry loop
135 AliInfo(Form("AOD chain created......."));
136 AliInfo(Form("Chain entries: %d",fChain->GetEntries()));
137 CreateTag(fChain,"local");
142 //______________________________________________________________________________
143 Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) {
144 // Temporary solution for CAF: Takes as an input the ascii file that
145 // lists the ESDs stored in the SE of the CAF and creates the tags.
147 // Open the input stream
153 // Read the input list of files and add them to the chain
156 if (!esdfile.Contains("root")) continue; // protection
158 fChain->Add(esdfile);
160 //TFile *f = TFile::Open(esdfile,"READ");
161 //CreateTag(f,esdfile,counter);
168 AliInfo(Form("AOD chain created......."));
169 AliInfo(Form("Chain entries: %d",fChain->GetEntries()));
170 CreateTag(fChain,"proof");
175 //__________________________________________________________________________
176 void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList *grpList) {
177 //creates tag files for AODs
179 Float_t fLowPtCut = 1.0;
180 Float_t fHighPtCut = 3.0;
181 Float_t fVeryHighPtCut = 10.0;
184 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
186 // Creates the tags for all the events in a given AOD file
188 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
189 Int_t nPos, nNeg, nNeutr;
190 Int_t nKinks, nV0s, nCascades;
191 Int_t nK0s, nNeutrons, nPi0s, nGamas;
192 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
193 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
194 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
195 Float_t maxPt = .0, meanPt = .0, totalP = .0;
197 //reading the esd tag file
198 TChain *oldTagTree = new TChain("T");
199 const char * tagPattern = "ESD.tag";
200 // Open the working directory
201 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
202 const char * name = 0x0;
203 // Add all files matching *pattern* to the chain
204 while((name = gSystem->GetDirEntry(dirp))) {
205 if (strstr(name,tagPattern)) oldTagTree->Add(name);
207 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
209 AliInfo(Form("Creating the AOD tags......."));
211 TFile *file = TFile::Open("AliAOD.root");
212 if (!file || !file->IsOpen()) {
213 AliError(Form("opening failed"));
217 TTree *aodTree = (TTree*)file->Get("aodTree");
218 AliAODEvent *aod = new AliAODEvent();
219 aod->ReadFromTree(aodTree);
222 if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries();
223 else lastEvent = fLastEvent;
225 if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries();
226 else lastEvent = fLastEvent;
229 sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root",
230 aod->GetRunNumber(),fFirstEvent,lastEvent );
231 AliInfo(Form("writing tags to file %s", fileName));
232 AliDebug(1, Form("writing tags to file %s", fileName));
234 TFile* ftag = TFile::Open(fileName, "recreate");
236 AliRunTag *tag = new AliRunTag();
237 TTree ttag("T","A Tree with event tags");
238 TBranch * btag = ttag.Branch("AliTAG", &tag);
239 btag->SetCompressionLevel(9);
241 //reading the esd tag file
242 AliRunTag *oldtag = new AliRunTag();
244 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
245 oldTagTree->GetEntry(0);
246 tag->CopyStandardContent(oldtag);
247 const TClonesArray *evTagList = oldtag->GetEventTags();
250 Int_t nEvents = aodTree->GetEntries();
251 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
252 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
254 nPos = 0; nNeg = 0; nNeutr =0;
255 nKinks = 0; nV0s = 0; nCascades = 0;
256 nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0;
257 nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0;
258 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
259 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
260 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
261 maxPt = .0; meanPt = .0; totalP = .0;
264 aodTree->GetEvent(iEventNumber);
267 aod->GetStdContent();
269 Int_t nTracks = aod->GetNTracks();
270 // loop over vertices
271 Int_t nVtxs = aod->GetNVertices();
272 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
274 AliAODVertex *vertex = aod->GetVertex(nVtx);
275 if(vertex->GetType() == 1) nKinks += 1;
276 if(vertex->GetType() == 2) nV0s += 1;
277 if(vertex->GetType() == 3) nCascades += 1;
279 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
280 AliAODTrack *track = aod->GetTrack(nTr);
282 Double_t fPt = track->Pt();
283 if(fPt > maxPt) maxPt = fPt;
284 if(track->Charge() > 0) {
286 if(fPt > fLowPtCut) nCh1GeV++;
287 if(fPt > fHighPtCut) nCh3GeV++;
288 if(fPt > fVeryHighPtCut) nCh10GeV++;
290 if(track->Charge() < 0) {
292 if(fPt > fLowPtCut) nCh1GeV++;
293 if(fPt > fHighPtCut) nCh3GeV++;
294 if(fPt > fVeryHighPtCut) nCh10GeV++;
296 if(track->Charge() == 0) nNeutr++;
299 const Double32_t *prob = track->PID();
301 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
302 if(rcc == 0.0) continue;
305 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
308 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
310 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
312 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
314 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
316 if(fPt > fLowPtCut) nMu1GeV++;
317 if(fPt > fHighPtCut) nMu3GeV++;
318 if(fPt > fVeryHighPtCut) nMu10GeV++;
321 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
323 if(fPt > fLowPtCut) nEl1GeV++;
324 if(fPt > fHighPtCut) nEl3GeV++;
325 if(fPt > fVeryHighPtCut) nEl10GeV++;
328 totalP += track->P();
332 // Fill the event tags
334 meanPt = meanPt/ntrack;
336 evTag->SetEventId(iEventNumber+1);
338 evTag->SetNumOfTracks(nTracks);
339 evTag->SetNumOfPosTracks(nPos);
340 evTag->SetNumOfNegTracks(nNeg);
341 evTag->SetNumOfNeutrTracks(nNeutr);
343 evTag->SetNumOfV0s(nV0s);
344 evTag->SetNumOfCascades(nCascades);
345 evTag->SetNumOfKinks(nKinks);
347 evTag->SetNumOfProtons(nProtons);
348 evTag->SetNumOfKaons(nKaons);
349 evTag->SetNumOfPions(nPions);
350 evTag->SetNumOfMuons(nMuons);
351 evTag->SetNumOfElectrons(nElectrons);
352 evTag->SetNumOfPhotons(nGamas);
353 evTag->SetNumOfPi0s(nPi0s);
354 evTag->SetNumOfNeutrons(nNeutrons);
355 evTag->SetNumOfKaon0s(nK0s);
357 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
358 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
359 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
360 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
361 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
362 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
363 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
364 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
365 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
367 evTag->SetTotalMomentum(totalP);
368 evTag->SetMeanPt(meanPt);
369 evTag->SetMaxPt(maxPt);
370 tag->AddEventTag(*evTag);
382 //_____________________________________________________________________________
383 void AliAODTagCreator::CreateTag(TChain* fChain, const char *type) {
384 //private method that creates tag files
385 TString fSession = type;
386 TString fguid, fmd5, fturl;
387 TString fTempGuid = 0;
389 //private method that creates tag files
390 Float_t fLowPtCut = 1.0;
391 Float_t fHighPtCut = 3.0;
392 Float_t fVeryHighPtCut = 10.0;
394 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
396 // Creates the tags for all the events in a given AOD file
398 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
399 Int_t nPos, nNeg, nNeutr;
400 Int_t nKinks, nV0s, nCascades;
401 Int_t nK0s, nNeutrons, nPi0s, nGamas;
402 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
403 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
404 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
405 Float_t maxPt = .0, meanPt = .0, totalP = .0;
407 //reading the esd tag file
408 TChain *oldTagTree = new TChain("T");
409 const char * tagPattern = "ESD.tag";
410 // Open the working directory
411 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
412 const char * name = 0x0;
413 // Add all files matching *pattern* to the chain
414 while((name = gSystem->GetDirEntry(dirp))) {
415 if (strstr(name,tagPattern)) oldTagTree->Add(name);
417 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
419 /*if (!file || !file->IsOpen()) {
420 AliError(Form("opening failed"));
424 TTree *aodTree = (TTree*)file->Get("aodTree");*/
425 AliAODEvent *aod = new AliAODEvent();
426 aod->ReadFromTree(fChain);
428 TFile *f = fChain->GetFile();
429 fTempGuid = f->GetUUID().AsString();
430 Int_t firstEvent = 0, lastEvent = 0;
431 //lastEvent = (Int_t)aodTree->GetEntries();
433 TString localFileName = "Run"; localFileName += aod->GetRunNumber();
434 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += fChain->GetEntries(); //localFileName += "."; localFileName += Counter;
435 localFileName += ".AOD.tag.root";
440 fileName = localFileName.Data();
441 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
443 else if(fStorage == 1) {
444 TString alienLocation = "/alien";
445 alienLocation += gGrid->Pwd();
446 alienLocation += fgridpath.Data();
447 alienLocation += "/";
448 alienLocation += localFileName;
449 alienLocation += "?se=";
450 alienLocation += fSE.Data();
451 fileName = alienLocation.Data();
452 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
455 TFile* ftag = TFile::Open(fileName, "recreate");
457 AliRunTag *tag = new AliRunTag();
458 TTree ttag("T","A Tree with event tags");
459 TBranch * btag = ttag.Branch("AliTAG", &tag);
460 btag->SetCompressionLevel(9);
462 //reading the esd tag file
463 AliRunTag *oldtag = new AliRunTag();
465 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
466 oldTagTree->GetEntry(0);
467 tag->CopyStandardContent(oldtag);
468 const TClonesArray *evTagList = oldtag->GetEventTags();
470 AliInfo(Form("Creating the AOD tags......."));
473 Int_t nEvents = fChain->GetEntries();
474 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
475 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
477 nPos = 0; nNeg = 0; nNeutr =0;
478 nKinks = 0; nV0s = 0; nCascades = 0;
479 nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0;
480 nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0;
481 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
482 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
483 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
484 maxPt = .0; meanPt = .0; totalP = .0;
487 fChain->GetEntry(iEventNumber);
488 TFile *f = fChain->GetFile();
489 const TUrl *url = f->GetEndpointUrl();
490 fguid = f->GetUUID().AsString();
491 if(fSession == "grid") {
492 TString fturltemp = "alien://"; fturltemp += url->GetFile();
493 fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
495 else fturl = url->GetFile();
498 aod->GetStdContent();
500 Int_t nTracks = aod->GetNTracks();
501 // loop over vertices
502 Int_t nVtxs = aod->GetNVertices();
503 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
504 AliAODVertex *vertex = aod->GetVertex(nVtx);
505 if(vertex->GetType() == 1) nKinks += 1;
506 if(vertex->GetType() == 2) nV0s += 1;
507 if(vertex->GetType() == 3) nCascades += 1;
509 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
510 AliAODTrack *track = aod->GetTrack(nTr);
512 Double_t fPt = track->Pt();
513 if(fPt > maxPt) maxPt = fPt;
514 if(track->Charge() > 0) {
516 if(fPt > fLowPtCut) nCh1GeV++;
517 if(fPt > fHighPtCut) nCh3GeV++;
518 if(fPt > fVeryHighPtCut) nCh10GeV++;
520 if(track->Charge() < 0) {
522 if(fPt > fLowPtCut) nCh1GeV++;
523 if(fPt > fHighPtCut) nCh3GeV++;
524 if(fPt > fVeryHighPtCut) nCh10GeV++;
526 if(track->Charge() == 0) nNeutr++;
528 const Double32_t *prob = track->PID();
530 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
531 if(rcc == 0.0) continue;
534 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
537 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
539 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
541 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
543 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
545 if(fPt > fLowPtCut) nMu1GeV++;
546 if(fPt > fHighPtCut) nMu3GeV++;
547 if(fPt > fVeryHighPtCut) nMu10GeV++;
550 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
552 if(fPt > fLowPtCut) nEl1GeV++;
553 if(fPt > fHighPtCut) nEl3GeV++;
554 if(fPt > fVeryHighPtCut) nEl10GeV++;
557 totalP += track->P();
561 // Fill the event tags
563 meanPt = meanPt/ntrack;
565 evTag->SetEventId(iEventNumber+1);
566 evTag->SetGUID(fguid);
567 if(fSession == "grid") {
569 evTag->SetTURL(fturl);
572 else evTag->SetPath(fturl);
574 evTag->SetNumOfTracks(nTracks);
575 evTag->SetNumOfPosTracks(nPos);
576 evTag->SetNumOfNegTracks(nNeg);
577 evTag->SetNumOfNeutrTracks(nNeutr);
579 evTag->SetNumOfV0s(nV0s);
580 evTag->SetNumOfCascades(nCascades);
581 evTag->SetNumOfKinks(nKinks);
583 evTag->SetNumOfProtons(nProtons);
584 evTag->SetNumOfKaons(nKaons);
585 evTag->SetNumOfPions(nPions);
586 evTag->SetNumOfMuons(nMuons);
587 evTag->SetNumOfElectrons(nElectrons);
588 evTag->SetNumOfPhotons(nGamas);
589 evTag->SetNumOfPi0s(nPi0s);
590 evTag->SetNumOfNeutrons(nNeutrons);
591 evTag->SetNumOfKaon0s(nK0s);
593 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
594 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
595 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
596 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
597 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
598 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
599 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
600 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
601 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
603 evTag->SetTotalMomentum(totalP);
604 evTag->SetMeanPt(meanPt);
605 evTag->SetMaxPt(maxPt);
607 if(fguid != fTempGuid) {
612 tag->AddEventTag(*evTag);
613 if(iEventNumber+1 == fChain->GetEntries()) {
614 //AliInfo(Form("File: %s",fturl.Data()));
619 lastEvent = fChain->GetEntries();
628 //_____________________________________________________________________________
629 void AliAODTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) {
630 //private method that creates tag files
631 TString fguid = guid;
633 TString fturl = turl;
635 //private method that creates tag files
636 Float_t fLowPtCut = 1.0;
637 Float_t fHighPtCut = 3.0;
638 Float_t fVeryHighPtCut = 10.0;
640 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
642 // Creates the tags for all the events in a given AOD file
644 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
645 Int_t nPos, nNeg, nNeutr;
646 Int_t nKinks, nV0s, nCascades;
647 Int_t nK0s, nNeutrons, nPi0s, nGamas;
648 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
649 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
650 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
651 Float_t maxPt = .0, meanPt = .0, totalP = .0;
653 AliRunTag *tag = new AliRunTag();
654 TTree ttag("T","A Tree with event tags");
655 TBranch * btag = ttag.Branch("AliTAG", &tag);
656 btag->SetCompressionLevel(9);
658 //reading the esd tag file
660 TChain *oldTagTree = new TChain("T");
661 const char * tagPattern = "ESD.tag";
662 // Open the working directory
663 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
664 const char * name = 0x0;
665 // Add all files matching *pattern* to the chain
666 while((name = gSystem->GetDirEntry(dirp))) {
667 if (strstr(name,tagPattern)) oldTagTree->Add(name);
669 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
671 //reading the esd tag file
672 AliRunTag *oldtag = new AliRunTag();
674 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
675 oldTagTree->GetEntry(0);
676 tag->CopyStandardContent(oldtag);
677 const TClonesArray *evTagList = oldtag->GetEventTags();
679 AliInfo(Form("Creating the AOD tags......."));
681 if (!file || !file->IsOpen()) {
682 AliError(Form("opening failed"));
686 TTree *aodTree = (TTree*)file->Get("aodTree");
687 AliAODEvent *aod = new AliAODEvent();
688 aod->ReadFromTree(aodTree);
689 Int_t firstEvent = 0, lastEvent = 0;
690 lastEvent = (Int_t)aodTree->GetEntries();
693 Int_t nEvents = aodTree->GetEntries();
694 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
695 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
697 nPos = 0; nNeg = 0; nNeutr =0;
698 nKinks = 0; nV0s = 0; nCascades = 0;
699 nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0;
700 nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0;
701 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
702 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
703 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
704 maxPt = .0; meanPt = .0; totalP = .0;
707 aodTree->GetEvent(iEventNumber);
709 aod->GetStdContent();
711 Int_t nTracks = aod->GetNTracks();
712 // loop over vertices
713 Int_t nVtxs = aod->GetNVertices();
714 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
715 AliAODVertex *vertex = aod->GetVertex(nVtx);
716 if(vertex->GetType() == 1) nKinks += 1;
717 if(vertex->GetType() == 2) nV0s += 1;
718 if(vertex->GetType() == 3) nCascades += 1;
720 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
721 AliAODTrack *track = aod->GetTrack(nTr);
723 Double_t fPt = track->Pt();
724 if(fPt > maxPt) maxPt = fPt;
725 if(track->Charge() > 0) {
727 if(fPt > fLowPtCut) nCh1GeV++;
728 if(fPt > fHighPtCut) nCh3GeV++;
729 if(fPt > fVeryHighPtCut) nCh10GeV++;
731 if(track->Charge() < 0) {
733 if(fPt > fLowPtCut) nCh1GeV++;
734 if(fPt > fHighPtCut) nCh3GeV++;
735 if(fPt > fVeryHighPtCut) nCh10GeV++;
737 if(track->Charge() == 0) nNeutr++;
739 const Double32_t *prob = track->PID();
741 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
742 if(rcc == 0.0) continue;
745 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
748 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
750 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
752 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
754 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
756 if(fPt > fLowPtCut) nMu1GeV++;
757 if(fPt > fHighPtCut) nMu3GeV++;
758 if(fPt > fVeryHighPtCut) nMu10GeV++;
761 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
763 if(fPt > fLowPtCut) nEl1GeV++;
764 if(fPt > fHighPtCut) nEl3GeV++;
765 if(fPt > fVeryHighPtCut) nEl10GeV++;
768 totalP += track->P();
772 // Fill the event tags
774 meanPt = meanPt/ntrack;
776 evTag->SetEventId(iEventNumber+1);
777 evTag->SetGUID(fguid);
779 evTag->SetTURL(fturl);
780 evTag->SetSize(size);
782 evTag->SetNumOfTracks(nTracks);
783 evTag->SetNumOfPosTracks(nPos);
784 evTag->SetNumOfNegTracks(nNeg);
785 evTag->SetNumOfNeutrTracks(nNeutr);
787 evTag->SetNumOfV0s(nV0s);
788 evTag->SetNumOfCascades(nCascades);
789 evTag->SetNumOfKinks(nKinks);
791 evTag->SetNumOfProtons(nProtons);
792 evTag->SetNumOfKaons(nKaons);
793 evTag->SetNumOfPions(nPions);
794 evTag->SetNumOfMuons(nMuons);
795 evTag->SetNumOfElectrons(nElectrons);
796 evTag->SetNumOfPhotons(nGamas);
797 evTag->SetNumOfPi0s(nPi0s);
798 evTag->SetNumOfNeutrons(nNeutrons);
799 evTag->SetNumOfKaon0s(nK0s);
801 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
802 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
803 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
804 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
805 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
806 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
807 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
808 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
809 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
811 evTag->SetTotalMomentum(totalP);
812 evTag->SetMeanPt(meanPt);
813 evTag->SetMaxPt(maxPt);
814 tag->AddEventTag(*evTag);
817 TString localFileName = "Run"; localFileName += tag->GetRunId();
818 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_";
819 localFileName += lastEvent; localFileName += "."; localFileName += Counter;
820 localFileName += ".AOD.tag.root";
825 fileName = localFileName.Data();
826 AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data()));
828 else if(fStorage == 1) {
829 TString alienLocation = "/alien";
830 alienLocation += gGrid->Pwd();
831 alienLocation += fgridpath.Data();
832 alienLocation += "/";
833 alienLocation += localFileName;
834 alienLocation += "?se=";
835 alienLocation += fSE.Data();
836 fileName = alienLocation.Data();
837 AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data()));
840 TFile* ftag = TFile::Open(fileName, "recreate");
849 //_____________________________________________________________________________
850 void AliAODTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) {
851 //private method that creates tag files
852 Float_t fLowPtCut = 1.0;
853 Float_t fHighPtCut = 3.0;
854 Float_t fVeryHighPtCut = 10.0;
857 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
859 // Creates the tags for all the events in a given AOD file
861 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
862 Int_t nPos, nNeg, nNeutr;
863 Int_t nKinks, nV0s, nCascades;
864 Int_t nK0s, nNeutrons, nPi0s, nGamas;
865 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
866 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
867 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
868 Float_t maxPt = .0, meanPt = .0, totalP = .0;
870 AliRunTag *tag = new AliRunTag();
871 TTree ttag("T","A Tree with event tags");
872 TBranch * btag = ttag.Branch("AliTAG", &tag);
873 btag->SetCompressionLevel(9);
875 //reading the esd tag file
876 TChain *oldTagTree = new TChain("T");
877 const char * tagPattern = "ESD.tag";
878 // Open the working directory
879 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
880 const char * name = 0x0;
881 // Add all files matching *pattern* to the chain
882 while((name = gSystem->GetDirEntry(dirp))) {
883 if (strstr(name,tagPattern)) oldTagTree->Add(name);
885 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
887 //reading the esd tag file
888 AliRunTag *oldtag = new AliRunTag();
890 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
891 oldTagTree->GetEntry(0);
892 tag->CopyStandardContent(oldtag);
893 const TClonesArray *evTagList = oldtag->GetEventTags();
895 AliInfo(Form("Creating the AOD tags......."));
897 if (!file || !file->IsOpen()) {
898 AliError(Form("opening failed"));
902 TTree *aodTree = (TTree*)file->Get("aodTree");
903 AliAODEvent *aod = new AliAODEvent();
904 aod->ReadFromTree(aodTree);
905 Int_t firstEvent = 0, lastEvent = 0;
906 lastEvent = (Int_t)aodTree->GetEntries();
909 Int_t nEvents = aodTree->GetEntries();
910 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
911 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
913 nPos = 0; nNeg = 0; nNeutr =0;
914 nKinks = 0; nV0s = 0; nCascades = 0;
915 nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0;
916 nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0;
917 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
918 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
919 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
920 maxPt = .0; meanPt = .0; totalP = .0;
923 aodTree->GetEvent(iEventNumber);
926 aod->GetStdContent();
928 Int_t nTracks = aod->GetNTracks();
929 // loop over vertices
930 Int_t nVtxs = aod->GetNVertices();
931 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
933 AliAODVertex *vertex = aod->GetVertex(nVtx);
934 if(vertex->GetType() == 1) nKinks += 1;
935 if(vertex->GetType() == 2) nV0s += 1;
936 if(vertex->GetType() == 3) nCascades += 1;
938 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
939 AliAODTrack *track = aod->GetTrack(nTr);
941 Double_t fPt = track->Pt();
942 if(fPt > maxPt) maxPt = fPt;
943 if(track->Charge() > 0) {
945 if(fPt > fLowPtCut) nCh1GeV++;
946 if(fPt > fHighPtCut) nCh3GeV++;
947 if(fPt > fVeryHighPtCut) nCh10GeV++;
949 if(track->Charge() < 0) {
951 if(fPt > fLowPtCut) nCh1GeV++;
952 if(fPt > fHighPtCut) nCh3GeV++;
953 if(fPt > fVeryHighPtCut) nCh10GeV++;
955 if(track->Charge() == 0) nNeutr++;
958 const Double32_t *prob = track->PID();
960 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
961 if(rcc == 0.0) continue;
964 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
967 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
969 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
971 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
973 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
975 if(fPt > fLowPtCut) nMu1GeV++;
976 if(fPt > fHighPtCut) nMu3GeV++;
977 if(fPt > fVeryHighPtCut) nMu10GeV++;
980 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
982 if(fPt > fLowPtCut) nEl1GeV++;
983 if(fPt > fHighPtCut) nEl3GeV++;
984 if(fPt > fVeryHighPtCut) nEl10GeV++;
987 totalP += track->P();
991 // Fill the event tags
993 meanPt = meanPt/ntrack;
995 evTag->SetEventId(iEventNumber+1);
996 evTag->SetPath(filepath);
998 evTag->SetNumOfTracks(nTracks);
999 evTag->SetNumOfPosTracks(nPos);
1000 evTag->SetNumOfNegTracks(nNeg);
1001 evTag->SetNumOfNeutrTracks(nNeutr);
1003 evTag->SetNumOfV0s(nV0s);
1004 evTag->SetNumOfCascades(nCascades);
1005 evTag->SetNumOfKinks(nKinks);
1007 evTag->SetNumOfProtons(nProtons);
1008 evTag->SetNumOfKaons(nKaons);
1009 evTag->SetNumOfPions(nPions);
1010 evTag->SetNumOfMuons(nMuons);
1011 evTag->SetNumOfElectrons(nElectrons);
1012 evTag->SetNumOfPhotons(nGamas);
1013 evTag->SetNumOfPi0s(nPi0s);
1014 evTag->SetNumOfNeutrons(nNeutrons);
1015 evTag->SetNumOfKaon0s(nK0s);
1017 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1018 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1019 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1020 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1021 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1022 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
1023 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
1024 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
1025 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
1027 evTag->SetTotalMomentum(totalP);
1028 evTag->SetMeanPt(meanPt);
1029 evTag->SetMaxPt(maxPt);
1030 tag->AddEventTag(*evTag);
1033 TString localFileName = "Run"; localFileName += tag->GetRunId();
1034 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_";
1035 localFileName += lastEvent; localFileName += "."; localFileName += Counter;
1036 localFileName += ".AOD.tag.root";
1041 fileName = localFileName.Data();
1042 AliInfo(Form("Writing AOD tags to local file: %s",fileName.Data()));
1044 else if(fStorage == 1) {
1045 TString alienLocation = "/alien";
1046 alienLocation += gGrid->Pwd();
1047 alienLocation += fgridpath.Data();
1048 alienLocation += "/";
1049 alienLocation += localFileName;
1050 alienLocation += "?se=";
1051 alienLocation += fSE.Data();
1052 fileName = alienLocation.Data();
1053 AliInfo(Form("Writing AOD tags to grid file: %s",fileName.Data()));
1056 TFile* ftag = TFile::Open(fileName, "recreate");