CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/ParticleFlowCandidate/src/PFCandidateEGammaExtra.cc

Go to the documentation of this file.
00001 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateEGammaExtra.h"
00002 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00003 #include <ostream>
00004 #include <iomanip>
00005 
00006 using namespace reco;
00007 
00008 PFCandidateEGammaExtra::PFCandidateEGammaExtra() {
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 PFCandidateEGammaExtra::PFCandidateEGammaExtra(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 PFCandidateEGammaExtra::setGsfTrackRef(const reco::GsfTrackRef& ref) {
00048   gsfTrackRef_= ref;
00049 }   
00050 
00051 void PFCandidateEGammaExtra::setGsfTrackPout(const math::XYZTLorentzVector& pout) {
00052   pout_ = pout;
00053   
00054 }
00055 
00056 void PFCandidateEGammaExtra::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 PFCandidateEGammaExtra::setLateBrem(float val) {
00070   lateBrem_ = val;
00071   setVariable(MVA_LateBrem,val);
00072 }
00073 
00074 void PFCandidateEGammaExtra::setEarlyBrem(float val) {
00075   earlyBrem_ = val;
00076   setVariable(MVA_FirstBrem,val);
00077 }
00078 
00079 void PFCandidateEGammaExtra::setHadEnergy(float val) {
00080   hadEnergy_ = val;
00081   if(clusterEnergies_.size()>0)
00082     setVariable(MVA_HOverHE,hadEnergy_/(hadEnergy_+clusterEnergies_[0]));
00083 }
00084 
00085 void PFCandidateEGammaExtra::setSigmaEtaEta(float val) {
00086   sigmaEtaEta_ = val;
00087   setVariable(MVA_LogSigmaEtaEta,val);
00088 }
00089 
00090 void PFCandidateEGammaExtra::setDeltaEta(float val) {
00091   deltaEta_ = val;
00092   setVariable(MVA_DeltaEtaTrackCluster,val);
00093 }
00094 
00095 
00096 void PFCandidateEGammaExtra::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 PFCandidateEGammaExtra::setMVA(float val) {
00125   setVariable(MVA_MVA,val);
00126 }
00127 
00128 void PFCandidateEGammaExtra::setVariable(MvaVariable type,float val) {
00129   
00130   mvaVariables_[type]=val;
00131   mvaStatus_ |= (1 << (type)) ;    
00132 }
00133 
00134 
00135 void PFCandidateEGammaExtra::setStatus(StatusFlag type,bool status){
00136   if(status)     {
00137     status_ |= (1 << type);
00138   }
00139   else     {
00140     status_ &= ~(1 <<type);
00141   }
00142 }
00143 
00144 bool PFCandidateEGammaExtra::electronStatus(StatusFlag flag) const {
00145   return status_ & (1<<flag) ;
00146 }
00147 
00148 bool PFCandidateEGammaExtra::mvaStatus(MvaVariable flag) const {
00149   return mvaStatus_ & (1<< (flag)) ;
00150 }
00151 
00152 float PFCandidateEGammaExtra::mvaVariable(MvaVariable var) const {
00153   return (mvaStatus(var) ? mvaVariables_[var] : -9999. );
00154 }
00155 
00156 void PFCandidateEGammaExtra::addSingleLegConvTrackRef(const reco::TrackRef& trackref){
00157   assoSingleLegRefTrack_.push_back(trackref);
00158 }
00159 
00160 void PFCandidateEGammaExtra::addSingleLegConvMva(float& mvasingleleg){
00161   assoSingleLegMva_.push_back(mvasingleleg);
00162 }
00163 
00164 void PFCandidateEGammaExtra::addConversionRef(const reco::ConversionRef& convref){
00165   assoConversionsRef_.push_back(convref);
00166 }
00167 
00168 #include <string>
00169 
00170 std::ostream& reco::operator<<(std::ostream& out, 
00171                                const PFCandidateEGammaExtra& extra ) { 
00172   if(!out) return out;
00173 
00174   static std::vector<std::string> listVar;
00175   if(listVar.size()==0) {
00176     listVar.push_back("LogPt");
00177     listVar.push_back("Eta");
00178     listVar.push_back("SigmaPtOverPt");
00179     listVar.push_back("fbrem");
00180     listVar.push_back("Chi2Gsf");
00181     listVar.push_back("NhitsKf");
00182     listVar.push_back("Chi2Kf");
00183     listVar.push_back("EtotOverPin");
00184     listVar.push_back("EseedOverPout");
00185     listVar.push_back("EbremOverDeltaP");
00186     listVar.push_back("DeltaEtaTrackCluster");
00187     listVar.push_back("LogSigmaEtaEta");
00188     listVar.push_back("H/(H+E)");
00189     listVar.push_back("LateBrem");
00190     listVar.push_back("FirstBrem");
00191     listVar.push_back("MVA");
00192   }
00193   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;  
00194   for(  PFCandidateEGammaExtra::MvaVariable i=PFCandidateEGammaExtra::MVA_FIRST;
00195         i<PFCandidateEGammaExtra::MVA_LAST;i=PFCandidateEGammaExtra::MvaVariable(i+1)) {
00196     out << std::setw(20)<< i <<  std::setw(20) << listVar[i] << std::setw(10) << extra.mvaStatus(i) << std::setw(8) << extra.mvaVariable(i) << std::endl;
00197   }
00198   
00199   return out;
00200 }