ATLAS Offline Software
Samplers.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Helper for MultiParticleGunPileup
6 // Olivier Arnaez, started 17/12/15
7 // adapted from Generators/ParticleGun/python/samplers.py
8 
9 #include "TLorentzVector.h"
10 #include "TRandom.h"
11 #include "TMath.h"
12 #include <map>
13 #include <vector>
14 #include <iostream>
15 #include <string>
16 
17 //Base class for all samplers
18 class Sampler {
19  public:
20  Sampler() : m_val(0.) {};
21  virtual ~Sampler(){};
22  virtual float shoot() {return m_val;};
23  //float operator () { return this->shoot();};
24  float m_val;
25  TRandom m_random;
26 };
27 
28 //A special-case sampler which just returns one value rather than sampling.
29 class ConstSampler : public Sampler {
30  public:
34  virtual float shoot() { return m_val;};
35  //std::string str() { return std::string("ConstSampler[%s]" + m_val);};
36 };
37 
38 class MomSampler {
39  public:
40  MomSampler() : m_mass(NULL) {};
42  virtual TLorentzVector shoot() {return m_val;};
43  TLorentzVector m_val;
45 };
46 
47 //--------------------------------
48 //Continuous distribution samplers
49 //--------------------------------
50 
51 //Uniformly sample in the range [low,high).
52 class UniformSampler : public Sampler {
53  public:
55  UniformSampler(float low, float high) {
56  assert(low <= high);
57  m_low = float(low);
58  m_high = float(high);
59  };
61  float shoot() { return Sampler::m_random.Uniform(m_low, m_high); };
62 
63  float m_low, m_high;
64 };
65 
66 //Uniformly sample in the modulus range (-high,low]+[low,high).
68  public:
70  ModUniformSampler(float low, float high) : UniformSampler (low, high){
71  assert(low == fabs(low) && high == fabs(high));
72  assert(low <= high);
73  m_low = float(low);
74  m_high = float(high);
75  };
76 
77  float shoot() {
78  m_val = m_random.Uniform(m_low, m_high);
79  if (m_random.Uniform() > 0.5)
80  m_val *= -1;
81  return m_val;
82  };
83 };
84 
85 //Uniformly sample from a set of disjoint intervals.
87  /* The ranges variable can either be a list of increasing numbers or a
88  list of pairs of numbers.
89 
90  The former case will be treated as
91  defining alternating on/off ranges for sampling, starting with an active
92  one (i.e. it's a list of bin edges). The latter way specifically lists
93  the 'on' regions only, with their start and end values in the pairs.
94 
95  The behaviour is undefined if the numbers are not ordered or overlap --
96  i.e. it might work but hasn't been designed that way and might change in
97  future. Don't rely on this behaviour!
98  */
99  public:
101  DisjointUniformSampler(std::vector<float> ranges) {
102  for (unsigned int i=0; i<ranges.size();) {
103  std::pair<float,float> p(ranges[i],ranges[i+1]);
104  i+=2;
105  m_ranges.push_back(p);
106  }
107  _setRanges();
108  };
109  DisjointUniformSampler(std::vector< std::pair<float,float> > ranges) { m_ranges = ranges; _setRanges();};
110 
111  std::vector< std::pair<float,float> > _getRanges() { return m_ranges; };
112 
113  void _setRanges() {
114  for (unsigned int i=0; i<m_ranges.size(); i++) {
115  m_totalwidth += m_ranges[i].second - m_ranges[i].first;
116  };
117  float runningwidth = 0.0;
118  m_divisions.push_back(0.0);
119  for (unsigned int i=0; i<m_ranges.size(); i++) {
120  assert(m_ranges[i].second >= m_ranges[i].first);
121  runningwidth += float(m_ranges[i].second - m_ranges[i].first);
122  m_divisions.push_back(runningwidth);
123  }
124  m_totalwidth = runningwidth;
125  for (unsigned int i=0; i<m_ranges.size(); i++)
127  };
128 
129  float _map_unit_to_val(float x){
130  assert(x >= 0 && x <= 1);
131  unsigned int idx = -1, rem = 0;
132  for (unsigned int i=0; i<m_divisions.size()-1; i++)
133  if (x >= m_divisions[i] and x < m_divisions[i+1]) {
134  idx = i;
135  rem = x - m_divisions[i];
136  break;
137  }
138  float val = m_ranges[idx].first + m_totalwidth * rem;
139  return val;
140  };
141 
142  float shoot(){
143  float rand = m_random.Uniform();
144  float val = _map_unit_to_val(rand);
145  return val;
146  };
147  private:
148  std::vector< std::pair<float,float> > m_ranges;
150  std::vector<float> m_divisions;
151 };
152 
153 //Randomly sample from an exponential distribution (i.e. uniformly on a log scale).
154 class LogSampler : public UniformSampler {
155  public:
156  LogSampler(float low, float high): UniformSampler (low, high){
157  m_low = low;
158  m_high = high;
159  };
161 
162  float shoot(){
163  float rand = m_random.Uniform();
164  float logval = rand * TMath::Log(m_high) + (1 - rand) * TMath::Log(m_low);
165  float val = TMath::Exp(logval);
166  return val;
167  };
168 };
169 
170 //Randomly sample from a 1D Gaussian distribution.
172  public:
174  GaussianSampler(float mean, float sigma): UniformSampler (0, 1){
175  m_mean = mean;
176  m_sigma = sigma;
177  }
178 
179  float shoot() { return m_random.Gaus(m_mean, m_sigma);};
180  private:
182 };
183 
184 
185 /*//Randomly sample from a 1D ROOT histogram.
186 class TH1Sampler : UniformSampler {
187  ~TH1Sampler(){};
188  def __init__(self, *args):
189  m_hist = TH1(*args)
190  if m_hist.GetEntries() < 1:
191  raise Exception("Histogram %s is EMPTY! Cannot sample" % m_hist.GetName())
192 
193  def shoot(self):
194  return m_hist.GetRandom()
195 */
196 
197 
198 // Discrete sequence samplers
199 /*
200 //Uniformly random sample from a list of values.
201 class RandomSeqSampler :Sampler {
202  ~RandomSeqSampler(){};
203 
204  def __init__(self, *args):
205  if len(args) == 1:
206  m_sequence = args[0]
207  else:
208  m_sequence = args
209 
210  def shoot(self):
211  return random.choice(m_sequence)
212 # Alias:
213 RndmSeq = RandomSeqSampler
214 */
215 
216 //Sequentially sample from a list of values, returning to the beginning once exhausted.
217 class CyclicSeqSampler : public Sampler {
218  public:
221  CyclicSeqSampler(std::string s) {
222  size_t pos = 0;
223  std::string token;
224  std::cout << "Initializing CyclicSeqSampler..." << std::endl;
225  while ((pos = s.find(',')) != std::string::npos) {
226  token = s.substr(0, pos);
227  m_sequence.push_back(std::stoi(token));
228  s.erase(0, pos + 1);
229  std::cout << " adding " << m_sequence[m_sequence.size()-1] << " from " << token.c_str() << std::endl;
230  }
231  m_index = 0;
232  };
233  float shoot() {
234  m_index = (m_index + 1) % m_sequence.size();
235  std::cout << "CyclicSeqSampler returning " << m_sequence[m_index] << std::endl;
236  return m_sequence[m_index];
237  };
238  private:
239  std::vector<int> m_sequence;
240  int m_index;
241 };
242 
243 // Convenience function for sampler-making from Python literals
244 /*
245 Sampler mksampler(x){
246 
247 // Automatically cast the provided object to a sampler type. This is used
248 // extensively inside the particle and position samplers, so that the user
249 // can pass in a primitive type like a number or list and it will be
250 // treated as if the more verbose sampler constructors had been called.
251 //
252 // Behaviour:
253 // - if x can be called, i.e. x() is valid, we just return x;
254 // - a Python list (square brackets) will be converted to a continuous
255 // UniformSampler or DisjointUniformSampler;
256 // - TODO: a Python tuple (round brackets/parentheses) will be treated
257 // as a discrete CyclicSeqSampler;
258 // - TODO: a Python set (curly brackets/braces) will be treated
259 // as a discrete RandomSeqSampler;
260 // - otherwise a ConstSampler will be created from x, so that x is
261 // returned when the sampler is called.
262 
263  if hasattr(x, "__call__"):
264  return x
265  elif type(x) is list:
266  # NB: disjoint ranges can be given as nested lists, e.g. [(1,2), (4,5)]
267  if len(x) == 2 and type(x[0]) in (int,float) and type(x[1]) in (int,float):
268  #print "MKSAMPLER: Casting %s to UniformSampler" % str(x)
269  return UniformSampler(*x)
270  elif len(x) > 2 or (len(x) > 0 and type(x[0]) not in (int,float)):
271  #print "MKSAMPLER: Casting %s to DisjointUniformSampler" % str(x)
272  return DisjointUniformSampler(x)
273  if len(x) < 2:
274  raise Exception("Supplied list could not be converted to a continuous sampler")
275  elif type(x) is tuple:
276  #print "MKSAMPLER: Casting %s to CyclicSeqSampler" % str(x)
277  return CyclicSeqSampler(*x)
278  elif type(x) is set:
279  #print "MKSAMPLER: Casting %s to RandomSeqSampler" % str(x)
280  return RandomSeqSampler(*x)
281  else:
282  #print "MKSAMPLER: Casting %s to ConstSampler" % str(x)
283  return ConstSampler(x)
284 */
285 
286 
287 // Beam-spot (origin vertex) sampling
288 //Sampler of position 3-vectors, for modelling a beamspot.
289 class PosSampler {
290  public:
293  PosSampler(float x, float y, float z, float t=0) {
294  m_x = ConstSampler(x);
295  m_y = ConstSampler(y);
296  m_z = ConstSampler(z);
297  m_t = ConstSampler(t);
298  }
299 
300  TLorentzVector shoot(){
301  float x = m_x.shoot();
302  float y = m_y.shoot();
303  float z = m_z.shoot();
304  float t = m_t.shoot();
305  return TLorentzVector(x, y, z, t);
306  }
307  private:
309 };
310 
311 // Momentum sampling
312 //A momentum sampler which just returns a null vector with the given mass.
313 class NullMomSampler : public MomSampler{
314  public:
316  NullMomSampler(float mass=0.0) { m_mass = new ConstSampler(mass);};
317 
318  TLorentzVector shoot() {
319  return TLorentzVector(0, 0, 0, m_mass->shoot());
320  }
321 };
322 
323 /*
324 class MXYZSampler(MomSampler):
325  "Create a 4-momentum vector from mass, px, py, pz distributions/samplers."
326 
327  def __init__(self, px, py, pz, mass=0.0):
328  m_mass = mass
329  m_px = px
330  m_py = py
331  m_pz = pz
332 
333  @property
334  def mass(self):
335  "Mass sampler"
336  return m__m
337  @mass.setter
338  def mass(self, x):
339  m__m = mksampler(x)
340 
341  @property
342  def px(self):
343  "px sampler"
344  return m__px
345  @px.setter
346  def px(self, x):
347  m__px = mksampler(x)
348 
349  @property
350  def py(self):
351  "py sampler"
352  return m__py
353  @py.setter
354  def py(self, x):
355  m__py = mksampler(x)
356 
357  @property
358  def pz(self):
359  "pz sampler"
360  return m__pz
361  @pz.setter
362  def pz(self, x):
363  m__pz = mksampler(x)
364 
365  def shoot(self):
366  m = m_mass()
367  px = m_px()
368  py = m_py()
369  pz = m_pz()
370  e = math.sqrt(px**2 + py**2 + pz**2 + m**2)
371  v4 = ROOT.TLorentzVector(px, py, pz, e)
372  return v4
373 
374 
375 class EEtaMPhiSampler(MomSampler):
376  "Create a 4-momentum vector from E, eta, m and phi distributions/samplers."
377 
378  # TODO: ensure that E >= m!
379 
380  def __init__(self, energy, eta, mass=0.0, phi=[0, TWOPI]):
381  m_energy = energy
382  m_eta = eta
383  m_mass = mass
384  m_phi = phi
385 
386  @property
387  def energy(self):
388  "Energy sampler"
389  return m__e
390  @energy.setter
391  def energy(self, x):
392  m__e = mksampler(x)
393 
394  @property
395  def eta(self):
396  "Pseudorapidity sampler"
397  return m__eta
398  @eta.setter
399  def eta(self, x):
400  m__eta = mksampler(x)
401 
402  @property
403  def mass(self):
404  "Mass sampler"
405  return m__m
406  @mass.setter
407  def mass(self, x):
408  m__m = mksampler(x)
409 
410  @property
411  def phi(self):
412  "Azimuthal angle sampler"
413  return m__phi
414  @phi.setter
415  def phi(self, x):
416  m__phi = mksampler(x)
417 
418  def shoot(self):
419  """
420  eta = - ln(tan(theta/2)) / 2
421  => theta = 2 atan( exp(-eta) )
422  """
423  eta = m_eta()
424  theta = 2 * math.atan(math.exp(-eta));
425  e = m_energy()
426  m = m_mass()
427  p = math.sqrt( e**2 - m**2 )
428  pz = p * math.cos(theta)
429  pt = p * math.sin(theta)
430  phi = m_phi()
431  px = pt * math.cos(phi)
432  py = pt * math.sin(phi)
433  v4 = ROOT.TLorentzVector(px, py, pz, e)
434  return v4
435 
436 
437 class ERapMPhiSampler(MomSampler):
438  "Create a 4-momentum vector from E, y, m and phi distributions."
439 
440  # TODO: ensure that E >= m!
441 
442  def __init__(self, energy, eta, mass=0.0, phi=[0, TWOPI]):
443  m_energy = energy
444  m_rap = rap
445  m_mass = mass
446  m_phi = phi
447 
448  @property
449  def energy(self):
450  "Energy sampler"
451  return m__e
452  @energy.setter
453  def energy(self, x):
454  m__e = mksampler(x)
455 
456  @property
457  def rap(self):
458  "Rapidity sampler"
459  return m__rap
460  @rap.setter
461  def rap(self, x):
462  m__rap = mksampler(x)
463 
464  @property
465  def mass(self):
466  "Mass sampler"
467  return m__m
468  @mass.setter
469  def mass(self, x):
470  m__m = mksampler(x)
471 
472  @property
473  def phi(self):
474  "Azimuthal angle sampler"
475  return m__phi
476  @phi.setter
477  def phi(self, x):
478  m__phi = mksampler(x)
479 
480  def shoot(self):
481  """
482  y = 0.5 * ln((E+pz)/(E-pz))
483  -> (E^2 - pz^2) exp(2y) = (E+pz)^2
484  & (E^2 - pz^2) exp(-2y) = (E-pz)^2
485  -> E = sqrt(pt^2 + m^2) cosh(y)
486  -> pz = sqrt(pt^2 + m^2) sinh(y)
487  -> sqrt(pt^2 + m^2) = E / cosh(y)
488  """
489  e = m_energy()
490  y = m_rap()
491  sqrt_pt2_m2 = e / math.cosh(y)
492  pz = sqrt_pt2_m2 * math.sinh(y)
493  m = m_mass()
494  pt = math.sqrt( sqrt_pt2_m2**2 - m**2 )
495  phi = m_phi()
496  px = pt * math.cos(phi);
497  py = pt * math.sin(phi);
498  v4 = ROOT.TLorentzVector(px, py, pz, e)
499  return v4
500 
501 
502 class EThetaMPhiSampler(MomSampler):
503  "Create a 4-momentum vector from E, theta, m and phi distributions/samplers."
504 
505  # TODO: ensure that E >= m!
506 
507  def __init__(self, energy, theta, mass=0.0, phi=[0, TWOPI]):
508  m_energy = energy
509  m_theta = theta
510  m_mass = mass
511  m_phi = phi
512 
513  @property
514  def energy(self):
515  "Energy sampler"
516  return m__e
517  @energy.setter
518  def energy(self, x):
519  m__e = mksampler(x)
520 
521  @property
522  def theta(self):
523  "Polar angle sampler"
524  return m__theta
525  @theta.setter
526  def theta(self, x):
527  m__theta = mksampler(x)
528 
529  @property
530  def mass(self):
531  "Mass sampler"
532  return m__m
533  @mass.setter
534  def mass(self, x):
535  m__m = mksampler(x)
536 
537  @property
538  def phi(self):
539  "Azimuthal angle sampler"
540  return m__phi
541  @phi.setter
542  def phi(self, x):
543  m__phi = mksampler(x)
544 
545  def shoot(self):
546  """
547  p = sqrt(e^2 - m^2)
548  pz = p cos(theta)
549  pt = p sin(theta)
550  """
551  e = m_energy()
552  m = m_mass()
553  p = math.sqrt( e**2 - m**2 )
554  theta = m_theta()
555  pz = p * math.cos(theta)
556  pt = p * math.sin(theta)
557  phi = m_phi()
558  px = pt * math.cos(phi)
559  py = pt * math.sin(phi)
560  v4 = ROOT.TLorentzVector(px, py, pz, e)
561  return v4
562 
563 */
564 
565 //Create a 4-momentum vector from pt, eta, m and phi distributions/samplers.
567  public:
568  ~PtEtaMPhiSampler() { if (m_pt) delete m_pt; if (m_eta) delete m_eta; if (m_phi) delete m_phi;};
569  PtEtaMPhiSampler(float ptmin, float ptmax, float etamin, float etamax, float mass=0.0, float phimin=0, float phimax=2.*TMath::Pi()){
570  if (ptmin==ptmax)
571  m_pt = new ConstSampler(ptmin);
572  else
574  if (etamin==etamax)
575  m_eta = new ConstSampler(etamin);
576  else
577  m_eta = new UniformSampler(etamin,etamax);
578  m_mass = new ConstSampler(mass);
579  if (phimin==phimax)
580  m_phi = new ConstSampler(phimin);
581  else
582  m_phi = new UniformSampler(phimin,phimax);
583  };
584 
585  TLorentzVector shoot() {
586  float eta = m_eta->shoot();
587  float pt = m_pt->shoot();
588  float phi = m_phi->shoot();
589  //float theta = 2. * TMath::ATan(TMath::Exp(-eta));
590  //float p = pt / TMath::Sin(theta);
591  //float px = pt * TMath::Cos(phi);
592  //float py = pt * TMath::Sin(phi);
593  //float pz = p * TMath::Cos(theta);
594  //float e = sqrt( p*p + m*m );
595  float m = m_mass->shoot();
596  TLorentzVector tlv; tlv.SetPtEtaPhiM(pt,eta,phi,m);
597  return tlv;
598  };
599 
600  private:
602 };
603  /*
604 
605 class PtRapMPhiSampler(MomSampler):
606  "Create a 4-momentum vector from pt, y, m and phi distributions/samplers."
607 
608  def __init__(self, pt, rap, mass=0.0, phi=[0, TWOPI]):
609  m_pt = pt
610  m_rap = rap
611  m_mass = mass
612  m_phi = phi
613 
614  @property
615  def pt(self):
616  "Transverse momentum sampler"
617  return m__pt
618  @pt.setter
619  def pt(self, x):
620  m__pt = mksampler(x)
621 
622  @property
623  def rap(self):
624  "Rapidity sampler"
625  return m__rap
626  @rap.setter
627  def rap(self, x):
628  m__rap = mksampler(x)
629 
630  @property
631  def mass(self):
632  "Mass sampler"
633  return m__m
634  @mass.setter
635  def mass(self, x):
636  m__m = mksampler(x)
637 
638  @property
639  def phi(self):
640  "Azimuthal angle sampler"
641  return m__phi
642  @phi.setter
643  def phi(self, x):
644  m__phi = mksampler(x)
645 
646  def shoot(self):
647  """
648  y = 0.5 * ln((E+pz)/(E-pz))
649  -> (E^2 - pz^2) exp(2y) = (E+pz)^2
650  & (E^2 - pz^2) exp(-2y) = (E-pz)^2
651  -> E = sqrt(pt^2 + m^2) cosh(y)
652  -> pz = sqrt(pt^2 + m^2) sinh(y)
653  -> sqrt(pt^2 + m^2) = E / cosh(y)
654  """
655  pt = m_pt()
656  assert pt >= 0
657  m = m_mass()
658  assert m >= 0
659  sqrt_pt2_m2 = math.sqrt( pt**2 + m**2 )
660  y = m_rap()
661  e = sqrt_pt2_m2 * math.cosh(y)
662  pz = sqrt_pt2_m2 * math.sinh(y)
663  phi = m_phi()
664  px = pt * math.cos(phi);
665  py = pt * math.sin(phi);
666  v4 = ROOT.TLorentzVector(px, py, pz, e)
667  return v4
668 
669 
670 class PtThetaMPhiSampler(MomSampler):
671  "Create a 4-momentum vector from pt, theta, m and phi distributions/samplers."
672 
673  def __init__(self, pt, theta, mass=0.0, phi=[0, TWOPI]):
674  m_pt = pt
675  m_theta = theta
676  m_mass = mass
677  m_phi = phi
678 
679  @property
680  def pt(self):
681  "Transverse momentum sampler"
682  return m__pt
683  @pt.setter
684  def pt(self, x):
685  m__pt = mksampler(x)
686 
687  @property
688  def theta(self):
689  "Polar angle sampler"
690  return m__theta
691  @theta.setter
692  def theta(self, x):
693  m__theta = mksampler(x)
694 
695  @property
696  def mass(self):
697  "Mass sampler"
698  return m__m
699  @mass.setter
700  def mass(self, x):
701  m__m = mksampler(x)
702 
703  @property
704  def phi(self):
705  "Azimuthal angle sampler"
706  return m__phi
707  @phi.setter
708  def phi(self, x):
709  m__phi = mksampler(x)
710 
711  def shoot(self):
712  """
713  p = pt / math.sin(theta)
714  pz = p cos(theta)
715  pt = p sin(theta)
716  E = sqrt(p^2 + m^2)
717  """
718  theta = m_theta()
719  pt = m_pt()
720  p = pt / math.sin(theta)
721  phi = m_phi()
722  px = pt * math.cos(phi)
723  py = pt * math.sin(phi)
724  pz = p * math.cos(theta)
725  m = m_mass()
726  e = math.sqrt( p**2 + m**2 )
727  v4 = ROOT.TLorentzVector(px, py, pz, e)
728  return v4
729 
730 
731 # TODO: add the missing ways to specify/sample 4-momenta
732 
733 
734 ###########################################################
735 
736 */
737 // Combined samplers returning a particle configuration
738 
739 // A particle object for use as a return value from the particle samplers
741  public:
743  SampledParticle(int pid=0, TLorentzVector mom=TLorentzVector(0,0,0,0), TLorentzVector pos= TLorentzVector(0,0,0,0)) {
744  // Constructor/initializer: PID is the (int) PDG particle ID code
745  // of this particle, mom is its momentum 4-vector, and pos is
746  // the vertex 4-position (both as ROOT.TLorentzVector, in MeV).
747  m_pid = pid;
748  m_mom = mom;
749  m_pos = pos;
750  m_mass = 0;
751  }
752  int m_pid;
753  TLorentzVector m_mom, m_pos;
754  float m_mass;
755 };
756 
757 // A simple N-independent-particle sampler.
759  public:
762  m_pid = pid;
763  m_mom=mom;
764  m_n = ConstSampler(n);
765  m_pos = PosSampler(0,0,0);
766  // A default dictionary of particle masses (in MeV)
767  m_massdict[22 ] = 0.0; // photon
768  m_massdict[11 ] = 0.5; // electron
769  m_massdict[12 ] = 0.0; // nu_e
770  m_massdict[13 ] = 105.7; // muon
771  m_massdict[14 ] = 0.0; // nu_mu
772  m_massdict[15 ] = 1777.8; // tau
773  m_massdict[16 ] = 0.0; // nu_tau
774  m_massdict[2212] = 938.0; // proton
775  m_massdict[2112] = 940.0; // neutron
776  m_massdict[111 ] = 135.0; // pi0
777  m_massdict[211 ] = 140.0; // pi+-
778  m_massdict[221 ] = 547.0; // eta
779  m_massdict[321 ] = 494.0; // K+-
780  m_massdict[311 ] = 598.0; // K0
781  m_mass_override = true;
782  };
783 
784  //Return a vector of sampled particles
785  std::vector<SampledParticle> shoot() {
786  int numparticles = m_n.shoot();
787  std::cout << "ParticleSampler throwing " << numparticles << " particles" << std::endl;
788  std::vector<SampledParticle> rtn;
789  for (int i=0; i<numparticles ; i++){
790  //Sample the particle ID and create a particle
791  int pid = m_pid->shoot();
792  std::cout << " shot pid=" << pid << std::endl;
794  // Pass mass info to the v4 sampler and set same generated mass
795  if (m_mass_override && m_massdict.find(abs(pid))!=m_massdict.end()){
796  float m = m_massdict[abs(pid)];
797  m_mom->m_mass = new ConstSampler(m);
798  p.m_mass = m;
799  }
800  // Sample momentum and vertex positions into the particle
801  p.m_mom = m_mom->shoot();
802  p.m_pos = m_pos.shoot();
803  std::cout << " (" << p.m_mom.Eta() << ", " << p.m_mom.Phi() << ", " << p.m_mom.E() << ", " << p.m_mom.M() << ")" << std::endl;
804  // Add particle to output list
805  rtn.push_back(p);
806  }
807  return rtn;
808  }
809  private:
815  std::map<unsigned int,float> m_massdict;
816 };
PosSampler::PosSampler
PosSampler(float x, float y, float z, float t=0)
Definition: Samplers.h:293
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
trigbs_pickEvents.ranges
ranges
Definition: trigbs_pickEvents.py:60
ParticleSampler::m_massdict
std::map< unsigned int, float > m_massdict
Definition: Samplers.h:815
CyclicSeqSampler::~CyclicSeqSampler
~CyclicSeqSampler()
Definition: Samplers.h:219
ModUniformSampler::~ModUniformSampler
~ModUniformSampler()
Definition: Samplers.h:69
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Sampler::m_val
float m_val
Definition: Samplers.h:22
UniformSampler::~UniformSampler
~UniformSampler()
Definition: Samplers.h:60
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
ptmax
double ptmax
Definition: dependence.cxx:60
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
DisjointUniformSampler::~DisjointUniformSampler
~DisjointUniformSampler()
Definition: Samplers.h:100
PtEtaMPhiSampler::m_pt
Sampler * m_pt
Definition: Samplers.h:598
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
GaussianSampler::shoot
float shoot()
Definition: Samplers.h:179
MomSampler
Definition: Samplers.h:38
DisjointUniformSampler::m_divisions
std::vector< float > m_divisions
Definition: Samplers.h:150
NullMomSampler::NullMomSampler
NullMomSampler(float mass=0.0)
Definition: Samplers.h:316
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
DisjointUniformSampler::DisjointUniformSampler
DisjointUniformSampler(std::vector< float > ranges)
Definition: Samplers.h:101
MomSampler::shoot
virtual TLorentzVector shoot()
Definition: Samplers.h:42
TrigJetMonitorAlgorithm.ptmin
ptmin
Definition: TrigJetMonitorAlgorithm.py:1081
GaussianSampler::m_mean
float m_mean
Definition: Samplers.h:179
test_pyathena.pt
pt
Definition: test_pyathena.py:11
DisjointUniformSampler::m_totalwidth
float m_totalwidth
Definition: Samplers.h:149
MomSampler::m_mass
ConstSampler * m_mass
Definition: Samplers.h:44
ModUniformSampler
Definition: Samplers.h:67
NullMomSampler::~NullMomSampler
~NullMomSampler()
Definition: Samplers.h:315
GaussianSampler::GaussianSampler
GaussianSampler(float mean, float sigma)
Definition: Samplers.h:174
LogSampler::~LogSampler
~LogSampler()
Definition: Samplers.h:160
UniformSampler::UniformSampler
UniformSampler(float low, float high)
Definition: Samplers.h:55
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ParticleSampler::m_mass_override
bool m_mass_override
Definition: Samplers.h:814
Sampler::shoot
virtual float shoot()
Definition: Samplers.h:22
PosSampler::shoot
TLorentzVector shoot()
Definition: Samplers.h:300
ConstSampler
Definition: Samplers.h:29
PtEtaMPhiSampler::m_phi
Sampler * m_phi
Definition: Samplers.h:601
PosSampler
Definition: Samplers.h:289
x
#define x
CyclicSeqSampler::CyclicSeqSampler
CyclicSeqSampler(const CyclicSeqSampler &orig)
Definition: Samplers.h:220
ParticleSampler::m_pid
Sampler * m_pid
Definition: Samplers.h:812
DisjointUniformSampler::_getRanges
std::vector< std::pair< float, float > > _getRanges()
Definition: Samplers.h:111
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
ConstSampler::~ConstSampler
~ConstSampler()
Definition: Samplers.h:33
Sampler::m_random
TRandom m_random
Definition: Samplers.h:25
DisjointUniformSampler::shoot
float shoot()
Definition: Samplers.h:142
CyclicSeqSampler::m_index
int m_index
Definition: Samplers.h:240
PtEtaMPhiSampler::shoot
TLorentzVector shoot()
Definition: Samplers.h:585
SampledParticle::SampledParticle
SampledParticle(int pid=0, TLorentzVector mom=TLorentzVector(0, 0, 0, 0), TLorentzVector pos=TLorentzVector(0, 0, 0, 0))
Definition: Samplers.h:743
DisjointUniformSampler::_setRanges
void _setRanges()
Definition: Samplers.h:113
LogSampler::shoot
float shoot()
Definition: Samplers.h:162
GaussianSampler::~GaussianSampler
~GaussianSampler()
Definition: Samplers.h:173
ConstSampler::ConstSampler
ConstSampler(float val)
Definition: Samplers.h:32
SampledParticle
Definition: Samplers.h:740
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
ParticleSampler
Definition: Samplers.h:758
LArG4FSStartPointFilter.rand
rand
Definition: LArG4FSStartPointFilter.py:80
NullMomSampler::shoot
TLorentzVector shoot()
Definition: Samplers.h:318
lumiFormat.i
int i
Definition: lumiFormat.py:92
ConstSampler::shoot
virtual float shoot()
Definition: Samplers.h:34
z
#define z
ParticleSampler::~ParticleSampler
~ParticleSampler()
Definition: Samplers.h:760
beamspotman.n
n
Definition: beamspotman.py:731
ModUniformSampler::shoot
float shoot()
Definition: Samplers.h:77
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
ConstSampler::ConstSampler
ConstSampler()
Definition: Samplers.h:31
UniformSampler::m_high
float m_high
Definition: Samplers.h:63
CyclicSeqSampler
Definition: Samplers.h:217
CyclicSeqSampler::CyclicSeqSampler
CyclicSeqSampler(std::string s)
Definition: Samplers.h:221
PosSampler::m_x
Sampler m_x
Definition: Samplers.h:308
PosSampler::m_z
Sampler m_z
Definition: Samplers.h:308
LogSampler
Definition: Samplers.h:154
PosSampler::~PosSampler
~PosSampler()
Definition: Samplers.h:291
ParticleSampler::shoot
std::vector< SampledParticle > shoot()
Definition: Samplers.h:785
DisjointUniformSampler::m_ranges
std::vector< std::pair< float, float > > m_ranges
Definition: Samplers.h:146
ParticleSampler::ParticleSampler
ParticleSampler(Sampler *pid, MomSampler *mom, int n=1)
Definition: Samplers.h:761
ParticleSampler::m_pos
PosSampler m_pos
Definition: Samplers.h:811
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
MomSampler::~MomSampler
~MomSampler()
Definition: Samplers.h:41
SampledParticle::m_mass
float m_mass
Definition: Samplers.h:754
MomSampler::MomSampler
MomSampler()
Definition: Samplers.h:40
SampledParticle::m_pid
int m_pid
Definition: Samplers.h:752
y
#define y
SampledParticle::~SampledParticle
~SampledParticle()
Definition: Samplers.h:742
Sampler::Sampler
Sampler()
Definition: Samplers.h:20
LogSampler::LogSampler
LogSampler(float low, float high)
Definition: Samplers.h:156
DisjointUniformSampler::_map_unit_to_val
float _map_unit_to_val(float x)
Definition: Samplers.h:129
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DeMoScan.first
bool first
Definition: DeMoScan.py:534
SampledParticle::m_pos
TLorentzVector m_pos
Definition: Samplers.h:753
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
DisjointUniformSampler::DisjointUniformSampler
DisjointUniformSampler(std::vector< std::pair< float, float > > ranges)
Definition: Samplers.h:109
ModUniformSampler::ModUniformSampler
ModUniformSampler(float low, float high)
Definition: Samplers.h:70
Sampler
Definition: Samplers.h:18
ParticleSampler::m_n
ConstSampler m_n
Definition: Samplers.h:813
UniformSampler::m_low
float m_low
Definition: Samplers.h:61
PtEtaMPhiSampler::~PtEtaMPhiSampler
~PtEtaMPhiSampler()
Definition: Samplers.h:568
PtEtaMPhiSampler
Definition: Samplers.h:566
UniformSampler::shoot
float shoot()
Definition: Samplers.h:61
MomSampler::m_val
TLorentzVector m_val
Definition: Samplers.h:42
CyclicSeqSampler::m_sequence
std::vector< int > m_sequence
Definition: Samplers.h:237
DisjointUniformSampler
Definition: Samplers.h:86
UniformSampler
Definition: Samplers.h:52
NullMomSampler
Definition: Samplers.h:313
PtEtaMPhiSampler::PtEtaMPhiSampler
PtEtaMPhiSampler(float ptmin, float ptmax, float etamin, float etamax, float mass=0.0, float phimin=0, float phimax=2.*TMath::Pi())
Definition: Samplers.h:569
LArCellBinning.etamin
etamin
Definition: LArCellBinning.py:137
CyclicSeqSampler::shoot
float shoot()
Definition: Samplers.h:233
PosSampler::PosSampler
PosSampler()
Definition: Samplers.h:292
GaussianSampler::m_sigma
float m_sigma
Definition: Samplers.h:181
readCCLHist.float
float
Definition: readCCLHist.py:83
Sampler::~Sampler
virtual ~Sampler()
Definition: Samplers.h:21
GaussianSampler
Definition: Samplers.h:171
SampledParticle::m_mom
TLorentzVector m_mom
Definition: Samplers.h:753
ParticleSampler::m_mom
MomSampler * m_mom
Definition: Samplers.h:810
UniformSampler::UniformSampler
UniformSampler()
Definition: Samplers.h:54
PosSampler::m_y
Sampler m_y
Definition: Samplers.h:308
PtEtaMPhiSampler::m_eta
Sampler * m_eta
Definition: Samplers.h:601
PosSampler::m_t
Sampler m_t
Definition: Samplers.h:308