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