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);
HepMC::FourVector make_particle(double t, double Xi, double phi, int PartID, int direction)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
RandomtXiGunProducer(const ParameterSet &)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
T getUntrackedParameter(std::string const &, T const &) const
T sqrt(T t)
Definition: SSEVec.h:23
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ESHandle< HepPDT::ParticleDataTable > fPDGTable
Log< level::Info, false > LogInfo
void produce(Event &e, const EventSetup &es) override
HLT enums.
const HepPDT::ParticleData * PData
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511
def exit(msg="")