+// cout<<">>>>energy "<<en<<endl;
+// cout<<">>>>electron : x "<<x<<" xprob "<<elprobx<<" z "<<z<<" zprob "<<elprobz<<endl;
+// cout<<">>>>hadron : x "<<x<<" xprob "<<chprobx<<" z "<<z<<" zprob "<<chprobz<<endl;
+// cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
+
+ // Is neutral or charged?
+ if(pcpvelectron >= pcpvcharged)
+ pcpv = pcpvelectron ;
+ else
+ pcpv = pcpvcharged ;
+
+ if(pcpv < fChargedNeutralThreshold)
+ {
+ pcpvneutral = 1. ;
+ pcpvcharged = 0. ;
+ pcpvelectron = 0. ;
+ }
+ // else
+ // cout<<">>>>>>>>>>>CHARGED>>>>>>>>>>>"<<endl;
+
+ scpv[AliPID::kPion][index] = pcpvcharged ;
+ scpv[AliPID::kKaon][index] = pcpvcharged ;
+ scpv[AliPID::kProton][index] = pcpvcharged ;
+
+ scpv[AliPID::kMuon][index] = pcpvelectron ;
+ scpv[AliPID::kElectron][index] = pcpvelectron ;
+ scpv[AliPID::kEleCon][index] = pcpvelectron ;
+
+ scpv[AliPID::kPhoton][index] = pcpvneutral ;
+ scpv[AliPID::kNeutron][index] = pcpvneutral ;
+ scpv[AliPID::kKaon0][index] = pcpvneutral ;
+
+
+ // Info("MakePID", "CPV passed");
+
+ //############## Pi0 #############################
+ stof[AliPID::kPi0][index] = 0. ;
+ scpv[AliPID::kPi0][index] = 0. ;
+ sdp [AliPID::kPi0][index] = 0. ;
+
+ if(en > 30.){
+ // pi0 are detected via decay photon
+ stof[AliPID::kPi0][index] = stof[AliPID::kPhoton][index];
+ scpv[AliPID::kPi0][index] = pcpvneutral ;
+ if(emc->GetMultiplicity() > fDispMultThreshold)
+ sdp [AliPID::kPi0][index] = GausF(en , dispersion, fDpi0) ;
+ //sdp [AliPID::kPi0][index] = GausPol2(en , dispersion, fDpi0) ;
+// cout<<"E = "<<en<<" GeV; disp = "<<dispersion<<"; mult = "
+// <<emc->GetMultiplicity()<<endl;
+// cout<<"PDF: photon = "<<sdp [AliPID::kPhoton][index]<<"; pi0 = "
+// <<sdp [AliPID::kPi0][index]<<endl;
+ }
+
+
+
+
+ //############## muon #############################
+
+ if(en > 0.5){
+ //Muons deposit few energy
+ scpv[AliPID::kMuon][index] = 0 ;
+ stof[AliPID::kMuon][index] = 0 ;
+ sdp [AliPID::kMuon][index] = 0 ;
+ }
+
+ //Weight to apply to hadrons due to energy reconstruction
+
+ Float_t weight = fERecWeight ->Eval(en) ;
+
+ sw[AliPID::kPhoton][index] = 1. ;
+ sw[AliPID::kElectron][index] = 1. ;
+ sw[AliPID::kPion][index] = weight ;
+ sw[AliPID::kKaon][index] = weight ;
+ sw[AliPID::kProton][index] = weight ;
+ sw[AliPID::kNeutron][index] = weight ;
+ sw[AliPID::kEleCon][index] = 1. ;
+ sw[AliPID::kKaon0][index] = weight ;
+ sw[AliPID::kMuon][index] = weight ;
+ sw[AliPID::kPi0][index] = 1. ;
+
+// if(en > 0.5){
+// cout<<"######################################################"<<endl;
+// //cout<<"MakePID: energy "<<en<<", tof "<<time<<", distance "<<distance<<", dispersion "<<dispersion<<endl ;
+// cout<<"MakePID: energy "<<en<<", tof "<<time<<", dispersion "<<dispersion<<", x "<<x<<", z "<<z<<endl ;
+// cout<<">>>>>multiplicity "<<emc->GetMultiplicity()<<endl;
+// cout<<">>>>electron : xprob "<<elprobx<<" zprob "<<elprobz<<endl;
+// cout<<">>>>hadron : xprob "<<chprobx<<" zprob "<<chprobz<<endl;
+// cout<<">>>>electron : px*pz "<<pcpvelectron <<" hadron: px*pz "<<pcpvcharged<<endl;
+
+// cout<<"Photon , pid "<< fInitPID[AliPID::kPhoton]<<" tof "<<stof[AliPID::kPhoton][index]
+// <<", cpv "<<scpv[AliPID::kPhoton][index]<<", ss "<<sdp[AliPID::kPhoton][index]<<endl;
+// cout<<"EleCon , pid "<< fInitPID[AliPID::kEleCon]<<", tof "<<stof[AliPID::kEleCon][index]
+// <<", cpv "<<scpv[AliPID::kEleCon][index]<<" ss "<<sdp[AliPID::kEleCon][index]<<endl;
+// cout<<"Electron , pid "<< fInitPID[AliPID::kElectron]<<", tof "<<stof[AliPID::kElectron][index]
+// <<", cpv "<<scpv[AliPID::kElectron][index]<<" ss "<<sdp[AliPID::kElectron][index]<<endl;
+// cout<<"Muon , pid "<< fInitPID[AliPID::kMuon]<<", tof "<<stof[AliPID::kMuon][index]
+// <<", cpv "<<scpv[AliPID::kMuon][index]<<" ss "<<sdp[AliPID::kMuon][index]<<endl;
+// cout<<"Pi0 , pid "<< fInitPID[AliPID::kPi0]<<", tof "<<stof[AliPID::kPi0][index]
+// <<", cpv "<<scpv[AliPID::kPi0][index]<<" ss "<<sdp[AliPID::kPi0][index]<<endl;
+// cout<<"Pion , pid "<< fInitPID[AliPID::kPion]<<", tof "<<stof[AliPID::kPion][index]
+// <<", cpv "<<scpv[AliPID::kPion][index]<<" ss "<<sdp[AliPID::kPion][index]<<endl;
+// cout<<"Kaon0 , pid "<< fInitPID[AliPID::kKaon0]<<", tof "<<stof[AliPID::kKaon0][index]
+// <<", cpv "<<scpv[AliPID::kKaon0][index]<<" ss "<<sdp[AliPID::kKaon0][index]<<endl;
+// cout<<"Kaon , pid "<< fInitPID[AliPID::kKaon]<<", tof "<<stof[AliPID::kKaon][index]
+// <<", cpv "<<scpv[AliPID::kKaon][index]<<" ss "<<sdp[AliPID::kKaon][index]<<endl;
+// cout<<"Neutron , pid "<< fInitPID[AliPID::kNeutron]<<", tof "<<stof[AliPID::kNeutron][index]
+// <<", cpv "<<scpv[AliPID::kNeutron][index]<<" ss "<<sdp[AliPID::kNeutron][index]<<endl;
+// cout<<"Proton , pid "<< fInitPID[AliPID::kProton]<<", tof "<<stof[AliPID::kProton][index]
+// <<", cpv "<<scpv[AliPID::kProton][index]<<" ss "<<sdp[AliPID::kProton][index]<<endl;
+// cout<<"######################################################"<<endl;
+// }
+ index++;
+ }
+
+ //for (index = 0 ; index < kSPECIES ; index++)
+ // pid[index] /= nparticles ;
+
+
+ // Info("MakePID", "Total Probability calculation");
+
+ for(index = 0 ; index < nparticles ; index ++) {
+
+ AliPHOSRecParticle * recpar = gime->RecParticle(index) ;
+
+ //Conversion electron?
+
+ if(recpar->IsEleCon()){
+ fInitPID[AliPID::kEleCon] = 1. ;
+ fInitPID[AliPID::kPhoton] = 0. ;
+ fInitPID[AliPID::kElectron] = 0. ;
+ }
+ else{
+ fInitPID[AliPID::kEleCon] = 0. ;
+ fInitPID[AliPID::kPhoton] = 1. ;
+ fInitPID[AliPID::kElectron] = 1. ;
+ }
+ // fInitPID[AliPID::kEleCon] = 0. ;
+
+
+ // calculates the Bayesian weight
+
+ Int_t jndex ;
+ Double_t wn = 0.0 ;
+ for (jndex = 0 ; jndex < kSPECIES ; jndex++)
+ wn += stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
+ sw[jndex][index] * fInitPID[jndex] ;
+
+ // cout<<"*************wn "<<wn<<endl;
+ if (TMath::Abs(wn)>0)
+ for (jndex = 0 ; jndex < kSPECIES ; jndex++) {
+ //cout<<"jndex "<<jndex<<" wn "<<wn<<" SetPID * wn"
+ //<<stof[jndex][index] * sdp[jndex][index] * pid[jndex] << endl;
+ //cout<<" tof "<<stof[jndex][index] << " disp " <<sdp[jndex][index] << " pid "<< fInitPID[jndex] << endl;
+ // if(jndex == AliPID::kPi0 || jndex == AliPID::kPhoton){
+ // cout<<"Particle "<<jndex<<" final prob * wn "
+ // <<stof[jndex][index] * sdp[jndex][index] * scpv[jndex][index] *
+ // fInitPID[jndex] <<" wn "<< wn<<endl;
+ // cout<<"pid "<< fInitPID[jndex]<<", tof "<<stof[jndex][index]
+ // <<", cpv "<<scpv[jndex][index]<<" ss "<<sdp[jndex][index]<<endl;
+ // }
+ recpar->SetPID(jndex, stof[jndex][index] * sdp[jndex][index] *
+ sw[jndex][index] * scpv[jndex][index] *
+ fInitPID[jndex] / wn) ;
+ }
+ }
+ // Info("MakePID", "Delete");
+
+ for (Int_t i =0; i< kSPECIES; i++){
+ delete [] stof[i];
+ delete [] sdp [i];
+ delete [] scpv[i];
+ delete [] sw [i];
+ }
+ // Info("MakePID","End MakePID");