CMS 3D CMS Logo

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

#include <FileRandomMultiParticlePGunProducer.h>

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

Public Member Functions

 FileRandomMultiParticlePGunProducer (const ParameterSet &pset)
 
void produce (Event &e, const EventSetup &es) override
 
 ~FileRandomMultiParticlePGunProducer () 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
 
 EDProducer (const EDProducer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () 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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

int fEtaBin_
 
double fEtaBinWidth_
 
double fEtaMin_
 
double fMaxP_
 
double fMinP_
 
std::vector< double > fP_
 
int fPBin_
 
std::map< int, std::vector< double > > fProbParticle_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
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::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 
- 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
 

Detailed Description

Definition at line 9 of file FileRandomMultiParticlePGunProducer.h.

Constructor & Destructor Documentation

◆ FileRandomMultiParticlePGunProducer()

FileRandomMultiParticlePGunProducer::FileRandomMultiParticlePGunProducer ( const ParameterSet pset)

Definition at line 21 of file FileRandomMultiParticlePGunProducer.cc.

References Exception, fEtaBin_, fEtaBinWidth_, fEtaMin_, geometryDiff::file, fMaxP_, fMinP_, personalPlayback::fp, fP_, edm::BaseFlatGunProducer::fPartIDs, fPBin_, fProbParticle_, edm::BaseFlatGunProducer::fVerbosity, edm::ParameterSet::getParameter(), recoMuon::in, dqmdumpme::k, kfactor, np, TtFullHadEvtBuilder_cfi::prob, muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

23  ParameterSet pgunParams = pset.getParameter<ParameterSet>("PGunParameters");
24  fMinP_ = pgunParams.getParameter<double>("MinP");
25  fMaxP_ = pgunParams.getParameter<double>("MaxP");
26  edm::FileInPath fp = pgunParams.getParameter<edm::FileInPath>("FileName");
27  std::string file = fp.fullPath();
28 
29  produces<HepMCProduct>("unsmeared");
30  produces<GenEventInfoProduct>();
31  edm::LogVerbatim("ParticleGun") << "FileRandomMultiParticlePGun is initialzed with i/p file " << file
32  << " and use momentum range " << fMinP_ << ":" << fMaxP_;
33 
34  if (fPartIDs.size() != np)
35  throw cms::Exception("ParticleGun") << "Invalid list of partices: " << fPartIDs.size() << " should be " << np
36  << "\n";
37 
38  std::ifstream is(file.c_str(), std::ios::in);
39  if (!is) {
40  throw cms::Exception("Configuration") << "Cannot find the file " << file << "\n";
41  } else {
42  double xl, xh;
43  is >> fPBin_ >> xl >> xh >> fEtaBin_ >> fEtaMin_ >> fEtaBinWidth_;
44  fP_.emplace_back(xl);
45  edm::LogVerbatim("ParticleGun") << "FileRandomMultiParticlePGun: p: " << fPBin_ << ":" << xl << ":" << xh
46  << " Eta: " << fEtaBin_ << ":" << fEtaMin_ << ":" << fEtaBinWidth_;
47  for (int ip = 0; ip < fPBin_; ++ip) {
48  for (int ie = 0; ie < fEtaBin_; ++ie) {
49  double totprob(0);
50  std::vector<double> prob(np, 0);
51  int je;
52  is >> xl >> xh >> je >> prob[0] >> prob[1] >> prob[2] >> prob[3] >> prob[4] >> prob[5];
53  if (ie == 0)
54  fP_.emplace_back(xh);
55  for (unsigned int k = 0; k < np; ++k) {
56  totprob += prob[k];
57  if (k > 0)
58  prob[k] += prob[k - 1];
59  }
60  for (unsigned int k = 0; k < np; ++k)
61  prob[k] /= totprob;
62  int indx = (ip + 1) * kfactor + ie;
63  fProbParticle_[indx] = prob;
64  if (fVerbosity > 0)
65  edm::LogVerbatim("ParticleGun")
66  << "FileRandomMultiParticlePGun [" << ip << "," << ie << ", " << indx << "] Probability " << prob[0]
67  << ", " << prob[1] << ", " << prob[2] << ", " << prob[3] << ", " << prob[4] << ", " << prob[5];
68  }
69  }
70  is.close();
71  }
72 }
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
BaseFlatGunProducer(const ParameterSet &)
std::vector< int > fPartIDs
const unsigned int np
std::map< int, std::vector< double > > fProbParticle_
const unsigned int kfactor

◆ ~FileRandomMultiParticlePGunProducer()

FileRandomMultiParticlePGunProducer::~FileRandomMultiParticlePGunProducer ( )
override

Definition at line 74 of file FileRandomMultiParticlePGunProducer.cc.

74 {}

Member Function Documentation

◆ produce()

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

Implements edm::one::EDProducerBase.

Definition at line 76 of file FileRandomMultiParticlePGunProducer.cc.

