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