]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/TPC/AliPerformanceTask.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGPP / TPC / AliPerformanceTask.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercial purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 //------------------------------------------------------------------------------
17 // Implementation of the AliPerformanceTask class. It checks reconstruction performance 
18 // for the reconstructed vs MC particle tracks under several conditions. For real data 
19 // the control QA histograms are filled.
20 //
21 // The comparison output objects deriving from AliPerformanceObject 
22 // (e.g. AliPerformanceRes, AliPerformanceEff, AliPerformanceDEdx, AliPerformanceDCA ...) 
23 // are stored in the output file (details in description of these classes).
24 // 
25 // Author: J.Otwinowski 01/04/2009 
26 // Changes by M.Knichel 15/10/2010
27 //------------------------------------------------------------------------------
28
29 #include "iostream"
30
31 #include "TChain.h"
32 #include "TTree.h"
33 #include "TH1F.h"
34 #include "TCanvas.h"
35 #include "TList.h"
36 #include "TFile.h"
37 #include "TSystem.h"
38
39 #include "AliAnalysisTask.h"
40 #include "AliAnalysisManager.h"
41 #include "AliESDEvent.h"
42 #include "AliESDfriend.h"
43 #include "AliMCEvent.h"
44 #include "AliESDInputHandler.h"
45 #include "AliMCEventHandler.h"
46 #include "AliESDVertex.h"
47 #include "AliMagF.h"
48 #include "AliTracker.h"
49 #include "AliGeomManager.h"
50 #include "AliCDBManager.h"
51
52 #include "AliCentrality.h"
53 #include "AliESDVZERO.h"
54 #include "AliMultiplicity.h"
55
56 #include "AliMCInfo.h"
57 #include "AliESDRecInfo.h"
58 #include "AliMCInfoCuts.h"
59 #include "AliRecInfoCuts.h"
60 #include "AliPerformanceObject.h"
61 #include "AliTPCPerformanceSummary.h"
62 #include "AliPerformanceTPC.h"
63 #include "AliPerformanceDEdx.h"
64 #include "AliPerformanceMatch.h"
65 #include "AliPerformanceTask.h"
66
67
68 using namespace std;
69
70 ClassImp(AliPerformanceTask)
71
72 //_____________________________________________________________________________
73 AliPerformanceTask::AliPerformanceTask() 
74   : AliAnalysisTaskSE("Performance")
75   , fESD(0)
76   , fESDfriend(0)
77   , fMC(0)
78   , fOutput(0)
79   , fOutputSummary(0)
80   , fPitList(0)
81   , fCompList(0)
82   , fUseMCInfo(kFALSE)
83   , fUseESDfriend(kFALSE)
84   , fUseHLT(kFALSE)
85   , fUseTerminate(kTRUE)
86   , fUseCentrality(0)
87   , fUseOCDB(kTRUE)
88   , fUseCentralityBin(0)
89 {
90   // Dummy Constructor
91   // should not be used
92 }
93
94 //_____________________________________________________________________________
95 AliPerformanceTask::AliPerformanceTask(const char *name, const char */*title*/) 
96   : AliAnalysisTaskSE(name)
97   , fESD(0)
98   , fESDfriend(0)
99   , fMC(0)
100   , fOutput(0)
101   , fOutputSummary(0)
102   , fPitList(0)
103   , fCompList(0)
104   , fUseMCInfo(kFALSE)
105   , fUseESDfriend(kFALSE)
106   , fUseHLT(kFALSE)
107   , fUseTerminate(kTRUE)
108   , fUseCentrality(0)
109   , fUseOCDB(kTRUE)
110   , fUseCentralityBin(0)
111 {
112   // Constructor
113
114   // Define input and output slots here
115   DefineOutput(0, TTree::Class());
116   DefineOutput(1, TList::Class());
117
118   // create the list for comparison objects
119   fCompList = new TList;
120 }
121
122 //_____________________________________________________________________________
123 AliPerformanceTask::~AliPerformanceTask()
124 {
125   if (!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
126     if (fOutput)     delete fOutput;    fOutput   = 0; 
127     if (fOutputSummary) delete fOutputSummary; fOutputSummary = 0;
128     if (fCompList)   delete fCompList;  fCompList = 0; 
129   }
130 }
131
132 //_____________________________________________________________________________
133 Bool_t AliPerformanceTask::AddPerformanceObject(AliPerformanceObject *pObj) 
134 {
135   // add comparison object to the list
136   if(pObj == 0) {
137     Printf("ERROR: Could not add comparison object");
138     return kFALSE;
139   }
140
141   // add object to the list
142   fCompList->AddLast(pObj);
143        
144 return kTRUE;
145 }
146
147 //_____________________________________________________________________________
148 void AliPerformanceTask::UserCreateOutputObjects()
149 {
150   // Create histograms
151   // Called once
152
153   // create output list
154   fOutput = new TList;
155   fOutput->SetOwner();
156   fPitList = fOutput->MakeIterator();
157   
158   // create output list
159   //fOutputSummary = new TTree;
160   
161   // add comparison objects to the output
162   AliPerformanceObject *pObj=0;
163   Int_t count=0;
164   TIterator *pitCompList = fCompList->MakeIterator();
165   pitCompList->Reset();
166   while(( pObj = (AliPerformanceObject *)pitCompList->Next()) != NULL) {
167     fOutput->Add(pObj);
168     count++;
169   }
170   Printf("UserCreateOutputObjects(): Number of output comparison objects: %d \n", count);
171   
172   PostData(1, fOutput);  
173   PostData(0, fOutputSummary);  
174 }
175
176 //_____________________________________________________________________________
177 void AliPerformanceTask::UserExec(Option_t *) 
178 {
179   // Main loop
180   // Called for each event
181
182
183   // Decide whether to use HLT or Offline ESD
184   if(fUseHLT){
185
186     AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> 
187       (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
188     
189     if (!esdH) {
190       printf("ERROR: Could not get ESDInputHandler");
191       return;
192     } 
193     fESD = esdH->GetHLTEvent();
194   }// end if fUseHLT
195   else  
196     fESD = (AliESDEvent*) (InputEvent());
197
198   if(fUseESDfriend)
199     {
200           if (fUseHLT)
201           {
202                 AliESDEvent *fESDoffline;
203             fESDoffline = (AliESDEvent*) (InputEvent());
204                 fESDfriend = static_cast<AliESDfriend*>(fESDoffline->FindListObject("AliESDfriend"));
205           }
206           else
207           {
208         fESDfriend = static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
209           }
210       if(!fESDfriend) {
211         Printf("ERROR: ESD friends not available");
212       }
213     }
214   
215   if(fUseMCInfo) {
216       fMC = MCEvent();
217   }  
218
219
220   if (!fESD) {
221     Printf("ERROR: ESD event not available");
222     return;
223   }
224   
225   if (fUseMCInfo && !fMC) {
226     Printf("ERROR: MC event not available");
227     return;
228   }
229
230   if(fUseESDfriend)
231   {
232     if(!fESDfriend) {
233     Printf("ERROR: ESD friends not available");
234     }
235   }
236
237   // Process analysis
238   Bool_t process = kTRUE;
239
240   // Check for centrality
241   if (fUseCentrality) {
242     if ( CalculateCentralityBin() != fUseCentralityBin ) {
243       process = kFALSE;
244     }
245   }
246
247   // Process comparison
248   if (process) {
249     AliPerformanceObject *pObj=0;
250     fPitList->Reset();
251     while(( pObj = (AliPerformanceObject *)fPitList->Next()) != NULL) {
252           AliInfo(pObj->GetName());
253           pObj->Exec(fMC,fESD,fESDfriend,fUseMCInfo,fUseESDfriend);
254     }
255   }
256
257   // Post output data.
258   PostData(1, fOutput);
259 }
260
261 //_____________________________________________________________________________
262 void AliPerformanceTask::Terminate(Option_t *) 
263 {
264   // Called once at the end 
265
266   if ( !fUseTerminate )
267     return;
268   
269   // check output data
270     fOutputSummary = dynamic_cast<TTree*> (GetOutputData(0));
271     fOutput = dynamic_cast<TList*> (GetOutputData(1));
272     if (!fOutput) {
273         Printf("ERROR: AliPerformanceTask::Terminate(): fOutput data not available  ..." );
274         return;
275    }
276     if (fOutputSummary) { delete fOutputSummary; fOutputSummary=0; }      
277     AliPerformanceObject* pObj=0;
278     AliPerformanceTPC*  pTPC = 0;
279     AliPerformanceDEdx* pDEdx = 0;
280     AliPerformanceMatch* pMatch = 0;
281     AliPerformanceMatch* pPull = 0;
282     AliPerformanceMatch* pConstrain = 0;
283     TIterator* itOut = fOutput->MakeIterator();
284     itOut->Reset();
285     while(( pObj = dynamic_cast<AliPerformanceObject*>(itOut->Next())) != NULL) { 
286       pObj->AnalyseFinal();
287       /*      if (!  pTPC)  {    pTPC = dynamic_cast<AliPerformanceTPC*>(pObj); }
288         if (! pDEdx)  {   pDEdx = dynamic_cast<AliPerformanceDEdx*>(pObj); }
289         if (! pMatch) {  pMatch = dynamic_cast<AliPerformanceMatch*>(pObj); }
290         if ((! pPull) && pMatch ) {  pPull = dynamic_cast<AliPerformanceMatch*>(pObj);*/
291
292         if (!strcmp(pObj->GetName(),"AliPerformanceTPC"))  {    pTPC = dynamic_cast<AliPerformanceTPC*>(pObj); }
293         if (!strcmp(pObj->GetName(),"AliPerformanceDEdxTPCInner"))  {   pDEdx = dynamic_cast<AliPerformanceDEdx*>(pObj); }
294         if (!strcmp(pObj->GetName(),"AliPerformanceMatchTPCITS")) {  pMatch = dynamic_cast<AliPerformanceMatch*>(pObj); }
295         if (!strcmp(pObj->GetName(),"AliPerformanceMatchITSTPC")) {  pPull = dynamic_cast<AliPerformanceMatch*>(pObj);}
296         if (!strcmp(pObj->GetName(),"AliPerformanceMatchTPCConstrain")) {  pConstrain = dynamic_cast<AliPerformanceMatch*>(pObj);}
297     }
298   
299    
300     if(!fUseOCDB)  { 
301       printf("DO NOT USE OCDB \n");
302       return;
303     }
304   
305     if (! AliCDBManager::Instance()->GetDefaultStorage()) { AliCDBManager::Instance()->SetDefaultStorage("raw://"); }
306     TUUID uuid;
307     TString tmpFile = gSystem->TempDirectory() + TString("/TPCQASummary.") + uuid.AsString() + TString(".root");
308     AliTPCPerformanceSummary::WriteToFile(pTPC, pDEdx, pMatch, pPull, pConstrain, tmpFile.Data());
309     TChain* chain = new TChain("tpcQA");
310     if(!chain) return;
311     chain->Add(tmpFile.Data());
312     TTree *tree = chain->CopyTree("1");
313     if (chain) { delete chain; chain=0; }
314     fOutputSummary = tree;
315       
316      // Post output data.
317      PostData(0, fOutputSummary);
318
319 }
320
321 //_____________________________________________________________________________
322 void AliPerformanceTask::FinishTaskOutput()
323 {
324     // called once at the end of each job (on the workernode)
325     //
326     // projects THnSparse to TH1,2,3
327     
328     fOutput = dynamic_cast<TList*> (GetOutputData(1));
329     if (!fOutput) {
330         Printf("ERROR: AliPerformanceTask::FinishTaskOutput(): fOutput data not available  ..." );
331         return;
332    }
333
334       AliPerformanceObject* pObj=0;
335       TIterator* itOut = fOutput->MakeIterator();  
336       itOut->Reset();
337       while(( pObj = dynamic_cast<AliPerformanceObject*>(itOut->Next())) != NULL) {
338           pObj->SetRunNumber(fCurrentRunNumber);
339           pObj->Analyse();
340       }
341       
342      // Post output data.
343      PostData(1, fOutput);
344 }
345
346 //_____________________________________________________________________________
347 Bool_t AliPerformanceTask::Notify()
348 {
349   static Int_t count = 0;
350   count++;
351   Printf("Processing %d. file", count);
352
353   return kTRUE;
354 }
355
356 //________________________________________________________________________
357 Int_t AliPerformanceTask::CalculateCentralityBin(){
358   // Get Centrality bin
359
360   Int_t centrality = -1;
361   Float_t centralityF = -1;
362
363   if (fUseCentrality == 0)
364     return centrality;
365
366   AliCentrality *esdCentrality = fESD->GetCentrality();
367     
368   // New : 2010-11-18 JMT 
369   if ( fUseCentrality == 1 )
370     centralityF = esdCentrality->GetCentralityPercentile("V0M");
371   else if ( fUseCentrality == 2 )
372     centralityF = esdCentrality->GetCentralityPercentile("CL1");
373   else if ( fUseCentrality == 3 )
374     centralityF = esdCentrality->GetCentralityPercentile("TRK"); 
375   if (centralityF == 0.)
376     centralityF = 100.;
377
378   if      ( centralityF >=  0. && centralityF <   5.) centrality =  0;
379   else if ( centralityF >=  5. && centralityF <  10.) centrality =  5;
380   else if ( centralityF >= 10. && centralityF <  20.) centrality = 10;
381   else if ( centralityF >= 20. && centralityF <  30.) centrality = 20;
382   else if ( centralityF >= 30. && centralityF <  40.) centrality = 30;
383   else if ( centralityF >= 40. && centralityF <  50.) centrality = 40;
384   else if ( centralityF >= 50. && centralityF <  60.) centrality = 50;
385   else if ( centralityF >= 60. && centralityF <  70.) centrality = 60;
386   else if ( centralityF >= 70. && centralityF <  80.) centrality = 70;
387   else if ( centralityF >= 80. && centralityF <  90.) centrality = 80;
388   else if ( centralityF >= 90. && centralityF <=100.) centrality = 90;
389   
390   return centrality;
391 }