CMS 3D CMS Logo

FileRandomMultiParticlePGunProducer.cc
Go to the documentation of this file.
1 #include <ostream>
2 
4 
7 
14 #include "CLHEP/Random/RandFlat.h"
15 
16 using namespace edm;
17 
18 const unsigned int np = 6;
19 const unsigned int kfactor = 100;
20 
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 }
73 
75 
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 }
edm::BaseFlatGunProducer::fMaxPhi
double fMaxPhi
Definition: BaseFlatGunProducer.h:45
GenEventInfoProduct
Definition: GenEventInfoProduct.h:17
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
MessageLogger.h
edm::BaseFlatGunProducer::fMaxEta
double fMaxEta
Definition: BaseFlatGunProducer.h:43
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
edm
HLT enums.
Definition: AlignableModifier.h:19
RandomNumberGenerator.h
edm::BaseFlatGunProducer::fEvt
HepMC::GenEvent * fEvt
Definition: BaseFlatGunProducer.h:48
ZgammaFilter_cfi.HepMCProduct
HepMCProduct
Definition: ZgammaFilter_cfi.py:9
edm::FileRandomMultiParticlePGunProducer::fMinP_
double fMinP_
Definition: FileRandomMultiParticlePGunProducer.h:24
edm::FileRandomMultiParticlePGunProducer::FileRandomMultiParticlePGunProducer
FileRandomMultiParticlePGunProducer(const ParameterSet &pset)
Definition: FileRandomMultiParticlePGunProducer.cc:21
edm::FileRandomMultiParticlePGunProducer::fProbParticle_
std::map< int, std::vector< double > > fProbParticle_
Definition: FileRandomMultiParticlePGunProducer.h:21
edm::BaseFlatGunProducer::fMinPhi
double fMinPhi
Definition: BaseFlatGunProducer.h:44
personalPlayback.fp
fp
Definition: personalPlayback.py:523
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
edm::FileRandomMultiParticlePGunProducer::fEtaMin_
double fEtaMin_
Definition: FileRandomMultiParticlePGunProducer.h:22
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
EDMException.h
edm::FileInPath
Definition: FileInPath.h:61
edm::BaseFlatGunProducer::fPartIDs
std::vector< int > fPartIDs
Definition: BaseFlatGunProducer.h:41
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Service.h
PVValHelper::eta
Definition: PVValidationHelpers.h:70
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::FileRandomMultiParticlePGunProducer::fEtaBin_
int fEtaBin_
Definition: FileRandomMultiParticlePGunProducer.h:19
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
dqmdumpme.k
k
Definition: dqmdumpme.py:60
geometryDiff.file
file
Definition: geometryDiff.py:13
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
GenEventInfoProduct.h
Event.h
recoMuon::in
Definition: RecoMuonEnumerators.h:6
edm::FileRandomMultiParticlePGunProducer::fPBin_
int fPBin_
Definition: FileRandomMultiParticlePGunProducer.h:18
edm::Service< edm::RandomNumberGenerator >
kfactor
const unsigned int kfactor
Definition: FileRandomMultiParticlePGunProducer.cc:19
edm::EventSetup
Definition: EventSetup.h:58
FileRandomMultiParticlePGunProducer.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::BaseFlatGunProducer
Definition: BaseFlatGunProducer.h:26
edm::BaseFlatGunProducer::fPDGTable
ESHandle< HepPDT::ParticleDataTable > fPDGTable
Definition: BaseFlatGunProducer.h:57
np
const unsigned int np
Definition: FileRandomMultiParticlePGunProducer.cc:18
edm::FileRandomMultiParticlePGunProducer::fMaxP_
double fMaxP_
Definition: FileRandomMultiParticlePGunProducer.h:25
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::FileRandomMultiParticlePGunProducer::produce
void produce(Event &e, const EventSetup &es) override
Definition: FileRandomMultiParticlePGunProducer.cc:76
genParticles2HepMC_cfi.genEventInfo
genEventInfo
Definition: genParticles2HepMC_cfi.py:6
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Exception
Definition: hltDiff.cc:245
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
edm::BaseFlatGunProducer::fVerbosity
int fVerbosity
Definition: BaseFlatGunProducer.h:59
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
cms::Exception
Definition: Exception.h:70
ParameterSet.h
HepMCProduct.h
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
edm::Event
Definition: Event.h:73
LHEGenericFilter_cfi.ParticleID
ParticleID
Definition: LHEGenericFilter_cfi.py:6
TtFullHadEvtBuilder_cfi.prob
prob
Definition: TtFullHadEvtBuilder_cfi.py:33
edm::FileRandomMultiParticlePGunProducer::fEtaBinWidth_
double fEtaBinWidth_
Definition: FileRandomMultiParticlePGunProducer.h:23
edm::FileRandomMultiParticlePGunProducer::fP_
std::vector< double > fP_
Definition: FileRandomMultiParticlePGunProducer.h:20
edm::FileRandomMultiParticlePGunProducer::~FileRandomMultiParticlePGunProducer
~FileRandomMultiParticlePGunProducer() override
Definition: FileRandomMultiParticlePGunProducer.cc:74
edm::BaseFlatGunProducer::fMinEta
double fMinEta
Definition: BaseFlatGunProducer.h:42
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37