CMS 3D CMS Logo

TtFullLepHypGenMatch.cc
Go to the documentation of this file.
2 
6 
8 public:
10 
11 private:
15  void buildHypo(edm::Event& evt,
16  const edm::Handle<std::vector<pat::Electron> >& elecs,
17  const edm::Handle<std::vector<pat::Muon> >& mus,
18  const edm::Handle<std::vector<pat::Jet> >& jets,
19  const edm::Handle<std::vector<pat::MET> >& mets,
20  std::vector<int>& match,
21  const unsigned int iComb) override;
22 
23  template <typename O>
24  int findMatchingLepton(const reco::GenParticle*, const edm::Handle<std::vector<O> >&);
25  void buildMatchingNeutrinos(edm::Event&, const edm::Handle<std::vector<pat::MET> >&);
26 
27 protected:
29 };
30 
32  : TtFullLepHypothesis(cfg), genEvtToken_(consumes<TtGenEvent>(edm::InputTag("genEvt"))) {}
33 
35  const edm::Handle<std::vector<pat::Electron> >& elecs,
36  const edm::Handle<std::vector<pat::Muon> >& mus,
37  const edm::Handle<std::vector<pat::Jet> >& jets,
38  const edm::Handle<std::vector<pat::MET> >& mets,
39  std::vector<int>& match,
40  const unsigned int iComb) {
41  // -----------------------------------------------------
42  // add jets
43  // -----------------------------------------------------
44  for (unsigned idx = 0; idx < match.size(); ++idx) {
45  if (isValid(match[idx], jets)) {
46  switch (idx) {
49  break;
52  break;
53  }
54  }
55  }
56 
57  // -----------------------------------------------------
58  // add leptons
59  // -----------------------------------------------------
60  // get genEvent
63 
64  // push back fake indices if no leptons in genevent
65  if (!genEvt->isFullLeptonic() || !genEvt->lepton() || !genEvt->leptonBar()) {
66  match.push_back(-1);
67  match.push_back(-1);
68  match.push_back(-1);
69  match.push_back(-1);
70  } else if (genEvt->isFullLeptonic(WDecay::kElec, WDecay::kElec) && elecs->size() >= 2) {
71  //search indices for electrons
72  int iLepBar = findMatchingLepton(genEvt->leptonBar(), elecs);
73  leptonBar_ = makeCandidate(elecs, iLepBar);
74  match.push_back(iLepBar);
75  int iLep = findMatchingLepton(genEvt->lepton(), elecs);
76  lepton_ = makeCandidate(elecs, iLep);
77  match.push_back(iLep);
78 
79  // fake indices for muons
80  match.push_back(-1);
81  match.push_back(-1);
82  } else if (genEvt->isFullLeptonic(WDecay::kElec, WDecay::kMuon) && !elecs->empty() && !mus->empty()) {
83  if (genEvt->leptonBar()->isElectron()) {
84  // push back index for e+
85  int iLepBar = findMatchingLepton(genEvt->leptonBar(), elecs);
86  leptonBar_ = makeCandidate(elecs, iLepBar);
87  match.push_back(iLepBar);
88  // push back fake indices for e- and mu+
89  match.push_back(-1);
90  match.push_back(-1);
91  // push back index for mu-
92  int iLep = findMatchingLepton(genEvt->lepton(), mus);
93  lepton_ = makeCandidate(mus, iLep);
94  match.push_back(iLep);
95  } else {
96  // push back fake index for e+
97  match.push_back(-1);
98  // push back index for e-
99  int iLepBar = findMatchingLepton(genEvt->leptonBar(), mus);
100  leptonBar_ = makeCandidate(mus, iLepBar);
101  match.push_back(iLepBar);
102  // push back index for mu+
103  int iLep = findMatchingLepton(genEvt->lepton(), elecs);
104  lepton_ = makeCandidate(elecs, iLep);
105  match.push_back(iLep);
106  // push back fake index for mu-
107  match.push_back(-1);
108  }
109  } else if (genEvt->isFullLeptonic(WDecay::kMuon, WDecay::kMuon) && mus->size() >= 2) {
110  // fake indices for electrons
111  match.push_back(-1);
112  match.push_back(-1);
113 
114  //search indices for electrons
115  int iLepBar = findMatchingLepton(genEvt->leptonBar(), mus);
116  leptonBar_ = makeCandidate(mus, iLepBar);
117  match.push_back(iLepBar);
118  int iLep = findMatchingLepton(genEvt->lepton(), mus);
119  lepton_ = makeCandidate(mus, iLep);
120  match.push_back(iLep);
121  } else { //this 'else' should happen if at least one genlepton is a tau
122  match.push_back(-1);
123  match.push_back(-1);
124  match.push_back(-1);
125  match.push_back(-1);
126  }
127 
128  // -----------------------------------------------------
129  // add met and neutrinos
130  // -----------------------------------------------------
131  if (!mets->empty()) {
132  //met_ = makeCandidate(mets, 0);
134  }
135 }
136 
137 template <typename O>
139  const edm::Handle<std::vector<O> >& leps) {
140  int idx = -1;
141  double minDR = -1;
142  for (unsigned i = 0; i < leps->size(); ++i) {
143  double dR = deltaR(genLep->eta(), genLep->phi(), (*leps)[i].eta(), (*leps)[i].phi());
144  if (minDR < 0 || dR < minDR) {
145  minDR = dR;
146  idx = i;
147  }
148  }
149  return idx;
150 }
151 
152 void TtFullLepHypGenMatch::buildMatchingNeutrinos(edm::Event& evt, const edm::Handle<std::vector<pat::MET> >& mets) {
153  // get genEvent
156 
157  if (genEvt->isTtBar() && genEvt->isFullLeptonic() && genEvt->neutrino() && genEvt->neutrinoBar()) {
158  double momXNu = genEvt->neutrino()->px();
159  double momYNu = genEvt->neutrino()->py();
160  double momXNuBar = genEvt->neutrinoBar()->px();
161  double momYNuBar = genEvt->neutrinoBar()->py();
162 
163  double momXMet = mets->at(0).px();
164  double momYMet = mets->at(0).py();
165 
166  double momXNeutrino = 0.5 * (momXNu - momXNuBar + momXMet);
167  double momYNeutrino = 0.5 * (momYNu - momYNuBar + momYMet);
168  double momXNeutrinoBar = momXMet - momXNeutrino;
169  double momYNeutrinoBar = momYMet - momYNeutrino;
170 
171  math::XYZTLorentzVector recNuFM(
172  momXNeutrino, momYNeutrino, 0, sqrt(momXNeutrino * momXNeutrino + momYNeutrino * momYNeutrino));
173  recNu = std::make_unique<reco::LeafCandidate>(0, recNuFM);
174 
175  math::XYZTLorentzVector recNuBarFM(momXNeutrinoBar,
176  momYNeutrinoBar,
177  0,
178  sqrt(momXNeutrinoBar * momXNeutrinoBar + momYNeutrinoBar * momYNeutrinoBar));
179  recNuBar = std::make_unique<reco::LeafCandidate>(0, recNuBarFM);
180  }
181 }
182 
std::unique_ptr< reco::LeafCandidate > recNu
candidates needed for the genmatch hypothesis
std::unique_ptr< reco::ShallowClonePtrCandidate > leptonBar_
int key_
hypothesis key (to be set by the buildKey function)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
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
TtFullLepHypGenMatch(const edm::ParameterSet &)
void buildMatchingNeutrinos(edm::Event &, const edm::Handle< std::vector< pat::MET > > &)
void buildKey() override
build the event hypothesis key
edm::EDGetTokenT< TtGenEvent > genEvtToken_
int findMatchingLepton(const reco::GenParticle *, const edm::Handle< std::vector< O > > &)
std::unique_ptr< reco::LeafCandidate > recNuBar
std::string jetCorrectionLevel_
std::unique_ptr< reco::ShallowClonePtrCandidate > lepton_
HLT enums.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::unique_ptr< reco::ShallowClonePtrCandidate > b_
std::unique_ptr< reco::ShallowClonePtrCandidate > makeCandidate(const edm::Handle< C > &handle, const int &idx)
use one object in a collection to set a ShallowClonePtrCandidate
double phi() const final
momentum azimuthal angle
bool isValid(const int &idx, const edm::Handle< std::vector< pat::Jet > > &jets)
check if index is in valid range of selected jets
std::unique_ptr< reco::ShallowClonePtrCandidate > bBar_
double eta() const final
momentum pseudorapidity