CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::InRun>();
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::auto_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(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::auto_ptr<LHEEventProduct> lhEvent(new LHEEventProduct(hepeup,hepeup.XWGTUP));
190  lhEvent->addComment(makeConfigLine("#IHPRO", ihpro));
191  event.put(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 
virtual void produce(edm::Event &event)
int i
Definition: DBlmapReader.cc:9
virtual ~MCatNLOSource()
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
void mcatnloupinit_(int *, const char *, int)
int emmins
Definition: MCatNLOSource.h:29
def gen
run2 Cosmic #### Run 256259 @ 0T 2015C### Run 272133 @ 3.8T 2016B###
std::vector< std::string > const & fileNames() const
Definition: FromFiles.h:22
double gammax
Definition: MCatNLOSource.h:25
double emmin
Definition: MCatNLOSource.h:23
#define DEFINE_FWK_INPUT_SOURCE(type)
static void readHEPRUP(HEPRUP *heprup)
int rmasss[1000]
Definition: MCatNLOSource.h:32
virtual void endJob()
virtual bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &)
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)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
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
tuple skipEvents
Definition: gather_cfg.py:48
virtual bool hwwarn(const std::string &fn, int code)
std::string fileName
Name of the input file.
Definition: MCatNLOSource.h:61
boost::shared_ptr< lhef::LHERunInfo > runInfo
Definition: MCatNLOSource.h:78
std::unique_ptr< std::ifstream > reader
Definition: MCatNLOSource.h:76
unsigned int skipEvents
Number of events to skip.
Definition: MCatNLOSource.h:67
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:112
volatile std::atomic< bool > shutdown_flag false
void mcatnloupevnt_(int *, int *, int *)
UInt_t nEvents
Definition: hcalCalib.cc:42
long double T
static void readHEPEUP(HEPEUP *hepeup)
virtual void beginRun(edm::Run &run)
double XWGTUP
Definition: LesHouches.h:196
Definition: Run.h:43
static HepMC::HEPEVT_Wrapper wrapper
std::vector< int > LPRUP
Definition: LesHouches.h:124