1 /**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
5 * Permission to use, copy, modify and distribute this software and its *
6 * documentation strictly for non-commercial purposes is hereby granted *
7 * without fee, provided that the above copyright notice appears in all *
8 * copies and that both the copyright notice and this permission notice *
9 * appear in the supporting documentation. The authors make no claims *
10 * about the suitability of this software for any purpose. It is *
11 * provided "as is" without express or implied warranty. *
12 **************************************************************************/
16 //-----------------------------------------------------------------
17 // AliAODTagCreator class
18 // This is the class to deal with the tag creation (post process)
19 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
20 //-----------------------------------------------------------------
23 #include <Riostream.h>
29 #include <TLorentzVector.h>
30 #include <TRefArray.h>
34 #include <TGridResult.h>
37 #include "AliRunTag.h"
38 #include "AliEventTag.h"
39 #include "AliFileTag.h"
41 #include "AliAODEvent.h"
42 #include "AliAODVertex.h"
45 #include "AliAODTagCreator.h"
48 ClassImp(AliAODTagCreator)
51 //______________________________________________________________________________
52 AliAODTagCreator::AliAODTagCreator() :
61 //==============Default constructor for a AliAODTagCreator================
64 //______________________________________________________________________________
65 AliAODTagCreator::~AliAODTagCreator() {
66 //================Default destructor for a AliAODTagCreator===================
71 //______________________________________________________________________________
72 Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) {
73 // Reads the entry of the TGridResult and creates the tags
74 Int_t nEntries = fresult->GetEntries();
82 fChain = new TChain("aodTree");
84 for(Int_t i = 0; i < nEntries; i++) {
85 alienUrl = fresult->GetKey(i,"turl");
86 guid = fresult->GetKey(i,"guid");
87 if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size"));
88 md5 = fresult->GetKey(i,"md5");
89 turl = fresult->GetKey(i,"turl");
90 if(md5 && !strlen(guid)) md5 = 0;
91 if(guid && !strlen(guid)) guid = 0;
93 fChain->Add(alienUrl);
96 AliInfo(Form("AOD chain created......."));
97 AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));
99 CreateTag(fChain, "grid");
104 //______________________________________________________________________________
105 Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath, const char* pattern) {
106 // Checks the different subdirs of the given local path and in the
107 // case where it finds an AliAOD.root file it creates the tags
109 void *dira = gSystem->OpenDirectory(localpath);
111 const char * dirname = 0x0;
112 const char * filename = 0x0;
114 fChain = new TChain("aodTree");
116 while((dirname = gSystem->GetDirEntry(dira))) {
117 sprintf(fPath,"%s/%s",localpath,dirname);
118 void *dirb = gSystem->OpenDirectory(fPath);
119 while((filename = gSystem->GetDirEntry(dirb))) {
120 TString bstr = dirname;
121 if(bstr.Contains("..")) continue;
122 if(strstr(filename,pattern)) {
126 aodFileName += pattern;
127 fChain->Add(aodFileName);
129 } //child directory's entry loop
130 } //parent directory's entry loop
132 AliInfo(Form("AOD chain created......."));
133 AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));
135 CreateTag(fChain, "local");
140 //______________________________________________________________________________
141 Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) {
142 // Temporary solution for CAF: Takes as an input the ascii file that
143 // lists the AODs stored in the SE of the CAF and creates the tags.
145 // Open the input stream
151 fChain = new TChain("aodTree");
153 // Read the input list of files and add them to the chain
156 if (!aodfile.Contains("root")) continue; // protection
157 fChain->Add(aodfile);
160 AliInfo(Form("AOD chain created......."));
161 AliInfo(Form("Chain entries: %lld",fChain->GetEntries()));
163 CreateTag(fChain, "proof");
168 //__________________________________________________________________________
169 void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList */*grpList*/) {
170 // Creates tag files for AODs
172 AliInfo(Form("Creating the AOD tags......."));
174 TFile *file = TFile::Open("AliAOD.root");
175 if (!file || !file->IsOpen()) {
176 AliError(Form("opening failed"));
181 fChain = new TChain("aodTree");
182 fChain->Add("AliAOD.root");
184 fAODEvent = new AliAODEvent();
185 fAODEvent->ReadFromTree(fChain);
188 if(fLastEvent == -1) lastEvent = (Int_t)fChain->GetEntries();
189 else lastEvent = fLastEvent;
192 sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root",
193 fAODEvent->GetRunNumber(), fFirstEvent, lastEvent );
194 AliInfo(Form("writing tags to file %s", fileName));
195 AliDebug(1, Form("writing tags to file %s", fileName));
197 TFile* ftag = TFile::Open(fileName, "recreate");
199 fRunTag = new AliRunTag();
200 fTreeT = new TTree("T","A Tree with event tags");
201 TBranch * btag = fTreeT->Branch("AliTAG", &fRunTag);
202 btag->SetCompressionLevel(9);
215 //_____________________________________________________________________________
216 void AliAODTagCreator::CreateTag(TChain* chain, const char *type) {
218 // Private method that creates tag files
221 //reading the esd tag file
222 fTreeTEsd = new TChain("T");
223 const char * tagPattern = "ESD.tag";
224 // Open the working directory
225 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
226 const char * name = 0x0;
227 // Add all files matching *pattern* to the chain
228 while((name = gSystem->GetDirEntry(dirp))) {
229 if (strstr(name,tagPattern)) fTreeTEsd->Add(name);
231 AliInfo(Form("Chained tag files: %lld",fTreeTEsd->GetEntries()));
235 TString fSession = type;
236 TString fguid, fmd5, fturl;
237 fAODEvent = new AliAODEvent();
238 fAODEvent->ReadFromTree(fChain);
240 Int_t firstEvent = 0;
242 TString localFileName = "Run";
243 localFileName += fAODEvent->GetRunNumber();
244 localFileName += ".Event";
245 localFileName += firstEvent;
246 localFileName += "_";
247 localFileName += chain->GetEntries(); //localFileName += "."; localFileName += Counter;
248 localFileName += ".AOD.tag.root";
253 fileName = localFileName.Data();
254 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
256 else if(fStorage == 1) {
257 TString alienLocation = "/alien";
258 alienLocation += gGrid->Pwd();
259 alienLocation += fgridpath.Data();
260 alienLocation += "/";
261 alienLocation += localFileName;
262 alienLocation += "?se=";
263 alienLocation += fSE.Data();
264 fileName = alienLocation.Data();
265 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
268 TFile* ftag = TFile::Open(fileName, "recreate");
270 fRunTag = new AliRunTag();
271 fTreeT = new TTree("T", "A Tree with event tags");
272 TBranch * btag = fTreeT->Branch("AliTAG", &fRunTag);
273 btag->SetCompressionLevel(9);
275 // Access information from esd tag
276 fRunTagEsd = new AliRunTag();
277 fTreeTEsd->SetBranchAddress("AliTAG",&fRunTagEsd);
278 // Creating new information of aod
279 AliInfo(Form("Creating the AOD tags......."));
287 void AliAODTagCreator::CreateTags(const char* type)
289 // Event loop for tag creation
294 TFile *f = fChain->GetFile();
295 TString ftempGuid = f->GetUUID().AsString();
297 Int_t nEvents = fChain->GetEntries();
300 // const TClonesArray *evTagList = 0;
301 TString foldguid = "";
303 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
304 // Copy old tag information
305 if (iEventNumber >= ntags) {
306 fTreeTEsd->GetEntry(tagentry++);
307 fRunTag->CopyStandardContent(fRunTagEsd);
308 // evTagList = fRunTagEsd->GetEventTags();
309 // ntags += evTagList->GetEntries();
310 ntags = fRunTagEsd->GetNEvents();
314 AliEventTag* evTag = new AliEventTag();
316 fChain->GetEntry(iEventNumber);
317 if (iEventNumber == 0) oldRun = fAODEvent->GetRunNumber();
318 // Reference to the input file
319 TFile *file = fChain->GetFile();
320 const TUrl *url = file->GetEndpointUrl();
321 fguid = file->GetUUID().AsString();
323 if (!strcmp(type,"grid")) {
324 TString fturltemp = "alien://"; fturltemp += url->GetFile();
325 fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5);
327 fturl = url->GetFile();
330 fAODEvent->GetStdContent();
332 // Fill the event tag from the aod informatiom
333 FillEventTag(fAODEvent, evTag);
334 // Set the event and input file references
335 //evTag->SetEventId(iEventNumber+1);
338 // evTag->SetGUID(fguid);
339 // if(!strcmp(type,"grid")) {
340 // evTag->SetMD5("");
341 // evTag->SetTURL(fturl);
342 // evTag->SetSize(0);
344 // else evTag->SetPath(fturl);
347 // Check if a new run has to be created
349 if(fguid != ftempGuid) {
354 AliFileTag *nftag = new AliFileTag();
356 // if(fSession == "grid") {
358 nftag->SetTURL(fturl);
362 // nftag->SetPath(fturl);
363 // nftag->SetSize(0);
364 // nftag->SetMD5("");
365 // nftag->SetTURL(fturl);
368 if (fRunTag->GetFileId(fguid) > -1)
369 AliFatal("Adding a file which is already in the RunTag.");
371 fRunTag->AddFileTag(nftag);
376 if (oldRun != (fAODEvent->GetRunNumber()))
378 oldRun = fAODEvent->GetRunNumber();
386 AliFileTag *nftag = new AliFileTag();
388 // if(fSession == "grid") {
390 nftag->SetTURL(fturl);
394 // nftag->SetPath(fturl);
395 // nftag->SetSize(0);
396 // nftag->SetMD5("");
397 // nftag->SetTURL(fturl);
400 if (fRunTag->GetFileId(fguid) > -1)
401 AliFatal("Adding a file which is already in the RunTag.");
403 fRunTag->AddFileTag(nftag);
408 fRunTag->AddEventTag(*evTag);
411 if(iEventNumber+1 == fChain->GetEntries()) {
420 void AliAODTagCreator::FillEventTag(AliAODEvent* aod, AliEventTag* evTag)
423 // Fill the event tag information
428 Float_t fLowPtCut = 1.0;
429 Float_t fHighPtCut = 3.0;
430 Float_t fVeryHighPtCut = 10.0;
432 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
434 // Creates the tags for all the events in a given AOD file
436 Int_t nPos = 0, nNeg = 0, nNeutr =0;
437 Int_t nKinks = 0, nV0s = 0, nCascades = 0;
438 Int_t nK0s = 0, nNeutrons = 0, nPi0s = 0, nGamas = 0;
439 Int_t nProtons = 0, nKaons = 0, nPions = 0, nMuons = 0, nElectrons = 0, nFWMuons = 0;
440 Int_t nCh1GeV = 0, nCh3GeV = 0, nCh10GeV = 0;
441 Int_t nMu1GeV = 0, nMu3GeV = 0, nMu10GeV = 0;
442 Int_t nEl1GeV = 0, nEl3GeV = 0, nEl10GeV = 0;
443 Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0;
449 AliAODVertex *pVertex = fAODEvent->GetPrimaryVertex();
451 evTag->SetVertexX(pVertex->GetX());
452 evTag->SetVertexY(pVertex->GetY());
453 evTag->SetVertexZ(pVertex->GetZ());
454 Double_t covmatrix[6];
455 pVertex->GetCovarianceMatrix(covmatrix);
456 evTag->SetVertexZError(sqrt(covmatrix[5]));
458 // loop over vertices
459 Int_t nVtxs = fAODEvent->GetNumberOfVertices();
460 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
461 AliAODVertex *vertex = fAODEvent->GetVertex(nVtx);
462 if(vertex->GetType() == 1) nKinks += 1;
463 if(vertex->GetType() == 2) nV0s += 1;
464 if(vertex->GetType() == 3) nCascades += 1;
466 Int_t nTracks = fAODEvent->GetNTracks();
467 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
468 AliAODTrack *track = fAODEvent->GetTrack(nTr);
470 Double_t fPt = track->Pt();
473 etamaxPt = track->Eta();
474 phimaxPt = track->Phi();
477 if(track->Charge() > 0) {
479 if(fPt > fLowPtCut) nCh1GeV++;
480 if(fPt > fHighPtCut) nCh3GeV++;
481 if(fPt > fVeryHighPtCut) nCh10GeV++;
483 if(track->Charge() < 0) {
485 if(fPt > fLowPtCut) nCh1GeV++;
486 if(fPt > fHighPtCut) nCh3GeV++;
487 if(fPt > fVeryHighPtCut) nCh10GeV++;
489 if(track->Charge() == 0) nNeutr++;
491 const Double32_t *prob = track->PID();
493 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
494 if(rcc == 0.0) continue;
497 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
500 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
502 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
504 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
506 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
508 if(fPt > fLowPtCut) nMu1GeV++;
509 if(fPt > fHighPtCut) nMu3GeV++;
510 if(fPt > fVeryHighPtCut) nMu10GeV++;
513 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
515 if(fPt > fLowPtCut) nEl1GeV++;
516 if(fPt > fHighPtCut) nEl3GeV++;
517 if(fPt > fVeryHighPtCut) nEl10GeV++;
519 totalP += track->P();
522 // forward muons (in the dimuon spectrometer)
523 if(track->IsMuonTrack()) nFWMuons++;
527 // Fill the event tags
529 meanPt = meanPt/ntrack;
532 evTag->SetNumOfTracks(nTracks);
533 evTag->SetNumOfPosTracks(nPos);
534 evTag->SetNumOfNegTracks(nNeg);
535 evTag->SetNumOfNeutrTracks(nNeutr);
537 evTag->SetNumOfV0s(nV0s);
538 evTag->SetNumOfCascades(nCascades);
539 evTag->SetNumOfKinks(nKinks);
541 evTag->SetNumOfProtons(nProtons);
542 evTag->SetNumOfKaons(nKaons);
543 evTag->SetNumOfPions(nPions);
544 evTag->SetNumOfMuons(nMuons);
545 evTag->SetNumOfFWMuons(nFWMuons);
546 evTag->SetNumOfElectrons(nElectrons);
547 evTag->SetNumOfPhotons(nGamas);
548 evTag->SetNumOfPi0s(nPi0s);
549 evTag->SetNumOfNeutrons(nNeutrons);
550 evTag->SetNumOfKaon0s(nK0s);
552 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
553 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
554 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
555 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
556 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
557 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
558 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
559 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
560 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
563 evTag->SetNumOfPHOSClusters(fAODEvent->GetPHOSClusters(&tmp));
565 evTag->SetNumOfEMCALClusters(fAODEvent->GetEMCALClusters(&tmp));
567 evTag->SetTotalMomentum(totalP);
568 evTag->SetMeanPt(meanPt);
569 evTag->SetMaxPt(maxPt);
570 evTag->SetEtaMaxPt(etamaxPt);
571 evTag->SetPhiMaxPt(phimaxPt);