CMS 3D CMS Logo

FlatRandomPtAndDxyGunProducer.cc
Go to the documentation of this file.
1 #include <ostream>
2 
4 
7 
12 
13 #include "CLHEP/Random/RandFlat.h"
14 
15 using namespace edm;
16 using namespace std;
17 
19  ParameterSet defpset;
20  ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters");
21 
22  fMinPt = pgun_params.getParameter<double>("MinPt");
23  fMaxPt = pgun_params.getParameter<double>("MaxPt");
24  dxyMin_ = pgun_params.getParameter<double>("dxyMin");
25  dxyMax_ = pgun_params.getParameter<double>("dxyMax");
26  lxyMax_ = pgun_params.getParameter<double>("LxyMax");
27  lzMax_ = pgun_params.getParameter<double>("LzMax");
28  ConeRadius_ = pgun_params.getParameter<double>("ConeRadius");
29  ConeH_ = pgun_params.getParameter<double>("ConeH");
30  DistanceToAPEX_ = pgun_params.getParameter<double>("DistanceToAPEX");
31 
32  produces<HepMCProduct>("unsmeared");
33  produces<GenEventInfoProduct>();
34 }
35 
37  // no need to cleanup GenEvent memory - done in HepMCProduct
38 }
39 
42  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
43 
44  if (fVerbosity > 0) {
45  cout << " FlatRandomPtAndDxyGunProducer : Begin New Event Generation" << endl;
46  }
47  // event loop (well, another step in it...)
48 
49  // no need to clean up GenEvent memory - done in HepMCProduct
50  //
51 
52  // here re-create fEvt (memory)
53  //
54  fEvt = new HepMC::GenEvent();
55 
56  // now actualy, cook up the event from PDGTable and gun parameters
57  int barcode = 1;
58  for (unsigned int ip = 0; ip < fPartIDs.size(); ++ip) {
59  double phi_vtx = 0;
60  double dxy = 0;
61  double pt = 0;
62  double eta = 0;
63  double px = 0;
64  double py = 0;
65  double pz = 0;
66  double vx = 0;
67  double vy = 0;
68  double vz = 0;
69  double lxy = 0;
70 
71  bool passLoop = false;
72  while (not passLoop) {
73  bool passLxy = false;
74  bool passLz = false;
75  phi_vtx = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
76  dxy = CLHEP::RandFlat::shoot(engine, dxyMin_, dxyMax_);
77  float dxysign = CLHEP::RandFlat::shoot(engine, -1, 1);
78  if (dxysign < 0)
79  dxy = -dxy;
80  pt = CLHEP::RandFlat::shoot(engine, fMinPt, fMaxPt);
81  px = pt * cos(phi_vtx);
82  py = pt * sin(phi_vtx);
83  for (int i = 0; i < 10000; i++) {
84  vx = CLHEP::RandFlat::shoot(engine, -lxyMax_, lxyMax_);
85  vy = (pt * dxy + vx * py) / px;
86  lxy = sqrt(vx * vx + vy * vy);
87  if (lxy < abs(lxyMax_) and (vx * px + vy * py) > 0) {
88  passLxy = true;
89  break;
90  }
91  }
92  eta = CLHEP::RandFlat::shoot(engine, fMinEta, fMaxEta);
93  pz = pt * sinh(eta);
94  //vz = fabs(fRandomGaussGenerator->fire(0.0, LzWidth_/2.0));
95  float ConeTheta = ConeRadius_ / ConeH_;
96  for (int j = 0; j < 100; j++) {
97  vz = CLHEP::RandFlat::shoot(engine, 0.0, lzMax_); // this is abs(vz)
98  float v0 = vz - DistanceToAPEX_;
99  if (v0 <= 0 or lxy * lxy / (ConeTheta * ConeTheta) > v0 * v0) {
100  passLz = true;
101  break;
102  }
103  }
104  if (pz < 0)
105  vz = -vz;
106  passLoop = (passLxy and passLz);
107 
108  if (passLoop)
109  break;
110  }
111 
112  float time = sqrt(vx * vx + vy * vy + vz * vz);
113 
114  HepMC::GenVertex* Vtx1 = new HepMC::GenVertex(HepMC::FourVector(vx, vy, vz, time));
115 
116  int PartID = fPartIDs[ip];
117  const HepPDT::ParticleData* PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID)));
118  double mass = PData->mass().value();
119  double energy2 = px * px + py * py + pz * pz + mass * mass;
120  double energy = sqrt(energy2);
121  HepMC::FourVector p(px, py, pz, energy);
123  Part->suggest_barcode(barcode);
124  barcode++;
125  Vtx1->add_particle_out(Part);
126  fEvt->add_vertex(Vtx1);
127 
128  if (fAddAntiParticle) {
129  HepMC::GenVertex* Vtx2 = new HepMC::GenVertex(HepMC::FourVector(-vx, -vy, -vz, time));
130  HepMC::FourVector ap(-px, -py, -pz, energy);
131  int APartID = -PartID;
132  if (PartID == 22 || PartID == 23) {
133  APartID = PartID;
134  }
135  HepMC::GenParticle* APart = new HepMC::GenParticle(ap, APartID, 1);
136  APart->suggest_barcode(barcode);
137  barcode++;
138  Vtx2->add_particle_out(APart);
139  fEvt->add_vertex(Vtx2);
140  }
141  }
142  fEvt->set_event_number(e.id().event());
143  fEvt->set_signal_process_id(20);
144 
145  if (fVerbosity > 0) {
146  fEvt->print();
147  }
148 
149  unique_ptr<HepMCProduct> BProduct(new HepMCProduct());
150  BProduct->addHepMCData(fEvt);
151  e.put(std::move(BProduct), "unsmeared");
152 
153  unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
154  e.put(std::move(genEventInfo));
155 
156  if (fVerbosity > 0) {
157  cout << " FlatRandomPtAndDxyGunProducer : End New Event Generation" << endl;
158  fEvt->print();
159  }
160 }
edm::FlatRandomPtAndDxyGunProducer::dxyMin_
double dxyMin_
Definition: FlatRandomPtAndDxyGunProducer.h:36
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.
V0Monitor_cff.v0
v0
Definition: V0Monitor_cff.py:7
mps_fire.i
i
Definition: mps_fire.py:428
edm::BaseFlatGunProducer::fAddAntiParticle
bool fAddAntiParticle
Definition: BaseFlatGunProducer.h:61
edm::FlatRandomPtAndDxyGunProducer::dxyMax_
double dxyMax_
Definition: FlatRandomPtAndDxyGunProducer.h:37
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
edm::FlatRandomPtAndDxyGunProducer::lzMax_
double lzMax_
Definition: FlatRandomPtAndDxyGunProducer.h:39
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
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::BaseFlatGunProducer::fEvt
HepMC::GenEvent * fEvt
Definition: BaseFlatGunProducer.h:48
ZgammaFilter_cfi.HepMCProduct
HepMCProduct
Definition: ZgammaFilter_cfi.py:9
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::FlatRandomPtAndDxyGunProducer::ConeRadius_
double ConeRadius_
Definition: FlatRandomPtAndDxyGunProducer.h:40
protons_cff.time
time
Definition: protons_cff.py:39
edm::BaseFlatGunProducer::fMinPhi
double fMinPhi
Definition: BaseFlatGunProducer.h:44
edm::FlatRandomPtAndDxyGunProducer::DistanceToAPEX_
double DistanceToAPEX_
Definition: FlatRandomPtAndDxyGunProducer.h:42
edm::FlatRandomPtAndDxyGunProducer::fMinPt
double fMinPt
Definition: FlatRandomPtAndDxyGunProducer.h:34
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
edm::FlatRandomPtAndDxyGunProducer::produce
void produce(Event &e, const EventSetup &es) override
Definition: FlatRandomPtAndDxyGunProducer.cc:40
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
FlatRandomPtAndDxyGunProducer.h
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
edm::FlatRandomPtAndDxyGunProducer::ConeH_
double ConeH_
Definition: FlatRandomPtAndDxyGunProducer.h:41
edm::FlatRandomPtAndDxyGunProducer::FlatRandomPtAndDxyGunProducer
FlatRandomPtAndDxyGunProducer(const ParameterSet &pset)
Definition: FlatRandomPtAndDxyGunProducer.cc:18
edm::FlatRandomPtAndDxyGunProducer::~FlatRandomPtAndDxyGunProducer
~FlatRandomPtAndDxyGunProducer() override
Definition: FlatRandomPtAndDxyGunProducer.cc:36
edm::ParameterSet
Definition: ParameterSet.h:47
GenEventInfoProduct.h
Event.h
edm::Service< edm::RandomNumberGenerator >
edm::EventSetup
Definition: EventSetup.h:58
genfragment_ptgun_cfg.PartID
PartID
Definition: genfragment_ptgun_cfg.py:6
edm::BaseFlatGunProducer
Definition: BaseFlatGunProducer.h:26
edm::BaseFlatGunProducer::fPDGTable
ESHandle< HepPDT::ParticleDataTable > fPDGTable
Definition: BaseFlatGunProducer.h:57
edm::FlatRandomPtAndDxyGunProducer::fMaxPt
double fMaxPt
Definition: FlatRandomPtAndDxyGunProducer.h:35
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
std
Definition: JetResolutionObject.h:76
genParticles2HepMC_cfi.genEventInfo
genEventInfo
Definition: genParticles2HepMC_cfi.py:6
PVValHelper::dxy
Definition: PVValidationHelpers.h:48
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
edm::BaseFlatGunProducer::fVerbosity
int fVerbosity
Definition: BaseFlatGunProducer.h:59
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::FlatRandomPtAndDxyGunProducer::lxyMax_
double lxyMax_
Definition: FlatRandomPtAndDxyGunProducer.h:38
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
HepMCProduct.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
LHEGenericFilter_cfi.ParticleID
ParticleID
Definition: LHEGenericFilter_cfi.py:6
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