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