]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/PartCorrBase/AliCaloPID.cxx
Adding ZDC TDC histo for DQM shifter
[u/mrichter/AliRoot.git] / PWG4 / PartCorrBase / AliCaloPID.cxx
CommitLineData
1c5acb87 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/* $Id: AliCaloPID.cxx 21839 2007-10-29 13:49:42Z gustavo $ */
16
17//_________________________________________________________________________
bdd2a262 18// Class for PID selection with calorimeters
19// The Output of the 2 main methods GetPdg is a PDG number identifying the cluster,
20// being kPhoton, kElectron, kPi0 ... as defined in the header file
21// - GetPdg(const TString calo, const Double_t * pid, const Float_t energy)
22// Reads the PID weights array of the ESDs and depending on its magnitude identifies the particle
0ae57829 23// - GetPdg(const TString calo,const TLorentzVector mom, const AliVCluster * cluster)
bdd2a262 24// Recalcultes PID, the bayesian or any new one to be implemented in the future
25// Right now only the possibility to recalculate EMCAL with bayesian and simple PID.
26// In order to recalculate Bayesian, it is necessary to load the EMCALUtils library
27// and do SwitchOnBayesianRecalculation().
28// To change the PID parameters from Low to High like the ones by default, use the constructor
29// AliCaloPID(flux)
30// where flux is AliCaloPID::kLow or AliCaloPID::kHigh
31// If it is necessary to change the parameters use the constructor
32// AliCaloPID(AliEMCALPIDUtils *utils) and set the parameters before.
33// - SetPIDBits: Simple PID, depending on the thresholds fDispCut fTOFCut and even the
34// result of the PID bayesian a different PID bit is set.
35//
36// All these methods can be called in the analysis you are interested.
37//
1c5acb87 38//*-- Author: Gustavo Conesa (LNF-INFN)
39//////////////////////////////////////////////////////////////////////////////
40
41
42// --- ROOT system ---
43#include <TMath.h>
1c5acb87 44#include <TString.h>
a33b76ed 45//#include <TFormula.h>
1c5acb87 46
47//---- ANALYSIS system ----
1c5acb87 48#include "AliCaloPID.h"
0ae57829 49#include "AliVCluster.h"
1c5acb87 50#include "AliAODPWG4Particle.h"
bdd2a262 51#include "AliEMCALPIDUtils.h"
f2ccb5b8 52#include "AliCalorimeterUtils.h"
53
1c5acb87 54ClassImp(AliCaloPID)
55
56
57//________________________________________________
58AliCaloPID::AliCaloPID() :
59TObject(), fEMCALPhotonWeight(0.), fEMCALPi0Weight(0.),
60fEMCALElectronWeight(0.), fEMCALChargeWeight(0.),
61fEMCALNeutralWeight(0.),
62fPHOSPhotonWeight(0.), fPHOSPi0Weight(0.),
63fPHOSElectronWeight(0.), fPHOSChargeWeight(0.) ,
a33b76ed 64fPHOSNeutralWeight(0.), //fPHOSWeightFormula(0),
65//fPHOSPhotonWeightFormula(0x0), fPHOSPi0WeightFormula(0x0),
bdd2a262 66fDispCut(0.),fTOFCut(0.), fDebug(-1),
f2ccb5b8 67fRecalculateBayesian(kFALSE), fParticleFlux(kLow),
68fEMCALPIDUtils(new AliEMCALPIDUtils)
1c5acb87 69{
477d6cee 70 //Ctor
71
72 //Initialize parameters
73 InitParameters();
1c5acb87 74}
75
bdd2a262 76//________________________________________________
77AliCaloPID::AliCaloPID(const Int_t flux) :
78TObject(), fEMCALPhotonWeight(0.), fEMCALPi0Weight(0.),
79fEMCALElectronWeight(0.), fEMCALChargeWeight(0.),
80fEMCALNeutralWeight(0.),
81fPHOSPhotonWeight(0.), fPHOSPi0Weight(0.),
82fPHOSElectronWeight(0.), fPHOSChargeWeight(0.) ,
a33b76ed 83fPHOSNeutralWeight(0.), //fPHOSWeightFormula(0),
84//fPHOSPhotonWeightFormula(0x0), fPHOSPi0WeightFormula(0x0),
bdd2a262 85fDispCut(0.),fTOFCut(0.), fDebug(-1),
f2ccb5b8 86fRecalculateBayesian(kTRUE), fParticleFlux(flux),
87fEMCALPIDUtils(new AliEMCALPIDUtils)
bdd2a262 88{
89 //Ctor
90
91 //Initialize parameters
92 InitParameters();
93}
94
95//________________________________________________
96AliCaloPID::AliCaloPID(const TTask * emcalpid) :
97TObject(), fEMCALPhotonWeight(0.), fEMCALPi0Weight(0.),
98fEMCALElectronWeight(0.), fEMCALChargeWeight(0.),
99fEMCALNeutralWeight(0.),
100fPHOSPhotonWeight(0.), fPHOSPi0Weight(0.),
101fPHOSElectronWeight(0.), fPHOSChargeWeight(0.) ,
a33b76ed 102fPHOSNeutralWeight(0.), //fPHOSWeightFormula(0),
103//fPHOSPhotonWeightFormula(0x0), fPHOSPi0WeightFormula(0x0),
bdd2a262 104fDispCut(0.),fTOFCut(0.), fDebug(-1),
f2ccb5b8 105fRecalculateBayesian(kTRUE), fParticleFlux(-1),
106fEMCALPIDUtils( (AliEMCALPIDUtils*) emcalpid)
bdd2a262 107{
108 //Ctor
109
110 //Initialize parameters
111 InitParameters();
112}
113
1c5acb87 114//____________________________________________________________________________
115AliCaloPID::AliCaloPID(const AliCaloPID & pid) :
116TObject(pid), fEMCALPhotonWeight(pid.fEMCALPhotonWeight),
117fEMCALPi0Weight(pid.fEMCALPi0Weight),
118fEMCALElectronWeight(pid.fEMCALElectronWeight),
119fEMCALChargeWeight(pid.fEMCALChargeWeight),
120fEMCALNeutralWeight(pid.fEMCALNeutralWeight),
121fPHOSPhotonWeight(pid.fPHOSPhotonWeight),
122fPHOSPi0Weight(pid.fPHOSPi0Weight),
123fPHOSElectronWeight(pid.fPHOSElectronWeight),
124fPHOSChargeWeight(pid.fPHOSChargeWeight),
125fPHOSNeutralWeight(pid.fPHOSNeutralWeight),
a33b76ed 126//fPHOSWeightFormula(pid.fPHOSWeightFormula),
127//fPHOSPhotonWeightFormula(new TFormula(*pid.fPHOSPhotonWeightFormula)),
128//fPHOSPi0WeightFormula (new TFormula(*pid.fPHOSPi0WeightFormula)),
1c5acb87 129fDispCut(pid.fDispCut),fTOFCut(pid.fTOFCut),
bdd2a262 130fDebug(pid.fDebug), fRecalculateBayesian(pid.fRecalculateBayesian),
fb9841b8 131fParticleFlux(pid.fParticleFlux),
132fEMCALPIDUtils(new AliEMCALPIDUtils(*pid.fEMCALPIDUtils))
1c5acb87 133{
477d6cee 134 // cpy ctor
1c5acb87 135
136}
137
138//_________________________________________________________________________
614701c6 139//AliCaloPID & AliCaloPID::operator = (const AliCaloPID & pid)
140//{
141// // assignment operator
142//
143// if(&pid == this) return *this;
144//
145// fEMCALPhotonWeight = pid. fEMCALPhotonWeight ;
146// fEMCALPi0Weight = pid.fEMCALPi0Weight ;
147// fEMCALElectronWeight = pid.fEMCALElectronWeight;
148// fEMCALChargeWeight = pid.fEMCALChargeWeight;
149// fEMCALNeutralWeight = pid.fEMCALNeutralWeight;
150//
151// fPHOSPhotonWeight = pid.fPHOSPhotonWeight ;
152// fPHOSPi0Weight = pid.fPHOSPi0Weight ;
153// fPHOSElectronWeight = pid.fPHOSElectronWeight;
154// fPHOSChargeWeight = pid.fPHOSChargeWeight;
155// fPHOSNeutralWeight = pid.fPHOSNeutralWeight;
156//
157// fPHOSWeightFormula = pid.fPHOSWeightFormula;
158// delete fPHOSPhotonWeightFormula; fPHOSPhotonWeightFormula = new TFormula(*pid.fPHOSPhotonWeightFormula);
159// delete fPHOSPi0WeightFormula; fPHOSPi0WeightFormula = new TFormula(*pid.fPHOSPi0WeightFormula);
160//
161// fDispCut = pid.fDispCut;
162// fTOFCut = pid.fTOFCut;
163// fDebug = pid.fDebug;
164//
165// fRecalculateBayesian = pid.fRecalculateBayesian;
166// fParticleFlux = pid.fParticleFlux;
167//
168// delete fEMCALPIDUtils; fEMCALPIDUtils = new AliEMCALPIDUtils(*pid.fEMCALPIDUtils);
169//
170// return *this;
171//
172//}
1c5acb87 173
174//_________________________________
175AliCaloPID::~AliCaloPID() {
477d6cee 176 //Dtor
177
a33b76ed 178// if(fPHOSPhotonWeightFormula) delete fPHOSPhotonWeightFormula ;
179// if(fPHOSPi0WeightFormula) delete fPHOSPi0WeightFormula ;
fb9841b8 180 if(fEMCALPIDUtils) delete fEMCALPIDUtils ;
1c5acb87 181}
182
183
1c5acb87 184//_______________________________________________________________
185void AliCaloPID::InitParameters()
186{
477d6cee 187 //Initialize the parameters of the PID.
188
691c43c9 189 fEMCALPhotonWeight = 0.5 ;
477d6cee 190 fEMCALPi0Weight = 0.5 ;
691c43c9 191 fEMCALElectronWeight = 0.5 ;
477d6cee 192 fEMCALChargeWeight = 0.5 ;
193 fEMCALNeutralWeight = 0.5 ;
194
691c43c9 195 fPHOSPhotonWeight = 0.5 ;
196 fPHOSPi0Weight = 0.5 ;
477d6cee 197 fPHOSElectronWeight = 0.5 ;
198 fPHOSChargeWeight = 0.5 ;
199 fPHOSNeutralWeight = 0.5 ;
200
201 //Formula to set the PID weight threshold for photon or pi0
a33b76ed 202 //fPHOSWeightFormula = kTRUE;
203 //if(fPHOSPhotonWeightFormula) delete fPHOSPhotonWeightFormula;
204 //if(fPHOSPi0WeightFormula) delete fPHOSPi0WeightFormula;
205 //fPHOSPhotonWeightFormula =
206 //new TFormula("photonWeight","0.98*(x<40)+ 0.68*(x>=100)+(x>=40 && x<100)*(0.98+x*(6e-3)-x*x*(2e-04)+x*x*x*(1.1e-06))");
207 //fPHOSPi0WeightFormula =
208 //new TFormula("pi0Weight","0.98*(x<65)+ 0.915*(x>=100)+(x>=65 && x-x*(1.95e-3)-x*x*(4.31e-05)+x*x*x*(3.61e-07))");
477d6cee 209
5ae09196 210 fDispCut = 0.25;
477d6cee 211 fTOFCut = 5.e-9;
212 fDebug = -1;
bdd2a262 213
214 if(fRecalculateBayesian){
bdd2a262 215 if(fParticleFlux == kLow){
216 printf("AliCaloPID::Init() - SetLOWFluxParam\n");
217 fEMCALPIDUtils->SetLowFluxParam() ;
218 }
219 else if (fParticleFlux == kHigh){
220 printf("AliCaloPID::Init() - SetHIGHFluxParam\n");
221 fEMCALPIDUtils->SetHighFluxParam() ;
222 }
bdd2a262 223 }
1c5acb87 224}
225
226//_______________________________________________________________
227Int_t AliCaloPID::GetPdg(const TString calo, const Double_t * pid, const Float_t energy) const {
477d6cee 228 //Return most probable identity of the particle.
229
230 if(!pid){
231 printf("AliCaloPID::GetPdg() - pid pointer not initialized!!!\n");
232 abort();
233 }
234
15800db4 235 Float_t wPh = fPHOSPhotonWeight ;
477d6cee 236 Float_t wPi0 = fPHOSPi0Weight ;
15800db4 237 Float_t wE = fPHOSElectronWeight ;
238 Float_t wCh = fPHOSChargeWeight ;
239 Float_t wNe = fPHOSNeutralWeight ;
477d6cee 240
241
a33b76ed 242// if(calo == "PHOS" && fPHOSWeightFormula){
243// wPh = fPHOSPhotonWeightFormula->Eval(energy) ;
244// wPi0 = fPHOSPi0WeightFormula->Eval(energy);
245// }
477d6cee 246
247 if(calo == "EMCAL"){
248
249 wPh = fEMCALPhotonWeight ;
250 wPi0 = fEMCALPi0Weight ;
251 wE = fEMCALElectronWeight ;
252 wCh = fEMCALChargeWeight ;
253 wNe = fEMCALNeutralWeight ;
254
255 }
256
257 if(fDebug > 0) printf("AliCaloPID::GetPdg: calo %s, ph %0.2f, pi0 %0.2f, el %0.2f, conv el %0.2f, hadrons: pion %0.2f, kaon %0.2f, proton %0.2f , neutron %0.2f, kaon %0.2f \n",
c8fe2783 258 calo.Data(),pid[AliVCluster::kPhoton], pid[AliVCluster::kPi0],
259 pid[AliVCluster::kElectron], pid[AliVCluster::kEleCon],
260 pid[AliVCluster::kPion], pid[AliVCluster::kKaon], pid[AliVCluster::kProton],
261 pid[AliVCluster::kNeutron], pid[AliVCluster::kKaon0]);
477d6cee 262
263 Int_t pdg = kNeutralUnknown ;
c8fe2783 264 Float_t chargedHadronWeight = pid[AliVCluster::kProton]+pid[AliVCluster::kKaon]+
265 pid[AliVCluster::kPion]+pid[AliVCluster::kMuon];
266 Float_t neutralHadronWeight = pid[AliVCluster::kNeutron]+pid[AliVCluster::kKaon0];
267 Float_t allChargedWeight = pid[AliVCluster::kElectron]+pid[AliVCluster::kEleCon]+ chargedHadronWeight;
268 Float_t allNeutralWeight = pid[AliVCluster::kPhoton]+pid[AliVCluster::kPi0]+ neutralHadronWeight;
477d6cee 269
270 //Select most probable ID
271 if(calo=="PHOS"){
c8fe2783 272 if(pid[AliVCluster::kPhoton] > wPh) pdg = kPhoton ;
273 else if(pid[AliVCluster::kPi0] > wPi0) pdg = kPi0 ;
274 else if(pid[AliVCluster::kElectron] > wE) pdg = kElectron ;
275 else if(pid[AliVCluster::kEleCon] > wE) pdg = kEleCon ;
477d6cee 276 else if(chargedHadronWeight > wCh) pdg = kChargedHadron ;
277 else if(neutralHadronWeight > wNe) pdg = kNeutralHadron ;
278 else if(allChargedWeight > allNeutralWeight)
279 pdg = kChargedUnknown ;
280 else
281 pdg = kNeutralUnknown ;
282 }
283 else{//EMCAL
bdd2a262 284
c8fe2783 285 if(pid[AliVCluster::kPhoton]+pid[AliVCluster::kElectron] > wPh) pdg = kPhoton ; //temporal sollution until track matching for electrons is considered
286 //if(pid[AliVCluster::kPhoton] > wPh) pdg = kPhoton ;
287 else if(pid[AliVCluster::kPi0] > wPi0) pdg = kPi0 ;
288 //else if(pid[AliVCluster::kElectron] > wE) pdg = kElectron ;
477d6cee 289 else if(chargedHadronWeight + neutralHadronWeight > wCh) pdg = kChargedHadron ;
290 else if(neutralHadronWeight + chargedHadronWeight > wNe) pdg = kNeutralHadron ;
291 else pdg = kNeutralUnknown ;
292
293 }
294
ebc881ec 295 if(fDebug > 0)printf("AliCaloPID::GetPdg:Final Pdg: %d, cluster energy %2.2f \n", pdg,energy);
477d6cee 296
297 return pdg ;
298
1c5acb87 299}
300
301//_______________________________________________________________
0ae57829 302Int_t AliCaloPID::GetPdg(const TString calo,const TLorentzVector mom, const AliVCluster * cluster) const {
477d6cee 303 //Recalculated PID with all parameters
bdd2a262 304 Float_t lambda0 = cluster->GetM02();
305 Float_t energy = mom.E();
306
307 if(fDebug > 0) printf("AliCaloPID::GetPdg: Calorimeter %s, E %3.2f, l0 %3.2f, l1 %3.2f, disp %3.2f, tof %1.11f, distCPV %3.2f, distToBC %1.1f, NMax %d\n",
308 calo.Data(),energy,lambda0,cluster->GetM20(),cluster->GetDispersion(),cluster->GetTOF(),
c8fe2783 309 cluster->GetEmcCpvDistance(), cluster->GetDistanceToBadChannel(),cluster->GetNExMax());
bdd2a262 310
477d6cee 311 if(calo == "EMCAL") {
bdd2a262 312 //Recalculate Bayesian
313 if(fRecalculateBayesian){
bdd2a262 314 if(fDebug > 0) {
c8fe2783 315 const Double_t *pid0 = cluster->GetPID();
bdd2a262 316 printf("AliCaloPID::GetPdg: BEFORE calo %s, ph %0.2f, pi0 %0.2f, el %0.2f, conv el %0.2f, hadrons: pion %0.2f, kaon %0.2f, proton %0.2f , neutron %0.2f, kaon %0.2f \n",
c8fe2783 317 calo.Data(),pid0[AliVCluster::kPhoton], pid0[AliVCluster::kPi0],
318 pid0[AliVCluster::kElectron], pid0[AliVCluster::kEleCon],
319 pid0[AliVCluster::kPion], pid0[AliVCluster::kKaon], pid0[AliVCluster::kProton],
320 pid0[AliVCluster::kNeutron], pid0[AliVCluster::kKaon0]);
bdd2a262 321 }
322
323 fEMCALPIDUtils->ComputePID(energy, lambda0);
324 Double_t pid[AliPID::kSPECIESN];
325 for(Int_t i = 0; i < AliPID::kSPECIESN; i++) pid[i] = fEMCALPIDUtils->GetPIDFinal(i);
326 return GetPdg(calo, pid, energy);
327
bdd2a262 328
329 }
330
c8fe2783 331 // If no use of bayesian, simple PID
332 if(lambda0 < 0.25) return kPhoton ;
333 //else return kNeutralHadron ;
334 else return kPi0 ;
477d6cee 335 }
336
337 // if(calo == "PHOS") {
338 // if(cluster->GetM02()< 0.25) return kPhoton ;
339 // else return kNeutralHadron ;
340 // }
341
342 return kNeutralHadron ;
343
1c5acb87 344}
345
346//__________________________________________________
347TString AliCaloPID::GetPIDParametersList() {
477d6cee 348 //Put data member values in string to keep in output container
349
350 TString parList ; //this will be list of parameters used for this analysis.
5ae09196 351 const Int_t buffersize = 255;
352 char onePar[buffersize] ;
353 snprintf(onePar,buffersize,"--- AliCaloPID ---\n") ;
477d6cee 354 parList+=onePar ;
5ae09196 355 snprintf(onePar,buffersize,"fDispCut =%2.2f (Cut on dispersion, used in PID evaluation) \n",fDispCut) ;
477d6cee 356 parList+=onePar ;
5ae09196 357 snprintf(onePar,buffersize,"fTOFCut =%e (Cut on TOF, used in PID evaluation) \n",fTOFCut) ;
477d6cee 358 parList+=onePar ;
5ae09196 359 snprintf(onePar,buffersize,"fEMCALPhotonWeight =%2.2f (EMCAL bayesian weight for photons)\n",fEMCALPhotonWeight) ;
477d6cee 360 parList+=onePar ;
5ae09196 361 snprintf(onePar,buffersize,"fEMCALPi0Weight =%2.2f (EMCAL bayesian weight for pi0)\n",fEMCALPi0Weight) ;
477d6cee 362 parList+=onePar ;
5ae09196 363 snprintf(onePar,buffersize,"fEMCALElectronWeight =%2.2f(EMCAL bayesian weight for electrons)\n",fEMCALElectronWeight) ;
477d6cee 364 parList+=onePar ;
5ae09196 365 snprintf(onePar,buffersize,"fEMCALChargeWeight =%2.2f (EMCAL bayesian weight for charged hadrons)\n",fEMCALChargeWeight) ;
477d6cee 366 parList+=onePar ;
5ae09196 367 snprintf(onePar,buffersize,"fEMCALNeutralWeight =%2.2f (EMCAL bayesian weight for neutral hadrons)\n",fEMCALNeutralWeight) ;
477d6cee 368 parList+=onePar ;
5ae09196 369 snprintf(onePar,buffersize,"fPHOSPhotonWeight =%2.2f (PHOS bayesian weight for photons)\n",fPHOSPhotonWeight) ;
477d6cee 370 parList+=onePar ;
5ae09196 371 snprintf(onePar,buffersize,"fPHOSPi0Weight =%2.2f (PHOS bayesian weight for pi0)\n",fPHOSPi0Weight) ;
477d6cee 372 parList+=onePar ;
5ae09196 373 snprintf(onePar,buffersize,"fPHOSElectronWeight =%2.2f(PHOS bayesian weight for electrons)\n",fPHOSElectronWeight) ;
477d6cee 374 parList+=onePar ;
5ae09196 375 snprintf(onePar,buffersize,"fPHOSChargeWeight =%2.2f (PHOS bayesian weight for charged hadrons)\n",fPHOSChargeWeight) ;
477d6cee 376 parList+=onePar ;
5ae09196 377 snprintf(onePar,buffersize,"fPHOSNeutralWeight =%2.2f (PHOS bayesian weight for neutral hadrons)\n",fPHOSNeutralWeight) ;
477d6cee 378 parList+=onePar ;
379
a33b76ed 380// if(fPHOSWeightFormula){
5ae09196 381// sprintf(onePar,buffersize,"PHOS Photon Weight Formula: %s\n",(fPHOSPhotonWeightFormula->GetExpFormula("p")).Data()) ;
a33b76ed 382// parList+=onePar;
5ae09196 383// sprintf(onePar,buffersize,"PHOS Pi0 Weight Formula: %s\n",(fPHOSPi0WeightFormula->GetExpFormula("p")).Data()) ;
a33b76ed 384// parList+=onePar;
385// }
477d6cee 386
387 return parList;
388
1c5acb87 389}
390
391//________________________________________________________________
392void AliCaloPID::Print(const Option_t * opt) const
393{
477d6cee 394
395 //Print some relevant parameters set for the analysis
396 if(! opt)
397 return;
398
399 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
400
401 printf("PHOS PID weight , photon %0.2f, pi0 %0.2f, e %0.2f, charge %0.2f, neutral %0.2f \n",
402 fPHOSPhotonWeight, fPHOSPi0Weight,
403 fPHOSElectronWeight, fPHOSChargeWeight, fPHOSNeutralWeight) ;
404 printf("EMCAL PID weight, photon %0.2f, pi0 %0.2f, e %0.2f, charge %0.2f, neutral %0.2f\n",
405 fEMCALPhotonWeight, fEMCALPi0Weight,
406 fEMCALElectronWeight, fEMCALChargeWeight, fEMCALNeutralWeight) ;
407
a33b76ed 408// printf("PHOS Parametrized weight on? = %d\n", fPHOSWeightFormula) ;
409// if(fPHOSWeightFormula){
410// printf("Photon weight formula = %s\n", (fPHOSPhotonWeightFormula->GetExpFormula("p")).Data());
411// printf("Pi0 weight formula = %s\n", (fPHOSPhotonWeightFormula->GetExpFormula("p")).Data());
412// }
477d6cee 413
414 printf("TOF cut = %e\n",fTOFCut);
415 printf("Dispersion cut = %2.2f\n",fDispCut);
416 printf("Debug level = %d\n",fDebug);
bdd2a262 417 printf("Recalculate Bayesian? = %d\n",fRecalculateBayesian);
418 if(fRecalculateBayesian) printf("Particle Flux? = %d\n",fParticleFlux);
477d6cee 419 printf(" \n");
420
1c5acb87 421}
422
423//_______________________________________________________________
f2ccb5b8 424void AliCaloPID::SetPIDBits(const TString calo, const AliVCluster * cluster, AliAODPWG4Particle * ph, const AliCalorimeterUtils* cu) {
477d6cee 425 //Set Bits for PID selection
426
427 //Dispersion/lambdas
5ae09196 428 //Double_t disp= cluster->GetDispersion() ;
429 Double_t l1 = cluster->GetM20() ;
430 Double_t l0 = cluster->GetM02() ;
431 Bool_t isDispOK = kTRUE ;
432 if(cluster->IsPHOS()){
433
434 if(l1>= 0 && l0>= 0 && l1 < 0.1 && l0 < 0.1) isDispOK=kFALSE ;
435 if(l1>= 0 && l0 > 0.5 && l1 < 0.1 && l0 < 1.5) isDispOK=kTRUE ;
436 if(l1>= 0 && l0 > 2.0 && l1 < 0.1 && l0 < 2.7) isDispOK=kFALSE ;
437 if(l1>= 0 && l0 > 2.7 && l1 < 0.1 && l0 < 4.0) isDispOK=kFALSE ;
438 if(l1 > 0.1 && l1 < 0.7 && l0 > 0.7 && l0 < 2.1) isDispOK=kTRUE ;
439 if(l1 > 0.1 && l1 < 0.3 && l0 > 3.0 && l0 < 5.0) isDispOK=kFALSE ;
440 if(l1 > 0.3 && l1 < 0.7 && l0 > 2.5 && l0 < 4.0) isDispOK=kFALSE ;
441 if(l1 > 0.7 && l1 < 1.3 && l0 > 1.0 && l0 < 1.6) isDispOK=kTRUE ;
442 if(l1 > 0.7 && l1 < 1.3 && l0 > 1.6 && l0 < 3.5) isDispOK=kTRUE ;
443 if(l1 > 1.3 && l1 < 3.5 && l0 > 1.3 && l0 < 3.5) isDispOK=kTRUE ;
444
445 }
446 else{//EMCAL
447
448 if(l0 > fDispCut || l0 < 0.) isDispOK = kFALSE;
449
450 }
451
452 ph->SetDispBit(isDispOK) ;
477d6cee 453
454 //TOF
455 Double_t tof=cluster->GetTOF() ;
456 ph->SetTOFBit(TMath::Abs(tof)<fTOFCut) ;
457
5ae09196 458 //Charged veto
459 //Bool_t isNeutral = kTRUE ;
460 //if(cluster->IsPHOS()) isNeutral = cluster->GetEmcCpvDistance() > 5. ;
461 //else
f2ccb5b8 462 Bool_t isNeutral = IsTrackMatched(cluster,cu);
5ae09196 463
464 ph->SetChargedBit(isNeutral);
477d6cee 465
466 //Set PID pdg
c8fe2783 467 ph->SetPdg(GetPdg(calo,cluster->GetPID(),ph->E()));
477d6cee 468
469 if(fDebug > 0){
5ae09196 470 printf("AliCaloPID::SetPIDBits: TOF %e, Lambda0 %2.2f, Lambda1 %2.2f\n",tof , l0, l1);
477d6cee 471 printf("AliCaloPID::SetPIDBits: pdg %d, bits: TOF %d, Dispersion %d, Charge %d\n",
6639984f 472 ph->GetPdg(), ph->GetTOFBit() , ph->GetDispBit() , ph->GetChargedBit());
477d6cee 473 }
1c5acb87 474}
475
5ae09196 476//__________________________________________________________________________
f2ccb5b8 477Bool_t AliCaloPID::IsTrackMatched(const AliVCluster* cluster, const AliCalorimeterUtils * cu) const {
5ae09196 478 //Check if there is any track attached to this cluster
479
480 Int_t nMatches = cluster->GetNTracksMatched();
481
482 // printf("N matches %d, first match %d\n",nMatches,cluster->GetTrackMatchedIndex());
483 // if (cluster->GetTrackMatched(0)) printf("\t matched track id %d\n",((AliVTrack*)cluster->GetTrackMatched(0))->GetID()) ;
484 // else if(cluster->GetTrackMatchedIndex()>=0) printf("\t matched track id %d\n",((AliVTrack*) GetReader()->GetInputEvent()->GetTrack(cluster->GetTrackMatchedIndex()))->GetID()) ;
485
f2ccb5b8 486
5ae09196 487 if(!strcmp("AliESDCaloCluster",Form("%s",cluster->ClassName())))
488 {
f2ccb5b8 489 //If EMCAL track matching needs to be recalculated
490 if(cluster->IsEMCAL() && cu && cu->IsRecalculationOfClusterTrackMatchingOn()){
491 Float_t dR = 999., dZ = 999.;
492 cu->GetEMCALRecoUtils()->GetMatchedResiduals(cluster->GetID(),dR,dZ);
493 if(dR < 999) return kTRUE;
494 else return kFALSE;
495 }
496
5ae09196 497 if (nMatches > 0) {
498 if (nMatches == 1 ) {
499 Int_t iESDtrack = cluster->GetTrackMatchedIndex();
500 //printf("Track Matched index %d\n",iESDtrack);
501 if(iESDtrack==-1) return kFALSE ;// Default value of array, there is no match
502 else return kTRUE;
503 }//Just one, check
504 else return kTRUE ;//More than one, there is a match.
505 }// > 0
506 else return kFALSE; //It does not happen, but in case
507
508 }//ESDs
509 else
510 {
511 //AODs
f2ccb5b8 512 if(cu && cu->IsRecalculationOfClusterTrackMatchingOn()){
513 Float_t dR = TMath::Abs(cluster->GetEmcCpvDistance()) ; //FIXME
514 if(dR > cu->GetCutR()) return kFALSE;
515 else return kTRUE;
516 }
517 else {
518 if(nMatches > 0) return kTRUE; //There is at least one match.
519 else return kFALSE;
520 }
5ae09196 521 }//AODs or MC (copy into AOD)
522
523 return kFALSE;
524
525}
526
1c5acb87 527