References funct::cos(), MillePedeFileConverter_cfg::e, hcalRecHitTable_cff::energy, PVValHelper::eta, JetChargeProducer_cfi::exp, fEtaBinWidth_, fEtaMin_, edm::BaseFlatGunProducer::fEvt, edm::BaseFlatGunProducer::fMaxEta, fMaxP_, edm::BaseFlatGunProducer::fMaxPhi, edm::BaseFlatGunProducer::fMinEta, fMinP_, edm::BaseFlatGunProducer::fMinPhi, fP_, edm::BaseFlatGunProducer::fPartIDs, edm::BaseFlatGunProducer::fPDGTable, fProbParticle_, edm::BaseFlatGunProducer::fVerbosity, genParticles2HepMC_cfi::genEventInfo, GenParticle::GenParticle, edm::RandomNumberGenerator::getEngine(), ZgammaFilter_cfi::HepMCProduct, hcalRecHitTable_cff::ieta, kfactor, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, EgHLTOffHistBins_cfi::mass, eostools::move(), AlCaHLTBitMon_ParallelJobs::p, LHEGenericFilter_cfi::ParticleID, multPhiCorr_741_25nsDY_cfi::px, multPhiCorr_741_25nsDY_cfi::py, funct::sin(), mathSSE::sqrt(), and theta().

76  {
78  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
79 
80  if (fVerbosity > 0)
81  edm::LogVerbatim("ParticleGun") << "FileRandomMultiParticlePGunProducer: Begin New Event Generation";
82 
83  // event loop (well, another step in it...)
84  // no need to clean up GenEvent memory - done in HepMCProduct
85  // here re-create fEvt (memory)
86  //
87  fEvt = new HepMC::GenEvent();
88 
89  // now actualy, cook up the event from PDGTable and gun parameters
90  //
91 
92  // 1st, primary vertex
93  //
94  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0., 0., 0.));
95 
96  // Now p, eta, phi
97  double mom = CLHEP::RandFlat::shoot(engine, fMinP_, fMaxP_);
98  double eta = CLHEP::RandFlat::shoot(engine, fMinEta, fMaxEta);
99  double phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
100  int ieta = static_cast<int>((eta - fEtaMin_) / fEtaBinWidth_);
101  auto ipp = std::lower_bound(fP_.begin(), fP_.end(), mom);
102  if (ipp == fP_.end())
103  --ipp;
104  int ip = static_cast<int>(ipp - fP_.begin());
105  int indx = ip * kfactor + ieta;
106  if (fVerbosity > 0)
107  edm::LogVerbatim("ParticleGun") << "FileRandomMultiParticlePGunProducer: p " << mom << " Eta " << eta << " Phi "
108  << phi << " Index " << indx;
109 
110  // Now particle id
111  //
112  int barcode(0), partID(fPartIDs[0]);
113  double r1 = CLHEP::RandFlat::shoot(engine, 0., 1.);
114  for (unsigned int ip = 0; ip < fPartIDs.size(); ip++) {
115  if (r1 <= fProbParticle_[indx][ip])
116  break;
117  partID = fPartIDs[ip];
118  }
119  if (fVerbosity > 0)
120  edm::LogVerbatim("ParticleGun") << "Random " << r1 << " PartID " << partID;
121  const HepPDT::ParticleData* PData = fPDGTable->particle(HepPDT::ParticleID(partID));
122  double mass = PData->mass().value();
123  double energy = sqrt(mom * mom + mass * mass);
124  double theta = 2. * atan(exp(-eta));
125  double px = mom * sin(theta) * cos(phi);
126  double py = mom * sin(theta) * sin(phi);
127  double pz = mom * cos(theta);
128 
129  HepMC::FourVector p(px, py, pz, energy);
130  HepMC::GenParticle* Part = new HepMC::GenParticle(p, partID, 1);
131  barcode++;
132  Part->suggest_barcode(barcode);
133  Vtx->add_particle_out(Part);
134 
135  fEvt->add_vertex(Vtx);
136  fEvt->set_event_number(e.id().event());
137  fEvt->set_signal_process_id(20);
138 
139  if (fVerbosity > 1)
140  fEvt->print();
141 
142  std::unique_ptr<HepMCProduct> BProduct(new HepMCProduct());
143  BProduct->addHepMCData(fEvt);
144  e.put(std::move(BProduct), "unsmeared");
145 
146  std::unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
147  e.put(std::move(genEventInfo));
148  if (fVerbosity > 0)
149  edm::LogVerbatim("ParticleGun") << "FileRandomMultiParticlePGunProducer : Event Generation Done";
150 }
Log< level::Info, true > LogVerbatim
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:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< int > fPartIDs
HepPDT::ParticleData ParticleData
std::map< int, std::vector< double > > fProbParticle_
const unsigned int kfactor
Geom::Theta< T > theta() const
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ fEtaBin_

int edm::FileRandomMultiParticlePGunProducer::fEtaBin_
private

◆ fEtaBinWidth_

double edm::FileRandomMultiParticlePGunProducer::fEtaBinWidth_
private

◆ fEtaMin_

double edm::FileRandomMultiParticlePGunProducer::fEtaMin_
private

◆ fMaxP_

double edm::FileRandomMultiParticlePGunProducer::fMaxP_
private

◆ fMinP_

double edm::FileRandomMultiParticlePGunProducer::fMinP_
private

◆ fP_

std::vector<double> edm::FileRandomMultiParticlePGunProducer::fP_
private

◆ fPBin_

int edm::FileRandomMultiParticlePGunProducer::fPBin_
private

◆ fProbParticle_

std::map<int, std::vector<double> > edm::FileRandomMultiParticlePGunProducer::fProbParticle_
private