]>
Commit | Line | Data |
---|---|---|
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 | // AliESDTagCreator 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 | |
23 | #include <Riostream.h> | |
24 | #include <TFile.h> | |
25 | #include <TString.h> | |
26 | #include <TTree.h> | |
27 | #include <TSystem.h> | |
28 | #include <TChain.h> | |
29 | #include <TList.h> | |
30 | #include <TObjString.h> | |
31 | #include <TLorentzVector.h> | |
32 | #include <TMap.h> | |
33 | #include <TTimeStamp.h> | |
34 | #include <TRefArray.h> | |
35 | ||
36 | //ROOT-AliEn | |
37 | #include <TGrid.h> | |
38 | #include <TGridResult.h> | |
39 | ||
40 | //AliRoot | |
41 | #include "AliRunTag.h" | |
42 | #include "AliEventTag.h" | |
43 | #include "AliESD.h" | |
44 | #include "AliESDEvent.h" | |
45 | #include "AliESDVertex.h" | |
46 | #include "AliLog.h" | |
47 | #include "AliGRPObject.h" | |
48 | ||
49 | #include "AliESDTagCreator.h" | |
50 | ||
51 | ||
52 | ClassImp(AliESDTagCreator) | |
53 | ||
54 | ||
55 | //______________________________________________________________________________ | |
56 | AliESDTagCreator::AliESDTagCreator() : | |
57 | AliTagCreator(), | |
58 | fChain(new TChain("esdTree")), fGUIDList(new TList()), | |
59 | fMD5List(new TList()), fTURLList(new TList()), fBranches(""), | |
60 | meminfo(new MemInfo_t) { | |
61 | //==============Default constructor for a AliESDTagCreator================ | |
62 | } | |
63 | ||
64 | //______________________________________________________________________________ | |
65 | AliESDTagCreator::~AliESDTagCreator() { | |
66 | //================Default destructor for a AliESDTagCreator=================== | |
67 | delete fChain; | |
68 | delete fGUIDList; | |
69 | delete fMD5List; | |
70 | delete fTURLList; | |
71 | delete meminfo; | |
72 | } | |
73 | ||
74 | //______________________________________________________________________________ | |
75 | Bool_t AliESDTagCreator::ReadGridCollection(TGridResult *fresult) { | |
76 | // Reads the entry of the TGridResult and creates the tags | |
77 | Int_t nEntries = fresult->GetEntries(); | |
78 | ||
79 | TString alienUrl; | |
80 | // const char* guid; | |
81 | // const char* md5; | |
82 | // const char* turl; | |
83 | // Long64_t size = -1; | |
84 | ||
85 | Int_t counter = 0; | |
86 | for(Int_t i = 0; i < nEntries; i++) { | |
87 | alienUrl = fresult->GetKey(i,"turl"); | |
88 | // guid = fresult->GetKey(i,"guid"); | |
89 | // if(fresult->GetKey(i,"size")) size = atol (fresult->GetKey(i,"size")); | |
90 | // md5 = fresult->GetKey(i,"md5"); | |
91 | // turl = fresult->GetKey(i,"turl"); | |
92 | // if(md5 && !strlen(guid)) md5 = 0; | |
93 | // if(guid && !strlen(guid)) guid = 0; | |
94 | ||
95 | fChain->Add(alienUrl); | |
96 | //fGUIDList->Add(new TObjString(guid)); | |
97 | //fMD5List->Add(new TObjString(md5)); | |
98 | //fTURLList->Add(new TObjString(turl)); | |
99 | ||
100 | //TFile *f = TFile::Open(alienUrl,"READ"); | |
101 | //CreateTag(f,guid,md5,turl,size,counter); | |
102 | //f->Close(); | |
103 | //delete f; | |
104 | counter += 1; | |
105 | }//grid result loop | |
106 | ||
107 | if (fChain->GetEntries() > 0) { | |
108 | AliInfo(Form("ESD chain created.......")); | |
109 | AliInfo(Form("Chain entries: %lld",fChain->GetEntries())); | |
110 | } else { | |
111 | AliWarning(Form("No ESD files found !")); | |
112 | return kFALSE; | |
113 | } | |
114 | ||
115 | // Switch of branches on user request | |
116 | SwitchOffBranches(); | |
117 | CreateTag(fChain,"grid"); | |
118 | ||
119 | return kTRUE; | |
120 | } | |
121 | ||
122 | //______________________________________________________________________________ | |
123 | Bool_t AliESDTagCreator::ReadLocalCollection(const char *localpath) { | |
124 | // Checks the different subdirs of the given local path and in the | |
125 | // case where it finds an AliESDs.root file it creates the tags | |
126 | ||
127 | void *dira = gSystem->OpenDirectory(localpath); | |
128 | Char_t fPath[512]; | |
129 | const char * dirname = 0x0; | |
130 | const char * filename = 0x0; | |
131 | const char * pattern = "AliESDs.root"; | |
132 | ||
133 | Int_t counter = 0; | |
134 | while((dirname = gSystem->GetDirEntry(dira))) { | |
135 | snprintf(fPath, 512,"%s/%s",localpath,dirname); | |
136 | void *dirb = gSystem->OpenDirectory(fPath); | |
137 | while((filename = gSystem->GetDirEntry(dirb))) { | |
138 | if(strstr(filename,pattern)) { | |
139 | TString fESDFileName; | |
140 | fESDFileName = fPath; | |
141 | fESDFileName += "/"; | |
142 | fESDFileName += pattern; | |
143 | ||
144 | fChain->Add(fESDFileName); | |
145 | ||
146 | //TFile *f = TFile::Open(fESDFileName,"READ"); | |
147 | //CreateTag(f,fESDFileName,counter); | |
148 | //f->Close(); | |
149 | //delete f; | |
150 | ||
151 | counter += 1; | |
152 | }//pattern check | |
153 | }//child directory's entry loop | |
154 | }//parent directory's entry loop | |
155 | ||
156 | AliInfo(Form("ESD chain created.......")); | |
157 | AliInfo(Form("Chain entries: %lld",fChain->GetEntries())); | |
158 | // Switch of branches on user request | |
159 | SwitchOffBranches(); | |
160 | CreateTag(fChain,"local"); | |
161 | ||
162 | return kTRUE; | |
163 | } | |
164 | ||
165 | //______________________________________________________________________________ | |
166 | Bool_t AliESDTagCreator::ReadCAFCollection(const char *filename) { | |
167 | // Temporary solution for CAF: Takes as an input the ascii file that | |
168 | // lists the ESDs stored in the SE of the CAF and creates the tags. | |
169 | ||
170 | // Open the input stream | |
171 | ifstream in; | |
172 | in.open(filename); | |
173 | ||
174 | Int_t counter = 0; | |
175 | TString esdfile; | |
176 | // Read the input list of files and add them to the chain | |
177 | while(in.good()) { | |
178 | in >> esdfile; | |
179 | if (!esdfile.Contains("root")) continue; // protection | |
180 | ||
181 | fChain->Add(esdfile); | |
182 | ||
183 | //TFile *f = TFile::Open(esdfile,"READ"); | |
184 | //CreateTag(f,esdfile,counter); | |
185 | //f->Close(); | |
186 | //delete f; | |
187 | ||
188 | counter += 1; | |
189 | } | |
190 | ||
191 | AliInfo(Form("ESD chain created.......")); | |
192 | AliInfo(Form("Chain entries: %lld",fChain->GetEntries())); | |
193 | // Switch of branches on user request | |
194 | SwitchOffBranches(); | |
195 | CreateTag(fChain,"proof"); | |
196 | ||
197 | return kTRUE; | |
198 | } | |
199 | ||
200 | //_____________________________________________________________________________ | |
201 | void AliESDTagCreator::CreateTag(TChain* chain, const char *type) { | |
202 | //private method that creates tag files | |
203 | TString fSession = type; | |
204 | TString fguid, fmd5, fturl, foldguid; | |
205 | TString fTempGuid; | |
206 | ||
207 | Int_t iRunNumber = 0; | |
208 | //gSystem->GetMemInfo(meminfo); | |
209 | //AliInfo(Form("After the tag initialization - Memory used: %d MB",meminfo->fMemUsed)); | |
210 | //Int_t tempmem = meminfo->fMemUsed; | |
211 | ||
212 | AliInfo(Form("Creating the ESD tags.......")); | |
213 | ||
214 | Int_t firstEvent = 0,lastEvent = 0; | |
215 | AliESDEvent *esd = new AliESDEvent(); | |
216 | esd->ReadFromTree(chain); | |
217 | // AliESD *esdold = 0x0; | |
218 | ||
219 | //gSystem->GetMemInfo(meminfo); | |
220 | //AliInfo(Form("After the esd initialization - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
221 | //tempmem = meminfo->fMemUsed; | |
222 | ||
223 | Int_t iInitRunNumber = -1; | |
224 | chain->GetEntry(0); | |
225 | TFile *f = chain->GetFile(); | |
226 | fTempGuid = f->GetUUID().AsString(); | |
227 | ||
228 | TString localFileName = "Run"; localFileName += esd->GetRunNumber(); | |
229 | localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += chain->GetEntries(); //localFileName += "."; localFileName += Counter; | |
230 | localFileName += ".ESD.tag.root"; | |
231 | ||
232 | TString fileName; | |
233 | ||
234 | if(fStorage == 0) { | |
235 | fileName = localFileName.Data(); | |
236 | AliInfo(Form("Writing tags to local file: %s",fileName.Data())); | |
237 | } | |
238 | else if(fStorage == 1) { | |
239 | TString alienLocation = "/alien"; | |
240 | alienLocation += gGrid->Pwd(); | |
241 | alienLocation += fgridpath.Data(); | |
242 | alienLocation += "/"; | |
243 | alienLocation += localFileName; | |
244 | alienLocation += "?se="; | |
245 | alienLocation += fSE.Data(); | |
246 | fileName = alienLocation.Data(); | |
247 | AliInfo(Form("Writing tags to grid file: %s",fileName.Data())); | |
248 | } | |
249 | ||
250 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
251 | ||
252 | AliRunTag *tag = new AliRunTag(); | |
253 | AliEventTag *evTag = new AliEventTag(); | |
254 | TTree * ttag = new TTree("T","A Tree with event tags"); | |
255 | TBranch * btag = ttag->Branch("AliTAG", &tag); | |
256 | btag->SetCompressionLevel(9); | |
257 | // Run related information | |
258 | tag->SetMagneticField(esd->GetMagneticField()); | |
259 | tag->SetBeamEnergy(esd->GetBeamEnergy()); | |
260 | tag->SetBeamType(TString(esd->GetBeamType())); | |
261 | tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses()); | |
262 | ||
263 | foldguid = ""; | |
264 | ||
265 | for(Int_t iEventNumber = 0; iEventNumber < chain->GetEntries(); iEventNumber++) { | |
266 | FillEventTag(chain, evTag, iEventNumber, esd); | |
267 | ||
268 | if(iEventNumber == 0) iInitRunNumber = esd->GetRunNumber(); | |
269 | iRunNumber = esd->GetRunNumber(); | |
270 | if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD - You are trying to merge different runs!!!"); | |
271 | ||
272 | TFile *file = chain->GetFile(); | |
273 | // const TUrl *url = file->GetEndpointUrl(); | |
274 | fguid = file->GetUUID().AsString(); | |
275 | ||
276 | if (foldguid == fguid) { | |
277 | tag->AddEventTag(*evTag); | |
278 | } | |
279 | else { | |
280 | AliFileTag *nftag = new AliFileTag(); | |
281 | nftag->SetGUID(fguid); | |
282 | ||
283 | // if(fSession == "grid") { | |
284 | // TString fturltemp = "alien://"; fturltemp += url->GetFile(); | |
285 | // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5); | |
286 | // } | |
287 | // else fturl = url->GetFile(); | |
288 | fturl = file->GetName(); | |
289 | ||
290 | if(fSession == "grid") { | |
291 | nftag->SetMD5(""); | |
292 | nftag->SetTURL(fturl); | |
293 | nftag->SetSize(0); | |
294 | } | |
295 | else { | |
296 | nftag->SetPath(fturl); | |
297 | nftag->SetSize(0); | |
298 | nftag->SetMD5(""); | |
299 | nftag->SetTURL(fturl); | |
300 | } | |
301 | foldguid = fguid; | |
302 | ||
303 | if (tag->GetFileId(fguid) > -1) | |
304 | AliFatal("Adding a file which is already in the RunTag."); | |
305 | ||
306 | tag->AddFileTag(nftag); | |
307 | } | |
308 | ||
309 | tag->SetRunId(iInitRunNumber); | |
310 | // if(fIsSim) tag->SetDataType(0); | |
311 | // else tag->SetDataType(1); | |
312 | ||
313 | // if(fguid != fTempGuid) { | |
314 | // fTempGuid = fguid; | |
315 | // ttag->Fill(); | |
316 | // tag->Clear(""); | |
317 | // } | |
318 | if(iEventNumber+1 == chain->GetEntries()) { | |
319 | //AliInfo(Form("File: %s",fturl.Data())); | |
320 | ||
321 | ttag->Fill(); | |
322 | tag->Clear(""); | |
323 | } | |
324 | }//event loop | |
325 | lastEvent = chain->GetEntries(); | |
326 | ||
327 | //gSystem->GetMemInfo(meminfo); | |
328 | //AliInfo(Form("After the event and track loop - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
329 | //tempmem = meminfo->fMemUsed; | |
330 | ||
331 | //chain->Delete(""); | |
332 | ||
333 | //gSystem->GetMemInfo(meminfo); | |
334 | //AliInfo(Form("After the t->Delete - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
335 | //tempmem = meminfo->fMemUsed; | |
336 | ||
337 | ftag->cd(); | |
338 | tag->Clear(); | |
339 | ttag->Write(); | |
340 | ftag->Close(); | |
341 | ||
342 | //gSystem->GetMemInfo(meminfo); | |
343 | //AliInfo(Form("After the file closing - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
344 | //tempmem = meminfo->fMemUsed; | |
345 | ||
346 | delete esd; | |
347 | delete tag; | |
348 | ||
349 | //gSystem->GetMemInfo(meminfo); | |
350 | //AliInfo(Form("After the delete objects - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
351 | } | |
352 | ||
353 | //_____________________________________________________________________________ | |
354 | void AliESDTagCreator::CreateTag(TFile* file, const char *guid, const char *md5, const char *turl, Long64_t size, Int_t Counter) { | |
355 | //private method that creates tag files | |
356 | TString fguid = guid; | |
357 | TString fmd5 = md5; | |
358 | TString fturl = turl; | |
359 | ///////////// | |
360 | //muon code// | |
361 | //////////// | |
362 | // Double_t fMUONMASS = 0.105658369; | |
363 | //Variables | |
364 | // Double_t fX,fY,fZ ; | |
365 | // Double_t fThetaX, fThetaY, fPyz, fChisquare; | |
366 | // Double_t fPxRec, fPyRec, fPzRec, fEnergy; | |
367 | // Int_t fCharge; | |
368 | // TLorentzVector fEPvector; | |
369 | ||
370 | // Float_t fLowPtCut = 1.0; | |
371 | // Float_t fHighPtCut = 3.0; | |
372 | // Float_t fVeryHighPtCut = 10.0; | |
373 | //////////// | |
374 | ||
375 | // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05}; | |
376 | ||
377 | // Creates the tags for all the events in a given ESD file | |
378 | Bool_t fIsSim = kTRUE; | |
379 | // Int_t ntrack; | |
380 | // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons; | |
381 | // Int_t nPos, nNeg, nNeutr; | |
382 | // Int_t nK0s, nNeutrons, nPi0s, nGamas; | |
383 | // Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
384 | // Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
385 | // Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
386 | // Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0; | |
387 | // Int_t fVertexflag; | |
388 | Int_t iRunNumber = 0; | |
389 | // TString fVertexName; | |
390 | // TRefArray tmp; | |
391 | ||
392 | AliRunTag *tag = new AliRunTag(); | |
393 | AliEventTag *evTag = new AliEventTag(); | |
394 | TTree * ttag = new TTree("T","A Tree with event tags"); | |
395 | TBranch * btag = ttag->Branch("AliTAG", &tag); | |
396 | btag->SetCompressionLevel(9); | |
397 | gSystem->GetMemInfo(meminfo); | |
398 | AliInfo(Form("After the tag initialization - Memory used: %d MB",meminfo->fMemUsed)); | |
399 | Int_t tempmem = meminfo->fMemUsed; | |
400 | ||
401 | AliInfo(Form("Creating the ESD tags.......")); | |
402 | ||
403 | Int_t firstEvent = 0,lastEvent = 0; | |
404 | TTree *t = (TTree*) file->Get("esdTree"); | |
405 | AliESDEvent *esd = new AliESDEvent(); | |
406 | esd->ReadFromTree(t); | |
407 | ||
408 | gSystem->GetMemInfo(meminfo); | |
409 | AliInfo(Form("After the esd initialization - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
410 | tempmem = meminfo->fMemUsed; | |
411 | ||
412 | t->GetEntry(0); | |
413 | Int_t iInitRunNumber = esd->GetRunNumber(); | |
414 | tag->SetMagneticField(esd->GetMagneticField()); | |
415 | tag->SetBeamEnergy(esd->GetBeamEnergy()); | |
416 | tag->SetBeamType(TString(esd->GetBeamType())); | |
417 | tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses()); | |
418 | ||
419 | AliFileTag *eftag = new AliFileTag(); | |
420 | eftag->SetMD5(md5); | |
421 | eftag->SetTURL(fturl); | |
422 | eftag->SetSize(size); | |
423 | tag->AddFileTag(eftag); | |
424 | ||
425 | Int_t iNumberOfEvents = (Int_t)t->GetEntries(); | |
426 | for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) { | |
427 | FillEventTag(t, evTag, iEventNumber, esd); | |
428 | iRunNumber = esd->GetRunNumber(); | |
429 | if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!"); | |
430 | ||
431 | tag->SetRunId(iInitRunNumber); | |
432 | if(fIsSim) tag->SetDataType(0); | |
433 | else tag->SetDataType(1); | |
434 | tag->AddEventTag(*evTag); | |
435 | }//event loop | |
436 | lastEvent = iNumberOfEvents; | |
437 | ||
438 | gSystem->GetMemInfo(meminfo); | |
439 | AliInfo(Form("After the event and track loop - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
440 | tempmem = meminfo->fMemUsed; | |
441 | t->Delete(""); | |
442 | ||
443 | gSystem->GetMemInfo(meminfo); | |
444 | AliInfo(Form("After the t->Delete - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
445 | tempmem = meminfo->fMemUsed; | |
446 | ||
447 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
448 | localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter; | |
449 | localFileName += ".ESD.tag.root"; | |
450 | ||
451 | TString fileName; | |
452 | ||
453 | if(fStorage == 0) { | |
454 | fileName = localFileName.Data(); | |
455 | AliInfo(Form("Writing tags to local file: %s",fileName.Data())); | |
456 | } | |
457 | else if(fStorage == 1) { | |
458 | TString alienLocation = "/alien"; | |
459 | alienLocation += gGrid->Pwd(); | |
460 | alienLocation += fgridpath.Data(); | |
461 | alienLocation += "/"; | |
462 | alienLocation += localFileName; | |
463 | alienLocation += "?se="; | |
464 | alienLocation += fSE.Data(); | |
465 | fileName = alienLocation.Data(); | |
466 | AliInfo(Form("Writing tags to grid file: %s",fileName.Data())); | |
467 | } | |
468 | ||
469 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
470 | ftag->cd(); | |
471 | ttag->Fill(); | |
472 | tag->Clear(); | |
473 | ttag->Write(); | |
474 | ftag->Close(); | |
475 | ||
476 | gSystem->GetMemInfo(meminfo); | |
477 | AliInfo(Form("After the file closing - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
478 | tempmem = meminfo->fMemUsed; | |
479 | ||
480 | delete ftag; | |
481 | delete esd; | |
482 | ||
483 | delete tag; | |
484 | gSystem->GetMemInfo(meminfo); | |
485 | AliInfo(Form("After the delete objects - Memory used: %d MB - Increase: %d MB",meminfo->fMemUsed,meminfo->fMemUsed - tempmem)); | |
486 | } | |
487 | ||
488 | //_____________________________________________________________________________ | |
489 | void AliESDTagCreator::CreateTag(TFile* file, const char *filepath, Int_t Counter) { | |
490 | //private method that creates tag files | |
491 | ///////////// | |
492 | //muon code// | |
493 | //////////// | |
494 | // Double_t fMUONMASS = 0.105658369; | |
495 | //Variables | |
496 | // Double_t fX,fY,fZ ; | |
497 | // Double_t fThetaX, fThetaY, fPyz, fChisquare; | |
498 | // Double_t fPxRec, fPyRec, fPzRec, fEnergy; | |
499 | // Int_t fCharge; | |
500 | // TLorentzVector fEPvector; | |
501 | ||
502 | // Float_t fLowPtCut = 1.0; | |
503 | // Float_t fHighPtCut = 3.0; | |
504 | // Float_t fVeryHighPtCut = 10.0; | |
505 | //////////// | |
506 | ||
507 | // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05}; | |
508 | ||
509 | // Creates the tags for all the events in a given ESD file | |
510 | // Bool_t fIsSim = kTRUE; | |
511 | // Int_t ntrack; | |
512 | // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons; | |
513 | // Int_t nPos, nNeg, nNeutr; | |
514 | // Int_t nK0s, nNeutrons, nPi0s, nGamas; | |
515 | // Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
516 | // Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
517 | // Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
518 | // Float_t maxPt = .0, etamaxPt = -999, phimaxPt = -999., meanPt = .0, totalP = .0; | |
519 | // Int_t fVertexflag; | |
520 | Int_t iRunNumber = 0; | |
521 | // TString fVertexName; | |
522 | // TRefArray tmp; | |
523 | ||
524 | AliRunTag *tag = new AliRunTag(); | |
525 | AliEventTag *evTag = new AliEventTag(); | |
526 | TTree * ttag = new TTree("T","A Tree with event tags"); | |
527 | TBranch * btag = ttag->Branch("AliTAG", &tag); | |
528 | btag->SetCompressionLevel(9); | |
529 | ||
530 | AliInfo(Form("Creating the ESD tags.......")); | |
531 | ||
532 | Int_t firstEvent = 0,lastEvent = 0; | |
533 | ||
534 | TTree *t = (TTree*) file->Get("esdTree"); | |
535 | AliESDEvent *esd = new AliESDEvent(); | |
536 | esd->ReadFromTree(t); | |
537 | ||
538 | t->GetEntry(0); | |
539 | Int_t iInitRunNumber = esd->GetRunNumber(); | |
540 | tag->SetMagneticField(esd->GetMagneticField()); | |
541 | tag->SetBeamEnergy(esd->GetBeamEnergy()); | |
542 | tag->SetBeamType(TString(esd->GetBeamType())); | |
543 | tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses()); | |
544 | ||
545 | AliFileTag *eftag = new AliFileTag(); | |
546 | eftag->SetPath(filepath); | |
547 | eftag->SetTURL(Form("local://%s", filepath)); | |
548 | eftag->SetSize(0); | |
549 | eftag->SetMD5(""); | |
550 | tag->AddFileTag(eftag); | |
551 | ||
552 | Int_t iNumberOfEvents = (Int_t)t->GetEntries(); | |
553 | for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) { | |
554 | FillEventTag(t, evTag, iEventNumber, esd); | |
555 | iRunNumber = esd->GetRunNumber(); | |
556 | if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!"); | |
557 | // evTag->SetPath(filepath); | |
558 | ||
559 | tag->SetRunId(iInitRunNumber); | |
560 | // if(fIsSim) tag->SetDataType(0); | |
561 | // else tag->SetDataType(1); | |
562 | tag->AddEventTag(*evTag); | |
563 | }//event loop | |
564 | lastEvent = iNumberOfEvents; | |
565 | ||
566 | t->Delete(""); | |
567 | ||
568 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
569 | localFileName += ".Event"; localFileName += firstEvent; localFileName += "_"; localFileName += lastEvent; localFileName += "."; localFileName += Counter; | |
570 | localFileName += ".ESD.tag.root"; | |
571 | ||
572 | TString fileName; | |
573 | ||
574 | if(fStorage == 0) { | |
575 | fileName = localFileName.Data(); | |
576 | AliInfo(Form("Writing tags to local file: %s",fileName.Data())); | |
577 | } | |
578 | else if(fStorage == 1) { | |
579 | TString alienLocation = "/alien"; | |
580 | alienLocation += gGrid->Pwd(); | |
581 | alienLocation += fgridpath.Data(); | |
582 | alienLocation += "/"; | |
583 | alienLocation += localFileName; | |
584 | alienLocation += "?se="; | |
585 | alienLocation += fSE.Data(); | |
586 | fileName = alienLocation.Data(); | |
587 | AliInfo(Form("Writing tags to grid file: %s",fileName.Data())); | |
588 | } | |
589 | ||
590 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
591 | ftag->cd(); | |
592 | ttag->Fill(); | |
593 | tag->Clear(); | |
594 | ttag->Write(); | |
595 | ftag->Close(); | |
596 | ||
597 | delete ftag; | |
598 | delete esd; | |
599 | ||
600 | delete tag; | |
601 | } | |
602 | ||
603 | //_____________________________________________________________________________ | |
604 | void AliESDTagCreator::CreateESDTags(Int_t fFirstEvent, Int_t fLastEvent, AliGRPObject *grpData, ULong_t * qa, Bool_t * es, Int_t qalength, Int_t eslength) { | |
605 | //GRP | |
606 | Float_t lhcLuminosity = 0.0; | |
607 | TString lhcState = "test"; | |
608 | //UInt_t detectorMask = 0; | |
609 | Int_t detectorMask = 0; | |
610 | ||
611 | detectorMask = grpData->GetDetectorMask(); | |
612 | time_t startTime = grpData->GetTimeStart(); | |
613 | TTimeStamp t1(startTime); | |
614 | time_t endTime = grpData->GetTimeEnd(); | |
615 | TTimeStamp t2(endTime); | |
616 | const char* beamtype = grpData->GetBeamType(); | |
617 | Float_t beamenergy = grpData->GetBeamEnergy(); | |
618 | ||
619 | ||
620 | ///////////// | |
621 | //muon code// | |
622 | //////////// | |
623 | // Double_t fMUONMASS = 0.105658369; | |
624 | //Variables | |
625 | // Double_t fX,fY,fZ ; | |
626 | // Double_t fThetaX, fThetaY, fPyz, fChisquare; | |
627 | // Double_t fPxRec,fPyRec, fPzRec, fEnergy; | |
628 | // Int_t fCharge; | |
629 | // TLorentzVector fEPvector; | |
630 | ||
631 | // Float_t fLowPtCut = 1.0; | |
632 | // Float_t fHighPtCut = 3.0; | |
633 | // Float_t fVeryHighPtCut = 10.0; | |
634 | //////////// | |
635 | ||
636 | // Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05}; | |
637 | ||
638 | // Creates the tags for all the events in a given ESD file | |
639 | // Int_t ntrack; | |
640 | // Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons; | |
641 | // Int_t nPos, nNeg, nNeutr; | |
642 | // Int_t nK0s, nNeutrons, nPi0s, nGamas; | |
643 | // Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
644 | // Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
645 | // Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
646 | // Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0; | |
647 | // Int_t fVertexflag; | |
648 | Int_t iRunNumber = 0; | |
649 | TString fguid, fmd5, fturl; | |
650 | // TString fVertexName("default"); | |
651 | // TRefArray tmp; | |
652 | ||
653 | AliInfo(Form("Creating the ESD tags.......")); | |
654 | ||
655 | TFile *esdfile = TFile::Open("AliESDs.root"); | |
656 | if (!esdfile || !esdfile->IsOpen()) { | |
657 | AliError(Form("opening failed")); | |
658 | delete esdfile; | |
659 | return ; | |
660 | } | |
661 | Int_t lastEvent = 0; | |
662 | TTree *b = (TTree*) esdfile->Get("esdTree"); | |
663 | AliESDEvent *esd = new AliESDEvent(); | |
664 | esd->ReadFromTree(b); | |
665 | ||
666 | b->GetEntry(fFirstEvent); | |
667 | Int_t iInitRunNumber = esd->GetRunNumber(); | |
668 | ||
669 | Int_t iNumberOfEvents = (Int_t)b->GetEntries(); | |
670 | if ((fLastEvent == -1) || ((Int_t) b->GetEntries() < fLastEvent)) | |
671 | lastEvent = (Int_t)b->GetEntries(); | |
672 | else lastEvent = fLastEvent; | |
673 | ||
674 | char fileName[256]; | |
675 | snprintf(fileName, 256, "Run%d.Event%d_%d.ESD.tag.root", | |
676 | iInitRunNumber,fFirstEvent,lastEvent); | |
677 | AliInfo(Form("writing tags to file %s", fileName)); | |
678 | AliDebug(1, Form("writing tags to file %s", fileName)); | |
679 | ||
680 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
681 | ||
682 | AliRunTag *tag = new AliRunTag(); | |
683 | AliEventTag *evTag = new AliEventTag(); | |
684 | TTree * ttag = new TTree("T","A Tree with event tags"); | |
685 | TBranch * btag = ttag->Branch("AliTAG", &tag); | |
686 | btag->SetCompressionLevel(9); | |
687 | ||
688 | if ((fLastEvent != -1) && ((Int_t) b->GetEntries() > fLastEvent)) | |
689 | iNumberOfEvents = fLastEvent + 1; | |
690 | ||
691 | AliFileTag *eftag = new AliFileTag(); | |
692 | tag->AddFileTag(eftag); | |
693 | ||
694 | for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) { | |
695 | FillEventTag(b, evTag, iEventNumber, esd); | |
696 | iRunNumber = esd->GetRunNumber(); | |
697 | if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!"); | |
698 | ||
699 | if (iEventNumber == fFirstEvent) { | |
700 | TFile *file = b->GetCurrentFile(); | |
701 | // const TUrl *url = file->GetEndpointUrl(); | |
702 | fguid = file->GetUUID().AsString(); | |
703 | ||
704 | // if(fStorage == 1) { | |
705 | // TString fturltemp = "alien://"; fturltemp += url->GetFile(); | |
706 | // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5); | |
707 | // } | |
708 | // else fturl = url->GetFile(); | |
709 | fturl = file->GetName(); | |
710 | ||
711 | // evTag->SetGUID(fguid); | |
712 | ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetGUID(fguid); | |
713 | if(fStorage == 1) { | |
714 | ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetMD5(""); | |
715 | ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetTURL(fturl); | |
716 | ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetSize(0); | |
717 | } | |
718 | else { | |
719 | // evTag->SetPath(fturl); | |
720 | ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetPath(fturl); | |
721 | ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetMD5(""); | |
722 | ((AliFileTag *) tag->GetFileTag(tag->GetNFiles()-1))->SetSize(0); | |
723 | } | |
724 | ||
725 | } | |
726 | ||
727 | tag->AddEventTag(*evTag); | |
728 | } | |
729 | ||
730 | tag->SetLHCTag(lhcLuminosity,lhcState); | |
731 | tag->SetDetectorTag(esd->GetESDRun()->GetDetectorsInDAQ(), esd->GetESDRun()->GetDetectorsInReco()); | |
732 | tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses()); | |
733 | ||
734 | // Get magnetic field info | |
735 | Bool_t ok = kTRUE; | |
736 | ||
737 | Float_t l3Current = grpData->GetL3Current((AliGRPObject::Stats)0); | |
738 | if (l3Current == AliGRPObject::GetInvalidFloat()) { | |
739 | AliError("GRP/GRP/Data entry: missing value for the L3 current !"); | |
740 | ok = kFALSE; | |
741 | } | |
742 | ||
743 | Char_t l3Polarity = grpData->GetL3Polarity(); | |
744 | if (l3Polarity == AliGRPObject::GetInvalidChar()) { | |
745 | AliError("GRP/GRP/Data entry: missing value for the L3 polarity !"); | |
746 | ok = kFALSE; | |
747 | } | |
748 | ||
749 | // Dipole | |
750 | Float_t diCurrent = grpData->GetDipoleCurrent((AliGRPObject::Stats)0); | |
751 | if (diCurrent == AliGRPObject::GetInvalidFloat()) { | |
752 | AliError("GRP/GRP/Data entry: missing value for the dipole current !"); | |
753 | ok = kFALSE; | |
754 | } | |
755 | ||
756 | Char_t diPolarity = grpData->GetDipolePolarity(); | |
757 | if (diPolarity == AliGRPObject::GetInvalidChar()) { | |
758 | AliError("GRP/GRP/Data entry: missing value for the dipole polarity !"); | |
759 | ok = kFALSE; | |
760 | } | |
761 | ||
762 | if (ok && grpData->IsPolarityConventionLHC()) { | |
763 | if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 1)) | |
764 | tag->SetMagneticField(-0.5); | |
765 | if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 0)) | |
766 | tag->SetMagneticField(0.5); | |
767 | if (TMath::Abs(l3Current) < 2000.0) | |
768 | tag->SetMagneticField(0.0); | |
769 | ||
770 | if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 1)) | |
771 | tag->SetDipoleField(-0.2); | |
772 | if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 0)) | |
773 | tag->SetDipoleField(0.2); | |
774 | if (TMath::Abs(diCurrent) < 500.0) | |
775 | tag->SetDipoleField(0.0); | |
776 | } | |
777 | ||
778 | tag->SetRunId(iInitRunNumber); | |
779 | tag->SetRunStartTime(t1.GetDate()); | |
780 | tag->SetRunStopTime(t2.GetDate()); | |
781 | tag->SetBeamEnergy(beamenergy); | |
782 | tag->SetBeamType(beamtype); | |
783 | ||
784 | //QA setting | |
785 | tag->SetQAArray(qa, qalength) ; | |
786 | tag->SetEventSpecies(es, eslength) ; | |
787 | ||
788 | ftag->cd(); | |
789 | ttag->Fill(); | |
790 | tag->Clear(); | |
791 | ttag->Write(); | |
792 | ftag->Close(); | |
793 | esdfile->cd(); | |
794 | delete esdfile; | |
795 | delete ftag; | |
796 | delete esd; | |
797 | delete tag; | |
798 | delete evTag; | |
799 | } | |
800 | ||
801 | void AliESDTagCreator::CreateESDTagsFullRun(TTree *chain, AliGRPObject *grpData, ULong_t * qa, Bool_t * es, Int_t qalength, Int_t eslength) | |
802 | { | |
803 | //GRP | |
804 | Float_t lhcLuminosity = 0.0; | |
805 | TString lhcState = "test"; | |
806 | //UInt_t detectorMask = 0; | |
807 | Int_t detectorMask = 0; | |
808 | ||
809 | detectorMask = grpData->GetDetectorMask(); | |
810 | time_t startTime = grpData->GetTimeStart(); | |
811 | TTimeStamp t1(startTime); | |
812 | time_t endTime = grpData->GetTimeEnd(); | |
813 | TTimeStamp t2(endTime); | |
814 | const char* beamtype = grpData->GetBeamType(); | |
815 | Float_t beamenergy = grpData->GetBeamEnergy(); | |
816 | ||
817 | Int_t iRunNumber = 0; | |
818 | TString fguid, fmd5, fturl; | |
819 | TString fturlold; | |
820 | ||
821 | AliInfo(Form("Creating the ESD tags.......")); | |
822 | ||
823 | AliESDEvent *esd = new AliESDEvent(); | |
824 | esd->ReadFromTree(chain); | |
825 | ||
826 | chain->GetEntry(0); | |
827 | Int_t iInitRunNumber = esd->GetRunNumber(); | |
828 | ||
829 | Int_t iNumberOfEvents = (Int_t)chain->GetEntries(); | |
830 | Int_t iFirstEvent = 0; | |
831 | ||
832 | char fileName[256]; | |
833 | snprintf(fileName, 256, "Run%d.Event%d_%d.ESD.tag.root", | |
834 | iInitRunNumber,iFirstEvent,iNumberOfEvents); | |
835 | AliInfo(Form("writing tags to file %s", fileName)); | |
836 | AliDebug(1, Form("writing tags to file %s", fileName)); | |
837 | ||
838 | TFile* ftag = TFile::Open(fileName, "recreate"); | |
839 | ||
840 | AliRunTag *tag = new AliRunTag(); | |
841 | AliEventTag *evTag = new AliEventTag(); | |
842 | TTree * ttag = new TTree("T","A Tree with event tags"); | |
843 | TBranch * btag = ttag->Branch("AliTAG", &tag); | |
844 | btag->SetCompressionLevel(9); | |
845 | ||
846 | // AliFileTag *eftag = new AliFileTag(); | |
847 | // tag->AddFileTag(*eftag); | |
848 | ||
849 | for (Int_t iEventNumber = iFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) { | |
850 | FillEventTag(chain, evTag, iEventNumber, esd); | |
851 | ||
852 | iRunNumber = esd->GetRunNumber(); | |
853 | if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!"); | |
854 | ||
855 | TFile *file = chain->GetCurrentFile(); | |
856 | // const TUrl *url = file->GetName(); | |
857 | fguid = file->GetUUID().AsString(); | |
858 | fturl = file->GetName(); | |
859 | // if(fStorage == 1) { | |
860 | // TString fturltemp = "alien://"; fturltemp += url->GetFile(); | |
861 | // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5); | |
862 | // } | |
863 | // else fturl = url->GetFile(); | |
864 | ||
865 | if (fturl.CompareTo(fturlold)) { | |
866 | ||
867 | AliFileTag *eftag = new AliFileTag(); | |
868 | ||
869 | //evTag->SetGUID(fguid); | |
870 | eftag->SetGUID(fguid); | |
871 | if(fStorage == 1) { | |
872 | // evTag->SetMD5(""); | |
873 | // evTag->SetTURL(fturl); | |
874 | // evTag->SetSize(0); | |
875 | eftag->SetPath(""); | |
876 | eftag->SetMD5(""); | |
877 | eftag->SetTURL(fturl); | |
878 | eftag->SetSize(0); | |
879 | } | |
880 | else { | |
881 | // evTag->SetPath(fturl); | |
882 | // evTag->SetTURL(fturl); | |
883 | eftag->SetPath(fturl); | |
884 | eftag->SetTURL(fturl); | |
885 | eftag->SetMD5(""); | |
886 | eftag->SetSize(0); | |
887 | } | |
888 | ||
889 | tag->AddFileTag(eftag); | |
890 | ||
891 | fturlold = fturl; | |
892 | ||
893 | } | |
894 | else { | |
895 | // cout << "FileTag found " << fturl.Data() << " " << fturlold.Data() << endl; | |
896 | } | |
897 | ||
898 | tag->AddEventTag(*evTag); | |
899 | } | |
900 | ||
901 | tag->SetLHCTag(lhcLuminosity,lhcState); | |
902 | tag->SetDetectorTag(esd->GetESDRun()->GetDetectorsInDAQ(), esd->GetESDRun()->GetDetectorsInReco()); | |
903 | tag->SetActiveTriggerClasses(esd->GetESDRun()->GetActiveTriggerClasses()); | |
904 | ||
905 | // Get magnetic field info | |
906 | Bool_t ok = kTRUE; | |
907 | ||
908 | Float_t l3Current = grpData->GetL3Current((AliGRPObject::Stats)0); | |
909 | if (l3Current == AliGRPObject::GetInvalidFloat()) { | |
910 | AliError("GRP/GRP/Data entry: missing value for the L3 current !"); | |
911 | ok = kFALSE; | |
912 | } | |
913 | ||
914 | Char_t l3Polarity = grpData->GetL3Polarity(); | |
915 | if (l3Polarity == AliGRPObject::GetInvalidChar()) { | |
916 | AliError("GRP/GRP/Data entry: missing value for the L3 polarity !"); | |
917 | ok = kFALSE; | |
918 | } | |
919 | ||
920 | // Dipole | |
921 | Float_t diCurrent = grpData->GetDipoleCurrent((AliGRPObject::Stats)0); | |
922 | if (diCurrent == AliGRPObject::GetInvalidFloat()) { | |
923 | AliError("GRP/GRP/Data entry: missing value for the dipole current !"); | |
924 | ok = kFALSE; | |
925 | } | |
926 | ||
927 | Char_t diPolarity = grpData->GetDipolePolarity(); | |
928 | if (diPolarity == AliGRPObject::GetInvalidChar()) { | |
929 | AliError("GRP/GRP/Data entry: missing value for the dipole polarity !"); | |
930 | ok = kFALSE; | |
931 | } | |
932 | ||
933 | if (ok && grpData->IsPolarityConventionLHC()) { | |
934 | if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 1)) | |
935 | tag->SetMagneticField(-0.5); | |
936 | if ((TMath::Abs(l3Current) > 29000.0) && (l3Polarity == 0)) | |
937 | tag->SetMagneticField(0.5); | |
938 | if (TMath::Abs(l3Current) < 2000.0) | |
939 | tag->SetMagneticField(0.0); | |
940 | ||
941 | if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 1)) | |
942 | tag->SetDipoleField(-0.2); | |
943 | if ((TMath::Abs(diCurrent) > 5900.0) && (diPolarity == 0)) | |
944 | tag->SetDipoleField(0.2); | |
945 | if (TMath::Abs(diCurrent) < 500.0) | |
946 | tag->SetDipoleField(0.0); | |
947 | } | |
948 | ||
949 | tag->SetRunId(iInitRunNumber); | |
950 | tag->SetRunStartTime(t1.GetDate()); | |
951 | tag->SetRunStopTime(t2.GetDate()); | |
952 | tag->SetBeamEnergy(beamenergy); | |
953 | tag->SetBeamType(beamtype); | |
954 | ||
955 | //QA setting | |
956 | tag->SetQAArray(qa, qalength) ; | |
957 | tag->SetEventSpecies(es, eslength) ; | |
958 | ||
959 | ftag->cd(); | |
960 | ttag->Fill(); | |
961 | tag->Clear(); | |
962 | ttag->Write(); | |
963 | ftag->Close(); | |
964 | delete ftag; | |
965 | delete esd; | |
966 | delete tag; | |
967 | delete evTag; | |
968 | } | |
969 | ||
970 | //_____________________________________________________________________________ | |
971 | void AliESDTagCreator::SwitchOffBranches() const { | |
972 | // | |
973 | // Switch of branches on user request | |
974 | TObjArray * tokens = fBranches.Tokenize(" "); | |
975 | Int_t ntok = tokens->GetEntries(); | |
976 | for (Int_t i = 0; i < ntok; i++) { | |
977 | TString str = ((TObjString*) tokens->At(i))->GetString(); | |
978 | fChain->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0); | |
979 | AliInfo(Form("Branch %s switched off \n", str.Data())); | |
980 | } | |
981 | delete tokens; | |
982 | } | |
983 | ||
984 | //_____________________________________________________________________________ | |
985 | void AliESDTagCreator::FillEventTag(TTree *chain, AliEventTag *evTag, Int_t iEventNumber, AliESDEvent *esd) | |
986 | { | |
987 | // Fill the event specific information in the EventTag | |
988 | AliESD *esdold = 0x0; | |
989 | ||
990 | TString fTempGuid; | |
991 | ||
992 | ///////////// | |
993 | //muon code// | |
994 | //////////// | |
995 | Double_t fMUONMASS = 0.105658369; | |
996 | //Variables | |
997 | Double_t fX,fY,fZ ; | |
998 | Double_t fThetaX, fThetaY, fPyz, fChisquare; | |
999 | Double_t fPxRec, fPyRec, fPzRec, fEnergy; | |
1000 | Int_t fCharge; | |
1001 | TLorentzVector fEPvector; | |
1002 | ||
1003 | Float_t fLowPtCut = 1.0; | |
1004 | Float_t fHighPtCut = 3.0; | |
1005 | Float_t fVeryHighPtCut = 10.0; | |
1006 | //////////// | |
1007 | ||
1008 | Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05}; | |
1009 | ||
1010 | // Creates the tags for all the events in a given ESD file | |
1011 | Bool_t fIsSim = kTRUE; | |
1012 | Int_t ntrack; | |
1013 | Int_t nProtons, nKaons, nPions, nMuons, nElectrons, nFWMuons, nFWMatchedMuons; | |
1014 | Int_t nPos, nNeg, nNeutr; | |
1015 | Int_t nK0s, nLambdas, nNeutrons, nPi0s, nGamas; | |
1016 | Int_t nCh1GeV, nCh3GeV, nCh10GeV; | |
1017 | Int_t nMu1GeV, nMu3GeV, nMu10GeV; | |
1018 | Int_t nEl1GeV, nEl3GeV, nEl10GeV; | |
1019 | Float_t maxPt = .0, etamaxPt = -999., phimaxPt = -999., meanPt = .0, totalP = .0; | |
1020 | Int_t fVertexflag; | |
1021 | TString fVertexName; | |
1022 | ||
1023 | TRefArray tmp; | |
1024 | ||
1025 | ntrack = 0; nPos = 0; nNeg = 0; nNeutr =0; | |
1026 | nK0s = 0; nLambdas = 0; nNeutrons = 0; nPi0s = 0; | |
1027 | nGamas = 0; nProtons = 0; nKaons = 0; | |
1028 | nPions = 0; nMuons = 0; nElectrons = 0; nFWMuons = 0; nFWMatchedMuons = 0; | |
1029 | nCh1GeV = 0; nCh3GeV = 0; nCh10GeV = 0; | |
1030 | nMu1GeV = 0; nMu3GeV = 0; nMu10GeV = 0; | |
1031 | nEl1GeV = 0; nEl3GeV = 0; nEl10GeV = 0; | |
1032 | maxPt = .0; etamaxPt = -999.; phimaxPt = -999.; meanPt = .0; totalP = .0; | |
1033 | fVertexflag = 1; | |
1034 | ||
1035 | chain->GetEntry(iEventNumber); | |
1036 | esdold = esd->GetAliESDOld(); | |
1037 | if(esdold) esd->CopyFromOldESD(); | |
1038 | ||
1039 | // TFile *file = chain->GetFile(); | |
1040 | // const TUrl *url = file->GetEndpointUrl(); | |
1041 | // fguid = file->GetUUID().AsString(); | |
1042 | // if(fSession == "grid") { | |
1043 | // TString fturltemp = "alien://"; fturltemp += url->GetFile(); | |
1044 | // fturl = fturltemp(0,fturltemp.Index(".root",5,0,TString::kExact)+5); | |
1045 | // } | |
1046 | // else fturl = url->GetFile(); | |
1047 | ||
1048 | const AliESDVertex * vertexIn = esd->GetVertex(); | |
1049 | fVertexName = vertexIn->GetName(); | |
1050 | if(fVertexName == "default") fVertexflag = 0; | |
1051 | ||
1052 | for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) { | |
1053 | AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber); | |
1054 | if(esdTrack->GetLabel() != 0) fIsSim = kTRUE; | |
1055 | else if(esdTrack->GetLabel() == 0) fIsSim = kFALSE; | |
1056 | UInt_t status = esdTrack->GetStatus(); | |
1057 | ||
1058 | //select only tracks with ITS refit | |
1059 | if ((status&AliESDtrack::kITSrefit)==0) continue; | |
1060 | //select only tracks with TPC refit | |
1061 | if ((status&AliESDtrack::kTPCrefit)==0) continue; | |
1062 | ||
1063 | //select only tracks with the "combined PID" | |
1064 | if ((status&AliESDtrack::kESDpid)==0) continue; | |
1065 | Double_t p[3]; | |
1066 | esdTrack->GetPxPyPz(p); | |
1067 | Double_t pt2 = p[0]*p[0]+p[1]*p[1]; | |
1068 | Double_t momentum = TMath::Sqrt(pt2+p[2]*p[2]); | |
1069 | Double_t fPt = TMath::Sqrt(pt2); | |
1070 | totalP += momentum; | |
1071 | meanPt += fPt; | |
1072 | if(fPt > maxPt) { | |
1073 | maxPt = fPt; | |
1074 | phimaxPt = esdTrack->Phi(); | |
1075 | etamaxPt = esdTrack->Eta(); | |
1076 | } | |
1077 | ||
1078 | if(esdTrack->GetSign() > 0) { | |
1079 | nPos++; | |
1080 | if(fPt > fLowPtCut) nCh1GeV++; | |
1081 | if(fPt > fHighPtCut) nCh3GeV++; | |
1082 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
1083 | } | |
1084 | if(esdTrack->GetSign() < 0) { | |
1085 | nNeg++; | |
1086 | if(fPt > fLowPtCut) nCh1GeV++; | |
1087 | if(fPt > fHighPtCut) nCh3GeV++; | |
1088 | if(fPt > fVeryHighPtCut) nCh10GeV++; | |
1089 | } | |
1090 | if(esdTrack->GetSign() == 0) nNeutr++; | |
1091 | ||
1092 | //PID | |
1093 | Double_t prob[5]; | |
1094 | esdTrack->GetESDpid(prob); | |
1095 | ||
1096 | Double_t rcc = 0.0; | |
1097 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i]; | |
1098 | if(rcc == 0.0) continue; | |
1099 | //Bayes' formula | |
1100 | Double_t w[5]; | |
1101 | for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc; | |
1102 | ||
1103 | //protons | |
1104 | if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++; | |
1105 | //kaons | |
1106 | if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++; | |
1107 | //pions | |
1108 | if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++; | |
1109 | //electrons | |
1110 | if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) { | |
1111 | nElectrons++; | |
1112 | if(fPt > fLowPtCut) nEl1GeV++; | |
1113 | if(fPt > fHighPtCut) nEl3GeV++; | |
1114 | if(fPt > fVeryHighPtCut) nEl10GeV++; | |
1115 | } | |
1116 | ntrack++; | |
1117 | } | |
1118 | //esd track loop | |
1119 | ||
1120 | /* muon code */ | |
1121 | Int_t nMuonTracks = esd->GetNumberOfMuonTracks(); | |
1122 | // loop over all reconstructed tracks (also first track of combination) | |
1123 | for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) { | |
1124 | AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack); | |
1125 | if (muonTrack == 0x0) continue; | |
1126 | ||
1127 | // Coordinates at vertex | |
1128 | fZ = muonTrack->GetZ(); | |
1129 | fY = muonTrack->GetBendingCoor(); | |
1130 | fX = muonTrack->GetNonBendingCoor(); | |
1131 | ||
1132 | fThetaX = muonTrack->GetThetaX(); | |
1133 | fThetaY = muonTrack->GetThetaY(); | |
1134 | ||
1135 | fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum()); | |
1136 | fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY)); | |
1137 | fPxRec = fPzRec * TMath::Tan(fThetaX); | |
1138 | fPyRec = fPzRec * TMath::Tan(fThetaY); | |
1139 | fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum())); | |
1140 | ||
1141 | //ChiSquare of the track if needed | |
1142 | fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5); | |
1143 | fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec); | |
1144 | fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy); | |
1145 | ||
1146 | if (muonTrack->GetMatchTrigger()>0) nFWMatchedMuons++; | |
1147 | ||
1148 | nMuons++; | |
1149 | nFWMuons++; | |
1150 | if(fEPvector.Pt() > fLowPtCut) { | |
1151 | nMu1GeV++; | |
1152 | if(fEPvector.Pt() > fHighPtCut) { | |
1153 | nMu3GeV++; | |
1154 | if (fEPvector.Pt() > fVeryHighPtCut) { | |
1155 | nMu10GeV++; | |
1156 | } | |
1157 | } | |
1158 | } | |
1159 | }//muon track loop | |
1160 | ||
1161 | // Fill the event tags | |
1162 | if(ntrack != 0) meanPt = meanPt/ntrack; | |
1163 | ||
1164 | //AliInfo(Form("=====================================")); | |
1165 | //AliInfo(Form("URL: %s - GUID: %s",fturl.Data(),fguid.Data())); | |
1166 | //AliInfo(Form("=====================================")); | |
1167 | ||
1168 | //First physics data | |
1169 | const AliMultiplicity *spdMult = esd->GetMultiplicity(); | |
1170 | evTag->SetNumberOfFiredChipsLayer1(spdMult->GetNumberOfFiredChips(0)); | |
1171 | evTag->SetNumberOfFiredChipsLayer2(spdMult->GetNumberOfFiredChips(1)); | |
1172 | evTag->SetNumberOfSPDTracklets(spdMult->GetNumberOfTracklets()); | |
1173 | ||
1174 | AliESDVZERO *vzeroData = esd->GetVZEROData(); | |
1175 | evTag->SetMTotV0A(vzeroData->GetMTotV0A()); | |
1176 | evTag->SetMTotV0C(vzeroData->GetMTotV0C()); | |
1177 | evTag->SetNbPMV0A(vzeroData->GetNbPMV0A()); | |
1178 | evTag->SetNbPMV0C(vzeroData->GetNbPMV0C()); | |
1179 | ||
1180 | //evTag->SetEventId(iEventNumber+1); | |
1181 | evTag->SetPeriodNumber(esd->GetPeriodNumber()); | |
1182 | evTag->SetOrbitNumber(esd->GetOrbitNumber()); | |
1183 | evTag->SetBunchCrossNumber(esd->GetBunchCrossNumber()); | |
1184 | // evTag->SetGUID(fguid); | |
1185 | // if(fSession == "grid") { | |
1186 | // evTag->SetMD5(""); | |
1187 | // evTag->SetTURL(fturl); | |
1188 | // evTag->SetSize(0); | |
1189 | // } | |
1190 | // else evTag->SetPath(fturl); | |
1191 | ||
1192 | evTag->SetVertexX(vertexIn->GetXv()); | |
1193 | evTag->SetVertexY(vertexIn->GetYv()); | |
1194 | evTag->SetVertexZ(vertexIn->GetZv()); | |
1195 | evTag->SetVertexZError(vertexIn->GetZRes()); | |
1196 | evTag->SetVertexFlag(fVertexflag); | |
1197 | ||
1198 | evTag->SetT0VertexZ(esd->GetT0zVertex()); | |
1199 | ||
1200 | evTag->SetTriggerMask(esd->GetTriggerMask()); | |
1201 | evTag->SetTriggerCluster(esd->GetTriggerCluster()); | |
1202 | ||
1203 | evTag->SetEventType(esd->GetEventType()); | |
1204 | //*T* evTag->SetFiredTriggerClasses(esd->GetFiredTriggerClasses()); | |
1205 | ||
1206 | evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy()); | |
1207 | evTag->SetZDCProton1Energy(esd->GetZDCP1Energy()); | |
1208 | evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1)); | |
1209 | evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy()); | |
1210 | evTag->SetZDCProton2Energy(esd->GetZDCP2Energy()); | |
1211 | evTag->SetNumOfParticipants(esd->GetZDCParticipants()); | |
1212 | ||
1213 | evTag->SetNumOfTracks(esd->GetNumberOfTracks()); | |
1214 | evTag->SetNumOfPosTracks(nPos); | |
1215 | evTag->SetNumOfNegTracks(nNeg); | |
1216 | evTag->SetNumOfNeutrTracks(nNeutr); | |
1217 | ||
1218 | evTag->SetNumOfV0s(esd->GetNumberOfV0s()); | |
1219 | evTag->SetNumOfCascades(esd->GetNumberOfCascades()); | |
1220 | evTag->SetNumOfKinks(esd->GetNumberOfKinks()); | |
1221 | evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks()); | |
1222 | ||
1223 | evTag->SetNumOfProtons(nProtons); | |
1224 | evTag->SetNumOfKaons(nKaons); | |
1225 | evTag->SetNumOfPions(nPions); | |
1226 | evTag->SetNumOfMuons(nMuons); | |
1227 | evTag->SetNumOfFWMuons(nFWMuons); | |
1228 | evTag->SetNumOfFWMatchedMuons(nFWMatchedMuons); | |
1229 | evTag->SetNumOfElectrons(nElectrons); | |
1230 | evTag->SetNumOfPhotons(nGamas); | |
1231 | evTag->SetNumOfPi0s(nPi0s); | |
1232 | evTag->SetNumOfNeutrons(nNeutrons); | |
1233 | evTag->SetNumOfKaon0s(nK0s); | |
1234 | evTag->SetNumOfLambdas(nLambdas); | |
1235 | ||
1236 | evTag->SetNumOfChargedAbove1GeV(nCh1GeV); | |
1237 | evTag->SetNumOfChargedAbove3GeV(nCh3GeV); | |
1238 | evTag->SetNumOfChargedAbove10GeV(nCh10GeV); | |
1239 | evTag->SetNumOfMuonsAbove1GeV(nMu1GeV); | |
1240 | evTag->SetNumOfMuonsAbove3GeV(nMu3GeV); | |
1241 | evTag->SetNumOfMuonsAbove10GeV(nMu10GeV); | |
1242 | evTag->SetNumOfElectronsAbove1GeV(nEl1GeV); | |
1243 | evTag->SetNumOfElectronsAbove3GeV(nEl3GeV); | |
1244 | evTag->SetNumOfElectronsAbove10GeV(nEl10GeV); | |
1245 | ||
1246 | tmp.Clear(); | |
1247 | evTag->SetNumOfPHOSClusters(esd->GetPHOSClusters(&tmp)); | |
1248 | tmp.Clear(); | |
1249 | evTag->SetNumOfEMCALClusters(esd->GetEMCALClusters(&tmp)); | |
1250 | ||
1251 | evTag->SetTotalMomentum(totalP); | |
1252 | evTag->SetMeanPt(meanPt); | |
1253 | evTag->SetMaxPt(maxPt); | |
1254 | evTag->SetEtaMaxPt(etamaxPt); | |
1255 | evTag->SetPhiMaxPt(phimaxPt); | |
1256 | ||
1257 | evTag->SetPhysicsFlag(kTRUE); | |
1258 | evTag->SetBackgroungFlag(kFALSE); | |
1259 | } | |
1260 | ||
1261 | void AliESDTagCreator::CreateESDRunTagSummary(TTree *chain) | |
1262 | { | |
1263 | // Merge all tags from a run into a single RunTag | |
1264 | // with only the File tags | |
1265 | AliRunTag *rtag; | |
1266 | chain->SetBranchAddress("AliTAG", &rtag); | |
1267 | ||
1268 | TFile* ftag = TFile::Open("RunTagSummary.tag.root", "recreate"); | |
1269 | ||
1270 | AliRunTag *tag = new AliRunTag(); | |
1271 | TTree * ttag = new TTree("T","A Tree with event tags"); | |
1272 | TBranch * btag = ttag->Branch("AliTAG", &tag); | |
1273 | btag->SetCompressionLevel(9); | |
1274 | ||
1275 | for (int itag=0; itag<chain->GetEntries(); itag++) { | |
1276 | chain->GetEntry(itag); | |
1277 | tag->CopyStandardContent(rtag); | |
1278 | ||
1279 | ttag->Fill(); | |
1280 | tag->Clear(); | |
1281 | } | |
1282 | ||
1283 | ftag->cd(); | |
1284 | ttag->Write(); | |
1285 | ftag->Close(); | |
1286 | ||
1287 | } |