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