CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
gen::JetMatchingMadgraph Class Reference

#include <JetMatchingMadgraph.h>

Inheritance diagram for gen::JetMatchingMadgraph:
gen::JetMatching

Public Member Functions

 JetMatchingMadgraph (const edm::ParameterSet &params)
 
template<>
std::string parseParameter (const std::string &value)
 
template<>
bool parseParameter (const std::string &value_)
 
 ~JetMatchingMadgraph () override
 
- Public Member Functions inherited from gen::JetMatching
virtual const std::vector< int > * getPartonList ()
 
virtual bool initAfterBeams ()
 
bool isMatchingDone ()
 
 JetMatching (const edm::ParameterSet &params)
 
void resetMatchingStatus ()
 
virtual ~JetMatching ()
 

Protected Member Functions

void beforeHadronisation (const lhef::LHEEvent *event) override
 
void beforeHadronisationExec () override
 
std::set< std::string > capabilities () const override
 
double getJetEtaMax () const override
 
template<typename T >
T getParameter (const std::string &var, const T &defValue=T()) const
 
void init (const lhef::LHERunInfo *runInfo) override
 
int match (const lhef::LHEEvent *partonLevel, const std::vector< fastjet::PseudoJet > *jetInput) override
 

Static Protected Member Functions

template<typename T >
static T getParameter (const std::map< std::string, std::string > &params, const std::string &var, const T &defValue=T())
 
template<typename T >
static T parseParameter (const std::string &value)
 
template<typename T >
static void updateOrDie (const std::map< std::string, std::string > &params, T &param, const std::string &name)
 

Protected Attributes

bool eventInitialized
 
bool exclusive
 
std::map< std::string, std::string > mgParams
 
bool runInitialized
 
bool soup
 
- Protected Attributes inherited from gen::JetMatching
bool fMatchingStatus
 

Additional Inherited Members

- Static Public Member Functions inherited from gen::JetMatching
static std::unique_ptr< JetMatchingcreate (const edm::ParameterSet &params)
 

Detailed Description

Definition at line 8 of file JetMatchingMadgraph.h.

Constructor & Destructor Documentation

◆ JetMatchingMadgraph()

gen::JetMatchingMadgraph::JetMatchingMadgraph ( const edm::ParameterSet params)

Definition at line 112 of file JetMatchingMadgraph.cc.

References gen::MEMAIN::clfact, gen::MEMAIN::etaclmax, gen::MEMAIN::etcjet, Exception, exclusive, gen::MEMAIN::excres, gen::OUTTREE::flag, B2GTnPMonitor_cfi::item, gen::MEMAIN::ktsche, gen::MEMAIN::maxjets, gen::memain_, gen::MEMAIN::minjets, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, gen::MEMAIN::nexcres, gen::MEMAIN::nqmatch, gen::outtree_, submitPVValidationJobs::params, gen::MEMAIN::qcut, gen::MEMAIN::rclmax, gen::MEMAIN::showerkt, soup, contentValuesCheck::ss, and AlCaHLTBitMon_QueryRunRegistry::string.

113  : JetMatching(params), runInitialized(false) {
114  std::string mode = params.getParameter<std::string>("mode");
115  if (mode == "inclusive") {
116  soup = false;
117  exclusive = false;
118  } else if (mode == "exclusive") {
119  soup = false;
120  exclusive = true;
121  } else if (mode == "auto")
122  soup = true;
123  else
124  throw cms::Exception("Generator|LHEInterface") << "Madgraph jet matching scheme requires \"mode\" "
125  "parameter to be set to either \"inclusive\", "
126  "\"exclusive\" or \"auto\"."
127  << std::endl;
128 
129  memain_.etcjet = 0.;
130  memain_.rclmax = 0.0;
131  memain_.clfact = 0.0;
132  memain_.ktsche = 0.0;
133  memain_.etaclmax = params.getParameter<double>("MEMAIN_etaclmax");
134  memain_.qcut = params.getParameter<double>("MEMAIN_qcut");
135  memain_.minjets = params.getParameter<int>("MEMAIN_minjets");
136  memain_.maxjets = params.getParameter<int>("MEMAIN_maxjets");
137  memain_.showerkt = params.getParameter<double>("MEMAIN_showerkt");
138  memain_.nqmatch = params.getParameter<int>("MEMAIN_nqmatch");
139  outtree_.flag = params.getParameter<int>("outTree_flag");
140  std::string list_excres = params.getParameter<std::string>("MEMAIN_excres");
141  std::vector<std::string> elems;
142  std::stringstream ss(list_excres);
144  int index = 0;
145  while (std::getline(ss, item, ',')) {
146  elems.push_back(item);
147  memain_.excres[index] = std::atoi(item.c_str());
148  index++;
149  }
151  }
struct gen::OUTTREE outtree_
struct gen::MEMAIN memain_
JetMatching(const edm::ParameterSet &params)
Definition: JetMatching.cc:17

