CMS 3D CMS Logo

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