CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TtSemiLepHypothesis.cc
Go to the documentation of this file.
6 
8 
11  : jetsToken_(consumes<std::vector<pat::Jet> >(cfg.getParameter<edm::InputTag>("jets"))),
12  lepsToken_(consumes<edm::View<reco::RecoCandidate> >(cfg.getParameter<edm::InputTag>("leps"))),
13  metsToken_(consumes<std::vector<pat::MET> >(cfg.getParameter<edm::InputTag>("mets"))),
14  nJetsConsideredToken_(consumes<int>(cfg.getParameter<edm::InputTag>("nJetsConsidered"))),
15  numberOfRealNeutrinoSolutions_(-1),
16  lightQ_(nullptr),
17  lightQBar_(nullptr),
18  hadronicB_(nullptr),
19  leptonicB_(nullptr),
20  neutrino_(nullptr),
21  lepton_(nullptr) {
22  getMatch_ = false;
23  if (cfg.exists("match")) {
24  getMatch_ = true;
25  matchToken_ = consumes<std::vector<std::vector<int> > >(cfg.getParameter<edm::InputTag>("match"));
26  }
27  if (cfg.exists("neutrinoSolutionType"))
28  neutrinoSolutionType_ = cfg.getParameter<int>("neutrinoSolutionType");
29  else
31  if (cfg.exists("jetCorrectionLevel")) {
32  jetCorrectionLevel_ = cfg.getParameter<std::string>("jetCorrectionLevel");
33  }
34  produces<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >();
35  produces<int>("Key");
36  produces<int>("NumberOfRealNeutrinoSolutions");
37  produces<int>("NumberOfConsideredJets");
38 }
39 
42  if (lightQ_)
43  delete lightQ_;
44  if (lightQBar_)
45  delete lightQBar_;
46  if (hadronicB_)
47  delete hadronicB_;
48  if (leptonicB_)
49  delete leptonicB_;
50  if (neutrino_)
51  delete neutrino_;
52  if (lepton_)
53  delete lepton_;
54 }
55 
59  evt.getByToken(jetsToken_, jets);
60 
62  evt.getByToken(lepsToken_, leps);
63 
65  evt.getByToken(metsToken_, mets);
66 
67  edm::Handle<int> nJetsConsidered;
68  evt.getByToken(nJetsConsideredToken_, nJetsConsidered);
69 
70  std::vector<std::vector<int> > matchVec;
71  if (getMatch_) {
73  evt.getByToken(matchToken_, matchHandle);
74  matchVec = *matchHandle;
75  } else {
76  std::vector<int> dummyMatch;
77  for (unsigned int i = 0; i < 4; ++i)
78  dummyMatch.push_back(-1);
79  matchVec.push_back(dummyMatch);
80  }
81 
82  // declare unique_ptr for products
83  std::unique_ptr<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > > pOut(
84  new std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > >);
85  std::unique_ptr<int> pKey(new int);
86  std::unique_ptr<int> pNeutrinoSolutions(new int);
87  std::unique_ptr<int> pJetsConsidered(new int);
88 
89  // go through given vector of jet combinations
90  unsigned int idMatch = 0;
91  typedef std::vector<std::vector<int> >::iterator MatchVecIterator;
92  for (MatchVecIterator match = matchVec.begin(); match != matchVec.end(); ++match) {
93  // reset pointers
95  // build hypothesis
96  buildHypo(evt, leps, mets, jets, *match, idMatch++);
97  pOut->push_back(std::make_pair(hypo(), *match));
98  }
99  // feed out hyps and matches
100  evt.put(std::move(pOut));
101 
102  // build and feed out key
103  buildKey();
104  *pKey = key();
105  evt.put(std::move(pKey), "Key");
106 
107  // feed out number of real neutrino solutions
108  *pNeutrinoSolutions = numberOfRealNeutrinoSolutions_;
109  evt.put(std::move(pNeutrinoSolutions), "NumberOfRealNeutrinoSolutions");
110 
111  // feed out number of considered jets
112  *pJetsConsidered = *nJetsConsidered;
113  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
114 }
115 
119  lightQ_ = nullptr;
120  lightQBar_ = nullptr;
121  hadronicB_ = nullptr;
122  leptonicB_ = nullptr;
123  neutrino_ = nullptr;
124  lepton_ = nullptr;
125 }
126 
129  // check for sanity of the hypothesis
130  if (!lightQ_ || !lightQBar_ || !hadronicB_ || !leptonicB_ || !neutrino_ || !lepton_)
131  return reco::CompositeCandidate();
132 
133  // setup transient references
134  reco::CompositeCandidate hyp, hadTop, hadW, lepTop, lepW;
135 
136  AddFourMomenta addFourMomenta;
137  // build up the top branch that decays leptonically
140  addFourMomenta.set(lepW);
141  lepTop.addDaughter(lepW, TtSemiLepDaughter::LepW);
143  addFourMomenta.set(lepTop);
144 
145  // build up the top branch that decays hadronically
148  addFourMomenta.set(hadW);
149  hadTop.addDaughter(hadW, TtSemiLepDaughter::HadW);
151  addFourMomenta.set(hadTop);
152 
153  // build ttbar hypotheses
156  addFourMomenta.set(hyp);
157 
158  return hyp;
159 }
160 
163  // check whetherwe are dealing with a reco muon or a reco electron
165  if (dynamic_cast<const reco::Muon*>(cand)) {
166  type = WDecay::kMuon;
167  } else if (dynamic_cast<const reco::GsfElectron*>(cand)) {
168  type = WDecay::kElec;
169  }
170  return type;
171 }
172 
175  // jetCorrectionLevel was not configured
176  if (jetCorrectionLevel_.empty())
177  throw cms::Exception("Configuration")
178  << "Unconfigured jetCorrectionLevel. Please use an appropriate, non-empty string.\n";
179 
180  // quarkType is unknown
181  if (!(quarkType == "wQuarkMix" || quarkType == "udsQuark" || quarkType == "cQuark" || quarkType == "bQuark"))
182  throw cms::Exception("Configuration") << quarkType << " is unknown as a quarkType for the jetCorrectionLevel.\n";
183 
184  // combine correction level; start with a ':' even if
185  // there is no flavor tag to be added, as it is needed
186  // by setCandidate to disentangle the correction tag
187  // from a potential flavor tag, which can be empty
189  if (level == "L5Flavor:" || level == "L6UE:" || level == "L7Parton:") {
190  if (quarkType == "wQuarkMix") {
191  level += "wMix";
192  }
193  if (quarkType == "udsQuark") {
194  level += "uds";
195  }
196  if (quarkType == "cQuark") {
197  level += "charm";
198  }
199  if (quarkType == "bQuark") {
200  level += "bottom";
201  }
202  } else {
203  level += "none";
204  }
205  return level;
206 }
207 
209 void TtSemiLepHypothesis::setCandidate(const edm::Handle<std::vector<pat::Jet> >& handle,
210  const int& idx,
212  const std::string& correctionLevel) {
214  // disentangle the correction from the potential flavor tag
215  // by the separating ':'; the flavor tag can be empty though
216  std::string step = correctionLevel.substr(0, correctionLevel.find(':'));
217  std::string flavor = correctionLevel.substr(1 + correctionLevel.find(':'));
218  float corrFactor = 1.;
219  if (flavor == "wMix")
220  corrFactor = 0.75 * ptr->jecFactor(step, "uds") + 0.25 * ptr->jecFactor(step, "charm");
221  else
222  corrFactor = ptr->jecFactor(step, flavor);
223  clone = new reco::ShallowClonePtrCandidate(ptr, ptr->charge(), ptr->p4() * corrFactor, ptr->vertex());
224 }
225 
227 void TtSemiLepHypothesis::setNeutrino(const edm::Handle<std::vector<pat::MET> >& met,
229  const int& idx,
230  const int& type) {
232  MEzCalculator mez;
233  mez.SetMET(*(met->begin()));
234  if (leptonType(&(leps->front())) == WDecay::kMuon)
235  mez.SetLepton((*leps)[idx], true);
236  else if (leptonType(&(leps->front())) == WDecay::kElec)
237  mez.SetLepton((*leps)[idx], false);
238  else
239  throw cms::Exception("UnimplementedFeature")
240  << "Type of lepton given together with MET for solving neutrino kinematics is neither muon nor electron.\n";
241  double pz = mez.Calculate(type);
242  numberOfRealNeutrinoSolutions_ = mez.IsComplex() ? 0 : 2;
243  const math::XYZTLorentzVector p4(
244  ptr->px(), ptr->py(), pz, sqrt(ptr->px() * ptr->px() + ptr->py() * ptr->py() + pz * pz));
245  neutrino_ = new reco::ShallowClonePtrCandidate(ptr, ptr->charge(), p4, ptr->vertex());
246 }
247 
250  const edm::Handle<std::vector<pat::MET> >& mets,
251  const edm::Handle<std::vector<pat::Jet> >& jets,
252  std::vector<int>& match) {
253  // -----------------------------------------------------
254  // add jets
255  // -----------------------------------------------------
256  for (unsigned idx = 0; idx < match.size(); ++idx) {
257  if (isValid(match[idx], jets)) {
258  switch (idx) {
260  setCandidate(jets, match[idx], lightQ_, jetCorrectionLevel("wQuarkMix"));
261  break;
263  setCandidate(jets, match[idx], lightQBar_, jetCorrectionLevel("wQuarkMix"));
264  break;
266  setCandidate(jets, match[idx], hadronicB_, jetCorrectionLevel("bQuark"));
267  break;
269  setCandidate(jets, match[idx], leptonicB_, jetCorrectionLevel("bQuark"));
270  break;
271  }
272  }
273  }
274 
275  // -----------------------------------------------------
276  // add lepton
277  // -----------------------------------------------------
278  if (leps->empty())
279  return;
280  setCandidate(leps, 0, lepton_);
281  match.push_back(0);
282 
283  // -----------------------------------------------------
284  // add neutrino
285  // -----------------------------------------------------
286  if (mets->empty())
287  return;
288  if (neutrinoSolutionType_ == -1)
289  setCandidate(mets, 0, neutrino_);
290  else
291  setNeutrino(mets, leps, 0, neutrinoSolutionType_);
292 }
edm::EDGetTokenT< int > nJetsConsideredToken_
static const std::string HadB
static const std::string LepTop
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
tuple cfg
Definition: looper.py:296
static const std::string Lep
static const std::string LepW
WDecay::LeptonType leptonType(const reco::RecoCandidate *cand)
determine lepton type of reco candidate and return a corresponding WDecay::LeptonType; the type is kN...
bool isValid(const int &idx, const edm::Handle< std::vector< pat::Jet > > &jets)
check if index is in valid range of selected jets
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
reco::ShallowClonePtrCandidate * lepton_
reco::ShallowClonePtrCandidate * lightQBar_
bool exists(std::string const &parameterName) const
checks if a parameter exists
static const std::string HadP
void buildHypo(const edm::Handle< edm::View< reco::RecoCandidate > > &leps, const edm::Handle< std::vector< pat::MET > > &mets, const edm::Handle< std::vector< pat::Jet > > &jets, std::vector< int > &jetPartonAssociation)
minimalistic build function for simple hypotheses
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
TtSemiLepHypothesis(const edm::ParameterSet &)
default constructor
reco::ShallowClonePtrCandidate * neutrino_
T sqrt(T t)
Definition: SSEVec.h:19
void resetCandidates()
reset candidate pointers before hypo build process
vector< PseudoJet > jets
def move
Definition: eostools.py:511
tuple handle
Definition: patZpeak.py:23
virtual void buildKey()=0
build the event hypothesis key
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
input label for all necessary collections
static const std::string HadTop
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
reco::ShallowClonePtrCandidate * hadronicB_
static const std::string HadQ
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
static const std::string HadW
void setNeutrino(const edm::Handle< std::vector< pat::MET > > &met, const edm::Handle< edm::View< reco::RecoCandidate > > &leps, const int &idx, const int &type)
set neutrino, using mW = 80.4 to calculate the neutrino pz
reco::CompositeCandidate hypo()
return event hypothesis
constexpr char Jet[]
Definition: modules.cc:9
static const std::string Nu
void setCandidate(const edm::Handle< C > &handle, const int &idx, reco::ShallowClonePtrCandidate *&clone)
use one object in a collection to set a ShallowClonePtrCandidate
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
static const std::string LepB
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
void set(reco::Candidate &c) const
set up a candidate
edm::EDGetTokenT< std::vector< std::vector< int > > > matchToken_
step
Definition: StallMonitor.cc:94
tuple level
Definition: testEve_cfg.py:47
int neutrinoSolutionType_
algorithm used to calculate neutrino solutions (see cfi for further details)
void produce(edm::Event &, const edm::EventSetup &) override
produce the event hypothesis as CompositeCandidate and Key
reco::ShallowClonePtrCandidate * lightQ_
~TtSemiLepHypothesis() override
default destructor
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
reco::ShallowClonePtrCandidate * leptonicB_
std::string jetCorrectionLevel(const std::string &quarkType)
helper function to construct the proper correction level string for corresponding quarkType ...