◆ ~JetMatchingMadgraph()

gen::JetMatchingMadgraph::~JetMatchingMadgraph ( )
override

Definition at line 153 of file JetMatchingMadgraph.cc.

153 {}

Member Function Documentation

◆ beforeHadronisation()

void gen::JetMatchingMadgraph::beforeHadronisation ( const lhef::LHEEvent event)
overrideprotectedvirtual

Reimplemented from gen::JetMatching.

Definition at line 261 of file JetMatchingMadgraph.cc.

References eventInitialized, Exception, mps_fire::i, gen::UPPRIV::ickkw, MT2Analyzer::mt2, lhef::HEPEUP::NUP, DiDispStaMuonMonitor_cfi::pt, gen::PYPART::ptpart, lhef::HEPEUP::PUP, gen::pypart_, runInitialized, mathSSE::sqrt(), contentValuesCheck::ss, and gen::uppriv_.

261  {
262  if (!runInitialized)
263  throw cms::Exception("Generator|PartonShowerVeto") << "Run not initialized in JetMatchingMadgraph" << std::endl;
264 
265  if (uppriv_.ickkw) {
266  std::vector<std::string> comments = event->getComments();
267  if (comments.size() == 1) {
268  std::istringstream ss(comments[0].substr(1));
269  for (int i = 0; i < 1000; i++) {
270  double pt;
271  ss >> pt;
272  if (!ss.good())
273  break;
274  pypart_.ptpart[i] = pt;
275  }
276  } else {
277  edm::LogWarning("Generator|LHEInterface") << "Expected exactly one comment line per "
278  "event containing MadGraph parton scale "
279  "information."
280  << std::endl;
281 
282  const lhef::HEPEUP *hepeup = event->getHEPEUP();
283  for (int i = 2; i < hepeup->NUP; i++) {
284  double mt2 = hepeup->PUP[i][0] * hepeup->PUP[i][0] + hepeup->PUP[i][1] * hepeup->PUP[i][1] +
285  hepeup->PUP[i][4] * hepeup->PUP[i][4];
286  pypart_.ptpart[i - 2] = std::sqrt(mt2);
287  }
288  }
289  }
290 
291  // mgevnt_();
292  eventInitialized = true;
293  }
struct gen::PYPART pypart_
double ptpart[1000]
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< FiveVector > PUP
Definition: LesHouches.h:246
Log< level::Warning, false > LogWarning
struct gen::UPPRIV uppriv_

◆ beforeHadronisationExec()

void gen::JetMatchingMadgraph::beforeHadronisationExec ( )
overrideprotectedvirtual

Reimplemented from gen::JetMatching.

Definition at line 295 of file JetMatchingMadgraph.cc.

References eventInitialized, and gen::mgevnt_().

295  {
296  mgevnt_();
297  eventInitialized = true;
298  return;
299  }
void mgevnt_(void)

◆ capabilities()

std::set< std::string > gen::JetMatchingMadgraph::capabilities ( ) const
overrideprotectedvirtual

Reimplemented from gen::JetMatching.

Definition at line 157 of file JetMatchingMadgraph.cc.

References mps_fire::result.

157  {
158  std::set<std::string> result;
159  result.insert("psFinalState");
160  result.insert("hepevt");
161  result.insert("pythia6");
162  return result;
163  }

◆ getJetEtaMax()

double gen::JetMatchingMadgraph::getJetEtaMax ( ) const
overrideprotectedvirtual

Implements gen::JetMatching.

Definition at line 155 of file JetMatchingMadgraph.cc.

References gen::MEMAIN::etaclmax, and gen::memain_.

155 { return memain_.etaclmax; }
struct gen::MEMAIN memain_

◆ getParameter() [1/2]

template<typename T >
T gen::JetMatchingMadgraph::getParameter ( const std::map< std::string, std::string > &  params,
const std::string &  var,
const T defValue = T() 
)
staticprotected

Definition at line 98 of file JetMatchingMadgraph.cc.

References submitPVValidationJobs::params, and trigObjTnPSource_cfi::var.

