Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-25 05:52:12

0001 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
0002 #include "TopQuarkAnalysis/TopJetCombination/interface/TtFullLepHypothesis.h"
0003 
0004 /// default constructor
0005 TtFullLepHypothesis::TtFullLepHypothesis(const edm::ParameterSet& cfg)
0006     : elecsToken_(consumes<std::vector<pat::Electron> >(cfg.getParameter<edm::InputTag>("electrons"))),
0007       musToken_(consumes<std::vector<pat::Muon> >(cfg.getParameter<edm::InputTag>("muons"))),
0008       jetsToken_(consumes<std::vector<pat::Jet> >(cfg.getParameter<edm::InputTag>("jets"))),
0009       metsToken_(consumes<std::vector<pat::MET> >(cfg.getParameter<edm::InputTag>("mets"))) {
0010   getMatch_ = false;
0011   if (cfg.exists("match")) {
0012     getMatch_ = true;
0013     matchToken_ = consumes<std::vector<std::vector<int> > >(cfg.getParameter<edm::InputTag>("match"));
0014   }
0015   // if no other correction is given apply L3 (abs) correction
0016   jetCorrectionLevel_ = "abs";
0017   if (cfg.exists("jetCorrectionLevel")) {
0018     jetCorrectionLevel_ = cfg.getParameter<std::string>("jetCorrectionLevel");
0019   } else {  // if no other correction is given apply L3 (abs) correction
0020     jetCorrectionLevel_ = "abs";
0021   }
0022   produces<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >();
0023   produces<int>("Key");
0024 }
0025 
0026 /// produce the event hypothesis as CompositeCandidate and Key
0027 void TtFullLepHypothesis::produce(edm::Event& evt, const edm::EventSetup& setup) {
0028   edm::Handle<std::vector<pat::Electron> > elecs;
0029   evt.getByToken(elecsToken_, elecs);
0030 
0031   edm::Handle<std::vector<pat::Muon> > mus;
0032   evt.getByToken(musToken_, mus);
0033 
0034   edm::Handle<std::vector<pat::Jet> > jets;
0035   evt.getByToken(jetsToken_, jets);
0036 
0037   edm::Handle<std::vector<pat::MET> > mets;
0038   evt.getByToken(metsToken_, mets);
0039 
0040   std::vector<std::vector<int> > matchVec;
0041   if (getMatch_) {
0042     edm::Handle<std::vector<std::vector<int> > > matchHandle;
0043     evt.getByToken(matchToken_, matchHandle);
0044     ;
0045     matchVec = *matchHandle;
0046   } else {
0047     std::vector<int> dummyMatch;
0048     for (unsigned int i = 0; i < 4; ++i)
0049       dummyMatch.push_back(-1);
0050     matchVec.push_back(dummyMatch);
0051   }
0052 
0053   // declare unique_ptr for products
0054   std::unique_ptr<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > > pOut(
0055       new std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > >);
0056   std::unique_ptr<int> pKey(new int);
0057 
0058   // build and feed out key
0059   buildKey();
0060   *pKey = key();
0061   evt.put(std::move(pKey), "Key");
0062 
0063   // go through given vector of jet combinations
0064   unsigned int idMatch = 0;
0065   typedef std::vector<std::vector<int> >::iterator MatchVecIterator;
0066   for (MatchVecIterator match = matchVec.begin(); match != matchVec.end(); ++match) {
0067     // reset pointers
0068     resetCandidates();
0069     // build hypothesis
0070     buildHypo(evt, elecs, mus, jets, mets, *match, idMatch++);
0071     pOut->push_back(std::make_pair(hypo(), *match));
0072   }
0073   // feed out hyps and matches
0074   evt.put(std::move(pOut));
0075 }
0076 
0077 /// reset candidate pointers before hypo build process
0078 void TtFullLepHypothesis::resetCandidates() {
0079   lepton_.reset();
0080   leptonBar_.reset();
0081   b_.reset();
0082   bBar_.reset();
0083   neutrino_.reset();
0084   neutrinoBar_.reset();
0085   //met_        = 0;
0086 }
0087 
0088 /// return event hypothesis
0089 reco::CompositeCandidate TtFullLepHypothesis::hypo() {
0090   // check for sanity of the hypothesis
0091   if (!lepton_ || !leptonBar_ || !b_ || !bBar_) {
0092     return reco::CompositeCandidate();
0093   }
0094 
0095   if (key() == TtFullLeptonicEvent::kGenMatch && (!recNu || !recNuBar)) {
0096     edm::LogInfo("TtFullHypothesis") << "no neutrinos for gen match" << std::endl;
0097     return reco::CompositeCandidate();
0098   }
0099   if (key() == TtFullLeptonicEvent::kKinSolution && (!neutrino_ || !neutrinoBar_)) {
0100     edm::LogInfo("TtFullHypothesis") << "no neutrinos for kin solution" << std::endl;
0101     return reco::CompositeCandidate();
0102   }
0103 
0104   // setup transient references
0105   reco::CompositeCandidate hyp, Top, WPlus, TopBar, WMinus;
0106 
0107   AddFourMomenta addFourMomenta;
0108 
0109   // build up the top branch
0110   WPlus.addDaughter(std::move(leptonBar_), TtFullLepDaughter::LepBar);
0111   if (key() == TtFullLeptonicEvent::kKinSolution)
0112     WPlus.addDaughter(std::move(neutrino_), TtFullLepDaughter::Nu);
0113   else if (key() == TtFullLeptonicEvent::kGenMatch)
0114     WPlus.addDaughter(std::move(recNu), TtFullLepDaughter::Nu);
0115   addFourMomenta.set(WPlus);
0116   Top.addDaughter(WPlus, TtFullLepDaughter::WPlus);
0117   Top.addDaughter(std::move(b_), TtFullLepDaughter::B);
0118   addFourMomenta.set(Top);
0119 
0120   // build up the anti top branch
0121   WMinus.addDaughter(std::move(lepton_), TtFullLepDaughter::Lep);
0122   if (key() == TtFullLeptonicEvent::kKinSolution)
0123     WMinus.addDaughter(std::move(neutrinoBar_), TtFullLepDaughter::NuBar);
0124   else if (key() == TtFullLeptonicEvent::kGenMatch)
0125     WMinus.addDaughter(std::move(recNuBar), TtFullLepDaughter::NuBar);
0126   addFourMomenta.set(WMinus);
0127   TopBar.addDaughter(WMinus, TtFullLepDaughter::WMinus);
0128   TopBar.addDaughter(std::move(bBar_), TtFullLepDaughter::BBar);
0129   addFourMomenta.set(TopBar);
0130 
0131   // build ttbar hypothesis
0132   hyp.addDaughter(Top, TtFullLepDaughter::Top);
0133   hyp.addDaughter(TopBar, TtFullLepDaughter::TopBar);
0134   addFourMomenta.set(hyp);
0135 
0136   // the four momentum of the met is not added to the hypothesis
0137   // because it is allready included through the neutrinos
0138   //hyp.addDaughter(*met_, TtFullLepDaughter::Met);
0139   return hyp;
0140 }
0141 
0142 /// use one object in a jet collection to set a ShallowClonePtrCandidate with proper jet corrections
0143 std::unique_ptr<reco::ShallowClonePtrCandidate> TtFullLepHypothesis::makeCandidate(
0144     const edm::Handle<std::vector<pat::Jet> >& handle, const int& idx, const std::string& correctionLevel) {
0145   edm::Ptr<pat::Jet> ptr = edm::Ptr<pat::Jet>(handle, idx);
0146   return std::make_unique<reco::ShallowClonePtrCandidate>(
0147       ptr, ptr->charge(), ptr->correctedJet(jetCorrectionLevel_, "bottom").p4(), ptr->vertex());
0148 }