CMS 3D CMS Logo

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