CMS 3D CMS Logo

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