CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HijingHadronizer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 
4 #include "boost/lexical_cast.hpp"
5 
14 
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* hijRandomEngine;
34 
35 extern "C"
36 {
37  double gen::hijran_(int *idummy)
38  {
39  return hijRandomEngine->flat();
40  }
41 }
42 
43 HijingHadronizer::HijingHadronizer(const ParameterSet &pset) :
44  BaseHadronizer(pset),
45  evt(0),
46  pset_(pset),
47  bmax_(pset.getParameter<double>("bMax")),
48  bmin_(pset.getParameter<double>("bMin")),
49  efrm_(pset.getParameter<double>("comEnergy")),
50  frame_(pset.getParameter<string>("frame")),
51  proj_(pset.getParameter<string>("proj")),
52  targ_(pset.getParameter<string>("targ")),
53  iap_(pset.getParameter<int>("iap")),
54  izp_(pset.getParameter<int>("izp")),
55  iat_(pset.getParameter<int>("iat")),
56  izt_(pset.getParameter<int>("izt")),
57  phi0_(0.),
58  sinphi0_(0.),
59  cosphi0_(1.),
60  rotate_(pset.getParameter<bool>("rotateEventPlane"))
61 {
62  // Default constructor
64  hijRandomEngine = &(rng->getEngine());
65 
66 }
67 
68 
69 //_____________________________________________________________________
71 {
72  // destructor
73 }
74 
75 //_____________________________________________________________________
76 void HijingHadronizer::add_heavy_ion_rec(HepMC::GenEvent *evt)
77 {
78  // heavy ion record in the final CMSSW Event
79  HepMC::HeavyIon* hi = new HepMC::HeavyIon(
80  himain1.jatt, // Ncoll_hard/N of SubEvents
81  himain1.np, // Npart_proj
82  himain1.nt, // Npart_targ
83  himain1.n0+himain1.n01+himain1.n10+himain1.n11, // Ncoll
84  0, // spectator_neutrons
85  0, // spectator_protons
86  himain1.n01, // N_Nwounded_collisions
87  himain1.n10, // Nwounded_N_collisions
88  himain1.n11, // Nwounded_Nwounded_collisions
89  //gsfs Changed from 19 to 18 (Fortran counts from 1 , not 0)
90  hiparnt.hint1[18], // impact_parameter in [fm]
91  phi0_, // event_plane_angle
92  0, // eccentricity
93  //gsfs Changed from 12 to 11 (Fortran counts from 1 , not 0)
94  hiparnt.hint1[11] // sigma_inel_NN
95  );
96  evt->set_heavy_ion(*hi);
97  delete hi;
98 }
99 
100 //___________________________________________________________________
102 {
103  // Build particle object corresponding to index in hijing
104 
105  double x0 = himain2.patt[0][index];
106  double y0 = himain2.patt[1][index];
107 
108  double x = x0*cosphi0_-y0*sinphi0_;
109  double y = y0*cosphi0_+x0*sinphi0_;
110 
112  HepMC::FourVector(x, // px
113  y, // py
114  himain2.patt[2][index], // pz
115  himain2.patt[3][index]), // E
116  himain2.katt[0][index],// id
117  himain2.katt[3][index] // status
118  );
119  p->suggest_barcode(barcode);
120 
121  return p;
122 }
123 
124 //___________________________________________________________________
125 HepMC::GenVertex* HijingHadronizer::build_hijing_vertex(int i,int id)
126 {
127  // build verteces for the hijing stored events
128  HepMC::GenVertex* vertex = new HepMC::GenVertex(HepMC::FourVector(0,0,0,0),id);
129  return vertex;
130 }
131 
133 {
134  // generate single event
135  if(rotate_) rotateEvtPlane();
136 
137  // generate a HIJING event
138  HIJING(frame_.data(), bmin_, bmax_, strlen(frame_.data()));
139 
140  // event information
141  HepMC::GenEvent *evt = new HepMC::GenEvent();
142  get_particles(evt);
143 
144  // evt->set_signal_process_id(pypars.msti[0]); // type of the process
145  // evt->set_event_scale(pypars.pari[16]); // Q^2
146  add_heavy_ion_rec(evt);
147 
148  event().reset(evt);
149 
150 
151  return true;
152 }
153 
154 //_____________________________________________________________________
155 bool HijingHadronizer::get_particles(HepMC::GenEvent *evt )
156 {
157  HepMC::GenVertex* vertice;
158 
159  vector<HepMC::GenParticle*> particles;
160  vector<int> mother_ids;
161  vector<HepMC::GenVertex*> prods;
162 
163  vertice = new HepMC::GenVertex(HepMC::FourVector(0,0,0,0),0);
164  evt->add_vertex(vertice);
165  if(!evt->signal_process_vertex()) evt->set_signal_process_vertex(vertice);
166 
167  const unsigned int knumpart = himain1.natt;
168  for (unsigned int ipart = 0; ipart<knumpart; ipart++) {
169 
170  int mid = himain2.katt[2][ipart];
171  particles.push_back(build_hijing(ipart,ipart+1));
172  prods.push_back(build_hijing_vertex(ipart,0));
173  mother_ids.push_back(mid);
174  LogDebug("DecayChain")<<"Mother index : "<<mid;
175  }
176 
177  LogDebug("Hijing")<<"Number of particles in vector "<<particles.size();
178 
179  for (unsigned int ipart = 0; ipart<particles.size(); ipart++) {
180  HepMC::GenParticle* part = particles[ipart];
181 
182  int mid = mother_ids[ipart];
183  LogDebug("DecayChain")<<"Particle "<<ipart;
184  LogDebug("DecayChain")<<"Mother's ID "<<mid;
185  LogDebug("DecayChain")<<"Particle's PDG ID "<<part->pdg_id();
186 
187  if(mid <= 0){
188  vertice->add_particle_out(part);
189  continue;
190  }
191 
192  if(mid > 0){
193  HepMC::GenParticle* mother = particles[mid];
194  LogDebug("DecayChain")<<"Mother's PDG ID "<<mother->pdg_id();
195 
196  HepMC::GenVertex* prod_vertex = mother->end_vertex();
197  if(!prod_vertex){
198  prod_vertex = prods[ipart];
199  prod_vertex->add_particle_in(mother);
200  evt->add_vertex(prod_vertex);
201  prods[ipart]=0; // mark to protect deletion
202 
203  }
204  prod_vertex->add_particle_out(part);
205  }
206  }
207 
208  // cleanup vertices not assigned to evt
209  for (unsigned int i = 0; i<prods.size(); i++) {
210  if(prods[i]) delete prods[i];
211  }
212 
213  return true;
214 }
215 
216 //_____________________________________________________________________
217 bool HijingHadronizer::call_hijset(double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt)
218 {
219  // initialize hydjet
220  HIJSET(efrm,frame.data(),proj.data(),targ.data(),iap,izp,iat,izt,strlen(frame.data()),strlen(proj.data()),strlen(targ.data()));
221  return true;
222 }
223 
224 //______________________________________________________________
226 
227  //initialize pythia5
228 
229  if(0){
230  std::string dumstr = "";
231  call_pygive(dumstr);
232  }
233 
234  // initialize hijing
235  LogInfo("HIJINGinAction") << "##### Calling HIJSET(" << efrm_ << "," <<frame_<<","<<proj_<<","<<targ_<<","<<iap_<<","<<izp_<<","<<iat_<<","<<izt_<<") ####";
237 
238  return true;
239 
240 }
241 
242 bool HijingHadronizer::declareStableParticles( std::vector<int> pdg )
243 {
244  return true;
245 }
246 
247 //________________________________________________________________
249 
250  phi0_ = 2.*pi*gen::hijran_(0) - pi;
251  sinphi0_ = sin(phi0_);
252  cosphi0_ = cos(phi0_);
253 }
254 
255 //________________________________________________________________
257 {
258  return false;
259 }
260 
262 {
263  return true;
264 }
265 
267 {
268  return true;
269 }
270 
272  return;
273 }
274 
276  return;
277 }
278 
279 const char* HijingHadronizer::classname() const
280 {
281  return "gen::HijingHadronizer";
282 }
283 
#define LogDebug(id)
double hijran_(int *)
int i
Definition: DBlmapReader.cc:9
HepMC::GenEvent * evt
HepMC::GenParticle * build_hijing(int index, int barcode)
CLHEP::HepRandomEngine * hijRandomEngine
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool call_pygive(const std::string &line)
std::auto_ptr< HepMC::GenEvent > & event()
void add_heavy_ion_rec(HepMC::GenEvent *evt)
double p[5][pyjets_maxn]
bool declareStableParticles(const std::vector< int >)
#define HIJSET
Definition: HijingWrapper.h:13
#define himain2
Definition: HijingWrapper.h:41
HepMC::GenVertex * build_hijing_vertex(int i, int id)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
tuple pset
Definition: CrabTask.py:85
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
const char * classname() const
bool get_particles(HepMC::GenEvent *evt)
#define HIJING
Definition: HijingWrapper.h:18
part
Definition: HCALResponse.h:21
#define hiparnt
Definition: HijingWrapper.h:51
bool call_hijset(double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt)
double pi
#define himain1
Definition: HijingWrapper.h:33