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();
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 sprintf(fPath,"%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();
282 // if(fSession == "grid") {
283 // TString fturltemp = "alien://"; fturltemp += url->GetFile();
284 // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
286 // else fturl = url->GetFile();
287 fturl = file->GetName();
289 if(fSession == "grid") {
291 nftag->SetTURL(fturl);
295 nftag->SetPath(fturl);
298 nftag->SetTURL(fturl);
302 if (tag->GetFileId(fguid) > -1)
303 AliFatal("Adding a file which is already in the RunTag.");
305 tag->AddFileTag(nftag);
308 tag->SetRunId(iInitRunNumber);
309 // if(fIsSim) tag->SetDataType(0);
310 // else tag->SetDataType(1);
312 // if(fguid != fTempGuid) {
313 // fTempGuid = fguid;
317 if(iEventNumber+1 == chain->GetEntries()) {
318 //AliInfo(Form("File: %s",fturl.Data()));
324 lastEvent = chain->GetEntries();
326 //gSystem->GetMemInfo(meminfo);
327 //AliInfo(Form("After the event and track loop - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
328 //tempmem = meminfo->fMemUsed;
332 //gSystem->GetMemInfo(meminfo);
333 //AliInfo(Form("After the t->Delete - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
334 //tempmem = meminfo->fMemUsed;
341 //gSystem->GetMemInfo(meminfo);
342 //AliInfo(Form("After the file closing - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
343 //tempmem = meminfo->fMemUsed;
348 //gSystem->GetMemInfo(meminfo);
349 //AliInfo(Form("After the delete objects - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
352 //_____________________________________________________________________________
353 void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) {
354 //private method that creates tag files
355 TString fguid = guid;
357 TString fturl = turl;
361 // Double_t fMUONMASS = 0.105658369;
363 // Double_t fX,fY,fZ ;
364 // Double_t fThetaX, fThetaY, fPyz, fChisquare;
365 // Double_t fPxRec, fPyRec, fPzRec, fEnergy;
367 // TLorentzVector fEPvector;
369 // Float_t fLowPtCut = 1.0;
370 // Float_t fHighPtCut = 3.0;
371 // Float_t fVeryHighPtCut = 10.0;
374 // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
376 // Creates the tags for all the events in a given ESD file
377 Bool_t fIsSim = kTRUE;
379 // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
380 // Int_t nPos, nNeg, nNeutr;
381 // Int_t nK0s, nNeutrons, nPi0s, nGamas;
382 // Int_t nCh1GeV, nCh3GeV, nCh10GeV;
383 // Int_t nMu1GeV, nMu3GeV, nMu10GeV;
384 // Int_t nEl1GeV, nEl3GeV, nEl10GeV;
385 // Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
386 // Int_t fVertexflag;
387 Int_t iRunNumber = 0;
388 // TString fVertexName;
391 AliRunTag *tag = new AliRunTag();
392 AliEventTag *evTag = new AliEventTag();
393 TTree * ttag = new TTree("T","A Tree with event tags");
394 TBranch * btag = ttag->Branch("AliTAG", &tag);
395 btag->SetCompressionLevel(9);
396 gSystem->GetMemInfo(meminfo);
397 AliInfo(Form("After the tag initialization - Memory used: %d MB",meminfo->fMemUsed));
398 Int_t tempmem = meminfo->fMemUsed;
400 AliInfo(Form("Creating the ESD tags......."));
402 Int_t firstEvent = 0,lastEvent = 0;
403 TTree *t = (TTree*) file->Get("esdTree");
404 AliESDEvent *esd = new AliESDEvent();
405 esd->ReadFromTree(t);
407 gSystem->GetMemInfo(meminfo);
408 AliInfo(Form("After the esd initialization - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
409 tempmem = meminfo->fMemUsed;
412 Int_t iInitRunNumber = esd->GetRunNumber();
413 tag->SetMagneticField(esd->GetMagneticField());
414 tag->SetBeamEnergy(esd->GetBeamEnergy());
415 tag->SetBeamType(TString(esd->GetBeamType()));
416 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
418 AliFileTag *eftag = new AliFileTag();
420 eftag->SetTURL(fturl);
421 eftag->SetSize(size);
422 tag->AddFileTag(eftag);
424 Int_t iNumberOfEvents = (Int_t)t->GetEntries();
425 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
426 FillEventTag(t, evTag, iEventNumber, esd);
427 iRunNumber = esd->GetRunNumber();
428 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
430 tag->SetRunId(iInitRunNumber);
431 if(fIsSim) tag->SetDataType(0);
432 else tag->SetDataType(1);
433 tag->AddEventTag(*evTag);
435 lastEvent = iNumberOfEvents;
437 gSystem->GetMemInfo(meminfo);
438 AliInfo(Form("After the event and track loop - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
439 tempmem = meminfo->fMemUsed;
442 gSystem->GetMemInfo(meminfo);
443 AliInfo(Form("After the t->Delete - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
444 tempmem = meminfo->fMemUsed;
446 TString localFileName = "Run"; localFileName += tag->GetRunId();
447 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
448 localFileName += ".ESD.tag.root";
453 fileName = localFileName.Data();
454 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
456 else if(fStorage == 1) {
457 TString alienLocation = "/alien";
458 alienLocation += gGrid->Pwd();
459 alienLocation += fgridpath.Data();
460 alienLocation += "/";
461 alienLocation += localFileName;
462 alienLocation += "?se=";
463 alienLocation += fSE.Data();
464 fileName = alienLocation.Data();
465 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
468 TFile* ftag = TFile::Open(fileName, "recreate");
475 gSystem->GetMemInfo(meminfo);
476 AliInfo(Form("After the file closing - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
477 tempmem = meminfo->fMemUsed;
483 gSystem->GetMemInfo(meminfo);
484 AliInfo(Form("After the delete objects - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem));
487 //_____________________________________________________________________________
488 void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) {
489 //private method that creates tag files
493 // Double_t fMUONMASS = 0.105658369;
495 // Double_t fX,fY,fZ ;
496 // Double_t fThetaX, fThetaY, fPyz, fChisquare;
497 // Double_t fPxRec, fPyRec, fPzRec, fEnergy;
499 // TLorentzVector fEPvector;
501 // Float_t fLowPtCut = 1.0;
502 // Float_t fHighPtCut = 3.0;
503 // Float_t fVeryHighPtCut = 10.0;
506 // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
508 // Creates the tags for all the events in a given ESD file
509 // Bool_t fIsSim = kTRUE;
511 // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
512 // Int_t nPos, nNeg, nNeutr;
513 // Int_t nK0s, nNeutrons, nPi0s, nGamas;
514 // Int_t nCh1GeV, nCh3GeV, nCh10GeV;
515 // Int_t nMu1GeV, nMu3GeV, nMu10GeV;
516 // Int_t nEl1GeV, nEl3GeV, nEl10GeV;
517 // Float_t maxPt = .0, etamaxPt = -999, phimaxPt = -999., meanPt = .0, totalP = .0;
518 // Int_t fVertexflag;
519 Int_t iRunNumber = 0;
520 // TString fVertexName;
523 AliRunTag *tag = new AliRunTag();
524 AliEventTag *evTag = new AliEventTag();
525 TTree * ttag = new TTree("T","A Tree with event tags");
526 TBranch * btag = ttag->Branch("AliTAG", &tag);
527 btag->SetCompressionLevel(9);
529 AliInfo(Form("Creating the ESD tags......."));
531 Int_t firstEvent = 0,lastEvent = 0;
533 TTree *t = (TTree*) file->Get("esdTree");
534 AliESDEvent *esd = new AliESDEvent();
535 esd->ReadFromTree(t);
538 Int_t iInitRunNumber = esd->GetRunNumber();
539 tag->SetMagneticField(esd->GetMagneticField());
540 tag->SetBeamEnergy(esd->GetBeamEnergy());
541 tag->SetBeamType(TString(esd->GetBeamType()));
542 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
544 AliFileTag *eftag = new AliFileTag();
545 eftag->SetPath(filepath);
546 eftag->SetTURL(Form("local://%s", filepath));
549 tag->AddFileTag(eftag);
551 Int_t iNumberOfEvents = (Int_t)t->GetEntries();
552 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
553 FillEventTag(t, evTag, iEventNumber, esd);
554 iRunNumber = esd->GetRunNumber();
555 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
556 // evTag->SetPath(filepath);
558 tag->SetRunId(iInitRunNumber);
559 // if(fIsSim) tag->SetDataType(0);
560 // else tag->SetDataType(1);
561 tag->AddEventTag(*evTag);
563 lastEvent = iNumberOfEvents;
567 TString localFileName = "Run"; localFileName += tag->GetRunId();
568 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
569 localFileName += ".ESD.tag.root";
574 fileName = localFileName.Data();
575 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
577 else if(fStorage == 1) {
578 TString alienLocation = "/alien";
579 alienLocation += gGrid->Pwd();
580 alienLocation += fgridpath.Data();
581 alienLocation += "/";
582 alienLocation += localFileName;
583 alienLocation += "?se=";
584 alienLocation += fSE.Data();
585 fileName = alienLocation.Data();
586 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
589 TFile* ftag = TFile::Open(fileName, "recreate");
602 //_____________________________________________________________________________
603 void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRPObject *grpData, ULong_t * qa, Bool_t * es, Int_t qalength, Int_t eslength) {
605 Float_t lhcLuminosity = 0.0;
606 TString lhcState = "test";
607 //UInt_t detectorMask = 0;
608 Int_t detectorMask = 0;
610 detectorMask = grpData->GetDetectorMask();
611 time_t startTime = grpData->GetTimeStart();
612 TTimeStamp t1(startTime);
613 time_t endTime = grpData->GetTimeEnd();
614 TTimeStamp t2(endTime);
615 const char* beamtype = grpData->GetBeamType();
616 Float_t beamenergy = grpData->GetBeamEnergy();
622 // Double_t fMUONMASS = 0.105658369;
624 // Double_t fX,fY,fZ ;
625 // Double_t fThetaX, fThetaY, fPyz, fChisquare;
626 // Double_t fPxRec,fPyRec, fPzRec, fEnergy;
628 // TLorentzVector fEPvector;
630 // Float_t fLowPtCut = 1.0;
631 // Float_t fHighPtCut = 3.0;
632 // Float_t fVeryHighPtCut = 10.0;
635 // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
637 // Creates the tags for all the events in a given ESD file
639 // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
640 // Int_t nPos, nNeg, nNeutr;
641 // Int_t nK0s, nNeutrons, nPi0s, nGamas;
642 // Int_t nCh1GeV, nCh3GeV, nCh10GeV;
643 // Int_t nMu1GeV, nMu3GeV, nMu10GeV;
644 // Int_t nEl1GeV, nEl3GeV, nEl10GeV;
645 // Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
646 // Int_t fVertexflag;
647 Int_t iRunNumber = 0;
648 TString fguid, fmd5, fturl;
649 // TString fVertexName("default");
652 AliInfo(Form("Creating the ESD tags......."));
654 TFile *esdfile = TFile::Open("AliESDs.root");
655 if (!esdfile || !esdfile->IsOpen()) {
656 AliError(Form("opening failed"));
661 TTree *b = (TTree*) esdfile->Get("esdTree");
662 AliESDEvent *esd = new AliESDEvent();
663 esd->ReadFromTree(b);
665 b->GetEntry(fFirstEvent);
666 Int_t iInitRunNumber = esd->GetRunNumber();
668 Int_t iNumberOfEvents = (Int_t)b->GetEntries();
669 if ((fLastEvent == -1) || ((Int_t) b->GetEntries() < fLastEvent))
670 lastEvent = (Int_t)b->GetEntries();
671 else lastEvent = fLastEvent;
674 sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root",
675 iInitRunNumber,fFirstEvent,lastEvent);
676 AliInfo(Form("writing tags to file %s", fileName));
677 AliDebug(1, Form("writing tags to file %s", fileName));
679 TFile* ftag = TFile::Open(fileName, "recreate");
681 AliRunTag *tag = new AliRunTag();
682 AliEventTag *evTag = new AliEventTag();
683 TTree * ttag = new TTree("T","A Tree with event tags");
684 TBranch * btag = ttag->Branch("AliTAG", &tag);
685 btag->SetCompressionLevel(9);
687 if ((fLastEvent != -1) && ((Int_t) b->GetEntries() > fLastEvent))
688 iNumberOfEvents = fLastEvent + 1;
690 AliFileTag *eftag = new AliFileTag();
691 tag->AddFileTag(eftag);
693 for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
694 FillEventTag(b, evTag, iEventNumber, esd);
695 iRunNumber = esd->GetRunNumber();
696 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
698 if (iEventNumber == fFirstEvent) {
699 TFile *file = b->GetCurrentFile();
700 // const TUrl *url = file->GetEndpointUrl();
701 fguid = file->GetUUID().AsString();
703 // if(fStorage == 1) {
704 // TString fturltemp = "alien://"; fturltemp += url->GetFile();
705 // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
707 // else fturl = url->GetFile();
708 fturl = file->GetName();
710 // evTag->SetGUID(fguid);
711 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetGUID(fguid);
713 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetMD5("");
714 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetTURL(fturl);
715 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetSize(0);
718 // evTag->SetPath(fturl);
719 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetPath(fturl);
720 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetMD5("");
721 ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetSize(0);
726 tag->AddEventTag(*evTag);
729 tag->SetLHCTag(lhcLuminosity,lhcState);
730 tag->SetDetectorTag(esd->GetESDRun()->GetDetectorsInDAQ(), esd->GetESDRun()->GetDetectorsInReco());
731 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
733 // Get magnetic field info
736 Float_t l3Current = grpData->GetL3Current((AliGRPObject::Stats)0);
737 if (l3Current == AliGRPObject::GetInvalidFloat()) {
738 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
742 Char_t l3Polarity = grpData->GetL3Polarity();
743 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
744 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
749 Float_t diCurrent = grpData->GetDipoleCurrent((AliGRPObject::Stats)0);
750 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
751 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
755 Char_t diPolarity = grpData->GetDipolePolarity();
756 if (diPolarity == AliGRPObject::GetInvalidChar()) {
757 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
761 if (ok && grpData->IsPolarityConventionLHC()) {
762 if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 1))
763 tag->SetMagneticField(-0.5);
764 if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 0))
765 tag->SetMagneticField(0.5);
766 if (TMath::Abs(l3Current) < 2000.0)
767 tag->SetMagneticField(0.0);
769 if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 1))
770 tag->SetDipoleField(-0.2);
771 if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 0))
772 tag->SetDipoleField(0.2);
773 if (TMath::Abs(diCurrent) < 500.0)
774 tag->SetDipoleField(0.0);
777 tag->SetRunId(iInitRunNumber);
778 tag->SetRunStartTime(t1.GetDate());
779 tag->SetRunStopTime(t2.GetDate());
780 tag->SetBeamEnergy(beamenergy);
781 tag->SetBeamType(beamtype);
784 tag->SetQAArray(qa, qalength) ;
785 tag->SetEventSpecies(es, eslength) ;
800 void AliESDTagCreator::CreateESDTagsFullRun(TTree *chain, AliGRPObject *grpData, ULong_t * qa, Bool_t * es, Int_t qalength, Int_t eslength)
803 Float_t lhcLuminosity = 0.0;
804 TString lhcState = "test";
805 //UInt_t detectorMask = 0;
806 Int_t detectorMask = 0;
808 detectorMask = grpData->GetDetectorMask();
809 time_t startTime = grpData->GetTimeStart();
810 TTimeStamp t1(startTime);
811 time_t endTime = grpData->GetTimeEnd();
812 TTimeStamp t2(endTime);
813 const char* beamtype = grpData->GetBeamType();
814 Float_t beamenergy = grpData->GetBeamEnergy();
816 Int_t iRunNumber = 0;
817 TString fguid, fmd5, fturl;
820 AliInfo(Form("Creating the ESD tags......."));
822 AliESDEvent *esd = new AliESDEvent();
823 esd->ReadFromTree(chain);
826 Int_t iInitRunNumber = esd->GetRunNumber();
828 Int_t iNumberOfEvents = (Int_t)chain->GetEntries();
829 Int_t iFirstEvent = 0;
832 sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root",
833 iInitRunNumber,iFirstEvent,iNumberOfEvents);
834 AliInfo(Form("writing tags to file %s", fileName));
835 AliDebug(1, Form("writing tags to file %s", fileName));
837 TFile* ftag = TFile::Open(fileName, "recreate");
839 AliRunTag *tag = new AliRunTag();
840 AliEventTag *evTag = new AliEventTag();
841 TTree * ttag = new TTree("T","A Tree with event tags");
842 TBranch * btag = ttag->Branch("AliTAG", &tag);
843 btag->SetCompressionLevel(9);
845 // AliFileTag *eftag = new AliFileTag();
846 // tag->AddFileTag(*eftag);
848 for (Int_t iEventNumber = iFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
849 FillEventTag(chain, evTag, iEventNumber, esd);
851 iRunNumber = esd->GetRunNumber();
852 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
854 TFile *file = chain->GetCurrentFile();
855 // const TUrl *url = file->GetName();
856 fguid = file->GetUUID().AsString();
857 fturl = file->GetName();
858 // if(fStorage == 1) {
859 // TString fturltemp = "alien://"; fturltemp += url->GetFile();
860 // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
862 // else fturl = url->GetFile();
864 if (fturl.CompareTo(fturlold)) {
866 AliFileTag *eftag = new AliFileTag();
868 //evTag->SetGUID(fguid);
869 eftag->SetGUID(fguid);
871 // evTag->SetMD5("");
872 // evTag->SetTURL(fturl);
873 // evTag->SetSize(0);
876 eftag->SetTURL(fturl);
880 // evTag->SetPath(fturl);
881 // evTag->SetTURL(fturl);
882 eftag->SetPath(fturl);
883 eftag->SetTURL(fturl);
888 tag->AddFileTag(eftag);
894 // cout << "FileTag found " << fturl.Data() << " " << fturlold.Data() << endl;
897 tag->AddEventTag(*evTag);
900 tag->SetLHCTag(lhcLuminosity,lhcState);
901 tag->SetDetectorTag(esd->GetESDRun()->GetDetectorsInDAQ(), esd->GetESDRun()->GetDetectorsInReco());
902 tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses());
904 // Get magnetic field info
907 Float_t l3Current = grpData->GetL3Current((AliGRPObject::Stats)0);
908 if (l3Current == AliGRPObject::GetInvalidFloat()) {
909 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
913 Char_t l3Polarity = grpData->GetL3Polarity();
914 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
915 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
920 Float_t diCurrent = grpData->GetDipoleCurrent((AliGRPObject::Stats)0);
921 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
922 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
926 Char_t diPolarity = grpData->GetDipolePolarity();
927 if (diPolarity == AliGRPObject::GetInvalidChar()) {
928 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
932 if (ok && grpData->IsPolarityConventionLHC()) {
933 if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 1))
934 tag->SetMagneticField(-0.5);
935 if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 0))
936 tag->SetMagneticField(0.5);
937 if (TMath::Abs(l3Current) < 2000.0)
938 tag->SetMagneticField(0.0);
940 if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 1))
941 tag->SetDipoleField(-0.2);
942 if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 0))
943 tag->SetDipoleField(0.2);
944 if (TMath::Abs(diCurrent) < 500.0)
945 tag->SetDipoleField(0.0);
948 tag->SetRunId(iInitRunNumber);
949 tag->SetRunStartTime(t1.GetDate());
950 tag->SetRunStopTime(t2.GetDate());
951 tag->SetBeamEnergy(beamenergy);
952 tag->SetBeamType(beamtype);
955 tag->SetQAArray(qa, qalength) ;
956 tag->SetEventSpecies(es, eslength) ;
969 //_____________________________________________________________________________
970 void AliESDTagCreator::SwitchOffBranches() const {
972 // Switch of branches on user request
973 TObjArray * tokens = fBranches.Tokenize(" ");
974 Int_t ntok = tokens->GetEntries();
975 for (Int_t i = 0; i < ntok; i++) {
976 TString str = ((TObjString*) tokens->At(i))->GetString();
977 fChain->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
978 AliInfo(Form("Branch %s switched off \n", str.Data()));
982 //_____________________________________________________________________________
983 void AliESDTagCreator::FillEventTag(TTree *chain, AliEventTag *evTag, Int_t iEventNumber, AliESDEvent *esd)
985 // Fill the event specific information in the EventTag
986 AliESD *esdold = 0x0;
993 Double_t fMUONMASS = 0.105658369;
996 Double_t fThetaX, fThetaY, fPyz, fChisquare;
997 Double_t fPxRec, fPyRec, fPzRec, fEnergy;
999 TLorentzVector fEPvector;
1001 Float_t fLowPtCut = 1.0;
1002 Float_t fHighPtCut = 3.0;
1003 Float_t fVeryHighPtCut = 10.0;
1006 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
1008 // Creates the tags for all the events in a given ESD file
1009 Bool_t fIsSim = kTRUE;
1011 Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons;
1012 Int_t nPos, nNeg, nNeutr;
1013 Int_t nK0s, nLambdas, nNeutrons, nPi0s, nGamas;
1014 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
1015 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
1016 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
1017 Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
1019 TString fVertexName;
1023 ntrack = 0; nPos = 0; nNeg = 0; nNeutr =0;
1024 nK0s = 0; nLambdas = 0; nNeutrons = 0; nPi0s = 0;
1025 nGamas = 0; nProtons = 0; nKaons = 0;
1026 nPions = 0; nMuons = 0; nElectrons = 0; nFWMuons = 0; nFWMatchedMuons = 0;
1027 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
1028 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
1029 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
1030 maxPt = .0; etamaxPt = -999.; phimaxPt = -999.; meanPt = .0; totalP = .0;
1033 chain->GetEntry(iEventNumber);
1034 esdold = esd->GetAliESDOld();
1035 if(esdold) esd->CopyFromOldESD();
1037 // TFile *file = chain->GetFile();
1038 // const TUrl *url = file->GetEndpointUrl();
1039 // fguid = file->GetUUID().AsString();
1040 // if(fSession == "grid") {
1041 // TString fturltemp = "alien://"; fturltemp += url->GetFile();
1042 // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
1044 // else fturl = url->GetFile();
1046 const AliESDVertex * vertexIn = esd->GetVertex();
1047 fVertexName = vertexIn->GetName();
1048 if(fVertexName == "default") fVertexflag = 0;
1050 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
1051 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
1052 if(esdTrack->GetLabel() != 0) fIsSim = kTRUE;
1053 else if(esdTrack->GetLabel() == 0) fIsSim = kFALSE;
1054 UInt_t status = esdTrack->GetStatus();
1056 //select only tracks with ITS refit
1057 if ((status&AliESDtrack::kITSrefit)==0) continue;
1058 //select only tracks with TPC refit
1059 if ((status&AliESDtrack::kTPCrefit)==0) continue;
1061 //select only tracks with the "combined PID"
1062 if ((status&AliESDtrack::kESDpid)==0) continue;
1064 esdTrack->GetPxPyPz(p);
1065 Double_t pt2 = p[0]*p[0]+p[1]*p[1];
1066 Double_t momentum = TMath::Sqrt(pt2+p[2]*p[2]);
1067 Double_t fPt = TMath::Sqrt(pt2);
1072 phimaxPt = esdTrack->Phi();
1073 etamaxPt = esdTrack->Eta();
1076 if(esdTrack->GetSign() > 0) {
1078 if(fPt > fLowPtCut) nCh1GeV++;
1079 if(fPt > fHighPtCut) nCh3GeV++;
1080 if(fPt > fVeryHighPtCut) nCh10GeV++;
1082 if(esdTrack->GetSign() < 0) {
1084 if(fPt > fLowPtCut) nCh1GeV++;
1085 if(fPt > fHighPtCut) nCh3GeV++;
1086 if(fPt > fVeryHighPtCut) nCh10GeV++;
1088 if(esdTrack->GetSign() == 0) nNeutr++;
1092 esdTrack->GetESDpid(prob);
1095 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
1096 if(rcc == 0.0) continue;
1099 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
1102 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
1104 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
1106 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
1108 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
1110 if(fPt > fLowPtCut) nEl1GeV++;
1111 if(fPt > fHighPtCut) nEl3GeV++;
1112 if(fPt > fVeryHighPtCut) nEl10GeV++;
1119 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
1120 // loop over all reconstructed tracks (also first track of combination)
1121 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
1122 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
1123 if (muonTrack == 0x0) continue;
1125 // Coordinates at vertex
1126 fZ = muonTrack->GetZ();
1127 fY = muonTrack->GetBendingCoor();
1128 fX = muonTrack->GetNonBendingCoor();
1130 fThetaX = muonTrack->GetThetaX();
1131 fThetaY = muonTrack->GetThetaY();
1133 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
1134 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
1135 fPxRec = fPzRec * TMath::Tan(fThetaX);
1136 fPyRec = fPzRec * TMath::Tan(fThetaY);
1137 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
1139 //ChiSquare of the track if needed
1140 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
1141 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
1142 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
1144 if (muonTrack->GetMatchTrigger()>0) nFWMatchedMuons++;
1148 if(fEPvector.Pt() > fLowPtCut) {
1150 if(fEPvector.Pt() > fHighPtCut) {
1152 if (fEPvector.Pt() > fVeryHighPtCut) {
1159 // Fill the event tags
1160 if(ntrack != 0) meanPt = meanPt/ntrack;
1162 //AliInfo(Form("====================================="));
1163 //AliInfo(Form("URL: %s - GUID: %s",fturl.Data(),fguid.Data()));
1164 //AliInfo(Form("====================================="));
1166 //First physics data
1167 const AliMultiplicity *spdMult = esd->GetMultiplicity();
1168 evTag->SetNumberOfFiredChipsLayer1(spdMult->GetNumberOfFiredChips(0));
1169 evTag->SetNumberOfFiredChipsLayer2(spdMult->GetNumberOfFiredChips(1));
1170 evTag->SetNumberOfSPDTracklets(spdMult->GetNumberOfTracklets());
1172 AliESDVZERO *vzeroData = esd->GetVZEROData();
1173 evTag->SetMTotV0A(vzeroData->GetMTotV0A());
1174 evTag->SetMTotV0C(vzeroData->GetMTotV0C());
1175 evTag->SetNbPMV0A(vzeroData->GetNbPMV0A());
1176 evTag->SetNbPMV0C(vzeroData->GetNbPMV0C());
1178 //evTag->SetEventId(iEventNumber+1);
1179 evTag->SetPeriodNumber(esd->GetPeriodNumber());
1180 evTag->SetOrbitNumber(esd->GetOrbitNumber());
1181 evTag->SetBunchCrossNumber(esd->GetBunchCrossNumber());
1182 // evTag->SetGUID(fguid);
1183 // if(fSession == "grid") {
1184 // evTag->SetMD5("");
1185 // evTag->SetTURL(fturl);
1186 // evTag->SetSize(0);
1188 // else evTag->SetPath(fturl);
1190 evTag->SetVertexX(vertexIn->GetXv());
1191 evTag->SetVertexY(vertexIn->GetYv());
1192 evTag->SetVertexZ(vertexIn->GetZv());
1193 evTag->SetVertexZError(vertexIn->GetZRes());
1194 evTag->SetVertexFlag(fVertexflag);
1196 evTag->SetT0VertexZ(esd->GetT0zVertex());
1198 evTag->SetTriggerMask(esd->GetTriggerMask());
1199 evTag->SetTriggerCluster(esd->GetTriggerCluster());
1201 evTag->SetEventType(esd->GetEventType());
1202 //*T* evTag->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
1204 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
1205 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
1206 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
1207 evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
1208 evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
1209 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
1211 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
1212 evTag->SetNumOfPosTracks(nPos);
1213 evTag->SetNumOfNegTracks(nNeg);
1214 evTag->SetNumOfNeutrTracks(nNeutr);
1216 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
1217 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
1218 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
1219 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
1221 evTag->SetNumOfProtons(nProtons);
1222 evTag->SetNumOfKaons(nKaons);
1223 evTag->SetNumOfPions(nPions);
1224 evTag->SetNumOfMuons(nMuons);
1225 evTag->SetNumOfFWMuons(nFWMuons);
1226 evTag->SetNumOfFWMatchedMuons(nFWMatchedMuons);
1227 evTag->SetNumOfElectrons(nElectrons);
1228 evTag->SetNumOfPhotons(nGamas);
1229 evTag->SetNumOfPi0s(nPi0s);
1230 evTag->SetNumOfNeutrons(nNeutrons);
1231 evTag->SetNumOfKaon0s(nK0s);
1232 evTag->SetNumOfLambdas(nLambdas);
1234 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1235 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1236 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1237 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1238 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1239 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
1240 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
1241 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
1242 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
1245 evTag->SetNumOfPHOSClusters(esd->GetPHOSClusters(&tmp));
1247 evTag->SetNumOfEMCALClusters(esd->GetEMCALClusters(&tmp));
1249 evTag->SetTotalMomentum(totalP);
1250 evTag->SetMeanPt(meanPt);
1251 evTag->SetMaxPt(maxPt);
1252 evTag->SetEtaMaxPt(etamaxPt);
1253 evTag->SetPhiMaxPt(phimaxPt);
1255 evTag->SetPhysicsFlag(kTRUE);
1256 evTag->SetBackgroungFlag(kFALSE);
1259 void AliESDTagCreator::CreateESDRunTagSummary(TTree *chain)
1261 // Merge all tags from a run into a single RunTag
1262 // with only the File tags
1264 chain->SetBranchAddress("AliTAG", &rtag);
1266 TFile* ftag = TFile::Open("RunTagSummary.tag.root", "recreate");
1268 AliRunTag *tag = new AliRunTag();
1269 TTree * ttag = new TTree("T","A Tree with event tags");
1270 TBranch * btag = ttag->Branch("AliTAG", &tag);
1271 btag->SetCompressionLevel(9);
1273 for (int itag=0; itag<chain->GetEntries(); itag++) {
1274 chain->GetEntry(itag);
1275 tag->CopyStandardContent(rtag);