CMS 3D CMS Logo

PomwigHadronizer.cc
Go to the documentation of this file.
2 
3 #include <cstring>
4 #include <sstream>
5 #include <string>
6 #include <vector>
7 #include <memory>
8 #include <map>
9 #include <set>
10 
11 #include <boost/algorithm/string/classification.hpp>
12 #include <boost/algorithm/string/split.hpp>
13 
14 #include <HepMC/GenEvent.h>
15 #include <HepMC/GenParticle.h>
16 #include <HepMC/GenVertex.h>
17 #include <HepMC/PdfInfo.h>
18 #include <HepMC/HerwigWrapper.h>
19 #include <HepMC/HEPEVT_Wrapper.h>
20 #include <HepMC/IO_HERWIG.h>
21 #include "HepPID/ParticleIDTranslations.hh"
22 
25 
28 
31 
35 
37 
40 
41 namespace gen {
42  extern "C" {
43  void hwuidt_(int *iopt, int *ipdg, int *iwig, char nwig[8]);
44  }
45 
46  // helpers
47  namespace {
48  inline bool call_hwmsct() {
49  int result;
50  hwmsct(&result);
51  return result;
52  }
53 
54  int pdgToHerwig(int ipdg, char *nwig) {
55  int iopt = 1;
56  int iwig = 0;
57  hwuidt_(&iopt, &ipdg, &iwig, nwig);
58  return ipdg ? iwig : 0;
59  }
60 
61  bool markStable(int pdgId) {
62  char nwig[9] = " ";
63  if (!pdgToHerwig(pdgId, nwig))
64  return false;
65  hwusta(nwig, 1);
66  return true;
67  }
68  } // namespace
69 
70 #define qcd_1994 qcd_1994_
71  extern "C" {
72  void qcd_1994(double &, double &, double *, int &);
73  }
74 // For H1 2006 fits
75 #define qcd_2006 qcd_2006_
76  extern "C" {
77  void qcd_2006(double &, double &, int &, double *, double *, double *, double *, double *);
78  }
79 
80  extern "C" {
81  void hwwarn_(const char *method, int *id);
82  void setherwpdf_(void);
83  void mysetpdfpath_(const char *path);
84  }
85 
88 
91  needClear(false),
92  parameters(params.getParameter<edm::ParameterSet>("HerwigParameters")),
93  herwigVerbosity(params.getUntrackedParameter<int>("herwigVerbosity", 0)),
94  hepmcVerbosity(params.getUntrackedParameter<int>("hepmcVerbosity", 0)),
95  maxEventsToPrint(params.getUntrackedParameter<int>("maxEventsToPrint", 0)),
96  printCards(params.getUntrackedParameter<bool>("printCards", false)),
97  comEnergy(params.getParameter<double>("comEnergy")),
98  survivalProbability(params.getParameter<double>("survivalProbability")),
99  diffTopology(params.getParameter<int>("diffTopology")),
100  h1fit(params.getParameter<int>("h1fit")),
101  useJimmy(params.getParameter<bool>("useJimmy")),
102  doMPInteraction(params.getParameter<bool>("doMPInteraction")),
103  numTrials(params.getUntrackedParameter<int>("numTrialsMPI", 100)),
105  if (params.exists("doPDGConvert"))
106  doPDGConvert = params.getParameter<bool>("doPDGConvert");
107  }
108 
110 
111  void PomwigHadronizer::doSetRandomEngine(CLHEP::HepRandomEngine *v) { setHerwigRandomEngine(v); }
112 
114  if (!needClear)
115  return;
116 
117  // teminate elementary process
118  call(hwefin);
119  if (useJimmy)
120  call(jmefin);
121 
122  needClear = false;
123  }
124 
126 
128  clear();
129 
130  edm::LogVerbatim("") << "----------------------------------------------\n"
131  << "Initializing PomwigHadronizer\n"
132  << "----------------------------------------------\n";
133 
134  // Call hwudat to set up HERWIG block data
135  hwudat();
136 
137  // Setting basic parameters ...
138  hwproc.PBEAM1 = comEnergy / 2.;
139  hwproc.PBEAM2 = comEnergy / 2.;
140  // Choose beam particles for POMWIG depending on topology
141  switch (diffTopology) {
142  case 0: //DPE
143  hwbmch.PART1[0] = 'E';
144  hwbmch.PART1[1] = '-';
145  hwbmch.PART2[0] = 'E';
146  hwbmch.PART2[1] = '-';
147  break;
148  case 1: //SD survive PART1
149  hwbmch.PART1[0] = 'E';
150  hwbmch.PART1[1] = '-';
151  hwbmch.PART2[0] = 'P';
152  hwbmch.PART2[1] = ' ';
153  break;
154  case 2: //SD survive PART2
155  hwbmch.PART1[0] = 'P';
156  hwbmch.PART1[1] = ' ';
157  hwbmch.PART2[0] = 'E';
158  hwbmch.PART2[1] = '-';
159  break;
160  case 3: //Non diffractive
161  hwbmch.PART1[0] = 'P';
162  hwbmch.PART1[1] = ' ';
163  hwbmch.PART2[0] = 'P';
164  hwbmch.PART2[1] = ' ';
165  break;
166  default:
167  throw edm::Exception(edm::errors::Configuration, "PomwigError")
168  << " Invalid Diff. Topology. Must be DPE(diffTopology = 0), SD particle 1 (diffTopology = 1), SD particle "
169  "2 (diffTopology = 2) and Non diffractive (diffTopology = 3)";
170  break;
171  }
172  for (int i = 2; i < 8; ++i) {
173  hwbmch.PART1[i] = ' ';
174  hwbmch.PART2[i] = ' ';
175  }
176 
177  // initialize other common blocks ...
178  call(hwigin);
179 
180  hwevnt.MAXER = 100000000; // O(inf)
181  hwpram.LWSUD = 0; // don't write Sudakov form factors
182  hwdspn.LWDEC = 0; // don't write three/four body decays
183  // (no fort.77 and fort.88 ...)a
184 
185  std::memset(hwprch.AUTPDF, ' ', sizeof hwprch.AUTPDF);
186  for (unsigned int i = 0; i < 2; i++) {
187  hwpram.MODPDF[i] = -111;
188  std::memcpy(hwprch.AUTPDF[i], "HWLHAPDF", 8);
189  }
190 
191  hwevnt.MAXPR = maxEventsToPrint;
192  hwpram.IPRINT = herwigVerbosity;
193 
194  edm::LogVerbatim("") << "------------------------------------\n"
195  << "Reading HERWIG parameters\n"
196  << "------------------------------------\n";
197 
199  edm::LogVerbatim("") << " " << *line;
200  if (!give(*line))
202  << "Herwig 6 did not accept the following: \"" << *line << "\"." << std::endl;
203  }
204 
205  needClear = true;
206 
207  return true;
208  }
209 
211  call(hwuinc);
212 
213  hwusta("PI0 ", 1);
214 
215  if (!initializeDPDF())
216  return false;
217 
218  call(hweini);
219 
220  return true;
221  }
222 
224  // Initialize H1 pomeron/reggeon
225 
226  if (diffTopology == 3)
227  return true;
228 
229  if ((diffTopology != 0) && (diffTopology != 1) && (diffTopology != 2))
230  return false;
231 
232  int nstru = hwpram.NSTRU;
233  int ifit = h1fit;
234  if ((nstru == 9) || (nstru == 10)) {
235  if ((ifit <= 0) || (ifit >= 7)) {
236  throw edm::Exception(edm::errors::Configuration, "PomwigError")
237  << " Attempted to set non existant H1 1997 fit index. Has to be 1...6";
238  }
239  std::string aux((nstru == 9) ? "Pomeron" : "Reggeon");
240  edm::LogVerbatim("") << " H1 1997 pdf's: " << aux << "\n"
241  << " IFIT = " << ifit;
242  double xp = 0.1;
243  double Q2 = 75.0;
244  double xpq[13];
245  qcd_1994(xp, Q2, xpq, ifit);
246  } else if ((nstru >= 12) && (nstru <= 15)) {
247  bool isPom = (nstru == 12) || (nstru == 14);
248  bool isFitA = (nstru == 12) || (nstru == 13);
249  ifit = (isFitA) ? 1 : 2;
250  std::string aux_0((isFitA) ? "A" : "B");
251  std::string aux_1((isPom) ? "Pomeron" : "Reggeon");
252  edm::LogVerbatim("") << " H1 2006 Fit " << aux_0 << " " << aux_1 << "\n"
253  << " IFIT = " << ifit;
254  double xp = 0.1;
255  double Q2 = 75.0;
256  double xpq[13];
257  double f2[2];
258  double fl[2];
259  double c2[2];
260  double cl[2];
261  qcd_2006(xp, Q2, ifit, xpq, f2, fl, c2, cl);
262  } else {
263  throw edm::Exception(edm::errors::Configuration, "PomwigError")
264  << " Only running Pomeron H1 1997 (NSTRU=9), H1 2006 fit A (NSTRU=12) and H1 2006 fit B (NSTRU=14) or "
265  "Reggeon H1 1997 (NSTRU=10), H1 2006 fit A (NSTRU=13) and H1 2006 fit B (NSTRU=15)";
266  }
267 
268  return true;
269  }
270 
271  bool PomwigHadronizer::declareStableParticles(const std::vector<int> &pdgIds) {
272  for (std::vector<int>::const_iterator iter = pdgIds.begin(); iter != pdgIds.end(); ++iter)
273  if (!markStable(*iter))
274  return false;
275  return true;
276  }
277 
279  double RNWGT = 1. / hwevnt.NWGTS;
280  double AVWGT = hwevnt.WGTSUM * RNWGT;
281 
282  double xsec = 1.0e3 * AVWGT;
283  xsec = survivalProbability * xsec;
284 
285  runInfo().setInternalXSec(xsec);
286  }
287 
288  bool PomwigHadronizer::hadronize() { return false; }
289 
291  // hard process generation, parton shower, hadron formation
292 
293  InstanceWrapper wrapper(this); // safe guard
294 
295  event().reset();
296 
297  // call herwig routines to create HEPEVT
298 
299  hwuine(); // initialize event
300 
301  if (callWithTimeout(10, hwepro)) { // process event and PS
302  // We hung for more than 10 seconds
303  int error = 199;
304  hwwarn_("HWHGUP", &error);
305  }
306 
307  hwbgen(); // parton cascades
308 
309  // call jimmy ... only if event is not killed yet by HERWIG
310  if (useJimmy && doMPInteraction && !hwevnt.IERROR && call_hwmsct())
311  return false;
312 
313  hwdhob(); // heavy quark decays
314  hwcfor(); // cluster formation
315  hwcdec(); // cluster decays
316 
317  // if event *not* killed by HERWIG, return true
318  if (!hwevnt.IERROR)
319  return true;
320 
321  hwufne(); // finalize event
322  return false;
323  }
324 
327 
328  event()->set_signal_process_id(hwproc.IPROC);
329 
330  event()->weights().push_back(hwevnt.EVWGT);
331  }
332 
334  // hadron decays
335 
336  InstanceWrapper wrapper(this); // safe guard
337 
338  hwdhad(); // unstable particle decays
339  hwdhvy(); // heavy flavour decays
340  hwmevt(); // soft underlying event
341 
342  hwufne(); // finalize event
343 
344  if (hwevnt.IERROR)
345  return false;
346 
347  event().reset(new HepMC::GenEvent);
348  if (!conv.fill_next_event(event().get()))
349  throw cms::Exception("PomwigError") << "HepMC Conversion problems in event." << std::endl;
350 
351  // do particle ID conversion Herwig->PDG, if requested
352  if (doPDGConvert) {
353  for (HepMC::GenEvent::particle_iterator part = event()->particles_begin(); part != event()->particles_end();
354  ++part) {
355  if ((*part)->pdg_id() != HepPID::translateHerwigtoPDT((*part)->pdg_id()))
356  (*part)->set_pdg_id(HepPID::translateHerwigtoPDT((*part)->pdg_id()));
357  }
358  }
359 
360  return true;
361  }
362 
363  bool PomwigHadronizer::residualDecay() { return true; }
364 
365 } //namespace gen
electrons_cff.bool
bool
Definition: electrons_cff.py:372
gen::PomwigHadronizer::needClear
bool needClear
Definition: PomwigHadronizer.h:50
mps_fire.i
i
Definition: mps_fire.py:355
gen::PomwigHadronizer::initializeForExternalPartons
bool initializeForExternalPartons()
Definition: PomwigHadronizer.cc:125
MessageLogger.h
edm::SharedResourceNames::kHerwig6
static const std::string kHerwig6
Definition: SharedResourceNames.h:31
herwig.h
gen::PomwigHadronizer::comEnergy
double comEnergy
Definition: PomwigHadronizer.h:58
funct::false
false
Definition: Factorize.h:34
gen::Herwig6Instance::setHerwigRandomEngine
void setHerwigRandomEngine(CLHEP::HepRandomEngine *v)
Definition: Herwig6Instance.h:38
gen::PomwigHadronizer::survivalProbability
double survivalProbability
Definition: PomwigHadronizer.h:59
qcd_1994
#define qcd_1994
Definition: PomwigHadronizer.cc:70
gen::PomwigHadronizer::herwigVerbosity
int herwigVerbosity
Definition: PomwigHadronizer.h:53
gen::PomwigHadronizer::clear
void clear()
Definition: PomwigHadronizer.cc:113
gen::PomwigHadronizer::initializeDPDF
bool initializeDPDF()
Definition: PomwigHadronizer.cc:223
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
gen::PomwigHadronizer::PomwigHadronizer
PomwigHadronizer(const edm::ParameterSet &params)
Definition: PomwigHadronizer.cc:89
generator_cfi.maxEventsToPrint
maxEventsToPrint
Definition: generator_cfi.py:7
edm
HLT enums.
Definition: AlignableModifier.h:19
BaseHadronizer.h
AlcaSiPixelAliHarvester0T_cff.method
method
Definition: AlcaSiPixelAliHarvester0T_cff.py:41
gen::FortranInstance::kFortranInstance
static const std::string kFortranInstance
Definition: FortranInstance.h:88
gen::ParameterCollector::const_iterator
Definition: ParameterCollector.h:35
hwprch
#define hwprch
Definition: herwig.h:60
wrapper
static HepMC::HEPEVT_Wrapper wrapper
Definition: BeamHaloProducer.cc:47
GenRunInfoProduct::setInternalXSec
void setInternalXSec(const XSec &xsec)
Definition: GenRunInfoProduct.h:26
gen::PomwigHadronizer::declareStableParticles
bool declareStableParticles(const std::vector< int > &pdgIds)
Definition: PomwigHadronizer.cc:271
relativeConstraints.error
error
Definition: relativeConstraints.py:53
gen::BaseHadronizer
Definition: BaseHadronizer.h:46
gen::PomwigHadronizer::initializeForInternalPartons
bool initializeForInternalPartons()
Definition: PomwigHadronizer.cc:210
GenRunInfoProduct.h
gen::PomwigHadronizer::statistics
void statistics()
Definition: PomwigHadronizer.cc:278
gen::PomwigHadronizer::diffTopology
int diffTopology
Definition: PomwigHadronizer.h:60
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
jmefin
#define jmefin
Definition: herwig.h:318
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
GetRecoTauVFromDQM_MC_cff.cl
cl
Definition: GetRecoTauVFromDQM_MC_cff.py:38
gen::PomwigHadronizer::decay
bool decay()
Definition: PomwigHadronizer.cc:333
part
part
Definition: HCALResponse.h:20
gen::PomwigHadronizer::hadronize
bool hadronize()
Definition: PomwigHadronizer.cc:288
gen::PomwigHadronizer::doMPInteraction
bool doMPInteraction
Definition: PomwigHadronizer.h:64
POMWIG_DPEDijets_10TeV_Pt_30_cff.useJimmy
useJimmy
Definition: POMWIG_DPEDijets_10TeV_Pt_30_cff.py:5
POMWIG_DPEDijets_10TeV_Pt_30_cff.diffTopology
diffTopology
Definition: POMWIG_DPEDijets_10TeV_Pt_30_cff.py:33
gen::PomwigHadronizer::maxEventsToPrint
int maxEventsToPrint
Definition: PomwigHadronizer.h:55
ParameterCollector.h
gen::FortranInstance::InstanceWrapper
Definition: FortranInstance.h:54
SharedResourceNames.h
gen
Definition: PythiaDecays.h:13
gen::setherwpdf_
void setherwpdf_(void)
FortranInstance.h
POMWIG_DPEDijets_10TeV_Pt_30_cff.survivalProbability
survivalProbability
Definition: POMWIG_DPEDijets_10TeV_Pt_30_cff.py:34
generator_cfi.comEnergy
comEnergy
Definition: generator_cfi.py:9
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
gen::FortranInstance::call
void call(void(&fn)())
Definition: FortranInstance.h:20
edm::ParameterSet
Definition: ParameterSet.h:36
gen::PomwigHadronizer::useJimmy
bool useJimmy
Definition: PomwigHadronizer.h:63
gen::PomwigHadronizer::theSharedResources
static const std::vector< std::string > theSharedResources
Definition: PomwigHadronizer.h:48
ParameterSet
Definition: Functions.h:16
gen::PomwigHadronizer::readSettings
bool readSettings(int)
Definition: PomwigHadronizer.cc:127
gen::mysetpdfpath_
void mysetpdfpath_(const char *path)
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
gen::PomwigHadronizer::h1fit
int h1fit
Definition: PomwigHadronizer.h:61
gen::v
double v[5][pyjets_maxn]
Definition: Cascade2Hadronizer.cc:74
printConversionInfo.aux
aux
Definition: printConversionInfo.py:19
CosmicGenFilterHelix_cfi.pdgIds
pdgIds
Definition: CosmicGenFilterHelix_cfi.py:5
gen::PomwigHadronizer::doPDGConvert
bool doPDGConvert
Definition: PomwigHadronizer.h:67
createfilelist.int
int
Definition: createfilelist.py:10
edm::LogVerbatim
Definition: MessageLogger.h:297
gen::hwwarn_
void hwwarn_(const char *method, int *id)
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
lhef::LHEEvent::fixHepMCEventTimeOrdering
static void fixHepMCEventTimeOrdering(HepMC::GenEvent *event)
Definition: LHEEvent.cc:451
get
#define get
LesHouches.h
POMWIG_DPEDijets_10TeV_Pt_30_cff.herwigVerbosity
herwigVerbosity
Definition: POMWIG_DPEDijets_10TeV_Pt_30_cff.py:9
POMWIG_DPEDijets_10TeV_Pt_30_cff.doMPInteraction
doMPInteraction
Definition: POMWIG_DPEDijets_10TeV_Pt_30_cff.py:6
hwmsct
#define hwmsct
Definition: herwig.h:317
gen::BaseHadronizer::event
std::unique_ptr< HepMC::GenEvent > & event()
Definition: BaseHadronizer.h:86
gen::PomwigHadronizer::finalizeEvent
void finalizeEvent()
Definition: PomwigHadronizer.cc:325
gen::Herwig6Instance::callWithTimeout
bool callWithTimeout(unsigned int secs, void(*fn)())
Definition: Herwig6Instance.h:30
gen::PomwigHadronizer::generatePartonsAndHadronize
bool generatePartonsAndHadronize()
Definition: PomwigHadronizer.cc:290
Exception
Definition: hltDiff.cc:246
POMWIG_DPEDijets_10TeV_Pt_30_cff.doPDGConvert
doPDGConvert
Definition: POMWIG_DPEDijets_10TeV_Pt_30_cff.py:36
PomwigHadronizer.h
gen::PomwigHadronizer::conv
HepMC::IO_HERWIG conv
Definition: PomwigHadronizer.h:69
LHEEvent.h
POMWIG_DPEDijets_10TeV_Pt_30_cff.printCards
printCards
Definition: POMWIG_DPEDijets_10TeV_Pt_30_cff.py:10
gen::PomwigHadronizer::residualDecay
bool residualDecay()
Definition: PomwigHadronizer.cc:363
mps_fire.result
result
Definition: mps_fire.py:303
qcd_2006
#define qcd_2006
Definition: PomwigHadronizer.cc:75
cms::Exception
Definition: Exception.h:70
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
gen::PomwigHadronizer::~PomwigHadronizer
~PomwigHadronizer() override
Definition: PomwigHadronizer.cc:109
HepMCProduct.h
POMWIG_DPEDijets_10TeV_Pt_30_cff.h1fit
h1fit
Definition: POMWIG_DPEDijets_10TeV_Pt_30_cff.py:35
event
Definition: event.py:1
gen::hwuidt_
void hwuidt_(int *iopt, int *ipdg, int *iwig, char nwig[8])
mps_splice.line
line
Definition: mps_splice.py:76
gen::BaseHadronizer::runInfo
GenRunInfoProduct & runInfo()
Definition: BaseHadronizer.h:85
gen::PomwigHadronizer::doSetRandomEngine
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
Definition: PomwigHadronizer.cc:111
edm::errors::Configuration
Definition: EDMException.h:36
hwdspn
#define hwdspn
Definition: herwig.h:220
Herwig6Instance.h
gen::Herwig6Instance::give
bool give(const std::string &line)
Definition: Herwig6Instance.cc:173
LHECommonBlocks.h