CMS 3D CMS Logo

RandomtXiGunProducer.cc
Go to the documentation of this file.
1 /*
2  * $Date: 2011/12/19 23:10:40 $
3  * $Revision: 1.4 $
4  * \author Luiz Mundim
5  */
6 
7 #include <ostream>
8 
10 
13 
19 
20 #include <CLHEP/Random/RandFlat.h>
21 
22 using namespace edm;
23 using namespace std;
24 
26  ParameterSet defpset;
27  edm::ParameterSet pgun_params = pset.getParameter<edm::ParameterSet>("PGunParameters");
28 
29  fMint = pgun_params.getParameter<double>("Mint");
30  fMaxt = pgun_params.getParameter<double>("Maxt");
31  fMinXi = pgun_params.getParameter<double>("MinXi");
32  fMaxXi = pgun_params.getParameter<double>("MaxXi");
33  fLog_t = pgun_params.getUntrackedParameter<bool>("Log_t", false);
34 
35  produces<HepMCProduct>("unsmeared");
36  produces<GenEventInfoProduct>();
37 }
38 
40  // no need to cleanup GenEvent memory - done in HepMCProduct
41 }
42 
45  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
46 
47  if (fVerbosity > 0) {
48  edm::LogInfo("RandomtXiGunProducer") << "Begin New Event Generation\n";
49  }
50  // event loop (well, another step in it...)
51 
52  // no need to clean up GenEvent memory - done in HepMCProduct
53  //
54 
55  // here re-create fEvt (memory)
56  //
57  fEvt = new HepMC::GenEvent();
58 
59  // now actualy, cook up the event from PDGTable and gun parameters
60  //
61  // 1st, primary vertex
62  //
63  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0., 0., 0.));
64 
65  // loop over particles
66  //
67  int barcode = 1;
68  for (unsigned int ip = 0; ip < fPartIDs.size(); ++ip) {
69  int PartID = fPartIDs[ip];
70  // t = -2*P*P'*(1-cos(theta)) -> t/(2*P*P')+1=cos(theta)
71  // xi = 1 - P'/P --> P'= (1-xi)*P
72  //
74  if (!PData)
75  exit(1);
76  double t = 0;
77  double Xi = 0;
78  double phi = 0;
79  if (fFireForward) {
80  while (true) {
81  Xi = CLHEP::RandFlat::shoot(engine, fMinXi, fMaxXi);
82  double min_t = std::max(fMint, Minimum_t(Xi));
83  double max_t = fMaxt;
84  if (min_t > max_t) {
85  edm::LogInfo("RandomtXiGunProducer") << "WARNING: t limits redefined (unphysical values for given xi).\n";
86  max_t = min_t;
87  }
88  t = (fLog_t) ? pow(CLHEP::RandFlat::shoot(engine, log10(min_t), log10(max_t)), 10)
89  : CLHEP::RandFlat::shoot(engine, min_t, max_t);
90  break;
91  }
92  phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
94  Part->suggest_barcode(barcode);
95  barcode++;
96  Vtx->add_particle_out(Part);
97  }
98  if (fFireBackward) {
99  while (true) {
100  Xi = CLHEP::RandFlat::shoot(engine, fMinXi, fMaxXi);
101  double min_t = std::max(fMint, Minimum_t(Xi));
102  double max_t = fMaxt;
103  if (min_t > max_t) {
104  edm::LogInfo("RandomtXiGunProducer")
105  << "WARNING: t limits redefined (unphysical values for given xi)." << endl;
106  max_t = min_t;
107  }
108  t = (fLog_t) ? pow(CLHEP::RandFlat::shoot(engine, log10(min_t), log10(max_t)), 10)
109  : CLHEP::RandFlat::shoot(engine, min_t, max_t);
110  break;
111  }
112  phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
114  Part2->suggest_barcode(barcode);
115  barcode++;
116  Vtx->add_particle_out(Part2);
117  }
118  }
119 
120  fEvt->add_vertex(Vtx);
121  fEvt->set_event_number(e.id().event());
122  fEvt->set_signal_process_id(20);
123 
124  if (fVerbosity > 0) {
125  fEvt->print();
126  }
127 
128  std::unique_ptr<HepMCProduct> BProduct(new HepMCProduct());
129  BProduct->addHepMCData(fEvt);
130  e.put(std::move(BProduct), "unsmeared");
131 
132  std::unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
133  e.put(std::move(genEventInfo));
134 
135  if (fVerbosity > 0) {
136  // for testing purpose only
137  // fEvt->print() ; // prints empty info after it's made into edm::Event
138  edm::LogInfo("RandomtXiGunProducer") << " Event Generation Done \n";
139  }
140 }
141 HepMC::FourVector RandomtXiGunProducer::make_particle(double t, double Xi, double phi, int PartID, int direction) {
142  double mass = PData->mass().value();
143  double fpMom = sqrt(fpEnergy * fpEnergy - mass * mass); // momentum of beam proton
144  double sEnergy = (1.0 - Xi) * fpEnergy; // energy of scattered particle
145  double sMom = sqrt(sEnergy * sEnergy - mass * mass); // momentum of scattered particle
146  double min_t = -2. * (fpMom * sMom - fpEnergy * sEnergy + mass * mass);
147  if (t < min_t)
148  t = min_t; // protect against kinemactically forbiden region
149  long double theta = acos((-t / 2. - mass * mass + fpEnergy * sEnergy) / (sMom * fpMom)); // use t = -t
150 
151  if (direction < 1)
152  theta = acos(-1.) - theta;
153 
154  double px = sMom * cos(phi) * sin(theta);
155  double py = sMom * sin(phi) * sin(theta);
156  double pz = sMom * cos(theta); // the direction is already set by the theta angle
157  if (fVerbosity > 0)
158  edm::LogInfo("RandomXiGunProducer")
159  << "-----------------------------------------------------------------------------------------------------\n"
160  << "Produced a proton with phi : " << phi << " theta: " << theta << " t: " << t << " Xi: " << Xi << "\n"
161  << " Px : " << px << " Py : " << py << " Pz : " << pz << "\n"
162  << " direction: " << direction << "\n"
163  << "-----------------------------------------------------------------------------------------------------"
164  << std::endl;
165 
166  return HepMC::FourVector(px, py, pz, sEnergy);
167 }
168 //#include "FWCore/Framework/interface/MakerMacros.h"
169 //DEFINE_FWK_MODULE(RandomtXiGunProducer);
edm::BaseRandomtXiGunProducer::fEvt
HepMC::GenEvent * fEvt
Definition: BaseRandomtXiGunProducer.h:48
GenEventInfoProduct
Definition: GenEventInfoProduct.h:17
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
edm::RandomtXiGunProducer::fMaxt
double fMaxt
Definition: RandomtXiGunProducer.h:29
MessageLogger.h
edm::BaseRandomtXiGunProducer::fPartIDs
std::vector< int > fPartIDs
Definition: BaseRandomtXiGunProducer.h:41
edm::BaseRandomtXiGunProducer::PData
const HepPDT::ParticleData * PData
Definition: BaseRandomtXiGunProducer.h:54
edm::BaseRandomtXiGunProducer::fMinPhi
double fMinPhi
Definition: BaseRandomtXiGunProducer.h:42
edm::BaseRandomtXiGunProducer::fFireForward
bool fFireForward
Definition: BaseRandomtXiGunProducer.h:56
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
edm
HLT enums.
Definition: AlignableModifier.h:19
RandomNumberGenerator.h
ZgammaFilter_cfi.HepMCProduct
HepMCProduct
Definition: ZgammaFilter_cfi.py:9
edm::LogInfo
Definition: MessageLogger.h:254
edm::RandomtXiGunProducer::produce
void produce(Event &e, const EventSetup &es) override
Definition: RandomtXiGunProducer.cc:43
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::RandomtXiGunProducer::fMint
double fMint
Definition: RandomtXiGunProducer.h:23
edm::BaseRandomtXiGunProducer::fLog_t
bool fLog_t
Definition: BaseRandomtXiGunProducer.h:58
edm::RandomtXiGunProducer::make_particle
HepMC::FourVector make_particle(double t, double Xi, double phi, int PartID, int direction)
Definition: RandomtXiGunProducer.cc:141
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Service.h
edm::RandomtXiGunProducer::RandomtXiGunProducer
RandomtXiGunProducer(const ParameterSet &)
Definition: RandomtXiGunProducer.cc:25
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
RandomtXiGunProducer.h
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
OrderedSet.t
t
Definition: OrderedSet.py:90
edm::RandomtXiGunProducer::fMinXi
double fMinXi
Definition: RandomtXiGunProducer.h:30
edm::BaseRandomtXiGunProducer::fpEnergy
double fpEnergy
Definition: BaseRandomtXiGunProducer.h:44
edm::RandomtXiGunProducer::fMaxXi
double fMaxXi
Definition: RandomtXiGunProducer.h:31
edm::ParameterSet
Definition: ParameterSet.h:36
GenEventInfoProduct.h
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::Service< edm::RandomNumberGenerator >
edm::EventSetup
Definition: EventSetup.h:57
genfragment_ptgun_cfg.PartID
PartID
Definition: genfragment_ptgun_cfg.py:6
edm::RandomtXiGunProducer::~RandomtXiGunProducer
~RandomtXiGunProducer() override
Definition: RandomtXiGunProducer.cc:39
DDAxes::phi
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
edm::BaseRandomtXiGunProducer::fPDGTable
ESHandle< HepPDT::ParticleDataTable > fPDGTable
Definition: BaseRandomtXiGunProducer.h:50
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
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
edm::BaseRandomtXiGunProducer::fFireBackward
bool fFireBackward
Definition: BaseRandomtXiGunProducer.h:57
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
ParameterSet.h
edm::BaseRandomtXiGunProducer
Definition: BaseRandomtXiGunProducer.h:26
HepMCProduct.h
edm::BaseRandomtXiGunProducer::fVerbosity
int fVerbosity
Definition: BaseRandomtXiGunProducer.h:52
edm::Event
Definition: Event.h:73
LHEGenericFilter_cfi.ParticleID
ParticleID
Definition: LHEGenericFilter_cfi.py:6
edm::RandomtXiGunProducer::Minimum_t
double Minimum_t(double xi)
Definition: RandomtXiGunProducer.h:18
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::BaseRandomtXiGunProducer::fMaxPhi
double fMaxPhi
Definition: BaseRandomtXiGunProducer.h:43