CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes | Private Member Functions
edm::CloseByParticleGunProducer Class Reference

#include <CloseByParticleGunProducer.h>

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

Public Member Functions

 CloseByParticleGunProducer (const ParameterSet &)
 
 ~CloseByParticleGunProducer () override
 
- 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
 
 ~BaseFlatGunProducer () override
 
- Public Member Functions inherited from edm::one::EDProducer< one::WatchRuns, EndRunProducer >
 EDProducer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Protected Attributes

double fDelta
 
double fEnMax
 
double fEnMin
 
int fNParticles
 
bool fOverlapping = false
 
std::vector< int > fPartIDs
 
double fPhiMax
 
double fPhiMin
 
bool fPointing = false
 
bool fRandomShoot = false
 
double fRMax
 
double fRMin
 
double fZMax
 
double fZMin
 
- Protected Attributes inherited from edm::BaseFlatGunProducer
bool fAddAntiParticle
 
HepMC::GenEventfEvt
 
double fMaxEta
 
double fMaxPhi
 
double fMinEta
 
double fMinPhi
 
std::vector< int > fPartIDs
 
ESHandle< HepPDT::ParticleDataTablefPDGTable
 
int fVerbosity
 

Private Member Functions

void produce (Event &e, const EventSetup &es) override
 

Additional Inherited Members

- Public Types inherited from edm::one::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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)
 

Detailed Description

Definition at line 9 of file CloseByParticleGunProducer.h.

Constructor & Destructor Documentation

CloseByParticleGunProducer::CloseByParticleGunProducer ( const ParameterSet pset)

Definition at line 24 of file CloseByParticleGunProducer.cc.

References fDelta, fEnMax, fEnMin, fNParticles, fOverlapping, fPartIDs, fPhiMax, fPhiMin, fPointing, fRandomShoot, fRMax, fRMin, fZMax, fZMin, and edm::ParameterSet::getParameter().

24  :
26 {
27 
28  ParameterSet defpset ;
29  ParameterSet pgun_params =
30  pset.getParameter<ParameterSet>("PGunParameters") ;
31 
32  fEnMax = pgun_params.getParameter<double>("EnMax");
33  fEnMin = pgun_params.getParameter<double>("EnMin");
34  fRMax = pgun_params.getParameter<double>("RMax");
35  fRMin = pgun_params.getParameter<double>("RMin");
36  fZMax = pgun_params.getParameter<double>("ZMax");
37  fZMin = pgun_params.getParameter<double>("ZMin");
38  fDelta = pgun_params.getParameter<double>("Delta");
39  fPhiMin = pgun_params.getParameter<double>("MinPhi");
40  fPhiMax = pgun_params.getParameter<double>("MaxPhi");
41  fPointing = pgun_params.getParameter<bool>("Pointing");
42  fOverlapping = pgun_params.getParameter<bool>("Overlapping");
43  fRandomShoot = pgun_params.getParameter<bool>("RandomShoot");
44  fNParticles = pgun_params.getParameter<int>("NParticles");
45  fPartIDs = pgun_params.getParameter< vector<int> >("PartID");
46 
47  produces<HepMCProduct>("unsmeared");
48  produces<GenEventInfoProduct>();
49 
50 }
T getParameter(std::string const &) const
BaseFlatGunProducer(const ParameterSet &)
CloseByParticleGunProducer::~CloseByParticleGunProducer ( )
override

Definition at line 52 of file CloseByParticleGunProducer.cc.

53 {
54  // no need to cleanup GenEvent memory - done in HepMCProduct
55 }

Member Function Documentation

void CloseByParticleGunProducer::produce ( Event e,
const EventSetup es 
)
overrideprivate

Definition at line 57 of file CloseByParticleGunProducer.cc.

References funct::abs(), EnergyCorrector::c, constexpr, funct::cos(), randomXiThetaGunProducer_cfi::energy, edm::EventID::event(), fDelta, fEnMax, fEnMin, edm::BaseFlatGunProducer::fEvt, fNParticles, fOverlapping, fPartIDs, edm::BaseFlatGunProducer::fPDGTable, fPhiMax, fPhiMin, fPointing, fRandomShoot, fRMax, fRMin, edm::BaseFlatGunProducer::fVerbosity, fZMax, fZMin, particlelevel_cff::genEventInfo, GenParticle::GenParticle, edm::RandomNumberGenerator::getEngine(), mps_fire::i, edm::EventBase::id(), LogDebug, ResonanceBuilder::mass, eostools::move(), AlCaHLTBitMon_ParallelJobs::p, source_particleGun_cfi::ParticleID, HadronAndPartonSelector_cfi::particles, CastorDigiValidation::PartID, partIdx(), edm::Event::put(), funct::sin(), mathSSE::sqrt(), edm::Event::streamID(), and hgcalLayerClusters_cff::timeOffset.

