CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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_(0), lightQBar_(0), hadronicB_(0),
17  leptonicB_(0), neutrino_(0), lepton_(0)
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 
61  edm::Handle<int> nJetsConsidered;
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 auto_ptr for products
78  std::auto_ptr<std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > >
79  pOut( new std::vector<std::pair<reco::CompositeCandidate, std::vector<int> > > );
80  std::auto_ptr<int> pKey(new int);
81  std::auto_ptr<int> pNeutrinoSolutions(new int);
82  std::auto_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(pOut);
96 
97  // build and feed out key
98  buildKey();
99  *pKey=key();
100  evt.put(pKey, "Key");
101 
102  // feed out number of real neutrino solutions
103  *pNeutrinoSolutions=numberOfRealNeutrinoSolutions_;
104  evt.put(pNeutrinoSolutions, "NumberOfRealNeutrinoSolutions");
105 
106  // feed out number of considered jets
107  *pJetsConsidered=*nJetsConsidered;
108  evt.put(pJetsConsidered, "NumberOfConsideredJets");
109 }
110 
112 void
114 {
116  lightQ_ = 0;
117  lightQBar_ = 0;
118  hadronicB_ = 0;
119  leptonicB_ = 0;
120  neutrino_ = 0;
121  lepton_ = 0;
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;
277  setCandidate(leps, 0, lepton_);
278  match.push_back( 0 );
279 
280  // -----------------------------------------------------
281  // add neutrino
282  // -----------------------------------------------------
283  if( mets->empty() )
284  return;
285  if(neutrinoSolutionType_ == -1)
286  setCandidate(mets, 0, neutrino_);
287  else
288  setNeutrino(mets, leps, 0, neutrinoSolutionType_);
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
int i
Definition: DBlmapReader.cc:9
static const std::string LepTop
tuple cfg
Definition: looper.py:293
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:462
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
~TtSemiLepHypothesis()
default destructor
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
TtSemiLepHypothesis(const edm::ParameterSet &)
default constructor
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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
tuple handle
Definition: patZpeak.py:22
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_
virtual void produce(edm::Event &, const edm::EventSetup &)
produce the event hypothesis as CompositeCandidate and Key
static const std::string HadQ
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
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
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_
tuple level
Definition: testEve_cfg.py:34
int neutrinoSolutionType_
algorithm used to calculate neutrino solutions (see cfi for further details)
reco::ShallowClonePtrCandidate * lightQ_
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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 ...