TENDER becomes Tender
[u/mrichter/AliRoot.git] / PWGPP / TPC / macros / AddTaskPerformanceTPCPbPb.C
1 ///////////////////////////////////////////////////////////////////////////////
2 // Macro to setup AliPerformanceTask for 
3 // TPC performance QA to run on PWGPP QA train. 
4 //
5 // Input: ESDs, ESDfriends (optional), Kinematics (optional), TrackRefs (optional)
6 // ESD and MC input handlers must be attached to AliAnalysisManager
7 // to run default configuration. 
8 //
9 // By default 1 performance components are added to 
10 // the task: 
11 // 1. AliPerformanceTPC (TPC cluster and track and event information)
12 // 2. AliPerformancedEdx (TPC dEdx information)
13 //
14 // Usage on the analysis train (default configuration):
15 // gSystem->Load("libANALYSIS");
16 // gSystem->Load("libANALYSISalice");
17 // gSystem->Load("libTPCcalib.so");
18 // gSystem->Load("libTender.so");
19 // gSystem->Load("libPWGPP.so");
20 //
21 // gROOT->LoadMacro("$ALICE_ROOT/PWGPP/TPC/macros/AddTaskPerformanceTPCPbPb.C");
22 // AliPerformanceTask *tpcQA = AddTaskPerformanceTPCPbPb("kFALSE","kTRUE","triggerClass"); 
23 // 
24 // Output:
25 // TPC.Performance.root file with TPC performance components is created.
26 //
27 // Each of the components contains THnSparse generic histograms which 
28 // have to be analysed (post-analysis) by using Analyse() function. 
29 // Each component contains such function.
30 //
31 //30.09.2010 -  J.Otwinowski@gsi.de
32 ///////////////////////////////////////////////////////////////////////////////
33
34 //____________________________________________
35 AliPerformanceTask* AddTaskPerformanceTPCPbPb(Bool_t bUseMCInfo=kFALSE, Bool_t bUseESDfriend=kTRUE, const char *triggerClass=0)
36 {
37   //
38   // Add AliPerformanceTask with TPC performance components
39   //
40   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
41   if(!mgr) { 
42     Error("AddTaskPerformanceTPCPbPb","AliAnalysisManager not set!");
43     return NULL;
44   }
45   
46   TString type = mgr->GetInputEventHandler()->GetDataType();
47   if (!type.Contains("ESD")) {
48     Error("AddTaskPerformanceTPCPbPb", "ESD input handler needed!");
49     return NULL;
50   }
51   
52   AliMCEventHandler *mcH = (AliMCEventHandler*)mgr->GetMCtruthEventHandler();
53   if (!mcH && bUseMCInfo) {
54     Error("AddTaskPerformanceTPCPbPb", "MC input handler needed!");
55     return NULL;
56   }
57
58   //
59   // Create task
60   //
61   AliPerformanceTask *task = new AliPerformanceTask("PerformanceQA","TPC Performance");
62   if (!task) {
63     Error("AddTaskPerformanceTPCPbPb", "TPC performance task cannot be created!");
64     return NULL;
65   }
66   task->SetUseMCInfo(bUseMCInfo);
67   task->SetUseESDfriend(bUseESDfriend);
68
69   task->SetUseTerminate(kFALSE);
70
71   task->SetUseCentrality(1); // 0=off,1=Vzero,2=SPD
72   Int_t cent0 = 0;
73   Int_t cent1 = 20;
74   Int_t cent2 = 40;
75
76   //
77   // Add task to analysis manager
78   //
79   mgr->AddTask(task);
80
81   //
82   // Create TPC-ESD track reconstruction cuts
83   // MB tracks
84   //
85   AliRecInfoCuts *pRecInfoCutsTPC = new AliRecInfoCuts(); 
86   if(pRecInfoCutsTPC) {
87     pRecInfoCutsTPC->SetMaxDCAToVertexXY(3.0);
88     pRecInfoCutsTPC->SetMaxDCAToVertexZ(3.0);
89     pRecInfoCutsTPC->SetRequireSigmaToVertex(kFALSE);
90     pRecInfoCutsTPC->SetRequireTPCRefit(kFALSE);
91     pRecInfoCutsTPC->SetAcceptKinkDaughters(kTRUE);
92     pRecInfoCutsTPC->SetMinNClustersTPC(70);
93     pRecInfoCutsTPC->SetMaxChi2PerClusterTPC(1000000.);
94     pRecInfoCutsTPC->SetDCAToVertex2D(kFALSE);
95
96     pRecInfoCutsTPC->SetHistogramsOn(kFALSE); 
97   } 
98   else {
99     Error("AddTaskPerformanceTPC", "AliRecInfoCutsTPC cannot be created!");
100     return NULL;
101   }
102
103   //
104   // Create TPC-MC track reconstruction cuts
105   //
106   AliMCInfoCuts  *pMCInfoCuts = new AliMCInfoCuts();
107   if(pMCInfoCuts) {
108     pMCInfoCuts->SetMinTrackLength(70);
109   } 
110   else {
111     Error("AddTaskPerformanceTPC", "AliMCInfoCuts cannot be created!");
112     return NULL;
113   }
114
115   //
116   // Create performance objects for TPC and set cuts 
117   //
118   enum { kTPC = 0, kTPCITS, kConstrained, kTPCInner, kTPCOuter, kTPCSec };
119
120   //
121   // TPC performance  ------------------------------------------------------------------------------------
122   //
123   
124   AliPerformanceTPC *pCompTPC0 = NULL;
125   AliPerformanceTPC *pCompTPCc0 = NULL;
126   AliPerformanceTPC *pCompTPCc1 = NULL;
127   AliPerformanceTPC *pCompTPCc2 = NULL;
128
129   if( !task->GetUseCentrality() ) {
130     
131     pCompTPC0 = new AliPerformanceTPC("AliPerformanceTPC","AliPerformanceTPC",kTPC,kFALSE); 
132     if(!pCompTPC0) {
133       Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceTPC");
134     }
135     pCompTPC0->SetAliRecInfoCuts(pRecInfoCutsTPC);
136     pCompTPC0->SetAliMCInfoCuts(pMCInfoCuts);
137     pCompTPC0->SetUseTrackVertex(kFALSE);
138     pCompTPC0->SetUseHLT(kFALSE);
139   }
140   else {
141     pCompTPCc0 = new AliPerformanceTPC("AliPerformanceTPC",Form("AliPerformanceTPC_cent_%d",cent0),kTPC,kFALSE); 
142     if(!pCompTPCc0) {
143       Error(Form("AddTaskPerformanceTPC_cent_%d",cent0), "Cannot create AliPerformanceTPC");
144     }
145     pCompTPCc0->SetAliRecInfoCuts(pRecInfoCutsTPC);
146     pCompTPCc0->SetAliMCInfoCuts(pMCInfoCuts);
147     pCompTPCc0->SetUseTrackVertex(kFALSE);
148     pCompTPCc0->SetUseHLT(kFALSE);
149     pCompTPCc0->SetUseCentralityBin(cent0);
150
151     pCompTPCc1 = new AliPerformanceTPC("AliPerformanceTPC",Form("AliPerformanceTPC_cent_%d",cent1),kTPC,kFALSE); 
152     if(!pCompTPCc1) {
153       Error(Form("AddTaskPerformanceTPC_cent_%d",cent1), "Cannot create AliPerformanceTPC");
154     }
155     pCompTPCc1->SetAliRecInfoCuts(pRecInfoCutsTPC);
156     pCompTPCc1->SetAliMCInfoCuts(pMCInfoCuts);
157     pCompTPCc1->SetUseTrackVertex(kFALSE);
158     pCompTPCc1->SetUseHLT(kFALSE);
159     pCompTPCc1->SetUseCentralityBin(cent1);
160
161     pCompTPCc2 = new AliPerformanceTPC("AliPerformanceTPC",Form("AliPerformanceTPC_cent_%d",cent2),kTPC,kFALSE); 
162     if(!pCompTPCc2) {
163       Error(Form("AddTaskPerformanceTPC_cent_%d",cent2), "Cannot create AliPerformanceTPC");
164     }
165     pCompTPCc2->SetAliRecInfoCuts(pRecInfoCutsTPC);
166     pCompTPCc2->SetAliMCInfoCuts(pMCInfoCuts);
167     pCompTPCc2->SetUseTrackVertex(kFALSE);
168     pCompTPCc2->SetUseHLT(kFALSE);
169     pCompTPCc2->SetUseCentralityBin(cent2);
170   }
171   
172   //
173   // dEdx ------------------------------------------------------------------------------------
174   //
175
176   AliPerformanceDEdx *pCompDEdx0 = NULL;
177   AliPerformanceDEdx *pCompDEdxc0 = NULL;
178   AliPerformanceDEdx *pCompDEdxc1 = NULL;
179   AliPerformanceDEdx *pCompDEdxc2 = NULL;
180
181   if( !task->GetUseCentrality() ) {
182     pCompDEdx0 = new AliPerformanceDEdx("AliPerformanceDEdxTPCInner","AliPerformanceDEdxTPCInner",kTPCInner,kFALSE); 
183     if(!pCompDEdx0) {
184       Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceDEdxTPCInner");
185     }
186     pCompDEdx0->SetAliRecInfoCuts(pRecInfoCutsTPC);
187     pCompDEdx0->SetAliMCInfoCuts(pMCInfoCuts);
188     pCompDEdx0->SetUseTrackVertex(kFALSE);
189   }
190   else {
191     pCompDEdxc0 = new AliPerformanceDEdx("AliPerformanceDEdxTPCInner",
192                                          Form("AliPerformanceDEdxTPCInner_cent_%d",cent0),kTPCInner,kFALSE); 
193     if(!pCompDEdxc0) {
194       Error(Form("AddTaskPerformanceTPC_cent_%d",cent0), "Cannot create AliPerformanceDEdxTPCInner");
195     }
196     pCompDEdxc0->SetAliRecInfoCuts(pRecInfoCutsTPC);
197     pCompDEdxc0->SetAliMCInfoCuts(pMCInfoCuts);
198     pCompDEdxc0->SetUseTrackVertex(kFALSE);   
199     pCompDEdxc0->SetUseCentralityBin(cent0);
200
201     pCompDEdxc1 = new AliPerformanceDEdx("AliPerformanceDEdxTPCInner",
202                                          Form("AliPerformanceDEdxTPCInner_cent_%d",cent1),kTPCInner,kFALSE); 
203     if(!pCompDEdxc1) {
204       Error(Form("AddTaskPerformanceTPC_cent_%d",cent1), "Cannot create AliPerformanceDEdxTPCInner");
205     }
206     pCompDEdxc1->SetAliRecInfoCuts(pRecInfoCutsTPC);
207     pCompDEdxc1->SetAliMCInfoCuts(pMCInfoCuts);
208     pCompDEdxc1->SetUseTrackVertex(kFALSE);   
209     pCompDEdxc1->SetUseCentralityBin(cent1);
210
211     pCompDEdxc2 = new AliPerformanceDEdx("AliPerformanceDEdxTPCInner",
212                                          Form("AliPerformanceDEdxTPCInner_cent_%d",cent2),kTPCInner,kFALSE); 
213     if(!pCompDEdxc2) {
214       Error(Form("AddTaskPerformanceTPC_cent_%d",cent2), "Cannot create AliPerformanceDEdxTPCInner");
215     }
216     pCompDEdxc2->SetAliRecInfoCuts(pRecInfoCutsTPC);
217     pCompDEdxc2->SetAliMCInfoCuts(pMCInfoCuts);
218     pCompDEdxc2->SetUseTrackVertex(kFALSE);
219     pCompDEdxc2->SetUseCentralityBin(cent2);  
220   }
221
222   //
223   // Efficiency ------------------------------------------------------------------------------------
224   //
225
226   AliPerformanceEff *pCompEff0  = NULL;
227   AliPerformanceEff *pCompEffc0 = NULL;
228   AliPerformanceEff *pCompEffc1 = NULL;
229   AliPerformanceEff *pCompEffc2 = NULL;
230
231   if( !task->GetUseCentrality() ) {
232     pCompEff0 = new AliPerformanceEff("AliPerformanceEff", "AliPerformanceEff",kTPC,kFALSE); 
233     if(!pCompEff0) {
234       Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceEff");
235     }
236     pCompEff0->SetAliRecInfoCuts(pRecInfoCutsTPC);
237     pCompEff0->SetAliMCInfoCuts(pMCInfoCuts);
238     pCompEff0->SetUseTrackVertex(kFALSE);
239     pCompEff0->InitHighMult();
240   }
241   else {
242     pCompEffc0 = new AliPerformanceEff("AliPerformanceEff", Form("AliPerformanceEff_cent_%d",cent0),kTPC,kFALSE); 
243     if(!pCompEffc0) {
244       Error(Form("AddTaskPerformanceTPC_cent_%d",cent0), "Cannot create AliPerformanceEff");
245     }
246     pCompEffc0->SetAliRecInfoCuts(pRecInfoCutsTPC);
247     pCompEffc0->SetAliMCInfoCuts(pMCInfoCuts);
248     pCompEffc0->SetUseTrackVertex(kFALSE);
249     pCompEffc0->InitHighMult();
250     pCompEffc0->SetUseCentralityBin(cent0);  
251
252     pCompEffc1 = new AliPerformanceEff("AliPerformanceEff", Form("AliPerformanceEff_cent_%d",cent1),kTPC,kFALSE); 
253     if(!pCompEffc1) {
254       Error(Form("AddTaskPerformanceTPC_cent_%d",cent1), "Cannot create AliPerformanceEff");
255     }
256     pCompEffc1->SetAliRecInfoCuts(pRecInfoCutsTPC);
257     pCompEffc1->SetAliMCInfoCuts(pMCInfoCuts);
258     pCompEffc1->SetUseTrackVertex(kFALSE);
259     pCompEffc1->InitHighMult();
260     pCompEffc1->SetUseCentralityBin(cent1);  
261
262     pCompEffc2 = new AliPerformanceEff("AliPerformanceEff", Form("AliPerformanceEff_cent_%d",cent2),kTPC,kFALSE); 
263     if(!pCompEffc2) {
264       Error(Form("AddTaskPerformanceTPC_cent_%d",cent2), "Cannot create AliPerformanceEff");
265     }
266     pCompEffc2->SetAliRecInfoCuts(pRecInfoCutsTPC);
267     pCompEffc2->SetAliMCInfoCuts(pMCInfoCuts);
268     pCompEffc2->SetUseTrackVertex(kFALSE);
269     pCompEffc2->InitHighMult();
270     pCompEffc2->SetUseCentralityBin(cent2);  
271   }
272
273   //
274   // Resolution ------------------------------------------------------------------------------------
275   //
276
277   AliPerformanceRes *pCompRes0 = NULL;
278   AliPerformanceRes *pCompResc0 = NULL;
279   AliPerformanceRes *pCompResc1 = NULL;
280   AliPerformanceRes *pCompResc2 = NULL;
281
282   if( !task->GetUseCentrality() ) {
283     pCompRes0 = new AliPerformanceRes("AliPerformanceRes", "AliPerformanceRes",kTPC,kFALSE); 
284     if(!pCompRes0) {
285       Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceRes");
286     }
287     pCompRes0->SetAliRecInfoCuts(pRecInfoCutsTPC);
288     pCompRes0->SetAliMCInfoCuts(pMCInfoCuts);
289     pCompRes0->SetUseTrackVertex(kFALSE);
290     pCompRes0->InitHighMult();
291   }
292   else {
293     pCompResc0 = new AliPerformanceRes("AliPerformanceRes", Form("AliPerformanceRes_cent_%d",cent0), kTPC, kFALSE); 
294     if(!pCompResc0) {
295       Error(Form("AddTaskPerformanceTPC_cent_%d",cent0), "Cannot create AliPerformanceRes");
296     }
297     pCompResc0->SetAliRecInfoCuts(pRecInfoCutsTPC);
298     pCompResc0->SetAliMCInfoCuts(pMCInfoCuts);
299     pCompResc0->SetUseTrackVertex(kFALSE);
300     pCompResc0->InitHighMult();
301     pCompResc0->SetUseCentralityBin(cent0); 
302
303     pCompResc1 = new AliPerformanceRes("AliPerformanceRes", Form("AliPerformanceRes_cent_%d",cent1), kTPC, kFALSE); 
304     if(!pCompResc1) {
305       Error(Form("AddTaskPerformanceTPC_cent_%d",cent1), "Cannot create AliPerformanceRes");
306     }
307     pCompResc1->SetAliRecInfoCuts(pRecInfoCutsTPC);
308     pCompResc1->SetAliMCInfoCuts(pMCInfoCuts);
309     pCompResc1->SetUseTrackVertex(kFALSE);
310     pCompResc1->InitHighMult();
311     pCompResc1->SetUseCentralityBin(cent1); 
312
313
314     pCompResc2 = new AliPerformanceRes("AliPerformanceRes", Form("AliPerformanceRes_cent_%d",cent2), kTPC, kFALSE); 
315     if(!pCompResc2) {
316       Error(Form("AddTaskPerformanceTPC_cent_%d",cent2), "Cannot create AliPerformanceRes");
317     }
318     pCompResc2->SetAliRecInfoCuts(pRecInfoCutsTPC);
319     pCompResc2->SetAliMCInfoCuts(pMCInfoCuts);
320     pCompResc2->SetUseTrackVertex(kFALSE);
321     pCompResc2->InitHighMult();
322     pCompResc2->SetUseCentralityBin(cent2); 
323   }
324
325   // ----------------------------------------------------------------------------------------------------------------------------
326   
327   //
328   // Add components to the performance task  ------------------------------------------------------------------------------------
329   //
330   if( !task->GetUseCentrality() ) {
331     task->AddPerformanceObject( pCompTPC0 );
332     task->AddPerformanceObject( pCompDEdx0 );
333     task->AddPerformanceObject( pCompEff0 );
334     task->AddPerformanceObject( pCompRes0 );
335
336     if(!bUseMCInfo) { 
337       pCompTPC0->SetTriggerClass(triggerClass);
338       pCompDEdx0->SetTriggerClass(triggerClass);
339       pCompEff0->SetTriggerClass(triggerClass);
340       pCompRes0->SetTriggerClass(triggerClass);
341     }
342   }
343   else {
344     task->AddPerformanceObject( pCompTPCc0 );
345     task->AddPerformanceObject( pCompTPCc1 );
346     task->AddPerformanceObject( pCompTPCc2 );
347     task->AddPerformanceObject( pCompDEdxc0 );
348     task->AddPerformanceObject( pCompDEdxc1 );
349     task->AddPerformanceObject( pCompDEdxc2 );
350     task->AddPerformanceObject( pCompEffc0 );
351     task->AddPerformanceObject( pCompEffc1 );
352     task->AddPerformanceObject( pCompEffc2 );
353     task->AddPerformanceObject( pCompResc0 );
354     task->AddPerformanceObject( pCompResc1 );
355     task->AddPerformanceObject( pCompResc2 );
356
357     if(!bUseMCInfo) { 
358       pCompTPCc0->SetTriggerClass(triggerClass);
359       pCompDEdxc0->SetTriggerClass(triggerClass);
360       pCompTPCc1->SetTriggerClass(triggerClass);
361       pCompDEdxc1->SetTriggerClass(triggerClass);
362       pCompTPCc2->SetTriggerClass(triggerClass);
363       pCompDEdxc2->SetTriggerClass(triggerClass);
364       pCompEffc0->SetTriggerClass(triggerClass);
365       pCompEffc1->SetTriggerClass(triggerClass);
366       pCompEffc2->SetTriggerClass(triggerClass);
367       pCompResc0->SetTriggerClass(triggerClass);
368       pCompResc1->SetTriggerClass(triggerClass);
369       pCompResc2->SetTriggerClass(triggerClass);
370     }
371   }
372
373   //
374   // Create containers for input
375   //
376   mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
377
378   //
379   // Create containers for output
380   //
381   AliAnalysisDataContainer *coutput_tpc = mgr->CreateContainer("TPCQA", TList::Class(), AliAnalysisManager::kOutputContainer, Form("%s:TPC_%s", mgr->GetCommonFileName(), task->GetName()));
382
383   AliAnalysisDataContainer *coutput2_tpc = mgr->CreateContainer("TPCQASummary", TTree::Class(), AliAnalysisManager::kParamContainer, "trending.root:SummaryTPCQA"); 
384
385   mgr->ConnectOutput(task, 1, coutput_tpc);
386   mgr->ConnectOutput(task, 2, coutput2_tpc);
387
388 return task;  
389 }