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