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==================
78 TString grid = "alien://";
84 TGrid::Connect(grid.Data(),fUser.Data());
87 AliError("Connection failed!!!");
93 //______________________________________________________________________________
94 AliTagCreator::AliTagCreator(const char *host, Int_t port, const char *username, const char *passwd)
96 //==============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 Bool_t AliTagCreator::ConnectToGrid(const char *host, Int_t port, const char *username)
136 TString grid = "alien://";
141 //connect to the grid
142 TGrid::Connect(grid.Data(),fUser.Data());
145 AliError("Connection failed!!!");
147 } //connect to the grid
152 //______________________________________________________________________________
153 Bool_t AliTagCreator::ReadESDCollection(const char *CollectionFile)
155 fCollectionFile = CollectionFile;
157 gSystem->Load("libXMLIO.so");
158 gSystem->Load("libXMLParser.so");
159 //define the tag collection
160 TAlienCollection *collection = new TAlienCollection(fCollectionFile.Data());
166 TString gridname = "alien://";
167 Int_t gridnameSize = gridname.Sizeof();
168 TString Esd = "AliEsds.root";
174 TString EsdPattern = "/alien";
177 while((map = collection->Next()))
179 TIter next(map->GetTable());
181 while ((pair = (TPair*) next()))
183 EsdFilePath = pair->Key()->GetName();
184 AlienUrl = collection->GetTURL(EsdFilePath);
185 EsdFilePath = pair->Value()->GetName();
187 lfn = EsdFilePath.Replace(0,gridnameSize-1,EsdFilePath,0);
188 //TAlienFile *f = new TAlienFile(AlienUrl,"READ");
189 //TFile *f = new TFile(AlienUrl,"READ");
190 TFile *f = TFile::Open(AlienUrl,"READ");
192 TGridResult* result = gGrid->Ls(lfn,"-b");
193 guid = result->GetKey(0,"guid");
195 CreateTag(f,guid,counter);
205 //_____________________________________________________________________________
206 void AliTagCreator::CreateTag(TFile* file, const char *guid, Int_t Counter)
209 Int_t NProtons, NKaons, NPions, NMuons, NElectrons;
210 Int_t Npos, Nneg, Nneutr;
211 Int_t NK0s, Nneutrons, Npi0s, Ngamas;
212 Int_t Nch1GeV, Nch3GeV, Nch10GeV;
213 Int_t Nmu1GeV, Nmu3GeV, Nmu10GeV;
214 Int_t Nel1GeV, Nel3GeV, Nel10GeV;
215 Float_t MaxPt = .0, MeanPt = .0, TotalP = .0;
217 AliRunTag *tag = new AliRunTag();
218 AliDetectorTag *detTag = new AliDetectorTag();
219 AliEventTag *evTag = new AliEventTag();
220 TTree ttag("T","A Tree with event tags");
221 TBranch * btag = ttag.Branch("AliTAG", "AliRunTag", &tag);
222 btag->SetCompressionLevel(9);
224 AliInfo(Form("Creating the tags......."));
226 Int_t firstEvent = 0,lastEvent = 0;
227 TTree *t = (TTree*) file->Get("esdTree");
228 TBranch * b = t->GetBranch("ESD");
232 tag->SetRunId(esd->GetRunNumber());
234 Int_t i_NumberOfEvents = b->GetEntries();
235 for (Int_t i_EventNumber = 0; i_EventNumber < i_NumberOfEvents; i_EventNumber++)
263 b->GetEntry(i_EventNumber);
264 const AliESDVertex * VertexIn = esd->GetVertex();
266 for (Int_t i_TrackNumber = 0; i_TrackNumber < esd->GetNumberOfTracks(); i_TrackNumber++)
268 AliESDtrack * ESDTrack = esd->GetTrack(i_TrackNumber);
269 UInt_t status = ESDTrack->GetStatus();
271 //select only tracks with ITS refit
272 if ((status&AliESDtrack::kITSrefit)==0) continue;
274 //select only tracks with TPC refit-->remove extremely high Pt tracks
275 if ((status&AliESDtrack::kTPCrefit)==0) continue;
277 //select only tracks with the "combined PID"
278 if ((status&AliESDtrack::kESDpid)==0) continue;
280 ESDTrack->GetPxPyPz(p);
281 Double_t P = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
282 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
288 if(ESDTrack->GetSign() > 0)
298 if(ESDTrack->GetSign() < 0)
308 if(ESDTrack->GetSign() == 0)
313 ESDTrack->GetESDpid(prob);
316 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]))
319 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]))
322 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]))
325 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]))
328 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]))
331 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]))
334 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]))
337 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]))
348 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]))
363 // Fill the event tags
365 MeanPt = MeanPt/ntrack;
367 evTag->SetEventId(i_EventNumber+1);
368 evTag->SetGUID(guid);
369 evTag->SetVertexX(VertexIn->GetXv());
370 evTag->SetVertexY(VertexIn->GetYv());
371 evTag->SetVertexZ(VertexIn->GetZv());
373 evTag->SetT0VertexZ(esd->GetT0zVertex());
375 evTag->SetTrigger(esd->GetTrigger());
377 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
378 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
379 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
380 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
383 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
384 evTag->SetNumOfPosTracks(Npos);
385 evTag->SetNumOfNegTracks(Nneg);
386 evTag->SetNumOfNeutrTracks(Nneutr);
388 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
389 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
390 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
391 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
393 evTag->SetNumOfProtons(NProtons);
394 evTag->SetNumOfKaons(NKaons);
395 evTag->SetNumOfPions(NPions);
396 evTag->SetNumOfMuons(NMuons);
397 evTag->SetNumOfElectrons(NElectrons);
398 evTag->SetNumOfPhotons(Ngamas);
399 evTag->SetNumOfPi0s(Npi0s);
400 evTag->SetNumOfNeutrons(Nneutrons);
401 evTag->SetNumOfKaon0s(NK0s);
403 evTag->SetNumOfChargedAbove1GeV(Nch1GeV);
404 evTag->SetNumOfChargedAbove3GeV(Nch3GeV);
405 evTag->SetNumOfChargedAbove10GeV(Nch10GeV);
406 evTag->SetNumOfMuonsAbove1GeV(Nmu1GeV);
407 evTag->SetNumOfMuonsAbove3GeV(Nmu3GeV);
408 evTag->SetNumOfMuonsAbove10GeV(Nmu10GeV);
409 evTag->SetNumOfElectronsAbove1GeV(Nel1GeV);
410 evTag->SetNumOfElectronsAbove3GeV(Nel3GeV);
411 evTag->SetNumOfElectronsAbove10GeV(Nel10GeV);
413 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
414 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
416 evTag->SetTotalMomentum(TotalP);
417 evTag->SetMeanPt(MeanPt);
418 evTag->SetMaxPt(MaxPt);
420 tag->AddEventTag(evTag);
422 lastEvent = i_NumberOfEvents;
429 TString LocalfileName = "Run"; LocalfileName += tag->GetRunId();
430 LocalfileName += ".Event"; LocalfileName += firstEvent; LocalfileName += "_"; LocalfileName += lastEvent; LocalfileName += "."; LocalfileName += Counter;
431 LocalfileName += ".ESD.tag.root";
433 cout<<"Writing tags to local file: "<<LocalfileName<<endl;
435 TFile* ftag = TFile::Open(LocalfileName, "recreate");
448 //_____________________________________________________________________________
449 Bool_t AliTagCreator::StoreGridTagFile(const char *localpath, const char *gridpath)
451 gSystem->Load("libThread.so");
452 gSystem->Load("libTreePlayer.so");
453 gSystem->Load("libProof.so");
454 cout<<"Storing tag file to alien's file catalog..."<<endl;
456 const char * pattern = "tag.root";
457 // Open the working directory
458 void * dirp = gSystem->OpenDirectory(localpath);
459 const char * name = 0x0;
460 TString AlienLocation;
461 Char_t LocalLocation[256];
463 // Add all files matching *pattern* to the chain
464 while((name = gSystem->GetDirEntry(dirp)))
466 if (strstr(name,pattern))
468 sprintf(LocalLocation,"file:%s/%s",localpath,name);
469 AlienLocation = "/alien";
470 AlienLocation += gGrid->Pwd();
471 AlienLocation += gridpath;
472 AlienLocation += "/";
473 AlienLocation += name;
474 AlienLocation += "?se=";
475 AlienLocation += fSE.Data();
476 merger.Cp(LocalLocation,AlienLocation);
480 gSystem->FreeDirectory(dirp);