58 {
60  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
61 
62  if ( fVerbosity > 0 )
63  {
64  LogDebug("CloseByParticleGunProducer") << " CloseByParticleGunProducer : Begin New Event Generation" << endl ;
65  }
66  fEvt = new HepMC::GenEvent() ;
67 
68  // loop over particles
69  //
70  int barcode = 1 ;
71  int numParticles = fRandomShoot ? CLHEP::RandFlat::shoot(engine, 1, fNParticles) : fNParticles;
72  std::vector<int> particles;
73 
74  for(int i=0; i<numParticles; i++){
75  int partIdx = CLHEP::RandFlat::shoot(engine, 0, fPartIDs.size());
76  particles.push_back(fPartIDs[partIdx]);
77  }
78 
79  double phi = CLHEP::RandFlat::shoot(engine, fPhiMin, fPhiMax);
80  double fR = CLHEP::RandFlat::shoot(engine,fRMin,fRMax);
81  double fZ = CLHEP::RandFlat::shoot(engine,fZMin,fZMax);
82  double tmpPhi = phi;
83  double tmpR = fR;
84 
85  for (unsigned int ip=0; ip<particles.size(); ++ip)
86  {
87  if(fOverlapping)
88  {
89  fR = CLHEP::RandFlat::shoot(engine,tmpR-fDelta,tmpR+fDelta);
90  phi = CLHEP::RandFlat::shoot(engine, tmpPhi-fDelta/fR, tmpPhi+fDelta/fR);
91  }
92  else
93  phi += fDelta/fR;
94 
95  double fEn = CLHEP::RandFlat::shoot(engine,fEnMin,fEnMax);
96  int PartID = particles[ip] ;
97  const HepPDT::ParticleData *PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
98  double mass = PData->mass().value() ;
99  double mom = sqrt(fEn*fEn-mass*mass);
100  double px = 0.;
101  double py = 0.;
102  double pz = mom;
103  double energy = fEn;
104 
105  // Compute Vertex Position
106  double x=fR*cos(phi);
107  double y=fR*sin(phi);
108  constexpr double c= 2.99792458e+1; // cm/ns
109  double timeOffset = sqrt(x*x + y*y + fZ*fZ)/c*ns*c_light;
110  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(x*cm,y*cm,fZ*cm,timeOffset));
111 
112  HepMC::FourVector p(px,py,pz,energy) ;
113  // If we are requested to be pointing to (0,0,0), correct the momentum direction
114  if (fPointing) {
115  math::XYZVector direction(x,y,fZ);
116  math::XYZVector momentum = direction.unit() * mom;
117  p.setX(momentum.x());
118  p.setY(momentum.y());
119  p.setZ(momentum.z());
120  }
121  HepMC::GenParticle* Part = new HepMC::GenParticle(p,PartID,1);
122  Part->suggest_barcode( barcode );
123  barcode++;
124 
125  Vtx->add_particle_out(Part);
126 
127  if (fVerbosity > 0) {
128  Vtx->print();
129  Part->print();
130  }
131  fEvt->add_vertex(Vtx);
132  }
133 
134 
135  fEvt->set_event_number(e.id().event());
136  fEvt->set_signal_process_id(20);
137 
138  if ( fVerbosity > 0 )
139  {
140  fEvt->print();
141  }
142 
143  unique_ptr<HepMCProduct> BProduct(new HepMCProduct());
144  BProduct->addHepMCData( fEvt );
145  e.put(std::move(BProduct), "unsmeared");
146 
147  unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
149 
150  if ( fVerbosity > 0 )
151  {
152  LogDebug("CloseByParticleGunProducer") << " CloseByParticleGunProducer : Event Generation Done " << endl;
153  }
154 
155  particles.clear();
156 }
#define LogDebug(id)
EventNumber_t event() const
Definition: EventID.h:41
static unsigned int partIdx(const InputGenJetsParticleSelector::ParticleVector &p, const reco::Candidate *particle)
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
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
ESHandle< HepPDT::ParticleDataTable > fPDGTable
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
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
edm::EventID id() const
Definition: EventBase.h:59
StreamID streamID() const
Definition: Event.h:95
def move(src, dest)
Definition: eostools.py:511
#define constexpr

Member Data Documentation

double edm::CloseByParticleGunProducer::fDelta
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

double edm::CloseByParticleGunProducer::fEnMax
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

double edm::CloseByParticleGunProducer::fEnMin
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

int edm::CloseByParticleGunProducer::fNParticles
protected

Definition at line 24 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

bool edm::CloseByParticleGunProducer::fOverlapping = false
protected

Definition at line 26 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

std::vector<int> edm::CloseByParticleGunProducer::fPartIDs
protected

Definition at line 28 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

double edm::CloseByParticleGunProducer::fPhiMax
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

double edm::CloseByParticleGunProducer::fPhiMin
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

bool edm::CloseByParticleGunProducer::fPointing = false
protected

Definition at line 25 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

bool edm::CloseByParticleGunProducer::fRandomShoot = false
protected

Definition at line 27 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

double edm::CloseByParticleGunProducer::fRMax
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

double edm::CloseByParticleGunProducer::fRMin
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

double edm::CloseByParticleGunProducer::fZMax
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().

double edm::CloseByParticleGunProducer::fZMin
protected

Definition at line 23 of file CloseByParticleGunProducer.h.

Referenced by CloseByParticleGunProducer(), and produce().