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 //-----------------------------------------------------------------
29 #include <TGridResult.h>
32 #include "AliRunTag.h"
33 #include "AliEventTag.h"
35 #include "AliESDVertex.h"
39 #include "AliTagCreator.h"
42 ClassImp(AliTagCreator)
45 //______________________________________________________________________________
46 AliTagCreator::AliTagCreator() //local mode
48 //==============Default constructor for a AliTagCreator==================
58 //______________________________________________________________________________
59 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username)
61 //==============Default constructor for a AliTagCreator==================
68 TString grid = "alien://";
74 TGrid::Connect(grid.Data(),fUser.Data());
77 AliError("Connection failed!!!");
83 //______________________________________________________________________________
84 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username, const char *passwd)
86 //==============Default constructor for a AliTagCreator==================
94 TString grid = "alien://";
100 TGrid::Connect(grid.Data(),fUser.Data(),fPasswd.Data());
103 AliError("Connection failed!!!");
109 //______________________________________________________________________________
110 AliTagCreator::~AliTagCreator()
112 //================Default destructor for a AliTagCreator=======================
115 //______________________________________________________________________________
116 void AliTagCreator::SetStorage(Int_t storage)
118 // Sets correctly the storage: 0 for local, 1 for GRID
121 AliInfo(Form("Tags will be stored locally...."));
123 AliInfo(Form("Tags will be stored in the grid...."));
124 if((fStorage != 0)&&(fStorage != 1))
126 AliInfo(Form("Storage was not properly set!!!"));
131 //______________________________________________________________________________
132 Bool_t AliTagCreator::ConnectToGrid(const char *host, Int_t port, const char *username)
134 // Connects to a given AliEn API service
139 TString grid = "alien://";
144 //connect to the grid
145 TGrid::Connect(grid.Data(),fUser.Data());
148 AliError("Connection failed!!!");
150 } //connect to the grid
155 //______________________________________________________________________________
156 Bool_t AliTagCreator::ReadESDCollection(TGridResult *fresult)
158 // Reads the entry of the TGridResult and creates the tags
159 Int_t nEntries = fresult->GetEntries();
168 for(Int_t i = 0; i < nEntries; i++)
170 alienUrl = fresult->GetKey(i,"turl");
171 guid = fresult->GetKey(i,"guid");
172 if(fresult->GetKey(i,"size"))
173 size = atol (fresult->GetKey(i,"size"));
174 md5 = fresult->GetKey(i,"md5");
175 turl = fresult->GetKey(i,"turl");
176 if(md5 && !strlen(guid))
178 if(guid && !strlen(guid))
181 TFile *f = TFile::Open(alienUrl,"READ");
182 //CreateTag(f,guid,counter);
183 CreateTag(f,guid,md5,turl,size,counter);
193 //_____________________________________________________________________________
194 //void AliTagCreator::CreateTag(TFile* file, const char *guid, Int_t Counter)
195 void AliTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter)
197 // Creates the tags for all the events in a given ESD file
199 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
200 Int_t nPos, nNeg, nNeutr;
201 Int_t nK0s, nNeutrons, nPi0s, nGamas;
202 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
203 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
204 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
205 Float_t maxPt = .0, meanPt = .0, totalP = .0;
207 AliRunTag *tag = new AliRunTag();
208 AliEventTag *evTag = new AliEventTag();
209 TTree ttag("T","A Tree with event tags");
210 TBranch * btag = ttag.Branch("AliTAG", "AliRunTag", &tag);
211 btag->SetCompressionLevel(9);
213 AliInfo(Form("Creating the tags......."));
215 Int_t firstEvent = 0,lastEvent = 0;
216 TTree *t = (TTree*) file->Get("esdTree");
217 TBranch * b = t->GetBranch("ESD");
221 tag->SetRunId(esd->GetRunNumber());
223 Int_t iNumberOfEvents = b->GetEntries();
224 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++)
252 b->GetEntry(iEventNumber);
253 const AliESDVertex * vertexIn = esd->GetVertex();
255 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++)
257 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
258 UInt_t status = esdTrack->GetStatus();
260 //select only tracks with ITS refit
261 if ((status&AliESDtrack::kITSrefit)==0) continue;
263 //select only tracks with TPC refit-->remove extremely high Pt tracks
264 if ((status&AliESDtrack::kTPCrefit)==0) continue;
266 //select only tracks with the "combined PID"
267 if ((status&AliESDtrack::kESDpid)==0) continue;
269 esdTrack->GetPxPyPz(p);
270 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
271 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
277 if(esdTrack->GetSign() > 0)
287 if(esdTrack->GetSign() < 0)
297 if(esdTrack->GetSign() == 0)
302 esdTrack->GetESDpid(prob);
305 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]))
308 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]))
311 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]))
314 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]))
317 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]))
320 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]))
323 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]))
326 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]))
337 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]))
352 // Fill the event tags
354 meanPt = meanPt/ntrack;
356 evTag->SetEventId(iEventNumber+1);
357 evTag->SetGUID(guid);
359 evTag->SetTURL(turl);
360 evTag->SetSize(size);
361 evTag->SetVertexX(vertexIn->GetXv());
362 evTag->SetVertexY(vertexIn->GetYv());
363 evTag->SetVertexZ(vertexIn->GetZv());
365 evTag->SetT0VertexZ(esd->GetT0zVertex());
367 evTag->SetTrigger(esd->GetTrigger());
369 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
370 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
371 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
372 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
375 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
376 evTag->SetNumOfPosTracks(nPos);
377 evTag->SetNumOfNegTracks(nNeg);
378 evTag->SetNumOfNeutrTracks(nNeutr);
380 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
381 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
382 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
383 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
385 evTag->SetNumOfProtons(nProtons);
386 evTag->SetNumOfKaons(nKaons);
387 evTag->SetNumOfPions(nPions);
388 evTag->SetNumOfMuons(nMuons);
389 evTag->SetNumOfElectrons(nElectrons);
390 evTag->SetNumOfPhotons(nGamas);
391 evTag->SetNumOfPi0s(nPi0s);
392 evTag->SetNumOfNeutrons(nNeutrons);
393 evTag->SetNumOfKaon0s(nK0s);
395 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
396 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
397 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
398 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
399 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
400 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
401 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
402 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
403 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
405 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
406 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
408 evTag->SetTotalMomentum(totalP);
409 evTag->SetMeanPt(meanPt);
410 evTag->SetMaxPt(maxPt);
412 tag->AddEventTag(*evTag);
414 lastEvent = iNumberOfEvents;
421 TString localFileName = "Run"; localFileName += tag->GetRunId();
422 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
423 localFileName += ".ESD.tag.root";
425 TString alienLocation = "/alien";
426 alienLocation += gGrid->Pwd();
427 alienLocation += fgridpath.Data();
428 alienLocation += "/";
429 alienLocation += localFileName;
430 alienLocation += "?se=";
431 alienLocation += fSE.Data();
437 fileName = localFileName.Data();
438 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
442 fileName = alienLocation.Data();
443 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
446 TFile* ftag = TFile::Open(fileName, "recreate");