1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 $ */
17 //_________________________________________________________________________
18 // Class for track/cluster acceptance selection
19 // Selection in Central barrel, EMCAL and PHOS
21 //*-- Author: Gustavo Conesa (LNF-INFN)
22 //////////////////////////////////////////////////////////////////////////////
25 // --- ROOT system ---
27 #include <TLorentzVector.h>
31 //---- ANALYSIS system ----
33 #include "AliCaloPID.h"
34 #include "AliAODCaloCluster.h"
35 #include "AliAODPWG4Particle.h"
37 #include "TParticle.h"
42 //________________________________________________
43 AliCaloPID::AliCaloPID() :
44 TObject(), fEMCALPhotonWeight(0.), fEMCALPi0Weight(0.),
45 fEMCALElectronWeight(0.), fEMCALChargeWeight(0.),
46 fEMCALNeutralWeight(0.),
47 fPHOSPhotonWeight(0.), fPHOSPi0Weight(0.),
48 fPHOSElectronWeight(0.), fPHOSChargeWeight(0.) ,
49 fPHOSNeutralWeight(0.), fPHOSWeightFormula(0),
50 fPHOSPhotonWeightFormula(0x0), fPHOSPi0WeightFormula(0x0),
51 fDispCut(0.),fTOFCut(0.), fDebug(-1), fMCGenerator("")
55 //Initialize parameters
59 //____________________________________________________________________________
60 AliCaloPID::AliCaloPID(const AliCaloPID & pid) :
61 TObject(pid), fEMCALPhotonWeight(pid.fEMCALPhotonWeight),
62 fEMCALPi0Weight(pid.fEMCALPi0Weight),
63 fEMCALElectronWeight(pid.fEMCALElectronWeight),
64 fEMCALChargeWeight(pid.fEMCALChargeWeight),
65 fEMCALNeutralWeight(pid.fEMCALNeutralWeight),
66 fPHOSPhotonWeight(pid.fPHOSPhotonWeight),
67 fPHOSPi0Weight(pid.fPHOSPi0Weight),
68 fPHOSElectronWeight(pid.fPHOSElectronWeight),
69 fPHOSChargeWeight(pid.fPHOSChargeWeight),
70 fPHOSNeutralWeight(pid.fPHOSNeutralWeight),
71 fPHOSWeightFormula(pid.fPHOSWeightFormula),
72 fPHOSPhotonWeightFormula(pid.fPHOSPhotonWeightFormula),
73 fPHOSPi0WeightFormula(pid.fPHOSPi0WeightFormula),
74 fDispCut(pid.fDispCut),fTOFCut(pid.fTOFCut),
75 fDebug(pid.fDebug),fMCGenerator(pid.fMCGenerator)
81 //_________________________________________________________________________
82 AliCaloPID & AliCaloPID::operator = (const AliCaloPID & pid)
84 // assignment operator
86 if(&pid == this) return *this;
88 fEMCALPhotonWeight = pid. fEMCALPhotonWeight ;
89 fEMCALPi0Weight = pid.fEMCALPi0Weight ;
90 fEMCALElectronWeight = pid.fEMCALElectronWeight;
91 fEMCALChargeWeight = pid.fEMCALChargeWeight;
92 fEMCALNeutralWeight = pid.fEMCALNeutralWeight;
94 fPHOSPhotonWeight = pid.fPHOSPhotonWeight ;
95 fPHOSPi0Weight = pid.fPHOSPi0Weight ;
96 fPHOSElectronWeight = pid.fPHOSElectronWeight;
97 fPHOSChargeWeight = pid.fPHOSChargeWeight;
98 fPHOSNeutralWeight = pid.fPHOSNeutralWeight;
100 fPHOSWeightFormula = pid.fPHOSWeightFormula;
101 fPHOSPhotonWeightFormula = pid.fPHOSPhotonWeightFormula;
102 fPHOSPi0WeightFormula = pid.fPHOSPi0WeightFormula;
104 fDispCut = pid.fDispCut;
105 fTOFCut = pid.fTOFCut;
107 fMCGenerator = pid.fMCGenerator;
113 //_________________________________
114 AliCaloPID::~AliCaloPID() {
117 if(fPHOSPhotonWeightFormula) delete fPHOSPhotonWeightFormula ;
118 if(fPHOSPi0WeightFormula) delete fPHOSPi0WeightFormula ;
123 //_________________________________________________________________________
124 Int_t AliCaloPID::CheckOrigin(const Int_t label, AliStack * stack) const {
125 //Play with the MC stack if available
126 //Check origin of the candidates, good for PYTHIA
128 if(!stack) AliFatal("Stack is not available, check analysis settings in configuration file, STOP!!");
130 if(label >= 0 && label < stack->GetNtrack()){
132 TParticle * mom = stack->Particle(label);
133 Int_t mPdg = TMath::Abs(mom->GetPdgCode());
134 Int_t mStatus = mom->GetStatusCode() ;
135 Int_t iParent = mom->GetFirstMother() ;
136 if(fDebug > 0 && label < 8 ) printf("AliCaloPID::CheckOrigin: Mother is parton %d\n",iParent);
139 TParticle * parent = new TParticle ;
143 parent = stack->Particle(iParent);
144 pPdg = TMath::Abs(parent->GetPdgCode());
145 pStatus = parent->GetStatusCode();
147 else if(fDebug > 0 ) printf("AliCaloPID::CheckOrigin: Parent with label %d\n",iParent);
152 if(fMCGenerator == "PYTHIA"){
153 if(iParent < 8 && iParent > 5) {//outgoing partons
154 if(pPdg == 22) return kMCPrompt;
155 else return kMCFragmentation;
157 else if(pStatus == 11){//Decay
158 if(pPdg == 111) return kMCPi0Decay ;
159 else if (pPdg == 321) return kMCEtaDecay ;
160 else return kMCOtherDecay ;
162 else return kMCISR; //Initial state radiation
165 else if(fMCGenerator == "HERWIG"){
166 if(pStatus < 197){//Not decay
168 if(parent->GetFirstMother()<=5) break;
169 iParent = parent->GetFirstMother();
170 parent=stack->Particle(iParent);
171 pStatus= parent->GetStatusCode();
172 pPdg = parent->GetPdgCode();
173 }//Look for the parton
175 if(iParent < 8 && iParent > 5) {
176 if(pPdg == 22) return kMCPrompt;
177 else return kMCFragmentation;
179 return kMCISR;//Initial state radiation
182 if(pPdg == 111) return kMCPi0Decay ;
183 else if (pPdg == 321) return kMCEtaDecay ;
184 else return kMCOtherDecay ;
187 else return kMCUnknown;
188 }//Status 1 : Pythia generated
189 else if(mStatus == 0){
190 if(pPdg ==22 || pPdg ==11) return kMCConversion ;
191 if(pPdg == 111) return kMCPi0Decay ;
192 else if (pPdg == 221) return kMCEtaDecay ;
193 else return kMCOtherDecay ;
194 }//status 0 : geant generated
196 else if(mPdg == 111) return kMCPi0 ;
197 else if(mPdg == 221) return kMCEta ;
199 printf("Origin electron, pT %f\n",mom->Pt());
201 if(mStatus == 0) return kMCConversion ;
202 else return kMCElectron ;
204 else return kMCUnknown;
207 if(label < 0 ) printf("AliCaloPID::CheckOrigin: *** bad label or no stack ***: label %d \n", label);
208 if(label >= stack->GetNtrack()) printf("AliCaloPID::CheckOrigin: *** large label ***: label %d, n tracks %d \n", label, stack->GetNtrack());
216 //_______________________________________________________________
217 void AliCaloPID::InitParameters()
219 //Initialize the parameters of the PID.
221 fEMCALPhotonWeight = 0.8 ;
222 fEMCALPi0Weight = 0.5 ;
223 fEMCALElectronWeight = 0.8 ;
224 fEMCALChargeWeight = 0.5 ;
225 fEMCALNeutralWeight = 0.5 ;
227 fPHOSPhotonWeight = 0.75 ;
228 fPHOSPi0Weight = 0.8 ;
229 fPHOSElectronWeight = 0.5 ;
230 fPHOSChargeWeight = 0.5 ;
231 fPHOSNeutralWeight = 0.5 ;
233 //Formula to set the PID weight threshold for photon or pi0
234 fPHOSWeightFormula = kTRUE;
235 fPHOSPhotonWeightFormula =
236 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))");
237 fPHOSPi0WeightFormula =
238 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))");
243 fMCGenerator = "PYTHIA";
246 //_______________________________________________________________
247 Int_t AliCaloPID::GetPdg(const TString calo, const Double_t * pid, const Float_t energy) const {
248 //Return most probable identity of the particle.
250 if(!pid) AliFatal("pid pointer not initialized!!!");
252 Float_t wPh = fPHOSPhotonWeight ;
253 Float_t wPi0 = fPHOSPi0Weight ;
254 Float_t wE = fPHOSElectronWeight ;
255 Float_t wCh = fPHOSChargeWeight ;
256 Float_t wNe = fPHOSNeutralWeight ;
259 if(calo == "PHOS" && fPHOSWeightFormula){
260 wPh = fPHOSPhotonWeightFormula->Eval(energy) ;
261 wPi0 = fPHOSPi0WeightFormula->Eval(energy);
266 wPh = fEMCALPhotonWeight ;
267 wPi0 = fEMCALPi0Weight ;
268 wE = fEMCALElectronWeight ;
269 wCh = fEMCALChargeWeight ;
270 wNe = fEMCALNeutralWeight ;
274 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",
275 calo.Data(),pid[AliAODCluster::kPhoton], pid[AliAODCluster::kPi0],
276 pid[AliAODCluster::kElectron], pid[AliAODCluster::kEleCon],
277 pid[AliAODCluster::kPion], pid[AliAODCluster::kKaon], pid[AliAODCluster::kProton],
278 pid[AliAODCluster::kNeutron], pid[AliAODCluster::kKaon0]);
280 Int_t pdg = kNeutralUnknown ;
281 Float_t chargedHadronWeight = pid[AliAODCluster::kProton]+pid[AliAODCluster::kKaon]+
282 pid[AliAODCluster::kPion]+pid[AliAODCluster::kMuon];
283 Float_t neutralHadronWeight = pid[AliAODCluster::kNeutron]+pid[AliAODCluster::kKaon0];
284 Float_t allChargedWeight = pid[AliAODCluster::kElectron]+pid[AliAODCluster::kEleCon]+ chargedHadronWeight;
285 Float_t allNeutralWeight = pid[AliAODCluster::kPhoton]+pid[AliAODCluster::kPi0]+ neutralHadronWeight;
287 //Select most probable ID
289 if(pid[AliAODCluster::kPhoton] > wPh) pdg = kPhoton ;
290 else if(pid[AliAODCluster::kPi0] > wPi0) pdg = kPi0 ;
291 else if(pid[AliAODCluster::kElectron] > wE) pdg = kElectron ;
292 else if(pid[AliAODCluster::kEleCon] > wE) pdg = kEleCon ;
293 else if(chargedHadronWeight > wCh) pdg = kChargedHadron ;
294 else if(neutralHadronWeight > wNe) pdg = kNeutralHadron ;
295 else if(allChargedWeight > allNeutralWeight)
296 pdg = kChargedUnknown ;
298 pdg = kNeutralUnknown ;
301 if(pid[AliAODCluster::kPhoton] > wPh) pdg = kPhoton ;
302 else if(pid[AliAODCluster::kPi0] > wPi0) pdg = kPi0 ;
303 else if(pid[AliAODCluster::kElectron] > wE) pdg = kElectron ;
304 else if(chargedHadronWeight + neutralHadronWeight > wCh) pdg = kChargedHadron ;
305 else if(neutralHadronWeight + chargedHadronWeight > wNe) pdg = kNeutralHadron ;
306 else pdg = kNeutralUnknown ;
311 if(fDebug > 0)printf("AliCaloPID::GetPdg:Final Pdg: %d \n", pdg);
319 //_______________________________________________________________
320 Int_t AliCaloPID::GetPdg(const TString calo,const TLorentzVector mom, const AliAODCaloCluster * cluster) const {
321 //Recalculated PID with all parameters
322 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",
323 calo.Data(),mom.E(),cluster->GetM02(),cluster->GetM20(),cluster->GetDispersion(),cluster->GetTOF(),
324 cluster->GetEmcCpvDistance(), cluster->GetDistToBadChannel(),cluster->GetNExMax());
326 if(calo == "EMCAL") {
327 if(cluster->GetM02()< 0.25) return kPhoton ;
328 else return kNeutralHadron ;
331 // if(calo == "PHOS") {
332 // if(cluster->GetM02()< 0.25) return kPhoton ;
333 // else return kNeutralHadron ;
336 return kNeutralHadron ;
340 //__________________________________________________
341 TString AliCaloPID::GetPIDParametersList() {
342 //Put data member values in string to keep in output container
344 TString parList ; //this will be list of parameters used for this analysis.
346 sprintf(onePar,"--- AliCaloPID ---\n") ;
348 sprintf(onePar,"fDispCut =%2.2f (Cut on dispersion, used in PID evaluation) \n",fDispCut) ;
350 sprintf(onePar,"fTOFCut =%e (Cut on TOF, used in PID evaluation) \n",fTOFCut) ;
352 sprintf(onePar,"fEMCALPhotonWeight =%2.2f (EMCAL bayesian weight for photons)\n",fEMCALPhotonWeight) ;
354 sprintf(onePar,"fEMCALPi0Weight =%2.2f (EMCAL bayesian weight for pi0)\n",fEMCALPi0Weight) ;
356 sprintf(onePar,"fEMCALElectronWeight =%2.2f(EMCAL bayesian weight for electrons)\n",fEMCALElectronWeight) ;
358 sprintf(onePar,"fEMCALChargeWeight =%2.2f (EMCAL bayesian weight for charged hadrons)\n",fEMCALChargeWeight) ;
360 sprintf(onePar,"fEMCALNeutralWeight =%2.2f (EMCAL bayesian weight for neutral hadrons)\n",fEMCALNeutralWeight) ;
362 sprintf(onePar,"fPHOSPhotonWeight =%2.2f (PHOS bayesian weight for photons)\n",fPHOSPhotonWeight) ;
364 sprintf(onePar,"fPHOSPi0Weight =%2.2f (PHOS bayesian weight for pi0)\n",fPHOSPi0Weight) ;
366 sprintf(onePar,"fPHOSElectronWeight =%2.2f(PHOS bayesian weight for electrons)\n",fPHOSElectronWeight) ;
368 sprintf(onePar,"fPHOSChargeWeight =%2.2f (PHOS bayesian weight for charged hadrons)\n",fPHOSChargeWeight) ;
370 sprintf(onePar,"fPHOSNeutralWeight =%2.2f (PHOS bayesian weight for neutral hadrons)\n",fPHOSNeutralWeight) ;
373 if(fPHOSWeightFormula){
374 parList+="PHOS Photon Weight Formula: "+(fPHOSPhotonWeightFormula->GetExpFormula("p"));
375 parList+="PHOS Pi0 Weight Formula: "+(fPHOSPi0WeightFormula->GetExpFormula("p"));
382 //________________________________________________________________
383 void AliCaloPID::Print(const Option_t * opt) const
386 //Print some relevant parameters set for the analysis
390 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
392 printf("PHOS PID weight , photon %0.2f, pi0 %0.2f, e %0.2f, charge %0.2f, neutral %0.2f \n",
393 fPHOSPhotonWeight, fPHOSPi0Weight,
394 fPHOSElectronWeight, fPHOSChargeWeight, fPHOSNeutralWeight) ;
395 printf("EMCAL PID weight, photon %0.2f, pi0 %0.2f, e %0.2f, charge %0.2f, neutral %0.2f\n",
396 fEMCALPhotonWeight, fEMCALPi0Weight,
397 fEMCALElectronWeight, fEMCALChargeWeight, fEMCALNeutralWeight) ;
399 printf("PHOS Parametrized weight on? = %d\n", fPHOSWeightFormula) ;
400 if(fPHOSWeightFormula){
401 printf("Photon weight formula = %s\n", (fPHOSPhotonWeightFormula->GetExpFormula("p")).Data());
402 printf("Pi0 weight formula = %s\n", (fPHOSPhotonWeightFormula->GetExpFormula("p")).Data());
405 printf("TOF cut = %e\n",fTOFCut);
406 printf("Dispersion cut = %2.2f\n",fDispCut);
407 printf("Debug level = %d\n",fDebug);
408 printf("MC Generator = %s\n",fMCGenerator.Data());
414 //_______________________________________________________________
415 void AliCaloPID::SetPIDBits(const TString calo, const AliAODCaloCluster * cluster, AliAODPWG4Particle * ph) {
416 //Set Bits for PID selection
419 Double_t disp=cluster->GetDispersion() ;
420 // Double_t m20=calo->GetM20() ;
421 // Double_t m02=calo->GetM02() ;
422 ph->SetDispBit(disp<fDispCut) ;
425 Double_t tof=cluster->GetTOF() ;
426 ph->SetTOFBit(TMath::Abs(tof)<fTOFCut) ;
429 // Double_t cpvR=calo->GetEmcCpvDistance() ;
430 Int_t ntr=cluster->GetNTracksMatched(); //number of track matched
431 ph->SetChargedBit(ntr>0) ; //Temporary cut, should we evaluate distance?
434 ph->SetPdg(GetPdg(calo,cluster->PID(),ph->E()));
437 printf("AliCaloPID::SetPIDBits: TOF %e, Dispersion %2.2f, NTracks %d\n",tof , disp, ntr);
438 printf("AliCaloPID::SetPIDBits: pdg %d, bits: TOF %d, Dispersion %d, Charge %d\n",
439 ph->GetPdg(), ph->GetTOFBit() , ph->GetDispBit() , ph->GetChargedBit());