CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/TopQuarkAnalysis/TopJetCombination/src/TtFullLepHypothesis.cc

Go to the documentation of this file.
00001 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
00002 #include "TopQuarkAnalysis/TopJetCombination/interface/TtFullLepHypothesis.h"
00003 
00005 TtFullLepHypothesis::TtFullLepHypothesis(const edm::ParameterSet& cfg):
00006   elecs_(cfg.getParameter<edm::InputTag>("electrons")),
00007   mus_  (cfg.getParameter<edm::InputTag>("muons")),
00008   jets_ (cfg.getParameter<edm::InputTag>("jets")),
00009   mets_ (cfg.getParameter<edm::InputTag>("mets")),
00010 
00011   lepton_(0), leptonBar_(0), b_(0), 
00012   bBar_(0), neutrino_(0), neutrinoBar_(0)
00013 {  
00014   getMatch_ = false;
00015   if( cfg.exists("match") ) {
00016     getMatch_ = true;
00017     match_ = cfg.getParameter<edm::InputTag>("match");
00018   }
00019   // if no other correction is given apply L3 (abs) correction
00020   jetCorrectionLevel_ = "abs";
00021   if( cfg.exists("jetCorrectionLevel") ) {
00022     jetCorrectionLevel_ = cfg.getParameter<std::string>("jetCorrectionLevel");
00023   }
00024   else{ // if no other correction is given apply L3 (abs) correction
00025     jetCorrectionLevel_ = "abs";
00026   }
00027   produces<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >();
00028   produces<int>("Key");
00029 }
00030 
00032 TtFullLepHypothesis::~TtFullLepHypothesis()
00033 {
00034   if( lepton_      ) delete lepton_;
00035   if( leptonBar_   ) delete leptonBar_;
00036   if( b_           ) delete b_;
00037   if( bBar_        ) delete bBar_;
00038   if( neutrino_    ) delete neutrino_;
00039   if( neutrinoBar_ ) delete neutrinoBar_;
00040   //if( met_         ) delete met_;
00041 }
00042 
00044 void
00045 TtFullLepHypothesis::produce(edm::Event& evt, const edm::EventSetup& setup)
00046 {
00047   edm::Handle<std::vector<pat::Electron> > elecs;
00048   evt.getByLabel(elecs_, elecs);
00049   
00050   edm::Handle<std::vector<pat::Muon> > mus;
00051   evt.getByLabel(mus_, mus);  
00052 
00053   edm::Handle<std::vector<pat::Jet> > jets;
00054   evt.getByLabel(jets_, jets);
00055 
00056   edm::Handle<std::vector<pat::MET> > mets;
00057   evt.getByLabel(mets_, mets);
00058 
00059   std::vector<std::vector<int> > matchVec;
00060   if( getMatch_ ) {
00061     edm::Handle<std::vector<std::vector<int> > > matchHandle;
00062     evt.getByLabel(match_, matchHandle);;  
00063     matchVec = *matchHandle;
00064   }
00065   else {
00066     std::vector<int> dummyMatch;
00067     for(unsigned int i = 0; i < 4; ++i) 
00068       dummyMatch.push_back( -1 );
00069     matchVec.push_back( dummyMatch );
00070   }
00071 
00072   // declare auto_ptr for products
00073   std::auto_ptr<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >
00074     pOut( new std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > );
00075   std::auto_ptr<int> pKey(new int);
00076   
00077   // build and feed out key
00078   buildKey();  
00079   *pKey=key();
00080   evt.put(pKey, "Key");
00081 
00082   // go through given vector of jet combinations
00083   unsigned int idMatch = 0;  
00084   typedef std::vector<std::vector<int> >::iterator MatchVecIterator;
00085   for(MatchVecIterator match = matchVec.begin(); match != matchVec.end(); ++match) {        
00086     // reset pointers
00087     resetCandidates();
00088     // build hypothesis
00089     buildHypo(evt, elecs, mus, jets, mets, *match, idMatch++);        
00090     pOut->push_back( std::make_pair(hypo(), *match) );    
00091   }
00092   // feed out hyps and matches
00093   evt.put(pOut);
00094 }
00095 
00097 void
00098 TtFullLepHypothesis::resetCandidates()
00099 {
00100   lepton_     = 0;
00101   leptonBar_  = 0;
00102   b_          = 0;
00103   bBar_       = 0;
00104   neutrino_   = 0;
00105   neutrinoBar_= 0;
00106   //met_        = 0;
00107 }
00108 
00110 reco::CompositeCandidate
00111 TtFullLepHypothesis::hypo()
00112 { 
00113   // check for sanity of the hypothesis  
00114   if( !lepton_ || !leptonBar_ || !b_ || !bBar_ ){
00115     return reco::CompositeCandidate();
00116   } 
00117        
00118   if( key()==TtFullLeptonicEvent::kGenMatch && (!recNu || !recNuBar) ){
00119     edm::LogWarning("TtFullHypothesis") << "no neutrinos for gen match" << std::endl; 
00120     return reco::CompositeCandidate();
00121   }  
00122   if( key()==TtFullLeptonicEvent::kKinSolution && (!neutrino_ || !neutrinoBar_) ){
00123     edm::LogWarning("TtFullHypothesis") << "no neutrinos for kin solution" << std::endl;  
00124     return reco::CompositeCandidate();    
00125   }
00126           
00127   // setup transient references
00128   reco::CompositeCandidate hyp, Top, WPlus, TopBar, WMinus;
00129 
00130   AddFourMomenta addFourMomenta; 
00131      
00132   // build up the top branch
00133   WPlus.addDaughter(*leptonBar_, TtFullLepDaughter::LepBar);
00134   if(key()==TtFullLeptonicEvent::kKinSolution)
00135     WPlus.addDaughter(*neutrino_, TtFullLepDaughter::Nu);  
00136   else if(key()==TtFullLeptonicEvent::kGenMatch)
00137     WPlus.addDaughter(*recNu, TtFullLepDaughter::Nu);     
00138   addFourMomenta.set(WPlus);
00139   Top.addDaughter(WPlus, TtFullLepDaughter::WPlus);
00140   Top.addDaughter(*b_,TtFullLepDaughter::B);
00141   addFourMomenta.set(Top);   
00142    
00143   // build up the anti top branch
00144   WMinus.addDaughter(*lepton_, TtFullLepDaughter::Lep); 
00145   if(key()==TtFullLeptonicEvent::kKinSolution)
00146     WMinus.addDaughter(*neutrinoBar_, TtFullLepDaughter::NuBar);  
00147   else if(key()==TtFullLeptonicEvent::kGenMatch)  
00148     WMinus.addDaughter(*recNuBar, TtFullLepDaughter::NuBar);   
00149   addFourMomenta.set(WMinus);
00150   TopBar.addDaughter(WMinus, TtFullLepDaughter::WMinus);
00151   TopBar.addDaughter(*bBar_, TtFullLepDaughter::BBar);
00152   addFourMomenta.set(TopBar);   
00153 
00154   // build ttbar hypothesis
00155   hyp.addDaughter(Top, TtFullLepDaughter::Top);
00156   hyp.addDaughter(TopBar, TtFullLepDaughter::TopBar);
00157   addFourMomenta.set( hyp );
00158      
00159   // the four momentum of the met is not added to the hypothesis
00160   // because it is allready included through the neutrinos     
00161   //hyp.addDaughter(*met_, TtFullLepDaughter::Met);
00162   return hyp;
00163 }
00164 
00166 void 
00167 TtFullLepHypothesis::setCandidate(const edm::Handle<std::vector<pat::Jet> >& handle, const int& idx, reco::ShallowClonePtrCandidate*& clone, const std::string& correctionLevel)
00168 {
00169   edm::Ptr<pat::Jet> ptr = edm::Ptr<pat::Jet>(handle, idx);
00170   clone = new reco::ShallowClonePtrCandidate( ptr, ptr->charge(), ptr->correctedJet(jetCorrectionLevel_, "bottom").p4(), ptr->vertex() );
00171 }