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 // AliESDTagCreator 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>
30 #include <TObjString.h>
31 #include <TLorentzVector.h>
33 #include <TTimeStamp.h>
34 #include <TRefArray.h>
38 #include <TGridResult.h>
41 #include "AliRunTag.h"
42 #include "AliEventTag.h"
44 #include "AliESDEvent.h"
45 #include "AliESDVertex.h"
47 #include "AliGRPObject.h"
49 #include "AliESDTagCreator.h"
52 ClassImp(AliESDTagCreator)
55 //______________________________________________________________________________
56 AliESDTagCreator::AliESDTagCreator() :
58 fChain(new TChain("esdTree")), fGUIDList(new TList()),
59 fMD5List(new TList()), fTURLList(new TList()), fBranches(""),
60 meminfo(new MemInfo_t) {
61 //==============Default constructor for a AliESDTagCreator================
64 //______________________________________________________________________________
65 AliESDTagCreator::~AliESDTagCreator() {
66 //================Default destructor for a AliESDTagCreator===================
74 //______________________________________________________________________________
75 Bool_t AliESDTagCreator::ReadGridCollection(TGridResult *fresult) {
76 // Reads the entry of the TGridResult and creates the tags
77 Int_t nEntries = fresult->GetEntries();
83 // Long64_t size = -1;
86 for(Int_t i = 0; i < nEntries; i++) {
87 alienUrl = fresult->GetKey(i,"turl");
88 // guid = fresult->GetKey(i,"guid");
89 // if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size"));
90 // md5 = fresult->GetKey(i,"md5");
91 // turl = fresult->GetKey(i,"turl");
92 // if(md5 && !strlen(guid)) md5 = 0;
93 // if(guid && !strlen(guid)) guid = 0;
95 fChain->Add(alienUrl);
96 //fGUIDList->Add(new TObjString(guid));
97 //fMD5List->Add(new TObjString(md5));
98 //fTURLList->Add(new TObjString(turl));
100 //TFile *f = TFile::Open(alienUrl,"READ");
101 //CreateTag(f,guid,md5,turl,size,counter);
107 if (fChain->GetEntries() > 0) {
108 AliInfo(Form("ESD chain created......."));
109 AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));
111 AliWarning(Form("No ESD files found !"));
115 // Switch of branches on user request
117 CreateTag(fChain,"grid");
122 //______________________________________________________________________________
123 Bool_t AliESDTagCreator::ReadLocalCollection(const char *localpath) {
124 // Checks the different subdirs of the given local path and in the
125 // case where it finds an AliESDs.root file it creates the tags
127 void *dira = gSystem->OpenDirectory(localpath);
129 const char * dirname = 0x0;
130 const char * filename = 0x0;
131 const char * pattern = "AliESDs.root";
134 while((dirname = gSystem->GetDirEntry(dira))) {
135 snprintf(fPath, 512,"%s/%s",localpath,dirname);
136 void *dirb = gSystem->OpenDirectory(fPath);
137 while((filename = gSystem->GetDirEntry(dirb))) {
138 if(strstr(filename,pattern)) {
139 TString fESDFileName;
140 fESDFileName = fPath;
142 fESDFileName += pattern;
144 fChain->Add(fESDFileName);
146 //TFile *f = TFile::Open(fESDFileName,"READ");
147 //CreateTag(f,fESDFileName,counter);
153 }//child directory's entry loop
154 }//parent directory's entry loop
156 AliInfo(Form("ESD chain created......."));
157 AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));
158 // Switch of branches on user request
160 CreateTag(fChain,"local");
165 //______________________________________________________________________________
166 Bool_t AliESDTagCreator::ReadCAFCollection(const char *filename) {
167 // Temporary solution for CAF: Takes as an input the ascii file that
168 // lists the ESDs stored in the SE of the CAF and creates the tags.
170 // Open the input stream
176 // Read the input list of files and add them to the chain
179 if (!esdfile.Contains("root")) continue; // protection
181 fChain->Add(esdfile);
183 //TFile *f = TFile::Open(esdfile,"READ");
184 //CreateTag(f,esdfile,counter);
191 AliInfo(Form("ESD chain created......."));
192 AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));
193 // Switch of branches on user request
195 CreateTag(fChain,"proof");
200 //_____________________________________________________________________________
201 void AliESDTagCreator::CreateTag(TChain* chain, const char *type) {
202 //private method that creates tag files
203 TString fSession = type;
204 TString fguid, fmd5, fturl, foldguid;
207 Int_t iRunNumber = 0;
208 //gSystem->GetMemInfo(meminfo);
209 //AliInfo(Form("After the tag initialization - Memory used: %d MB",meminfo->fMemUsed));
210 //Int_t tempmem = meminfo->fMemUsed;
212 AliInfo(Form("Creating the ESD tags......."));
214 Int_t firstEvent = 0,lastEvent = 0;
215 AliESDEvent *esd = new AliESDEvent();
216 esd->ReadFromTree(chain);
217 // AliESD *esdold = 0x0;
219 //gSystem->GetMemInfo(meminfo);
220 //AliInfo(Form("After the esd initialization - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
221 //tempmem = meminfo->fMemUsed;
223 Int_t iInitRunNumber = -1;
225 TFile *f = chain->GetFile();
226 fTempGuid = f->GetUUID().AsString();
228 TString localFileName = "Run"; localFileName += esd->GetRunNumber();
229 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += chain->GetEntries(); //localFileName += "."; localFileName += Counter;
230 localFileName += ".ESD.tag.root";
235 fileName = localFileName.Data();
236 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
238 else if(fStorage == 1) {
239 TString alienLocation = "/alien";
240 alienLocation += gGrid->Pwd();
241 alienLocation += fgridpath.Data();
242 alienLocation += "/";
243 alienLocation += localFileName;
244 alienLocation += "?se=";
245 alienLocation += fSE.Data();
246 fileName = alienLocation.Data();
247 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
250 TFile* ftag = TFile::Open(fileName, "recreate");
252 AliRunTag *tag = new AliRunTag();
253 AliEventTag *evTag = new AliEventTag();
254 TTree * ttag = new TTree("T","A Tree with event tags");
255 TBranch * btag = ttag->Branch("AliTAG", &tag);
256 btag->SetCompressionLevel(9);
257 // Run related information
258 tag->SetMagneticField(esd->GetMagneticField());
259 tag->SetBeamEnergy(esd->GetBeamEnergy());
260 tag->SetBeamType(TString(esd->GetBeamType()));
261 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
265 for(Int_t iEventNumber = 0; iEventNumber < chain->GetEntries(); iEventNumber++) {
266 FillEventTag(chain, evTag, iEventNumber, esd);
268 if(iEventNumber == 0) iInitRunNumber = esd->GetRunNumber();
269 iRunNumber = esd->GetRunNumber();
270 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD - You are trying to merge different runs!!!");
272 TFile *file = chain->GetFile();
273 // const TUrl *url = file->GetEndpointUrl();
274 fguid = file->GetUUID().AsString();
276 if (foldguid == fguid) {
277 tag->AddEventTag(*evTag);
280 AliFileTag *nftag = new AliFileTag();
281 nftag->SetGUID(fguid);
283 // if(fSession == "grid") {
284 // TString fturltemp = "alien://"; fturltemp += url->GetFile();
285 // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
287 // else fturl = url->GetFile();
288 fturl = file->GetName();
290 if(fSession == "grid") {
292 nftag->SetTURL(fturl);
296 nftag->SetPath(fturl);
299 nftag->SetTURL(fturl);
303 if (tag->GetFileId(fguid) > -1)
304 AliFatal("Adding a file which is already in the RunTag.");
306 tag->AddFileTag(nftag);
309 tag->SetRunId(iInitRunNumber);
310 // if(fIsSim) tag->SetDataType(0);
311 // else tag->SetDataType(1);
313 // if(fguid != fTempGuid) {
314 // fTempGuid = fguid;
318 if(iEventNumber+1 == chain->GetEntries()) {
319 //AliInfo(Form("File: %s",fturl.Data()));
325 lastEvent = chain->GetEntries();
327 //gSystem->GetMemInfo(meminfo);
328 //AliInfo(Form("After the event and track loop - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
329 //tempmem = meminfo->fMemUsed;
333 //gSystem->GetMemInfo(meminfo);
334 //AliInfo(Form("After the t->Delete - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
335 //tempmem = meminfo->fMemUsed;
342 //gSystem->GetMemInfo(meminfo);
343 //AliInfo(Form("After the file closing - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
344 //tempmem = meminfo->fMemUsed;
349 //gSystem->GetMemInfo(meminfo);
350 //AliInfo(Form("After the delete objects - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
353 //_____________________________________________________________________________
354 void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) {
355 //private method that creates tag files
356 TString fguid = guid;
358 TString fturl = turl;
362 // Double_t fMUONMASS = 0.105658369;
364 // Double_t fX,fY,fZ ;
365 // Double_t fThetaX, fThetaY, fPyz, fChisquare;
366 // Double_t fPxRec, fPyRec, fPzRec, fEnergy;
368 // TLorentzVector fEPvector;
370 // Float_t fLowPtCut = 1.0;
371 // Float_t fHighPtCut = 3.0;
372 // Float_t fVeryHighPtCut = 10.0;
375 // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
377 // Creates the tags for all the events in a given ESD file
378 Bool_t fIsSim = kTRUE;
380 // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
381 // Int_t nPos, nNeg, nNeutr;
382 // Int_t nK0s, nNeutrons, nPi0s, nGamas;
383 // Int_t nCh1GeV, nCh3GeV, nCh10GeV;
384 // Int_t nMu1GeV, nMu3GeV, nMu10GeV;
385 // Int_t nEl1GeV, nEl3GeV, nEl10GeV;
386 // Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
387 // Int_t fVertexflag;
388 Int_t iRunNumber = 0;
389 // TString fVertexName;
392 AliRunTag *tag = new AliRunTag();
393 AliEventTag *evTag = new AliEventTag();
394 TTree * ttag = new TTree("T","A Tree with event tags");
395 TBranch * btag = ttag->Branch("AliTAG", &tag);
396 btag->SetCompressionLevel(9);
397 gSystem->GetMemInfo(meminfo);
398 AliInfo(Form("After the tag initialization - Memory used: %d MB",meminfo->fMemUsed));
399 Int_t tempmem = meminfo->fMemUsed;
401 AliInfo(Form("Creating the ESD tags......."));
403 Int_t firstEvent = 0,lastEvent = 0;
404 TTree *t = (TTree*) file->Get("esdTree");
405 AliESDEvent *esd = new AliESDEvent();
406 esd->ReadFromTree(t);
408 gSystem->GetMemInfo(meminfo);
409 AliInfo(Form("After the esd initialization - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
410 tempmem = meminfo->fMemUsed;
413 Int_t iInitRunNumber = esd->GetRunNumber();
414 tag->SetMagneticField(esd->GetMagneticField());
415 tag->SetBeamEnergy(esd->GetBeamEnergy());
416 tag->SetBeamType(TString(esd->GetBeamType()));
417 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
419 AliFileTag *eftag = new AliFileTag();
421 eftag->SetTURL(fturl);
422 eftag->SetSize(size);
423 tag->AddFileTag(eftag);
425 Int_t iNumberOfEvents = (Int_t)t->GetEntries();
426 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
427 FillEventTag(t, evTag, iEventNumber, esd);
428 iRunNumber = esd->GetRunNumber();
429 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
431 tag->SetRunId(iInitRunNumber);
432 if(fIsSim) tag->SetDataType(0);
433 else tag->SetDataType(1);
434 tag->AddEventTag(*evTag);
436 lastEvent = iNumberOfEvents;
438 gSystem->GetMemInfo(meminfo);
439 AliInfo(Form("After the event and track loop - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
440 tempmem = meminfo->fMemUsed;
443 gSystem->GetMemInfo(meminfo);
444 AliInfo(Form("After the t->Delete - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
445 tempmem = meminfo->fMemUsed;
447 TString localFileName = "Run"; localFileName += tag->GetRunId();
448 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
449 localFileName += ".ESD.tag.root";
454 fileName = localFileName.Data();
455 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
457 else if(fStorage == 1) {
458 TString alienLocation = "/alien";
459 alienLocation += gGrid->Pwd();
460 alienLocation += fgridpath.Data();
461 alienLocation += "/";
462 alienLocation += localFileName;
463 alienLocation += "?se=";
464 alienLocation += fSE.Data();
465 fileName = alienLocation.Data();
466 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
469 TFile* ftag = TFile::Open(fileName, "recreate");
476 gSystem->GetMemInfo(meminfo);
477 AliInfo(Form("After the file closing - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
478 tempmem = meminfo->fMemUsed;
484 gSystem->GetMemInfo(meminfo);
485 AliInfo(Form("After the delete objects - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
488 //_____________________________________________________________________________
489 void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) {
490 //private method that creates tag files
494 // Double_t fMUONMASS = 0.105658369;
496 // Double_t fX,fY,fZ ;
497 // Double_t fThetaX, fThetaY, fPyz, fChisquare;
498 // Double_t fPxRec, fPyRec, fPzRec, fEnergy;
500 // TLorentzVector fEPvector;
502 // Float_t fLowPtCut = 1.0;
503 // Float_t fHighPtCut = 3.0;
504 // Float_t fVeryHighPtCut = 10.0;
507 // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
509 // Creates the tags for all the events in a given ESD file
510 // Bool_t fIsSim = kTRUE;
512 // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
513 // Int_t nPos, nNeg, nNeutr;
514 // Int_t nK0s, nNeutrons, nPi0s, nGamas;
515 // Int_t nCh1GeV, nCh3GeV, nCh10GeV;
516 // Int_t nMu1GeV, nMu3GeV, nMu10GeV;
517 // Int_t nEl1GeV, nEl3GeV, nEl10GeV;
518 // Float_t maxPt = .0, etamaxPt = -999, phimaxPt = -999., meanPt = .0, totalP = .0;
519 // Int_t fVertexflag;
520 Int_t iRunNumber = 0;
521 // TString fVertexName;
524 AliRunTag *tag = new AliRunTag();
525 AliEventTag *evTag = new AliEventTag();
526 TTree * ttag = new TTree("T","A Tree with event tags");
527 TBranch * btag = ttag->Branch("AliTAG", &tag);
528 btag->SetCompressionLevel(9);
530 AliInfo(Form("Creating the ESD tags......."));
532 Int_t firstEvent = 0,lastEvent = 0;
534 TTree *t = (TTree*) file->Get("esdTree");
535 AliESDEvent *esd = new AliESDEvent();
536 esd->ReadFromTree(t);
539 Int_t iInitRunNumber = esd->GetRunNumber();
540 tag->SetMagneticField(esd->GetMagneticField());
541 tag->SetBeamEnergy(esd->GetBeamEnergy());
542 tag->SetBeamType(TString(esd->GetBeamType()));
543 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
545 AliFileTag *eftag = new AliFileTag();
546 eftag->SetPath(filepath);
547 eftag->SetTURL(Form("local://%s", filepath));
550 tag->AddFileTag(eftag);
552 Int_t iNumberOfEvents = (Int_t)t->GetEntries();
553 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
554 FillEventTag(t, evTag, iEventNumber, esd);
555 iRunNumber = esd->GetRunNumber();
556 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
557 // evTag->SetPath(filepath);
559 tag->SetRunId(iInitRunNumber);
560 // if(fIsSim) tag->SetDataType(0);
561 // else tag->SetDataType(1);
562 tag->AddEventTag(*evTag);
564 lastEvent = iNumberOfEvents;
568 TString localFileName = "Run"; localFileName += tag->GetRunId();
569 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
570 localFileName += ".ESD.tag.root";
575 fileName = localFileName.Data();
576 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
578 else if(fStorage == 1) {
579 TString alienLocation = "/alien";
580 alienLocation += gGrid->Pwd();
581 alienLocation += fgridpath.Data();
582 alienLocation += "/";
583 alienLocation += localFileName;
584 alienLocation += "?se=";
585 alienLocation += fSE.Data();
586 fileName = alienLocation.Data();
587 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
590 TFile* ftag = TFile::Open(fileName, "recreate");
603 //_____________________________________________________________________________
604 void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRPObject *grpData, ULong_t * qa, Bool_t * es, Int_t qalength, Int_t eslength) {
606 Float_t lhcLuminosity = 0.0;
607 TString lhcState = "test";
608 //UInt_t detectorMask = 0;
609 Int_t detectorMask = 0;
611 detectorMask = grpData->GetDetectorMask();
612 time_t startTime = grpData->GetTimeStart();
613 TTimeStamp t1(startTime);
614 time_t endTime = grpData->GetTimeEnd();
615 TTimeStamp t2(endTime);
616 const char* beamtype = grpData->GetBeamType();
617 Float_t beamenergy = grpData->GetBeamEnergy();
623 // Double_t fMUONMASS = 0.105658369;
625 // Double_t fX,fY,fZ ;
626 // Double_t fThetaX, fThetaY, fPyz, fChisquare;
627 // Double_t fPxRec,fPyRec, fPzRec, fEnergy;
629 // TLorentzVector fEPvector;
631 // Float_t fLowPtCut = 1.0;
632 // Float_t fHighPtCut = 3.0;
633 // Float_t fVeryHighPtCut = 10.0;
636 // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
638 // Creates the tags for all the events in a given ESD file
640 // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
641 // Int_t nPos, nNeg, nNeutr;
642 // Int_t nK0s, nNeutrons, nPi0s, nGamas;
643 // Int_t nCh1GeV, nCh3GeV, nCh10GeV;
644 // Int_t nMu1GeV, nMu3GeV, nMu10GeV;
645 // Int_t nEl1GeV, nEl3GeV, nEl10GeV;
646 // Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
647 // Int_t fVertexflag;
648 Int_t iRunNumber = 0;
649 TString fguid, fmd5, fturl;
650 // TString fVertexName("default");
653 AliInfo(Form("Creating the ESD tags......."));
655 TFile *esdfile = TFile::Open("AliESDs.root");
656 if (!esdfile || !esdfile->IsOpen()) {
657 AliError(Form("opening failed"));
662 TTree *b = (TTree*) esdfile->Get("esdTree");
663 AliESDEvent *esd = new AliESDEvent();
664 esd->ReadFromTree(b);
666 b->GetEntry(fFirstEvent);
667 Int_t iInitRunNumber = esd->GetRunNumber();
669 Int_t iNumberOfEvents = (Int_t)b->GetEntries();
670 if ((fLastEvent == -1) || ((Int_t) b->GetEntries() < fLastEvent))
671 lastEvent = (Int_t)b->GetEntries();
672 else lastEvent = fLastEvent;
675 snprintf(fileName, 256, "Run%d.Event%d_%d.ESD.tag.root",
676 iInitRunNumber,fFirstEvent,lastEvent);
677 AliInfo(Form("writing tags to file %s", fileName));
678 AliDebug(1, Form("writing tags to file %s", fileName));
680 TFile* ftag = TFile::Open(fileName, "recreate");
682 AliRunTag *tag = new AliRunTag();
683 AliEventTag *evTag = new AliEventTag();
684 TTree * ttag = new TTree("T","A Tree with event tags");
685 TBranch * btag = ttag->Branch("AliTAG", &tag);
686 btag->SetCompressionLevel(9);
688 if ((fLastEvent != -1) && ((Int_t) b->GetEntries() > fLastEvent))
689 iNumberOfEvents = fLastEvent + 1;
691 AliFileTag *eftag = new AliFileTag();
692 tag->AddFileTag(eftag);
694 for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
695 FillEventTag(b, evTag, iEventNumber, esd);
696 iRunNumber = esd->GetRunNumber();
697 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
699 if (iEventNumber == fFirstEvent) {
700 TFile *file = b->GetCurrentFile();
701 // const TUrl *url = file->GetEndpointUrl();
702 fguid = file->GetUUID().AsString();
704 // if(fStorage == 1) {
705 // TString fturltemp = "alien://"; fturltemp += url->GetFile();
706 // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
708 // else fturl = url->GetFile();
709 fturl = file->GetName();
711 // evTag->SetGUID(fguid);
712 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetGUID(fguid);
714 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetMD5("");
715 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetTURL(fturl);
716 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetSize(0);
719 // evTag->SetPath(fturl);
720 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetPath(fturl);
721 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetMD5("");
722 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetSize(0);
727 tag->AddEventTag(*evTag);
730 tag->SetLHCTag(lhcLuminosity,lhcState);
731 tag->SetDetectorTag(esd->GetESDRun()->GetDetectorsInDAQ(), esd->GetESDRun()->GetDetectorsInReco());
732 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
734 // Get magnetic field info
737 Float_t l3Current = grpData->GetL3Current((AliGRPObject::Stats)0);
738 if (l3Current == AliGRPObject::GetInvalidFloat()) {
739 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
743 Char_t l3Polarity = grpData->GetL3Polarity();
744 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
745 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
750 Float_t diCurrent = grpData->GetDipoleCurrent((AliGRPObject::Stats)0);
751 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
752 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
756 Char_t diPolarity = grpData->GetDipolePolarity();
757 if (diPolarity == AliGRPObject::GetInvalidChar()) {
758 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
762 if (ok && grpData->IsPolarityConventionLHC()) {
763 if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 1))
764 tag->SetMagneticField(-0.5);
765 if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 0))
766 tag->SetMagneticField(0.5);
767 if (TMath::Abs(l3Current) < 2000.0)
768 tag->SetMagneticField(0.0);
770 if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 1))
771 tag->SetDipoleField(-0.2);
772 if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 0))
773 tag->SetDipoleField(0.2);
774 if (TMath::Abs(diCurrent) < 500.0)
775 tag->SetDipoleField(0.0);
778 tag->SetRunId(iInitRunNumber);
779 tag->SetRunStartTime(t1.GetDate());
780 tag->SetRunStopTime(t2.GetDate());
781 tag->SetBeamEnergy(beamenergy);
782 tag->SetBeamType(beamtype);
785 tag->SetQAArray(qa, qalength) ;
786 tag->SetEventSpecies(es, eslength) ;
801 void AliESDTagCreator::CreateESDTagsFullRun(TTree *chain, AliGRPObject *grpData, ULong_t * qa, Bool_t * es, Int_t qalength, Int_t eslength)
804 Float_t lhcLuminosity = 0.0;
805 TString lhcState = "test";
806 //UInt_t detectorMask = 0;
807 Int_t detectorMask = 0;
809 detectorMask = grpData->GetDetectorMask();
810 time_t startTime = grpData->GetTimeStart();
811 TTimeStamp t1(startTime);
812 time_t endTime = grpData->GetTimeEnd();
813 TTimeStamp t2(endTime);
814 const char* beamtype = grpData->GetBeamType();
815 Float_t beamenergy = grpData->GetBeamEnergy();
817 Int_t iRunNumber = 0;
818 TString fguid, fmd5, fturl;
821 AliInfo(Form("Creating the ESD tags......."));
823 AliESDEvent *esd = new AliESDEvent();
824 esd->ReadFromTree(chain);
827 Int_t iInitRunNumber = esd->GetRunNumber();
829 Int_t iNumberOfEvents = (Int_t)chain->GetEntries();
830 Int_t iFirstEvent = 0;
833 snprintf(fileName, 256, "Run%d.Event%d_%d.ESD.tag.root",
834 iInitRunNumber,iFirstEvent,iNumberOfEvents);
835 AliInfo(Form("writing tags to file %s", fileName));
836 AliDebug(1, Form("writing tags to file %s", fileName));
838 TFile* ftag = TFile::Open(fileName, "recreate");
840 AliRunTag *tag = new AliRunTag();
841 AliEventTag *evTag = new AliEventTag();
842 TTree * ttag = new TTree("T","A Tree with event tags");
843 TBranch * btag = ttag->Branch("AliTAG", &tag);
844 btag->SetCompressionLevel(9);
846 // AliFileTag *eftag = new AliFileTag();
847 // tag->AddFileTag(*eftag);
849 for (Int_t iEventNumber = iFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
850 FillEventTag(chain, evTag, iEventNumber, esd);
852 iRunNumber = esd->GetRunNumber();
853 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
855 TFile *file = chain->GetCurrentFile();
856 // const TUrl *url = file->GetName();
857 fguid = file->GetUUID().AsString();
858 fturl = file->GetName();
859 // if(fStorage == 1) {
860 // TString fturltemp = "alien://"; fturltemp += url->GetFile();
861 // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
863 // else fturl = url->GetFile();
865 if (fturl.CompareTo(fturlold)) {
867 AliFileTag *eftag = new AliFileTag();
869 //evTag->SetGUID(fguid);
870 eftag->SetGUID(fguid);
872 // evTag->SetMD5("");
873 // evTag->SetTURL(fturl);
874 // evTag->SetSize(0);
877 eftag->SetTURL(fturl);
881 // evTag->SetPath(fturl);
882 // evTag->SetTURL(fturl);
883 eftag->SetPath(fturl);
884 eftag->SetTURL(fturl);
889 tag->AddFileTag(eftag);
895 // cout << "FileTag found " << fturl.Data() << " " << fturlold.Data() << endl;
898 tag->AddEventTag(*evTag);
901 tag->SetLHCTag(lhcLuminosity,lhcState);
902 tag->SetDetectorTag(esd->GetESDRun()->GetDetectorsInDAQ(), esd->GetESDRun()->GetDetectorsInReco());
903 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
905 // Get magnetic field info
908 Float_t l3Current = grpData->GetL3Current((AliGRPObject::Stats)0);
909 if (l3Current == AliGRPObject::GetInvalidFloat()) {
910 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
914 Char_t l3Polarity = grpData->GetL3Polarity();
915 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
916 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
921 Float_t diCurrent = grpData->GetDipoleCurrent((AliGRPObject::Stats)0);
922 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
923 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
927 Char_t diPolarity = grpData->GetDipolePolarity();
928 if (diPolarity == AliGRPObject::GetInvalidChar()) {
929 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
933 if (ok && grpData->IsPolarityConventionLHC()) {
934 if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 1))
935 tag->SetMagneticField(-0.5);
936 if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 0))
937 tag->SetMagneticField(0.5);
938 if (TMath::Abs(l3Current) < 2000.0)
939 tag->SetMagneticField(0.0);
941 if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 1))
942 tag->SetDipoleField(-0.2);
943 if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 0))
944 tag->SetDipoleField(0.2);
945 if (TMath::Abs(diCurrent) < 500.0)
946 tag->SetDipoleField(0.0);
949 tag->SetRunId(iInitRunNumber);
950 tag->SetRunStartTime(t1.GetDate());
951 tag->SetRunStopTime(t2.GetDate());
952 tag->SetBeamEnergy(beamenergy);
953 tag->SetBeamType(beamtype);
956 tag->SetQAArray(qa, qalength) ;
957 tag->SetEventSpecies(es, eslength) ;
970 //_____________________________________________________________________________
971 void AliESDTagCreator::SwitchOffBranches() const {
973 // Switch of branches on user request
974 TObjArray * tokens = fBranches.Tokenize(" ");
975 Int_t ntok = tokens->GetEntries();
976 for (Int_t i = 0; i < ntok; i++) {
977 TString str = ((TObjString*) tokens->At(i))->GetString();
978 fChain->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
979 AliInfo(Form("Branch %s switched off \n", str.Data()));
984 //_____________________________________________________________________________
985 void AliESDTagCreator::FillEventTag(TTree *chain, AliEventTag *evTag, Int_t iEventNumber, AliESDEvent *esd)
987 // Fill the event specific information in the EventTag
988 AliESD *esdold = 0x0;
995 Double_t fMUONMASS = 0.105658369;
998 Double_t fThetaX, fThetaY, fPyz, fChisquare;
999 Double_t fPxRec, fPyRec, fPzRec, fEnergy;
1001 TLorentzVector fEPvector;
1003 Float_t fLowPtCut = 1.0;
1004 Float_t fHighPtCut = 3.0;
1005 Float_t fVeryHighPtCut = 10.0;
1008 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
1010 // Creates the tags for all the events in a given ESD file
1011 Bool_t fIsSim = kTRUE;
1013 Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
1014 Int_t nPos, nNeg, nNeutr;
1015 Int_t nK0s, nLambdas, nNeutrons, nPi0s, nGamas;
1016 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
1017 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
1018 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
1019 Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
1021 TString fVertexName;
1025 ntrack = 0; nPos = 0; nNeg = 0; nNeutr =0;
1026 nK0s = 0; nLambdas = 0; nNeutrons = 0; nPi0s = 0;
1027 nGamas = 0; nProtons = 0; nKaons = 0;
1028 nPions = 0; nMuons = 0; nElectrons = 0; nFWMuons = 0; nFWMatchedMuons = 0;
1029 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
1030 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
1031 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
1032 maxPt = .0; etamaxPt = -999.; phimaxPt = -999.; meanPt = .0; totalP = .0;
1035 chain->GetEntry(iEventNumber);
1036 esdold = esd->GetAliESDOld();
1037 if(esdold) esd->CopyFromOldESD();
1039 // TFile *file = chain->GetFile();
1040 // const TUrl *url = file->GetEndpointUrl();
1041 // fguid = file->GetUUID().AsString();
1042 // if(fSession == "grid") {
1043 // TString fturltemp = "alien://"; fturltemp += url->GetFile();
1044 // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
1046 // else fturl = url->GetFile();
1048 const AliESDVertex * vertexIn = esd->GetVertex();
1049 fVertexName = vertexIn->GetName();
1050 if(fVertexName == "default") fVertexflag = 0;
1052 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
1053 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
1054 if(esdTrack->GetLabel() != 0) fIsSim = kTRUE;
1055 else if(esdTrack->GetLabel() == 0) fIsSim = kFALSE;
1056 UInt_t status = esdTrack->GetStatus();
1058 //select only tracks with ITS refit
1059 if ((status&AliESDtrack::kITSrefit)==0) continue;
1060 //select only tracks with TPC refit
1061 if ((status&AliESDtrack::kTPCrefit)==0) continue;
1063 //select only tracks with the "combined PID"
1064 if ((status&AliESDtrack::kESDpid)==0) continue;
1066 esdTrack->GetPxPyPz(p);
1067 Double_t pt2 = p[0]*p[0]+p[1]*p[1];
1068 Double_t momentum = TMath::Sqrt(pt2+p[2]*p[2]);
1069 Double_t fPt = TMath::Sqrt(pt2);
1074 phimaxPt = esdTrack->Phi();
1075 etamaxPt = esdTrack->Eta();
1078 if(esdTrack->GetSign() > 0) {
1080 if(fPt > fLowPtCut) nCh1GeV++;
1081 if(fPt > fHighPtCut) nCh3GeV++;
1082 if(fPt > fVeryHighPtCut) nCh10GeV++;
1084 if(esdTrack->GetSign() < 0) {
1086 if(fPt > fLowPtCut) nCh1GeV++;
1087 if(fPt > fHighPtCut) nCh3GeV++;
1088 if(fPt > fVeryHighPtCut) nCh10GeV++;
1090 if(esdTrack->GetSign() == 0) nNeutr++;
1094 esdTrack->GetESDpid(prob);
1097 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
1098 if(rcc == 0.0) continue;
1101 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
1104 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
1106 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
1108 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
1110 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
1112 if(fPt > fLowPtCut) nEl1GeV++;
1113 if(fPt > fHighPtCut) nEl3GeV++;
1114 if(fPt > fVeryHighPtCut) nEl10GeV++;
1121 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
1122 // loop over all reconstructed tracks (also first track of combination)
1123 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
1124 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
1125 if (muonTrack == 0x0) continue;
1127 // Coordinates at vertex
1128 fZ = muonTrack->GetZ();
1129 fY = muonTrack->GetBendingCoor();
1130 fX = muonTrack->GetNonBendingCoor();
1132 fThetaX = muonTrack->GetThetaX();
1133 fThetaY = muonTrack->GetThetaY();
1135 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
1136 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
1137 fPxRec = fPzRec * TMath::Tan(fThetaX);
1138 fPyRec = fPzRec * TMath::Tan(fThetaY);
1139 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
1141 //ChiSquare of the track if needed
1142 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
1143 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
1144 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
1146 if (muonTrack->GetMatchTrigger()>0) nFWMatchedMuons++;
1150 if(fEPvector.Pt() > fLowPtCut) {
1152 if(fEPvector.Pt() > fHighPtCut) {
1154 if (fEPvector.Pt() > fVeryHighPtCut) {
1161 // Fill the event tags
1162 if(ntrack != 0) meanPt = meanPt/ntrack;
1164 //AliInfo(Form("====================================="));
1165 //AliInfo(Form("URL: %s - GUID: %s",fturl.Data(),fguid.Data()));
1166 //AliInfo(Form("====================================="));
1168 //First physics data
1169 const AliMultiplicity *spdMult = esd->GetMultiplicity();
1170 evTag->SetNumberOfFiredChipsLayer1(spdMult->GetNumberOfFiredChips(0));
1171 evTag->SetNumberOfFiredChipsLayer2(spdMult->GetNumberOfFiredChips(1));
1172 evTag->SetNumberOfSPDTracklets(spdMult->GetNumberOfTracklets());
1174 AliESDVZERO *vzeroData = esd->GetVZEROData();
1175 evTag->SetMTotV0A(vzeroData->GetMTotV0A());
1176 evTag->SetMTotV0C(vzeroData->GetMTotV0C());
1177 evTag->SetNbPMV0A(vzeroData->GetNbPMV0A());
1178 evTag->SetNbPMV0C(vzeroData->GetNbPMV0C());
1180 //evTag->SetEventId(iEventNumber+1);
1181 evTag->SetPeriodNumber(esd->GetPeriodNumber());
1182 evTag->SetOrbitNumber(esd->GetOrbitNumber());
1183 evTag->SetBunchCrossNumber(esd->GetBunchCrossNumber());
1184 // evTag->SetGUID(fguid);
1185 // if(fSession == "grid") {
1186 // evTag->SetMD5("");
1187 // evTag->SetTURL(fturl);
1188 // evTag->SetSize(0);
1190 // else evTag->SetPath(fturl);
1192 evTag->SetVertexX(vertexIn->GetXv());
1193 evTag->SetVertexY(vertexIn->GetYv());
1194 evTag->SetVertexZ(vertexIn->GetZv());
1195 evTag->SetVertexZError(vertexIn->GetZRes());
1196 evTag->SetVertexFlag(fVertexflag);
1198 evTag->SetT0VertexZ(esd->GetT0zVertex());
1200 evTag->SetTriggerMask(esd->GetTriggerMask());
1201 evTag->SetTriggerCluster(esd->GetTriggerCluster());
1203 evTag->SetEventType(esd->GetEventType());
1204 //*T* evTag->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
1206 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
1207 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
1208 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
1209 evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
1210 evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
1211 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
1213 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
1214 evTag->SetNumOfPosTracks(nPos);
1215 evTag->SetNumOfNegTracks(nNeg);
1216 evTag->SetNumOfNeutrTracks(nNeutr);
1218 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
1219 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
1220 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
1221 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
1223 evTag->SetNumOfProtons(nProtons);
1224 evTag->SetNumOfKaons(nKaons);
1225 evTag->SetNumOfPions(nPions);
1226 evTag->SetNumOfMuons(nMuons);
1227 evTag->SetNumOfFWMuons(nFWMuons);
1228 evTag->SetNumOfFWMatchedMuons(nFWMatchedMuons);
1229 evTag->SetNumOfElectrons(nElectrons);
1230 evTag->SetNumOfPhotons(nGamas);
1231 evTag->SetNumOfPi0s(nPi0s);
1232 evTag->SetNumOfNeutrons(nNeutrons);
1233 evTag->SetNumOfKaon0s(nK0s);
1234 evTag->SetNumOfLambdas(nLambdas);
1236 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1237 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1238 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1239 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1240 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1241 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
1242 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
1243 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
1244 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
1247 evTag->SetNumOfPHOSClusters(esd->GetPHOSClusters(&tmp));
1249 evTag->SetNumOfEMCALClusters(esd->GetEMCALClusters(&tmp));
1251 evTag->SetTotalMomentum(totalP);
1252 evTag->SetMeanPt(meanPt);
1253 evTag->SetMaxPt(maxPt);
1254 evTag->SetEtaMaxPt(etamaxPt);
1255 evTag->SetPhiMaxPt(phimaxPt);
1257 evTag->SetPhysicsFlag(kTRUE);
1258 evTag->SetBackgroungFlag(kFALSE);
1261 void AliESDTagCreator::CreateESDRunTagSummary(TTree *chain)
1263 // Merge all tags from a run into a single RunTag
1264 // with only the File tags
1266 chain->SetBranchAddress("AliTAG", &rtag);
1268 TFile* ftag = TFile::Open("RunTagSummary.tag.root", "recreate");
1270 AliRunTag *tag = new AliRunTag();
1271 TTree * ttag = new TTree("T","A Tree with event tags");
1272 TBranch * btag = ttag->Branch("AliTAG", &tag);
1273 btag->SetCompressionLevel(9);
1275 for (int itag=0; itag<chain->GetEntries(); itag++) {
1276 chain->GetEntry(itag);
1277 tag->CopyStandardContent(rtag);