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() :
52 //==============Default constructor for a AliAODTagCreator================
55 //______________________________________________________________________________
56 AliAODTagCreator::~AliAODTagCreator() {
57 //================Default destructor for a AliAODTagCreator===================
60 //______________________________________________________________________________
61 Bool_t AliAODTagCreator::ReadGridCollection(TGridResult *fresult) {
62 // Reads the entry of the TGridResult and creates the tags
63 Int_t nEntries = fresult->GetEntries();
72 for(Int_t i = 0; i < nEntries; i++) {
73 alienUrl = fresult->GetKey(i,"turl");
74 guid = fresult->GetKey(i,"guid");
75 if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size"));
76 md5 = fresult->GetKey(i,"md5");
77 turl = fresult->GetKey(i,"turl");
78 if(md5 && !strlen(guid)) md5 = 0;
79 if(guid && !strlen(guid)) guid = 0;
81 TFile *f = TFile::Open(alienUrl,"READ");
82 //CreateTag(f,guid,md5,turl,size,counter);
91 //______________________________________________________________________________
92 Bool_t AliAODTagCreator::ReadLocalCollection(const char *localpath) {
93 // Checks the different subdirs of the given local path and in the
94 // case where it finds an AliAODs.root file it creates the tags
96 void *dira = gSystem->OpenDirectory(localpath);
98 const char * dirname = 0x0;
99 const char * filename = 0x0;
100 const char * pattern = "AliAODs.root";
103 while((dirname = gSystem->GetDirEntry(dira))) {
104 sprintf(fPath,"%s/%s",localpath,dirname);
105 void *dirb = gSystem->OpenDirectory(fPath);
106 while((filename = gSystem->GetDirEntry(dirb))) {
107 if(strstr(filename,pattern)) {
108 TString fAODFileName;
109 fAODFileName = fPath;
111 fAODFileName += pattern;
112 TFile *f = TFile::Open(fAODFileName,"READ");
113 //CreateTag(f,fAODFileName,counter);
119 }//child directory's entry loop
120 }//parent directory's entry loop
125 //______________________________________________________________________________
126 Bool_t AliAODTagCreator::ReadCAFCollection(const char *filename) {
127 // Temporary solution for CAF: Takes as an input the ascii file that
128 // lists the AODs stored in the SE of the CAF and creates the tags.
130 // Open the input stream
136 // Read the input list of files and add them to the chain
139 if (!esdfile.Contains("root")) continue; // protection
140 TFile *f = TFile::Open(esdfile,"READ");
141 //CreateTag(f,esdfile,counter);
151 //__________________________________________________________________________
152 void AliAODTagCreator::CreateAODTags(Int_t fFirstEvent, Int_t fLastEvent) {
153 //creates tag files for AODs
155 Float_t fLowPtCut = 1.0;
156 Float_t fHighPtCut = 3.0;
157 Float_t fVeryHighPtCut = 10.0;
160 Double_t partFrac[10] = {0.01, 0.01, 0.85, 0.10, 0.05, 0., 0., 0., 0., 0.};
162 // Creates the tags for all the events in a given AOD file
164 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
165 Int_t nPos, nNeg, nNeutr;
166 Int_t nKinks, nV0s, nCascades;
167 Int_t nK0s, nNeutrons, nPi0s, nGamas;
168 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
169 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
170 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
171 Float_t maxPt = .0, meanPt = .0, totalP = .0;
173 AliRunTag *tag = new AliRunTag();
174 TTree ttag("T","A Tree with event tags");
175 TBranch * btag = ttag.Branch("AliTAG", &tag);
176 btag->SetCompressionLevel(9);
178 //reading the esd tag file
179 TChain *oldTagTree = new TChain("T");
180 const char * tagPattern = "ESD.tag";
181 // Open the working directory
182 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
183 const char * name = 0x0;
184 // Add all files matching *pattern* to the chain
185 while((name = gSystem->GetDirEntry(dirp))) {
186 if (strstr(name,tagPattern)) oldTagTree->Add(name);
188 AliInfo(Form("Chained tag files: %d",oldTagTree->GetEntries()));
190 //reading the esd tag file
191 AliRunTag *oldtag = new AliRunTag();
193 oldTagTree->SetBranchAddress("AliTAG",&oldtag);
194 oldTagTree->GetEntry(0);
195 tag->CopyStandardContent(oldtag);
196 const TClonesArray *evTagList = oldtag->GetEventTags();
198 AliInfo(Form("Creating the AOD tags......."));
200 TFile *file = TFile::Open("AliAOD.root");
201 if (!file || !file->IsOpen()) {
202 AliError(Form("opening failed"));
206 TTree *aodTree = (TTree*)file->Get("aodTree");
207 AliAODEvent *aod = new AliAODEvent();
208 aod->ReadFromTree(aodTree);
211 if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries();
212 else lastEvent = fLastEvent;
215 Int_t nEvents = aodTree->GetEntries();
216 for (Int_t iEventNumber = 0; iEventNumber < nEvents; iEventNumber++) {
217 AliEventTag *evTag = (AliEventTag *)evTagList->At(iEventNumber);
219 nPos = 0; nNeg = 0; nNeutr =0;
220 nKinks = 0; nV0s = 0; nCascades = 0;
221 nK0s = 0; nNeutrons = 0; nPi0s = 0; nGamas = 0;
222 nProtons = 0; nKaons = 0; nPions = 0; nMuons = 0; nElectrons = 0;
223 nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0;
224 nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0;
225 nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0;
226 maxPt = .0; meanPt = .0; totalP = .0;
229 aodTree->GetEvent(iEventNumber);
232 aod->GetStdContent();
234 Int_t nTracks = aod->GetNTracks();
235 // loop over vertices
236 Int_t nVtxs = aod->GetNVertices();
237 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
239 AliAODVertex *vertex = aod->GetVertex(nVtx);
240 if(vertex->GetType() == 1) nKinks += 1;
241 if(vertex->GetType() == 2) nV0s += 1;
242 if(vertex->GetType() == 3) nCascades += 1;
244 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
245 AliAODTrack *track = aod->GetTrack(nTr);
247 Double_t fPt = track->Pt();
248 if(fPt > maxPt) maxPt = fPt;
249 if(track->Charge() > 0) {
251 if(fPt > fLowPtCut) nCh1GeV++;
252 if(fPt > fHighPtCut) nCh3GeV++;
253 if(fPt > fVeryHighPtCut) nCh10GeV++;
255 if(track->Charge() < 0) {
257 if(fPt > fLowPtCut) nCh1GeV++;
258 if(fPt > fHighPtCut) nCh3GeV++;
259 if(fPt > fVeryHighPtCut) nCh10GeV++;
261 if(track->Charge() == 0) nNeutr++;
264 const Double32_t *prob = track->PID();
266 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
267 if(rcc == 0.0) continue;
270 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
273 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
275 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
277 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
279 if ((w[1]>w[4])&&(w[1]>w[3])&&(w[1]>w[2])&&(w[1]>w[0])) {
281 if(fPt > fLowPtCut) nMu1GeV++;
282 if(fPt > fHighPtCut) nMu3GeV++;
283 if(fPt > fVeryHighPtCut) nMu10GeV++;
286 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
288 if(fPt > fLowPtCut) nEl1GeV++;
289 if(fPt > fHighPtCut) nEl3GeV++;
290 if(fPt > fVeryHighPtCut) nEl10GeV++;
293 totalP += track->P();
297 // Fill the event tags
299 meanPt = meanPt/ntrack;
301 evTag->SetEventId(iEventNumber+1);
303 evTag->SetNumOfTracks(nTracks);
304 evTag->SetNumOfPosTracks(nPos);
305 evTag->SetNumOfNegTracks(nNeg);
306 evTag->SetNumOfNeutrTracks(nNeutr);
308 evTag->SetNumOfV0s(nV0s);
309 evTag->SetNumOfCascades(nCascades);
310 evTag->SetNumOfKinks(nKinks);
312 evTag->SetNumOfProtons(nProtons);
313 evTag->SetNumOfKaons(nKaons);
314 evTag->SetNumOfPions(nPions);
315 evTag->SetNumOfMuons(nMuons);
316 evTag->SetNumOfElectrons(nElectrons);
317 evTag->SetNumOfPhotons(nGamas);
318 evTag->SetNumOfPi0s(nPi0s);
319 evTag->SetNumOfNeutrons(nNeutrons);
320 evTag->SetNumOfKaon0s(nK0s);
322 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
323 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
324 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
325 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
326 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
327 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
328 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
329 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
330 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
332 evTag->SetTotalMomentum(totalP);
333 evTag->SetMeanPt(meanPt);
334 evTag->SetMaxPt(maxPt);
335 tag->AddEventTag(*evTag);
337 if(fLastEvent == -1) lastEvent = (Int_t)aodTree->GetEntries();
338 else lastEvent = fLastEvent;
344 sprintf(fileName, "Run%d.Event%d_%d.AOD.tag.root",
345 tag->GetRunId(),fFirstEvent,lastEvent );
346 AliInfo(Form("writing tags to file %s", fileName));
347 AliDebug(1, Form("writing tags to file %s", fileName));
349 TFile* ftag = TFile::Open(fileName, "recreate");
357 //_____________________________________________________________________________
358 /*void AliAODTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) {
359 //private method that creates tag files
360 TString fguid = guid;
362 TString fturl = turl;
366 Double_t fMUONMASS = 0.105658369;
369 Double_t fThetaX, fThetaY, fPyz, fChisquare;
370 Double_t fPxRec, fPyRec, fPzRec, fEnergy;
372 TLorentzVector fEPvector;
374 Float_t fZVertexCut = 10.0;
375 Float_t fRhoVertexCut = 2.0;
377 Float_t fLowPtCut = 1.0;
378 Float_t fHighPtCut = 3.0;
379 Float_t fVeryHighPtCut = 10.0;
382 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
384 // Creates the tags for all the events in a given AOD file
385 Bool_t fIsSim = kTRUE;
387 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
388 Int_t nPos, nNeg, nNeutr;
389 Int_t nK0s, nNeutrons, nPi0s, nGamas;
390 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
391 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
392 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
393 Float_t maxPt = .0, meanPt = .0, totalP = .0;
395 Int_t iRunNumber = 0;
398 AliRunTag *tag = new AliRunTag();
399 AliEventTag *evTag = new AliEventTag();
400 TTree ttag("T","A Tree with event tags");
401 TBranch * btag = ttag.Branch("AliTAG", &tag);
402 btag->SetCompressionLevel(9);
404 AliInfo(Form("Creating the tags......."));
406 Int_t firstEvent = 0,lastEvent = 0;
407 TTree *t = (TTree*) file->Get("esdTree");
408 AliESDEvent *esd = new AliESDEvent();
409 esd->ReadFromTree(t);
412 Int_t iInitRunNumber = esd->GetRunNumber();
414 Int_t iNumberOfEvents = (Int_t)t->GetEntries();
415 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
443 t->GetEntry(iEventNumber);
444 iRunNumber = esd->GetRunNumber();
445 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
446 const AliESDVertex * vertexIn = esd->GetVertex();
447 fVertexName = vertexIn->GetName();
448 if(fVertexName == "default") fVertexflag = 0;
450 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
451 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
452 if(esdTrack->GetLabel() != 0) fIsSim = kTRUE;
453 else if(esdTrack->GetLabel() == 0) fIsSim = kFALSE;
454 UInt_t status = esdTrack->GetStatus();
456 //select only tracks with ITS refit
457 if ((status&AliESDtrack::kITSrefit)==0) continue;
458 //select only tracks with TPC refit
459 if ((status&AliESDtrack::kTPCrefit)==0) continue;
461 //select only tracks with the "combined PID"
462 if ((status&AliESDtrack::kESDpid)==0) continue;
464 esdTrack->GetPxPyPz(p);
465 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
466 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
469 if(fPt > maxPt) maxPt = fPt;
471 if(esdTrack->GetSign() > 0) {
473 if(fPt > fLowPtCut) nCh1GeV++;
474 if(fPt > fHighPtCut) nCh3GeV++;
475 if(fPt > fVeryHighPtCut) nCh10GeV++;
477 if(esdTrack->GetSign() < 0) {
479 if(fPt > fLowPtCut) nCh1GeV++;
480 if(fPt > fHighPtCut) nCh3GeV++;
481 if(fPt > fVeryHighPtCut) nCh10GeV++;
483 if(esdTrack->GetSign() == 0) nNeutr++;
487 esdTrack->GetESDpid(prob);
490 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
491 if(rcc == 0.0) continue;
494 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
497 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
499 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
501 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
503 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
505 if(fPt > fLowPtCut) nEl1GeV++;
506 if(fPt > fHighPtCut) nEl3GeV++;
507 if(fPt > fVeryHighPtCut) nEl10GeV++;
515 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
516 // loop over all reconstructed tracks (also first track of combination)
517 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
518 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
519 if (muonTrack == 0x0) continue;
521 // Coordinates at vertex
522 fZ = muonTrack->GetZ();
523 fY = muonTrack->GetBendingCoor();
524 fX = muonTrack->GetNonBendingCoor();
526 fThetaX = muonTrack->GetThetaX();
527 fThetaY = muonTrack->GetThetaY();
529 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
530 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
531 fPxRec = fPzRec * TMath::Tan(fThetaX);
532 fPyRec = fPzRec * TMath::Tan(fThetaY);
533 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
535 //ChiSquare of the track if needed
536 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
537 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
538 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
540 // total number of muons inside a vertex cut
541 if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
543 if(fEPvector.Pt() > fLowPtCut) {
545 if(fEPvector.Pt() > fHighPtCut) {
547 if (fEPvector.Pt() > fVeryHighPtCut) {
555 // Fill the event tags
556 if(ntrack != 0) meanPt = meanPt/ntrack;
558 evTag->SetEventId(iEventNumber+1);
559 evTag->SetGUID(fguid);
561 evTag->SetTURL(fturl);
562 evTag->SetSize(size);
563 evTag->SetVertexX(vertexIn->GetXv());
564 evTag->SetVertexY(vertexIn->GetYv());
565 evTag->SetVertexZ(vertexIn->GetZv());
566 evTag->SetVertexZError(vertexIn->GetZRes());
567 evTag->SetVertexFlag(fVertexflag);
569 evTag->SetT0VertexZ(esd->GetT0zVertex());
571 evTag->SetTriggerMask(esd->GetTriggerMask());
572 evTag->SetTriggerCluster(esd->GetTriggerCluster());
574 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
575 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
576 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
577 evTag->SetZDCNeutron1Energy(esd->GetZDCN2Energy());
578 evTag->SetZDCProton1Energy(esd->GetZDCP2Energy());
579 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
582 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
583 evTag->SetNumOfPosTracks(nPos);
584 evTag->SetNumOfNegTracks(nNeg);
585 evTag->SetNumOfNeutrTracks(nNeutr);
587 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
588 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
589 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
590 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
592 evTag->SetNumOfProtons(nProtons);
593 evTag->SetNumOfKaons(nKaons);
594 evTag->SetNumOfPions(nPions);
595 evTag->SetNumOfMuons(nMuons);
596 evTag->SetNumOfElectrons(nElectrons);
597 evTag->SetNumOfPhotons(nGamas);
598 evTag->SetNumOfPi0s(nPi0s);
599 evTag->SetNumOfNeutrons(nNeutrons);
600 evTag->SetNumOfKaon0s(nK0s);
602 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
603 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
604 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
605 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
606 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
607 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
608 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
609 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
610 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
612 evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
613 evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
615 evTag->SetTotalMomentum(totalP);
616 evTag->SetMeanPt(meanPt);
617 evTag->SetMaxPt(maxPt);
619 tag->SetRunId(iInitRunNumber);
620 if(fIsSim) tag->SetDataType(0);
621 else tag->SetDataType(1);
622 tag->AddEventTag(*evTag);
624 lastEvent = iNumberOfEvents;
631 TString localFileName = "Run"; localFileName += tag->GetRunId();
632 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
633 localFileName += ".ESD.tag.root";
638 fileName = localFileName.Data();
639 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
641 else if(fStorage == 1) {
642 TString alienLocation = "/alien";
643 alienLocation += gGrid->Pwd();
644 alienLocation += fgridpath.Data();
645 alienLocation += "/";
646 alienLocation += localFileName;
647 alienLocation += "?se=";
648 alienLocation += fSE.Data();
649 fileName = alienLocation.Data();
650 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
653 TFile* ftag = TFile::Open(fileName, "recreate");
664 //_____________________________________________________________________________
665 /*void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) {
666 //private method that creates tag files
670 Double_t fMUONMASS = 0.105658369;
673 Double_t fThetaX, fThetaY, fPyz, fChisquare;
674 Double_t fPxRec, fPyRec, fPzRec, fEnergy;
676 TLorentzVector fEPvector;
678 Float_t fZVertexCut = 10.0;
679 Float_t fRhoVertexCut = 2.0;
681 Float_t fLowPtCut = 1.0;
682 Float_t fHighPtCut = 3.0;
683 Float_t fVeryHighPtCut = 10.0;
686 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
688 // Creates the tags for all the events in a given ESD file
689 Bool_t fIsSim = kTRUE;
691 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
692 Int_t nPos, nNeg, nNeutr;
693 Int_t nK0s, nNeutrons, nPi0s, nGamas;
694 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
695 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
696 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
697 Float_t maxPt = .0, meanPt = .0, totalP = .0;
699 Int_t iRunNumber = 0;
702 AliRunTag *tag = new AliRunTag();
703 AliEventTag *evTag = new AliEventTag();
704 TTree ttag("T","A Tree with event tags");
705 TBranch * btag = ttag.Branch("AliTAG", &tag);
706 btag->SetCompressionLevel(9);
708 AliInfo(Form("Creating the tags......."));
710 Int_t firstEvent = 0,lastEvent = 0;
712 TTree *t = (TTree*) file->Get("esdTree");
713 AliESDEvent *esd = new AliESDEvent();
714 esd->ReadFromTree(t);
717 Int_t iInitRunNumber = esd->GetRunNumber();
719 Int_t iNumberOfEvents = (Int_t)t->GetEntries();
720 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
748 t->GetEntry(iEventNumber);
749 iRunNumber = esd->GetRunNumber();
750 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
751 const AliESDVertex * vertexIn = esd->GetVertex();
752 fVertexName = vertexIn->GetName();
753 if(fVertexName == "default") fVertexflag = 0;
755 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
756 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
757 if(esdTrack->GetLabel() != 0) fIsSim = kTRUE;
758 else if(esdTrack->GetLabel() == 0) fIsSim = kFALSE;
759 UInt_t status = esdTrack->GetStatus();
761 //select only tracks with ITS refit
762 if ((status&AliESDtrack::kITSrefit)==0) continue;
763 //select only tracks with TPC refit
764 if ((status&AliESDtrack::kTPCrefit)==0) continue;
766 //select only tracks with the "combined PID"
767 if ((status&AliESDtrack::kESDpid)==0) continue;
769 esdTrack->GetPxPyPz(p);
770 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
771 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
774 if(fPt > maxPt) maxPt = fPt;
776 if(esdTrack->GetSign() > 0) {
778 if(fPt > fLowPtCut) nCh1GeV++;
779 if(fPt > fHighPtCut) nCh3GeV++;
780 if(fPt > fVeryHighPtCut) nCh10GeV++;
782 if(esdTrack->GetSign() < 0) {
784 if(fPt > fLowPtCut) nCh1GeV++;
785 if(fPt > fHighPtCut) nCh3GeV++;
786 if(fPt > fVeryHighPtCut) nCh10GeV++;
788 if(esdTrack->GetSign() == 0) nNeutr++;
792 esdTrack->GetESDpid(prob);
795 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
796 if(rcc == 0.0) continue;
799 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
802 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
804 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
806 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
808 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
810 if(fPt > fLowPtCut) nEl1GeV++;
811 if(fPt > fHighPtCut) nEl3GeV++;
812 if(fPt > fVeryHighPtCut) nEl10GeV++;
820 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
821 // loop over all reconstructed tracks (also first track of combination)
822 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
823 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
824 if (muonTrack == 0x0) continue;
826 // Coordinates at vertex
827 fZ = muonTrack->GetZ();
828 fY = muonTrack->GetBendingCoor();
829 fX = muonTrack->GetNonBendingCoor();
831 fThetaX = muonTrack->GetThetaX();
832 fThetaY = muonTrack->GetThetaY();
834 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
835 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
836 fPxRec = fPzRec * TMath::Tan(fThetaX);
837 fPyRec = fPzRec * TMath::Tan(fThetaY);
838 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
840 //ChiSquare of the track if needed
841 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
842 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
843 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
845 // total number of muons inside a vertex cut
846 if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
848 if(fEPvector.Pt() > fLowPtCut) {
850 if(fEPvector.Pt() > fHighPtCut) {
852 if (fEPvector.Pt() > fVeryHighPtCut) {
860 // Fill the event tags
861 if(ntrack != 0) meanPt = meanPt/ntrack;
863 evTag->SetEventId(iEventNumber+1);
864 evTag->SetPath(filepath);
866 evTag->SetVertexX(vertexIn->GetXv());
867 evTag->SetVertexY(vertexIn->GetYv());
868 evTag->SetVertexZ(vertexIn->GetZv());
869 evTag->SetVertexZError(vertexIn->GetZRes());
870 evTag->SetVertexFlag(fVertexflag);
872 evTag->SetT0VertexZ(esd->GetT0zVertex());
874 evTag->SetTriggerMask(esd->GetTriggerMask());
875 evTag->SetTriggerCluster(esd->GetTriggerCluster());
877 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
878 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
879 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
880 evTag->SetZDCNeutron1Energy(esd->GetZDCN2Energy());
881 evTag->SetZDCProton1Energy(esd->GetZDCP2Energy());
882 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
885 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
886 evTag->SetNumOfPosTracks(nPos);
887 evTag->SetNumOfNegTracks(nNeg);
888 evTag->SetNumOfNeutrTracks(nNeutr);
890 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
891 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
892 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
893 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
895 evTag->SetNumOfProtons(nProtons);
896 evTag->SetNumOfKaons(nKaons);
897 evTag->SetNumOfPions(nPions);
898 evTag->SetNumOfMuons(nMuons);
899 evTag->SetNumOfElectrons(nElectrons);
900 evTag->SetNumOfPhotons(nGamas);
901 evTag->SetNumOfPi0s(nPi0s);
902 evTag->SetNumOfNeutrons(nNeutrons);
903 evTag->SetNumOfKaon0s(nK0s);
905 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
906 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
907 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
908 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
909 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
910 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
911 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
912 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
913 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
915 evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
916 evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
918 evTag->SetTotalMomentum(totalP);
919 evTag->SetMeanPt(meanPt);
920 evTag->SetMaxPt(maxPt);
922 tag->SetRunId(iInitRunNumber);
923 if(fIsSim) tag->SetDataType(0);
924 else tag->SetDataType(1);
925 tag->AddEventTag(*evTag);
927 lastEvent = iNumberOfEvents;
934 TString localFileName = "Run"; localFileName += tag->GetRunId();
935 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
936 localFileName += ".ESD.tag.root";
941 fileName = localFileName.Data();
942 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
944 else if(fStorage == 1) {
945 TString alienLocation = "/alien";
946 alienLocation += gGrid->Pwd();
947 alienLocation += fgridpath.Data();
948 alienLocation += "/";
949 alienLocation += localFileName;
950 alienLocation += "?se=";
951 alienLocation += fSE.Data();
952 fileName = alienLocation.Data();
953 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
956 TFile* ftag = TFile::Open(fileName, "recreate");