Line data Source code
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 170 : ClassImp(AliAnalysisTaskPIDResponse)
34 :
35 : //______________________________________________________________________________
36 : AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse():
37 0 : AliAnalysisTaskSE(),
38 0 : fIsMC(kFALSE),
39 0 : fCachePID(kTRUE),
40 0 : fOADBPath(),
41 0 : fSpecialDetResponse(),
42 0 : fPIDResponse(0x0),
43 0 : fRun(-1),
44 0 : fOldRun(-1),
45 0 : fRecoPass(0),
46 0 : fIsTunedOnData(kFALSE),
47 0 : fTunedOnDataMask(0),
48 0 : fRecoPassTuned(0),
49 0 : fUseTPCEtaCorrection(kTRUE),
50 0 : fUseTPCMultiplicityCorrection(kTRUE),
51 0 : fUseTRDEtaCorrection(kTRUE),
52 0 : fUserDataRecoPass(-1)
53 0 : {
54 : //
55 : // Dummy constructor
56 : //
57 0 : }
58 :
59 : //______________________________________________________________________________
60 : AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse(const char* name):
61 0 : AliAnalysisTaskSE(name),
62 0 : fIsMC(kFALSE),
63 0 : fCachePID(kTRUE),
64 0 : fOADBPath(),
65 0 : fSpecialDetResponse(),
66 0 : fPIDResponse(0x0),
67 0 : fRun(-1),
68 0 : fOldRun(-1),
69 0 : fRecoPass(0),
70 0 : fIsTunedOnData(kFALSE),
71 0 : fTunedOnDataMask(0),
72 0 : fRecoPassTuned(0),
73 0 : fUseTPCEtaCorrection(kTRUE),
74 0 : fUseTPCMultiplicityCorrection(kTRUE),
75 0 : fUseTRDEtaCorrection(kTRUE),
76 0 : fUserDataRecoPass(-1)
77 0 : {
78 : //
79 : // Default constructor
80 : //
81 0 : DefineInput(0,TChain::Class());
82 0 : }
83 :
84 : //______________________________________________________________________________
85 : AliAnalysisTaskPIDResponse::~AliAnalysisTaskPIDResponse()
86 0 : {
87 : //
88 : // Destructor
89 : //
90 0 : }
91 :
92 : //______________________________________________________________________________
93 : void AliAnalysisTaskPIDResponse::UserCreateOutputObjects()
94 : {
95 : //
96 : // Create the output QA objects
97 : //
98 :
99 0 : AliLog::SetClassDebugLevel("AliAnalysisTaskPIDResponse",10);
100 :
101 : //input hander
102 0 : AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
103 0 : AliInputEventHandler *inputHandler=dynamic_cast<AliInputEventHandler*>(man->GetInputEventHandler());
104 0 : if (!inputHandler) AliFatal("Input handler needed");
105 :
106 : //pid response object
107 0 : inputHandler->CreatePIDResponse(fIsMC);
108 0 : fPIDResponse=inputHandler->GetPIDResponse();
109 0 : if (!fPIDResponse) AliFatal("PIDResponse object was not created");
110 :
111 0 : fPIDResponse->SetOADBPath(AliAnalysisManager::GetOADBPath());
112 0 : fPIDResponse->SetCachePID(fCachePID);
113 0 : if (!fOADBPath.IsNull()) fPIDResponse->SetOADBPath(fOADBPath.Data());
114 :
115 0 : if(fTunedOnDataMask != 0) fPIDResponse->SetTunedOnDataMask(fTunedOnDataMask);
116 :
117 0 : if (!fSpecialDetResponse.IsNull()){
118 0 : TObjArray *arr=fSpecialDetResponse.Tokenize("; ");
119 0 : for (Int_t i=0; i<arr->GetEntriesFast();++i){
120 0 : TString resp(arr->At(i)->GetName());
121 0 : if (resp.BeginsWith("TPC:")){
122 0 : resp.ReplaceAll("TPC:","");
123 0 : fPIDResponse->SetCustomTPCpidResponse(resp.Data());
124 0 : AliInfo(Form("Setting custom TPC response file: '%s'",resp.Data()));
125 : }
126 0 : else if (resp.BeginsWith("TPC-OADB:")){
127 0 : resp.ReplaceAll("TPC-OADB:","");
128 0 : fPIDResponse->SetCustomTPCpidResponseOADBFile(resp.Data());
129 0 : AliInfo(Form("Setting custom TPC response OADB file: '%s'",resp.Data()));
130 : }
131 0 : else if (resp.BeginsWith("TPC-Maps:")){
132 0 : resp.ReplaceAll("TPC-Maps:","");
133 0 : fPIDResponse->SetCustomTPCetaMaps(resp.Data());
134 0 : AliInfo(Form("Setting custom TPC eta maps file: '%s'",resp.Data()));
135 : }
136 0 : else if (resp.BeginsWith("TPC-dEdxType:")){
137 0 : resp.ReplaceAll("TPC-dEdxType:","");
138 0 : fPIDResponse->GetTPCResponse().SetdEdxTypeFromString(resp);
139 : }
140 0 : }
141 0 : delete arr;
142 0 : }
143 0 : }
144 :
145 : //______________________________________________________________________________
146 : void AliAnalysisTaskPIDResponse::UserExec(Option_t */*option*/)
147 : {
148 : // Setup the PID response functions and fill the QA histograms
149 : //
150 0 : AliVEvent *event=InputEvent();
151 0 : if (!event) return;
152 0 : fRun=event->GetRunNumber();
153 :
154 0 : if (fRun!=fOldRun){
155 0 : SetRecoInfo();
156 0 : if(fIsTunedOnData) fPIDResponse->SetTunedOnData(kTRUE,fRecoPassTuned);
157 :
158 0 : fOldRun=fRun;
159 :
160 0 : fPIDResponse->SetUseTPCEtaCorrection(fUseTPCEtaCorrection);
161 0 : fPIDResponse->SetUseTPCMultiplicityCorrection(fUseTPCMultiplicityCorrection);
162 :
163 0 : fPIDResponse->SetUseTRDEtaCorrection(fUseTRDEtaCorrection);
164 0 : }
165 :
166 0 : fPIDResponse->InitialiseEvent(event,fRecoPass);
167 0 : fPIDResponse->SetCurrentMCEvent(MCEvent());
168 0 : AliESDpid *pidresp = dynamic_cast<AliESDpid*>(fPIDResponse);
169 0 : if(pidresp && AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()){
170 0 : pidresp->SetEventHandler(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
171 0 : }
172 : //create and attach transient PID object
173 : // if (fCachePID) {
174 : // fPIDResponse->FillTrackDetectorPID();
175 : // }
176 0 : }
177 :
178 : //______________________________________________________________________________
179 : void AliAnalysisTaskPIDResponse::SetRecoInfo()
180 : {
181 : //
182 : // Set reconstruction information
183 : //
184 :
185 : //reset information
186 0 : fRecoPass=0;
187 :
188 : //Get UserInfo from the current tree
189 0 : AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
190 0 : AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
191 0 : if (!inputHandler) return;
192 :
193 0 : TList *uiList = inputHandler->GetUserInfo();
194 0 : AliProdInfo prodInfo(uiList);
195 0 : prodInfo.List();
196 :
197 0 : TTree *tree= (TTree*)inputHandler->GetTree();
198 0 : TFile *file= (TFile*)tree->GetCurrentFile();
199 0 : if (!file) {
200 0 : AliError("Current file not found, cannot set reconstruction information");
201 0 : return;
202 : } else {
203 0 : TString fileName(file->GetName());
204 0 : fPIDResponse->SetCurrentFile(fileName.Data());
205 0 : }
206 :
207 0 : fPIDResponse->SetCurrentAliRootRev(prodInfo.GetAlirootSvnVersion());
208 :
209 0 : if (prodInfo.IsMC() == kTRUE) fIsMC=kTRUE; // protection if user didn't use macro switch
210 0 : if ( (prodInfo.IsMC() == kFALSE) && (fIsMC == kFALSE) ) { // reco pass is needed only for data
211 :
212 0 : if (fUserDataRecoPass > -1) {
213 0 : AliInfo(Form("Data reconstruction pass is user specified. Setting pass #: %d",fUserDataRecoPass));
214 0 : fRecoPass = fUserDataRecoPass;
215 0 : } else {
216 0 : fRecoPass = prodInfo.GetRecoPass();
217 0 : if (fRecoPass < 0) { // as last resort we find pass from file name (UGLY, but not stored in ESDs/AODs before LHC12d )
218 0 : TString fileName(file->GetName());
219 0 : if (fileName.Contains("pass1") ) {
220 0 : fRecoPass=1;
221 0 : } else if (fileName.Contains("pass2") ) {
222 0 : fRecoPass=2;
223 0 : } else if (fileName.Contains("pass3") ) {
224 0 : fRecoPass=3;
225 0 : } else if (fileName.Contains("pass4") ) {
226 0 : fRecoPass=4;
227 0 : } else if (fileName.Contains("pass5") ) {
228 0 : fRecoPass=5;
229 0 : }
230 0 : }
231 : }
232 0 : if (fRecoPass <= 0) {
233 0 : AliError(" ******** Failed to find reconstruction pass number *********");
234 0 : AliError(" ******** PID information loaded for 'pass 0': parameters unreliable ******");
235 0 : AliError(" --> If these are MC data: please set kTRUE first argument of AddTaskPIDResponse");
236 0 : AliError(" --> If these are real data: ");
237 0 : AliError(" (a) please insert pass number inside the path of your local file OR");
238 0 : AliError(" (b) specify reconstruction pass number when adding PIDResponse task");
239 0 : AliError(" !!! Note that this will lead to untrustable PID !!!");
240 : // AliFatal(" no pass number specified for this data file, abort. Asserting AliFatal");
241 : }
242 : } else {
243 : // we have MC
244 0 : if (fIsTunedOnData) {
245 0 : if (prodInfo.HasLPMPass() && prodInfo.GetRecoPass()!=fRecoPassTuned) {
246 0 : AliWarning ("******* Tuned on data reco pass mismatch *******");
247 0 : AliWarning (" MC with tune on data is requested,");
248 0 : AliWarningF(" but the anchored reco pass from the 'LPMRawPass=' (%d)",prodInfo.GetRecoPass());
249 0 : AliWarningF(" does not match the reco pass set manually by the user (%d)", fRecoPassTuned);
250 0 : AliWarning (" falling back to the reco pass from the 'LPMRawPass=' tag");
251 0 : fRecoPassTuned = prodInfo.GetRecoPass();
252 0 : }
253 : }
254 : }
255 :
256 0 : }
|