CMS 3D CMS Logo

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  getMatch_ = false;
17  if (cfg.exists("match")) {
18  getMatch_ = true;
19  matchToken_ = consumes<std::vector<std::vector<int> > >(cfg.getParameter<edm::InputTag>("match"));
20  }
21  if (cfg.exists("neutrinoSolutionType"))
22  neutrinoSolutionType_ = cfg.getParameter<int>("neutrinoSolutionType");
23  else
25  if (cfg.exists("jetCorrectionLevel")) {
26  jetCorrectionLevel_ = cfg.getParameter<std::string>("jetCorrectionLevel");
27  }
28  produces<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >();
29  produces<int>("Key");
30  produces<int>("NumberOfRealNeutrinoSolutions");
31  produces<int>("NumberOfConsideredJets");
32 }
33 
38 
41 
44 
47 
48  std::vector<std::vector<int> > matchVec;
49  if (getMatch_) {
51  evt.getByToken(matchToken_, matchHandle);
52  matchVec = *matchHandle;
53  } else {
54  std::vector<int> dummyMatch;
55  for (unsigned int i = 0; i < 4; ++i)
56  dummyMatch.push_back(-1);
57  matchVec.push_back(dummyMatch);
58  }
59 
60  // declare unique_ptr for products
61  std::unique_ptr<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > > pOut(
62  new std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > >);
63  std::unique_ptr<int> pKey(new int);
64  std::unique_ptr<int> pNeutrinoSolutions(new int);
65  std::unique_ptr<int> pJetsConsidered(new int);
66 
67  // go through given vector of jet combinations
68  unsigned int idMatch = 0;
69  typedef std::vector<std::vector<int> >::iterator MatchVecIterator;
70  for (MatchVecIterator match = matchVec.begin(); match != matchVec.end(); ++match) {
71  // reset pointers
73  // build hypothesis
74  buildHypo(evt, leps, mets, jets, *match, idMatch++);
75  pOut->push_back(std::make_pair(hypo(), *match));
76  }
77  // feed out hyps and matches
78  evt.put(std::move(pOut));
79 
80  // build and feed out key
81  buildKey();
82  *pKey = key();
83  evt.put(std::move(pKey), "Key");
84 
85  // feed out number of real neutrino solutions
86  *pNeutrinoSolutions = numberOfRealNeutrinoSolutions_;
87  evt.put(std::move(pNeutrinoSolutions), "NumberOfRealNeutrinoSolutions");
88 
89  // feed out number of considered jets
90  *pJetsConsidered = *nJetsConsidered;
91  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
92 }
93 
97  lightQ_.reset();
98  lightQBar_.reset();
99  hadronicB_.reset();
100  leptonicB_.reset();
101  neutrino_.reset();
102  lepton_.reset();
103 }
104 
107  // check for sanity of the hypothesis
108  if (!lightQ_ || !lightQBar_ || !hadronicB_ || !leptonicB_ || !neutrino_ || !lepton_)
109  return reco::CompositeCandidate();
110 
111  // setup transient references
112  reco::CompositeCandidate hyp, hadTop, hadW, lepTop, lepW;
113 
114  AddFourMomenta addFourMomenta;
115  // build up the top branch that decays leptonically
118  addFourMomenta.set(lepW);
119  lepTop.addDaughter(lepW, TtSemiLepDaughter::LepW);
121  addFourMomenta.set(lepTop);
122 
123  // build up the top branch that decays hadronically
126  addFourMomenta.set(hadW);
127  hadTop.addDaughter(hadW, TtSemiLepDaughter::HadW);
129  addFourMomenta.set(hadTop);
130 
131  // build ttbar hypotheses
134  addFourMomenta.set(hyp);
135 
136  return hyp;
137 }
138 
141  // check whetherwe are dealing with a reco muon or a reco electron
143  if (dynamic_cast<const reco::Muon*>(cand)) {
145  } else if (dynamic_cast<const reco::GsfElectron*>(cand)) {
147  }
148  return type;
149 }
150 
153  // jetCorrectionLevel was not configured
154  if (jetCorrectionLevel_.empty())
155  throw cms::Exception("Configuration")
156  << "Unconfigured jetCorrectionLevel. Please use an appropriate, non-empty string.\n";
157 
158  // quarkType is unknown
159  if (!(quarkType == "wQuarkMix" || quarkType == "udsQuark" || quarkType == "cQuark" || quarkType == "bQuark"))
160  throw cms::Exception("Configuration") << quarkType << " is unknown as a quarkType for the jetCorrectionLevel.\n";
161 
162  // combine correction level; start with a ':' even if
163  // there is no flavor tag to be added, as it is needed
164  // by makeCandidate to disentangle the correction tag
165  // from a potential flavor tag, which can be empty
167  if (level == "L5Flavor:" || level == "L6UE:" || level == "L7Parton:") {
168  if (quarkType == "wQuarkMix") {
169  level += "wMix";
170  }
171  if (quarkType == "udsQuark") {
172  level += "uds";
173  }
174  if (quarkType == "cQuark") {
175  level += "charm";
176  }
177  if (quarkType == "bQuark") {
178  level += "bottom";
179  }
180  } else {
181  level += "none";
182  }
183  return level;
184 }
185 
187 std::unique_ptr<reco::ShallowClonePtrCandidate> TtSemiLepHypothesis::makeCandidate(
188  const edm::Handle<std::vector<pat::Jet> >& handle, const int& idx, const std::string& correctionLevel) {
190  // disentangle the correction from the potential flavor tag
191  // by the separating ':'; the flavor tag can be empty though
192  std::string step = correctionLevel.substr(0, correctionLevel.find(':'));
193  std::string flavor = correctionLevel.substr(1 + correctionLevel.find(':'));
194  float corrFactor = 1.;
195  if (flavor == "wMix")
196  corrFactor = 0.75 * ptr->jecFactor(step, "uds") + 0.25 * ptr->jecFactor(step, "charm");
197  else
198  corrFactor = ptr->jecFactor(step, flavor);
199  return std::make_unique<reco::ShallowClonePtrCandidate>(ptr, ptr->charge(), ptr->p4() * corrFactor, ptr->vertex());
200 }
201 
203 void TtSemiLepHypothesis::setNeutrino(const edm::Handle<std::vector<pat::MET> >& met,
205  const int& idx,
206  const int& type) {
208  MEzCalculator mez;
209  mez.SetMET(*(met->begin()));
210  if (leptonType(&(leps->front())) == WDecay::kMuon)
211  mez.SetLepton((*leps)[idx], true);
212  else if (leptonType(&(leps->front())) == WDecay::kElec)
213  mez.SetLepton((*leps)[idx], false);
214  else
215  throw cms::Exception("UnimplementedFeature")
216  << "Type of lepton given together with MET for solving neutrino kinematics is neither muon nor electron.\n";
217  double pz = mez.Calculate(type);
218  numberOfRealNeutrinoSolutions_ = mez.IsComplex() ? 0 : 2;
219  const math::XYZTLorentzVector p4(
220  ptr->px(), ptr->py(), pz, sqrt(ptr->px() * ptr->px() + ptr->py() * ptr->py() + pz * pz));
221  neutrino_ = std::make_unique<reco::ShallowClonePtrCandidate>(ptr, ptr->charge(), p4, ptr->vertex());
222 }
223 
226  const edm::Handle<std::vector<pat::MET> >& mets,
227  const edm::Handle<std::vector<pat::Jet> >& jets,
228  std::vector<int>& match) {
229  // -----------------------------------------------------
230  // add jets
231  // -----------------------------------------------------
232  for (unsigned idx = 0; idx < match.size(); ++idx) {
233  if (isValid(match[idx], jets)) {
234  switch (idx) {
237  break;
240  break;
243  break;
246  break;
247  }
248  }
249  }
250 
251  // -----------------------------------------------------
252  // add lepton
253  // -----------------------------------------------------
254  if (leps->empty())
255  return;
256  lepton_ = makeCandidate(leps, 0);
257  match.push_back(0);
258 
259  // -----------------------------------------------------
260  // add neutrino
261  // -----------------------------------------------------
262  if (mets->empty())
263  return;
264  if (neutrinoSolutionType_ == -1)
266  else
268 }
std::string jetCorrectionLevel_
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
static const std::string Lep
float jecFactor(const std::string &level, const std::string &flavor="none", const std::string &set="") const
static const std::string LepW
void set(reco::Candidate &c) const
set up a candidate
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:528
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
std::unique_ptr< reco::ShallowClonePtrCandidate > leptonicB_
Definition: HeavyIon.h:7
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
TtSemiLepHypothesis(const edm::ParameterSet &)
default constructor
double px() const final
x coordinate of momentum vector
std::unique_ptr< reco::ShallowClonePtrCandidate > lepton_
Definition: Jet.py:1
T sqrt(T t)
Definition: SSEVec.h:19
void resetCandidates()
reset candidate pointers before hypo build process
std::unique_ptr< reco::ShallowClonePtrCandidate > makeCandidate(const edm::Handle< C > &handle, const int &idx)
use one object in a collection to set a ShallowClonePtrCandidate
virtual void buildKey()=0
build the event hypothesis key
nJetsConsidered
number of considered jets
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
input label for all necessary collections
static const std::string HadTop
double py() const final
y coordinate of momentum vector
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
static const std::string HadQ
std::unique_ptr< reco::ShallowClonePtrCandidate > lightQBar_
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
std::unique_ptr< reco::ShallowClonePtrCandidate > neutrino_
static const std::string Nu
fixed size matrix
std::unique_ptr< reco::ShallowClonePtrCandidate > lightQ_
HLT enums.
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
edm::EDGetTokenT< std::vector< std::vector< int > > > matchToken_
step
Definition: StallMonitor.cc:83
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
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< reco::ShallowClonePtrCandidate > hadronicB_
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
int charge() const final
electric charge
std::string jetCorrectionLevel(const std::string &quarkType)
helper function to construct the proper correction level string for corresponding quarkType ...