]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEERBase/AliPIDResponse.cxx
o bug fixes for 11h gain scenarios (Mikolaj)
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliPIDResponse.cxx
CommitLineData
29bf19f2 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
4ec8e76d 16/* $Id: AliPIDResponse.cxx 46193 2010-12-21 09:00:14Z wiechula $ */
29bf19f2 17
18//-----------------------------------------------------------------
4ec8e76d 19// Base class for handling the pid response //
20// functions of all detectors //
21// and give access to the nsigmas //
22// //
23// Origin: Jens Wiechula, Uni Tuebingen, jens.wiechula@cern.ch //
29bf19f2 24//-----------------------------------------------------------------
25
4ec8e76d 26#include <TList.h>
27#include <TObjArray.h>
28#include <TPRegexp.h>
29#include <TF1.h>
f84b18dd 30#include <TH2D.h>
4ec8e76d 31#include <TSpline.h>
32#include <TFile.h>
00a38d07 33#include <TArrayI.h>
db0e2c5f 34#include <TArrayF.h>
f84b18dd 35#include <TLinearFitter.h>
4ec8e76d 36
37#include <AliVEvent.h>
fd21ec8d 38#include <AliVTrack.h>
4ec8e76d 39#include <AliLog.h>
40#include <AliPID.h>
ea235c90 41#include <AliOADBContainer.h>
db0e2c5f 42#include <AliTRDPIDResponseObject.h>
b79db598 43#include <AliTOFPIDParams.h>
29bf19f2 44
45#include "AliPIDResponse.h"
00a38d07 46#include "AliDetectorPID.h"
29bf19f2 47
80f28562 48#include "AliCentrality.h"
49
29bf19f2 50ClassImp(AliPIDResponse);
51
4ec8e76d 52AliPIDResponse::AliPIDResponse(Bool_t isMC/*=kFALSE*/) :
53TNamed("PIDResponse","PIDResponse"),
54fITSResponse(isMC),
55fTPCResponse(),
56fTRDResponse(),
57fTOFResponse(),
e96b9916 58fEMCALResponse(),
fd21ec8d 59fRange(5.),
60fITSPIDmethod(kITSTruncMean),
4ec8e76d 61fIsMC(isMC),
1c9d11be 62fCachePID(kTRUE),
4ec8e76d 63fOADBPath(),
00a38d07 64fCustomTPCpidResponse(),
4ec8e76d 65fBeamType("PP"),
66fLHCperiod(),
67fMCperiodTPC(),
fd21ec8d 68fMCperiodUser(),
ea235c90 69fCurrentFile(),
4ec8e76d 70fRecoPass(0),
fd21ec8d 71fRecoPassUser(-1),
4ec8e76d 72fRun(0),
73fOldRun(0),
78cbd205 74fResT0A(75.),
75fResT0C(65.),
76fResT0AC(55.),
644666df 77fArrPidResponseMaster(NULL),
78fResolutionCorrection(NULL),
79fOADBvoltageMaps(NULL),
f84b18dd 80fUseTPCEtaCorrection(kFALSE),//TODO: In future, default kTRUE
644666df 81fTRDPIDResponseObject(NULL),
0b39f221 82fTOFtail(1.1),
644666df 83fTOFPIDParams(NULL),
84fEMCALPIDParams(NULL),
85fCurrentEvent(NULL),
539a5a59 86fCurrCentrality(0.0),
87fTuneMConData(kFALSE)
4ec8e76d 88{
89 //
90 // default ctor
91 //
a635821f 92 AliLog::SetClassDebugLevel("AliPIDResponse",0);
93 AliLog::SetClassDebugLevel("AliESDpid",0);
94 AliLog::SetClassDebugLevel("AliAODpidUtil",0);
ea235c90 95
4ec8e76d 96}
97
98//______________________________________________________________________________
99AliPIDResponse::~AliPIDResponse()
100{
101 //
102 // dtor
103 //
00a38d07 104 delete fArrPidResponseMaster;
105 delete fTRDPIDResponseObject;
106 delete fTOFPIDParams;
4ec8e76d 107}
108
109//______________________________________________________________________________
110AliPIDResponse::AliPIDResponse(const AliPIDResponse &other) :
111TNamed(other),
112fITSResponse(other.fITSResponse),
113fTPCResponse(other.fTPCResponse),
114fTRDResponse(other.fTRDResponse),
115fTOFResponse(other.fTOFResponse),
e96b9916 116fEMCALResponse(other.fEMCALResponse),
fd21ec8d 117fRange(other.fRange),
118fITSPIDmethod(other.fITSPIDmethod),
4ec8e76d 119fIsMC(other.fIsMC),
1c9d11be 120fCachePID(other.fCachePID),
4ec8e76d 121fOADBPath(other.fOADBPath),
00a38d07 122fCustomTPCpidResponse(other.fCustomTPCpidResponse),
4ec8e76d 123fBeamType("PP"),
124fLHCperiod(),
125fMCperiodTPC(),
fd21ec8d 126fMCperiodUser(other.fMCperiodUser),
ea235c90 127fCurrentFile(),
4ec8e76d 128fRecoPass(0),
fd21ec8d 129fRecoPassUser(other.fRecoPassUser),
4ec8e76d 130fRun(0),
131fOldRun(0),
78cbd205 132fResT0A(75.),
133fResT0C(65.),
134fResT0AC(55.),
644666df 135fArrPidResponseMaster(NULL),
136fResolutionCorrection(NULL),
137fOADBvoltageMaps(NULL),
f84b18dd 138fUseTPCEtaCorrection(other.fUseTPCEtaCorrection),
644666df 139fTRDPIDResponseObject(NULL),
0b39f221 140fTOFtail(1.1),
644666df 141fTOFPIDParams(NULL),
142fEMCALPIDParams(NULL),
143fCurrentEvent(NULL),
539a5a59 144fCurrCentrality(0.0),
145fTuneMConData(kFALSE)
4ec8e76d 146{
147 //
148 // copy ctor
149 //
150}
151
152//______________________________________________________________________________
153AliPIDResponse& AliPIDResponse::operator=(const AliPIDResponse &other)
154{
155 //
156 // copy ctor
157 //
158 if(this!=&other) {
159 delete fArrPidResponseMaster;
160 TNamed::operator=(other);
161 fITSResponse=other.fITSResponse;
162 fTPCResponse=other.fTPCResponse;
163 fTRDResponse=other.fTRDResponse;
164 fTOFResponse=other.fTOFResponse;
e96b9916 165 fEMCALResponse=other.fEMCALResponse;
fd21ec8d 166 fRange=other.fRange;
167 fITSPIDmethod=other.fITSPIDmethod;
4ec8e76d 168 fOADBPath=other.fOADBPath;
00a38d07 169 fCustomTPCpidResponse=other.fCustomTPCpidResponse;
4ec8e76d 170 fIsMC=other.fIsMC;
1c9d11be 171 fCachePID=other.fCachePID;
4ec8e76d 172 fBeamType="PP";
173 fLHCperiod="";
174 fMCperiodTPC="";
fd21ec8d 175 fMCperiodUser=other.fMCperiodUser;
ea235c90 176 fCurrentFile="";
4ec8e76d 177 fRecoPass=0;
fd21ec8d 178 fRecoPassUser=other.fRecoPassUser;
4ec8e76d 179 fRun=0;
180 fOldRun=0;
78cbd205 181 fResT0A=75.;
182 fResT0C=65.;
183 fResT0AC=55.;
644666df 184 fArrPidResponseMaster=NULL;
185 fResolutionCorrection=NULL;
186 fOADBvoltageMaps=NULL;
f84b18dd 187 fUseTPCEtaCorrection=other.fUseTPCEtaCorrection;
644666df 188 fTRDPIDResponseObject=NULL;
189 fEMCALPIDParams=NULL;
0b39f221 190 fTOFtail=1.1;
644666df 191 fTOFPIDParams=NULL;
e96b9916 192 fCurrentEvent=other.fCurrentEvent;
bd58d4b9 193
4ec8e76d 194 }
195 return *this;
196}
197
fd21ec8d 198//______________________________________________________________________________
199Float_t AliPIDResponse::NumberOfSigmas(EDetCode detCode, const AliVParticle *track, AliPID::EParticleType type) const
200{
201 //
202 // NumberOfSigmas for 'detCode'
203 //
204
205 switch (detCode){
206 case kDetITS: return NumberOfSigmasITS(track, type); break;
207 case kDetTPC: return NumberOfSigmasTPC(track, type); break;
208 case kDetTOF: return NumberOfSigmasTOF(track, type); break;
00a38d07 209 case kDetEMCAL: return NumberOfSigmasEMCAL(track, type); break;
fd21ec8d 210 default: return -999.;
211 }
212
213}
214
e96b9916 215//______________________________________________________________________________
00a38d07 216Float_t AliPIDResponse::NumberOfSigmas(EDetector detCode, const AliVParticle *track, AliPID::EParticleType type) const
217{
218 //
219 // NumberOfSigmas for 'detCode'
220 //
221 return NumberOfSigmas((EDetCode)(1<<detCode), track, type);
222}
223
1c9d11be 224//______________________________________________________________________________
225// public buffered versions of the PID calculation
226//
227
00a38d07 228//______________________________________________________________________________
229Float_t AliPIDResponse::NumberOfSigmasITS(const AliVParticle *vtrack, AliPID::EParticleType type) const
230{
231 //
232 // Calculate the number of sigmas in the ITS
233 //
234
235 AliVTrack *track=(AliVTrack*)vtrack;
236
237 // look for cached value first
1c9d11be 238 const AliDetectorPID *detPID=track->GetDetectorPID();
239 const EDetector detector=kITS;
240
241 if ( detPID && detPID->HasNumberOfSigmas(detector)){
242 return detPID->GetNumberOfSigmas(detector, type);
243 } else if (fCachePID) {
244 FillTrackDetectorPID(track, detector);
245 detPID=track->GetDetectorPID();
246 return detPID->GetNumberOfSigmas(detector, type);
00a38d07 247 }
00a38d07 248
1c9d11be 249 return GetNumberOfSigmasITS(track, type);
00a38d07 250}
251
252//______________________________________________________________________________
253Float_t AliPIDResponse::NumberOfSigmasTPC(const AliVParticle *vtrack, AliPID::EParticleType type) const
254{
255 //
256 // Calculate the number of sigmas in the TPC
257 //
258
259 AliVTrack *track=(AliVTrack*)vtrack;
260
261 // look for cached value first
1c9d11be 262 const AliDetectorPID *detPID=track->GetDetectorPID();
263 const EDetector detector=kTPC;
264
265 if ( detPID && detPID->HasNumberOfSigmas(detector)){
266 return detPID->GetNumberOfSigmas(detector, type);
267 } else if (fCachePID) {
268 FillTrackDetectorPID(track, detector);
269 detPID=track->GetDetectorPID();
270 return detPID->GetNumberOfSigmas(detector, type);
00a38d07 271 }
272
1c9d11be 273 return GetNumberOfSigmasTPC(track, type);
00a38d07 274}
275
644666df 276//______________________________________________________________________________
277Float_t AliPIDResponse::NumberOfSigmasTPC( const AliVParticle *vtrack,
278 AliPID::EParticleType type,
f84b18dd 279 AliTPCPIDResponse::ETPCdEdxSource dedxSource) const
644666df 280{
281 //get number of sigmas according the selected TPC gain configuration scenario
282 const AliVTrack *track=static_cast<const AliVTrack*>(vtrack);
283
f84b18dd 284 Float_t nSigma=fTPCResponse.GetNumberOfSigmas(track, type, dedxSource, fUseTPCEtaCorrection);
644666df 285
286 return nSigma;
287}
288
00a38d07 289//______________________________________________________________________________
1c9d11be 290Float_t AliPIDResponse::NumberOfSigmasTOF(const AliVParticle *vtrack, AliPID::EParticleType type) const
00a38d07 291{
292 //
1c9d11be 293 // Calculate the number of sigmas in the TOF
00a38d07 294 //
295
296 AliVTrack *track=(AliVTrack*)vtrack;
1c9d11be 297
00a38d07 298 // look for cached value first
1c9d11be 299 const AliDetectorPID *detPID=track->GetDetectorPID();
300 const EDetector detector=kTOF;
301
302 if ( detPID && detPID->HasNumberOfSigmas(detector)){
303 return detPID->GetNumberOfSigmas(detector, type);
304 } else if (fCachePID) {
305 FillTrackDetectorPID(track, detector);
306 detPID=track->GetDetectorPID();
307 return detPID->GetNumberOfSigmas(detector, type);
00a38d07 308 }
309
1c9d11be 310 return GetNumberOfSigmasTOF(track, type);
311}
e96b9916 312
1c9d11be 313//______________________________________________________________________________
314Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVParticle *vtrack, AliPID::EParticleType type) const
315{
316 //
317 // Calculate the number of sigmas in the EMCAL
318 //
e96b9916 319
1c9d11be 320 AliVTrack *track=(AliVTrack*)vtrack;
321
322 // look for cached value first
323 const AliDetectorPID *detPID=track->GetDetectorPID();
324 const EDetector detector=kEMCAL;
325
326 if ( detPID && detPID->HasNumberOfSigmas(detector)){
327 return detPID->GetNumberOfSigmas(detector, type);
328 } else if (fCachePID) {
329 FillTrackDetectorPID(track, detector);
330 detPID=track->GetDetectorPID();
331 return detPID->GetNumberOfSigmas(detector, type);
e96b9916 332 }
6d0064aa 333
1c9d11be 334 return GetNumberOfSigmasEMCAL(track, type);
e96b9916 335}
336
6d0064aa 337//______________________________________________________________________________
1c9d11be 338Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVParticle *vtrack, AliPID::EParticleType type, Double_t &eop, Double_t showershape[4]) const
339{
340 //
341 // emcal nsigma with eop and showershape
342 //
00a38d07 343 AliVTrack *track=(AliVTrack*)vtrack;
344
6d0064aa 345 AliVCluster *matchedClus = NULL;
346
347 Double_t mom = -1.;
348 Double_t pt = -1.;
349 Double_t EovP = -1.;
350 Double_t fClsE = -1.;
32fa24d6 351
352 // initialize eop and shower shape parameters
353 eop = -1.;
354 for(Int_t i = 0; i < 4; i++){
355 showershape[i] = -1.;
356 }
6d0064aa 357
358 Int_t nMatchClus = -1;
359 Int_t charge = 0;
360
361 // Track matching
362 nMatchClus = track->GetEMCALcluster();
363 if(nMatchClus > -1){
364
365 mom = track->P();
366 pt = track->Pt();
367 charge = track->Charge();
368
369 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
370
371 if(matchedClus){
372
373 // matched cluster is EMCAL
374 if(matchedClus->IsEMCAL()){
375
376 fClsE = matchedClus->E();
377 EovP = fClsE/mom;
378
379 // fill used EMCAL variables here
380 eop = EovP; // E/p
381 showershape[0] = matchedClus->GetNCells(); // number of cells in cluster
382 showershape[1] = matchedClus->GetM02(); // long axis
383 showershape[2] = matchedClus->GetM20(); // short axis
384 showershape[3] = matchedClus->GetDispersion(); // dispersion
1c9d11be 385
386 // look for cached value first
387 const AliDetectorPID *detPID=track->GetDetectorPID();
388 const EDetector detector=kEMCAL;
389
390 if ( detPID && detPID->HasNumberOfSigmas(detector)){
391 return detPID->GetNumberOfSigmas(detector, type);
392 } else if (fCachePID) {
393 FillTrackDetectorPID(track, detector);
394 detPID=track->GetDetectorPID();
395 return detPID->GetNumberOfSigmas(detector, type);
396 }
397
398 // NSigma value really meaningful only for electrons!
399 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
6d0064aa 400 }
401 }
402 }
403 return -999;
404}
405
406
fd21ec8d 407//______________________________________________________________________________
f84b18dd 408AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetCode detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
fd21ec8d 409{
410 //
411 // Compute PID response of 'detCode'
412 //
413
414 switch (detCode){
415 case kDetITS: return ComputeITSProbability(track, nSpecies, p); break;
416 case kDetTPC: return ComputeTPCProbability(track, nSpecies, p); break;
fd21ec8d 417 case kDetTRD: return ComputeTRDProbability(track, nSpecies, p); break;
00a38d07 418 case kDetTOF: return ComputeTOFProbability(track, nSpecies, p); break;
fd21ec8d 419 case kDetPHOS: return ComputePHOSProbability(track, nSpecies, p); break;
420 case kDetEMCAL: return ComputeEMCALProbability(track, nSpecies, p); break;
421 case kDetHMPID: return ComputeHMPIDProbability(track, nSpecies, p); break;
422 default: return kDetNoSignal;
423 }
424}
425
00a38d07 426//______________________________________________________________________________
427AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetector detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
428{
429 //
430 // Compute PID response of 'detCode'
431 //
432
433 return ComputePIDProbability((EDetCode)(1<<detCode),track,nSpecies,p);
434}
435
fd21ec8d 436//______________________________________________________________________________
437AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeITSProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
438{
439 //
440 // Compute PID response for the ITS
441 //
442
00a38d07 443 // look for cached value first
1c9d11be 444 const AliDetectorPID *detPID=track->GetDetectorPID();
445 const EDetector detector=kITS;
446
447 if ( detPID && detPID->HasRawProbabilitiy(detector)){
448 return detPID->GetRawProbability(detector, p, nSpecies);
449 } else if (fCachePID) {
450 FillTrackDetectorPID(track, detector);
451 detPID=track->GetDetectorPID();
452 return detPID->GetRawProbability(detector, p, nSpecies);
fd21ec8d 453 }
454
1c9d11be 455 return GetComputeITSProbability(track, nSpecies, p);
fd21ec8d 456}
457//______________________________________________________________________________
458AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTPCProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
459{
460 //
461 // Compute PID response for the TPC
462 //
00a38d07 463
464 // look for cached value first
1c9d11be 465 const AliDetectorPID *detPID=track->GetDetectorPID();
466 const EDetector detector=kTPC;
467
468 if ( detPID && detPID->HasRawProbabilitiy(detector)){
469 return detPID->GetRawProbability(detector, p, nSpecies);
470 } else if (fCachePID) {
471 FillTrackDetectorPID(track, detector);
472 detPID=track->GetDetectorPID();
473 return detPID->GetRawProbability(detector, p, nSpecies);
00a38d07 474 }
475
1c9d11be 476 return GetComputeTPCProbability(track, nSpecies, p);
fd21ec8d 477}
478//______________________________________________________________________________
479AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTOFProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
480{
481 //
482 // Compute PID response for the
483 //
00a38d07 484
1c9d11be 485 const AliDetectorPID *detPID=track->GetDetectorPID();
486 const EDetector detector=kTOF;
fd21ec8d 487
1c9d11be 488 if ( detPID && detPID->HasRawProbabilitiy(detector)){
489 return detPID->GetRawProbability(detector, p, nSpecies);
490 } else if (fCachePID) {
491 FillTrackDetectorPID(track, detector);
492 detPID=track->GetDetectorPID();
493 return detPID->GetRawProbability(detector, p, nSpecies);
fd21ec8d 494 }
1c9d11be 495
496 return GetComputeTOFProbability(track, nSpecies, p);
fd21ec8d 497}
498//______________________________________________________________________________
bd58d4b9 499AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[],AliTRDPIDResponse::ETRDPIDMethod PIDmethod) const
fd21ec8d 500{
501 //
502 // Compute PID response for the
1c9d11be 503 //
00a38d07 504
1c9d11be 505 const AliDetectorPID *detPID=track->GetDetectorPID();
506 const EDetector detector=kTRD;
ea235c90 507
1c9d11be 508 // chacke only for the default method (1d at the moment)
509 if (PIDmethod!=AliTRDPIDResponse::kLQ1D) return GetComputeTRDProbability(track, nSpecies, p, PIDmethod);
510
511 if ( detPID && detPID->HasRawProbabilitiy(detector)){
512 return detPID->GetRawProbability(detector, p, nSpecies);
513 } else if (fCachePID) {
514 FillTrackDetectorPID(track, detector);
515 detPID=track->GetDetectorPID();
516 return detPID->GetRawProbability(detector, p, nSpecies);
ea235c90 517 }
1c9d11be 518
519 return GetComputeTRDProbability(track, nSpecies, p);
fd21ec8d 520}
521//______________________________________________________________________________
e96b9916 522AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeEMCALProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
fd21ec8d 523{
524 //
525 // Compute PID response for the EMCAL
526 //
00a38d07 527
1c9d11be 528 const AliDetectorPID *detPID=track->GetDetectorPID();
529 const EDetector detector=kEMCAL;
530
531 if ( detPID && detPID->HasRawProbabilitiy(detector)){
532 return detPID->GetRawProbability(detector, p, nSpecies);
533 } else if (fCachePID) {
534 FillTrackDetectorPID(track, detector);
535 detPID=track->GetDetectorPID();
536 return detPID->GetRawProbability(detector, p, nSpecies);
00a38d07 537 }
1c9d11be 538
539 return GetComputeEMCALProbability(track, nSpecies, p);
540}
541//______________________________________________________________________________
542AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePHOSProbability (const AliVTrack */*track*/, Int_t nSpecies, Double_t p[]) const
543{
544 //
545 // Compute PID response for the PHOS
546 //
547
548 // look for cached value first
549// if (track->GetDetectorPID()){
550// return track->GetDetectorPID()->GetRawProbability(kPHOS, p, nSpecies);
551// }
552
553 // set flat distribution (no decision)
00a38d07 554 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1c9d11be 555 return kDetNoSignal;
556}
557//______________________________________________________________________________
558AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeHMPIDProbability(const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
559{
560 //
561 // Compute PID response for the HMPID
562 //
fd21ec8d 563
1c9d11be 564 const AliDetectorPID *detPID=track->GetDetectorPID();
565 const EDetector detector=kHMPID;
e96b9916 566
1c9d11be 567 if ( detPID && detPID->HasRawProbabilitiy(detector)){
568 return detPID->GetRawProbability(detector, p, nSpecies);
569 } else if (fCachePID) {
570 FillTrackDetectorPID(track, detector);
571 detPID=track->GetDetectorPID();
572 return detPID->GetRawProbability(detector, p, nSpecies);
e96b9916 573 }
00a38d07 574
1c9d11be 575 return GetComputeHMPIDProbability(track, nSpecies, p);
fd21ec8d 576}
577
4ec8e76d 578//______________________________________________________________________________
00a38d07 579void AliPIDResponse::InitialiseEvent(AliVEvent *event, Int_t pass, Int_t run)
4ec8e76d 580{
581 //
582 // Apply settings for the current event
583 //
584 fRecoPass=pass;
e96b9916 585
78cbd205 586
644666df 587 fCurrentEvent=NULL;
4ec8e76d 588 if (!event) return;
e96b9916 589 fCurrentEvent=event;
00a38d07 590 if (run>0) fRun=run;
591 else fRun=event->GetRunNumber();
4ec8e76d 592
593 if (fRun!=fOldRun){
594 ExecNewRun();
595 fOldRun=fRun;
596 }
597
598 //TPC resolution parametrisation PbPb
599 if ( fResolutionCorrection ){
600 Double_t corrSigma=fResolutionCorrection->Eval(GetTPCMultiplicityBin(event));
601 fTPCResponse.SetSigma(3.79301e-03*corrSigma, 2.21280e+04);
602 }
603
604 //TOF resolution
b79db598 605 SetTOFResponse(event, (AliPIDResponse::EStartTimeType_t)fTOFPIDParams->GetStartTimeMethod());
606
80f28562 607
608 // Get and set centrality
609 AliCentrality *centrality = event->GetCentrality();
610 if(centrality){
611 fCurrCentrality = centrality->GetCentralityPercentile("V0M");
612 }
613 else{
614 fCurrCentrality = -1;
615 }
4ec8e76d 616}
617
618//______________________________________________________________________________
619void AliPIDResponse::ExecNewRun()
620{
621 //
622 // Things to Execute upon a new run
623 //
624 SetRecoInfo();
625
626 SetITSParametrisation();
627
628 SetTPCPidResponseMaster();
629 SetTPCParametrisation();
f84b18dd 630 SetTPCEtaMaps();
53d016dc 631
632 SetTRDPidResponseMaster();
633 InitializeTRDResponse();
b2138b40 634
635 SetEMCALPidResponseMaster();
636 InitializeEMCALResponse();
4ec8e76d 637
b79db598 638 SetTOFPidResponseMaster();
639 InitializeTOFResponse();
644666df 640
641 if (fCurrentEvent) fTPCResponse.SetMagField(fCurrentEvent->GetMagneticField());
4ec8e76d 642}
643
1c9d11be 644//______________________________________________________________________________
4ec8e76d 645Double_t AliPIDResponse::GetTPCMultiplicityBin(const AliVEvent * const event)
646{
647 //
648 // Get TPC multiplicity in bins of 150
649 //
650
651 const AliVVertex* vertexTPC = event->GetPrimaryVertex();
652 Double_t tpcMulti=0.;
653 if(vertexTPC){
654 Double_t vertexContribTPC=vertexTPC->GetNContributors();
655 tpcMulti=vertexContribTPC/150.;
656 if (tpcMulti>20.) tpcMulti=20.;
657 }
658
659 return tpcMulti;
660}
661
662//______________________________________________________________________________
663void AliPIDResponse::SetRecoInfo()
664{
665 //
666 // Set reconstruction information
667 //
668
669 //reset information
670 fLHCperiod="";
671 fMCperiodTPC="";
672
673 fBeamType="";
674
675 fBeamType="PP";
676
1436d6bb 677 TPRegexp reg(".*(LHC1[1-2][a-z]+[0-9]+[a-z_]*)/.*");
a78fd045 678 TPRegexp reg12a17(".*(LHC12a17[a-z]+)/.*");
1436d6bb 679
4ec8e76d 680 //find the period by run number (UGLY, but not stored in ESD and AOD... )
681 if (fRun>=114737&&fRun<=117223) { fLHCperiod="LHC10B"; fMCperiodTPC="LHC10D1"; }
682 else if (fRun>=118503&&fRun<=121040) { fLHCperiod="LHC10C"; fMCperiodTPC="LHC10D1"; }
683 else if (fRun>=122195&&fRun<=126437) { fLHCperiod="LHC10D"; fMCperiodTPC="LHC10F6A"; }
99e9d5ec 684 else if (fRun>=127710&&fRun<=130850) { fLHCperiod="LHC10E"; fMCperiodTPC="LHC10F6A"; }
4ec8e76d 685 else if (fRun>=133004&&fRun<=135029) { fLHCperiod="LHC10F"; fMCperiodTPC="LHC10F6A"; }
686 else if (fRun>=135654&&fRun<=136377) { fLHCperiod="LHC10G"; fMCperiodTPC="LHC10F6A"; }
12d3abbc 687 else if (fRun>=136851&&fRun<=139846) {
ea235c90 688 fLHCperiod="LHC10H";
689 fMCperiodTPC="LHC10H8";
690 if (reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11A10";
691 fBeamType="PBPB";
692 }
12d3abbc 693 else if (fRun>=139847&&fRun<=146974) { fLHCperiod="LHC11A"; fMCperiodTPC="LHC10F6A"; }
694 //TODO: periods 11B (146975-150721), 11C (150722-155837) are not yet treated assume 11d for the moment
695 else if (fRun>=146975&&fRun<=155837) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
696 else if (fRun>=155838&&fRun<=159649) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
697 // also for 11e (159650-162750),f(162751-165771) use 11d
698 else if (fRun>=159650&&fRun<=162750) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
699 else if (fRun>=162751&&fRun<=165771) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
00a38d07 700
12d3abbc 701 else if (fRun>=165772 && fRun<=170718) {
3077a03d 702 fLHCperiod="LHC11H";
703 fMCperiodTPC="LHC11A10";
704 fBeamType="PBPB";
a78fd045 705 if (reg12a17.MatchB(fCurrentFile)) fMCperiodTPC="LHC12A17";
3077a03d 706 }
8af51a65 707 if (fRun>=170719 && fRun<=177311) { fLHCperiod="LHC12A"; fBeamType="PP"; /*fMCperiodTPC="";*/ }
708 // for the moment use LHC12b parameters up to LHC12e
709 if (fRun>=177312 /*&& fRun<=179356*/) { fLHCperiod="LHC12B"; fBeamType="PP"; /*fMCperiodTPC="";*/ }
710// if (fRun>=179357 && fRun<=183173) { fLHCperiod="LHC12C"; fBeamType="PP"; /*fMCperiodTPC="";*/ }
711// if (fRun>=183174 && fRun<=186345) { fLHCperiod="LHC12D"; fBeamType="PP"; /*fMCperiodTPC="";*/ }
712// if (fRun>=186346 && fRun<=186635) { fLHCperiod="LHC12E"; fBeamType="PP"; /*fMCperiodTPC="";*/ }
713
714// if (fRun>=186636 && fRun<=188166) { fLHCperiod="LHC12F"; fBeamType="PP"; /*fMCperiodTPC="";*/ }
715// if (fRun >= 188167 && fRun <= 188355 ) { fLHCperiod="LHC12G"; fBeamType="PP"; /*fMCperiodTPC="";*/ }
716// if (fRun >= 188356 && fRun <= 188503 ) { fLHCperiod="LHC12G"; fBeamType="PPB"; /*fMCperiodTPC="";*/ }
717// for the moment use 12g parametrisation for all full gain runs (LHC12f+)
718 if (fRun >= 186636 ) { fLHCperiod="LHC12G"; fBeamType="PPB"; /*fMCperiodTPC="";*/ }
80ab5635 719
720 //exception new pp MC productions from 2011
f85a3764 721 if ( (fBeamType=="PP" || fBeamType=="PPB") && reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11B2";
4a527e08 722 // exception for 11f1
00a38d07 723 if (fCurrentFile.Contains("LHC11f1/")) fMCperiodTPC="LHC11F1";
4ec8e76d 724}
725
726//______________________________________________________________________________
727void AliPIDResponse::SetITSParametrisation()
728{
729 //
730 // Set the ITS parametrisation
731 //
732}
733
f84b18dd 734
735//______________________________________________________________________________
736void AliPIDResponse::AddPointToHyperplane(TH2D* h, TLinearFitter* linExtrapolation, Int_t binX, Int_t binY)
737{
738 if (h->GetBinContent(binX, binY) <= 1e-4)
739 return; // Reject bins without content (within some numerical precision) or with strange content
740
741 Double_t coord[2] = {0, 0};
742 coord[0] = h->GetXaxis()->GetBinCenter(binX);
743 coord[1] = h->GetYaxis()->GetBinCenter(binY);
744 Double_t binError = h->GetBinError(binX, binY);
745 if (binError <= 0) {
746 binError = 1000; // Should not happen because bins without content are rejected for the map (TH2D* h)
747 printf("ERROR: This should never happen: Trying to add bin in addPointToHyperplane with error not set....\n");
748 }
749 linExtrapolation->AddPoint(coord, h->GetBinContent(binX, binY, binError));
750}
751
752
753//______________________________________________________________________________
754TH2D* AliPIDResponse::RefineHistoViaLinearInterpolation(TH2D* h, Double_t refineFactorX, Double_t refineFactorY)
755{
756 if (!h)
757 return 0x0;
758
759 // Interpolate to finer map
760 TLinearFitter* linExtrapolation = new TLinearFitter(2, "hyp2", "");
761
762 Double_t upperMapBoundY = h->GetYaxis()->GetBinUpEdge(h->GetYaxis()->GetNbins());
763 Double_t lowerMapBoundY = h->GetYaxis()->GetBinLowEdge(1);
764 Int_t nBinsX = 20;
765 // Binning was find to yield good results, if 40 bins are chosen for the range 0.0016 to 0.02. For the new variable range,
766 // scale the number of bins correspondingly
767 Int_t nBinsY = TMath::Nint((upperMapBoundY - lowerMapBoundY) / (0.02 - lowerMapBoundY) * 40);
768 Int_t nBinsXrefined = nBinsX * refineFactorX;
769 Int_t nBinsYrefined = nBinsY * refineFactorY;
770
771 TH2D* hRefined = new TH2D(Form("%s_refined", h->GetName()), Form("%s (refined)", h->GetTitle()),
772 nBinsXrefined, h->GetXaxis()->GetBinLowEdge(1), h->GetXaxis()->GetBinUpEdge(h->GetXaxis()->GetNbins()),
773 nBinsYrefined, lowerMapBoundY, upperMapBoundY);
774
775 for (Int_t binX = 1; binX <= nBinsXrefined; binX++) {
776 for (Int_t binY = 1; binY <= nBinsYrefined; binY++) {
777
778 hRefined->SetBinContent(binX, binY, 1); // Default value is 1
779
780 Double_t centerX = hRefined->GetXaxis()->GetBinCenter(binX);
781 Double_t centerY = hRefined->GetYaxis()->GetBinCenter(binY);
782
f85a3764 783 /*
f84b18dd 784 linExtrapolation->ClearPoints();
785
786 // For interpolation: Just take the corresponding bin from the old histo.
787 // For extrapolation: take the last available bin from the old histo.
788 // If the boundaries are to be skipped, also skip the corresponding bins
789 Int_t oldBinX = h->GetXaxis()->FindBin(centerX);
790 if (oldBinX < 1)
791 oldBinX = 1;
792 if (oldBinX > nBinsX)
793 oldBinX = nBinsX;
794
795 Int_t oldBinY = h->GetYaxis()->FindBin(centerY);
796 if (oldBinY < 1)
797 oldBinY = 1;
798 if (oldBinY > nBinsY)
799 oldBinY = nBinsY;
800
801 // Neighbours left column
802 if (oldBinX >= 2) {
803 if (oldBinY >= 2) {
804 AddPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY - 1);
805 }
806
807 AddPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY);
808
809 if (oldBinY < nBinsY) {
810 AddPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY + 1);
811 }
812 }
813
814 // Neighbours (and point itself) same column
815 if (oldBinY >= 2) {
816 AddPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY - 1);
817 }
818
819 AddPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY);
820
821 if (oldBinY < nBinsY) {
822 AddPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY + 1);
823 }
824
825 // Neighbours right column
826 if (oldBinX < nBinsX) {
827 if (oldBinY >= 2) {
828 AddPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY - 1);
829 }
830
831 AddPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY);
832
833 if (oldBinY < nBinsY) {
834 AddPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY + 1);
835 }
836 }
837
838
839 // Fit 2D-hyperplane
840 if (linExtrapolation->GetNpoints() <= 0)
841 continue;
842
843 if (linExtrapolation->Eval() != 0)// EvalRobust -> Takes much, much, [...], much more time (~hours instead of seconds)
844 continue;
845
846 // Fill the bin of the refined histogram with the extrapolated value
847 Double_t interpolatedValue = linExtrapolation->GetParameter(0) + linExtrapolation->GetParameter(1) * centerX
848 + linExtrapolation->GetParameter(2) * centerY;
849 */
f85a3764 850 Double_t interpolatedValue = h->Interpolate(centerX, centerY) ;
f84b18dd 851 hRefined->SetBinContent(binX, binY, interpolatedValue);
852 }
853 }
854
855 delete linExtrapolation;
856
857 return hRefined;
858}
859
860//______________________________________________________________________________
861void AliPIDResponse::SetTPCEtaMaps(Double_t refineFactorMapX, Double_t refineFactorMapY,
862 Double_t refineFactorSigmaMapX, Double_t refineFactorSigmaMapY)
863{
864 //
865 // Load the TPC eta correction maps from the OADB
866 //
867
f85a3764 868 if (fUseTPCEtaCorrection == kFALSE) {
869 // Disable eta correction via setting no maps
870 if (!fTPCResponse.SetEtaCorrMap(0x0))
871 AliInfo("Request to disable TPC eta correction -> Eta correction has been disabled");
872 else
873 AliError("Request to disable TPC eta correction -> Some error occured when unloading the correction maps");
874
875 if (!fTPCResponse.SetSigmaParams(0x0, 0))
876 AliInfo("Request to disable TPC eta correction -> Using old parametrisation for sigma");
877 else
878 AliError("Request to disable TPC eta correction -> Some error occured when unloading the sigma maps");
879
880 return;
881 }
882
f84b18dd 883 TString dataType = "DATA";
884 TString period = fLHCperiod.IsNull() ? "No period information" : fLHCperiod;
885
886 if (fIsMC) {
f85a3764 887 if (!fTuneMConData) {
888 period=fMCperiodTPC;
889 dataType="MC";
890 }
f84b18dd 891 fRecoPass = 1;
892
f85a3764 893 if (!fTuneMConData && fMCperiodTPC.IsNull()) {
f84b18dd 894 AliFatal("MC detected, but no MC period set -> Not changing eta maps!");
895 return;
896 }
f84b18dd 897 }
f85a3764 898
899 Int_t recopass = fRecoPass;
900 if (fTuneMConData)
901 recopass = fRecoPassUser;
f84b18dd 902
f85a3764 903 TString defaultObj = Form("Default_%s_pass%d", dataType.Data(), recopass);
f84b18dd 904
f85a3764 905 AliInfo(Form("Current period and reco pass: %s.pass%d", period.Data(), recopass));
f84b18dd 906
907 // Invalidate old maps
908 fTPCResponse.SetEtaCorrMap(0x0);
909 fTPCResponse.SetSigmaParams(0x0, 0);
910
911 // Load the eta correction maps
f85a3764 912 AliOADBContainer etaMapsCont(Form("TPCetaMaps_%s_pass%d", dataType.Data(), recopass));
f84b18dd 913
914 Int_t statusCont = etaMapsCont.InitFromFile(Form("%s/COMMON/PID/data/TPCetaMaps.root", fOADBPath.Data()),
f85a3764 915 Form("TPCetaMaps_%s_pass%d", dataType.Data(), recopass));
f84b18dd 916 if (statusCont) {
917 AliError("Failed initializing TPC eta correction maps from OADB -> Disabled eta correction");
918 }
919 else {
920 AliInfo(Form("Loading TPC eta correction map from %s/COMMON/PID/data/TPCetaMaps.root", fOADBPath.Data()));
921
922 TH2D* etaMap = 0x0;
923
f85a3764 924 if (fIsMC && !fTuneMConData) {
925 TString searchMap = Form("TPCetaMaps_%s_%s_pass%d", dataType.Data(), period.Data(), recopass);
f84b18dd 926 etaMap = dynamic_cast<TH2D *>(etaMapsCont.GetDefaultObject(searchMap.Data()));
927 if (!etaMap) {
928 // Try default object
929 etaMap = dynamic_cast<TH2D *>(etaMapsCont.GetDefaultObject(defaultObj.Data()));
930 }
931 }
932 else {
933 etaMap = dynamic_cast<TH2D *>(etaMapsCont.GetObject(fRun, defaultObj.Data()));
934 }
935
936
937 if (!etaMap) {
938 AliError(Form("TPC eta correction map not found for run %d and also no default map found -> Disabled eta correction!!!", fRun));
939 }
940 else {
941 TH2D* etaMapRefined = RefineHistoViaLinearInterpolation(etaMap, refineFactorMapX, refineFactorMapY);
942
943 if (etaMapRefined) {
944 if (!fTPCResponse.SetEtaCorrMap(etaMapRefined)) {
945 AliError(Form("Failed to set TPC eta correction map for run %d -> Disabled eta correction!!!", fRun));
946 fTPCResponse.SetEtaCorrMap(0x0);
947 }
948 else {
949 AliInfo(Form("Loaded TPC eta correction map (refine factors %.2f/%.2f) from %s/COMMON/PID/data/TPCetaMaps.root: %s",
950 refineFactorMapX, refineFactorMapY, fOADBPath.Data(), fTPCResponse.GetEtaCorrMap()->GetTitle()));
951 }
952
953 delete etaMapRefined;
954 }
955 else {
956 AliError(Form("Failed to set TPC eta correction map for run %d (map was loaded, but couldn't be refined) -> Disabled eta correction!!!", fRun));
957 }
958 }
959 }
960
961 // Load the sigma parametrisation (1/dEdx vs tanTheta_local (~eta))
f85a3764 962 AliOADBContainer etaSigmaMapsCont(Form("TPCetaSigmaMaps_%s_pass%d", dataType.Data(), recopass));
f84b18dd 963
964 statusCont = etaSigmaMapsCont.InitFromFile(Form("%s/COMMON/PID/data/TPCetaMaps.root", fOADBPath.Data()),
f85a3764 965 Form("TPCetaSigmaMaps_%s_pass%d", dataType.Data(), recopass));
f84b18dd 966 if (statusCont) {
967 AliError("Failed initializing TPC eta sigma maps from OADB -> Using old sigma parametrisation");
968 }
969 else {
970 AliInfo(Form("Loading TPC eta sigma map from %s/COMMON/PID/data/TPCetaMaps.root", fOADBPath.Data()));
971
972 TObjArray* etaSigmaPars = 0x0;
973
f85a3764 974 if (fIsMC && !fTuneMConData) {
975 TString searchMap = Form("TPCetaSigmaMaps_%s_%s_pass%d", dataType.Data(), period.Data(), recopass);
f84b18dd 976 etaSigmaPars = dynamic_cast<TObjArray *>(etaSigmaMapsCont.GetDefaultObject(searchMap.Data()));
977 if (!etaSigmaPars) {
978 // Try default object
979 etaSigmaPars = dynamic_cast<TObjArray *>(etaSigmaMapsCont.GetDefaultObject(defaultObj.Data()));
980 }
981 }
982 else {
983 etaSigmaPars = dynamic_cast<TObjArray *>(etaSigmaMapsCont.GetObject(fRun, defaultObj.Data()));
984 }
985
986 if (!etaSigmaPars) {
987 AliError(Form("TPC eta sigma parametrisation not found for run %d -> Using old sigma parametrisation!!!", fRun));
988 }
989 else {
990 TH2D* etaSigmaPar1Map = dynamic_cast<TH2D *>(etaSigmaPars->FindObject("sigmaPar1Map"));
991 TNamed* sigmaPar0Info = dynamic_cast<TNamed *>(etaSigmaPars->FindObject("sigmaPar0"));
992 Double_t sigmaPar0 = 0.0;
993
994 if (sigmaPar0Info) {
995 TString sigmaPar0String = sigmaPar0Info->GetTitle();
996 sigmaPar0 = sigmaPar0String.Atof();
997 }
998 else {
999 // Something is weired because the object for parameter 0 could not be loaded -> New sigma parametrisation can not be used!
1000 etaSigmaPar1Map = 0x0;
1001 }
1002
1003 TH2D* etaSigmaPar1MapRefined = RefineHistoViaLinearInterpolation(etaSigmaPar1Map, refineFactorSigmaMapX, refineFactorSigmaMapY);
1004
1005
1006 if (etaSigmaPar1MapRefined) {
1007 if (!fTPCResponse.SetSigmaParams(etaSigmaPar1MapRefined, sigmaPar0)) {
1008 AliError(Form("Failed to set TPC eta sigma map for run %d -> Using old sigma parametrisation!!!", fRun));
1009 fTPCResponse.SetSigmaParams(0x0, 0);
1010 }
1011 else {
1012 AliInfo(Form("Loaded TPC sigma correction map (refine factors %.2f/%.2f) from %s/COMMON/PID/data/TPCetaMaps.root: %s",
1013 refineFactorSigmaMapX, refineFactorSigmaMapY, fOADBPath.Data(), fTPCResponse.GetSigmaPar1Map()->GetTitle()));
1014 }
1015
1016 delete etaSigmaPar1MapRefined;
1017 }
1018 else {
1019 AliError(Form("Failed to set TPC eta sigma map for run %d (map was loaded, but couldn't be refined) -> Using old sigma parametrisation!!!",
1020 fRun));
1021 }
1022 }
1023 }
1024}
1025
4ec8e76d 1026//______________________________________________________________________________
1027void AliPIDResponse::SetTPCPidResponseMaster()
1028{
1029 //
1030 // Load the TPC pid response functions from the OADB
644666df 1031 // Load the TPC voltage maps from OADB
4ec8e76d 1032 //
09b50a42 1033 //don't load twice for the moment
1034 if (fArrPidResponseMaster) return;
1035
1036
4ec8e76d 1037 //reset the PID response functions
1038 delete fArrPidResponseMaster;
644666df 1039 fArrPidResponseMaster=NULL;
4ec8e76d 1040
1041 TString fileName(Form("%s/COMMON/PID/data/TPCPIDResponse.root", fOADBPath.Data()));
644666df 1042 TFile *f=NULL;
00a38d07 1043 if (!fCustomTPCpidResponse.IsNull()) fileName=fCustomTPCpidResponse;
4ec8e76d 1044
644666df 1045 TString fileNamePIDresponse(Form("%s/COMMON/PID/data/TPCPIDResponse.root", fOADBPath.Data()));
1046 f=TFile::Open(fileNamePIDresponse.Data());
ea235c90 1047 if (f && f->IsOpen() && !f->IsZombie()){
1048 fArrPidResponseMaster=dynamic_cast<TObjArray*>(f->Get("TPCPIDResponse"));
4ec8e76d 1049 }
ea235c90 1050 delete f;
644666df 1051
1052 TString fileNameVoltageMaps(Form("%s/COMMON/PID/data/TPCvoltageSettings.root", fOADBPath.Data()));
1053 f=TFile::Open(fileNameVoltageMaps.Data());
1054 if (f && f->IsOpen() && !f->IsZombie()){
1055 fOADBvoltageMaps=dynamic_cast<AliOADBContainer*>(f->Get("TPCvoltageSettings"));
1056 }
1057 delete f;
4ec8e76d 1058
1059 if (!fArrPidResponseMaster){
644666df 1060 AliFatal(Form("Could not retrieve the TPC pid response from: %s",fileNamePIDresponse.Data()));
4ec8e76d 1061 return;
1062 }
1063 fArrPidResponseMaster->SetOwner();
644666df 1064
1065 if (!fOADBvoltageMaps)
1066 {
1067 AliFatal(Form("Could not retrieve the TPC voltage maps from: %s",fileNameVoltageMaps.Data()));
1068 }
1069 fArrPidResponseMaster->SetOwner();
4ec8e76d 1070}
1071
1072//______________________________________________________________________________
1073void AliPIDResponse::SetTPCParametrisation()
1074{
1075 //
1076 // Change BB parametrisation for current run
1077 //
1078
12d3abbc 1079 //
1080 //reset old splines
1081 //
1082 fTPCResponse.ResetSplines();
1083
4ec8e76d 1084 if (fLHCperiod.IsNull()) {
12d3abbc 1085 AliError("No period set, not changing parametrisation");
4ec8e76d 1086 return;
1087 }
1088
1089 //
1090 // Set default parametrisations for data and MC
1091 //
1092
1093 //data type
1094 TString datatype="DATA";
1095 //in case of mc fRecoPass is per default 1
1096 if (fIsMC) {
539a5a59 1097 if(!fTuneMConData) datatype="MC";
1098 fRecoPass=1;
4ec8e76d 1099 }
f84b18dd 1100
4a527e08 1101 // period
1102 TString period=fLHCperiod;
539a5a59 1103 if (fIsMC && !fTuneMConData) period=fMCperiodTPC;
4a527e08 1104
f85a3764 1105 Int_t recopass = fRecoPass;
1106 if(fTuneMConData) recopass = fRecoPassUser;
1107
1108 AliInfo(Form("Searching splines for: %s %s PASS%d %s",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
4a527e08 1109 Bool_t found=kFALSE;
4ec8e76d 1110 //
1111 //set the new PID splines
1112 //
4ec8e76d 1113 if (fArrPidResponseMaster){
4ec8e76d 1114 //for MC don't use period information
644666df 1115 //if (fIsMC) period="[A-Z0-9]*";
4ec8e76d 1116 //for MC use MC period information
644666df 1117 //pattern for the default entry (valid for all particles)
de678885 1118 TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN(_*)([A-Z1-9]*)",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
644666df 1119
f85a3764 1120 //find particle id and gain scenario
644666df 1121 for (Int_t igainScenario=0; igainScenario<AliTPCPIDResponse::fgkNumberOfGainScenarios; igainScenario++)
1122 {
1123 TObject *grAll=NULL;
1124 TString gainScenario = AliTPCPIDResponse::GainScenarioName(igainScenario);
1125 gainScenario.ToUpper();
1126 //loop over entries and filter them
1127 for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp)
1128 {
1129 TObject *responseFunction=fArrPidResponseMaster->At(iresp);
1130 if (responseFunction==NULL) continue;
1131 TString responseName=responseFunction->GetName();
1132
1133 if (!reg.MatchB(responseName)) continue;
1134
1135 TObjArray *arr=reg.MatchS(responseName); if (!arr) continue;
1136 TObject* tmp=NULL;
1137 tmp=arr->At(1); if (!tmp) continue;
1138 TString particleName=tmp->GetName();
1139 tmp=arr->At(3); if (!tmp) continue;
1140 TString gainScenarioName=tmp->GetName();
1141 delete arr;
1142 if (particleName.IsNull()) continue;
1143 if (!grAll && particleName=="ALL" && gainScenarioName==gainScenario) grAll=responseFunction;
1144 else
1145 {
1146 for (Int_t ispec=0; ispec<(AliTPCPIDResponse::fgkNumberOfParticleSpecies); ++ispec)
1147 {
1148 TString particle=AliPID::ParticleName(ispec);
1149 particle.ToUpper();
1150 //std::cout<<responseName<<" "<<particle<<" "<<particleName<<" "<<gainScenario<<" "<<gainScenarioName<<std::endl;
1151 if ( particle == particleName && gainScenario == gainScenarioName )
1152 {
1153 fTPCResponse.SetResponseFunction( responseFunction,
1154 (AliPID::EParticleType)ispec,
1155 (AliTPCPIDResponse::ETPCgainScenario)igainScenario );
1156 fTPCResponse.SetUseDatabase(kTRUE);
1157 AliInfo(Form("Adding graph: %d %d - %s",ispec,igainScenario,responseFunction->GetName()));
1158 found=kTRUE;
1159 // overwrite default with proton spline (for light nuclei)
1160 if (ispec==AliPID::kProton) grAll=responseFunction;
1161 break;
1162 }
4ec8e76d 1163 }
1164 }
1165 }
644666df 1166 if (grAll)
1167 {
1168 for (Int_t ispec=0; ispec<(AliTPCPIDResponse::fgkNumberOfParticleSpecies); ++ispec)
1169 {
1170 if (!fTPCResponse.GetResponseFunction( (AliPID::EParticleType)ispec,
1171 (AliTPCPIDResponse::ETPCgainScenario)igainScenario))
1172 {
1173 fTPCResponse.SetResponseFunction( grAll,
1174 (AliPID::EParticleType)ispec,
1175 (AliTPCPIDResponse::ETPCgainScenario)igainScenario );
1176 fTPCResponse.SetUseDatabase(kTRUE);
1177 AliInfo(Form("Adding graph: %d %d - %s",ispec,igainScenario,grAll->GetName()));
1178 found=kTRUE;
1179 }
4ec8e76d 1180 }
1181 }
1182 }
1183 }
644666df 1184 else AliInfo("no fArrPidResponseMaster");
4a527e08 1185
1186 if (!found){
f85a3764 1187 AliError(Form("No splines found for: %s %s PASS%d %s",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
4a527e08 1188 }
644666df 1189
4ec8e76d 1190 //
1191 // Setup resolution parametrisation
1192 //
1193
1194 //default
1195 fTPCResponse.SetSigma(3.79301e-03, 2.21280e+04);
1196
1197 if (fRun>=122195){
1198 fTPCResponse.SetSigma(2.30176e-02, 5.60422e+02);
1199 }
8af51a65 1200
1201 if (fRun>=186636){
1202// if (fRun>=188356){
723c4874 1203 fTPCResponse.SetSigma(8.62022e-04, 9.08156e+05);
1204 }
1205
23425eb2 1206 if (fArrPidResponseMaster)
f85a3764 1207 fResolutionCorrection=(TF1*)fArrPidResponseMaster->FindObject(Form("TF1_%s_ALL_%s_PASS%d_%s_SIGMA",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
4ec8e76d 1208
1209 if (fResolutionCorrection) AliInfo(Form("Setting multiplicity correction function: %s",fResolutionCorrection->GetName()));
644666df 1210
1211 //read in the voltage map
12d3abbc 1212 TVectorF* gsm = 0x0;
1213 if (fOADBvoltageMaps) gsm=dynamic_cast<TVectorF*>(fOADBvoltageMaps->GetObject(fRun));
644666df 1214 if (gsm)
1215 {
1216 fTPCResponse.SetVoltageMap(*gsm);
1217 TString vals;
1218 AliInfo(Form("Reading the voltage map for run %d\n",fRun));
1219 vals="IROC A: "; for (Int_t i=0; i<18; i++){vals+=Form("%.2f ",(*gsm)[i]);}
1220 AliInfo(vals.Data());
1221 vals="IROC C: "; for (Int_t i=18; i<36; i++){vals+=Form("%.2f ",(*gsm)[i]);}
1222 AliInfo(vals.Data());
1223 vals="OROC A: "; for (Int_t i=36; i<54; i++){vals+=Form("%.2f ",(*gsm)[i]);}
1224 AliInfo(vals.Data());
1225 vals="OROC C: "; for (Int_t i=54; i<72; i++){vals+=Form("%.2f ",(*gsm)[i]);}
1226 AliInfo(vals.Data());
1227 }
1228 else AliInfo("no voltage map, ideal default assumed");
4ec8e76d 1229}
1230
ea235c90 1231//______________________________________________________________________________
1232void AliPIDResponse::SetTRDPidResponseMaster()
1233{
1234 //
1235 // Load the TRD pid params and references from the OADB
1236 //
db0e2c5f 1237 if(fTRDPIDResponseObject) return;
53d016dc 1238 AliOADBContainer contParams("contParams");
1239
db0e2c5f 1240 Int_t statusResponse = contParams.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDResponse.root", fOADBPath.Data()), "AliTRDPIDResponseObject");
1241 if(statusResponse){
1242 AliError("Failed initializing PID Response Object from OADB");
59a8e853 1243 } else {
db0e2c5f 1244 AliInfo(Form("Loading TRD Response from %s/COMMON/PID/data/TRDPIDResponse.root", fOADBPath.Data()));
1245 fTRDPIDResponseObject = dynamic_cast<AliTRDPIDResponseObject *>(contParams.GetObject(fRun));
1246 if(!fTRDPIDResponseObject){
1247 AliError(Form("TRD Response not found in run %d", fRun));
59a8e853 1248 }
1249 }
ea235c90 1250}
1251
1252//______________________________________________________________________________
1253void AliPIDResponse::InitializeTRDResponse(){
1254 //
1255 // Set PID Params and references to the TRD PID response
1256 //
db0e2c5f 1257 fTRDResponse.SetPIDResponseObject(fTRDPIDResponseObject);
f2762b1c 1258}
1259
bd58d4b9 1260//______________________________________________________________________________
1261void AliPIDResponse::SetTRDSlices(UInt_t TRDslicesForPID[2],AliTRDPIDResponse::ETRDPIDMethod method) const{
1262
1263 if(fLHCperiod == "LHC10d" || fLHCperiod == "LHC10e"){
1264 // backward compatibility for setting with 8 slices
1265 TRDslicesForPID[0] = 0;
1266 TRDslicesForPID[1] = 7;
f2762b1c 1267 }
bd58d4b9 1268 else{
1269 if(method==AliTRDPIDResponse::kLQ1D){
1270 TRDslicesForPID[0] = 0; // first Slice contains normalized dEdx
1271 TRDslicesForPID[1] = 0;
1272 }
1273 if(method==AliTRDPIDResponse::kLQ2D){
1274 TRDslicesForPID[0] = 1;
1275 TRDslicesForPID[1] = 7;
1276 }
db0e2c5f 1277 }
bd58d4b9 1278 AliDebug(1,Form("Slice Range set to %d - %d",TRDslicesForPID[0],TRDslicesForPID[1]));
ea235c90 1279}
1280
b79db598 1281//______________________________________________________________________________
1282void AliPIDResponse::SetTOFPidResponseMaster()
1283{
1284 //
1285 // Load the TOF pid params from the OADB
1286 //
00a38d07 1287
1288 if (fTOFPIDParams) delete fTOFPIDParams;
644666df 1289 fTOFPIDParams=NULL;
00a38d07 1290
b79db598 1291 TFile *oadbf = new TFile(Form("%s/COMMON/PID/data/TOFPIDParams.root",fOADBPath.Data()));
00a38d07 1292 if (oadbf && oadbf->IsOpen()) {
b79db598 1293 AliInfo(Form("Loading TOF Params from %s/COMMON/PID/data/TOFPIDParams.root", fOADBPath.Data()));
1294 AliOADBContainer *oadbc = (AliOADBContainer *)oadbf->Get("TOFoadb");
00a38d07 1295 if (oadbc) fTOFPIDParams = dynamic_cast<AliTOFPIDParams *>(oadbc->GetObject(fRun,"TOFparams"));
b79db598 1296 oadbf->Close();
1297 delete oadbc;
b79db598 1298 }
1299 delete oadbf;
1300
00a38d07 1301 if (!fTOFPIDParams) AliFatal("TOFPIDParams could not be retrieved");
1302}
b79db598 1303
1304//______________________________________________________________________________
1305void AliPIDResponse::InitializeTOFResponse(){
1306 //
1307 // Set PID Params to the TOF PID response
00a38d07 1308 //
1309
1310 AliInfo("TOF PID Params loaded from OADB");
1311 AliInfo(Form(" TOF resolution %5.2f [ps]",fTOFPIDParams->GetTOFresolution()));
1312 AliInfo(Form(" StartTime method %d",fTOFPIDParams->GetStartTimeMethod()));
1313 AliInfo(Form(" TOF res. mom. params: %5.2f %5.2f %5.2f %5.2f",
1314 fTOFPIDParams->GetSigParams(0),fTOFPIDParams->GetSigParams(1),fTOFPIDParams->GetSigParams(2),fTOFPIDParams->GetSigParams(3)));
1315
b79db598 1316 for (Int_t i=0;i<4;i++) {
1317 fTOFResponse.SetTrackParameter(i,fTOFPIDParams->GetSigParams(i));
1318 }
1319 fTOFResponse.SetTimeResolution(fTOFPIDParams->GetTOFresolution());
1320
78cbd205 1321 AliInfo("TZERO resolution loaded from ESDrun/AODheader");
1322 Float_t t0Spread[4];
1323 for (Int_t i=0;i<4;i++) t0Spread[i]=fCurrentEvent->GetT0spread(i);
1324 AliInfo(Form(" TZERO spreads from data: (A+C)/2 %f A %f C %f (A'-C')/2: %f",t0Spread[0],t0Spread[1],t0Spread[2],t0Spread[3]));
1325 Float_t a = t0Spread[1]*t0Spread[1]-t0Spread[0]*t0Spread[0]+t0Spread[3]*t0Spread[3];
1326 Float_t c = t0Spread[2]*t0Spread[2]-t0Spread[0]*t0Spread[0]+t0Spread[3]*t0Spread[3];
1327 if ( (t0Spread[0] > 50. && t0Spread[0] < 400.) && (a > 0.) && (c>0.)) {
1328 fResT0AC=t0Spread[3];
1329 fResT0A=TMath::Sqrt(a);
1330 fResT0C=TMath::Sqrt(c);
1331 } else {
1332 AliInfo(" TZERO spreads not present or inconsistent, loading default");
1333 fResT0A=75.;
1334 fResT0C=65.;
1335 fResT0AC=55.;
1336 }
1337 AliInfo(Form(" TZERO resolution set to: T0A: %f [ps] T0C: %f [ps] T0AC %f [ps]",fResT0A,fResT0C,fResT0AC));
1338
b79db598 1339}
1340
1341
1c9d11be 1342//______________________________________________________________________________
bd58d4b9 1343Bool_t AliPIDResponse::IdentifiedAsElectronTRD(const AliVTrack *vtrack, Double_t efficiencyLevel,Double_t centrality,AliTRDPIDResponse::ETRDPIDMethod PIDmethod) const {
ea235c90 1344 //
1345 // Check whether track is identified as electron under a given electron efficiency hypothesis
bd58d4b9 1346 //
1347
ea235c90 1348 Double_t probs[AliPID::kSPECIES];
bd58d4b9 1349 ComputeTRDProbability(vtrack, AliPID::kSPECIES, probs,PIDmethod);
ea235c90 1350
99e9d5ec 1351 Int_t ntracklets = vtrack->GetTRDntrackletsPID();
1352 // Take mean of the TRD momenta in the given tracklets
1353 Float_t p = 0, trdmomenta[AliVTrack::kTRDnPlanes];
1354 Int_t nmomenta = 0;
ea235c90 1355 for(Int_t iPl=0;iPl<AliVTrack::kTRDnPlanes;iPl++){
1356 if(vtrack->GetTRDmomentum(iPl) > 0.){
99e9d5ec 1357 trdmomenta[nmomenta++] = vtrack->GetTRDmomentum(iPl);
ea235c90 1358 }
1359 }
99e9d5ec 1360 p = TMath::Mean(nmomenta, trdmomenta);
ea235c90 1361
bd58d4b9 1362 return fTRDResponse.IdentifiedAsElectron(ntracklets, probs, p, efficiencyLevel,centrality,PIDmethod);
ea235c90 1363}
1364
b2138b40 1365//______________________________________________________________________________
1366void AliPIDResponse::SetEMCALPidResponseMaster()
1367{
1368 //
1369 // Load the EMCAL pid response functions from the OADB
1370 //
1371 TObjArray* fEMCALPIDParamsRun = NULL;
1372 TObjArray* fEMCALPIDParamsPass = NULL;
1373
1374 if(fEMCALPIDParams) return;
1375 AliOADBContainer contParams("contParams");
1376
1377 Int_t statusPars = contParams.InitFromFile(Form("%s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()), "AliEMCALPIDParams");
1378 if(statusPars){
1379 AliError("Failed initializing PID Params from OADB");
1380 }
1381 else {
1382 AliInfo(Form("Loading EMCAL Params from %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
1383
1384 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(fRun));
1385 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",fRecoPass)));
1386 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
1387
1388 if(!fEMCALPIDParams){
f8d39067 1389 AliInfo(Form("EMCAL Params not found in run %d pass %d", fRun, fRecoPass));
1f631618 1390 AliInfo("Will take the standard LHC11d instead ...");
b2138b40 1391
1f631618 1392 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(156477));
1393 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",1)));
b2138b40 1394 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
1395
1396 if(!fEMCALPIDParams){
1f631618 1397 AliError(Form("DEFAULT EMCAL Params (LHC11d) not found in file %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
b2138b40 1398 }
1399 }
1400 }
1401}
1402
1403//______________________________________________________________________________
1404void AliPIDResponse::InitializeEMCALResponse(){
1405 //
1406 // Set PID Params to the EMCAL PID response
1407 //
1408 fEMCALResponse.SetPIDParams(fEMCALPIDParams);
1409
1410}
00a38d07 1411
1c9d11be 1412//______________________________________________________________________________
1413void AliPIDResponse::FillTrackDetectorPID(const AliVTrack *track, EDetector detector) const
00a38d07 1414{
1415 //
1416 // create detector PID information and setup the transient pointer in the track
1417 //
1c9d11be 1418
1419 // check if detector number is inside accepted range
1420 if (detector == kNdetectors) return;
1421
1422 // get detector pid
1423 AliDetectorPID *detPID=const_cast<AliDetectorPID*>(track->GetDetectorPID());
1424 if (!detPID) {
1425 detPID=new AliDetectorPID;
1426 (const_cast<AliVTrack*>(track))->SetDetectorPID(detPID);
1427 }
1428
1429 //check if values exist
1430 if (detPID->HasRawProbabilitiy(detector) && detPID->HasNumberOfSigmas(detector)) return;
00a38d07 1431
1432 //TODO: which particles to include? See also the loops below...
1433 Double_t values[AliPID::kSPECIESC]={0};
1c9d11be 1434
1435 //nsigmas
1436 for (Int_t ipart=0; ipart<AliPID::kSPECIESC; ++ipart)
1437 values[ipart]=GetNumberOfSigmas(detector,track,(AliPID::EParticleType)ipart);
1438 detPID->SetNumberOfSigmas(detector, values, (Int_t)AliPID::kSPECIESC);
1439
1440 //probabilities
1441 EDetPidStatus status=GetComputePIDProbability(detector,track,AliPID::kSPECIESC,values);
1442 detPID->SetRawProbability(detector, values, (Int_t)AliPID::kSPECIESC, status);
1443}
1444
1445//______________________________________________________________________________
1446void AliPIDResponse::FillTrackDetectorPID()
1447{
1448 //
1449 // create detector PID information and setup the transient pointer in the track
1450 //
1451
1452 if (!fCurrentEvent) return;
00a38d07 1453
1454 for (Int_t itrack=0; itrack<fCurrentEvent->GetNumberOfTracks(); ++itrack){
1455 AliVTrack *track=dynamic_cast<AliVTrack*>(fCurrentEvent->GetTrack(itrack));
1456 if (!track) continue;
1457
00a38d07 1458 for (Int_t idet=0; idet<kNdetectors; ++idet){
1c9d11be 1459 FillTrackDetectorPID(track, (EDetector)idet);
00a38d07 1460 }
00a38d07 1461 }
1462}
1463
1c9d11be 1464//______________________________________________________________________________
5f8db5fe 1465void AliPIDResponse::SetTOFResponse(AliVEvent *vevent,EStartTimeType_t option){
1466 //
1467 // Set TOF response function
1468 // Input option for event_time used
1469 //
1470
1471 Float_t t0spread = 0.; //vevent->GetEventTimeSpread();
1472 if(t0spread < 10) t0spread = 80;
1473
1474 // T0 from TOF algorithm
1475
1476 Bool_t flagT0TOF=kFALSE;
1477 Bool_t flagT0T0=kFALSE;
1478 Float_t *startTime = new Float_t[fTOFResponse.GetNmomBins()];
1479 Float_t *startTimeRes = new Float_t[fTOFResponse.GetNmomBins()];
1480 Int_t *startTimeMask = new Int_t[fTOFResponse.GetNmomBins()];
1481
1482 // T0-TOF arrays
1483 Float_t *estimatedT0event = new Float_t[fTOFResponse.GetNmomBins()];
1484 Float_t *estimatedT0resolution = new Float_t[fTOFResponse.GetNmomBins()];
1485 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1486 estimatedT0event[i]=0.0;
1487 estimatedT0resolution[i]=0.0;
1488 startTimeMask[i] = 0;
1489 }
1490
78cbd205 1491 Float_t resT0A=fResT0A;
1492 Float_t resT0C=fResT0C;
1493 Float_t resT0AC=fResT0AC;
5f8db5fe 1494 if(vevent->GetT0TOF()){ // check if T0 detector information is available
1495 flagT0T0=kTRUE;
1496 }
1497
1498
1499 AliTOFHeader *tofHeader = (AliTOFHeader*)vevent->GetTOFHeader();
1500
1501 if (tofHeader) { // read global info and T0-TOF
1502 fTOFResponse.SetTimeResolution(tofHeader->GetTOFResolution());
1503 t0spread = tofHeader->GetT0spread(); // read t0 sprad
1504 if(t0spread < 10) t0spread = 80;
1505
1506 flagT0TOF=kTRUE;
1507 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){ // read T0-TOF default value
1508 startTime[i]=tofHeader->GetDefaultEventTimeVal();
1509 startTimeRes[i]=tofHeader->GetDefaultEventTimeRes();
1510 if(startTimeRes[i] < 1.e-5) startTimeRes[i] = t0spread;
1511 }
1512
1513 TArrayI *ibin=(TArrayI*)tofHeader->GetNvalues();
1514 TArrayF *t0Bin=(TArrayF*)tofHeader->GetEventTimeValues();
1515 TArrayF *t0ResBin=(TArrayF*)tofHeader->GetEventTimeRes();
1516 for(Int_t j=0;j < tofHeader->GetNbins();j++){ // fill T0-TOF in p-bins
1517 Int_t icurrent = (Int_t)ibin->GetAt(j);
1518 startTime[icurrent]=t0Bin->GetAt(j);
1519 startTimeRes[icurrent]=t0ResBin->GetAt(j);
1520 if(startTimeRes[icurrent] < 1.e-5) startTimeRes[icurrent] = t0spread;
1521 }
1522 }
1523
1524 // for cut of 3 sigma on t0 spread
1525 Float_t t0cut = 3 * t0spread;
1526 if(t0cut < 500) t0cut = 500;
1527
1528 if(option == kFILL_T0){ // T0-FILL is used
1529 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1530 estimatedT0event[i]=0.0;
1531 estimatedT0resolution[i]=t0spread;
1532 }
1533 fTOFResponse.SetT0event(estimatedT0event);
1534 fTOFResponse.SetT0resolution(estimatedT0resolution);
1535 }
1536
1537 if(option == kTOF_T0){ // T0-TOF is used when available (T0-FILL otherwise) from ESD
1538 if(flagT0TOF){
1539 fTOFResponse.SetT0event(startTime);
1540 fTOFResponse.SetT0resolution(startTimeRes);
1541 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1542 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1543 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1544 }
1545 }
1546 else{
1547 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1548 estimatedT0event[i]=0.0;
1549 estimatedT0resolution[i]=t0spread;
1550 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1551 }
1552 fTOFResponse.SetT0event(estimatedT0event);
1553 fTOFResponse.SetT0resolution(estimatedT0resolution);
1554 }
1555 }
1556 else if(option == kBest_T0){ // T0-T0 or T0-TOF are used when available (T0-FILL otherwise) from ESD
1557 Float_t t0AC=-10000;
1558 Float_t t0A=-10000;
1559 Float_t t0C=-10000;
1560 if(flagT0T0){
5f8db5fe 1561 t0A= vevent->GetT0TOF()[1];
1562 t0C= vevent->GetT0TOF()[2];
f84b18dd 1563 // t0AC= vevent->GetT0TOF()[0];
1564 t0AC= t0A/resT0A/resT0A + t0C/resT0C/resT0C;
1565 resT0AC= TMath::Sqrt(1./resT0A/resT0A + 1./resT0C/resT0C);
1566 t0AC /= resT0AC*resT0AC;
5f8db5fe 1567 }
1568
1569 Float_t t0t0Best = 0;
1570 Float_t t0t0BestRes = 9999;
1571 Int_t t0used=0;
1572 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1573 t0t0Best = t0AC;
1574 t0t0BestRes = resT0AC;
1575 t0used=6;
1576 }
1577 else if(TMath::Abs(t0C) < t0cut){
1578 t0t0Best = t0C;
1579 t0t0BestRes = resT0C;
1580 t0used=4;
1581 }
1582 else if(TMath::Abs(t0A) < t0cut){
1583 t0t0Best = t0A;
1584 t0t0BestRes = resT0A;
1585 t0used=2;
1586 }
1587
1588 if(flagT0TOF){ // if T0-TOF info is available
1589 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1590 if(t0t0BestRes < 999){
1591 if(startTimeRes[i] < t0spread){
1592 Double_t wtot = 1./startTimeRes[i]/startTimeRes[i] + 1./t0t0BestRes/t0t0BestRes;
1593 Double_t t0best = startTime[i]/startTimeRes[i]/startTimeRes[i] + t0t0Best/t0t0BestRes/t0t0BestRes;
1594 estimatedT0event[i]=t0best / wtot;
1595 estimatedT0resolution[i]=1./TMath::Sqrt(wtot);
1596 startTimeMask[i] = t0used+1;
1597 }
1598 else {
1599 estimatedT0event[i]=t0t0Best;
1600 estimatedT0resolution[i]=t0t0BestRes;
1601 startTimeMask[i] = t0used;
1602 }
1603 }
1604 else{
1605 estimatedT0event[i]=startTime[i];
1606 estimatedT0resolution[i]=startTimeRes[i];
1607 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1608 }
1609 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1610 }
1611 fTOFResponse.SetT0event(estimatedT0event);
1612 fTOFResponse.SetT0resolution(estimatedT0resolution);
1613 }
1614 else{ // if no T0-TOF info is available
1615 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1616 fTOFResponse.SetT0binMask(i,t0used);
1617 if(t0t0BestRes < 999){
1618 estimatedT0event[i]=t0t0Best;
1619 estimatedT0resolution[i]=t0t0BestRes;
1620 }
1621 else{
1622 estimatedT0event[i]=0.0;
1623 estimatedT0resolution[i]=t0spread;
1624 }
1625 }
1626 fTOFResponse.SetT0event(estimatedT0event);
1627 fTOFResponse.SetT0resolution(estimatedT0resolution);
1628 }
1629 }
1630
1631 else if(option == kT0_T0){ // T0-T0 is used when available (T0-FILL otherwise)
1632 Float_t t0AC=-10000;
1633 Float_t t0A=-10000;
1634 Float_t t0C=-10000;
1635 if(flagT0T0){
5f8db5fe 1636 t0A= vevent->GetT0TOF()[1];
1637 t0C= vevent->GetT0TOF()[2];
f84b18dd 1638 // t0AC= vevent->GetT0TOF()[0];
1639 t0AC= t0A/resT0A/resT0A + t0C/resT0C/resT0C;
1640 resT0AC= TMath::Sqrt(1./resT0A/resT0A + 1./resT0C/resT0C);
1641 t0AC /= resT0AC*resT0AC;
5f8db5fe 1642 }
1643
1644 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1645 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1646 estimatedT0event[i]=t0AC;
1647 estimatedT0resolution[i]=resT0AC;
1648 fTOFResponse.SetT0binMask(i,6);
1649 }
1650 }
1651 else if(TMath::Abs(t0C) < t0cut){
1652 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1653 estimatedT0event[i]=t0C;
1654 estimatedT0resolution[i]=resT0C;
1655 fTOFResponse.SetT0binMask(i,4);
1656 }
1657 }
1658 else if(TMath::Abs(t0A) < t0cut){
1659 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1660 estimatedT0event[i]=t0A;
1661 estimatedT0resolution[i]=resT0A;
1662 fTOFResponse.SetT0binMask(i,2);
1663 }
1664 }
1665 else{
1666 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1667 estimatedT0event[i]=0.0;
1668 estimatedT0resolution[i]=t0spread;
1669 fTOFResponse.SetT0binMask(i,0);
1670 }
1671 }
1672 fTOFResponse.SetT0event(estimatedT0event);
1673 fTOFResponse.SetT0resolution(estimatedT0resolution);
1674 }
1675 delete [] startTime;
1676 delete [] startTimeRes;
1677 delete [] startTimeMask;
1678 delete [] estimatedT0event;
1679 delete [] estimatedT0resolution;
1680}
1c9d11be 1681
1682//______________________________________________________________________________
1683// private non cached versions of the PID calculation
1684//
1685
1686
1687//______________________________________________________________________________
1688Float_t AliPIDResponse::GetNumberOfSigmas(EDetector detCode, const AliVParticle *track, AliPID::EParticleType type) const
1689{
1690 //
1691 // NumberOfSigmas for 'detCode'
1692 //
1693
1694 switch (detCode){
1695 case kITS: return GetNumberOfSigmasITS(track, type); break;
1696 case kTPC: return GetNumberOfSigmasTPC(track, type); break;
1697 case kTOF: return GetNumberOfSigmasTOF(track, type); break;
1698 case kEMCAL: return GetNumberOfSigmasEMCAL(track, type); break;
1699 default: return -999.;
1700 }
1701
1702}
1703
1704
1705
1706//______________________________________________________________________________
1707Float_t AliPIDResponse::GetNumberOfSigmasITS(const AliVParticle *vtrack, AliPID::EParticleType type) const
1708{
1709 //
1710 // Calculate the number of sigmas in the ITS
1711 //
1712
1713 AliVTrack *track=(AliVTrack*)vtrack;
1714
1715 Float_t dEdx=track->GetITSsignal();
1716 if (dEdx<=0) return -999.;
1717
1718 UChar_t clumap=track->GetITSClusterMap();
1719 Int_t nPointsForPid=0;
1720 for(Int_t i=2; i<6; i++){
1721 if(clumap&(1<<i)) ++nPointsForPid;
1722 }
1723 Float_t mom=track->P();
1724
1725 //check for ITS standalone tracks
1726 Bool_t isSA=kTRUE;
1727 if( track->GetStatus() & AliVTrack::kTPCin ) isSA=kFALSE;
1728
1729 //TODO: in case of the electron, use the SA parametrisation,
1730 // this needs to be changed if ITS provides a parametrisation
1731 // for electrons also for ITS+TPC tracks
1732 return fITSResponse.GetNumberOfSigmas(mom,dEdx,type,nPointsForPid,isSA || (type==AliPID::kElectron));
1733}
1734
1735//______________________________________________________________________________
1736Float_t AliPIDResponse::GetNumberOfSigmasTPC(const AliVParticle *vtrack, AliPID::EParticleType type) const
1737{
1738 //
1739 // Calculate the number of sigmas in the TPC
1740 //
1741
1742 AliVTrack *track=(AliVTrack*)vtrack;
1743
1c9d11be 1744 Double_t nSigma = -999.;
f84b18dd 1745
f85a3764 1746 if (fTuneMConData)
1747 this->GetTPCsignalTunedOnData(track);
f84b18dd 1748
f85a3764 1749 nSigma = fTPCResponse.GetNumberOfSigmas(track, type, AliTPCPIDResponse::kdEdxDefault, fUseTPCEtaCorrection);
1c9d11be 1750
1751 return nSigma;
1752}
1753
1754//______________________________________________________________________________
1755Float_t AliPIDResponse::GetNumberOfSigmasEMCAL(const AliVParticle *vtrack, AliPID::EParticleType type) const
1756{
1757 //
1758 // Calculate the number of sigmas in the EMCAL
1759 //
1760
1761 AliVTrack *track=(AliVTrack*)vtrack;
1762
1763 AliVCluster *matchedClus = NULL;
1764
1765 Double_t mom = -1.;
1766 Double_t pt = -1.;
1767 Double_t EovP = -1.;
1768 Double_t fClsE = -1.;
1769
1770 Int_t nMatchClus = -1;
1771 Int_t charge = 0;
1772
1773 // Track matching
1774 nMatchClus = track->GetEMCALcluster();
1775 if(nMatchClus > -1){
1776
1777 mom = track->P();
1778 pt = track->Pt();
1779 charge = track->Charge();
1780
1781 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
1782
1783 if(matchedClus){
1784
1785 // matched cluster is EMCAL
1786 if(matchedClus->IsEMCAL()){
1787
1788 fClsE = matchedClus->E();
1789 EovP = fClsE/mom;
1790
1791
1792 // NSigma value really meaningful only for electrons!
1793 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
1794 }
1795 }
1796 }
1797
1798 return -999;
1799
1800}
1801
1802
1803//______________________________________________________________________________
1804AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputePIDProbability (EDetector detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
1805{
1806 //
1807 // Compute PID response of 'detCode'
1808 //
1809
1810 switch (detCode){
1811 case kITS: return GetComputeITSProbability(track, nSpecies, p); break;
1812 case kTPC: return GetComputeTPCProbability(track, nSpecies, p); break;
1813 case kTRD: return GetComputeTRDProbability(track, nSpecies, p); break;
1814 case kTOF: return GetComputeTOFProbability(track, nSpecies, p); break;
1815 case kPHOS: return GetComputePHOSProbability(track, nSpecies, p); break;
1816 case kEMCAL: return GetComputeEMCALProbability(track, nSpecies, p); break;
1817 case kHMPID: return GetComputeHMPIDProbability(track, nSpecies, p); break;
1818 default: return kDetNoSignal;
1819 }
1820}
1821
1822//______________________________________________________________________________
1823AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeITSProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
1824{
1825 //
1826 // Compute PID response for the ITS
1827 //
1828
1829 // look for cached value first
1830 // only the non SA tracks are cached
1831 if (track->GetDetectorPID()){
1832 return track->GetDetectorPID()->GetRawProbability(kITS, p, nSpecies);
1833 }
1834
1835 // set flat distribution (no decision)
1836 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1837
1838 if ((track->GetStatus()&AliVTrack::kITSin)==0 &&
1839 (track->GetStatus()&AliVTrack::kITSout)==0) return kDetNoSignal;
1840
1841 //check for ITS standalone tracks
1842 Bool_t isSA=kTRUE;
1843 if( track->GetStatus() & AliVTrack::kTPCin ) isSA=kFALSE;
1844
1845 Double_t mom=track->P();
1846 Double_t dedx=track->GetITSsignal();
1847 Double_t momITS=mom;
1848 UChar_t clumap=track->GetITSClusterMap();
1849 Int_t nPointsForPid=0;
1850 for(Int_t i=2; i<6; i++){
1851 if(clumap&(1<<i)) ++nPointsForPid;
1852 }
1853
1854 if(nPointsForPid<3) { // track not to be used for combined PID purposes
1855 // track->ResetStatus(AliVTrack::kITSpid);
1856 return kDetNoSignal;
1857 }
1858
1859 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
1860 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
1861 Double_t mass=AliPID::ParticleMassZ(j);//GeV/c^2
1862 const Double_t chargeFactor = TMath::Power(AliPID::ParticleCharge(j),2.);
1863 Double_t bethe=fITSResponse.Bethe(momITS,mass)*chargeFactor;
1864 //TODO: in case of the electron, use the SA parametrisation,
1865 // this needs to be changed if ITS provides a parametrisation
1866 // for electrons also for ITS+TPC tracks
1867 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA || (j==(Int_t)AliPID::kElectron));
1868 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
1869 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
1870 } else {
1871 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
1872 mismatch=kFALSE;
1873 }
1874
1875 // Check for particles heavier than (AliPID::kSPECIES - 1)
1876 // if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
1877
1878 }
1879
1880 if (mismatch){
1881 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
1882 return kDetNoSignal;
1883 }
1884
1885
1886 return kDetPidOk;
1887}
1888//______________________________________________________________________________
1889AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeTPCProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
1890{
1891 //
1892 // Compute PID response for the TPC
1893 //
1894
1895 // set flat distribution (no decision)
1896 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1897
1898 // check quality of the track
1899 if ( (track->GetStatus()&AliVTrack::kTPCin )==0 && (track->GetStatus()&AliVTrack::kTPCout)==0 ) return kDetNoSignal;
1900
1c9d11be 1901 Double_t dedx=track->GetTPCsignal();
1902 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
1903
1904 if(fTuneMConData) dedx = this->GetTPCsignalTunedOnData(track);
1905
f84b18dd 1906 Double_t bethe = 0.;
1907 Double_t sigma = 0.;
1908
1c9d11be 1909 for (Int_t j=0; j<AliPID::kSPECIESC; j++) {
1910 AliPID::EParticleType type=AliPID::EParticleType(j);
f84b18dd 1911
f85a3764 1912 bethe=fTPCResponse.GetExpectedSignal(track, type, AliTPCPIDResponse::kdEdxDefault, fUseTPCEtaCorrection);
1913 sigma=fTPCResponse.GetExpectedSigma(track, type, AliTPCPIDResponse::kdEdxDefault, fUseTPCEtaCorrection);
1914
1c9d11be 1915 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
1916 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
1917 } else {
1918 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
1919 mismatch=kFALSE;
1920 }
1921 }
1922
1923 if (mismatch){
1924 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1925 return kDetNoSignal;
1926 }
1927
1928 return kDetPidOk;
1929}
1930//______________________________________________________________________________
1931AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeTOFProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
1932{
1933 //
1934 // Compute PID response for the
1935 //
1936
1937 Double_t meanCorrFactor = 0.11/fTOFtail; // Correction factor on the mean because of the tail (should be ~ 0.1 with tail = 1.1)
1938
1939 // set flat distribution (no decision)
1940 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1941
1942 if ((track->GetStatus()&AliVTrack::kTOFout)==0) return kDetNoSignal;
1943 if ((track->GetStatus()&AliVTrack::kTIME)==0) return kDetNoSignal;
1944
1945 Bool_t mismatch = kTRUE/*, heavy = kTRUE*/;
1946 for (Int_t j=0; j<AliPID::kSPECIESC; j++) {
1947 AliPID::EParticleType type=AliPID::EParticleType(j);
1948 Double_t nsigmas=GetNumberOfSigmasTOF(track,type) + meanCorrFactor;
1949
1950 Double_t expTime = fTOFResponse.GetExpectedSignal(track,type);
1951 Double_t sig = fTOFResponse.GetExpectedSigma(track->P(),expTime,AliPID::ParticleMassZ(type));
1952 if (TMath::Abs(nsigmas) > (fRange+2)) {
1953 if(nsigmas < fTOFtail)
1954 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
1955 else
1956 p[j] = TMath::Exp(-(fRange+2 - fTOFtail*0.5)*fTOFtail)/sig;
1957 } else{
1958 if(nsigmas < fTOFtail)
1959 p[j] = TMath::Exp(-0.5*nsigmas*nsigmas)/sig;
1960 else
1961 p[j] = TMath::Exp(-(nsigmas - fTOFtail*0.5)*fTOFtail)/sig;
1962 }
1963
1964 if (TMath::Abs(nsigmas)<5.){
1965 Double_t nsigmasTPC=GetNumberOfSigmasTPC(track,type);
1966 if (TMath::Abs(nsigmasTPC)<5.) mismatch=kFALSE;
1967 }
1968 }
1969
1970 if (mismatch){
1971 return kDetMismatch;
1972 }
1973
1974 // TODO: Light nuclei
1975
1976 return kDetPidOk;
1977}
1978//______________________________________________________________________________
1979AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[],AliTRDPIDResponse::ETRDPIDMethod PIDmethod/*=AliTRDPIDResponse::kLQ1D*/) const
1980{
1981 //
1982 // Compute PID response for the
1983 //
1984
1985 UInt_t TRDslicesForPID[2];
1986 SetTRDSlices(TRDslicesForPID,PIDmethod);
1987 // set flat distribution (no decision)
1988 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1989 if((track->GetStatus()&AliVTrack::kTRDout)==0) return kDetNoSignal;
1990
1991 Float_t mom[6]={0.};
1992 Double_t dedx[48]={0.}; // Allocate space for the maximum number of TRD slices
1993 Int_t nslices = TRDslicesForPID[1] - TRDslicesForPID[0] + 1;
1994 AliDebug(1, Form("First Slice: %d, Last Slice: %d, Number of slices: %d", TRDslicesForPID[0], TRDslicesForPID[1], nslices));
1995 for(UInt_t ilayer = 0; ilayer < 6; ilayer++){
1996 mom[ilayer] = track->GetTRDmomentum(ilayer);
1997 for(UInt_t islice = TRDslicesForPID[0]; islice <= TRDslicesForPID[1]; islice++){
1998 dedx[ilayer*nslices+islice-TRDslicesForPID[0]] = track->GetTRDslice(ilayer, islice);
1999 }
2000 }
2001 fTRDResponse.GetResponse(nslices, dedx, mom, p,PIDmethod);
2002 return kDetPidOk;
2003
2004}
2005//______________________________________________________________________________
2006AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeEMCALProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
2007{
2008 //
2009 // Compute PID response for the EMCAL
2010 //
2011
2012 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
2013
2014 AliVCluster *matchedClus = NULL;
2015
2016 Double_t mom = -1.;
2017 Double_t pt = -1.;
2018 Double_t EovP = -1.;
2019 Double_t fClsE = -1.;
2020
2021 Int_t nMatchClus = -1;
2022 Int_t charge = 0;
2023
2024 // Track matching
2025 nMatchClus = track->GetEMCALcluster();
2026
2027 if(nMatchClus > -1){
2028
2029 mom = track->P();
2030 pt = track->Pt();
2031 charge = track->Charge();
2032
2033 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
2034
2035 if(matchedClus){
2036
2037 // matched cluster is EMCAL
2038 if(matchedClus->IsEMCAL()){
2039
2040 fClsE = matchedClus->E();
2041 EovP = fClsE/mom;
2042
2043
2044 // compute the probabilities
2045 if(fEMCALResponse.ComputeEMCALProbability(nSpecies,pt,EovP,charge,p)){
2046
2047 // in case everything is OK
2048 return kDetPidOk;
2049 }
2050 }
2051 }
2052 }
2053
2054 // in all other cases set flat distribution (no decision)
2055 for (Int_t j=0; j<nSpecies; j++) p[j] = 1./nSpecies;
2056 return kDetNoSignal;
2057
2058}
2059//______________________________________________________________________________
2060AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputePHOSProbability (const AliVTrack */*track*/, Int_t nSpecies, Double_t p[]) const
2061{
2062 //
2063 // Compute PID response for the PHOS
2064 //
2065
2066 // set flat distribution (no decision)
2067 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
2068 return kDetNoSignal;
2069}
2070//______________________________________________________________________________
2071AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeHMPIDProbability(const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
2072{
2073 //
2074 // Compute PID response for the HMPID
2075 //
2076 // set flat distribution (no decision)
2077 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
2078 if((track->GetStatus()&AliVTrack::kHMPIDpid)==0) return kDetNoSignal;
2079
2080 track->GetHMPIDpid(p);
2081
2082 return kDetPidOk;
2083}