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  lightQ_(nullptr), lightQBar_(nullptr), hadronicB_(nullptr),
17  leptonicB_(nullptr), neutrino_(nullptr), lepton_(nullptr)
18 {
19  getMatch_ = false;
20  if( cfg.exists("match") ) {
21  getMatch_ = true;
22  matchToken_ = consumes<std::vector<std::vector<int> > >(cfg.getParameter<edm::InputTag>("match"));
23  }
24  if( cfg.exists("neutrinoSolutionType") )
25  neutrinoSolutionType_ = cfg.getParameter<int>("neutrinoSolutionType");
26  else
28  if( cfg.exists("jetCorrectionLevel") ) {
29  jetCorrectionLevel_ = cfg.getParameter<std::string>("jetCorrectionLevel");
30  }
31  produces<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >();
32  produces<int>("Key");
33  produces<int>("NumberOfRealNeutrinoSolutions");
34  produces<int>("NumberOfConsideredJets");
35 }
36 
39 {
40  if( lightQ_ ) delete lightQ_;
41  if( lightQBar_ ) delete lightQBar_;
42  if( hadronicB_ ) delete hadronicB_;
43  if( leptonicB_ ) delete leptonicB_;
44  if( neutrino_ ) delete neutrino_;
45  if( lepton_ ) delete lepton_;
46 }
47 
49 void
51 {
53  evt.getByToken(jetsToken_, jets);
54 
56  evt.getByToken(lepsToken_, leps);
57 
59  evt.getByToken(metsToken_, mets);
60 
62  evt.getByToken(nJetsConsideredToken_, nJetsConsidered);
63 
64  std::vector<std::vector<int> > matchVec;
65  if( getMatch_ ) {
67  evt.getByToken(matchToken_, matchHandle);
68  matchVec = *matchHandle;
69  }
70  else {
71  std::vector<int> dummyMatch;
72  for(unsigned int i = 0; i < 4; ++i)
73  dummyMatch.push_back( -1 );
74  matchVec.push_back( dummyMatch );
75  }
76 
77  // declare unique_ptr for products
78  std::unique_ptr<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >
79  pOut( new std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > );
80  std::unique_ptr<int> pKey(new int);
81  std::unique_ptr<int> pNeutrinoSolutions(new int);
82  std::unique_ptr<int> pJetsConsidered(new int);
83 
84  // go through given vector of jet combinations
85  unsigned int idMatch = 0;
86  typedef std::vector<std::vector<int> >::iterator MatchVecIterator;
87  for(MatchVecIterator match = matchVec.begin(); match != matchVec.end(); ++match) {
88  // reset pointers
90  // build hypothesis
91  buildHypo(evt, leps, mets, jets, *match, idMatch++);
92  pOut->push_back( std::make_pair(hypo(), *match) );
93  }
94  // feed out hyps and matches
95  evt.put(std::move(pOut));
96 
97  // build and feed out key
98  buildKey();
99  *pKey=key();
100  evt.put(std::move(pKey), "Key");
101 
102  // feed out number of real neutrino solutions
103  *pNeutrinoSolutions=numberOfRealNeutrinoSolutions_;
104  evt.put(std::move(pNeutrinoSolutions), "NumberOfRealNeutrinoSolutions");
105 
106  // feed out number of considered jets
107  *pJetsConsidered=*nJetsConsidered;
108  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
109 }
110 
112 void
114 {
116  lightQ_ = nullptr;
117  lightQBar_ = nullptr;
118  hadronicB_ = nullptr;
119  leptonicB_ = nullptr;
120  neutrino_ = nullptr;
121  lepton_ = nullptr;
122 }
123 
127 {
128  // check for sanity of the hypothesis
129  if( !lightQ_ || !lightQBar_ || !hadronicB_ ||
130  !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
154  hyp.addDaughter( lepTop, TtSemiLepDaughter::LepTop );
155  hyp.addDaughter( hadTop, TtSemiLepDaughter::HadTop );
156  addFourMomenta.set( hyp );
157 
158  return hyp;
159 }
160 
164 {
165  // check whetherwe are dealing with a reco muon or a reco electron
167  if( dynamic_cast<const reco::Muon*>(cand) ){
168  type = WDecay::kMuon;
169  }
170  else if( dynamic_cast<const reco::GsfElectron*>(cand) ){
171  type = WDecay::kElec;
172  }
173  return type;
174 }
175 
179 {
180  // jetCorrectionLevel was not configured
181  if(jetCorrectionLevel_.empty())
182  throw cms::Exception("Configuration")
183  << "Unconfigured jetCorrectionLevel. Please use an appropriate, non-empty string.\n";
184 
185  // quarkType is unknown
186  if( !(quarkType=="wQuarkMix" ||
187  quarkType=="udsQuark" ||
188  quarkType=="cQuark" ||
189  quarkType=="bQuark") )
190  throw cms::Exception("Configuration")
191  << quarkType << " is unknown as a quarkType for the jetCorrectionLevel.\n";
192 
193  // combine correction level; start with a ':' even if
194  // there is no flavor tag to be added, as it is needed
195  // by setCandidate to disentangle the correction tag
196  // from a potential flavor tag, which can be empty
198  if( level=="L5Flavor:" || level=="L6UE:" || level=="L7Parton:" ){
199  if(quarkType=="wQuarkMix"){level+="wMix";}
200  if(quarkType=="udsQuark" ){level+="uds";}
201  if(quarkType=="cQuark" ){level+="charm";}
202  if(quarkType=="bQuark" ){level+="bottom";}
203  }
204  else{
205  level+="none";
206  }
207  return level;
208 }
209 
211 void
212 TtSemiLepHypothesis::setCandidate(const edm::Handle<std::vector<pat::Jet> >& handle, const int& idx,
213  reco::ShallowClonePtrCandidate*& clone, const std::string& correctionLevel)
214 {
216  // disentangle the correction from the potential flavor tag
217  // by the separating ':'; the flavor tag can be empty though
218  std::string step = correctionLevel.substr(0,correctionLevel.find(":"));
219  std::string flavor = correctionLevel.substr(1+correctionLevel.find(":"));
220  float corrFactor = 1.;
221  if(flavor=="wMix")
222  corrFactor = 0.75*ptr->jecFactor(step, "uds") + 0.25*ptr->jecFactor(step, "charm");
223  else
224  corrFactor = ptr->jecFactor(step, flavor);
225  clone = new reco::ShallowClonePtrCandidate( ptr, ptr->charge(), ptr->p4()*corrFactor, ptr->vertex() );
226 }
227 
229 void TtSemiLepHypothesis::setNeutrino(const edm::Handle<std::vector<pat::MET> >& met,
230  const edm::Handle<edm::View<reco::RecoCandidate> >& leps, const int& idx, const int& type)
231 {
233  MEzCalculator mez;
234  mez.SetMET( *(met->begin()) );
235  if( leptonType( &(leps->front()) ) == WDecay::kMuon )
236  mez.SetLepton( (*leps)[idx], true );
237  else if( leptonType( &(leps->front()) ) == WDecay::kElec )
238  mez.SetLepton( (*leps)[idx], false );
239  else
240  throw cms::Exception("UnimplementedFeature") << "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( ptr->px(), ptr->py(), pz, sqrt(ptr->px()*ptr->px() + ptr->py()*ptr->py() + pz*pz) );
244  neutrino_ = new reco::ShallowClonePtrCandidate( ptr, ptr->charge(), p4, ptr->vertex() );
245 }
246 
248 void
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  // -----------------------------------------------------
255  // add jets
256  // -----------------------------------------------------
257  for(unsigned idx=0; idx<match.size(); ++idx){
258  if( isValid(match[idx], jets) ){
259  switch(idx){
261  setCandidate(jets, match[idx], lightQ_, jetCorrectionLevel("wQuarkMix")); break;
263  setCandidate(jets, match[idx], lightQBar_, jetCorrectionLevel("wQuarkMix")); break;
265  setCandidate(jets, match[idx], hadronicB_, jetCorrectionLevel("bQuark")); break;
267  setCandidate(jets, match[idx], leptonicB_, jetCorrectionLevel("bQuark")); break;
268  }
269  }
270  }
271 
272  // -----------------------------------------------------
273  // add lepton
274  // -----------------------------------------------------
275  if( leps->empty() )
276  return;
278  match.push_back( 0 );
279 
280  // -----------------------------------------------------
281  // add neutrino
282  // -----------------------------------------------------
283  if( mets->empty() )
284  return;
285  if(neutrinoSolutionType_ == -1)
287  else
289 }
290 
std::string jetCorrectionLevel_
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
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:125
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:517
double px() const final
x coordinate of momentum vector
reco::ShallowClonePtrCandidate * lepton_
#define nullptr
reco::ShallowClonePtrCandidate * lightQBar_
bool exists(std::string const &parameterName) const
checks if a parameter exists
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
int charge() const final
electric charge
Definition: LeafCandidate.h:91
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
Definition: HeavyIon.h:7
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
TtSemiLepHypothesis(const edm::ParameterSet &)
default constructor
Definition: Jet.py:1
reco::ShallowClonePtrCandidate * neutrino_
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
void resetCandidates()
reset candidate pointers before hypo build process
vector< PseudoJet > jets
const Point & vertex() const override
vertex position (overwritten by PF...)
virtual void buildKey()=0
build the event hypothesis key
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
nJetsConsidered
number of considered jets
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_
met
===> hadronic RAZOR
static const std::string HadQ
double py() const final
y coordinate of momentum vector
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
static const std::string Nu
fixed size matrix
HLT enums.
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
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
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
float jecFactor(const std::string &level, const std::string &flavor="none", const std::string &set="") const
edm::EDGetTokenT< std::vector< std::vector< int > > > matchToken_
step
Definition: StallMonitor.cc:94
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
def move(src, dest)
Definition: eostools.py:511
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 ...