]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/QA/tasks/macros/compare-HLT-offline-grid.C
Split: AddTaskPhysicsSelection+Centrality -> OADB
[u/mrichter/AliRoot.git] / HLT / QA / tasks / macros / compare-HLT-offline-grid.C
1 // $Id$
2 /*
3  * Example macro to run an HLT analysis task for comparing the offline
4  * with the HLT esd tree on the GRID.
5  *
6  * The output is a root file containing the histograms defined in the
7  * analysis task. There is one output file per detector.
8  *
9  * Usage:
10  * <pre>
11  *   aliroot -q compare-HLT-offline-grid.C'("000115322","/alice/data/2010/LHC10b","ESDcomparison","output","full","global")'
12  * </pre>
13  * - run number
14  * - GRID input directory, where you define in which LHC period the run number belongs to
15  * - GRID working directory, where the .xml, .jdl and the task are uploaded 
16  * - GRID output directory with respect to the working one, where the output files of the task are located 
17  * - run in full mode, i.e. completely on the GRID with all the chunks of the run processed
18  * - specify the analysis task you want to run
19  * - specify the path where the task is located, by default it takes $ALICE_ROOT/HLT/QA/tasks
20  * - specify the beam type
21  * - specify which THnSparse objects you want to have filled
22  * - specify whether you are interested only in HLT triggered events
23  * - specify how many events you want to analyze
24  *
25  * @ingroup alihlt_qa
26  * @author Hege.Erdal@student.uib.no, Kalliopi.Kanaki@ift.uib.no
27  */
28
29 void compare_HLT_offline_grid( TString runNumber
30                               ,TString dataDir
31                               ,TString gridWorkingDir
32                               ,TString gridOutputDir
33                               ,const char* mode = "full"
34                               ,const char* detectorTask="global"
35                               ,TString taskFolder="$ALICE_ROOT/HLT/QA/tasks/"
36                               ,TString beamType="p-p"
37                               ,TString options="event-off event-hlt track-off track-hlt"
38                               ,bool fUseHLTTrigger=kFALSE
39                               ,Long64_t nEvents=1234567890
40                              )
41 {
42  
43   TStopwatch timer;
44   timer.Start();
45
46   //gSystem->Load("libTree");
47   gSystem->Load("libCore");
48   gSystem->Load("libGeom");
49   gSystem->Load("libVMC");
50   gSystem->Load("libPhysics");
51  
52   //----------- Loading the required libraries ---------//
53
54   gSystem->Load("libSTEERBase");
55   gSystem->Load("libESD");
56   gSystem->Load("libAOD");
57   gSystem->Load("libANALYSIS");
58   gSystem->Load("libANALYSISalice");
59   gSystem->Load("libHLTbase");
60   gROOT->ProcessLine(".include $ALICE_ROOT/include"); 
61   gSystem->AddIncludePath("-I$ALICE_ROOT/HLT/BASE -I. -I$ALICE_ROOT/STEER -I$ALICE_ROOT/ANALYSIS");
62   //gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
63
64   
65   Bool_t bTPC=kFALSE, bPHOS=kFALSE, bEMCAL=kFALSE, bGLOBAL=kFALSE, bD0=kFALSE, bCB=kFALSE;
66  
67   TString allArgs = detectorTask;
68   TString argument;
69  
70   TObjArray *pTokens = allArgs.Tokenize(" ");
71   if(pTokens){
72      for(int i=0; i<pTokens->GetEntries(); i++){
73          argument=((TObjString*)pTokens->At(i))->GetString();
74          if(argument.IsNull()) continue;
75
76          if(argument.CompareTo("phos", TString::kIgnoreCase)==0){
77             bPHOS = kTRUE;
78             continue;
79          }
80          if(argument.CompareTo("emcal", TString::kIgnoreCase)==0){
81             bEMCAL = kTRUE;
82             continue;
83          }         
84          if(argument.CompareTo("global", TString::kIgnoreCase)==0){
85             bGLOBAL = kTRUE;
86             continue;
87          }  
88          if(argument.CompareTo("D0", TString::kIgnoreCase)==0){
89            bD0 = kTRUE;
90            continue;
91          }  
92          if(argument.CompareTo("cb", TString::kIgnoreCase)==0){
93            bCB = kTRUE;
94            continue;
95          }  
96          else break;
97     }
98   }
99     
100   //-------- Make the analysis manager ---------------//
101  
102   AliAnalysisManager *mgr  = new AliAnalysisManager("TestManager");
103   AliESDInputHandler *esdH = new AliESDInputHandler;
104   esdH->SetReadHLT();
105   esdH->SetReadFriends(kFALSE);
106   mgr->SetInputEventHandler(esdH);  
107   mgr->SetNSysInfo(1000);
108
109   //To use Physics Selection
110   //AliPhysicsSelectionTask *physSelTask = AddTaskPhysicsSelection(kFALSE,kTRUE);
111
112   // Create and configure the alien handler plugin
113   gROOT->LoadMacro("$ALICE_ROOT/HLT/QA/tasks/macros/CreateAlienHandler.C");
114   AliAnalysisGrid *alienHandler = CreateAlienHandler(runNumber, dataDir, gridWorkingDir, gridOutputDir, mode, detectorTask);
115   if (!alienHandler) return;
116   
117   // Connect plugin to the analysis manager
118   mgr->SetGridHandler(alienHandler);
119  
120   //-------------- Compile the analysis tasks ---------- //
121   if(bPHOS && bEMCAL) {
122     gSystem->Load("libHLTbase");
123     gSystem->Load("libAliHLTUtil");
124     gSystem->Load("libAliHLTGlobal");
125     TString strTask1("AliAnalysisTaskHLTCalo.cxx+");
126     TString strTask2("AliAnalysisTaskHLTPHOS.cxx+");    
127     TString strTask3("AliAnalysisTaskHLTEMCAL.cxx+");    
128     gROOT->LoadMacro(taskFolder+strTask1); 
129     gROOT->LoadMacro(taskFolder+strTask2);  
130     gROOT->LoadMacro(taskFolder+strTask3);      
131   }
132   else if(bPHOS) {
133     gSystem->Load("libHLTbase");
134     gSystem->Load("libAliHLTUtil");
135     gSystem->Load("libAliHLTGlobal");
136     TString strTask1("AliAnalysisTaskHLTCalo.cxx+");
137     TString strTask2("AliAnalysisTaskHLTPHOS.cxx+");    
138     gROOT->LoadMacro(taskFolder+strTask1); 
139     gROOT->LoadMacro(taskFolder+strTask2);  
140   }
141   else if(bEMCAL) {
142     gSystem->Load("libHLTbase");
143     gSystem->Load("libAliHLTUtil");
144     gSystem->Load("libAliHLTGlobal");
145     TString strTask1("AliAnalysisTaskHLTCalo.cxx+");
146     TString strTask2("AliAnalysisTaskHLTEMCAL.cxx+");    
147     gROOT->LoadMacro(taskFolder+strTask1); 
148     gROOT->LoadMacro(taskFolder+strTask2);  
149   }
150   if(bGLOBAL){
151      TString strTask("AliAnalysisTaskHLT.cxx+");   
152      gROOT->LoadMacro(taskFolder+strTask);
153   }
154   if(bD0){
155     TString strTask("AliAnalysisTaskD0Trigger.cxx+");
156     gROOT->LoadMacro(taskFolder+strTask);     
157   }
158   if(bCB){
159     TString strTask("AliAnalysisTaskHLTCentralBarrel.cxx+");
160     gROOT->LoadMacro(taskFolder+strTask);
161   } 
162  
163   //-------------- define the tasks ------------//
164   
165   if(bPHOS){
166      AliAnalysisTaskHLTPHOS *taskPHOS = new AliAnalysisTaskHLTPHOS("offhlt_comparison_PHOS");
167      mgr->AddTask(taskPHOS);
168      AliAnalysisDataContainer *coutputPHOS =  mgr->CreateContainer("phos_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-PHOS-comparison.root");  
169      mgr->ConnectInput(taskPHOS,0,mgr->GetCommonInputContainer());
170      mgr->ConnectOutput(taskPHOS,1,coutputPHOS);
171   }
172   if(bEMCAL){
173      AliAnalysisTaskHLTEMCAL *taskEMCAL = new AliAnalysisTaskHLTEMCAL("offhlt_comparison_EMCAL");
174      mgr->AddTask(taskEMCAL);
175      AliAnalysisDataContainer *coutputEMCAL =  mgr->CreateContainer("emcal_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-EMCAL-comparison.root");  
176      mgr->ConnectInput(taskEMCAL,0,mgr->GetCommonInputContainer());
177      mgr->ConnectOutput(taskEMCAL,1,coutputEMCAL);
178   }
179   
180   if(bGLOBAL){
181      AliAnalysisTaskHLT *taskGLOBAL = new AliAnalysisTaskHLT("offhlt_comparison_GLOBAL");
182      taskGLOBAL->SetUseHLTTriggerDecision(fUseHLTTrigger);
183      if(fUseHLTTrigger==kTRUE) printf("\n\nOnly HLT triggered events will be used to fill the distributions for task %s.\n\n", taskGLOBAL->GetName());
184      //taskGLOBAL->SelectCollisionCandidates();
185      mgr->AddTask(taskGLOBAL);
186      if(fUseHLTTrigger==kFALSE)
187        AliAnalysisDataContainer *coutputGLOBAL =  mgr->CreateContainer("global_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-GLOBAL-comparison.root");  
188      else
189        AliAnalysisDataContainer *coutputGLOBAL =  mgr->CreateContainer("global_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-GLOBAL-comparison_triggered.root");  
190      mgr->ConnectInput(taskGLOBAL,0,mgr->GetCommonInputContainer());
191      mgr->ConnectOutput(taskGLOBAL,1,coutputGLOBAL);
192   }
193   if(bD0){
194     float cuts[7]={0.5,0.04,0.7,0.8,0.05,-0.00025,0.7};
195     AliAnalysisTaskD0Trigger *taskD0 = new AliAnalysisTaskD0Trigger("offhlt_comparison_D0_Trigger",cuts);
196     mgr->AddTask(taskD0);
197     AliAnalysisDataContainer *coutputD0 =  mgr->CreateContainer("D0_histograms",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-D0-comparison.root");  
198     mgr->ConnectInput(taskD0,0,mgr->GetCommonInputContainer());
199     mgr->ConnectOutput(taskD0,1,coutputD0);
200   }
201   if(bCB){
202      AliAnalysisTaskHLTCentralBarrel *taskCB = new AliAnalysisTaskHLTCentralBarrel("offhlt_comparison_CB");
203      mgr->AddTask(taskCB);     
204      taskCB->SetBeamType(beamType);
205      if(beamType.Contains("Pb-Pb")){
206         gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
207         AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
208         taskCentrality->SetPass(1); 
209      }  
210      taskCB->SetOptions(options); 
211      AliAnalysisDataContainer *coutputCB =  mgr->CreateContainer("esd_thnsparse",TList::Class(), AliAnalysisManager::kOutputContainer, "HLT-OFFLINE-CentralBarrel-comparison.root");       
212      mgr->ConnectInput(taskCB,0,mgr->GetCommonInputContainer());
213      mgr->ConnectOutput(taskCB,1,coutputCB);
214   }
215   // Enable debug printouts
216   mgr->SetDebugLevel(2);
217
218   if (!mgr->InitAnalysis()) return;
219   mgr->PrintStatus();
220   mgr->StartAnalysis("grid", nEvents);
221
222   timer.Stop();
223   timer.Print();
224 }
225
226 void compare_HLT_offline_grid(){
227   cout << " " << endl;
228   cout << " Usage examples:" << endl;
229   cout << "    compare-HLT-offline-grid.C'(runNumber, dataDir, gridWorkingDir, gridOutputDir, mode, taskOption, taskFolder, beamType, THnSparse_names, fUseHLTTrigger)'" << endl;
230   cout << "    compare-HLT-offline-grid.C'(\"000115322\",\"/alice/data/2010/LHC10b\",\"ESDcomparison\",\"output\",\"full\",\"global\",\"./\",\"p-p\",\"event-off event-hlt track-off track-hlt\",kTRUE)'" << endl;
231   cout << " " << endl;
232 }