CMS 3D CMS Logo

FlatRandomEThetaGunProducer.cc
Go to the documentation of this file.
1 #include <ostream>
2 
4 
7 
13 
14 #include "CLHEP/Random/RandFlat.h"
15 
16 namespace CLHEP {
17  class HepRandomEngine;
18 }
19 
20 using namespace edm;
21 
22 FlatRandomEThetaGunProducer::FlatRandomEThetaGunProducer(const edm::ParameterSet& pset) :
24 
25  edm::ParameterSet defpset ;
26  edm::ParameterSet pgun_params =
27  pset.getParameter<edm::ParameterSet>("PGunParameters") ;
28 
29  // doesn't seem necessary to check if pset is empty - if this
30  // is the case, default values will be taken for params
31  fMinE = pgun_params.getParameter<double>("MinE");
32  fMaxE = pgun_params.getParameter<double>("MaxE");
33 
34  produces<HepMCProduct>("unsmeared");
35  produces<GenEventInfoProduct>();
36 
37 // edm::LogInfo("FlatThetaGun") << "Internal FlatRandomEThetaGun is initialzed"
38 // << "\nIt is going to generate "
39 // << remainingEvents() << " events";
40 }
41 
43 
45 
46  if ( fVerbosity > 0 ) {
47  LogDebug("FlatThetaGun") << "FlatRandomEThetaGunProducer : Begin New Event Generation";
48  }
49 
51  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
52 
53  // event loop (well, another step in it...)
54 
55  // no need to clean up GenEvent memory - done in HepMCProduct
56 
57  // here re-create fEvt (memory)
58  //
59  fEvt = new HepMC::GenEvent() ;
60 
61  // now actualy, cook up the event from PDGTable and gun parameters
62  //
63 
64  // 1st, primary vertex
65  //
66  HepMC::GenVertex* Vtx = new HepMC::GenVertex( HepMC::FourVector(0.,0.,0.));
67 
68  // loop over particles
69  //
70  int barcode = 1;
71  for (unsigned int ip=0; ip<fPartIDs.size(); ip++) {
72  double energy = CLHEP::RandFlat::shoot(engine, fMinE, fMaxE);
73  double theta = CLHEP::RandFlat::shoot(engine, fMinTheta, fMaxTheta);
74  double phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
75  int PartID = fPartIDs[ip] ;
76  const HepPDT::ParticleData*
77  PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
78  double mass = PData->mass().value() ;
79  double mom2 = energy*energy - mass*mass ;
80  double mom = (mom2 > 0. ? std::sqrt(mom2) : 0.);
81  double px = mom*sin(theta)*cos(phi) ;
82  double py = mom*sin(theta)*sin(phi) ;
83  double pz = mom*cos(theta) ;
84 
85  HepMC::FourVector p(px,py,pz,energy) ;
86  HepMC::GenParticle* Part = new HepMC::GenParticle(p,PartID,1);
87  Part->suggest_barcode( barcode ) ;
88  barcode++ ;
89  Vtx->add_particle_out(Part);
90 
91  if ( fAddAntiParticle ) {
92  HepMC::FourVector ap(-px,-py,-pz,energy) ;
93  int APartID = -PartID ;
94  if ( PartID == 22 || PartID == 23 ) {
95  APartID = PartID ;
96  }
97  HepMC::GenParticle* APart = new HepMC::GenParticle(ap,APartID,1);
98  APart->suggest_barcode( barcode ) ;
99  barcode++ ;
100  Vtx->add_particle_out(APart) ;
101  }
102 
103  }
104  fEvt->add_vertex(Vtx) ;
105  fEvt->set_event_number(e.id().event()) ;
106  fEvt->set_signal_process_id(20) ;
107 
108 
109  if ( fVerbosity > 0 ) {
110  fEvt->print() ;
111  }
112 
113  std::unique_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
114  BProduct->addHepMCData( fEvt );
115  e.put(std::move(BProduct), "unsmeared");
116 
117  std::unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
118  e.put(std::move(genEventInfo));
119 
120  if ( fVerbosity > 0 ) {
121  LogDebug("FlatThetaGun") << "FlatRandomEThetaGunProducer : Event Generation Done";
122  }
123 }
#define LogDebug(id)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ESHandle< HepPDT::ParticleDataTable > fPDGTable
Geom::Theta< T > theta() const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HepPDT::ParticleData ParticleData
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
StreamID streamID() const
Definition: Event.h:95
void produce(Event &e, const EventSetup &es) override
def move(src, dest)
Definition: eostools.py:511