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==================
59 //______________________________________________________________________________
60 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username)
62 //==============Default constructor for a AliTagCreator==================
70 TString grid = "alien://";
76 TGrid::Connect(grid.Data(),fUser.Data());
79 AliError("Connection failed!!!");
85 //______________________________________________________________________________
86 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username, const char *passwd)
88 //==============Default constructor for a AliTagCreator==================
97 TString grid = "alien://";
102 //connect to the grid
103 TGrid::Connect(grid.Data(),fUser.Data(),fPasswd.Data());
106 AliError("Connection failed!!!");
112 //______________________________________________________________________________
113 AliTagCreator::~AliTagCreator()
115 //================Default destructor for a AliTagCreator=======================
118 //______________________________________________________________________________
119 void AliTagCreator::SetStorage(Int_t storage)
121 // Sets correctly the storage: 0 for local, 1 for GRID
124 AliInfo(Form("Tags will be stored locally...."));
126 AliInfo(Form("Tags will be stored in the grid...."));
127 if((fStorage != 0)&&(fStorage != 1))
129 AliInfo(Form("Storage was not properly set!!!"));
134 //______________________________________________________________________________
135 Bool_t AliTagCreator::ConnectToGrid(const char *host, Int_t port, const char *username)
137 // Connects to a given AliEn API service
142 TString grid = "alien://";
147 //connect to the grid
148 TGrid::Connect(grid.Data(),fUser.Data());
151 AliError("Connection failed!!!");
153 } //connect to the grid
158 //______________________________________________________________________________
159 Bool_t AliTagCreator::ReadESDCollection(TGridResult *fresult)
161 // Reads the entry of the TGridResult and creates the tags
162 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 TFile *f = TFile::Open(alienUrl,"READ");
173 CreateTag(f,guid,counter);
183 //_____________________________________________________________________________
184 void AliTagCreator::CreateTag(TFile* file, const char *guid, Int_t Counter)
186 // Creates the tags for all the events in a given ESD file
188 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
189 Int_t nPos, nNeg, nNeutr;
190 Int_t nK0s, nNeutrons, nPi0s, nGamas;
191 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
192 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
193 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
194 Float_t maxPt = .0, meanPt = .0, totalP = .0;
196 AliRunTag *tag = new AliRunTag();
197 AliDetectorTag *detTag = new AliDetectorTag();
198 AliEventTag *evTag = new AliEventTag();
199 TTree ttag("T","A Tree with event tags");
200 TBranch * btag = ttag.Branch("AliTAG", "AliRunTag", &tag);
201 btag->SetCompressionLevel(9);
203 AliInfo(Form("Creating the tags......."));
205 Int_t firstEvent = 0,lastEvent = 0;
206 TTree *t = (TTree*) file->Get("esdTree");
207 TBranch * b = t->GetBranch("ESD");
211 tag->SetRunId(esd->GetRunNumber());
213 Int_t iNumberOfEvents = b->GetEntries();
214 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++)
242 b->GetEntry(iEventNumber);
243 const AliESDVertex * vertexIn = esd->GetVertex();
245 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++)
247 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
248 UInt_t status = esdTrack->GetStatus();
250 //select only tracks with ITS refit
251 if ((status&AliESDtrack::kITSrefit)==0) continue;
253 //select only tracks with TPC refit-->remove extremely high Pt tracks
254 if ((status&AliESDtrack::kTPCrefit)==0) continue;
256 //select only tracks with the "combined PID"
257 if ((status&AliESDtrack::kESDpid)==0) continue;
259 esdTrack->GetPxPyPz(p);
260 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
261 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
267 if(esdTrack->GetSign() > 0)
277 if(esdTrack->GetSign() < 0)
287 if(esdTrack->GetSign() == 0)
292 esdTrack->GetESDpid(prob);
295 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]))
298 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]))
301 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]))
304 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]))
307 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]))
310 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]))
313 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]))
316 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]))
327 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]))
342 // Fill the event tags
344 meanPt = meanPt/ntrack;
346 evTag->SetEventId(iEventNumber+1);
347 evTag->SetGUID(guid);
348 evTag->SetVertexX(vertexIn->GetXv());
349 evTag->SetVertexY(vertexIn->GetYv());
350 evTag->SetVertexZ(vertexIn->GetZv());
352 evTag->SetT0VertexZ(esd->GetT0zVertex());
354 evTag->SetTrigger(esd->GetTrigger());
356 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
357 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
358 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
359 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
362 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
363 evTag->SetNumOfPosTracks(nPos);
364 evTag->SetNumOfNegTracks(nNeg);
365 evTag->SetNumOfNeutrTracks(nNeutr);
367 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
368 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
369 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
370 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
372 evTag->SetNumOfProtons(nProtons);
373 evTag->SetNumOfKaons(nKaons);
374 evTag->SetNumOfPions(nPions);
375 evTag->SetNumOfMuons(nMuons);
376 evTag->SetNumOfElectrons(nElectrons);
377 evTag->SetNumOfPhotons(nGamas);
378 evTag->SetNumOfPi0s(nPi0s);
379 evTag->SetNumOfNeutrons(nNeutrons);
380 evTag->SetNumOfKaon0s(nK0s);
382 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
383 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
384 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
385 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
386 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
387 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
388 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
389 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
390 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
392 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
393 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
395 evTag->SetTotalMomentum(totalP);
396 evTag->SetMeanPt(meanPt);
397 evTag->SetMaxPt(maxPt);
399 tag->AddEventTag(*evTag);
401 lastEvent = iNumberOfEvents;
408 TString localFileName = "Run"; localFileName += tag->GetRunId();
409 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
410 localFileName += ".ESD.tag.root";
412 TString alienLocation = "/alien";
413 alienLocation += gGrid->Pwd();
414 alienLocation += fgridpath.Data();
415 alienLocation += "/";
416 alienLocation += localFileName;
417 alienLocation += "?se=";
418 alienLocation += fSE.Data();
424 fileName = localFileName.Data();
425 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
429 fileName = alienLocation.Data();
430 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
433 TFile* ftag = TFile::Open(fileName, "recreate");