Skip to content

Commit

Permalink
Merge pull request cms-sw#14 from kdlong/ImprovedParsing
Browse files Browse the repository at this point in the history
Improved parsing
  • Loading branch information
kdlong authored Jul 9, 2020
2 parents fec4dd1 + 8eeaff3 commit 3d8e722
Show file tree
Hide file tree
Showing 48 changed files with 16,639 additions and 1,212 deletions.
72 changes: 72 additions & 0 deletions GeneratorInterface/Core/files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
M Configuration/Applications/python/ConfigBuilder.py
M DataFormats/NanoAOD/src/classes_def.xml
M GeneratorInterface/Core/BuildFile.xml
A GeneratorInterface/Core/interface/GenWeightHelper.h
A GeneratorInterface/Core/interface/LHEWeightHelper.h
A GeneratorInterface/Core/interface/WeightHelper.h
M GeneratorInterface/Core/plugins/BuildFile.xml
A GeneratorInterface/Core/plugins/GenWeightProductProducer.cc
A GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc
A GeneratorInterface/Core/src/GenWeightHelper.cc
A GeneratorInterface/Core/src/LHEWeightHelper.cc
A GeneratorInterface/Core/src/WeightHelper.cc
A GeneratorInterface/Core/test/dumpWeightInfo.py
A GeneratorInterface/Core/test/testGenWeightProducer_cfg.py
M GeneratorInterface/LHEInterface/plugins/BuildFile.xml
M GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc
M GeneratorInterface/LHEInterface/plugins/LHESource.cc
M GeneratorInterface/LHEInterface/plugins/LHESource.h
A GeneratorInterface/LHEInterface/test/test_Weights_cfg.py
M GeneratorInterface/PhotosInterface/plugins/PhotosppInterface.cc
M GeneratorInterface/PhotosInterface/test/DYphotospp_Tune4C_13TeV_pythia8.py
M PhysicsTools/NanoAOD/BuildFile.xml
M PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc
A PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc
M PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc
M PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc
M PhysicsTools/NanoAOD/plugins/TableOutputBranches.h
M PhysicsTools/NanoAOD/python/NanoAODEDMEventContent_cff.py
A PhysicsTools/NanoAOD/python/genWeightsTable_cfi.py
M PhysicsTools/NanoAOD/python/nano_cff.py
A PhysicsTools/NanoAOD/python/nanogen_cff.py
A PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py
A SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h
A SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h
A SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h
A SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h
A SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h
A SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h
A SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h
A SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h
A SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc
A SimDataFormats/GeneratorProducts/src/MEParamWeightGroupInfo.cc
A SimDataFormats/GeneratorProducts/src/PartonShowerWeights.cc
A SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc
A SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc
A SimDataFormats/GeneratorProducts/src/UnknownWeightGroupInfo.cc
A SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc
M SimDataFormats/GeneratorProducts/src/classes.h
M SimDataFormats/GeneratorProducts/src/classes_def.xml
A Test/Test/BuildFile.xml
A Test/Test/interface/test.h
A Test/Test/src/classes.h
A Test/Test/src/classes_def.xml
A Test/Test/src/test.cc
A lhe_test.C
A testFiles/DrellYan_LO_MGMLMv233_2016_weightInfo.txt
A testFiles/DrellYan_LO_MGMLMv242_2017_weightInfo.txt
A testFiles/DrellYan_NLO_MGFXFXv233_2016_weightInfo.txt
A testFiles/DrellYan_NLO_MGFXFXv242_2017_weightInfo.txt
A testFiles/VVV_2017_weight_info.txt
A testFiles/W1jet_260_simplescale_weight_info.txt
A testFiles/W1jet_260_weight_info.txt
A testFiles/WJ_MiNNLO_weightinfo.txt
A testFiles/WJ_NNLOPS_weightinfo.txt
A testFiles/WZVBS_2017_weightInfo.txt
A testFiles/WZVBS_private_weightInfo.txt
A testFiles/ZJ_MiNNLO_weightinfo.txt
A testFiles/ZMiNNLO.txt
A testFiles/ZZTo4L_powheg_2016_weightInfo.txt
A testFiles/ZZTo4L_powheg_2017_weightInfo.txt
A testFiles/overview.txt
A testFiles/susyweights.txt
17 changes: 8 additions & 9 deletions GeneratorInterface/Core/interface/GenWeightHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
#include <tinyxml2.h>

namespace gen {
class GenWeightHelper : public WeightHelper {
public:
GenWeightHelper();
class GenWeightHelper : public WeightHelper {
public:
GenWeightHelper();

void parseWeightGroupsFromNames(std::vector<std::string> weightNames);
private:
};
}

#endif
void parseWeightGroupsFromNames(std::vector<std::string> weightNames);

private:
};
} // namespace gen

