Added loop for extraction of clusters really attached to its track.
[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 #include <AliProdInfo.h>
30
31 #include "AliAnalysisTaskPIDResponse.h"
32
33 ClassImp(AliAnalysisTaskPIDResponse)
34
35 //______________________________________________________________________________
36 AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse():
37 AliAnalysisTaskSE(),
38 fIsMC(kFALSE),
39 fCachePID(kTRUE),
40 fOADBPath(),
41 fSpecialDetResponse(),
42 fPIDResponse(0x0),
43 fRun(-1),
44 fOldRun(-1),
45 fRecoPass(0),
46 fIsTunedOnData(kFALSE),
47 fTunedOnDataMask(0),
48 fRecoPassTuned(0),
49 fUseTPCEtaCorrection(kFALSE),//TODO: In future, default kTRUE 
50 fUseTPCMultiplicityCorrection(kFALSE)//TODO: In future, default kTRUE  
51 {
52   //
53   // Dummy constructor
54   //
55 }
56
57 //______________________________________________________________________________
58 AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse(const char* name):
59 AliAnalysisTaskSE(name),
60 fIsMC(kFALSE),
61 fCachePID(kTRUE),
62 fOADBPath(),
63 fSpecialDetResponse(),
64 fPIDResponse(0x0),
65 fRun(-1),
66 fOldRun(-1),
67 fRecoPass(0),
68 fIsTunedOnData(kFALSE),
69 fTunedOnDataMask(0),
70 fRecoPassTuned(0),
71 fUseTPCEtaCorrection(kFALSE),//TODO: In future, default kTRUE
72 fUseTPCMultiplicityCorrection(kFALSE)//TODO: In future, default kTRUE  
73 {
74   //
75   // Default constructor
76   //
77   DefineInput(0,TChain::Class());
78 }
79
80 //______________________________________________________________________________
81 AliAnalysisTaskPIDResponse::~AliAnalysisTaskPIDResponse()
82 {
83   //
84   // Destructor
85   //
86 }
87
88 //______________________________________________________________________________
89 void AliAnalysisTaskPIDResponse::UserCreateOutputObjects()
90 {
91   //
92   // Create the output QA objects
93   //
94   
95   AliLog::SetClassDebugLevel("AliAnalysisTaskPIDResponse",10);
96   
97   //input hander
98   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
99   AliInputEventHandler *inputHandler=dynamic_cast<AliInputEventHandler*>(man->GetInputEventHandler());
100   if (!inputHandler) AliFatal("Input handler needed");
101   
102   //pid response object
103   inputHandler->CreatePIDResponse(fIsMC);
104   fPIDResponse=inputHandler->GetPIDResponse();
105   if (!fPIDResponse) AliFatal("PIDResponse object was not created");
106
107   fPIDResponse->SetOADBPath(AliAnalysisManager::GetOADBPath());
108   fPIDResponse->SetCachePID(fCachePID);
109   if (!fOADBPath.IsNull()) fPIDResponse->SetOADBPath(fOADBPath.Data());
110
111   if(fIsTunedOnData) fPIDResponse->SetTunedOnData(kTRUE,fRecoPassTuned);
112   if(fTunedOnDataMask != 0) fPIDResponse->SetTunedOnDataMask(fTunedOnDataMask);
113
114   if (!fSpecialDetResponse.IsNull()){
115     TObjArray *arr=fSpecialDetResponse.Tokenize("; ");
116     for (Int_t i=0; i<arr->GetEntriesFast();++i){
117       TString resp(arr->At(i)->GetName());
118       if (resp.BeginsWith("TPC:")){
119         resp.ReplaceAll("TPC:","");
120         fPIDResponse->SetCustomTPCpidResponse(resp.Data());
121         AliInfo(Form("Setting custom TPC response file: '%s'",resp.Data()));
122       }
123     }
124     delete arr;
125   }  
126 }
127
128 //______________________________________________________________________________
129 void AliAnalysisTaskPIDResponse::UserExec(Option_t */*option*/)
130 {
131   // Setup the PID response functions and fill the QA histograms
132   //
133   AliVEvent *event=InputEvent();
134   if (!event) return;
135   fRun=event->GetRunNumber();
136   
137   if (fRun!=fOldRun){
138     SetRecoInfo();
139     fOldRun=fRun;
140     
141     fPIDResponse->SetUseTPCEtaCorrection(fUseTPCEtaCorrection);
142     fPIDResponse->SetUseTPCMultiplicityCorrection(fUseTPCMultiplicityCorrection);
143   }
144
145   fPIDResponse->InitialiseEvent(event,fRecoPass);
146   AliESDpid *pidresp = dynamic_cast<AliESDpid*>(fPIDResponse);
147   if(pidresp && AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()){
148       pidresp->SetEventHandler(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
149   }
150   //create and attach transient PID object
151 //   if (fCachePID) {
152 //     fPIDResponse->FillTrackDetectorPID();
153 //   }
154 }
155
156 //______________________________________________________________________________
157 void AliAnalysisTaskPIDResponse::SetRecoInfo()
158 {
159   //
160   // Set reconstruction information
161   //
162   
163   //reset information
164   fRecoPass=0;
165   
166   //Get UserInfo from the current tree 
167   AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
168   AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
169   if (!inputHandler) return;
170
171   TList *uiList = inputHandler->GetUserInfo();
172   AliProdInfo prodInfo(uiList);
173   prodInfo.List();
174
175   TTree *tree= (TTree*)inputHandler->GetTree();
176   TFile *file= (TFile*)tree->GetCurrentFile();
177   if (!file) {
178     AliError("Current file not found, cannot set reconstruction information");
179     return;
180   } else {
181     TString fileName(file->GetName());
182     fPIDResponse->SetCurrentFile(fileName.Data());
183   }
184
185   fPIDResponse->SetCurrentAliRootRev(prodInfo.GetAlirootSvnVersion());
186   
187   if (prodInfo.IsMC() == kTRUE) fIsMC=kTRUE;         // protection if user didn't use macro switch
188   if ( (prodInfo.IsMC() == kFALSE) && (fIsMC == kFALSE) ) {      // reco pass is needed only for data
189     fRecoPass = prodInfo.GetRecoPass();
190     if (fRecoPass < 0) {   // as last resort we find pass from file name (UGLY, but not stored in ESDs/AODs before LHC12d )
191       TString fileName(file->GetName());
192       if (fileName.Contains("pass1") ) {
193         fRecoPass=1;
194       } else if (fileName.Contains("pass2") ) {
195         fRecoPass=2;
196       } else if (fileName.Contains("pass3") ) {
197         fRecoPass=3;
198       } else if (fileName.Contains("pass4") ) {
199         fRecoPass=4;
200       } else if (fileName.Contains("pass5") ) {
201         fRecoPass=5;
202       }
203     } 
204     if (fRecoPass <= 0) {
205       AliError(" ******** Failed to find reconstruction pass number *********");
206       AliError(" ******** PID information loaded for 'pass 0': parameters unreliable ******");
207       AliError("      --> If these are MC data: please set kTRUE first argument of AddTaskPIDResponse");
208       AliError("      --> If these are real data: please insert pass number inside the path of your local file ******");
209     }
210   }
211
212 }