CMS 3D CMS Logo

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