]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Author: Panos Christakoglou. * | |
3 | * Contributors are mentioned in the code where appropriate. * | |
4 | * * | |
5 | * Permission to use, copy, modify and distribute this software and its * | |
6 | * documentation strictly for non-commercial purposes is hereby granted * | |
7 | * without fee, provided that the above copyright notice appears in all * | |
8 | * copies and that both the copyright notice and this permission notice * | |
9 | * appear in the supporting documentation. The authors make no claims * | |
10 | * about the suitability of this software for any purpose. It is * | |
11 | * provided "as is" without express or implied warranty. * | |
12 | **************************************************************************/ | |
13 | ||
14 | /* $Id$ */ | |
15 | ||
16 | //----------------------------------------------------------------- | |
17 | // AliTagAnalysis class | |
18 | // This is the class to deal with the tag analysis | |
19 | // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch | |
20 | //----------------------------------------------------------------- | |
21 | ||
22 | //ROOT | |
23 | #include <Riostream.h> | |
24 | #include <TSystem.h> | |
25 | #include <TChain.h> | |
26 | #include <TFile.h> | |
27 | #include <TEventList.h> | |
28 | #include <TEntryList.h> | |
29 | #include <TTreeFormula.h> | |
30 | #include <TMap.h> | |
31 | ||
32 | //ROOT-AliEn | |
33 | #include <TGridResult.h> | |
34 | ||
35 | #include "AliLog.h" | |
36 | ||
37 | #include "AliRunTag.h" | |
38 | #include "AliEventTag.h" | |
39 | #include "AliTagAnalysis.h" | |
40 | #include "AliEventTagCuts.h" | |
41 | #include "AliDetectorTagCuts.h" | |
42 | #include "AliLHCTagCuts.h" | |
43 | #include "AliRunTagCuts.h" | |
44 | #include "AliXMLCollection.h" | |
45 | ||
46 | class TTree; | |
47 | ||
48 | ClassImp(AliTagAnalysis) | |
49 | ||
50 | //___________________________________________________________________________ | |
51 | AliTagAnalysis::AliTagAnalysis(): | |
52 | TObject(), | |
53 | ftagresult(0x0), | |
54 | fTagDirName(), | |
55 | fChain(0x0), | |
56 | fAnalysisType(), | |
57 | fGlobalList(0) { | |
58 | //Default constructor for a AliTagAnalysis | |
59 | } | |
60 | ||
61 | //___________________________________________________________________________ | |
62 | AliTagAnalysis::AliTagAnalysis(const char* type): | |
63 | TObject(), | |
64 | ftagresult(0x0), | |
65 | fTagDirName(), | |
66 | fChain(0x0), | |
67 | fAnalysisType(type), | |
68 | fGlobalList(0) { | |
69 | //constructor for a AliTagAnalysis | |
70 | } | |
71 | ||
72 | //___________________________________________________________________________ | |
73 | AliTagAnalysis::~AliTagAnalysis() { | |
74 | //Default destructor for a AliTagAnalysis | |
75 | if(ftagresult) delete ftagresult; | |
76 | if(fChain) delete fChain; | |
77 | if(fGlobalList) delete fGlobalList; | |
78 | } | |
79 | ||
80 | //___________________________________________________________________________ | |
81 | Bool_t | |
82 | AliTagAnalysis::AddTagsFile(const char* alienUrl, Bool_t checkFile) | |
83 | { | |
84 | /// Add a single tags file to the chain | |
85 | /// | |
86 | /// If checkFile=kTRUE (default) the file is opened to check | |
87 | /// it can be and that it contains data. | |
88 | /// It's safer but a lot longer... | |
89 | ||
90 | if (!fChain) fChain = new TChain("T"); | |
91 | ||
92 | if ( checkFile ) | |
93 | { | |
94 | return ( fChain->AddFile(alienUrl,-1) > 0 ); | |
95 | } | |
96 | else | |
97 | { | |
98 | return ( fChain->AddFile(alienUrl) > 0 ); | |
99 | } | |
100 | ||
101 | } | |
102 | ||
103 | //___________________________________________________________________________ | |
104 | void AliTagAnalysis::ChainLocalTags(const char *dirname) { | |
105 | //Searches the entries of the provided direcory | |
106 | //Chains the tags that are stored locally | |
107 | fTagDirName = dirname; | |
108 | TString fTagFilename; | |
109 | ||
110 | if (! fChain) fChain = new TChain("T"); | |
111 | const char * tagPattern = 0x0; | |
112 | if(fAnalysisType == "ESD") tagPattern = "ESD.tag.root"; | |
113 | else if(fAnalysisType == "AOD") tagPattern = "AOD.tag.root"; | |
114 | else AliFatal("Only ESD and AOD type is implemented!!!"); | |
115 | ||
116 | // Open the working directory | |
117 | void * dirp = gSystem->OpenDirectory(fTagDirName); | |
118 | const char * name = 0x0; | |
119 | // Add all files matching *pattern* to the chain | |
120 | while((name = gSystem->GetDirEntry(dirp))) { | |
121 | if (strstr(name,tagPattern)) { | |
122 | fTagFilename = fTagDirName; | |
123 | fTagFilename += "/"; | |
124 | fTagFilename += name; | |
125 | ||
126 | fChain->Add(fTagFilename); | |
127 | printf("Tag file %s\n", fTagFilename.Data()); | |
128 | ||
129 | }//pattern check | |
130 | }//directory loop | |
131 | //AliInfo(Form("Chained tag files: %d ",fChain->GetEntries())); | |
132 | // AliDebug(Form("Chained tag files: %d ",fChain->GetEntries())); | |
133 | fChain->ls(); | |
134 | ||
135 | } | |
136 | ||
137 | ||
138 | //___________________________________________________________________________ | |
139 | TChain * AliTagAnalysis::ChainGridTags(TGridResult *res) { | |
140 | //Loops overs the entries of the TGridResult | |
141 | //Chains the tags that are stored in the GRID | |
142 | ftagresult = res; | |
143 | Int_t nEntries = ftagresult->GetEntries(); | |
144 | ||
145 | if (! fChain) fChain = new TChain("T"); | |
146 | ||
147 | TString gridname = "alien://"; | |
148 | TString alienUrl; | |
149 | ||
150 | for(Int_t i = 0; i < nEntries; i++) { | |
151 | alienUrl = ftagresult->GetKey(i,"turl"); | |
152 | fChain->Add(alienUrl); | |
153 | }//grid result loop | |
154 | return fChain; | |
155 | } | |
156 | ||
157 | ||
158 | //___________________________________________________________________________ | |
159 | TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts, | |
160 | AliLHCTagCuts *lhcTagCuts, | |
161 | AliDetectorTagCuts *detTagCuts, | |
162 | AliEventTagCuts *evTagCuts) { | |
163 | //Queries the tag chain using the defined | |
164 | //event tag cuts from the AliEventTagCuts object | |
165 | //and returns a TChain along with the associated TEventList | |
166 | AliInfo(Form("Querying the tags........")); | |
167 | ||
168 | Bool_t aod = kFALSE; | |
169 | TString aliceFile; | |
170 | if(fAnalysisType == "ESD") aliceFile = "esdTree"; | |
171 | else if(fAnalysisType == "AOD") { | |
172 | aliceFile = "aodTree"; | |
173 | aod = kTRUE; | |
174 | } | |
175 | else AliFatal("Only ESD and AOD type is implemented!!!"); | |
176 | ||
177 | //ESD file chain | |
178 | TChain *esdChain = new TChain(aliceFile.Data()); | |
179 | //global entry list | |
180 | fGlobalList = new TEntryList(); | |
181 | ||
182 | //Defining tag objects | |
183 | AliRunTag *tag = new AliRunTag; | |
184 | AliEventTag *evTag = new AliEventTag; | |
185 | fChain->SetBranchAddress("AliTAG",&tag); | |
186 | ||
187 | TString guid; | |
188 | TString turl; | |
189 | TString path; | |
190 | ||
191 | TTree* cTree = 0; | |
192 | TEntryList* localList = new TEntryList(); | |
193 | ||
194 | Int_t iAccepted = 0; | |
195 | Int_t iev = 0; | |
196 | Int_t ientry = 0; | |
197 | Int_t cEntries = 0; | |
198 | ||
199 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
200 | fChain->GetEntry(iTagFiles); | |
201 | TTree* tree = fChain->GetTree(); | |
202 | if (cTree != tree) { | |
203 | // Fix for aod tags: for each tree in the chain, merge the entries | |
204 | cTree = tree; | |
205 | cEntries = tree->GetEntries(); | |
206 | iev = 0; | |
207 | ientry = 0; | |
208 | } | |
209 | ||
210 | if(runTagCuts->IsAccepted(tag)) { | |
211 | if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) { | |
212 | if(detTagCuts->IsAccepted(tag->GetDetectorTags())) { | |
213 | if ((iev == 0) || !aod) localList->Reset(); | |
214 | Int_t iEvents = tag->GetNEvents(); | |
215 | const TClonesArray *tagList = tag->GetEventTags(); | |
216 | for(Int_t i = 0; i < iEvents; i++) { | |
217 | evTag = (AliEventTag *) tagList->At(i); | |
218 | guid = evTag->GetGUID(); | |
219 | turl = evTag->GetTURL(); | |
220 | path = evTag->GetPath(); | |
221 | localList->SetTreeName(aliceFile.Data()); | |
222 | if(turl!="") localList->SetFileName(turl.Data()); | |
223 | else localList->SetFileName(path.Data()); | |
224 | ||
225 | if(evTagCuts->IsAccepted(evTag)) { | |
226 | if(aod) localList->Enter(iev); | |
227 | else localList->Enter(i); | |
228 | } | |
229 | iev++; | |
230 | }//event loop | |
231 | if ((ientry == cEntries-1) || !aod) { | |
232 | iAccepted += localList->GetN(); | |
233 | if(path != "") esdChain->AddFile(path); | |
234 | else if(turl != "") esdChain->AddFile(turl); | |
235 | fGlobalList->Add(localList); | |
236 | } | |
237 | }//detector tag cuts | |
238 | }//lhc tag cuts | |
239 | }//run tags cut | |
240 | tag->Clear(); | |
241 | ientry++; | |
242 | }//tag file loop | |
243 | AliInfo(Form("Accepted events: %d",iAccepted)); | |
244 | esdChain->ls(); | |
245 | esdChain->SetEntryList(fGlobalList,"ne"); | |
246 | delete tag; | |
247 | delete localList; | |
248 | ||
249 | return esdChain; | |
250 | } | |
251 | ||
252 | //___________________________________________________________________________ | |
253 | TChain *AliTagAnalysis::QueryTags(const char *fRunCut, | |
254 | const char *fLHCCut, | |
255 | const char *fDetectorCut, | |
256 | const char *fEventCut) { | |
257 | //Queries the tag chain using the defined | |
258 | //event tag cuts from the AliEventTagCuts object | |
259 | //and returns a TChain along with the associated TEventList | |
260 | AliInfo(Form("Querying the tags........")); | |
261 | ||
262 | Bool_t aod = kFALSE; | |
263 | TString aliceFile; | |
264 | if(fAnalysisType == "ESD") aliceFile = "esdTree"; | |
265 | else if(fAnalysisType == "AOD") { | |
266 | aliceFile = "aodTree"; | |
267 | aod = kTRUE; | |
268 | } | |
269 | else AliFatal("Only ESD and AOD type is implemented!!!"); | |
270 | ||
271 | //ESD file chain | |
272 | TChain *esdChain = new TChain(aliceFile.Data()); | |
273 | //global entry list | |
274 | fGlobalList = new TEntryList(); | |
275 | ||
276 | //Defining tag objects | |
277 | AliRunTag *tag = new AliRunTag; | |
278 | AliEventTag *evTag = new AliEventTag; | |
279 | fChain->SetBranchAddress("AliTAG",&tag); | |
280 | ||
281 | TString guid; | |
282 | TString turl; | |
283 | TString path; | |
284 | ||
285 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
286 | TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain); | |
287 | TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain); | |
288 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
289 | ||
290 | TEntryList* localList = new TEntryList(); | |
291 | ||
292 | Int_t iev = 0; | |
293 | Int_t ientry = 0; | |
294 | Int_t cEntries = 0; | |
295 | Int_t current = -1; | |
296 | Int_t iAccepted = 0; | |
297 | ||
298 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
299 | fChain->GetEntry(iTagFiles); | |
300 | if (current != fChain->GetTreeNumber()) { | |
301 | fRunFormula->UpdateFormulaLeaves(); | |
302 | fLHCFormula->UpdateFormulaLeaves(); | |
303 | fDetectorFormula->UpdateFormulaLeaves(); | |
304 | fEventFormula->UpdateFormulaLeaves(); | |
305 | // Fix for aod tags: for each tree in the chain, merge the entries | |
306 | cEntries = (fChain->GetTree())->GetEntries(); | |
307 | iev = 0; | |
308 | ientry = 0; | |
309 | // | |
310 | current = fChain->GetTreeNumber(); | |
311 | } | |
312 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
313 | if(fLHCFormula->EvalInstance(iTagFiles) == 1) { | |
314 | if(fDetectorFormula->EvalInstance(iTagFiles) == 1) { | |
315 | if ((iev == 0) || !aod) localList->Reset(); | |
316 | Int_t iEvents = fEventFormula->GetNdata(); | |
317 | const TClonesArray *tagList = tag->GetEventTags(); | |
318 | for(Int_t i = 0; i < iEvents; i++) { | |
319 | evTag = (AliEventTag *) tagList->At(i); | |
320 | guid = evTag->GetGUID(); | |
321 | turl = evTag->GetTURL(); | |
322 | path = evTag->GetPath(); | |
323 | localList->SetTreeName(aliceFile.Data()); | |
324 | localList->SetFileName(turl.Data()); | |
325 | if(fEventFormula->EvalInstance(i) == 1) { | |
326 | if(aod) localList->Enter(iev); | |
327 | else localList->Enter(i); | |
328 | } | |
329 | iev++; | |
330 | }//event loop | |
331 | ||
332 | if ((ientry == cEntries-1) || !aod) { | |
333 | if(path != "") esdChain->AddFile(path); | |
334 | else if(turl != "") esdChain->AddFile(turl); | |
335 | fGlobalList->Add(localList); | |
336 | iAccepted += localList->GetN(); | |
337 | } | |
338 | }//detector tag cuts | |
339 | }//lhc tag cuts | |
340 | }//run tag cut | |
341 | tag->Clear(); | |
342 | ientry++; | |
343 | }//tag file loop | |
344 | AliInfo(Form("Accepted events: %d",iAccepted)); | |
345 | esdChain->SetEntryList(fGlobalList,"ne"); | |
346 | ||
347 | delete tag; | |
348 | delete localList; | |
349 | return esdChain; | |
350 | } | |
351 | ||
352 | //___________________________________________________________________________ | |
353 | Bool_t | |
354 | AliTagAnalysis::CreateXMLCollection(const char* name, | |
355 | AliRunTagCuts *runTagCuts, | |
356 | AliLHCTagCuts *lhcTagCuts, | |
357 | AliDetectorTagCuts *detTagCuts, | |
358 | AliEventTagCuts *evTagCuts) | |
359 | { | |
360 | /// Queries the tag chain using the defined run, lhc, detector and event tag objects | |
361 | /// and create a XML collection named "name.xml" | |
362 | /// if any of the runTagCuts, lhcTagCuts, detTagCuts or evTagCuts is NULL | |
363 | /// check on that object will be skipped. | |
364 | ||
365 | AliInfo(Form("Creating the collection........")); | |
366 | ||
367 | if (!fChain) | |
368 | { | |
369 | AliError("fChain is NULL. Cannot make a collection from that !"); | |
370 | return kFALSE; | |
371 | } | |
372 | ||
373 | Bool_t aod = kFALSE; | |
374 | if(fAnalysisType == "AOD") aod = kTRUE; | |
375 | ||
376 | ||
377 | AliXMLCollection collection; | |
378 | collection.SetCollectionName(name); | |
379 | collection.WriteHeader(); | |
380 | ||
381 | TString guid; | |
382 | TString turl; | |
383 | TString lfn; | |
384 | ||
385 | TTree* cTree = 0; | |
386 | TEntryList localList; | |
387 | Int_t iAccepted = 0; | |
388 | Int_t iev = 0; | |
389 | Int_t ientry = 0; | |
390 | Int_t cEntries = 0; | |
391 | ||
392 | Int_t iRejectedRun = 0; | |
393 | Int_t iRejectedLHC = 0; | |
394 | Int_t iRejectedDet = 0; | |
395 | Int_t iRejectedEvt = 0; | |
396 | ||
397 | Int_t iTotalEvents = 0; | |
398 | ||
399 | Int_t iAcceptedEvtInFile = 0; | |
400 | Int_t iRejectedEvtInFile = 0; | |
401 | ||
402 | //Defining tag objects | |
403 | AliRunTag* tag = new AliRunTag; | |
404 | fChain->SetBranchAddress("AliTAG",&tag); | |
405 | ||
406 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetListOfFiles()->GetEntries(); ++iTagFiles) | |
407 | { | |
408 | fChain->GetEntry(iTagFiles); | |
409 | TTree* tree = fChain->GetTree(); | |
410 | if (cTree != tree) { | |
411 | // Fix for aod tags: for each tree in the chain, merge the entries | |
412 | cTree = tree; | |
413 | cEntries = tree->GetEntries(); | |
414 | iev = 0; | |
415 | ientry = 0; | |
416 | } | |
417 | //Event list | |
418 | iTotalEvents += tag->GetNEvents(); | |
419 | if ((iev == 0) || !aod) localList.Reset(); | |
420 | ||
421 | if ( !runTagCuts || ( runTagCuts && runTagCuts->IsAccepted(tag) ) ) | |
422 | { | |
423 | if ( !lhcTagCuts || ( lhcTagCuts && lhcTagCuts->IsAccepted(tag->GetLHCTag())) ) | |
424 | { | |
425 | if ( !detTagCuts || ( detTagCuts && detTagCuts->IsAccepted(tag->GetDetectorTags())) ) | |
426 | { | |
427 | Int_t i(0); | |
428 | TIter next(tag->GetEventTags()); | |
429 | AliEventTag* evTag(0x0); | |
430 | iRejectedEvtInFile = 0; | |
431 | iAcceptedEvtInFile = 0; | |
432 | while ( ( evTag = static_cast<AliEventTag*>(next()) ) ) | |
433 | { | |
434 | guid = evTag->GetGUID(); | |
435 | turl = evTag->GetTURL(); | |
436 | lfn = turl(8,turl.Length()); | |
437 | if( !evTagCuts || ( evTagCuts && evTagCuts->IsAccepted(evTag)) ) | |
438 | { | |
439 | if (aod) localList.Enter(iev); | |
440 | else localList.Enter(i); | |
441 | iAcceptedEvtInFile++; | |
442 | ||
443 | // AliInfo(Form("Period %5d Orbit# %12d BC %10d (%5d ? in TURL %s) Trigger %s nmus %d", | |
444 | // evTag->GetPeriodNumber(), | |
445 | // evTag->GetOrbitNumber(), | |
446 | // evTag->GetBunchCrossNumber(), | |
447 | // i, | |
448 | // evTag->GetTURL(), | |
449 | // evTag->GetFiredTriggerClasses().Data(), | |
450 | // evTag->GetNumOfMuons())); | |
451 | } | |
452 | else | |
453 | { | |
454 | ++iRejectedEvt; | |
455 | ++iRejectedEvtInFile; | |
456 | } | |
457 | ++i; | |
458 | ++iev; | |
459 | }//event loop | |
460 | if ((ientry == cEntries-1) || !aod) | |
461 | { | |
462 | iAccepted += localList.GetN(); | |
463 | collection.WriteBody(iTagFiles+1,guid,lfn,turl,&localList,iAcceptedEvtInFile,iRejectedEvtInFile); | |
464 | } | |
465 | }//detector tag cuts | |
466 | else { | |
467 | iRejectedDet += tag->GetNEvents(); | |
468 | } | |
469 | }//lhc tag cuts | |
470 | else { | |
471 | iRejectedLHC += tag->GetNEvents(); | |
472 | } | |
473 | }//run tag cuts | |
474 | else { | |
475 | iRejectedRun += tag->GetNEvents(); | |
476 | } | |
477 | tag->Clear(); | |
478 | ++ientry; | |
479 | } //tag file loop | |
480 | ||
481 | collection.WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt); | |
482 | collection.Export(); | |
483 | ||
484 | return kTRUE; | |
485 | } | |
486 | ||
487 | //___________________________________________________________________________ | |
488 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, | |
489 | const char *fRunCut, | |
490 | const char *fLHCCut, | |
491 | const char *fDetectorCut, | |
492 | const char *fEventCut) { | |
493 | //Queries the tag chain using the defined | |
494 | //event tag cuts from the AliEventTagCuts object | |
495 | //and returns a XML collection | |
496 | AliInfo(Form("Creating the collection........")); | |
497 | ||
498 | Bool_t aod = kFALSE; | |
499 | if(fAnalysisType == "AOD") aod = kTRUE; | |
500 | ||
501 | AliXMLCollection *collection = new AliXMLCollection(); | |
502 | collection->SetCollectionName(name); | |
503 | collection->WriteHeader(); | |
504 | ||
505 | TString guid; | |
506 | TString turl; | |
507 | TString lfn; | |
508 | TEntryList* localList = new TEntryList(); | |
509 | ||
510 | Int_t iAccepted = 0; | |
511 | Int_t iev = 0; | |
512 | Int_t ientry = 0; | |
513 | Int_t cEntries = 0; | |
514 | ||
515 | Int_t iRejectedRun = 0; | |
516 | Int_t iRejectedLHC = 0; | |
517 | Int_t iRejectedDet = 0; | |
518 | Int_t iRejectedEvt = 0; | |
519 | ||
520 | Int_t iTotalEvents = 0; | |
521 | ||
522 | Int_t iAcceptedEvtInFile = 0; | |
523 | Int_t iRejectedEvtInFile = 0; | |
524 | ||
525 | //Defining tag objects | |
526 | AliRunTag *tag = new AliRunTag; | |
527 | AliEventTag *evTag = new AliEventTag; | |
528 | fChain->SetBranchAddress("AliTAG",&tag); | |
529 | ||
530 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
531 | TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain); | |
532 | TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain); | |
533 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
534 | ||
535 | Int_t current = -1; | |
536 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
537 | ||
538 | fChain->GetEntry(iTagFiles); | |
539 | if (current != fChain->GetTreeNumber()) { | |
540 | fRunFormula->UpdateFormulaLeaves(); | |
541 | fLHCFormula->UpdateFormulaLeaves(); | |
542 | fDetectorFormula->UpdateFormulaLeaves(); | |
543 | fEventFormula->UpdateFormulaLeaves(); | |
544 | // Fix for aod tags: for each tree in the chain, merge the entries | |
545 | cEntries = (fChain->GetTree())->GetEntries(); | |
546 | iev = 0; | |
547 | ientry = 0; | |
548 | // | |
549 | current = fChain->GetTreeNumber(); | |
550 | } | |
551 | //Event list | |
552 | iTotalEvents += tag->GetNEvents(); | |
553 | if ((iev == 0) || !aod) localList->Reset(); | |
554 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
555 | if(fLHCFormula->EvalInstance(iTagFiles) == 1) { | |
556 | if(fDetectorFormula->EvalInstance(iTagFiles) == 1) { | |
557 | Int_t iEvents = fEventFormula->GetNdata(); | |
558 | const TClonesArray *tagList = tag->GetEventTags(); | |
559 | iRejectedEvtInFile = 0; | |
560 | iAcceptedEvtInFile = 0; | |
561 | for(Int_t i = 0; i < iEvents; i++) { | |
562 | evTag = (AliEventTag *) tagList->At(i); | |
563 | guid = evTag->GetGUID(); | |
564 | turl = evTag->GetTURL(); | |
565 | lfn = turl(8,turl.Length()); | |
566 | if(fEventFormula->EvalInstance(i) == 1) { | |
567 | if(aod) localList->Enter(iev); | |
568 | else localList->Enter(i); | |
569 | iAcceptedEvtInFile++; | |
570 | } | |
571 | else { | |
572 | iRejectedEvt++; | |
573 | iRejectedEvtInFile++; | |
574 | } | |
575 | iev++; | |
576 | }//event loop | |
577 | if ((ientry == cEntries-1) || !aod) { | |
578 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList,iAcceptedEvtInFile, iRejectedEvtInFile); | |
579 | iAccepted += localList->GetN(); | |
580 | } | |
581 | }//detector tag cuts | |
582 | else { | |
583 | iRejectedDet += tag->GetNEvents(); | |
584 | } | |
585 | }//lhc tag cuts | |
586 | else { | |
587 | iRejectedLHC += tag->GetNEvents(); | |
588 | } | |
589 | }//run tag cuts | |
590 | else { | |
591 | iRejectedRun += tag->GetNEvents(); | |
592 | } | |
593 | ientry++; | |
594 | }//tag file loop | |
595 | collection->WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt); | |
596 | collection->Export(); | |
597 | ||
598 | delete tag; | |
599 | return kTRUE; | |
600 | } | |
601 | ||
602 | //___________________________________________________________________________ | |
603 | TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) { | |
604 | //returns the chain+event list - used in batch sessions | |
605 | // this function will be removed once the new root | |
606 | // improvements are committed | |
607 | TString fsystem = system; | |
608 | Int_t iAccepted = 0; | |
609 | ||
610 | TChain *fAnalysisChain = 0; | |
611 | if(fAnalysisType == "ESD") fAnalysisChain = new TChain("esdTree"); | |
612 | else if(fAnalysisType == "AOD") fAnalysisChain = new TChain("aodTree"); | |
613 | else AliFatal("Only ESD and AOD type is implemented!!!"); | |
614 | ||
615 | //Event list | |
616 | TEventList *fEventList = new TEventList(); | |
617 | AliXMLCollection *collection = AliXMLCollection::Open(wn); | |
618 | ||
619 | collection->Reset(); | |
620 | while (collection->Next()) { | |
621 | AliInfo(Form("Adding: %s",collection->GetTURL(""))); | |
622 | fAnalysisChain->Add(collection->GetTURL("")); | |
623 | TEntryList *list = (TEntryList *)collection->GetEventList(""); | |
624 | for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i)); | |
625 | ||
626 | if(fsystem == "pp") iAccepted += 100; | |
627 | else if(fsystem == "PbPb") iAccepted += 1; | |
628 | } | |
629 | ||
630 | fAnalysisChain->SetEventList(fEventList); | |
631 | ||
632 | AliInfo(Form("Number of selected events: %d",fEventList->GetN())); | |
633 | ||
634 | return fAnalysisChain; | |
635 | } | |
636 | ||
637 | //___________________________________________________________________________ | |
638 | TChain* | |
639 | AliTagAnalysis::CreateChainFromCollection(const char* collectionname, const char* treename) | |
640 | { | |
641 | /// Build a TChain (with its TEntryList object attached) from an XML collection. | |
642 | /// Returned chain must be deleted by the client. | |
643 | ||
644 | TString streename(treename); | |
645 | if ( streename != "esdTree" && streename != "aodTree" ) | |
646 | { | |
647 | AliErrorClass("Only esdTree and aodTree implemented so far..."); | |
648 | return 0x0; | |
649 | } | |
650 | ||
651 | TChain* chain = new TChain(streename.Data()); | |
652 | ||
653 | // create the event list for the chain. Will be attached to the chain | |
654 | // which thus becomes the owner of it. | |
655 | TEntryList* elist = new TEntryList; | |
656 | ||
657 | AliXMLCollection* collection = AliXMLCollection::Open(collectionname); | |
658 | ||
659 | // Tag selection summary per file | |
660 | TMap* tagCutSummary = new TMap(); | |
661 | tagCutSummary->SetName("TagCutSumm"); | |
662 | ||
663 | Int_t iAccepted = 0; | |
664 | ||
665 | collection->Reset(); | |
666 | ||
667 | while (collection->Next()) | |
668 | { | |
669 | AliDebugClass(1,Form("Adding: %s",collection->GetTURL(""))); | |
670 | chain->Add(collection->GetTURL("")); | |
671 | TEntryList *list = collection->GetEventList(""); | |
672 | list->SetTreeName(streename.Data()); | |
673 | list->SetFileName(collection->GetTURL("")); | |
674 | elist->Add(list); | |
675 | iAccepted += list->GetN(); | |
676 | if (collection->GetCutSumm()) | |
677 | { | |
678 | tagCutSummary->Add(new TObjString(collection->GetTURL("")), new TObjString(collection->GetCutSumm())); | |
679 | } | |
680 | } | |
681 | ||
682 | chain->SetEntryList(elist,"ne"); // ne => do not expand tree name and/or file names | |
683 | ||
684 | AliDebugClass(1,Form("Number of selected events: %d",iAccepted)); | |
685 | ||
686 | TList *aUserInfo = chain->GetUserInfo(); | |
687 | aUserInfo->Add(tagCutSummary); | |
688 | ||
689 | Int_t iAccEv; | |
690 | Int_t iTotalEvents; | |
691 | Int_t iRejRun; | |
692 | Int_t iRejLHC; | |
693 | Int_t iRejDet; | |
694 | Int_t iRejEvt; | |
695 | ||
696 | collection->GetCollectionSummary(&iTotalEvents, &iAccEv, &iRejRun, &iRejLHC, &iRejDet, &iRejEvt); | |
697 | ||
698 | char nstr[2000]; | |
699 | ||
700 | sprintf(nstr, "TotalEvents=%i", iTotalEvents); | |
701 | TObjString *iTotStr = new TObjString(nstr); | |
702 | aUserInfo->Add(iTotStr); | |
703 | ||
704 | sprintf(nstr, "AcceptedEvents=%i", iAccepted); | |
705 | TObjString *iAccStr = new TObjString(nstr); | |
706 | aUserInfo->Add(iAccStr); | |
707 | ||
708 | sprintf(nstr, "RejectedRun=%i", iRejRun); | |
709 | TObjString *iRejRunStr = new TObjString(nstr); | |
710 | aUserInfo->Add(iRejRunStr); | |
711 | ||
712 | sprintf(nstr, "RejectedLHC=%i", iRejLHC); | |
713 | TObjString *iRejLHCStr = new TObjString(nstr); | |
714 | aUserInfo->Add(iRejLHCStr); | |
715 | ||
716 | sprintf(nstr, "RejectedDet=%i", iRejDet); | |
717 | TObjString *iRejDetStr = new TObjString(nstr); | |
718 | aUserInfo->Add(iRejDetStr); | |
719 | ||
720 | sprintf(nstr, "RejectedEvt=%i", iRejEvt); | |
721 | TObjString *iRejEvtStr = new TObjString(nstr); | |
722 | aUserInfo->Add(iRejEvtStr); | |
723 | ||
724 | return chain; | |
725 | } |