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