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>
33 #include <TGridResult.h>
36 #include "AliRunTag.h"
37 #include "AliEventTag.h"
39 #include "AliAODEvent.h"
40 #include "AliAODVertex.h"
43 #include "AliAODTagCreator.h"
46 ClassImp(AliAODTagCreator)
49 //______________________________________________________________________________
50 AliAODTagCreator::AliAODTagCreator() :
59 //==============Default constructor for a AliAODTagCreator================
62 //______________________________________________________________________________
63 AliAODTagCreator::~AliAODTagCreator() {
64 //================Default destructor for a AliAODTagCreator===================
69 //______________________________________________________________________________
70 Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) {
71 // Reads the entry of the TGridResult and creates the tags
72 Int_t nEntries = fresult->GetEntries();
80 fChain = new TChain("aodTree");
82 for(Int_t i = 0; i < nEntries; i++) {
83 alienUrl = fresult->GetKey(i,"turl");
84 guid = fresult->GetKey(i,"guid");
85 if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size"));
86 md5 = fresult->GetKey(i,"md5");
87 turl = fresult->GetKey(i,"turl");
88 if(md5 && !strlen(guid)) md5 = 0;
89 if(guid && !strlen(guid)) guid = 0;
91 fChain->Add(alienUrl);
94 AliInfo(Form("AOD chain created......."));
95 AliInfo(Form("Chain entries: %d",fChain->GetEntries()));
97 CreateTag(fChain, "grid");
102 //______________________________________________________________________________
103 Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) {
104 // Checks the different subdirs of the given local path and in the
105 // case where it finds an AliAODs.root file it creates the tags
107 void *dira = gSystem->OpenDirectory(localpath);
109 const char * dirname = 0x0;
110 const char * filename = 0x0;
111 const char * pattern = "AliAODs.root";
113 fChain = new TChain("aodTree");
115 while((dirname = gSystem->GetDirEntry(dira))) {
116 sprintf(fPath,"%s/%s",localpath,dirname);
117 void *dirb = gSystem->OpenDirectory(fPath);
118 while((filename = gSystem->GetDirEntry(dirb))) {
119 TString bstr = dirname;
120 if(bstr.Contains("..")) continue;
121 if(strstr(filename,pattern)) {
125 aodFileName += pattern;
126 fChain->Add(aodFileName);
128 } //child directory's entry loop
129 } //parent directory's entry loop
131 AliInfo(Form("AOD chain created......."));
132 AliInfo(Form("Chain entries: %d",fChain->GetEntries()));
134 CreateTag(fChain, "local");
139 //______________________________________________________________________________
140 Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) {
141 // Temporary solution for CAF: Takes as an input the ascii file that
142 // lists the AODs stored in the SE of the CAF and creates the tags.
144 // Open the input stream
150 fChain = new TChain("aodTree");
152 // Read the input list of files and add them to the chain
155 if (!aodfile.Contains("root")) continue; // protection
156 fChain->Add(aodfile);
159 AliInfo(Form("AOD chain created......."));
160 AliInfo(Form("Chain entries: %d",fChain->GetEntries()));
162 CreateTag(fChain, "proof");
167 //__________________________________________________________________________
168 void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent, TList */*grpList*/) {
169 // Creates tag files for AODs
171 AliInfo(Form("Creating the AOD tags......."));
173 TFile *file = TFile::Open("AliAOD.root");
174 if (!file || !file->IsOpen()) {
175 AliError(Form("opening failed"));
180 fChain = new TChain("aodTree");
181 fChain->Add("AliAOD.root");
183 fAODEvent = new AliAODEvent();
184 fAODEvent->ReadFromTree(fChain);
187 if(fLastEvent == -1) lastEvent = (Int_t)fChain->GetEntries();
188 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
222 //reading the esd tag file
223 fTreeTEsd = new TChain("T");
224 const char * tagPattern = "ESD.tag";
225 // Open the working directory
226 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
227 const char * name = 0x0;
228 // Add all files matching *pattern* to the chain
229 while((name = gSystem->GetDirEntry(dirp))) {
230 if (strstr(name,tagPattern)) fTreeTEsd->Add(name);
232 AliInfo(Form("Chained tag files: %d", fTreeTEsd->GetEntries()));
237 TString fSession = type;
238 TString fguid, fmd5, fturl;
239 fAODEvent = new AliAODEvent();
240 fAODEvent->ReadFromTree(fChain);
242 Int_t firstEvent = 0;
244 TString localFileName = "Run";
245 localFileName += fAODEvent->GetRunNumber();
246 localFileName += ".Event";
247 localFileName += firstEvent;
248 localFileName += "_";
249 localFileName += chain->GetEntries(); //localFileName += "."; localFileName += Counter;
250 localFileName += ".AOD.tag.root";
255 fileName = localFileName.Data();
256 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
258 else if(fStorage == 1) {
259 TString alienLocation = "/alien";
260 alienLocation += gGrid->Pwd();
261 alienLocation += fgridpath.Data();
262 alienLocation += "/";
263 alienLocation += localFileName;
264 alienLocation += "?se=";
265 alienLocation += fSE.Data();
266 fileName = alienLocation.Data();
267 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
270 TFile* ftag = TFile::Open(fileName, "recreate");
272 fRunTag = new AliRunTag();
273 fTreeT = new TTree("T", "A Tree with event tags");
274 TBranch * btag = fTreeT->Branch("AliTAG", &fRunTag);
275 btag->SetCompressionLevel(9);
277 // Access information from esd tag
278 fRunTagEsd = new AliRunTag();
279 fTreeTEsd->SetBranchAddress("AliTAG",&fRunTagEsd);
280 // Creating new information of aod
281 AliInfo(Form("Creating the AOD tags......."));
289 void AliAODTagCreator::CreateTags(const char* type)
291 // Event loop for tag creation
296 TFile *f = fChain->GetFile();
297 TString ftempGuid = f->GetUUID().AsString();
299 Int_t nEvents = fChain->GetEntries();
302 const TClonesArray *evTagList = 0;
304 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
305 // Copy old tag information
306 if (iEventNumber >= ntags) {
307 fTreeTEsd->GetEntry(tagentry++);
308 fRunTag->CopyStandardContent(fRunTagEsd);
309 evTagList = fRunTagEsd->GetEventTags();
310 ntags += evTagList->GetEntries();
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);
336 evTag->SetGUID(fguid);
337 if(!strcmp(type,"grid")) {
339 evTag->SetTURL(fturl);
342 else evTag->SetPath(fturl);
344 // Check if a new run has to be created
346 if(fguid != ftempGuid) {
352 if (oldRun != (fAODEvent->GetRunNumber()))
354 oldRun = fAODEvent->GetRunNumber();
360 fRunTag->AddEventTag(*evTag);
363 if(iEventNumber+1 == fChain->GetEntries()) {
372 void AliAODTagCreator::FillEventTag(AliAODEvent* aod, AliEventTag* evTag)
375 // Fill the event tag information
380 Float_t fLowPtCut = 1.0;
381 Float_t fHighPtCut = 3.0;
382 Float_t fVeryHighPtCut = 10.0;
384 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
386 // Creates the tags for all the events in a given AOD file
388 Int_t nPos = 0, nNeg = 0, nNeutr =0;
389 Int_t nKinks = 0, nV0s = 0, nCascades = 0;
390 Int_t nK0s = 0, nNeutrons = 0, nPi0s = 0, nGamas = 0;
391 Int_t nProtons = 0, nKaons = 0, nPions = 0, nMuons = 0, nElectrons = 0, nFWMuons = 0;
392 Int_t nCh1GeV = 0, nCh3GeV = 0, nCh10GeV = 0;
393 Int_t nMu1GeV = 0, nMu3GeV = 0, nMu10GeV = 0;
394 Int_t nEl1GeV = 0, nEl3GeV = 0, nEl10GeV = 0;
395 Float_t maxPt = .0, meanPt = .0, totalP = .0;
397 Int_t nTracks = fAODEvent->GetNTracks();
398 // loop over vertices
399 Int_t nVtxs = fAODEvent->GetNumberOfVertices();
400 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
401 AliAODVertex *vertex = fAODEvent->GetVertex(nVtx);
402 if(vertex->GetType() == 1) nKinks += 1;
403 if(vertex->GetType() == 2) nV0s += 1;
404 if(vertex->GetType() == 3) nCascades += 1;
406 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
407 AliAODTrack *track = fAODEvent->GetTrack(nTr);
409 Double_t fPt = track->Pt();
410 if(fPt > maxPt) maxPt = fPt;
411 if(track->Charge() > 0) {
413 if(fPt > fLowPtCut) nCh1GeV++;
414 if(fPt > fHighPtCut) nCh3GeV++;
415 if(fPt > fVeryHighPtCut) nCh10GeV++;
417 if(track->Charge() < 0) {
419 if(fPt > fLowPtCut) nCh1GeV++;
420 if(fPt > fHighPtCut) nCh3GeV++;
421 if(fPt > fVeryHighPtCut) nCh10GeV++;
423 if(track->Charge() == 0) nNeutr++;
425 const Double32_t *prob = track->PID();
427 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
428 if(rcc == 0.0) continue;
431 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
434 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
436 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
438 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
440 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
442 if(fPt > fLowPtCut) nMu1GeV++;
443 if(fPt > fHighPtCut) nMu3GeV++;
444 if(fPt > fVeryHighPtCut) nMu10GeV++;
447 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
449 if(fPt > fLowPtCut) nEl1GeV++;
450 if(fPt > fHighPtCut) nEl3GeV++;
451 if(fPt > fVeryHighPtCut) nEl10GeV++;
453 totalP += track->P();
456 // forward muons (in the dimuon spectrometer)
457 if(track->IsMuonTrack()) nFWMuons++;
461 // Fill the event tags
463 meanPt = meanPt/ntrack;
466 evTag->SetNumOfTracks(nTracks);
467 evTag->SetNumOfPosTracks(nPos);
468 evTag->SetNumOfNegTracks(nNeg);
469 evTag->SetNumOfNeutrTracks(nNeutr);
471 evTag->SetNumOfV0s(nV0s);
472 evTag->SetNumOfCascades(nCascades);
473 evTag->SetNumOfKinks(nKinks);
475 evTag->SetNumOfProtons(nProtons);
476 evTag->SetNumOfKaons(nKaons);
477 evTag->SetNumOfPions(nPions);
478 evTag->SetNumOfMuons(nMuons);
479 evTag->SetNumOfFWMuons(nFWMuons);
480 evTag->SetNumOfElectrons(nElectrons);
481 evTag->SetNumOfPhotons(nGamas);
482 evTag->SetNumOfPi0s(nPi0s);
483 evTag->SetNumOfNeutrons(nNeutrons);
484 evTag->SetNumOfKaon0s(nK0s);
486 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
487 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
488 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
489 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
490 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
491 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
492 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
493 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
494 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
496 evTag->SetTotalMomentum(totalP);
497 evTag->SetMeanPt(meanPt);
498 evTag->SetMaxPt(maxPt);