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