CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
edm::FlatRandomOneOverPtGunProducer Class Reference

#include <FlatRandomOneOverPtGunProducer.h>

Inheritance diagram for edm::FlatRandomOneOverPtGunProducer:
edm::BaseFlatGunProducer edm::one::EDProducer< one::WatchRuns, EndRunProducer > edm::one::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 FlatRandomOneOverPtGunProducer (const ParameterSet &pset)
 
virtual void produce (Event &e, const EventSetup &es) override
 
virtual ~FlatRandomOneOverPtGunProducer ()
 
- Public Member Functions inherited from edm::BaseFlatGunProducer
 BaseFlatGunProducer (const ParameterSet &)
 
void beginRun (const edm::Run &r, const edm::EventSetup &) override
 
void endRun (edm::Run const &r, const edm::EventSetup &) override
 
void endRunProduce (edm::Run &r, const edm::EventSetup &) override
 
virtual ~BaseFlatGunProducer ()
 
- Public Member Functions inherited from edm::one::EDProducer< one::WatchRuns, EndRunProducer >
 EDProducer ()=default
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

double fMaxOneOverPt
 
double fMinOneOverPt
 

Additional Inherited Members

- Public Types inherited from edm::one::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
- Protected Attributes inherited from edm::BaseFlatGunProducer
bool fAddAntiParticle
 
HepMC::GenEvent * fEvt
 
double fMaxEta
 
double fMaxPhi
 
double fMinEta
 
double fMinPhi
 
std::vector< int > fPartIDs
 
ESHandle
< HepPDT::ParticleDataTable
fPDGTable
 
int fVerbosity
 

Detailed Description

Definition at line 14 of file FlatRandomOneOverPtGunProducer.h.

Constructor & Destructor Documentation

FlatRandomOneOverPtGunProducer::FlatRandomOneOverPtGunProducer ( const ParameterSet pset)

Definition at line 18 of file FlatRandomOneOverPtGunProducer.cc.

References fMaxOneOverPt, fMinOneOverPt, and edm::ParameterSet::getParameter().

18  :
19  BaseFlatGunProducer(pset) {
20 
21 
22  edm::ParameterSet defpset ;
23  edm::ParameterSet pgun_params =
24  pset.getParameter<ParameterSet>("PGunParameters") ;
25 
26  fMinOneOverPt = pgun_params.getParameter<double>("MinOneOverPt");
27  fMaxOneOverPt = pgun_params.getParameter<double>("MaxOneOverPt");
28 
29  produces<HepMCProduct>("unsmeared");
30  produces<GenEventInfoProduct>();
31 
32  edm::LogInfo("ParticleGun") << "FlatRandomOneOverPtGunProducer: initialized with minimum and maximum 1/pt " << fMinOneOverPt << ":" << fMaxOneOverPt;
33 }
T getParameter(std::string const &) const
BaseFlatGunProducer(const ParameterSet &)
FlatRandomOneOverPtGunProducer::~FlatRandomOneOverPtGunProducer ( )
virtual

Definition at line 35 of file FlatRandomOneOverPtGunProducer.cc.

35  {
36  // no need to cleanup GenEvent memory - done in HepMCProduct
37 }

Member Function Documentation

void FlatRandomOneOverPtGunProducer::produce ( Event e,
const EventSetup es 
)
overridevirtual

Implements edm::one::EDProducerBase.

Definition at line 39 of file FlatRandomOneOverPtGunProducer.cc.

