Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / QA / tasks / macros / compare-HLT-offline-local.C
CommitLineData
be1fa04a 1// $Id$
2/*
3 * Example macro to run locally an analysis task for comparing the offline
4 * with the HLT esd tree.
5 *
ecccac06 6 * The output is a root file containing the objects defined in the
7 * analysis task. These could be histograms or THnSparse objects.
b4a7280c 8 * There is one output file per task containing a TList of TH1 or THnSparse objects.
be1fa04a 9 *
ecccac06 10 * Run without arguments to get a few examples how to use the macro
11 * and which tasks are available in svn.
b3406717 12 *
20e8390f 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
b2642c4c 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
20e8390f 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.
1e81c36d 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.
b4a7280c 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://
7742dbd5 34 *
b71630ca 35 * @ingroup alihlt_qa
4b621d9c 36 * @author Kalliopi.Kanaki@ift.uib.no, Hege.Erdal@student.uib.no
be1fa04a 37 */
38
20e8390f 39void 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
4b621d9c 46 )
47{
fc0eba5b 48
be1fa04a 49 TStopwatch timer;
50 timer.Start();
51
230b7aff 52 gSystem->Load("libTree");
53 gSystem->Load("libGeom");
54 gSystem->Load("libVMC");
55 gSystem->Load("libPhysics");
be1fa04a 56
57 //----------- Loading the required libraries ---------//
58
230b7aff 59 gSystem->Load("libSTEERBase");
60 gSystem->Load("libESD");
61 gSystem->Load("libAOD");
62 gSystem->Load("libANALYSIS");
63 gSystem->Load("libANALYSISalice");
64 gSystem->Load("libHLTbase");
fc0eba5b 65
2bfe5463 66 gSystem->AddIncludePath("-I$ALICE_ROOT/HLT/BASE -I$ALICE_ROOT/PWGPP/TPC -I. -I$ALICE_ROOT/STEER -I$ALICE_ROOT/ANALYSIS");
da6744ee 67
230b7aff 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");
da6744ee 75
be1fa04a 76 gROOT->ProcessLine(".include $ALICE_ROOT/include");
63b6cbd0 77 //gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskPhysicsSelection.C");
0e76c8bc 78
2bfe5463 79 Bool_t bPHOS = kFALSE, bGLOBAL = kFALSE, bEMCAL = kFALSE, bPWGPP = kFALSE, bD0 = kFALSE, bCB = kFALSE;
7742dbd5 80
81 TString allArgs = detectorTask;
82 TString argument;
83
84 TObjArray *pTokens = allArgs.Tokenize(" ");
85 if(pTokens){
da6744ee 86 for(int i=0; i<pTokens->GetEntries(); i++){
87 argument=((TObjString*)pTokens->At(i))->GetString();
88 if(argument.IsNull()) continue;
be1fa04a 89
da6744ee 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 }
da6744ee 98 if(argument.CompareTo("global", TString::kIgnoreCase)==0){
99 bGLOBAL = kTRUE;
100 continue;
101 }
2bfe5463 102 if(argument.CompareTo("pwgpp", TString::kIgnoreCase)==0){
103 bPWGPP = kTRUE;
da6744ee 104 continue;
105 }
cd785861 106 if(argument.CompareTo("D0", TString::kIgnoreCase)==0){
107 bD0 = kTRUE;
108 continue;
109 }
ff84363f 110 if(argument.CompareTo("cb", TString::kIgnoreCase)==0){
111 bCB = kTRUE;
112 continue;
113 }
da6744ee 114 else break;
7742dbd5 115 }
116 }
ea46fe48 117
7742dbd5 118 //-------------- Compile the analysis tasks ---------- //
fc0eba5b 119
ea46fe48 120 if(bPHOS){
7e9b72dc 121 //gSystem->Load("libHLTbase");
ea46fe48 122 gSystem->Load("libAliHLTUtil");
123 gSystem->Load("libAliHLTGlobal");
7e9b72dc 124 TString strTask1("AliAnalysisTaskHLTCalo.cxx+");
125 TString strTask2("AliAnalysisTaskHLTPHOS.cxx+");
4b621d9c 126 gROOT->LoadMacro(taskFolder+strTask1);
127 gROOT->LoadMacro(taskFolder+strTask2);
394b9d00 128 cout << "\n========= You are loading the following tasks --> "<< (taskFolder+strTask1).Chop() << " and " << (taskFolder+strTask2).Chop() << endl;
fc0eba5b 129 }
130
ea46fe48 131 if(bEMCAL){
7e9b72dc 132 //gSystem->Load("libHLTbase");
ea46fe48 133 gSystem->Load("libAliHLTUtil");
134 gSystem->Load("libAliHLTGlobal");
7e9b72dc 135 TString strTask1("AliAnalysisTaskHLTCalo.cxx+");
136 TString strTask2("AliAnalysisTaskHLTEMCAL.cxx+");
4b621d9c 137 gROOT->LoadMacro(taskFolder+strTask1);
138 gROOT->LoadMacro(taskFolder+strTask2);
394b9d00 139 cout << "\n========= You are loading the following tasks --> "<< (taskFolder+strTask1).Chop() << " and " << (taskFolder+strTask2).Chop() << endl;
fc0eba5b 140 }
141
4b621d9c 142 if(bGLOBAL){
143 TString strTask("AliAnalysisTaskHLT.cxx+");
144 gROOT->LoadMacro(taskFolder+strTask);
394b9d00 145 cout << "\n========= You are loading the following task --> "<< (taskFolder+strTask).Chop() << endl;
4b621d9c 146 }
147 if(bD0){
148 TString strTask("AliAnalysisTaskD0Trigger.cxx+");
149 gROOT->LoadMacro(taskFolder+strTask);
394b9d00 150 cout << "\n========= You are loading the following task --> "<< (taskFolder+strTask).Chop() << endl;
4b621d9c 151 }
ff84363f 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 }
4b621d9c 158
2bfe5463 159 if(bPWGPP) gROOT->LoadMacro("$ALICE_ROOT/HLT/QA/tasks/macros/AddTaskPerformance.C");
ea46fe48 160
b4a7280c 161 if(file.BeginsWith("alien://")) TGrid::Connect("alien://");
1e81c36d 162
163 if(file.Contains("AliESDs.root")){
164 TChain *chain = new TChain("esdTree");
165 chain->Add(file);
166 }
167
b4a7280c 168 // Constructs chain from filenames in *.txt
169 // in the form $DIR/AliESDs.root
1e81c36d 170 else if(file.Contains(".txt")){
171 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
b4a7280c 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://");
1e81c36d 187 }
3d9c49a9 188
d8cdf034 189 else if(!file){
3d9c49a9 190 printf("File %s does not exist or is corrupted.\n",file.Data());
191 return;
192 }
1e81c36d 193
194 if(!chain){
20e8390f 195 Printf("Chain is empty.\n");
1e81c36d 196 return;
197 }
d4598f43 198
be1fa04a 199 //-------- Make the analysis manager ---------------//
200
201 AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
202 AliESDInputHandler *esdH = new AliESDInputHandler;
ea46fe48 203
2bfe5463 204 //For the PWGPP task, setting HLT is handled inside AliPerformanceTask.C
205 if(!bPWGPP) esdH->SetReadHLT();
fcf71d87 206 esdH->SetReadFriends(kFALSE);
be1fa04a 207 mgr->SetInputEventHandler(esdH);
208 mgr->SetNSysInfo(1000);
da6744ee 209
ea46fe48 210 //AliPhysicsSelectionTask *physSelTask = AddTaskPhysicsSelection(kFALSE,kTRUE);
be1fa04a 211
212 //-------------- define the tasks ------------//
213
7742dbd5 214 if(bPHOS){
da6744ee 215 AliAnalysisTaskHLTPHOS *taskPHOS = new AliAnalysisTaskHLTPHOS("offhlt_comparison_PHOS");
7e9b72dc 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());
da6744ee 218 mgr->AddTask(taskPHOS);
7e9b72dc 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");
da6744ee 223 mgr->ConnectInput(taskPHOS,0,mgr->GetCommonInputContainer());
4b621d9c 224 mgr->ConnectOutput(taskPHOS,1,coutputPHOS);
7742dbd5 225 }
fc0eba5b 226
227 if(bEMCAL){
da6744ee 228 AliAnalysisTaskHLTEMCAL *taskEMCAL = new AliAnalysisTaskHLTEMCAL("offhlt_comparison_EMCAL");
7e9b72dc 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());
da6744ee 231 mgr->AddTask(taskEMCAL);
7e9b72dc 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");
da6744ee 236 mgr->ConnectInput(taskEMCAL,0,mgr->GetCommonInputContainer());
4b621d9c 237 mgr->ConnectOutput(taskEMCAL,1,coutputEMCAL);
fc0eba5b 238 }
a63c69d8 239
db575e59 240 if(bGLOBAL){
971bbba6 241 AliAnalysisTaskHLT *taskGLOBAL = new AliAnalysisTaskHLT("offhlt_comparison_GLOBAL",0.9,0.3,7,7,20); // eta, pt, DCAr, DCAz, vertexZ
4b621d9c 242 taskGLOBAL->SetUseHLTTriggerDecision(fUseHLTTrigger);
daa64b60 243 taskGLOBAL->SetBeamType(beamType);
b2642c4c 244 mgr->AddTask(taskGLOBAL);
245 if(beamType.Contains("Pb")){
1c06a186 246 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskCentrality.C");
b2642c4c 247 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
248 taskCentrality->SetPass(1);
249 }
4b621d9c 250 if(fUseHLTTrigger==kTRUE) printf("\n\nOnly HLT triggered events will be used to fill the distributions for task %s.\n\n", taskGLOBAL->GetName());
ea46fe48 251 //taskGLOBAL->SelectCollisionCandidates();
4b621d9c 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");
da6744ee 256 mgr->ConnectInput(taskGLOBAL,0,mgr->GetCommonInputContainer());
4b621d9c 257 mgr->ConnectOutput(taskGLOBAL,1,coutputGLOBAL);
db575e59 258 }
da6744ee 259
2bfe5463 260 if(bPWGPP){
da6744ee 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 }
cd785861 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);
4b621d9c 274 AliAnalysisDataContainer *coutputD0 = mgr->CreateContainer("D0_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-D0-comparison.root");
cd785861 275 mgr->ConnectInput(taskD0,0,mgr->GetCommonInputContainer());
4b621d9c 276 mgr->ConnectOutput(taskD0,1,coutputD0);
ff84363f 277 }
278
279 if(bCB){
0e76c8bc 280 AliAnalysisTaskHLTCentralBarrel *taskCB = new AliAnalysisTaskHLTCentralBarrel("offhlt_comparison_CB");
281 mgr->AddTask(taskCB);
282 taskCB->SetBeamType(beamType);
b2642c4c 283 if(beamType.Contains("Pb")){
1c06a186 284 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskCentrality.C");
0e76c8bc 285 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
bda8eaf3 286 taskCentrality->SetPass(1);
20e8390f 287 }
288 taskCB->SetOptions(options);
ff84363f 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);
cd785861 292 }
89ad7eb5 293
be1fa04a 294 if (!mgr->InitAnalysis()) return;
295 mgr->PrintStatus();
ea46fe48 296 mgr->StartAnalysis("local",chain, nEvents);
be1fa04a 297
298 timer.Stop();
299 timer.Print();
300}
4b621d9c 301
302void compare_HLT_offline_local(){
b4a7280c 303 cout << "\n The following tasks and respective plotting macros are available and maintained in $ALICE_ROOT/HLT/QA/tasks/ :\n"<< endl;
ecccac06 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
4b621d9c 307 cout << " Usage examples:" << endl;
879e7143 308 cout << " compare-HLT-offline-local.C'(file, taskOption, taskFolder, beamType, options, fUseHLTTrigger, nEvents)' 2>&1 | tee log" << endl;
4b621d9c 309 cout << " compare-HLT-offline-local.C'(\"AliESDs.root\",\"global\")' 2>&1 | tee log" << endl;
879e7143 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;
4b621d9c 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}