Referenced by getParameter(), and updateOrDie().

100  {
101  std::map<std::string, std::string>::const_iterator pos = params.find(var);
102  if (pos == params.end())
103  return defValue;
104  return parseParameter<T>(pos->second);
105  }

◆ getParameter() [2/2]

template<typename T >
T gen::JetMatchingMadgraph::getParameter ( const std::string &  var,
const T defValue = T() 
) const
protected

Definition at line 108 of file JetMatchingMadgraph.cc.

References getParameter(), mgParams, and trigObjTnPSource_cfi::var.

108  {
109  return getParameter(mgParams, var, defValue);
110  }
static T getParameter(const std::map< std::string, std::string > &params, const std::string &var, const T &defValue=T())
std::map< std::string, std::string > mgParams

◆ init()

void gen::JetMatchingMadgraph::init ( const lhef::LHERunInfo runInfo)
overrideprotectedvirtual

Reimplemented from gen::JetMatching.

Definition at line 208 of file JetMatchingMadgraph.cc.

References gather_cfg::cout, gen::MEMAIN::etaclmax, RecoTauValidation_cfi::header, gen::UPPRIV::ickkw, gen::MEMAIN::maxjets, gen::MEMAIN::mektsc, gen::memain_, gen::mginit_(), mgParams, gen::MEMAIN::minjets, gen::MEMAIN::nqmatch, submitPVValidationJobs::params, gen::parseHeader(), gen::MEMAIN::qcut, submitPVValidationJobs::runInfo, runInitialized, gen::MEMAIN::showerkt, updateOrDie(), gen::uppriv_, and contentValuesCheck::values.

208  {
209  // read MadGraph run card
210 
211  std::map<std::string, std::string> parameters;
212 
213  std::vector<std::string> header = runInfo->findHeader("MGRunCard");
214  if (header.empty())
215  throw cms::Exception("Generator|PartonShowerVeto") << "In order to use MadGraph jet matching, "
216  "the input file has to contain the corresponding "
217  "MadGraph headers."
218  << std::endl;
219 
221 
222  // set variables in common block
223 
224  std::vector<Param> params;
225  std::vector<Param> values;
226  for (std::map<std::string, std::string>::const_iterator iter = mgParams.begin(); iter != mgParams.end(); ++iter) {
227  params.push_back(" " + iter->first);
228  values.push_back(iter->second);
229  }
230 
231  // set MG matching parameters
232 
233  uppriv_.ickkw = getParameter<int>("ickkw", 0);
234  memain_.mektsc = getParameter<int>("ktscheme", 0);
235 
236  header = runInfo->findHeader("MGParamCMS");
237 
238  std::map<std::string, std::string> mgInfoCMS = parseHeader(header);
239 
240  for (std::map<std::string, std::string>::const_iterator iter = mgInfoCMS.begin(); iter != mgInfoCMS.end(); ++iter) {
241  std::cout << "mgInfoCMS: " << iter->first << " " << iter->second << std::endl;
242  }
243 
244  updateOrDie(mgInfoCMS, memain_.etaclmax, "etaclmax");
245  updateOrDie(mgInfoCMS, memain_.qcut, "qcut");
246  updateOrDie(mgInfoCMS, memain_.minjets, "minjets");
247  updateOrDie(mgInfoCMS, memain_.maxjets, "maxjets");
248  updateOrDie(mgInfoCMS, memain_.showerkt, "showerkt");
249  updateOrDie(mgInfoCMS, memain_.nqmatch, "nqmatch");
250 
251  // run Fortran initialization code
252 
253  int nparam = params.size();
254  mginit_(&nparam, &params.front(), &values.front());
255  runInitialized = true;
256  }
struct gen::MEMAIN memain_
static void updateOrDie(const std::map< std::string, std::string > &params, T &param, const std::string &name)
static std::map< std::string, std::string > parseHeader(const std::vector< std::string > &header)
std::map< std::string, std::string > mgParams
void mginit_(int *npara, Param *params, Param *values)
struct gen::UPPRIV uppriv_

◆ match()

int gen::JetMatchingMadgraph::match ( const lhef::LHEEvent partonLevel,
const std::vector< fastjet::PseudoJet > *  jetInput 
)
overrideprotectedvirtual

Implements gen::JetMatching.

Definition at line 306 of file JetMatchingMadgraph.cc.

