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