CMS 3D CMS Logo

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