References eventInitialized, Exception, exclusive, gen::JetMatching::fMatchingStatus, gen::MEMAEV::iexc, gen::MEMAIN::maxjets, gen::memaev_, gen::memain_, gen::mgveto_(), gen::MEMAEV::nljets, runInitialized, soup, and PbPb_ZMuSkimMuonDPG_cff::veto.

306  {
307  /*
308  if (!showeredFinalState)
309  throw cms::Exception("Generator|LHEInterface")
310  << "MadGraph matching expected parton shower "
311  "final state." << std::endl;
312 */
313 
314  if (!runInitialized)
315  throw cms::Exception("Generator|LHEInterface") << "Run not initialized in JetMatchingMadgraph" << std::endl;
316 
317  if (!eventInitialized)
318  throw cms::Exception("Generator|LHEInterface") << "Event not initialized in JetMatchingMadgraph" << std::endl;
319 
320  if (soup)
322  else
324 
325  int veto = 0;
326  mgveto_(&veto);
327  fMatchingStatus = true;
328  eventInitialized = false;
329 
330  return veto;
331  }
struct gen::MEMAIN memain_
struct gen::MEMAEV memaev_
void mgveto_(int *veto)

◆ parseParameter() [1/3]

template<typename T >
T gen::JetMatchingMadgraph::parseParameter ( const std::string &  value)
staticprotected

Definition at line 73 of file JetMatchingMadgraph.cc.

References mps_fire::result, and contentValuesCheck::ss.

73  {
74  std::istringstream ss(value);
75  T result;
76  ss >> result;
77  return result;
78  }
Definition: value.py:1
long double T

◆ parseParameter() [2/3]

template<>
std::string gen::JetMatchingMadgraph::parseParameter ( const std::string &  value)

Definition at line 81 of file JetMatchingMadgraph.cc.

References mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

81  {
83  if (!result.empty() && result[0] == '\'')
84  result = result.substr(1);
85  if (!result.empty() && result[result.length() - 1] == '\'')
86  result.resize(result.length() - 1);
87  return result;
88  }

◆ parseParameter() [3/3]

template<>
bool gen::JetMatchingMadgraph::parseParameter ( const std::string &  value_)

Definition at line 91 of file JetMatchingMadgraph.cc.

References createfilelist::int, AlCaHLTBitMon_QueryRunRegistry::string, HcalDetIdTransform::transform(), and relativeConstraints::value.

91  {
92  std::string value(value_);
93  std::transform(value.begin(), value.end(), value.begin(), (int (*)(int))std::toupper);
94  return value == "T" || value == "Y" || value == "True" || value == "1" || value == ".TRUE.";
95  }
Definition: value.py:1
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ updateOrDie()

template<typename T >
void gen::JetMatchingMadgraph::updateOrDie ( const std::map< std::string, std::string > &  params,
T param,
const std::string &  name 
)
staticprotected

Definition at line 191 of file JetMatchingMadgraph.cc.

References Exception, getParameter(), Skims_PA_cff::name, and submitPVValidationJobs::params.

Referenced by init().

193  {
194  if (param < 0) {
195  param = getParameter(params, name, param);
196  }
197  if (param < 0)
198  throw cms::Exception("Generator|PartonShowerVeto") << "The MGParamCMS header does not specify the jet "
199  "matching parameter \""
200  << name
201  << "\", but it "
202  "is requested by the CMSSW configuration."
203  << std::endl;
204  }
static T getParameter(const std::map< std::string, std::string > &params, const std::string &var, const T &defValue=T())

Member Data Documentation

◆ eventInitialized

bool gen::JetMatchingMadgraph::eventInitialized
protected

Definition at line 44 of file JetMatchingMadgraph.h.

Referenced by beforeHadronisation(), beforeHadronisationExec(), and match().

◆ exclusive

bool gen::JetMatchingMadgraph::exclusive
protected

Definition at line 46 of file JetMatchingMadgraph.h.

Referenced by JetMatchingMadgraph(), and match().

◆ mgParams

std::map<std::string, std::string> gen::JetMatchingMadgraph::mgParams
protected

Definition at line 41 of file JetMatchingMadgraph.h.

Referenced by getParameter(), and init().

◆ runInitialized

bool gen::JetMatchingMadgraph::runInitialized
protected

Definition at line 43 of file JetMatchingMadgraph.h.

Referenced by beforeHadronisation(), init(), and match().

◆ soup

bool gen::JetMatchingMadgraph::soup
protected

Definition at line 45 of file JetMatchingMadgraph.h.

Referenced by JetMatchingMadgraph(), and match().