CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AMPTHadronizer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 
8 
11 
15 
16 #include "HepMC/GenEvent.h"
17 #include "HepMC/HeavyIon.h"
18 #include "HepMC/SimpleVector.h"
19 #include "CLHEP/Random/RandomEngine.h"
20 
21 static const double pi = 3.14159265358979;
22 
23 using namespace edm;
24 using namespace std;
25 using namespace gen;
26 
27 static CLHEP::HepRandomEngine* amptRandomEngine;
28 
29 extern "C" {
30 float gen::ranart_(int*) {
31  float rannum = amptRandomEngine->flat();
32  return rannum;
33 }
34 }
35 
36 extern "C" {
37 float gen::ran1_(int*) { return amptRandomEngine->flat(); }
38 }
39 
40 AMPTHadronizer::AMPTHadronizer(const ParameterSet& pset)
41  : BaseHadronizer(pset),
42  evt(nullptr),
43  pset_(pset),
44  bmax_(pset.getParameter<double>("bMax")),
45  bmin_(pset.getParameter<double>("bMin")),
46  efrm_(pset.getParameter<double>("comEnergy")),
47  frame_(pset.getParameter<string>("frame")),
48  proj_(pset.getParameter<string>("proj")),
49  targ_(pset.getParameter<string>("targ")),
50  iap_(pset.getParameter<int>("iap")),
51  izp_(pset.getParameter<int>("izp")),
52  iat_(pset.getParameter<int>("iat")),
53  izt_(pset.getParameter<int>("izt")),
54  amptmode_(pset.getParameter<int>("amptmode")),
55  ntmax_(pset.getParameter<int>("ntmax")),
56  dt_(pset.getParameter<double>("dt")),
57  stringFragA_(pset.getParameter<double>("stringFragA")),
58  stringFragB_(pset.getParameter<double>("stringFragB")),
59  popcornmode_(pset.getParameter<bool>("popcornmode")),
60  popcornpar_(pset.getParameter<double>("popcornpar")),
61  shadowingmode_(pset.getParameter<bool>("shadowingmode")),
62  quenchingmode_(pset.getParameter<bool>("quenchingmode")),
63  quenchingpar_(pset.getParameter<double>("quenchingpar")),
64  pthard_(pset.getParameter<double>("pthard")),
65  mu_(pset.getParameter<double>("mu")),
66  izpc_(pset.getParameter<int>("izpc")),
67  alpha_(pset.getParameter<double>("alpha")),
68  dpcoal_(pset.getParameter<double>("dpcoal")),
69  drcoal_(pset.getParameter<double>("drcoal")),
70  ks0decay_(pset.getParameter<bool>("ks0decay")),
71  phidecay_(pset.getParameter<bool>("phidecay")),
72  deuteronmode_(pset.getParameter<int>("deuteronmode")),
73  deuteronfactor_(pset.getParameter<int>("deuteronfactor")),
74  deuteronxsec_(pset.getParameter<int>("deuteronxsec")),
75  minijetpt_(pset.getParameter<double>("minijetpt")),
76  maxmiss_(pset.getParameter<int>("maxmiss")),
77  doInitialAndFinalRadiation_(pset.getParameter<int>("doInitialAndFinalRadiation")),
78  ktkick_(pset.getParameter<int>("ktkick")),
79  diquarkembedding_(pset.getParameter<int>("diquarkembedding")),
80  diquarkpx_(pset.getParameter<double>("diquarkpx")),
81  diquarkpy_(pset.getParameter<double>("diquarkpy")),
82  diquarkx_(pset.getParameter<double>("diquarkx")),
83  diquarky_(pset.getParameter<double>("diquarky")),
84  phi0_(0.),
85  sinphi0_(0.),
86  cosphi0_(1.),
87  rotate_(pset.getParameter<bool>("rotateEventPlane")) {}
88 
89 //_____________________________________________________________________
91 
92 //_____________________________________________________________________
93 void AMPTHadronizer::doSetRandomEngine(CLHEP::HepRandomEngine* v) { amptRandomEngine = v; }
94 
95 //_____________________________________________________________________
97  // heavy ion record in the final CMSSW Event
98  HepMC::HeavyIon* hi = new HepMC::HeavyIon(hmain1.jatt, // Ncoll_hard/N of SubEvents
99  hmain1.np, // Npart_proj
100  hmain1.nt, // Npart_targ
101  hmain1.n0 + hmain1.n01 + hmain1.n10 + hmain1.n11, // Ncoll
102  0, // spectator_neutrons
103  0, // spectator_protons
104  hmain1.n01, // N_Nwounded_collisions
105  hmain1.n10, // Nwounded_N_collisions
106  hmain1.n11, // Nwounded_Nwounded_collisions
107  hparnt.hint1[18], // impact_parameter in [fm]
108  phi0_, // event_plane_angle
109  0, // eccentricity
110  hparnt.hint1[11] // sigma_inel_NN
111  );
112  evt->set_heavy_ion(*hi);
113  delete hi;
114 }
115 
116 //___________________________________________________________________
118  // Build particle object corresponding to index in ampt
119 
120  float px0 = hbt.plast[index][0];
121  float py0 = hbt.plast[index][1];
122  float pz0 = hbt.plast[index][2];
123  float m = hbt.plast[index][3];
124 
125  float px = px0 * cosphi0_ - py0 * sinphi0_;
126  float py = py0 * cosphi0_ + px0 * sinphi0_;
127  float pz = pz0;
128  float e = sqrt(px * px + py * py + pz * pz + m * m);
129  int status = 1;
130 
131  HepMC::GenParticle* p = new HepMC::GenParticle(HepMC::FourVector(px, py, pz, e),
132  INVFLV(hbt.lblast[index]), // id
133  status // status
134  );
135 
136  p->suggest_barcode(barcode);
137  return p;
138 }
139 
140 //___________________________________________________________________
141 HepMC::GenVertex* AMPTHadronizer::build_ampt_vertex(int i, int id) {
142  // build verteces for the ampt stored events
143  HepMC::GenVertex* vertex = new HepMC::GenVertex(HepMC::FourVector(0, 0, 0, 0), id);
144  return vertex;
145 }
146 //_____________________________________________________________________
148  // generate single event
149  if (rotate_)
150  rotateEvtPlane();
151 
152  // generate a AMPT event
153  AMPT(frame_.c_str(), bmin_, bmax_, frame_.length());
154 
155  // event information
157  get_particles(evt);
158 
159  add_heavy_ion_rec(evt);
160 
161  event().reset(evt);
162 
163  return true;
164 }
165 
166 //_____________________________________________________________________
168  HepMC::GenVertex* vertice;
169 
170  vector<HepMC::GenParticle*> particles;
171  vector<int> mother_ids;
172  vector<HepMC::GenVertex*> prods;
173 
174  vertice = new HepMC::GenVertex(HepMC::FourVector(0, 0, 0, 0), 0);
175  evt->add_vertex(vertice);
176  if (!evt->signal_process_vertex())
177  evt->set_signal_process_vertex(vertice);
178 
179  const unsigned int knumpart = hbt.nlast;
180  for (unsigned int ipart = 0; ipart < knumpart; ipart++) {
181  int mid = 0;
182  particles.push_back(build_ampt(ipart, ipart + 1));
183  prods.push_back(build_ampt_vertex(ipart, 0));
184  mother_ids.push_back(mid);
185  LogDebug("DecayChain") << "Mother index : " << mid;
186  }
187 
188  LogDebug("AMPT") << "Number of particles in vector " << particles.size();
189 
190  for (unsigned int ipart = 0; ipart < particles.size(); ipart++) {
191  HepMC::GenParticle* part = particles[ipart];
192 
193  int mid = mother_ids[ipart];
194  LogDebug("DecayChain") << "Particle " << ipart;
195  LogDebug("DecayChain") << "Mother's ID " << mid;
196  LogDebug("DecayChain") << "Particle's PDG ID " << part->pdg_id();
197 
198  if (mid <= 0) {
199  vertice->add_particle_out(part);
200  continue;
201  }
202 
203  if (mid > 0) {
204  HepMC::GenParticle* mother = particles[mid];
205  LogDebug("DecayChain") << "Mother's PDG ID " << mother->pdg_id();
206 
207  HepMC::GenVertex* prod_vertex = mother->end_vertex();
208  if (!prod_vertex) {
209  prod_vertex = prods[ipart];
210  prod_vertex->add_particle_in(mother);
211  evt->add_vertex(prod_vertex);
212  prods[ipart] = nullptr; // mark to protect deletion
213  }
214  prod_vertex->add_particle_out(part);
215  }
216  }
217 
218  // cleanup vertices not assigned to evt
219  for (unsigned int i = 0; i < prods.size(); i++) {
220  if (prods[i])
221  delete prods[i];
222  }
223 
224  return true;
225 }
226 
227 //_____________________________________________________________________
229  double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt) {
230  // initialize hydjet
231  AMPTSET(
232  efrm, frame.c_str(), proj.c_str(), targ.c_str(), iap, izp, iat, izt, frame.length(), proj.length(), targ.length());
233  return true;
234 }
235 //______________________________________________________________________
237  anim.isoft = amptmode_;
238  input2.ntmax = ntmax_;
239  input1.dt = dt_;
240  ludat1.parj[40] = stringFragA_;
241  ludat1.parj[41] = stringFragB_;
242  popcorn.ipop = popcornmode_;
243  ludat1.parj[4] = popcornpar_;
244  hparnt.ihpr2[5] = shadowingmode_;
245  hparnt.ihpr2[3] = quenchingmode_;
246  hparnt.hipr1[13] = quenchingpar_;
247  hparnt.hipr1[7] = pthard_;
248  para2.xmu = mu_;
249  anim.izpc = izpc_;
250  para2.alpha = alpha_;
251  coal.dpcoal = dpcoal_;
252  coal.drcoal = drcoal_;
253  resdcy.iksdcy = ks0decay_;
254  phidcy.iphidcy = phidecay_;
255  para8.idpert = deuteronmode_;
256  para8.npertd = deuteronfactor_;
257  para8.idxsec = deuteronxsec_;
258  phidcy.pttrig = minijetpt_;
259  phidcy.maxmiss = maxmiss_;
261  hparnt.ihpr2[4] = ktkick_;
262  embed.iembed = diquarkembedding_;
263  embed.pxqembd = diquarkpx_;
264  embed.pyqembd = diquarkpy_;
265  embed.xembd = diquarkx_;
266  embed.yembd = diquarky_;
267 
268  return true;
269 }
270 
271 //_____________________________________________________________________
273  // ampt running options
274  ampt_init(pset_);
275 
276  // initialize ampt
277  LogInfo("AMPTinAction") << "##### Calling AMPTSET(" << efrm_ << "," << frame_ << "," << proj_ << "," << targ_ << ","
278  << iap_ << "," << izp_ << "," << iat_ << "," << izt_ << ") ####";
279 
281 
282  return true;
283 }
284 
285 bool AMPTHadronizer::declareStableParticles(const std::vector<int>& pdg) { return true; }
286 
287 //________________________________________________________________
289  int zero = 0;
290  double test = (double)gen::ranart_(&zero);
291  phi0_ = 2. * pi * test - pi;
292  sinphi0_ = sin(phi0_);
293  cosphi0_ = cos(phi0_);
294 }
295 
296 //________________________________________________________________
297 bool AMPTHadronizer::hadronize() { return false; }
298 
299 bool AMPTHadronizer::decay() { return true; }
300 
301 bool AMPTHadronizer::residualDecay() { return true; }
302 
304 
305 void AMPTHadronizer::statistics() { return; }
306 
307 const char* AMPTHadronizer::classname() const { return "gen::AMPTHadronizer"; }
#define popcorn
Definition: AMPTWrapper.h:193
#define ludat1
Definition: AMPTWrapper.h:80
bool initializeForInternalPartons()
float ran1_(int *)
#define phidcy
Definition: AMPTWrapper.h:177
#define AMPT
Definition: AMPTWrapper.h:29
HepMC::GenEvent * evt
void add_heavy_ion_rec(HepMC::GenEvent *evt)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool generatePartonsAndHadronize()
#define hparnt
Definition: AMPTWrapper.h:70
list status
Definition: mps_update.py:107
#define anim
Definition: AMPTWrapper.h:90
double v[5][pyjets_maxn]
#define input2
Definition: AMPTWrapper.h:159
bool declareStableParticles(const std::vector< int > &)
#define embed
Definition: AMPTWrapper.h:188
float ranart_(int *)
const char * classname() const
#define AMPTSET
Definition: AMPTWrapper.h:24
const Double_t pi
#define resdcy
Definition: AMPTWrapper.h:167
bool call_amptset(double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt)
#define hbt
Definition: AMPTWrapper.h:60
double p[5][pyjets_maxn]
T sqrt(T t)
Definition: SSEVec.h:19
~AMPTHadronizer() override
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define hmain1
Definition: AMPTWrapper.h:50
#define para2
Definition: AMPTWrapper.h:110
#define input1
Definition: AMPTWrapper.h:139
uint8_t *__restrict__ izt
edm::ParameterSet pset_
static CLHEP::HepRandomEngine * amptRandomEngine
std::unique_ptr< HepMC::GenEvent > & event()
Log< level::Info, false > LogInfo
part
Definition: HCALResponse.h:20
#define para8
Definition: AMPTWrapper.h:128
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
HepMC::GenParticle * build_ampt(int index, int barcode)
bool ampt_init(const edm::ParameterSet &pset)
#define INVFLV
Definition: AMPTWrapper.h:34
HepMC::GenVertex * build_ampt_vertex(int i, int id)
#define coal
Definition: AMPTWrapper.h:99
bool get_particles(HepMC::GenEvent *evt)
#define LogDebug(id)