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 //-----------------------------------------------------------------
24 #include <Riostream.h>
32 #include <TGridResult.h>
35 #include "AliRunTag.h"
36 #include "AliEventTag.h"
38 #include "AliESDVertex.h"
40 #include "AliESDpid.h"
44 #include "AliTagCreator.h"
47 ClassImp(AliTagCreator)
50 //______________________________________________________________________________
51 AliTagCreator::AliTagCreator() //local mode
53 //==============Default constructor for a AliTagCreator==================
64 //______________________________________________________________________________
65 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username)
67 //==============Default constructor for a AliTagCreator==================
75 TString grid = "alien://";
81 TGrid::Connect(grid.Data(),fUser.Data());
84 AliError("Connection failed!!!");
90 //______________________________________________________________________________
91 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username, const char *passwd)
93 //==============Default constructor for a AliTagCreator==================
102 TString grid = "alien://";
107 //connect to the grid
108 TGrid::Connect(grid.Data(),fUser.Data(),fPasswd.Data());
111 AliError("Connection failed!!!");
117 //______________________________________________________________________________
118 AliTagCreator::~AliTagCreator()
120 //================Default destructor for a AliTagCreator=======================
123 //______________________________________________________________________________
124 void AliTagCreator::SetSE(const char *se)
129 //______________________________________________________________________________
130 void AliTagCreator::SetGridPath(const char *gridpath)
132 fgridpath = gridpath;
135 //______________________________________________________________________________
136 void AliTagCreator::SetStorage(Int_t storage)
140 AliInfo(Form("Tags will be stored locally...."));
142 AliInfo(Form("Tags will be stored in the grid...."));
143 if((fStorage != 0)&&(fStorage != 1))
145 AliInfo(Form("Storage was not properly set!!!"));
150 //______________________________________________________________________________
151 Bool_t AliTagCreator::ConnectToGrid(const char *host, Int_t port, const char *username)
157 TString grid = "alien://";
162 //connect to the grid
163 TGrid::Connect(grid.Data(),fUser.Data());
166 AliError("Connection failed!!!");
168 } //connect to the grid
173 //______________________________________________________________________________
174 Bool_t AliTagCreator::ReadESDCollection(TGridResult *res)
177 Int_t NEntries = fresult->GetEntries();
179 TString gridname = "alien://";
184 for(Int_t i = 0; i < NEntries; i++)
187 AlienUrl += fresult->GetKey(i,"lfn");
188 guid = fresult->GetKey(i,"guid");
189 TFile *f = TFile::Open(AlienUrl,"READ");
190 CreateTag(f,guid,counter);
200 //_____________________________________________________________________________
201 void AliTagCreator::CreateTag(TFile* file, const char *guid, Int_t Counter)
204 Int_t NProtons, NKaons, NPions, NMuons, NElectrons;
205 Int_t Npos, Nneg, Nneutr;
206 Int_t NK0s, Nneutrons, Npi0s, Ngamas;
207 Int_t Nch1GeV, Nch3GeV, Nch10GeV;
208 Int_t Nmu1GeV, Nmu3GeV, Nmu10GeV;
209 Int_t Nel1GeV, Nel3GeV, Nel10GeV;
210 Float_t MaxPt = .0, MeanPt = .0, TotalP = .0;
212 AliRunTag *tag = new AliRunTag();
213 AliDetectorTag *detTag = new AliDetectorTag();
214 AliEventTag *evTag = new AliEventTag();
215 TTree ttag("T","A Tree with event tags");
216 TBranch * btag = ttag.Branch("AliTAG", "AliRunTag", &tag);
217 btag->SetCompressionLevel(9);
219 AliInfo(Form("Creating the tags......."));
221 Int_t firstEvent = 0,lastEvent = 0;
222 TTree *t = (TTree*) file->Get("esdTree");
223 TBranch * b = t->GetBranch("ESD");
227 tag->SetRunId(esd->GetRunNumber());
229 Int_t i_NumberOfEvents = b->GetEntries();
230 for (Int_t i_EventNumber = 0; i_EventNumber < i_NumberOfEvents; i_EventNumber++)
258 b->GetEntry(i_EventNumber);
259 const AliESDVertex * VertexIn = esd->GetVertex();
261 for (Int_t i_TrackNumber = 0; i_TrackNumber < esd->GetNumberOfTracks(); i_TrackNumber++)
263 AliESDtrack * ESDTrack = esd->GetTrack(i_TrackNumber);
264 UInt_t status = ESDTrack->GetStatus();
266 //select only tracks with ITS refit
267 if ((status&AliESDtrack::kITSrefit)==0) continue;
269 //select only tracks with TPC refit-->remove extremely high Pt tracks
270 if ((status&AliESDtrack::kTPCrefit)==0) continue;
272 //select only tracks with the "combined PID"
273 if ((status&AliESDtrack::kESDpid)==0) continue;
275 ESDTrack->GetPxPyPz(p);
276 Double_t P = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
277 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
283 if(ESDTrack->GetSign() > 0)
293 if(ESDTrack->GetSign() < 0)
303 if(ESDTrack->GetSign() == 0)
308 ESDTrack->GetESDpid(prob);
311 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]))
314 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]))
317 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]))
320 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]))
323 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]))
326 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]))
329 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]))
332 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]))
343 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]))
358 // Fill the event tags
360 MeanPt = MeanPt/ntrack;
362 evTag->SetEventId(i_EventNumber+1);
363 evTag->SetGUID(guid);
364 evTag->SetVertexX(VertexIn->GetXv());
365 evTag->SetVertexY(VertexIn->GetYv());
366 evTag->SetVertexZ(VertexIn->GetZv());
368 evTag->SetT0VertexZ(esd->GetT0zVertex());
370 evTag->SetTrigger(esd->GetTrigger());
372 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
373 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
374 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
375 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
378 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
379 evTag->SetNumOfPosTracks(Npos);
380 evTag->SetNumOfNegTracks(Nneg);
381 evTag->SetNumOfNeutrTracks(Nneutr);
383 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
384 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
385 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
386 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
388 evTag->SetNumOfProtons(NProtons);
389 evTag->SetNumOfKaons(NKaons);
390 evTag->SetNumOfPions(NPions);
391 evTag->SetNumOfMuons(NMuons);
392 evTag->SetNumOfElectrons(NElectrons);
393 evTag->SetNumOfPhotons(Ngamas);
394 evTag->SetNumOfPi0s(Npi0s);
395 evTag->SetNumOfNeutrons(Nneutrons);
396 evTag->SetNumOfKaon0s(NK0s);
398 evTag->SetNumOfChargedAbove1GeV(Nch1GeV);
399 evTag->SetNumOfChargedAbove3GeV(Nch3GeV);
400 evTag->SetNumOfChargedAbove10GeV(Nch10GeV);
401 evTag->SetNumOfMuonsAbove1GeV(Nmu1GeV);
402 evTag->SetNumOfMuonsAbove3GeV(Nmu3GeV);
403 evTag->SetNumOfMuonsAbove10GeV(Nmu10GeV);
404 evTag->SetNumOfElectronsAbove1GeV(Nel1GeV);
405 evTag->SetNumOfElectronsAbove3GeV(Nel3GeV);
406 evTag->SetNumOfElectronsAbove10GeV(Nel10GeV);
408 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
409 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
411 evTag->SetTotalMomentum(TotalP);
412 evTag->SetMeanPt(MeanPt);
413 evTag->SetMaxPt(MaxPt);
415 tag->AddEventTag(evTag);
417 lastEvent = i_NumberOfEvents;
424 TString LocalfileName = "Run"; LocalfileName += tag->GetRunId();
425 LocalfileName += ".Event"; LocalfileName += firstEvent; LocalfileName += "_"; LocalfileName += lastEvent; LocalfileName += "."; LocalfileName += Counter;
426 LocalfileName += ".ESD.tag.root";
428 TString AlienLocation = "/alien";
429 AlienLocation += gGrid->Pwd();
430 AlienLocation += fgridpath.Data();
431 AlienLocation += "/";
432 AlienLocation += LocalfileName;
433 AlienLocation += "?se=";
434 AlienLocation += fSE.Data();
440 FileName = LocalfileName.Data();
441 cout<<"Writing tags to local file: "<<FileName.Data()<<endl;
445 FileName = AlienLocation.Data();
446 cout<<"Writing tags to grid file: "<<FileName.Data()<<endl;
449 TFile* ftag = TFile::Open(FileName, "recreate");