CMS 3D CMS Logo

PyquenHadronizer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <ctime>
3 
5 
10 
12 
17 
19 
20 #include "HepMC/IO_HEPEVT.h"
21 #include "HepMC/PythiaWrapper.h"
22 
23 using namespace gen;
24 using namespace edm;
25 using namespace std;
26 
27 HepMC::IO_HEPEVT pyquen_hepevtio;
28 
31 
34  pset_(pset),
35  abeamtarget_(pset.getParameter<double>("aBeamTarget")),
36  angularspecselector_(pset.getParameter<int>("angularSpectrumSelector")),
37  bmin_(pset.getParameter<double>("bMin")),
38  bmax_(pset.getParameter<double>("bMax")),
39  bfixed_(pset.getParameter<double>("bFixed")),
40  cflag_(pset.getParameter<int>("cFlag")),
41  comenergy(pset.getParameter<double>("comEnergy")),
42  doquench_(pset.getParameter<bool>("doQuench")),
43  doradiativeenloss_(pset.getParameter<bool>("doRadiativeEnLoss")),
44  docollisionalenloss_(pset.getParameter<bool>("doCollisionalEnLoss")),
45  doIsospin_(pset.getParameter<bool>("doIsospin")),
46  protonSide_(pset.getUntrackedParameter<int>("protonSide", 0)),
47  embedding_(pset.getParameter<int>("embeddingMode")),
48  evtPlane_(0),
49  nquarkflavor_(pset.getParameter<int>("qgpNumQuarkFlavor")),
50  qgpt0_(pset.getParameter<double>("qgpInitialTemperature")),
51  qgptau0_(pset.getParameter<double>("qgpProperTimeFormation")),
52  maxEventsToPrint_(pset.getUntrackedParameter<int>("maxEventsToPrint", 1)),
53  fVertex_(nullptr),
54  pythiaHepMCVerbosity_(pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false)),
55  pythiaPylistVerbosity_(pset.getUntrackedParameter<int>("pythiaPylistVerbosity", 0)),
56  pythia6Service_(new Pythia6Service(pset)),
57  filterType_(pset.getUntrackedParameter<string>("filterType", "None")) {
58  if (pset.exists("signalVtx"))
59  signalVtx_ = pset.getUntrackedParameter<std::vector<double> >("signalVtx");
60 
61  if (signalVtx_.size() == 4) {
62  if (!fVertex_)
63  fVertex_ = new HepMC::FourVector();
64  LogDebug("EventSignalVertex") << "Setting event signal vertex "
65  << " x = " << signalVtx_.at(0) << " y = " << signalVtx_.at(1)
66  << " z= " << signalVtx_.at(2) << " t = " << signalVtx_.at(3) << endl;
67  fVertex_->set(signalVtx_.at(0), signalVtx_.at(1), signalVtx_.at(2), signalVtx_.at(3));
68  }
69 
70  // Verbosity Level
71  // Valid PYLIST arguments are: 1, 2, 3, 5, 7, 11, 12, 13
72  LogDebug("PYLISTverbosity") << "Pythia PYLIST verbosity level = " << pythiaPylistVerbosity_ << endl;
73  // HepMC event verbosity Level
74  pythiaHepMCVerbosity_ = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false);
75  LogDebug("HepMCverbosity") << "Pythia HepMC verbosity = " << pythiaHepMCVerbosity_ << endl;
76 
77  //Max number of events printed on verbosity level
78  maxEventsToPrint_ = pset.getUntrackedParameter<int>("maxEventsToPrint", 0);
79  LogDebug("Events2Print") << "Number of events to be printed = " << maxEventsToPrint_ << endl;
80 
81  if (embedding_ == 1) {
82  cflag_ = 0;
83  src_ = iC.consumes<CrossingFrame<edm::HepMCProduct> >(
84  pset.getUntrackedParameter<edm::InputTag>("backgroundLabel", edm::InputTag("mix", "generatorSmeared")));
85  }
87 
88  int cm = 1, va, vb, vc;
89  PYQVER(cm, va, vb, vc);
90  //HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
91 }
92 
93 //_____________________________________________________________________
95  // distructor
96  call_pystat(1);
97 
98  delete pythia6Service_;
99 }
100 
101 //_____________________________________________________________________
103 
104 //_____________________________________________________________________
106  HepMC::HeavyIon* hi = new HepMC::HeavyIon(1, // Ncoll_hard
107  -1, // Npart_proj
108  -1, // Npart_targ
109  1, // Ncoll
110  -1, // spectator_neutrons
111  -1, // spectator_protons
112  -1, // N_Nwounded_collisions
113  -1, // Nwounded_N_collisions
114  -1, // Nwounded_Nwounded_collisions
115  plfpar.bgen, // impact_parameter in [fm]
116  evtPlane_, // event_plane_angle
117  0, // eccentricity
118  -1 // sigma_inel_NN
119  );
120 
121  evt->set_heavy_ion(*hi);
122 
123  delete hi;
124 }
125 
126 //_____________________________________________________________________
129 
130  // Not possible to retrieve impact paramter and event plane info
131  // at this part, need to overwrite filter() in
132  // PyquenGeneratorFilter
133 
134  if (embedding_ == 1) {
135  const edm::Event& e = getEDMEvent();
136  HepMC::GenVertex* genvtx = nullptr;
137  const HepMC::GenEvent* inev = nullptr;
139  e.getByToken(src_, cf);
141  if (mix.size() < 1) {
142  throw cms::Exception("MatchVtx") << "Mixing has " << mix.size() << " sub-events, should have been at least 1"
143  << endl;
144  }
145  const HepMCProduct& bkg = mix.getObject(0);
146  if (!(bkg.isVtxGenApplied())) {
147  throw cms::Exception("MatchVtx") << "Input background does not have smeared vertex!" << endl;
148  } else {
149  inev = bkg.GetEvent();
150  }
151 
152  genvtx = inev->signal_process_vertex();
153 
154  if (!genvtx)
155  throw cms::Exception("MatchVtx") << "Input background does not have signal process vertex!" << endl;
156 
157  double aX, aY, aZ, aT;
158 
159  aX = genvtx->position().x();
160  aY = genvtx->position().y();
161  aZ = genvtx->position().z();
162  aT = genvtx->position().t();
163 
164  if (!fVertex_) {
165  fVertex_ = new HepMC::FourVector();
166  }
167 
168  //LogInfo("MatchVtx")
169  std::cout << " setting vertex "
170  << " aX " << aX << " aY " << aY << " aZ " << aZ << " aT " << aT << endl;
171  fVertex_->set(aX, aY, aZ, aT);
172 
173  const HepMC::HeavyIon* hi = inev->heavy_ion();
174 
175  if (hi) {
176  bfixed_ = hi->impact_parameter();
177  evtPlane_ = hi->event_plane_angle();
178  } else {
179  LogWarning("EventEmbedding") << "Background event does not have heavy ion record!";
180  }
181  }
182 
183  // Generate PYQUEN event
184  // generate single partonic PYTHIA jet event
185 
186  // Take into account whether it's a nn or pp or pn interaction
187  if (doIsospin_) {
188  string projN = "p";
189  string targN = "p";
190  if (protonSide_ != 1)
191  projN = nucleon();
192  if (protonSide_ != 2)
193  targN = nucleon();
194  call_pyinit("CMS", projN.data(), targN.data(), comenergy);
195  }
196  call_pyevnt();
197 
198  // call PYQUEN to apply parton rescattering and energy loss
199  // if doQuench=FALSE, it is pure PYTHIA
200  if (doquench_) {
202  edm::LogInfo("PYQUENinAction") << "##### Calling PYQUEN(" << abeamtarget_ << "," << cflag_ << "," << bfixed_
203  << ") ####";
204  } else {
205  edm::LogInfo("PYQUENinAction") << "##### Calling PYQUEN: QUENCHING OFF!! This is just PYTHIA !!!! ####";
206  }
207 
208  // call PYTHIA to finish the hadronization
209  pyexec_();
210 
211  // fill the HEPEVT with the PYJETS event record
212  call_pyhepc(1);
213 
214  // event information
215  // pyquen_hepevtio.set_trust_mothers_before_daughters(true);
216  HepMC::GenEvent* evt = pyquen_hepevtio.read_next_event();
217 
218  // signal vertex
219  HepMC::GenVertex* sub_vertices = new HepMC::GenVertex(HepMC::FourVector(0, 0, 0, 0), 0); // just initialization
220  if (!evt->signal_process_vertex())
221  evt->set_signal_process_vertex(sub_vertices);
222 
223  delete sub_vertices;
224  evt->set_signal_process_id(pypars.msti[0]); // type of the process
225  evt->set_event_scale(pypars.pari[16]); // Q^2
226 
227  if (embedding_)
229  add_heavy_ion_rec(evt);
230 
231  if (fVertex_) {
232  // Copy the HepMC::GenEvent
233  std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(evt));
234 
235  HepMCEvt->applyVtxGen(fVertex_);
236  evt = new HepMC::GenEvent((*HepMCEvt->GetEvent()));
237  }
238 
239  // HepMC::HEPEVT_Wrapper::check_hepevt_consistency();
240 
241  event().reset(evt);
242 
243  return true;
244 }
245 
250 
251  //Proton to Nucleon fraction
252  pfrac_ = 1. / (1.98 + 0.015 * pow(abeamtarget_, 2. / 3));
253 
254  //initialize pythia
256 
257  //initilize pyquen
259 
260  return true;
261 }
262 
265 
266  // Call PYTHIA
267  call_pyinit("CMS", "p", "p", comenergy);
268 
269  return true;
270 }
271 
272 //_____________________________________________________________________
274  //Turn Hadronization Off whether or not there is quenching
275  // PYEXEC is called later anyway
276  string sHadOff("MSTP(111)=0");
277  gen::call_pygive(sHadOff);
278 
279  return true;
280 }
281 
282 //_________________________________________________________________
284  // PYQUEN initialization
285 
286  // angular emitted gluon spectrum selection
287  pyqpar.ianglu = angularspecselector_;
288 
289  // type of medium induced partonic energy loss
291  edm::LogInfo("PYQUENinEnLoss") << "##### PYQUEN: Radiative AND Collisional partonic energy loss ON ####";
292  pyqpar.ienglu = 0;
293  } else if (doradiativeenloss_) {
294  edm::LogInfo("PYQUENinRad") << "##### PYQUEN: Only RADIATIVE partonic energy loss ON ####";
295  pyqpar.ienglu = 1;
296  } else if (docollisionalenloss_) {
297  edm::LogInfo("PYQUENinColl") << "##### PYQUEN: Only COLLISIONAL partonic energy loss ON ####";
298  pyqpar.ienglu = 2;
299  } else {
300  edm::LogInfo("PYQUENinEnLoss") << "##### PYQUEN: Radiative AND Collisional partonic energy loss ON ####";
301  pyqpar.ienglu = 0;
302  }
303 
304  // number of active quark flavors in qgp
305  pyqpar.nfu = nquarkflavor_;
306  // initial temperature of QGP
307  pyqpar.T0u = qgpt0_;
308  // proper time of QGP formation
309  pyqpar.tau0u = qgptau0_;
310 
311  return true;
312 }
313 
315  int* dummy = nullptr;
316  double random = gen::pyr_(dummy);
317  const char* nuc = nullptr;
318  if (random > pfrac_)
319  nuc = "n";
320  else
321  nuc = "p";
322 
323  return nuc;
324 }
325 
327  double sinphi0 = sin(angle);
328  double cosphi0 = cos(angle);
329 
330  for (HepMC::GenEvent::vertex_iterator vt = evt->vertices_begin(); vt != evt->vertices_end(); ++vt) {
331  double x0 = (*vt)->position().x();
332  double y0 = (*vt)->position().y();
333  double z = (*vt)->position().z();
334  double t = (*vt)->position().t();
335 
336  double x = x0 * cosphi0 - y0 * sinphi0;
337  double y = y0 * cosphi0 + x0 * sinphi0;
338 
339  (*vt)->set_position(HepMC::FourVector(x, y, z, t));
340  }
341 
342  for (HepMC::GenEvent::particle_iterator vt = evt->particles_begin(); vt != evt->particles_end(); ++vt) {
343  double x0 = (*vt)->momentum().x();
344  double y0 = (*vt)->momentum().y();
345  double z = (*vt)->momentum().z();
346  double t = (*vt)->momentum().t();
347 
348  double x = x0 * cosphi0 - y0 * sinphi0;
349  double y = y0 * cosphi0 + x0 * sinphi0;
350 
351  (*vt)->set_momentum(HepMC::FourVector(x, y, z, t));
352  }
353 }
354 
355 bool PyquenHadronizer::declareStableParticles(const std::vector<int>& _pdg) {
356  std::vector<int> pdg = _pdg;
357  for (size_t i = 0; i < pdg.size(); i++) {
358  int pyCode = pycomp_(pdg[i]);
359  std::ostringstream pyCard;
360  pyCard << "MDCY(" << pyCode << ",1)=0";
361  std::cout << pyCard.str() << std::endl;
362  call_pygive(pyCard.str());
363  }
364 
365  return true;
366 }
367 
368 //____________________________________________________________________
369 
370 bool PyquenHadronizer::hadronize() { return false; }
371 
372 bool PyquenHadronizer::decay() { return true; }
373 
374 bool PyquenHadronizer::residualDecay() { return true; }
375 
377 
379 
380 const char* PyquenHadronizer::classname() const { return "gen::PyquenHadronizer"; }
const char * classname() const
unsigned int maxEventsToPrint_
Events to print if verbosity.
#define plfpar
Definition: PyquenWrapper.h:29
bool pyquen_init(const edm::ParameterSet &pset)
bool declareStableParticles(const std::vector< int > &)
bool isVtxGenApplied() const
Definition: HepMCProduct.h:39
double pyr_(int *idummy)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T const * product() const
Definition: Handle.h:70
bool call_pygive(const std::string &line)
bool doradiativeenloss_
DEFAULT = true.
bool docollisionalenloss_
DEFAULT = true.
double v[5][pyjets_maxn]
void rotateEvtPlane(HepMC::GenEvent *evt, double angle)
#define PYQVER
Definition: PyquenWrapper.h:22
double bmax_
max impact param (fm); valid only if cflag_!=0
double abeamtarget_
beam/target atomic mass number
static const std::string kPythia6
int cflag_
centrality flag =0 fixed impact param, <>0 minbias
edm::Event & getEDMEvent() const
unsigned int pythiaPylistVerbosity_
Pythia PYLIST Verbosity flag.
Definition: EPCuts.h:4
bool doIsospin_
Run n&p with proper ratios; if false, only p+p collisions.
static BaseHiGenEvtSelector * get(std::string, const edm::ParameterSet &)
unsigned int angularspecselector_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > src_
HepMC::FourVector * fVertex_
Event signal vertex.
void add_heavy_ion_rec(HepMC::GenEvent *evt)
Pythia6Service * pythia6Service_
std::unique_ptr< HepMC::GenEvent > & event()
PyquenHadronizer(const edm::ParameterSet &, edm::ConsumesCollector &&)
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
edm::ParameterSet pset_
Log< level::Info, false > LogInfo
static const std::string kFortranInstance
int pycomp_(int &)
#define pypars
bool pyqpythia_init(const edm::ParameterSet &pset)
unsigned int nquarkflavor_
bool doquench_
if true perform quenching (default = true)
std::vector< double > signalVtx_
Pset double vector to set event signal vertex.
double comenergy
collision energy
bool pythiaHepMCVerbosity_
HepMC verbosity flag.
void setRandomEngine(CLHEP::HepRandomEngine *v)
#define pyqpar
HLT enums.
static const std::vector< std::string > theSharedResources
BaseHiGenEvtSelector * selector_
float x
double bmin_
min impact param (fm); valid only if cflag_!=0
#define PYQUEN
Definition: PyquenWrapper.h:17
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
Definition: VertexFwd.h:19
double bfixed_
fixed impact param (fm); valid only if cflag_=0
Log< level::Warning, false > LogWarning
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
double pfrac_
Proton fraction in the nucleus.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
HepMC::IO_HEPEVT pyquen_hepevtio
void pyexec_()
#define LogDebug(id)
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11