]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskPIDResponse.cxx
From Francesco: Now I pass the MC event handler with a method avoiding to call AliAna...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskPIDResponse.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 /* $Id: AliAnalysisTaskPIDResponse.cxx 43811 2010-09-23 14:13:31Z wiechula $ */
17 #include <TFile.h>
18 #include <TChain.h>
19
20 #include <AliAnalysisManager.h>
21 #include <AliInputEventHandler.h>
22 #include <AliVEventHandler.h>
23 #include <AliVEvent.h>
24 #include <AliVParticle.h>
25 #include <AliVTrack.h>
26 #include <AliLog.h>
27 #include <AliPIDResponse.h>
28 #include <AliESDpid.h>
29
30
31 #include "AliAnalysisTaskPIDResponse.h"
32
33 ClassImp(AliAnalysisTaskPIDResponse)
34
35 //______________________________________________________________________________
36 AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse():
37 AliAnalysisTaskSE(),
38 fIsMC(kFALSE),
39 fOADBPath(),
40 fPIDResponse(0x0),
41 fRun(0),
42 fOldRun(0),
43 fRecoPass(0),
44 fIsTunedOnData(kFALSE),
45 fRecoPassTuned(0)  
46 {
47   //
48   // Dummy constructor
49   //
50 }
51
52 //______________________________________________________________________________
53 AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse(const char* name):
54 AliAnalysisTaskSE(name),
55 fIsMC(kFALSE),
56 fOADBPath(),
57 fPIDResponse(0x0),
58 fRun(0),
59 fOldRun(0),
60 fRecoPass(0),
61 fIsTunedOnData(kFALSE),
62 fRecoPassTuned(0)
63 {
64   //
65   // Default constructor
66   //
67   DefineInput(0,TChain::Class());
68 }
69
70 //______________________________________________________________________________
71 AliAnalysisTaskPIDResponse::~AliAnalysisTaskPIDResponse()
72 {
73   //
74   // Destructor
75   //
76 }
77
78 //______________________________________________________________________________
79 void AliAnalysisTaskPIDResponse::UserCreateOutputObjects()
80 {
81   //
82   // Create the output QA objects
83   //
84     
85   AliLog::SetClassDebugLevel("AliAnalysisTaskPIDResponse",10);
86   //input hander
87   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
88   AliInputEventHandler *inputHandler=dynamic_cast<AliInputEventHandler*>(man->GetInputEventHandler());
89   if (!inputHandler) AliFatal("Input handler needed");
90   
91   //pid response object
92   inputHandler->CreatePIDResponse(fIsMC);
93   fPIDResponse=inputHandler->GetPIDResponse();
94   if (!fPIDResponse) AliFatal("PIDResponse object was not created");
95
96   fPIDResponse->SetOADBPath(AliAnalysisManager::GetOADBPath());
97   if (!fOADBPath.IsNull()) fPIDResponse->SetOADBPath(fOADBPath.Data());
98
99   if(fIsTunedOnData) fPIDResponse->SetTunedOnData(kTRUE,fRecoPassTuned);
100 }
101
102 //______________________________________________________________________________
103 void AliAnalysisTaskPIDResponse::UserExec(Option_t */*option*/)
104 {
105   // Setup the PID response functions and fill the QA histograms
106   //
107   AliVEvent *event=InputEvent();
108   if (!event) return;
109   fRun=event->GetRunNumber();
110   
111   if (fRun!=fOldRun){
112     SetRecoInfo();
113     fOldRun=fRun;
114   }
115
116   fPIDResponse->InitialiseEvent(event,fRecoPass);
117   AliESDpid *pidresp = dynamic_cast<AliESDpid*>(fPIDResponse);
118   if(pidresp && AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()){
119       pidresp->SetEventHandler(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
120   }
121 }
122
123 //______________________________________________________________________________
124 void AliAnalysisTaskPIDResponse::SetRecoInfo()
125 {
126   //
127   // Set reconstruction information
128   //
129   
130   //reset information
131   fRecoPass=0;
132   
133   //Get the current file to check the reconstruction pass (UGLY, but not stored in ESD... )
134   AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
135   AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
136   if (!inputHandler) return;
137   
138   TTree *tree= (TTree*)inputHandler->GetTree();
139   TFile *file= (TFile*)tree->GetCurrentFile();
140   
141   if (!file) {
142     AliError("Current file not found, cannot set reconstruction information");
143     return;
144   }
145   
146   //find pass from file name (UGLY, but not stored in ESD... )
147   TString fileName(file->GetName());
148   if (fileName.Contains("pass1") ) {
149     fRecoPass=1;
150   } else if (fileName.Contains("pass2") ) {
151     fRecoPass=2;
152   } else if (fileName.Contains("pass3") ) {
153     fRecoPass=3;
154   } else if (fileName.Contains("pass4") ) {
155     fRecoPass=4;
156   } else if (fileName.Contains("pass5") ) {
157     fRecoPass=5;
158   }
159
160   fPIDResponse->SetCurrentFile(fileName.Data());
161 }