1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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.
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).
25 // Author: J.Otwinowski 01/04/2009
26 // Changes by M.Knichel 15/10/2010
27 //------------------------------------------------------------------------------
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"
48 #include "AliTracker.h"
49 #include "AliGeomManager.h"
50 #include "AliCDBManager.h"
52 #include "AliCentrality.h"
53 #include "AliESDVZERO.h"
54 #include "AliMultiplicity.h"
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"
70 ClassImp(AliPerformanceTask)
72 //_____________________________________________________________________________
73 AliPerformanceTask::AliPerformanceTask()
74 : AliAnalysisTaskSE("Performance")
83 , fUseESDfriend(kFALSE)
85 , fUseTerminate(kTRUE)
88 , fUseCentralityBin(0)
94 //_____________________________________________________________________________
95 AliPerformanceTask::AliPerformanceTask(const char *name, const char */*title*/)
96 : AliAnalysisTaskSE(name)
105 , fUseESDfriend(kFALSE)
107 , fUseTerminate(kTRUE)
110 , fUseCentralityBin(0)
114 // Define input and output slots here
115 DefineOutput(0, TTree::Class());
116 DefineOutput(1, TList::Class());
118 // create the list for comparison objects
119 fCompList = new TList;
122 //_____________________________________________________________________________
123 AliPerformanceTask::~AliPerformanceTask()
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;
132 //_____________________________________________________________________________
133 Bool_t AliPerformanceTask::AddPerformanceObject(AliPerformanceObject *pObj)
135 // add comparison object to the list
137 Printf("ERROR: Could not add comparison object");
141 // add object to the list
142 fCompList->AddLast(pObj);
147 //_____________________________________________________________________________
148 void AliPerformanceTask::UserCreateOutputObjects()
153 // create output list
156 fPitList = fOutput->MakeIterator();
158 // create output list
159 //fOutputSummary = new TTree;
161 // add comparison objects to the output
162 AliPerformanceObject *pObj=0;
164 TIterator *pitCompList = fCompList->MakeIterator();
165 pitCompList->Reset();
166 while(( pObj = (AliPerformanceObject *)pitCompList->Next()) != NULL) {
170 Printf("UserCreateOutputObjects(): Number of output comparison objects: %d \n", count);
172 PostData(1, fOutput);
173 PostData(0, fOutputSummary);
176 //_____________________________________________________________________________
177 void AliPerformanceTask::UserExec(Option_t *)
180 // Called for each event
183 // Decide whether to use HLT or Offline ESD
186 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>
187 (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
190 printf("ERROR: Could not get ESDInputHandler");
193 fESD = esdH->GetHLTEvent();
196 fESD = (AliESDEvent*) (InputEvent());
202 AliESDEvent *fESDoffline;
203 fESDoffline = (AliESDEvent*) (InputEvent());
204 fESDfriend = static_cast<AliESDfriend*>(fESDoffline->FindListObject("AliESDfriend"));
208 fESDfriend = static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
211 Printf("ERROR: ESD friends not available");
221 Printf("ERROR: ESD event not available");
225 if (fUseMCInfo && !fMC) {
226 Printf("ERROR: MC event not available");
233 Printf("ERROR: ESD friends not available");
238 Bool_t process = kTRUE;
240 // Check for centrality
241 if (fUseCentrality) {
242 if ( CalculateCentralityBin() != fUseCentralityBin ) {
247 // Process comparison
249 AliPerformanceObject *pObj=0;
251 while(( pObj = (AliPerformanceObject *)fPitList->Next()) != NULL) {
252 //AliInfo(pObj->GetName());
253 pObj->Exec(fMC,fESD,fESDfriend,fUseMCInfo,fUseESDfriend);
258 PostData(1, fOutput);
261 //_____________________________________________________________________________
262 void AliPerformanceTask::Terminate(Option_t *)
264 // Called once at the end
266 if ( !fUseTerminate )
270 fOutputSummary = dynamic_cast<TTree*> (GetOutputData(0));
271 fOutput = dynamic_cast<TList*> (GetOutputData(1));
273 Printf("ERROR: AliPerformanceTask::Terminate(): fOutput data not available ..." );
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();
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);*/
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);}
301 printf("DO NOT USE OCDB \n");
305 if (! AliCDBManager::Instance()->GetDefaultStorage()) { AliCDBManager::Instance()->SetDefaultStorage("raw://"); }
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");
311 chain->Add(tmpFile.Data());
312 TTree *tree = chain->CopyTree("1");
313 if (chain) { delete chain; chain=0; }
314 fOutputSummary = tree;
317 PostData(0, fOutputSummary);
321 //_____________________________________________________________________________
322 void AliPerformanceTask::FinishTaskOutput()
324 // called once at the end of each job (on the workernode)
326 // projects THnSparse to TH1,2,3
328 fOutput = dynamic_cast<TList*> (GetOutputData(1));
330 Printf("ERROR: AliPerformanceTask::FinishTaskOutput(): fOutput data not available ..." );
334 AliPerformanceObject* pObj=0;
335 TIterator* itOut = fOutput->MakeIterator();
337 while(( pObj = dynamic_cast<AliPerformanceObject*>(itOut->Next())) != NULL) {
338 pObj->SetRunNumber(fCurrentRunNumber);
343 PostData(1, fOutput);
346 //_____________________________________________________________________________
347 Bool_t AliPerformanceTask::Notify()
349 static Int_t count = 0;
351 Printf("Processing %d. file", count);
356 //________________________________________________________________________
357 Int_t AliPerformanceTask::CalculateCentralityBin(){
358 // Get Centrality bin
360 Int_t centrality = -1;
361 Float_t centralityF = -1;
363 if (fUseCentrality == 0)
366 AliCentrality *esdCentrality = fESD->GetCentrality();
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.)
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;