]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/QA/tasks/macros/compare-HLT-offline-local.C
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / HLT / QA / tasks / macros / compare-HLT-offline-local.C
1 // $Id$
2 /*
3  * Example macro to run locally an analysis task for comparing the offline
4  * with the HLT esd tree.
5  *
6  * The output is a root file containing the objects defined in the
7  * analysis task. These could be histograms or THnSparse objects.
8  * There is one output file per task containing a TList of TH1 or THnSparse objects. 
9  *
10  * Run without arguments to get a few examples how to use the macro
11  * and which tasks are available in svn.
12  * 
13  * The arguments are:
14  * - the input file or txt file containing a list of ESDs to be processed (CreateESDChain takes 20 files as a default argument)
15  * - the task you want to use
16  * - the path of the task location
17  * - the beam type, "p-p" or "Pb-Pb", this is relevant for the central barrel and global tasks at the moment and is 
18  *   used to select proper binning and axes ranges for the THnSparse/TH1 objects that it fills
19  * - options to make the central barrel task more flexible and lightweight; you can select if you want to 
20  *   fill the THnSparse object with only event or track properties or only HLT data or only OFF
21  *   possible options are: event-off event-hlt track-off track-hlt, all are turned on by default
22  * - boolean variable for selecting events which contain an HLT trigger
23  * - number of events to be analyzed
24  *
25  * If alien:// is placed before the input filename, then the macro connects to the grid to access the file.
26  * 
27  * In case you want to run over many ESD files, then prepare a list of them in a .txt file and they will be chained for the analysis.
28  * The .txt file takes the place of the first argument in that case. The chain can take up to 200 files at the moment. The user
29  * can modify this in the call CreateESDChain(file.Data(),200); 
30  *
31  * If the files are not sitting locally but on the GRID, then their location should be designated like:
32  * alien:///alice/data/2011/LHC11a/000146018/ESDs/pass1/11000146018023.20/AliESDs.root in the *txt file.
33  * The macro takes care of connecting to the GRID, as soon as the first file is found that begins with alien://
34  *
35  * @ingroup alihlt_qa
36  * @author Kalliopi.Kanaki@ift.uib.no, Hege.Erdal@student.uib.no
37  */
38
39 void compare_HLT_offline_local( TString file
40                                ,const char* detectorTask="global"
41                                ,TString taskFolder="$ALICE_ROOT/HLT/QA/tasks/"
42                                ,TString beamType="p-p"
43                                ,TString options="event-off event-hlt track-off track-hlt"
44                                ,bool fUseHLTTrigger=kFALSE
45                                ,Long64_t nEvents=1234567890
46                               )
47 {
48
49   TStopwatch timer;
50   timer.Start();
51
52   gSystem->Load("libTree");
53   gSystem->Load("libGeom");
54   gSystem->Load("libVMC");
55   gSystem->Load("libPhysics");
56  
57   //----------- Loading the required libraries ---------//
58
59   gSystem->Load("libSTEERBase");
60   gSystem->Load("libESD");
61   gSystem->Load("libAOD");
62   gSystem->Load("libANALYSIS");
63   gSystem->Load("libANALYSISalice");
64   gSystem->Load("libHLTbase");
65  
66   gSystem->AddIncludePath("-I$ALICE_ROOT/HLT/BASE -I$ALICE_ROOT/PWGPP/TPC -I. -I$ALICE_ROOT/STEER -I$ALICE_ROOT/ANALYSIS");
67   
68   gSystem->Load("libTPCcalib");
69   gSystem->Load("libTRDbase");
70   gSystem->Load("libTRDrec");
71   gSystem->Load("libITSbase");
72   gSystem->Load("libITSrec");
73   gSystem->Load("libTender");
74   gSystem->Load("libPWGPP");
75  
76   gROOT->ProcessLine(".include $ALICE_ROOT/include");
77   //gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
78     
79   Bool_t bPHOS = kFALSE, bGLOBAL = kFALSE, bEMCAL = kFALSE, bPWGPP = kFALSE, bD0 = kFALSE, bCB = kFALSE;
80  
81   TString allArgs = detectorTask;
82   TString argument;
83  
84   TObjArray *pTokens = allArgs.Tokenize(" ");
85   if(pTokens){
86     for(int i=0; i<pTokens->GetEntries(); i++){
87       argument=((TObjString*)pTokens->At(i))->GetString();
88       if(argument.IsNull()) continue;
89
90       if(argument.CompareTo("phos", TString::kIgnoreCase)==0){
91         bPHOS = kTRUE;
92         continue;
93       }         
94       else if(argument.CompareTo("emcal", TString::kIgnoreCase)==0){
95         bEMCAL = kTRUE;
96         continue;
97       }         
98       if(argument.CompareTo("global", TString::kIgnoreCase)==0){
99         bGLOBAL = kTRUE;
100         continue;
101       }      
102       if(argument.CompareTo("pwgpp", TString::kIgnoreCase)==0){
103         bPWGPP = kTRUE;
104         continue;
105       }
106       if(argument.CompareTo("D0", TString::kIgnoreCase)==0){
107         bD0 = kTRUE;
108         continue;
109       }
110       if(argument.CompareTo("cb", TString::kIgnoreCase)==0){
111         bCB = kTRUE;
112         continue;
113       } 
114       else break;
115     }
116   }
117       
118   //-------------- Compile the analysis tasks ---------- //
119   
120   if(bPHOS){
121     //gSystem->Load("libHLTbase");
122     gSystem->Load("libAliHLTUtil");
123     gSystem->Load("libAliHLTGlobal");
124     TString strTask1("AliAnalysisTaskHLTCalo.cxx+");
125     TString strTask2("AliAnalysisTaskHLTPHOS.cxx+");    
126     gROOT->LoadMacro(taskFolder+strTask1); 
127     gROOT->LoadMacro(taskFolder+strTask2); 
128     cout << "\n========= You are loading the following tasks --> "<< (taskFolder+strTask1).Chop()  << " and " <<  (taskFolder+strTask2).Chop() << endl;
129   }
130   
131   if(bEMCAL){
132     //gSystem->Load("libHLTbase");
133     gSystem->Load("libAliHLTUtil");
134     gSystem->Load("libAliHLTGlobal");
135     TString strTask1("AliAnalysisTaskHLTCalo.cxx+");
136     TString strTask2("AliAnalysisTaskHLTEMCAL.cxx+");
137     gROOT->LoadMacro(taskFolder+strTask1); 
138     gROOT->LoadMacro(taskFolder+strTask2); 
139     cout << "\n========= You are loading the following tasks --> "<< (taskFolder+strTask1).Chop()  << " and " <<  (taskFolder+strTask2).Chop() << endl;
140   }  
141   
142   if(bGLOBAL){
143      TString strTask("AliAnalysisTaskHLT.cxx+");
144      gROOT->LoadMacro(taskFolder+strTask);
145      cout << "\n========= You are loading the following task --> "<< (taskFolder+strTask).Chop()  << endl;
146   }
147   if(bD0){
148      TString strTask("AliAnalysisTaskD0Trigger.cxx+");
149      gROOT->LoadMacro(taskFolder+strTask); 
150      cout << "\n========= You are loading the following task --> "<< (taskFolder+strTask).Chop()  << endl;
151   }
152  
153   if(bCB){
154     TString strTask("AliAnalysisTaskHLTCentralBarrel.cxx+");
155     gROOT->LoadMacro(taskFolder+strTask);
156     cout << "\n========= You are loading the following task --> "<< (taskFolder+strTask).Chop()  << endl;
157   }
158   
159   if(bPWGPP) gROOT->LoadMacro("$ALICE_ROOT/HLT/QA/tasks/macros/AddTaskPerformance.C");
160    
161   if(file.BeginsWith("alien://")) TGrid::Connect("alien://");
162     
163   if(file.Contains("AliESDs.root")){
164     TChain *chain = new TChain("esdTree"); 
165     chain->Add(file);
166   }
167   
168   // Constructs chain from filenames in *.txt
169   // in the form $DIR/AliESDs.root  
170   else if(file.Contains(".txt")){
171     gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
172     chain = CreateESDChain(file.Data(),200); 
173     // chain can contain up to 200 files, value can be modified to 
174     // include a subset of what the *txt file contains
175     
176     TObjArray *fileElements = chain->GetListOfFiles();
177     TIter next(fileElements);
178     TChainElement *chEl = 0;
179     bool alienList = kFALSE;
180     while(( chEl = (TChainElement*)next() )){
181     // loop over the list of files in the *txt and as soon as one is found that starts with alien://, 
182     // the boolean alienList turns to kTRUE, which allows the TGrid::Connect call outside the loop.
183             TString tmp = chEl->GetTitle();         
184             if(tmp.BeginsWith("alien://")) alienList = kTRUE;           
185     }
186     if(alienList==kTRUE) TGrid::Connect("alien://");
187   }
188   
189   else if(!file){
190     printf("File %s does not exist or is corrupted.\n",file.Data());
191     return;  
192   }
193
194   if(!chain){
195     Printf("Chain is empty.\n");
196     return;
197   }
198    
199   //-------- Make the analysis manager ---------------//
200  
201   AliAnalysisManager *mgr  = new AliAnalysisManager("TestManager");
202   AliESDInputHandler *esdH = new AliESDInputHandler;
203
204   //For the PWGPP task, setting HLT is handled inside AliPerformanceTask.C
205   if(!bPWGPP)  esdH->SetReadHLT();
206   esdH->SetReadFriends(kFALSE);
207   mgr->SetInputEventHandler(esdH);  
208   mgr->SetNSysInfo(1000);
209
210   //AliPhysicsSelectionTask *physSelTask = AddTaskPhysicsSelection(kFALSE,kTRUE);
211  
212   //-------------- define the tasks ------------//
213   
214   if(bPHOS){
215     AliAnalysisTaskHLTPHOS *taskPHOS = new AliAnalysisTaskHLTPHOS("offhlt_comparison_PHOS");
216     taskPHOS->SetUseHLTTriggerDecision(fUseHLTTrigger);
217     if(fUseHLTTrigger==kTRUE) printf("\n\nOnly HLT triggered events will be used to fill the distributions for task %s.\n\n", taskPHOS->GetName());
218     mgr->AddTask(taskPHOS);
219     if(fUseHLTTrigger==kFALSE)
220        AliAnalysisDataContainer *coutputPHOS =  mgr->CreateContainer("phos_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-PHOS-comparison.root");  
221     else 
222        AliAnalysisDataContainer *coutputPHOS =  mgr->CreateContainer("phos_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-PHOS-comparison_triggered.root");      
223     mgr->ConnectInput(taskPHOS,0,mgr->GetCommonInputContainer());
224     mgr->ConnectOutput(taskPHOS,1,coutputPHOS);
225   }
226
227   if(bEMCAL){
228     AliAnalysisTaskHLTEMCAL *taskEMCAL = new AliAnalysisTaskHLTEMCAL("offhlt_comparison_EMCAL");
229     taskEMCAL->SetUseHLTTriggerDecision(fUseHLTTrigger);
230     if(fUseHLTTrigger==kTRUE) printf("\n\nOnly HLT triggered events will be used to fill the distributions for task %s.\n\n", taskEMCAL->GetName());
231     mgr->AddTask(taskEMCAL);
232     if(fUseHLTTrigger==kFALSE)
233        AliAnalysisDataContainer *coutputEMCAL =  mgr->CreateContainer("emcal_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-EMCAL-comparison.root");  
234     else
235       AliAnalysisDataContainer *coutputEMCAL =  mgr->CreateContainer("emcal_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-EMCAL-comparison_triggered.root");      
236     mgr->ConnectInput(taskEMCAL,0,mgr->GetCommonInputContainer());
237     mgr->ConnectOutput(taskEMCAL,1,coutputEMCAL);
238   }
239   
240   if(bGLOBAL){
241     AliAnalysisTaskHLT *taskGLOBAL = new AliAnalysisTaskHLT("offhlt_comparison_GLOBAL",0.9,0.3,7,7,20); // eta, pt, DCAr, DCAz, vertexZ
242     taskGLOBAL->SetUseHLTTriggerDecision(fUseHLTTrigger);
243     taskGLOBAL->SetBeamType(beamType);
244     mgr->AddTask(taskGLOBAL);
245     if(beamType.Contains("Pb")){
246        gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
247        AliCentralitySelectionTask *taskCentrality = AddTaskCentrality(); 
248        taskCentrality->SetPass(1);
249     }        
250     if(fUseHLTTrigger==kTRUE) printf("\n\nOnly HLT triggered events will be used to fill the distributions for task %s.\n\n", taskGLOBAL->GetName());
251     //taskGLOBAL->SelectCollisionCandidates();
252     if(fUseHLTTrigger==kFALSE)
253       AliAnalysisDataContainer *coutputGLOBAL =  mgr->CreateContainer("global_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-GLOBAL-comparison.root");  
254     else 
255       AliAnalysisDataContainer *coutputGLOBAL =  mgr->CreateContainer("global_histograms",TList::Class(), AliAnalysisManager::kOutputContainer,"HLT-OFFLINE-GLOBAL-comparison_triggered.root");  
256     mgr->ConnectInput(taskGLOBAL,0,mgr->GetCommonInputContainer());
257     mgr->ConnectOutput(taskGLOBAL,1,coutputGLOBAL);
258   }
259
260   if(bPWGPP){
261     Bool_t hasMC=kFALSE;  
262     // -- Add Task for HLT and Offline
263     AliPerformanceTask *HLTtpcQA = AddTaskPerformance(hasMC,kFALSE,kTRUE);
264     AliPerformanceTask *tpcQA = AddTaskPerformance(hasMC,kFALSE); 
265     if(!HLTtpcQA || !tpcQA) {
266       Error("RunPerformanceTrain","AliPerformanceTask not created!");
267       return;
268     }
269   }
270   if(bD0){
271     float cuts[7]={0.5,0.04,0.7,0.8,0.05,-0.00025,0.7};
272     AliAnalysisTaskD0Trigger *taskD0 = new AliAnalysisTaskD0Trigger("offhlt_comparison_D0",cuts);
273     mgr->AddTask(taskD0);
274     AliAnalysisDataContainer *coutputD0 =  mgr->CreateContainer("D0_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-D0-comparison.root");  
275     mgr->ConnectInput(taskD0,0,mgr->GetCommonInputContainer());
276     mgr->ConnectOutput(taskD0,1,coutputD0);
277   }  
278   
279   if(bCB){
280      AliAnalysisTaskHLTCentralBarrel *taskCB = new AliAnalysisTaskHLTCentralBarrel("offhlt_comparison_CB"); 
281      mgr->AddTask(taskCB); 
282      taskCB->SetBeamType(beamType);
283      if(beamType.Contains("Pb")){
284         gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
285         AliCentralitySelectionTask *taskCentrality = AddTaskCentrality(); 
286         taskCentrality->SetPass(1);
287      }        
288      taskCB->SetOptions(options);
289      AliAnalysisDataContainer *coutputCB =  mgr->CreateContainer("esd_thnsparse", TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-CentralBarrel-comparison.root");  
290      mgr->ConnectInput(taskCB,0,mgr->GetCommonInputContainer());
291      mgr->ConnectOutput(taskCB,1,coutputCB);
292   }
293   
294   if (!mgr->InitAnalysis()) return;
295   mgr->PrintStatus();
296   mgr->StartAnalysis("local",chain, nEvents);
297
298   timer.Stop();
299   timer.Print();
300 }
301
302 void compare_HLT_offline_local(){
303   cout << "\n The following tasks and respective plotting macros are available and maintained in $ALICE_ROOT/HLT/QA/tasks/ :\n"<< endl;
304   cout << " AliAnalysisTaskHLTCentralBarrel (macros/drawTHnSparse.C)\n AliAnalysisTaskHLT.cxx (macros/drawGlobalESDHistograms.C)" << endl;
305   cout << " AliAnalysisTaskHLTCalo (EMCAL+PHOS) (macros/drawCaloHistograms.C) \n AliAnalysisTaskD0Trigger (no plotting macro committed)\n" << endl;
306   
307   cout << " Usage examples:" << endl;
308   cout << "    compare-HLT-offline-local.C'(file, taskOption, taskFolder, beamType, options, fUseHLTTrigger, nEvents)' 2>&1 | tee log" << endl;
309   cout << "    compare-HLT-offline-local.C'(\"AliESDs.root\",\"global\")' 2>&1 | tee log" << endl;
310   cout << "    compare-HLT-offline-local.C'(\"AliESDs.root\",\"global\",\"./\", \"p-p\", \"event-off event-hlt track-off track-hlt\", kFALSE, nEvents)' 2>&1 | tee log" << endl;
311   cout << "    compare-HLT-offline-local.C'(\"AliESDs.root\",\"global phos cb D0\", \"./\", \"Pb-Pb\", \"event-hlt\", kTRUE, nEvents)' 2>&1 | tee log" << endl;
312   cout << "    compare-HLT-offline-local.C'(\"alien:///alice/data/2010/LHC10b/000115322/ESDs/pass1/10000115322040.20/AliESDs.root\",\"global\")' 2>&1 | tee log" << endl;
313   cout << " " << endl;
314 }