]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliTagAnalysis.cxx
Documentation and test macros for the FastJet interface.
[u/mrichter/AliRoot.git] / ANALYSIS / AliTagAnalysis.cxx
CommitLineData
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
23#include <TSystem.h>
24#include <TChain.h>
25#include <TFile.h>
26#include <TEventList.h>
27#include <TEntryList.h>
28#include <TTreeFormula.h>
29
30//ROOT-AliEn
31#include <TGridResult.h>
32
33#include "AliLog.h"
34
35#include "AliRunTag.h"
36#include "AliEventTag.h"
37#include "AliTagAnalysis.h"
38#include "AliEventTagCuts.h"
2ec6a1d3 39#include "AliDetectorTagCuts.h"
40#include "AliLHCTagCuts.h"
d08133e6 41#include "AliRunTagCuts.h"
42#include "AliXMLCollection.h"
43
44class TTree;
45
46ClassImp(AliTagAnalysis)
47
48//___________________________________________________________________________
49AliTagAnalysis::AliTagAnalysis():
50 TObject(),
51 ftagresult(0x0),
52 fTagDirName(),
6cfbb923 53 fChain(0x0),
54 fAnalysisType()
d08133e6 55{
56 //Default constructor for a AliTagAnalysis
57}
58
6cfbb923 59//___________________________________________________________________________
60AliTagAnalysis::AliTagAnalysis(const char* type):
61 TObject(),
62 ftagresult(0x0),
63 fTagDirName(),
64 fChain(0x0),
65 fAnalysisType(type)
66{
67 //constructor for a AliTagAnalysis
68}
69
d08133e6 70//___________________________________________________________________________
71AliTagAnalysis::~AliTagAnalysis() {
72//Default destructor for a AliTagAnalysis
73}
74
75//___________________________________________________________________________
76Bool_t AliTagAnalysis::AddTagsFile(const char *alienUrl) {
77
78 // Add a single tags file to the chain
79
80 Bool_t rv = kTRUE ;
81
82 if (! fChain) fChain = new TChain("T");
83
84 TFile *f = TFile::Open(alienUrl,"READ");
85 fChain->Add(alienUrl);
86 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
87 delete f;
88
89 if (fChain->GetEntries() == 0 )
90 rv = kFALSE ;
91
92 return rv ;
93}
94
95//___________________________________________________________________________
96void AliTagAnalysis::ChainLocalTags(const char *dirname) {
97 //Searches the entries of the provided direcory
98 //Chains the tags that are stored locally
99 fTagDirName = dirname;
100 TString fTagFilename;
101
102 if (! fChain) fChain = new TChain("T");
6cfbb923 103 const char * tagPattern = 0x0;
104 if(fAnalysisType == "ESD") tagPattern = "ESD.tag.root";
105 else if(fAnalysisType == "AOD") tagPattern = "AOD.tag.root";
106 else AliFatal("Only ESD and AOD type is implemented!!!");
107
d08133e6 108 // Open the working directory
109 void * dirp = gSystem->OpenDirectory(fTagDirName);
110 const char * name = 0x0;
111 // Add all files matching *pattern* to the chain
112 while((name = gSystem->GetDirEntry(dirp))) {
113 if (strstr(name,tagPattern)) {
114 fTagFilename = fTagDirName;
115 fTagFilename += "/";
116 fTagFilename += name;
117
118 fChain->Add(fTagFilename);
119 }//pattern check
120 }//directory loop
121 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
122}
123
124
125//___________________________________________________________________________
126void AliTagAnalysis::ChainGridTags(TGridResult *res) {
127 //Loops overs the entries of the TGridResult
128 //Chains the tags that are stored in the GRID
129 ftagresult = res;
130 Int_t nEntries = ftagresult->GetEntries();
131
132 if (! fChain) fChain = new TChain("T");
133
134 TString gridname = "alien://";
135 TString alienUrl;
136
137 for(Int_t i = 0; i < nEntries; i++) {
138 alienUrl = ftagresult->GetKey(i,"turl");
139 fChain->Add(alienUrl);
140 }//grid result loop
141}
142
143
144//___________________________________________________________________________
2ec6a1d3 145TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts, AliLHCTagCuts *lhcTagCuts, AliDetectorTagCuts *detTagCuts, AliEventTagCuts *evTagCuts) {
d08133e6 146 //Queries the tag chain using the defined
147 //event tag cuts from the AliEventTagCuts object
148 //and returns a TChain along with the associated TEventList
149 AliInfo(Form("Querying the tags........"));
b97856f9 150
6cfbb923 151 TString fAliceFile;
152 if(fAnalysisType == "ESD") fAliceFile = "esdTree";
153 else if(fAnalysisType == "AOD") fAliceFile = "aodTree";
154 else AliFatal("Only ESD and AOD type is implemented!!!");
b97856f9 155
d08133e6 156 //ESD file chain
b97856f9 157 TChain *fESDchain = new TChain(fAliceFile.Data());
158 //global entry list
159 TEntryList *fGlobalList = new TEntryList();
d08133e6 160
161 //Defining tag objects
5a561fa0 162 AliRunTag *tag = new AliRunTag;
163 AliEventTag *evTag = new AliEventTag;
d08133e6 164 fChain->SetBranchAddress("AliTAG",&tag);
165
166 TString guid = 0;
167 TString turl = 0;
168 TString path = 0;
169
170 Int_t iAccepted = 0;
171 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
172 fChain->GetEntry(iTagFiles);
2ec6a1d3 173 if(runTagCuts->IsAccepted(tag)) {
174 if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) {
175 if(detTagCuts->IsAccepted(tag->GetDetectorTags())) {
176 TEntryList *fLocalList = new TEntryList();
177 Int_t iEvents = tag->GetNEvents();
178 const TClonesArray *tagList = tag->GetEventTags();
179 for(Int_t i = 0; i < iEvents; i++) {
180 evTag = (AliEventTag *) tagList->At(i);
181 guid = evTag->GetGUID();
182 turl = evTag->GetTURL();
183 path = evTag->GetPath();
184 fLocalList->SetTreeName(fAliceFile.Data());
c51c9b0e 185 if(turl!="") fLocalList->SetFileName(turl.Data());
186 else fLocalList->SetFileName(path.Data());
2ec6a1d3 187 if(evTagCuts->IsAccepted(evTag)) fLocalList->Enter(i);
188 }//event loop
2ec6a1d3 189 if(path != "") fESDchain->AddFile(path);
190 else if(turl != "") fESDchain->AddFile(turl);
191 fGlobalList->Add(fLocalList);
192 iAccepted += fLocalList->GetN();
193 }//detector tag cuts
194 }//lhc tag cuts
d08133e6 195 }//run tags cut
5a561fa0 196 tag->Clear();
d08133e6 197 }//tag file loop
b97856f9 198 AliInfo(Form("Accepted events: %d",iAccepted));
199 fESDchain->SetEntryList(fGlobalList,"ne");
d08133e6 200
201 return fESDchain;
202}
203
204//___________________________________________________________________________
2ec6a1d3 205TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fLHCCut, const char *fDetectorCut, const char *fEventCut) {
d08133e6 206 //Queries the tag chain using the defined
207 //event tag cuts from the AliEventTagCuts object
208 //and returns a TChain along with the associated TEventList
209 AliInfo(Form("Querying the tags........"));
210
6cfbb923 211 TString fAliceFile;
212 if(fAnalysisType == "ESD") fAliceFile = "esdTree";
213 else if(fAnalysisType == "AOD") fAliceFile = "aodTree";
214 else AliFatal("Only ESD and AOD type is implemented!!!");
b97856f9 215
216 //ESD file chain
217 TChain *fESDchain = new TChain(fAliceFile.Data());
218 //global entry list
219 TEntryList *fGlobalList = new TEntryList();
d08133e6 220
221 //Defining tag objects
222 AliRunTag *tag = new AliRunTag;
223 AliEventTag *evTag = new AliEventTag;
224 fChain->SetBranchAddress("AliTAG",&tag);
225
226 TString guid = 0;
227 TString turl = 0;
228 TString path = 0;
229
230 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
2ec6a1d3 231 TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain);
232 TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain);
233 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
d08133e6 234
235 Int_t current = -1;
236 Int_t iAccepted = 0;
237 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
238 fChain->GetEntry(iTagFiles);
239 if (current != fChain->GetTreeNumber()) {
240 fRunFormula->UpdateFormulaLeaves();
2ec6a1d3 241 fLHCFormula->UpdateFormulaLeaves();
242 fDetectorFormula->UpdateFormulaLeaves();
d08133e6 243 fEventFormula->UpdateFormulaLeaves();
244 current = fChain->GetTreeNumber();
245 }
246 if(fRunFormula->EvalInstance(iTagFiles) == 1) {
2ec6a1d3 247 if(fLHCFormula->EvalInstance(iTagFiles) == 1) {
248 if(fDetectorFormula->EvalInstance(iTagFiles) == 1) {
249 TEntryList *fLocalList = new TEntryList();
250 Int_t iEvents = fEventFormula->GetNdata();
251 const TClonesArray *tagList = tag->GetEventTags();
252 for(Int_t i = 0; i < iEvents; i++) {
253 evTag = (AliEventTag *) tagList->At(i);
254 guid = evTag->GetGUID();
255 turl = evTag->GetTURL();
256 path = evTag->GetPath();
257 fLocalList->SetTreeName(fAliceFile.Data());
258 fLocalList->SetFileName(turl.Data());
259 if(fEventFormula->EvalInstance(i) == 1) fLocalList->Enter(i);
260 }//event loop
261 iAccepted += fLocalList->GetN();
262
263 if(path != "") fESDchain->AddFile(path);
264 else if(turl != "") fESDchain->AddFile(turl);
265 fGlobalList->Add(fLocalList);
266 iAccepted += fLocalList->GetN();
267 }//detector tag cuts
268 }//lhc tag cuts
d08133e6 269 }//run tag cut
270 }//tag file loop
b97856f9 271 AliInfo(Form("Accepted events: %d",iAccepted));
272 fESDchain->SetEntryList(fGlobalList,"ne");
d08133e6 273
274 return fESDchain;
275}
276
277//___________________________________________________________________________
2ec6a1d3 278Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *runTagCuts, AliLHCTagCuts *lhcTagCuts, AliDetectorTagCuts *detTagCuts, AliEventTagCuts *evTagCuts) {
d08133e6 279 //Queries the tag chain using the defined
280 //event tag cuts from the AliEventTagCuts object
281 //and returns a XML collection
282 AliInfo(Form("Creating the collection........"));
283
284 AliXMLCollection *collection = new AliXMLCollection();
285 collection->SetCollectionName(name);
286 collection->WriteHeader();
287
d08133e6 288 TString guid = 0x0;
289 TString turl = 0x0;
290 TString lfn = 0x0;
291
292 //Defining tag objects
293 AliRunTag *tag = new AliRunTag;
294 AliEventTag *evTag = new AliEventTag;
295 fChain->SetBranchAddress("AliTAG",&tag);
296
297 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
298 //Event list
299 TEntryList *fList = new TEntryList();
300 fChain->GetEntry(iTagFiles);
2ec6a1d3 301 if(runTagCuts->IsAccepted(tag)) {
302 if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) {
303 if(detTagCuts->IsAccepted(tag->GetDetectorTags())) {
304 Int_t iEvents = tag->GetNEvents();
305 const TClonesArray *tagList = tag->GetEventTags();
306 for(Int_t i = 0; i < iEvents; i++) {
307 evTag = (AliEventTag *) tagList->At(i);
308 guid = evTag->GetGUID();
309 turl = evTag->GetTURL();
310 lfn = turl(8,turl.Length());
311 if(evTagCuts->IsAccepted(evTag)) fList->Enter(i);
312 }//event loop
313 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
314 }//detector tag cuts
315 }//lhc tag cuts
d08133e6 316 }//run tag cuts
5a561fa0 317 tag->Clear();
d08133e6 318 }//tag file loop
319 collection->Export();
320
321 return kTRUE;
322}
323
324//___________________________________________________________________________
2ec6a1d3 325Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut, const char *fLHCCut, const char *fDetectorCut, const char *fEventCut) {
d08133e6 326 //Queries the tag chain using the defined
327 //event tag cuts from the AliEventTagCuts object
328 //and returns a XML collection
329 AliInfo(Form("Creating the collection........"));
330
331 AliXMLCollection *collection = new AliXMLCollection();
332 collection->SetCollectionName(name);
333 collection->WriteHeader();
334
335 TString guid = 0x0;
336 TString turl = 0x0;
337 TString lfn = 0x0;
338
339 //Defining tag objects
340 AliRunTag *tag = new AliRunTag;
341 AliEventTag *evTag = new AliEventTag;
342 fChain->SetBranchAddress("AliTAG",&tag);
343
344 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
2ec6a1d3 345 TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain);
346 TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain);
d08133e6 347 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
348
349 Int_t current = -1;
350 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
351 //Event list
352 TEntryList *fList = new TEntryList();
353 fChain->GetEntry(iTagFiles);
354 if (current != fChain->GetTreeNumber()) {
355 fRunFormula->UpdateFormulaLeaves();
2ec6a1d3 356 fLHCFormula->UpdateFormulaLeaves();
357 fDetectorFormula->UpdateFormulaLeaves();
d08133e6 358 fEventFormula->UpdateFormulaLeaves();
359 current = fChain->GetTreeNumber();
360 }
361 if(fRunFormula->EvalInstance(iTagFiles) == 1) {
2ec6a1d3 362 if(fLHCFormula->EvalInstance(iTagFiles) == 1) {
363 if(fDetectorFormula->EvalInstance(iTagFiles) == 1) {
364 Int_t iEvents = fEventFormula->GetNdata();
365 const TClonesArray *tagList = tag->GetEventTags();
366 for(Int_t i = 0; i < iEvents; i++) {
367 evTag = (AliEventTag *) tagList->At(i);
368 guid = evTag->GetGUID();
369 turl = evTag->GetTURL();
370 lfn = turl(8,turl.Length());
371 if(fEventFormula->EvalInstance(i) == 1) fList->Enter(i);
372 }//event loop
373 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
374 }//detector tag cuts
375 }//lhc tag cuts
d08133e6 376 }//run tag cuts
377 }//tag file loop
378 collection->Export();
379
380 return kTRUE;
381}
382
383//___________________________________________________________________________
384TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) {
385 //returns the chain+event list - used in batch sessions
386 // this function will be removed once the new root
387 // improvements are committed
388 TString fsystem = system;
389 Int_t iAccepted = 0;
6cfbb923 390
88fb0edc 391 TChain *fAnalysisChain = 0;
392 if(fAnalysisType == "ESD") fAnalysisChain = new TChain("esdTree");
393 else if(fAnalysisType == "AOD") fAnalysisChain = new TChain("aodTree");
6cfbb923 394 else AliFatal("Only ESD and AOD type is implemented!!!");
395
d08133e6 396 //Event list
397 TEventList *fEventList = new TEventList();
398 AliXMLCollection *collection = AliXMLCollection::Open(wn);
399
400 collection->Reset();
401 while (collection->Next()) {
402 AliInfo(Form("Adding: %s",collection->GetTURL("")));
6cfbb923 403 fAnalysisChain->Add(collection->GetTURL(""));
d08133e6 404 TEntryList *list = (TEntryList *)collection->GetEventList("");
405 for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i));
406
407 if(fsystem == "pp") iAccepted += 100;
408 else if(fsystem == "PbPb") iAccepted += 1;
409 }
410
6cfbb923 411 fAnalysisChain->SetEventList(fEventList);
d08133e6 412
413 AliInfo(Form("Number of selected events: %d",fEventList->GetN()));
414
6cfbb923 415 return fAnalysisChain;
d08133e6 416}
417
418//___________________________________________________________________________
419TChain *AliTagAnalysis::GetChainFromCollection(const char* collectionname, const char* treename) {
420 //returns the TChain+TEntryList object- used in batch sessions
421 TString fAliceFile = treename;
422 Int_t iAccepted = 0;
88fb0edc 423 TChain *fAnalysisChain = 0;
424 if(fAliceFile == "esdTree") fAnalysisChain = new TChain("esdTree");
425 else if(fAliceFile == "aodTree") fAnalysisChain = new TChain("aodTree");
d08133e6 426 else AliFatal("Inconsistent tree name - use esdTree or aodTree!");
6cfbb923 427
d08133e6 428 //Event list
429 TEntryList *fGlobalList = new TEntryList();
430 AliXMLCollection *collection = AliXMLCollection::Open(collectionname);
431
432 collection->Reset();
433 while (collection->Next()) {
434 AliInfo(Form("Adding: %s",collection->GetTURL("")));
435 fAnalysisChain->Add(collection->GetTURL(""));
436 TEntryList *list = (TEntryList *)collection->GetEventList("");
437 list->SetTreeName(fAliceFile.Data());
438 list->SetFileName(collection->GetTURL(""));
439 fGlobalList->Add(list);
440 iAccepted += list->GetN();
441 }
442
443 fAnalysisChain->SetEntryList(fGlobalList,"ne");
444
445 AliInfo(Form("Number of selected events: %d",iAccepted));
446
447 return fAnalysisChain;
448}