CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
gentop.cc
Go to the documentation of this file.
1 //
2 // $Id: gentop.cc,v 1.1 2011/05/26 09:47:00 mseidel Exp $
3 //
4 // File: src/gentop.cc
5 // Purpose: Toy ttbar event generator for testing.
6 // Created: Jul, 2000, sss.
7 //
8 // CMSSW File : src/gentop.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 
39 #include "CLHEP/Random/RandFlat.h"
40 #include "CLHEP/Random/RandExponential.h"
41 #include "CLHEP/Random/RandBreitWigner.h"
42 #include "CLHEP/Random/RandGauss.h"
43 #include "CLHEP/Units/PhysicalConstants.h"
47 #include <cmath>
48 #include <ostream>
49 
50 
51 using std::ostream;
52 
53 
54 // Event number counter.
58 namespace {
59 int next_evnum = 0;
60 }
61 
62 
63 namespace hitfit {
64 
65 
66 //**************************************************************************
67 // Argument handling.
68 //
69 
70 
72 //
73 // Purpose: Constructor.
74 //
75 // Inputs:
76 // defs - The Defaults instance from which to initialize.
77 //
78  : _t_pt_mean (defs.get_float ("t_pt_mean")),
79  _mt (defs.get_float ("mt")),
80  _sigma_mt (defs.get_float ("sigma_mt")),
81  _mh (defs.get_float ("mh")),
82  _sigma_mh (defs.get_float ("sigma_mh")),
83  _recoil_pt_mean (defs.get_float ("recoil_pt_mean")),
84  _boost_sigma (defs.get_float ("boost_sigma")),
85  _m_boost (defs.get_float ("m_boost")),
86  _mb (defs.get_float ("mb")),
87  _sigma_mb (defs.get_float ("sigma_mb")),
88  _mw (defs.get_float ("mw")),
89  _sigma_mw (defs.get_float ("sigma_mw")),
90  _svx_tageff (defs.get_float ("svx_tageff")),
91  _smear (defs.get_bool ("smear")),
92  _smear_dir (defs.get_bool ("smear_dir")),
93  _muon (defs.get_bool ("muon")),
94  _ele_res_str (defs.get_string ("ele_res_str")),
95  _muo_res_str (defs.get_string ("muo_res_str")),
96  _jet_res_str (defs.get_string ("jet_res_str")),
97  _kt_res_str (defs.get_string ("kt_res_str"))
98 {
99 }
100 
101 
103 //
104 // Purpose: Return the t_pt_mean parameter.
105 // See the header for documentation.
106 //
107 {
108  return _t_pt_mean;
109 }
110 
111 
113 //
114 // Purpose: Return the mt parameter.
115 // See the header for documentation.
116 //
117 {
118  return _mt;
119 }
120 
121 
123 //
124 // Purpose: Return the sigma_mt parameter.
125 // See the header for documentation.
126 //
127 {
128  return _sigma_mt;
129 }
130 
131 
133 //
134 // Purpose: Return the svx_tageff parameter.
135 // See the header for documentation.
136 //
137 {
138  return _svx_tageff;
139 }
140 
141 
143 //
144 // Purpose: Return the mh parameter.
145 // See the header for documentation.
146 //
147 {
148  return _mh;
149 }
150 
151 
153 //
154 // Purpose: Return the sigma_mh parameter.
155 // See the header for documentation.
156 //
157 {
158  return _sigma_mh;
159 }
160 
161 
163 //
164 // Purpose: Return the smear parameter.
165 // See the header for documentation.
166 //
167 {
168  return _smear;
169 }
170 
171 
173 //
174 // Purpose: Return the smear_dir parameter.
175 // See the header for documentation.
176 //
177 {
178  return _smear_dir;
179 }
180 
181 
183 //
184 // Purpose: Return the muon parameter.
185 // See the header for documentation.
186 //
187 {
188  return _muon;
189 }
190 
191 
193 //
194 // Purpose: Return the recoil_pt_mean parameter.
195 // See the header for documentation.
196 //
197 {
198  return _recoil_pt_mean;
199 }
200 
201 
203 //
204 // Purpose: Return the boost_sigma parameter.
205 // See the header for documentation.
206 //
207 {
208  return _boost_sigma;
209 }
210 
211 
213 //
214 // Purpose: Return the m_boost parameter.
215 // See the header for documentation.
216 //
217 {
218  return _m_boost;
219 }
220 
221 
223 //
224 // Purpose: Return the mb parameter.
225 // See the header for documentation.
226 //
227 {
228  return _mb;
229 }
230 
231 
233 //
234 // Purpose: Return the sigma_mb parameter.
235 // See the header for documentation.
236 //
237 {
238  return _sigma_mb;
239 }
240 
241 
243 //
244 // Purpose: Return the mw parameter.
245 // See the header for documentation.
246 //
247 {
248  return _mw;
249 }
250 
251 
253 //
254 // Purpose: Return the sigma_mw parameter.
255 // See the header for documentation.
256 //
257 {
258  return _sigma_mw;
259 }
260 
261 
263 //
264 // Purpose: Return the ele_res_str parameter.
265 // See the header for documentation.
266 //
267 {
268  return _ele_res_str;
269 }
270 
271 
273 //
274 // Purpose: Return the muo_res_str parameter.
275 // See the header for documentation.
276 //
277 {
278  return _muo_res_str;
279 }
280 
281 
283 //
284 // Purpose: Return the jet_res_str parameter.
285 // See the header for documentation.
286 //
287 {
288  return _jet_res_str;
289 }
290 
291 
293 //
294 // Purpose: Return the kt_res_str parameter.
295 // See the header for documentation.
296 //
297 {
298  return _kt_res_str;
299 }
300 
301 
302 //**************************************************************************
303 // Internal helper functions.
304 //
305 
306 
307 namespace {
308 
309 
316 Threevec rand_spher (CLHEP::HepRandomEngine& engine)
317 //
318 // Purpose: Return a unit vector with (theta, phi) uniformly distributed
319 // over a sphere.
320 //
321 // Inputs:
322 // engine - The underlying RNG.
323 //
324 // Returns:
325 // The generated vector.
326 //
327 {
328  CLHEP::RandFlat r (engine);
329 
330  Threevec v;
331 
332  double U = r.fire(0.0,1.0);
333  double V = r.fire(0.0,1.0);
334 
335  double theta = 2.0*CLHEP::pi*U ;
336  double phi = acos(2*V - 1.0);
337 
338  double x = sin(theta)*cos(phi);
339  double y = sin(theta)*sin(phi);
340  double z = cos(theta);
341 
342  v = Threevec(x,y,z);
343 
344  return v.unit ();
345 }
346 
347 
362 Fourvec make_massive (const Threevec& p,
363  double m_true,
364  double sigma,
365  CLHEP::HepRandomEngine& engine)
366 //
367 // Purpose: Given a direction, mass, and width, choose a mass from a
368 // Breit-Wigner and return a 4-vector with the chosen mass
369 // and the specified direction.
370 //
371 // Inputs:
372 // p - The direction.
373 // m_true - The mean for the Breit-Wigner.
374 // sigma - The width for the Breit-Wigner.
375 // engine - The underlying RNG.
376 //
377 // Returns:
378 // The generated 4-vector.
379 //
380 {
381  CLHEP::RandBreitWigner rbw (engine);
382  double m = rbw.fire (m_true, sigma);
383  return Fourvec (p, sqrt (m*m + p.mag2()));
384 }
385 
403 void decay (const Fourvec& v, double m1, double m2,
404  CLHEP::HepRandomEngine& engine,
405  Fourvec& vout1, Fourvec& vout2)
406 //
407 // Purpose: v decays into two particles w/masses m1, m2.
408 //
409 // Inputs:
410 // v - The incoming 4-vector.
411 // m1 - Mass of the first decay product.
412 // m2 - Mass of the second decay product.
413 // engine - The underlying RNG.
414 //
415 // Outputs:
416 // vout1 - Outgoing 4-vector of the first decay product.
417 // vout2 - Outgoing 4-vector of the second decay product.
418 //
419 {
420  // Construct a decay in the incoming particle's rest frame,
421  // uniformly distributed in direction.
422  Threevec p = rand_spher (engine);
423  double m0 = v.m();
424 
425  if (m1 + m2 > m0) {
426  // What ya gonna do?
427  double f = m0 / (m1 + m2);
428  m1 *= f;
429  m2 *= f;
430  }
431 
432  double m0_2 = m0*m0;
433  double m1_2 = m1*m1;
434  double m2_2 = m2*m2;
435 
436  // Calculate the 3-momentum of each particle in the decay frame.
437  p *= 0.5/m0 * sqrt ( m0_2*m0_2 + m1_2*m1_2 + m2_2*m2_2
438  - 2*m0_2*m1_2 - 2*m0_2*m2_2 - 2*m1_2*m2_2);
439  double p2 = p.mag2();
440 
441  vout1 = Fourvec ( p, sqrt (p2 + m1_2));
442  vout2 = Fourvec (-p, sqrt (p2 + m2_2));
443 
444  // Boost out of the rest frame.
445  vout1.boost (v.boostVector ());
446  vout2.boost (v.boostVector ());
447 }
448 
449 
459 Threevec rand_pt (double pt_mean,
460  CLHEP::HepRandomEngine& engine)
461 //
462 // Purpose: Generate a vector in a (uniformly) random direction,
463 // with pt chosen from an exponential distribution with mean pt_mean.
464 //
465 // Inputs:
466 // pt_mean - The mean of the distribution.
467 // engine - The underlying RNG.
468 //
469 // Returns:
470 // The generated vector.
471 //
472 {
473  CLHEP::RandExponential rexp (engine);
474 
475  // A random direction.
476  Threevec p = rand_spher (engine);
477 
478  // Scale by random pt.
479  p *= (rexp.fire (pt_mean) / p.perp());
480 
481  return p;
482 }
483 
484 
492 Fourvec rand_boost (const Gentop_Args& args, CLHEP::HepRandomEngine& engine)
493 //
494 // Purpose: Generate a random boost for the event.
495 //
496 // Inputs:
497 // args - The parameter settings.
498 // engine - The underlying RNG.
499 //
500 // Returns:
501 // The generated boost.
502 //
503 {
504  CLHEP::RandExponential rexp (engine);
505  CLHEP::RandFlat rflat (engine);
506  CLHEP::RandGauss rgauss (engine);
507 
508  // Boost in pt and z.
509  Threevec p (1, 0, 0);
510  p.rotateZ (rflat.fire (0, 2 * M_PI));
511  p *= rexp.fire (args.recoil_pt_mean());
512  p.setZ (rgauss.fire (0, args.boost_sigma()));
513  return Fourvec (p, sqrt (p.mag2() + args.m_boost()*args.m_boost()));
514 }
515 
516 
526 void tagsim (const Gentop_Args& args,
527  Lepjets_Event& ev,
528  CLHEP::HepRandomEngine& engine)
529 //
530 // Purpose: Simulate SVX tagging.
531 //
532 // Inputs:
533 // args - The parameter settings.
534 // ev - The event to tag.
535 // engine - The underlying RNG.
536 //
537 // Outputs:
538 // ev - The event with tags filled in.
539 //
540 {
541  CLHEP::RandFlat rflat (engine);
542  for (std::vector<Lepjets_Event_Jet>::size_type i=0; i < ev.njets(); i++) {
543  int typ = ev.jet(i).type();
544  if (typ == hadb_label || typ == lepb_label || typ == higgs_label) {
545  if (rflat.fire() < args.svx_tageff())
546  ev.jet(i).svx_tag() = true;
547  }
548  }
549 }
550 
551 
552 } // unnamed namespace
553 
554 
555 //**************************************************************************
556 // External interface.
557 //
558 
559 
561  CLHEP::HepRandomEngine& engine)
562 //
563 // Purpose: Generate a ttbar -> ljets event.
564 //
565 // Inputs:
566 // args - The parameter settings.
567 // engine - The underlying RNG.
568 //
569 // Returns:
570 // The generated event.
571 //
572 {
573  CLHEP::RandBreitWigner rbw (engine);
574  CLHEP::RandGauss rgauss (engine);
575 
576  // Get the t decay momentum in the ttbar rest frame.
577  Threevec p = rand_pt (args.t_pt_mean(), engine);
578 
579  // Make the t/tbar vectors.
580  Fourvec lept = make_massive ( p, args.mt(), args.sigma_mt(), engine);
581  Fourvec hadt = make_massive (-p, args.mt(), args.sigma_mt(), engine);
582 
583  // Boost the rest frame.
584  Fourvec boost = rand_boost (args, engine);
585  lept.boost (boost.boostVector());
586  hadt.boost (boost.boostVector());
587 
588  // Decay t -> b W, leptonic side.
589  Fourvec lepb, lepw;
590  double mlb = rgauss.fire (args.mb(), args.sigma_mb());
591  double mlw = rbw.fire (args.mw(), args.sigma_mw());
592  decay (lept,
593  mlb,
594  mlw,
595  engine,
596  lepb,
597  lepw);
598 
599  // Decay t -> b W, hadronic side.
600  Fourvec hadb, hadw;
601  double mhb = rgauss.fire (args.mb(), args.sigma_mb());
602  double mhw = rbw.fire (args.mw(), args.sigma_mw());
603  decay (hadt,
604  mhb,
605  mhw,
606  engine,
607  hadb,
608  hadw);
609 
610  // Decay W -> l nu.
611  Fourvec lep, nu;
612  decay (lepw, 0, 0, engine, lep, nu);
613 
614  // Decay W -> qqbar.
615  Fourvec q1, q2;
616  decay (hadw, 0, 0, engine, q1, q2);
617 
618  // Fill in the event.
619  Lepjets_Event ev (0, ++next_evnum);
620  Vector_Resolution lep_res (args.muon() ?
621  args.muo_res_str() :
622  args.ele_res_str());
623  Vector_Resolution jet_res (args.jet_res_str());
624  Resolution kt_res = (args.kt_res_str());
625 
626  ev.add_lep (Lepjets_Event_Lep (lep,
627  args.muon() ? muon_label : electron_label,
628  lep_res));
629 
630  ev.add_jet (Lepjets_Event_Jet (lepb, lepb_label, jet_res));
631  ev.add_jet (Lepjets_Event_Jet (hadb, hadb_label, jet_res));
632  ev.add_jet (Lepjets_Event_Jet ( q1, hadw1_label, jet_res));
633  ev.add_jet (Lepjets_Event_Jet ( q2, hadw2_label, jet_res));
634 
635  ev.met() = nu;
636  ev.kt_res() = kt_res;
637 
638  // Simulate SVX tagging.
639  tagsim (args, ev, engine);
640 
641  // Smear the event, if requested.
642  if (args.smear())
643  ev.smear (engine, args.smear_dir());
644 
645  // Done!
646  return ev;
647 }
648 
649 
651  CLHEP::HepRandomEngine& engine)
652 //
653 // Purpose: Generate a ttH -> ljets event.
654 //
655 // Inputs:
656 // args - The parameter settings.
657 // engine - The underlying RNG.
658 //
659 // Returns:
660 // The generated event.
661 //
662 {
663  CLHEP::RandBreitWigner rbw (engine);
664  CLHEP::RandGauss rgauss (engine);
665 
666  // Generate three-vectors for two tops.
667  Threevec p_t1 = rand_pt (args.t_pt_mean(), engine);
668  Threevec p_t2 = rand_pt (args.t_pt_mean(), engine);
669 
670  // Conserve momentum.
671  Threevec p_h = -(p_t1 + p_t2);
672 
673  // Construct the 4-vectors.
674  Fourvec lept = make_massive (p_t1, args.mt(), args.sigma_mt(), engine);
675  Fourvec hadt = make_massive (p_t2, args.mt(), args.sigma_mt(), engine);
676  Fourvec higgs = make_massive ( p_h, args.mh(), args.sigma_mh(), engine);
677 
678  // Boost the rest frame.
679  Fourvec boost = rand_boost (args, engine);
680  lept.boost (boost.boostVector());
681  hadt.boost (boost.boostVector());
682  higgs.boost (boost.boostVector());
683 
684  // Decay t -> b W, leptonic side.
685  Fourvec lepb, lepw;
686  decay (lept,
687  rgauss.fire (args.mb(), args.sigma_mb()),
688  rbw.fire (args.mw(), args.sigma_mw()),
689  engine,
690  lepb,
691  lepw);
692 
693  // Decay t -> b W, hadronic side.
694  Fourvec hadb, hadw;
695  decay (hadt,
696  rgauss.fire (args.mb(), args.sigma_mb()),
697  rbw.fire (args.mw(), args.sigma_mw()),
698  engine,
699  hadb,
700  hadw);
701 
702  // Decay W -> l nu.
703  Fourvec lep, nu;
704  decay (lepw, 0, 0, engine, lep, nu);
705 
706  // Decay W -> qqbar.
707  Fourvec q1, q2;
708  decay (hadw, 0, 0, engine, q1, q2);
709 
710  // Decay H -> bbbar.
711  Fourvec hb1, hb2;
712  decay (higgs,
713  rgauss.fire (args.mb(), args.sigma_mb()),
714  rgauss.fire (args.mb(), args.sigma_mb()),
715  engine,
716  hb1,
717  hb2);
718 
719  // Fill in the event.
720  Lepjets_Event ev (0, ++next_evnum);
721  Vector_Resolution lep_res (args.muon() ?
722  args.muo_res_str() :
723  args.ele_res_str());
724  Vector_Resolution jet_res (args.jet_res_str());
725  Resolution kt_res = (args.kt_res_str());
726 
727  ev.add_lep (Lepjets_Event_Lep (lep,
728  args.muon() ? muon_label : electron_label,
729  lep_res));
730 
731  ev.add_jet (Lepjets_Event_Jet (lepb, lepb_label, jet_res));
732  ev.add_jet (Lepjets_Event_Jet (hadb, hadb_label, jet_res));
733  ev.add_jet (Lepjets_Event_Jet ( q1, hadw1_label, jet_res));
734  ev.add_jet (Lepjets_Event_Jet ( q2, hadw2_label, jet_res));
735  ev.add_jet (Lepjets_Event_Jet ( hb1, higgs_label, jet_res));
736  ev.add_jet (Lepjets_Event_Jet ( hb2, higgs_label, jet_res));
737 
738  ev.met() = nu;
739  ev.kt_res() = kt_res;
740 
741  // Simulate SVX tagging.
742  tagsim (args, ev, engine);
743 
744  // Smear the event, if requested.
745  if (args.smear())
746  ev.smear (engine, args.smear_dir());
747 
748  // Done!
749  return ev;
750 }
751 
752 
753 } // namespace hitfit
bool muon() const
Return the value of muon parameter.
Definition: gentop.cc:182
int i
Definition: DBlmapReader.cc:9
std::string muo_res_str() const
Return the value of muon_res_str parameter.
Definition: gentop.cc:272
std::string _jet_res_str
Definition: gentop.h:342
Define an abstract interface for getting parameter settings.
double _sigma_mt
Definition: gentop.h:257
Represent a lepton in an instance of Lepjets_Event class. This class hold the following information: ...
double boost_sigma() const
Return the value of boost_sigma parameter.
Definition: gentop.cc:202
Define three-vector and four-vector classes for the HitFit package, and supply a few additional opera...
Calculate and represent resolution for a physical quantity.
Definition: Resolution.h:103
double mh() const
Return the value of mh parameter.
Definition: gentop.cc:142
Gentop_Args(const Defaults &defs)
Constructor, initialize an instance of Gentop_Args from an instance of Defaults object.
Definition: gentop.cc:71
Resolution & kt_res()
Return a reference to the resolution.
double _t_pt_mean
Definition: gentop.h:247
double mw() const
Return the value of mw parameter.
Definition: gentop.cc:242
void add_lep(const Lepjets_Event_Lep &lep)
Add a new lepton to the event.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Lepjets_Event gentth(const Gentop_Args &args, CLHEP::HepRandomEngine &engine)
Generate a event.
Definition: gentop.cc:650
Geom::Theta< T > theta() const
double _sigma_mh
Definition: gentop.h:267
std::string jet_res_str() const
Return the value of jet_res_str parameter.
Definition: gentop.cc:282
double _svx_tageff
Definition: gentop.h:309
uint16_t size_type
double double double z
std::string _kt_res_str
Definition: gentop.h:348
double q2[4]
Definition: TauolaWrapper.h:88
double sigma_mt() const
Return the value of sigma_mt parameter.
Definition: gentop.cc:122
double sigma_mh() const
Return the value of sigma_mh parameter.
Definition: gentop.cc:152
double _sigma_mb
Definition: gentop.h:293
double _recoil_pt_mean
Definition: gentop.h:273
double sigma_mb() const
Return the value of sigma_mb parameter.
Definition: gentop.cc:232
Represent a simple event consisting of lepton(s) and jet(s).
std::string kt_res_str() const
Return the value of kt_res_str parameter.
Definition: gentop.cc:292
T sqrt(T t)
Definition: SSEVec.h:46
double recoil_pt_mean() const
Return the value of recoil_pt_mean parameter.
Definition: gentop.cc:192
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
double mb() const
Return the value of mb parameter.
Definition: gentop.cc:222
Lepjets_Event gentop(const Gentop_Args &args, CLHEP::HepRandomEngine &engine)
Generate a event.
Definition: gentop.cc:560
std::string _ele_res_str
Definition: gentop.h:332
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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...
double sigma_mw() const
Return the value of sigma_mw parameter.
Definition: gentop.cc:252
double f[11][100]
double _sigma_mw
Definition: gentop.h:303
bool smear_dir() const
Return the value of smear_dir parameter.
Definition: gentop.cc:172
double p2[4]
Definition: TauolaWrapper.h:90
Hold on to parameters for the toy event generator.
Definition: gentop.h:74
double mt() const
Return the value of mt parameter.
Definition: gentop.cc:112
Fourvec & met()
Return a reference to the missing transverse energy.
double m_boost() const
Return the value of m_boost parameter.
Definition: gentop.cc:212
#define M_PI
Definition: BFit3D.cc:3
CLHEP::Hep3Vector Threevec
Typedef for a Hep3Vector.
Definition: fourvec.h:63
std::string _muo_res_str
Definition: gentop.h:337
double q1[4]
Definition: TauolaWrapper.h:87
string const
Definition: compareJSON.py:14
std::string ele_res_str() const
Return the value of ele_res_str parameter.
Definition: gentop.cc:262
void add_jet(const Lepjets_Event_Jet &jet)
Add a new jet to the event.
dictionary args
Define an interface for getting parameter settings.
Definition: Defaults.h:62
double _boost_sigma
Definition: gentop.h:278
bool smear() const
Return the value of smear parameter.
Definition: gentop.cc:162
double pi
Definition: DDAxes.h:10
Calculate and represent resolution for a vector of , pseudorapidity , and azimuthal angle ...
A toy event generator for events.
void smear(CLHEP::HepRandomEngine &engine, bool smear_dir=false)
Smear the objects in the event according to their resolutions.
mathSSE::Vec4< T > v
double svx_tageff() const
Return the value of svx_tageff parameter.
Definition: gentop.cc:132
double t_pt_mean() const
Return the value of t_pt_mean parameter.
Definition: gentop.cc:102
Definition: DDAxes.h:10