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