#include "TMath.h" #include "TRandom3.h" #include "PndHypAdvancedPidAlgo.h" #include "PndHypPidCand.h" #include #include "TROOT.h" //test ClassImp(PndHypAdvancedPidAlgo) //public void PndHypAdvancedPidAlgo::CalcLikelihood(PndHypPidCand* cand) { //computes pid likelihoods for pi, k, p, mu, e and stores them in the likelihood //map with the map key used as pdg id. This is basically done by integrating the //respective energy loss distribution within the chosen selector limits double weight[kNPidType]; double dE=0; double dx=0; fmomentum=0; for (int k=0;kGetHypHits(); k++) { dE+=cand->GetHypHitdE(k); dx+=cand->GetHypHitdx(k); fmomentum+=cand->GetHypHitMomentum(k); } if (dx>0) { fmomentum/=cand->GetHypHits(); fenergyloss=dE/dx; } else fmomentum=-1; // whateva CalcLikelihood(weight); cand->SetLikelihood(2212, weight[kProton]); cand->SetLikelihood(211, weight[kPion]); cand->SetLikelihood(321, weight[kKaon]); cand->SetLikelihood(13, weight[kMuon]); cand->SetLikelihood(11, weight[kElectron]); } void PndHypAdvancedPidAlgo::CalcLikelihood(PidType part, double momentum, PndHypPidCand* cand) { double weight[kNPidType]; CalcLikelihood(part, momentum, weight); cand->SetLikelihood(2212, weight[kProton]); cand->SetLikelihood(211, weight[kPion]); cand->SetLikelihood(321, weight[kKaon]); cand->SetLikelihood(13, weight[kMuon]); cand->SetLikelihood(11, weight[kElectron]); } //the following is a workaround interface for fastsim void PndHypAdvancedPidAlgo::CalcLikelihood(PidType part, double momentum, double* lh) { fmomentum=momentum; //Initialise random generator if not already done if (!frand) frand=new TRandom3(); //Build random energy loss fenergyloss = MeanEnergyLoss(part) + mpv(part) + frand->Landau(0, width1(part)) + frand->Gaus(0, width2(part)); std::cout<<" energy loss "<Landau(0, width1(part)) + frand->Gaus(0, width2(part))<=0 && fmomentum<=2.5) { for (PidType part=kElectron; part<=kProton;part=(PidType)(part+1)) lh[part]=LandauGaus(fenergyloss - MeanEnergyLoss(part) - mpv(part), width1(part), width2(part)); } else for (char part=kElectron;part<=kProton;part++) lh[part]=1; double sum=0; for (char part=kElectron;part<=kProton;part++) sum+=lh[part]; for (char part=kElectron;part<=kProton;part++) lh[part]/=sum; } double PndHypAdvancedPidAlgo::MeanEnergyLoss(PidType part) { //Calculate the lower boundary of the energy loss distribution. //[GeV] static float eb=0.14e-6; //[m/s] static float c=2.99792458e8; //[GeV/c**2] //static float Mass[kNPidType]={ 0.511e-3, 0.1058, 0.1396, 0.4937, 0.9383 }; float Mass[kNPidType]={ 0.511e-3, 0.1058, 0.1396, 0.4937, 0.9383 }; std::cout<<" meanloss mass"<< Mass[kProton]<<" "<=5*width2) { bb=5*width2; redo=false; } h += s16; } else bb = c1; } while (redo); return h; } } double PndHypAdvancedPidAlgo::mpv(PidType part) { double x=fmomentum; double x0=0; double x1=0; double c0=0; double c1=0; double d1=0; double a3=0; double a4=0; double a5=0; switch(part) { case kProton: x0 = 0.45; std::cout<<" proton "<=x1) return c0+c1*(x1-x0)+d1*(x-x1); if (x>=x0) return c0+c1*(x-x0); else return c0+c1*(x-x0)+pow(x0-x,3)*(a3+(x0-x)*(a4+(x0-x)*a5)); } double PndHypAdvancedPidAlgo::width1(PidType part) { double x=fmomentum; switch(part) { case kProton: if (x>=1.10) return +3.81174e-04+x*(-2.25108e-04+x*+5.45154e-05); else return -5.28145e-05+x*(+8.29883e-04+x*-5.35972e-04); break; case kKaon: if (x>=1.05) return +2.61134e-04+x*(-1.30818e-04+x*+3.44165e-05); else return +3.41858e-04+x*(-3.21115e-04+x*+1.37459e-04); break; case kPion: if (x>=1.00) return +1.88718e-04+x*(-6.38948e-05+x*+1.78590e-05); else return +1.82872e-04+x*(-1.28373e-04+x*+8.01459e-05); break; case kMuon: if (x>=1.20) return +1.06142e-04+x*(+3.68777e-05+x*-1.00190e-05); else return +1.89374e-04+x*(-1.46441e-04+x*+9.10813e-05); break; case kElectron: if (x>1.2) x=1.2; // electrons are constant for momentum > 1.2GeV return +1.27955e-04+x*(-3.15732e-06+x*+9.64736e-06); break; } } double PndHypAdvancedPidAlgo::width2(PidType part) { double x=fmomentum; switch(part) { case kProton: if (x>=1.10) return +6.41067e-04+x*(-3.82507e-04+x*+9.03732e-05); else return +6.40328e-04-3.21725e-04*x+3.17708e-05*pow(x,-3); break; case kKaon: if (x>=1.05) return +2.22504e-04+x*(-6.40051e-06+x*+2.14434e-06); else return +3.86684e-04-1.61873e-04*x+7.76586e-06*pow(x,-3); break; case kPion: if (x>=1.00) return +1.32999e-04+x*(+1.19714e-04+x*-3.53302e-05); else return +2.21603e-04-3.21357e-06*x+4.64793e-06*pow(x,-2); break; case kMuon: if (x>=1.20) return +7.84582e-05+x*(+1.88988e-04+x*-5.49637e-05); else return +1.67388e-04+5.67991e-05*x+3.42702e-06*pow(x,-2); break; case kElectron: if (x>1.2) x=1.2; // electrons are constant for momentum > 1.2GeV return +4.08849e-04-3.56548e-05*x+1.84825e-08*pow(x,-3); break; } } double PndHypAdvancedPidAlgo::fmomentum; double PndHypAdvancedPidAlgo::fenergyloss; TRandom3* PndHypAdvancedPidAlgo::frand=0;