]>
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 |
215dee2d | 141 | //Chains the tags that are stored in the GRID |
d08133e6 | 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 | TString aliceFile; |
169 | if(fAnalysisType == "ESD") aliceFile = "esdTree"; | |
215dee2d | 170 | else if(fAnalysisType == "AOD") aliceFile = "aodTree"; |
6cfbb923 | 171 | else AliFatal("Only ESD and AOD type is implemented!!!"); |
b97856f9 | 172 | |
d08133e6 | 173 | //ESD file chain |
68550043 | 174 | TChain *esdChain = new TChain(aliceFile.Data()); |
b97856f9 | 175 | //global entry list |
cd305eb1 | 176 | fGlobalList = new TEntryList(); |
d08133e6 | 177 | |
178 | //Defining tag objects | |
5a561fa0 | 179 | AliRunTag *tag = new AliRunTag; |
180 | AliEventTag *evTag = new AliEventTag; | |
d08133e6 | 181 | fChain->SetBranchAddress("AliTAG",&tag); |
182 | ||
9b4aee57 | 183 | TString guid; |
184 | TString turl; | |
185 | TString path; | |
d08133e6 | 186 | |
9ce6b490 | 187 | TEntryList* localList = new TEntryList(); |
68550043 | 188 | |
d08133e6 | 189 | Int_t iAccepted = 0; |
68550043 | 190 | |
215dee2d | 191 | for(Int_t iEntry = 0; iEntry < fChain->GetEntries(); iEntry++) { |
192 | fChain->GetEntry(iEntry); | |
68550043 | 193 | |
2ec6a1d3 | 194 | if(runTagCuts->IsAccepted(tag)) { |
195 | if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) { | |
196 | if(detTagCuts->IsAccepted(tag->GetDetectorTags())) { | |
215dee2d | 197 | localList->Reset(); |
2ec6a1d3 | 198 | Int_t iEvents = tag->GetNEvents(); |
199 | const TClonesArray *tagList = tag->GetEventTags(); | |
200 | for(Int_t i = 0; i < iEvents; i++) { | |
201 | evTag = (AliEventTag *) tagList->At(i); | |
202 | guid = evTag->GetGUID(); | |
203 | turl = evTag->GetTURL(); | |
204 | path = evTag->GetPath(); | |
68550043 | 205 | localList->SetTreeName(aliceFile.Data()); |
206 | if(turl!="") localList->SetFileName(turl.Data()); | |
207 | else localList->SetFileName(path.Data()); | |
215dee2d | 208 | |
209 | if(evTagCuts->IsAccepted(evTag)) localList->Enter(i); | |
2ec6a1d3 | 210 | }//event loop |
215dee2d | 211 | iAccepted += localList->GetN(); |
212 | if(turl != "") esdChain->AddFile(turl); | |
213 | else if(path != "") esdChain->AddFile(path); | |
214 | fGlobalList->Add(localList); | |
2ec6a1d3 | 215 | }//detector tag cuts |
216 | }//lhc tag cuts | |
d08133e6 | 217 | }//run tags cut |
5a561fa0 | 218 | tag->Clear(); |
d08133e6 | 219 | }//tag file loop |
215dee2d | 220 | AliInfo(Form("Accepted events: %d", iAccepted)); |
5d0e8364 | 221 | esdChain->ls(); |
68550043 | 222 | esdChain->SetEntryList(fGlobalList,"ne"); |
9ce6b490 | 223 | delete tag; |
0c57b780 | 224 | delete localList; |
9ce6b490 | 225 | |
68550043 | 226 | return esdChain; |
d08133e6 | 227 | } |
228 | ||
229 | //___________________________________________________________________________ | |
cd305eb1 | 230 | TChain *AliTagAnalysis::QueryTags(const char *fRunCut, |
231 | const char *fLHCCut, | |
232 | const char *fDetectorCut, | |
233 | const char *fEventCut) { | |
d08133e6 | 234 | //Queries the tag chain using the defined |
235 | //event tag cuts from the AliEventTagCuts object | |
236 | //and returns a TChain along with the associated TEventList | |
237 | AliInfo(Form("Querying the tags........")); | |
215dee2d | 238 | |
68550043 | 239 | TString aliceFile; |
240 | if(fAnalysisType == "ESD") aliceFile = "esdTree"; | |
215dee2d | 241 | else if(fAnalysisType == "AOD") aliceFile = "aodTree"; |
6cfbb923 | 242 | else AliFatal("Only ESD and AOD type is implemented!!!"); |
b97856f9 | 243 | |
215dee2d | 244 | |
b97856f9 | 245 | //ESD file chain |
68550043 | 246 | TChain *esdChain = new TChain(aliceFile.Data()); |
b97856f9 | 247 | //global entry list |
cd305eb1 | 248 | fGlobalList = new TEntryList(); |
d08133e6 | 249 | |
250 | //Defining tag objects | |
940b4031 | 251 | AliRunTag *tag = new AliRunTag; |
d08133e6 | 252 | AliEventTag *evTag = new AliEventTag; |
253 | fChain->SetBranchAddress("AliTAG",&tag); | |
254 | ||
9b4aee57 | 255 | TString guid; |
256 | TString turl; | |
257 | TString path; | |
d08133e6 | 258 | |
259 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
2ec6a1d3 | 260 | TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain); |
261 | TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain); | |
262 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
d08133e6 | 263 | |
940b4031 | 264 | TEntryList* localList = new TEntryList(); |
68550043 | 265 | |
215dee2d | 266 | Int_t current = -1; |
d08133e6 | 267 | Int_t iAccepted = 0; |
215dee2d | 268 | |
cd305eb1 | 269 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { |
d08133e6 | 270 | fChain->GetEntry(iTagFiles); |
271 | if (current != fChain->GetTreeNumber()) { | |
272 | fRunFormula->UpdateFormulaLeaves(); | |
2ec6a1d3 | 273 | fLHCFormula->UpdateFormulaLeaves(); |
274 | fDetectorFormula->UpdateFormulaLeaves(); | |
d08133e6 | 275 | fEventFormula->UpdateFormulaLeaves(); |
276 | current = fChain->GetTreeNumber(); | |
277 | } | |
215dee2d | 278 | |
d08133e6 | 279 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { |
2ec6a1d3 | 280 | if(fLHCFormula->EvalInstance(iTagFiles) == 1) { |
68550043 | 281 | if(fDetectorFormula->EvalInstance(iTagFiles) == 1) { |
215dee2d | 282 | localList->Reset(); |
2ec6a1d3 | 283 | Int_t iEvents = fEventFormula->GetNdata(); |
284 | const TClonesArray *tagList = tag->GetEventTags(); | |
285 | for(Int_t i = 0; i < iEvents; i++) { | |
286 | evTag = (AliEventTag *) tagList->At(i); | |
287 | guid = evTag->GetGUID(); | |
288 | turl = evTag->GetTURL(); | |
289 | path = evTag->GetPath(); | |
68550043 | 290 | localList->SetTreeName(aliceFile.Data()); |
291 | localList->SetFileName(turl.Data()); | |
215dee2d | 292 | if(fEventFormula->EvalInstance(i) == 1) localList->Enter(i); |
2ec6a1d3 | 293 | }//event loop |
68550043 | 294 | |
215dee2d | 295 | if(path != "") esdChain->AddFile(path); |
296 | else if(turl != "") esdChain->AddFile(turl); | |
297 | fGlobalList->Add(localList); | |
298 | iAccepted += localList->GetN(); | |
2ec6a1d3 | 299 | }//detector tag cuts |
300 | }//lhc tag cuts | |
d08133e6 | 301 | }//run tag cut |
68550043 | 302 | tag->Clear(); |
d08133e6 | 303 | }//tag file loop |
215dee2d | 304 | AliInfo(Form("Accepted events: %d", iAccepted)); |
68550043 | 305 | esdChain->SetEntryList(fGlobalList,"ne"); |
940b4031 | 306 | |
307 | delete tag; | |
0c57b780 | 308 | delete localList; |
68550043 | 309 | return esdChain; |
d08133e6 | 310 | } |
311 | ||
312 | //___________________________________________________________________________ | |
0bf3148c | 313 | Bool_t |
314 | AliTagAnalysis::CreateXMLCollection(const char* name, | |
315 | AliRunTagCuts *runTagCuts, | |
316 | AliLHCTagCuts *lhcTagCuts, | |
317 | AliDetectorTagCuts *detTagCuts, | |
318 | AliEventTagCuts *evTagCuts) | |
319 | { | |
320 | /// Queries the tag chain using the defined run, lhc, detector and event tag objects | |
321 | /// and create a XML collection named "name.xml" | |
322 | /// if any of the runTagCuts, lhcTagCuts, detTagCuts or evTagCuts is NULL | |
323 | /// check on that object will be skipped. | |
324 | ||
d08133e6 | 325 | AliInfo(Form("Creating the collection........")); |
0bf3148c | 326 | |
327 | if (!fChain) | |
328 | { | |
329 | AliError("fChain is NULL. Cannot make a collection from that !"); | |
330 | return kFALSE; | |
331 | } | |
332 | ||
0bf3148c | 333 | AliXMLCollection collection; |
334 | collection.SetCollectionName(name); | |
335 | collection.WriteHeader(); | |
336 | ||
9b4aee57 | 337 | TString guid; |
338 | TString turl; | |
339 | TString lfn; | |
d08133e6 | 340 | |
0bf3148c | 341 | TEntryList localList; |
68550043 | 342 | Int_t iAccepted = 0; |
215dee2d | 343 | |
f0f29480 | 344 | Int_t iRejectedRun = 0; |
345 | Int_t iRejectedLHC = 0; | |
346 | Int_t iRejectedDet = 0; | |
347 | Int_t iRejectedEvt = 0; | |
0bf3148c | 348 | |
f0f29480 | 349 | Int_t iTotalEvents = 0; |
0bf3148c | 350 | |
f0f29480 | 351 | Int_t iAcceptedEvtInFile = 0; |
352 | Int_t iRejectedEvtInFile = 0; | |
0bf3148c | 353 | |
d08133e6 | 354 | //Defining tag objects |
0bf3148c | 355 | AliRunTag* tag = new AliRunTag; |
d08133e6 | 356 | fChain->SetBranchAddress("AliTAG",&tag); |
0bf3148c | 357 | |
358 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetListOfFiles()->GetEntries(); ++iTagFiles) | |
359 | { | |
d08133e6 | 360 | fChain->GetEntry(iTagFiles); |
68550043 | 361 | //Event list |
f0f29480 | 362 | iTotalEvents += tag->GetNEvents(); |
215dee2d | 363 | localList.Reset(); |
364 | ||
0bf3148c | 365 | if ( !runTagCuts || ( runTagCuts && runTagCuts->IsAccepted(tag) ) ) |
0bf3148c | 366 | { |
215dee2d | 367 | if ( !lhcTagCuts || ( lhcTagCuts && lhcTagCuts->IsAccepted(tag->GetLHCTag())) ) |
368 | { | |
369 | if ( !detTagCuts || ( detTagCuts && detTagCuts->IsAccepted(tag->GetDetectorTags())) ) | |
370 | { | |
371 | Int_t i(0); | |
372 | TIter next(tag->GetEventTags()); | |
373 | AliEventTag* evTag(0x0); | |
374 | iRejectedEvtInFile = 0; | |
375 | iAcceptedEvtInFile = 0; | |
376 | while ( ( evTag = static_cast<AliEventTag*>(next()) ) ) | |
377 | { | |
378 | guid = evTag->GetGUID(); | |
379 | turl = evTag->GetTURL(); | |
380 | lfn = turl(8,turl.Length()); | |
381 | if( !evTagCuts || ( evTagCuts && evTagCuts->IsAccepted(evTag)) ) | |
0bf3148c | 382 | { |
215dee2d | 383 | localList.Enter(i); |
0bf3148c | 384 | iAcceptedEvtInFile++; |
0bf3148c | 385 | } |
215dee2d | 386 | else |
387 | { | |
388 | ++iRejectedEvt; | |
389 | ++iRejectedEvtInFile; | |
390 | } | |
391 | ++i; | |
392 | }//event loop | |
393 | iAccepted += localList.GetN(); | |
394 | collection.WriteBody(iTagFiles+1,guid,lfn,turl,&localList,iAcceptedEvtInFile,iRejectedEvtInFile); | |
395 | }//detector tag cuts | |
396 | else { | |
397 | iRejectedDet += tag->GetNEvents(); | |
398 | } | |
399 | }//lhc tag cuts | |
400 | else { | |
401 | iRejectedLHC += tag->GetNEvents(); | |
402 | } | |
403 | }//run tag cuts | |
f0f29480 | 404 | else { |
405 | iRejectedRun += tag->GetNEvents(); | |
406 | } | |
5a561fa0 | 407 | tag->Clear(); |
0bf3148c | 408 | } //tag file loop |
409 | ||
410 | collection.WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt); | |
411 | collection.Export(); | |
940b4031 | 412 | |
d08133e6 | 413 | return kTRUE; |
414 | } | |
415 | ||
416 | //___________________________________________________________________________ | |
cd305eb1 | 417 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, |
418 | const char *fRunCut, | |
419 | const char *fLHCCut, | |
420 | const char *fDetectorCut, | |
421 | const char *fEventCut) { | |
d08133e6 | 422 | //Queries the tag chain using the defined |
423 | //event tag cuts from the AliEventTagCuts object | |
424 | //and returns a XML collection | |
425 | AliInfo(Form("Creating the collection........")); | |
426 | ||
68550043 | 427 | |
d08133e6 | 428 | AliXMLCollection *collection = new AliXMLCollection(); |
429 | collection->SetCollectionName(name); | |
430 | collection->WriteHeader(); | |
431 | ||
9b4aee57 | 432 | TString guid; |
433 | TString turl; | |
434 | TString lfn; | |
940b4031 | 435 | TEntryList* localList = new TEntryList(); |
d08133e6 | 436 | |
68550043 | 437 | Int_t iAccepted = 0; |
cd305eb1 | 438 | |
f0f29480 | 439 | Int_t iRejectedRun = 0; |
440 | Int_t iRejectedLHC = 0; | |
441 | Int_t iRejectedDet = 0; | |
442 | Int_t iRejectedEvt = 0; | |
443 | ||
444 | Int_t iTotalEvents = 0; | |
445 | ||
446 | Int_t iAcceptedEvtInFile = 0; | |
447 | Int_t iRejectedEvtInFile = 0; | |
448 | ||
cd305eb1 | 449 | //Defining tag objects |
940b4031 | 450 | AliRunTag *tag = new AliRunTag; |
cd305eb1 | 451 | AliEventTag *evTag = new AliEventTag; |
452 | fChain->SetBranchAddress("AliTAG",&tag); | |
453 | ||
454 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
455 | TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain); | |
456 | TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain); | |
457 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
215dee2d | 458 | |
cd305eb1 | 459 | Int_t current = -1; |
215dee2d | 460 | |
cd305eb1 | 461 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { |
68550043 | 462 | |
cd305eb1 | 463 | fChain->GetEntry(iTagFiles); |
464 | if (current != fChain->GetTreeNumber()) { | |
465 | fRunFormula->UpdateFormulaLeaves(); | |
466 | fLHCFormula->UpdateFormulaLeaves(); | |
467 | fDetectorFormula->UpdateFormulaLeaves(); | |
468 | fEventFormula->UpdateFormulaLeaves(); | |
469 | current = fChain->GetTreeNumber(); | |
215dee2d | 470 | } |
471 | ||
472 | //Event list | |
f0f29480 | 473 | iTotalEvents += tag->GetNEvents(); |
215dee2d | 474 | localList->Reset(); |
cd305eb1 | 475 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { |
476 | if(fLHCFormula->EvalInstance(iTagFiles) == 1) { | |
477 | if(fDetectorFormula->EvalInstance(iTagFiles) == 1) { | |
478 | Int_t iEvents = fEventFormula->GetNdata(); | |
479 | const TClonesArray *tagList = tag->GetEventTags(); | |
f0f29480 | 480 | iRejectedEvtInFile = 0; |
481 | iAcceptedEvtInFile = 0; | |
cd305eb1 | 482 | for(Int_t i = 0; i < iEvents; i++) { |
483 | evTag = (AliEventTag *) tagList->At(i); | |
484 | guid = evTag->GetGUID(); | |
485 | turl = evTag->GetTURL(); | |
486 | lfn = turl(8,turl.Length()); | |
68550043 | 487 | if(fEventFormula->EvalInstance(i) == 1) { |
215dee2d | 488 | localList->Enter(i); |
489 | iAcceptedEvtInFile++; | |
f0f29480 | 490 | } |
491 | else { | |
492 | iRejectedEvt++; | |
493 | iRejectedEvtInFile++; | |
68550043 | 494 | } |
cd305eb1 | 495 | }//event loop |
215dee2d | 496 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList,iAcceptedEvtInFile, iRejectedEvtInFile); |
497 | iAccepted += localList->GetN(); | |
cd305eb1 | 498 | }//detector tag cuts |
f0f29480 | 499 | else { |
500 | iRejectedDet += tag->GetNEvents(); | |
501 | } | |
cd305eb1 | 502 | }//lhc tag cuts |
f0f29480 | 503 | else { |
504 | iRejectedLHC += tag->GetNEvents(); | |
505 | } | |
cd305eb1 | 506 | }//run tag cuts |
f0f29480 | 507 | else { |
508 | iRejectedRun += tag->GetNEvents(); | |
509 | } | |
cd305eb1 | 510 | }//tag file loop |
f0f29480 | 511 | collection->WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt); |
68550043 | 512 | collection->Export(); |
215dee2d | 513 | |
940b4031 | 514 | delete tag; |
cd305eb1 | 515 | return kTRUE; |
516 | } | |
517 | ||
d08133e6 | 518 | //___________________________________________________________________________ |
519 | TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) { | |
520 | //returns the chain+event list - used in batch sessions | |
521 | // this function will be removed once the new root | |
522 | // improvements are committed | |
523 | TString fsystem = system; | |
524 | Int_t iAccepted = 0; | |
6cfbb923 | 525 | |
88fb0edc | 526 | TChain *fAnalysisChain = 0; |
527 | if(fAnalysisType == "ESD") fAnalysisChain = new TChain("esdTree"); | |
528 | else if(fAnalysisType == "AOD") fAnalysisChain = new TChain("aodTree"); | |
6cfbb923 | 529 | else AliFatal("Only ESD and AOD type is implemented!!!"); |
530 | ||
d08133e6 | 531 | //Event list |
532 | TEventList *fEventList = new TEventList(); | |
533 | AliXMLCollection *collection = AliXMLCollection::Open(wn); | |
534 | ||
535 | collection->Reset(); | |
536 | while (collection->Next()) { | |
537 | AliInfo(Form("Adding: %s",collection->GetTURL(""))); | |
6cfbb923 | 538 | fAnalysisChain->Add(collection->GetTURL("")); |
d08133e6 | 539 | TEntryList *list = (TEntryList *)collection->GetEventList(""); |
540 | for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i)); | |
541 | ||
542 | if(fsystem == "pp") iAccepted += 100; | |
543 | else if(fsystem == "PbPb") iAccepted += 1; | |
544 | } | |
545 | ||
6cfbb923 | 546 | fAnalysisChain->SetEventList(fEventList); |
d08133e6 | 547 | |
548 | AliInfo(Form("Number of selected events: %d",fEventList->GetN())); | |
549 | ||
6cfbb923 | 550 | return fAnalysisChain; |
d08133e6 | 551 | } |
552 | ||
553 | //___________________________________________________________________________ | |
0bf3148c | 554 | TChain* |
555 | AliTagAnalysis::CreateChainFromCollection(const char* collectionname, const char* treename) | |
556 | { | |
557 | /// Build a TChain (with its TEntryList object attached) from an XML collection. | |
558 | /// Returned chain must be deleted by the client. | |
559 | ||
560 | TString streename(treename); | |
561 | if ( streename != "esdTree" && streename != "aodTree" ) | |
562 | { | |
563 | AliErrorClass("Only esdTree and aodTree implemented so far..."); | |
564 | return 0x0; | |
565 | } | |
566 | ||
567 | TChain* chain = new TChain(streename.Data()); | |
6cfbb923 | 568 | |
0bf3148c | 569 | // create the event list for the chain. Will be attached to the chain |
570 | // which thus becomes the owner of it. | |
571 | TEntryList* elist = new TEntryList; | |
572 | ||
573 | AliXMLCollection* collection = AliXMLCollection::Open(collectionname); | |
d08133e6 | 574 | |
f0f29480 | 575 | // Tag selection summary per file |
0bf3148c | 576 | TMap* tagCutSummary = new TMap(); |
f0f29480 | 577 | tagCutSummary->SetName("TagCutSumm"); |
578 | ||
0bf3148c | 579 | Int_t iAccepted = 0; |
580 | ||
d08133e6 | 581 | collection->Reset(); |
0bf3148c | 582 | |
583 | while (collection->Next()) | |
584 | { | |
585 | AliDebugClass(1,Form("Adding: %s",collection->GetTURL(""))); | |
586 | chain->Add(collection->GetTURL("")); | |
587 | TEntryList *list = collection->GetEventList(""); | |
588 | list->SetTreeName(streename.Data()); | |
d08133e6 | 589 | list->SetFileName(collection->GetTURL("")); |
0bf3148c | 590 | elist->Add(list); |
d08133e6 | 591 | iAccepted += list->GetN(); |
f0f29480 | 592 | if (collection->GetCutSumm()) |
0bf3148c | 593 | { |
f0f29480 | 594 | tagCutSummary->Add(new TObjString(collection->GetTURL("")), new TObjString(collection->GetCutSumm())); |
0bf3148c | 595 | } |
d08133e6 | 596 | } |
597 | ||
0bf3148c | 598 | chain->SetEntryList(elist,"ne"); // ne => do not expand tree name and/or file names |
d08133e6 | 599 | |
0bf3148c | 600 | AliDebugClass(1,Form("Number of selected events: %d",iAccepted)); |
d08133e6 | 601 | |
0bf3148c | 602 | TList *aUserInfo = chain->GetUserInfo(); |
f0f29480 | 603 | aUserInfo->Add(tagCutSummary); |
604 | ||
605 | Int_t iAccEv; | |
606 | Int_t iTotalEvents; | |
607 | Int_t iRejRun; | |
608 | Int_t iRejLHC; | |
609 | Int_t iRejDet; | |
610 | Int_t iRejEvt; | |
611 | ||
612 | collection->GetCollectionSummary(&iTotalEvents, &iAccEv, &iRejRun, &iRejLHC, &iRejDet, &iRejEvt); | |
613 | ||
614 | char nstr[2000]; | |
615 | ||
616 | sprintf(nstr, "TotalEvents=%i", iTotalEvents); | |
617 | TObjString *iTotStr = new TObjString(nstr); | |
618 | aUserInfo->Add(iTotStr); | |
619 | ||
620 | sprintf(nstr, "AcceptedEvents=%i", iAccepted); | |
621 | TObjString *iAccStr = new TObjString(nstr); | |
622 | aUserInfo->Add(iAccStr); | |
623 | ||
624 | sprintf(nstr, "RejectedRun=%i", iRejRun); | |
625 | TObjString *iRejRunStr = new TObjString(nstr); | |
626 | aUserInfo->Add(iRejRunStr); | |
627 | ||
628 | sprintf(nstr, "RejectedLHC=%i", iRejLHC); | |
629 | TObjString *iRejLHCStr = new TObjString(nstr); | |
630 | aUserInfo->Add(iRejLHCStr); | |
631 | ||
632 | sprintf(nstr, "RejectedDet=%i", iRejDet); | |
633 | TObjString *iRejDetStr = new TObjString(nstr); | |
634 | aUserInfo->Add(iRejDetStr); | |
635 | ||
636 | sprintf(nstr, "RejectedEvt=%i", iRejEvt); | |
637 | TObjString *iRejEvtStr = new TObjString(nstr); | |
638 | aUserInfo->Add(iRejEvtStr); | |
639 | ||
0bf3148c | 640 | return chain; |
d08133e6 | 641 | } |