References funct::abs(), funct::cos(), relval_parameters_module::energy, eta, edm::EventID::event(), create_public_lumi_plots::exp, edm::BaseFlatGunProducer::fAddAntiParticle, edm::BaseFlatGunProducer::fEvt, edm::BaseFlatGunProducer::fMaxEta, fMaxOneOverPt, edm::BaseFlatGunProducer::fMaxPhi, edm::BaseFlatGunProducer::fMinEta, fMinOneOverPt, edm::BaseFlatGunProducer::fMinPhi, edm::BaseFlatGunProducer::fPartIDs, edm::BaseFlatGunProducer::fPDGTable, edm::BaseFlatGunProducer::fVerbosity, GenParticle::GenParticle, edm::RandomNumberGenerator::getEngine(), edm::EventBase::id(), dqm-mbProfile::log, LogDebug, AlCaHLTBitMon_ParallelJobs::p, phi, EnergyCorrector::pt, edm::Event::put(), funct::sin(), mathSSE::sqrt(), edm::Event::streamID(), and theta().

39  {
41  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
42 
43 
44  LogDebug("ParticleGun") << " FlatRandomOneOverPtGunProducer : Begin New Event Generation";
45 
46  // event loop (well, another step in it...)
47 
48  // no need to clean up GenEvent memory - done in HepMCProduct
49  //
50 
51  // here re-create fEvt (memory)
52  //
53  fEvt = new HepMC::GenEvent() ;
54 
55  // now actualy, cook up the event from PDGTable and gun parameters
56  //
57  // 1st, primary vertex
58  //
59  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0.,0.,0.));
60 
61  // loop over particles
62  //
63  int barcode = 1 ;
64  for (unsigned int ip=0; ip<fPartIDs.size(); ++ip) {
65 
66  double xx = CLHEP::RandFlat::shoot(engine, 0.0, 1.0);
67  double pt = std::exp((1.-xx)*std::log(fMinOneOverPt)+
68  xx*std::log(fMaxOneOverPt)) ;
69  double eta = CLHEP::RandFlat::shoot(engine, fMinEta, fMaxEta) ;
70  double phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi) ;
71  if (pt != 0) pt = 1./pt;
72  int PartID = fPartIDs[ip] ;
73  const HepPDT::ParticleData*
74  PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
75  double mass = PData->mass().value() ;
76  double theta = 2.*atan(exp(-eta)) ;
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  LogDebug("ParticleGun") << "FlatRandomOneOverPtGunProducer: Event generated with pt:eta:phi " << pt << " " << eta << " " << phi << " (" << theta/CLHEP::deg << ":" << phi/CLHEP::deg << ")";
89 
90  if ( fAddAntiParticle ) {
91  HepMC::FourVector ap(-px,-py,-pz,energy) ;
92  int APartID = -PartID ;
93  if ( PartID == 22 || PartID == 23 ) {
94  APartID = PartID ;
95  }
96  HepMC::GenParticle* APart = new HepMC::GenParticle(ap,APartID,1);
97  APart->suggest_barcode( barcode ) ;
98  barcode++ ;
99  Vtx->add_particle_out(APart) ;
100  }
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  if ( fVerbosity > 0 ) {
109  fEvt->print() ;
110  }
111 
112  std::auto_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
113  BProduct->addHepMCData( fEvt );
114  e.put(BProduct, "unsmeared");
115 
116  std::auto_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
117  e.put(genEventInfo);
118 
119  LogDebug("ParticleGun") << " FlatRandomOneOverPtGunProducer : Event Generation Done ";
120 }
#define LogDebug(id)
EventNumber_t event() const
Definition: EventID.h:41
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
ESHandle< HepPDT::ParticleDataTable > fPDGTable
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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
std::vector< int > fPartIDs
HepPDT::ParticleData ParticleData
edm::EventID id() const
Definition: EventBase.h:59
StreamID streamID() const
Definition: Event.h:80

Member Data Documentation

double edm::FlatRandomOneOverPtGunProducer::fMaxOneOverPt
private

Definition at line 28 of file FlatRandomOneOverPtGunProducer.h.

Referenced by FlatRandomOneOverPtGunProducer(), and produce().

double edm::FlatRandomOneOverPtGunProducer::fMinOneOverPt
private

Definition at line 27 of file FlatRandomOneOverPtGunProducer.h.

Referenced by FlatRandomOneOverPtGunProducer(), and produce().