]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisTaskPIDResponse.cxx
o add option to switch off pid caching in AddTask
[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>
29
66ab8ab2 30#include "AliAnalysisTaskPIDResponse.h"
31
66ab8ab2 32ClassImp(AliAnalysisTaskPIDResponse)
33
34//______________________________________________________________________________
35AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse():
36AliAnalysisTaskSE(),
37fIsMC(kFALSE),
00a38d07 38fCachePID(kTRUE),
67ad8680 39fOADBPath(),
b438e263 40fSpecialDetResponse(),
66ab8ab2 41fPIDResponse(0x0),
66ab8ab2 42fRun(0),
43fOldRun(0),
539a5a59 44fRecoPass(0),
45fIsTunedOnData(kFALSE),
46fRecoPassTuned(0)
66ab8ab2 47{
48 //
49 // Dummy constructor
50 //
51}
52
53//______________________________________________________________________________
54AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse(const char* name):
55AliAnalysisTaskSE(name),
56fIsMC(kFALSE),
00a38d07 57fCachePID(kTRUE),
67ad8680 58fOADBPath(),
b438e263 59fSpecialDetResponse(),
66ab8ab2 60fPIDResponse(0x0),
66ab8ab2 61fRun(0),
62fOldRun(0),
539a5a59 63fRecoPass(0),
64fIsTunedOnData(kFALSE),
65fRecoPassTuned(0)
66ab8ab2 66{
67 //
68 // Default constructor
69 //
70 DefineInput(0,TChain::Class());
66ab8ab2 71}
72
73//______________________________________________________________________________
74AliAnalysisTaskPIDResponse::~AliAnalysisTaskPIDResponse()
75{
76 //
77 // Destructor
78 //
66ab8ab2 79}
80
81//______________________________________________________________________________
82void AliAnalysisTaskPIDResponse::UserCreateOutputObjects()
83{
84 //
85 // Create the output QA objects
86 //
00a38d07 87
66ab8ab2 88 AliLog::SetClassDebugLevel("AliAnalysisTaskPIDResponse",10);
00a38d07 89
66ab8ab2 90 //input hander
91 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
92 AliInputEventHandler *inputHandler=dynamic_cast<AliInputEventHandler*>(man->GetInputEventHandler());
93 if (!inputHandler) AliFatal("Input handler needed");
6a45d03f 94
66ab8ab2 95 //pid response object
96 inputHandler->CreatePIDResponse(fIsMC);
97 fPIDResponse=inputHandler->GetPIDResponse();
87977cf5 98 if (!fPIDResponse) AliFatal("PIDResponse object was not created");
66ab8ab2 99
6a45d03f 100 fPIDResponse->SetOADBPath(AliAnalysisManager::GetOADBPath());
b438e263 101 fPIDResponse->SetCachePID(fCachePID);
67ad8680 102 if (!fOADBPath.IsNull()) fPIDResponse->SetOADBPath(fOADBPath.Data());
539a5a59 103
104 if(fIsTunedOnData) fPIDResponse->SetTunedOnData(kTRUE,fRecoPassTuned);
b438e263 105
106 if (!fSpecialDetResponse.IsNull()){
107 TObjArray *arr=fSpecialDetResponse.Tokenize("; ");
108 for (Int_t i=0; i<arr->GetEntriesFast();++i){
109 TString resp(arr->At(i)->GetName());
110 if (resp.BeginsWith("TPC:")){
111 resp.ReplaceAll("TPC:","");
112 fPIDResponse->SetCustomTPCpidResponse(resp.Data());
113 AliInfo(Form("Setting custom TPC response file: '%s'",resp.Data()));
114 }
115 }
116 }
66ab8ab2 117}
118
66ab8ab2 119//______________________________________________________________________________
120void AliAnalysisTaskPIDResponse::UserExec(Option_t */*option*/)
121{
66ab8ab2 122 // Setup the PID response functions and fill the QA histograms
123 //
66ab8ab2 124 AliVEvent *event=InputEvent();
125 if (!event) return;
126 fRun=event->GetRunNumber();
6a45d03f 127
66ab8ab2 128 if (fRun!=fOldRun){
6a45d03f 129 SetRecoInfo();
66ab8ab2 130 fOldRun=fRun;
131 }
132
6a45d03f 133 fPIDResponse->InitialiseEvent(event,fRecoPass);
a864479b 134 AliESDpid *pidresp = dynamic_cast<AliESDpid*>(fPIDResponse);
135 if(pidresp && AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()){
136 pidresp->SetEventHandler(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
137 }
00a38d07 138 //create and attach transient PID object
139 if (fCachePID) {
140 fPIDResponse->FillTrackDetectorPID();
141 }
66ab8ab2 142}
143
66ab8ab2 144//______________________________________________________________________________
145void AliAnalysisTaskPIDResponse::SetRecoInfo()
146{
147 //
148 // Set reconstruction information
149 //
150
151 //reset information
152 fRecoPass=0;
66ab8ab2 153
154 //Get the current file to check the reconstruction pass (UGLY, but not stored in ESD... )
155 AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
156 AliVEventHandler *inputHandler=mgr->GetInputEventHandler();
157 if (!inputHandler) return;
158
159 TTree *tree= (TTree*)inputHandler->GetTree();
160 TFile *file= (TFile*)tree->GetCurrentFile();
161
162 if (!file) {
163 AliError("Current file not found, cannot set reconstruction information");
164 return;
165 }
66ab8ab2 166
167 //find pass from file name (UGLY, but not stored in ESD... )
168 TString fileName(file->GetName());
5a0aa7cb 169 if (fileName.Contains("pass1") ) {
66ab8ab2 170 fRecoPass=1;
5a0aa7cb 171 } else if (fileName.Contains("pass2") ) {
66ab8ab2 172 fRecoPass=2;
5a0aa7cb 173 } else if (fileName.Contains("pass3") ) {
66ab8ab2 174 fRecoPass=3;
6ca0da23 175 } else if (fileName.Contains("pass4") ) {
176 fRecoPass=4;
177 } else if (fileName.Contains("pass5") ) {
178 fRecoPass=5;
66ab8ab2 179 }
67ad8680 180
ab4db4eb 181 fPIDResponse->SetCurrentFile(fileName.Data());
66ab8ab2 182}