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 //-----------------------------------------------------------------
28 #include <TLorentzVector.h>
32 #include <TGridResult.h>
35 #include "AliRunTag.h"
36 #include "AliEventTag.h"
38 #include "AliESDVertex.h"
42 #include "AliTagCreator.h"
45 ClassImp(AliTagCreator)
48 //______________________________________________________________________________
49 AliTagCreator::AliTagCreator() //local mode
51 //==============Default constructor for a AliTagCreator==================
57 //______________________________________________________________________________
58 AliTagCreator::~AliTagCreator()
60 //================Default destructor for a AliTagCreator=======================
63 //______________________________________________________________________________
64 void AliTagCreator::SetStorage(Int_t storage)
66 // Sets correctly the storage: 0 for local, 1 for GRID
69 AliInfo(Form("Tags will be stored locally...."));
71 AliInfo(Form("Tags will be stored in the grid...."));
72 if((fStorage != 0)&&(fStorage != 1))
74 AliInfo(Form("Storage was not properly set!!!"));
80 //______________________________________________________________________________
81 Bool_t AliTagCreator::ReadESDCollection(TGridResult *fresult)
83 // Reads the entry of the TGridResult and creates the tags
84 Int_t nEntries = fresult->GetEntries();
93 for(Int_t i = 0; i < nEntries; i++)
95 alienUrl = fresult->GetKey(i,"turl");
96 guid = fresult->GetKey(i,"guid");
97 if(fresult->GetKey(i,"size"))
98 size = atol (fresult->GetKey(i,"size"));
99 md5 = fresult->GetKey(i,"md5");
100 turl = fresult->GetKey(i,"turl");
101 if(md5 && !strlen(guid))
103 if(guid && !strlen(guid))
106 TFile *f = TFile::Open(alienUrl,"READ");
107 CreateTag(f,guid,md5,turl,size,counter);
116 //__________________________________________________________________________
117 Bool_t AliTagCreator::MergeTags()
119 //Merges the tags and stores the merged tag file
120 //locally if fStorage=0 or in the grid if fStorage=1
121 AliInfo(Form("Merging tags....."));
122 TChain *fgChain = new TChain("T");
125 const char * tagPattern = "tag";
126 // Open the working directory
127 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
128 const char * name = 0x0;
129 // Add all files matching *pattern* to the chain
130 while((name = gSystem->GetDirEntry(dirp))) {
131 if (strstr(name,tagPattern))
134 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
137 else if(fStorage == 1) {
138 TString alienLocation = gGrid->Pwd();
139 alienLocation += fgridpath.Data();
140 alienLocation += "/";
142 TGridResult *tagresult = gGrid->Query(alienLocation,"*tag.root","","");
143 Int_t nEntries = tagresult->GetEntries();
144 for(Int_t i = 0; i < nEntries; i++) {
145 TString alienUrl = tagresult->GetKey(i,"turl");
146 fgChain->Add(alienUrl);
148 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
151 AliRunTag *tag = new AliRunTag;
152 AliEventTag *evTag = new AliEventTag;
153 fgChain->SetBranchAddress("AliTAG",&tag);
155 //Defining new tag objects
156 AliRunTag *newTag = new AliRunTag();
157 TTree ttag("T","A Tree with event tags");
158 TBranch * btag = ttag.Branch("AliTAG", &newTag);
159 btag->SetCompressionLevel(9);
160 for(Int_t iTagFiles = 0; iTagFiles < fgChain->GetEntries(); iTagFiles++) {
161 fgChain->GetEntry(iTagFiles);
162 newTag->SetRunId(tag->GetRunId());
163 const TClonesArray *tagList = tag->GetEventTags();
164 for(Int_t j = 0; j < tagList->GetEntries(); j++) {
165 evTag = (AliEventTag *) tagList->At(j);
166 newTag->AddEventTag(*evTag);
172 TString localFileName = "Run"; localFileName += tag->GetRunId();
173 localFileName += ".Merged"; localFileName += ".ESD.tag.root";
175 TString alienFileName = "/alien";
176 alienFileName += gGrid->Pwd();
177 alienFileName += fgridpath.Data();
178 alienFileName += "/";
179 alienFileName += localFileName;
180 alienFileName += "?se=";
181 alienFileName += fSE.Data();
183 TString filename = 0x0;
186 filename = localFileName.Data();
187 AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
190 filename = alienFileName.Data();
191 AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
194 TFile* ftag = TFile::Open(filename, "recreate");
206 //_____________________________________________________________________________
207 void AliTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter)
212 Double_t MUON_MASS = 0.105658369;
215 Double_t ThetaX, ThetaY, Pyz,Chisquare;
216 Double_t PxRec,PyRec, PzRec, Energy;
218 TLorentzVector EPvector;
220 Float_t ZVertexCut = 10.0;
221 Float_t RhoVertexCut = 2.0;
223 Float_t LowPtCut = 1.0;
224 Float_t HighPtCut = 3.0;
225 Float_t VeryHighPtCut = 10.0;
228 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
230 // Creates the tags for all the events in a given ESD file
232 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
233 Int_t nPos, nNeg, nNeutr;
234 Int_t nK0s, nNeutrons, nPi0s, nGamas;
235 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
236 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
237 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
238 Float_t maxPt = .0, meanPt = .0, totalP = .0;
240 AliRunTag *tag = new AliRunTag();
241 AliEventTag *evTag = new AliEventTag();
242 TTree ttag("T","A Tree with event tags");
243 TBranch * btag = ttag.Branch("AliTAG", &tag);
244 btag->SetCompressionLevel(9);
246 AliInfo(Form("Creating the tags......."));
248 Int_t firstEvent = 0,lastEvent = 0;
249 TTree *t = (TTree*) file->Get("esdTree");
250 TBranch * b = t->GetBranch("ESD");
254 tag->SetRunId(esd->GetRunNumber());
256 Int_t iNumberOfEvents = b->GetEntries();
257 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
284 b->GetEntry(iEventNumber);
285 const AliESDVertex * vertexIn = esd->GetVertex();
287 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
288 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
289 UInt_t status = esdTrack->GetStatus();
291 //select only tracks with ITS refit
292 if ((status&AliESDtrack::kITSrefit)==0) continue;
293 //select only tracks with TPC refit
294 if ((status&AliESDtrack::kTPCrefit)==0) continue;
296 //select only tracks with the "combined PID"
297 if ((status&AliESDtrack::kESDpid)==0) continue;
299 esdTrack->GetPxPyPz(p);
300 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
301 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
304 if(fPt > maxPt) maxPt = fPt;
306 if(esdTrack->GetSign() > 0) {
308 if(fPt > LowPtCut) nCh1GeV++;
309 if(fPt > HighPtCut) nCh3GeV++;
310 if(fPt > VeryHighPtCut) nCh10GeV++;
312 if(esdTrack->GetSign() < 0) {
314 if(fPt > LowPtCut) nCh1GeV++;
315 if(fPt > HighPtCut) nCh3GeV++;
316 if(fPt > VeryHighPtCut) nCh10GeV++;
318 if(esdTrack->GetSign() == 0) nNeutr++;
322 esdTrack->GetESDpid(prob);
325 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
326 if(rcc == 0.0) continue;
329 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
332 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
334 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
336 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
338 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
340 if(fPt > LowPtCut) nEl1GeV++;
341 if(fPt > HighPtCut) nEl3GeV++;
342 if(fPt > VeryHighPtCut) nEl10GeV++;
350 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
351 // loop over all reconstructed tracks (also first track of combination)
352 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
353 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
354 if (muonTrack == 0x0) continue;
356 // Coordinates at vertex
357 Z = muonTrack->GetZ();
358 Y = muonTrack->GetBendingCoor();
359 X = muonTrack->GetNonBendingCoor();
361 ThetaX = muonTrack->GetThetaX();
362 ThetaY = muonTrack->GetThetaY();
364 Pyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
365 PzRec = - Pyz / TMath::Sqrt(1.0 + TMath::Tan(ThetaY)*TMath::Tan(ThetaY));
366 PxRec = PzRec * TMath::Tan(ThetaX);
367 PyRec = PzRec * TMath::Tan(ThetaY);
368 Charge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
370 //ChiSquare of the track if needed
371 Chisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
372 Energy = TMath::Sqrt(MUON_MASS * MUON_MASS + PxRec * PxRec + PyRec * PyRec + PzRec * PzRec);
373 EPvector.SetPxPyPzE(PxRec, PyRec, PzRec, Energy);
375 // total number of muons inside a vertex cut
376 if((TMath::Abs(Z)<ZVertexCut) && (TMath::Sqrt(Y*Y+X*X)<RhoVertexCut)) {
378 if(EPvector.Pt() > LowPtCut) {
380 if(EPvector.Pt() > HighPtCut) {
382 if (EPvector.Pt() > VeryHighPtCut) {
390 // Fill the event tags
392 meanPt = meanPt/ntrack;
394 evTag->SetEventId(iEventNumber+1);
395 evTag->SetGUID(guid);
397 evTag->SetTURL(turl);
398 evTag->SetSize(size);
399 evTag->SetVertexX(vertexIn->GetXv());
400 evTag->SetVertexY(vertexIn->GetYv());
401 evTag->SetVertexZ(vertexIn->GetZv());
403 evTag->SetT0VertexZ(esd->GetT0zVertex());
405 evTag->SetTrigger(esd->GetTrigger());
407 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
408 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
409 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
410 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
413 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
414 evTag->SetNumOfPosTracks(nPos);
415 evTag->SetNumOfNegTracks(nNeg);
416 evTag->SetNumOfNeutrTracks(nNeutr);
418 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
419 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
420 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
421 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
423 evTag->SetNumOfProtons(nProtons);
424 evTag->SetNumOfKaons(nKaons);
425 evTag->SetNumOfPions(nPions);
426 evTag->SetNumOfMuons(nMuons);
427 evTag->SetNumOfElectrons(nElectrons);
428 evTag->SetNumOfPhotons(nGamas);
429 evTag->SetNumOfPi0s(nPi0s);
430 evTag->SetNumOfNeutrons(nNeutrons);
431 evTag->SetNumOfKaon0s(nK0s);
433 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
434 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
435 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
436 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
437 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
438 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
439 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
440 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
441 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
443 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
444 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
446 evTag->SetTotalMomentum(totalP);
447 evTag->SetMeanPt(meanPt);
448 evTag->SetMaxPt(maxPt);
450 tag->AddEventTag(*evTag);
452 lastEvent = iNumberOfEvents;
459 TString localFileName = "Run"; localFileName += tag->GetRunId();
460 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
461 localFileName += ".ESD.tag.root";
463 TString alienLocation = "/alien";
464 alienLocation += gGrid->Pwd();
465 alienLocation += fgridpath.Data();
466 alienLocation += "/";
467 alienLocation += localFileName;
468 alienLocation += "?se=";
469 alienLocation += fSE.Data();
475 fileName = localFileName.Data();
476 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
480 fileName = alienLocation.Data();
481 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
484 TFile* ftag = TFile::Open(fileName, "recreate");