]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTagCreator.cxx
Modified ApplyDisplacements method (R.Grosso).
[u/mrichter/AliRoot.git] / STEER / AliTagCreator.cxx
CommitLineData
b45e5084 1/**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
4 * *
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 **************************************************************************/
13
14/* $Id$ */
15
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//-----------------------------------------------------------------
21
22//ROOT
b45e5084 23#include <TFile.h>
24#include <TString.h>
cb1645b7 25#include <TTree.h>
4fd84456 26#include <TSystem.h>
27#include <TChain.h>
b45e5084 28
29//ROOT-AliEn
30#include <TGrid.h>
b45e5084 31#include <TGridResult.h>
b45e5084 32
33//AliRoot
34#include "AliRunTag.h"
35#include "AliEventTag.h"
36#include "AliESD.h"
37#include "AliESDVertex.h"
b45e5084 38#include "AliLog.h"
39
40
41#include "AliTagCreator.h"
42
43
44ClassImp(AliTagCreator)
45
46
47//______________________________________________________________________________
48AliTagCreator::AliTagCreator() //local mode
49{
50 //==============Default constructor for a AliTagCreator==================
28afeb2e 51 fgridpath = "";
b45e5084 52 fSE = "";
28afeb2e 53 fStorage = 0;
b45e5084 54}
55
b45e5084 56//______________________________________________________________________________
57AliTagCreator::~AliTagCreator()
58{
59//================Default destructor for a AliTagCreator=======================
60}
61
28afeb2e 62//______________________________________________________________________________
63void AliTagCreator::SetStorage(Int_t storage)
64{
cb1645b7 65 // Sets correctly the storage: 0 for local, 1 for GRID
28afeb2e 66 fStorage = storage;
67 if(fStorage == 0)
68 AliInfo(Form("Tags will be stored locally...."));
69 if(fStorage == 1)
70 AliInfo(Form("Tags will be stored in the grid...."));
71 if((fStorage != 0)&&(fStorage != 1))
72 {
73 AliInfo(Form("Storage was not properly set!!!"));
74 abort();
75 }
76}
77
b45e5084 78
79//______________________________________________________________________________
cb1645b7 80Bool_t AliTagCreator::ReadESDCollection(TGridResult *fresult)
b45e5084 81{
cb1645b7 82 // Reads the entry of the TGridResult and creates the tags
83 Int_t nEntries = fresult->GetEntries();
b45e5084 84
cb1645b7 85 TString alienUrl;
b45e5084 86 const char *guid;
e16601cf 87 const char *md5;
88 const char *turl;
89 Long64_t size = -1;
90
b45e5084 91 Int_t counter = 0;
cb1645b7 92 for(Int_t i = 0; i < nEntries; i++)
09c52d4a 93 {
cb1645b7 94 alienUrl = fresult->GetKey(i,"turl");
09c52d4a 95 guid = fresult->GetKey(i,"guid");
e16601cf 96 if(fresult->GetKey(i,"size"))
97 size = atol (fresult->GetKey(i,"size"));
98 md5 = fresult->GetKey(i,"md5");
99 turl = fresult->GetKey(i,"turl");
100 if(md5 && !strlen(guid))
101 md5 = 0;
102 if(guid && !strlen(guid))
103 guid = 0;
104
cb1645b7 105 TFile *f = TFile::Open(alienUrl,"READ");
e16601cf 106 CreateTag(f,guid,md5,turl,size,counter);
09c52d4a 107 f->Close();
108 delete f;
b45e5084 109 counter += 1;
09c52d4a 110 }//grid result loop
b45e5084 111
112 return kTRUE;
113}
114
4fd84456 115//__________________________________________________________________________
116Bool_t AliTagCreator::MergeTags()
117{
118 //Merges the tags and stores the merged tag file
119 //locally if fStorage=0 or in the grid if fStorage=1
120 AliInfo(Form("Merging tags....."));
121 TChain *fgChain = new TChain("T");
122
123 if(fStorage == 0) {
124 const char * tagPattern = "tag";
125 // Open the working directory
126 void * dirp = gSystem->OpenDirectory(gSystem->pwd());
127 const char * name = 0x0;
128 // Add all files matching *pattern* to the chain
129 while((name = gSystem->GetDirEntry(dirp))) {
130 if (strstr(name,tagPattern))
131 fgChain->Add(name);
132 }//directory loop
133 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
134 }//local mode
135
136 else if(fStorage == 1) {
137 TString alienLocation = gGrid->Pwd();
138 alienLocation += fgridpath.Data();
139 alienLocation += "/";
140
141 TGridResult *tagresult = gGrid->Query(alienLocation,"*tag.root","","");
142 Int_t nEntries = tagresult->GetEntries();
143 for(Int_t i = 0; i < nEntries; i++) {
144 TString alienUrl = tagresult->GetKey(i,"turl");
145 fgChain->Add(alienUrl);
146 }//grid result loop
147 AliInfo(Form("Chained tag files: %d",fgChain->GetEntries()));
148 }//grid mode
149
150 AliRunTag *tag = new AliRunTag;
151 AliEventTag *evTag = new AliEventTag;
152 fgChain->SetBranchAddress("AliTAG",&tag);
153
154 //Defining new tag objects
155 AliRunTag *newTag = new AliRunTag();
156 TTree ttag("T","A Tree with event tags");
157 TBranch * btag = ttag.Branch("AliTAG", &newTag);
158 btag->SetCompressionLevel(9);
159 for(Int_t iTagFiles = 0; iTagFiles < fgChain->GetEntries(); iTagFiles++) {
160 fgChain->GetEntry(iTagFiles);
161 newTag->SetRunId(tag->GetRunId());
162 const TClonesArray *tagList = tag->GetEventTags();
163 for(Int_t j = 0; j < tagList->GetEntries(); j++) {
164 evTag = (AliEventTag *) tagList->At(j);
165 newTag->AddEventTag(*evTag);
166 }
167 ttag.Fill();
168 newTag->Clear();
169 }//tag file loop
170
171 TString localFileName = "Run"; localFileName += tag->GetRunId();
172 localFileName += ".Merged"; localFileName += ".ESD.tag.root";
173
174 TString alienFileName = "/alien";
175 alienFileName += gGrid->Pwd();
176 alienFileName += fgridpath.Data();
177 alienFileName += "/";
178 alienFileName += localFileName;
179 alienFileName += "?se=";
180 alienFileName += fSE.Data();
181
182 TString filename = 0x0;
183
184 if(fStorage == 0) {
185 filename = localFileName.Data();
186 AliInfo(Form("Writing merged tags to local file: %s",filename.Data()));
187 }
188 if(fStorage == 1) {
189 filename = alienFileName.Data();
190 AliInfo(Form("Writing merged tags to grid file: %s",filename.Data()));
191 }
192
193 TFile* ftag = TFile::Open(filename, "recreate");
194 ftag->cd();
195 ttag.Write();
196 ftag->Close();
197
198 delete tag;
199 delete evTag;
200 delete newTag;
201
202 return kTRUE;
203}
b45e5084 204
205//_____________________________________________________________________________
e16601cf 206void AliTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter)
b45e5084 207{
cb1645b7 208 // Creates the tags for all the events in a given ESD file
b45e5084 209 Int_t ntrack;
cb1645b7 210 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
211 Int_t nPos, nNeg, nNeutr;
212 Int_t nK0s, nNeutrons, nPi0s, nGamas;
213 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
214 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
215 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
216 Float_t maxPt = .0, meanPt = .0, totalP = .0;
b45e5084 217
218 AliRunTag *tag = new AliRunTag();
b45e5084 219 AliEventTag *evTag = new AliEventTag();
220 TTree ttag("T","A Tree with event tags");
4fd84456 221 TBranch * btag = ttag.Branch("AliTAG", &tag);
b45e5084 222 btag->SetCompressionLevel(9);
223
224 AliInfo(Form("Creating the tags......."));
225
226 Int_t firstEvent = 0,lastEvent = 0;
227 TTree *t = (TTree*) file->Get("esdTree");
228 TBranch * b = t->GetBranch("ESD");
229 AliESD *esd = 0;
230 b->SetAddress(&esd);
231
232 tag->SetRunId(esd->GetRunNumber());
233
cb1645b7 234 Int_t iNumberOfEvents = b->GetEntries();
235 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++)
b45e5084 236 {
237 ntrack = 0;
cb1645b7 238 nPos = 0;
239 nNeg = 0;
240 nNeutr =0;
241 nK0s = 0;
242 nNeutrons = 0;
243 nPi0s = 0;
244 nGamas = 0;
245 nProtons = 0;
246 nKaons = 0;
247 nPions = 0;
248 nMuons = 0;
249 nElectrons = 0;
250 nCh1GeV = 0;
251 nCh3GeV = 0;
252 nCh10GeV = 0;
253 nMu1GeV = 0;
254 nMu3GeV = 0;
255 nMu10GeV = 0;
256 nEl1GeV = 0;
257 nEl3GeV = 0;
258 nEl10GeV = 0;
259 maxPt = .0;
260 meanPt = .0;
261 totalP = .0;
b45e5084 262
cb1645b7 263 b->GetEntry(iEventNumber);
264 const AliESDVertex * vertexIn = esd->GetVertex();
b45e5084 265
cb1645b7 266 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++)
b45e5084 267 {
cb1645b7 268 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
269 UInt_t status = esdTrack->GetStatus();
b45e5084 270
271 //select only tracks with ITS refit
272 if ((status&AliESDtrack::kITSrefit)==0) continue;
273
274 //select only tracks with TPC refit-->remove extremely high Pt tracks
275 if ((status&AliESDtrack::kTPCrefit)==0) continue;
276
277 //select only tracks with the "combined PID"
278 if ((status&AliESDtrack::kESDpid)==0) continue;
279 Double_t p[3];
cb1645b7 280 esdTrack->GetPxPyPz(p);
281 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
b45e5084 282 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
cb1645b7 283 totalP += momentum;
284 meanPt += fPt;
285 if(fPt > maxPt)
286 maxPt = fPt;
b45e5084 287
cb1645b7 288 if(esdTrack->GetSign() > 0)
b45e5084 289 {
cb1645b7 290 nPos++;
b45e5084 291 if(fPt > 1.0)
cb1645b7 292 nCh1GeV++;
b45e5084 293 if(fPt > 3.0)
cb1645b7 294 nCh3GeV++;
b45e5084 295 if(fPt > 10.0)
cb1645b7 296 nCh10GeV++;
b45e5084 297 }
cb1645b7 298 if(esdTrack->GetSign() < 0)
b45e5084 299 {
cb1645b7 300 nNeg++;
b45e5084 301 if(fPt > 1.0)
cb1645b7 302 nCh1GeV++;
b45e5084 303 if(fPt > 3.0)
cb1645b7 304 nCh3GeV++;
b45e5084 305 if(fPt > 10.0)
cb1645b7 306 nCh10GeV++;
b45e5084 307 }
cb1645b7 308 if(esdTrack->GetSign() == 0)
309 nNeutr++;
b45e5084 310
311 //PID
312 Double_t prob[10];
cb1645b7 313 esdTrack->GetESDpid(prob);
b45e5084 314
315 //K0s
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]))
cb1645b7 317 nK0s++;
b45e5084 318 //neutrons
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]))
cb1645b7 320 nNeutrons++;
b45e5084 321 //pi0s
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]))
cb1645b7 323 nPi0s++;
b45e5084 324 //gamas
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]))
cb1645b7 326 nGamas++;
b45e5084 327 //protons
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]))
cb1645b7 329 nProtons++;
b45e5084 330 //kaons
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]))
cb1645b7 332 nKaons++;
b45e5084 333 //pions
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]))
cb1645b7 335 nPions++;
b45e5084 336 //muons
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]))
338 {
cb1645b7 339 nMuons++;
b45e5084 340 if(fPt > 1.0)
cb1645b7 341 nMu1GeV++;
b45e5084 342 if(fPt > 3.0)
cb1645b7 343 nMu3GeV++;
b45e5084 344 if(fPt > 10.0)
cb1645b7 345 nMu10GeV++;
b45e5084 346 }
347 //electrons
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]))
349 {
cb1645b7 350 nElectrons++;
b45e5084 351 if(fPt > 1.0)
cb1645b7 352 nEl1GeV++;
b45e5084 353 if(fPt > 3.0)
cb1645b7 354 nEl3GeV++;
b45e5084 355 if(fPt > 10.0)
cb1645b7 356 nEl10GeV++;
4fd84456 357 }
b45e5084 358 ntrack++;
359 }//track loop
360 // Fill the event tags
361 if(ntrack != 0)
cb1645b7 362 meanPt = meanPt/ntrack;
b45e5084 363
cb1645b7 364 evTag->SetEventId(iEventNumber+1);
b45e5084 365 evTag->SetGUID(guid);
e16601cf 366 evTag->SetMD5(md5);
367 evTag->SetTURL(turl);
368 evTag->SetSize(size);
cb1645b7 369 evTag->SetVertexX(vertexIn->GetXv());
370 evTag->SetVertexY(vertexIn->GetYv());
371 evTag->SetVertexZ(vertexIn->GetZv());
b45e5084 372
373 evTag->SetT0VertexZ(esd->GetT0zVertex());
374
375 evTag->SetTrigger(esd->GetTrigger());
376
377 evTag->SetZDCNeutronEnergy(esd->GetZDCNEnergy());
378 evTag->SetZDCProtonEnergy(esd->GetZDCPEnergy());
379 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
380 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
381
382
383 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
cb1645b7 384 evTag->SetNumOfPosTracks(nPos);
385 evTag->SetNumOfNegTracks(nNeg);
386 evTag->SetNumOfNeutrTracks(nNeutr);
b45e5084 387
388 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
389 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
390 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
391 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
392
cb1645b7 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);
b45e5084 402
cb1645b7 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);
b45e5084 412
413 evTag->SetNumOfPHOSTracks(esd->GetNumberOfPHOSParticles());
414 evTag->SetNumOfEMCALTracks(esd->GetNumberOfEMCALParticles());
415
cb1645b7 416 evTag->SetTotalMomentum(totalP);
417 evTag->SetMeanPt(meanPt);
418 evTag->SetMaxPt(maxPt);
b45e5084 419
cb1645b7 420 tag->AddEventTag(*evTag);
b45e5084 421 }
cb1645b7 422 lastEvent = iNumberOfEvents;
b45e5084 423
424 t->Delete("");
425
426 ttag.Fill();
427 tag->Clear();
428
cb1645b7 429 TString localFileName = "Run"; localFileName += tag->GetRunId();
430 localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter;
431 localFileName += ".ESD.tag.root";
b45e5084 432
cb1645b7 433 TString alienLocation = "/alien";
434 alienLocation += gGrid->Pwd();
435 alienLocation += fgridpath.Data();
436 alienLocation += "/";
437 alienLocation += localFileName;
438 alienLocation += "?se=";
439 alienLocation += fSE.Data();
28afeb2e 440
cb1645b7 441 TString fileName;
28afeb2e 442
443 if(fStorage == 0)
444 {
cb1645b7 445 fileName = localFileName.Data();
446 AliInfo(Form("Writing tags to local file: %s",fileName.Data()));
28afeb2e 447 }
448 if(fStorage == 1)
449 {
cb1645b7 450 fileName = alienLocation.Data();
451 AliInfo(Form("Writing tags to grid file: %s",fileName.Data()));
28afeb2e 452 }
b45e5084 453
cb1645b7 454 TFile* ftag = TFile::Open(fileName, "recreate");
b45e5084 455 ftag->cd();
456 ttag.Write();
457 ftag->Close();
458
459 delete ftag;
460 delete esd;
461
462 delete tag;
b45e5084 463 delete evTag;
464}
465