CMS 3D CMS Logo

RandomXiThetaGunProducer.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  ****************************************************************************/
5 
7 
15 
16 #include "HepPDT/ParticleDataTable.hh"
18 
19 using namespace edm;
20 using namespace std;
21 
22 //----------------------------------------------------------------------------------------------------
23 
25  verbosity_ (iConfig.getUntrackedParameter<unsigned int>("verbosity", 0)),
26  particleId_ (iConfig.getParameter<unsigned int>("particleId")),
27  energy_ (iConfig.getParameter<double>("energy")),
28  xi_min_ (iConfig.getParameter<double>("xi_min")),
29  xi_max_ (iConfig.getParameter<double>("xi_max")),
30  theta_x_mean_ (iConfig.getParameter<double>("theta_x_mean")),
31  theta_x_sigma_ (iConfig.getParameter<double>("theta_x_sigma")),
32  theta_y_mean_ (iConfig.getParameter<double>("theta_y_mean")),
33  theta_y_sigma_ (iConfig.getParameter<double>("theta_y_sigma")),
34  nParticlesSector45_(iConfig.getParameter<unsigned int>("nParticlesSector45")),
35  nParticlesSector56_(iConfig.getParameter<unsigned int>("nParticlesSector56")),
36  engine_(nullptr)
37 {
38  produces<HepMCProduct>("unsmeared");
39 }
40 
41 //----------------------------------------------------------------------------------------------------
42 
44 {
45  // get conditions
47  engine_ = &rng->getEngine(e.streamID());
48 
50  es.getData(pdgTable);
51 
52  // prepare HepMC event
53  HepMC::GenEvent *fEvt = new HepMC::GenEvent();
54  fEvt->set_event_number(e.id().event());
55 
56  HepMC::GenVertex *vtx = new HepMC::GenVertex(HepMC::FourVector(0., 0., 0., 0.));
57  fEvt->add_vertex(vtx);
58 
59  const HepPDT::ParticleData *pData = pdgTable->particle(HepPDT::ParticleID(particleId_));
60  double mass = pData->mass().value();
61 
62  // generate particles
63  unsigned int barcode = 0;
64 
65  for (unsigned int i = 0; i < nParticlesSector45_; ++i)
66  generateParticle(+1., mass, ++barcode, vtx);
67 
68  for (unsigned int i = 0; i < nParticlesSector56_; ++i)
69  generateParticle(-1., mass, ++barcode, vtx);
70 
71  // save output
72  std::unique_ptr<HepMCProduct> output(new HepMCProduct()) ;
73  output->addHepMCData(fEvt);
74  e.put(std::move(output), "unsmeared");
75 }
76 
77 //----------------------------------------------------------------------------------------------------
78 
79 void RandomXiThetaGunProducer::generateParticle(double z_sign, double mass, unsigned int barcode,
80  HepMC::GenVertex *vtx) const
81 {
82  const double xi = CLHEP::RandFlat::shoot(engine_, xi_min_, xi_max_);
83  const double theta_x = CLHEP::RandGauss::shoot(engine_, theta_x_mean_, theta_x_sigma_);
84  const double theta_y = CLHEP::RandGauss::shoot(engine_, theta_y_mean_, theta_y_sigma_);
85 
86  if (verbosity_)
87  LogInfo("RandomXiThetaGunProducer") << "xi = " << xi << ", theta_x = " << theta_x
88  << ", theta_y" << theta_y << ", z_sign = " << z_sign;
89 
90  const double cos_theta = sqrt(1. - theta_x*theta_x - theta_y*theta_y);
91 
92  const double p_nom = sqrt(energy_*energy_ - mass*mass);
93  const double p = p_nom * (1. - xi);
94  const double e = sqrt(p*p + mass*mass);
95 
96  HepMC::FourVector momentum(
97  p * theta_x,
98  p * theta_y,
99  z_sign * p * cos_theta,
100  e
101  );
102 
103  HepMC::GenParticle* particle = new HepMC::GenParticle(momentum, particleId_, 1);
104  particle->suggest_barcode(barcode);
105  vtx->add_particle_out(particle);
106 }
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
#define nullptr
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
bool getData(T &iHolder) const
Definition: EventSetup.h:111
void generateParticle(double z_sign, double mass, unsigned int barcode, HepMC::GenVertex *vtx) const
T sqrt(T t)
Definition: SSEVec.h:18
HepPDT::ParticleData ParticleData
RandomXiThetaGunProducer(const ParameterSet &)
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
StreamID streamID() const
Definition: Event.h:95
void produce(Event &, const EventSetup &) override
def move(src, dest)
Definition: eostools.py:511