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>
29 #include <THashTable.h>
33 //#include <TAlienCollection.h>
34 #include <TGridResult.h>
35 #include <TFileMerger.h>
37 #include <TXMLParser.h>
39 #include <TTreePlayer.h>
43 #include "AliRunTag.h"
44 #include "AliEventTag.h"
46 #include "AliESDVertex.h"
48 #include "AliESDpid.h"
52 #include "AliTagCreator.h"
55 ClassImp(AliTagCreator)
58 //______________________________________________________________________________
59 AliTagCreator::AliTagCreator() //local mode
61 //==============Default constructor for a AliTagCreator==================
70 //______________________________________________________________________________
71 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username)
73 //==============Default constructor for a AliTagCreator==================
79 TString grid = "alien://";
85 TGrid::Connect(grid.Data(),fUser.Data());
88 AliError("Connection failed!!!");
94 //______________________________________________________________________________
95 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username, const char *passwd)
97 //==============Default constructor for a AliTagCreator==================
104 TString grid = "alien://";
109 //connect to the grid
110 TGrid::Connect(grid.Data(),fUser.Data(),fPasswd.Data());
113 AliError("Connection failed!!!");
119 //______________________________________________________________________________
120 AliTagCreator::~AliTagCreator()
122 //================Default destructor for a AliTagCreator=======================
125 //______________________________________________________________________________
126 void AliTagCreator::SetSE(const char *se)
131 //______________________________________________________________________________
132 Bool_t AliTagCreator::ConnectToGrid(const char *host, Int_t port, const char *username)
138 TString grid = "alien://";
143 //connect to the grid
144 TGrid::Connect(grid.Data(),fUser.Data());
147 AliError("Connection failed!!!");
149 } //connect to the grid
154 //______________________________________________________________________________
155 Bool_t AliTagCreator::ReadESDCollection(TGridResult *res)
158 Int_t NEntries = fresult->GetEntries();
160 TString gridname = "alien://";
165 for(Int_t i = 0; i < NEntries; i++)
168 AlienUrl += fresult->GetKey(i,"lfn");
169 guid = fresult->GetKey(i,"guid");
170 TFile *f = TFile::Open(AlienUrl,"READ");
171 CreateTag(f,guid,counter);
181 //_____________________________________________________________________________
182 void AliTagCreator::CreateTag(TFile* file, const char *guid, Int_t Counter)
185 Int_t NProtons, NKaons, NPions, NMuons, NElectrons;
186 Int_t Npos, Nneg, Nneutr;
187 Int_t NK0s, Nneutrons, Npi0s, Ngamas;
188 Int_t Nch1GeV, Nch3GeV, Nch10GeV;
189 Int_t Nmu1GeV, Nmu3GeV, Nmu10GeV;
190 Int_t Nel1GeV, Nel3GeV, Nel10GeV;
191 Float_t MaxPt = .0, MeanPt = .0, TotalP = .0;
193 AliRunTag *tag = new AliRunTag();
194 AliDetectorTag *detTag = new AliDetectorTag();
195 AliEventTag *evTag = new AliEventTag();
196 TTree ttag("T","A Tree with event tags");
197 TBranch * btag = ttag.Branch("AliTAG", "AliRunTag", &tag);
198 btag->SetCompressionLevel(9);
200 AliInfo(Form("Creating the tags......."));
202 Int_t firstEvent = 0,lastEvent = 0;
203 TTree *t = (TTree*) file->Get("esdTree");
204 TBranch * b = t->GetBranch("ESD");
208 tag->SetRunId(esd->GetRunNumber());
210 Int_t i_NumberOfEvents = b->GetEntries();
211 for (Int_t i_EventNumber = 0; i_EventNumber < i_NumberOfEvents; i_EventNumber++)
239 b->GetEntry(i_EventNumber);
240 const AliESDVertex * VertexIn = esd->GetVertex();
242 for (Int_t i_TrackNumber = 0; i_TrackNumber < esd->GetNumberOfTracks(); i_TrackNumber++)
244 AliESDtrack * ESDTrack = esd->GetTrack(i_TrackNumber);
245 UInt_t status = ESDTrack->GetStatus();
247 //select only tracks with ITS refit
248 if ((status&AliESDtrack::kITSrefit)==0) continue;
250 //select only tracks with TPC refit-->remove extremely high Pt tracks
251 if ((status&AliESDtrack::kTPCrefit)==0) continue;
253 //select only tracks with the "combined PID"
254 if ((status&AliESDtrack::kESDpid)==0) continue;
256 ESDTrack->GetPxPyPz(p);
257 Double_t P = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
258 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
264 if(ESDTrack->GetSign() > 0)
274 if(ESDTrack->GetSign() < 0)
284 if(ESDTrack->GetSign() == 0)
289 ESDTrack->GetESDpid(prob);
292 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]))
295 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]))
298 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]))
301 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]))
304 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]))
307 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]))
310 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]))
313 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]))
324 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]))
339 // Fill the event tags
341 MeanPt = MeanPt/ntrack;
343 evTag->SetEventId(i_EventNumber+1);
344 evTag->SetGUID(guid);
345 evTag->SetVertexX(VertexIn->GetXv());
346 evTag->SetVertexY(VertexIn->GetYv());
347 evTag->SetVertexZ(VertexIn->GetZv());
349 evTag->SetT0VertexZ(esd->GetT0zVertex());
351 evTag->SetTrigger(esd->GetTrigger());
353 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
354 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
355 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
356 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
359 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
360 evTag->SetNumOfPosTracks(Npos);
361 evTag->SetNumOfNegTracks(Nneg);
362 evTag->SetNumOfNeutrTracks(Nneutr);
364 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
365 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
366 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
367 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
369 evTag->SetNumOfProtons(NProtons);
370 evTag->SetNumOfKaons(NKaons);
371 evTag->SetNumOfPions(NPions);
372 evTag->SetNumOfMuons(NMuons);
373 evTag->SetNumOfElectrons(NElectrons);
374 evTag->SetNumOfPhotons(Ngamas);
375 evTag->SetNumOfPi0s(Npi0s);
376 evTag->SetNumOfNeutrons(Nneutrons);
377 evTag->SetNumOfKaon0s(NK0s);
379 evTag->SetNumOfChargedAbove1GeV(Nch1GeV);
380 evTag->SetNumOfChargedAbove3GeV(Nch3GeV);
381 evTag->SetNumOfChargedAbove10GeV(Nch10GeV);
382 evTag->SetNumOfMuonsAbove1GeV(Nmu1GeV);
383 evTag->SetNumOfMuonsAbove3GeV(Nmu3GeV);
384 evTag->SetNumOfMuonsAbove10GeV(Nmu10GeV);
385 evTag->SetNumOfElectronsAbove1GeV(Nel1GeV);
386 evTag->SetNumOfElectronsAbove3GeV(Nel3GeV);
387 evTag->SetNumOfElectronsAbove10GeV(Nel10GeV);
389 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
390 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
392 evTag->SetTotalMomentum(TotalP);
393 evTag->SetMeanPt(MeanPt);
394 evTag->SetMaxPt(MaxPt);
396 tag->AddEventTag(evTag);
398 lastEvent = i_NumberOfEvents;
405 TString LocalfileName = "Run"; LocalfileName += tag->GetRunId();
406 LocalfileName += ".Event"; LocalfileName += firstEvent; LocalfileName += "_"; LocalfileName += lastEvent; LocalfileName += "."; LocalfileName += Counter;
407 LocalfileName += ".ESD.tag.root";
409 cout<<"Writing tags to local file: "<<LocalfileName<<endl;
411 TFile* ftag = TFile::Open(LocalfileName, "recreate");
424 //_____________________________________________________________________________
425 Bool_t AliTagCreator::StoreGridTagFile(const char *localpath, const char *gridpath)
427 gSystem->Load("libThread.so");
428 gSystem->Load("libTreePlayer.so");
429 gSystem->Load("libProof.so");
430 cout<<"Storing tag file to alien's file catalog..."<<endl;
432 const char * pattern = "tag.root";
433 // Open the working directory
434 void * dirp = gSystem->OpenDirectory(localpath);
435 const char * name = 0x0;
436 TString AlienLocation;
437 Char_t LocalLocation[256];
439 // Add all files matching *pattern* to the chain
440 while((name = gSystem->GetDirEntry(dirp)))
442 if (strstr(name,pattern))
444 sprintf(LocalLocation,"file:%s/%s",localpath,name);
445 AlienLocation = "/alien";
446 AlienLocation += gGrid->Pwd();
447 AlienLocation += gridpath;
448 AlienLocation += "/";
449 AlienLocation += name;
450 AlienLocation += "?se=";
451 AlienLocation += fSE.Data();
452 merger.Cp(LocalLocation,AlienLocation);
456 gSystem->FreeDirectory(dirp);