CMS 3D CMS Logo

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