test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Lepjets_Event.cc
Go to the documentation of this file.
1 //
2 //
3 // File: src/Lepjets_Event.h
4 // Purpose: Represent a simple `event' consisting of leptons and jets.
5 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
6 //
7 // CMSSW File : src/Lepjets_Event.cc
8 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
9 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
10 //
11 
12 
36 #include <algorithm>
37 #include <functional>
38 #include <cmath>
39 #include <cassert>
40 
41 
42 using std::stable_sort;
43 using std::less;
44 using std::not2;
45 using std::remove_if;
46 using std::abs;
47 
48 
49 namespace hitfit {
50 
51 
53 //
54 // Purpose: Constructor.
55 //
56 // Inputs:
57 // runnum - The run number.
58 // evnum - The event number.
59 //
60  : _zvertex (0),
61  _isMC(false),
62  _runnum (runnum),
63  _evnum (evnum),
64  _dlb (-1),
65  _dnn (-1)
66 {
67 }
68 
69 
71 //
72 // Purpose: Return the run number.
73 //
74 // Returns:
75 // The run number.
76 //
77 {
78  return _runnum;
79 }
80 
81 
83 //
84 // Purpose: Return the run number.
85 //
86 // Returns:
87 // The run number.
88 //
89 {
90  return _runnum;
91 }
92 
93 
95 //
96 // Purpose: Return the event number.
97 //
98 // Returns:
99 // The event number.
100 //
101 {
102  return _evnum;
103 }
104 
105 
107 //
108 // Purpose: Return the event number.
109 //
110 // Returns:
111 // The event number.
112 //
113 {
114  return _evnum;
115 }
116 
117 
119 //
120 // Purpose: Return the length of the lepton list.
121 //
122 // Returns:
123 // The length of the lepton list.
124 //
125 {
126  return _leps.size ();
127 }
128 
129 
131 //
132 // Purpose: Return the length of the jet list.
133 //
134 // Returns:
135 // The length of the jet list.
136 //
137 {
138  return _jets.size ();
139 }
140 
141 
143 //
144 // Purpose: Return the Ith lepton.
145 //
146 // Inputs:
147 // i - The lepton index (counting from 0).
148 //
149 // Returns:
150 // The Ith lepton.
151 //
152 {
153  assert (i < _leps.size());
154  return _leps[i];
155 }
156 
157 
159 //
160 // Purpose: Return the Ith jet.
161 //
162 // Inputs:
163 // i - The jet index (counting from 0).
164 //
165 // Returns:
166 // The Ith jet.
167 //
168 {
169  assert (i < _jets.size());
170  return _jets[i];
171 }
172 
173 
175 //
176 // Purpose: Return the Ith lepton.
177 //
178 // Inputs:
179 // i - The lepton index (counting from 0).
180 //
181 // Returns:
182 // The Ith lepton.
183 //
184 {
185  assert (i < _leps.size());
186  return _leps[i];
187 }
188 
189 
191 //
192 // Purpose: Return the Ith jet.
193 //
194 // Inputs:
195 // i - The jet index (counting from 0).
196 //
197 // Returns:
198 // The Ith jet.
199 //
200 {
201  assert (i < _jets.size());
202  return _jets[i];
203 }
204 
205 
207 //
208 // Purpose: Return the missing Et.
209 //
210 // Returns:
211 // The missing Et.
212 //
213 {
214  return _met;
215 }
216 
217 
219 //
220 // Purpose: Return the missing Et.
221 //
222 // Returns:
223 // The missing Et.
224 //
225 {
226  return _met;
227 }
228 
229 
231 //
232 // Purpose: Return the kt resolution.
233 //
234 // Returns:
235 // The kt resolution.
236 //
237 {
238  return _kt_res;
239 }
240 
241 
243 //
244 // Purpose: Return the kt resolution.
245 //
246 // Returns:
247 // The kt resolution.
248 //
249 {
250  return _kt_res;
251 }
252 
253 
255 //
256 // Purpose: Return the z-vertex.
257 //
258 // Returns:
259 // The z-vertex.
260 //
261 {
262  return _zvertex;
263 }
264 
265 
267 //
268 // Purpose: Return the z-vertex.
269 //
270 // Returns:
271 // The z-vertex.
272 //
273 {
274  return _zvertex;
275 }
276 
277 
279 //
280 // Purpose: Return the isMC flag.
281 //
282 // Returns:
283 // The isMC flag.
284 //
285 {
286  return _isMC;
287 }
288 
289 
290 void Lepjets_Event::setMC (bool isMC)
291 //
292 // Purpose: set isMC flag.
293 //
294 // Returns:
295 // nothing
296 //
297 {
298  _isMC = isMC;
299 }
300 
302 //
303 // Purpose: Return the LB discriminant.
304 //
305 // Returns:
306 // The LB discriminant.
307 //
308 {
309  return _dlb;
310 }
311 
312 
314 //
315 // Purpose: Return the LB discriminant.
316 //
317 // Returns:
318 // The LB discriminant.
319 //
320 {
321  return _dlb;
322 }
323 
324 
326 //
327 // Purpose: Return the NN discriminant.
328 //
329 // Returns:
330 // The NN discriminant.
331 //
332 {
333  return _dnn;
334 }
335 
336 
338 //
339 // Purpose: Return the NN discriminant.
340 //
341 // Returns:
342 // The NN discriminant.
343 //
344 {
345  return _dnn;
346 }
347 
348 
350 //
351 // Purpose: Sum all objects with type code TYPE.
352 //
353 // Inputs:
354 // type - The type code to match.
355 //
356 // Returns:
357 // The sum of all objects with type code TYPE.
358 //
359 {
360  Fourvec out;
361  for (std::vector<Lepjets_Event_Lep>::size_type i=0; i < _leps.size(); i++)
362  if (_leps[i].type() == type)
363  out += _leps[i].p();
364  for (std::vector<Lepjets_Event_Jet>::size_type i=0; i < _jets.size(); i++)
365  if (_jets[i].type() == type)
366  out += _jets[i].p();
367  return out;
368 }
369 
370 
372 //
373 // Purpose: Calculate kt --- sum of all objects plus missing Et.
374 //
375 // Returns:
376 // The event kt.
377 {
378  Fourvec v = _met;
380  v += _leps[i].p();
382  v += _jets[i].p();
383  return v;
384 }
385 
386 
388 //
389 // Purpose: Add a lepton to the event.
390 //
391 // Inputs:
392 // lep - The lepton to add.
393 //
394 {
395  _leps.push_back (lep);
396 }
397 
398 
400 //
401 // Purpose: Add a jet to the event.
402 //
403 // Inputs:
404 // jet - The jet to add.
405 //
406 {
407  _jets.push_back (jet);
408 }
409 
410 
411 void Lepjets_Event::smear (CLHEP::HepRandomEngine& engine, bool smear_dir /*= false*/)
412 //
413 // Purpose: Smear the objects in the event according to their resolutions.
414 //
415 // Inputs:
416 // engine - The underlying RNG.
417 // smear_dir - If false, smear the momentum only.
418 //
419 {
420  Fourvec before, after;
421  for (std::vector<Lepjets_Event_Lep>::size_type i=0; i < _leps.size(); i++) {
422  before += _leps[i].p();
423  _leps[i].smear (engine, smear_dir);
424  after += _leps[i].p();
425  }
426  for (std::vector<Lepjets_Event_Jet>::size_type i=0; i < _jets.size(); i++) {
427  before += _jets[i].p();
428  _jets[i].smear (engine, smear_dir);
429  after += _jets[i].p();
430  }
431 
432  Fourvec kt = _met + before;
434  kt(Fourvec::Y) = _kt_res.pick (kt(Fourvec::Y), kt(Fourvec::Y), engine);
435  _met = kt - after;
436 }
437 
438 
440 //
441 // Purpose: Sort the objects in the event in order of descending pt.
442 //
443 {
444  std::stable_sort (_leps.begin(), _leps.end(), not2 (less<Lepjets_Event_Lep> ()));
445  std::stable_sort (_jets.begin(), _jets.end(), not2 (less<Lepjets_Event_Lep> ()));
446 }
447 
448 
449 std::vector<int> Lepjets_Event::jet_types() const
450 //
451 // Purpose: Return the jet types of the event
452 //
453 {
454  std::vector<int> ret;
456  ijet != _jets.size() ;
457  ijet++) {
458  ret.push_back(jet(ijet).type());
459  }
460  return ret;
461 }
462 
463 
464 bool Lepjets_Event::set_jet_types(const std::vector<int>& _jet_types)
465 //
466 // Purpose: Set the jet types of the event
467 // Return false if it fails, trus if it succeeds
468 //
469 {
470  if (_jets.size() != _jet_types.size()) {
471  return false;
472  }
473  bool saw_hadw1 = false;
475  int t = _jet_types[i];
476  if (t == hadw1_label) {
477  if (saw_hadw1)
478  t = hadw2_label;
479  saw_hadw1 = true;
480  }
481  jet (i).type() = t;
482  }
483  return true;
484 }
485 
486 
487 namespace {
488 
489 
490 struct Lepjets_Event_Cutter
491 //
492 // Purpose: Helper for cutting on objects.
493 //
494 {
495  Lepjets_Event_Cutter (double pt_cut, double eta_cut)
496  : _pt_cut (pt_cut), _eta_cut (eta_cut)
497  {}
498  bool operator() (const Lepjets_Event_Lep& l) const;
499  double _pt_cut;
500  double _eta_cut;
501 };
502 
503 
504 bool Lepjets_Event_Cutter::operator () (const Lepjets_Event_Lep& l) const
505 //
506 // Purpose: Object cut evaluator.
507 //
508 {
509  return ! (l.p().perp() > _pt_cut && abs (l.p().pseudoRapidity()) < _eta_cut);
510 }
511 
512 
513 } // unnamed namespace
514 
515 
516 int Lepjets_Event::cut_leps (double pt_cut, double eta_cut)
517 //
518 // Purpose: Remove all leptons failing the pt and eta cuts.
519 //
520 // Inputs:
521 // pt_cut - Pt cut. Remove objects with pt less than this.
522 // eta_cut - Eta cut. Remove objects with abs(eta) larger than this.
523 //
524 // Returns:
525 // The number of leptons remaining after the cuts.
526 //
527 {
528  _leps.erase (remove_if (_leps.begin(), _leps.end(),
529  Lepjets_Event_Cutter (pt_cut, eta_cut)),
530  _leps.end ());
531  return _leps.size ();
532 }
533 
534 
535 int Lepjets_Event::cut_jets (double pt_cut, double eta_cut)
536 //
537 // Purpose: Remove all jets failing the pt and eta cuts.
538 //
539 // Inputs:
540 // pt_cut - Pt cut. Remove objects with pt less than this.
541 // eta_cut - Eta cut. Remove objects with abs(eta) larger than this.
542 //
543 // Returns:
544 // The number of jets remaining after the cuts.
545 //
546 {
547  _jets.erase (remove_if (_jets.begin(), _jets.end(),
548  Lepjets_Event_Cutter (pt_cut, eta_cut)),
549  _jets.end ());
550  return _jets.size ();
551 }
552 
553 
555 //
556 // Purpose: Remove all but the first N jets.
557 //
558 // Inputs:
559 // n - The number of jets to keep.
560 //
561 {
562  if (n >= _jets.size())
563  return;
564  _jets.erase (_jets.begin() + n, _jets.end());
565 }
566 
567 
568 std::ostream& Lepjets_Event::dump (std::ostream& s, bool full /*=false*/) const
569 //
570 // Purpose: Dump out this object.
571 //
572 // Inputs:
573 // s - The stream to which to write.
574 // full - If true, dump all information for this object.
575 //
576 // Returns:
577 // The stream S.
578 //
579 {
580  s << "Run: " << _runnum << " Event: " << _evnum << "\n";
581  s << "Leptons:\n";
582  for (std::vector<Lepjets_Event_Lep>::size_type i=0; i < _leps.size(); i++) {
583  s << " ";
584  _leps[i].dump (s, full);
585  s << "\n";
586  }
587  s << "Jets:\n";
588  for (std::vector<Lepjets_Event_Jet>::size_type i=0; i < _jets.size(); i++) {
589  s << " ";
590  _jets[i].dump (s, full);
591  s << "\n";
592  }
593  s << "Missing Et: " << _met << "\n";
594  if (_zvertex != 0)
595  s << "z-vertex: " << _zvertex << "\n";
596  return s;
597 }
598 
599 
601 //
602 // Purpose: Return a string representation of the jet permutation
603 // g - isr/gluon
604 // b - leptonic b
605 // B - hadronic b
606 // w - hadronic W
607 // h - Higgs to b-bbar
608 // ? - Unknown
609 {
610  std::string permutation;
611  for (size_t jet = 0 ; jet != _jets.size() ; ++jet) {
612  permutation = permutation + hitfit::jetTypeString(_jets[jet].type());
613  }
614  return permutation;
615 }
616 
625 std::ostream& operator<< (std::ostream& s, const Lepjets_Event& ev)
626 //
627 // Purpose: Dump out this object.
628 //
629 // Inputs:
630 // s - The stream to which to write.
631 // ev - The object to dump.
632 //
633 // Returns:
634 // The stream S.
635 //
636 {
637  return ev.dump (s);
638 }
639 
640 
641 } // namespace hitfit
642 
643 
644 
645 
646 
const int & runnum() const
Return a constant reference to the run number.
double zvertex() const
Return the value of z-vertex.
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
void trimjets(std::vector< Lepjets_Event_Jet >::size_type n)
Remove all but the first n jets.
Fourvec kt() const
Return the sum of all objects&#39; four-momentum and missing transverse energy.
Represent a lepton in an instance of Lepjets_Event class. This class hold the following information: ...
Lepjets_Event(int runnum, int evnum)
Constructor.
int cut_leps(double pt_cut, double eta_cut)
Remove leptons which fail transverse momentum and pseudorapidity cut.
Calculate and represent resolution for a physical quantity.
Definition: Resolution.h:102
int cut_jets(double pt_cut, double eta_cut)
Remove jets which fail transverse momentum and pseudorapidity cut.
Resolution & kt_res()
Return a reference to the resolution.
bool set_jet_types(const std::vector< int > &)
Set the jet types in the event.
void add_lep(const Lepjets_Event_Lep &lep)
Add a new lepton to the event.
assert(m_qm.get())
#define X(str)
Definition: MuonsGrabber.cc:48
std::vector< Lepjets_Event_Lep > _leps
bool ev
double pick(double x, double p, CLHEP::HepRandomEngine &engine) const
Generate random value from a Gaussian distribution described by this resolution. Given a value ...
Definition: Resolution.cc:227
uint16_t size_type
Lepjets_Event_Jet & jet(std::vector< Lepjets_Event_Jet >::size_type i)
Return a reference to jet at index position i.
void setMC(bool isMC)
Set the Monte Carlo flag.
double & dnn()
Return a reference to the value of neural network (NN) discriminant (Irrelevant for non-D0 experiment...
int & type()
Return a reference to the type code.
double & dlb()
Return a reference to the value of low-bias (LB) discriminant (Irrelevant for non-D0 experiment)...
std::string jetTypeString(int type)
Helper function: Translate jet type code from integer to char. The following notation is used for eac...
Represent a simple event consisting of lepton(s) and jet(s).
std::vector< Lepjets_Event_Jet >::size_type njets() const
Return the number of jets in the event.
std::vector< Lepjets_Event_Lep >::size_type nleps() const
Return the number of leptons in the event.
Represent a simple event consisting of lepton(s) and jet(s). An instance of this class holds a list o...
Definition: Lepjets_Event.h:66
std::vector< int > jet_types() const
Return the jet types in the event.
Definition: GenABIO.cc:180
CLHEP::HepLorentzVector Fourvec
Typedef for a HepLorentzVector.
Definition: fourvec.h:57
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
A class to represent a jet in an instance of Lepjets_Event class. The class is derived from the Lepje...
Fourvec sum(int type) const
Return the sum of all objects&#39; four-momentum which have a particular type.
double _pt_cut
Fourvec & met()
Return a reference to the missing transverse energy.
Lepjets_Event_Lep & lep(std::vector< Lepjets_Event_Lep >::size_type i)
Return a reference to lepton at index position i.
std::ostream & dump(std::ostream &s, bool full=false) const
Print the content of this object.
string const
Definition: compareJSON.py:14
void add_jet(const Lepjets_Event_Jet &jet)
Add a new jet to the event.
bool isMC() const
Return the Monte Carlo flag.
void sort()
Sort objects in the event according to their transverse momentum .
const int & evnum() const
Return a constant reference to the event number.
std::ostream & operator<<(std::ostream &s, const Constraint_Intermed &ci)
Output stream operator, print the content of this Constraint_Intermed to an output stream...
tuple runnum
Definition: summaryLumi.py:210
double _eta_cut
volatile std::atomic< bool > shutdown_flag false
std::vector< Lepjets_Event_Jet > _jets
std::string jet_permutation() const
Return a string representing the jet permutation. The following notation is used for each type of jet...
void smear(CLHEP::HepRandomEngine &engine, bool smear_dir=false)
Smear the objects in the event according to their resolutions.