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/HerwigWrapper.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 
136  clear();
137 
138  edm::LogVerbatim("") << "----------------------------------------------\n"
139  << "Initializing PomwigHadronizer\n"
140  << "----------------------------------------------\n";
141 
142  // Call hwudat to set up HERWIG block data
143  hwudat();
144 
145  // Setting basic parameters ...
146  hwproc.PBEAM1 = comEnergy/2.;
147  hwproc.PBEAM2 = comEnergy/2.;
148  // Choose beam particles for POMWIG depending on topology
149  switch (diffTopology){
150  case 0: //DPE
151  hwbmch.PART1[0] = 'E';
152  hwbmch.PART1[1] = '-';
153  hwbmch.PART2[0] = 'E';
154  hwbmch.PART2[1] = '-';
155  break;
156  case 1: //SD survive PART1
157  hwbmch.PART1[0] = 'E';
158  hwbmch.PART1[1] = '-';
159  hwbmch.PART2[0] = 'P';
160  hwbmch.PART2[1] = ' ';
161  break;
162  case 2: //SD survive PART2
163  hwbmch.PART1[0] = 'P';
164  hwbmch.PART1[1] = ' ';
165  hwbmch.PART2[0] = 'E';
166  hwbmch.PART2[1] = '-';
167  break;
168  case 3: //Non diffractive
169  hwbmch.PART1[0] = 'P';
170  hwbmch.PART1[1] = ' ';
171  hwbmch.PART2[0] = 'P';
172  hwbmch.PART2[1] = ' ';
173  break;
174  default:
175  throw edm::Exception(edm::errors::Configuration,"PomwigError")
176  <<" Invalid Diff. Topology. Must be DPE(diffTopology = 0), SD particle 1 (diffTopology = 1), SD particle 2 (diffTopology = 2) and Non diffractive (diffTopology = 3)";
177  break;
178  }
179  for(int i=2;i<8;++i){
180  hwbmch.PART1[i] = ' ';
181  hwbmch.PART2[i] = ' ';}
182 
183  // initialize other common blocks ...
184  call(hwigin);
185 
186  hwevnt.MAXER = 100000000; // O(inf)
187  hwpram.LWSUD = 0; // don't write Sudakov form factors
188  hwdspn.LWDEC = 0; // don't write three/four body decays
189  // (no fort.77 and fort.88 ...)a
190 
191  std::memset(hwprch.AUTPDF, ' ', sizeof hwprch.AUTPDF);
192  for(unsigned int i = 0; i < 2; i++) {
193  hwpram.MODPDF[i] = -111;
194  std::memcpy(hwprch.AUTPDF[i], "HWLHAPDF", 8);
195  }
196 
197  hwevnt.MAXPR = maxEventsToPrint;
198  hwpram.IPRINT = herwigVerbosity;
199 
200  edm::LogVerbatim("") << "------------------------------------\n"
201  << "Reading HERWIG parameters\n"
202  << "------------------------------------\n";
203 
205  line != parameters.end(); ++line) {
206  edm::LogVerbatim("") << " " << *line;
207  if (!give(*line))
209  << "Herwig 6 did not accept the following: \""
210  << *line << "\"." << std::endl;
211  }
212 
213  needClear = true;
214 
215  return true;
216 
217 }
218 
220 {
221 
222  call(hwuinc);
223 
224  hwusta("PI0 ",1);
225 
226  if(!initializeDPDF()) return false;
227 
228  call(hweini);
229 
230  return true;
231 }
232 
234 {
235  // Initialize H1 pomeron/reggeon
236 
237  if(diffTopology == 3) return true;
238 
239  if((diffTopology != 0)&&(diffTopology != 1)&&(diffTopology != 2)) return false;
240 
241  int nstru = hwpram.NSTRU;
242  int ifit = h1fit;
243  if((nstru == 9)||(nstru == 10)){
244  if((ifit <= 0)||(ifit >= 7)){
245  throw edm::Exception(edm::errors::Configuration,"PomwigError")
246  <<" Attempted to set non existant H1 1997 fit index. Has to be 1...6";
247  }
248  std::string aux((nstru == 9)?"Pomeron":"Reggeon");
249  edm::LogVerbatim("") << " H1 1997 pdf's: " << aux << "\n"
250  << " IFIT = " << ifit;
251  double xp = 0.1;
252  double Q2 = 75.0;
253  double xpq[13];
254  qcd_1994(xp,Q2,xpq,ifit);
255  } else if((nstru >= 12)&&(nstru <= 15)){
256  bool isPom = (nstru == 12)||(nstru == 14);
257  bool isFitA = (nstru == 12)||(nstru == 13);
258  ifit = (isFitA)?1:2;
259  std::string aux_0((isFitA)?"A":"B");
260  std::string aux_1((isPom)?"Pomeron":"Reggeon");
261  edm::LogVerbatim("") << " H1 2006 Fit " << aux_0 << " " << aux_1 << "\n"
262  << " IFIT = "<< ifit;
263  double xp = 0.1;
264  double Q2 = 75.0;
265  double xpq[13];
266  double f2[2];
267  double fl[2];
268  double c2[2];
269  double cl[2];
270  qcd_2006(xp,Q2,ifit,xpq,f2,fl,c2,cl);
271  } else{
272  throw edm::Exception(edm::errors::Configuration,"PomwigError")
273  <<" 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)";
274  }
275 
276  return true;
277 }
278 
279 bool PomwigHadronizer::declareStableParticles(const std::vector<int> &pdgIds)
280 {
281  for(std::vector<int>::const_iterator iter = pdgIds.begin();
282  iter != pdgIds.end(); ++iter)
283  if (!markStable(*iter))
284  return false;
285  return true;
286 }
287 
289 {
290  double RNWGT = 1. / hwevnt.NWGTS;
291  double AVWGT = hwevnt.WGTSUM * RNWGT;
292 
293  double xsec = 1.0e3 * AVWGT;
294  xsec = survivalProbability*xsec;
295 
296  runInfo().setInternalXSec(xsec);
297 }
298 
300 {
301  return false;
302 }
303 
305 {
306  // hard process generation, parton shower, hadron formation
307 
308  InstanceWrapper wrapper(this); // safe guard
309 
310  event().reset();
311 
312  // call herwig routines to create HEPEVT
313 
314  hwuine(); // initialize event
315 
316  if (callWithTimeout(10, hwepro)) { // process event and PS
317  // We hung for more than 10 seconds
318  int error = 199;
319  hwwarn_("HWHGUP", &error);
320  }
321 
322  hwbgen(); // parton cascades
323 
324  // call jimmy ... only if event is not killed yet by HERWIG
325  if (useJimmy && doMPInteraction && !hwevnt.IERROR && call_hwmsct())
326  return false;
327 
328  hwdhob(); // heavy quark decays
329  hwcfor(); // cluster formation
330  hwcdec(); // cluster decays
331 
332  // if event *not* killed by HERWIG, return true
333  if (!hwevnt.IERROR) return true;
334 
335  hwufne(); // finalize event
336  return false;
337 }
338 
340 {
342 
343  event()->set_signal_process_id(hwproc.IPROC);
344 
345  event()->weights().push_back(hwevnt.EVWGT);
346 }
347 
349 {
350  // hadron decays
351 
352  InstanceWrapper wrapper(this); // safe guard
353 
354  hwdhad(); // unstable particle decays
355  hwdhvy(); // heavy flavour decays
356  hwmevt(); // soft underlying event
357 
358  hwufne(); // finalize event
359 
360  if (hwevnt.IERROR)
361  return false;
362 
363  event().reset(new HepMC::GenEvent);
364  if (!conv.fill_next_event(event().get()))
365  throw cms::Exception("PomwigError")
366  << "HepMC Conversion problems in event." << std::endl;
367 
368  // do particle ID conversion Herwig->PDG, if requested
369  if(doPDGConvert){
370  for ( HepMC::GenEvent::particle_iterator part = event()->particles_begin(); part != event()->particles_end(); ++part) {
371  if ((*part)->pdg_id() != HepPID::translateHerwigtoPDT((*part)->pdg_id()))
372  (*part)->set_pdg_id(HepPID::translateHerwigtoPDT((*part)->pdg_id()));
373  }
374  }
375 
376  return true;
377 }
378 
380 {
381  return true;
382 }
383 
384 }//namespace gen
bool declareStableParticles(const std::vector< int > &pdgIds)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
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:508
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
GenRunInfoProduct & runInfo()
list path
Definition: scaleCards.py:51
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)
float cl
Definition: Combine.cc:71
#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