]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEERBase/AliPIDResponse.cxx
- PIDResponse: Loading of special TPC response (splines) for debugging purposes has...
[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>
5a9dc560 36#include <TSystem.h>
37#include <TMD5.h>
4ec8e76d 38
39#include <AliVEvent.h>
fd21ec8d 40#include <AliVTrack.h>
4ec8e76d 41#include <AliLog.h>
42#include <AliPID.h>
ea235c90 43#include <AliOADBContainer.h>
db0e2c5f 44#include <AliTRDPIDResponseObject.h>
9c499471 45#include <AliTRDdEdxParams.h>
b79db598 46#include <AliTOFPIDParams.h>
567624b5 47#include <AliHMPIDPIDParams.h>
29bf19f2 48
49#include "AliPIDResponse.h"
00a38d07 50#include "AliDetectorPID.h"
29bf19f2 51
80f28562 52#include "AliCentrality.h"
53
29bf19f2 54ClassImp(AliPIDResponse);
55
42fcc729 56Float_t AliPIDResponse::fgTOFmismatchProb = 0.0;
57
4ec8e76d 58AliPIDResponse::AliPIDResponse(Bool_t isMC/*=kFALSE*/) :
59TNamed("PIDResponse","PIDResponse"),
60fITSResponse(isMC),
61fTPCResponse(),
62fTRDResponse(),
63fTOFResponse(),
567624b5 64fHMPIDResponse(),
e96b9916 65fEMCALResponse(),
fd21ec8d 66fRange(5.),
67fITSPIDmethod(kITSTruncMean),
1ceae0ac 68fTuneMConData(kFALSE),
69fTuneMConDataMask(kDetTOF|kDetTPC),
4ec8e76d 70fIsMC(isMC),
a017c06a 71fCachePID(kFALSE),
4ec8e76d 72fOADBPath(),
00a38d07 73fCustomTPCpidResponse(),
d5113358 74fCustomTPCetaMaps(),
4ec8e76d 75fBeamType("PP"),
76fLHCperiod(),
77fMCperiodTPC(),
fd21ec8d 78fMCperiodUser(),
ea235c90 79fCurrentFile(),
87da0205 80fCurrentAliRootRev(-1),
4ec8e76d 81fRecoPass(0),
fd21ec8d 82fRecoPassUser(-1),
1ceae0ac 83fRun(-1),
1b9e31a6 84fOldRun(-1),
78cbd205 85fResT0A(75.),
86fResT0C(65.),
87fResT0AC(55.),
644666df 88fArrPidResponseMaster(NULL),
89fResolutionCorrection(NULL),
90fOADBvoltageMaps(NULL),
87da0205 91fUseTPCEtaCorrection(kFALSE),
92fUseTPCMultiplicityCorrection(kFALSE),
644666df 93fTRDPIDResponseObject(NULL),
9c499471 94fTRDdEdxParams(NULL),
c5fb644a 95fTOFtail(0.9),
644666df 96fTOFPIDParams(NULL),
567624b5 97fHMPIDPIDParams(NULL),
644666df 98fEMCALPIDParams(NULL),
99fCurrentEvent(NULL),
42fcc729 100fCurrCentrality(0.0),
101fBeamTypeNum(kPP)
4ec8e76d 102{
103 //
104 // default ctor
105 //
a635821f 106 AliLog::SetClassDebugLevel("AliPIDResponse",0);
107 AliLog::SetClassDebugLevel("AliESDpid",0);
108 AliLog::SetClassDebugLevel("AliAODpidUtil",0);
ea235c90 109
4ec8e76d 110}
111
112//______________________________________________________________________________
113AliPIDResponse::~AliPIDResponse()
114{
115 //
116 // dtor
117 //
00a38d07 118 delete fArrPidResponseMaster;
119 delete fTRDPIDResponseObject;
9c499471 120 delete fTRDdEdxParams;
00a38d07 121 delete fTOFPIDParams;
4ec8e76d 122}
123
124//______________________________________________________________________________
125AliPIDResponse::AliPIDResponse(const AliPIDResponse &other) :
126TNamed(other),
127fITSResponse(other.fITSResponse),
128fTPCResponse(other.fTPCResponse),
129fTRDResponse(other.fTRDResponse),
130fTOFResponse(other.fTOFResponse),
567624b5 131fHMPIDResponse(other.fHMPIDResponse),
e96b9916 132fEMCALResponse(other.fEMCALResponse),
fd21ec8d 133fRange(other.fRange),
134fITSPIDmethod(other.fITSPIDmethod),
1ceae0ac 135fTuneMConData(other.fTuneMConData),
136fTuneMConDataMask(other.fTuneMConDataMask),
4ec8e76d 137fIsMC(other.fIsMC),
1c9d11be 138fCachePID(other.fCachePID),
4ec8e76d 139fOADBPath(other.fOADBPath),
00a38d07 140fCustomTPCpidResponse(other.fCustomTPCpidResponse),
d5113358 141fCustomTPCetaMaps(other.fCustomTPCetaMaps),
4ec8e76d 142fBeamType("PP"),
143fLHCperiod(),
144fMCperiodTPC(),
fd21ec8d 145fMCperiodUser(other.fMCperiodUser),
ea235c90 146fCurrentFile(),
87da0205 147fCurrentAliRootRev(other.fCurrentAliRootRev),
4ec8e76d 148fRecoPass(0),
fd21ec8d 149fRecoPassUser(other.fRecoPassUser),
1ceae0ac 150fRun(-1),
1b9e31a6 151fOldRun(-1),
78cbd205 152fResT0A(75.),
153fResT0C(65.),
154fResT0AC(55.),
644666df 155fArrPidResponseMaster(NULL),
156fResolutionCorrection(NULL),
157fOADBvoltageMaps(NULL),
f84b18dd 158fUseTPCEtaCorrection(other.fUseTPCEtaCorrection),
87da0205 159fUseTPCMultiplicityCorrection(other.fUseTPCMultiplicityCorrection),
644666df 160fTRDPIDResponseObject(NULL),
9c499471 161fTRDdEdxParams(NULL),
c5fb644a 162fTOFtail(0.9),
644666df 163fTOFPIDParams(NULL),
567624b5 164fHMPIDPIDParams(NULL),
644666df 165fEMCALPIDParams(NULL),
166fCurrentEvent(NULL),
42fcc729 167fCurrCentrality(0.0),
168fBeamTypeNum(kPP)
4ec8e76d 169{
170 //
171 // copy ctor
172 //
173}
174
175//______________________________________________________________________________
176AliPIDResponse& AliPIDResponse::operator=(const AliPIDResponse &other)
177{
178 //
179 // copy ctor
180 //
181 if(this!=&other) {
182 delete fArrPidResponseMaster;
183 TNamed::operator=(other);
184 fITSResponse=other.fITSResponse;
185 fTPCResponse=other.fTPCResponse;
186 fTRDResponse=other.fTRDResponse;
187 fTOFResponse=other.fTOFResponse;
567624b5 188 fHMPIDResponse=other.fHMPIDResponse;
e96b9916 189 fEMCALResponse=other.fEMCALResponse;
fd21ec8d 190 fRange=other.fRange;
191 fITSPIDmethod=other.fITSPIDmethod;
4ec8e76d 192 fOADBPath=other.fOADBPath;
00a38d07 193 fCustomTPCpidResponse=other.fCustomTPCpidResponse;
d5113358 194 fCustomTPCetaMaps=other.fCustomTPCetaMaps;
1ceae0ac 195 fTuneMConData=other.fTuneMConData;
196 fTuneMConDataMask=other.fTuneMConDataMask;
4ec8e76d 197 fIsMC=other.fIsMC;
1c9d11be 198 fCachePID=other.fCachePID;
4ec8e76d 199 fBeamType="PP";
42fcc729 200 fBeamTypeNum=kPP;
4ec8e76d 201 fLHCperiod="";
202 fMCperiodTPC="";
fd21ec8d 203 fMCperiodUser=other.fMCperiodUser;
ea235c90 204 fCurrentFile="";
87da0205 205 fCurrentAliRootRev=other.fCurrentAliRootRev;
4ec8e76d 206 fRecoPass=0;
fd21ec8d 207 fRecoPassUser=other.fRecoPassUser;
1ceae0ac 208 fRun=-1;
1b9e31a6 209 fOldRun=-1;
78cbd205 210 fResT0A=75.;
211 fResT0C=65.;
212 fResT0AC=55.;
644666df 213 fArrPidResponseMaster=NULL;
214 fResolutionCorrection=NULL;
215 fOADBvoltageMaps=NULL;
1ceae0ac 216 fUseTPCEtaCorrection=other.fUseTPCEtaCorrection;
87da0205 217 fUseTPCMultiplicityCorrection=other.fUseTPCMultiplicityCorrection;
644666df 218 fTRDPIDResponseObject=NULL;
9c499471 219 fTRDdEdxParams=NULL;
644666df 220 fEMCALPIDParams=NULL;
c5fb644a 221 fTOFtail=0.9;
644666df 222 fTOFPIDParams=NULL;
567624b5 223 fHMPIDPIDParams=NULL;
e96b9916 224 fCurrentEvent=other.fCurrentEvent;
87da0205 225
4ec8e76d 226 }
227 return *this;
228}
229
fd21ec8d 230//______________________________________________________________________________
355b831b 231Float_t AliPIDResponse::NumberOfSigmas(EDetector detector, const AliVParticle *vtrack, AliPID::EParticleType type) const
fd21ec8d 232{
233 //
234 // NumberOfSigmas for 'detCode'
235 //
355b831b 236
237 const AliVTrack *track=static_cast<const AliVTrack*>(vtrack);
238 // look for cached value first
239 const AliDetectorPID *detPID=track->GetDetectorPID();
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);
fd21ec8d 247 }
355b831b 248
249 return GetNumberOfSigmas(detector, track, type);
fd21ec8d 250}
251
e96b9916 252//______________________________________________________________________________
355b831b 253AliPIDResponse::EDetPidStatus AliPIDResponse::NumberOfSigmas(EDetector detCode, const AliVParticle *track,
254 AliPID::EParticleType type, Double_t &val) const
00a38d07 255{
256 //
355b831b 257 // NumberOfSigmas with detector status as return value
00a38d07 258 //
355b831b 259
260 val=NumberOfSigmas(detCode, track, type);
261 return CheckPIDStatus(detCode, (AliVTrack*)track);
00a38d07 262}
263
1c9d11be 264//______________________________________________________________________________
265// public buffered versions of the PID calculation
266//
267
00a38d07 268//______________________________________________________________________________
269Float_t AliPIDResponse::NumberOfSigmasITS(const AliVParticle *vtrack, AliPID::EParticleType type) const
270{
271 //
272 // Calculate the number of sigmas in the ITS
273 //
274
355b831b 275 return NumberOfSigmas(kITS, vtrack, type);
00a38d07 276}
277
278//______________________________________________________________________________
279Float_t AliPIDResponse::NumberOfSigmasTPC(const AliVParticle *vtrack, AliPID::EParticleType type) const
280{
281 //
282 // Calculate the number of sigmas in the TPC
283 //
284
355b831b 285 return NumberOfSigmas(kTPC, vtrack, type);
00a38d07 286}
287
644666df 288//______________________________________________________________________________
289Float_t AliPIDResponse::NumberOfSigmasTPC( const AliVParticle *vtrack,
290 AliPID::EParticleType type,
f84b18dd 291 AliTPCPIDResponse::ETPCdEdxSource dedxSource) const
644666df 292{
293 //get number of sigmas according the selected TPC gain configuration scenario
294 const AliVTrack *track=static_cast<const AliVTrack*>(vtrack);
295
87da0205 296 Float_t nSigma=fTPCResponse.GetNumberOfSigmas(track, type, dedxSource, fUseTPCEtaCorrection, fUseTPCMultiplicityCorrection);
644666df 297
298 return nSigma;
299}
300
5cd0300d 301//______________________________________________________________________________
302Float_t AliPIDResponse::NumberOfSigmasTRD(const AliVParticle *vtrack, AliPID::EParticleType type) const
303{
304 //
305 // Calculate the number of sigmas in the TRD
306 //
307 return NumberOfSigmas(kTRD, vtrack, type);
308}
309
00a38d07 310//______________________________________________________________________________
1c9d11be 311Float_t AliPIDResponse::NumberOfSigmasTOF(const AliVParticle *vtrack, AliPID::EParticleType type) const
00a38d07 312{
313 //
1c9d11be 314 // Calculate the number of sigmas in the TOF
00a38d07 315 //
316
355b831b 317 return NumberOfSigmas(kTOF, vtrack, type);
1c9d11be 318}
e96b9916 319
567624b5 320//______________________________________________________________________________
321Float_t AliPIDResponse::NumberOfSigmasHMPID(const AliVParticle *vtrack, AliPID::EParticleType type) const
322{
323 //
324 // Calculate the number of sigmas in the EMCAL
325 //
326
327 return NumberOfSigmas(kHMPID, vtrack, type);
328}
329
1c9d11be 330//______________________________________________________________________________
331Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVParticle *vtrack, AliPID::EParticleType type) const
332{
333 //
334 // Calculate the number of sigmas in the EMCAL
335 //
e96b9916 336
355b831b 337 return NumberOfSigmas(kEMCAL, vtrack, type);
e96b9916 338}
339
6d0064aa 340//______________________________________________________________________________
1c9d11be 341Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVParticle *vtrack, AliPID::EParticleType type, Double_t &eop, Double_t showershape[4]) const
342{
343 //
344 // emcal nsigma with eop and showershape
345 //
00a38d07 346 AliVTrack *track=(AliVTrack*)vtrack;
347
6d0064aa 348 AliVCluster *matchedClus = NULL;
349
350 Double_t mom = -1.;
351 Double_t pt = -1.;
352 Double_t EovP = -1.;
353 Double_t fClsE = -1.;
32fa24d6 354
355 // initialize eop and shower shape parameters
356 eop = -1.;
357 for(Int_t i = 0; i < 4; i++){
358 showershape[i] = -1.;
359 }
6d0064aa 360
361 Int_t nMatchClus = -1;
362 Int_t charge = 0;
363
364 // Track matching
365 nMatchClus = track->GetEMCALcluster();
366 if(nMatchClus > -1){
367
368 mom = track->P();
369 pt = track->Pt();
370 charge = track->Charge();
371
372 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
373
374 if(matchedClus){
375
376 // matched cluster is EMCAL
377 if(matchedClus->IsEMCAL()){
378
379 fClsE = matchedClus->E();
380 EovP = fClsE/mom;
381
382 // fill used EMCAL variables here
383 eop = EovP; // E/p
384 showershape[0] = matchedClus->GetNCells(); // number of cells in cluster
385 showershape[1] = matchedClus->GetM02(); // long axis
386 showershape[2] = matchedClus->GetM20(); // short axis
387 showershape[3] = matchedClus->GetDispersion(); // dispersion
1c9d11be 388
389 // look for cached value first
390 const AliDetectorPID *detPID=track->GetDetectorPID();
391 const EDetector detector=kEMCAL;
392
393 if ( detPID && detPID->HasNumberOfSigmas(detector)){
394 return detPID->GetNumberOfSigmas(detector, type);
395 } else if (fCachePID) {
396 FillTrackDetectorPID(track, detector);
397 detPID=track->GetDetectorPID();
398 return detPID->GetNumberOfSigmas(detector, type);
399 }
400
401 // NSigma value really meaningful only for electrons!
402 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
6d0064aa 403 }
404 }
405 }
406 return -999;
407}
408
567624b5 409//______________________________________________________________________________
1d59271b 410AliPIDResponse::EDetPidStatus AliPIDResponse::GetSignalDelta(EDetector detector, const AliVParticle *track, AliPID::EParticleType type, Double_t &val, Bool_t ratio/*=kFALSE*/) const
567624b5 411{
412 //
413 //
414 //
415 val=-9999.;
416 switch (detector){
1d59271b 417 case kITS: return GetSignalDeltaITS(track,type,val,ratio); break;
418 case kTPC: return GetSignalDeltaTPC(track,type,val,ratio); break;
5cd0300d 419 case kTRD: return GetSignalDeltaTRD(track,type,val,ratio); break;
1d59271b 420 case kTOF: return GetSignalDeltaTOF(track,type,val,ratio); break;
421 case kHMPID: return GetSignalDeltaHMPID(track,type,val,ratio); break;
567624b5 422 default: return kDetNoSignal;
423 }
424 return kDetNoSignal;
425}
426
427//______________________________________________________________________________
1d59271b 428Double_t AliPIDResponse::GetSignalDelta(EDetector detCode, const AliVParticle *track, AliPID::EParticleType type, Bool_t ratio/*=kFALSE*/) const
567624b5 429{
430 //
431 //
432 //
433 Double_t val=-9999.;
1d59271b 434 EDetPidStatus stat=GetSignalDelta(detCode, track, type, val, ratio);
567624b5 435 if ( stat==kDetNoSignal ) val=-9999.;
436 return val;
437}
438
00a38d07 439//______________________________________________________________________________
355b831b 440AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetCode detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
00a38d07 441{
00a38d07 442 // Compute PID response of 'detCode'
355b831b 443
444 // find detector code from detector bit mask
445 Int_t detector=-1;
446 for (Int_t idet=0; idet<kNdetectors; ++idet) if ( (detCode&(1<<idet)) ) { detector=idet; break; }
447 if (detector==-1) return kDetNoSignal;
00a38d07 448
355b831b 449 return ComputePIDProbability((EDetector)detector, track, nSpecies, p);
00a38d07 450}
451
fd21ec8d 452//______________________________________________________________________________
355b831b 453AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetector detector, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
fd21ec8d 454{
455 //
355b831b 456 // Compute PID response of 'detector'
fd21ec8d 457 //
458
1c9d11be 459 const AliDetectorPID *detPID=track->GetDetectorPID();
355b831b 460
461 if ( detPID && detPID->HasRawProbability(detector)){
1c9d11be 462 return detPID->GetRawProbability(detector, p, nSpecies);
463 } else if (fCachePID) {
464 FillTrackDetectorPID(track, detector);
465 detPID=track->GetDetectorPID();
466 return detPID->GetRawProbability(detector, p, nSpecies);
fd21ec8d 467 }
468
355b831b 469 //if no caching return values calculated from scratch
470 return GetComputePIDProbability(detector, track, nSpecies, p);
471}
472
473//______________________________________________________________________________
474AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeITSProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
475{
476 // Compute PID response for the ITS
477 return ComputePIDProbability(kITS, track, nSpecies, p);
fd21ec8d 478}
355b831b 479
fd21ec8d 480//______________________________________________________________________________
481AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTPCProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
482{
fd21ec8d 483 // Compute PID response for the TPC
355b831b 484 return ComputePIDProbability(kTPC, track, nSpecies, p);
fd21ec8d 485}
355b831b 486
fd21ec8d 487//______________________________________________________________________________
488AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTOFProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
489{
fd21ec8d 490 // Compute PID response for the
355b831b 491 return ComputePIDProbability(kTOF, track, nSpecies, p);
fd21ec8d 492}
355b831b 493
fd21ec8d 494//______________________________________________________________________________
355b831b 495AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
fd21ec8d 496{
fd21ec8d 497 // Compute PID response for the
355b831b 498 return ComputePIDProbability(kTRD, track, nSpecies, p);
fd21ec8d 499}
355b831b 500
fd21ec8d 501//______________________________________________________________________________
e96b9916 502AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeEMCALProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
fd21ec8d 503{
fd21ec8d 504 // Compute PID response for the EMCAL
355b831b 505 return ComputePIDProbability(kEMCAL, track, nSpecies, p);
1c9d11be 506}
507//______________________________________________________________________________
508AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePHOSProbability (const AliVTrack */*track*/, Int_t nSpecies, Double_t p[]) const
509{
1c9d11be 510 // Compute PID response for the PHOS
1c9d11be 511
512 // set flat distribution (no decision)
00a38d07 513 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1c9d11be 514 return kDetNoSignal;
515}
355b831b 516
1c9d11be 517//______________________________________________________________________________
518AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeHMPIDProbability(const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
519{
1c9d11be 520 // Compute PID response for the HMPID
355b831b 521 return ComputePIDProbability(kHMPID, track, nSpecies, p);
522}
fd21ec8d 523
355b831b 524//______________________________________________________________________________
525AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[],AliTRDPIDResponse::ETRDPIDMethod PIDmethod) const
526{
527 // Compute PID response for the
528 return GetComputeTRDProbability(track, nSpecies, p, PIDmethod);
529}
e96b9916 530
355b831b 531//______________________________________________________________________________
532AliPIDResponse::EDetPidStatus AliPIDResponse::CheckPIDStatus(EDetector detector, const AliVTrack *track) const
533{
534 // calculate detector pid status
535
536 const Int_t iDetCode=(Int_t)detector;
537 if (iDetCode<0||iDetCode>=kNdetectors) return kDetNoSignal;
538 const AliDetectorPID *detPID=track->GetDetectorPID();
539
540 if ( detPID ){
541 return detPID->GetPIDStatus(detector);
1c9d11be 542 } else if (fCachePID) {
543 FillTrackDetectorPID(track, detector);
544 detPID=track->GetDetectorPID();
355b831b 545 return detPID->GetPIDStatus(detector);
e96b9916 546 }
355b831b 547
548 // if not buffered and no buffering is requested
549 return GetPIDStatus(detector, track);
fd21ec8d 550}
551
4ec8e76d 552//______________________________________________________________________________
00a38d07 553void AliPIDResponse::InitialiseEvent(AliVEvent *event, Int_t pass, Int_t run)
4ec8e76d 554{
555 //
556 // Apply settings for the current event
557 //
558 fRecoPass=pass;
e96b9916 559
78cbd205 560
644666df 561 fCurrentEvent=NULL;
4ec8e76d 562 if (!event) return;
e96b9916 563 fCurrentEvent=event;
00a38d07 564 if (run>0) fRun=run;
565 else fRun=event->GetRunNumber();
4ec8e76d 566
567 if (fRun!=fOldRun){
568 ExecNewRun();
569 fOldRun=fRun;
570 }
571
572 //TPC resolution parametrisation PbPb
573 if ( fResolutionCorrection ){
574 Double_t corrSigma=fResolutionCorrection->Eval(GetTPCMultiplicityBin(event));
575 fTPCResponse.SetSigma(3.79301e-03*corrSigma, 2.21280e+04);
576 }
577
87da0205 578 // Set up TPC multiplicity for PbPb
22158469
JW
579 if (fUseTPCMultiplicityCorrection) {
580 Int_t numESDtracks = event->GetNumberOfESDTracks();
581 if (numESDtracks < 0) {
582 AliError("Cannot obtain event multiplicity (number of ESD tracks < 0). If you are using AODs, this might be a too old production. Please disable the multiplicity correction to get a reliable PID result!");
583 numESDtracks = 0;
584 }
585 fTPCResponse.SetCurrentEventMultiplicity(numESDtracks);
87da0205 586 }
87da0205 587 else
588 fTPCResponse.SetCurrentEventMultiplicity(0);
589
4ec8e76d 590 //TOF resolution
b79db598 591 SetTOFResponse(event, (AliPIDResponse::EStartTimeType_t)fTOFPIDParams->GetStartTimeMethod());
592
80f28562 593
594 // Get and set centrality
595 AliCentrality *centrality = event->GetCentrality();
596 if(centrality){
597 fCurrCentrality = centrality->GetCentralityPercentile("V0M");
598 }
599 else{
600 fCurrCentrality = -1;
601 }
87da0205 602
603 // Set centrality percentile for EMCAL
604 fEMCALResponse.SetCentrality(fCurrCentrality);
605
c53e310b 606 // switch off some TOF channel according to OADB to match data TOF matching eff
607 if (fTuneMConData && ((fTuneMConDataMask & kDetTOF) == kDetTOF) && fTOFPIDParams->GetTOFmatchingLossMC() > 0.01){
608 Int_t ntrk = event->GetNumberOfTracks();
609 for(Int_t i=0;i < ntrk;i++){
610 AliVParticle *trk = event->GetTrack(i);
611 Int_t channel = GetTOFResponse().GetTOFchannel(trk);
612 Int_t swoffEachOfThem = Int_t(100./fTOFPIDParams->GetTOFmatchingLossMC() + 0.5);
613 if(!(channel%swoffEachOfThem)) ((AliVTrack *) trk)->ResetStatus(AliVTrack::kTOFout);
614 }
615 }
616
4ec8e76d 617}
618
619//______________________________________________________________________________
620void AliPIDResponse::ExecNewRun()
621{
622 //
623 // Things to Execute upon a new run
624 //
625 SetRecoInfo();
626
627 SetITSParametrisation();
628
629 SetTPCPidResponseMaster();
630 SetTPCParametrisation();
f84b18dd 631 SetTPCEtaMaps();
53d016dc 632
633 SetTRDPidResponseMaster();
5eb3e944 634 //has to precede InitializeTRDResponse(), otherwise the read-out fTRDdEdxParams is not pased in TRDResponse!
9c499471 635 SetTRDdEdxParams();
53d016dc 636 InitializeTRDResponse();
b2138b40 637
638 SetEMCALPidResponseMaster();
639 InitializeEMCALResponse();
4ec8e76d 640
b79db598 641 SetTOFPidResponseMaster();
642 InitializeTOFResponse();
644666df 643
567624b5 644 SetHMPIDPidResponseMaster();
645 InitializeHMPIDResponse();
646
644666df 647 if (fCurrentEvent) fTPCResponse.SetMagField(fCurrentEvent->GetMagneticField());
4ec8e76d 648}
649
1c9d11be 650//______________________________________________________________________________
4ec8e76d 651Double_t AliPIDResponse::GetTPCMultiplicityBin(const AliVEvent * const event)
652{
653 //
654 // Get TPC multiplicity in bins of 150
655 //
656
657 const AliVVertex* vertexTPC = event->GetPrimaryVertex();
658 Double_t tpcMulti=0.;
659 if(vertexTPC){
660 Double_t vertexContribTPC=vertexTPC->GetNContributors();
661 tpcMulti=vertexContribTPC/150.;
662 if (tpcMulti>20.) tpcMulti=20.;
663 }
664
665 return tpcMulti;
666}
667
668//______________________________________________________________________________
669void AliPIDResponse::SetRecoInfo()
670{
671 //
672 // Set reconstruction information
673 //
674
675 //reset information
676 fLHCperiod="";
677 fMCperiodTPC="";
678
679 fBeamType="";
680
681 fBeamType="PP";
42fcc729 682 fBeamTypeNum=kPP;
bbce5a64 683
684 Bool_t hasProdInfo=(fCurrentFile.BeginsWith("LHC"));
4ec8e76d 685
3e95957e 686 TPRegexp reg(".*(LHC1[1-3][a-z]+[0-9]+[a-z_]*)[/_].*");
bbce5a64 687 if (hasProdInfo) reg=TPRegexp("LHC1[1-2][a-z]+[0-9]+[a-z_]*");
ea6ba565 688 TPRegexp reg12a17("LHC1[2-4][a-z]");
1436d6bb 689
4ec8e76d 690 //find the period by run number (UGLY, but not stored in ESD and AOD... )
691 if (fRun>=114737&&fRun<=117223) { fLHCperiod="LHC10B"; fMCperiodTPC="LHC10D1"; }
692 else if (fRun>=118503&&fRun<=121040) { fLHCperiod="LHC10C"; fMCperiodTPC="LHC10D1"; }
693 else if (fRun>=122195&&fRun<=126437) { fLHCperiod="LHC10D"; fMCperiodTPC="LHC10F6A"; }
99e9d5ec 694 else if (fRun>=127710&&fRun<=130850) { fLHCperiod="LHC10E"; fMCperiodTPC="LHC10F6A"; }
4ec8e76d 695 else if (fRun>=133004&&fRun<=135029) { fLHCperiod="LHC10F"; fMCperiodTPC="LHC10F6A"; }
696 else if (fRun>=135654&&fRun<=136377) { fLHCperiod="LHC10G"; fMCperiodTPC="LHC10F6A"; }
12d3abbc 697 else if (fRun>=136851&&fRun<=139846) {
ea235c90 698 fLHCperiod="LHC10H";
699 fMCperiodTPC="LHC10H8";
700 if (reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11A10";
ef7661fd 701 // exception for 13d2 and later
702 if (fCurrentAliRootRev >= 62714) fMCperiodTPC="LHC13D2";
ea235c90 703 fBeamType="PBPB";
42fcc729 704 fBeamTypeNum=kPBPB;
ea235c90 705 }
12d3abbc 706 else if (fRun>=139847&&fRun<=146974) { fLHCperiod="LHC11A"; fMCperiodTPC="LHC10F6A"; }
707 //TODO: periods 11B (146975-150721), 11C (150722-155837) are not yet treated assume 11d for the moment
708 else if (fRun>=146975&&fRun<=155837) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
709 else if (fRun>=155838&&fRun<=159649) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
710 // also for 11e (159650-162750),f(162751-165771) use 11d
711 else if (fRun>=159650&&fRun<=162750) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
712 else if (fRun>=162751&&fRun<=165771) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
00a38d07 713
12d3abbc 714 else if (fRun>=165772 && fRun<=170718) {
3077a03d 715 fLHCperiod="LHC11H";
716 fMCperiodTPC="LHC11A10";
717 fBeamType="PBPB";
42fcc729 718 fBeamTypeNum=kPBPB;
a78fd045 719 if (reg12a17.MatchB(fCurrentFile)) fMCperiodTPC="LHC12A17";
3077a03d 720 }
03696add 721 if (fRun>=170719 && fRun<=177311) {
722 fLHCperiod="LHC12A";
723 fBeamType="PP";
724 fBeamTypeNum=kPP;
725 fMCperiodTPC="LHC10F6A";
726 if (fCurrentAliRootRev >= 62714)
dbeb0132 727 fMCperiodTPC="LHC14E2";
03696add 728 }
3b3bf053 729 // for the moment use LHC12b parameters up to LHC12d
03696add 730 if (fRun>=177312 /*&& fRun<=179356*/) {
731 fLHCperiod="LHC12B";
732 fBeamType="PP";
733 fBeamTypeNum=kPP;
734 fMCperiodTPC="LHC10F6A";
735 if (fCurrentAliRootRev >= 62714)
dbeb0132 736 fMCperiodTPC="LHC14E2";
03696add 737 }
42fcc729 738// if (fRun>=179357 && fRun<=183173) { fLHCperiod="LHC12C"; fBeamType="PP"; fBeamTypeNum=kPP;/*fMCperiodTPC="";*/ }
739// if (fRun>=183174 && fRun<=186345) { fLHCperiod="LHC12D"; fBeamType="PP"; fBeamTypeNum=kPP;/*fMCperiodTPC="";*/ }
740// if (fRun>=186346 && fRun<=186635) { fLHCperiod="LHC12E"; fBeamType="PP"; fBeamTypeNum=kPP;/*fMCperiodTPC="";*/ }
741
742// if (fRun>=186636 && fRun<=188166) { fLHCperiod="LHC12F"; fBeamType="PP"; fBeamTypeNum=kPP;/*fMCperiodTPC="";*/ }
743// if (fRun >= 188167 && fRun <= 188355 ) { fLHCperiod="LHC12G"; fBeamType="PP"; fBeamTypeNum=kPP;/*fMCperiodTPC="";*/ }
744// if (fRun >= 188356 && fRun <= 188503 ) { fLHCperiod="LHC12G"; fBeamType="PPB"; fBeamTypeNum=kPPB;/*fMCperiodTPC="";*/ }
3b3bf053 745// for the moment use 12g parametrisation for all full gain runs (LHC12e+)
5b7afd75 746 if (fRun >= 186346 && fRun < 188719) { fLHCperiod="LHC12G"; fBeamType="PPB";fBeamTypeNum=kPPB; fMCperiodTPC="LHC12G"; }
87da0205 747
5b7afd75 748 // Dedicated splines for periods 12g and 12i(j) (and use more appropriate MC)
749 if (fRun >= 188720 && fRun <= 192738) {
750 fLHCperiod="LHC12H";
751 fBeamType="PP";
752 fBeamTypeNum=kPP;
753 fMCperiodTPC="LHC10F6A";
754 if (fCurrentAliRootRev >= 62714)
755 fMCperiodTPC="LHC13B2_FIXn1";
756 }
757 if (fRun >= 192739 && fRun <= 194479) {
758 fLHCperiod="LHC12I";
759 fBeamType="PP";
760 fBeamTypeNum=kPP;
761 fMCperiodTPC="LHC10F6A";
762 if (fCurrentAliRootRev >= 62714)
763 fMCperiodTPC="LHC13B2_FIXn1";
764 }
765
87da0205 766 // New parametrisation for 2013 pPb runs
5b7afd75 767 if (fRun >= 194480) {
87da0205 768 fLHCperiod="LHC13B";
769 fBeamType="PPB";
42fcc729 770 fBeamTypeNum=kPPB;
bbce5a64 771 fMCperiodTPC="LHC12G";
87da0205 772
773 if (fCurrentAliRootRev >= 61605)
774 fMCperiodTPC="LHC13B2_FIX";
bbce5a64 775 if (fCurrentAliRootRev >= 62714)
776 fMCperiodTPC="LHC13B2_FIXn1";
c4bec231 777
778 // High luminosity pPb runs require different parametrisations
779 if (fRun >= 195875 && fRun <= 197411) {
780 fLHCperiod="LHC13F";
781 }
87da0205 782 }
80ab5635 783
66de625c 784 //exception new pp MC productions from 2011 (11a periods have 10f6a splines!)
42fcc729 785 if (fBeamType=="PP" && reg.MatchB(fCurrentFile) && !fCurrentFile.Contains("LHC11a")) { fMCperiodTPC="LHC11B2"; fBeamType="PP";fBeamTypeNum=kPP; }
4a527e08 786 // exception for 11f1
bbce5a64 787 if (fCurrentFile.Contains("LHC11f1")) fMCperiodTPC="LHC11F1";
bf26ce58 788 // exception for 12f1a, 12f1b and 12i3
bbce5a64 789 if (fCurrentFile.Contains("LHC12f1") || fCurrentFile.Contains("LHC12i3")) fMCperiodTPC="LHC12F1";
c3ee524d 790 // exception for 12c4
bbce5a64 791 if (fCurrentFile.Contains("LHC12c4")) fMCperiodTPC="LHC12C4";
361813a2 792 // exception for 13d1 11d anchored prod
793 if (fLHCperiod=="LHC11D" && fCurrentFile.Contains("LHC13d1")) fMCperiodTPC="LHC13D1";
4ec8e76d 794}
795
796//______________________________________________________________________________
797void AliPIDResponse::SetITSParametrisation()
798{
799 //
800 // Set the ITS parametrisation
801 //
802}
803
f84b18dd 804
805//______________________________________________________________________________
806void AliPIDResponse::AddPointToHyperplane(TH2D* h, TLinearFitter* linExtrapolation, Int_t binX, Int_t binY)
807{
808 if (h->GetBinContent(binX, binY) <= 1e-4)
809 return; // Reject bins without content (within some numerical precision) or with strange content
810
811 Double_t coord[2] = {0, 0};
812 coord[0] = h->GetXaxis()->GetBinCenter(binX);
813 coord[1] = h->GetYaxis()->GetBinCenter(binY);
814 Double_t binError = h->GetBinError(binX, binY);
815 if (binError <= 0) {
816 binError = 1000; // Should not happen because bins without content are rejected for the map (TH2D* h)
817 printf("ERROR: This should never happen: Trying to add bin in addPointToHyperplane with error not set....\n");
818 }
819 linExtrapolation->AddPoint(coord, h->GetBinContent(binX, binY, binError));
820}
821
822
823//______________________________________________________________________________
824TH2D* AliPIDResponse::RefineHistoViaLinearInterpolation(TH2D* h, Double_t refineFactorX, Double_t refineFactorY)
825{
826 if (!h)
827 return 0x0;
828
829 // Interpolate to finer map
830 TLinearFitter* linExtrapolation = new TLinearFitter(2, "hyp2", "");
831
832 Double_t upperMapBoundY = h->GetYaxis()->GetBinUpEdge(h->GetYaxis()->GetNbins());
833 Double_t lowerMapBoundY = h->GetYaxis()->GetBinLowEdge(1);
1b45e564 834 Int_t nBinsX = 30;
f84b18dd 835 // 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,
836 // scale the number of bins correspondingly
1b45e564 837 Int_t nBinsY = TMath::Nint((upperMapBoundY - lowerMapBoundY) / (0.02 - 0.0016) * 40);
f84b18dd 838 Int_t nBinsXrefined = nBinsX * refineFactorX;
839 Int_t nBinsYrefined = nBinsY * refineFactorY;
840
841 TH2D* hRefined = new TH2D(Form("%s_refined", h->GetName()), Form("%s (refined)", h->GetTitle()),
842 nBinsXrefined, h->GetXaxis()->GetBinLowEdge(1), h->GetXaxis()->GetBinUpEdge(h->GetXaxis()->GetNbins()),
843 nBinsYrefined, lowerMapBoundY, upperMapBoundY);
844
845 for (Int_t binX = 1; binX <= nBinsXrefined; binX++) {
846 for (Int_t binY = 1; binY <= nBinsYrefined; binY++) {
847
848 hRefined->SetBinContent(binX, binY, 1); // Default value is 1
849
850 Double_t centerX = hRefined->GetXaxis()->GetBinCenter(binX);
851 Double_t centerY = hRefined->GetYaxis()->GetBinCenter(binY);
852
1b45e564 853 /*OLD
f84b18dd 854 linExtrapolation->ClearPoints();
855
856 // For interpolation: Just take the corresponding bin from the old histo.
857 // For extrapolation: take the last available bin from the old histo.
858 // If the boundaries are to be skipped, also skip the corresponding bins
859 Int_t oldBinX = h->GetXaxis()->FindBin(centerX);
860 if (oldBinX < 1)
861 oldBinX = 1;
862 if (oldBinX > nBinsX)
863 oldBinX = nBinsX;
864
865 Int_t oldBinY = h->GetYaxis()->FindBin(centerY);
866 if (oldBinY < 1)
867 oldBinY = 1;
868 if (oldBinY > nBinsY)
869 oldBinY = nBinsY;
870
871 // Neighbours left column
872 if (oldBinX >= 2) {
873 if (oldBinY >= 2) {
874 AddPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY - 1);
875 }
876
877 AddPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY);
878
879 if (oldBinY < nBinsY) {
880 AddPointToHyperplane(h, linExtrapolation, oldBinX - 1, oldBinY + 1);
881 }
882 }
883
884 // Neighbours (and point itself) same column
885 if (oldBinY >= 2) {
886 AddPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY - 1);
887 }
888
889 AddPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY);
890
891 if (oldBinY < nBinsY) {
892 AddPointToHyperplane(h, linExtrapolation, oldBinX, oldBinY + 1);
893 }
894
895 // Neighbours right column
896 if (oldBinX < nBinsX) {
897 if (oldBinY >= 2) {
898 AddPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY - 1);
899 }
900
901 AddPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY);
902
903 if (oldBinY < nBinsY) {
904 AddPointToHyperplane(h, linExtrapolation, oldBinX + 1, oldBinY + 1);
905 }
906 }
907
908
909 // Fit 2D-hyperplane
910 if (linExtrapolation->GetNpoints() <= 0)
911 continue;
912
913 if (linExtrapolation->Eval() != 0)// EvalRobust -> Takes much, much, [...], much more time (~hours instead of seconds)
914 continue;
915
916 // Fill the bin of the refined histogram with the extrapolated value
917 Double_t interpolatedValue = linExtrapolation->GetParameter(0) + linExtrapolation->GetParameter(1) * centerX
918 + linExtrapolation->GetParameter(2) * centerY;
919 */
f85a3764 920 Double_t interpolatedValue = h->Interpolate(centerX, centerY) ;
f84b18dd 921 hRefined->SetBinContent(binX, binY, interpolatedValue);
922 }
923 }
924
1b45e564 925
926 // Problem: Interpolation does not work before/beyond center of first/last bin (as the name suggests).
927 // Therefore, for each row in dEdx: Take last bin from old map and interpolate values from center and edge.
928 // Assume line through these points and extropolate to last bin of refined map
929 const Double_t firstOldXbinUpEdge = h->GetXaxis()->GetBinUpEdge(1);
930 const Double_t firstOldXbinCenter = h->GetXaxis()->GetBinCenter(1);
931
932 const Double_t oldXbinHalfWidth = firstOldXbinUpEdge - firstOldXbinCenter;
933
934 const Double_t lastOldXbinLowEdge = h->GetXaxis()->GetBinLowEdge(h->GetNbinsX());
935 const Double_t lastOldXbinCenter = h->GetXaxis()->GetBinCenter(h->GetNbinsX());
936
937 for (Int_t binY = 1; binY <= nBinsYrefined; binY++) {
938 Double_t centerY = hRefined->GetYaxis()->GetBinCenter(binY);
939
940 const Double_t interpolatedCenterFirstXbin = h->Interpolate(firstOldXbinCenter, centerY);
941 const Double_t interpolatedUpEdgeFirstXbin = h->Interpolate(firstOldXbinUpEdge, centerY);
942
943 const Double_t extrapolationSlopeFirstXbin = (interpolatedUpEdgeFirstXbin - interpolatedCenterFirstXbin) / oldXbinHalfWidth;
944 const Double_t extrapolationOffsetFirstXbin = interpolatedCenterFirstXbin;
945
946
947 const Double_t interpolatedCenterLastXbin = h->Interpolate(lastOldXbinCenter, centerY);
948 const Double_t interpolatedLowEdgeLastXbin = h->Interpolate(lastOldXbinLowEdge, centerY);
949
950 const Double_t extrapolationSlopeLastXbin = (interpolatedCenterLastXbin - interpolatedLowEdgeLastXbin) / oldXbinHalfWidth;
951 const Double_t extrapolationOffsetLastXbin = interpolatedCenterLastXbin;
952
953 for (Int_t binX = 1; binX <= nBinsXrefined; binX++) {
954 Double_t centerX = hRefined->GetXaxis()->GetBinCenter(binX);
955
956 if (centerX < firstOldXbinCenter) {
957 Double_t extrapolatedValue = extrapolationOffsetFirstXbin + (centerX - firstOldXbinCenter) * extrapolationSlopeFirstXbin;
958 hRefined->SetBinContent(binX, binY, extrapolatedValue);
959 }
960 else if (centerX <= lastOldXbinCenter) {
961 continue;
962 }
963 else {
964 Double_t extrapolatedValue = extrapolationOffsetLastXbin + (centerX - lastOldXbinCenter) * extrapolationSlopeLastXbin;
965 hRefined->SetBinContent(binX, binY, extrapolatedValue);
966 }
967 }
968 }
969
f84b18dd 970 delete linExtrapolation;
971
972 return hRefined;
973}
974
975//______________________________________________________________________________
976void AliPIDResponse::SetTPCEtaMaps(Double_t refineFactorMapX, Double_t refineFactorMapY,
977 Double_t refineFactorSigmaMapX, Double_t refineFactorSigmaMapY)
978{
979 //
980 // Load the TPC eta correction maps from the OADB
981 //
982
f85a3764 983 if (fUseTPCEtaCorrection == kFALSE) {
984 // Disable eta correction via setting no maps
985 if (!fTPCResponse.SetEtaCorrMap(0x0))
1b45e564 986 AliInfo("Request to disable TPC eta correction -> Eta correction has been disabled");
f85a3764 987 else
988 AliError("Request to disable TPC eta correction -> Some error occured when unloading the correction maps");
989
990 if (!fTPCResponse.SetSigmaParams(0x0, 0))
1b45e564 991 AliInfo("Request to disable TPC eta correction -> Using old parametrisation for sigma");
992 else
f85a3764 993 AliError("Request to disable TPC eta correction -> Some error occured when unloading the sigma maps");
994
995 return;
996 }
1b45e564 997
f84b18dd 998 TString dataType = "DATA";
999 TString period = fLHCperiod.IsNull() ? "No period information" : fLHCperiod;
1000
1001 if (fIsMC) {
87da0205 1002 if (!(fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC))) {
f85a3764 1003 period=fMCperiodTPC;
1004 dataType="MC";
1005 }
f84b18dd 1006 fRecoPass = 1;
1007
87da0205 1008 if (!(fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC)) && fMCperiodTPC.IsNull()) {
f84b18dd 1009 AliFatal("MC detected, but no MC period set -> Not changing eta maps!");
1010 return;
1011 }
f84b18dd 1012 }
f85a3764 1013
1014 Int_t recopass = fRecoPass;
a2c30af1 1015 if (fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC) )
f85a3764 1016 recopass = fRecoPassUser;
f84b18dd 1017
f85a3764 1018 TString defaultObj = Form("Default_%s_pass%d", dataType.Data(), recopass);
f84b18dd 1019
f85a3764 1020 AliInfo(Form("Current period and reco pass: %s.pass%d", period.Data(), recopass));
f84b18dd 1021
1022 // Invalidate old maps
1023 fTPCResponse.SetEtaCorrMap(0x0);
1024 fTPCResponse.SetSigmaParams(0x0, 0);
1025
d5113358 1026
1027 TString fileNameMaps(Form("%s/COMMON/PID/data/TPCetaMaps.root", fOADBPath.Data()));
1028 if (!fCustomTPCetaMaps.IsNull()) fileNameMaps=fCustomTPCetaMaps;
1029
f84b18dd 1030 // Load the eta correction maps
f85a3764 1031 AliOADBContainer etaMapsCont(Form("TPCetaMaps_%s_pass%d", dataType.Data(), recopass));
f84b18dd 1032
d5113358 1033 Int_t statusCont = etaMapsCont.InitFromFile(fileNameMaps.Data(), Form("TPCetaMaps_%s_pass%d", dataType.Data(), recopass));
f84b18dd 1034 if (statusCont) {
1035 AliError("Failed initializing TPC eta correction maps from OADB -> Disabled eta correction");
87da0205 1036 fUseTPCEtaCorrection = kFALSE;
f84b18dd 1037 }
1038 else {
d5113358 1039 AliInfo(Form("Loading TPC eta correction map from %s", fileNameMaps.Data()));
f84b18dd 1040
1041 TH2D* etaMap = 0x0;
1042
87da0205 1043 if (fIsMC && !(fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC))) {
f85a3764 1044 TString searchMap = Form("TPCetaMaps_%s_%s_pass%d", dataType.Data(), period.Data(), recopass);
f84b18dd 1045 etaMap = dynamic_cast<TH2D *>(etaMapsCont.GetDefaultObject(searchMap.Data()));
1046 if (!etaMap) {
1047 // Try default object
1048 etaMap = dynamic_cast<TH2D *>(etaMapsCont.GetDefaultObject(defaultObj.Data()));
1049 }
1050 }
1051 else {
1052 etaMap = dynamic_cast<TH2D *>(etaMapsCont.GetObject(fRun, defaultObj.Data()));
1053 }
1054
1055
1056 if (!etaMap) {
1057 AliError(Form("TPC eta correction map not found for run %d and also no default map found -> Disabled eta correction!!!", fRun));
87da0205 1058 fUseTPCEtaCorrection = kFALSE;
f84b18dd 1059 }
1060 else {
1061 TH2D* etaMapRefined = RefineHistoViaLinearInterpolation(etaMap, refineFactorMapX, refineFactorMapY);
1062
1063 if (etaMapRefined) {
1064 if (!fTPCResponse.SetEtaCorrMap(etaMapRefined)) {
1065 AliError(Form("Failed to set TPC eta correction map for run %d -> Disabled eta correction!!!", fRun));
1066 fTPCResponse.SetEtaCorrMap(0x0);
87da0205 1067 fUseTPCEtaCorrection = kFALSE;
f84b18dd 1068 }
1069 else {
d5113358 1070 AliInfo(Form("Loaded TPC eta correction map (refine factors %.2f/%.2f) from %s: %s (MD5(map) = %s)",
1071 refineFactorMapX, refineFactorMapY, fileNameMaps.Data(), fTPCResponse.GetEtaCorrMap()->GetTitle(),
5a9dc560 1072 GetChecksum(fTPCResponse.GetEtaCorrMap()).Data()));
f84b18dd 1073 }
1074
1075 delete etaMapRefined;
1076 }
1077 else {
1078 AliError(Form("Failed to set TPC eta correction map for run %d (map was loaded, but couldn't be refined) -> Disabled eta correction!!!", fRun));
87da0205 1079 fUseTPCEtaCorrection = kFALSE;
f84b18dd 1080 }
1081 }
1082 }
1083
87da0205 1084 // If there was some problem loading the eta maps, it makes no sense to load the sigma maps (that require eta corrected data)
1085 if (fUseTPCEtaCorrection == kFALSE) {
1086 AliError("Failed to load TPC eta correction map required by sigma maps -> Using old parametrisation for sigma");
1087 return;
1088 }
1089
f84b18dd 1090 // Load the sigma parametrisation (1/dEdx vs tanTheta_local (~eta))
f85a3764 1091 AliOADBContainer etaSigmaMapsCont(Form("TPCetaSigmaMaps_%s_pass%d", dataType.Data(), recopass));
f84b18dd 1092
d5113358 1093 statusCont = etaSigmaMapsCont.InitFromFile(fileNameMaps.Data(), Form("TPCetaSigmaMaps_%s_pass%d", dataType.Data(), recopass));
f84b18dd 1094 if (statusCont) {
1095 AliError("Failed initializing TPC eta sigma maps from OADB -> Using old sigma parametrisation");
1096 }
1097 else {
d5113358 1098 AliInfo(Form("Loading TPC eta sigma map from %s", fileNameMaps.Data()));
f84b18dd 1099
1100 TObjArray* etaSigmaPars = 0x0;
1101
87da0205 1102 if (fIsMC && !(fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC))) {
f85a3764 1103 TString searchMap = Form("TPCetaSigmaMaps_%s_%s_pass%d", dataType.Data(), period.Data(), recopass);
f84b18dd 1104 etaSigmaPars = dynamic_cast<TObjArray *>(etaSigmaMapsCont.GetDefaultObject(searchMap.Data()));
1105 if (!etaSigmaPars) {
1106 // Try default object
1107 etaSigmaPars = dynamic_cast<TObjArray *>(etaSigmaMapsCont.GetDefaultObject(defaultObj.Data()));
1108 }
1109 }
1110 else {
1111 etaSigmaPars = dynamic_cast<TObjArray *>(etaSigmaMapsCont.GetObject(fRun, defaultObj.Data()));
1112 }
1113
1114 if (!etaSigmaPars) {
1115 AliError(Form("TPC eta sigma parametrisation not found for run %d -> Using old sigma parametrisation!!!", fRun));
1116 }
1117 else {
1118 TH2D* etaSigmaPar1Map = dynamic_cast<TH2D *>(etaSigmaPars->FindObject("sigmaPar1Map"));
1119 TNamed* sigmaPar0Info = dynamic_cast<TNamed *>(etaSigmaPars->FindObject("sigmaPar0"));
1120 Double_t sigmaPar0 = 0.0;
1121
1122 if (sigmaPar0Info) {
1123 TString sigmaPar0String = sigmaPar0Info->GetTitle();
1124 sigmaPar0 = sigmaPar0String.Atof();
1125 }
1126 else {
1127 // Something is weired because the object for parameter 0 could not be loaded -> New sigma parametrisation can not be used!
1128 etaSigmaPar1Map = 0x0;
1129 }
1130
1131 TH2D* etaSigmaPar1MapRefined = RefineHistoViaLinearInterpolation(etaSigmaPar1Map, refineFactorSigmaMapX, refineFactorSigmaMapY);
1132
1133
1134 if (etaSigmaPar1MapRefined) {
1135 if (!fTPCResponse.SetSigmaParams(etaSigmaPar1MapRefined, sigmaPar0)) {
1136 AliError(Form("Failed to set TPC eta sigma map for run %d -> Using old sigma parametrisation!!!", fRun));
1137 fTPCResponse.SetSigmaParams(0x0, 0);
1138 }
1139 else {
d5113358 1140 AliInfo(Form("Loaded TPC sigma correction map (refine factors %.2f/%.2f) from %s: %s (MD5(map) = %s, sigmaPar0 = %f)",
1141 refineFactorSigmaMapX, refineFactorSigmaMapY, fileNameMaps.Data(), fTPCResponse.GetSigmaPar1Map()->GetTitle(),
5a9dc560 1142 GetChecksum(fTPCResponse.GetSigmaPar1Map()).Data(), sigmaPar0));
f84b18dd 1143 }
1144
1145 delete etaSigmaPar1MapRefined;
1146 }
1147 else {
1148 AliError(Form("Failed to set TPC eta sigma map for run %d (map was loaded, but couldn't be refined) -> Using old sigma parametrisation!!!",
1149 fRun));
1150 }
1151 }
1152 }
1153}
1154
4ec8e76d 1155//______________________________________________________________________________
1156void AliPIDResponse::SetTPCPidResponseMaster()
1157{
1158 //
1159 // Load the TPC pid response functions from the OADB
644666df 1160 // Load the TPC voltage maps from OADB
4ec8e76d 1161 //
09b50a42 1162 //don't load twice for the moment
1163 if (fArrPidResponseMaster) return;
1164
1165
4ec8e76d 1166 //reset the PID response functions
1167 delete fArrPidResponseMaster;
644666df 1168 fArrPidResponseMaster=NULL;
4ec8e76d 1169
644666df 1170 TFile *f=NULL;
4ec8e76d 1171
644666df 1172 TString fileNamePIDresponse(Form("%s/COMMON/PID/data/TPCPIDResponse.root", fOADBPath.Data()));
d5113358 1173 if (!fCustomTPCpidResponse.IsNull()) fileNamePIDresponse=fCustomTPCpidResponse;
1174
644666df 1175 f=TFile::Open(fileNamePIDresponse.Data());
ea235c90 1176 if (f && f->IsOpen() && !f->IsZombie()){
1177 fArrPidResponseMaster=dynamic_cast<TObjArray*>(f->Get("TPCPIDResponse"));
4ec8e76d 1178 }
ea235c90 1179 delete f;
644666df 1180
1181 TString fileNameVoltageMaps(Form("%s/COMMON/PID/data/TPCvoltageSettings.root", fOADBPath.Data()));
1182 f=TFile::Open(fileNameVoltageMaps.Data());
1183 if (f && f->IsOpen() && !f->IsZombie()){
1184 fOADBvoltageMaps=dynamic_cast<AliOADBContainer*>(f->Get("TPCvoltageSettings"));
1185 }
1186 delete f;
4ec8e76d 1187
1188 if (!fArrPidResponseMaster){
644666df 1189 AliFatal(Form("Could not retrieve the TPC pid response from: %s",fileNamePIDresponse.Data()));
4ec8e76d 1190 return;
1191 }
1192 fArrPidResponseMaster->SetOwner();
644666df 1193
1194 if (!fOADBvoltageMaps)
1195 {
1196 AliFatal(Form("Could not retrieve the TPC voltage maps from: %s",fileNameVoltageMaps.Data()));
1197 }
1198 fArrPidResponseMaster->SetOwner();
4ec8e76d 1199}
1200
1201//______________________________________________________________________________
1202void AliPIDResponse::SetTPCParametrisation()
1203{
1204 //
1205 // Change BB parametrisation for current run
1206 //
1207
12d3abbc 1208 //
1209 //reset old splines
1210 //
1211 fTPCResponse.ResetSplines();
1212
4ec8e76d 1213 if (fLHCperiod.IsNull()) {
12d3abbc 1214 AliError("No period set, not changing parametrisation");
4ec8e76d 1215 return;
1216 }
1217
1218 //
1219 // Set default parametrisations for data and MC
1220 //
1221
1222 //data type
1223 TString datatype="DATA";
1224 //in case of mc fRecoPass is per default 1
1225 if (fIsMC) {
87da0205 1226 if(!(fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC))) datatype="MC";
539a5a59 1227 fRecoPass=1;
4ec8e76d 1228 }
f84b18dd 1229
4a527e08 1230 // period
1231 TString period=fLHCperiod;
87da0205 1232 if (fIsMC && !(fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC))) period=fMCperiodTPC;
4a527e08 1233
f85a3764 1234 Int_t recopass = fRecoPass;
87da0205 1235 if(fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC)) recopass = fRecoPassUser;
f85a3764 1236
1237 AliInfo(Form("Searching splines for: %s %s PASS%d %s",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
4a527e08 1238 Bool_t found=kFALSE;
4ec8e76d 1239 //
1240 //set the new PID splines
1241 //
4ec8e76d 1242 if (fArrPidResponseMaster){
4ec8e76d 1243 //for MC don't use period information
644666df 1244 //if (fIsMC) period="[A-Z0-9]*";
4ec8e76d 1245 //for MC use MC period information
644666df 1246 //pattern for the default entry (valid for all particles)
de678885 1247 TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN(_*)([A-Z1-9]*)",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
644666df 1248
f85a3764 1249 //find particle id and gain scenario
644666df 1250 for (Int_t igainScenario=0; igainScenario<AliTPCPIDResponse::fgkNumberOfGainScenarios; igainScenario++)
1251 {
1252 TObject *grAll=NULL;
1253 TString gainScenario = AliTPCPIDResponse::GainScenarioName(igainScenario);
1254 gainScenario.ToUpper();
1255 //loop over entries and filter them
1256 for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp)
1257 {
1258 TObject *responseFunction=fArrPidResponseMaster->At(iresp);
1259 if (responseFunction==NULL) continue;
1260 TString responseName=responseFunction->GetName();
1261
1262 if (!reg.MatchB(responseName)) continue;
1263
1264 TObjArray *arr=reg.MatchS(responseName); if (!arr) continue;
1265 TObject* tmp=NULL;
1266 tmp=arr->At(1); if (!tmp) continue;
1267 TString particleName=tmp->GetName();
1268 tmp=arr->At(3); if (!tmp) continue;
1269 TString gainScenarioName=tmp->GetName();
1270 delete arr;
1271 if (particleName.IsNull()) continue;
1272 if (!grAll && particleName=="ALL" && gainScenarioName==gainScenario) grAll=responseFunction;
1273 else
1274 {
1275 for (Int_t ispec=0; ispec<(AliTPCPIDResponse::fgkNumberOfParticleSpecies); ++ispec)
1276 {
1277 TString particle=AliPID::ParticleName(ispec);
1278 particle.ToUpper();
1279 //std::cout<<responseName<<" "<<particle<<" "<<particleName<<" "<<gainScenario<<" "<<gainScenarioName<<std::endl;
1280 if ( particle == particleName && gainScenario == gainScenarioName )
1281 {
1282 fTPCResponse.SetResponseFunction( responseFunction,
1283 (AliPID::EParticleType)ispec,
1284 (AliTPCPIDResponse::ETPCgainScenario)igainScenario );
1285 fTPCResponse.SetUseDatabase(kTRUE);
5a9dc560 1286 AliInfo(Form("Adding graph: %d %d - %s (MD5(spline) = %s)",ispec,igainScenario,responseFunction->GetName(),
1287 GetChecksum((TSpline3*)responseFunction).Data()));
644666df 1288 found=kTRUE;
644666df 1289 break;
1290 }
4ec8e76d 1291 }
1292 }
1293 }
bf26ce58 1294
1295 // Retrieve responsefunction for pions - will (if available) be used for muons if there are no dedicated muon splines.
1296 // For light nuclei, try to set the proton spline, if no dedicated splines are available.
1297 // In both cases: Use default splines, if no dedicated splines and no pion/proton splines are available.
1298 TObject* responseFunctionPion = fTPCResponse.GetResponseFunction( (AliPID::EParticleType)AliPID::kPion,
1299 (AliTPCPIDResponse::ETPCgainScenario)igainScenario);
1300 TObject* responseFunctionProton = fTPCResponse.GetResponseFunction( (AliPID::EParticleType)AliPID::kProton,
1301 (AliTPCPIDResponse::ETPCgainScenario)igainScenario);
1302
1303 for (Int_t ispec=0; ispec<(AliTPCPIDResponse::fgkNumberOfParticleSpecies); ++ispec)
644666df 1304 {
bf26ce58 1305 if (!fTPCResponse.GetResponseFunction( (AliPID::EParticleType)ispec,
1306 (AliTPCPIDResponse::ETPCgainScenario)igainScenario))
644666df 1307 {
bf26ce58 1308 if (ispec == AliPID::kMuon) { // Muons
1309 if (responseFunctionPion) {
1310 fTPCResponse.SetResponseFunction( responseFunctionPion,
1311 (AliPID::EParticleType)ispec,
1312 (AliTPCPIDResponse::ETPCgainScenario)igainScenario );
1313 fTPCResponse.SetUseDatabase(kTRUE);
5a9dc560 1314 AliInfo(Form("Adding graph: %d %d - %s (MD5(spline) = %s)",ispec,igainScenario,responseFunctionPion->GetName(),
1315 GetChecksum((TSpline3*)responseFunctionPion).Data()));
bf26ce58 1316 found=kTRUE;
1317 }
1318 else if (grAll) {
1319 fTPCResponse.SetResponseFunction( grAll,
1320 (AliPID::EParticleType)ispec,
1321 (AliTPCPIDResponse::ETPCgainScenario)igainScenario );
1322 fTPCResponse.SetUseDatabase(kTRUE);
5a9dc560 1323 AliInfo(Form("Adding graph: %d %d - %s (MD5(spline) = %s)",ispec,igainScenario,grAll->GetName(),
1324 GetChecksum((TSpline3*)grAll).Data()));
bf26ce58 1325 found=kTRUE;
1326 }
1327 //else
1328 // AliError(Form("No splines found for muons (also no pion splines and no default splines) for gain scenario %d!", igainScenario));
1329 }
1330 else if (ispec >= AliPID::kSPECIES) { // Light nuclei
1331 if (responseFunctionProton) {
1332 fTPCResponse.SetResponseFunction( responseFunctionProton,
1333 (AliPID::EParticleType)ispec,
1334 (AliTPCPIDResponse::ETPCgainScenario)igainScenario );
1335 fTPCResponse.SetUseDatabase(kTRUE);
5a9dc560 1336 AliInfo(Form("Adding graph: %d %d - %s (MD5(spline) = %s)",ispec,igainScenario,responseFunctionProton->GetName(),
1337 GetChecksum((TSpline3*)responseFunctionProton).Data()));
bf26ce58 1338 found=kTRUE;
1339 }
1340 else if (grAll) {
644666df 1341 fTPCResponse.SetResponseFunction( grAll,
1342 (AliPID::EParticleType)ispec,
1343 (AliTPCPIDResponse::ETPCgainScenario)igainScenario );
1344 fTPCResponse.SetUseDatabase(kTRUE);
5a9dc560 1345 AliInfo(Form("Adding graph: %d %d - %s (MD5(spline) = %s)",ispec,igainScenario,grAll->GetName(),
1346 GetChecksum((TSpline3*)grAll).Data()));
644666df 1347 found=kTRUE;
bf26ce58 1348 }
1349 //else
1350 // AliError(Form("No splines found for species %d (also no proton splines and no default splines) for gain scenario %d!",
1351 // ispec, igainScenario));
644666df 1352 }
4ec8e76d 1353 }
1354 }
1355 }
1356 }
644666df 1357 else AliInfo("no fArrPidResponseMaster");
4a527e08 1358
1359 if (!found){
f85a3764 1360 AliError(Form("No splines found for: %s %s PASS%d %s",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
4a527e08 1361 }
644666df 1362
87da0205 1363
1364 //
22158469 1365 // Setup multiplicity correction (only used for non-pp collisions)
87da0205 1366 //
22158469
JW
1367
1368 const Bool_t isPP = (fBeamType.CompareTo("PP") == 0);
1369
1370 // 2013 pPb data taking at low luminosity
1371 const Bool_t isPPb2013LowLuminosity = period.Contains("LHC13B") || period.Contains("LHC13C") || period.Contains("LHC13D");
1372 // PbPb 2010, period 10h.pass2
1373 //TODO Needs further development const Bool_t is10hpass2 = period.Contains("LHC10H") && recopass == 2;
1374
eafa51b5
JW
1375
1376 // In case of MC without(!) tune on data activated for the TPC, don't use the multiplicity correction for the moment
1377 Bool_t isMCandNotTPCtuneOnData = fIsMC && !(fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC));
1378
22158469 1379 // If correction is available, but disabled (highly NOT recommended!), print warning
eafa51b5 1380 if (!fUseTPCMultiplicityCorrection && !isPP && !isMCandNotTPCtuneOnData) {
22158469
JW
1381 //TODO: Needs further development if (is10hpass2 || isPPb2013LowLuminosity) {
1382 if (isPPb2013LowLuminosity) {
1383 AliWarning("Mulitplicity correction disabled, but correction parameters for this period exist. It is highly recommended to use enable the correction. Otherwise the splines might be off!");
1384 }
1385 }
1386
eafa51b5 1387 if (fUseTPCMultiplicityCorrection && !isPP && !isMCandNotTPCtuneOnData) {
87da0205 1388 AliInfo("Multiplicity correction enabled!");
1389
1390 //TODO After testing, load parameters from outside
22158469 1391 /*TODO no correction for MC
87da0205 1392 if (period.Contains("LHC11A10")) {//LHC11A10A
1393 AliInfo("Using multiplicity correction parameters for 11a10!");
1394 fTPCResponse.SetParameterMultiplicityCorrection(0, 6.90133e-06);
1395 fTPCResponse.SetParameterMultiplicityCorrection(1, -1.22123e-03);
1396 fTPCResponse.SetParameterMultiplicityCorrection(2, 1.80220e-02);
1397 fTPCResponse.SetParameterMultiplicityCorrection(3, 0.1);
1398 fTPCResponse.SetParameterMultiplicityCorrection(4, 6.45306e-03);
1399
1400 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(0, -2.85505e-07);
1401 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(1, -1.31911e-06);
1402 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(2, -0.5);
1403
1404 fTPCResponse.SetParameterMultiplicitySigmaCorrection(0, -4.29665e-05);
1405 fTPCResponse.SetParameterMultiplicitySigmaCorrection(1, 1.37023e-02);
1406 fTPCResponse.SetParameterMultiplicitySigmaCorrection(2, -6.36337e-01);
1407 fTPCResponse.SetParameterMultiplicitySigmaCorrection(3, 1.13479e-02);
1408 }
22158469
JW
1409 else*/ if (isPPb2013LowLuminosity) {// 2013 pPb data taking at low luminosity
1410 AliInfo("Using multiplicity correction parameters for 13b.pass2 (at least also valid for 13{c,d} and pass 3)!");
ef7661fd 1411
1412 fTPCResponse.SetParameterMultiplicityCorrection(0, -5.906e-06);
1413 fTPCResponse.SetParameterMultiplicityCorrection(1, -5.064e-04);
1414 fTPCResponse.SetParameterMultiplicityCorrection(2, -3.521e-02);
1415 fTPCResponse.SetParameterMultiplicityCorrection(3, 2.469e-02);
1416 fTPCResponse.SetParameterMultiplicityCorrection(4, 0);
1417
1418 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(0, -5.32e-06);
1419 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(1, 1.177e-05);
1420 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(2, -0.5);
1421
1422 fTPCResponse.SetParameterMultiplicitySigmaCorrection(0, 0.);
1423 fTPCResponse.SetParameterMultiplicitySigmaCorrection(1, 0.);
1424 fTPCResponse.SetParameterMultiplicitySigmaCorrection(2, 0.);
1425 fTPCResponse.SetParameterMultiplicitySigmaCorrection(3, 0.);
1426
1427 /* Not too bad, but far from perfect in the details
1428 fTPCResponse.SetParameterMultiplicityCorrection(0, -6.27187e-06);
1429 fTPCResponse.SetParameterMultiplicityCorrection(1, -4.60649e-04);
1430 fTPCResponse.SetParameterMultiplicityCorrection(2, -4.26450e-02);
1431 fTPCResponse.SetParameterMultiplicityCorrection(3, 2.40590e-02);
1432 fTPCResponse.SetParameterMultiplicityCorrection(4, 0);
1433
1434 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(0, -5.338e-06);
1435 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(1, 1.220e-05);
1436 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(2, -0.5);
1437
1438 fTPCResponse.SetParameterMultiplicitySigmaCorrection(0, 7.89237e-05);
1439 fTPCResponse.SetParameterMultiplicitySigmaCorrection(1, -1.30662e-02);
1440 fTPCResponse.SetParameterMultiplicitySigmaCorrection(2, 8.91548e-01);
1441 fTPCResponse.SetParameterMultiplicitySigmaCorrection(3, 1.47931e-02);
1442 */
1443 }
22158469
JW
1444 /*TODO: Needs further development
1445 else if (is10hpass2) {
87da0205 1446 AliInfo("Using multiplicity correction parameters for 10h.pass2!");
1447 fTPCResponse.SetParameterMultiplicityCorrection(0, 3.21636e-07);
1448 fTPCResponse.SetParameterMultiplicityCorrection(1, -6.65876e-04);
1449 fTPCResponse.SetParameterMultiplicityCorrection(2, 1.28786e-03);
1450 fTPCResponse.SetParameterMultiplicityCorrection(3, 1.47677e-02);
1451 fTPCResponse.SetParameterMultiplicityCorrection(4, 0);
1452
1453 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(0, 7.23591e-08);
1454 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(1, 2.7469e-06);
1455 fTPCResponse.SetParameterMultiplicityCorrectionTanTheta(2, -0.5);
1456
1457 fTPCResponse.SetParameterMultiplicitySigmaCorrection(0, -1.22590e-05);
1458 fTPCResponse.SetParameterMultiplicitySigmaCorrection(1, 6.88888e-03);
1459 fTPCResponse.SetParameterMultiplicitySigmaCorrection(2, -3.20788e-01);
1460 fTPCResponse.SetParameterMultiplicitySigmaCorrection(3, 1.07345e-02);
1461 }
22158469 1462 */
87da0205 1463 else {
1464 AliError(Form("Multiplicity correction is enabled, but no multiplicity correction parameters have been found for period %s.pass%d -> Mulitplicity correction DISABLED!", period.Data(), recopass));
1465 fUseTPCMultiplicityCorrection = kFALSE;
1466 fTPCResponse.ResetMultiplicityCorrectionFunctions();
1467 }
1468 }
1469 else {
1470 // Just set parameters such that overall correction factor is 1, i.e. no correction.
1471 // This is just a reasonable choice for the parameters for safety reasons. Disabling
1472 // the multiplicity correction will anyhow skip the calculation of the corresponding
1473 // correction factor inside THIS class. Nevertheless, experts can access the TPCPIDResponse
1474 // directly and use it for calculations - which should still give valid results, even if
1475 // the multiplicity correction is explicitely enabled in such expert calls.
1476
eafa51b5
JW
1477 TString reasonForDisabling = "requested by user";
1478 if (fUseTPCMultiplicityCorrection) {
1479 if (isPP)
1480 reasonForDisabling = "pp collisions";
1481 else
1482 reasonForDisabling = "MC w/o tune on data";
1483 }
1484
87da0205 1485 AliInfo(Form("Multiplicity correction %sdisabled (%s)!", fUseTPCMultiplicityCorrection ? "automatically " : "",
eafa51b5 1486 reasonForDisabling.Data()));
87da0205 1487
1488 fUseTPCMultiplicityCorrection = kFALSE;
1489 fTPCResponse.ResetMultiplicityCorrectionFunctions();
1490 }
1491
22158469
JW
1492 if (fUseTPCMultiplicityCorrection) {
1493 for (Int_t i = 0; i <= 4 + 1; i++) {
1494 AliInfo(Form("parMultCorr: %d, %e", i, fTPCResponse.GetMultiplicityCorrectionFunction()->GetParameter(i)));
1495 }
1496 for (Int_t j = 0; j <= 2 + 1; j++) {
1497 AliInfo(Form("parMultCorrTanTheta: %d, %e", j, fTPCResponse.GetMultiplicityCorrectionFunctionTanTheta()->GetParameter(j)));
1498 }
1499 for (Int_t j = 0; j <= 3 + 1; j++) {
1500 AliInfo(Form("parMultSigmaCorr: %d, %e", j, fTPCResponse.GetMultiplicitySigmaCorrectionFunction()->GetParameter(j)));
1501 }
87da0205 1502 }
1503
4ec8e76d 1504 //
87da0205 1505 // Setup old resolution parametrisation
4ec8e76d 1506 //
1507
1508 //default
1509 fTPCResponse.SetSigma(3.79301e-03, 2.21280e+04);
1510
3b3bf053 1511 if (fRun>=122195){ //LHC10d
4ec8e76d 1512 fTPCResponse.SetSigma(2.30176e-02, 5.60422e+02);
1513 }
3b3bf053 1514
1515 if (fRun>=170719){ // LHC12a
1516 fTPCResponse.SetSigma(2.95714e-03, 1.01953e+05);
1517 }
1518
1519 if (fRun>=177312){ // LHC12b
1520 fTPCResponse.SetSigma(3.74633e-03, 7.11829e+04 );
1521 }
1522
1523 if (fRun>=186346){ // LHC12e
723c4874 1524 fTPCResponse.SetSigma(8.62022e-04, 9.08156e+05);
1525 }
1526
23425eb2 1527 if (fArrPidResponseMaster)
f85a3764 1528 fResolutionCorrection=(TF1*)fArrPidResponseMaster->FindObject(Form("TF1_%s_ALL_%s_PASS%d_%s_SIGMA",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
4ec8e76d 1529
5a9dc560 1530 if (fResolutionCorrection) AliInfo(Form("Setting multiplicity correction function: %s (MD5(corr function) = %s)",
1531 fResolutionCorrection->GetName(), GetChecksum(fResolutionCorrection).Data()));
644666df 1532
1533 //read in the voltage map
12d3abbc 1534 TVectorF* gsm = 0x0;
1535 if (fOADBvoltageMaps) gsm=dynamic_cast<TVectorF*>(fOADBvoltageMaps->GetObject(fRun));
644666df 1536 if (gsm)
1537 {
1538 fTPCResponse.SetVoltageMap(*gsm);
1539 TString vals;
1540 AliInfo(Form("Reading the voltage map for run %d\n",fRun));
1541 vals="IROC A: "; for (Int_t i=0; i<18; i++){vals+=Form("%.2f ",(*gsm)[i]);}
1542 AliInfo(vals.Data());
1543 vals="IROC C: "; for (Int_t i=18; i<36; i++){vals+=Form("%.2f ",(*gsm)[i]);}
1544 AliInfo(vals.Data());
1545 vals="OROC A: "; for (Int_t i=36; i<54; i++){vals+=Form("%.2f ",(*gsm)[i]);}
1546 AliInfo(vals.Data());
1547 vals="OROC C: "; for (Int_t i=54; i<72; i++){vals+=Form("%.2f ",(*gsm)[i]);}
1548 AliInfo(vals.Data());
1549 }
1550 else AliInfo("no voltage map, ideal default assumed");
4ec8e76d 1551}
1552
ea235c90 1553//______________________________________________________________________________
1554void AliPIDResponse::SetTRDPidResponseMaster()
1555{
1556 //
1557 // Load the TRD pid params and references from the OADB
1558 //
db0e2c5f 1559 if(fTRDPIDResponseObject) return;
53d016dc 1560 AliOADBContainer contParams("contParams");
1561
db0e2c5f 1562 Int_t statusResponse = contParams.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDResponse.root", fOADBPath.Data()), "AliTRDPIDResponseObject");
1563 if(statusResponse){
1564 AliError("Failed initializing PID Response Object from OADB");
59a8e853 1565 } else {
db0e2c5f 1566 AliInfo(Form("Loading TRD Response from %s/COMMON/PID/data/TRDPIDResponse.root", fOADBPath.Data()));
1567 fTRDPIDResponseObject = dynamic_cast<AliTRDPIDResponseObject *>(contParams.GetObject(fRun));
1568 if(!fTRDPIDResponseObject){
1569 AliError(Form("TRD Response not found in run %d", fRun));
59a8e853 1570 }
1571 }
ea235c90 1572}
1573
1574//______________________________________________________________________________
1575void AliPIDResponse::InitializeTRDResponse(){
1576 //
1577 // Set PID Params and references to the TRD PID response
1578 //
db0e2c5f 1579 fTRDResponse.SetPIDResponseObject(fTRDPIDResponseObject);
9c499471 1580 fTRDResponse.SetdEdxParams(fTRDdEdxParams);
f2762b1c 1581}
1582
bd58d4b9 1583//______________________________________________________________________________
1584void AliPIDResponse::SetTRDSlices(UInt_t TRDslicesForPID[2],AliTRDPIDResponse::ETRDPIDMethod method) const{
1585
72abc110 1586 if(fLHCperiod.Contains("LHC10D") || fLHCperiod.Contains("LHC10E")){
bd58d4b9 1587 // backward compatibility for setting with 8 slices
1588 TRDslicesForPID[0] = 0;
1589 TRDslicesForPID[1] = 7;
f2762b1c 1590 }
bd58d4b9 1591 else{
1592 if(method==AliTRDPIDResponse::kLQ1D){
1593 TRDslicesForPID[0] = 0; // first Slice contains normalized dEdx
1594 TRDslicesForPID[1] = 0;
1595 }
1596 if(method==AliTRDPIDResponse::kLQ2D){
1597 TRDslicesForPID[0] = 1;
1598 TRDslicesForPID[1] = 7;
1599 }
db0e2c5f 1600 }
bd58d4b9 1601 AliDebug(1,Form("Slice Range set to %d - %d",TRDslicesForPID[0],TRDslicesForPID[1]));
ea235c90 1602}
1603
9c499471 1604//______________________________________________________________________________
1605void AliPIDResponse::SetTRDdEdxParams()
1606{
1607 if(fTRDdEdxParams) return;
1608
1609 const TString containerName = "TRDdEdxParamsContainer";
1610 AliOADBContainer cont(containerName.Data());
1611
1612 const TString filePathNamePackage=Form("%s/COMMON/PID/data/TRDdEdxParams.root", fOADBPath.Data());
1613
1614 const Int_t statusCont = cont.InitFromFile(filePathNamePackage.Data(), cont.GetName());
1615 if (statusCont){
1616 AliFatal("Failed initializing settings from OADB");
1617 }
1618 else{
2ddf4abb 1619 AliInfo(Form("Loading %s from %s\n", cont.GetName(), filePathNamePackage.Data()));
9c499471 1620
1621 fTRDdEdxParams = (AliTRDdEdxParams*)(cont.GetObject(fRun, "default"));
1622 //fTRDdEdxParams->Print();
1623
1624 if(!fTRDdEdxParams){
1625 AliError(Form("TRD dEdx Params default not found"));
1626 }
1627 }
1628}
1629
b79db598 1630//______________________________________________________________________________
1631void AliPIDResponse::SetTOFPidResponseMaster()
1632{
1633 //
1634 // Load the TOF pid params from the OADB
1635 //
00a38d07 1636
1637 if (fTOFPIDParams) delete fTOFPIDParams;
644666df 1638 fTOFPIDParams=NULL;
00a38d07 1639
b79db598 1640 TFile *oadbf = new TFile(Form("%s/COMMON/PID/data/TOFPIDParams.root",fOADBPath.Data()));
00a38d07 1641 if (oadbf && oadbf->IsOpen()) {
b79db598 1642 AliInfo(Form("Loading TOF Params from %s/COMMON/PID/data/TOFPIDParams.root", fOADBPath.Data()));
1643 AliOADBContainer *oadbc = (AliOADBContainer *)oadbf->Get("TOFoadb");
00a38d07 1644 if (oadbc) fTOFPIDParams = dynamic_cast<AliTOFPIDParams *>(oadbc->GetObject(fRun,"TOFparams"));
b79db598 1645 oadbf->Close();
1646 delete oadbc;
b79db598 1647 }
1648 delete oadbf;
1649
00a38d07 1650 if (!fTOFPIDParams) AliFatal("TOFPIDParams could not be retrieved");
1651}
b79db598 1652
1653//______________________________________________________________________________
1654void AliPIDResponse::InitializeTOFResponse(){
1655 //
1656 // Set PID Params to the TOF PID response
00a38d07 1657 //
1658
1659 AliInfo("TOF PID Params loaded from OADB");
1660 AliInfo(Form(" TOF resolution %5.2f [ps]",fTOFPIDParams->GetTOFresolution()));
1661 AliInfo(Form(" StartTime method %d",fTOFPIDParams->GetStartTimeMethod()));
1662 AliInfo(Form(" TOF res. mom. params: %5.2f %5.2f %5.2f %5.2f",
1663 fTOFPIDParams->GetSigParams(0),fTOFPIDParams->GetSigParams(1),fTOFPIDParams->GetSigParams(2),fTOFPIDParams->GetSigParams(3)));
c53e310b 1664 AliInfo(Form(" Fraction of tracks within gaussian behaviour: %6.4f",fTOFPIDParams->GetTOFtail()));
1665 AliInfo(Form(" MC: Fraction of tracks (percentage) to cut to fit matching in data: %6.2f%%",fTOFPIDParams->GetTOFmatchingLossMC()));
1666 AliInfo(Form(" MC: Fraction of random hits (percentage) to add to fit mismatch in data: %6.2f%%",fTOFPIDParams->GetTOFadditionalMismForMC()));
1667 AliInfo(Form(" Start Time Offset %6.2f ps",fTOFPIDParams->GetTOFtimeOffset()));
1668
b79db598 1669 for (Int_t i=0;i<4;i++) {
1670 fTOFResponse.SetTrackParameter(i,fTOFPIDParams->GetSigParams(i));
1671 }
1672 fTOFResponse.SetTimeResolution(fTOFPIDParams->GetTOFresolution());
1673
78cbd205 1674 AliInfo("TZERO resolution loaded from ESDrun/AODheader");
1675 Float_t t0Spread[4];
1676 for (Int_t i=0;i<4;i++) t0Spread[i]=fCurrentEvent->GetT0spread(i);
1677 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]));
1678 Float_t a = t0Spread[1]*t0Spread[1]-t0Spread[0]*t0Spread[0]+t0Spread[3]*t0Spread[3];
1679 Float_t c = t0Spread[2]*t0Spread[2]-t0Spread[0]*t0Spread[0]+t0Spread[3]*t0Spread[3];
1680 if ( (t0Spread[0] > 50. && t0Spread[0] < 400.) && (a > 0.) && (c>0.)) {
1681 fResT0AC=t0Spread[3];
1682 fResT0A=TMath::Sqrt(a);
1683 fResT0C=TMath::Sqrt(c);
1684 } else {
1685 AliInfo(" TZERO spreads not present or inconsistent, loading default");
1686 fResT0A=75.;
1687 fResT0C=65.;
1688 fResT0AC=55.;
1689 }
1690 AliInfo(Form(" TZERO resolution set to: T0A: %f [ps] T0C: %f [ps] T0AC %f [ps]",fResT0A,fResT0C,fResT0AC));
1691
b79db598 1692}
1693
567624b5 1694//______________________________________________________________________________
1695void AliPIDResponse::SetHMPIDPidResponseMaster()
1696{
1697 //
1698 // Load the HMPID pid params from the OADB
1699 //
1700
1701 if (fHMPIDPIDParams) delete fHMPIDPIDParams;
1702 fHMPIDPIDParams=NULL;
1703
b2f22270 1704 TFile *oadbf;
1705 if(!fIsMC) oadbf = new TFile(Form("%s/COMMON/PID/data/HMPIDPIDParams.root",fOADBPath.Data()));
1706 else oadbf = new TFile(Form("%s/COMMON/PID/MC/HMPIDPIDParams.root",fOADBPath.Data()));
567624b5 1707 if (oadbf && oadbf->IsOpen()) {
1708 AliInfo(Form("Loading HMPID Params from %s/COMMON/PID/data/HMPIDPIDParams.root", fOADBPath.Data()));
1709 AliOADBContainer *oadbc = (AliOADBContainer *)oadbf->Get("HMPoadb");
1710 if (oadbc) fHMPIDPIDParams = dynamic_cast<AliHMPIDPIDParams *>(oadbc->GetObject(fRun,"HMPparams"));
1711 oadbf->Close();
1712 delete oadbc;
1713 }
1714 delete oadbf;
1715
1716 if (!fHMPIDPIDParams) AliFatal("HMPIDPIDParams could not be retrieved");
1717}
1718
1719//______________________________________________________________________________
1720void AliPIDResponse::InitializeHMPIDResponse(){
1721 //
1722 // Set PID Params to the HMPID PID response
1723 //
1724
1725 fHMPIDResponse.SetRefIndexArray(fHMPIDPIDParams->GetHMPIDrefIndex());
1726}
b79db598 1727
1c9d11be 1728//______________________________________________________________________________
239fe91c 1729Bool_t AliPIDResponse::IdentifiedAsElectronTRD(const AliVTrack *vtrack,Double_t efficiencyLevel,Double_t centrality,AliTRDPIDResponse::ETRDPIDMethod PIDmethod) const {
1730 // old function for compatibility
1731 Int_t ntracklets=0;
1732 return IdentifiedAsElectronTRD(vtrack,ntracklets,efficiencyLevel,centrality,PIDmethod);
1733}
1734
1735//______________________________________________________________________________
1736Bool_t AliPIDResponse::IdentifiedAsElectronTRD(const AliVTrack *vtrack, Int_t &ntracklets,Double_t efficiencyLevel,Double_t centrality,AliTRDPIDResponse::ETRDPIDMethod PIDmethod) const {
ea235c90 1737 //
1738 // Check whether track is identified as electron under a given electron efficiency hypothesis
bd58d4b9 1739 //
239fe91c 1740 // ntracklets is the number of tracklets that has been used to calculate the PID signal
bd58d4b9 1741
ea235c90 1742 Double_t probs[AliPID::kSPECIES];
ea235c90 1743
239fe91c 1744 ntracklets =CalculateTRDResponse(vtrack,probs,PIDmethod);
1745
99e9d5ec 1746 // Take mean of the TRD momenta in the given tracklets
1747 Float_t p = 0, trdmomenta[AliVTrack::kTRDnPlanes];
1748 Int_t nmomenta = 0;
ea235c90 1749 for(Int_t iPl=0;iPl<AliVTrack::kTRDnPlanes;iPl++){
1750 if(vtrack->GetTRDmomentum(iPl) > 0.){
99e9d5ec 1751 trdmomenta[nmomenta++] = vtrack->GetTRDmomentum(iPl);
ea235c90 1752 }
1753 }
99e9d5ec 1754 p = TMath::Mean(nmomenta, trdmomenta);
ea235c90 1755
bd58d4b9 1756 return fTRDResponse.IdentifiedAsElectron(ntracklets, probs, p, efficiencyLevel,centrality,PIDmethod);
ea235c90 1757}
1758
b2138b40 1759//______________________________________________________________________________
1760void AliPIDResponse::SetEMCALPidResponseMaster()
1761{
1762 //
1763 // Load the EMCAL pid response functions from the OADB
1764 //
1765 TObjArray* fEMCALPIDParamsRun = NULL;
1766 TObjArray* fEMCALPIDParamsPass = NULL;
1767
1768 if(fEMCALPIDParams) return;
1769 AliOADBContainer contParams("contParams");
1770
1771 Int_t statusPars = contParams.InitFromFile(Form("%s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()), "AliEMCALPIDParams");
1772 if(statusPars){
1773 AliError("Failed initializing PID Params from OADB");
1774 }
1775 else {
1776 AliInfo(Form("Loading EMCAL Params from %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
1777
1778 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(fRun));
1779 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",fRecoPass)));
1780 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
1781
1782 if(!fEMCALPIDParams){
f8d39067 1783 AliInfo(Form("EMCAL Params not found in run %d pass %d", fRun, fRecoPass));
1f631618 1784 AliInfo("Will take the standard LHC11d instead ...");
b2138b40 1785
1f631618 1786 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(156477));
1787 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",1)));
b2138b40 1788 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
1789
1790 if(!fEMCALPIDParams){
1f631618 1791 AliError(Form("DEFAULT EMCAL Params (LHC11d) not found in file %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
b2138b40 1792 }
1793 }
1794 }
1795}
1796
1797//______________________________________________________________________________
1798void AliPIDResponse::InitializeEMCALResponse(){
1799 //
1800 // Set PID Params to the EMCAL PID response
1801 //
1802 fEMCALResponse.SetPIDParams(fEMCALPIDParams);
1803
1804}
00a38d07 1805
1c9d11be 1806//______________________________________________________________________________
1807void AliPIDResponse::FillTrackDetectorPID(const AliVTrack *track, EDetector detector) const
00a38d07 1808{
1809 //
1810 // create detector PID information and setup the transient pointer in the track
1811 //
1c9d11be 1812
1813 // check if detector number is inside accepted range
1814 if (detector == kNdetectors) return;
1815
1816 // get detector pid
1817 AliDetectorPID *detPID=const_cast<AliDetectorPID*>(track->GetDetectorPID());
1818 if (!detPID) {
1819 detPID=new AliDetectorPID;
1820 (const_cast<AliVTrack*>(track))->SetDetectorPID(detPID);
1821 }
1822
1823 //check if values exist
355b831b 1824 if (detPID->HasRawProbability(detector) && detPID->HasNumberOfSigmas(detector)) return;
00a38d07 1825
1826 //TODO: which particles to include? See also the loops below...
1827 Double_t values[AliPID::kSPECIESC]={0};
1c9d11be 1828
355b831b 1829 //probabilities
1830 EDetPidStatus status=GetComputePIDProbability(detector,track,AliPID::kSPECIESC,values);
1831 detPID->SetRawProbability(detector, values, (Int_t)AliPID::kSPECIESC, status);
1832
1c9d11be 1833 //nsigmas
1834 for (Int_t ipart=0; ipart<AliPID::kSPECIESC; ++ipart)
1835 values[ipart]=GetNumberOfSigmas(detector,track,(AliPID::EParticleType)ipart);
355b831b 1836 // the pid status is the same for probabilities and nSigmas, so it is
1837 // fine to use the one from the probabilities also here
1838 detPID->SetNumberOfSigmas(detector, values, (Int_t)AliPID::kSPECIESC, status);
1c9d11be 1839
1c9d11be 1840}
1841
1842//______________________________________________________________________________
1843void AliPIDResponse::FillTrackDetectorPID()
1844{
1845 //
1846 // create detector PID information and setup the transient pointer in the track
1847 //
1848
1849 if (!fCurrentEvent) return;
00a38d07 1850
1851 for (Int_t itrack=0; itrack<fCurrentEvent->GetNumberOfTracks(); ++itrack){
1852 AliVTrack *track=dynamic_cast<AliVTrack*>(fCurrentEvent->GetTrack(itrack));
1853 if (!track) continue;
1854
00a38d07 1855 for (Int_t idet=0; idet<kNdetectors; ++idet){
1c9d11be 1856 FillTrackDetectorPID(track, (EDetector)idet);
00a38d07 1857 }
00a38d07 1858 }
1859}
1860
1c9d11be 1861//______________________________________________________________________________
5f8db5fe 1862void AliPIDResponse::SetTOFResponse(AliVEvent *vevent,EStartTimeType_t option){
1863 //
1864 // Set TOF response function
1865 // Input option for event_time used
1866 //
c53e310b 1867
5f8db5fe 1868 Float_t t0spread = 0.; //vevent->GetEventTimeSpread();
1869 if(t0spread < 10) t0spread = 80;
1870
c53e310b 1871 // T0-FILL and T0-TO offset (because of TOF misallignment
1872 Float_t starttimeoffset = 0;
1873 if(fTOFPIDParams && !(fIsMC)) starttimeoffset=fTOFPIDParams->GetTOFtimeOffset();
b3f687a1 1874 if(fTOFPIDParams){
1875 fTOFtail = fTOFPIDParams->GetTOFtail();
1876 GetTOFResponse().SetTOFtail(fTOFtail);
1877 }
5f8db5fe 1878
c53e310b 1879 // T0 from TOF algorithm
5f8db5fe 1880 Bool_t flagT0TOF=kFALSE;
1881 Bool_t flagT0T0=kFALSE;
1882 Float_t *startTime = new Float_t[fTOFResponse.GetNmomBins()];
1883 Float_t *startTimeRes = new Float_t[fTOFResponse.GetNmomBins()];
1884 Int_t *startTimeMask = new Int_t[fTOFResponse.GetNmomBins()];
1885
1886 // T0-TOF arrays
1887 Float_t *estimatedT0event = new Float_t[fTOFResponse.GetNmomBins()];
1888 Float_t *estimatedT0resolution = new Float_t[fTOFResponse.GetNmomBins()];
1889 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1890 estimatedT0event[i]=0.0;
1891 estimatedT0resolution[i]=0.0;
1892 startTimeMask[i] = 0;
1893 }
1894
78cbd205 1895 Float_t resT0A=fResT0A;
1896 Float_t resT0C=fResT0C;
1897 Float_t resT0AC=fResT0AC;
5f8db5fe 1898 if(vevent->GetT0TOF()){ // check if T0 detector information is available
1899 flagT0T0=kTRUE;
1900 }
1901
1902
1903 AliTOFHeader *tofHeader = (AliTOFHeader*)vevent->GetTOFHeader();
1904
1905 if (tofHeader) { // read global info and T0-TOF
1906 fTOFResponse.SetTimeResolution(tofHeader->GetTOFResolution());
1907 t0spread = tofHeader->GetT0spread(); // read t0 sprad
1908 if(t0spread < 10) t0spread = 80;
1909
1910 flagT0TOF=kTRUE;
1911 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){ // read T0-TOF default value
1912 startTime[i]=tofHeader->GetDefaultEventTimeVal();
1913 startTimeRes[i]=tofHeader->GetDefaultEventTimeRes();
1914 if(startTimeRes[i] < 1.e-5) startTimeRes[i] = t0spread;
c53e310b 1915
1916 if(startTimeRes[i] > t0spread - 10 && TMath::Abs(startTime[i]) < 0.001) startTime[i] = -starttimeoffset; // apply offset for T0-fill
5f8db5fe 1917 }
1918
1919 TArrayI *ibin=(TArrayI*)tofHeader->GetNvalues();
1920 TArrayF *t0Bin=(TArrayF*)tofHeader->GetEventTimeValues();
1921 TArrayF *t0ResBin=(TArrayF*)tofHeader->GetEventTimeRes();
1922 for(Int_t j=0;j < tofHeader->GetNbins();j++){ // fill T0-TOF in p-bins
1923 Int_t icurrent = (Int_t)ibin->GetAt(j);
1924 startTime[icurrent]=t0Bin->GetAt(j);
1925 startTimeRes[icurrent]=t0ResBin->GetAt(j);
1926 if(startTimeRes[icurrent] < 1.e-5) startTimeRes[icurrent] = t0spread;
c53e310b 1927 if(startTimeRes[icurrent] > t0spread - 10 && TMath::Abs(startTime[icurrent]) < 0.001) startTime[icurrent] = -starttimeoffset; // apply offset for T0-fill
5f8db5fe 1928 }
1929 }
1930
1931 // for cut of 3 sigma on t0 spread
1932 Float_t t0cut = 3 * t0spread;
1933 if(t0cut < 500) t0cut = 500;
1934
1935 if(option == kFILL_T0){ // T0-FILL is used
1936 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
c53e310b 1937 estimatedT0event[i]=0.0-starttimeoffset;
5f8db5fe 1938 estimatedT0resolution[i]=t0spread;
1939 }
1940 fTOFResponse.SetT0event(estimatedT0event);
1941 fTOFResponse.SetT0resolution(estimatedT0resolution);
1942 }
1943
1944 if(option == kTOF_T0){ // T0-TOF is used when available (T0-FILL otherwise) from ESD
1945 if(flagT0TOF){
1946 fTOFResponse.SetT0event(startTime);
1947 fTOFResponse.SetT0resolution(startTimeRes);
1948 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1949 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1950 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1951 }
1952 }
1953 else{
1954 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
c53e310b 1955 estimatedT0event[i]=0.0-starttimeoffset;
5f8db5fe 1956 estimatedT0resolution[i]=t0spread;
1957 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1958 }
1959 fTOFResponse.SetT0event(estimatedT0event);
1960 fTOFResponse.SetT0resolution(estimatedT0resolution);
1961 }
1962 }
1963 else if(option == kBest_T0){ // T0-T0 or T0-TOF are used when available (T0-FILL otherwise) from ESD
1964 Float_t t0AC=-10000;
1965 Float_t t0A=-10000;
1966 Float_t t0C=-10000;
1967 if(flagT0T0){
c53e310b 1968 t0A= vevent->GetT0TOF()[1] - starttimeoffset;
1969 t0C= vevent->GetT0TOF()[2] - starttimeoffset;
f84b18dd 1970 // t0AC= vevent->GetT0TOF()[0];
c53e310b 1971 t0AC= t0A/resT0A/resT0A + t0C/resT0C/resT0C;
1972 resT0AC= TMath::Sqrt(1./resT0A/resT0A + 1./resT0C/resT0C);
1973 t0AC /= resT0AC*resT0AC;
5f8db5fe 1974 }
1975
1976 Float_t t0t0Best = 0;
1977 Float_t t0t0BestRes = 9999;
1978 Int_t t0used=0;
1979 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1980 t0t0Best = t0AC;
1981 t0t0BestRes = resT0AC;
1982 t0used=6;
1983 }
1984 else if(TMath::Abs(t0C) < t0cut){
1985 t0t0Best = t0C;
1986 t0t0BestRes = resT0C;
1987 t0used=4;
1988 }
1989 else if(TMath::Abs(t0A) < t0cut){
1990 t0t0Best = t0A;
1991 t0t0BestRes = resT0A;
1992 t0used=2;
1993 }
1994
1995 if(flagT0TOF){ // if T0-TOF info is available
1996 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1997 if(t0t0BestRes < 999){
1998 if(startTimeRes[i] < t0spread){
1999 Double_t wtot = 1./startTimeRes[i]/startTimeRes[i] + 1./t0t0BestRes/t0t0BestRes;
2000 Double_t t0best = startTime[i]/startTimeRes[i]/startTimeRes[i] + t0t0Best/t0t0BestRes/t0t0BestRes;
2001 estimatedT0event[i]=t0best / wtot;
2002 estimatedT0resolution[i]=1./TMath::Sqrt(wtot);
2003 startTimeMask[i] = t0used+1;
2004 }
2005 else {
2006 estimatedT0event[i]=t0t0Best;
2007 estimatedT0resolution[i]=t0t0BestRes;
2008 startTimeMask[i] = t0used;
2009 }
2010 }
2011 else{
2012 estimatedT0event[i]=startTime[i];
2013 estimatedT0resolution[i]=startTimeRes[i];
2014 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
2015 }
2016 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
2017 }
2018 fTOFResponse.SetT0event(estimatedT0event);
2019 fTOFResponse.SetT0resolution(estimatedT0resolution);
2020 }
2021 else{ // if no T0-TOF info is available
2022 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
2023 fTOFResponse.SetT0binMask(i,t0used);
2024 if(t0t0BestRes < 999){
2025 estimatedT0event[i]=t0t0Best;
2026 estimatedT0resolution[i]=t0t0BestRes;
2027 }
2028 else{
c53e310b 2029 estimatedT0event[i]=0.0-starttimeoffset;
5f8db5fe 2030 estimatedT0resolution[i]=t0spread;
2031 }
2032 }
2033 fTOFResponse.SetT0event(estimatedT0event);
2034 fTOFResponse.SetT0resolution(estimatedT0resolution);
2035 }
2036 }
2037
2038 else if(option == kT0_T0){ // T0-T0 is used when available (T0-FILL otherwise)
2039 Float_t t0AC=-10000;
2040 Float_t t0A=-10000;
2041 Float_t t0C=-10000;
2042 if(flagT0T0){
c53e310b 2043 t0A= vevent->GetT0TOF()[1] - starttimeoffset;
2044 t0C= vevent->GetT0TOF()[2] - starttimeoffset;
f84b18dd 2045 // t0AC= vevent->GetT0TOF()[0];
c53e310b 2046 t0AC= t0A/resT0A/resT0A + t0C/resT0C/resT0C;
2047 resT0AC= TMath::Sqrt(1./resT0A/resT0A + 1./resT0C/resT0C);
2048 t0AC /= resT0AC*resT0AC;
5f8db5fe 2049 }
2050
2051 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
2052 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
2053 estimatedT0event[i]=t0AC;
2054 estimatedT0resolution[i]=resT0AC;
2055 fTOFResponse.SetT0binMask(i,6);
2056 }
2057 }
2058 else if(TMath::Abs(t0C) < t0cut){
2059 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
2060 estimatedT0event[i]=t0C;
2061 estimatedT0resolution[i]=resT0C;
2062 fTOFResponse.SetT0binMask(i,4);
2063 }
2064 }
2065 else if(TMath::Abs(t0A) < t0cut){
2066 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
2067 estimatedT0event[i]=t0A;
2068 estimatedT0resolution[i]=resT0A;
2069 fTOFResponse.SetT0binMask(i,2);
2070 }
2071 }
2072 else{
2073 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
c53e310b 2074 estimatedT0event[i]= 0.0 - starttimeoffset;
5f8db5fe 2075 estimatedT0resolution[i]=t0spread;
2076 fTOFResponse.SetT0binMask(i,0);
2077 }
2078 }
2079 fTOFResponse.SetT0event(estimatedT0event);
2080 fTOFResponse.SetT0resolution(estimatedT0resolution);
2081 }
c53e310b 2082
5f8db5fe 2083 delete [] startTime;
2084 delete [] startTimeRes;
2085 delete [] startTimeMask;
2086 delete [] estimatedT0event;
2087 delete [] estimatedT0resolution;
2088}
1c9d11be 2089
2090//______________________________________________________________________________
2091// private non cached versions of the PID calculation
2092//
2093
2094
2095//______________________________________________________________________________
355b831b 2096Float_t AliPIDResponse::GetNumberOfSigmas(EDetector detector, const AliVParticle *vtrack, AliPID::EParticleType type) const
1c9d11be 2097{
2098 //
2099 // NumberOfSigmas for 'detCode'
2100 //
355b831b 2101
2102 const AliVTrack *track=static_cast<const AliVTrack*>(vtrack);
1c9d11be 2103
355b831b 2104 switch (detector){
567624b5 2105 case kITS: return GetNumberOfSigmasITS(track, type); break;
2106 case kTPC: return GetNumberOfSigmasTPC(track, type); break;
5cd0300d 2107 case kTRD: return GetNumberOfSigmasTRD(track, type); break;
567624b5 2108 case kTOF: return GetNumberOfSigmasTOF(track, type); break;
2109 case kHMPID: return GetNumberOfSigmasHMPID(track, type); break;
1c9d11be 2110 case kEMCAL: return GetNumberOfSigmasEMCAL(track, type); break;
2111 default: return -999.;
2112 }
1c9d11be 2113
355b831b 2114 return -999.;
2115}
1c9d11be 2116
2117//______________________________________________________________________________
2118Float_t AliPIDResponse::GetNumberOfSigmasITS(const AliVParticle *vtrack, AliPID::EParticleType type) const
2119{
2120 //
2121 // Calculate the number of sigmas in the ITS
2122 //
2123
2124 AliVTrack *track=(AliVTrack*)vtrack;
355b831b 2125
2126 const EDetPidStatus pidStatus=GetITSPIDStatus(track);
2127 if (pidStatus!=kDetPidOk) return -999.;
355b831b 2128
567624b5 2129 return fITSResponse.GetNumberOfSigmas(track,type);
1c9d11be 2130}
2131
2132//______________________________________________________________________________
2133Float_t AliPIDResponse::GetNumberOfSigmasTPC(const AliVParticle *vtrack, AliPID::EParticleType type) const
2134{
2135 //
2136 // Calculate the number of sigmas in the TPC
2137 //
2138
2139 AliVTrack *track=(AliVTrack*)vtrack;
355b831b 2140
2141 const EDetPidStatus pidStatus=GetTPCPIDStatus(track);
a017c06a 2142 if (pidStatus==kDetNoSignal) return -999.;
1d59271b 2143
2144 // the following call is needed in order to fill the transient data member
2145 // fTPCsignalTuned which is used in the TPCPIDResponse to judge
2146 // if using tuned on data
87da0205 2147 if (fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC))
2148 this->GetTPCsignalTunedOnData(track);
1c9d11be 2149
87da0205 2150 return fTPCResponse.GetNumberOfSigmas(track, type, AliTPCPIDResponse::kdEdxDefault, fUseTPCEtaCorrection, fUseTPCMultiplicityCorrection);
1c9d11be 2151}
2152
5cd0300d 2153//______________________________________________________________________________
2154Float_t AliPIDResponse::GetNumberOfSigmasTRD(const AliVParticle *vtrack, AliPID::EParticleType type) const
2155{
2156 //
2157 // Calculate the number of sigmas in the TRD
2158 //
2159
2160 AliVTrack *track=(AliVTrack*)vtrack;
2161
2162 const EDetPidStatus pidStatus=GetTRDPIDStatus(track);
2163 if (pidStatus!=kDetPidOk) return -999.;
2164
2165 return fTRDResponse.GetNumberOfSigmas(track,type);
2166}
2167
1c9d11be 2168//______________________________________________________________________________
355b831b 2169Float_t AliPIDResponse::GetNumberOfSigmasTOF(const AliVParticle *vtrack, AliPID::EParticleType type) const
1c9d11be 2170{
2171 //
355b831b 2172 // Calculate the number of sigmas in the TOF
1c9d11be 2173 //
2174
2175 AliVTrack *track=(AliVTrack*)vtrack;
355b831b 2176
2177 const EDetPidStatus pidStatus=GetTOFPIDStatus(track);
2178 if (pidStatus!=kDetPidOk) return -999.;
1c9d11be 2179
355b831b 2180 return GetNumberOfSigmasTOFold(vtrack, type);
2181}
567624b5 2182//______________________________________________________________________________
2183
2184Float_t AliPIDResponse::GetNumberOfSigmasHMPID(const AliVParticle *vtrack, AliPID::EParticleType type) const
2185{
2186 //
2187 // Calculate the number of sigmas in the HMPID
2188 //
2189 AliVTrack *track=(AliVTrack*)vtrack;
2190
2191 const EDetPidStatus pidStatus=GetHMPIDPIDStatus(track);
2192 if (pidStatus!=kDetPidOk) return -999.;
2193
2194 return fHMPIDResponse.GetNumberOfSigmas(track, type);
2195}
355b831b 2196
2197//______________________________________________________________________________
2198Float_t AliPIDResponse::GetNumberOfSigmasEMCAL(const AliVParticle *vtrack, AliPID::EParticleType type) const
2199{
2200 //
2201 // Calculate the number of sigmas in the EMCAL
2202 //
1c9d11be 2203
355b831b 2204 AliVTrack *track=(AliVTrack*)vtrack;
2205
2206 const EDetPidStatus pidStatus=GetEMCALPIDStatus(track);
2207 if (pidStatus!=kDetPidOk) return -999.;
2208
2209 const Int_t nMatchClus = track->GetEMCALcluster();
2210 AliVCluster *matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
1c9d11be 2211
355b831b 2212 const Double_t mom = track->P();
2213 const Double_t pt = track->Pt();
2214 const Int_t charge = track->Charge();
2215 const Double_t fClsE = matchedClus->E();
2216 const Double_t EovP = fClsE/mom;
1c9d11be 2217
355b831b 2218 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
1c9d11be 2219}
2220
567624b5 2221//______________________________________________________________________________
1d59271b 2222AliPIDResponse::EDetPidStatus AliPIDResponse::GetSignalDeltaITS(const AliVParticle *vtrack, AliPID::EParticleType type, Double_t &val, Bool_t ratio/*=kFALSE*/) const
567624b5 2223{
2224 //
2225 // Signal minus expected Signal for ITS
2226 //
2227 AliVTrack *track=(AliVTrack*)vtrack;
1d59271b 2228 val=fITSResponse.GetSignalDelta(track,type,ratio);
567624b5 2229
2230 return GetITSPIDStatus(track);
2231}
2232
2233//______________________________________________________________________________
1d59271b 2234AliPIDResponse::EDetPidStatus AliPIDResponse::GetSignalDeltaTPC(const AliVParticle *vtrack, AliPID::EParticleType type, Double_t &val, Bool_t ratio/*=kFALSE*/) const
567624b5 2235{
2236 //
2237 // Signal minus expected Signal for TPC
2238 //
2239 AliVTrack *track=(AliVTrack*)vtrack;
1d59271b 2240
2241 // the following call is needed in order to fill the transient data member
2242 // fTPCsignalTuned which is used in the TPCPIDResponse to judge
2243 // if using tuned on data
87da0205 2244 if (fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC))
1d59271b 2245 this->GetTPCsignalTunedOnData(track);
2246
87da0205 2247 val=fTPCResponse.GetSignalDelta(track, type, AliTPCPIDResponse::kdEdxDefault, fUseTPCEtaCorrection, fUseTPCMultiplicityCorrection, ratio);
567624b5 2248
2249 return GetTPCPIDStatus(track);
2250}
2251
5cd0300d 2252//______________________________________________________________________________
2253AliPIDResponse::EDetPidStatus AliPIDResponse::GetSignalDeltaTRD(const AliVParticle *vtrack, AliPID::EParticleType type, Double_t &val, Bool_t ratio/*=kFALSE*/) const
2254{
2255 //
2256 // Signal minus expected Signal for TRD
2257 //
2258 AliVTrack *track=(AliVTrack*)vtrack;
2259 val=fTRDResponse.GetSignalDelta(track,type,ratio);
2260
2261 return GetTRDPIDStatus(track);
2262}
2263
567624b5 2264//______________________________________________________________________________
1d59271b 2265AliPIDResponse::EDetPidStatus AliPIDResponse::GetSignalDeltaTOF(const AliVParticle *vtrack, AliPID::EParticleType type, Double_t &val, Bool_t ratio/*=kFALSE*/) const
567624b5 2266{
2267 //
2268 // Signal minus expected Signal for TOF
2269 //
2270 AliVTrack *track=(AliVTrack*)vtrack;
1d59271b 2271 val=GetSignalDeltaTOFold(track, type, ratio);
87da0205 2272
567624b5 2273 return GetTOFPIDStatus(track);
2274}
2275
2276//______________________________________________________________________________
1d59271b 2277AliPIDResponse::EDetPidStatus AliPIDResponse::GetSignalDeltaHMPID(const AliVParticle *vtrack, AliPID::EParticleType type, Double_t &val, Bool_t ratio/*=kFALSE*/) const
567624b5 2278{
2279 //
2280 // Signal minus expected Signal for HMPID
2281 //
2282 AliVTrack *track=(AliVTrack*)vtrack;
1d59271b 2283 val=fHMPIDResponse.GetSignalDelta(track, type, ratio);
567624b5 2284
2285 return GetHMPIDPIDStatus(track);
2286}
1c9d11be 2287
2288//______________________________________________________________________________
2289AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputePIDProbability (EDetector detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
2290{
2291 //
2292 // Compute PID response of 'detCode'
2293 //
2294
2295 switch (detCode){
2296 case kITS: return GetComputeITSProbability(track, nSpecies, p); break;
2297 case kTPC: return GetComputeTPCProbability(track, nSpecies, p); break;
2298 case kTRD: return GetComputeTRDProbability(track, nSpecies, p); break;
2299 case kTOF: return GetComputeTOFProbability(track, nSpecies, p); break;
2300 case kPHOS: return GetComputePHOSProbability(track, nSpecies, p); break;
2301 case kEMCAL: return GetComputeEMCALProbability(track, nSpecies, p); break;
2302 case kHMPID: return GetComputeHMPIDProbability(track, nSpecies, p); break;
2303 default: return kDetNoSignal;
2304 }
2305}
2306
2307//______________________________________________________________________________
2308AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeITSProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
2309{
2310 //
2311 // Compute PID response for the ITS
2312 //
2313
1c9d11be 2314 // set flat distribution (no decision)
2315 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
2316
355b831b 2317 const EDetPidStatus pidStatus=GetITSPIDStatus(track);
2318 if (pidStatus!=kDetPidOk) return pidStatus;
2319
2320 if (track->GetDetectorPID()){
2321 return track->GetDetectorPID()->GetRawProbability(kITS, p, nSpecies);
2322 }
1c9d11be 2323
2324 //check for ITS standalone tracks
2325 Bool_t isSA=kTRUE;
2326 if( track->GetStatus() & AliVTrack::kTPCin ) isSA=kFALSE;
2327
2328 Double_t mom=track->P();
2329 Double_t dedx=track->GetITSsignal();
2330 Double_t momITS=mom;
2331 UChar_t clumap=track->GetITSClusterMap();
2332 Int_t nPointsForPid=0;
2333 for(Int_t i=2; i<6; i++){
2334 if(clumap&(1<<i)) ++nPointsForPid;
2335 }
2336
1c9d11be 2337 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
bf26ce58 2338 for (Int_t j=0; j<nSpecies; j++) {
1c9d11be 2339 Double_t mass=AliPID::ParticleMassZ(j);//GeV/c^2
2340 const Double_t chargeFactor = TMath::Power(AliPID::ParticleCharge(j),2.);
2341 Double_t bethe=fITSResponse.Bethe(momITS,mass)*chargeFactor;
2342 //TODO: in case of the electron, use the SA parametrisation,
2343 // this needs to be changed if ITS provides a parametrisation
2344 // for electrons also for ITS+TPC tracks
2345 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA || (j==(Int_t)AliPID::kElectron));
2346 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
2347 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
2348 } else {
2349 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
2350 mismatch=kFALSE;
2351 }
1c9d11be 2352 }
2353
2354 if (mismatch){
bf26ce58 2355 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1c9d11be 2356 }
2357
1c9d11be 2358 return kDetPidOk;
2359}
2360//______________________________________________________________________________
2361AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeTPCProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
2362{
2363 //
2364 // Compute PID response for the TPC
2365 //
2366
2367 // set flat distribution (no decision)
2368 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
2369
355b831b 2370 const EDetPidStatus pidStatus=GetTPCPIDStatus(track);
a017c06a 2371 if (pidStatus==kDetNoSignal) return pidStatus;
1c9d11be 2372
1c9d11be 2373 Double_t dedx=track->GetTPCsignal();
2374 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
2375
87da0205 2376 if (fTuneMConData && ((fTuneMConDataMask & kDetTPC) == kDetTPC)) dedx = this->GetTPCsignalTunedOnData(track);
1c9d11be 2377
f84b18dd 2378 Double_t bethe = 0.;
2379 Double_t sigma = 0.;
2380
bf26ce58 2381 for (Int_t j=0; j<nSpecies; j++) {
1c9d11be 2382 AliPID::EParticleType type=AliPID::EParticleType(j);
f84b18dd 2383
87da0205 2384 bethe=fTPCResponse.GetExpectedSignal(track, type, AliTPCPIDResponse::kdEdxDefault, fUseTPCEtaCorrection, fUseTPCMultiplicityCorrection);
2385 sigma=fTPCResponse.GetExpectedSigma(track, type, AliTPCPIDResponse::kdEdxDefault, fUseTPCEtaCorrection, fUseTPCMultiplicityCorrection);
f85a3764 2386
1c9d11be 2387 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
2388 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
2389 } else {
2390 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
2391 mismatch=kFALSE;
2392 }
2393 }
2394
2395 if (mismatch){
2396 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
1c9d11be 2397 }
2398
a017c06a 2399 return pidStatus;
1c9d11be 2400}
2401//______________________________________________________________________________
2402AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeTOFProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
2403{
2404 //
57e985ed 2405 // Compute PID probabilities for TOF
1c9d11be 2406 //
4fc0f532 2407
42fcc729 2408 fgTOFmismatchProb = 1E-8;
2409
2410 // centrality --> fCurrCentrality
2411 // Beam type --> fBeamTypeNum
2412 // N TOF cluster --> TOF header --> to get the TOF header we need to add a virtual method in AliVTrack extended to ESD and AOD tracks
2413 // isMC --> fIsMC
2414
2415 Int_t nTOFcluster = 0;
2416 if(track->GetTOFHeader() && track->GetTOFHeader()->GetTriggerMask()){ // N TOF clusters available
2417 nTOFcluster = track->GetTOFHeader()->GetNumberOfTOFclusters();
2418 if(fIsMC) nTOFcluster *= 1.5; // +50% in MC
2419 }
2420 else{
2421 switch(fBeamTypeNum){
2422 case kPP: // pp 7 TeV
2423 nTOFcluster = 50;
2424 break;
2425 case kPPB: // pPb 5.05 ATeV
2426 nTOFcluster = 50 + (100-fCurrCentrality)*50;
2427 break;
2428 case kPBPB: // PbPb 2.76 ATeV
2429 nTOFcluster = 50 + (100-fCurrCentrality)*150;
2430 break;
2431 }
2432 }
2433
4fc0f532 2434 //fTOFResponse.GetMismatchProbability(track->GetTOFsignal(),track->Eta()) * 0.01; // for future implementation of mismatch (i.e. 1% mismatch that should be extended for PbPb, pPb)
2435
1c9d11be 2436 // set flat distribution (no decision)
2437 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
2438
355b831b 2439 const EDetPidStatus pidStatus=GetTOFPIDStatus(track);
2440 if (pidStatus!=kDetPidOk) return pidStatus;
2441
c5fb644a 2442 const Double_t meanCorrFactor = 0.07/fTOFtail; // Correction factor on the mean because of the tail (should be ~ 0.1 with tail = 1.1)
1c9d11be 2443
bf26ce58 2444 for (Int_t j=0; j<nSpecies; j++) {
1c9d11be 2445 AliPID::EParticleType type=AliPID::EParticleType(j);
355b831b 2446 const Double_t nsigmas=GetNumberOfSigmasTOFold(track,type) + meanCorrFactor;
1c9d11be 2447
355b831b 2448 const Double_t expTime = fTOFResponse.GetExpectedSignal(track,type);
2449 const Double_t sig = fTOFResponse.GetExpectedSigma(track->P(),expTime,AliPID::ParticleMassZ(type));
4fc0f532 2450
2451 if(nsigmas < fTOFtail)
2452 p[j] = TMath::Exp(-0.5*nsigmas*nsigmas)/sig;
2453 else
2454 p[j] = TMath::Exp(-(nsigmas - fTOFtail*0.5)*fTOFtail)/sig;
2455
42fcc729 2456 p[j] += fgTOFmismatchProb;
1c9d11be 2457 }
2458
1c9d11be 2459 return kDetPidOk;
2460}
239fe91c 2461
2462Int_t AliPIDResponse::CalculateTRDResponse(const AliVTrack *track,Double_t p[],AliTRDPIDResponse::ETRDPIDMethod PIDmethod) const
2463{
2464 // new function for backward compatibility
2465 // returns number of tracklets PID
2466
2467 UInt_t TRDslicesForPID[2];
2468 SetTRDSlices(TRDslicesForPID,PIDmethod);
2469
2470 Float_t mom[6]={0.};
2471 Double_t dedx[48]={0.}; // Allocate space for the maximum number of TRD slices
2472 Int_t nslices = TRDslicesForPID[1] - TRDslicesForPID[0] + 1;
2473 AliDebug(1, Form("First Slice: %d, Last Slice: %d, Number of slices: %d", TRDslicesForPID[0], TRDslicesForPID[1], nslices));
2474 for(UInt_t ilayer = 0; ilayer < 6; ilayer++){
2475 mom[ilayer] = track->GetTRDmomentum(ilayer);
2476 for(UInt_t islice = TRDslicesForPID[0]; islice <= TRDslicesForPID[1]; islice++){
2477 dedx[ilayer*nslices+islice-TRDslicesForPID[0]] = track->GetTRDslice(ilayer, islice);
2478 }
2479 }
2480
2481 return fTRDResponse.GetResponse(nslices, dedx, mom, p,PIDmethod);
2482
2483}
1c9d11be 2484//______________________________________________________________________________
239fe91c 2485AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[],AliTRDPIDResponse::ETRDPIDMethod PIDmethod) const
1c9d11be 2486{
2487 //
355b831b 2488 // Compute PID probabilities for the TRD
1c9d11be 2489 //
2490
1c9d11be 2491 // set flat distribution (no decision)
2492 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
355b831b 2493
2494 const EDetPidStatus pidStatus=GetTRDPIDStatus(track);
2495 if (pidStatus!=kDetPidOk) return pidStatus;
2496
239fe91c 2497 CalculateTRDResponse(track,p,PIDmethod);
2498
1c9d11be 2499 return kDetPidOk;
1c9d11be 2500}
355b831b 2501
1c9d11be 2502//______________________________________________________________________________
2503AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeEMCALProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
2504{
2505 //
2506 // Compute PID response for the EMCAL
2507 //
2508
2509 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
355b831b 2510
2511 const EDetPidStatus pidStatus=GetEMCALPIDStatus(track);
2512 if (pidStatus!=kDetPidOk) return pidStatus;
2513
2514 const Int_t nMatchClus = track->GetEMCALcluster();
2515 AliVCluster *matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
1c9d11be 2516
355b831b 2517 const Double_t mom = track->P();
2518 const Double_t pt = track->Pt();
2519 const Int_t charge = track->Charge();
2520 const Double_t fClsE = matchedClus->E();
2521 const Double_t EovP = fClsE/mom;
1c9d11be 2522
355b831b 2523 // compute the probabilities
2524 fEMCALResponse.ComputeEMCALProbability(nSpecies,pt,EovP,charge,p);
2525 return kDetPidOk;
1c9d11be 2526}
355b831b 2527
1c9d11be 2528//______________________________________________________________________________
2529AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputePHOSProbability (const AliVTrack */*track*/, Int_t nSpecies, Double_t p[]) const
2530{
2531 //
2532 // Compute PID response for the PHOS
2533 //
2534
2535 // set flat distribution (no decision)
2536 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
2537 return kDetNoSignal;
2538}
355b831b 2539
1c9d11be 2540//______________________________________________________________________________
2541AliPIDResponse::EDetPidStatus AliPIDResponse::GetComputeHMPIDProbability(const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
2542{
2543 //
2544 // Compute PID response for the HMPID
2545 //
355b831b 2546
1c9d11be 2547 // set flat distribution (no decision)
2548 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
355b831b 2549
2550 const EDetPidStatus pidStatus=GetHMPIDPIDStatus(track);
2551 if (pidStatus!=kDetPidOk) return pidStatus;
1c9d11be 2552
567624b5 2553 fHMPIDResponse.GetProbability(track,nSpecies,p);
2554
1c9d11be 2555 return kDetPidOk;
2556}
355b831b 2557
2558//______________________________________________________________________________
2559AliPIDResponse::EDetPidStatus AliPIDResponse::GetITSPIDStatus(const AliVTrack *track) const
2560{
2561 // compute ITS pid status
2562
2563 // check status bits
2564 if ((track->GetStatus()&AliVTrack::kITSin)==0 &&
2565 (track->GetStatus()&AliVTrack::kITSout)==0) return kDetNoSignal;
2566
2567 const Float_t dEdx=track->GetITSsignal();
2568 if (dEdx<=0) return kDetNoSignal;
2569
2570 // requite at least 3 pid clusters
2571 const UChar_t clumap=track->GetITSClusterMap();
2572 Int_t nPointsForPid=0;
2573 for(Int_t i=2; i<6; i++){
2574 if(clumap&(1<<i)) ++nPointsForPid;
2575 }
2576
2577 if(nPointsForPid<3) {
2578 return kDetNoSignal;
2579 }
2580
2581 return kDetPidOk;
2582}
2583
2584//______________________________________________________________________________
2585AliPIDResponse::EDetPidStatus AliPIDResponse:: GetTPCPIDStatus(const AliVTrack *track) const
2586{
2587 // compute TPC pid status
2588
2589 // check quality of the track
2590 if ( (track->GetStatus()&AliVTrack::kTPCin )==0 && (track->GetStatus()&AliVTrack::kTPCout)==0 ) return kDetNoSignal;
2591
2592 // check pid values
2593 const Double_t dedx=track->GetTPCsignal();
2594 const UShort_t signalN=track->GetTPCsignalN();
2595 if (signalN<10 || dedx<10) return kDetNoSignal;
2596
2597 if (!(fArrPidResponseMaster && fArrPidResponseMaster->At(AliPID::kPion))) return kDetNoParams;
2598
2599 return kDetPidOk;
2600}
2601
2602//______________________________________________________________________________
2603AliPIDResponse::EDetPidStatus AliPIDResponse::GetTRDPIDStatus(const AliVTrack *track) const
2604{
2605 // compute TRD pid status
2606
2607 if((track->GetStatus()&AliVTrack::kTRDout)==0) return kDetNoSignal;
2608 return kDetPidOk;
2609}
2610
2611//______________________________________________________________________________
2612AliPIDResponse::EDetPidStatus AliPIDResponse::GetTOFPIDStatus(const AliVTrack *track) const
2613{
2614 // compute TOF pid status
2615
2616 if ((track->GetStatus()&AliVTrack::kTOFout)==0) return kDetNoSignal;
2617 if ((track->GetStatus()&AliVTrack::kTIME)==0) return kDetNoSignal;
2618
2619 return kDetPidOk;
2620}
2621
2622//______________________________________________________________________________
2623Float_t AliPIDResponse::GetTOFMismatchProbability(const AliVTrack *track) const
2624{
2625 // compute mismatch probability cross-checking at 5 sigmas with TPC
2626 // currently just implemented as a 5 sigma compatibility cut
2627
42fcc729 2628 if(!track) return fgTOFmismatchProb;
2629
355b831b 2630 // check pid status
2631 const EDetPidStatus tofStatus=GetTOFPIDStatus(track);
2632 if (tofStatus!=kDetPidOk) return 0.;
2633
2634 //mismatch
2635 const EDetPidStatus tpcStatus=GetTPCPIDStatus(track);
a017c06a 2636 if (tpcStatus==kDetNoSignal) return 0.;
355b831b 2637
2638 const Double_t meanCorrFactor = 0.11/fTOFtail; // Correction factor on the mean because of the tail (should be ~ 0.1 with tail = 1.1)
2639 Bool_t mismatch = kTRUE/*, heavy = kTRUE*/;
2640 for (Int_t j=0; j<AliPID::kSPECIESC; j++) {
2641 AliPID::EParticleType type=AliPID::EParticleType(j);
2642 const Double_t nsigmas=GetNumberOfSigmasTOFold(track,type) + meanCorrFactor;
2643
2644 if (TMath::Abs(nsigmas)<5.){
2645 const Double_t nsigmasTPC=GetNumberOfSigmasTPC(track,type);
2646 if (TMath::Abs(nsigmasTPC)<5.) mismatch=kFALSE;
2647 }
2648 }
2649
2650 if (mismatch){
2651 return 1.;
2652 }
2653
2654 return 0.;
2655}
2656
355b831b 2657//______________________________________________________________________________
2658AliPIDResponse::EDetPidStatus AliPIDResponse:: GetHMPIDPIDStatus(const AliVTrack *track) const
2659{
2660 // compute HMPID pid status
567624b5 2661
2662 Int_t ch = track->GetHMPIDcluIdx()/1000000;
2663 Double_t HMPIDsignal = track->GetHMPIDsignal();
2664
2665 if((track->GetStatus()&AliVTrack::kHMPIDpid)==0 || ch<0 || ch>6 || HMPIDsignal<0) return kDetNoSignal;
2666
355b831b 2667 return kDetPidOk;
2668}
2669
2670//______________________________________________________________________________
2671AliPIDResponse::EDetPidStatus AliPIDResponse:: GetPHOSPIDStatus(const AliVTrack */*track*/) const
2672{
2673 // compute PHOS pid status
2674 return kDetNoSignal;
2675}
2676
2677//______________________________________________________________________________
2678AliPIDResponse::EDetPidStatus AliPIDResponse:: GetEMCALPIDStatus(const AliVTrack *track) const
2679{
2680 // compute EMCAL pid status
2681
2682
2683 // Track matching
2684 const Int_t nMatchClus = track->GetEMCALcluster();
2685 if (nMatchClus<0) return kDetNoSignal;
2686
2687 AliVCluster *matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
2688
2689 if (!(matchedClus && matchedClus->IsEMCAL())) return kDetNoSignal;
2690
2691 const Int_t charge = track->Charge();
2692 if (TMath::Abs(charge)!=1) return kDetNoSignal;
2693
2694 if (!(fEMCALPIDParams && fEMCALPIDParams->At(AliPID::kElectron))) return kDetNoParams;
2695
2696 return kDetPidOk;
2697
2698}
2699
2700//______________________________________________________________________________
2701AliPIDResponse::EDetPidStatus AliPIDResponse::GetPIDStatus(EDetector detector, const AliVTrack *track) const
2702{
2703 //
2704 // check pid status for a track
2705 //
2706
2707 switch (detector){
2708 case kITS: return GetITSPIDStatus(track); break;
2709 case kTPC: return GetTPCPIDStatus(track); break;
2710 case kTRD: return GetTRDPIDStatus(track); break;
2711 case kTOF: return GetTOFPIDStatus(track); break;
2712 case kPHOS: return GetPHOSPIDStatus(track); break;
2713 case kEMCAL: return GetEMCALPIDStatus(track); break;
2714 case kHMPID: return GetHMPIDPIDStatus(track); break;
2715 default: return kDetNoSignal;
2716 }
2717 return kDetNoSignal;
2718
2719}
5a9dc560 2720
2721//______________________________________________________________________________
2722TString AliPIDResponse::GetChecksum(const TObject* obj) const
2723{
2724 // Return the checksum for an object obj (tested to work properly at least for histograms and TSplines).
2725
2726 TString fileName = Form("tempChecksum.C"); // File name must be fixed for data type "TSpline3", since the file name will end up in the file content!
2727
2728 // For parallel processing, a unique file pathname is required. Uniqueness can be guaranteed by using a unique directory name
2729 UInt_t index = 0;
2730 TString uniquePathName = Form("tempChecksum_%u", index);
2731
2732 // To get a unique path name, increase the index until no directory
2733 // of such a name exists.
2734 // NOTE: gSystem->AccessPathName(...) returns kTRUE, if the access FAILED!
2735 while (!gSystem->AccessPathName(uniquePathName.Data()))
2736 uniquePathName = Form("tempChecksum_%u", ++index);
2737
2738 if (gSystem->mkdir(uniquePathName.Data()) < 0) {
2739 AliError("Could not create temporary directory to store temp file for checksum determination!");
2740 return "ERROR";
2741 }
2742
2743 TString option = "";
2744
2745 // Save object as a macro, which will be deleted immediately after the checksum has been computed
2746 // (does not work for desired data types if saved as *.root for some reason) - one only wants to compare the content, not
2747 // the modification time etc. ...
2748 if (dynamic_cast<const TH1*>(obj))
2749 option = "colz"; // Histos need this option, since w/o this option, a counter is added to the filename
2750
2751
2752 // SaveAs must be called with the fixed fileName only, since the first argument goes into the file content
2753 // for some object types. Thus, change the directory, save the file and then go back
2754 TString oldDir = gSystem->pwd();
2755 gSystem->cd(uniquePathName.Data());
2756 obj->SaveAs(fileName.Data(), option.Data());
2757 gSystem->cd(oldDir.Data());
2758
2759 // Use the file to calculate the MD5 checksum
2760 TMD5* md5 = TMD5::FileChecksum(Form("%s/%s", uniquePathName.Data(), fileName.Data()));
2761 TString checksum = md5->AsString();
2762
2763 // Clean up
2764 delete md5;
2765 gSystem->Exec(Form("rm -rf %s", uniquePathName.Data()));
2766
2767 return checksum;
2768}