#endif
26 changes: 14 additions & 12 deletions GeneratorInterface/Core/interface/LHEWeightHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@
#include <tinyxml2.h>

namespace gen {
class LHEWeightHelper : public WeightHelper {
public:
LHEWeightHelper() : WeightHelper() {};
void setHeaderLines(std::vector<std::string> headerLines);
void parseWeights();
void buildGroups();
std::unique_ptr<WeightGroupInfo> buildGroup(const ParsedWeight& weight);
private:
std::vector<std::string> headerLines_;
};
}
class LHEWeightHelper : public WeightHelper {
public:
LHEWeightHelper() : WeightHelper(){};
void setHeaderLines(std::vector<std::string> headerLines);
void parseWeights();
void buildGroups();
bool isConsistent();
void swapHeaders();
std::unique_ptr<WeightGroupInfo> buildGroup(ParsedWeight& weight);

#endif
private:
std::vector<std::string> headerLines_;
};
} // namespace gen

#endif
98 changes: 49 additions & 49 deletions GeneratorInterface/Core/interface/WeightHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,59 @@
#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h"
#include "SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h"
#include "LHAPDF/LHAPDF.h"
#include <boost/algorithm/string.hpp>
#include <bits/stdc++.h>
#include <fstream>

namespace gen {
struct PdfSetInfo {
std::string name;
int lhapdfId;
PdfUncertaintyType uncertaintyType;
};
struct ParsedWeight {
std::string id;
size_t index;
std::string groupname;
std::string content;
std::unordered_map<std::string, std::string> attributes;
size_t wgtGroup_idx;
};

struct ParsedWeight {
std::string id;
size_t index;
std::string groupname;
std::string content;
std::unordered_map<std::string, std::string> attributes;
};

class WeightHelper {
public:
WeightHelper();
edm::OwnVector<gen::WeightGroupInfo> weightGroups() {
return weightGroups_;
}
std::unique_ptr<GenWeightProduct> weightProduct(std::vector<gen::WeightsInfo>, float w0);
std::unique_ptr<GenWeightProduct> weightProduct(std::vector<double>, float w0);
void setModel(std::string model) { model_ = model; }
int addWeightToProduct(std::unique_ptr<GenWeightProduct>& product, double weight, std::string name, int weightNum, int groupIndex);
int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex);
protected:
std::string model_;
std::vector<ParsedWeight> parsedWeights_;
const std::vector<PdfSetInfo> pdfSetsInfo;
std::map<std::string, std::string> currWeightAttributeMap_;
std::map<std::string, std::string> currGroupAttributeMap_;
edm::OwnVector<gen::WeightGroupInfo> weightGroups_;
bool isScaleWeightGroup(const ParsedWeight& weight);
bool isMEParamWeightGroup(const ParsedWeight& weight);
bool isPdfWeightGroup(const ParsedWeight& weight);
void updateScaleInfo(const ParsedWeight& weight);
void updatePdfInfo(const ParsedWeight& weight);
void splitPdfGroups();
std::string searchAttributes(const std::string& label, const ParsedWeight& weight) const;
std::string searchAttributesByTag(const std::string& label, const ParsedWeight& weight) const;
std::string searchAttributesByRegex(const std::string& label, const ParsedWeight& weight) const;
class WeightHelper {
public:
WeightHelper();
edm::OwnVector<gen::WeightGroupInfo> weightGroups() { return weightGroups_; }
std::unique_ptr<GenWeightProduct> weightProduct(std::vector<gen::WeightsInfo>, float w0);
std::unique_ptr<GenWeightProduct> weightProduct(std::vector<double>, float w0);
void setModel(std::string model) { model_ = model; }
int addWeightToProduct(
std::unique_ptr<GenWeightProduct>& product, double weight, std::string name, int weightNum, int groupIndex);
int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex);

// Possible names for the same thing
const std::unordered_map<std::string, std::vector<std::string>> attributeNames_ = {
{"muf", {"muR", "MUR", "muf","facscfact"}},
{"mur", {"muF", "MUF", "mur","renscfact"}},
{"pdf", {"PDF", "PDF set", "lhapdf", "pdf", "pdf set", "pdfset"}}
};
};
}
protected:
std::string model_;
std::vector<ParsedWeight> parsedWeights_;
std::map<std::string, std::string> currWeightAttributeMap_;
std::map<std::string, std::string> currGroupAttributeMap_;
edm::OwnVector<gen::WeightGroupInfo> weightGroups_;
bool isScaleWeightGroup(const ParsedWeight& weight);
bool isMEParamWeightGroup(const ParsedWeight& weight);
bool isPdfWeightGroup(const ParsedWeight& weight);
bool isOrphanPdfWeightGroup(ParsedWeight& weight);
void updateScaleInfo(const ParsedWeight& weight);
void updatePdfInfo(const ParsedWeight& weight);
void cleanupOrphanCentralWeight();

