CMS 3D CMS Logo

FlatRandomPtThetaGunProducer.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 FlatRandomPtThetaGunProducer::FlatRandomPtThetaGunProducer(const edm::ParameterSet& pset) :
24 {
25  edm::ParameterSet defpset ;
26  edm::ParameterSet pgun_params =
27  pset.getParameter<edm::ParameterSet>("PGunParameters") ;
28 
29  fMinPt = pgun_params.getParameter<double>("MinPt");
30  fMaxPt = pgun_params.getParameter<double>("MaxPt");
31 
32  produces<HepMCProduct>("unsmeared");
33  produces<GenEventInfoProduct>();
34 // edm::LogInfo("FlatThetaGun") << "Internal FlatRandomPtThetaGun is initialzed"
35 // << "\nIt is going to generate "
36 // << remainingEvents() << " events";
37 }
38 
40 
42 
43  if ( fVerbosity > 0 ) {
44  LogDebug("FlatThetaGun") << "FlatRandomPtThetaGunProducer : Begin New Event Generation";
45  }
46 
48  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
49 
50  // event loop (well, another step in it...)
51 
52  // no need to clean up GenEvent memory - done in HepMCProduct
53  //
54 
55  // here re-create fEvt (memory)
56  //
57  fEvt = new HepMC::GenEvent() ;
58 
59  // now actualy, cook up the event from PDGTable and gun parameters
60  //
61  // 1st, primary vertex
62  //
63  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0.,0.,0.));
64 
65  // loop over particles
66  //
67  int barcode = 1 ;
68  for (unsigned int ip=0; ip<fPartIDs.size(); ++ip) {
69 
70  double pt = CLHEP::RandFlat::shoot(engine, fMinPt, fMaxPt);
71  double theta = CLHEP::RandFlat::shoot(engine, fMinTheta, fMaxTheta);
72  double phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
73  int PartID = fPartIDs[ip] ;
74  const HepPDT::ParticleData*
75  PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
76  double mass = PData->mass().value() ;
77  double mom = pt/sin(theta) ;
78  double px = pt*cos(phi) ;
79  double py = pt*sin(phi) ;
80  double pz = mom*cos(theta) ;
81  double energy2= mom*mom + mass*mass ;
82  double energy = sqrt(energy2) ;
83  HepMC::FourVector p(px,py,pz,energy) ;
84  HepMC::GenParticle* Part = new HepMC::GenParticle(p,PartID,1);
85  Part->suggest_barcode( barcode ) ;
86  barcode++ ;
87  Vtx->add_particle_out(Part);
88 
89  if ( fAddAntiParticle ) {
90  HepMC::FourVector ap(-px,-py,-pz,energy) ;
91  int APartID = -PartID ;
92  if ( PartID == 22 || PartID == 23 ) {
93  APartID = PartID ;
94  }
95  HepMC::GenParticle* APart = new HepMC::GenParticle(ap,APartID,1);
96  APart->suggest_barcode( barcode ) ;
97  barcode++ ;
98  Vtx->add_particle_out(APart) ;
99  }
100  }
101 
102  fEvt->add_vertex(Vtx) ;
103  fEvt->set_event_number(e.id().event()) ;
104  fEvt->set_signal_process_id(20) ;
105 
106  if ( fVerbosity > 0 ) {
107  fEvt->print() ;
108  }
109 
110  std::unique_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
111  BProduct->addHepMCData( fEvt );
112  e.put(std::move(BProduct), "unsmeared");
113 
114  std::unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
115  e.put(std::move(genEventInfo));
116 
117  if ( fVerbosity > 0 ) {
118  LogDebug("FlatThetaGun") << "FlatRandomPtThetaGunProducer : Event Generation Done ";
119  }
120 }
#define LogDebug(id)
void produce(Event &e, const EventSetup &es) override
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
def move(src, dest)
Definition: eostools.py:511