CMS 3D CMS Logo

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

#include <FileRandomKEThetaGunProducer.h>

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

Public Member Functions

 FileRandomKEThetaGunProducer (const ParameterSet &)
 
 ~FileRandomKEThetaGunProducer () override
 
- Public Member Functions inherited from edm::FlatBaseThetaGunProducer
void beginRun (const edm::Run &, const edm::EventSetup &) override
 
void endRun (const edm::Run &r, const edm::EventSetup &) override
 
void endRunProduce (edm::Run &r, const edm::EventSetup &) override
 
 FlatBaseThetaGunProducer (const ParameterSet &)
 
 ~FlatBaseThetaGunProducer () 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

std::vector< double > fdistn
 
std::vector< double > kineticE
 
int particleN
 
- Protected Attributes inherited from edm::FlatBaseThetaGunProducer
bool fAddAntiParticle
 
HepMC::GenEventfEvt
 
double fMaxPhi
 
double fMaxTheta
 
double fMinPhi
 
double fMinTheta
 
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 FileRandomKEThetaGunProducer.h.

Constructor & Destructor Documentation

FileRandomKEThetaGunProducer::FileRandomKEThetaGunProducer ( const ParameterSet pset)

Definition at line 20 of file FileRandomKEThetaGunProducer.cc.

References HTMLExport::elem(), fdistn, FrontierConditions_GlobalTag_cff::file, edm::FlatBaseThetaGunProducer::fVerbosity, edm::ParameterSet::getParameter(), mps_fire::i, recoMuon::in, kineticE, plotBeamSpotDB::last, LogDebug, particleN, and AlCaHLTBitMon_QueryRunRegistry::string.

20  :
22 
23  edm::ParameterSet defpset ;
24  edm::ParameterSet pgun_params =
25  pset.getParameter<edm::ParameterSet>("PGunParameters") ;
26 
27  edm::FileInPath fp = pgun_params.getParameter<edm::FileInPath>("File");
28  std::string file = fp.fullPath();
29  particleN = pgun_params.getParameter<int>("Particles");
30  if (particleN <= 0) particleN = 1;
31  edm::LogInfo("FlatThetaGun") << "Internal FileRandomKEThetaGun is initialzed"
32  << " with data read from " << file << " and "
33  << particleN << " particles created/event";
34  std::ifstream is(file.c_str(), std::ios::in);
35  if (is) {
36  double energy, elem, sum=0;
37  while (!is.eof()) {
38  is >> energy >> elem;
39  kineticE.push_back(0.001*energy);
40  fdistn.push_back(elem);
41  sum += elem;
42  if (fVerbosity > 0) LogDebug("FlatThetaGun") << "KE " << energy
43  <<" GeV Count rate " <<elem;
44  }
45  is.close();
46  double last = 0;
47  for (unsigned int i=0; i<fdistn.size(); i++) {
48  fdistn[i] /= sum;
49  fdistn[i] += last;
50  last = fdistn[i];
51  if (fVerbosity > 0) LogDebug("FlatThetaGun") << "Bin [" << i << "]: KE "
52  << kineticE[i] << " Distn "
53  << fdistn[i];
54  }
55  }
56  if (kineticE.size() < 2)
57  throw cms::Exception("FileNotFound","Not enough data point found in file ")
58  << file << "\n";
59 
60 
61  produces<HepMCProduct>("unsmeared");
62  produces<GenEventInfoProduct>();
63 }
#define LogDebug(id)
T getParameter(std::string const &) const
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:19
FlatBaseThetaGunProducer(const ParameterSet &)
FileRandomKEThetaGunProducer::~FileRandomKEThetaGunProducer ( )
override

Definition at line 65 of file FileRandomKEThetaGunProducer.cc.

65 {}

Member Function Documentation

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

Definition at line 67 of file FileRandomKEThetaGunProducer.cc.

References funct::abs(), funct::cos(), edm::EventID::event(), fdistn, edm::FlatBaseThetaGunProducer::fEvt, edm::FlatBaseThetaGunProducer::fMaxPhi, edm::FlatBaseThetaGunProducer::fMaxTheta, edm::FlatBaseThetaGunProducer::fMinPhi, edm::FlatBaseThetaGunProducer::fMinTheta, edm::FlatBaseThetaGunProducer::fPartIDs, edm::FlatBaseThetaGunProducer::fPDGTable, edm::FlatBaseThetaGunProducer::fVerbosity, particlelevel_cff::genEventInfo, GenParticle::GenParticle, edm::RandomNumberGenerator::getEngine(), edm::EventBase::id(), cuy::ii, ke, kineticE, LogDebug, ResonanceBuilder::mass, eostools::move(), AlCaHLTBitMon_ParallelJobs::p, source_particleGun_cfi::ParticleID, particleN, CastorDigiValidation::PartID, edm::Event::put(), diffTwoXMLs::r1, hfnoseDigiStudy_cfi::rMax, hfnoseDigiStudy_cfi::rMin, funct::sin(), mathSSE::sqrt(), edm::Event::streamID(), and theta().

