CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DataFormats/ParticleFlowCandidate/src/PFCandidateElectronExtra.cc

Go to the documentation of this file.
00001 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateElectronExtra.h"
00002 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00003 #include <ostream>
00004 #include <iomanip>
00005 
00006 using namespace reco;
00007 
00008 PFCandidateElectronExtra::PFCandidateElectronExtra() {
00009   status_ = 0;  
00010   mvaStatus_ = 0;
00011   pout_ = math::XYZTLorentzVector(0.,0.,0.,0.);
00012   hadEnergy_ = -9999. ;
00013   sigmaEtaEta_ = -9999.;
00014 
00015   for(MvaVariable m=MVA_FIRST; m<MVA_LAST; m=MvaVariable(m+1))
00016     mvaVariables_.push_back(-9999.);
00017       
00018   gsfTrackRef_ = GsfTrackRef();
00019   kfTrackRef_ = TrackRef();
00020 }
00021 
00022 PFCandidateElectronExtra::PFCandidateElectronExtra(const reco::GsfTrackRef& gsfTrack) {
00023   status_ = 0;  
00024   mvaStatus_ = 0;
00025   pout_ = math::XYZTLorentzVector(0.,0.,0.,0.);
00026   hadEnergy_ = -9999. ;
00027   sigmaEtaEta_ = -9999.;
00028 
00029   for(MvaVariable m=MVA_FIRST; m<MVA_LAST; m=MvaVariable(m+1))
00030     mvaVariables_.push_back(-9999.);
00031       
00032   gsfTrackRef_ = gsfTrack;
00033   kfTrackRef_ = TrackRef();
00034   
00035   setVariable(MVA_LnPtGsf,log(gsfTrackRef_->ptMode()));
00036   setVariable(MVA_EtaGsf,gsfTrackRef_->etaMode());
00037   setVariable(MVA_Chi2Gsf,gsfTrackRef_->normalizedChi2());  
00038   float ptmodeerror=gsfTrackRef_->ptModeError() ;
00039   if(ptmodeerror>0.)
00040     setVariable(MVA_SigmaPtOverPt,ptmodeerror/gsfTrackRef_->ptMode());
00041   else
00042     setVariable(MVA_SigmaPtOverPt,-999.);
00043   
00044   setVariable(MVA_Fbrem,(gsfTrackRef_->ptMode() - pout_.pt())/gsfTrackRef_->ptMode());
00045 }
00046 
00047 void PFCandidateElectronExtra::setGsfTrackRef(const reco::GsfTrackRef& ref) {
00048   gsfTrackRef_= ref;
00049 }   
00050 
00051 void PFCandidateElectronExtra::setGsfTrackPout(const math::XYZTLorentzVector& pout) {
00052   pout_ = pout;
00053   
00054 }
00055 
00056 void PFCandidateElectronExtra::setKfTrackRef(const reco::TrackRef & ref){
00057   kfTrackRef_ = ref;
00058   float nhit_kf=0;
00059   float chi2_kf=-0.01;
00060   // if the reference is null, it does not mean that the variables have not been set
00061   if(kfTrackRef_.isNonnull()) {
00062     nhit_kf=(float)kfTrackRef_->hitPattern().trackerLayersWithMeasurement();
00063     chi2_kf=kfTrackRef_->normalizedChi2();
00064   }
00065   setVariable(MVA_NhitsKf,nhit_kf);
00066   setVariable(MVA_Chi2Kf,chi2_kf);
00067 }
00068 
00069 void PFCandidateElectronExtra::setLateBrem(float val) {
00070   lateBrem_ = val;
00071   setVariable(MVA_LateBrem,val);
00072 }
00073 
00074 void PFCandidateElectronExtra::setEarlyBrem(float val) {
00075   earlyBrem_ = val;
00076   setVariable(MVA_FirstBrem,val);
00077 }
00078 
00079 void PFCandidateElectronExtra::setHadEnergy(float val) {
00080   hadEnergy_ = val;
00081   if(clusterEnergies_.size()>0)
00082     setVariable(MVA_HOverHE,hadEnergy_/(hadEnergy_+clusterEnergies_[0]));
00083 }
00084 
00085 void PFCandidateElectronExtra::setSigmaEtaEta(float val) {
00086   sigmaEtaEta_ = val;
00087   setVariable(MVA_LogSigmaEtaEta,val);
00088 }
00089 
00090 void PFCandidateElectronExtra::setDeltaEta(float val) {
00091   deltaEta_ = val;
00092   setVariable(MVA_DeltaEtaTrackCluster,val);
00093 }
00094 
00095 
00096 void PFCandidateElectronExtra::setClusterEnergies(const std::vector<float>& energies){
00097   clusterEnergies_=energies;
00098 
00099   if(pout_.t()!=0.)
00100     setVariable(MVA_EseedOverPout,clusterEnergies_[0]/pout_.t());
00101  
00102   static float m_el2=0.00051*0.00051;
00103   float Ein_gsf =sqrt(gsfTrackRef_->pMode()*
00104                       gsfTrackRef_->pMode()+m_el2);
00105   
00106   float etot=0;
00107   unsigned size=clusterEnergies_.size();
00108   //  std::cout << " N clusters "  << size << std::endl;
00109   float ebrem=0.;
00110   for(unsigned ic=0;ic<size;++ic) {    
00111     etot+=clusterEnergies_[ic];
00112     if(ic>0)
00113       ebrem+=clusterEnergies_[ic];
00114   }
00115   setVariable(MVA_EtotOverPin,etot/Ein_gsf);
00116   setVariable(MVA_EbremOverDeltaP,ebrem/(Ein_gsf-pout_.t()));  
00117 
00118   // recompute - as in PFElectronAglo, the had energy is filled before the cluster energies
00119   if(hadEnergy_!=-9999.)
00120     setHadEnergy(hadEnergy_);
00121 
00122 }
00123 
00124 void PFCandidateElectronExtra::setMVA(float val) {
00125   setVariable(MVA_MVA,val);
00126 }
00127 
00128 void PFCandidateElectronExtra::setVariable(MvaVariable type,float val) {
00129   
00130   mvaVariables_[type]=val;
00131   mvaStatus_ |= (1 << (type)) ;    
00132 }
00133 
00134 
00135 void PFCandidateElectronExtra::setStatus(StatusFlag type,bool status){
00136   if(status)     {
00137     status_ |= (1 << type);
00138   }
00139   else     {
00140     status_ &= ~(1 <<type);
00141   }
00142 }
00143 
00144 bool PFCandidateElectronExtra::electronStatus(StatusFlag flag) const {
00145   return status_ & (1<<flag) ;
00146 }
00147 
00148 bool PFCandidateElectronExtra::mvaStatus(MvaVariable flag) const {
00149   return mvaStatus_ & (1<< (flag)) ;
00150 }
00151 
00152 float PFCandidateElectronExtra::mvaVariable(MvaVariable var) const {
00153   return (mvaStatus(var) ? mvaVariables_[var] : -9999. );
00154 }
00155 
00156 #include <string>
00157 
00158 std::ostream& reco::operator<<(std::ostream& out, 
00159                                const PFCandidateElectronExtra& extra ) { 
00160   if(!out) return out;
00161 
00162   static std::vector<std::string> listVar;
00163   if(listVar.size()==0) {
00164     listVar.push_back("LogPt");
00165     listVar.push_back("Eta");
00166     listVar.push_back("SigmaPtOverPt");
00167     listVar.push_back("fbrem");
00168     listVar.push_back("Chi2Gsf");
00169     listVar.push_back("NhitsKf");
00170     listVar.push_back("Chi2Kf");
00171     listVar.push_back("EtotOverPin");
00172     listVar.push_back("EseedOverPout");
00173     listVar.push_back("EbremOverDeltaP");
00174     listVar.push_back("DeltaEtaTrackCluster");
00175     listVar.push_back("LogSigmaEtaEta");
00176     listVar.push_back("H/(H+E)");
00177     listVar.push_back("LateBrem");
00178     listVar.push_back("FirstBrem");
00179     listVar.push_back("MVA");
00180   }
00181   out <<  std::setiosflags(std::ios::left)<<  std::setw(20) << "Variable index" << std::setw(20) << "Name"  << std::setw(10) << "Set(0/1)" << std::setw(8) << "value" << std::endl;  
00182   for(  PFCandidateElectronExtra::MvaVariable i=PFCandidateElectronExtra::MVA_FIRST;
00183         i<PFCandidateElectronExtra::MVA_LAST;i=PFCandidateElectronExtra::MvaVariable(i+1)) {
00184     out << std::setw(20)<< i <<  std::setw(20) << listVar[i] << std::setw(10) << extra.mvaStatus(i) << std::setw(8) << extra.mvaVariable(i) << std::endl;
00185   }
00186   
00187   return out;
00188 }