#endif
int getLhapdfId(const ParsedWeight& weight);
std::string searchAttributes(const std::string& label, const ParsedWeight& weight) const;
std::string searchAttributesByTag(const std::string& label, const ParsedWeight& weight) const;
std::string searchAttributesByRegex(const std::string& label, const ParsedWeight& weight) const;

// Possible names for the same thing
const std::unordered_map<std::string, std::vector<std::string>> attributeNames_ = {
{"muf", {"muF", "MUF", "muf", "facscfact"}},
{"mur", {"muR", "MUR", "mur", "renscfact"}},
{"pdf", {"PDF", "PDF set", "lhapdf", "pdf", "pdf set", "pdfset"}},
{"dyn", {"DYN_SCALE"}},
{"dyn_name", {"dyn_scale_choice"}}};
};
} // namespace gen

#endif
66 changes: 29 additions & 37 deletions GeneratorInterface/Core/plugins/GenWeightProductProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GenWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosit
public:
explicit GenWeightProductProducer(const edm::ParameterSet& iConfig);
~GenWeightProductProducer() override;

private:
std::vector<std::string> weightNames_;
gen::GenWeightHelper weightHelper_;
Expand All @@ -44,24 +44,19 @@ class GenWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosit
//
// constructors and destructor
//
GenWeightProductProducer::GenWeightProductProducer(const edm::ParameterSet& iConfig) :
genLumiInfoToken_(consumes<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genInfo"))),
genEventToken_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("genInfo"))),
genLumiInfoHeadTag_(mayConsume<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genLumiInfoHeader")))
{
GenWeightProductProducer::GenWeightProductProducer(const edm::ParameterSet& iConfig)
: genLumiInfoToken_(consumes<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genInfo"))),
genEventToken_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("genInfo"))),
genLumiInfoHeadTag_(
mayConsume<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genLumiInfoHeader"))) {
produces<GenWeightProduct>();
produces<GenWeightInfoProduct, edm::Transition::BeginLuminosityBlock>();
}


GenWeightProductProducer::~GenWeightProductProducer()
{
}

GenWeightProductProducer::~GenWeightProductProducer() {}

// ------------ method called to produce the data ------------
void
GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
void GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<GenEventInfoProduct> genEventInfo;
iEvent.getByToken(genEventToken_, genEventInfo);

Expand All @@ -70,30 +65,27 @@ GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
iEvent.put(std::move(weightProduct));
}

void
GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) {
edm::Handle<GenLumiInfoHeader> genLumiInfoHead;
iLumi.getByToken(genLumiInfoHeadTag_, genLumiInfoHead);
if (genLumiInfoHead.isValid()) {
std::string label = genLumiInfoHead->configDescription();
boost::replace_all(label,"-","_");
weightHelper_.setModel(label);
}

if (weightNames_.size() == 0) {
edm::Handle<GenLumiInfoHeader> genLumiInfoHandle;
iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle);

weightNames_ = genLumiInfoHandle->weightNames();
weightHelper_.parseWeightGroupsFromNames(weightNames_);
}
auto weightInfoProduct = std::make_unique<GenWeightInfoProduct>();
for (auto& weightGroup : weightHelper_.weightGroups()) {
weightInfoProduct->addWeightGroupInfo(weightGroup.clone());
}
iLumi.put(std::move(weightInfoProduct));
void GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) {
edm::Handle<GenLumiInfoHeader> genLumiInfoHead;
iLumi.getByToken(genLumiInfoHeadTag_, genLumiInfoHead);
if (genLumiInfoHead.isValid()) {
std::string label = genLumiInfoHead->configDescription();
boost::replace_all(label, "-", "_");
weightHelper_.setModel(label);
}

if (weightNames_.size() == 0) {
edm::Handle<GenLumiInfoHeader> genLumiInfoHandle;
iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle);

weightNames_ = genLumiInfoHandle->weightNames();
weightHelper_.parseWeightGroupsFromNames(weightNames_);
}
auto weightInfoProduct = std::make_unique<GenWeightInfoProduct>();
for (auto& weightGroup : weightHelper_.weightGroups()) {
weightInfoProduct->addWeightGroupInfo(weightGroup.clone());
}
iLumi.put(std::move(weightInfoProduct));
}

DEFINE_FWK_MODULE(GenWeightProductProducer);


Loading

0 comments on commit 3d8e722

Please sign in to comment.