CMS 3D CMS Logo

MCatNLOSource.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <functional>
3 #include <iostream>
4 #include <sstream>
5 #include <string>
6 #include <memory>
7 
8 #include <boost/bind.hpp>
9 
16 
19 
21 
24 
27 
28 #include "MCatNLOSource.h"
29 
30 
31 // MC@NLO v3.4 LHE file rountines (mcatnlo_hwlhin.f)
32 extern "C" {
33  void mcatnloupinit_(int*, const char*, int);
34  void mcatnloupevnt_(int*, int*, int*);
35 }
36 
37 
38 using namespace lhef;
39 
41  const edm::InputSourceDescription &desc) :
42  ProducerSourceFromFiles(params, desc, false),
43  gen::Herwig6Instance(),
44  skipEvents(params.getUntrackedParameter<unsigned int>("skipEvents", 0)),
45  nEvents(0),
46  ihpro(0),
47  processCode(params.getParameter<int>("processCode"))
48 {
49  std::vector<std::string> allFileNames = fileNames();
50 
51  // Only one filename
52  if (allFileNames.size() != 1)
53  throw cms::Exception("Generator|MCatNLOInterface")
54  << "MCatNLOSource needs exactly one file specified. " <<std::endl;
55 
56  fileName = allFileNames[0];
57 
58  // Strip the "file:" prefix
59  if (fileName.find("file:") != 0)
60  throw cms::Exception("Generator|MCatNLOInterface") << "MCatNLOSource only supports the file: scheme. "<<std::endl;
61  fileName.erase(0, 5);
62 
63  // open input file
64  reader.reset(new std::ifstream(fileName.c_str()));
65 
66  produces<LHEEventProduct>();
67  produces<LHERunInfoProduct, edm::Transition::BeginRun>();
68 }
69 
71 {
72 }
73 
75 {
76  reader.reset();
77 }
78 
80 {
81  return;
82 }
83 
84 template<typename T>
85 static std::string makeConfigLine(const char *var, T value)
86 {
87  std::ostringstream ss;
88  ss << var << " = " << value << "\n";
89  return ss.str();
90 }
91 
92 template<typename T>
93 static std::string makeConfigLine(const char *var, unsigned int index, T value)
94 {
95  std::ostringstream ss;
96  ss << var << "(" << index << ") = " << value << "\n";
97  return ss.str();
98 }
99 
101 {
102  InstanceWrapper wrapper(this);
103 
104  // call UPINIT privided by MC@NLO (v3.4)
105  mcatnloupinit_(&processCode, fileName.c_str(), fileName.length());
106 
107  // fill HEPRUP common block and store in edm::Run
108  lhef::HEPRUP heprup;
110 
111  // make sure we write a valid LHE header, Herwig6Hadronizer
112  // will interpret it correctly and set up LHAPDF
113  heprup.PDFGUP.first = 0;
114  heprup.PDFGUP.second = 0;
115 
116  std::unique_ptr<LHERunInfoProduct> runInfo(new LHERunInfoProduct(heprup));
117 
118  LHERunInfoProduct::Header hw6header("herwig6header");
119  hw6header.addLine("\n");
120  hw6header.addLine("# Herwig6 parameters\n");
121  hw6header.addLine(makeConfigLine("IPROC", processCode));
122  // add lines for parameter that have been touched by UPINIT
123  if(mcpars_.emmins)
124  hw6header.addLine(makeConfigLine("EMMIN", mcpars_.emmin));
125  if(mcpars_.emmaxs)
126  hw6header.addLine(makeConfigLine("EMMAX", mcpars_.emmax));
127  if(mcpars_.gammaxs)
128  hw6header.addLine(makeConfigLine("GAMMAX",mcpars_.gammax));
129  if(mcpars_.gamzs)
130  hw6header.addLine(makeConfigLine("GAMZ",mcpars_.gamz));
131  if(mcpars_.gamws)
132  hw6header.addLine(makeConfigLine("GAMW",mcpars_.gamw));
133  for(unsigned int i=0; i<1000; ++i) {
134  if(mcpars_.rmasss[i])
135  hw6header.addLine(makeConfigLine("RMASS",i+1,mcpars_.rmass[i]));
136  }
137 
138  // other needed MC@NLO defaults (from mcatnlo_hwdriver.f v3.4)
139  hw6header.addLine(makeConfigLine("SOFTME", false));
140  hw6header.addLine(makeConfigLine("NOWGT", false));
141  hw6header.addLine(makeConfigLine("NEGWTS", true));
142  if(abs(processCode)==1705 || abs(processCode)==11705)
143  hw6header.addLine(makeConfigLine("PSPLT",2,0.5));
144  double wgtmax_=1.000001;
145  hw6header.addLine(makeConfigLine("WGTMAX", wgtmax_));
146  hw6header.addLine(makeConfigLine("AVABW", wgtmax_));
147  hw6header.addLine(makeConfigLine("RLTIM",6, 1.0E-23));
148  hw6header.addLine(makeConfigLine("RLTIM",12, 1.0E-23));
149 
150 
151  runInfo->addHeader(hw6header);
152 
153  run.put(std::move(runInfo));
154 
155  return;
156 }
157 
159 {
160  InstanceWrapper wrapper(this);
161 
162  int lastEventDone=0;
163  ihpro=0;
164  // skip events if asked to...
165 
166  while(skipEvents>0) {
167  skipEvents--;
168  mcatnloupevnt_(&processCode,&lastEventDone,&ihpro);
169  if(lastEventDone) return false;
170  }
171 
172  // call UPINIT privided by MC@NLO (v3.4)
173  mcatnloupevnt_(&processCode,&lastEventDone,&ihpro);
174 
175  if(lastEventDone) return false;
176  return true;
177 }
178 
180 {
181  InstanceWrapper wrapper(this);
182 
183  // fill HEPRUP common block and store in edm::Run
184  lhef::HEPRUP heprup;
185  lhef::HEPEUP hepeup;
188  hepeup.IDPRUP = heprup.LPRUP[0];
189  std::unique_ptr<LHEEventProduct> lhEvent(new LHEEventProduct(hepeup,hepeup.XWGTUP));
190  lhEvent->addComment(makeConfigLine("#IHPRO", ihpro));
191  event.put(std::move(lhEvent));
192 }
193 
194 bool MCatNLOSource::hwwarn(const std::string &fn, int code)
195 {
196  // dummy ignoring useless HERWIG warnings
197  return true;
198 }
199 
bool hwwarn(const std::string &fn, int code) override
~MCatNLOSource() override
static std::string makeConfigLine(const char *var, T value)
struct MCPARS_ mcpars_
int emmaxs
Definition: MCatNLOSource.h:30
double rmass[1000]
Definition: MCatNLOSource.h:26
RunNumber_t run() const
void mcatnloupinit_(int *, const char *, int)
int emmins
Definition: MCatNLOSource.h:29
#define DEFINE_FWK_INPUT_SOURCE(type)
std::vector< std::string > const & fileNames() const
Definition: FromFiles.h:22
double gammax
Definition: MCatNLOSource.h:25
double emmin
Definition: MCatNLOSource.h:23
void produce(edm::Event &event) override
static void readHEPRUP(HEPRUP *heprup)
int rmasss[1000]
Definition: MCatNLOSource.h:32
void addLine(const std::string &line)
int gammaxs
Definition: MCatNLOSource.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MCatNLOSource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: value.py:1
double gamz
Definition: MCatNLOSource.h:28
unsigned long long TimeValue_t
Definition: Timestamp.h:28
double emmax
Definition: MCatNLOSource.h:24
double gamw
Definition: MCatNLOSource.h:27
void beginRun(edm::Run &run) override
std::string fileName
Name of the input file.
Definition: MCatNLOSource.h:61
boost::shared_ptr< lhef::LHERunInfo > runInfo
Definition: MCatNLOSource.h:78
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:108
std::unique_ptr< std::ifstream > reader
Definition: MCatNLOSource.h:76
unsigned int skipEvents
Number of events to skip.
Definition: MCatNLOSource.h:67
void endJob() override
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
void mcatnloupevnt_(int *, int *, int *)
UInt_t nEvents
Definition: hcalCalib.cc:41
long double T
static void readHEPEUP(HEPEUP *hepeup)
double XWGTUP
Definition: LesHouches.h:209
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45
static HepMC::HEPEVT_Wrapper wrapper
std::vector< int > LPRUP
Definition: LesHouches.h:137