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 conv;
28 
29 namespace gen
30 {
31 extern "C" {
32 extern struct {
33  int mstu[200];
34  double paru[200];
35  int mstj[200];
36  double parj[200];
37 } pydat1_;
38 #define pydat1 pydat1_
39 
40 extern struct {
41  int mstp[200];
42  double parp[200];
43  int msti[200];
44  double pari[200];
45 } pypars_;
46 #define pypars pypars_
47 
48 extern struct {
49  int mint[400];
50  double vint[400];
51 } pyint1_;
52 #define pyint1 pyint1_
53 }
54 
55 extern "C" {
56  void pylist_(int*);
57  int pycomp_(int&);
58  void pygive_(const char*, int);
59 }
60 #define pylist pylist_
61 #define pycomp pycomp_
62 #define pygive pygive_
63 
64 inline void call_pylist( int mode ){ pylist( &mode ); }
65 inline bool call_pygive(const std::string &line)
66 {
67  int numWarn = pydat1.mstu[26]; // # warnings
68  int numErr = pydat1.mstu[22]; // # errors
69 
70  pygive(line.c_str(), line.length());
71 
72  return (pydat1.mstu[26] == numWarn)&&(pydat1.mstu[22] == numErr);
73 }
74 
77 
79  : BaseHadronizer(pset),
80  pythia6Service_(new Pythia6Service(pset)),
81  randomEngine_(nullptr),
82  comEnergy_(pset.getParameter<double>("comEnergy")),
83  myPSet_(pset),
84  hepMCVerbosity_(pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity",false)),
85  maxEventsToPrint_(pset.getUntrackedParameter<int>("maxEventsToPrint", 0)),
86  pythiaListVerbosity_(pset.getUntrackedParameter<int>("pythiaPylistVerbosity", 0)),
87  exhumeEvent_(nullptr)
88 {
89 
90  convertToPDG_ = false;
91  if ( pset.exists( "doPDGConvert" ) )
92  {
93  convertToPDG_ = pset.getParameter<bool>("doPDGConvert");
94  }
95 
96  //pythia6Hadronizer_ = new Pythia6Hadronizer(pset);
97 }
98 
100  //delete pythia6Hadronizer_;
101  delete pythia6Service_;
102  delete exhumeEvent_;
103  delete exhumeProcess_;
104 }
105 
106 void ExhumeHadronizer::doSetRandomEngine(CLHEP::HepRandomEngine* v)
107 {
109  randomEngine_ = v;
110  if(exhumeEvent_) {
112  }
113 }
114 
116 {
117  //pythia6Hadronizer_->finalizeEvent();
118 
119  event()->set_signal_process_id( pypars.msti[0] );
120  event()->set_event_scale( pypars.pari[16] );
121 
122  HepMC::PdfInfo pdf;
123  pdf.set_id1( pyint1.mint[14] == 21 ? 0 : pyint1.mint[14] );
124  pdf.set_id2( pyint1.mint[15] == 21 ? 0 : pyint1.mint[15] );
125  pdf.set_x1( pyint1.vint[40] );
126  pdf.set_x2( pyint1.vint[41] );
127  pdf.set_pdf1( pyint1.vint[38] / pyint1.vint[40] );
128  pdf.set_pdf2( pyint1.vint[39] / pyint1.vint[41] );
129  pdf.set_scalePDF( pyint1.vint[50] );
130 
131  event()->set_pdf_info( pdf ) ;
132 
133  event()->weights().push_back( pyint1.vint[96] );
134 
135  // convert particle IDs Py6->PDG, if requested
136  if(convertToPDG_) {
137  for ( HepMC::GenEvent::particle_iterator part = event()->particles_begin();
138  part != event()->particles_end(); ++part) {
139  (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
140  }
141  }
142 
143  // service printouts, if requested
144  //
145  if (maxEventsToPrint_ > 0)
146  {
149  if (hepMCVerbosity_)
150  {
151  std::cout << "Event process = " << pypars.msti[0] << std::endl
152  << "----------------------" << std::endl;
153  event()->print();
154  }
155  }
156 
157  return;
158 }
159 
161 {
163 
165 
166  // generate event
167 
170 
171  event().reset( conv.read_next_event() );
172 
173  return true;
174 }
175 
177 {
178  return false;
179 }
180 
182 {
183  return true;
184 }
185 
187 {
188  return true;
189 }
190 
192 {
193  return false;
194 }
195 
197 {
198 
200 
202 
203  return true;
204 
205 }
206 
208 {
210 
211  // pythia6Service_->setGeneralParams();
212 
213  //Exhume Initialization
214  edm::ParameterSet processPSet = myPSet_.getParameter<edm::ParameterSet>("ExhumeProcess");
215  std::string processType = processPSet.getParameter<std::string>("ProcessType");
216  int sigID = -1;
217  if(processType == "Higgs"){
219  int higgsDecay = processPSet.getParameter<int>("HiggsDecay");
220  (static_cast<Exhume::Higgs*>(exhumeProcess_))->SetHiggsDecay(higgsDecay);
221  sigID = 100 + higgsDecay;
222  } else if(processType == "QQ"){
224  int quarkType = processPSet.getParameter<int>("QuarkType");
225  double thetaMin = processPSet.getParameter<double>("ThetaMin");
226  ((Exhume::QQ*)exhumeProcess_)->SetQuarkType(quarkType);
227  (static_cast<Exhume::QQ*>(exhumeProcess_))->SetThetaMin(thetaMin);
228  sigID = 200 + quarkType;
229  } else if(processType == "GG"){
231  double thetaMin = processPSet.getParameter<double>("ThetaMin");
232  (static_cast<Exhume::GG*>(exhumeProcess_))->SetThetaMin(thetaMin);
233  sigID = 300;
234  } else if(processType == "DiPhoton"){
236  double thetaMin = processPSet.getParameter<double>("ThetaMin");
237  (static_cast<Exhume::DiPhoton*>(exhumeProcess_))->SetThetaMin(thetaMin);
238  sigID = 400;
239  } else{
240  sigID = -1;
241  throw edm::Exception(edm::errors::Configuration,"ExhumeError") <<" No valid Exhume Process";
242  }
243 
244  pypars.msti[0] = sigID;
246 
247  double massRangeLow = processPSet.getParameter<double>("MassRangeLow");
248  double massRangeHigh = processPSet.getParameter<double>("MassRangeHigh");
249  exhumeEvent_->SetMassRange(massRangeLow,massRangeHigh);
251 
252  return true;
253 }
254 
255 bool ExhumeHadronizer::declareStableParticles(const std::vector<int>& _pdg )
256 {
257  std::vector<int> pdg = _pdg;
258  //return pythia6Hadronizer_->declareStableParticles(pdg);
259 
260  for ( size_t i=0; i < pdg.size(); i++ )
261  {
262  int pyCode = pycomp( pdg[i] );
263  std::ostringstream pyCard ;
264  pyCard << "MDCY(" << pyCode << ",1)=0";
265  std::cout << pyCard.str() << std::endl;
266  call_pygive( pyCard.str() );
267  }
268 
269  return true;
270 
271 }
272 
273 bool ExhumeHadronizer::declareSpecialSettings( const std::vector<std::string>& )
274 {
275  return true;
276 }
277 
279 {
280  std::ostringstream footer_str;
281 
283  double eff = exhumeEvent_->GetEfficiency();
285 
286  footer_str << "\n" <<" You have just been ExHuMEd." << "\n" << "\n";
287  footer_str << " The cross section for process " << name
288  << " is " << cs << " fb" << "\n" << "\n";
289  footer_str << " The efficiency of event generation was " << eff << "%" << "\n" << "\n";
290 
291  edm::LogInfo("") << footer_str.str();
292 
293  if ( !runInfo().internalXSec() )
294  {
295  runInfo().setInternalXSec( cs );
296  }
297 
298  return;
299 }
300 
301 const char* ExhumeHadronizer::classname() const
302 {
303  return "gen::ExhumeHadronizer";
304 }
305 
306 } // namespace gen
#define pydat1
T getParameter(std::string const &) const
auto_ptr< ClusterSequence > cs
Exhume::Event * exhumeEvent_
double CrossSectionCalculation()
ExhumeHadronizer(edm::ParameterSet const &ps)
int mint[400]
int mstp[200]
bool call_pygive(const std::string &line)
bool exists(std::string const &parameterName) const
checks if a parameter exists
double parp[200]
int mstj[200]
std::string GetName()
Definition: CrossSection.h:144
void pylist_(int *)
#define nullptr
void setInternalXSec(const XSec &xsec)
double v[5][pyjets_maxn]
void pygive_(const char *, int)
std::auto_ptr< HepMC::GenEvent > & event()
unsigned int maxEventsToPrint_
double GetEfficiency()
Definition: Event.h:72
static const std::vector< std::string > theSharedResources
static const std::string kPythia6
#define pycomp
GenRunInfoProduct & runInfo()
void call_pylist(int mode)
#define pylist
struct gen::@551 pyint1_
HepMC::IO_HEPEVT conv
Definition: QQ.h:11
struct gen::@550 pypars_
void SetMassRange(const double &Min_, const double &Max_)
Definition: Event.h:54
#define pyint1
int msti[200]
unsigned int pythiaListVerbosity_
void SetRandomEngine(CLHEP::HepRandomEngine *engine)
Definition: Event.h:24
int mstu[200]
Pythia6Service * pythia6Service_
const char * classname() const
void SetParameterSpace()
static const std::string kFortranInstance
static FortranCallback * getInstance()
int pycomp_(int &)
#define pypars
Definition: GG.h:11
struct gen::@549 pydat1_
double paru[200]
edm::ParameterSet myPSet_
part
Definition: HCALResponse.h:20
#define pygive
bool declareStableParticles(const std::vector< int > &)
double pari[200]
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
void setRandomEngine(CLHEP::HepRandomEngine *v)
Exhume::CrossSection * exhumeProcess_
double vint[400]
CLHEP::HepRandomEngine * randomEngine_
bool declareSpecialSettings(const std::vector< std::string > &)
double parj[200]