67  {
68 
69  if (fVerbosity > 0)
70  LogDebug("FlatThetaGun") << "FileRandomKEThetaGunProducer : Begin New Event Generation";
71 
73  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
74 
75  // event loop (well, another step in it...)
76 
77  // no need to clean up GenEvent memory - done in HepMCProduct
78 
79  // here re-create fEvt (memory)
80  //
81  fEvt = new HepMC::GenEvent() ;
82 
83  // now actualy, cook up the event from PDGTable and gun parameters
84  //
85 
86  // 1st, primary vertex
87  //
88  HepMC::GenVertex* Vtx = new HepMC::GenVertex( HepMC::FourVector(0.,0.,0.));
89 
90  // loop over particles
91  //
92  int barcode = 1;
93  for (int ip=0; ip<particleN; ip++) {
94  double keMin=kineticE[0], keMax=kineticE[1];
95  double rMin=fdistn[0], rMax=fdistn[1];
96  double r1 = engine->flat();
97  for (unsigned int ii=kineticE.size()-2; ii>0; --ii) {
98  if (r1 > fdistn[ii]) {
99  keMin = kineticE[ii]; keMax = kineticE[ii+1];
100  rMin = fdistn[ii]; rMax = fdistn[ii+1]; break;
101  }
102  }
103  double ke = (keMin*(rMax-r1) + keMax*(r1-rMin))/(rMax-rMin);
104  if (fVerbosity > 1)
105  LogDebug("FlatThetaGun") << "FileRandomKEThetaGunProducer: KE " << ke
106  << " in range " << keMin << ":" << keMax
107  << " with " << r1 <<" in " << rMin <<":" <<rMax;
108  double theta = CLHEP::RandFlat::shoot(engine, fMinTheta, fMaxTheta);
109  double phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
110  int PartID = fPartIDs[0];
111  const HepPDT::ParticleData*
112  PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
113  double mass = PData->mass().value() ;
114  double energy = ke + mass;
115  double mom2 = ke*ke + 2.*ke*mass ;
116  double mom = std::sqrt(mom2);
117  double px = mom*sin(theta)*cos(phi);
118  double py = mom*sin(theta)*sin(phi);
119  double pz = mom*cos(theta);
120 
121  HepMC::FourVector p(px,py,pz,energy) ;
122  HepMC::GenParticle* Part = new HepMC::GenParticle(p,PartID,1);
123  Part->suggest_barcode( barcode ) ;
124  barcode++ ;
125  Vtx->add_particle_out(Part);
126 
127  }
128  fEvt->add_vertex(Vtx) ;
129  fEvt->set_event_number(e.id().event()) ;
130  fEvt->set_signal_process_id(20) ;
131 
132 
133  if (fVerbosity > 0) {
134  fEvt->print() ;
135  }
136 
137  std::unique_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
138  BProduct->addHepMCData( fEvt );
139  e.put(std::move(BProduct), "unsmeared");
140 
141  std::unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
143 
144  if ( fVerbosity > 0 )
145  LogDebug("FlatThetaGun") << "FileRandomKEThetaGunProducer : Event Generation Done";
146 }
#define LogDebug(id)
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
ii
Definition: cuy.py:590
int ke
edm::EventID id() const
Definition: EventBase.h:59
StreamID streamID() const
Definition: Event.h:95
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

std::vector<double> edm::FileRandomKEThetaGunProducer::fdistn
protected

Definition at line 23 of file FileRandomKEThetaGunProducer.h.

Referenced by FileRandomKEThetaGunProducer(), and produce().

std::vector<double> edm::FileRandomKEThetaGunProducer::kineticE
protected

Definition at line 23 of file FileRandomKEThetaGunProducer.h.

Referenced by FileRandomKEThetaGunProducer(), and produce().

int edm::FileRandomKEThetaGunProducer::particleN
protected

Definition at line 24 of file FileRandomKEThetaGunProducer.h.

Referenced by FileRandomKEThetaGunProducer(), and produce().