CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TtFullLepHypGenMatch.cc
Go to the documentation of this file.
4 
6  : TtFullLepHypothesis(cfg), genEvtToken_(consumes<TtGenEvent>(edm::InputTag("genEvt"))) {}
7 
9 
11  const edm::Handle<std::vector<pat::Electron> >& elecs,
12  const edm::Handle<std::vector<pat::Muon> >& mus,
13  const edm::Handle<std::vector<pat::Jet> >& jets,
14  const edm::Handle<std::vector<pat::MET> >& mets,
15  std::vector<int>& match,
16  const unsigned int iComb) {
17  // -----------------------------------------------------
18  // add jets
19  // -----------------------------------------------------
20  for (unsigned idx = 0; idx < match.size(); ++idx) {
21  if (isValid(match[idx], jets)) {
22  switch (idx) {
24  setCandidate(jets, match[idx], b_, jetCorrectionLevel_);
25  break;
28  break;
29  }
30  }
31  }
32 
33  // -----------------------------------------------------
34  // add leptons
35  // -----------------------------------------------------
36  // get genEvent
38  evt.getByToken(genEvtToken_, genEvt);
39 
40  // push back fake indices if no leptons in genevent
41  if (!genEvt->isFullLeptonic() || !genEvt->lepton() || !genEvt->leptonBar()) {
42  match.push_back(-1);
43  match.push_back(-1);
44  match.push_back(-1);
45  match.push_back(-1);
46  } else if (genEvt->isFullLeptonic(WDecay::kElec, WDecay::kElec) && elecs->size() >= 2) {
47  //search indices for electrons
48  int iLepBar = findMatchingLepton(genEvt->leptonBar(), elecs);
49  setCandidate(elecs, iLepBar, leptonBar_);
50  match.push_back(iLepBar);
51  int iLep = findMatchingLepton(genEvt->lepton(), elecs);
52  setCandidate(elecs, iLep, lepton_);
53  match.push_back(iLep);
54 
55  // fake indices for muons
56  match.push_back(-1);
57  match.push_back(-1);
58  } else if (genEvt->isFullLeptonic(WDecay::kElec, WDecay::kMuon) && !elecs->empty() && !mus->empty()) {
59  if (genEvt->leptonBar()->isElectron()) {
60  // push back index for e+
61  int iLepBar = findMatchingLepton(genEvt->leptonBar(), elecs);
62  setCandidate(elecs, iLepBar, leptonBar_);
63  match.push_back(iLepBar);
64  // push back fake indices for e- and mu+
65  match.push_back(-1);
66  match.push_back(-1);
67  // push back index for mu-
68  int iLep = findMatchingLepton(genEvt->lepton(), mus);
69  setCandidate(mus, iLep, lepton_);
70  match.push_back(iLep);
71  } else {
72  // push back fake index for e+
73  match.push_back(-1);
74  // push back index for e-
75  int iLepBar = findMatchingLepton(genEvt->leptonBar(), mus);
76  setCandidate(mus, iLepBar, leptonBar_);
77  match.push_back(iLepBar);
78  // push back index for mu+
79  int iLep = findMatchingLepton(genEvt->lepton(), elecs);
80  setCandidate(elecs, iLep, lepton_);
81  match.push_back(iLep);
82  // push back fake index for mu-
83  match.push_back(-1);
84  }
85  } else if (genEvt->isFullLeptonic(WDecay::kMuon, WDecay::kMuon) && mus->size() >= 2) {
86  // fake indices for electrons
87  match.push_back(-1);
88  match.push_back(-1);
89 
90  //search indices for electrons
91  int iLepBar = findMatchingLepton(genEvt->leptonBar(), mus);
92  setCandidate(mus, iLepBar, leptonBar_);
93  match.push_back(iLepBar);
94  int iLep = findMatchingLepton(genEvt->lepton(), mus);
95  setCandidate(mus, iLep, lepton_);
96  match.push_back(iLep);
97  } else { //this 'else' should happen if at least one genlepton is a tau
98  match.push_back(-1);
99  match.push_back(-1);
100  match.push_back(-1);
101  match.push_back(-1);
102  }
103 
104  // -----------------------------------------------------
105  // add met and neutrinos
106  // -----------------------------------------------------
107  if (!mets->empty()) {
108  //setCandidate(mets, 0, met_);
109  buildMatchingNeutrinos(evt, mets);
110  }
111 }
112 
113 template <typename O>
115  const edm::Handle<std::vector<O> >& leps) {
116  int idx = -1;
117  double minDR = -1;
118  for (unsigned i = 0; i < leps->size(); ++i) {
119  double dR = deltaR(genLep->eta(), genLep->phi(), (*leps)[i].eta(), (*leps)[i].phi());
120  if (minDR < 0 || dR < minDR) {
121  minDR = dR;
122  idx = i;
123  }
124  }
125  return idx;
126 }
127 
128 void TtFullLepHypGenMatch::buildMatchingNeutrinos(edm::Event& evt, const edm::Handle<std::vector<pat::MET> >& mets) {
129  // get genEvent
131  evt.getByToken(genEvtToken_, genEvt);
132 
133  if (genEvt->isTtBar() && genEvt->isFullLeptonic() && genEvt->neutrino() && genEvt->neutrinoBar()) {
134  double momXNu = genEvt->neutrino()->px();
135  double momYNu = genEvt->neutrino()->py();
136  double momXNuBar = genEvt->neutrinoBar()->px();
137  double momYNuBar = genEvt->neutrinoBar()->py();
138 
139  double momXMet = mets->at(0).px();
140  double momYMet = mets->at(0).py();
141 
142  double momXNeutrino = 0.5 * (momXNu - momXNuBar + momXMet);
143  double momYNeutrino = 0.5 * (momYNu - momYNuBar + momYMet);
144  double momXNeutrinoBar = momXMet - momXNeutrino;
145  double momYNeutrinoBar = momYMet - momYNeutrino;
146 
147  math::XYZTLorentzVector recNuFM(
148  momXNeutrino, momYNeutrino, 0, sqrt(momXNeutrino * momXNeutrino + momYNeutrino * momYNeutrino));
149  recNu = new reco::LeafCandidate(0, recNuFM);
150 
151  math::XYZTLorentzVector recNuBarFM(momXNeutrinoBar,
152  momYNeutrinoBar,
153  0,
154  sqrt(momXNeutrinoBar * momXNeutrinoBar + momYNeutrinoBar * momYNeutrinoBar));
155  recNuBar = new reco::LeafCandidate(0, recNuBarFM);
156  }
157 }
reco::ShallowClonePtrCandidate * leptonBar_
tuple cfg
Definition: looper.py:296
reco::LeafCandidate * recNuBar
void setCandidate(const edm::Handle< C > &handle, const int &idx, reco::ShallowClonePtrCandidate *&clone)
use one object in a collection to set a ShallowClonePtrCandidate
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
reco::LeafCandidate * recNu
candidates needed for the genmatch hypothesis
void buildHypo(edm::Event &evt, const edm::Handle< std::vector< pat::Electron > > &elecs, const edm::Handle< std::vector< pat::Muon > > &mus, const edm::Handle< std::vector< pat::Jet > > &jets, const edm::Handle< std::vector< pat::MET > > &mets, std::vector< int > &match, const unsigned int iComb) override
build event hypothesis from the reco objects of a semi-leptonic event
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Class derived from the TopGenEvent for ttbar events.
Definition: TtGenEvent.h:18
T sqrt(T t)
Definition: SSEVec.h:19
vector< PseudoJet > jets
TtFullLepHypGenMatch(const edm::ParameterSet &)
void buildMatchingNeutrinos(edm::Event &, const edm::Handle< std::vector< pat::MET > > &)
edm::EDGetTokenT< TtGenEvent > genEvtToken_
reco::ShallowClonePtrCandidate * lepton_
int findMatchingLepton(const reco::GenParticle *, const edm::Handle< std::vector< O > > &)
reco::ShallowClonePtrCandidate * bBar_
std::string jetCorrectionLevel_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
reco::ShallowClonePtrCandidate * b_
double phi() const final
momentum azimuthal angle
genEvtToken_(mayConsume< TtGenEvent >(genEvt_))
bool isValid(const int &idx, const edm::Handle< std::vector< pat::Jet > > &jets)
check if index is in valid range of selected jets
double eta() const final
momentum pseudorapidity