AliRsnCutManager:
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutPIDTOF.cxx
CommitLineData
35e49ca5 1//
2// Class AliRsnCutPIDTOF
3//
4// General implementation of a single cut strategy, which can be:
5// - a value contained in a given interval [--> IsBetween() ]
6// - a value equal to a given reference [--> MatchesValue()]
7//
8// In all cases, the reference value(s) is (are) given as data members
9// and each kind of cut requires a given value type (Int, UInt, Double),
10// but the cut check procedure is then automatized and chosen thanks to
11// an enumeration of the implemented cut types.
12// At the end, the user (or any other point which uses this object) has
13// to use the method IsSelected() to check if this cut has been passed.
14//
15// authors: Martin Vala (martin.vala@cern.ch)
16// Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
17//
18
19#include <Riostream.h>
20
21#include "AliESDtrack.h"
22#include "AliAODTrack.h"
23#include "AliESDpid.h"
24#include "AliTOFT0maker.h"
25#include "AliTOFcalib.h"
26#include "AliCDBManager.h"
27#include "AliVTrack.h"
28
29#include "AliRsnEvent.h"
30#include "AliRsnDaughter.h"
31#include "AliRsnCutPIDTOF.h"
32
33ClassImp(AliRsnCutPIDTOF)
34
35//Bool_t AliRsnCutPIDTOF::fgTOFcalibrateESD = kTRUE;
36Bool_t AliRsnCutPIDTOF::fgTOFcorrectTExp = kTRUE;
37Bool_t AliRsnCutPIDTOF::fgTOFuseT0 = kTRUE;
38Bool_t AliRsnCutPIDTOF::fgTOFtuneMC = kFALSE;
39Double_t AliRsnCutPIDTOF::fgTOFresolution = 100.0;
40AliTOFT0maker* AliRsnCutPIDTOF::fgTOFmaker = 0x0;
41AliTOFcalib* AliRsnCutPIDTOF::fgTOFcalib = 0x0;
42Int_t AliRsnCutPIDTOF::fgLastRun = -1;
43Int_t AliRsnCutPIDTOF::fgLastEventID = -1;
44AliESDEvent* AliRsnCutPIDTOF::fgLastEvent = 0x0;
45
46
47//_________________________________________________________________________________________________
48AliRsnCutPIDTOF::AliRsnCutPIDTOF(const char *name, Bool_t isMC, Double_t min, Double_t max) :
49 AliRsnCut(name, AliRsnCut::kDaughter, min, max),
50 fIsMC(isMC),
51 fPIDtype(AliPID::kPion),
52 fESDpid(),
53 fAODpid()
54{
55//
56// Default constructor.
57//
58}
59
60//_________________________________________________________________________________________________
61AliRsnCutPIDTOF::AliRsnCutPIDTOF(const AliRsnCutPIDTOF& copy) :
62 AliRsnCut(copy),
63 fIsMC(copy.fIsMC),
64 fPIDtype(copy.fPIDtype),
65 fESDpid(copy.fESDpid),
66 fAODpid(copy.fAODpid)
67{
68//
69// Copy constructor
70//
71}
72
73//_________________________________________________________________________________________________
74AliRsnCutPIDTOF& AliRsnCutPIDTOF::operator=(const AliRsnCutPIDTOF& copy)
75{
76//
77// Assignment operator
78//
79
80 fIsMC = copy.fIsMC;
81 fPIDtype = copy.fPIDtype;
82 fESDpid = copy.fESDpid;
83 fAODpid = copy.fAODpid;
84
85 return (*this);
86}
87
88//_________________________________________________________________________________________________
89Bool_t AliRsnCutPIDTOF::IsSelected(TObject *object)
90{
91//
92// Cut checker.
93//
94
95 // coherence check
96 if (!TargetOK(object)) return kFALSE;
97
98 // reject not TOF-matched tracks
99 // status is checked in the same way for all tracks
100 AliVTrack *vtrack = dynamic_cast<AliVTrack*>(fDaughter->GetRef());
101 if (!vtrack)
102 {
103 AliDebug(AliLog::kDebug + 2, Form("This object is not either an ESD nor AOD track, it is an %s", fDaughter->GetRef()->ClassName()));
104 return kFALSE;
105 }
106 ULong_t status = (ULong_t)vtrack->GetStatus();
107 if ((status & AliESDtrack::kTOFout) == 0 || (status & AliESDtrack::kTIME) == 0)
108 {
109 AliDebug(AliLog::kDebug + 2, "Track is not matched with TOF");
110 return kFALSE;
111 }
112
113 // retrieve real object type
114 AliESDtrack *esdTrack = fDaughter->GetRefESDtrack();
115 AliAODTrack *aodTrack = fDaughter->GetRefAODtrack();
116 if (esdTrack)
117 {
118 AliDebug(AliLog::kDebug + 2, "Checking an ESD track");
119 ProcessCurrentEvent();
120 return CheckESD(esdTrack);
121 }
122 else if (aodTrack)
123 {
124 AliDebug(AliLog::kDebug + 2, "Checking an AOD track");
125 return CheckAOD(aodTrack);
126 }
127 else
128 {
129 AliDebug(AliLog::kDebug + 2, Form("This object is not either an ESD nor AOD track, it is an %s", fDaughter->GetRef()->ClassName()));
130 return kFALSE;
131 }
132}
133
134//_________________________________________________________________________________________________
135void AliRsnCutPIDTOF::ProcessCurrentEvent()
136{
137//
138// Repeats the PID for current event.
139// In order to avoid to repeat the operation for each track
140// this function uses the data-member pointers to check
141// if current event was already processed or not.
142//
143
144 // get current event and skip if it is the same as before
145 AliESDEvent *esd = fgCurrentEvent->GetRefESD();
146 if (esd == fgLastEvent) return;
147
148 // if event has changed, get run number and
149 // reinitialize the calib and time maker
150 // if this has changed
151 Int_t run = esd->GetRunNumber();
152 if (run != fgLastRun)
153 {
154 AliInfo("============================================================================================");
155 AliInfo(Form("*** CHANGING RUN NUMBER: PREVIOUS = %d --> CURRENT = %d ***", fgLastRun, run));
156 AliInfo("============================================================================================");
157 fgLastRun = run;
158
159 AliCDBManager::Instance()->SetDefaultStorage("raw://");
160 AliCDBManager::Instance()->SetRun(fgLastRun);
161
162 if (fgTOFmaker) delete fgTOFmaker;
163 if (fgTOFcalib) delete fgTOFcalib;
164
165 fgTOFcalib = new AliTOFcalib();
166 if (fIsMC)
167 {
168 fgTOFcalib->SetRemoveMeanT0(kFALSE);
169 fgTOFcalib->SetCalibrateTOFsignal(kFALSE);
170 }
171 else
172 {
173 fgTOFcalib->SetRemoveMeanT0(kTRUE);
174 fgTOFcalib->SetCalibrateTOFsignal(kTRUE);
175 }
176 if (fgTOFcorrectTExp) fgTOFcalib->SetCorrectTExp(kTRUE);
177 fgTOFcalib->Init();
178
179 fgTOFmaker = new AliTOFT0maker(&fESDpid, fgTOFcalib);
180 fgTOFmaker->SetTimeResolution(fgTOFresolution);
181 }
182
183 // repeat the calibration and PID computations
184 /*if (fgTOFcalibrateESD)*/ fgTOFcalib->CalibrateESD(esd);
185 if (fgTOFtuneMC) fgTOFmaker->TuneForMC(esd);
186 if (fgTOFuseT0)
187 {
188 fgTOFmaker->ComputeT0TOF(esd);
189 fgTOFmaker->ApplyT0TOF(esd);
190 fESDpid.MakePID(esd, kFALSE, 0.);
191 }
192}
193
194//_________________________________________________________________________________________________
195Bool_t AliRsnCutPIDTOF::CheckESD(AliESDtrack *track)
196{
197//
198// Check TOF particle identification for ESD tracks.
199// Uses the AlifESDpid odata member.
200//
201
202 // require a minimum length to have meaningful match
203 if (track->GetIntegratedLength() < 350.) return kFALSE;
204
205 // setup TOF PID response
206 AliTOFPIDResponse &tofrsp = fESDpid.GetTOFResponse();
207
208 // get info for computation
209 Double_t momentum = track->P();
210 Double_t time = track->GetTOFsignal();
211 Double_t timeint[AliPID::kSPECIES];
212 tofrsp.GetStartTime(momentum);
213 track->GetIntegratedTimes(timeint);
214 Double_t timeDiff = time - timeint[(Int_t)fPIDtype];
215 Double_t sigmaRef = tofrsp.GetExpectedSigma(momentum, timeint[(Int_t)fPIDtype], AliPID::ParticleMass(fPIDtype));
216
217 // port values to standard AliRsnCut checker
218 fCutValueD = timeDiff / sigmaRef;
219 return OkRangeD();
220}
221
222//_________________________________________________________________________________________________
223Bool_t AliRsnCutPIDTOF::CheckAOD(AliAODTrack *track)
224{
225//
226// check TOF particle identification for AOD tracks.
227// Uses the AliAODpidUtil data member.
228//
229
230 fCutValueD = (Double_t)fAODpid.NumberOfSigmasTOF(track, fPIDtype);
231 return OkRangeD();
232}