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 
34 HijingHadronizer::HijingHadronizer(const ParameterSet &pset) :
35  BaseHadronizer(pset),
36  evt(0),
37  pset_(pset),
38  bmax_(pset.getParameter<double>("bMax")),
39  bmin_(pset.getParameter<double>("bMin")),
40  efrm_(pset.getParameter<double>("comEnergy")),
41  frame_(pset.getParameter<string>("frame")),
42  proj_(pset.getParameter<string>("proj")),
43  targ_(pset.getParameter<string>("targ")),
44  iap_(pset.getParameter<int>("iap")),
45  izp_(pset.getParameter<int>("izp")),
46  iat_(pset.getParameter<int>("iat")),
47  izt_(pset.getParameter<int>("izt")),
48  phi0_(0.),
49  sinphi0_(0.),
50  cosphi0_(1.),
51  rotate_(pset.getParameter<bool>("rotateEventPlane"))
52 {
53  // Default constructor
55  hijRandomEngine = &(rng->getEngine());
56 
57 }
58 
59 
60 //_____________________________________________________________________
62 {
63  // destructor
64 }
65 
66 //_____________________________________________________________________
67 void HijingHadronizer::add_heavy_ion_rec(HepMC::GenEvent *evt)
68 {
69  // heavy ion record in the final CMSSW Event
70  HepMC::HeavyIon* hi = new HepMC::HeavyIon(
71  himain1.jatt, // Ncoll_hard/N of SubEvents
72  himain1.np, // Npart_proj
73  himain1.nt, // Npart_targ
74  himain1.n0+himain1.n01+himain1.n10+himain1.n11, // Ncoll
75  0, // spectator_neutrons
76  0, // spectator_protons
77  himain1.n01, // N_Nwounded_collisions
78  himain1.n10, // Nwounded_N_collisions
79  himain1.n11, // Nwounded_Nwounded_collisions
80  //gsfs Changed from 19 to 18 (Fortran counts from 1 , not 0)
81  hiparnt.hint1[18], // impact_parameter in [fm]
82  phi0_, // event_plane_angle
83  0, // eccentricity
84  //gsfs Changed from 12 to 11 (Fortran counts from 1 , not 0)
85  hiparnt.hint1[11] // sigma_inel_NN
86  );
87  evt->set_heavy_ion(*hi);
88  delete hi;
89 }
90 
91 //___________________________________________________________________
93 {
94  // Build particle object corresponding to index in hijing
95 
96  double x0 = himain2.patt[0][index];
97  double y0 = himain2.patt[1][index];
98 
99  double x = x0*cosphi0_-y0*sinphi0_;
100  double y = y0*cosphi0_+x0*sinphi0_;
101 
102  // Hijing gives V0's status=4, they need to have status=1 to be decayed in geant
103  // also change status=11 to status=2
104  if(himain2.katt[3][index]<=10 && himain2.katt[3][index]>0) himain2.katt[3][index]=1;
105  if(himain2.katt[3][index]<=20 && himain2.katt[3][index]>10) himain2.katt[3][index]=2;
106 
108  HepMC::FourVector(x, // px
109  y, // py
110  himain2.patt[2][index], // pz
111  himain2.patt[3][index]), // E
112  himain2.katt[0][index],// id
113  himain2.katt[3][index] // status
114  );
115  p->suggest_barcode(barcode);
116 
117  return p;
118 }
119 
120 //___________________________________________________________________
121 HepMC::GenVertex* HijingHadronizer::build_hijing_vertex(int i,int id)
122 {
123  // build verteces for the hijing stored events
124  double x0=himain2.vatt[0][i];
125  double y0=himain2.vatt[1][i];
126  double x = x0*cosphi0_-y0*sinphi0_;
127  double y = y0*cosphi0_+x0*sinphi0_;
128  double z=himain2.vatt[2][i];
129  double t=himain2.vatt[3][i];
130 
131  HepMC::GenVertex* vertex = new HepMC::GenVertex(HepMC::FourVector(x,y,z,t),id);
132  return vertex;
133 }
134 
136 {
137  // generate single event
138  if(rotate_) rotateEvtPlane();
139 
140  // generate a HIJING event
141 
142  float f_bmin = bmin_;
143  float f_bmax = bmax_;
144  HIJING(frame_.data(), f_bmin, f_bmax, strlen(frame_.data()));
145 
146  // event information
147  HepMC::GenEvent *evt = new HepMC::GenEvent();
148  get_particles(evt);
149 
150  // evt->set_signal_process_id(pypars.msti[0]); // type of the process
151  // evt->set_event_scale(pypars.pari[16]); // Q^2
152  add_heavy_ion_rec(evt);
153 
154  event().reset(evt);
155 
156  return true;
157 }
158 
159 //_____________________________________________________________________
160 bool HijingHadronizer::get_particles(HepMC::GenEvent *evt )
161 {
162  HepMC::GenVertex* vertice;
163 
164  vector<HepMC::GenParticle*> particles;
165  vector<int> mother_ids;
166  vector<HepMC::GenVertex*> prods;
167 
168  vertice = new HepMC::GenVertex(HepMC::FourVector(0,0,0,0),0);
169  evt->add_vertex(vertice);
170  if(!evt->signal_process_vertex()) evt->set_signal_process_vertex(vertice);
171 
172  const unsigned int knumpart = himain1.natt;
173 
174  for (unsigned int ipart = 0; ipart<knumpart; ipart++) {
175 
176  int mid = himain2.katt[2][ipart] - 1; // careful of fortan to c++ array index
177 
178  particles.push_back(build_hijing(ipart,ipart+1));
179  prods.push_back(build_hijing_vertex(ipart,0));
180  mother_ids.push_back(mid);
181  LogDebug("DecayChain")<<"Mother index : "<<mid;
182  }
183 
184  LogDebug("Hijing")<<"Number of particles in vector "<<particles.size();
185 
186  for (unsigned int ipart = 0; ipart<particles.size(); ipart++) {
187  HepMC::GenParticle* part = particles[ipart];
188 
189  int mid = mother_ids[ipart];
190  LogDebug("DecayChain")<<"Particle "<<ipart;
191  LogDebug("DecayChain")<<"Mother's ID "<<mid;
192  LogDebug("DecayChain")<<"Particle's PDG ID "<<part->pdg_id();
193 
194  // remove zero pT particles from list, protection for fastJet against pt=0 jets
195  if(part->status()==1&&sqrt(part->momentum().px()*part->momentum().px()+part->momentum().py()*part->momentum().py())==0)
196  continue;
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  HepMC::GenVertex* prod_vertex = mother->end_vertex();
207  if(!prod_vertex){
208  prod_vertex = prods[ipart];
209  prod_vertex->add_particle_in(mother);
210 
211  evt->add_vertex(prod_vertex);
212  prods[ipart]=0; // mark to protect deletion
213 
214  }
215  prod_vertex->add_particle_out(part);
216  }
217  }
218 
219  // cleanup vertices not assigned to evt
220  for (unsigned int i = 0; i<prods.size(); i++) {
221  if(prods[i]) delete prods[i];
222  }
223 
224  return true;
225 }
226 
227 //_____________________________________________________________________
228 bool HijingHadronizer::call_hijset(double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt)
229 {
230 
231  float ef = efrm;
232  // initialize hydjet
233  HIJSET(ef,frame.data(),proj.data(),targ.data(),iap,izp,iat,izt,strlen(frame.data()),strlen(proj.data()),strlen(targ.data()));
234  return true;
235 }
236 
237 //______________________________________________________________
239 
240  //initialize pythia5
241 
242  if(0){
243  std::string dumstr = "";
244  call_pygive(dumstr);
245  }
246 
247  // initialize hijing
248  LogInfo("HIJINGinAction") << "##### Calling HIJSET(" << efrm_ << "," <<frame_<<","<<proj_<<","<<targ_<<","<<iap_<<","<<izp_<<","<<iat_<<","<<izt_<<") ####";
250 
251  return true;
252 
253 }
254 
255 bool HijingHadronizer::declareStableParticles( std::vector<int> pdg )
256 {
257  return true;
258 }
259 
260 //________________________________________________________________
262 
263  phi0_ = 2.*pi*gen::hijran_(0) - pi;
264  sinphi0_ = sin(phi0_);
265  cosphi0_ = cos(phi0_);
266 }
267 
268 //________________________________________________________________
270 {
271  return false;
272 }
273 
275 {
276  return true;
277 }
278 
280 {
281  return true;
282 }
283 
285  return;
286 }
287 
289  return;
290 }
291 
292 const char* HijingHadronizer::classname() const
293 {
294  return "gen::HijingHadronizer";
295 }
296 
#define LogDebug(id)
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)
double double double z
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
T sqrt(T t)
Definition: SSEVec.h:46
#define himain2
Definition: HijingWrapper.h:42
HepMC::GenVertex * build_hijing_vertex(int i, int id)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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:52
bool call_hijset(double efrm, std::string frame, std::string proj, std::string targ, int iap, int izp, int iat, int izt)
double pi
Definition: DDAxes.h:10
float hijran_(int *)
#define himain1
Definition: HijingWrapper.h:33