CMS 3D CMS Logo

ExhumeHadronizer.cc
Go to the documentation of this file.
2 
5 
9 
10 #include "HepPID/ParticleIDTranslations.hh"
11 
12 #include "HepMC/GenEvent.h"
13 #include "HepMC/PdfInfo.h"
14 #include "HepMC/HEPEVT_Wrapper.h"
15 #include "HepMC/IO_HEPEVT.h"
16 
17 //ExHuME headers
23 
24 #include <string>
25 #include <sstream>
26 
27 HepMC::IO_HEPEVT exhume_conv;
28 
29 namespace gen {
30  extern "C" {
31  extern struct {
32  int mstu[200];
33  double paru[200];
34  int mstj[200];
35  double parj[200];
36  } pydat1_;
37 #define pydat1 pydat1_
38 
39  extern struct {
40  int mstp[200];
41  double parp[200];
42  int msti[200];
43  double pari[200];
44  } pypars_;
45 #define pypars pypars_
46 
47  extern struct {
48  int mint[400];
49  double vint[400];
50  } pyint1_;
51 #define pyint1 pyint1_
52  }
53 
54  extern "C" {
55  void pylist_(int*);
56  int pycomp_(int&);
57  void pygive_(const char*, int);
58  }
59 #define pylist pylist_
60 #define pycomp pycomp_
61 #define pygive pygive_
62 
63  inline void call_pylist(int mode) { pylist(&mode); }
64  inline bool call_pygive(const std::string& line) {
65  int numWarn = pydat1.mstu[26]; // # warnings
66  int numErr = pydat1.mstu[22]; // # errors
67 
68  pygive(line.c_str(), line.length());
69 
70  return (pydat1.mstu[26] == numWarn) && (pydat1.mstu[22] == numErr);
71  }
72 
75 
78  pythia6Service_(new Pythia6Service(pset)),
79  randomEngine_(nullptr),
80  comEnergy_(pset.getParameter<double>("comEnergy")),
81  myPSet_(pset),
82  hepMCVerbosity_(pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false)),
83  maxEventsToPrint_(pset.getUntrackedParameter<int>("maxEventsToPrint", 0)),
84  pythiaListVerbosity_(pset.getUntrackedParameter<int>("pythiaPylistVerbosity", 0)),
85  exhumeEvent_(nullptr) {
86  convertToPDG_ = false;
87  if (pset.exists("doPDGConvert")) {
88  convertToPDG_ = pset.getParameter<bool>("doPDGConvert");
89  }
90 
91  //pythia6Hadronizer_ = new Pythia6Hadronizer(pset);
92  }
93 
95  //delete pythia6Hadronizer_;
96  delete pythia6Service_;
97  delete exhumeEvent_;
98  delete exhumeProcess_;
99  }
100 
101  void ExhumeHadronizer::doSetRandomEngine(CLHEP::HepRandomEngine* v) {
103  randomEngine_ = v;
104  if (exhumeEvent_) {
106  }
107  }
108 
110  //pythia6Hadronizer_->finalizeEvent();
111 
112  event()->set_signal_process_id(pypars.msti[0]);
113  event()->set_event_scale(pypars.pari[16]);
114 
115  HepMC::PdfInfo pdf;
116  pdf.set_id1(pyint1.mint[14] == 21 ? 0 : pyint1.mint[14]);
117  pdf.set_id2(pyint1.mint[15] == 21 ? 0 : pyint1.mint[15]);
118  pdf.set_x1(pyint1.vint[40]);
119  pdf.set_x2(pyint1.vint[41]);
120  pdf.set_pdf1(pyint1.vint[38] / pyint1.vint[40]);
121  pdf.set_pdf2(pyint1.vint[39] / pyint1.vint[41]);
122  pdf.set_scalePDF(pyint1.vint[50]);
123 
124  event()->set_pdf_info(pdf);
125 
126  event()->weights().push_back(pyint1.vint[96]);
127 
128  // convert particle IDs Py6->PDG, if requested
129  if (convertToPDG_) {
130  for (HepMC::GenEvent::particle_iterator part = event()->particles_begin(); part != event()->particles_end();
131  ++part) {
132  (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
133  }
134  }
135 
136  // service printouts, if requested
137  //
138  if (maxEventsToPrint_ > 0) {
142  if (hepMCVerbosity_) {
143  std::cout << "Event process = " << pypars.msti[0] << std::endl << "----------------------" << std::endl;
144  event()->print();
145  }
146  }
147 
148  return;
149  }
150 
153 
155 
156  // generate event
157 
160 
161  event().reset(exhume_conv.read_next_event());
162 
163  return true;
164  }
165 
166  bool ExhumeHadronizer::hadronize() { return false; }
167 
168  bool ExhumeHadronizer::decay() { return true; }
169 
170  bool ExhumeHadronizer::residualDecay() { return true; }
171 
173 
176 
178 
179  return true;
180  }
181 
184 
185  // pythia6Service_->setGeneralParams();
186 
187  //Exhume Initialization
188  edm::ParameterSet processPSet = myPSet_.getParameter<edm::ParameterSet>("ExhumeProcess");
189  std::string processType = processPSet.getParameter<std::string>("ProcessType");
190  int sigID = -1;
191  if (processType == "Higgs") {
193  int higgsDecay = processPSet.getParameter<int>("HiggsDecay");
194  (static_cast<Exhume::Higgs*>(exhumeProcess_))->SetHiggsDecay(higgsDecay);
195  sigID = 100 + higgsDecay;
196  } else if (processType == "QQ") {
198  int quarkType = processPSet.getParameter<int>("QuarkType");
199  double thetaMin = processPSet.getParameter<double>("ThetaMin");
200  ((Exhume::QQ*)exhumeProcess_)->SetQuarkType(quarkType);
201  (static_cast<Exhume::QQ*>(exhumeProcess_))->SetThetaMin(thetaMin);
202  sigID = 200 + quarkType;
203  } else if (processType == "GG") {
205  double thetaMin = processPSet.getParameter<double>("ThetaMin");
206  (static_cast<Exhume::GG*>(exhumeProcess_))->SetThetaMin(thetaMin);
207  sigID = 300;
208  } else if (processType == "DiPhoton") {
210  double thetaMin = processPSet.getParameter<double>("ThetaMin");
211  (static_cast<Exhume::DiPhoton*>(exhumeProcess_))->SetThetaMin(thetaMin);
212  sigID = 400;
213  } else {
214  sigID = -1;
215  throw edm::Exception(edm::errors::Configuration, "ExhumeError") << " No valid Exhume Process";
216  }
217 
218  pypars.msti[0] = sigID;
220 
221  double massRangeLow = processPSet.getParameter<double>("MassRangeLow");
222  double massRangeHigh = processPSet.getParameter<double>("MassRangeHigh");
223  exhumeEvent_->SetMassRange(massRangeLow, massRangeHigh);
225 
226  return true;
227  }
228 
229  bool ExhumeHadronizer::declareStableParticles(const std::vector<int>& _pdg) {
230  std::vector<int> pdg = _pdg;
231  //return pythia6Hadronizer_->declareStableParticles(pdg);
232 
233  for (size_t i = 0; i < pdg.size(); i++) {
234  int pyCode = pycomp(pdg[i]);
235  std::ostringstream pyCard;
236  pyCard << "MDCY(" << pyCode << ",1)=0";
237  std::cout << pyCard.str() << std::endl;
238  call_pygive(pyCard.str());
239  }
240 
241  return true;
242  }
243 
244  bool ExhumeHadronizer::declareSpecialSettings(const std::vector<std::string>&) { return true; }
245 
247  std::ostringstream footer_str;
248 
250  double eff = exhumeEvent_->GetEfficiency();
252 
253  footer_str << "\n"
254  << " You have just been ExHuMEd."
255  << "\n"
256  << "\n";
257  footer_str << " The cross section for process " << name << " is " << cs << " fb"
258  << "\n"
259  << "\n";
260  footer_str << " The efficiency of event generation was " << eff << "%"
261  << "\n"
262  << "\n";
263 
264  edm::LogInfo("") << footer_str.str();
265 
266  if (!runInfo().internalXSec()) {
268  }
269 
270  return;
271  }
272 
273  const char* ExhumeHadronizer::classname() const { return "gen::ExhumeHadronizer"; }
274 
275 } // namespace gen
#define pydat1
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
HepMC::IO_HEPEVT exhume_conv
struct gen::@736 pyint1_
Exhume::Event * exhumeEvent_
double CrossSectionCalculation()
ExhumeHadronizer(edm::ParameterSet const &ps)
int mint[400]
int mstp[200]
struct gen::@735 pypars_
bool call_pygive(const std::string &line)
double parp[200]
int mstj[200]
struct gen::@734 pydat1_
std::string GetName()
Definition: CrossSection.h:105
void pylist_(int *)
void setInternalXSec(const XSec &xsec)
double v[5][pyjets_maxn]
void pygive_(const char *, int)
unsigned int maxEventsToPrint_
double GetEfficiency()
Definition: Event.h:66
static const std::vector< std::string > theSharedResources
static const std::string kPythia6
#define pycomp
GenRunInfoProduct & runInfo()
void call_pylist(int mode)
#define pylist
Definition: QQ.h:11
void SetMassRange(const double &Min_, const double &Max_)
Definition: Event.h:52
#define pyint1
int msti[200]
unsigned int pythiaListVerbosity_
void SetRandomEngine(CLHEP::HepRandomEngine *engine)
Definition: Event.h:22
std::unique_ptr< HepMC::GenEvent > & event()
int mstu[200]
Pythia6Service * pythia6Service_
void SetParameterSpace()
Log< level::Info, false > LogInfo
static const std::string kFortranInstance
static FortranCallback * getInstance()
int pycomp_(int &)
#define pypars
Definition: GG.h:11
double paru[200]
edm::ParameterSet myPSet_
part
Definition: HCALResponse.h:20
#define pygive
bool declareStableParticles(const std::vector< int > &)
double pari[200]
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
void setRandomEngine(CLHEP::HepRandomEngine *v)
Exhume::CrossSection * exhumeProcess_
double vint[400]
CLHEP::HepRandomEngine * randomEngine_
const char * classname() const
bool declareSpecialSettings(const std::vector< std::string > &)
double parj[200]