TENDER becomes Tender
[u/mrichter/AliRoot.git] / PWGPP / TPC / macros / AddTaskPerformanceTPC.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 7 performance components are added to 
10 // the task: 
11 // 1. AliPerformanceRes (TPC track resolution w.r.t MC at DCA)
12 // 2. AliPerformanceResTPCInner (TPC track resolution w.r.t MC at inner TPC wall)
13 // 3. AliPerformanceResTPCOuter (TPC track resolution w.r.t MC at outer TPC wall)
14 // 4. AliPerformanceEff (TPC track reconstruction efficiency, MC primaries)
15 // 5. AliPerformanceDEdxTPCInner (TPC dEdx response - track parameters at TPC inner wall)
16 // 6. AliPerformanceDCA (TPC impact parameters resolution at DCA)
17 // 7. AliPerformanceTPC (TPC cluster and track and event information)
18 // 8. AliPerformanceMatch (TPC and ITS/TRD matching and TPC eff w.r.t ITS)
19 //
20 // Usage on the analysis train (default configuration):
21 // gSystem->Load("libANALYSIS");
22 // gSystem->Load("libANALYSISalice");
23 // gSystem->Load("libTPCcalib.so");
24 // gSystem->Load("libTender.so");
25 // gSystem->Load("libPWGPP.so");
26 //
27 // gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTaskPerformanceTPC.C");
28 // AliPerformanceTask *tpcQA = AddTaskPerformanceTPC("kTRUE","kTRUE","triggerClass"); 
29 // 
30 // Output:
31 // TPC.Performance.root file with TPC performance components is created.
32 //
33 // Each of the components contains THnSparse generic histograms which 
34 // have to be analysed (post-analysis) by using Analyse() function. 
35 // Each component contains such function.
36 //
37 //13.10.2009 -  J.Otwinowski@gsi.de
38 ///////////////////////////////////////////////////////////////////////////////
39
40 //____________________________________________
41 AliPerformanceTask* AddTaskPerformanceTPC(Bool_t bUseMCInfo=kFALSE, Bool_t bUseESDfriend=kTRUE, const char *triggerClass=0)
42 {
43   //
44   // Add AliPerformanceTask with TPC performance components
45   //
46   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
47   if(!mgr) { 
48     Error("AddTaskPerformanceTPC","AliAnalysisManager not set!");
49     return NULL;
50   }
51   
52   TString type = mgr->GetInputEventHandler()->GetDataType();
53   if (!type.Contains("ESD")) {
54     Error("AddTaskPerformanceTPC", "ESD input handler needed!");
55     return NULL;
56   }
57   
58   AliMCEventHandler *mcH = (AliMCEventHandler*)mgr->GetMCtruthEventHandler();
59   if (!mcH && bUseMCInfo) {
60     Error("AddTaskPerformanceTPC", "MC input handler needed!");
61     return NULL;
62   }
63
64   //
65   // Create task
66   //
67   AliPerformanceTask *task = new AliPerformanceTask("Performance","TPC Performance");
68   if (!task) {
69     Error("AddTaskPerformanceTPC", "TPC performance task cannot be created!");
70     return NULL;
71   }
72   task->SetUseMCInfo(bUseMCInfo);
73   task->SetUseESDfriend(bUseESDfriend);
74   task->SelectCollisionCandidates();
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(30.0);
89     //pRecInfoCutsTPC->SetMaxDCAToVertexZ(3.0);
90     pRecInfoCutsTPC->SetRequireSigmaToVertex(kFALSE);
91     pRecInfoCutsTPC->SetRequireTPCRefit(kFALSE);
92     pRecInfoCutsTPC->SetAcceptKinkDaughters(kTRUE);
93     pRecInfoCutsTPC->SetMinNClustersTPC(50);
94     pRecInfoCutsTPC->SetMaxChi2PerClusterTPC(1000000.);
95     pRecInfoCutsTPC->SetDCAToVertex2D(kFALSE);
96
97     pRecInfoCutsTPC->SetHistogramsOn(kFALSE); 
98   } 
99   else {
100     Error("AddTaskPerformanceTPC", "AliRecInfoCutsTPC cannot be created!");
101     return NULL;
102   }
103
104   //
105   // Create TPC-ESD track reconstruction cuts
106   // MATCH tracks
107   //
108   AliRecInfoCuts *pRecInfoCutsMATCH = new AliRecInfoCuts(); 
109   if(pRecInfoCutsMATCH) {
110     pRecInfoCutsMATCH->SetMaxDCAToVertexXY(3.0);
111     pRecInfoCutsMATCH->SetMaxDCAToVertexZ(3.0);
112     pRecInfoCutsMATCH->SetRequireSigmaToVertex(kFALSE);
113     pRecInfoCutsMATCH->SetRequireTPCRefit(kFALSE);
114     pRecInfoCutsMATCH->SetAcceptKinkDaughters(kTRUE);
115     pRecInfoCutsMATCH->SetMinNClustersTPC(50);
116     pRecInfoCutsMATCH->SetMaxChi2PerClusterTPC(1000000.);
117     pRecInfoCutsMATCH->SetDCAToVertex2D(kFALSE);
118     pRecInfoCutsMATCH->SetTPCITSMatchingRadius(70); 
119     pRecInfoCutsMATCH->SetTPCTRDMatchingRadius(260); 
120     pRecInfoCutsMATCH->SetMinNClustersITS(3);
121
122     pRecInfoCutsMATCH->SetHistogramsOn(kFALSE); 
123   } 
124   else {
125     Error("AddTaskPerformanceTPC", "AliRecInfoCutsTPC cannot be created!");
126     return NULL;
127   }
128
129   //
130   // Create TPC-ESD track reconstruction cuts
131   // standard cuts
132   AliRecInfoCuts *pRecInfoCuts = new AliRecInfoCuts(); 
133   if(pRecInfoCuts) {
134     pRecInfoCuts->SetMaxDCAToVertexXY(3.0);
135     pRecInfoCuts->SetMaxDCAToVertexZ(3.0);
136     pRecInfoCuts->SetMinNClustersTPC(50);
137     pRecInfoCuts->SetMinNClustersITS(2);
138     pRecInfoCuts->SetHistogramsOn(kFALSE); 
139     pRecInfoCuts->SetTPCITSMatchingRadius(70); 
140     pRecInfoCuts->SetTPCTRDMatchingRadius(260); 
141   } 
142   else {
143     Error("AddTaskPerformanceTPC", "AliRecInfoCuts cannot be created!");
144     return NULL;
145   }
146   //
147   // Create TPC-MC track reconstruction cuts
148   //
149   AliMCInfoCuts  *pMCInfoCuts = new AliMCInfoCuts();
150   if(pMCInfoCuts) {
151     pMCInfoCuts->SetMinTrackLength(70);
152   } 
153   else {
154     Error("AddTaskPerformanceTPC", "AliMCInfoCuts cannot be created!");
155     return NULL;
156   }
157
158   //
159   // Create performance objects for TPC and set cuts 
160   //
161   enum { kTPC = 0, kTPCITS, kConstrained, kTPCInner, kTPCOuter, kTPCSec };
162
163   //
164   // Resolution
165   //
166   AliPerformanceRes *pCompRes0 = new AliPerformanceRes("AliPerformanceRes","AliPerformanceRes",kTPC,kFALSE); 
167   if(!pCompRes0) {
168     Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceRes");
169   }
170   pCompRes0->SetAliRecInfoCuts(pRecInfoCuts);
171   pCompRes0->SetAliMCInfoCuts(pMCInfoCuts);
172
173   AliPerformanceRes *pCompRes3 = new AliPerformanceRes("AliPerformanceResTPCInner","AliPerformanceResTPCInner",kTPCInner,kFALSE); 
174   if(!pCompRes3) {
175     Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceResTPCInner");
176   }
177   pCompRes3->SetAliRecInfoCuts(pRecInfoCuts);
178   pCompRes3->SetAliMCInfoCuts(pMCInfoCuts);
179
180   AliPerformanceRes *pCompRes4 = new AliPerformanceRes("AliPerformanceResTPCOuter","AliPerformanceResTPCOuter",kTPCOuter,kFALSE); 
181   if(!pCompRes4) {
182     Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceResTPCOuter");
183   }
184   pCompRes4->SetAliRecInfoCuts(pRecInfoCuts);
185   pCompRes4->SetAliMCInfoCuts(pMCInfoCuts);
186   //
187   // Efficiency
188   //
189   AliPerformanceEff *pCompEff0 = new AliPerformanceEff("AliPerformanceEff","AliPerformanceEff",kTPC,kFALSE); 
190   if(!pCompEff0) {
191     Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceEff");
192   }
193   pCompEff0->SetAliRecInfoCuts(pRecInfoCuts);
194   pCompEff0->SetAliMCInfoCuts(pMCInfoCuts);
195   //
196   // dEdx
197   //
198   AliPerformanceDEdx *pCompDEdx3 = new AliPerformanceDEdx("AliPerformanceDEdxTPCInner","AliPerformanceDEdxTPCInner",kTPCInner,kFALSE); 
199   if(!pCompDEdx3) {
200     Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceDEdxTPCInner");
201   }
202   pCompDEdx3->SetAliRecInfoCuts(pRecInfoCuts);
203   pCompDEdx3->SetAliMCInfoCuts(pMCInfoCuts);
204   //
205   // DCA
206   //
207   AliPerformanceDCA *pCompDCA0 = new AliPerformanceDCA("AliPerformanceDCA","AliPerformanceDCA",kTPC,kFALSE); 
208   if(!pCompDCA0) {
209     Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceDCA");
210   }
211   pCompDCA0->SetAliRecInfoCuts(pRecInfoCuts);
212   pCompDCA0->SetAliMCInfoCuts(pMCInfoCuts);
213   //
214   // TPC performance
215   //
216   AliPerformanceTPC *pCompTPC0 = new AliPerformanceTPC("AliPerformanceTPC","AliPerformanceTPC",kTPC,kFALSE); 
217   if(!pCompTPC0) {
218     Error("AddTaskPerformanceTPC", "Cannot create AliPerformanceTPC");
219   }
220   pCompTPC0->SetAliRecInfoCuts(pRecInfoCutsTPC);
221   pCompTPC0->SetAliMCInfoCuts(pMCInfoCuts);
222   //
223   // TPC+ITS matching performance
224   //
225   AliPerformanceMatch *pCompMatch0 = new AliPerformanceMatch("AliPerformanceMatchTPCITS","AliPerformanceMatchTPCITS",0,kFALSE); 
226   if(!pCompMatch0) {
227     Error("AddTaskPerformanceMatch", "Cannot create AliPerformanceMatchTPCITS");
228   }
229   pCompMatch0->SetAliRecInfoCuts(pRecInfoCutsMATCH);
230   pCompMatch0->SetAliMCInfoCuts(pMCInfoCuts);
231   //
232   // TPC+TRD matching performance
233   //
234   AliPerformanceMatch *pCompMatch1 = new AliPerformanceMatch("AliPerformanceMatchTPCTRD","AliPerformanceMatchTPCTRD",1,kFALSE); 
235   if(!pCompMatch1) {
236     Error("AddTaskPerformanceMatch", "Cannot create AliPerformanceMatchTPCTRD");
237   }
238   pCompMatch1->SetAliRecInfoCuts(pRecInfoCutsMATCH);
239   pCompMatch1->SetAliMCInfoCuts(pMCInfoCuts);
240  
241   AliPerformanceMatch *pCompMatch2 = new AliPerformanceMatch("AliPerformanceMatchTPCEFF","AliPerformanceMatchTPCEFF",2,kFALSE); 
242   if(!pCompMatch2) {
243     Error("AddTaskPerformanceMatch", "Cannot create AliPerformanceMatchTPCEFF");
244   }
245   pCompMatch2->SetAliRecInfoCuts(pRecInfoCutsMATCH);
246   pCompMatch2->SetAliMCInfoCuts(pMCInfoCuts);
247
248   //
249   // Add components to the performance task
250   //
251   task->AddPerformanceObject( pCompDEdx3 );
252   task->AddPerformanceObject( pCompDCA0 );
253   task->AddPerformanceObject( pCompTPC0 );
254   task->AddPerformanceObject( pCompMatch0 );
255   task->AddPerformanceObject( pCompMatch1 );
256   task->AddPerformanceObject( pCompMatch2 );
257
258   //
259   if(bUseMCInfo) { 
260      task->AddPerformanceObject( pCompRes0 );
261      task->AddPerformanceObject( pCompRes3 );
262      task->AddPerformanceObject( pCompRes4 );
263      task->AddPerformanceObject( pCompEff0 );
264   }
265
266   //
267   if(!bUseMCInfo &&  triggerClass) {
268     pCompDEdx3->SetTriggerClass(triggerClass);
269     pCompDCA0->SetTriggerClass(triggerClass);
270     pCompTPC0->SetTriggerClass(triggerClass);
271     pCompMatch0->SetTriggerClass(triggerClass);
272     pCompMatch1->SetTriggerClass(triggerClass);
273     pCompMatch2->SetTriggerClass(triggerClass);
274   }
275
276   //
277   // Create containers for input
278   //
279   mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
280
281   //
282   // Create containers for output
283   //
284   AliAnalysisDataContainer *coutput_tpc = mgr->CreateContainer("TPCPerform", TList::Class(), AliAnalysisManager::kOutputContainer, Form("TPC.%sDet.root", task->GetName()));
285   mgr->ConnectOutput(task, 1, coutput_tpc);
286
287 return task;  
288 }