]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskPIDResponse.cxx
solution of the problem: the BC id of the event header does not match the one from...
[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
30 #include "AliAnalysisTaskPIDResponse.h"
31
32 ClassImp(AliAnalysisTaskPIDResponse)
33
34 //______________________________________________________________________________
35 AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse():
36 AliAnalysisTaskSE(),
37 fIsMC(kFALSE),
38 fCachePID(kTRUE),
39 fOADBPath(),
40 fSpecialDetResponse(),
41 fPIDResponse(0x0),
42 fRun(0),
43 fOldRun(0),
44 fRecoPass(0),
45 fIsTunedOnData(kFALSE),
46 fRecoPassTuned(0)  
47 {
48   //
49   // Dummy constructor
50   //
51 }
52
53 //______________________________________________________________________________
54 AliAnalysisTaskPIDResponse::AliAnalysisTaskPIDResponse(const char* name):
55 AliAnalysisTaskSE(name),
56 fIsMC(kFALSE),
57 fCachePID(kTRUE),
58 fOADBPath(),
59 fSpecialDetResponse(),
60 fPIDResponse(0x0),
61 fRun(0),
62 fOldRun(0),
63 fRecoPass(0),
64 fIsTunedOnData(kFALSE),
65 fRecoPassTuned(0)
66 {
67   //
68   // Default constructor
69   //
70   DefineInput(0,TChain::Class());
71 }
72
73 //______________________________________________________________________________
74 AliAnalysisTaskPIDResponse::~AliAnalysisTaskPIDResponse()
75 {
76   //
77   // Destructor
78   //
79 }
80
81 //______________________________________________________________________________
82 void AliAnalysisTaskPIDResponse::UserCreateOutputObjects()
83 {
84   //
85   // Create the output QA objects
86   //
87   
88   AliLog::SetClassDebugLevel("AliAnalysisTaskPIDResponse",10);
89   
90   //input hander
91   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
92   AliInputEventHandler *inputHandler=dynamic_cast<AliInputEventHandler*>(man->GetInputEventHandler());
93   if (!inputHandler) AliFatal("Input handler needed");
94   
95   //pid response object
96   inputHandler->CreatePIDResponse(fIsMC);
97   fPIDResponse=inputHandler->GetPIDResponse();
98   if (!fPIDResponse) AliFatal("PIDResponse object was not created");
99
100   fPIDResponse->SetOADBPath(AliAnalysisManager::GetOADBPath());
101 //   fPIDResponse->SetCachePID(fCachePID);
102   if (!fOADBPath.IsNull()) fPIDResponse->SetOADBPath(fOADBPath.Data());
103
104   if(fIsTunedOnData) fPIDResponse->SetTunedOnData(kTRUE,fRecoPassTuned);
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   }
117 }
118
119 //______________________________________________________________________________
120 void AliAnalysisTaskPIDResponse::UserExec(Option_t */*option*/)
121 {
122   // Setup the PID response functions and fill the QA histograms
123   //
124   AliVEvent *event=InputEvent();
125   if (!event) return;
126   fRun=event->GetRunNumber();
127   
128   if (fRun!=fOldRun){
129     SetRecoInfo();
130     fOldRun=fRun;
131   }
132
133   fPIDResponse->InitialiseEvent(event,fRecoPass);
134   AliESDpid *pidresp = dynamic_cast<AliESDpid*>(fPIDResponse);
135   if(pidresp && AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()){
136       pidresp->SetEventHandler(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
137   }
138   //create and attach transient PID object
139   if (fCachePID) {
140     fPIDResponse->FillTrackDetectorPID();
141   }
142 }
143
144 //______________________________________________________________________________
145 void AliAnalysisTaskPIDResponse::SetRecoInfo()
146 {
147   //
148   // Set reconstruction information
149   //
150   
151   //reset information
152   fRecoPass=0;
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   }
166   
167   //find pass from file name (UGLY, but not stored in ESD... )
168   TString fileName(file->GetName());
169   if (fileName.Contains("pass1") ) {
170     fRecoPass=1;
171   } else if (fileName.Contains("pass2") ) {
172     fRecoPass=2;
173   } else if (fileName.Contains("pass3") ) {
174     fRecoPass=3;
175   } else if (fileName.Contains("pass4") ) {
176     fRecoPass=4;
177   } else if (fileName.Contains("pass5") ) {
178     fRecoPass=5;
179   }
180
181   fPIDResponse->SetCurrentFile(fileName.Data());
182 }