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