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 // AliTagCreator 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 //-----------------------------------------------------------------
31 #include <TGridResult.h>
34 #include "AliRunTag.h"
35 #include "AliEventTag.h"
37 #include "AliESDVertex.h"
41 #include "AliTagCreator.h"
44 ClassImp(AliTagCreator)
47 //______________________________________________________________________________
48 AliTagCreator::AliTagCreator() //local mode
50 //==============Default constructor for a AliTagCreator==================
56 //______________________________________________________________________________
57 AliTagCreator::~AliTagCreator()
59 //================Default destructor for a AliTagCreator=======================
62 //______________________________________________________________________________
63 void AliTagCreator::SetStorage(Int_t storage)
65 // Sets correctly the storage: 0 for local, 1 for GRID
68 AliInfo(Form("Tags will be stored locally...."));
70 AliInfo(Form("Tags will be stored in the grid...."));
71 if((fStorage != 0)&&(fStorage != 1))
73 AliInfo(Form("Storage was not properly set!!!"));
79 //______________________________________________________________________________
80 Bool_t AliTagCreator::ReadESDCollection(TGridResult *fresult)
82 // Reads the entry of the TGridResult and creates the tags
83 Int_t nEntries = fresult->GetEntries();
92 for(Int_t i = 0; i < nEntries; i++)
94 alienUrl = fresult->GetKey(i,"turl");
95 guid = fresult->GetKey(i,"guid");
96 if(fresult->GetKey(i,"size"))
97 size = atol (fresult->GetKey(i,"size"));
98 md5 = fresult->GetKey(i,"md5");
99 turl = fresult->GetKey(i,"turl");
100 if(md5 && !strlen(guid))
102 if(guid && !strlen(guid))
105 TFile *f = TFile::Open(alienUrl,"READ");
106 CreateTag(f,guid,md5,turl,size,counter);
115 //__________________________________________________________________________
116 Bool_t AliTagCreator::MergeTags()
118 //Merges the tags and stores the merged tag file
119 //locally if fStorage=0 or in the grid if fStorage=1
120 AliInfo(Form("Merging tags....."));
121 TChain *fgChain = new TChain("T");
124 const char * tagPattern = "tag";
125 // Open the working directory
126 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
127 const char * name = 0x0;
128 // Add all files matching *pattern* to the chain
129 while((name = gSystem->GetDirEntry(dirp))) {
130 if (strstr(name,tagPattern))
133 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
136 else if(fStorage == 1) {
137 TString alienLocation = gGrid->Pwd();
138 alienLocation += fgridpath.Data();
139 alienLocation += "/";
141 TGridResult *tagresult = gGrid->Query(alienLocation,"*tag.root","","");
142 Int_t nEntries = tagresult->GetEntries();
143 for(Int_t i = 0; i < nEntries; i++) {
144 TString alienUrl = tagresult->GetKey(i,"turl");
145 fgChain->Add(alienUrl);
147 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
150 AliRunTag *tag = new AliRunTag;
151 AliEventTag *evTag = new AliEventTag;
152 fgChain->SetBranchAddress("AliTAG",&tag);
154 //Defining new tag objects
155 AliRunTag *newTag = new AliRunTag();
156 TTree ttag("T","A Tree with event tags");
157 TBranch * btag = ttag.Branch("AliTAG", &newTag);
158 btag->SetCompressionLevel(9);
159 for(Int_t iTagFiles = 0; iTagFiles < fgChain->GetEntries(); iTagFiles++) {
160 fgChain->GetEntry(iTagFiles);
161 newTag->SetRunId(tag->GetRunId());
162 const TClonesArray *tagList = tag->GetEventTags();
163 for(Int_t j = 0; j < tagList->GetEntries(); j++) {
164 evTag = (AliEventTag *) tagList->At(j);
165 newTag->AddEventTag(*evTag);
171 TString localFileName = "Run"; localFileName += tag->GetRunId();
172 localFileName += ".Merged"; localFileName += ".ESD.tag.root";
174 TString alienFileName = "/alien";
175 alienFileName += gGrid->Pwd();
176 alienFileName += fgridpath.Data();
177 alienFileName += "/";
178 alienFileName += localFileName;
179 alienFileName += "?se=";
180 alienFileName += fSE.Data();
182 TString filename = 0x0;
185 filename = localFileName.Data();
186 AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
189 filename = alienFileName.Data();
190 AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
193 TFile* ftag = TFile::Open(filename, "recreate");
205 //_____________________________________________________________________________
206 void AliTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter)
208 // Creates the tags for all the events in a given ESD file
210 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
211 Int_t nPos, nNeg, nNeutr;
212 Int_t nK0s, nNeutrons, nPi0s, nGamas;
213 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
214 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
215 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
216 Float_t maxPt = .0, meanPt = .0, totalP = .0;
218 AliRunTag *tag = new AliRunTag();
219 AliEventTag *evTag = new AliEventTag();
220 TTree ttag("T","A Tree with event tags");
221 TBranch * btag = ttag.Branch("AliTAG", &tag);
222 btag->SetCompressionLevel(9);
224 AliInfo(Form("Creating the tags......."));
226 Int_t firstEvent = 0,lastEvent = 0;
227 TTree *t = (TTree*) file->Get("esdTree");
228 TBranch * b = t->GetBranch("ESD");
232 tag->SetRunId(esd->GetRunNumber());
234 Int_t iNumberOfEvents = b->GetEntries();
235 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++)
263 b->GetEntry(iEventNumber);
264 const AliESDVertex * vertexIn = esd->GetVertex();
266 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++)
268 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
269 UInt_t status = esdTrack->GetStatus();
271 //select only tracks with ITS refit
272 if ((status&AliESDtrack::kITSrefit)==0) continue;
274 //select only tracks with TPC refit-->remove extremely high Pt tracks
275 if ((status&AliESDtrack::kTPCrefit)==0) continue;
277 //select only tracks with the "combined PID"
278 if ((status&AliESDtrack::kESDpid)==0) continue;
280 esdTrack->GetPxPyPz(p);
281 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
282 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
288 if(esdTrack->GetSign() > 0)
298 if(esdTrack->GetSign() < 0)
308 if(esdTrack->GetSign() == 0)
313 esdTrack->GetESDpid(prob);
316 if ((prob[8]>prob[7])&&(prob[8]>prob[6])&&(prob[8]>prob[5])&&(prob[8]>prob[4])&&(prob[8]>prob[3])&&(prob[8]>prob[2])&&(prob[8]>prob[1])&&(prob[8]>prob[0]))
319 if ((prob[7]>prob[8])&&(prob[7]>prob[6])&&(prob[7]>prob[5])&&(prob[7]>prob[4])&&(prob[7]>prob[3])&&(prob[7]>prob[2])&&(prob[7]>prob[1])&&(prob[7]>prob[0]))
322 if ((prob[6]>prob[8])&&(prob[6]>prob[7])&&(prob[6]>prob[5])&&(prob[6]>prob[4])&&(prob[6]>prob[3])&&(prob[6]>prob[2])&&(prob[6]>prob[1])&&(prob[6]>prob[0]))
325 if ((prob[5]>prob[8])&&(prob[5]>prob[7])&&(prob[5]>prob[6])&&(prob[5]>prob[4])&&(prob[5]>prob[3])&&(prob[5]>prob[2])&&(prob[5]>prob[1])&&(prob[5]>prob[0]))
328 if ((prob[4]>prob[8])&&(prob[4]>prob[7])&&(prob[4]>prob[6])&&(prob[4]>prob[5])&&(prob[4]>prob[3])&&(prob[4]>prob[2])&&(prob[4]>prob[1])&&(prob[4]>prob[0]))
331 if ((prob[3]>prob[8])&&(prob[3]>prob[7])&&(prob[3]>prob[6])&&(prob[3]>prob[5])&&(prob[3]>prob[4])&&(prob[3]>prob[2])&&(prob[3]>prob[1])&&(prob[3]>prob[0]))
334 if ((prob[2]>prob[8])&&(prob[2]>prob[7])&&(prob[2]>prob[6])&&(prob[2]>prob[5])&&(prob[2]>prob[4])&&(prob[2]>prob[3])&&(prob[2]>prob[1])&&(prob[2]>prob[0]))
337 if ((prob[1]>prob[8])&&(prob[1]>prob[7])&&(prob[1]>prob[6])&&(prob[1]>prob[5])&&(prob[1]>prob[4])&&(prob[1]>prob[3])&&(prob[1]>prob[2])&&(prob[1]>prob[0]))
348 if ((prob[0]>prob[8])&&(prob[0]>prob[7])&&(prob[0]>prob[6])&&(prob[0]>prob[5])&&(prob[0]>prob[4])&&(prob[0]>prob[3])&&(prob[0]>prob[2])&&(prob[0]>prob[1]))
360 // Fill the event tags
362 meanPt = meanPt/ntrack;
364 evTag->SetEventId(iEventNumber+1);
365 evTag->SetGUID(guid);
367 evTag->SetTURL(turl);
368 evTag->SetSize(size);
369 evTag->SetVertexX(vertexIn->GetXv());
370 evTag->SetVertexY(vertexIn->GetYv());
371 evTag->SetVertexZ(vertexIn->GetZv());
373 evTag->SetT0VertexZ(esd->GetT0zVertex());
375 evTag->SetTrigger(esd->GetTrigger());
377 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
378 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
379 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
380 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
383 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
384 evTag->SetNumOfPosTracks(nPos);
385 evTag->SetNumOfNegTracks(nNeg);
386 evTag->SetNumOfNeutrTracks(nNeutr);
388 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
389 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
390 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
391 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
393 evTag->SetNumOfProtons(nProtons);
394 evTag->SetNumOfKaons(nKaons);
395 evTag->SetNumOfPions(nPions);
396 evTag->SetNumOfMuons(nMuons);
397 evTag->SetNumOfElectrons(nElectrons);
398 evTag->SetNumOfPhotons(nGamas);
399 evTag->SetNumOfPi0s(nPi0s);
400 evTag->SetNumOfNeutrons(nNeutrons);
401 evTag->SetNumOfKaon0s(nK0s);
403 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
404 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
405 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
406 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
407 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
408 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
409 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
410 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
411 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
413 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
414 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
416 evTag->SetTotalMomentum(totalP);
417 evTag->SetMeanPt(meanPt);
418 evTag->SetMaxPt(maxPt);
420 tag->AddEventTag(*evTag);
422 lastEvent = iNumberOfEvents;
429 TString localFileName = "Run"; localFileName += tag->GetRunId();
430 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
431 localFileName += ".ESD.tag.root";
433 TString alienLocation = "/alien";
434 alienLocation += gGrid->Pwd();
435 alienLocation += fgridpath.Data();
436 alienLocation += "/";
437 alienLocation += localFileName;
438 alienLocation += "?se=";
439 alienLocation += fSE.Data();
445 fileName = localFileName.Data();
446 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
450 fileName = alienLocation.Data();
451 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
454 TFile* ftag = TFile::Open(fileName, "recreate");