10 #include <boost/algorithm/string/trim.hpp>
21 std::memcpy(
value, str.c_str(), len);
29 extern struct UPPRIV {
35 extern struct MEMAIN {
48 std::istringstream
ss(value);
57 if (!result.empty() && result[0] ==
'\'')
58 result = result.substr(1);
59 if (!result.empty() && result[result.length() - 1] ==
'\'')
60 result.resize(result.length() - 1);
67 std::transform(value.begin(), value.end(), value.begin(), (int (*)(int))std::toupper);
68 return value ==
"T" || value ==
"Y" || value ==
"True" || value ==
"1" || value ==
".TRUE.";
75 std::map<std::string, std::string>::const_iterator pos = params.find(var);
76 if (pos == params.end())
78 return parseParameter<T>(pos->second);
86 static std::map<std::string, std::string>
parseHeader(
const std::vector<std::string> &header) {
87 std::map<std::string, std::string>
params;
89 for (std::vector<std::string>::const_iterator iter = header.begin(); iter != header.end(); ++iter) {
91 if (line.empty() || line[0] ==
'#')
95 if (pos != std::string::npos)
99 if (pos == std::string::npos)
102 std::string var = boost::algorithm::trim_copy(line.substr(pos + 1));
111 template <
typename T>
119 throw cms::Exception(
"Generator|PartonShowerVeto") <<
"The MGParamCMS header does not specify the jet "
120 "matching parameter \""
123 "is requested by the CMSSW configuration."
130 if (mode ==
"inclusive") {
133 }
else if (mode ==
"exclusive") {
136 }
else if (mode ==
"auto")
139 throw cms::Exception(
"Generator|LHEInterface") <<
"MGFastJet jet matching scheme requires \"mode\" "
140 "parameter to be set to either \"inclusive\", "
141 "\"exclusive\" or \"auto\"."
156 std::vector<std::string> elems;
157 std::stringstream
ss(list_excres);
160 while (std::getline(ss, item,
',')) {
161 elems.push_back(item);
215 throw cms::Exception(
"Generator|PartonShowerVeto") <<
"Run not initialized in JetMatchingMGFastJet" << std::endl;
217 for (
int i = 0;
i < 3;
i++) {
229 for (
int i = 0;
i < hepeup.
NUP;
i++) {
250 int NPartons =
typeIdx[0].size();
264 std::map<std::string, std::string>
parameters;
266 std::vector<std::string> header = runInfo->
findHeader(
"MGRunCard");
268 throw cms::Exception(
"Generator|PartonShowerVeto") <<
"In order to use MGFastJet jet matching, "
269 "the input file has to contain the corresponding "
277 std::vector<Param>
params;
278 std::vector<Param>
values;
279 for (std::map<std::string, std::string>::const_iterator iter =
mgParams.begin(); iter !=
mgParams.end(); ++iter) {
280 params.push_back(
" " + iter->first);
281 values.push_back(iter->second);
291 std::map<std::string, std::string> mgInfoCMS =
parseHeader(header);
293 for (std::map<std::string, std::string>::const_iterator iter = mgInfoCMS.begin(); iter != mgInfoCMS.end(); ++iter) {
294 std::cout <<
"mgInfoCMS: " << iter->first <<
" " << iter->second << std::endl;
316 int NPartons =
typeIdx[0].size();
321 int ClusSeqNJets = 0;
323 fastjet::ClusterSequence ClusSequence(*jetInput, *
fJetFinder);
333 if (ClusSeqNJets < NPartons)
336 double localQcutSq =
qCutSq;
340 if (ClusSeqNJets > NPartons)
346 fClusJets = ClusSequence.exclusive_jets(NPartons);
347 ClusSeqNJets = NPartons;
353 std::vector<fastjet::PseudoJet> MatchingInput;
355 std::vector<bool> jetAssigned;
356 jetAssigned.assign(
fClusJets.size(),
false);
362 while (counter < NPartons) {
363 MatchingInput.clear();
365 for (
int i = 0;
i < ClusSeqNJets;
i++) {
375 MatchingInput.push_back(fastjet::PseudoJet(exjet.px(), exjet.py(), exjet.pz(), exjet.e()));
376 MatchingInput.back().set_user_index(i);
380 MatchingInput.push_back(
381 fastjet::PseudoJet(hepeup.
PUP[idx][0], hepeup.
PUP[idx][1], hepeup.
PUP[idx][2], hepeup.
PUP[idx][3]));
386 int NBefore = MatchingInput.size();
395 fastjet::ClusterSequence ClusSeq(MatchingInput, *
fJetFinder);
397 const std::vector<fastjet::PseudoJet> &
output = ClusSeq.jets();
398 int NClusJets = output.size() - NBefore;
412 if (NClusJets >= NBefore) {
423 bool matched =
false;
424 const std::vector<fastjet::ClusterSequence::history_element> &
history = ClusSeq.history();
427 for (
unsigned int i = NBefore;
i < output.size();
i++) {
428 int hidx = output[
i].cluster_sequence_history_index();
429 double dNext = history[hidx].dij;
430 if (dNext < localQcutSq) {
435 int parent1 = history[hidx].parent1;
436 int parent2 = history[hidx].parent2;
437 if (parent1 < 0 || parent2 < 0)
442 int pidx = MatchingInput[parent1].user_index();
443 jetAssigned[pidx] =
true;
461 std::vector<double> MergingScale;
462 MergingScale.clear();
463 for (
int nj = 0; nj < 4; nj++) {
464 double dmscale2 = ClusSequence.exclusive_dmerge(nj);
465 double dmscale =
sqrt(dmscale2);
466 MergingScale.push_back(dmscale);
468 fDJROutput.open(
"events.tree", std::ios_base::app);
469 double dNJets = (double)NPartons;
470 fDJROutput <<
" " << dNJets <<
" " << MergingScale[0] <<
" " << MergingScale[1] <<
" " << MergingScale[2] <<
" "
471 << MergingScale[3] << std::endl;
struct gen::OUTTREE outtree_
struct gen::MEMAIN memain_
fastjet::JetDefinition * fJetFinder
JetMatchingMGFastJet(const edm::ParameterSet ¶ms)
double getJetEtaMax() const override
static T getParameter(const std::map< std::string, std::string > ¶ms, const std::string &var, const T &defValue=T())
static void updateOrDie(const std::map< std::string, std::string > ¶ms, T ¶m, const std::string &name)
const HEPEUP * getHEPEUP() const
void beforeHadronisation(const lhef::LHEEvent *) override
int match(const lhef::LHEEvent *partonLevel, const std::vector< fastjet::PseudoJet > *jetInput) override
std::vector< FiveVector > PUP
list var
if using global norm cols_to_minmax = ['t_delta', 't_hmaxNearP','t_emaxNearP', 't_hAnnular', 't_eAnnular','t_pt','t_nVtx','t_ieta','t_eHcal10', 't_eHcal30','t_rhoh','t_eHcal'] df[cols_to_minmax] = df[cols_to_minmax].apply(lambda x: (x - x.min()) / (x.max() - x.min()) if (x.max() - x.min() > 0) else 1.0/200.0)
Abs< T >::type abs(const T &t)
bool initAfterBeams() override
std::vector< std::pair< int, int > > MOTHUP
static std::map< std::string, std::string > parseHeader(const std::vector< std::string > &header)
std::vector< fastjet::PseudoJet > fClusJets
static T parseParameter(const std::string &value)
std::vector< fastjet::PseudoJet > fPtSortedJets
std::map< std::string, std::string > mgParams
T getParameter(std::string const &) const
void init(const lhef::LHERunInfo *runInfo) override
static std::atomic< unsigned int > counter
std::vector< std::string > findHeader(const std::string &tag) const
Power< A, B >::type pow(const A &a, const B &b)
struct gen::UPPRIV uppriv_
std::vector< int > typeIdx[3]