]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/PartCorrBase/AliCaloPID.cxx
AliCaloPID: Correct matching rejection in case of recalculation in the analysis,...
[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"
d39cba7e 50#include "AliVTrack.h"
1c5acb87 51#include "AliAODPWG4Particle.h"
bdd2a262 52#include "AliEMCALPIDUtils.h"
f2ccb5b8 53#include "AliCalorimeterUtils.h"
54
1c5acb87 55ClassImp(AliCaloPID)
56
57
58//________________________________________________
59AliCaloPID::AliCaloPID() :
60TObject(), fEMCALPhotonWeight(0.), fEMCALPi0Weight(0.),
61fEMCALElectronWeight(0.), fEMCALChargeWeight(0.),
62fEMCALNeutralWeight(0.),
63fPHOSPhotonWeight(0.), fPHOSPi0Weight(0.),
64fPHOSElectronWeight(0.), fPHOSChargeWeight(0.) ,
a33b76ed 65fPHOSNeutralWeight(0.), //fPHOSWeightFormula(0),
66//fPHOSPhotonWeightFormula(0x0), fPHOSPi0WeightFormula(0x0),
bdd2a262 67fDispCut(0.),fTOFCut(0.), fDebug(-1),
f2ccb5b8 68fRecalculateBayesian(kFALSE), fParticleFlux(kLow),
d39cba7e 69fEMCALPIDUtils(new AliEMCALPIDUtils),
70fHistoNEBins(100), fHistoEMax(100.), fHistoEMin(0.),
71fHistoNDEtaBins(100),fHistoDEtaMax(0.15),fHistoDEtaMin(-0.15),
72fHistoNDPhiBins(100),fHistoDPhiMax(0.15),fHistoDPhiMin(-0.15),
73fhTrackMatchedDEta(),fhTrackMatchedDPhi(),fhTrackMatchedDEtaDPhi()
74
1c5acb87 75{
477d6cee 76 //Ctor
77
78 //Initialize parameters
79 InitParameters();
1c5acb87 80}
81
bdd2a262 82//________________________________________________
83AliCaloPID::AliCaloPID(const Int_t flux) :
84TObject(), fEMCALPhotonWeight(0.), fEMCALPi0Weight(0.),
85fEMCALElectronWeight(0.), fEMCALChargeWeight(0.),
86fEMCALNeutralWeight(0.),
87fPHOSPhotonWeight(0.), fPHOSPi0Weight(0.),
88fPHOSElectronWeight(0.), fPHOSChargeWeight(0.) ,
a33b76ed 89fPHOSNeutralWeight(0.), //fPHOSWeightFormula(0),
90//fPHOSPhotonWeightFormula(0x0), fPHOSPi0WeightFormula(0x0),
bdd2a262 91fDispCut(0.),fTOFCut(0.), fDebug(-1),
f2ccb5b8 92fRecalculateBayesian(kTRUE), fParticleFlux(flux),
d39cba7e 93fEMCALPIDUtils(new AliEMCALPIDUtils),
94fHistoNEBins(100), fHistoEMax(100.), fHistoEMin(0.),
95fHistoNDEtaBins(100),fHistoDEtaMax(0.15),fHistoDEtaMin(-0.15),
96fHistoNDPhiBins(100),fHistoDPhiMax(0.15),fHistoDPhiMin(-0.15),
97fhTrackMatchedDEta(),fhTrackMatchedDPhi(),fhTrackMatchedDEtaDPhi()
98
bdd2a262 99{
100 //Ctor
101
102 //Initialize parameters
103 InitParameters();
104}
105
106//________________________________________________
107AliCaloPID::AliCaloPID(const TTask * emcalpid) :
108TObject(), fEMCALPhotonWeight(0.), fEMCALPi0Weight(0.),
109fEMCALElectronWeight(0.), fEMCALChargeWeight(0.),
110fEMCALNeutralWeight(0.),
111fPHOSPhotonWeight(0.), fPHOSPi0Weight(0.),
112fPHOSElectronWeight(0.), fPHOSChargeWeight(0.) ,
a33b76ed 113fPHOSNeutralWeight(0.), //fPHOSWeightFormula(0),
114//fPHOSPhotonWeightFormula(0x0), fPHOSPi0WeightFormula(0x0),
bdd2a262 115fDispCut(0.),fTOFCut(0.), fDebug(-1),
f2ccb5b8 116fRecalculateBayesian(kTRUE), fParticleFlux(-1),
d39cba7e 117fEMCALPIDUtils( (AliEMCALPIDUtils*) emcalpid),
118fHistoNEBins(100), fHistoEMax(100.), fHistoEMin(0.),
119fHistoNDEtaBins(100),fHistoDEtaMax(0.15),fHistoDEtaMin(-0.15),
120fHistoNDPhiBins(100),fHistoDPhiMax(0.15),fHistoDPhiMin(-0.15),
121fhTrackMatchedDEta(),fhTrackMatchedDPhi(),fhTrackMatchedDEtaDPhi()
122
bdd2a262 123{
124 //Ctor
125
126 //Initialize parameters
127 InitParameters();
128}
129
1c5acb87 130//_________________________________
131AliCaloPID::~AliCaloPID() {
477d6cee 132 //Dtor
133
a33b76ed 134// if(fPHOSPhotonWeightFormula) delete fPHOSPhotonWeightFormula ;
135// if(fPHOSPi0WeightFormula) delete fPHOSPi0WeightFormula ;
fb9841b8 136 if(fEMCALPIDUtils) delete fEMCALPIDUtils ;
1c5acb87 137}
138
139
d39cba7e 140//________________________________________________________________________
141TList * AliCaloPID::GetCreateOutputObjects()
142{
143 // Create histograms to be saved in output file and
144 // store them in outputContainer of the analysis class that calls this class.
145
146 TList * outputContainer = new TList() ;
147 outputContainer->SetName("CaloPIDHistos") ;
148
149 outputContainer->SetOwner(kFALSE);
150
151 fhTrackMatchedDEta = new TH2F
152 ("TrackMatchedDEta",
153 "d#eta of cluster-track vs cluster energy",fHistoNEBins,fHistoEMin,fHistoEMax,fHistoNDEtaBins,fHistoDEtaMin,fHistoDEtaMax);
154 fhTrackMatchedDEta->SetYTitle("d#eta");
155 fhTrackMatchedDEta->SetXTitle("E_{cluster} (GeV)");
156
157 fhTrackMatchedDPhi = new TH2F
158 ("TrackMatchedDPhi",
159 "d#phi of cluster-track vs cluster energy"
160 ,fHistoNEBins,fHistoEMin,fHistoEMax,fHistoNDPhiBins,fHistoDPhiMin,fHistoDPhiMax);
161 fhTrackMatchedDPhi->SetYTitle("d#phi (rad)");
162 fhTrackMatchedDPhi->SetXTitle("E_{cluster} (GeV)");
163
164 fhTrackMatchedDEtaDPhi = new TH2F
165 ("TrackMatchedDEtaDPhi",
166 "d#eta vs d#phi of cluster-track vs cluster energy"
167 ,fHistoNDEtaBins,fHistoDEtaMin,fHistoDEtaMax,fHistoNDPhiBins,fHistoDPhiMin,fHistoDPhiMax);
168 fhTrackMatchedDEtaDPhi->SetYTitle("d#phi (rad)");
169 fhTrackMatchedDEtaDPhi->SetXTitle("d#eta");
170
171 outputContainer->Add(fhTrackMatchedDEta) ;
172 outputContainer->Add(fhTrackMatchedDPhi) ;
173 outputContainer->Add(fhTrackMatchedDEtaDPhi) ;
174
175 return outputContainer;
176}
177
178
179
1c5acb87 180//_______________________________________________________________
181void AliCaloPID::InitParameters()
182{
477d6cee 183 //Initialize the parameters of the PID.
184
2007809d 185 fEMCALPhotonWeight = 0.6 ;
186 fEMCALPi0Weight = 0.6 ;
187 fEMCALElectronWeight = 0.6 ;
188 fEMCALChargeWeight = 0.6 ;
189 fEMCALNeutralWeight = 0.6 ;
477d6cee 190
2007809d 191 fPHOSPhotonWeight = 0.6 ;
192 fPHOSPi0Weight = 0.6 ;
193 fPHOSElectronWeight = 0.6 ;
194 fPHOSChargeWeight = 0.6 ;
195 fPHOSNeutralWeight = 0.6 ;
477d6cee 196
197 //Formula to set the PID weight threshold for photon or pi0
a33b76ed 198 //fPHOSWeightFormula = kTRUE;
199 //if(fPHOSPhotonWeightFormula) delete fPHOSPhotonWeightFormula;
200 //if(fPHOSPi0WeightFormula) delete fPHOSPi0WeightFormula;
201 //fPHOSPhotonWeightFormula =
202 //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))");
203 //fPHOSPi0WeightFormula =
204 //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 205
5ae09196 206 fDispCut = 0.25;
477d6cee 207 fTOFCut = 5.e-9;
208 fDebug = -1;
bdd2a262 209
210 if(fRecalculateBayesian){
bdd2a262 211 if(fParticleFlux == kLow){
212 printf("AliCaloPID::Init() - SetLOWFluxParam\n");
213 fEMCALPIDUtils->SetLowFluxParam() ;
214 }
215 else if (fParticleFlux == kHigh){
216 printf("AliCaloPID::Init() - SetHIGHFluxParam\n");
217 fEMCALPIDUtils->SetHighFluxParam() ;
218 }
bdd2a262 219 }
1c5acb87 220}
221
222//_______________________________________________________________
223Int_t AliCaloPID::GetPdg(const TString calo, const Double_t * pid, const Float_t energy) const {
477d6cee 224 //Return most probable identity of the particle.
225
226 if(!pid){
227 printf("AliCaloPID::GetPdg() - pid pointer not initialized!!!\n");
228 abort();
229 }
230
15800db4 231 Float_t wPh = fPHOSPhotonWeight ;
477d6cee 232 Float_t wPi0 = fPHOSPi0Weight ;
15800db4 233 Float_t wE = fPHOSElectronWeight ;
234 Float_t wCh = fPHOSChargeWeight ;
235 Float_t wNe = fPHOSNeutralWeight ;
477d6cee 236
237
a33b76ed 238// if(calo == "PHOS" && fPHOSWeightFormula){
239// wPh = fPHOSPhotonWeightFormula->Eval(energy) ;
240// wPi0 = fPHOSPi0WeightFormula->Eval(energy);
241// }
477d6cee 242
243 if(calo == "EMCAL"){
244
245 wPh = fEMCALPhotonWeight ;
246 wPi0 = fEMCALPi0Weight ;
247 wE = fEMCALElectronWeight ;
248 wCh = fEMCALChargeWeight ;
249 wNe = fEMCALNeutralWeight ;
250
251 }
252
253 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 254 calo.Data(),pid[AliVCluster::kPhoton], pid[AliVCluster::kPi0],
255 pid[AliVCluster::kElectron], pid[AliVCluster::kEleCon],
256 pid[AliVCluster::kPion], pid[AliVCluster::kKaon], pid[AliVCluster::kProton],
257 pid[AliVCluster::kNeutron], pid[AliVCluster::kKaon0]);
477d6cee 258
259 Int_t pdg = kNeutralUnknown ;
c8fe2783 260 Float_t chargedHadronWeight = pid[AliVCluster::kProton]+pid[AliVCluster::kKaon]+
261 pid[AliVCluster::kPion]+pid[AliVCluster::kMuon];
262 Float_t neutralHadronWeight = pid[AliVCluster::kNeutron]+pid[AliVCluster::kKaon0];
263 Float_t allChargedWeight = pid[AliVCluster::kElectron]+pid[AliVCluster::kEleCon]+ chargedHadronWeight;
264 Float_t allNeutralWeight = pid[AliVCluster::kPhoton]+pid[AliVCluster::kPi0]+ neutralHadronWeight;
477d6cee 265
266 //Select most probable ID
267 if(calo=="PHOS"){
c8fe2783 268 if(pid[AliVCluster::kPhoton] > wPh) pdg = kPhoton ;
269 else if(pid[AliVCluster::kPi0] > wPi0) pdg = kPi0 ;
270 else if(pid[AliVCluster::kElectron] > wE) pdg = kElectron ;
271 else if(pid[AliVCluster::kEleCon] > wE) pdg = kEleCon ;
477d6cee 272 else if(chargedHadronWeight > wCh) pdg = kChargedHadron ;
273 else if(neutralHadronWeight > wNe) pdg = kNeutralHadron ;
274 else if(allChargedWeight > allNeutralWeight)
275 pdg = kChargedUnknown ;
276 else
277 pdg = kNeutralUnknown ;
278 }
279 else{//EMCAL
2007809d 280
281 if(pid[AliVCluster::kPhoton] > wPh) pdg = kPhoton ;
282 else if(pid[AliVCluster::kElectron] > wE) pdg = kElectron ;
283 else if(pid[AliVCluster::kPhoton]+pid[AliVCluster::kElectron] > wPh) pdg = kPhoton ; //temporal sollution until track matching for electrons is considered
284 else if(pid[AliVCluster::kPi0] > wPi0) pdg = kPi0 ;
477d6cee 285 else if(chargedHadronWeight + neutralHadronWeight > wCh) pdg = kChargedHadron ;
286 else if(neutralHadronWeight + chargedHadronWeight > wNe) pdg = kNeutralHadron ;
2007809d 287 else pdg = kNeutralUnknown ;
477d6cee 288 }
289
ebc881ec 290 if(fDebug > 0)printf("AliCaloPID::GetPdg:Final Pdg: %d, cluster energy %2.2f \n", pdg,energy);
477d6cee 291
292 return pdg ;
293
1c5acb87 294}
295
296//_______________________________________________________________
0ae57829 297Int_t AliCaloPID::GetPdg(const TString calo,const TLorentzVector mom, const AliVCluster * cluster) const {
477d6cee 298 //Recalculated PID with all parameters
bdd2a262 299 Float_t lambda0 = cluster->GetM02();
300 Float_t energy = mom.E();
301
302 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",
303 calo.Data(),energy,lambda0,cluster->GetM20(),cluster->GetDispersion(),cluster->GetTOF(),
c8fe2783 304 cluster->GetEmcCpvDistance(), cluster->GetDistanceToBadChannel(),cluster->GetNExMax());
bdd2a262 305
477d6cee 306 if(calo == "EMCAL") {
bdd2a262 307 //Recalculate Bayesian
308 if(fRecalculateBayesian){
bdd2a262 309 if(fDebug > 0) {
c8fe2783 310 const Double_t *pid0 = cluster->GetPID();
bdd2a262 311 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 312 calo.Data(),pid0[AliVCluster::kPhoton], pid0[AliVCluster::kPi0],
313 pid0[AliVCluster::kElectron], pid0[AliVCluster::kEleCon],
314 pid0[AliVCluster::kPion], pid0[AliVCluster::kKaon], pid0[AliVCluster::kProton],
315 pid0[AliVCluster::kNeutron], pid0[AliVCluster::kKaon0]);
bdd2a262 316 }
317
318 fEMCALPIDUtils->ComputePID(energy, lambda0);
319 Double_t pid[AliPID::kSPECIESN];
320 for(Int_t i = 0; i < AliPID::kSPECIESN; i++) pid[i] = fEMCALPIDUtils->GetPIDFinal(i);
321 return GetPdg(calo, pid, energy);
322
bdd2a262 323
324 }
325
c8fe2783 326 // If no use of bayesian, simple PID
327 if(lambda0 < 0.25) return kPhoton ;
328 //else return kNeutralHadron ;
329 else return kPi0 ;
477d6cee 330 }
331
332 // if(calo == "PHOS") {
333 // if(cluster->GetM02()< 0.25) return kPhoton ;
334 // else return kNeutralHadron ;
335 // }
336
337 return kNeutralHadron ;
338
1c5acb87 339}
340
341//__________________________________________________
342TString AliCaloPID::GetPIDParametersList() {
477d6cee 343 //Put data member values in string to keep in output container
344
345 TString parList ; //this will be list of parameters used for this analysis.
5ae09196 346 const Int_t buffersize = 255;
347 char onePar[buffersize] ;
348 snprintf(onePar,buffersize,"--- AliCaloPID ---\n") ;
477d6cee 349 parList+=onePar ;
5ae09196 350 snprintf(onePar,buffersize,"fDispCut =%2.2f (Cut on dispersion, used in PID evaluation) \n",fDispCut) ;
477d6cee 351 parList+=onePar ;
5ae09196 352 snprintf(onePar,buffersize,"fTOFCut =%e (Cut on TOF, used in PID evaluation) \n",fTOFCut) ;
477d6cee 353 parList+=onePar ;
5ae09196 354 snprintf(onePar,buffersize,"fEMCALPhotonWeight =%2.2f (EMCAL bayesian weight for photons)\n",fEMCALPhotonWeight) ;
477d6cee 355 parList+=onePar ;
5ae09196 356 snprintf(onePar,buffersize,"fEMCALPi0Weight =%2.2f (EMCAL bayesian weight for pi0)\n",fEMCALPi0Weight) ;
477d6cee 357 parList+=onePar ;
5ae09196 358 snprintf(onePar,buffersize,"fEMCALElectronWeight =%2.2f(EMCAL bayesian weight for electrons)\n",fEMCALElectronWeight) ;
477d6cee 359 parList+=onePar ;
5ae09196 360 snprintf(onePar,buffersize,"fEMCALChargeWeight =%2.2f (EMCAL bayesian weight for charged hadrons)\n",fEMCALChargeWeight) ;
477d6cee 361 parList+=onePar ;
5ae09196 362 snprintf(onePar,buffersize,"fEMCALNeutralWeight =%2.2f (EMCAL bayesian weight for neutral hadrons)\n",fEMCALNeutralWeight) ;
477d6cee 363 parList+=onePar ;
5ae09196 364 snprintf(onePar,buffersize,"fPHOSPhotonWeight =%2.2f (PHOS bayesian weight for photons)\n",fPHOSPhotonWeight) ;
477d6cee 365 parList+=onePar ;
5ae09196 366 snprintf(onePar,buffersize,"fPHOSPi0Weight =%2.2f (PHOS bayesian weight for pi0)\n",fPHOSPi0Weight) ;
477d6cee 367 parList+=onePar ;
5ae09196 368 snprintf(onePar,buffersize,"fPHOSElectronWeight =%2.2f(PHOS bayesian weight for electrons)\n",fPHOSElectronWeight) ;
477d6cee 369 parList+=onePar ;
5ae09196 370 snprintf(onePar,buffersize,"fPHOSChargeWeight =%2.2f (PHOS bayesian weight for charged hadrons)\n",fPHOSChargeWeight) ;
477d6cee 371 parList+=onePar ;
5ae09196 372 snprintf(onePar,buffersize,"fPHOSNeutralWeight =%2.2f (PHOS bayesian weight for neutral hadrons)\n",fPHOSNeutralWeight) ;
477d6cee 373 parList+=onePar ;
374
a33b76ed 375// if(fPHOSWeightFormula){
5ae09196 376// sprintf(onePar,buffersize,"PHOS Photon Weight Formula: %s\n",(fPHOSPhotonWeightFormula->GetExpFormula("p")).Data()) ;
a33b76ed 377// parList+=onePar;
5ae09196 378// sprintf(onePar,buffersize,"PHOS Pi0 Weight Formula: %s\n",(fPHOSPi0WeightFormula->GetExpFormula("p")).Data()) ;
a33b76ed 379// parList+=onePar;
380// }
477d6cee 381
382 return parList;
383
1c5acb87 384}
385
386//________________________________________________________________
387void AliCaloPID::Print(const Option_t * opt) const
388{
477d6cee 389
390 //Print some relevant parameters set for the analysis
391 if(! opt)
392 return;
393
394 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
395
396 printf("PHOS PID weight , photon %0.2f, pi0 %0.2f, e %0.2f, charge %0.2f, neutral %0.2f \n",
397 fPHOSPhotonWeight, fPHOSPi0Weight,
398 fPHOSElectronWeight, fPHOSChargeWeight, fPHOSNeutralWeight) ;
399 printf("EMCAL PID weight, photon %0.2f, pi0 %0.2f, e %0.2f, charge %0.2f, neutral %0.2f\n",
400 fEMCALPhotonWeight, fEMCALPi0Weight,
401 fEMCALElectronWeight, fEMCALChargeWeight, fEMCALNeutralWeight) ;
402
a33b76ed 403// printf("PHOS Parametrized weight on? = %d\n", fPHOSWeightFormula) ;
404// if(fPHOSWeightFormula){
405// printf("Photon weight formula = %s\n", (fPHOSPhotonWeightFormula->GetExpFormula("p")).Data());
406// printf("Pi0 weight formula = %s\n", (fPHOSPhotonWeightFormula->GetExpFormula("p")).Data());
407// }
477d6cee 408
409 printf("TOF cut = %e\n",fTOFCut);
410 printf("Dispersion cut = %2.2f\n",fDispCut);
411 printf("Debug level = %d\n",fDebug);
bdd2a262 412 printf("Recalculate Bayesian? = %d\n",fRecalculateBayesian);
413 if(fRecalculateBayesian) printf("Particle Flux? = %d\n",fParticleFlux);
477d6cee 414 printf(" \n");
415
1c5acb87 416}
417
418//_______________________________________________________________
f2ccb5b8 419void AliCaloPID::SetPIDBits(const TString calo, const AliVCluster * cluster, AliAODPWG4Particle * ph, const AliCalorimeterUtils* cu) {
477d6cee 420 //Set Bits for PID selection
421
422 //Dispersion/lambdas
5ae09196 423 //Double_t disp= cluster->GetDispersion() ;
424 Double_t l1 = cluster->GetM20() ;
425 Double_t l0 = cluster->GetM02() ;
426 Bool_t isDispOK = kTRUE ;
427 if(cluster->IsPHOS()){
428
429 if(l1>= 0 && l0>= 0 && l1 < 0.1 && l0 < 0.1) isDispOK=kFALSE ;
430 if(l1>= 0 && l0 > 0.5 && l1 < 0.1 && l0 < 1.5) isDispOK=kTRUE ;
431 if(l1>= 0 && l0 > 2.0 && l1 < 0.1 && l0 < 2.7) isDispOK=kFALSE ;
432 if(l1>= 0 && l0 > 2.7 && l1 < 0.1 && l0 < 4.0) isDispOK=kFALSE ;
433 if(l1 > 0.1 && l1 < 0.7 && l0 > 0.7 && l0 < 2.1) isDispOK=kTRUE ;
434 if(l1 > 0.1 && l1 < 0.3 && l0 > 3.0 && l0 < 5.0) isDispOK=kFALSE ;
435 if(l1 > 0.3 && l1 < 0.7 && l0 > 2.5 && l0 < 4.0) isDispOK=kFALSE ;
436 if(l1 > 0.7 && l1 < 1.3 && l0 > 1.0 && l0 < 1.6) isDispOK=kTRUE ;
437 if(l1 > 0.7 && l1 < 1.3 && l0 > 1.6 && l0 < 3.5) isDispOK=kTRUE ;
438 if(l1 > 1.3 && l1 < 3.5 && l0 > 1.3 && l0 < 3.5) isDispOK=kTRUE ;
439
440 }
441 else{//EMCAL
442
443 if(l0 > fDispCut || l0 < 0.) isDispOK = kFALSE;
444
445 }
446
447 ph->SetDispBit(isDispOK) ;
477d6cee 448
449 //TOF
450 Double_t tof=cluster->GetTOF() ;
451 ph->SetTOFBit(TMath::Abs(tof)<fTOFCut) ;
452
5ae09196 453 //Charged veto
454 //Bool_t isNeutral = kTRUE ;
455 //if(cluster->IsPHOS()) isNeutral = cluster->GetEmcCpvDistance() > 5. ;
456 //else
f2ccb5b8 457 Bool_t isNeutral = IsTrackMatched(cluster,cu);
5ae09196 458
459 ph->SetChargedBit(isNeutral);
477d6cee 460
461 //Set PID pdg
c8fe2783 462 ph->SetPdg(GetPdg(calo,cluster->GetPID(),ph->E()));
477d6cee 463
464 if(fDebug > 0){
5ae09196 465 printf("AliCaloPID::SetPIDBits: TOF %e, Lambda0 %2.2f, Lambda1 %2.2f\n",tof , l0, l1);
477d6cee 466 printf("AliCaloPID::SetPIDBits: pdg %d, bits: TOF %d, Dispersion %d, Charge %d\n",
6639984f 467 ph->GetPdg(), ph->GetTOFBit() , ph->GetDispBit() , ph->GetChargedBit());
477d6cee 468 }
1c5acb87 469}
470
5ae09196 471//__________________________________________________________________________
f2ccb5b8 472Bool_t AliCaloPID::IsTrackMatched(const AliVCluster* cluster, const AliCalorimeterUtils * cu) const {
5ae09196 473 //Check if there is any track attached to this cluster
474
475 Int_t nMatches = cluster->GetNTracksMatched();
d39cba7e 476// if(nMatches>0){
477// printf("N matches %d, first match (ESD) %d or (AOD) %d\n",nMatches,cluster->GetTrackMatchedIndex(), cluster->GetTrackMatched(0));
478// if (cluster->GetTrackMatched(0)) printf("\t matched track id %d\n",((AliVTrack*)cluster->GetTrackMatched(0)) ->GetID() ) ;
479// }
480// else {
481// printf("Not Matched");
482// }
483
484 //If EMCAL track matching needs to be recalculated
485 if(cluster->IsEMCAL() && cu && cu->IsRecalculationOfClusterTrackMatchingOn()){
486 Float_t dR = 999., dZ = 999.;
487 cu->GetEMCALRecoUtils()->GetMatchedResiduals(cluster->GetID(),dR,dZ);
488
489 if(dR < 999) {
490
491 fhTrackMatchedDEta->Fill(cluster->E(),dZ);
492 fhTrackMatchedDPhi->Fill(cluster->E(),dR);
493 if(cluster->E() > 0.5)fhTrackMatchedDEtaDPhi->Fill(dZ,dR);
494 //printf("dR %f, dZ %f \n",dR,dZ);
495 return kTRUE;
496 }
497 else
498 return kFALSE;
499 }//EMCAL cluster and recalculation of matching on
5ae09196 500
d39cba7e 501 fhTrackMatchedDEta->Fill(cluster->GetTrackDz(),cluster->E());
502 fhTrackMatchedDEta->Fill(cluster->GetTrackDx(),cluster->E());
503 if(cluster->E() > 0.5)fhTrackMatchedDEtaDPhi->Fill(cluster->GetTrackDz(),cluster->GetTrackDx());
5ae09196 504
f2ccb5b8 505
5ae09196 506 if(!strcmp("AliESDCaloCluster",Form("%s",cluster->ClassName())))
d39cba7e 507 {
5ae09196 508 if (nMatches > 0) {
509 if (nMatches == 1 ) {
510 Int_t iESDtrack = cluster->GetTrackMatchedIndex();
511 //printf("Track Matched index %d\n",iESDtrack);
512 if(iESDtrack==-1) return kFALSE ;// Default value of array, there is no match
513 else return kTRUE;
514 }//Just one, check
515 else return kTRUE ;//More than one, there is a match.
516 }// > 0
517 else return kFALSE; //It does not happen, but in case
518
519 }//ESDs
520 else
521 {
d39cba7e 522// //Patched AODs
523// if(cu && cu->IsRecalculationOfClusterTrackMatchingOn()){
524// Float_t dR = TMath::Abs(cluster->GetEmcCpvDistance()) ; //FIXME
525// if(dR > cu->GetCutR()) return kFALSE;
526// else return kTRUE;
527// }
528// else {
529// if(nMatches > 0) return kTRUE; //There is at least one match.
530// else return kFALSE;
531
532// }
533
534 if(nMatches > 0) return kTRUE; //There is at least one match.
535 else return kFALSE;
536
5ae09196 537 }//AODs or MC (copy into AOD)
538
539 return kFALSE;
540
541}
542
1c5acb87 543