]>
Commit | Line | Data |
---|---|---|
d08133e6 | 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 | |
cd305eb1 | 23 | #include <Riostream.h> |
d08133e6 | 24 | #include <TSystem.h> |
25 | #include <TChain.h> | |
26 | #include <TFile.h> | |
27 | #include <TEventList.h> | |
28 | #include <TEntryList.h> | |
29 | #include <TTreeFormula.h> | |
f0f29480 | 30 | #include <TMap.h> |
d08133e6 | 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" | |
2ec6a1d3 | 41 | #include "AliDetectorTagCuts.h" |
42 | #include "AliLHCTagCuts.h" | |
d08133e6 | 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(), | |
6cfbb923 | 55 | fChain(0x0), |
cd305eb1 | 56 | fAnalysisType(), |
57 | fGlobalList(0) { | |
d08133e6 | 58 | //Default constructor for a AliTagAnalysis |
59 | } | |
60 | ||
6cfbb923 | 61 | //___________________________________________________________________________ |
62 | AliTagAnalysis::AliTagAnalysis(const char* type): | |
63 | TObject(), | |
64 | ftagresult(0x0), | |
65 | fTagDirName(), | |
66 | fChain(0x0), | |
cd305eb1 | 67 | fAnalysisType(type), |
68 | fGlobalList(0) { | |
6cfbb923 | 69 | //constructor for a AliTagAnalysis |
70 | } | |
71 | ||
d08133e6 | 72 | //___________________________________________________________________________ |
73 | AliTagAnalysis::~AliTagAnalysis() { | |
cd305eb1 | 74 | //Default destructor for a AliTagAnalysis |
75 | if(ftagresult) delete ftagresult; | |
76 | if(fChain) delete fChain; | |
77 | if(fGlobalList) delete fGlobalList; | |
d08133e6 | 78 | } |
79 | ||
80 | //___________________________________________________________________________ | |
0bf3148c | 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"); | |
d08133e6 | 91 | |
0bf3148c | 92 | if ( checkFile ) |
93 | { | |
94 | return ( fChain->AddFile(alienUrl,-1) > 0 ); | |
95 | } | |
96 | else | |
97 | { | |
98 | return ( fChain->AddFile(alienUrl) > 0 ); | |
99 | } | |
d08133e6 | 100 | |
d08133e6 | 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"); | |
6cfbb923 | 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 | ||
d08133e6 | 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); | |
68550043 | 127 | printf("Tag file %s\n", fTagFilename.Data()); |
128 | ||
d08133e6 | 129 | }//pattern check |
130 | }//directory loop | |
0c57b780 | 131 | //AliInfo(Form("Chained tag files: %d ",fChain->GetEntries())); |
132 | // AliDebug(Form("Chained tag files: %d ",fChain->GetEntries())); | |
68550043 | 133 | fChain->ls(); |
134 | ||
d08133e6 | 135 | } |
136 | ||
137 | ||
138 | //___________________________________________________________________________ | |
727d922c | 139 | TChain * AliTagAnalysis::ChainGridTags(TGridResult *res) { |
d08133e6 | 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); | |
727d922c | 153 | }//grid result loop |
154 | return fChain; | |
d08133e6 | 155 | } |
156 | ||
157 | ||
158 | //___________________________________________________________________________ | |
cd305eb1 | 159 | TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts, |
160 | AliLHCTagCuts *lhcTagCuts, | |
161 | AliDetectorTagCuts *detTagCuts, | |
162 | AliEventTagCuts *evTagCuts) { | |
d08133e6 | 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........")); | |
b97856f9 | 167 | |
68550043 | 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 | } | |
6cfbb923 | 175 | else AliFatal("Only ESD and AOD type is implemented!!!"); |
b97856f9 | 176 | |
d08133e6 | 177 | //ESD file chain |
68550043 | 178 | TChain *esdChain = new TChain(aliceFile.Data()); |
b97856f9 | 179 | //global entry list |
cd305eb1 | 180 | fGlobalList = new TEntryList(); |
d08133e6 | 181 | |
182 | //Defining tag objects | |
5a561fa0 | 183 | AliRunTag *tag = new AliRunTag; |
184 | AliEventTag *evTag = new AliEventTag; | |
d08133e6 | 185 | fChain->SetBranchAddress("AliTAG",&tag); |
186 | ||
9b4aee57 | 187 | TString guid; |
188 | TString turl; | |
189 | TString path; | |
d08133e6 | 190 | |
68550043 | 191 | TTree* cTree = 0; |
9ce6b490 | 192 | TEntryList* localList = new TEntryList(); |
68550043 | 193 | |
d08133e6 | 194 | Int_t iAccepted = 0; |
68550043 | 195 | Int_t iev = 0; |
196 | Int_t ientry = 0; | |
197 | Int_t cEntries = 0; | |
198 | ||
d08133e6 | 199 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { |
200 | fChain->GetEntry(iTagFiles); | |
68550043 | 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 | ||
2ec6a1d3 | 210 | if(runTagCuts->IsAccepted(tag)) { |
211 | if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) { | |
212 | if(detTagCuts->IsAccepted(tag->GetDetectorTags())) { | |
9ce6b490 | 213 | if ((iev == 0) || !aod) localList->Reset(); |
2ec6a1d3 | 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(); | |
68550043 | 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++; | |
2ec6a1d3 | 230 | }//event loop |
68550043 | 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 | } | |
2ec6a1d3 | 237 | }//detector tag cuts |
238 | }//lhc tag cuts | |
d08133e6 | 239 | }//run tags cut |
5a561fa0 | 240 | tag->Clear(); |
68550043 | 241 | ientry++; |
d08133e6 | 242 | }//tag file loop |
b97856f9 | 243 | AliInfo(Form("Accepted events: %d",iAccepted)); |
5d0e8364 | 244 | esdChain->ls(); |
68550043 | 245 | esdChain->SetEntryList(fGlobalList,"ne"); |
9ce6b490 | 246 | delete tag; |
0c57b780 | 247 | delete localList; |
9ce6b490 | 248 | |
68550043 | 249 | return esdChain; |
d08133e6 | 250 | } |
251 | ||
252 | //___________________________________________________________________________ | |
cd305eb1 | 253 | TChain *AliTagAnalysis::QueryTags(const char *fRunCut, |
254 | const char *fLHCCut, | |
255 | const char *fDetectorCut, | |
256 | const char *fEventCut) { | |
d08133e6 | 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 | ||
68550043 | 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 | } | |
6cfbb923 | 269 | else AliFatal("Only ESD and AOD type is implemented!!!"); |
b97856f9 | 270 | |
271 | //ESD file chain | |
68550043 | 272 | TChain *esdChain = new TChain(aliceFile.Data()); |
b97856f9 | 273 | //global entry list |
cd305eb1 | 274 | fGlobalList = new TEntryList(); |
d08133e6 | 275 | |
276 | //Defining tag objects | |
940b4031 | 277 | AliRunTag *tag = new AliRunTag; |
d08133e6 | 278 | AliEventTag *evTag = new AliEventTag; |
279 | fChain->SetBranchAddress("AliTAG",&tag); | |
280 | ||
9b4aee57 | 281 | TString guid; |
282 | TString turl; | |
283 | TString path; | |
d08133e6 | 284 | |
285 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
2ec6a1d3 | 286 | TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain); |
287 | TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain); | |
288 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
d08133e6 | 289 | |
940b4031 | 290 | TEntryList* localList = new TEntryList(); |
68550043 | 291 | |
292 | Int_t iev = 0; | |
293 | Int_t ientry = 0; | |
294 | Int_t cEntries = 0; | |
295 | Int_t current = -1; | |
d08133e6 | 296 | Int_t iAccepted = 0; |
68550043 | 297 | |
cd305eb1 | 298 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { |
d08133e6 | 299 | fChain->GetEntry(iTagFiles); |
300 | if (current != fChain->GetTreeNumber()) { | |
301 | fRunFormula->UpdateFormulaLeaves(); | |
2ec6a1d3 | 302 | fLHCFormula->UpdateFormulaLeaves(); |
303 | fDetectorFormula->UpdateFormulaLeaves(); | |
d08133e6 | 304 | fEventFormula->UpdateFormulaLeaves(); |
68550043 | 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 | // | |
d08133e6 | 310 | current = fChain->GetTreeNumber(); |
311 | } | |
312 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
2ec6a1d3 | 313 | if(fLHCFormula->EvalInstance(iTagFiles) == 1) { |
68550043 | 314 | if(fDetectorFormula->EvalInstance(iTagFiles) == 1) { |
940b4031 | 315 | if ((iev == 0) || !aod) localList->Reset(); |
2ec6a1d3 | 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(); | |
68550043 | 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++; | |
2ec6a1d3 | 330 | }//event loop |
68550043 | 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 | } | |
2ec6a1d3 | 338 | }//detector tag cuts |
339 | }//lhc tag cuts | |
d08133e6 | 340 | }//run tag cut |
68550043 | 341 | tag->Clear(); |
342 | ientry++; | |
d08133e6 | 343 | }//tag file loop |
b97856f9 | 344 | AliInfo(Form("Accepted events: %d",iAccepted)); |
68550043 | 345 | esdChain->SetEntryList(fGlobalList,"ne"); |
940b4031 | 346 | |
347 | delete tag; | |
0c57b780 | 348 | delete localList; |
68550043 | 349 | return esdChain; |
d08133e6 | 350 | } |
351 | ||
352 | //___________________________________________________________________________ | |
0bf3148c | 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 | ||
d08133e6 | 365 | AliInfo(Form("Creating the collection........")); |
0bf3148c | 366 | |
367 | if (!fChain) | |
368 | { | |
369 | AliError("fChain is NULL. Cannot make a collection from that !"); | |
370 | return kFALSE; | |
371 | } | |
372 | ||
68550043 | 373 | Bool_t aod = kFALSE; |
374 | if(fAnalysisType == "AOD") aod = kTRUE; | |
0bf3148c | 375 | |
376 | ||
377 | AliXMLCollection collection; | |
378 | collection.SetCollectionName(name); | |
379 | collection.WriteHeader(); | |
380 | ||
9b4aee57 | 381 | TString guid; |
382 | TString turl; | |
383 | TString lfn; | |
d08133e6 | 384 | |
68550043 | 385 | TTree* cTree = 0; |
0bf3148c | 386 | TEntryList localList; |
68550043 | 387 | Int_t iAccepted = 0; |
388 | Int_t iev = 0; | |
389 | Int_t ientry = 0; | |
390 | Int_t cEntries = 0; | |
0bf3148c | 391 | |
f0f29480 | 392 | Int_t iRejectedRun = 0; |
393 | Int_t iRejectedLHC = 0; | |
394 | Int_t iRejectedDet = 0; | |
395 | Int_t iRejectedEvt = 0; | |
0bf3148c | 396 | |
f0f29480 | 397 | Int_t iTotalEvents = 0; |
0bf3148c | 398 | |
f0f29480 | 399 | Int_t iAcceptedEvtInFile = 0; |
400 | Int_t iRejectedEvtInFile = 0; | |
0bf3148c | 401 | |
d08133e6 | 402 | //Defining tag objects |
0bf3148c | 403 | AliRunTag* tag = new AliRunTag; |
d08133e6 | 404 | fChain->SetBranchAddress("AliTAG",&tag); |
0bf3148c | 405 | |
406 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetListOfFiles()->GetEntries(); ++iTagFiles) | |
407 | { | |
d08133e6 | 408 | fChain->GetEntry(iTagFiles); |
68550043 | 409 | TTree* tree = fChain->GetTree(); |
410 | if (cTree != tree) { | |
0bf3148c | 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; | |
68550043 | 416 | } |
417 | //Event list | |
f0f29480 | 418 | iTotalEvents += tag->GetNEvents(); |
0bf3148c | 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 | } | |
2ec6a1d3 | 469 | }//lhc tag cuts |
f0f29480 | 470 | else { |
0bf3148c | 471 | iRejectedLHC += tag->GetNEvents(); |
f0f29480 | 472 | } |
d08133e6 | 473 | }//run tag cuts |
f0f29480 | 474 | else { |
475 | iRejectedRun += tag->GetNEvents(); | |
476 | } | |
5a561fa0 | 477 | tag->Clear(); |
0bf3148c | 478 | ++ientry; |
479 | } //tag file loop | |
480 | ||
481 | collection.WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt); | |
482 | collection.Export(); | |
940b4031 | 483 | |
d08133e6 | 484 | return kTRUE; |
485 | } | |
486 | ||
487 | //___________________________________________________________________________ | |
cd305eb1 | 488 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, |
489 | const char *fRunCut, | |
490 | const char *fLHCCut, | |
491 | const char *fDetectorCut, | |
492 | const char *fEventCut) { | |
d08133e6 | 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 | ||
68550043 | 498 | Bool_t aod = kFALSE; |
499 | if(fAnalysisType == "AOD") aod = kTRUE; | |
500 | ||
d08133e6 | 501 | AliXMLCollection *collection = new AliXMLCollection(); |
502 | collection->SetCollectionName(name); | |
503 | collection->WriteHeader(); | |
504 | ||
9b4aee57 | 505 | TString guid; |
506 | TString turl; | |
507 | TString lfn; | |
940b4031 | 508 | TEntryList* localList = new TEntryList(); |
d08133e6 | 509 | |
68550043 | 510 | Int_t iAccepted = 0; |
511 | Int_t iev = 0; | |
512 | Int_t ientry = 0; | |
513 | Int_t cEntries = 0; | |
cd305eb1 | 514 | |
f0f29480 | 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 | ||
cd305eb1 | 525 | //Defining tag objects |
940b4031 | 526 | AliRunTag *tag = new AliRunTag; |
cd305eb1 | 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++) { | |
68550043 | 537 | |
cd305eb1 | 538 | fChain->GetEntry(iTagFiles); |
539 | if (current != fChain->GetTreeNumber()) { | |
540 | fRunFormula->UpdateFormulaLeaves(); | |
541 | fLHCFormula->UpdateFormulaLeaves(); | |
542 | fDetectorFormula->UpdateFormulaLeaves(); | |
543 | fEventFormula->UpdateFormulaLeaves(); | |
68550043 | 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 | // | |
cd305eb1 | 549 | current = fChain->GetTreeNumber(); |
550 | } | |
68550043 | 551 | //Event list |
f0f29480 | 552 | iTotalEvents += tag->GetNEvents(); |
940b4031 | 553 | if ((iev == 0) || !aod) localList->Reset(); |
cd305eb1 | 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(); | |
f0f29480 | 559 | iRejectedEvtInFile = 0; |
560 | iAcceptedEvtInFile = 0; | |
cd305eb1 | 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()); | |
68550043 | 566 | if(fEventFormula->EvalInstance(i) == 1) { |
567 | if(aod) localList->Enter(iev); | |
568 | else localList->Enter(i); | |
f0f29480 | 569 | iAcceptedEvtInFile++; |
570 | } | |
571 | else { | |
572 | iRejectedEvt++; | |
573 | iRejectedEvtInFile++; | |
68550043 | 574 | } |
575 | iev++; | |
cd305eb1 | 576 | }//event loop |
68550043 | 577 | if ((ientry == cEntries-1) || !aod) { |
f0f29480 | 578 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList,iAcceptedEvtInFile, iRejectedEvtInFile); |
579 | iAccepted += localList->GetN(); | |
68550043 | 580 | } |
cd305eb1 | 581 | }//detector tag cuts |
f0f29480 | 582 | else { |
583 | iRejectedDet += tag->GetNEvents(); | |
584 | } | |
cd305eb1 | 585 | }//lhc tag cuts |
f0f29480 | 586 | else { |
587 | iRejectedLHC += tag->GetNEvents(); | |
588 | } | |
cd305eb1 | 589 | }//run tag cuts |
f0f29480 | 590 | else { |
591 | iRejectedRun += tag->GetNEvents(); | |
592 | } | |
68550043 | 593 | ientry++; |
cd305eb1 | 594 | }//tag file loop |
f0f29480 | 595 | collection->WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt); |
68550043 | 596 | collection->Export(); |
940b4031 | 597 | |
598 | delete tag; | |
cd305eb1 | 599 | return kTRUE; |
600 | } | |
601 | ||
d08133e6 | 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; | |
6cfbb923 | 609 | |
88fb0edc | 610 | TChain *fAnalysisChain = 0; |
611 | if(fAnalysisType == "ESD") fAnalysisChain = new TChain("esdTree"); | |
612 | else if(fAnalysisType == "AOD") fAnalysisChain = new TChain("aodTree"); | |
6cfbb923 | 613 | else AliFatal("Only ESD and AOD type is implemented!!!"); |
614 | ||
d08133e6 | 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(""))); | |
6cfbb923 | 622 | fAnalysisChain->Add(collection->GetTURL("")); |
d08133e6 | 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 | ||
6cfbb923 | 630 | fAnalysisChain->SetEventList(fEventList); |
d08133e6 | 631 | |
632 | AliInfo(Form("Number of selected events: %d",fEventList->GetN())); | |
633 | ||
6cfbb923 | 634 | return fAnalysisChain; |
d08133e6 | 635 | } |
636 | ||
637 | //___________________________________________________________________________ | |
0bf3148c | 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()); | |
6cfbb923 | 652 | |
0bf3148c | 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); | |
d08133e6 | 658 | |
f0f29480 | 659 | // Tag selection summary per file |
0bf3148c | 660 | TMap* tagCutSummary = new TMap(); |
f0f29480 | 661 | tagCutSummary->SetName("TagCutSumm"); |
662 | ||
0bf3148c | 663 | Int_t iAccepted = 0; |
664 | ||
d08133e6 | 665 | collection->Reset(); |
0bf3148c | 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()); | |
d08133e6 | 673 | list->SetFileName(collection->GetTURL("")); |
0bf3148c | 674 | elist->Add(list); |
d08133e6 | 675 | iAccepted += list->GetN(); |
f0f29480 | 676 | if (collection->GetCutSumm()) |
0bf3148c | 677 | { |
f0f29480 | 678 | tagCutSummary->Add(new TObjString(collection->GetTURL("")), new TObjString(collection->GetCutSumm())); |
0bf3148c | 679 | } |
d08133e6 | 680 | } |
681 | ||
0bf3148c | 682 | chain->SetEntryList(elist,"ne"); // ne => do not expand tree name and/or file names |
d08133e6 | 683 | |
0bf3148c | 684 | AliDebugClass(1,Form("Number of selected events: %d",iAccepted)); |
d08133e6 | 685 | |
0bf3148c | 686 | TList *aUserInfo = chain->GetUserInfo(); |
f0f29480 | 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 | ||
0bf3148c | 724 | return chain; |
d08133e6 | 725 | } |