CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/TopQuarkAnalysis/TopJetCombination/plugins/TtSemiLepHypGenMatch.cc

Go to the documentation of this file.
00001 #include "DataFormats/Math/interface/deltaR.h"
00002 #include "AnalysisDataFormats/TopObjects/interface/TtGenEvent.h"
00003 #include "AnalysisDataFormats/TopObjects/interface/TtSemiLepEvtPartons.h"
00004 #include "TopQuarkAnalysis/TopJetCombination/plugins/TtSemiLepHypGenMatch.h"
00005 
00006 TtSemiLepHypGenMatch::TtSemiLepHypGenMatch(const edm::ParameterSet& cfg):
00007   TtSemiLepHypothesis( cfg ),
00008   neutrinoSolutionType_(cfg.getParameter<int>("neutrinoSolutionType"))
00009 { }
00010 
00011 TtSemiLepHypGenMatch::~TtSemiLepHypGenMatch() { }
00012 
00013 void
00014 TtSemiLepHypGenMatch::buildHypo(edm::Event& evt,
00015                                 const edm::Handle<edm::View<reco::RecoCandidate> >& leps, 
00016                                 const edm::Handle<std::vector<pat::MET> >& mets, 
00017                                 const edm::Handle<std::vector<pat::Jet> >& jets, 
00018                                 std::vector<int>& match, const unsigned int iComb)
00019 {
00020   // -----------------------------------------------------
00021   // get genEvent (to distinguish between uds and c quarks
00022   // and for the lepton matching)
00023   // -----------------------------------------------------
00024   edm::Handle<TtGenEvent> genEvt;
00025   evt.getByLabel("genEvt", genEvt);  
00026 
00027   // -----------------------------------------------------
00028   // add jets
00029   // -----------------------------------------------------
00030   for(unsigned idx=0; idx<match.size(); ++idx){
00031     if( isValid(match[idx], jets) ){
00032       switch(idx){
00033       case TtSemiLepEvtPartons::LightQ:
00034         if( std::abs(genEvt->hadronicDecayQuark()->pdgId())==4 )
00035           setCandidate(jets, match[idx], lightQ_, jetCorrectionLevel("cQuark"));
00036         else
00037           setCandidate(jets, match[idx], lightQ_, jetCorrectionLevel("udsQuark"));
00038         break;
00039       case TtSemiLepEvtPartons::LightQBar:
00040         if( std::abs(genEvt->hadronicDecayQuarkBar()->pdgId())==4 )
00041           setCandidate(jets, match[idx], lightQBar_, jetCorrectionLevel("cQuark"));
00042         else
00043           setCandidate(jets, match[idx], lightQBar_, jetCorrectionLevel("udsQuark"));
00044         break;
00045       case TtSemiLepEvtPartons::HadB:
00046         setCandidate(jets, match[idx], hadronicB_, jetCorrectionLevel("bQuark")); break;
00047       case TtSemiLepEvtPartons::LepB: 
00048         setCandidate(jets, match[idx], leptonicB_, jetCorrectionLevel("bQuark")); break;
00049       }
00050     }
00051   }
00052  
00053   // -----------------------------------------------------
00054   // add lepton
00055   // -----------------------------------------------------
00056   int iLepton = findMatchingLepton(genEvt, leps);
00057   if( iLepton<0 )
00058     return;
00059   setCandidate(leps, iLepton, lepton_);
00060   match.push_back( iLepton );
00061 
00062   // -----------------------------------------------------
00063   // add neutrino
00064   // -----------------------------------------------------
00065   if( mets->empty() )
00066     return;
00067   if(neutrinoSolutionType_ == -1)
00068     setCandidate(mets, 0, neutrino_);
00069   else
00070     setNeutrino(mets, leps, iLepton, neutrinoSolutionType_);
00071 }
00072 
00074 int
00075 TtSemiLepHypGenMatch::findMatchingLepton(const edm::Handle<TtGenEvent>& genEvt,
00076                                          const edm::Handle<edm::View<reco::RecoCandidate> >& leps)
00077 {
00078   int genIdx=-1;
00079 
00080   // jump out with -1 when the collection is empty
00081   if( leps->empty() ) return genIdx;
00082   
00083   if( genEvt->isTtBar() && genEvt->isSemiLeptonic( leptonType( &(leps->front()) ) ) && genEvt->singleLepton() ){
00084     double minDR=-1;
00085     for(unsigned i=0; i<leps->size(); ++i){
00086       double dR = deltaR(genEvt->singleLepton()->eta(), genEvt->singleLepton()->phi(), (*leps)[i].eta(), (*leps)[i].phi());
00087       if(minDR<0 || dR<minDR){
00088         minDR=dR;
00089         genIdx=i;
00090       }
00091     }
00092   }
00093   return genIdx;
00094 }