From 208a4a32607492d78c629c5878a9d8112b014c11 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 27 May 2019 20:33:29 -0500 Subject: [PATCH 01/75] Adding first outlines of weight products --- .../interface/LHEWeightInfoProduct.h | 47 +++++++++++++++ .../interface/LHEWeightProduct.h | 36 ++++++++++++ .../interface/WeightGroupInfo.h | 58 +++++++++++++++++++ .../GeneratorProducts/src/classes.h | 1 + .../GeneratorProducts/src/classes_def.xml | 3 + 5 files changed, 145 insertions(+) create mode 100644 SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h create mode 100644 SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h create mode 100644 SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h new file mode 100644 index 0000000000000..cacc814d43b9c --- /dev/null +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -0,0 +1,47 @@ +#ifndef SimDataFormats_GeneratorProducts_LHEWeightInfoProduct_h +#define SimDataFormats_GeneratorProducts_LHEWeightInfoProduct_h + +#include +#include +#include +#include + +//#include + +#include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" + +class LHEWeightInfoProduct { + public: + LHEWeightInfoProduct() { + gen::WeightGroupInfo scaleInfo( + "" + ); + //scaleInfo.isPDF = false; + //scaleInfo.pdfLabel = ""; + //scaleInfo.pdfLHAID = ""; + + gen::WeightGroupInfo cenPdfInfo( + "" + ); + + //cenPdfInfo.isPDF = true; + //cenPdfInfo.pdfLabel = "NNPDF31_nnlo_hessian_pdfas"; + //cenPdfInfo.pdfLHAID = "3061000"; + + weightGroupsInfo_.push_back(scaleInfo); + weightGroupsInfo_.push_back(cenPdfInfo); + }; + std::vector getWeightGroupsInfo() { return weightGroupsInfo_; } + void addWeightGroupInfo(gen::WeightGroupInfo info) { + weightGroupsInfo_.push_back(info); + } + + private: + std::vector weightGroupsInfo_; + + +}; + +#endif // GeneratorWeightInfo_LHEInterface_LHEWeightInfoProduct_h + diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h new file mode 100644 index 0000000000000..784aafea49b56 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h @@ -0,0 +1,36 @@ +#ifndef SimDataFormats_GeneratorProducts_LHEWeightProduct_h +#define SimDataFormats_GeneratorProducts_LHEWeightProduct_h + +#include +#include +#include + +#include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" +#include "SimDataFormats/GeneratorProducts/interface/WeightsInfo.h" + +class LHEWeightProduct { + public: + typedef weightsContainer std::vector>; + + LHEWeightProduct() {} + LHEWeightProduct& operator=(LHEWeightProduct&& other) { + weights_ = std::move(other.weights_); + originalXWGTUP_ = std::move(other.originalXWGTUP_); + return *this; + } + ~LHEWeightProduct() {} + + void addWeight(double weight, size_t setEntry, size_t weightNum) { + weights_.at(setEntry).insert(weight, weightNum); + } + double originalXWGTUP() const { return originalXWGTUP_; } + const std::vector& weights() const { return weights_; } + + private: + weightsContainer weights_; + std::map weightsMap_; + double originalXWGTUP_; +}; + +#endif // GeneratorEvent_LHEInterface_LHEWeightProduct_h + diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h new file mode 100644 index 0000000000000..262f85a39d6b2 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -0,0 +1,58 @@ +#ifndef SimDataFormats_GeneratorProducts_WeightGroupInfo_h +#define SimDataFormats_GeneratorProducts_WeightGroupInfo_h + +/** \class PdfInfo + * + */ +#include + +namespace gen { + typedef std::pair weightId; + + enum WeightType { + pdfWeights, + scaleWeights, + matrixElementWeights, + unknownWeights, + }; + + class WeightGroupInfo { + public: + WeightGroupInfo(std::string header): + headerEntry_(header), name_(header), firstId_(0), lastId_(0) {} + int getWeightVectorEntry(const std::string& wgtId, size_t weightEntry) { + int orderedEntry = weightEntry - firstId_; + int entry = -1; + if (orderedEntry >= 0 && static_cast(orderedEntry) < idsContained_.size()) + if (idsContained_.at(orderedEntry).second == wgtId) + return orderedEntry; + //auto it = std::find( + return entry; + } + void addContainedID(std::string id, size_t weightEntry) { + if (!indexInRange(weightEntry)) + throw std::domain_error("This entry is out of the expected range"); + size_t orderedEntry = weightEntry - firstId_; + idsContained_.insert(idsContained_.begin()+weightEntry, std::make_pair(orderedEntry, id)); + } + void setWeightType(WeightType type) { weightType_ = type; } + + void setFirstEntry(size_t entryNum) { firstId_ = entryNum;} + void setLastEntry(size_t entryNum) { lastId_ = entryNum;} + + bool indexInRange(size_t index) { + return (index <= lastId_ && index >= firstId_); + } + + private: + std::string headerEntry_; + std::string name_; + WeightType weightType_; + std::vector idsContained_; + size_t firstId_; + size_t lastId_; + }; +} + +#endif // SimDataFormats_GeneratorProducts_WeightGroupInfo_h + diff --git a/SimDataFormats/GeneratorProducts/src/classes.h b/SimDataFormats/GeneratorProducts/src/classes.h index b3dad1f96a313..460a735e2e403 100644 --- a/SimDataFormats/GeneratorProducts/src/classes.h +++ b/SimDataFormats/GeneratorProducts/src/classes.h @@ -8,6 +8,7 @@ #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index c3a00478db98d..bcf54ea90c7e3 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -221,6 +221,9 @@ + + + From 0a8810ee2870d5109feecef3c19dbd2e4a97c77f Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 29 May 2019 00:21:20 -0500 Subject: [PATCH 02/75] Close to an outline, not working for LHESource --- .../plugins/ExternalLHEProducer.cc | 24 ++++++++++++--- .../plugins/LHEProvenanceHelper.cc | 17 ++++++++++- .../plugins/LHEProvenanceHelper.h | 2 ++ .../LHEInterface/plugins/LHESource.cc | 24 ++++++++++++++- .../LHEInterface/plugins/LHESource.h | 1 + .../interface/LHEWeightInfoProduct.h | 29 +++++++------------ .../interface/WeightGroupInfo.h | 1 + .../GeneratorProducts/src/classes.h | 1 + .../GeneratorProducts/src/classes_def.xml | 5 ++++ 9 files changed, 79 insertions(+), 25 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index f9f76cbcfbd41..614ac5e45627e 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -49,6 +49,7 @@ Description: [one line class summary] #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" @@ -158,6 +159,7 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig) : produces(); produces(); produces(); + produces(); } @@ -326,6 +328,22 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) unsigned int skip = 0; reader_ = std::make_unique(infiles, skip); + std::cout << "Adding the Weight product!"; + std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); + gen::WeightGroupInfo scaleInfo( + "" + ); + scaleInfo.setWeightType(gen::scaleWeights); + + gen::WeightGroupInfo cenPdfInfo( + "" + ); + cenPdfInfo.setWeightType(gen::pdfWeights); + + weightInfoProduct->addWeightGroupInfo(scaleInfo); + weightInfoProduct->addWeightGroupInfo(cenPdfInfo); + run.put(std::move(weightInfoProduct)); + nextEvent(); if (runInfoLast) { runInfo = runInfoLast; @@ -343,12 +361,11 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) // keep a copy around in case of merging runInfoProducts.push_back(new LHERunInfoProduct(*product)); wasMerged = false; - + run.put(std::move(product)); runInfo.reset(); } - } // ------------ method called when ending the processing of a run ------------ @@ -360,7 +377,7 @@ ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) std::unique_ptr product(runInfoProducts.pop_front().release()); run.put(std::move(product)); } - + nextEvent(); if (partonLevel) { throw edm::Exception(edm::errors::EventGenerationFailure) << "Error in ExternalLHEProducer::endRunProduce(). " @@ -373,7 +390,6 @@ ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) if (unlink(outputFile_.c_str())) { throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ")."; } - } // ------------ Close all the open file descriptors ------------ diff --git a/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc b/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc index 3947edb9af738..e5a3a461b8d84 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc @@ -2,6 +2,7 @@ #include #include "GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h" #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" +#include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" #include "DataFormats/Provenance/interface/ProcessHistory.h" #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h" @@ -15,7 +16,8 @@ #include "FWCore/Version/interface/GetReleaseVersion.h" namespace edm { - LHEProvenanceHelper::LHEProvenanceHelper(TypeID const& eventProductType, TypeID const& runProductType, ProductRegistry& productRegistry) + LHEProvenanceHelper::LHEProvenanceHelper(TypeID const& eventProductType, TypeID const& runProductType, + TypeID const& weightProductType, ProductRegistry& productRegistry) : eventProductBranchDescription_(BranchDescription( InEvent , "source" @@ -40,12 +42,25 @@ namespace edm { , ParameterSetID() , TypeWithDict(runProductType.typeInfo()) , false)) + , weightProductBranchDescription_(BranchDescription( + InRun + , "source" + , "LHEFile" + // , "LHE" + , "LHEWeightInfoProduct" + , "LHEWeightInfoProduct" + , "" + , "LHESource" + , ParameterSetID() + , TypeWithDict(weightProductType.typeInfo()) + , false)) , eventProductProvenance_(eventProductBranchDescription_.branchID()) , commonProcessParameterSet_(fillCommonProcessParameterSet()) , processParameterSet_() { // Add the products to the product registry productRegistry.copyProduct(eventProductBranchDescription_); + productRegistry.copyProduct(weightProductBranchDescription_); productRegistry.copyProduct(runProductBranchDescription_); } diff --git a/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h b/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h index 39fec2179fbb3..1f89820d3473c 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h +++ b/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h @@ -17,12 +17,14 @@ namespace edm { struct LHEProvenanceHelper { explicit LHEProvenanceHelper(TypeID const& eventProductType, TypeID const& runProductType, + TypeID const& weightProductType, ProductRegistry& productRegistry); ParameterSet fillCommonProcessParameterSet(); void lheAugment(lhef::LHERunInfo const* runInfo); ProcessHistoryID lheInit(ProcessHistoryRegistry& processHistoryRegistry); BranchDescription const eventProductBranchDescription_; BranchDescription const runProductBranchDescription_; + BranchDescription const weightProductBranchDescription_; ProductProvenance eventProductProvenance_; ParameterSet const commonProcessParameterSet_; ParameterSet processParameterSet_; diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.cc b/GeneratorInterface/LHEInterface/plugins/LHESource.cc index a072d5ad54af7..c0598348fd5bf 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.cc @@ -23,6 +23,7 @@ #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" @@ -36,7 +37,7 @@ LHESource::LHESource(const edm::ParameterSet ¶ms, const edm::InputSourceDescription &desc) : ProducerSourceFromFiles(params, desc, false), reader_(new LHEReader(fileNames(), params.getUntrackedParameter("skipEvents", 0))), - lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()), + lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), edm::TypeID(typeid(LHEWeightInfoProduct)), productRegistryUpdate()), phid_() { nextEvent(); @@ -116,6 +117,7 @@ LHESource::readRun_(edm::RunPrincipal& runPrincipal) { runPrincipal.fillRunPrincipal(processHistoryRegistryForUpdate()); putRunInfoProduct(runPrincipal); + putWeightInfoProduct(runPrincipal); } void @@ -132,6 +134,26 @@ void LHESource::putRunInfoProduct(edm::RunPrincipal& iRunPrincipal) { } } +void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { + if (runInfoProductLast_) { + auto product = std::make_unique(); + gen::WeightGroupInfo scaleInfo( + "" + ); + scaleInfo.setWeightType(gen::scaleWeights); + + gen::WeightGroupInfo cenPdfInfo( + "" + ); + cenPdfInfo.setWeightType(gen::pdfWeights); + + product->addWeightGroupInfo(scaleInfo); + product->addWeightGroupInfo(cenPdfInfo); + std::unique_ptr rdp(new edm::Wrapper(std::move(product))); + iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp)); + } +} + bool LHESource::setRunAndEventInfo(edm::EventID&, edm::TimeValue_t&, edm::EventAuxiliary::ExperimentType&) { nextEvent(); diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.h b/GeneratorInterface/LHEInterface/plugins/LHESource.h index c6e1457e8b2db..65cbac8f6e856 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.h +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.h @@ -53,6 +53,7 @@ class LHESource : public edm::ProducerSourceFromFiles { void nextEvent(); void putRunInfoProduct(edm::RunPrincipal&); + void putWeightInfoProduct(edm::RunPrincipal&); void fillRunInfoProduct(lhef::LHERunInfo const&, LHERunInfoProduct& ); std::unique_ptr reader_; diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h index cacc814d43b9c..ac16db65ae9fa 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -13,25 +13,16 @@ class LHEWeightInfoProduct { public: - LHEWeightInfoProduct() { - gen::WeightGroupInfo scaleInfo( - "" - ); - //scaleInfo.isPDF = false; - //scaleInfo.pdfLabel = ""; - //scaleInfo.pdfLHAID = ""; - - gen::WeightGroupInfo cenPdfInfo( - "" - ); - - //cenPdfInfo.isPDF = true; - //cenPdfInfo.pdfLabel = "NNPDF31_nnlo_hessian_pdfas"; - //cenPdfInfo.pdfLHAID = "3061000"; - - weightGroupsInfo_.push_back(scaleInfo); - weightGroupsInfo_.push_back(cenPdfInfo); - }; + LHEWeightInfoProduct() {} + LHEWeightInfoProduct(const LHEWeightInfoProduct& other) {weightGroupsInfo_ = other.weightGroupsInfo_;} + LHEWeightInfoProduct(LHEWeightInfoProduct&& other) {weightGroupsInfo_ = std::move(other.weightGroupsInfo_);} + ~LHEWeightInfoProduct() {} + LHEWeightInfoProduct(std::vector& weightGroups) { + weightGroupsInfo_ = weightGroups; + } + LHEWeightInfoProduct &operator = (const LHEWeightInfoProduct &other) {weightGroupsInfo_ = other.weightGroupsInfo_; return * this; } + LHEWeightInfoProduct &operator = (LHEWeightInfoProduct &&other) {weightGroupsInfo_ = std::move(other.weightGroupsInfo_); return *this;} + std::vector getWeightGroupsInfo() { return weightGroupsInfo_; } void addWeightGroupInfo(gen::WeightGroupInfo info) { weightGroupsInfo_.push_back(info); diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index 262f85a39d6b2..3f79786e6c7b3 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -18,6 +18,7 @@ namespace gen { class WeightGroupInfo { public: + WeightGroupInfo() {} WeightGroupInfo(std::string header): headerEntry_(header), name_(header), firstId_(0), lastId_(0) {} int getWeightVectorEntry(const std::string& wgtId, size_t weightEntry) { diff --git a/SimDataFormats/GeneratorProducts/src/classes.h b/SimDataFormats/GeneratorProducts/src/classes.h index 460a735e2e403..6ba5d46db727d 100644 --- a/SimDataFormats/GeneratorProducts/src/classes.h +++ b/SimDataFormats/GeneratorProducts/src/classes.h @@ -8,6 +8,7 @@ #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index bcf54ea90c7e3..b7b4126b900a3 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -197,6 +197,9 @@ + + + @@ -225,7 +228,9 @@ + + From 7cfc2feb0447c7f9c6f87ce2a3f402aa1c3ee7e7 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 29 May 2019 15:08:47 -0500 Subject: [PATCH 03/75] Working skeleton of LHEWeightInfoProduct --- .../plugins/ExternalLHEProducer.cc | 3 +-- .../interface/LHEWeightInfoProduct.h | 20 ++++++-------- .../src/LHEWeightInfoProduct.cc | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 614ac5e45627e..3697b4ae4ff36 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -159,7 +159,7 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig) : produces(); produces(); produces(); - produces(); + produces(); } @@ -328,7 +328,6 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) unsigned int skip = 0; reader_ = std::make_unique(infiles, skip); - std::cout << "Adding the Weight product!"; std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); gen::WeightGroupInfo scaleInfo( "" diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h index ac16db65ae9fa..6ab385ae70cdf 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -14,19 +14,15 @@ class LHEWeightInfoProduct { public: LHEWeightInfoProduct() {} - LHEWeightInfoProduct(const LHEWeightInfoProduct& other) {weightGroupsInfo_ = other.weightGroupsInfo_;} - LHEWeightInfoProduct(LHEWeightInfoProduct&& other) {weightGroupsInfo_ = std::move(other.weightGroupsInfo_);} + LHEWeightInfoProduct(std::vector& weightGroups); + LHEWeightInfoProduct(const LHEWeightInfoProduct& other); + LHEWeightInfoProduct(LHEWeightInfoProduct&& other); ~LHEWeightInfoProduct() {} - LHEWeightInfoProduct(std::vector& weightGroups) { - weightGroupsInfo_ = weightGroups; - } - LHEWeightInfoProduct &operator = (const LHEWeightInfoProduct &other) {weightGroupsInfo_ = other.weightGroupsInfo_; return * this; } - LHEWeightInfoProduct &operator = (LHEWeightInfoProduct &&other) {weightGroupsInfo_ = std::move(other.weightGroupsInfo_); return *this;} - - std::vector getWeightGroupsInfo() { return weightGroupsInfo_; } - void addWeightGroupInfo(gen::WeightGroupInfo info) { - weightGroupsInfo_.push_back(info); - } + LHEWeightInfoProduct& operator=(const LHEWeightInfoProduct &other); + LHEWeightInfoProduct& operator=(LHEWeightInfoProduct &&other); + + std::vector getWeightGroupsInfo(); + void addWeightGroupInfo(gen::WeightGroupInfo info); private: std::vector weightGroupsInfo_; diff --git a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc new file mode 100644 index 0000000000000..7aee2dbff205a --- /dev/null +++ b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc @@ -0,0 +1,26 @@ +#include +#include + +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" + +LHEWeightInfoProduct::LHEWeightInfoProduct(std::vector& weightGroups) { + weightGroupsInfo_ = weightGroups; +} + +LHEWeightInfoProduct& LHEWeightInfoProduct::operator=(const LHEWeightInfoProduct &other) { + weightGroupsInfo_ = other.weightGroupsInfo_; + return * this; +} + +LHEWeightInfoProduct& LHEWeightInfoProduct::operator=(LHEWeightInfoProduct &&other) { + weightGroupsInfo_ = std::move(other.weightGroupsInfo_); + return *this; +} + +std::vector LHEWeightInfoProduct::getWeightGroupsInfo() { + return weightGroupsInfo_; +} + +void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo info) { + weightGroupsInfo_.push_back(info); +} From 444dbc3d3924c325ca58144515c988d9874862c8 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 30 May 2019 00:19:08 -0500 Subject: [PATCH 04/75] About a working outline with weights in the event --- .../LHEInterface/interface/TestWeightInfo.h | 26 ++++++++ .../plugins/ExternalLHEProducer.cc | 37 +++++++++-- .../LHEInterface/plugins/LHESource.cc | 4 +- .../interface/LHEWeightProduct.h | 48 +++++++++------ .../interface/WeightGroupInfo.h | 61 +++++++++++++------ .../GeneratorProducts/src/classes.h | 1 + .../GeneratorProducts/src/classes_def.xml | 9 ++- 7 files changed, 139 insertions(+), 47 deletions(-) create mode 100644 GeneratorInterface/LHEInterface/interface/TestWeightInfo.h diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h new file mode 100644 index 0000000000000..451c60c03eed9 --- /dev/null +++ b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h @@ -0,0 +1,26 @@ +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" + +gen::WeightGroupInfo getExampleScaleWeights() { + gen::WeightGroupInfo scaleInfo( + "", + "centralScaleVariations" + ); + std::vector entries = { + R"( mur=1 muf=1 )", + R"( mur=1 muf=2 )", + R"( mur=1 muf=0.5 )", + R"( mur=2 muf=1 )", + R"( mur=2 muf=2 )", + R"( mur=2 muf=0.5 )", + R"( mur=0.5 muf=1 )", + R"( mur=0.5 muf=2 )", + R"( mur=0.5 muf=0.5 )", + }; + scaleInfo.setWeightType(gen::kScaleWeights); + + for (size_t i = 0; i < entries.size(); i++) { + scaleInfo.addContainedId(i, std::to_string(i+1), entries[i]); + } + return scaleInfo; +} + diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 3697b4ae4ff36..ee3a7ea3e6d8d 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -51,11 +51,13 @@ Description: [one line class summary] #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" #include "GeneratorInterface/LHEInterface/interface/LHEReader.h" +#include "GeneratorInterface/LHEInterface/interface/TestWeightInfo.h" #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Utilities/interface/RandomNumberGenerator.h" @@ -83,6 +85,7 @@ class ExternalLHEProducer : public edm::one::EDProducer readOutput(); void nextEvent(); @@ -106,6 +109,7 @@ class ExternalLHEProducer : public edm::one::EDProducer partonLevel; boost::ptr_deque runInfoProducts; bool wasMerged; + std::vector weightGroups_; class FileCloseSentry : private boost::noncopyable { public: @@ -157,6 +161,7 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig) : produces("LHEScriptOutput"); produces(); + produces(); produces(); produces(); produces(); @@ -201,6 +206,23 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) partonLevel->weights().end(), boost::bind(&LHEEventProduct::addWeight, product.get(), _1)); + + std::unique_ptr weightProduct(new LHEWeightProduct); + weightProduct->setNumWeightSets(weightGroups_.size()); + int weightGroupIndex = 0; + int weightNum = 0; + for (const auto& weight : partonLevel->weights()) { + if (weightNum > 8) + continue; + weightGroupIndex = findWeightGroup(weight.id, weightGroupIndex); + std::cout << "Size is " << weightGroups_.size() << std::endl; + int entry = weightGroups_.at(weightGroupIndex).weightVectorEntry(weight.id, weightNum); + std::cout << "Still going. Entry is " << entry << std::endl; + weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); + weightNum++; + } + iEvent.put(std::move(weightProduct)); + product->setScales(partonLevel->scales()); if (nPartonMapping_.empty()) { product->setNpLO(partonLevel->npLO()); @@ -329,18 +351,16 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) reader_ = std::make_unique(infiles, skip); std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); - gen::WeightGroupInfo scaleInfo( - "" - ); - scaleInfo.setWeightType(gen::scaleWeights); - + gen::WeightGroupInfo scaleInfo = getExampleScaleWeights(); + gen::WeightGroupInfo cenPdfInfo( "" ); - cenPdfInfo.setWeightType(gen::pdfWeights); + cenPdfInfo.setWeightType(gen::kPdfWeights); weightInfoProduct->addWeightGroupInfo(scaleInfo); weightInfoProduct->addWeightGroupInfo(cenPdfInfo); + weightGroups_ = weightInfoProduct->getWeightGroupsInfo(); run.put(std::move(weightInfoProduct)); nextEvent(); @@ -515,6 +535,11 @@ ExternalLHEProducer::executeScript() } + +int ExternalLHEProducer::findWeightGroup(std::string wgtId, int previousIndex) { + return 0; +} + // ------------ Read the output script ------------ #define BUFSIZE 4096 std::unique_ptr ExternalLHEProducer::readOutput() diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.cc b/GeneratorInterface/LHEInterface/plugins/LHESource.cc index c0598348fd5bf..a238a0fc613ca 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.cc @@ -140,12 +140,12 @@ void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { gen::WeightGroupInfo scaleInfo( "" ); - scaleInfo.setWeightType(gen::scaleWeights); + scaleInfo.setWeightType(gen::kScaleWeights); gen::WeightGroupInfo cenPdfInfo( "" ); - cenPdfInfo.setWeightType(gen::pdfWeights); + cenPdfInfo.setWeightType(gen::kPdfWeights); product->addWeightGroupInfo(scaleInfo); product->addWeightGroupInfo(cenPdfInfo); diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h index 784aafea49b56..e58927987bdd3 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h @@ -4,32 +4,44 @@ #include #include #include +#include #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/WeightsInfo.h" +typedef std::vector> WeightsContainer; + class LHEWeightProduct { public: - typedef weightsContainer std::vector>; - - LHEWeightProduct() {} - LHEWeightProduct& operator=(LHEWeightProduct&& other) { - weights_ = std::move(other.weights_); - originalXWGTUP_ = std::move(other.originalXWGTUP_); - return *this; - } - ~LHEWeightProduct() {} - - void addWeight(double weight, size_t setEntry, size_t weightNum) { - weights_.at(setEntry).insert(weight, weightNum); - } - double originalXWGTUP() const { return originalXWGTUP_; } - const std::vector& weights() const { return weights_; } + LHEWeightProduct() { weightsVector_ = {}; } + LHEWeightProduct& operator=(LHEWeightProduct&& other) { + weightsVector_ = std::move(other.weightsVector_); + return *this; + } + ~LHEWeightProduct() {} + + void setNumWeightSets(int num) { weightsVector_.resize(num); } + void addWeightSet() { weightsVector_.push_back({}); } + void addWeight(double weight, int setEntry, int weightNum) { + if (weightsVector_.size() == 0 && setEntry == 0) + addWeightSet(); + if (static_cast(weightsVector_.size()) <= setEntry) + throw std::domain_error("Out of range weight"); + auto& weights = weightsVector_.at(setEntry); + std::cout << "Weights size is " << weights.size() << std::endl; + if (static_cast(weights.size()) == weightNum) + weights.push_back(weight); + else if (static_cast(weights.size()) < weightNum) { + weights.resize(weightNum); + weights.insert(weights.begin()+weightNum, weight); + } + else + weights.insert(weights.begin()+weightNum, weight); + } + const WeightsContainer& weights() const { return weightsVector_; } private: - weightsContainer weights_; - std::map weightsMap_; - double originalXWGTUP_; + WeightsContainer weightsVector_; }; #endif // GeneratorEvent_LHEInterface_LHEWeightProduct_h diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index 3f79786e6c7b3..43e189df5c50b 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -7,41 +7,64 @@ #include namespace gen { - typedef std::pair weightId; + struct WeightMetaInfo { + int globalIndex; + int localIndex; + std::string id; + std::string label; + }; enum WeightType { - pdfWeights, - scaleWeights, - matrixElementWeights, - unknownWeights, + kPdfWeights, + kScaleWeights, + kMatrixElementWeights, + kUnknownWeights, + kShowerWeights, }; class WeightGroupInfo { public: WeightGroupInfo() {} + WeightGroupInfo(std::string header, std::string name): + headerEntry_(header), name_(name), firstId_(-1), lastId_(-1) {} WeightGroupInfo(std::string header): headerEntry_(header), name_(header), firstId_(0), lastId_(0) {} - int getWeightVectorEntry(const std::string& wgtId, size_t weightEntry) { + + int weightVectorEntry(const std::string& wgtId) { + return weightVectorEntry(wgtId, 0); + } + + int weightVectorEntry(const std::string& wgtId, int weightEntry) { int orderedEntry = weightEntry - firstId_; int entry = -1; if (orderedEntry >= 0 && static_cast(orderedEntry) < idsContained_.size()) - if (idsContained_.at(orderedEntry).second == wgtId) + if (idsContained_.at(orderedEntry).id == wgtId) return orderedEntry; //auto it = std::find( return entry; } - void addContainedID(std::string id, size_t weightEntry) { - if (!indexInRange(weightEntry)) - throw std::domain_error("This entry is out of the expected range"); - size_t orderedEntry = weightEntry - firstId_; - idsContained_.insert(idsContained_.begin()+weightEntry, std::make_pair(orderedEntry, id)); + + void addContainedId(int weightEntry, std::string id, std::string label="") { + if (firstId_ == -1 || weightEntry < firstId_) + firstId_ = weightEntry; + if (firstId_ == -1 || weightEntry > lastId_) + lastId_ = weightEntry; + + int orderedEntry = weightEntry - firstId_; + WeightMetaInfo info; + info.globalIndex = weightEntry; + info.localIndex = orderedEntry; + info.id = id; + info.label = label; + + idsContained_.insert(idsContained_.begin()+orderedEntry, info); } - void setWeightType(WeightType type) { weightType_ = type; } - void setFirstEntry(size_t entryNum) { firstId_ = entryNum;} - void setLastEntry(size_t entryNum) { lastId_ = entryNum;} + std::vector containedIds() { return idsContained_; } + + void setWeightType(WeightType type) { weightType_ = type; } - bool indexInRange(size_t index) { + bool indexInRange(int index) { return (index <= lastId_ && index >= firstId_); } @@ -49,9 +72,9 @@ namespace gen { std::string headerEntry_; std::string name_; WeightType weightType_; - std::vector idsContained_; - size_t firstId_; - size_t lastId_; + std::vector idsContained_; + int firstId_; + int lastId_; }; } diff --git a/SimDataFormats/GeneratorProducts/src/classes.h b/SimDataFormats/GeneratorProducts/src/classes.h index 6ba5d46db727d..266b790487bbe 100644 --- a/SimDataFormats/GeneratorProducts/src/classes.h +++ b/SimDataFormats/GeneratorProducts/src/classes.h @@ -10,6 +10,7 @@ #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index b7b4126b900a3..26a7a43ed572d 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -200,6 +200,7 @@ + @@ -224,13 +225,17 @@ - - + + + + + + From 49c25ba7a201cac7dc3c516f0dd8be95e4901509 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 30 May 2019 16:14:26 -0500 Subject: [PATCH 05/75] Working rough implementation of Weight/WeightInfo prods --- .../LHEInterface/interface/TestWeightInfo.h | 34 ++++++++++++++++++- .../plugins/ExternalLHEProducer.cc | 3 +- .../interface/LHEWeightInfoProduct.h | 3 +- .../interface/LHEWeightProduct.h | 3 +- .../interface/WeightGroupInfo.h | 21 ++++++++++-- .../src/LHEWeightInfoProduct.cc | 10 +++++- 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h index 451c60c03eed9..9ae3212728f77 100644 --- a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h +++ b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h @@ -1,4 +1,12 @@ #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include + +std::string parseId(std::string label) { + auto re = std::regex("id=\"([0-9]*)\""); + std::smatch matches; + std::regex_search(label, matches, re); + return std::string(matches.str(1)); +} gen::WeightGroupInfo getExampleScaleWeights() { gen::WeightGroupInfo scaleInfo( @@ -19,7 +27,31 @@ gen::WeightGroupInfo getExampleScaleWeights() { scaleInfo.setWeightType(gen::kScaleWeights); for (size_t i = 0; i < entries.size(); i++) { - scaleInfo.addContainedId(i, std::to_string(i+1), entries[i]); + scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); + } + return scaleInfo; +} + +gen::WeightGroupInfo getExampleScaleWeightsOutOfOrder() { + gen::WeightGroupInfo scaleInfo( + "", + "centralScaleVariations" + ); + std::vector entries = { + R"( mur=1 muf=1 )", + R"( mur=1 muf=2 )", + R"( mur=1 muf=0.5 )", + R"( mur=2 muf=2 )", + R"( mur=2 muf=1 )", + R"( mur=2 muf=0.5 )", + R"( mur=0.5 muf=2 )", + R"( mur=0.5 muf=1 )", + R"( mur=0.5 muf=0.5 )", + }; + scaleInfo.setWeightType(gen::kScaleWeights); + + for (size_t i = 0; i < entries.size(); i++) { + scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); } return scaleInfo; } diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index ee3a7ea3e6d8d..763437e587a98 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -352,6 +352,7 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); gen::WeightGroupInfo scaleInfo = getExampleScaleWeights(); + //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); gen::WeightGroupInfo cenPdfInfo( "" @@ -360,7 +361,7 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) weightInfoProduct->addWeightGroupInfo(scaleInfo); weightInfoProduct->addWeightGroupInfo(cenPdfInfo); - weightGroups_ = weightInfoProduct->getWeightGroupsInfo(); + weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); run.put(std::move(weightInfoProduct)); nextEvent(); diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h index 6ab385ae70cdf..a68418dabecdb 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -21,7 +21,8 @@ class LHEWeightInfoProduct { LHEWeightInfoProduct& operator=(const LHEWeightInfoProduct &other); LHEWeightInfoProduct& operator=(LHEWeightInfoProduct &&other); - std::vector getWeightGroupsInfo(); + const std::vector& allWeightGroupsInfo() const; + const gen::WeightGroupInfo& containingWeightGroupInfo(int index) const; void addWeightGroupInfo(gen::WeightGroupInfo info); private: diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h index e58927987bdd3..0e8ecc1ed2408 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h @@ -28,7 +28,6 @@ class LHEWeightProduct { if (static_cast(weightsVector_.size()) <= setEntry) throw std::domain_error("Out of range weight"); auto& weights = weightsVector_.at(setEntry); - std::cout << "Weights size is " << weights.size() << std::endl; if (static_cast(weights.size()) == weightNum) weights.push_back(weight); else if (static_cast(weights.size()) < weightNum) { @@ -36,7 +35,7 @@ class LHEWeightProduct { weights.insert(weights.begin()+weightNum, weight); } else - weights.insert(weights.begin()+weightNum, weight); + weights[weightNum] = weight; } const WeightsContainer& weights() const { return weightsVector_; } diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index 43e189df5c50b..75a2dccbf7f8e 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -5,6 +5,7 @@ * */ #include +#include namespace gen { struct WeightMetaInfo { @@ -30,6 +31,15 @@ namespace gen { WeightGroupInfo(std::string header): headerEntry_(header), name_(header), firstId_(0), lastId_(0) {} + WeightMetaInfo weightMetaInfo(int weightEntry) { + return idsContained_.at(weightEntry); + } + + WeightMetaInfo weightMetaInfo(std::string wgtId) { + int weightEntry = weightVectorEntry(wgtId); + return idsContained_.at(weightEntry); + } + int weightVectorEntry(const std::string& wgtId) { return weightVectorEntry(wgtId, 0); } @@ -40,7 +50,10 @@ namespace gen { if (orderedEntry >= 0 && static_cast(orderedEntry) < idsContained_.size()) if (idsContained_.at(orderedEntry).id == wgtId) return orderedEntry; - //auto it = std::find( + auto it = std::find_if(idsContained_.begin(), idsContained_.end(), + [wgtId] (const WeightMetaInfo& w) { return w.id == wgtId; }); + if (it != idsContained_.end()) + return std::distance(idsContained_.begin(), it); return entry; } @@ -57,14 +70,16 @@ namespace gen { info.id = id; info.label = label; + if (static_cast(idsContained_.size()) < orderedEntry) + idsContained_.resize(orderedEntry); idsContained_.insert(idsContained_.begin()+orderedEntry, info); } - std::vector containedIds() { return idsContained_; } + std::vector containedIds() const { return idsContained_; } void setWeightType(WeightType type) { weightType_ = type; } - bool indexInRange(int index) { + bool indexInRange(int index) const { return (index <= lastId_ && index >= firstId_); } diff --git a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc index 7aee2dbff205a..d20b76b934189 100644 --- a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc @@ -17,10 +17,18 @@ LHEWeightInfoProduct& LHEWeightInfoProduct::operator=(LHEWeightInfoProduct &&oth return *this; } -std::vector LHEWeightInfoProduct::getWeightGroupsInfo() { +const std::vector& LHEWeightInfoProduct::allWeightGroupsInfo() const { return weightGroupsInfo_; } +const gen::WeightGroupInfo& LHEWeightInfoProduct::containingWeightGroupInfo(int index) const { + for (const auto& weightGroup : weightGroupsInfo_) { + if (weightGroup.indexInRange(index)) + return weightGroup; + } + throw std::domain_error("Failed to find containing weight group"); +} + void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo info) { weightGroupsInfo_.push_back(info); } From bb431b79b74099c817e8848de2c6c2edb27ca62c Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 31 May 2019 02:23:21 -0500 Subject: [PATCH 06/75] Fix bug in insert to containedIds for WeightGroup --- .../LHEInterface/interface/TestWeightInfo.h | 952 ++++++++++++++++++ .../plugins/ExternalLHEProducer.cc | 48 +- .../interface/LHEWeightInfoProduct.h | 1 + .../interface/LHEWeightProduct.h | 10 +- .../interface/WeightGroupInfo.h | 46 +- .../src/LHEWeightInfoProduct.cc | 4 + .../GeneratorProducts/src/classes_def.xml | 4 +- 7 files changed, 1028 insertions(+), 37 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h index 9ae3212728f77..d42179471cfc5 100644 --- a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h +++ b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h @@ -56,3 +56,955 @@ gen::WeightGroupInfo getExampleScaleWeightsOutOfOrder() { return scaleInfo; } +std::vector getExamplePdfWeights() { + gen::WeightGroupInfo scaleInfo( + "", + "centralScaleVariations" + ); + std::vector entries = { + R"()", + R"( Member 0 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 1 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 2 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 3 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 4 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 5 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 6 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 7 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 8 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 9 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 10 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 11 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 12 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 13 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 14 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 15 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 16 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 17 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 18 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 19 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 20 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 21 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 22 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 23 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 24 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 25 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 26 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 27 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 28 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 29 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 30 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 31 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 32 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 33 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 34 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 35 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 36 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 37 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 38 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 39 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 40 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 41 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 42 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 43 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 44 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 45 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 46 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 47 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 48 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 49 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 50 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 51 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 52 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 53 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 54 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 55 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 56 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 57 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 58 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 59 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 60 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 61 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 62 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 63 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 64 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 65 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 66 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 67 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 68 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 69 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 70 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 71 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 72 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 73 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 74 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 75 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 76 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 77 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 78 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 79 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 80 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 81 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 82 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 83 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 84 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 85 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 86 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 87 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 88 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 89 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 90 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 91 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 92 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 93 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 94 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 95 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 96 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 97 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 98 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 99 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 100 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 101 of sets NNPDF31_nnlo_hessian_pdfas)", + R"( Member 102 of sets NNPDF31_nnlo_hessian_pdfas)", + R"()", + R"()", + R"( Member 0 of sets CT10nlo_nf4)", + R"()", + R"()", + R"( Member 0 of sets CT14nnlo_NF4)", + R"()", + R"()", + R"( Member 0 of sets CT14nlo_NF4)", + R"()", + R"()", + R"( Member 0 of sets CT14lo_NF4)", + R"()", + R"()", + R"( Member 0 of sets MSTW2008lo68cl_nf4)", + R"( Member 1 of sets MSTW2008lo68cl_nf4)", + R"( Member 2 of sets MSTW2008lo68cl_nf4)", + R"( Member 3 of sets MSTW2008lo68cl_nf4)", + R"( Member 4 of sets MSTW2008lo68cl_nf4)", + R"( Member 5 of sets MSTW2008lo68cl_nf4)", + R"( Member 6 of sets MSTW2008lo68cl_nf4)", + R"( Member 7 of sets MSTW2008lo68cl_nf4)", + R"( Member 8 of sets MSTW2008lo68cl_nf4)", + R"( Member 9 of sets MSTW2008lo68cl_nf4)", + R"( Member 10 of sets MSTW2008lo68cl_nf4)", + R"( Member 11 of sets MSTW2008lo68cl_nf4)", + R"( Member 12 of sets MSTW2008lo68cl_nf4)", + R"( Member 13 of sets MSTW2008lo68cl_nf4)", + R"( Member 14 of sets MSTW2008lo68cl_nf4)", + R"( Member 15 of sets MSTW2008lo68cl_nf4)", + R"( Member 16 of sets MSTW2008lo68cl_nf4)", + R"( Member 17 of sets MSTW2008lo68cl_nf4)", + R"( Member 18 of sets MSTW2008lo68cl_nf4)", + R"( Member 19 of sets MSTW2008lo68cl_nf4)", + R"( Member 20 of sets MSTW2008lo68cl_nf4)", + R"( Member 21 of sets MSTW2008lo68cl_nf4)", + R"( Member 22 of sets MSTW2008lo68cl_nf4)", + R"( Member 23 of sets MSTW2008lo68cl_nf4)", + R"( Member 24 of sets MSTW2008lo68cl_nf4)", + R"( Member 25 of sets MSTW2008lo68cl_nf4)", + R"( Member 26 of sets MSTW2008lo68cl_nf4)", + R"( Member 27 of sets MSTW2008lo68cl_nf4)", + R"( Member 28 of sets MSTW2008lo68cl_nf4)", + R"( Member 29 of sets MSTW2008lo68cl_nf4)", + R"( Member 30 of sets MSTW2008lo68cl_nf4)", + R"( Member 31 of sets MSTW2008lo68cl_nf4)", + R"( Member 32 of sets MSTW2008lo68cl_nf4)", + R"( Member 33 of sets MSTW2008lo68cl_nf4)", + R"( Member 34 of sets MSTW2008lo68cl_nf4)", + R"( Member 35 of sets MSTW2008lo68cl_nf4)", + R"( Member 36 of sets MSTW2008lo68cl_nf4)", + R"( Member 37 of sets MSTW2008lo68cl_nf4)", + R"( Member 38 of sets MSTW2008lo68cl_nf4)", + R"( Member 39 of sets MSTW2008lo68cl_nf4)", + R"( Member 40 of sets MSTW2008lo68cl_nf4)", + R"()", + R"()", + R"( Member 0 of sets MSTW2008nlo68cl_nf4)", + R"( Member 1 of sets MSTW2008nlo68cl_nf4)", + R"( Member 2 of sets MSTW2008nlo68cl_nf4)", + R"( Member 3 of sets MSTW2008nlo68cl_nf4)", + R"( Member 4 of sets MSTW2008nlo68cl_nf4)", + R"( Member 5 of sets MSTW2008nlo68cl_nf4)", + R"( Member 6 of sets MSTW2008nlo68cl_nf4)", + R"( Member 7 of sets MSTW2008nlo68cl_nf4)", + R"( Member 8 of sets MSTW2008nlo68cl_nf4)", + R"( Member 9 of sets MSTW2008nlo68cl_nf4)", + R"( Member 10 of sets MSTW2008nlo68cl_nf4)", + R"( Member 11 of sets MSTW2008nlo68cl_nf4)", + R"( Member 12 of sets MSTW2008nlo68cl_nf4)", + R"( Member 13 of sets MSTW2008nlo68cl_nf4)", + R"( Member 14 of sets MSTW2008nlo68cl_nf4)", + R"( Member 15 of sets MSTW2008nlo68cl_nf4)", + R"( Member 16 of sets MSTW2008nlo68cl_nf4)", + R"( Member 17 of sets MSTW2008nlo68cl_nf4)", + R"( Member 18 of sets MSTW2008nlo68cl_nf4)", + R"( Member 19 of sets MSTW2008nlo68cl_nf4)", + R"( Member 20 of sets MSTW2008nlo68cl_nf4)", + R"( Member 21 of sets MSTW2008nlo68cl_nf4)", + R"( Member 22 of sets MSTW2008nlo68cl_nf4)", + R"( Member 23 of sets MSTW2008nlo68cl_nf4)", + R"( Member 24 of sets MSTW2008nlo68cl_nf4)", + R"( Member 25 of sets MSTW2008nlo68cl_nf4)", + R"( Member 26 of sets MSTW2008nlo68cl_nf4)", + R"( Member 27 of sets MSTW2008nlo68cl_nf4)", + R"( Member 28 of sets MSTW2008nlo68cl_nf4)", + R"( Member 29 of sets MSTW2008nlo68cl_nf4)", + R"( Member 30 of sets MSTW2008nlo68cl_nf4)", + R"( Member 31 of sets MSTW2008nlo68cl_nf4)", + R"( Member 32 of sets MSTW2008nlo68cl_nf4)", + R"( Member 33 of sets MSTW2008nlo68cl_nf4)", + R"( Member 34 of sets MSTW2008nlo68cl_nf4)", + R"( Member 35 of sets MSTW2008nlo68cl_nf4)", + R"( Member 36 of sets MSTW2008nlo68cl_nf4)", + R"( Member 37 of sets MSTW2008nlo68cl_nf4)", + R"( Member 38 of sets MSTW2008nlo68cl_nf4)", + R"( Member 39 of sets MSTW2008nlo68cl_nf4)", + R"( Member 40 of sets MSTW2008nlo68cl_nf4)", + R"()", + R"()", + R"( Member 0 of sets MSTW2008nlo_mbrange_nf4)", + R"( Member 1 of sets MSTW2008nlo_mbrange_nf4)", + R"( Member 2 of sets MSTW2008nlo_mbrange_nf4)", + R"( Member 3 of sets MSTW2008nlo_mbrange_nf4)", + R"( Member 4 of sets MSTW2008nlo_mbrange_nf4)", + R"( Member 5 of sets MSTW2008nlo_mbrange_nf4)", + R"( Member 6 of sets MSTW2008nlo_mbrange_nf4)", + R"()", + R"()", + R"( Member 0 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 1 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 2 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 3 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 4 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 5 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 6 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 7 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 8 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 9 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 10 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 11 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 12 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 13 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 14 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 15 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 16 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 17 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 18 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 19 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 20 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 21 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 22 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 23 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 24 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 25 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 26 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 27 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 28 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 29 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 30 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 31 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 32 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 33 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 34 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 35 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 36 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 37 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 38 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 39 of sets MSTW2008nnlo68cl_nf4)", + R"( Member 40 of sets MSTW2008nnlo68cl_nf4)", + R"()", + R"()", + R"( Member 0 of sets MSTW2008nnlo_mbrange_nf4)", + R"( Member 1 of sets MSTW2008nnlo_mbrange_nf4)", + R"( Member 2 of sets MSTW2008nnlo_mbrange_nf4)", + R"( Member 3 of sets MSTW2008nnlo_mbrange_nf4)", + R"( Member 4 of sets MSTW2008nnlo_mbrange_nf4)", + R"( Member 5 of sets MSTW2008nnlo_mbrange_nf4)", + R"( Member 6 of sets MSTW2008nnlo_mbrange_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nlo68cl_nf4)", + R"( Member 1 of sets MMHT2014nlo68cl_nf4)", + R"( Member 2 of sets MMHT2014nlo68cl_nf4)", + R"( Member 3 of sets MMHT2014nlo68cl_nf4)", + R"( Member 4 of sets MMHT2014nlo68cl_nf4)", + R"( Member 5 of sets MMHT2014nlo68cl_nf4)", + R"( Member 6 of sets MMHT2014nlo68cl_nf4)", + R"( Member 7 of sets MMHT2014nlo68cl_nf4)", + R"( Member 8 of sets MMHT2014nlo68cl_nf4)", + R"( Member 9 of sets MMHT2014nlo68cl_nf4)", + R"( Member 10 of sets MMHT2014nlo68cl_nf4)", + R"( Member 11 of sets MMHT2014nlo68cl_nf4)", + R"( Member 12 of sets MMHT2014nlo68cl_nf4)", + R"( Member 13 of sets MMHT2014nlo68cl_nf4)", + R"( Member 14 of sets MMHT2014nlo68cl_nf4)", + R"( Member 15 of sets MMHT2014nlo68cl_nf4)", + R"( Member 16 of sets MMHT2014nlo68cl_nf4)", + R"( Member 17 of sets MMHT2014nlo68cl_nf4)", + R"( Member 18 of sets MMHT2014nlo68cl_nf4)", + R"( Member 19 of sets MMHT2014nlo68cl_nf4)", + R"( Member 20 of sets MMHT2014nlo68cl_nf4)", + R"( Member 21 of sets MMHT2014nlo68cl_nf4)", + R"( Member 22 of sets MMHT2014nlo68cl_nf4)", + R"( Member 23 of sets MMHT2014nlo68cl_nf4)", + R"( Member 24 of sets MMHT2014nlo68cl_nf4)", + R"( Member 25 of sets MMHT2014nlo68cl_nf4)", + R"( Member 26 of sets MMHT2014nlo68cl_nf4)", + R"( Member 27 of sets MMHT2014nlo68cl_nf4)", + R"( Member 28 of sets MMHT2014nlo68cl_nf4)", + R"( Member 29 of sets MMHT2014nlo68cl_nf4)", + R"( Member 30 of sets MMHT2014nlo68cl_nf4)", + R"( Member 31 of sets MMHT2014nlo68cl_nf4)", + R"( Member 32 of sets MMHT2014nlo68cl_nf4)", + R"( Member 33 of sets MMHT2014nlo68cl_nf4)", + R"( Member 34 of sets MMHT2014nlo68cl_nf4)", + R"( Member 35 of sets MMHT2014nlo68cl_nf4)", + R"( Member 36 of sets MMHT2014nlo68cl_nf4)", + R"( Member 37 of sets MMHT2014nlo68cl_nf4)", + R"( Member 38 of sets MMHT2014nlo68cl_nf4)", + R"( Member 39 of sets MMHT2014nlo68cl_nf4)", + R"( Member 40 of sets MMHT2014nlo68cl_nf4)", + R"( Member 41 of sets MMHT2014nlo68cl_nf4)", + R"( Member 42 of sets MMHT2014nlo68cl_nf4)", + R"( Member 43 of sets MMHT2014nlo68cl_nf4)", + R"( Member 44 of sets MMHT2014nlo68cl_nf4)", + R"( Member 45 of sets MMHT2014nlo68cl_nf4)", + R"( Member 46 of sets MMHT2014nlo68cl_nf4)", + R"( Member 47 of sets MMHT2014nlo68cl_nf4)", + R"( Member 48 of sets MMHT2014nlo68cl_nf4)", + R"( Member 49 of sets MMHT2014nlo68cl_nf4)", + R"( Member 50 of sets MMHT2014nlo68cl_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 1 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 2 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 3 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 4 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 5 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 6 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 7 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 8 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 9 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 10 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 11 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 12 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 13 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 14 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 15 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 16 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 17 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 18 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 19 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 20 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 21 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 22 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 23 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 24 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 25 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 26 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 27 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 28 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 29 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 30 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 31 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 32 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 33 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 34 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 35 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 36 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 37 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 38 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 39 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 40 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 41 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 42 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 43 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 44 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 45 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 46 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 47 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 48 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 49 of sets MMHT2014nlo68clas118_nf4)", + R"( Member 50 of sets MMHT2014nlo68clas118_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nlo_asmzsmallrange_nf4)", + R"( Member 1 of sets MMHT2014nlo_asmzsmallrange_nf4)", + R"( Member 2 of sets MMHT2014nlo_asmzsmallrange_nf4)", + R"( Member 3 of sets MMHT2014nlo_asmzsmallrange_nf4)", + R"( Member 4 of sets MMHT2014nlo_asmzsmallrange_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nlo_mcrange_nf4)", + R"( Member 1 of sets MMHT2014nlo_mcrange_nf4)", + R"( Member 2 of sets MMHT2014nlo_mcrange_nf4)", + R"( Member 3 of sets MMHT2014nlo_mcrange_nf4)", + R"( Member 4 of sets MMHT2014nlo_mcrange_nf4)", + R"( Member 5 of sets MMHT2014nlo_mcrange_nf4)", + R"( Member 6 of sets MMHT2014nlo_mcrange_nf4)", + R"( Member 7 of sets MMHT2014nlo_mcrange_nf4)", + R"( Member 8 of sets MMHT2014nlo_mcrange_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nlo_mbrange_nf4)", + R"( Member 1 of sets MMHT2014nlo_mbrange_nf4)", + R"( Member 2 of sets MMHT2014nlo_mbrange_nf4)", + R"( Member 3 of sets MMHT2014nlo_mbrange_nf4)", + R"( Member 4 of sets MMHT2014nlo_mbrange_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 1 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 2 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 3 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 4 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 5 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 6 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 7 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 8 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 9 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 10 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 11 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 12 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 13 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 14 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 15 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 16 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 17 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 18 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 19 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 20 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 21 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 22 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 23 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 24 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 25 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 26 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 27 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 28 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 29 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 30 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 31 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 32 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 33 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 34 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 35 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 36 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 37 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 38 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 39 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 40 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 41 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 42 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 43 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 44 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 45 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 46 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 47 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 48 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 49 of sets MMHT2014nnlo68cl_nf4)", + R"( Member 50 of sets MMHT2014nnlo68cl_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nnlo_asmzsmallrange_nf4)", + R"( Member 1 of sets MMHT2014nnlo_asmzsmallrange_nf4)", + R"( Member 2 of sets MMHT2014nnlo_asmzsmallrange_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nnlo_mcrange_nf4)", + R"( Member 1 of sets MMHT2014nnlo_mcrange_nf4)", + R"( Member 2 of sets MMHT2014nnlo_mcrange_nf4)", + R"( Member 3 of sets MMHT2014nnlo_mcrange_nf4)", + R"( Member 4 of sets MMHT2014nnlo_mcrange_nf4)", + R"( Member 5 of sets MMHT2014nnlo_mcrange_nf4)", + R"( Member 6 of sets MMHT2014nnlo_mcrange_nf4)", + R"( Member 7 of sets MMHT2014nnlo_mcrange_nf4)", + R"( Member 8 of sets MMHT2014nnlo_mcrange_nf4)", + R"()", + R"()", + R"( Member 0 of sets MMHT2014nnlo_mbrange_nf4)", + R"( Member 1 of sets MMHT2014nnlo_mbrange_nf4)", + R"( Member 2 of sets MMHT2014nnlo_mbrange_nf4)", + R"( Member 3 of sets MMHT2014nnlo_mbrange_nf4)", + R"( Member 4 of sets MMHT2014nnlo_mbrange_nf4)", + R"()", + R"()", + R"( Member 0 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 1 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 2 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 3 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 4 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 5 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 6 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 7 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 8 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 9 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 10 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 11 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 12 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 13 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 14 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 15 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 16 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 17 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 18 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 19 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 20 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 21 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 22 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 23 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 24 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 25 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 26 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 27 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 28 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 29 of sets PDF4LHC15_nlo_nf4_30)", + R"( Member 30 of sets PDF4LHC15_nlo_nf4_30)", + R"()", + R"()", + R"( Member 0 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 1 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 2 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 3 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 4 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 5 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 6 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 7 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 8 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 9 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 10 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 11 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 12 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 13 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 14 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 15 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 16 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 17 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 18 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 19 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 20 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 21 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 22 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 23 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 24 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 25 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 26 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 27 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 28 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 29 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 30 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 31 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 32 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 33 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 34 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 35 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 36 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 37 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 38 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 39 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 40 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 41 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 42 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 43 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 44 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 45 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 46 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 47 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 48 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 49 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 50 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 51 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 52 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 53 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 54 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 55 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 56 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 57 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 58 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 59 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 60 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 61 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 62 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 63 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 64 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 65 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 66 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 67 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 68 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 69 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 70 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 71 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 72 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 73 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 74 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 75 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 76 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 77 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 78 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 79 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 80 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 81 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 82 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 83 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 84 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 85 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 86 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 87 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 88 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 89 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 90 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 91 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 92 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 93 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 94 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 95 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 96 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 97 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 98 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 99 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"( Member 100 of sets NNPDF31_nnlo_as_0118_nf_4)", + R"()", + R"()", + R"( Member 0 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 1 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 2 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 3 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 4 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 5 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 6 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 7 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 8 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 9 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 10 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 11 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 12 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 13 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 14 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 15 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 16 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 17 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 18 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 19 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 20 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 21 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 22 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 23 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 24 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 25 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 26 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 27 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 28 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 29 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 30 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 31 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 32 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 33 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 34 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 35 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 36 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 37 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 38 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 39 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 40 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 41 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 42 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 43 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 44 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 45 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 46 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 47 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 48 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 49 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 50 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 51 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 52 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 53 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 54 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 55 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 56 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 57 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 58 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 59 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 60 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 61 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 62 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 63 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 64 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 65 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 66 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 67 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 68 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 69 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 70 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 71 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 72 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 73 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 74 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 75 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 76 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 77 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 78 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 79 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 80 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 81 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 82 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 83 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 84 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 85 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 86 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 87 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 88 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 89 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 90 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 91 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 92 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 93 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 94 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 95 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 96 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 97 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 98 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 99 of sets NNPDF31_nlo_as_0118_nf_4)", + R"( Member 100 of sets NNPDF31_nlo_as_0118_nf_4)", + R"()", + R"()", + R"( Member 0 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 1 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 2 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 3 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 4 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 5 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 6 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 7 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 8 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 9 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 10 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 11 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 12 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 13 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 14 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 15 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 16 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 17 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 18 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 19 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 20 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 21 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 22 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 23 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 24 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 25 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 26 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 27 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 28 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 29 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 30 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 31 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 32 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 33 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 34 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 35 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 36 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 37 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 38 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 39 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 40 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 41 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 42 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 43 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 44 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 45 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 46 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 47 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 48 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 49 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 50 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 51 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 52 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 53 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 54 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 55 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 56 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 57 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 58 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 59 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 60 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 61 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 62 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 63 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 64 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 65 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 66 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 67 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 68 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 69 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 70 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 71 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 72 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 73 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 74 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 75 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 76 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 77 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 78 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 79 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 80 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 81 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 82 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 83 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 84 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 85 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 86 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 87 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 88 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 89 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 90 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 91 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 92 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 93 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 94 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 95 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 96 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 97 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 98 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 99 of sets NNPDF30_nlo_as_0118_nf_4)", + R"( Member 100 of sets NNPDF30_nlo_as_0118_nf_4)", + R"()", + R"()", + R"( Member 0 of sets NNPDF30_lo_as_0118_nf_4)", + R"()", + R"()", + R"( Member 0 of sets NNPDF30_lo_as_0130_nf_4)", + R"()", + R"()", + R"( Member 0 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 1 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 2 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 3 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 4 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 5 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 6 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 7 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 8 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 9 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 10 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 11 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 12 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 13 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 14 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 15 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 16 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 17 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 18 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 19 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 20 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 21 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 22 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 23 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 24 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 25 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 26 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 27 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 28 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 29 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 30 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 31 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 32 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 33 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 34 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 35 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 36 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 37 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 38 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 39 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 40 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 41 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 42 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 43 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 44 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 45 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 46 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 47 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 48 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 49 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 50 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 51 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 52 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 53 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 54 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 55 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 56 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 57 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 58 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 59 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 60 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 61 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 62 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 63 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 64 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 65 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 66 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 67 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 68 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 69 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 70 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 71 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 72 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 73 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 74 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 75 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 76 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 77 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 78 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 79 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 80 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 81 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 82 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 83 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 84 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 85 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 86 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 87 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 88 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 89 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 90 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 91 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 92 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 93 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 94 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 95 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 96 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 97 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 98 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 99 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 100 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 101 of sets NNPDF30_nlo_nf_4_pdfas)", + R"( Member 102 of sets NNPDF30_nlo_nf_4_pdfas)", + R"()", + R"()", + R"( Member 0 of sets NNPDF30_nnlo_nf_4_pdfas)", + R"()", + }; + + std::vector pdfWeights; + + //Don't forget about the scale weights + int counter = 8; + for (const auto& entry : entries) { + if (entry.find(" readOutput(); void nextEvent(); @@ -212,11 +212,17 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) int weightGroupIndex = 0; int weightNum = 0; for (const auto& weight : partonLevel->weights()) { - if (weightNum > 8) - continue; - weightGroupIndex = findWeightGroup(weight.id, weightGroupIndex); - std::cout << "Size is " << weightGroups_.size() << std::endl; + weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex); + std::cout << "Weight group index" << weightGroupIndex << std::endl; + std::cout << weightGroups_.at(1).name() << std::endl; + if (weightGroupIndex < 0) { + std::cout << "Yep that's the case."; + std::cout << " num Contained IDs " << weightGroups_.at(1).containedIds().size() << std::endl; + for (auto& id : weightGroups_.at(1).containedIds()) + std::cout << id.id; + } int entry = weightGroups_.at(weightGroupIndex).weightVectorEntry(weight.id, weightNum); + std::cout << "Matching entry is " << entry; std::cout << "Still going. Entry is " << entry << std::endl; weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); weightNum++; @@ -353,15 +359,13 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); gen::WeightGroupInfo scaleInfo = getExampleScaleWeights(); //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); + std::vector pdfSets = getExamplePdfWeights(); - gen::WeightGroupInfo cenPdfInfo( - "" - ); - cenPdfInfo.setWeightType(gen::kPdfWeights); - weightInfoProduct->addWeightGroupInfo(scaleInfo); - weightInfoProduct->addWeightGroupInfo(cenPdfInfo); + for (auto& pdfSet : pdfSets) + weightInfoProduct->addWeightGroupInfo(pdfSet); weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); + std::cout << "Number of groups is " << weightGroups_.size() << std::endl; run.put(std::move(weightInfoProduct)); nextEvent(); @@ -537,8 +541,26 @@ ExternalLHEProducer::executeScript() } -int ExternalLHEProducer::findWeightGroup(std::string wgtId, int previousIndex) { - return 0; +int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex) { + // Start search at previous index, under expectation of ordered weights + std::cout << "Here we are"; + for (int index = previousGroupIndex; + index < std::min(index+1, static_cast(weightGroups_.size())); index++) { + auto& weightGroup = weightGroups_.at(previousGroupIndex); + // Fast search assuming order is not perturbed outside of weight group + if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) + return static_cast(index); + } + std::cout << "Done"; + + // Fall back to unordered search + int counter = 0; + for (auto& weightGroup : weightGroups_) { + if (weightGroup.containsWeight(wgtId, weightIndex)) + return counter; + counter++; + } + return -1; } // ------------ Read the output script ------------ diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h index a68418dabecdb..54849d32a8935 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -23,6 +23,7 @@ class LHEWeightInfoProduct { const std::vector& allWeightGroupsInfo() const; const gen::WeightGroupInfo& containingWeightGroupInfo(int index) const; + const gen::WeightGroupInfo& orderedWeightGroupInfo(int index) const; void addWeightGroupInfo(gen::WeightGroupInfo info); private: diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h index 0e8ecc1ed2408..5c5fa132b4ee7 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h @@ -28,14 +28,10 @@ class LHEWeightProduct { if (static_cast(weightsVector_.size()) <= setEntry) throw std::domain_error("Out of range weight"); auto& weights = weightsVector_.at(setEntry); - if (static_cast(weights.size()) == weightNum) - weights.push_back(weight); - else if (static_cast(weights.size()) < weightNum) { - weights.resize(weightNum); - weights.insert(weights.begin()+weightNum, weight); + if (static_cast(weights.size()) <= weightNum) { + weights.resize(weightNum+1); } - else - weights[weightNum] = weight; + weights[weightNum] = weight; } const WeightsContainer& weights() const { return weightsVector_; } diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index 75a2dccbf7f8e..c666e39ed2cca 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -9,8 +9,8 @@ namespace gen { struct WeightMetaInfo { - int globalIndex; - int localIndex; + size_t globalIndex; + size_t localIndex; std::string id; std::string label; }; @@ -29,7 +29,7 @@ namespace gen { WeightGroupInfo(std::string header, std::string name): headerEntry_(header), name_(name), firstId_(-1), lastId_(-1) {} WeightGroupInfo(std::string header): - headerEntry_(header), name_(header), firstId_(0), lastId_(0) {} + headerEntry_(header), name_(header), firstId_(-1), lastId_(-1) {} WeightMetaInfo weightMetaInfo(int weightEntry) { return idsContained_.at(weightEntry); @@ -44,12 +44,18 @@ namespace gen { return weightVectorEntry(wgtId, 0); } + int containsWeight(const std::string& wgtId, int weightEntry) { + return weightVectorEntry(wgtId, weightEntry) != -1; + } + int weightVectorEntry(const std::string& wgtId, int weightEntry) { - int orderedEntry = weightEntry - firstId_; int entry = -1; - if (orderedEntry >= 0 && static_cast(orderedEntry) < idsContained_.size()) - if (idsContained_.at(orderedEntry).id == wgtId) - return orderedEntry; + if (!indexInRange(weightEntry)) { + size_t orderedEntry = weightEntry - firstId_; + if (orderedEntry < idsContained_.size()) + if (idsContained_.at(orderedEntry).id == wgtId) + return orderedEntry; + } auto it = std::find_if(idsContained_.begin(), idsContained_.end(), [wgtId] (const WeightMetaInfo& w) { return w.id == wgtId; }); if (it != idsContained_.end()) @@ -58,26 +64,38 @@ namespace gen { } void addContainedId(int weightEntry, std::string id, std::string label="") { - if (firstId_ == -1 || weightEntry < firstId_) + if (firstId_ == -1 || weightEntry < firstId_) { firstId_ = weightEntry; - if (firstId_ == -1 || weightEntry > lastId_) + // Reset to reflect that indices will be shifted + for (auto& id : idsContained_) + id.localIndex = id.globalIndex - firstId_; + } + if (weightEntry > lastId_) lastId_ = weightEntry; - int orderedEntry = weightEntry - firstId_; WeightMetaInfo info; info.globalIndex = weightEntry; - info.localIndex = orderedEntry; + info.localIndex = weightEntry - firstId_; info.id = id; info.label = label; - if (static_cast(idsContained_.size()) < orderedEntry) - idsContained_.resize(orderedEntry); - idsContained_.insert(idsContained_.begin()+orderedEntry, info); + if (idsContained_.size() < info.localIndex) { + idsContained_.resize(info.localIndex); + idsContained_.insert(idsContained_.begin()+info.localIndex, info); + } + else if (idsContained_.size() == info.localIndex) { + idsContained_.push_back(info); + } + else { + idsContained_.resize(info.localIndex+1); + idsContained_[info.localIndex] = info; + } } std::vector containedIds() const { return idsContained_; } void setWeightType(WeightType type) { weightType_ = type; } + std::string name() { return name_; } bool indexInRange(int index) const { return (index <= lastId_ && index >= firstId_); diff --git a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc index d20b76b934189..78aed95c08fe1 100644 --- a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc @@ -29,6 +29,10 @@ const gen::WeightGroupInfo& LHEWeightInfoProduct::containingWeightGroupInfo(int throw std::domain_error("Failed to find containing weight group"); } +const gen::WeightGroupInfo& LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { + return weightGroupsInfo_.at(weightGroupIndex); +} + void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo info) { weightGroupsInfo_.push_back(info); } diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index 26a7a43ed572d..e3ef861932c3d 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -228,9 +228,7 @@ - - - + From df8416421345ba3a7e3d920edc30c914ad7d7cf2 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 31 May 2019 02:46:15 -0500 Subject: [PATCH 07/75] Add test scripts --- .../plugins/ExternalLHEProducer.cc | 13 --- .../LHEInterface/test/testWeights.py | 31 +++++++ .../LHEInterface/test/test_Weights_cfg.py | 86 +++++++++++++++++++ 3 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 GeneratorInterface/LHEInterface/test/testWeights.py create mode 100644 GeneratorInterface/LHEInterface/test/test_Weights_cfg.py diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 345fec6bd5917..354a34e75e9f9 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -213,17 +213,7 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) int weightNum = 0; for (const auto& weight : partonLevel->weights()) { weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex); - std::cout << "Weight group index" << weightGroupIndex << std::endl; - std::cout << weightGroups_.at(1).name() << std::endl; - if (weightGroupIndex < 0) { - std::cout << "Yep that's the case."; - std::cout << " num Contained IDs " << weightGroups_.at(1).containedIds().size() << std::endl; - for (auto& id : weightGroups_.at(1).containedIds()) - std::cout << id.id; - } int entry = weightGroups_.at(weightGroupIndex).weightVectorEntry(weight.id, weightNum); - std::cout << "Matching entry is " << entry; - std::cout << "Still going. Entry is " << entry << std::endl; weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); weightNum++; } @@ -365,7 +355,6 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) for (auto& pdfSet : pdfSets) weightInfoProduct->addWeightGroupInfo(pdfSet); weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); - std::cout << "Number of groups is " << weightGroups_.size() << std::endl; run.put(std::move(weightInfoProduct)); nextEvent(); @@ -543,7 +532,6 @@ ExternalLHEProducer::executeScript() int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex) { // Start search at previous index, under expectation of ordered weights - std::cout << "Here we are"; for (int index = previousGroupIndex; index < std::min(index+1, static_cast(weightGroups_.size())); index++) { auto& weightGroup = weightGroups_.at(previousGroupIndex); @@ -551,7 +539,6 @@ int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) return static_cast(index); } - std::cout << "Done"; // Fall back to unordered search int counter = 0; diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/LHEInterface/test/testWeights.py new file mode 100644 index 0000000000000..12e2961868af9 --- /dev/null +++ b/GeneratorInterface/LHEInterface/test/testWeights.py @@ -0,0 +1,31 @@ +from DataFormats.FWLite import Events,Handle,Runs +source = "externalLHEProducer" + +#for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: +for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: + runs = Runs(filename) + run = runs.__iter__().next() + weightInfoHandle = Handle("LHEWeightInfoProduct") + run.getByLabel(source, weightInfoHandle) + weightInfoProd = weightInfoHandle.product() + + events = Events(filename) + event = events.__iter__().next() + weightHandle = Handle("LHEWeightProduct") + event.getByLabel("externalLHEProducer", weightHandle) + event.getByLabel(source, weightHandle) + weightInfo = weightHandle.product() + print "Content of the weights" + for j, weights in enumerate(weightInfo.weights()): + print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 + matching = weightInfoProd.orderedWeightGroupInfo(j) + print "Weights length?", len(weights), "Contained ids lenths?", len(matching.containedIds()) + print "-"*80 + for i,weight in enumerate(weights): + print i, weight + info = matching.weightMetaInfo(i) + print " ID, localIndex, globalIndex, label, set:", info.id, info.localIndex, info.globalIndex, info.label, matching.name() + print "-"*80 + + + diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py new file mode 100644 index 0000000000000..aeb7882932c6e --- /dev/null +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -0,0 +1,86 @@ +# Auto generated configuration file +# using: +# Revision: 1.19 +# Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v +# with command line options: Configuration/GenProduction/python/HIG-RunIIFall18wmLHEGS-00509-fragment.py --fileout file:HIG-RunIIFall18wmLHEGS-00509.root --mc --eventcontent LHE --datatier LHE --conditions 102X_upgrade2018_realistic_v11 --step LHE --python_filename HIG-RunIIFall18wmLHEGS-00509_1_cfg.py --no_exec +import FWCore.ParameterSet.Config as cms + + + +process = cms.Process('LHE') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.EventContent.EventContent_cff') +process.load('SimGeneral.MixingModule.mixNoPU_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.StandardSequences.MagneticField_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(10) +) + +# Input source +process.source = cms.Source("EmptySource") + +process.options = cms.untracked.PSet( + +) + +# Production Info +process.configurationMetadata = cms.untracked.PSet( + annotation = cms.untracked.string('Configuration/GenProduction/python/HIG-RunIIFall18wmLHEGS-00509-fragment.py nevts:10'), + name = cms.untracked.string('Applications'), + version = cms.untracked.string('$Revision: 1.19 $') +) + +# Output definition + +process.LHEoutput = cms.OutputModule("PoolOutputModule", + dataset = cms.untracked.PSet( + dataTier = cms.untracked.string('LHE'), + filterName = cms.untracked.string('') + ), + fileName = cms.untracked.string('file:HIG-RunIIFall18wmLHEGS-00509.root'), + #outputCommands = process.LHEEventContent.outputCommands, + outputCommands = cms.untracked.vstring('keep *', + 'drop ME*_MEtoEDM*_*_*'), + splitLevel = cms.untracked.int32(0) +) + +# Additional output definition + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, '102X_upgrade2018_realistic_v11', '') + +process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", + args = cms.vstring('/afs/hep.wisc.edu/home/kdlong/public/DarkMatter_MonoZPrime_V_Mx50_Mv500_gDMgQ1_LO_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + nEvents = cms.untracked.uint32(10), + numberOfParameters = cms.uint32(1), + outputFile = cms.string('cmsgrid_final.lhe'), + scriptName = cms.FileInPath('GeneratorInterface/LHEInterface/data/run_generic_tarball_cvmfs.sh') +) + + +# Path and EndPath definitions +process.lhe_step = cms.Path(process.externalLHEProducer) +process.endjob_step = cms.EndPath(process.endOfProcess) +process.LHEoutput_step = cms.EndPath(process.LHEoutput) + +# Schedule definition +process.schedule = cms.Schedule(process.lhe_step,process.endjob_step,process.LHEoutput_step) +from PhysicsTools.PatAlgos.tools.helpers import associatePatAlgosToolsTask +associatePatAlgosToolsTask(process) + + +# Customisation from command line + +# Add early deletion of temporary data products to reduce peak memory need +from Configuration.StandardSequences.earlyDeleteSettings_cff import customiseEarlyDelete +process = customiseEarlyDelete(process) +# End adding early deletion From 23bee6651a368d039c37fa89cfa9a231f03b02dd Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 5 Aug 2019 16:10:06 -0400 Subject: [PATCH 08/75] Store pointers to WeightGroupInfo First step to moving towards edm::OwnVector and polymorphic storage --- .../LHEInterface/interface/TestWeightInfo.h | 30 ++++++++----------- .../plugins/ExternalLHEProducer.cc | 21 +++++++------ .../LHEInterface/plugins/LHESource.cc | 4 +-- .../interface/LHEWeightInfoProduct.h | 12 ++++---- .../src/LHEWeightInfoProduct.cc | 14 ++++----- .../GeneratorProducts/src/classes_def.xml | 6 ++-- 6 files changed, 43 insertions(+), 44 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h index d42179471cfc5..b3b63d40c71ff 100644 --- a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h +++ b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h @@ -8,8 +8,8 @@ std::string parseId(std::string label) { return std::string(matches.str(1)); } -gen::WeightGroupInfo getExampleScaleWeights() { - gen::WeightGroupInfo scaleInfo( +gen::WeightGroupInfo* getExampleScaleWeights() { + gen::WeightGroupInfo* scaleInfo = new gen::WeightGroupInfo( "", "centralScaleVariations" ); @@ -24,16 +24,16 @@ gen::WeightGroupInfo getExampleScaleWeights() { R"( mur=0.5 muf=2 )", R"( mur=0.5 muf=0.5 )", }; - scaleInfo.setWeightType(gen::kScaleWeights); + scaleInfo->setWeightType(gen::kScaleWeights); for (size_t i = 0; i < entries.size(); i++) { - scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); + scaleInfo->addContainedId(i, parseId(entries[i]), entries[i]); } return scaleInfo; } -gen::WeightGroupInfo getExampleScaleWeightsOutOfOrder() { - gen::WeightGroupInfo scaleInfo( +gen::WeightGroupInfo* getExampleScaleWeightsOutOfOrder() { + gen::WeightGroupInfo* scaleInfo = new gen::WeightGroupInfo( "", "centralScaleVariations" ); @@ -48,19 +48,15 @@ gen::WeightGroupInfo getExampleScaleWeightsOutOfOrder() { R"( mur=0.5 muf=1 )", R"( mur=0.5 muf=0.5 )", }; - scaleInfo.setWeightType(gen::kScaleWeights); + scaleInfo->setWeightType(gen::kScaleWeights); for (size_t i = 0; i < entries.size(); i++) { - scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); + scaleInfo->addContainedId(i, parseId(entries[i]), entries[i]); } return scaleInfo; } -std::vector getExamplePdfWeights() { - gen::WeightGroupInfo scaleInfo( - "", - "centralScaleVariations" - ); +std::vector getExamplePdfWeights() { std::vector entries = { R"()", R"( Member 0 of sets NNPDF31_nnlo_hessian_pdfas)", @@ -991,18 +987,18 @@ std::vector getExamplePdfWeights() { R"()", }; - std::vector pdfWeights; + std::vector pdfWeights; //Don't forget about the scale weights int counter = 8; for (const auto& entry : entries) { if (entry.find("addContainedId(counter, parseId(entry), entry); } counter++; } diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 354a34e75e9f9..78074f894fd23 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -109,7 +109,7 @@ class ExternalLHEProducer : public edm::one::EDProducer partonLevel; boost::ptr_deque runInfoProducts; bool wasMerged; - std::vector weightGroups_; + std::vector weightGroups_; class FileCloseSentry : private boost::noncopyable { public: @@ -213,7 +213,10 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) int weightNum = 0; for (const auto& weight : partonLevel->weights()) { weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex); - int entry = weightGroups_.at(weightGroupIndex).weightVectorEntry(weight.id, weightNum); + auto group = weightGroups_.at(weightGroupIndex); + if (!group) + throw std::out_of_range("Invalid index " + weightGroupIndex); + int entry = group->weightVectorEntry(weight.id, weightNum); weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); weightNum++; } @@ -347,12 +350,12 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) reader_ = std::make_unique(infiles, skip); std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); - gen::WeightGroupInfo scaleInfo = getExampleScaleWeights(); + gen::WeightGroupInfo* scaleInfo = getExampleScaleWeights(); //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); - std::vector pdfSets = getExamplePdfWeights(); + std::vector pdfSets = getExamplePdfWeights(); weightInfoProduct->addWeightGroupInfo(scaleInfo); - for (auto& pdfSet : pdfSets) + for (auto pdfSet : pdfSets) weightInfoProduct->addWeightGroupInfo(pdfSet); weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); run.put(std::move(weightInfoProduct)); @@ -534,16 +537,16 @@ int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int // Start search at previous index, under expectation of ordered weights for (int index = previousGroupIndex; index < std::min(index+1, static_cast(weightGroups_.size())); index++) { - auto& weightGroup = weightGroups_.at(previousGroupIndex); + gen::WeightGroupInfo* weightGroup = weightGroups_.at(previousGroupIndex); // Fast search assuming order is not perturbed outside of weight group - if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) + if (weightGroup->indexInRange(weightIndex) && weightGroup->containsWeight(wgtId, weightIndex)) return static_cast(index); } // Fall back to unordered search int counter = 0; - for (auto& weightGroup : weightGroups_) { - if (weightGroup.containsWeight(wgtId, weightIndex)) + for (auto weightGroup : weightGroups_) { + if (weightGroup->containsWeight(wgtId, weightIndex)) return counter; counter++; } diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.cc b/GeneratorInterface/LHEInterface/plugins/LHESource.cc index a238a0fc613ca..03402f473651f 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.cc @@ -147,8 +147,8 @@ void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { ); cenPdfInfo.setWeightType(gen::kPdfWeights); - product->addWeightGroupInfo(scaleInfo); - product->addWeightGroupInfo(cenPdfInfo); + product->addWeightGroupInfo(&scaleInfo); + product->addWeightGroupInfo(&cenPdfInfo); std::unique_ptr rdp(new edm::Wrapper(std::move(product))); iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp)); } diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h index 54849d32a8935..6d6af2cf99ca6 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -14,20 +14,20 @@ class LHEWeightInfoProduct { public: LHEWeightInfoProduct() {} - LHEWeightInfoProduct(std::vector& weightGroups); + LHEWeightInfoProduct(std::vector& weightGroups); LHEWeightInfoProduct(const LHEWeightInfoProduct& other); LHEWeightInfoProduct(LHEWeightInfoProduct&& other); ~LHEWeightInfoProduct() {} LHEWeightInfoProduct& operator=(const LHEWeightInfoProduct &other); LHEWeightInfoProduct& operator=(LHEWeightInfoProduct &&other); - const std::vector& allWeightGroupsInfo() const; - const gen::WeightGroupInfo& containingWeightGroupInfo(int index) const; - const gen::WeightGroupInfo& orderedWeightGroupInfo(int index) const; - void addWeightGroupInfo(gen::WeightGroupInfo info); + const std::vector& allWeightGroupsInfo() const; + const gen::WeightGroupInfo* containingWeightGroupInfo(int index) const; + const gen::WeightGroupInfo* orderedWeightGroupInfo(int index) const; + void addWeightGroupInfo(gen::WeightGroupInfo* info); private: - std::vector weightGroupsInfo_; + std::vector weightGroupsInfo_; }; diff --git a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc index 78aed95c08fe1..2e6c653ddbfd1 100644 --- a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc @@ -3,7 +3,7 @@ #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" -LHEWeightInfoProduct::LHEWeightInfoProduct(std::vector& weightGroups) { +LHEWeightInfoProduct::LHEWeightInfoProduct(std::vector& weightGroups) { weightGroupsInfo_ = weightGroups; } @@ -17,22 +17,22 @@ LHEWeightInfoProduct& LHEWeightInfoProduct::operator=(LHEWeightInfoProduct &&oth return *this; } -const std::vector& LHEWeightInfoProduct::allWeightGroupsInfo() const { +const std::vector& LHEWeightInfoProduct::allWeightGroupsInfo() const { return weightGroupsInfo_; } -const gen::WeightGroupInfo& LHEWeightInfoProduct::containingWeightGroupInfo(int index) const { - for (const auto& weightGroup : weightGroupsInfo_) { - if (weightGroup.indexInRange(index)) +const gen::WeightGroupInfo* LHEWeightInfoProduct::containingWeightGroupInfo(int index) const { + for (const auto weightGroup : weightGroupsInfo_) { + if (weightGroup->indexInRange(index)) return weightGroup; } throw std::domain_error("Failed to find containing weight group"); } -const gen::WeightGroupInfo& LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { +const gen::WeightGroupInfo* LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { return weightGroupsInfo_.at(weightGroupIndex); } -void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo info) { +void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo* info) { weightGroupsInfo_.push_back(info); } diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index e3ef861932c3d..2b548abbc5cad 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -197,9 +197,7 @@ - - - + @@ -231,6 +229,8 @@ + + From 0ba28e0e82f8b6ae52dde4a2cc9bdea0f48e033d Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Tue, 6 Aug 2019 04:16:08 -0400 Subject: [PATCH 09/75] Compiles with OwnVector, but need a proper copy constructor --- .../LHEInterface/interface/TestWeightInfo.h | 22 ++++++++--------- .../plugins/ExternalLHEProducer.cc | 18 +++++++------- .../LHEInterface/plugins/LHESource.cc | 4 ++-- .../interface/LHEWeightInfoProduct.h | 13 +++++----- .../interface/WeightGroupInfo.h | 24 +++++++++++++++++++ .../src/LHEWeightInfoProduct.cc | 18 +++++++------- .../GeneratorProducts/src/classes_def.xml | 1 + 7 files changed, 63 insertions(+), 37 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h index b3b63d40c71ff..65b934d8667d0 100644 --- a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h +++ b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h @@ -8,8 +8,8 @@ std::string parseId(std::string label) { return std::string(matches.str(1)); } -gen::WeightGroupInfo* getExampleScaleWeights() { - gen::WeightGroupInfo* scaleInfo = new gen::WeightGroupInfo( +gen::WeightGroupInfo getExampleScaleWeights() { + gen::WeightGroupInfo scaleInfo = gen::WeightGroupInfo( "", "centralScaleVariations" ); @@ -24,16 +24,16 @@ gen::WeightGroupInfo* getExampleScaleWeights() { R"( mur=0.5 muf=2 )", R"( mur=0.5 muf=0.5 )", }; - scaleInfo->setWeightType(gen::kScaleWeights); + scaleInfo.setWeightType(gen::kScaleWeights); for (size_t i = 0; i < entries.size(); i++) { - scaleInfo->addContainedId(i, parseId(entries[i]), entries[i]); + scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); } return scaleInfo; } -gen::WeightGroupInfo* getExampleScaleWeightsOutOfOrder() { - gen::WeightGroupInfo* scaleInfo = new gen::WeightGroupInfo( +gen::WeightGroupInfo getExampleScaleWeightsOutOfOrder() { + gen::WeightGroupInfo scaleInfo = gen::WeightGroupInfo( "", "centralScaleVariations" ); @@ -48,15 +48,15 @@ gen::WeightGroupInfo* getExampleScaleWeightsOutOfOrder() { R"( mur=0.5 muf=1 )", R"( mur=0.5 muf=0.5 )", }; - scaleInfo->setWeightType(gen::kScaleWeights); + scaleInfo.setWeightType(gen::kScaleWeights); for (size_t i = 0; i < entries.size(); i++) { - scaleInfo->addContainedId(i, parseId(entries[i]), entries[i]); + scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); } return scaleInfo; } -std::vector getExamplePdfWeights() { +edm::OwnVector getExamplePdfWeights() { std::vector entries = { R"()", R"( Member 0 of sets NNPDF31_nnlo_hessian_pdfas)", @@ -987,7 +987,7 @@ std::vector getExamplePdfWeights() { R"()", }; - std::vector pdfWeights; + edm::OwnVector pdfWeights; //Don't forget about the scale weights int counter = 8; @@ -998,7 +998,7 @@ std::vector getExamplePdfWeights() { else if (entry.find("addContainedId(counter, parseId(entry), entry); + currentSet.addContainedId(counter, parseId(entry), entry); } counter++; } diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 78074f894fd23..ee96964797482 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -109,7 +109,7 @@ class ExternalLHEProducer : public edm::one::EDProducer partonLevel; boost::ptr_deque runInfoProducts; bool wasMerged; - std::vector weightGroups_; + edm::OwnVector weightGroups_; class FileCloseSentry : private boost::noncopyable { public: @@ -213,10 +213,8 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) int weightNum = 0; for (const auto& weight : partonLevel->weights()) { weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex); - auto group = weightGroups_.at(weightGroupIndex); - if (!group) - throw std::out_of_range("Invalid index " + weightGroupIndex); - int entry = group->weightVectorEntry(weight.id, weightNum); + auto group = weightGroups_[weightGroupIndex]; + int entry = group.weightVectorEntry(weight.id, weightNum); weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); weightNum++; } @@ -350,9 +348,9 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) reader_ = std::make_unique(infiles, skip); std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); - gen::WeightGroupInfo* scaleInfo = getExampleScaleWeights(); + gen::WeightGroupInfo scaleInfo = getExampleScaleWeights(); //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); - std::vector pdfSets = getExamplePdfWeights(); + edm::OwnVector pdfSets = getExamplePdfWeights(); weightInfoProduct->addWeightGroupInfo(scaleInfo); for (auto pdfSet : pdfSets) @@ -537,16 +535,16 @@ int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int // Start search at previous index, under expectation of ordered weights for (int index = previousGroupIndex; index < std::min(index+1, static_cast(weightGroups_.size())); index++) { - gen::WeightGroupInfo* weightGroup = weightGroups_.at(previousGroupIndex); + gen::WeightGroupInfo& weightGroup = weightGroups_[previousGroupIndex]; // Fast search assuming order is not perturbed outside of weight group - if (weightGroup->indexInRange(weightIndex) && weightGroup->containsWeight(wgtId, weightIndex)) + if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) return static_cast(index); } // Fall back to unordered search int counter = 0; for (auto weightGroup : weightGroups_) { - if (weightGroup->containsWeight(wgtId, weightIndex)) + if (weightGroup.containsWeight(wgtId, weightIndex)) return counter; counter++; } diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.cc b/GeneratorInterface/LHEInterface/plugins/LHESource.cc index 03402f473651f..a238a0fc613ca 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.cc @@ -147,8 +147,8 @@ void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { ); cenPdfInfo.setWeightType(gen::kPdfWeights); - product->addWeightGroupInfo(&scaleInfo); - product->addWeightGroupInfo(&cenPdfInfo); + product->addWeightGroupInfo(scaleInfo); + product->addWeightGroupInfo(cenPdfInfo); std::unique_ptr rdp(new edm::Wrapper(std::move(product))); iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp)); } diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h index 6d6af2cf99ca6..f0fa291ab3423 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -8,26 +8,27 @@ //#include +#include "DataFormats/Common/interface/OwnVector.h" #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" class LHEWeightInfoProduct { public: LHEWeightInfoProduct() {} - LHEWeightInfoProduct(std::vector& weightGroups); + LHEWeightInfoProduct(edm::OwnVector& weightGroups); LHEWeightInfoProduct(const LHEWeightInfoProduct& other); LHEWeightInfoProduct(LHEWeightInfoProduct&& other); ~LHEWeightInfoProduct() {} LHEWeightInfoProduct& operator=(const LHEWeightInfoProduct &other); LHEWeightInfoProduct& operator=(LHEWeightInfoProduct &&other); - const std::vector& allWeightGroupsInfo() const; - const gen::WeightGroupInfo* containingWeightGroupInfo(int index) const; - const gen::WeightGroupInfo* orderedWeightGroupInfo(int index) const; - void addWeightGroupInfo(gen::WeightGroupInfo* info); + const edm::OwnVector& allWeightGroupsInfo() const; + const gen::WeightGroupInfo& containingWeightGroupInfo(int index) const; + const gen::WeightGroupInfo& orderedWeightGroupInfo(int index) const; + void addWeightGroupInfo(gen::WeightGroupInfo& info); private: - std::vector weightGroupsInfo_; + edm::OwnVector weightGroupsInfo_; }; diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index c666e39ed2cca..064a8c1001628 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -31,6 +31,30 @@ namespace gen { WeightGroupInfo(std::string header): headerEntry_(header), name_(header), firstId_(-1), lastId_(-1) {} + //WeightGroupInfo& operator=(const WeightGroupInfo &other) { + // headerEntry_ = other.headerEntry_; + // name_ = other.name_; + // weightType_ = other.weightType_; + // idsContained_ = other.idsContained_; + // firstId_ = other.firstId_; + // lastId_ = other.lastId_; + // return * this; + //} + + //WeightGroupInfo& operator=(WeightGroupInfo &&other) { + // headerEntry_ = std::move(other.headerEntry_); + // name_ = std::move(other.name_); + // weightType_ = std::move(other.weightType_); + // idsContained_ = std::move(other.idsContained_); + // firstId_ = std::move(other.firstId_); + // lastId_ = std::move(other.lastId_); + // return *this; + //} + + WeightGroupInfo* clone() const { + return new WeightGroupInfo(*this); + } + WeightMetaInfo weightMetaInfo(int weightEntry) { return idsContained_.at(weightEntry); } diff --git a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc index 2e6c653ddbfd1..78c7d858f65f6 100644 --- a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc @@ -3,7 +3,7 @@ #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" -LHEWeightInfoProduct::LHEWeightInfoProduct(std::vector& weightGroups) { +LHEWeightInfoProduct::LHEWeightInfoProduct(edm::OwnVector& weightGroups) { weightGroupsInfo_ = weightGroups; } @@ -17,22 +17,24 @@ LHEWeightInfoProduct& LHEWeightInfoProduct::operator=(LHEWeightInfoProduct &&oth return *this; } -const std::vector& LHEWeightInfoProduct::allWeightGroupsInfo() const { +const edm::OwnVector& LHEWeightInfoProduct::allWeightGroupsInfo() const { return weightGroupsInfo_; } -const gen::WeightGroupInfo* LHEWeightInfoProduct::containingWeightGroupInfo(int index) const { - for (const auto weightGroup : weightGroupsInfo_) { - if (weightGroup->indexInRange(index)) +const gen::WeightGroupInfo& LHEWeightInfoProduct::containingWeightGroupInfo(int index) const { + for (const auto& weightGroup : weightGroupsInfo_) { + if (weightGroup.indexInRange(index)) return weightGroup; } throw std::domain_error("Failed to find containing weight group"); } -const gen::WeightGroupInfo* LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { - return weightGroupsInfo_.at(weightGroupIndex); +const gen::WeightGroupInfo& LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { + if (weightGroupIndex >= static_cast(weightGroupsInfo_.size())) + throw std::range_error("Weight index out of range!"); + return weightGroupsInfo_[weightGroupIndex]; } -void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo* info) { +void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo& info) { weightGroupsInfo_.push_back(info); } diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index 2b548abbc5cad..7e6ae7131b9c8 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -231,6 +231,7 @@ + From 9ba9510ed189b63a00d1e489cb8fa6e147605e18 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Tue, 6 Aug 2019 15:22:07 -0400 Subject: [PATCH 10/75] Working with edm::OwnVector --- .../LHEInterface/interface/TestWeightInfo.h | 6 +-- .../plugins/ExternalLHEProducer.cc | 7 ++- .../interface/WeightGroupInfo.h | 44 +++++++++++-------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h index 65b934d8667d0..efb0162bb8063 100644 --- a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h +++ b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h @@ -996,11 +996,9 @@ edm::OwnVector getExamplePdfWeights() { pdfWeights.push_back(new gen::WeightGroupInfo(entry)); } else if (entry.find("weights()) { weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex); + if (weightGroupIndex < 0 || weightGroupIndex >= static_cast(weightGroups_.size())) { + continue; + } auto group = weightGroups_[weightGroupIndex]; int entry = group.weightVectorEntry(weight.id, weightNum); weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); @@ -533,12 +536,14 @@ ExternalLHEProducer::executeScript() int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex) { // Start search at previous index, under expectation of ordered weights + previousGroupIndex = previousGroupIndex >=0 ? previousGroupIndex : 0; for (int index = previousGroupIndex; index < std::min(index+1, static_cast(weightGroups_.size())); index++) { gen::WeightGroupInfo& weightGroup = weightGroups_[previousGroupIndex]; // Fast search assuming order is not perturbed outside of weight group - if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) + if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) { return static_cast(index); + } } // Fall back to unordered search diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index 064a8c1001628..526e34765167e 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -6,6 +6,7 @@ */ #include #include +#include namespace gen { struct WeightMetaInfo { @@ -31,25 +32,23 @@ namespace gen { WeightGroupInfo(std::string header): headerEntry_(header), name_(header), firstId_(-1), lastId_(-1) {} - //WeightGroupInfo& operator=(const WeightGroupInfo &other) { - // headerEntry_ = other.headerEntry_; - // name_ = other.name_; - // weightType_ = other.weightType_; - // idsContained_ = other.idsContained_; - // firstId_ = other.firstId_; - // lastId_ = other.lastId_; - // return * this; - //} - - //WeightGroupInfo& operator=(WeightGroupInfo &&other) { - // headerEntry_ = std::move(other.headerEntry_); - // name_ = std::move(other.name_); - // weightType_ = std::move(other.weightType_); - // idsContained_ = std::move(other.idsContained_); - // firstId_ = std::move(other.firstId_); - // lastId_ = std::move(other.lastId_); - // return *this; - //} + void copy(const WeightGroupInfo &other) { + headerEntry_ = other.headerEntry(); + name_ = other.name(); + weightType_ = other.weightType(); + idsContained_ = other.idsContained(); + firstId_ = other.firstId(); + lastId_ = other.lastId(); + } + + WeightGroupInfo(const WeightGroupInfo &other) { + copy(other); + } + + WeightGroupInfo& operator=(const WeightGroupInfo &other) { + copy(other); + return *this; + } WeightGroupInfo* clone() const { return new WeightGroupInfo(*this); @@ -125,6 +124,13 @@ namespace gen { return (index <= lastId_ && index >= firstId_); } + std::string headerEntry() const { return headerEntry_; } + std::string name() const { return name_; } + WeightType weightType() const { return weightType_; } + std::vector idsContained() const { return idsContained_; } + int firstId() const { return firstId_; } + int lastId() const { return lastId_; } + private: std::string headerEntry_; std::string name_; From 338a979e682f57fabe42084f055502ab4130c08a Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 7 Aug 2019 04:35:51 -0400 Subject: [PATCH 11/75] Separate WeightGroupInfo into .h and .cc files --- .../interface/WeightGroupInfo.h | 106 ++++-------------- .../GeneratorProducts/src/WeightGroupInfo.cc | 86 ++++++++++++++ 2 files changed, 105 insertions(+), 87 deletions(-) create mode 100644 SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index 526e34765167e..364a43937f2fa 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -6,7 +6,7 @@ */ #include #include -#include +#include namespace gen { struct WeightMetaInfo { @@ -26,106 +26,38 @@ namespace gen { class WeightGroupInfo { public: - WeightGroupInfo() {} + WeightGroupInfo() : headerEntry_(""), name_(""), firstId_(-1), lastId_(-1) {} WeightGroupInfo(std::string header, std::string name): headerEntry_(header), name_(name), firstId_(-1), lastId_(-1) {} WeightGroupInfo(std::string header): headerEntry_(header), name_(header), firstId_(-1), lastId_(-1) {} - - void copy(const WeightGroupInfo &other) { - headerEntry_ = other.headerEntry(); - name_ = other.name(); - weightType_ = other.weightType(); - idsContained_ = other.idsContained(); - firstId_ = other.firstId(); - lastId_ = other.lastId(); - } - WeightGroupInfo(const WeightGroupInfo &other) { copy(other); } - WeightGroupInfo& operator=(const WeightGroupInfo &other) { copy(other); return *this; } - - WeightGroupInfo* clone() const { - return new WeightGroupInfo(*this); - } - - WeightMetaInfo weightMetaInfo(int weightEntry) { - return idsContained_.at(weightEntry); - } - - WeightMetaInfo weightMetaInfo(std::string wgtId) { - int weightEntry = weightVectorEntry(wgtId); - return idsContained_.at(weightEntry); - } - - int weightVectorEntry(const std::string& wgtId) { - return weightVectorEntry(wgtId, 0); - } - - int containsWeight(const std::string& wgtId, int weightEntry) { - return weightVectorEntry(wgtId, weightEntry) != -1; - } - - int weightVectorEntry(const std::string& wgtId, int weightEntry) { - int entry = -1; - if (!indexInRange(weightEntry)) { - size_t orderedEntry = weightEntry - firstId_; - if (orderedEntry < idsContained_.size()) - if (idsContained_.at(orderedEntry).id == wgtId) - return orderedEntry; - } - auto it = std::find_if(idsContained_.begin(), idsContained_.end(), - [wgtId] (const WeightMetaInfo& w) { return w.id == wgtId; }); - if (it != idsContained_.end()) - return std::distance(idsContained_.begin(), it); - return entry; - } - - void addContainedId(int weightEntry, std::string id, std::string label="") { - if (firstId_ == -1 || weightEntry < firstId_) { - firstId_ = weightEntry; - // Reset to reflect that indices will be shifted - for (auto& id : idsContained_) - id.localIndex = id.globalIndex - firstId_; - } - if (weightEntry > lastId_) - lastId_ = weightEntry; - - WeightMetaInfo info; - info.globalIndex = weightEntry; - info.localIndex = weightEntry - firstId_; - info.id = id; - info.label = label; - - if (idsContained_.size() < info.localIndex) { - idsContained_.resize(info.localIndex); - idsContained_.insert(idsContained_.begin()+info.localIndex, info); - } - else if (idsContained_.size() == info.localIndex) { - idsContained_.push_back(info); - } - else { - idsContained_.resize(info.localIndex+1); - idsContained_[info.localIndex] = info; - } - } - - std::vector containedIds() const { return idsContained_; } - + void copy(const WeightGroupInfo &other); + + WeightGroupInfo* clone() const; + WeightMetaInfo weightMetaInfo(int weightEntry); + WeightMetaInfo weightMetaInfo(std::string wgtId); + int weightVectorEntry(const std::string& wgtId); + int containsWeight(const std::string& wgtId, int weightEntry); + int weightVectorEntry(const std::string& wgtId, int weightEntry); + void addContainedId(int weightEntry, std::string id, std::string label); + std::vector containedIds() const; + bool indexInRange(int index) const; + + void setName(std::string name) { name_ = name; } + void setHeaderEntry(std::string header) { headerEntry_ = header; } void setWeightType(WeightType type) { weightType_ = type; } - std::string name() { return name_; } - - bool indexInRange(int index) const { - return (index <= lastId_ && index >= firstId_); - } + void setFirstId(int firstId) { firstId_ = firstId; } + void setLastId(int lastId) { lastId_ = lastId; } - std::string headerEntry() const { return headerEntry_; } std::string name() const { return name_; } + std::string headerEntry() const { return headerEntry_; } WeightType weightType() const { return weightType_; } std::vector idsContained() const { return idsContained_; } int firstId() const { return firstId_; } diff --git a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc new file mode 100644 index 0000000000000..a9cbccfdea6f9 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc @@ -0,0 +1,86 @@ +#include +#include +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" + +namespace gen { + void WeightGroupInfo::copy(const WeightGroupInfo &other) { + headerEntry_ = other.headerEntry(); + name_ = other.name(); + weightType_ = other.weightType(); + idsContained_ = other.idsContained(); + firstId_ = other.firstId(); + lastId_ = other.lastId(); + } + + WeightGroupInfo* WeightGroupInfo::clone() const { + return new WeightGroupInfo(*this); + } + + WeightMetaInfo WeightGroupInfo::weightMetaInfo(int weightEntry) { + return idsContained_.at(weightEntry); + } + + WeightMetaInfo WeightGroupInfo::weightMetaInfo(std::string wgtId) { + int weightEntry = weightVectorEntry(wgtId); + return idsContained_.at(weightEntry); + } + + int WeightGroupInfo::weightVectorEntry(const std::string& wgtId) { + return weightVectorEntry(wgtId, 0); + } + + int WeightGroupInfo::containsWeight(const std::string& wgtId, int weightEntry) { + return weightVectorEntry(wgtId, weightEntry) != -1; + } + + int WeightGroupInfo::weightVectorEntry(const std::string& wgtId, int weightEntry) { + int entry = -1; + if (!indexInRange(weightEntry)) { + size_t orderedEntry = weightEntry - firstId_; + if (orderedEntry < idsContained_.size()) + if (idsContained_.at(orderedEntry).id == wgtId) + return orderedEntry; + } + auto it = std::find_if(idsContained_.begin(), idsContained_.end(), + [wgtId] (const WeightMetaInfo& w) { return w.id == wgtId; }); + if (it != idsContained_.end()) + return std::distance(idsContained_.begin(), it); + return entry; + } + + void WeightGroupInfo::addContainedId(int weightEntry, std::string id, std::string label="") { + if (firstId_ == -1 || weightEntry < firstId_) { + firstId_ = weightEntry; + // Reset to reflect that indices will be shifted + for (auto& id : idsContained_) + id.localIndex = id.globalIndex - firstId_; + } + if (weightEntry > lastId_) + lastId_ = weightEntry; + + WeightMetaInfo info; + info.globalIndex = weightEntry; + info.localIndex = weightEntry - firstId_; + info.id = id; + info.label = label; + + if (idsContained_.size() < info.localIndex) { + idsContained_.resize(info.localIndex); + idsContained_.insert(idsContained_.begin()+info.localIndex, info); + } + else if (idsContained_.size() == info.localIndex) { + idsContained_.push_back(info); + } + else { + idsContained_.resize(info.localIndex+1); + idsContained_[info.localIndex] = info; + } + } + + std::vector WeightGroupInfo::containedIds() const { return idsContained_; } + + + bool WeightGroupInfo::indexInRange(int index) const { + return (index <= lastId_ && index >= firstId_); + } +} From 8397fca6352d6d36297683c2d6dcc9400a035a60 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 7 Aug 2019 10:36:19 -0400 Subject: [PATCH 12/75] Separate out PDF weights --- .../LHEInterface/interface/TestWeightInfo.h | 3 +- .../interface/PdfWeightGroupInfo.h | 44 +++++++++++++++++++ .../interface/WeightGroupInfo.h | 4 +- .../src/PdfWeightGroupInfo.cc | 16 +++++++ .../GeneratorProducts/src/classes_def.xml | 5 +-- 5 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h create mode 100644 SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h index efb0162bb8063..7e386bf1cd4ce 100644 --- a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h +++ b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h @@ -1,4 +1,5 @@ #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include std::string parseId(std::string label) { @@ -993,7 +994,7 @@ edm::OwnVector getExamplePdfWeights() { int counter = 8; for (const auto& entry : entries) { if (entry.find(" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" + +namespace gen { + void PdfWeightGroupInfo::copy(const PdfWeightGroupInfo &other) { + uncertaintyType_ = other.uncertaintyType(); + hasAlphasVars_ = other.hasAlphasVariations(); + alphasUpIndex_ = other.alphasDownIndex(); + alphasDownIndex_ = other.alphasDownIndex(); + WeightGroupInfo::copy(other); + } + + PdfWeightGroupInfo* PdfWeightGroupInfo::clone() const { + return new PdfWeightGroupInfo(*this); + } +} diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index 7e6ae7131b9c8..6e36f2de18394 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -223,9 +223,8 @@ - - - + + From 9e062713d369cd61c3b0514c98f51515570eb4a1 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 15 Aug 2019 04:32:53 -0400 Subject: [PATCH 13/75] Add scale-specific weightgroupinfo class --- .../interface/PdfWeightGroupInfo.h | 2 +- .../interface/ScaleWeightGroupInfo.h | 64 +++++++++++++++++++ .../interface/WeightGroupInfo.h | 2 +- .../src/PdfWeightGroupInfo.cc | 1 - .../src/ScaleWeightGroupInfo.cc | 52 +++++++++++++++ .../src/ScaleWeightGroupInfo.h | 16 +++++ 6 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h create mode 100644 SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc create mode 100644 SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h diff --git a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h index 3071bf7aa0f4e..5f1e5559f46e2 100644 --- a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h @@ -25,7 +25,7 @@ namespace gen { PdfWeightGroupInfo(const PdfWeightGroupInfo &other) { copy(other); } - virtual ~PdfWeightGroupInfo() override {}; + virtual ~PdfWeightGroupInfo() override {} void copy(const PdfWeightGroupInfo &other); PdfWeightGroupInfo* clone() const; diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h new file mode 100644 index 0000000000000..4a4c7971f0ab8 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -0,0 +1,64 @@ +#ifndef SimDataFormats_GeneratorProducts_ScaleWeightGroupInfo_h +#define SimDataFormats_GeneratorProducts_ScaleWeightGroupInfo_h + +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" + +namespace gen { + class ScaleWeightGroupInfo : public WeightGroupInfo { + private: + bool isFuncationFormVar_; + size_t icentral; + size_t imuR1muF2; + size_t imuR1muF05; + size_t imuR2muF05; + size_t imuR2muF1; + size_t imuR2muF2; + size_t imuR05muF05; + size_t imuR05muF1; + size_t imuR05muF2; + public: + ScaleWeightGroupInfo() : ScaleWeightGroupInfo("") {} + ScaleWeightGroupInfo(std::string header, std::string name) : + WeightGroupInfo(header, name) { + weightType_ = kScaleWeights; + isFuncationFormVar_ = false; + icentral = 0; + imuR1muF2 = 0; + imuR1muF05 = 0; + imuR2muF05 = 0; + imuR2muF1 = 0; + imuR2muF2 = 0; + imuR2muF05 = 0; + imuR05muF05 = 0; + imuR05muF1 = 0; + imuR05muF2 = 0; + } + ScaleWeightGroupInfo(std::string header) : + ScaleWeightGroupInfo(header, header) { } + ScaleWeightGroupInfo(const ScaleWeightGroupInfo &other) { + copy(other); + } + virtual ~ScaleWeightGroupInfo() override {} + void copy(const ScaleWeightGroupInfo &other); + ScaleWeightGroupInfo* clone() const; + + void setMuRMuFIndex(WeightMetaInfo info, float muR, float muF); + void addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF); + + // Is a variation of the functional form of the dynamic scale + bool isFunctionalFormVariation(); + void setIsFunctionalFormVariation(bool functionalVar) {isFuncationFormVar_ = functionalVar; } + size_t centralIndex() {return icentral; } + size_t muR1muF2Index() { return imuR1muF2; } + size_t muR1muF05Index() { return imuR1muF05; } + size_t muR2muF05Index() { return imuR2muF05; } + size_t muR2muF1Index() { return imuR2muF1; } + size_t muR2muF2Index() { return imuR2muF2; } + size_t muR05muF05Index() { return imuR05muF05; } + size_t muR05muF1Index() { return imuR05muF1; } + size_t muR05muF2Index() { return imuR05muF2; } + }; +} + +#endif + diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index a8d8bd0585248..a815ec762f7f8 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -26,7 +26,7 @@ namespace gen { class WeightGroupInfo { public: - WeightGroupInfo() : headerEntry_(""), name_(""), firstId_(-1), lastId_(-1) {} + WeightGroupInfo() : WeightGroupInfo("") {} WeightGroupInfo(std::string header, std::string name): headerEntry_(header), name_(name), firstId_(-1), lastId_(-1) {} WeightGroupInfo(std::string header): diff --git a/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc index f78cb5a1850d2..4e0175bf9629c 100644 --- a/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc @@ -1,4 +1,3 @@ -#include #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" namespace gen { diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc new file mode 100644 index 0000000000000..cb237225cb76f --- /dev/null +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc @@ -0,0 +1,52 @@ +#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include + +namespace gen { + void ScaleWeightGroupInfo::copy(const ScaleWeightGroupInfo &other) { + icentral = centralIndex(); + imuR1muF2 = muR1muF2Index(); + imuR1muF05 = muR1muF05Index(); + imuR2muF05 = muR2muF05Index(); + imuR2muF1 = muR2muF1Index(); + imuR2muF2 = muR2muF2Index(); + imuR2muF05 = muR2muF05Index(); + imuR05muF1 = muR05muF1Index(); + imuR05muF2 = muR05muF2Index(); + WeightGroupInfo::copy(other); + } + + ScaleWeightGroupInfo* ScaleWeightGroupInfo::clone() const { + return new ScaleWeightGroupInfo(*this); + } + + void ScaleWeightGroupInfo::addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF) { + WeightGroupInfo::addContainedId(weightEntry, id, label); + auto metaInfo = weightMetaInfo(weightEntry); + setMuRMuFIndex(metaInfo, muR, muF); + } + + void ScaleWeightGroupInfo::setMuRMuFIndex(WeightMetaInfo info, float muR, float muF) { + if (muR == 0.5 && muF == 0.5) + imuR05muF05 = info.localIndex; + else if (muR == 0.5 && muF == 1.0) + imuR05muF1 = info.localIndex; + else if (muR == 0.5 && muF == 2.0) + imuR05muF2 = info.localIndex; + else if (muR == 1.0 && muF == 0.5) + imuR1muF05 = info.localIndex; + else if (muR == 1.0 && muF == 1.0) + icentral = info.localIndex; + else if (muR == 1.0 && muF == 2.0) + imuR1muF2 = info.localIndex; + else if (muR == 2.0 && muF == 0.5) + imuR2muF05 = info.localIndex; + else if (muR == 2.0 && muF == 1.0) + imuR2muF1 = info.localIndex; + else if (muR == 2.0 && muF == 2.0) + imuR2muF2 = info.localIndex; + else + throw std::invalid_argument("Invalid muF and muR variation is not a factor of two from central value"); + } +} + + diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h new file mode 100644 index 0000000000000..d84b109a9b18b --- /dev/null +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h @@ -0,0 +1,16 @@ +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" + +namespace gen { + void PdfWeightGroupInfo::copy(const PdfWeightGroupInfo &other) { + uncertaintyType_ = other.uncertaintyType(); + hasAlphasVars_ = other.hasAlphasVariations(); + alphasUpIndex_ = other.alphasDownIndex(); + alphasDownIndex_ = other.alphasDownIndex(); + WeightGroupInfo::copy(other); + } + + PdfWeightGroupInfo* PdfWeightGroupInfo::clone() const { + return new PdfWeightGroupInfo(*this); + } +} + From 071c069ce03bd33257f30f205694fdd8b39c881a Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Thu, 15 Aug 2019 07:21:30 -0400 Subject: [PATCH 14/75] First tests with parsing of lhe file. Need to incorp EDM lhe reader --- .../interface/LHEWeightGroupReaderHelper.h | 128 ++++++++++++++++++ .../plugins/ExternalLHEProducer.cc | 49 ++++--- 2 files changed, 159 insertions(+), 18 deletions(-) create mode 100644 GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h new file mode 100644 index 0000000000000..25cebc478fab3 --- /dev/null +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -0,0 +1,128 @@ +#ifndef GeneratorInterface_LHEInterface_LHEWeightGroupReaderHelper_h +#define GeneratorInterface_LHEInterface_LHEWeightGroupReaderHelper_h + +#include +#include +#include +#include + +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" + + +class LHEWeightGroupReaderHelper { +public: + LHEWeightGroupReaderHelper() : curGroup(gen::kUnknownWeights) {} + + //// possibly add more versions of this functions for different inputs + void parseLHEFile(std::string filename); + + + gen::WeightGroupInfo* getScaleInfo() {return scaleInfo;} + edm::OwnVector getPdfVector() {return pdfVector;} + +private: + // Functions + std::regex createRegexSearch(std::vector); + std::map getTagsMap(std::string, std::regex); + + // Variables + gen::WeightType curWeight; + gen::WeightGroupInfo* scaleInfo; + edm::OwnVector pdfVector; + std::regex weightStart(".*.*"); + std::regex weightEnd(".*.*"); + std::regex weightContent("\\s*(.+)"); + +}; + +void +LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { + ifstream file; + file.open(filename); + + + //// may put in constructor, can have flag to specify these values + //// To make this class a little more flexible + std::vector weightGroup = {"name|type", "combine"}; + std::vector weightInfo = {"MUF", "id", "MUR", "PDF"}; + + std::regex groupTags = createRegexSearch(weightGroup); + std::regex infoTags = createRegexSearch(weightInfo); + /// end that comment + + + std::string line; + std::smatch m; + int index = 0; + while(getline(file, line)) { + if(std::regex_match(line, weightStart)) { + std::string groupLine = line; + std::string name = getTagsMap(line, groupTags)["name"]; + + if(name == "Central scale variation") + curWeight = gen::kScaleWeights; + else + curWeight = gen::kPdfWeights; + + /// file weights + + while(getline(file, line) && !std::regex_match(line, weightEnd)) { + auto tmp = getTagsMap(line, infoTags); + std::regex_search(line, m, weightContent); + std::string content = m[1].str(); + + gen::WeightGroupInfo* tmpWeight = nullptr; + if(curWeight == gen::kScaleWeights) + tmpWeight = new gen::ScaleWeightGroupInfo(groupLine); + else if(curWeight == gen::kPdfWeights) + tmpWeight = new gen::PdfWeightGroupInfo(groupLine); + + tmpWeight->setWeightType(curWeight); + tmpWeight->addContainedId(index, tmp["id"], line); + index++; + } + curWeight = gen::kUnknownWeights; + } + } + +} + + +std::map +LHEWeightGroupReaderHelper::getTagsMap(std::string s, std::regex r) { + std::smatch m; + + std::map retMap; + while(std::regex_search(s, m, r)) { + for(int i = 1; i < m.length() - 1; i += 2) { + if(m[i] != "") { + retMap[m[i]] = m[i + 1]; + } + } + s = m.suffix().str(); + } + + return retMap; +} + + + +std::regex +LHEWeightGroupReaderHelper::createRegexSearch(std::vector names) { + std::string s = "(?:"; + size_t numNames = names.size(); + for(int i=0; i < numNames; ++i) { + s += "\\s*(" + names[i] + ")=\"([^\"]+)\""; + if(i != numNames - 1) { + s += "|"; + } + } + s += ")"; + + return std::regex(s); +} + + +#endif diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 0775cdacf6836..6a68f526fb3e9 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -58,6 +58,7 @@ Description: [one line class summary] #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" #include "GeneratorInterface/LHEInterface/interface/LHEReader.h" #include "GeneratorInterface/LHEInterface/interface/TestWeightInfo.h" +#include "GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h" #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Utilities/interface/RandomNumberGenerator.h" @@ -350,38 +351,50 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) unsigned int skip = 0; reader_ = std::make_unique(infiles, skip); + + + std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); - gen::WeightGroupInfo scaleInfo = getExampleScaleWeights(); + gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights(); + edm::OwnVector pdfSets;// = getExamplePdfWeights(); //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); - edm::OwnVector pdfSets = getExamplePdfWeights(); + + // setup file reader + string LHEfilename ="cmsgrid_final.lhe"; + LHEWeightGroupReaderHelper reader; + reader.parseLHEFile(LHEfilename); + scaleInfo = *reader.getScaleInfo(); + pdfSet = reader.getPdfVector(); + + weightInfoProduct->addWeightGroupInfo(scaleInfo); for (auto pdfSet : pdfSets) - weightInfoProduct->addWeightGroupInfo(pdfSet); + weightInfoProduct->addWeightGroupInfo(pdfSet); weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); run.put(std::move(weightInfoProduct)); nextEvent(); if (runInfoLast) { - runInfo = runInfoLast; + runInfo = runInfoLast; - std::unique_ptr product(new LHERunInfoProduct(*runInfo->getHEPRUP())); - std::for_each(runInfo->getHeaders().begin(), - runInfo->getHeaders().end(), - boost::bind(&LHERunInfoProduct::addHeader, - product.get(), _1)); - std::for_each(runInfo->getComments().begin(), - runInfo->getComments().end(), - boost::bind(&LHERunInfoProduct::addComment, - product.get(), _1)); + std::unique_ptr product(new LHERunInfoProduct(*runInfo->getHEPRUP())); + std::for_each(runInfo->getHeaders().begin(), + runInfo->getHeaders().end(), + boost::bind(&LHERunInfoProduct::addHeader, + product.get(), _1)); + std::for_each(runInfo->getComments().begin(), + runInfo->getComments().end(), + boost::bind(&LHERunInfoProduct::addComment, + product.get(), _1)); - // keep a copy around in case of merging - runInfoProducts.push_back(new LHERunInfoProduct(*product)); - wasMerged = false; + // keep a copy around in case of merging + runInfoProducts.push_back(new LHERunInfoProduct(*product)); + wasMerged = false; - run.put(std::move(product)); + run.put(std::move(product)); - runInfo.reset(); + runInfo.reset(); } } From 6bfea57af6dd3765ccb06147daa8491e40568964 Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Thu, 15 Aug 2019 23:13:59 +0200 Subject: [PATCH 15/75] fixing readerhelper problems --- .../interface/LHEWeightGroupReaderHelper.h | 41 +++++++++++-------- .../plugins/ExternalLHEProducer.cc | 6 +-- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index 25cebc478fab3..6a2855ddf44f8 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" @@ -13,7 +14,7 @@ class LHEWeightGroupReaderHelper { public: - LHEWeightGroupReaderHelper() : curGroup(gen::kUnknownWeights) {} + LHEWeightGroupReaderHelper() : curWeight(gen::kUnknownWeights) {} //// possibly add more versions of this functions for different inputs void parseLHEFile(std::string filename); @@ -31,18 +32,17 @@ class LHEWeightGroupReaderHelper { gen::WeightType curWeight; gen::WeightGroupInfo* scaleInfo; edm::OwnVector pdfVector; - std::regex weightStart(".*.*"); - std::regex weightEnd(".*.*"); - std::regex weightContent("\\s*(.+)"); + std::regex weightStart = std::regex(".*.*"); + std::regex weightEnd = std::regex(".*.*"); + std::regex weightContent = std::regex("\\s*(.+)"); }; void LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { - ifstream file; + std::ifstream file; file.open(filename); - //// may put in constructor, can have flag to specify these values //// To make this class a little more flexible std::vector weightGroup = {"name|type", "combine"}; @@ -52,7 +52,7 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { std::regex infoTags = createRegexSearch(weightInfo); /// end that comment - + std::string line; std::smatch m; int index = 0; @@ -60,28 +60,33 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { if(std::regex_match(line, weightStart)) { std::string groupLine = line; std::string name = getTagsMap(line, groupTags)["name"]; - + if(name == "Central scale variation") - curWeight = gen::kScaleWeights; - else - curWeight = gen::kPdfWeights; + curWeight = gen::kScaleWeights; + else + curWeight = gen::kPdfWeights; /// file weights - while(getline(file, line) && !std::regex_match(line, weightEnd)) { auto tmp = getTagsMap(line, infoTags); std::regex_search(line, m, weightContent); std::string content = m[1].str(); gen::WeightGroupInfo* tmpWeight = nullptr; - if(curWeight == gen::kScaleWeights) + if(curWeight == gen::kScaleWeights) { tmpWeight = new gen::ScaleWeightGroupInfo(groupLine); - else if(curWeight == gen::kPdfWeights) + scaleInfo = tmpWeight; + } + else if(curWeight == gen::kPdfWeights) { tmpWeight = new gen::PdfWeightGroupInfo(groupLine); - - tmpWeight->setWeightType(curWeight); + // pdfVector.push_back(tmpWeight); + } tmpWeight->addContainedId(index, tmp["id"], line); - index++; + + if(curWeight == gen::kPdfWeights) //hate hate hate + pdfVector.push_back(tmpWeight); + index++; + } curWeight = gen::kUnknownWeights; } @@ -113,7 +118,7 @@ std::regex LHEWeightGroupReaderHelper::createRegexSearch(std::vector names) { std::string s = "(?:"; size_t numNames = names.size(); - for(int i=0; i < numNames; ++i) { + for(size_t i=0; i < numNames; ++i) { s += "\\s*(" + names[i] + ")=\"([^\"]+)\""; if(i != numNames - 1) { s += "|"; diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 6a68f526fb3e9..444bf0993a87e 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -360,13 +360,11 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); // setup file reader - string LHEfilename ="cmsgrid_final.lhe"; + std::string LHEfilename ="cmsgrid_final.lhe"; LHEWeightGroupReaderHelper reader; reader.parseLHEFile(LHEfilename); scaleInfo = *reader.getScaleInfo(); - pdfSet = reader.getPdfVector(); - - + pdfSets = reader.getPdfVector(); weightInfoProduct->addWeightGroupInfo(scaleInfo); for (auto pdfSet : pdfSets) From f62468c7e64b1d83c0d30df79754e27332d847f5 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 15 Aug 2019 19:28:49 -0400 Subject: [PATCH 16/75] Working on parsing integration with scale/pdf weights --- .../interface/LHEWeightGroupReaderHelper.h | 79 ++++++++++--------- .../plugins/ExternalLHEProducer.cc | 9 +-- .../interface/ScaleWeightGroupInfo.h | 58 +++++++------- .../src/ScaleWeightGroupInfo.cc | 36 ++++----- .../src/ScaleWeightGroupInfo.h | 16 ---- .../GeneratorProducts/src/classes_def.xml | 7 ++ 6 files changed, 98 insertions(+), 107 deletions(-) delete mode 100644 SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index 6a2855ddf44f8..f669a3c6a6094 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -14,14 +14,17 @@ class LHEWeightGroupReaderHelper { public: - LHEWeightGroupReaderHelper() : curWeight(gen::kUnknownWeights) {} + LHEWeightGroupReaderHelper() : curWeight_(gen::kUnknownWeights) { + weightGroupStart_ = std::regex(".*.*"); + weightGroupEnd_ = std::regex(".*.*"); + weightContent_ = std::regex("\\s*(.+)"); + } //// possibly add more versions of this functions for different inputs void parseLHEFile(std::string filename); - gen::WeightGroupInfo* getScaleInfo() {return scaleInfo;} - edm::OwnVector getPdfVector() {return pdfVector;} + edm::OwnVector getWeightGroups() {return weightGroups_;} private: // Functions @@ -29,12 +32,11 @@ class LHEWeightGroupReaderHelper { std::map getTagsMap(std::string, std::regex); // Variables - gen::WeightType curWeight; - gen::WeightGroupInfo* scaleInfo; - edm::OwnVector pdfVector; - std::regex weightStart = std::regex(".*.*"); - std::regex weightEnd = std::regex(".*.*"); - std::regex weightContent = std::regex("\\s*(.+)"); + gen::WeightType curWeight_; + edm::OwnVector weightGroups_; + std::regex weightGroupStart_; + std::regex weightGroupEnd_; + std::regex weightContent_; }; @@ -54,44 +56,45 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { std::string line; - std::smatch m; + std::smatch matches; + // TODO: Not sure the weight indexing is right here, this seems to more or less + // count the lines which isn't quite the goal. TOCHECK! int index = 0; while(getline(file, line)) { - if(std::regex_match(line, weightStart)) { + if(std::regex_match(line, weightGroupStart_)) { std::string groupLine = line; std::string name = getTagsMap(line, groupTags)["name"]; + //TODO: Fine for now, but in general there should also be a check on the PDF weights, + // e.g., it could be an unknown weight if(name == "Central scale variation") - curWeight = gen::kScaleWeights; - else - curWeight = gen::kPdfWeights; + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(groupLine)); + else + weightGroups_.push_back(new gen::PdfWeightGroupInfo(groupLine)); /// file weights - while(getline(file, line) && !std::regex_match(line, weightEnd)) { - auto tmp = getTagsMap(line, infoTags); - std::regex_search(line, m, weightContent); - std::string content = m[1].str(); - - gen::WeightGroupInfo* tmpWeight = nullptr; - if(curWeight == gen::kScaleWeights) { - tmpWeight = new gen::ScaleWeightGroupInfo(groupLine); - scaleInfo = tmpWeight; - } - else if(curWeight == gen::kPdfWeights) { - tmpWeight = new gen::PdfWeightGroupInfo(groupLine); - // pdfVector.push_back(tmpWeight); - } - tmpWeight->addContainedId(index, tmp["id"], line); - - if(curWeight == gen::kPdfWeights) //hate hate hate - pdfVector.push_back(tmpWeight); - index++; - - } - curWeight = gen::kUnknownWeights; - } + while(getline(file, line) && !std::regex_match(line, weightGroupEnd_)) { + auto tagsMap = getTagsMap(line, infoTags); + std::regex_search(line, matches, weightContent_); + // TODO: Add proper check that it worked + std::string content = matches[1].str(); + + auto& group = weightGroups_.back(); + if (group.weightType() == gen::kScaleWeights) { + float muR = std::stof(tagsMap["MUR"]); + float muF = std::stof(tagsMap["MUF"]); + auto& scaleGroup = static_cast(group); + scaleGroup.addContainedId(index, tagsMap["id"], line, muR, muF); + } + else + group.addContainedId(index, tagsMap["id"], line); + + index++; + + curWeight_ = gen::kUnknownWeights; + } + } } - } diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 444bf0993a87e..924d8f34ca40d 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -355,19 +355,16 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); - gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights(); - edm::OwnVector pdfSets;// = getExamplePdfWeights(); + //gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights(); + //edm::OwnVector pdfSets;// = getExamplePdfWeights(); //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); // setup file reader std::string LHEfilename ="cmsgrid_final.lhe"; LHEWeightGroupReaderHelper reader; reader.parseLHEFile(LHEfilename); - scaleInfo = *reader.getScaleInfo(); - pdfSets = reader.getPdfVector(); - weightInfoProduct->addWeightGroupInfo(scaleInfo); - for (auto pdfSet : pdfSets) + for (auto pdfSet : reader.getWeightGroups()) weightInfoProduct->addWeightGroupInfo(pdfSet); weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); run.put(std::move(weightInfoProduct)); diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index 4a4c7971f0ab8..179b183c07fd9 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -7,31 +7,31 @@ namespace gen { class ScaleWeightGroupInfo : public WeightGroupInfo { private: bool isFuncationFormVar_; - size_t icentral; - size_t imuR1muF2; - size_t imuR1muF05; - size_t imuR2muF05; - size_t imuR2muF1; - size_t imuR2muF2; - size_t imuR05muF05; - size_t imuR05muF1; - size_t imuR05muF2; + size_t icentral_; + size_t imuR1muF2_; + size_t imuR1muF05_; + size_t imuR2muF05_; + size_t imuR2muF1_; + size_t imuR2muF2_; + size_t imuR05muF05_; + size_t imuR05muF1_; + size_t imuR05muF2_; public: ScaleWeightGroupInfo() : ScaleWeightGroupInfo("") {} ScaleWeightGroupInfo(std::string header, std::string name) : WeightGroupInfo(header, name) { weightType_ = kScaleWeights; isFuncationFormVar_ = false; - icentral = 0; - imuR1muF2 = 0; - imuR1muF05 = 0; - imuR2muF05 = 0; - imuR2muF1 = 0; - imuR2muF2 = 0; - imuR2muF05 = 0; - imuR05muF05 = 0; - imuR05muF1 = 0; - imuR05muF2 = 0; + icentral_ = 0; + imuR1muF2_ = 0; + imuR1muF05_ = 0; + imuR2muF05_ = 0; + imuR2muF1_ = 0; + imuR2muF2_ = 0; + imuR2muF05_ = 0; + imuR05muF05_ = 0; + imuR05muF1_ = 0; + imuR05muF2_ = 0; } ScaleWeightGroupInfo(std::string header) : ScaleWeightGroupInfo(header, header) { } @@ -48,16 +48,16 @@ namespace gen { // Is a variation of the functional form of the dynamic scale bool isFunctionalFormVariation(); void setIsFunctionalFormVariation(bool functionalVar) {isFuncationFormVar_ = functionalVar; } - size_t centralIndex() {return icentral; } - size_t muR1muF2Index() { return imuR1muF2; } - size_t muR1muF05Index() { return imuR1muF05; } - size_t muR2muF05Index() { return imuR2muF05; } - size_t muR2muF1Index() { return imuR2muF1; } - size_t muR2muF2Index() { return imuR2muF2; } - size_t muR05muF05Index() { return imuR05muF05; } - size_t muR05muF1Index() { return imuR05muF1; } - size_t muR05muF2Index() { return imuR05muF2; } - }; + size_t centralIndex() {return icentral_; } + size_t muR1muF2Index() { return imuR1muF2_; } + size_t muR1muF05Index() { return imuR1muF05_; } + size_t muR2muF05Index() { return imuR2muF05_; } + size_t muR2muF1Index() { return imuR2muF1_; } + size_t muR2muF2Index() { return imuR2muF2_; } + size_t muR05muF05Index() { return imuR05muF05_; } + size_t muR05muF1Index() { return imuR05muF1_; } + size_t muR05muF2Index() { return imuR05muF2_; } + }_; } #endif diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc index cb237225cb76f..5d2e392d89164 100644 --- a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc @@ -3,15 +3,15 @@ namespace gen { void ScaleWeightGroupInfo::copy(const ScaleWeightGroupInfo &other) { - icentral = centralIndex(); - imuR1muF2 = muR1muF2Index(); - imuR1muF05 = muR1muF05Index(); - imuR2muF05 = muR2muF05Index(); - imuR2muF1 = muR2muF1Index(); - imuR2muF2 = muR2muF2Index(); - imuR2muF05 = muR2muF05Index(); - imuR05muF1 = muR05muF1Index(); - imuR05muF2 = muR05muF2Index(); + icentral_ = centralIndex(); + imuR1muF2_ = muR1muF2Index(); + imuR1muF05_ = muR1muF05Index(); + imuR2muF05_ = muR2muF05Index(); + imuR2muF1_ = muR2muF1Index(); + imuR2muF2_ = muR2muF2Index(); + imuR2muF05_ = muR2muF05Index(); + imuR05muF1_ = muR05muF1Index(); + imuR05muF2_ = muR05muF2Index(); WeightGroupInfo::copy(other); } @@ -27,23 +27,23 @@ namespace gen { void ScaleWeightGroupInfo::setMuRMuFIndex(WeightMetaInfo info, float muR, float muF) { if (muR == 0.5 && muF == 0.5) - imuR05muF05 = info.localIndex; + imuR05muF05_ = info.localIndex; else if (muR == 0.5 && muF == 1.0) - imuR05muF1 = info.localIndex; + imuR05muF1_ = info.localIndex; else if (muR == 0.5 && muF == 2.0) - imuR05muF2 = info.localIndex; + imuR05muF2_ = info.localIndex; else if (muR == 1.0 && muF == 0.5) - imuR1muF05 = info.localIndex; + imuR1muF05_ = info.localIndex; else if (muR == 1.0 && muF == 1.0) - icentral = info.localIndex; + icentral_ = info.localIndex; else if (muR == 1.0 && muF == 2.0) - imuR1muF2 = info.localIndex; + imuR1muF2_ = info.localIndex; else if (muR == 2.0 && muF == 0.5) - imuR2muF05 = info.localIndex; + imuR2muF05_ = info.localIndex; else if (muR == 2.0 && muF == 1.0) - imuR2muF1 = info.localIndex; + imuR2muF1_ = info.localIndex; else if (muR == 2.0 && muF == 2.0) - imuR2muF2 = info.localIndex; + imuR2muF2_ = info.localIndex; else throw std::invalid_argument("Invalid muF and muR variation is not a factor of two from central value"); } diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h deleted file mode 100644 index d84b109a9b18b..0000000000000 --- a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h +++ /dev/null @@ -1,16 +0,0 @@ -#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" - -namespace gen { - void PdfWeightGroupInfo::copy(const PdfWeightGroupInfo &other) { - uncertaintyType_ = other.uncertaintyType(); - hasAlphasVars_ = other.hasAlphasVariations(); - alphasUpIndex_ = other.alphasDownIndex(); - alphasDownIndex_ = other.alphasDownIndex(); - WeightGroupInfo::copy(other); - } - - PdfWeightGroupInfo* PdfWeightGroupInfo::clone() const { - return new PdfWeightGroupInfo(*this); - } -} - diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index 6e36f2de18394..0429c3c799790 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -225,12 +225,19 @@ + + + + + + + From 28f0ba2f3ff4d69e3fa10b1d6c3a78925965e666 Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Fri, 16 Aug 2019 05:15:51 -0400 Subject: [PATCH 17/75] Fixing little bit of readerhelper to change things to non-ptrs --- .../interface/LHEWeightGroupReaderHelper.h | 18 +++++++----------- .../plugins/ExternalLHEProducer.cc | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index 6a2855ddf44f8..a9b0b56034f79 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -20,7 +20,7 @@ class LHEWeightGroupReaderHelper { void parseLHEFile(std::string filename); - gen::WeightGroupInfo* getScaleInfo() {return scaleInfo;} + gen::WeightGroupInfo getScaleInfo() {return scaleInfo;} edm::OwnVector getPdfVector() {return pdfVector;} private: @@ -30,7 +30,7 @@ class LHEWeightGroupReaderHelper { // Variables gen::WeightType curWeight; - gen::WeightGroupInfo* scaleInfo; + gen::WeightGroupInfo scaleInfo; edm::OwnVector pdfVector; std::regex weightStart = std::regex(".*.*"); std::regex weightEnd = std::regex(".*.*"); @@ -72,21 +72,17 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { std::regex_search(line, m, weightContent); std::string content = m[1].str(); - gen::WeightGroupInfo* tmpWeight = nullptr; + gen::WeightGroupInfo tmpWeight; if(curWeight == gen::kScaleWeights) { - tmpWeight = new gen::ScaleWeightGroupInfo(groupLine); + tmpWeight = gen::ScaleWeightGroupInfo(groupLine); scaleInfo = tmpWeight; } else if(curWeight == gen::kPdfWeights) { - tmpWeight = new gen::PdfWeightGroupInfo(groupLine); - // pdfVector.push_back(tmpWeight); + pdfVector.push_back(new gen::PdfWeightGroupInfo(groupLine)); + tmpWeight = pdfVector.back(); } - tmpWeight->addContainedId(index, tmp["id"], line); - - if(curWeight == gen::kPdfWeights) //hate hate hate - pdfVector.push_back(tmpWeight); + tmpWeight.addContainedId(index, tmp["id"], line); index++; - } curWeight = gen::kUnknownWeights; } diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 444bf0993a87e..c363979e6f946 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -363,7 +363,7 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) std::string LHEfilename ="cmsgrid_final.lhe"; LHEWeightGroupReaderHelper reader; reader.parseLHEFile(LHEfilename); - scaleInfo = *reader.getScaleInfo(); + scaleInfo = reader.getScaleInfo(); pdfSets = reader.getPdfVector(); weightInfoProduct->addWeightGroupInfo(scaleInfo); From db06b18a56c1caacd53157cd5f912e23777624bb Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Fri, 16 Aug 2019 05:18:53 -0400 Subject: [PATCH 18/75] Random commit before merge: only spacing diffs -_- --- .../interface/ScaleWeightGroupInfo.h | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index 4a4c7971f0ab8..74c007c9582e6 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -5,58 +5,58 @@ namespace gen { class ScaleWeightGroupInfo : public WeightGroupInfo { - private: - bool isFuncationFormVar_; - size_t icentral; - size_t imuR1muF2; - size_t imuR1muF05; - size_t imuR2muF05; - size_t imuR2muF1; - size_t imuR2muF2; - size_t imuR05muF05; - size_t imuR05muF1; - size_t imuR05muF2; - public: - ScaleWeightGroupInfo() : ScaleWeightGroupInfo("") {} - ScaleWeightGroupInfo(std::string header, std::string name) : - WeightGroupInfo(header, name) { - weightType_ = kScaleWeights; - isFuncationFormVar_ = false; - icentral = 0; - imuR1muF2 = 0; - imuR1muF05 = 0; - imuR2muF05 = 0; - imuR2muF1 = 0; - imuR2muF2 = 0; - imuR2muF05 = 0; - imuR05muF05 = 0; - imuR05muF1 = 0; - imuR05muF2 = 0; - } - ScaleWeightGroupInfo(std::string header) : - ScaleWeightGroupInfo(header, header) { } - ScaleWeightGroupInfo(const ScaleWeightGroupInfo &other) { - copy(other); - } - virtual ~ScaleWeightGroupInfo() override {} - void copy(const ScaleWeightGroupInfo &other); - ScaleWeightGroupInfo* clone() const; + private: + bool isFuncationFormVar_; + size_t icentral; + size_t imuR1muF2; + size_t imuR1muF05; + size_t imuR2muF05; + size_t imuR2muF1; + size_t imuR2muF2; + size_t imuR05muF05; + size_t imuR05muF1; + size_t imuR05muF2; + public: + ScaleWeightGroupInfo() : ScaleWeightGroupInfo("") {} + ScaleWeightGroupInfo(std::string header, std::string name) : + WeightGroupInfo(header, name) { + weightType_ = kScaleWeights; + isFuncationFormVar_ = false; + icentral = 0; + imuR1muF2 = 0; + imuR1muF05 = 0; + imuR2muF05 = 0; + imuR2muF1 = 0; + imuR2muF2 = 0; + imuR2muF05 = 0; + imuR05muF05 = 0; + imuR05muF1 = 0; + imuR05muF2 = 0; + } + ScaleWeightGroupInfo(std::string header) : + ScaleWeightGroupInfo(header, header) { } + ScaleWeightGroupInfo(const ScaleWeightGroupInfo &other) { + copy(other); + } + virtual ~ScaleWeightGroupInfo() override {} + void copy(const ScaleWeightGroupInfo &other); + ScaleWeightGroupInfo* clone() const; - void setMuRMuFIndex(WeightMetaInfo info, float muR, float muF); - void addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF); + void setMuRMuFIndex(WeightMetaInfo info, float muR, float muF); + void addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF); - // Is a variation of the functional form of the dynamic scale - bool isFunctionalFormVariation(); - void setIsFunctionalFormVariation(bool functionalVar) {isFuncationFormVar_ = functionalVar; } - size_t centralIndex() {return icentral; } - size_t muR1muF2Index() { return imuR1muF2; } - size_t muR1muF05Index() { return imuR1muF05; } - size_t muR2muF05Index() { return imuR2muF05; } - size_t muR2muF1Index() { return imuR2muF1; } - size_t muR2muF2Index() { return imuR2muF2; } - size_t muR05muF05Index() { return imuR05muF05; } - size_t muR05muF1Index() { return imuR05muF1; } - size_t muR05muF2Index() { return imuR05muF2; } + // Is a variation of the functional form of the dynamic scale + bool isFunctionalFormVariation(); + void setIsFunctionalFormVariation(bool functionalVar) {isFuncationFormVar_ = functionalVar; } + size_t centralIndex() {return icentral; } + size_t muR1muF2Index() { return imuR1muF2; } + size_t muR1muF05Index() { return imuR1muF05; } + size_t muR2muF05Index() { return imuR2muF05; } + size_t muR2muF1Index() { return imuR2muF1; } + size_t muR2muF2Index() { return imuR2muF2; } + size_t muR05muF05Index() { return imuR05muF05; } + size_t muR05muF1Index() { return imuR05muF1; } + size_t muR05muF2Index() { return imuR05muF2; } }; } From 71629cd0b87c58911e047368aa45d2bd3393df06 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 28 Aug 2019 04:14:52 -0400 Subject: [PATCH 19/75] Read header info from headers in externalLHEProducer --- .../interface/LHEWeightGroupReaderHelper.h | 71 +++++++++++++++++-- .../plugins/ExternalLHEProducer.cc | 35 +++++---- 2 files changed, 85 insertions(+), 21 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index f669a3c6a6094..e6c8cf6a35bbe 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -10,18 +10,20 @@ #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" class LHEWeightGroupReaderHelper { public: LHEWeightGroupReaderHelper() : curWeight_(gen::kUnknownWeights) { - weightGroupStart_ = std::regex(".*.*"); - weightGroupEnd_ = std::regex(".*.*"); - weightContent_ = std::regex("\\s*(.+)"); + weightGroupStart_ = std::regex(".*.*\n*"); + weightGroupEnd_ = std::regex(".*.*\n*"); + weightContent_ = std::regex("\\s*(.+)\n*"); } //// possibly add more versions of this functions for different inputs void parseLHEFile(std::string filename); + void parseWeightGroupsFromHeader(std::vector lheHeader); edm::OwnVector getWeightGroups() {return weightGroups_;} @@ -62,15 +64,14 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { int index = 0; while(getline(file, line)) { if(std::regex_match(line, weightGroupStart_)) { - std::string groupLine = line; std::string name = getTagsMap(line, groupTags)["name"]; //TODO: Fine for now, but in general there should also be a check on the PDF weights, // e.g., it could be an unknown weight if(name == "Central scale variation") - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(groupLine)); + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(groupLine)); + weightGroups_.push_back(new gen::PdfWeightGroupInfo(line)); /// file weights while(getline(file, line) && !std::regex_match(line, weightGroupEnd_)) { @@ -97,6 +98,64 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { } } +void +LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { + //// may put in constructor, can have flag to specify these values + //// To make this class a little more flexible + std::vector weightGroup = {"name|type", "combine"}; + std::vector weightInfo = {"MUF", "id", "MUR", "PDF"}; + + std::regex groupTags = createRegexSearch(weightGroup); + std::regex infoTags = createRegexSearch(weightInfo); + /// end that comment + + + std::smatch matches; + // TODO: Not sure the weight indexing is right here, this seems to more or less + // count the lines which isn't quite the goal. TOCHECK! + int index = 0; + bool foundGroup = false; + for (std::string headerLine : lheHeader) { + std::cout << "Header line is:" << headerLine << std::endl; + //TODO: Fine for now, but in general there should also be a check on the PDF weights, + // e.g., it could be an unknown weight + std::cout << "weightGroupStart_ .*.* ... match? " << static_cast(std::regex_match(headerLine, weightGroupStart_)) << std::endl; + if (std::regex_match(headerLine, weightGroupStart_)) { + std::cout << "Adding new group for headerLine" << std::endl; + foundGroup = true; + std::string name = getTagsMap(headerLine, groupTags)["name"]; + + if(name == "Central scale variation") + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); + else + weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + } + /// file weights + else if (foundGroup && !std::regex_match(headerLine, weightGroupEnd_)) { + std::cout << "Adding new weight for headerLine" << std::endl; + auto tagsMap = getTagsMap(headerLine, infoTags); + std::regex_search(headerLine, matches, weightContent_); + // TODO: Add proper check that it worked + std::string content = matches[1].str(); + + auto& group = weightGroups_.back(); + if (group.weightType() == gen::kScaleWeights) { + float muR = std::stof(tagsMap["MUR"]); + float muF = std::stof(tagsMap["MUF"]); + auto& scaleGroup = static_cast(group); + scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); + } + else + group.addContainedId(index, tagsMap["id"], headerLine); + + index++; + } + else { + std::cout << " No match..." << std::endl; + foundGroup = false; + } + } +} std::map LHEWeightGroupReaderHelper::getTagsMap(std::string s, std::regex r) { diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 924d8f34ca40d..57ebfe6489c8e 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -354,21 +354,6 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) - std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); - //gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights(); - //edm::OwnVector pdfSets;// = getExamplePdfWeights(); - //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); - - // setup file reader - std::string LHEfilename ="cmsgrid_final.lhe"; - LHEWeightGroupReaderHelper reader; - reader.parseLHEFile(LHEfilename); - - for (auto pdfSet : reader.getWeightGroups()) - weightInfoProduct->addWeightGroupInfo(pdfSet); - weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); - run.put(std::move(weightInfoProduct)); - nextEvent(); if (runInfoLast) { runInfo = runInfoLast; @@ -389,6 +374,26 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) run.put(std::move(product)); + std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); + //gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights(); + //edm::OwnVector pdfSets;// = getExamplePdfWeights(); + //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); + + // setup file reader + std::string LHEfilename ="cmsgrid_final.lhe"; + LHEWeightGroupReaderHelper reader; + //reader.parseLHEFile(LHEfilename); + std::cout << "Trying to find header initrwgt. Size is "; + std::cout << runInfo->findHeader("initrwgt").size() << std::endl; + for (auto line : runInfo->findHeader("initrwgt")) + std::cout << "Line in header is " << line << std::endl; + reader.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); + + for (auto weightGroup : reader.getWeightGroups()) + weightInfoProduct->addWeightGroupInfo(weightGroup); + weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); + run.put(std::move(weightInfoProduct)); + runInfo.reset(); } } From c98a07826f18351a74c30e47c31e1f078e129487 Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Mon, 2 Sep 2019 08:11:03 -0400 Subject: [PATCH 20/75] added Regex helper class and put under (kinda silly) namespace --- .../interface/LHEWeightGroupReaderHelper.h | 393 ++++++++++++------ .../plugins/ExternalLHEProducer.cc | 175 ++++---- 2 files changed, 365 insertions(+), 203 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index 0a582a288a838..818e6d06f67b8 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -13,49 +13,232 @@ #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" -class LHEWeightGroupReaderHelper { -public: - LHEWeightGroupReaderHelper() { - weightGroupStart_ = std::regex(".*.*"); - weightGroupEnd_ = std::regex(".*.*"); - weightContent_ = std::regex("\\s*(.+)"); +namespace dylanTest { + class RegexCreater + { + public: + void addValue(std::string baseName, std::vector altNames={}, bool isInContent=false ); + bool processString(std::string); + std::map getTagMap() {return valueMap;} + + + private: + std::string tagRegString = "(?:)"; + std::string contentRegString = "(?:)"; + + std::vector tagNames; + std::vector contentNames; + + std::regex tagRegex; + std::regex contentRegex; + + std::map valueMap; + + std::string orStrings(std::string baseName, std::vector altNames); + void updateRegexSearchTag(std::string matchName); + void updateRegexSearchContent(std::string matchName); + + }; + + + + + class LHEWeightGroupReaderHelper { + public: + LHEWeightGroupReaderHelper(); + + //// possibly add more versions of this functions for different inputs + void parseLHEFile(std::string filename); + void parseWeightGroupsFromHeader(std::vector lheHeader); + + + edm::OwnVector getWeightGroups() {return weightGroups_;} + + private: + // functions + std::map getMap_testAll(std::string, std::vector); + + // Variables + edm::OwnVector weightGroups_; + std::regex weightGroupStart_; + std::regex weightGroupEnd_; + std::regex weightContent_; + std::regex scaleWeightMatch_; + + std::vector regexOptions; + RegexCreater weightGroupInfo; + }; +} + + + +void +dylanTest::RegexCreater::addValue(std::string baseName, std::vector altNames, bool isInContent) { + std::string nameListString = orStrings(baseName, altNames); + + if (isInContent) { + contentNames.push_back(baseName); + updateRegexSearchContent(nameListString); } + else { + tagNames.push_back(baseName); + updateRegexSearchTag(nameListString); + } +} - //// possibly add more versions of this functions for different inputs - void parseLHEFile(std::string filename); - void parseWeightGroupsFromHeader(std::vector lheHeader); +std::string +dylanTest::RegexCreater::orStrings(std::string baseName, std::vector altNames) { + for(auto name: altNames) { + baseName += "|" + name; + } + return baseName; +} +void +dylanTest::RegexCreater::updateRegexSearchTag(std::string matchName) { + tagRegString.pop_back(); // remove last ) + if(tagRegString.size() > 5) tagRegString += "|";//for fence post issue + + tagRegString += "\\s*(" + matchName + ")=\"([^\"]+)\")"; + // Last bit is to ignore case + tagRegex = std::regex(tagRegString, std::regex_constants::ECMAScript | std::regex_constants::icase ); +} - edm::OwnVector getWeightGroups() {return weightGroups_;} +void +dylanTest::RegexCreater::updateRegexSearchContent(std::string matchName) { + contentRegString.pop_back(); // remove last ) + if(contentRegString.size() > 5) contentRegString += "|"; //for fence post issue + contentRegString += "(" + matchName + ")\\s*=\\s*(\\S+))"; + // Last bit is to ignore case + contentRegex = std::regex(contentRegString, std::regex_constants::ECMAScript | std::regex_constants::icase ); +} -private: - // Functions - std::regex createRegexSearch(std::vector); - std::map getTagsMap(std::string, std::regex); +bool +dylanTest::RegexCreater::processString(std::string fullString) { + valueMap.clear(); + std::smatch m; + + std::string processStr = fullString; + while(std::regex_search(processStr, m, tagRegex)) { + for(int i = 1; i < m.length() - 1; i += 2) { + if(m[i] != "") { + valueMap[tagNames.at(i/2)] = m[i + 1]; + } + + } + processStr = m.suffix().str(); + } + + std::regex weightContent_ = std::regex("\\s*(.+)\\s*"); + std::regex_search(fullString, m, weightContent_); + processStr = m[1]; + while(std::regex_search(processStr, m, contentRegex)) { + for(int i = 1; i < m.length() - 1; i += 2) { + if(m[i] != "") { + valueMap[contentNames.at(i/2)] = m[i + 1]; + } + } + processStr = m.suffix().str(); + } + + return valueMap.size() == (contentNames.size() + tagNames.size()); +} + + - // Variables - edm::OwnVector weightGroups_; - std::regex weightGroupStart_; - std::regex weightGroupEnd_; - std::regex weightContent_; -}; + + + + +dylanTest::LHEWeightGroupReaderHelper::LHEWeightGroupReaderHelper() { + weightGroupStart_ = std::regex(".*.*\n*"); + weightGroupEnd_ = std::regex(".*.*\n*"); + weightContent_ = std::regex("\\s*(.+)\\s*\n*"); + scaleWeightMatch_ = std::regex(".*(Central scale variation|scale_variation).*\n?"); + + std::cout << "Init" << "\n"; + + /// Might change later, order matters and code doesn't pick choices + + // WZVBS_2017_weightInfo.txt : scale-sometimes + // WZVBS_private_weightInfo.txt : scale-sometimes + RegexCreater rc_scale_dyn_pdf; + rc_scale_dyn_pdf.addValue("muf"); + rc_scale_dyn_pdf.addValue("mur"); + rc_scale_dyn_pdf.addValue("id"); + rc_scale_dyn_pdf.addValue("dyn_scale"); + rc_scale_dyn_pdf.addValue("pdf"); + regexOptions.push_back(rc_scale_dyn_pdf); + + // WZVBS_private_weightInfo.txt : scale-sometimes / other + // WZVBS_2017_weightInfo.txt : scale-sometimes / other + // DrellYan_LO_MGMLMv242_2017_weightInfo.txt : all + RegexCreater rc_scale_pdf; + rc_scale_pdf.addValue("muf"); + rc_scale_pdf.addValue("mur"); + rc_scale_pdf.addValue("id"); + rc_scale_pdf.addValue("pdf"); + regexOptions.push_back(rc_scale_pdf); + + + RegexCreater rc_scale; + rc_scale.addValue("muf"); + rc_scale.addValue("mur"); + rc_scale.addValue("id"); + regexOptions.push_back(rc_scale); + + + // ZZTo4L_powheg_2016_weightInfo.txt : scale / missing pdf option though... + // DrellYan_NLO_MGFXFXv233_2016_weightInfo.txt : scale + // DrellYan_LO_MGMLMv233_2016_weightInfo.txt : scale + RegexCreater rc_scaleAlt; + rc_scaleAlt.addValue("muf", {"facscfact"}, true); + rc_scaleAlt.addValue("mur", {"renscfact"}, true); + rc_scaleAlt.addValue("id"); + regexOptions.push_back(rc_scaleAlt); + + + // ZZTo4L_powheg_2016_weightInfo.txt : other + // ZZTo4L_powheg_2017_weightInfo.txt : other + // DrellYan_NLO_MGFXFXv242_2017_weightInfo.txt : other + // DrellYan_NLO_MGFXFXv233_2016_weightInfo.txt : other + RegexCreater rc_pdfAlt; + rc_scaleAlt.addValue("pdf", {"pdf set", "lhapdf", "pdfset"}, true); + rc_scaleAlt.addValue("id"); + regexOptions.push_back(rc_pdfAlt); + + // DrellYan_LO_MGMLMv233_2016_weightInfo.txt : other + RegexCreater rc_idOnly; + rc_idOnly.addValue("id"); + regexOptions.push_back(rc_idOnly); + + weightGroupInfo.addValue("name", {"type"}); + weightGroupInfo.addValue("combine"); + + +} + +std::map +dylanTest::LHEWeightGroupReaderHelper::getMap_testAll(std::string line, std::vector options) { + for (size_t i = 0; i < options.size(); ++i) { + if(options[i].processString(line)) { + return options[i].getTagMap(); + } + } + ////// problem!!!! + std::cout << "problem!!" << "\n"; + return std::map(); +} + + + void -LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { +dylanTest::LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { std::ifstream file; file.open(filename); - //// may put in constructor, can have flag to specify these values - //// To make this class a little more flexible - std::vector weightGroup = {"name|type", "combine"}; - std::vector weightInfo = {"MUF", "id", "MUR", "PDF"}; - - std::regex groupTags = createRegexSearch(weightGroup); - std::regex infoTags = createRegexSearch(weightInfo); - /// end that comment - - std::string line; std::smatch matches; // TODO: Not sure the weight indexing is right here, this seems to more or less @@ -63,26 +246,32 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { int index = 0; while(getline(file, line)) { if(std::regex_match(line, weightGroupStart_)) { - std::string name = getTagsMap(line, groupTags)["name"]; + std::string name = getMap_testAll(line, {weightGroupInfo})["name"]; + + //TODO: Fine for now, but in general there should also be a check on the PDF weights, + // e.g., it could be an unknown weight + + if(std::regex_match(name, scaleWeightMatch_)) { + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); + std::cout << "scale weight" << "\n"; + } + - //TODO: Fine for now, but in general there should also be a check on the PDF weights, - // e.g., it could be an unknown weight - if(name == "Central scale variation") - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(line)); + weightGroups_.push_back(new gen::PdfWeightGroupInfo(line)); /// file weights while(getline(file, line) && !std::regex_match(line, weightGroupEnd_)) { - auto tagsMap = getTagsMap(line, infoTags); + auto tagsMap = getMap_testAll(line, regexOptions); + std::regex_search(line, matches, weightContent_); // TODO: Add proper check that it worked std::string content = matches[1].str(); auto& group = weightGroups_.back(); if (group.weightType() == gen::kScaleWeights) { - float muR = std::stof(tagsMap["MUR"]); - float muF = std::stof(tagsMap["MUF"]); + float muR = std::stof(tagsMap["mur"]); + float muF = std::stof(tagsMap["muf"]); auto& scaleGroup = static_cast(group); scaleGroup.addContainedId(index, tagsMap["id"], line, muR, muF); } @@ -96,97 +285,63 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { } void -LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { - //// may put in constructor, can have flag to specify these values - //// To make this class a little more flexible - std::vector weightGroup = {"name|type", "combine"}; - std::vector weightInfo = {"MUF", "id", "MUR", "PDF"}; - - std::regex groupTags = createRegexSearch(weightGroup); - std::regex infoTags = createRegexSearch(weightInfo); - /// end that comment - - +dylanTest::LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { std::smatch matches; // TODO: Not sure the weight indexing is right here, this seems to more or less // count the lines which isn't quite the goal. TOCHECK! int index = 0; bool foundGroup = false; for (std::string headerLine : lheHeader) { - std::cout << "Header line is:" << headerLine << std::endl; - //TODO: Fine for now, but in general there should also be a check on the PDF weights, - // e.g., it could be an unknown weight - std::cout << "weightGroupStart_ .*.* ... match? " << static_cast(std::regex_match(headerLine, weightGroupStart_)) << std::endl; - if (std::regex_match(headerLine, weightGroupStart_)) { - std::cout << "Adding new group for headerLine" << std::endl; - foundGroup = true; - std::string name = getTagsMap(headerLine, groupTags)["name"]; - - if(name == "Central scale variation") - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); - else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); - } - /// file weights - else if (foundGroup && !std::regex_match(headerLine, weightGroupEnd_)) { - std::cout << "Adding new weight for headerLine" << std::endl; - auto tagsMap = getTagsMap(headerLine, infoTags); - std::regex_search(headerLine, matches, weightContent_); - // TODO: Add proper check that it worked - std::string content = matches[1].str(); - - auto& group = weightGroups_.back(); - if (group.weightType() == gen::kScaleWeights) { - float muR = std::stof(tagsMap["MUR"]); - float muF = std::stof(tagsMap["MUF"]); - auto& scaleGroup = static_cast(group); - scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); - } - else - group.addContainedId(index, tagsMap["id"], headerLine); - - index++; - } - else { - std::cout << " No match..." << std::endl; - foundGroup = false; - } - } -} - -std::map -LHEWeightGroupReaderHelper::getTagsMap(std::string s, std::regex r) { - std::smatch m; - - std::map retMap; - while(std::regex_search(s, m, r)) { - for(int i = 1; i < m.length() - 1; i += 2) { - if(m[i] != "") { - retMap[m[i]] = m[i + 1]; + std::cout << "Header line is:" << headerLine; + //TODO: Fine for now, but in general there should also be a check on the PDF weights, + // e.g., it could be an unknown weight + std::cout << "weightGroupStart_ .*.* ... match? " << static_cast(std::regex_match(headerLine, weightGroupStart_)) << std::endl; + if (std::regex_match(headerLine, weightGroupStart_)) { + //std::cout << "Adding new group for headerLine" << std::endl; + foundGroup = true; + std::string name = getMap_testAll(headerLine, {weightGroupInfo})["name"]; + + if(std::regex_match(name, scaleWeightMatch_)) { + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); + std::cout << "scale weight" << "\n"; + } + + else + weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + } + /// file weights + else if (foundGroup && !std::regex_match(headerLine, weightGroupEnd_)) { + //std::cout << "Adding new weight for headerLine" << std::endl; + auto tagsMap = getMap_testAll(headerLine, regexOptions); + for(auto pair: tagsMap) { + std::cout << pair.first << ": " << pair.second << " | "; + } + std::cout << "\n"; + std::regex_search(headerLine, matches, weightContent_); + // TODO: Add proper check that it worked + std::string content = matches[1].str(); + // std::cout << content << "\n"; + + auto& group = weightGroups_.back(); + if (group.weightType() == gen::kScaleWeights) { + float muR = std::stof(tagsMap["mur"]); + float muF = std::stof(tagsMap["muf"]); + std::cout << tagsMap["id"] << " " << muR << " " << muF << " " << content << "\n"; + auto& scaleGroup = static_cast(group); + scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); } + else + group.addContainedId(index, tagsMap["id"], headerLine); + index++; + } + else { + foundGroup = false; } - s = m.suffix().str(); } - - return retMap; } -std::regex -LHEWeightGroupReaderHelper::createRegexSearch(std::vector names) { - std::string s = "(?:"; - size_t numNames = names.size(); - for(size_t i=0; i < numNames; ++i) { - s += "\\s*(" + names[i] + ")=\"([^\"]+)\""; - if(i != numNames - 1) { - s += "|"; - } - } - s += ")"; - - return std::regex(s); -} +#endif -#endif diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 57ebfe6489c8e..4eed2e0575ba7 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -296,108 +296,115 @@ void ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) { - // pass the number of events as previous to last argument - - std::ostringstream eventStream; - eventStream << nEvents_; - // args_.push_back(eventStream.str()); - args_.insert(args_.begin() + 1, eventStream.str()); + // pass the number of events as previous to last argument + std::ostringstream eventStream; + eventStream << nEvents_; + // args_.push_back(eventStream.str()); + args_.insert(args_.begin() + 1, eventStream.str()); - // pass the random number generator seed as last argument + // pass the random number generator seed as last argument - edm::Service rng; + edm::Service rng; - if ( ! rng.isAvailable()) { - throw cms::Exception("Configuration") - << "The ExternalLHEProducer module requires the RandomNumberGeneratorService\n" - "which is not present in the configuration file. You must add the service\n" - "in the configuration file if you want to run ExternalLHEProducer"; - } - std::ostringstream randomStream; - randomStream << rng->mySeed(); - // args_.push_back(randomStream.str()); - args_.insert(args_.begin() + 2, randomStream.str()); + if ( ! rng.isAvailable()) { + throw cms::Exception("Configuration") + << "The ExternalLHEProducer module requires the RandomNumberGeneratorService\n" + "which is not present in the configuration file. You must add the service\n" + "in the configuration file if you want to run ExternalLHEProducer"; + } + std::ostringstream randomStream; + randomStream << rng->mySeed(); + // args_.push_back(randomStream.str()); + args_.insert(args_.begin() + 2, randomStream.str()); - // args_.emplace_back(std::to_string(nThreads_)); - args_.insert(args_.begin() + 3, std::to_string(nThreads_)); + // args_.emplace_back(std::to_string(nThreads_)); + args_.insert(args_.begin() + 3, std::to_string(nThreads_)); - for ( unsigned int iArg = 0; iArg < args_.size() ; iArg++ ) { - LogDebug("LHEInputArgs") << "arg [" << iArg << "] = " << args_[iArg]; - } + for ( unsigned int iArg = 0; iArg < args_.size() ; iArg++ ) { + LogDebug("LHEInputArgs") << "arg [" << iArg << "] = " << args_[iArg]; + } - executeScript(); + executeScript(); - //fill LHEXMLProduct (streaming read directly into compressed buffer to save memory) - std::unique_ptr p(new LHEXMLStringProduct); - - //store the XML file only if explictly requested - if (storeXML_) { - std::ifstream instream(outputFile_); - if (!instream) { - throw cms::Exception("OutputOpenError") << "Unable to open script output file " << outputFile_ << "."; - } - instream.seekg (0, instream.end); - int insize = instream.tellg(); - instream.seekg (0, instream.beg); - p->fillCompressedContent(instream, 0.25*insize); - instream.close(); - } - run.put(std::move(p), "LHEScriptOutput"); + //fill LHEXMLProduct (streaming read directly into compressed buffer to save memory) + std::unique_ptr p(new LHEXMLStringProduct); + + //store the XML file only if explictly requested + if (storeXML_) { + std::ifstream instream(outputFile_); + if (!instream) { + throw cms::Exception("OutputOpenError") << "Unable to open script output file " << outputFile_ << "."; + } + instream.seekg (0, instream.end); + int insize = instream.tellg(); + instream.seekg (0, instream.beg); + p->fillCompressedContent(instream, 0.25*insize); + instream.close(); + } + run.put(std::move(p), "LHEScriptOutput"); - // LHE C++ classes translation - // (read back uncompressed file from disk in streaming mode again to save memory) + // LHE C++ classes translation + // (read back uncompressed file from disk in streaming mode again to save memory) - std::vector infiles(1, outputFile_); - unsigned int skip = 0; - reader_ = std::make_unique(infiles, skip); + std::vector infiles(1, outputFile_); + unsigned int skip = 0; + reader_ = std::make_unique(infiles, skip); + + nextEvent(); + if (runInfoLast) { + runInfo = runInfoLast; - - - nextEvent(); - if (runInfoLast) { - runInfo = runInfoLast; - - std::unique_ptr product(new LHERunInfoProduct(*runInfo->getHEPRUP())); - std::for_each(runInfo->getHeaders().begin(), - runInfo->getHeaders().end(), - boost::bind(&LHERunInfoProduct::addHeader, - product.get(), _1)); - std::for_each(runInfo->getComments().begin(), - runInfo->getComments().end(), - boost::bind(&LHERunInfoProduct::addComment, - product.get(), _1)); + std::unique_ptr product(new LHERunInfoProduct(*runInfo->getHEPRUP())); + std::for_each(runInfo->getHeaders().begin(), + runInfo->getHeaders().end(), + boost::bind(&LHERunInfoProduct::addHeader, + product.get(), _1)); + std::for_each(runInfo->getComments().begin(), + runInfo->getComments().end(), + boost::bind(&LHERunInfoProduct::addComment, + product.get(), _1)); - // keep a copy around in case of merging - runInfoProducts.push_back(new LHERunInfoProduct(*product)); - wasMerged = false; + // keep a copy around in case of merging + runInfoProducts.push_back(new LHERunInfoProduct(*product)); + wasMerged = false; - run.put(std::move(product)); + run.put(std::move(product)); - std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); - //gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights(); - //edm::OwnVector pdfSets;// = getExamplePdfWeights(); - //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); - - // setup file reader - std::string LHEfilename ="cmsgrid_final.lhe"; - LHEWeightGroupReaderHelper reader; - //reader.parseLHEFile(LHEfilename); - std::cout << "Trying to find header initrwgt. Size is "; - std::cout << runInfo->findHeader("initrwgt").size() << std::endl; - for (auto line : runInfo->findHeader("initrwgt")) - std::cout << "Line in header is " << line << std::endl; - reader.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); + std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); + //gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights(); + //edm::OwnVector pdfSets;// = getExamplePdfWeights(); + //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); + + // setup file reader + //std::string LHEfilename ="cmsgrid_final.lhe"; + // std::string LHEfilename = "DrellYan_LO_MGMLMv233_2016_weightInfo.txt"; + //std::string LHEfilename = "DrellYan_LO_MGMLMv242_2017_weightInfo.txt"; + // std::string LHEfilename = "DrellYan_NLO_MGFXFXv233_2016_weightInfo.txt"; + // std::string LHEfilename = "DrellYan_NLO_MGFXFXv242_2017_weightInfo.txt"; + // std::string LHEfilename = "WZVBS_2017_weightInfo.txt"; // **** + std::string LHEfilename = "WZVBS_private_weightInfo.txt"; + // std::string LHEfilename = "ZZTo4L_powheg_2016_weightInfo.txt"; + // std::string LHEfilename = "ZZTo4L_powheg_2017_weightInfo.txt"; + + dylanTest::LHEWeightGroupReaderHelper reader; + //reader.parseLHEFile(LHEfilename); + std::cout << "Trying to find header initrwgt. Size is "; + std::cout << runInfo->findHeader("initrwgt").size() << std::endl; + // for (auto line : runInfo->findHeader("initrwgt")) + // std::cout << "Line in header is " << line; + reader.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); - for (auto weightGroup : reader.getWeightGroups()) - weightInfoProduct->addWeightGroupInfo(weightGroup); - weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); - run.put(std::move(weightInfoProduct)); + for (auto weightGroup : reader.getWeightGroups()) + weightInfoProduct->addWeightGroupInfo(weightGroup); + weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); + run.put(std::move(weightInfoProduct)); - runInfo.reset(); - } + runInfo.reset(); + } } + // ------------ method called when ending the processing of a run ------------ void ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) From de0ad7a1663419e0512413ba85b040a22ee193a2 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 2 Sep 2019 09:07:18 -0400 Subject: [PATCH 21/75] Fix problem with instantiating Scale/PdfWeightInfo to file --- .../GeneratorProducts/interface/ScaleWeightGroupInfo.h | 2 +- SimDataFormats/GeneratorProducts/src/classes.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index 179b183c07fd9..30a92cede74ec 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -57,7 +57,7 @@ namespace gen { size_t muR05muF05Index() { return imuR05muF05_; } size_t muR05muF1Index() { return imuR05muF1_; } size_t muR05muF2Index() { return imuR05muF2_; } - }_; + }; } #endif diff --git a/SimDataFormats/GeneratorProducts/src/classes.h b/SimDataFormats/GeneratorProducts/src/classes.h index 266b790487bbe..9e5f0b86ac2af 100644 --- a/SimDataFormats/GeneratorProducts/src/classes.h +++ b/SimDataFormats/GeneratorProducts/src/classes.h @@ -9,6 +9,8 @@ #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" From 59691bc6a647eef22e57ed248fa4d9a0d9520a8a Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Tue, 3 Sep 2019 09:23:07 -0400 Subject: [PATCH 22/75] Add an alternative sample for testing --- .../LHEInterface/plugins/ExternalLHEProducer.cc | 6 +----- GeneratorInterface/LHEInterface/test/test_Weights_cfg.py | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 57ebfe6489c8e..17ab2045a7822 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -380,13 +380,9 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); // setup file reader - std::string LHEfilename ="cmsgrid_final.lhe"; LHEWeightGroupReaderHelper reader; + //std::string LHEfilename ="cmsgrid_final.lhe"; //reader.parseLHEFile(LHEfilename); - std::cout << "Trying to find header initrwgt. Size is "; - std::cout << runInfo->findHeader("initrwgt").size() << std::endl; - for (auto line : runInfo->findHeader("initrwgt")) - std::cout << "Line in header is " << line << std::endl; reader.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); for (auto weightGroup : reader.getWeightGroups()) diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py index aeb7882932c6e..fe898901ed4aa 100644 --- a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -59,7 +59,8 @@ process.GlobalTag = GlobalTag(process.GlobalTag, '102X_upgrade2018_realistic_v11', '') process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", - args = cms.vstring('/afs/hep.wisc.edu/home/kdlong/public/DarkMatter_MonoZPrime_V_Mx50_Mv500_gDMgQ1_LO_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + #args = cms.vstring('/afs/hep.wisc.edu/home/kdlong/public/DarkMatter_MonoZPrime_V_Mx50_Mv500_gDMgQ1_LO_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_slc6_amd64_gcc630_CMSSW_9_3_0_ZZTo4L2017_pdf306000.tgz'), nEvents = cms.untracked.uint32(10), numberOfParameters = cms.uint32(1), outputFile = cms.string('cmsgrid_final.lhe'), From 1c1da7637d6c910ab5b99eca20a2a59e42a030c8 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Tue, 3 Sep 2019 16:14:28 -0400 Subject: [PATCH 23/75] Slight cleanup to naming and weightgroup type --- .../interface/LHEWeightGroupReaderHelper.h | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index e6c8cf6a35bbe..77881fe323c29 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -65,11 +65,14 @@ LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { while(getline(file, line)) { if(std::regex_match(line, weightGroupStart_)) { std::string name = getTagsMap(line, groupTags)["name"]; + std::cout << "Name is " << name << std::endl; //TODO: Fine for now, but in general there should also be a check on the PDF weights, // e.g., it could be an unknown weight - if(name == "Central scale variation") + if(name.find("scale") != std::string::npos) { + std::cout << "Yes, it's a scale variation!" << std::endl; weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); + } else weightGroups_.push_back(new gen::PdfWeightGroupInfo(line)); @@ -125,10 +128,16 @@ LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector foundGroup = true; std::string name = getTagsMap(headerLine, groupTags)["name"]; - if(name == "Central scale variation") - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); + std::cout << "Name is " << name << std::endl; + + //TODO: Fine for now, but in general there should also be a check on the PDF weights, + // e.g., it could be an unknown weight + if(name.find("scale") != std::string::npos) { + std::cout << "Yes, it's a scale variation!" << std::endl; + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(name)); + } else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + weightGroups_.push_back(new gen::PdfWeightGroupInfo(name)); } /// file weights else if (foundGroup && !std::regex_match(headerLine, weightGroupEnd_)) { @@ -140,8 +149,8 @@ LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector auto& group = weightGroups_.back(); if (group.weightType() == gen::kScaleWeights) { - float muR = std::stof(tagsMap["MUR"]); - float muF = std::stof(tagsMap["MUF"]); + float muR = (!tagsMap["MUR"].empty() && std::isdigit(tagsMap["MUR"][0])) ? std::stof(tagsMap["MUR"]) : 1; + float muF = (!tagsMap["MUF"].empty() && std::isdigit(tagsMap["MUF"][0])) ? std::stof(tagsMap["MUF"]) : 1; auto& scaleGroup = static_cast(group); scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); } From 80cde77e1e419d54a1ec19c5f7bdc91b070a010f Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Wed, 4 Sep 2019 04:25:41 -0400 Subject: [PATCH 24/75] Fixed small error in names of RegexCreater, should run on new gridp Need to look into more flexible implimentation/more error detection --- .../LHEInterface/interface/LHEWeightGroupReaderHelper.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index 818e6d06f67b8..f88dcba93d273 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -204,8 +204,8 @@ dylanTest::LHEWeightGroupReaderHelper::LHEWeightGroupReaderHelper() { // DrellYan_NLO_MGFXFXv242_2017_weightInfo.txt : other // DrellYan_NLO_MGFXFXv233_2016_weightInfo.txt : other RegexCreater rc_pdfAlt; - rc_scaleAlt.addValue("pdf", {"pdf set", "lhapdf", "pdfset"}, true); - rc_scaleAlt.addValue("id"); + rc_pdfAlt.addValue("pdf", {"pdf set", "lhapdf", "pdfset"}, true); + rc_pdfAlt.addValue("id"); regexOptions.push_back(rc_pdfAlt); // DrellYan_LO_MGMLMv233_2016_weightInfo.txt : other @@ -232,8 +232,6 @@ dylanTest::LHEWeightGroupReaderHelper::getMap_testAll(std::string line, std::vec } - - void dylanTest::LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { std::ifstream file; @@ -295,7 +293,7 @@ dylanTest::LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector.* ... match? " << static_cast(std::regex_match(headerLine, weightGroupStart_)) << std::endl; + //std::cout << "weightGroupStart_ .*.* ... match? " << static_cast(std::regex_match(headerLine, weightGroupStart_)) << std::endl; if (std::regex_match(headerLine, weightGroupStart_)) { //std::cout << "Adding new group for headerLine" << std::endl; foundGroup = true; From 33e246685138ddac48d2c72588aa2c82662a941f Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 4 Sep 2019 09:00:10 -0400 Subject: [PATCH 25/75] Remove bloated comments --- .../interface/LHEWeightGroupReaderHelper.h | 14 -------------- .../LHEInterface/plugins/ExternalLHEProducer.cc | 6 +----- .../LHEInterface/test/test_Weights_cfg.py | 3 ++- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index f88dcba93d273..026cbb4a5dd53 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -157,8 +157,6 @@ dylanTest::LHEWeightGroupReaderHelper::LHEWeightGroupReaderHelper() { weightContent_ = std::regex("\\s*(.+)\\s*\n*"); scaleWeightMatch_ = std::regex(".*(Central scale variation|scale_variation).*\n?"); - std::cout << "Init" << "\n"; - /// Might change later, order matters and code doesn't pick choices // WZVBS_2017_weightInfo.txt : scale-sometimes @@ -251,7 +249,6 @@ dylanTest::LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { if(std::regex_match(name, scaleWeightMatch_)) { weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); - std::cout << "scale weight" << "\n"; } @@ -290,18 +287,14 @@ dylanTest::LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector.* ... match? " << static_cast(std::regex_match(headerLine, weightGroupStart_)) << std::endl; if (std::regex_match(headerLine, weightGroupStart_)) { - //std::cout << "Adding new group for headerLine" << std::endl; foundGroup = true; std::string name = getMap_testAll(headerLine, {weightGroupInfo})["name"]; if(std::regex_match(name, scaleWeightMatch_)) { weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); - std::cout << "scale weight" << "\n"; } else @@ -309,22 +302,15 @@ dylanTest::LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector(group); scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); } diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 4eed2e0575ba7..4e3de6b64806a 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -386,13 +386,9 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) std::string LHEfilename = "WZVBS_private_weightInfo.txt"; // std::string LHEfilename = "ZZTo4L_powheg_2016_weightInfo.txt"; // std::string LHEfilename = "ZZTo4L_powheg_2017_weightInfo.txt"; - dylanTest::LHEWeightGroupReaderHelper reader; + //reader.parseLHEFile(LHEfilename); - std::cout << "Trying to find header initrwgt. Size is "; - std::cout << runInfo->findHeader("initrwgt").size() << std::endl; - // for (auto line : runInfo->findHeader("initrwgt")) - // std::cout << "Line in header is " << line; reader.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); for (auto weightGroup : reader.getWeightGroups()) diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py index fe898901ed4aa..a4b15881e73c6 100644 --- a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -60,7 +60,8 @@ process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", #args = cms.vstring('/afs/hep.wisc.edu/home/kdlong/public/DarkMatter_MonoZPrime_V_Mx50_Mv500_gDMgQ1_LO_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), - args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_slc6_amd64_gcc630_CMSSW_9_3_0_ZZTo4L2017_pdf306000.tgz'), + #args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_slc6_amd64_gcc630_CMSSW_9_3_0_ZZTo4L2017_pdf306000Dummy.tgz'), + args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_4L_NNPDF30_13TeV_tarballDummy.tar.gz'), nEvents = cms.untracked.uint32(10), numberOfParameters = cms.uint32(1), outputFile = cms.string('cmsgrid_final.lhe'), From 9baeee20d3686431d22a290965c55a95fcfbda87 Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Fri, 6 Sep 2019 09:26:24 -0400 Subject: [PATCH 26/75] overhaul of code: now works with tinyxml2 instead of regex --- GeneratorInterface/LHEInterface/BuildFile.xml | 1 + .../interface/LHEWeightGroupReaderHelper.h | 480 ++++++++---------- .../plugins/ExternalLHEProducer.cc | 18 +- 3 files changed, 221 insertions(+), 278 deletions(-) diff --git a/GeneratorInterface/LHEInterface/BuildFile.xml b/GeneratorInterface/LHEInterface/BuildFile.xml index 7ee840b3ea784..3c5338daa6d97 100644 --- a/GeneratorInterface/LHEInterface/BuildFile.xml +++ b/GeneratorInterface/LHEInterface/BuildFile.xml @@ -13,6 +13,7 @@ + diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index f88dcba93d273..38315664782aa 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -12,328 +12,284 @@ #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include +using namespace tinyxml2; -namespace dylanTest { - class RegexCreater - { - public: - void addValue(std::string baseName, std::vector altNames={}, bool isInContent=false ); - bool processString(std::string); - std::map getTagMap() {return valueMap;} - - private: - std::string tagRegString = "(?:)"; - std::string contentRegString = "(?:)"; - - std::vector tagNames; - std::vector contentNames; - - std::regex tagRegex; - std::regex contentRegex; +class LHEWeightGroupReaderHelper { +public: + LHEWeightGroupReaderHelper(); - std::map valueMap; - - std::string orStrings(std::string baseName, std::vector altNames); - void updateRegexSearchTag(std::string matchName); - void updateRegexSearchContent(std::string matchName); - - }; + //// possibly add more versions of this functions for different inputs + void parseLHEFile(std::string filename); + void parseWeightGroupsFromHeader(std::vector lheHeader); + edm::OwnVector getWeightGroups() {return weightGroups_;} +private: + void loadAttributeNames(std::string baseName, std::vector altNames ={}); + std::string toLowerCase(const char*); + std::string toLowerCase(const std::string); + std::map getAttributeMap(std::string); + std::string sanitizeText(std::string); + bool isAWeight(std::string); - - class LHEWeightGroupReaderHelper { - public: - LHEWeightGroupReaderHelper(); - - //// possibly add more versions of this functions for different inputs - void parseLHEFile(std::string filename); - void parseWeightGroupsFromHeader(std::vector lheHeader); - - - edm::OwnVector getWeightGroups() {return weightGroups_;} + // Variables + edm::OwnVector weightGroups_; + std::regex weightGroupStart_; + std::regex weightGroupEnd_; + std::regex weightContent_; - private: - // functions - std::map getMap_testAll(std::string, std::vector); - - // Variables - edm::OwnVector weightGroups_; - std::regex weightGroupStart_; - std::regex weightGroupEnd_; - std::regex weightContent_; - std::regex scaleWeightMatch_; - - std::vector regexOptions; - RegexCreater weightGroupInfo; - }; -} - + std::map nameConvMap; +}; -void -dylanTest::RegexCreater::addValue(std::string baseName, std::vector altNames, bool isInContent) { - std::string nameListString = orStrings(baseName, altNames); - - if (isInContent) { - contentNames.push_back(baseName); - updateRegexSearchContent(nameListString); - } - else { - tagNames.push_back(baseName); - updateRegexSearchTag(nameListString); - } -} - std::string -dylanTest::RegexCreater::orStrings(std::string baseName, std::vector altNames) { - for(auto name: altNames) { - baseName += "|" + name; - } - return baseName; +LHEWeightGroupReaderHelper::toLowerCase(const char* name) { + std::string returnStr; + for (size_t i = 0; i < strlen(name); ++i) + returnStr.push_back(tolower(name[i])); + return returnStr; } -void -dylanTest::RegexCreater::updateRegexSearchTag(std::string matchName) { - tagRegString.pop_back(); // remove last ) - if(tagRegString.size() > 5) tagRegString += "|";//for fence post issue - - tagRegString += "\\s*(" + matchName + ")=\"([^\"]+)\")"; - // Last bit is to ignore case - tagRegex = std::regex(tagRegString, std::regex_constants::ECMAScript | std::regex_constants::icase ); -} +std::string +LHEWeightGroupReaderHelper::toLowerCase(const std::string name) { + std::string returnStr = name; + transform(name.begin(), name.end(), returnStr.begin(), ::tolower); + return returnStr; -void -dylanTest::RegexCreater::updateRegexSearchContent(std::string matchName) { - contentRegString.pop_back(); // remove last ) - if(contentRegString.size() > 5) contentRegString += "|"; //for fence post issue - contentRegString += "(" + matchName + ")\\s*=\\s*(\\S+))"; - // Last bit is to ignore case - contentRegex = std::regex(contentRegString, std::regex_constants::ECMAScript | std::regex_constants::icase ); -} -bool -dylanTest::RegexCreater::processString(std::string fullString) { - valueMap.clear(); - std::smatch m; - - std::string processStr = fullString; - while(std::regex_search(processStr, m, tagRegex)) { - for(int i = 1; i < m.length() - 1; i += 2) { - if(m[i] != "") { - valueMap[tagNames.at(i/2)] = m[i + 1]; - } +} - } - processStr = m.suffix().str(); +void LHEWeightGroupReaderHelper::loadAttributeNames(std::string baseName, std::vector altNames) { + for(auto altname : altNames) { + nameConvMap[altname] = baseName; } + nameConvMap[baseName] = baseName; +} - std::regex weightContent_ = std::regex("\\s*(.+)\\s*"); - std::regex_search(fullString, m, weightContent_); - processStr = m[1]; - while(std::regex_search(processStr, m, contentRegex)) { - for(int i = 1; i < m.length() - 1; i += 2) { - if(m[i] != "") { - valueMap[contentNames.at(i/2)] = m[i + 1]; - } +std::string +LHEWeightGroupReaderHelper::sanitizeText(std::string line) { + std::map replaceMap = {{"<", "<"}, {">", ">"}}; + + for(auto pair: replaceMap) { + std::string badText = pair.first; + std::string goodText = pair.second; + while(line.find(badText) != std::string::npos) { + size_t spot = line.find(badText); + line.replace(spot, badText.size(), goodText); } - processStr = m.suffix().str(); } - - return valueMap.size() == (contentNames.size() + tagNames.size()); + return line; } - - - - - - -dylanTest::LHEWeightGroupReaderHelper::LHEWeightGroupReaderHelper() { +LHEWeightGroupReaderHelper::LHEWeightGroupReaderHelper() { weightGroupStart_ = std::regex(".*.*\n*"); weightGroupEnd_ = std::regex(".*.*\n*"); - weightContent_ = std::regex("\\s*(.+)\\s*\n*"); - scaleWeightMatch_ = std::regex(".*(Central scale variation|scale_variation).*\n?"); - + std::cout << "Init" << "\n"; /// Might change later, order matters and code doesn't pick choices - // WZVBS_2017_weightInfo.txt : scale-sometimes - // WZVBS_private_weightInfo.txt : scale-sometimes - RegexCreater rc_scale_dyn_pdf; - rc_scale_dyn_pdf.addValue("muf"); - rc_scale_dyn_pdf.addValue("mur"); - rc_scale_dyn_pdf.addValue("id"); - rc_scale_dyn_pdf.addValue("dyn_scale"); - rc_scale_dyn_pdf.addValue("pdf"); - regexOptions.push_back(rc_scale_dyn_pdf); - - // WZVBS_private_weightInfo.txt : scale-sometimes / other - // WZVBS_2017_weightInfo.txt : scale-sometimes / other - // DrellYan_LO_MGMLMv242_2017_weightInfo.txt : all - RegexCreater rc_scale_pdf; - rc_scale_pdf.addValue("muf"); - rc_scale_pdf.addValue("mur"); - rc_scale_pdf.addValue("id"); - rc_scale_pdf.addValue("pdf"); - regexOptions.push_back(rc_scale_pdf); - - - RegexCreater rc_scale; - rc_scale.addValue("muf"); - rc_scale.addValue("mur"); - rc_scale.addValue("id"); - regexOptions.push_back(rc_scale); - - - // ZZTo4L_powheg_2016_weightInfo.txt : scale / missing pdf option though... - // DrellYan_NLO_MGFXFXv233_2016_weightInfo.txt : scale - // DrellYan_LO_MGMLMv233_2016_weightInfo.txt : scale - RegexCreater rc_scaleAlt; - rc_scaleAlt.addValue("muf", {"facscfact"}, true); - rc_scaleAlt.addValue("mur", {"renscfact"}, true); - rc_scaleAlt.addValue("id"); - regexOptions.push_back(rc_scaleAlt); - - - // ZZTo4L_powheg_2016_weightInfo.txt : other - // ZZTo4L_powheg_2017_weightInfo.txt : other - // DrellYan_NLO_MGFXFXv242_2017_weightInfo.txt : other - // DrellYan_NLO_MGFXFXv233_2016_weightInfo.txt : other - RegexCreater rc_pdfAlt; - rc_pdfAlt.addValue("pdf", {"pdf set", "lhapdf", "pdfset"}, true); - rc_pdfAlt.addValue("id"); - regexOptions.push_back(rc_pdfAlt); - - // DrellYan_LO_MGMLMv233_2016_weightInfo.txt : other - RegexCreater rc_idOnly; - rc_idOnly.addValue("id"); - regexOptions.push_back(rc_idOnly); - - weightGroupInfo.addValue("name", {"type"}); - weightGroupInfo.addValue("combine"); + // Used for translating different naming convention to a common one + loadAttributeNames("muf", {"facscfact"}); + loadAttributeNames("mur", {"renscfact"}); + loadAttributeNames("id"); + loadAttributeNames("pdf", {"pdf set", "lhapdf", "pdfset"}); + loadAttributeNames("dyn_scale"); + loadAttributeNames("combine"); + loadAttributeNames("name", {"type"}); } -std::map -dylanTest::LHEWeightGroupReaderHelper::getMap_testAll(std::string line, std::vector options) { - for (size_t i = 0; i < options.size(); ++i) { - if(options[i].processString(line)) { - return options[i].getTagMap(); +std::map +LHEWeightGroupReaderHelper::getAttributeMap(std::string line) { + XMLDocument xmlParser; + int error = xmlParser.Parse(line.c_str()); + if (error) { + std::cout << "we have a problem!" << "\n"; + return std::map(); + //do something.... + } + + std::map attMap; + XMLElement* element = xmlParser.FirstChildElement(); + + for( const XMLAttribute* a = element->FirstAttribute(); a; a=a->Next()) { + attMap[nameConvMap[toLowerCase(a->Name())]] = a->Value(); + } + // get stuff from content of tag if it has anything. + // always assume format is AAAAA=( )BBBB ( ) => optional space + if (element->GetText() == nullptr) { + return attMap; + } + // This adds "content: " to the beginning of the content. not sure if its a big deal or? + std::string content = element->GetText(); + attMap["content"] = content; + + std::regex reg("(?:(\\S+)=\\s*(\\S+))"); + std::smatch m; + while(std::regex_search(content, m, reg)) { + std::string key = nameConvMap[toLowerCase(m.str(1))]; + if (attMap[key] != std::string()) { + if (m[2] != attMap[key]) { + std::cout << m.str(2) << " vs " << attMap[key]; + // might do something if content and attribute don't match? + // but need to be careful since some are purposefully different + // eg dyn_scale is described in content but just given a number + } + } + else { + attMap[key] = m.str(2); } + content = m.suffix().str(); } - ////// problem!!!! - std::cout << "problem!!" << "\n"; - return std::map(); + return attMap; + } +bool +LHEWeightGroupReaderHelper::isAWeight(std::string line) { + XMLDocument xmlParser; + int error = xmlParser.Parse(line.c_str()); + if (error) { + return false; + //do something.... + } + XMLElement* element = xmlParser.FirstChildElement(); + return element; +} -void -dylanTest::LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { - std::ifstream file; - file.open(filename); - - std::string line; - std::smatch matches; - // TODO: Not sure the weight indexing is right here, this seems to more or less - // count the lines which isn't quite the goal. TOCHECK! - int index = 0; - while(getline(file, line)) { - if(std::regex_match(line, weightGroupStart_)) { - std::string name = getMap_testAll(line, {weightGroupInfo})["name"]; +// void +// LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { +// std::ifstream file; +// file.open(filename); + +// std::string line; +// std::smatch matches; +// // TODO: Not sure the weight indexing is right here, this seems to more or less +// // count the lines which isn't quite the goal. TOCHECK! +// int index = 0; +// while(getline(file, line)) { +// if(std::regex_match(line, weightGroupStart_)) { +// std::string name = getMap_testAll(line, {weightGroupInfo})["name"]; - //TODO: Fine for now, but in general there should also be a check on the PDF weights, - // e.g., it could be an unknown weight - - if(std::regex_match(name, scaleWeightMatch_)) { - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); - std::cout << "scale weight" << "\n"; - } +// //TODO: Fine for now, but in general there should also be a check on the PDF weights, +// // e.g., it could be an unknown weight + +// if(std::regex_match(name, scaleWeightMatch_)) { +// weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); +// std::cout << "scale weight" << "\n"; +// } - else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(line)); +// else +// weightGroups_.push_back(new gen::PdfWeightGroupInfo(line)); - /// file weights - while(getline(file, line) && !std::regex_match(line, weightGroupEnd_)) { - auto tagsMap = getMap_testAll(line, regexOptions); +// /// file weights +// while(getline(file, line) && !std::regex_match(line, weightGroupEnd_)) { +// auto tagsMap = getMap_testAll(line, regexOptions); - std::regex_search(line, matches, weightContent_); - // TODO: Add proper check that it worked - std::string content = matches[1].str(); - - auto& group = weightGroups_.back(); - if (group.weightType() == gen::kScaleWeights) { - float muR = std::stof(tagsMap["mur"]); - float muF = std::stof(tagsMap["muf"]); - auto& scaleGroup = static_cast(group); - scaleGroup.addContainedId(index, tagsMap["id"], line, muR, muF); - } - else - group.addContainedId(index, tagsMap["id"], line); - - index++; - } - } - } -} +// std::regex_search(line, matches, weightContent_); +// // TODO: Add proper check that it worked +// std::string content = matches[1].str(); + +// auto& group = weightGroups_.back(); +// if (group.weightType() == gen::kScaleWeights) { +// float muR = std::stof(tagsMap["mur"]); +// float muF = std::stof(tagsMap["muf"]); +// auto& scaleGroup = static_cast(group); +// scaleGroup.addContainedId(index, tagsMap["id"], line, muR, muF); +// } +// else +// group.addContainedId(index, tagsMap["id"], line); + +// index++; +// } +// } +// } +// } void -dylanTest::LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { - std::smatch matches; +LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { // TODO: Not sure the weight indexing is right here, this seems to more or less // count the lines which isn't quite the goal. TOCHECK! int index = 0; bool foundGroup = false; + for (std::string headerLine : lheHeader) { std::cout << "Header line is:" << headerLine; + headerLine = sanitizeText(headerLine); + std::cout << "Header line is:" << weightGroups_.size() << " "<< headerLine; //TODO: Fine for now, but in general there should also be a check on the PDF weights, - // e.g., it could be an unknown weight - //std::cout << "weightGroupStart_ .*.* ... match? " << static_cast(std::regex_match(headerLine, weightGroupStart_)) << std::endl; - if (std::regex_match(headerLine, weightGroupStart_)) { - //std::cout << "Adding new group for headerLine" << std::endl; - foundGroup = true; - std::string name = getMap_testAll(headerLine, {weightGroupInfo})["name"]; + // e.g., it could be an unknown weight + + if (std::regex_match(headerLine, weightGroupStart_)) { + //std::cout << "Adding new group for headerLine" << std::endl; + foundGroup = true; + std::string fullTag = headerLine + ""; + auto groupMap = getAttributeMap(fullTag); + std::string name = groupMap["name"]; - if(std::regex_match(name, scaleWeightMatch_)) { - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); - std::cout << "scale weight" << "\n"; - } - + if(name.find("Central scale variation") != std::string::npos || + name.find("scale_variation") != std::string::npos) { + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); + std::cout << "scale weight" << "\n"; + } else weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); - } - /// file weights - else if (foundGroup && !std::regex_match(headerLine, weightGroupEnd_)) { - //std::cout << "Adding new weight for headerLine" << std::endl; - auto tagsMap = getMap_testAll(headerLine, regexOptions); + } + /// file weights + else if (foundGroup && isAWeight(headerLine)) { + //std::cout << "Adding new weight for headerLine" << std::endl; + auto tagsMap = getAttributeMap(headerLine); for(auto pair: tagsMap) { std::cout << pair.first << ": " << pair.second << " | "; } - std::cout << "\n"; - std::regex_search(headerLine, matches, weightContent_); - // TODO: Add proper check that it worked - std::string content = matches[1].str(); - // std::cout << content << "\n"; - - auto& group = weightGroups_.back(); - if (group.weightType() == gen::kScaleWeights) { - float muR = std::stof(tagsMap["mur"]); - float muF = std::stof(tagsMap["muf"]); - std::cout << tagsMap["id"] << " " << muR << " " << muF << " " << content << "\n"; - auto& scaleGroup = static_cast(group); + std::cout << "\n"; + + std::string content = tagsMap["content"]; + if (tagsMap["id"] == std::string()) { + std::cout << "error" << "\n"; + // should do something + } + + auto& group = weightGroups_.back(); + if (group.weightType() == gen::kScaleWeights) { + if (tagsMap["mur"] == std::string() || tagsMap["muf"] == std::string()) { + std::cout << "error" << "\n"; + // something should happen here + continue; + } + float muR = std::stof(tagsMap["mur"]); + float muF = std::stof(tagsMap["muf"]); + std::cout << tagsMap["id"] << " " << muR << " " << muF << " " << content << "\n"; + auto& scaleGroup = static_cast(group); scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); - } - else - group.addContainedId(index, tagsMap["id"], headerLine); - index++; + } + else + group.addContainedId(index, tagsMap["id"], headerLine); + index++; } - else { + // commented out since code doesn't work with this in.... + // else if(isAWeight(headerLine)) { + // // found header. Don't know what to do with it so just shove it into a new weightgroup for now + // // do minimum work for it + // weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + // auto& group = weightGroups_.back(); + // auto tagsMap = getAttributeMap(headerLine); + // group.addContainedId(index, tagsMap["id"], headerLine); + // foundGroup = true; + // index++; + // } + + else if(std::regex_match(headerLine, weightGroupEnd_)) { foundGroup = false; + } + else { + std::cout << "problem!!!" << "\n"; } } } diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 4eed2e0575ba7..9d8621fc3c216 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -372,22 +372,8 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) run.put(std::move(product)); std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); - //gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights(); - //edm::OwnVector pdfSets;// = getExamplePdfWeights(); - //gen::WeightGroupInfo scaleInfo = getExampleScaleWeightsOutOfOrder(); - - // setup file reader - //std::string LHEfilename ="cmsgrid_final.lhe"; - // std::string LHEfilename = "DrellYan_LO_MGMLMv233_2016_weightInfo.txt"; - //std::string LHEfilename = "DrellYan_LO_MGMLMv242_2017_weightInfo.txt"; - // std::string LHEfilename = "DrellYan_NLO_MGFXFXv233_2016_weightInfo.txt"; - // std::string LHEfilename = "DrellYan_NLO_MGFXFXv242_2017_weightInfo.txt"; - // std::string LHEfilename = "WZVBS_2017_weightInfo.txt"; // **** - std::string LHEfilename = "WZVBS_private_weightInfo.txt"; - // std::string LHEfilename = "ZZTo4L_powheg_2016_weightInfo.txt"; - // std::string LHEfilename = "ZZTo4L_powheg_2017_weightInfo.txt"; - - dylanTest::LHEWeightGroupReaderHelper reader; + + LHEWeightGroupReaderHelper reader; //reader.parseLHEFile(LHEfilename); std::cout << "Trying to find header initrwgt. Size is "; std::cout << runInfo->findHeader("initrwgt").size() << std::endl; From 1038e0df4d60d1679b531d77e3c243e0e4253987 Mon Sep 17 00:00:00 2001 From: Dylan Teague Date: Fri, 6 Sep 2019 09:29:02 -0400 Subject: [PATCH 27/75] testing helper stuff as comments --- .../LHEInterface/test/test_Weights_cfg.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py index aeb7882932c6e..bef001d3972f3 100644 --- a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -59,13 +59,19 @@ process.GlobalTag = GlobalTag(process.GlobalTag, '102X_upgrade2018_realistic_v11', '') process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", - args = cms.vstring('/afs/hep.wisc.edu/home/kdlong/public/DarkMatter_MonoZPrime_V_Mx50_Mv500_gDMgQ1_LO_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), - nEvents = cms.untracked.uint32(10), + args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/WLLJJ_WToLNu_EWK_4F_MLL-60_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + nEvents = cms.untracked.uint32(10), numberOfParameters = cms.uint32(1), outputFile = cms.string('cmsgrid_final.lhe'), scriptName = cms.FileInPath('GeneratorInterface/LHEInterface/data/run_generic_tarball_cvmfs.sh') ) +# args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/DarkMatter_MonoZPrime_V_Mx50_Mv500_gDMgQ1_LO_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), +# args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/WLLJJ_WToLNu_EWK_4F_MLL-60_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), +# args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_4L_NNPDF30_13TeV_tarballDummy.tar.gz'), +# args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_slc6_amd64_gcc630_CMSSW_9_3_0_ZZTo4L2017_pdf306000Dummy.tgz'), + + # Path and EndPath definitions process.lhe_step = cms.Path(process.externalLHEProducer) @@ -78,6 +84,8 @@ associatePatAlgosToolsTask(process) + + # Customisation from command line # Add early deletion of temporary data products to reduce peak memory need From f1a3ae406e49d6c904e27d83efa3050452aeb96b Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 11 Sep 2019 08:53:53 -0400 Subject: [PATCH 28/75] A bit of cleanup --- .../interface/LHEWeightGroupReaderHelper.h | 122 ++++++------------ .../LHEInterface/test/test_Weights_cfg.py | 3 +- 2 files changed, 38 insertions(+), 87 deletions(-) diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h index 38315664782aa..893c528e20379 100644 --- a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h +++ b/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h @@ -155,63 +155,13 @@ LHEWeightGroupReaderHelper::isAWeight(std::string line) { XMLDocument xmlParser; int error = xmlParser.Parse(line.c_str()); if (error) { - return false; - //do something.... + return false; + //do something.... } XMLElement* element = xmlParser.FirstChildElement(); return element; } -// void -// LHEWeightGroupReaderHelper::parseLHEFile(std::string filename) { -// std::ifstream file; -// file.open(filename); - -// std::string line; -// std::smatch matches; -// // TODO: Not sure the weight indexing is right here, this seems to more or less -// // count the lines which isn't quite the goal. TOCHECK! -// int index = 0; -// while(getline(file, line)) { -// if(std::regex_match(line, weightGroupStart_)) { -// std::string name = getMap_testAll(line, {weightGroupInfo})["name"]; - -// //TODO: Fine for now, but in general there should also be a check on the PDF weights, -// // e.g., it could be an unknown weight - -// if(std::regex_match(name, scaleWeightMatch_)) { -// weightGroups_.push_back(new gen::ScaleWeightGroupInfo(line)); -// std::cout << "scale weight" << "\n"; -// } - - -// else -// weightGroups_.push_back(new gen::PdfWeightGroupInfo(line)); - -// /// file weights -// while(getline(file, line) && !std::regex_match(line, weightGroupEnd_)) { -// auto tagsMap = getMap_testAll(line, regexOptions); - -// std::regex_search(line, matches, weightContent_); -// // TODO: Add proper check that it worked -// std::string content = matches[1].str(); - -// auto& group = weightGroups_.back(); -// if (group.weightType() == gen::kScaleWeights) { -// float muR = std::stof(tagsMap["mur"]); -// float muF = std::stof(tagsMap["muf"]); -// auto& scaleGroup = static_cast(group); -// scaleGroup.addContainedId(index, tagsMap["id"], line, muR, muF); -// } -// else -// group.addContainedId(index, tagsMap["id"], line); - -// index++; -// } -// } -// } -// } - void LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { // TODO: Not sure the weight indexing is right here, this seems to more or less @@ -220,11 +170,11 @@ LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector bool foundGroup = false; for (std::string headerLine : lheHeader) { - std::cout << "Header line is:" << headerLine; - headerLine = sanitizeText(headerLine); - std::cout << "Header line is:" << weightGroups_.size() << " "<< headerLine; - //TODO: Fine for now, but in general there should also be a check on the PDF weights, - // e.g., it could be an unknown weight + std::cout << "Header line is:" << headerLine; + headerLine = sanitizeText(headerLine); + std::cout << "Header line is:" << weightGroups_.size() << " "<< headerLine; + //TODO: Fine for now, but in general there should also be a check on the PDF weights, + // e.g., it could be an unknown weight if (std::regex_match(headerLine, weightGroupStart_)) { //std::cout << "Adding new group for headerLine" << std::endl; @@ -235,62 +185,62 @@ LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector if(name.find("Central scale variation") != std::string::npos || name.find("scale_variation") != std::string::npos) { - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(headerLine)); - std::cout << "scale weight" << "\n"; + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(name)); } - else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + else + weightGroups_.push_back(new gen::PdfWeightGroupInfo(name)); } /// file weights else if (foundGroup && isAWeight(headerLine)) { //std::cout << "Adding new weight for headerLine" << std::endl; auto tagsMap = getAttributeMap(headerLine); - for(auto pair: tagsMap) { - std::cout << pair.first << ": " << pair.second << " | "; - } + for(auto pair: tagsMap) { + std::cout << pair.first << ": " << pair.second << " | "; + } std::cout << "\n"; std::string content = tagsMap["content"]; - if (tagsMap["id"] == std::string()) { + if (tagsMap["id"].empty()) { std::cout << "error" << "\n"; // should do something } auto& group = weightGroups_.back(); if (group.weightType() == gen::kScaleWeights) { - if (tagsMap["mur"] == std::string() || tagsMap["muf"] == std::string()) { + if (tagsMap["mur"].empty() || tagsMap["muf"].empty()) { std::cout << "error" << "\n"; // something should happen here - continue; + continue; } float muR = std::stof(tagsMap["mur"]); float muF = std::stof(tagsMap["muf"]); std::cout << tagsMap["id"] << " " << muR << " " << muF << " " << content << "\n"; auto& scaleGroup = static_cast(group); - scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); + scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); } else group.addContainedId(index, tagsMap["id"], headerLine); + index++; - } - // commented out since code doesn't work with this in.... - // else if(isAWeight(headerLine)) { - // // found header. Don't know what to do with it so just shove it into a new weightgroup for now - // // do minimum work for it - // weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); - // auto& group = weightGroups_.back(); - // auto tagsMap = getAttributeMap(headerLine); - // group.addContainedId(index, tagsMap["id"], headerLine); - // foundGroup = true; - // index++; - // } + } + // commented out since code doesn't work with this in.... + // else if(isAWeight(headerLine)) { + // // found header. Don't know what to do with it so just shove it into a new weightgroup for now + // // do minimum work for it + // weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + // auto& group = weightGroups_.back(); + // auto tagsMap = getAttributeMap(headerLine); + // group.addContainedId(index, tagsMap["id"], headerLine); + // foundGroup = true; + // index++; + // } - else if(std::regex_match(headerLine, weightGroupEnd_)) { - foundGroup = false; - } - else { - std::cout << "problem!!!" << "\n"; - } + else if(std::regex_match(headerLine, weightGroupEnd_)) { + foundGroup = false; + } + else { + std::cout << "problem!!!" << "\n"; + } } } diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py index bef001d3972f3..fb6a1f58c66b4 100644 --- a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -59,7 +59,8 @@ process.GlobalTag = GlobalTag(process.GlobalTag, '102X_upgrade2018_realistic_v11', '') process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", - args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/WLLJJ_WToLNu_EWK_4F_MLL-60_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + #args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/WLLJJ_WToLNu_EWK_4F_MLL-60_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), + args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_4L_NNPDF30_13TeV_tarballDummy.tar.gz'), nEvents = cms.untracked.uint32(10), numberOfParameters = cms.uint32(1), outputFile = cms.string('cmsgrid_final.lhe'), From 79efbe6f198d3826f4446afc57e154f37b4146b9 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 18 Sep 2019 17:48:51 -0400 Subject: [PATCH 29/75] Adding a dummy analyzer for weights, need to clean up organization --- .../interface/ScaleWeightGroupInfo.h | 6 +- .../TestAnalyzer/plugins/BuildFile.xml | 6 + .../TestAnalyzer/plugins/TestAnalyzer.cc | 162 ++++++++++++++++++ .../TestAnalyzer/test/BuildFile.xml | 4 + .../test/test_catch2_TestAnalyzer.cc | 51 ++++++ .../TestAnalyzer/test/test_catch2_main.cc | 2 + TestWeightInfo/TestAnalyzer/test/test_cfg.py | 17 ++ 7 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 TestWeightInfo/TestAnalyzer/plugins/BuildFile.xml create mode 100644 TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc create mode 100644 TestWeightInfo/TestAnalyzer/test/BuildFile.xml create mode 100644 TestWeightInfo/TestAnalyzer/test/test_catch2_TestAnalyzer.cc create mode 100644 TestWeightInfo/TestAnalyzer/test/test_catch2_main.cc create mode 100644 TestWeightInfo/TestAnalyzer/test/test_cfg.py diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index 8f5a76f12cdcb..ec9b9723343a2 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -6,7 +6,7 @@ namespace gen { class ScaleWeightGroupInfo : public WeightGroupInfo { private: - bool isFuncationFormVar_; + bool isFunctionalFormVar_; size_t icentral_; size_t imuR1muF2_; size_t imuR1muF05_; @@ -21,7 +21,7 @@ namespace gen { ScaleWeightGroupInfo(std::string header, std::string name) : WeightGroupInfo(header, name) { weightType_ = kScaleWeights; - isFuncationFormVar_ = false; + isFunctionalFormVar_ = false; icentral_ = 0; imuR1muF2_ = 0; imuR1muF05_ = 0; @@ -47,7 +47,7 @@ namespace gen { // Is a variation of the functional form of the dynamic scale bool isFunctionalFormVariation(); - void setIsFunctionalFormVariation(bool functionalVar) {isFuncationFormVar_ = functionalVar; } + void setIsFunctionalFormVariation(bool functionalVar) {isFunctionalFormVar_ = functionalVar; } size_t centralIndex() {return icentral_; } size_t muR1muF2Index() { return imuR1muF2_; } size_t muR1muF05Index() { return imuR1muF05_; } diff --git a/TestWeightInfo/TestAnalyzer/plugins/BuildFile.xml b/TestWeightInfo/TestAnalyzer/plugins/BuildFile.xml new file mode 100644 index 0000000000000..29ffa306d8174 --- /dev/null +++ b/TestWeightInfo/TestAnalyzer/plugins/BuildFile.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc b/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc new file mode 100644 index 0000000000000..fea4414ac270b --- /dev/null +++ b/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc @@ -0,0 +1,162 @@ +// -*- C++ -*- +// +// Package: TestWeightInfo/TestAnalyzer +// Class: TestAnalyzer +// +/**\class TestAnalyzer TestAnalyzer.cc TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Kenneth David Long +// Created: Wed, 18 Sep 2019 13:44:58 GMT +// +// + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" + #include "FWCore/Utilities/interface/InputTag.h" + #include "DataFormats/TrackReco/interface/Track.h" + #include "DataFormats/TrackReco/interface/TrackFwd.h" + #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" + #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" + #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +// +// class declaration +// + +// If the analyzer does not use TFileService, please remove +// the template argument to the base class so the class inherits +// from edm::one::EDAnalyzer<> +// This will improve performance in multithreaded jobs. + + +using reco::TrackCollection; + +class TestAnalyzer : public edm::one::EDAnalyzer { + public: + explicit TestAnalyzer(const edm::ParameterSet&); + ~TestAnalyzer(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + + private: + edm::EDGetTokenT lheWeightInfoToken_; + virtual void beginJob() override; + void beginRun(edm::Run const& iRun, edm::EventSetup const&) override; + void endRun(edm::Run const& iRun, edm::EventSetup const&) override; + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; + + // ----------member data --------------------------- +}; + +// +// constants, enums and typedefs +// + +// +// static data member definitions +// + +// +// constructors and destructor +// +TestAnalyzer::TestAnalyzer(const edm::ParameterSet& iConfig) : + lheWeightInfoToken_(consumes(edm::InputTag("externalLHEProducer"))) +{ + //now do what ever initialization is needed + +} + + +TestAnalyzer::~TestAnalyzer() +{ + + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// + +// ------------ method called for each event ------------ +void +TestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + std::cerr << "Event" << std::endl; +} + +#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE + ESHandle pSetup; + iSetup.get().get(pSetup); +#endif + + +// ------------ method called once each job just before starting event loop ------------ +void +TestAnalyzer::beginJob() +{ +} + +// ------------ method called once each job just after ending the event loop ------------ +void +TestAnalyzer::endJob() +{ +} + +void TestAnalyzer::endRun(edm::Run const& iRun, edm::EventSetup const&) {} + +void TestAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const&) +{ + edm::Handle lheWeightInfoHandle; + iRun.getByToken( lheWeightInfoToken_, lheWeightInfoHandle ); + + const LHEWeightInfoProduct* lheProd = lheWeightInfoHandle.product(); + edm::OwnVector groups = lheProd->allWeightGroupsInfo(); + for (const auto& group : groups) { + std::cout << "Type of the weight is " << group.weightType() << " name is " << group.name() << std::endl; + if (group.weightType() == 0) { + //gen::ScaleWeightGroupInfo* scaleInfo = group.clone();//static_cast(group); + gen::ScaleWeightGroupInfo* scaleInfo = static_cast(&group); + std::cout << "muR05muF1 " << scaleInfo->muR05muF1Index() << std::endl; + std::cout << "muR05muF05 " << scaleInfo->muR05muF05Index() << std::endl; + } + } +} +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +TestAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); + + //Specify that only 'tracks' is allowed + //To use, remove the default given above and uncomment below + //ParameterSetDescription desc; + //desc.addUntracked("tracks","ctfWithMaterialTracks"); + //descriptions.addDefault(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(TestAnalyzer); diff --git a/TestWeightInfo/TestAnalyzer/test/BuildFile.xml b/TestWeightInfo/TestAnalyzer/test/BuildFile.xml new file mode 100644 index 0000000000000..853ca18422452 --- /dev/null +++ b/TestWeightInfo/TestAnalyzer/test/BuildFile.xml @@ -0,0 +1,4 @@ + + + + diff --git a/TestWeightInfo/TestAnalyzer/test/test_catch2_TestAnalyzer.cc b/TestWeightInfo/TestAnalyzer/test/test_catch2_TestAnalyzer.cc new file mode 100644 index 0000000000000..fa1c318a56534 --- /dev/null +++ b/TestWeightInfo/TestAnalyzer/test/test_catch2_TestAnalyzer.cc @@ -0,0 +1,51 @@ +#include "catch.hpp" +#include "FWCore/TestProcessor/interface/TestProcessor.h" +#include "FWCore/Utilities/interface/Exception.h" + +static constexpr auto s_tag = "[TestAnalyzer]"; + +TEST_CASE("Standard checks of TestAnalyzer", s_tag) { + const std::string baseConfig{ +R"_(from FWCore.TestProcessor.TestProcess import * +process = TestProcess() +process.toTest = cms.EDProducer("TestAnalyzer" +#necessary configuration parameters + ) +process.moduleToTest(process.toTest) +)_" + }; + + edm::test::TestProcessor::Config config{ baseConfig }; + SECTION("base configuration is OK") { + REQUIRE_NOTHROW(edm::test::TestProcessor(config)); + } + + SECTION("No event data") { + edm::test::TestProcessor tester(config); + + REQUIRE_THROWS_AS(tester.test(), cms::Exception); + //If the module does not throw when given no data, substitute + //REQUIRE_NOTHROW for REQUIRE_THROWS_AS + } + + SECTION("beginJob and endJob only") { + edm::test::TestProcessor tester(config); + + REQUIRE_NOTHROW(tester.testBeginAndEndJobOnly()); + } + + SECTION("Run with no LuminosityBlocks") { + edm::test::TestProcessor tester(config); + + REQUIRE_NOTHROW(tester.testRunWithNoLuminosityBlocks()); + } + + SECTION("LuminosityBlock with no Events") { + edm::test::TestProcessor tester(config); + + REQUIRE_NOTHROW(tester.testLuminosityBlockWithNoEvents()); + } + +} + +//Add additional TEST_CASEs to exercise the modules capabilities diff --git a/TestWeightInfo/TestAnalyzer/test/test_catch2_main.cc b/TestWeightInfo/TestAnalyzer/test/test_catch2_main.cc new file mode 100644 index 0000000000000..0c7c351f437f5 --- /dev/null +++ b/TestWeightInfo/TestAnalyzer/test/test_catch2_main.cc @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include "catch.hpp" diff --git a/TestWeightInfo/TestAnalyzer/test/test_cfg.py b/TestWeightInfo/TestAnalyzer/test/test_cfg.py new file mode 100644 index 0000000000000..cdb44a5404eb5 --- /dev/null +++ b/TestWeightInfo/TestAnalyzer/test/test_cfg.py @@ -0,0 +1,17 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("test") + +process.source = cms.Source("PoolSource", + # replace 'myfile.root' with the source file you want to use + fileNames = cms.untracked.vstring("file:HIG-RunIIFall18wmLHEGS-00509.root") + ) + +process.TFileService = cms.Service("TFileService", + fileName = cms.string("test.root") +) + +process.testWeights = cms.EDAnalyzer("TestAnalyzer") + +process.p = cms.Path(process.testWeights) + From 07eb97abc8336ed0006db49d6a46c6b229ac2d8f Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 18 Sep 2019 17:58:34 -0400 Subject: [PATCH 30/75] Use dynamic cast, but then it segfaults --- .../interface/ScaleWeightGroupInfo.h | 18 +++++++++--------- .../TestAnalyzer/plugins/TestAnalyzer.cc | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index ec9b9723343a2..543b2b6d976e3 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -48,15 +48,15 @@ namespace gen { // Is a variation of the functional form of the dynamic scale bool isFunctionalFormVariation(); void setIsFunctionalFormVariation(bool functionalVar) {isFunctionalFormVar_ = functionalVar; } - size_t centralIndex() {return icentral_; } - size_t muR1muF2Index() { return imuR1muF2_; } - size_t muR1muF05Index() { return imuR1muF05_; } - size_t muR2muF05Index() { return imuR2muF05_; } - size_t muR2muF1Index() { return imuR2muF1_; } - size_t muR2muF2Index() { return imuR2muF2_; } - size_t muR05muF05Index() { return imuR05muF05_; } - size_t muR05muF1Index() { return imuR05muF1_; } - size_t muR05muF2Index() { return imuR05muF2_; } + size_t centralIndex() const {return icentral_; } + size_t muR1muF2Index() const { return imuR1muF2_; } + size_t muR1muF05Index() const { return imuR1muF05_; } + size_t muR2muF05Index() const { return imuR2muF05_; } + size_t muR2muF1Index() const { return imuR2muF1_; } + size_t muR2muF2Index() const { return imuR2muF2_; } + size_t muR05muF05Index() const { return imuR05muF05_; } + size_t muR05muF1Index() const { return imuR05muF1_; } + size_t muR05muF2Index() const { return imuR05muF2_; } }; } diff --git a/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc b/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc index fea4414ac270b..3c8d7065faf6c 100644 --- a/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc +++ b/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc @@ -134,9 +134,9 @@ void TestAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const&) edm::OwnVector groups = lheProd->allWeightGroupsInfo(); for (const auto& group : groups) { std::cout << "Type of the weight is " << group.weightType() << " name is " << group.name() << std::endl; - if (group.weightType() == 0) { + if (group.weightType() == 1) { //gen::ScaleWeightGroupInfo* scaleInfo = group.clone();//static_cast(group); - gen::ScaleWeightGroupInfo* scaleInfo = static_cast(&group); + const gen::ScaleWeightGroupInfo* scaleInfo = dynamic_cast(&group); std::cout << "muR05muF1 " << scaleInfo->muR05muF1Index() << std::endl; std::cout << "muR05muF05 " << scaleInfo->muR05muF05Index() << std::endl; } From 5668f0da242c77aa8e6a38aa25d59e9263d500cd Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 20 Sep 2019 17:14:32 -0400 Subject: [PATCH 31/75] Incorporate changes to make OwnVector work --- .../plugins/ExternalLHEProducer.cc | 37 ++++++++++--------- .../LHEInterface/plugins/LHESource.cc | 4 +- .../LHEInterface/test/testWeights.py | 9 +++++ .../LHEInterface/test/test_Weights_cfg.py | 9 ----- .../interface/LHEWeightInfoProduct.h | 7 ++-- .../interface/PdfWeightGroupInfo.h | 2 +- .../interface/ScaleWeightGroupInfo.h | 2 +- .../interface/WeightGroupInfo.h | 12 +++--- .../src/LHEWeightInfoProduct.cc | 10 ++--- .../src/PdfWeightGroupInfo.cc | 1 + .../src/ScaleWeightGroupInfo.cc | 1 + .../GeneratorProducts/src/WeightGroupInfo.cc | 11 +++--- .../GeneratorProducts/src/classes_def.xml | 9 ++++- 13 files changed, 64 insertions(+), 50 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 0bea679e0cb11..9eaf6bc5c6029 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -107,10 +107,10 @@ class ExternalLHEProducer : public edm::one::EDProducer reader_; std::shared_ptr runInfoLast; std::shared_ptr runInfo; + std::unique_ptr weightInfoProduct_; std::shared_ptr partonLevel; boost::ptr_deque runInfoProducts; bool wasMerged; - edm::OwnVector weightGroups_; class FileCloseSentry : private boost::noncopyable { public: @@ -165,7 +165,7 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig) : produces(); produces(); produces(); - produces(); + produces(); } @@ -208,17 +208,18 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) boost::bind(&LHEEventProduct::addWeight, product.get(), _1)); - std::unique_ptr weightProduct(new LHEWeightProduct); - weightProduct->setNumWeightSets(weightGroups_.size()); + auto weightProduct = std::make_unique(); + weightProduct->setNumWeightSets(weightInfoProduct_->numberOfGroups()); int weightGroupIndex = 0; int weightNum = 0; for (const auto& weight : partonLevel->weights()) { weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex); - if (weightGroupIndex < 0 || weightGroupIndex >= static_cast(weightGroups_.size())) { - continue; + if (weightGroupIndex < 0 || weightGroupIndex >= weightInfoProduct_->numberOfGroups()) { + // Needs to be properly handled + throw std::range_error("Unmatched weight"); } - auto group = weightGroups_[weightGroupIndex]; - int entry = group.weightVectorEntry(weight.id, weightNum); + auto* group = weightInfoProduct_->orderedWeightGroupInfo(weightGroupIndex); + int entry = group->weightVectorEntry(weight.id, weightNum); weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); weightNum++; } @@ -371,16 +372,15 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) run.put(std::move(product)); - std::unique_ptr weightInfoProduct(new LHEWeightInfoProduct); + weightInfoProduct_ = std::make_unique(); LHEWeightGroupReaderHelper reader; //reader.parseLHEFile(LHEfilename); reader.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); - for (auto weightGroup : reader.getWeightGroups()) - weightInfoProduct->addWeightGroupInfo(weightGroup); - weightGroups_ = weightInfoProduct->allWeightGroupsInfo(); - run.put(std::move(weightInfoProduct)); + for (auto& weightGroup : reader.getWeightGroups()) { + weightInfoProduct_->addWeightGroupInfo(weightGroup.clone()); + } runInfo.reset(); } @@ -405,6 +405,7 @@ ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) } reader_.reset(); + run.put(std::move(weightInfoProduct_)); if (unlink(outputFile_.c_str())) { throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ")."; @@ -540,17 +541,19 @@ int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int // Start search at previous index, under expectation of ordered weights previousGroupIndex = previousGroupIndex >=0 ? previousGroupIndex : 0; for (int index = previousGroupIndex; - index < std::min(index+1, static_cast(weightGroups_.size())); index++) { - gen::WeightGroupInfo& weightGroup = weightGroups_[previousGroupIndex]; + index < std::min(index+1, static_cast(weightInfoProduct_->numberOfGroups())); index++) { + const gen::WeightGroupInfo* weightGroup = weightInfoProduct_->orderedWeightGroupInfo(index); + // index < std::min(index+1, static_cast(weightGroups_.size())); index++) { + //gen::WeightGroupInfo& weightGroup = weightGroups_[previousGroupIndex]; // Fast search assuming order is not perturbed outside of weight group - if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) { + if (weightGroup->indexInRange(weightIndex) && weightGroup->containsWeight(wgtId, weightIndex)) { return static_cast(index); } } // Fall back to unordered search int counter = 0; - for (auto weightGroup : weightGroups_) { + for (auto weightGroup : weightInfoProduct_->allWeightGroupsInfo()) { if (weightGroup.containsWeight(wgtId, weightIndex)) return counter; counter++; diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.cc b/GeneratorInterface/LHEInterface/plugins/LHESource.cc index a238a0fc613ca..03402f473651f 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.cc @@ -147,8 +147,8 @@ void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { ); cenPdfInfo.setWeightType(gen::kPdfWeights); - product->addWeightGroupInfo(scaleInfo); - product->addWeightGroupInfo(cenPdfInfo); + product->addWeightGroupInfo(&scaleInfo); + product->addWeightGroupInfo(&cenPdfInfo); std::unique_ptr rdp(new edm::Wrapper(std::move(product))); iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp)); } diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/LHEInterface/test/testWeights.py index 12e2961868af9..630821f3947ce 100644 --- a/GeneratorInterface/LHEInterface/test/testWeights.py +++ b/GeneratorInterface/LHEInterface/test/testWeights.py @@ -1,4 +1,5 @@ from DataFormats.FWLite import Events,Handle,Runs +import ROOT source = "externalLHEProducer" #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: @@ -19,6 +20,14 @@ for j, weights in enumerate(weightInfo.weights()): print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 matching = weightInfoProd.orderedWeightGroupInfo(j) + print matching + if matching.weightType() == 1: + print " muR1muF05Index", matching.muR1muF05Index() + print " muR1muF1Index", matching.centralIndex() + print " muR2muF2Index", matching.muR2muF2Index() + print " muR05muF05Index", matching.muR05muF05Index() + else: + print "uncertaintyType", "Hessian" if matching.uncertaintyType() == ROOT.gen.kHessianUnc else "MC" print "Weights length?", len(weights), "Contained ids lenths?", len(matching.containedIds()) print "-"*80 for i,weight in enumerate(weights): diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py index fb6a1f58c66b4..f4cbf5ce94694 100644 --- a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -11,14 +11,9 @@ # import of standard configurations process.load('Configuration.StandardSequences.Services_cff') -process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') process.load('FWCore.MessageService.MessageLogger_cfi') process.load('Configuration.EventContent.EventContent_cff') -process.load('SimGeneral.MixingModule.mixNoPU_cfi') -process.load('Configuration.StandardSequences.GeometryRecoDB_cff') -process.load('Configuration.StandardSequences.MagneticField_cff') process.load('Configuration.StandardSequences.EndOfProcess_cff') -process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10) @@ -54,10 +49,6 @@ # Additional output definition -# Other statements -from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag, '102X_upgrade2018_realistic_v11', '') - process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", #args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/WLLJJ_WToLNu_EWK_4F_MLL-60_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_4L_NNPDF30_13TeV_tarballDummy.tar.gz'), diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h index f0fa291ab3423..9ed6c8b1927e9 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -23,9 +23,10 @@ class LHEWeightInfoProduct { LHEWeightInfoProduct& operator=(LHEWeightInfoProduct &&other); const edm::OwnVector& allWeightGroupsInfo() const; - const gen::WeightGroupInfo& containingWeightGroupInfo(int index) const; - const gen::WeightGroupInfo& orderedWeightGroupInfo(int index) const; - void addWeightGroupInfo(gen::WeightGroupInfo& info); + const gen::WeightGroupInfo* containingWeightGroupInfo(int index) const; + const gen::WeightGroupInfo* orderedWeightGroupInfo(int index) const; + void addWeightGroupInfo(gen::WeightGroupInfo* info); + const int numberOfGroups() const { return weightGroupsInfo_.size(); } private: edm::OwnVector weightGroupsInfo_; diff --git a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h index 5f1e5559f46e2..6a3ea022609de 100644 --- a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h @@ -27,7 +27,7 @@ namespace gen { } virtual ~PdfWeightGroupInfo() override {} void copy(const PdfWeightGroupInfo &other); - PdfWeightGroupInfo* clone() const; + virtual PdfWeightGroupInfo* clone() const override; void setUncertaintyType(PdfUncertaintyType uncertaintyType) { uncertaintyType_ = uncertaintyType; } void setHasAlphasVariations(bool hasAlphasVars) { hasAlphasVars_ = hasAlphasVars; } diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index 543b2b6d976e3..d3a93b59744d6 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -40,7 +40,7 @@ namespace gen { } virtual ~ScaleWeightGroupInfo() override {} void copy(const ScaleWeightGroupInfo &other); - ScaleWeightGroupInfo* clone() const; + virtual ScaleWeightGroupInfo* clone() const override; void setMuRMuFIndex(WeightMetaInfo info, float muR, float muF); void addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF); diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index a815ec762f7f8..a2a645740cc9b 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -40,12 +40,12 @@ namespace gen { } virtual ~WeightGroupInfo() {}; void copy(const WeightGroupInfo &other); - WeightGroupInfo* clone() const; - WeightMetaInfo weightMetaInfo(int weightEntry); - WeightMetaInfo weightMetaInfo(std::string wgtId); - int weightVectorEntry(const std::string& wgtId); - int containsWeight(const std::string& wgtId, int weightEntry); - int weightVectorEntry(const std::string& wgtId, int weightEntry); + virtual WeightGroupInfo* clone() const; + WeightMetaInfo weightMetaInfo(int weightEntry) const; + WeightMetaInfo weightMetaInfo(std::string wgtId) const; + int weightVectorEntry(const std::string& wgtId) const; + int containsWeight(const std::string& wgtId, int weightEntry) const; + int weightVectorEntry(const std::string& wgtId, int weightEntry) const; void addContainedId(int weightEntry, std::string id, std::string label); std::vector containedIds() const; bool indexInRange(int index) const; diff --git a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc index 78c7d858f65f6..9e1f666325a75 100644 --- a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc @@ -21,20 +21,20 @@ const edm::OwnVector& LHEWeightInfoProduct::allWeightGroup return weightGroupsInfo_; } -const gen::WeightGroupInfo& LHEWeightInfoProduct::containingWeightGroupInfo(int index) const { +const gen::WeightGroupInfo* LHEWeightInfoProduct::containingWeightGroupInfo(int index) const { for (const auto& weightGroup : weightGroupsInfo_) { if (weightGroup.indexInRange(index)) - return weightGroup; + return &weightGroup; } throw std::domain_error("Failed to find containing weight group"); } -const gen::WeightGroupInfo& LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { +const gen::WeightGroupInfo* LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { if (weightGroupIndex >= static_cast(weightGroupsInfo_.size())) throw std::range_error("Weight index out of range!"); - return weightGroupsInfo_[weightGroupIndex]; + return &weightGroupsInfo_[weightGroupIndex]; } -void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo& info) { +void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo* info) { weightGroupsInfo_.push_back(info); } diff --git a/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc index 4e0175bf9629c..0f479619c05d9 100644 --- a/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc @@ -1,4 +1,5 @@ #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" +#include namespace gen { void PdfWeightGroupInfo::copy(const PdfWeightGroupInfo &other) { diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc index 5d2e392d89164..c65c35ad03afd 100644 --- a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc @@ -1,5 +1,6 @@ #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include +#include namespace gen { void ScaleWeightGroupInfo::copy(const ScaleWeightGroupInfo &other) { diff --git a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc index a9cbccfdea6f9..34812078bef6b 100644 --- a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc @@ -1,6 +1,7 @@ #include #include #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include namespace gen { void WeightGroupInfo::copy(const WeightGroupInfo &other) { @@ -16,24 +17,24 @@ namespace gen { return new WeightGroupInfo(*this); } - WeightMetaInfo WeightGroupInfo::weightMetaInfo(int weightEntry) { + WeightMetaInfo WeightGroupInfo::weightMetaInfo(int weightEntry) const { return idsContained_.at(weightEntry); } - WeightMetaInfo WeightGroupInfo::weightMetaInfo(std::string wgtId) { + WeightMetaInfo WeightGroupInfo::weightMetaInfo(std::string wgtId) const { int weightEntry = weightVectorEntry(wgtId); return idsContained_.at(weightEntry); } - int WeightGroupInfo::weightVectorEntry(const std::string& wgtId) { + int WeightGroupInfo::weightVectorEntry(const std::string& wgtId) const { return weightVectorEntry(wgtId, 0); } - int WeightGroupInfo::containsWeight(const std::string& wgtId, int weightEntry) { + int WeightGroupInfo::containsWeight(const std::string& wgtId, int weightEntry) const { return weightVectorEntry(wgtId, weightEntry) != -1; } - int WeightGroupInfo::weightVectorEntry(const std::string& wgtId, int weightEntry) { + int WeightGroupInfo::weightVectorEntry(const std::string& wgtId, int weightEntry) const { int entry = -1; if (!indexInRange(weightEntry)) { size_t orderedEntry = weightEntry - firstId_; diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index 0429c3c799790..8b2d802446db0 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -234,14 +234,21 @@ - + + + + + + + + From 8c0c98e491fced903b41919d38e4336fbd963f74 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 20 Sep 2019 17:46:49 -0400 Subject: [PATCH 32/75] Fix setting of ScaleWeight indices --- .../plugins/ExternalLHEProducer.cc | 5 ++ .../LHEInterface/test/testWeights.py | 9 ++- .../interface/ScaleWeightGroupInfo.h | 56 +++++++++---------- .../src/ScaleWeightGroupInfo.cc | 36 ++++++------ 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 9eaf6bc5c6029..67ec31046f1ee 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -379,6 +379,11 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) reader.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); for (auto& weightGroup : reader.getWeightGroups()) { + if (weightGroup.weightType() == 1) { + gen::ScaleWeightGroupInfo* group = static_cast(weightGroup.clone()); + std::cout << "MuR1MuF2Index is " << group->muR1muF2Index(); + } + weightInfoProduct_->addWeightGroupInfo(weightGroup.clone()); } diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/LHEInterface/test/testWeights.py index 630821f3947ce..c145a34497c11 100644 --- a/GeneratorInterface/LHEInterface/test/testWeights.py +++ b/GeneratorInterface/LHEInterface/test/testWeights.py @@ -20,12 +20,11 @@ for j, weights in enumerate(weightInfo.weights()): print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 matching = weightInfoProd.orderedWeightGroupInfo(j) - print matching + print "Group is", matching if matching.weightType() == 1: - print " muR1muF05Index", matching.muR1muF05Index() - print " muR1muF1Index", matching.centralIndex() - print " muR2muF2Index", matching.muR2muF2Index() - print " muR05muF05Index", matching.muR05muF05Index() + for var in [(x, y) for x in ["05", "1", "2"] for y in ["05", "1", "2"]]: + name = "muR%smuF%sIndex" % (var[0], var[1]) if not (var[0] == "1" and var[1] == "1") else "centralIndex" + print name, getattr(matching, name)() else: print "uncertaintyType", "Hessian" if matching.uncertaintyType() == ROOT.gen.kHessianUnc else "MC" print "Weights length?", len(weights), "Contained ids lenths?", len(matching.containedIds()) diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index d3a93b59744d6..00891a219db23 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -7,31 +7,31 @@ namespace gen { class ScaleWeightGroupInfo : public WeightGroupInfo { private: bool isFunctionalFormVar_; - size_t icentral_; - size_t imuR1muF2_; - size_t imuR1muF05_; - size_t imuR2muF05_; - size_t imuR2muF1_; - size_t imuR2muF2_; - size_t imuR05muF05_; - size_t imuR05muF1_; - size_t imuR05muF2_; + size_t centralIndex_; + size_t muR1muF2Index_; + size_t muR1muF05Index_; + size_t muR2muF05Index_; + size_t muR2muF1Index_; + size_t muR2muF2Index_; + size_t muR05muF05Index_; + size_t muR05muF1Index_; + size_t muR05muF2Index_; public: ScaleWeightGroupInfo() : ScaleWeightGroupInfo("") {} ScaleWeightGroupInfo(std::string header, std::string name) : WeightGroupInfo(header, name) { weightType_ = kScaleWeights; isFunctionalFormVar_ = false; - icentral_ = 0; - imuR1muF2_ = 0; - imuR1muF05_ = 0; - imuR2muF05_ = 0; - imuR2muF1_ = 0; - imuR2muF2_ = 0; - imuR2muF05_ = 0; - imuR05muF05_ = 0; - imuR05muF1_ = 0; - imuR05muF2_ = 0; + centralIndex_ = 0; + muR1muF2Index_ = 0; + muR1muF05Index_ = 0; + muR2muF05Index_ = 0; + muR2muF1Index_ = 0; + muR2muF2Index_ = 0; + muR2muF05Index_ = 0; + muR05muF05Index_ = 0; + muR05muF1Index_ = 0; + muR05muF2Index_ = 0; } ScaleWeightGroupInfo(std::string header) : ScaleWeightGroupInfo(header, header) { } @@ -48,15 +48,15 @@ namespace gen { // Is a variation of the functional form of the dynamic scale bool isFunctionalFormVariation(); void setIsFunctionalFormVariation(bool functionalVar) {isFunctionalFormVar_ = functionalVar; } - size_t centralIndex() const {return icentral_; } - size_t muR1muF2Index() const { return imuR1muF2_; } - size_t muR1muF05Index() const { return imuR1muF05_; } - size_t muR2muF05Index() const { return imuR2muF05_; } - size_t muR2muF1Index() const { return imuR2muF1_; } - size_t muR2muF2Index() const { return imuR2muF2_; } - size_t muR05muF05Index() const { return imuR05muF05_; } - size_t muR05muF1Index() const { return imuR05muF1_; } - size_t muR05muF2Index() const { return imuR05muF2_; } + size_t centralIndex() const {return centralIndex_; } + size_t muR1muF2Index() const { return muR1muF2Index_; } + size_t muR1muF05Index() const { return muR1muF05Index_; } + size_t muR2muF05Index() const { return muR2muF05Index_; } + size_t muR2muF1Index() const { return muR2muF1Index_; } + size_t muR2muF2Index() const { return muR2muF2Index_; } + size_t muR05muF05Index() const { return muR05muF05Index_; } + size_t muR05muF1Index() const { return muR05muF1Index_; } + size_t muR05muF2Index() const { return muR05muF2Index_; } }; } diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc index c65c35ad03afd..e14ace5fb750b 100644 --- a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc @@ -4,15 +4,15 @@ namespace gen { void ScaleWeightGroupInfo::copy(const ScaleWeightGroupInfo &other) { - icentral_ = centralIndex(); - imuR1muF2_ = muR1muF2Index(); - imuR1muF05_ = muR1muF05Index(); - imuR2muF05_ = muR2muF05Index(); - imuR2muF1_ = muR2muF1Index(); - imuR2muF2_ = muR2muF2Index(); - imuR2muF05_ = muR2muF05Index(); - imuR05muF1_ = muR05muF1Index(); - imuR05muF2_ = muR05muF2Index(); + centralIndex_ = other.centralIndex_; + muR1muF2Index_ = other.muR1muF2Index_; + muR1muF05Index_ = other.muR1muF05Index_; + muR2muF05Index_ = other.muR2muF05Index_; + muR2muF1Index_ = other.muR2muF1Index_; + muR2muF2Index_ = other.muR2muF2Index_; + muR2muF05Index_ = other.muR2muF05Index_; + muR05muF1Index_ = other.muR05muF1Index_; + muR05muF2Index_ = other.muR05muF2Index_; WeightGroupInfo::copy(other); } @@ -28,23 +28,23 @@ namespace gen { void ScaleWeightGroupInfo::setMuRMuFIndex(WeightMetaInfo info, float muR, float muF) { if (muR == 0.5 && muF == 0.5) - imuR05muF05_ = info.localIndex; + muR05muF05Index_ = info.localIndex; else if (muR == 0.5 && muF == 1.0) - imuR05muF1_ = info.localIndex; + muR05muF1Index_ = info.localIndex; else if (muR == 0.5 && muF == 2.0) - imuR05muF2_ = info.localIndex; + muR05muF2Index_ = info.localIndex; else if (muR == 1.0 && muF == 0.5) - imuR1muF05_ = info.localIndex; + muR1muF05Index_ = info.localIndex; else if (muR == 1.0 && muF == 1.0) - icentral_ = info.localIndex; + centralIndex_ = info.localIndex; else if (muR == 1.0 && muF == 2.0) - imuR1muF2_ = info.localIndex; + muR1muF2Index_ = info.localIndex; else if (muR == 2.0 && muF == 0.5) - imuR2muF05_ = info.localIndex; + muR2muF05Index_ = info.localIndex; else if (muR == 2.0 && muF == 1.0) - imuR2muF1_ = info.localIndex; + muR2muF1Index_ = info.localIndex; else if (muR == 2.0 && muF == 2.0) - imuR2muF2_ = info.localIndex; + muR2muF2Index_ = info.localIndex; else throw std::invalid_argument("Invalid muF and muR variation is not a factor of two from central value"); } From 8744839eeeb32b42c8cd880765daa725f208eaf8 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 20 Sep 2019 19:23:17 -0400 Subject: [PATCH 33/75] Add unknown weightgroup --- .../interface/PdfWeightGroupInfo.h | 4 ++++ .../interface/UnknownWeightGroupInfo.h | 22 +++++++++++++++++++ .../interface/WeightGroupInfo.h | 4 ++++ .../src/PdfWeightGroupInfo.cc | 1 - .../src/ScaleWeightGroupInfo.cc | 3 +-- .../src/UnknownWeightGroupInfo.cc | 8 +++++++ .../GeneratorProducts/src/WeightGroupInfo.cc | 5 +++-- .../GeneratorProducts/src/classes.h | 1 + .../GeneratorProducts/src/classes_def.xml | 7 ++---- 9 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h create mode 100644 SimDataFormats/GeneratorProducts/src/UnknownWeightGroupInfo.cc diff --git a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h index 6a3ea022609de..4f853103d4241 100644 --- a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h @@ -16,6 +16,7 @@ namespace gen { bool hasAlphasVars_; int alphasUpIndex_; int alphasDownIndex_; + std::vector lhapdfIdsContained_; public: PdfWeightGroupInfo() : WeightGroupInfo() { weightType_ = kPdfWeights; } PdfWeightGroupInfo(std::string header, std::string name) : @@ -35,8 +36,11 @@ namespace gen { void setAlphasDownIndex(int alphasDownIndex) { alphasDownIndex_ = alphasDownIndex; } PdfUncertaintyType uncertaintyType() const { return uncertaintyType_; } bool hasAlphasVariations() const { return hasAlphasVars_; } + bool containsMultipleSets() const { return lhapdfIdsContained_.size() > 1; } int alphasUpIndex() const { return alphasUpIndex_; } int alphasDownIndex() const { return alphasDownIndex_; } + void addLhapdfId(int lhaid) { lhapdfIdsContained_.push_back(lhaid); } + std::vector getLhapdfIdsContained() const { return lhapdfIdsContained_; } }; } diff --git a/SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h new file mode 100644 index 0000000000000..37f68289633d7 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h @@ -0,0 +1,22 @@ +#ifndef SimDataFormats_GeneratorProducts_UnknownWeightGroupInfo_h +#define SimDataFormats_GeneratorProducts_UnknownWeightGroupInfo_h + +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" + +namespace gen { + class UnknownWeightGroupInfo : public WeightGroupInfo { + public: + UnknownWeightGroupInfo() : WeightGroupInfo() { weightType_ = kUnknownWeights; } + UnknownWeightGroupInfo(std::string header, std::string name) : + WeightGroupInfo(header, name) { weightType_ = kUnknownWeights; isWellFormed_ = false;} + UnknownWeightGroupInfo(std::string header) : + WeightGroupInfo(header) { weightType_ = kUnknownWeights; isWellFormed_ = false;} + virtual ~UnknownWeightGroupInfo() override {} + void copy(const UnknownWeightGroupInfo &other); + virtual UnknownWeightGroupInfo* clone() const override; + }; +} + +#endif // SimDataFormats_GeneratorProducts_UnknownWeightGroupInfo_h + + diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index a2a645740cc9b..cc56681a7bfbf 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -62,8 +62,12 @@ namespace gen { std::vector idsContained() const { return idsContained_; } int firstId() const { return firstId_; } int lastId() const { return lastId_; } + // Store whether the group was fully parsed succesfully + void setIsWellFormed(bool wellFormed) { isWellFormed_ = wellFormed; } + bool isWellFormed() const { return isWellFormed_; } protected: + bool isWellFormed_; std::string headerEntry_; std::string name_; WeightType weightType_; diff --git a/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc index 0f479619c05d9..4e0175bf9629c 100644 --- a/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc @@ -1,5 +1,4 @@ #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" -#include namespace gen { void PdfWeightGroupInfo::copy(const PdfWeightGroupInfo &other) { diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc index e14ace5fb750b..5fd94f70aca3f 100644 --- a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc @@ -1,6 +1,5 @@ #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include -#include namespace gen { void ScaleWeightGroupInfo::copy(const ScaleWeightGroupInfo &other) { @@ -46,7 +45,7 @@ namespace gen { else if (muR == 2.0 && muF == 2.0) muR2muF2Index_ = info.localIndex; else - throw std::invalid_argument("Invalid muF and muR variation is not a factor of two from central value"); + isWellFormed_ = false; } } diff --git a/SimDataFormats/GeneratorProducts/src/UnknownWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/UnknownWeightGroupInfo.cc new file mode 100644 index 0000000000000..2d56e8e177b31 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/src/UnknownWeightGroupInfo.cc @@ -0,0 +1,8 @@ +#include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h" + +namespace gen { + UnknownWeightGroupInfo* UnknownWeightGroupInfo::clone() const { + return new UnknownWeightGroupInfo(*this); + } +} + diff --git a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc index 34812078bef6b..718447db14b96 100644 --- a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc @@ -1,10 +1,11 @@ #include #include #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" -#include +#include "FWCore/Utilities/interface/Exception.h" namespace gen { void WeightGroupInfo::copy(const WeightGroupInfo &other) { + isWellFormed_ = true; headerEntry_ = other.headerEntry(); name_ = other.name(); weightType_ = other.weightType(); @@ -14,7 +15,7 @@ namespace gen { } WeightGroupInfo* WeightGroupInfo::clone() const { - return new WeightGroupInfo(*this); + throw cms::Exception("LogicError", "WeightGroupInfo is abstract, so it's clone() method can't be implemented.\n"); } WeightMetaInfo WeightGroupInfo::weightMetaInfo(int weightEntry) const { diff --git a/SimDataFormats/GeneratorProducts/src/classes.h b/SimDataFormats/GeneratorProducts/src/classes.h index 9e5f0b86ac2af..5629d5765059d 100644 --- a/SimDataFormats/GeneratorProducts/src/classes.h +++ b/SimDataFormats/GeneratorProducts/src/classes.h @@ -10,6 +10,7 @@ #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index 8b2d802446db0..b52e0f7851b2a 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -224,22 +224,19 @@ + - - - - + - From 682ac14c6bc1d726141403970a70a4ed97d9fc82 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 20 Sep 2019 19:35:26 -0400 Subject: [PATCH 34/75] Start to move parsing tools to GeneratorInterface/Core --- GeneratorInterface/Core/BuildFile.xml | 1 + .../interface/LHEWeightGroupReaderHelper.h | 0 GeneratorInterface/LHEInterface/BuildFile.xml | 1 - GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename GeneratorInterface/{LHEInterface => Core}/interface/LHEWeightGroupReaderHelper.h (100%) diff --git a/GeneratorInterface/Core/BuildFile.xml b/GeneratorInterface/Core/BuildFile.xml index 4257af0e29ebe..07d1b0adc6194 100644 --- a/GeneratorInterface/Core/BuildFile.xml +++ b/GeneratorInterface/Core/BuildFile.xml @@ -10,6 +10,7 @@ + diff --git a/GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h similarity index 100% rename from GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h rename to GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h diff --git a/GeneratorInterface/LHEInterface/BuildFile.xml b/GeneratorInterface/LHEInterface/BuildFile.xml index 3c5338daa6d97..7ee840b3ea784 100644 --- a/GeneratorInterface/LHEInterface/BuildFile.xml +++ b/GeneratorInterface/LHEInterface/BuildFile.xml @@ -13,7 +13,6 @@ - diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 67ec31046f1ee..43ba899a0e394 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -58,7 +58,7 @@ Description: [one line class summary] #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" #include "GeneratorInterface/LHEInterface/interface/LHEReader.h" #include "GeneratorInterface/LHEInterface/interface/TestWeightInfo.h" -#include "GeneratorInterface/LHEInterface/interface/LHEWeightGroupReaderHelper.h" +#include "GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h" #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Utilities/interface/RandomNumberGenerator.h" From 037f6f9cd0508d68aa8e262e93ebe496da00137e Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sat, 21 Sep 2019 11:09:59 -0400 Subject: [PATCH 35/75] Move LHE reader to .h and .cc files, rename --- .../interface/LHEWeightGroupReaderHelper.h | 251 ------------------ .../Core/interface/LHEWeightHelper.h | 49 ++++ .../Core/src/LHEWeightHelper.cc | 207 +++++++++++++++ .../plugins/ExternalLHEProducer.cc | 9 +- 4 files changed, 261 insertions(+), 255 deletions(-) delete mode 100644 GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h create mode 100644 GeneratorInterface/Core/interface/LHEWeightHelper.h create mode 100644 GeneratorInterface/Core/src/LHEWeightHelper.cc diff --git a/GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h b/GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h deleted file mode 100644 index 893c528e20379..0000000000000 --- a/GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h +++ /dev/null @@ -1,251 +0,0 @@ -#ifndef GeneratorInterface_LHEInterface_LHEWeightGroupReaderHelper_h -#define GeneratorInterface_LHEInterface_LHEWeightGroupReaderHelper_h - -#include -#include -#include -#include -#include - -#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" -#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" -#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" -#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" - -#include -using namespace tinyxml2; - - -class LHEWeightGroupReaderHelper { -public: - LHEWeightGroupReaderHelper(); - - //// possibly add more versions of this functions for different inputs - void parseLHEFile(std::string filename); - void parseWeightGroupsFromHeader(std::vector lheHeader); - - - edm::OwnVector getWeightGroups() {return weightGroups_;} -private: - void loadAttributeNames(std::string baseName, std::vector altNames ={}); - std::string toLowerCase(const char*); - std::string toLowerCase(const std::string); - std::map getAttributeMap(std::string); - std::string sanitizeText(std::string); - bool isAWeight(std::string); - - // Variables - edm::OwnVector weightGroups_; - std::regex weightGroupStart_; - std::regex weightGroupEnd_; - std::regex weightContent_; - - std::map nameConvMap; -}; - - -std::string -LHEWeightGroupReaderHelper::toLowerCase(const char* name) { - std::string returnStr; - for (size_t i = 0; i < strlen(name); ++i) - returnStr.push_back(tolower(name[i])); - return returnStr; -} - -std::string -LHEWeightGroupReaderHelper::toLowerCase(const std::string name) { - std::string returnStr = name; - transform(name.begin(), name.end(), returnStr.begin(), ::tolower); - return returnStr; - - -} - -void LHEWeightGroupReaderHelper::loadAttributeNames(std::string baseName, std::vector altNames) { - for(auto altname : altNames) { - nameConvMap[altname] = baseName; - } - nameConvMap[baseName] = baseName; -} - -std::string -LHEWeightGroupReaderHelper::sanitizeText(std::string line) { - std::map replaceMap = {{"<", "<"}, {">", ">"}}; - - for(auto pair: replaceMap) { - std::string badText = pair.first; - std::string goodText = pair.second; - while(line.find(badText) != std::string::npos) { - size_t spot = line.find(badText); - line.replace(spot, badText.size(), goodText); - } - } - return line; -} - - -LHEWeightGroupReaderHelper::LHEWeightGroupReaderHelper() { - weightGroupStart_ = std::regex(".*.*\n*"); - weightGroupEnd_ = std::regex(".*.*\n*"); - - std::cout << "Init" << "\n"; - - /// Might change later, order matters and code doesn't pick choices - - // Used for translating different naming convention to a common one - loadAttributeNames("muf", {"facscfact"}); - loadAttributeNames("mur", {"renscfact"}); - loadAttributeNames("id"); - loadAttributeNames("pdf", {"pdf set", "lhapdf", "pdfset"}); - loadAttributeNames("dyn_scale"); - - loadAttributeNames("combine"); - loadAttributeNames("name", {"type"}); - -} - -std::map -LHEWeightGroupReaderHelper::getAttributeMap(std::string line) { - XMLDocument xmlParser; - int error = xmlParser.Parse(line.c_str()); - if (error) { - std::cout << "we have a problem!" << "\n"; - return std::map(); - //do something.... - } - - std::map attMap; - XMLElement* element = xmlParser.FirstChildElement(); - - for( const XMLAttribute* a = element->FirstAttribute(); a; a=a->Next()) { - attMap[nameConvMap[toLowerCase(a->Name())]] = a->Value(); - } - // get stuff from content of tag if it has anything. - // always assume format is AAAAA=( )BBBB ( ) => optional space - if (element->GetText() == nullptr) { - return attMap; - } - // This adds "content: " to the beginning of the content. not sure if its a big deal or? - std::string content = element->GetText(); - attMap["content"] = content; - - std::regex reg("(?:(\\S+)=\\s*(\\S+))"); - std::smatch m; - while(std::regex_search(content, m, reg)) { - std::string key = nameConvMap[toLowerCase(m.str(1))]; - if (attMap[key] != std::string()) { - if (m[2] != attMap[key]) { - std::cout << m.str(2) << " vs " << attMap[key]; - // might do something if content and attribute don't match? - // but need to be careful since some are purposefully different - // eg dyn_scale is described in content but just given a number - } - } - else { - attMap[key] = m.str(2); - } - content = m.suffix().str(); - } - return attMap; - -} - -bool -LHEWeightGroupReaderHelper::isAWeight(std::string line) { - XMLDocument xmlParser; - int error = xmlParser.Parse(line.c_str()); - if (error) { - return false; - //do something.... - } - XMLElement* element = xmlParser.FirstChildElement(); - return element; -} - -void -LHEWeightGroupReaderHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { - // TODO: Not sure the weight indexing is right here, this seems to more or less - // count the lines which isn't quite the goal. TOCHECK! - int index = 0; - bool foundGroup = false; - - for (std::string headerLine : lheHeader) { - std::cout << "Header line is:" << headerLine; - headerLine = sanitizeText(headerLine); - std::cout << "Header line is:" << weightGroups_.size() << " "<< headerLine; - //TODO: Fine for now, but in general there should also be a check on the PDF weights, - // e.g., it could be an unknown weight - - if (std::regex_match(headerLine, weightGroupStart_)) { - //std::cout << "Adding new group for headerLine" << std::endl; - foundGroup = true; - std::string fullTag = headerLine + ""; - auto groupMap = getAttributeMap(fullTag); - std::string name = groupMap["name"]; - - if(name.find("Central scale variation") != std::string::npos || - name.find("scale_variation") != std::string::npos) { - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(name)); - } - else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(name)); - } - /// file weights - else if (foundGroup && isAWeight(headerLine)) { - //std::cout << "Adding new weight for headerLine" << std::endl; - auto tagsMap = getAttributeMap(headerLine); - for(auto pair: tagsMap) { - std::cout << pair.first << ": " << pair.second << " | "; - } - std::cout << "\n"; - - std::string content = tagsMap["content"]; - if (tagsMap["id"].empty()) { - std::cout << "error" << "\n"; - // should do something - } - - auto& group = weightGroups_.back(); - if (group.weightType() == gen::kScaleWeights) { - if (tagsMap["mur"].empty() || tagsMap["muf"].empty()) { - std::cout << "error" << "\n"; - // something should happen here - continue; - } - float muR = std::stof(tagsMap["mur"]); - float muF = std::stof(tagsMap["muf"]); - std::cout << tagsMap["id"] << " " << muR << " " << muF << " " << content << "\n"; - auto& scaleGroup = static_cast(group); - scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); - } - else - group.addContainedId(index, tagsMap["id"], headerLine); - - index++; - } - // commented out since code doesn't work with this in.... - // else if(isAWeight(headerLine)) { - // // found header. Don't know what to do with it so just shove it into a new weightgroup for now - // // do minimum work for it - // weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); - // auto& group = weightGroups_.back(); - // auto tagsMap = getAttributeMap(headerLine); - // group.addContainedId(index, tagsMap["id"], headerLine); - // foundGroup = true; - // index++; - // } - - else if(std::regex_match(headerLine, weightGroupEnd_)) { - foundGroup = false; - } - else { - std::cout << "problem!!!" << "\n"; - } - } -} - - - -#endif - - diff --git a/GeneratorInterface/Core/interface/LHEWeightHelper.h b/GeneratorInterface/Core/interface/LHEWeightHelper.h new file mode 100644 index 0000000000000..5612851f20b21 --- /dev/null +++ b/GeneratorInterface/Core/interface/LHEWeightHelper.h @@ -0,0 +1,49 @@ +#ifndef GeneratorInterface_Core_LHEWeightHelper_h +#define GeneratorInterface_Core_LHEWeightHelper_h + +#include +#include +#include +#include +#include + +#include "DataFormats/Common/interface/OwnVector.h" +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" + +#include + +namespace gen { + //class LHEWeightHelper : public GenWeightHelper { + class LHEWeightHelper { + public: + LHEWeightHelper(); + + //// possibly add more versions of this functions for different inputs + void parseLHEFile(std::string filename); + void parseWeightGroupsFromHeader(std::vector lheHeader); + + + edm::OwnVector getWeightGroups() {return weightGroups_;} + private: + void loadAttributeNames(std::string baseName, std::vector altNames ={}); + std::string toLowerCase(const char*); + std::string toLowerCase(const std::string); + std::map getAttributeMap(std::string); + std::string sanitizeText(std::string); + bool isAWeight(std::string); + + // Variables + edm::OwnVector weightGroups_; + std::regex weightGroupStart_; + std::regex weightGroupEnd_; + std::regex weightContent_; + + std::map nameConvMap; + }; +} + +#endif + diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc new file mode 100644 index 0000000000000..63966dc5ccb79 --- /dev/null +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -0,0 +1,207 @@ +#include "GeneratorInterface/Core/interface/LHEWeightHelper.h" +#include + +using namespace tinyxml2; + +namespace gen { + std::string + LHEWeightHelper::toLowerCase(const char* name) { + std::string returnStr; + for (size_t i = 0; i < strlen(name); ++i) + returnStr.push_back(tolower(name[i])); + return returnStr; + } + + std::string + LHEWeightHelper::toLowerCase(const std::string name) { + std::string returnStr = name; + transform(name.begin(), name.end(), returnStr.begin(), ::tolower); + return returnStr; + + + } + + void LHEWeightHelper::loadAttributeNames(std::string baseName, std::vector altNames) { + for(auto altname : altNames) { + nameConvMap[altname] = baseName; + } + nameConvMap[baseName] = baseName; + } + + std::string + LHEWeightHelper::sanitizeText(std::string line) { + std::map replaceMap = {{"<", "<"}, {">", ">"}}; + + for(auto pair: replaceMap) { + std::string badText = pair.first; + std::string goodText = pair.second; + while(line.find(badText) != std::string::npos) { + size_t spot = line.find(badText); + line.replace(spot, badText.size(), goodText); + } + } + return line; + } + + + LHEWeightHelper::LHEWeightHelper() { + weightGroupStart_ = std::regex(".*.*\n*"); + weightGroupEnd_ = std::regex(".*.*\n*"); + + std::cout << "Init" << "\n"; + + /// Might change later, order matters and code doesn't pick choices + + // Used for translating different naming convention to a common one + loadAttributeNames("muf", {"facscfact"}); + loadAttributeNames("mur", {"renscfact"}); + loadAttributeNames("id"); + loadAttributeNames("pdf", {"pdf set", "lhapdf", "pdfset"}); + loadAttributeNames("dyn_scale"); + + loadAttributeNames("combine"); + loadAttributeNames("name", {"type"}); + + } + + std::map + LHEWeightHelper::getAttributeMap(std::string line) { + XMLDocument xmlParser; + int error = xmlParser.Parse(line.c_str()); + if (error) { + std::cout << "we have a problem!" << "\n"; + return std::map(); + //do something.... + } + + std::map attMap; + XMLElement* element = xmlParser.FirstChildElement(); + + for( const XMLAttribute* a = element->FirstAttribute(); a; a=a->Next()) { + attMap[nameConvMap[toLowerCase(a->Name())]] = a->Value(); + } + // get stuff from content of tag if it has anything. + // always assume format is AAAAA=( )BBBB ( ) => optional space + if (element->GetText() == nullptr) { + return attMap; + } + // This adds "content: " to the beginning of the content. not sure if its a big deal or? + std::string content = element->GetText(); + attMap["content"] = content; + + std::regex reg("(?:(\\S+)=\\s*(\\S+))"); + std::smatch m; + while(std::regex_search(content, m, reg)) { + std::string key = nameConvMap[toLowerCase(m.str(1))]; + if (attMap[key] != std::string()) { + if (m[2] != attMap[key]) { + std::cout << m.str(2) << " vs " << attMap[key]; + // might do something if content and attribute don't match? + // but need to be careful since some are purposefully different + // eg dyn_scale is described in content but just given a number + } + } + else { + attMap[key] = m.str(2); + } + content = m.suffix().str(); + } + return attMap; + + } + + bool + LHEWeightHelper::isAWeight(std::string line) { + XMLDocument xmlParser; + int error = xmlParser.Parse(line.c_str()); + if (error) { + return false; + //do something.... + } + XMLElement* element = xmlParser.FirstChildElement(); + return element; + } + + void + LHEWeightHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { + // TODO: Not sure the weight indexing is right here, this seems to more or less + // count the lines which isn't quite the goal. TOCHECK! + int index = 0; + bool foundGroup = false; + + for (std::string headerLine : lheHeader) { + std::cout << "Header line is:" << headerLine; + headerLine = sanitizeText(headerLine); + std::cout << "Header line is:" << weightGroups_.size() << " "<< headerLine; + //TODO: Fine for now, but in general there should also be a check on the PDF weights, + // e.g., it could be an unknown weight + + if (std::regex_match(headerLine, weightGroupStart_)) { + //std::cout << "Adding new group for headerLine" << std::endl; + foundGroup = true; + std::string fullTag = headerLine + ""; + auto groupMap = getAttributeMap(fullTag); + std::string name = groupMap["name"]; + + if(name.find("Central scale variation") != std::string::npos || + name.find("scale_variation") != std::string::npos) { + weightGroups_.push_back(new gen::ScaleWeightGroupInfo(name)); + } + else + weightGroups_.push_back(new gen::PdfWeightGroupInfo(name)); + } + /// file weights + else if (foundGroup && isAWeight(headerLine)) { + //std::cout << "Adding new weight for headerLine" << std::endl; + auto tagsMap = getAttributeMap(headerLine); + for(auto pair: tagsMap) { + std::cout << pair.first << ": " << pair.second << " | "; + } + std::cout << "\n"; + + std::string content = tagsMap["content"]; + if (tagsMap["id"].empty()) { + std::cout << "error" << "\n"; + // should do something + } + + auto& group = weightGroups_.back(); + if (group.weightType() == gen::kScaleWeights) { + if (tagsMap["mur"].empty() || tagsMap["muf"].empty()) { + std::cout << "error" << "\n"; + // something should happen here + continue; + } + float muR = std::stof(tagsMap["mur"]); + float muF = std::stof(tagsMap["muf"]); + std::cout << tagsMap["id"] << " " << muR << " " << muF << " " << content << "\n"; + auto& scaleGroup = static_cast(group); + scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); + } + else + group.addContainedId(index, tagsMap["id"], headerLine); + + index++; + } + // commented out since code doesn't work with this in.... + // else if(isAWeight(headerLine)) { + // // found header. Don't know what to do with it so just shove it into a new weightgroup for now + // // do minimum work for it + // weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); + // auto& group = weightGroups_.back(); + // auto tagsMap = getAttributeMap(headerLine); + // group.addContainedId(index, tagsMap["id"], headerLine); + // foundGroup = true; + // index++; + // } + + else if(std::regex_match(headerLine, weightGroupEnd_)) { + foundGroup = false; + } + else { + std::cout << "problem!!!" << "\n"; + } + } + } +} + diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 43ba899a0e394..42460852d5a3e 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -58,7 +58,8 @@ Description: [one line class summary] #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" #include "GeneratorInterface/LHEInterface/interface/LHEReader.h" #include "GeneratorInterface/LHEInterface/interface/TestWeightInfo.h" -#include "GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h" +//#include "GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h" +#include "GeneratorInterface/Core/interface/LHEWeightHelper.h" #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Utilities/interface/RandomNumberGenerator.h" @@ -374,11 +375,11 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) weightInfoProduct_ = std::make_unique(); - LHEWeightGroupReaderHelper reader; + gen::LHEWeightHelper weightHelper; //reader.parseLHEFile(LHEfilename); - reader.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); + weightHelper.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); - for (auto& weightGroup : reader.getWeightGroups()) { + for (auto& weightGroup : weightHelper.getWeightGroups()) { if (weightGroup.weightType() == 1) { gen::ScaleWeightGroupInfo* group = static_cast(weightGroup.clone()); std::cout << "MuR1MuF2Index is " << group->muR1muF2Index(); From a78163bbeb32b5b41fcee8628ff1c1a3e1995d1c Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sat, 21 Sep 2019 12:35:22 -0400 Subject: [PATCH 36/75] Separate WeightHelper into base and daughter classes --- .../Core/interface/LHEWeightHelper.h | 11 +--- .../Core/interface/WeightHelper.h | 22 +++++++ GeneratorInterface/Core/src/WeightHelper.cc | 44 +++++++++++++ .../plugins/ExternalLHEProducer.cc | 65 +++---------------- 4 files changed, 78 insertions(+), 64 deletions(-) create mode 100644 GeneratorInterface/Core/interface/WeightHelper.h create mode 100644 GeneratorInterface/Core/src/WeightHelper.cc diff --git a/GeneratorInterface/Core/interface/LHEWeightHelper.h b/GeneratorInterface/Core/interface/LHEWeightHelper.h index 5612851f20b21..8beb9dbbca21e 100644 --- a/GeneratorInterface/Core/interface/LHEWeightHelper.h +++ b/GeneratorInterface/Core/interface/LHEWeightHelper.h @@ -7,26 +7,21 @@ #include #include -#include "DataFormats/Common/interface/OwnVector.h" -#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include "GeneratorInterface/Core/interface/WeightHelper.h" #include namespace gen { - //class LHEWeightHelper : public GenWeightHelper { - class LHEWeightHelper { + class LHEWeightHelper : public WeightHelper { public: LHEWeightHelper(); //// possibly add more versions of this functions for different inputs void parseLHEFile(std::string filename); void parseWeightGroupsFromHeader(std::vector lheHeader); - - - edm::OwnVector getWeightGroups() {return weightGroups_;} private: void loadAttributeNames(std::string baseName, std::vector altNames ={}); std::string toLowerCase(const char*); @@ -35,8 +30,6 @@ namespace gen { std::string sanitizeText(std::string); bool isAWeight(std::string); - // Variables - edm::OwnVector weightGroups_; std::regex weightGroupStart_; std::regex weightGroupEnd_; std::regex weightContent_; diff --git a/GeneratorInterface/Core/interface/WeightHelper.h b/GeneratorInterface/Core/interface/WeightHelper.h new file mode 100644 index 0000000000000..64e1fb196d5d7 --- /dev/null +++ b/GeneratorInterface/Core/interface/WeightHelper.h @@ -0,0 +1,22 @@ +#ifndef GeneratorInterface_LHEInterface_WeightHelper_h +#define GeneratorInterface_LHEInterface_WeightHelper_h + +#include "DataFormats/Common/interface/OwnVector.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/WeightsInfo.h" + +namespace gen { + class WeightHelper { + public: + WeightHelper() {} + edm::OwnVector weightGroups() {return weightGroups_;} + std::unique_ptr weightProduct(std::vector); + int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex); + protected: + edm::OwnVector weightGroups_; + }; +} + +#endif + diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc new file mode 100644 index 0000000000000..98a38a34e9c5d --- /dev/null +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -0,0 +1,44 @@ +#include "GeneratorInterface/Core/interface/WeightHelper.h" + +namespace gen { + std::unique_ptr WeightHelper::weightProduct(std::vector weights) { + auto weightProduct = std::make_unique(); + weightProduct->setNumWeightSets(weightGroups_.size()); + int weightGroupIndex = 0; + int weightNum = 0; + for (const auto& weight : weights) { + weightGroupIndex = findContainingWeightGroup(weight.id, weightNum, weightGroupIndex); + if (weightGroupIndex < 0 || weightGroupIndex >= static_cast(weightGroups_.size())) { + // Needs to be properly handled + throw std::range_error("Unmatched weight"); + } + auto group = weightGroups_[weightGroupIndex]; + int entry = group.weightVectorEntry(weight.id, weightNum); + weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); + weightNum++; + } + return std::move(weightProduct); + } + + int WeightHelper::findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex) { + // Start search at previous index, under expectation of ordered weights + previousGroupIndex = previousGroupIndex >=0 ? previousGroupIndex : 0; + for (int index = previousGroupIndex; + index < std::min(index+1, static_cast(weightGroups_.size())); index++) { + const gen::WeightGroupInfo& weightGroup = weightGroups_[index]; + if (weightGroup.indexInRange(weightIndex) && weightGroup.containsWeight(wgtId, weightIndex)) { + return static_cast(index); + } + } + + // Fall back to unordered search + int counter = 0; + for (auto weightGroup : weightGroups_) { + if (weightGroup.containsWeight(wgtId, weightIndex)) + return counter; + counter++; + } + return -1; + } +} + diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 42460852d5a3e..d9d8c710ff16c 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -106,9 +106,9 @@ class ExternalLHEProducer : public edm::one::EDProducer> nPartonMapping_{}; std::unique_ptr reader_; + gen::LHEWeightHelper weightHelper_; std::shared_ptr runInfoLast; std::shared_ptr runInfo; - std::unique_ptr weightInfoProduct_; std::shared_ptr partonLevel; boost::ptr_deque runInfoProducts; bool wasMerged; @@ -209,21 +209,8 @@ ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) boost::bind(&LHEEventProduct::addWeight, product.get(), _1)); - auto weightProduct = std::make_unique(); - weightProduct->setNumWeightSets(weightInfoProduct_->numberOfGroups()); - int weightGroupIndex = 0; - int weightNum = 0; - for (const auto& weight : partonLevel->weights()) { - weightGroupIndex = findWeightGroup(weight.id, weightNum, weightGroupIndex); - if (weightGroupIndex < 0 || weightGroupIndex >= weightInfoProduct_->numberOfGroups()) { - // Needs to be properly handled - throw std::range_error("Unmatched weight"); - } - auto* group = weightInfoProduct_->orderedWeightGroupInfo(weightGroupIndex); - int entry = group->weightVectorEntry(weight.id, weightNum); - weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); - weightNum++; - } + // Should also zero out the weights in the GenInfoProduct + auto weightProduct = weightHelper_.weightProduct(partonLevel->weights()); iEvent.put(std::move(weightProduct)); product->setScales(partonLevel->scales()); @@ -373,21 +360,8 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) run.put(std::move(product)); - weightInfoProduct_ = std::make_unique(); - - gen::LHEWeightHelper weightHelper; - //reader.parseLHEFile(LHEfilename); - weightHelper.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); + weightHelper_.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); - for (auto& weightGroup : weightHelper.getWeightGroups()) { - if (weightGroup.weightType() == 1) { - gen::ScaleWeightGroupInfo* group = static_cast(weightGroup.clone()); - std::cout << "MuR1MuF2Index is " << group->muR1muF2Index(); - } - - weightInfoProduct_->addWeightGroupInfo(weightGroup.clone()); - } - runInfo.reset(); } } @@ -411,7 +385,12 @@ ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) } reader_.reset(); - run.put(std::move(weightInfoProduct_)); + + auto weightInfoProduct = std::make_unique(); + for (auto& weightGroup : weightHelper_.weightGroups()) { + weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); + } + run.put(std::move(weightInfoProduct)); if (unlink(outputFile_.c_str())) { throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ")."; @@ -543,30 +522,6 @@ ExternalLHEProducer::executeScript() } -int ExternalLHEProducer::findWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex) { - // Start search at previous index, under expectation of ordered weights - previousGroupIndex = previousGroupIndex >=0 ? previousGroupIndex : 0; - for (int index = previousGroupIndex; - index < std::min(index+1, static_cast(weightInfoProduct_->numberOfGroups())); index++) { - const gen::WeightGroupInfo* weightGroup = weightInfoProduct_->orderedWeightGroupInfo(index); - // index < std::min(index+1, static_cast(weightGroups_.size())); index++) { - //gen::WeightGroupInfo& weightGroup = weightGroups_[previousGroupIndex]; - // Fast search assuming order is not perturbed outside of weight group - if (weightGroup->indexInRange(weightIndex) && weightGroup->containsWeight(wgtId, weightIndex)) { - return static_cast(index); - } - } - - // Fall back to unordered search - int counter = 0; - for (auto weightGroup : weightInfoProduct_->allWeightGroupsInfo()) { - if (weightGroup.containsWeight(wgtId, weightIndex)) - return counter; - counter++; - } - return -1; -} - // ------------ Read the output script ------------ #define BUFSIZE 4096 std::unique_ptr ExternalLHEProducer::readOutput() From b6e3285ab650f7c00ea64adcada148c9121de778 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 23 Sep 2019 18:58:12 -0400 Subject: [PATCH 37/75] Producer or MiniAOD is finally working --- .../Core/plugins/LHEWeightProductProducer.cc | 106 ++++++++++++++++++ .../Core/test/testLHEWeightProducer_cfg.py | 24 ++++ .../LHEInterface/test/testWeights.py | 7 +- .../LHEInterface/test/test_Weights_cfg.py | 1 - TestWeightInfo/TestAnalyzer/test/test_cfg.py | 4 +- 5 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc create mode 100644 GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc new file mode 100644 index 0000000000000..3faed748e6a05 --- /dev/null +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -0,0 +1,106 @@ +#include +#include +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDProducer.h" +#include "FWCore/Framework/interface/LuminosityBlock.h" + +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/FileInPath.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" + +#include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" +#include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" +#include "GeneratorInterface/Core/interface/LHEWeightHelper.h" + +#include "FWCore/ServiceRegistry/interface/Service.h" + +class LHEWeightProductProducer : public edm::one::EDProducer { +public: + explicit LHEWeightProductProducer(const edm::ParameterSet& iConfig); + ~LHEWeightProductProducer() override; + +private: + gen::LHEWeightHelper weightHelper_; + edm::EDGetTokenT lheRunInfoToken_; + edm::EDGetTokenT lheEventToken_; + + void produce(edm::Event&, const edm::EventSetup&) override; + void beginRunProduce(edm::Run& run, edm::EventSetup const& es) override; + void endRunProduce(edm::Run&, edm::EventSetup const&) override; + +}; + +// +// constructors and destructor +// +LHEWeightProductProducer::LHEWeightProductProducer(const edm::ParameterSet& iConfig) : + lheRunInfoToken_(consumes(edm::InputTag("externalLHEProducer"))), + //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))), + lheEventToken_(consumes(edm::InputTag("externalLHEProducer"))) + //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) +{ + produces(); + produces(); +} + + +LHEWeightProductProducer::~LHEWeightProductProducer() +{ +} + + +// ------------ method called to produce the data ------------ +void +LHEWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + edm::Handle lheEventInfo; + iEvent.getByToken(lheEventToken_, lheEventInfo); + // Read weights from LHEEventProduct + auto weightProduct = weightHelper_.weightProduct(lheEventInfo->weights()); + iEvent.put(std::move(weightProduct)); +} + +// ------------ method called when starting to processes a run ------------ +void +LHEWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) { + edm::Handle lheRunInfoHandle; + //run.getByToken(lheRunInfoToken_, lheRunInfoHandle); + // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) + run.getByLabel("externalLHEProducer", lheRunInfoHandle); + + std::cout << "In the run" << std::endl; + typedef std::vector::const_iterator header_cit; + LHERunInfoProduct::Header headerWeightInfo; + for (header_cit iter=lheRunInfoHandle->headers_begin(); iter!=lheRunInfoHandle->headers_end(); iter++) { + //for (header_cit iter=lheRunInfoProduct.headers_begin(); iter!=lheRunInfoProduct.headers_end(); iter++) { + if (iter->tag() == "initrwgt") + headerWeightInfo = *iter; + } + + weightHelper_.parseWeightGroupsFromHeader(headerWeightInfo.lines()); +} + + +// ------------ method called when ending the processing of a run ------------ +void +LHEWeightProductProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) { + auto weightInfoProduct = std::make_unique(); + for (auto& weightGroup : weightHelper_.weightGroups()) { + weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); + } + run.put(std::move(weightInfoProduct)); +} + +DEFINE_FWK_MODULE(LHEWeightProductProducer); + diff --git a/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py b/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py new file mode 100644 index 0000000000000..72b9ed16248f3 --- /dev/null +++ b/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py @@ -0,0 +1,24 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("test") + +process.source = cms.Source("PoolSource", + # replace 'myfile.root' with the source file you want to use + #fileNames = cms.untracked.vstring("/store/mc/RunIISummer16MiniAODv3/WJetsToLNu_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_94X_mcRun2_asymptotic_v3-v2/20000/CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root") + fileNames = cms.untracked.vstring("file:CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root"), +) + +process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(100)) + +process.out = cms.OutputModule("PoolOutputModule", + fileName = cms.untracked.string('test.root'), + outputCommands = cms.untracked.vstring(['keep *']) +) + +process.testWeights = cms.EDProducer("LHEWeightProductProducer") + +process.p = cms.Path(process.testWeights) + +process.output = cms.EndPath(process.out) +process.schedule = cms.Schedule(process.p,process.output) + diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/LHEInterface/test/testWeights.py index c145a34497c11..2140372c5c5f0 100644 --- a/GeneratorInterface/LHEInterface/test/testWeights.py +++ b/GeneratorInterface/LHEInterface/test/testWeights.py @@ -1,9 +1,11 @@ from DataFormats.FWLite import Events,Handle,Runs import ROOT -source = "externalLHEProducer" +#source = "externalLHEProducer" +source = "testWeights" #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: -for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: +#for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: +for filename in ["test.root"]: runs = Runs(filename) run = runs.__iter__().next() weightInfoHandle = Handle("LHEWeightInfoProduct") @@ -13,7 +15,6 @@ events = Events(filename) event = events.__iter__().next() weightHandle = Handle("LHEWeightProduct") - event.getByLabel("externalLHEProducer", weightHandle) event.getByLabel(source, weightHandle) weightInfo = weightHandle.product() print "Content of the weights" diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py index f4cbf5ce94694..24846755a78be 100644 --- a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -34,7 +34,6 @@ ) # Output definition - process.LHEoutput = cms.OutputModule("PoolOutputModule", dataset = cms.untracked.PSet( dataTier = cms.untracked.string('LHE'), diff --git a/TestWeightInfo/TestAnalyzer/test/test_cfg.py b/TestWeightInfo/TestAnalyzer/test/test_cfg.py index cdb44a5404eb5..f856a8ce87a42 100644 --- a/TestWeightInfo/TestAnalyzer/test/test_cfg.py +++ b/TestWeightInfo/TestAnalyzer/test/test_cfg.py @@ -4,14 +4,14 @@ process.source = cms.Source("PoolSource", # replace 'myfile.root' with the source file you want to use - fileNames = cms.untracked.vstring("file:HIG-RunIIFall18wmLHEGS-00509.root") + fileNames = cms.untracked.vstring("/store/mc/RunIISummer16MiniAODv3/WJetsToLNu_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_94X_mcRun2_asymptotic_v3-v2/20000/CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root") ) process.TFileService = cms.Service("TFileService", fileName = cms.string("test.root") ) -process.testWeights = cms.EDAnalyzer("TestAnalyzer") +process.testWeights = cms.EDAnalyzer("LHEWeightProductProducer") process.p = cms.Path(process.testWeights) From c82792f33130092fba6fa07871218dadcdbcb830 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Tue, 24 Sep 2019 07:59:23 -0400 Subject: [PATCH 38/75] Add outline of Zplotter (from Andreas) with weights implemented --- .../Core/plugins/LHEWeightProductProducer.cc | 1 - .../LHEInterface/plugins/LHEWeightsTest.cc | 451 ++++++++++++++++++ 2 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index 3faed748e6a05..3e17e7f181879 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -79,7 +79,6 @@ LHEWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) run.getByLabel("externalLHEProducer", lheRunInfoHandle); - std::cout << "In the run" << std::endl; typedef std::vector::const_iterator header_cit; LHERunInfoProduct::Header headerWeightInfo; for (header_cit iter=lheRunInfoHandle->headers_begin(); iter!=lheRunInfoHandle->headers_end(); iter++) { diff --git a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc new file mode 100644 index 0000000000000..799a56d7426d4 --- /dev/null +++ b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc @@ -0,0 +1,451 @@ +// -*- C++ -*- +// +// Package: GenAnalysis/MergingAnalyzer +// Class: MergingAnalyzer +// +/**\class MergingAnalyzer MergingAnalyzer.cc GenAnalysis/MergingAnalyzer/plugins/MergingAnalyzer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Andreas Artur Eugen Albert +// Created: Fri, 21 Jul 2017 11:42:52 GMT +// +// + + +// system include files +#include +#include // std::pair +// user include files +#include +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/METReco/interface/GenMET.h" +#include "DataFormats/METReco/interface/GenMETCollection.h" +#include "DataFormats/JetReco/interface/GenJetCollection.h" + +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" + +#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" + +#include "Math/VectorUtil.h" + +#include +#include +#include +#include +// +// class declaration +// + +// If the analyzer does not use TFileService, please remove +// the template argument to the base class so the class inherits +// from edm::one::EDAnalyzer<> and also remove the line from +// constructor "usesResource("TFileService");" +// This will improve performance in multithreaded jobs. + +class MergingAnalyzer : public edm::one::EDAnalyzer { + public: + explicit MergingAnalyzer(const edm::ParameterSet&); + ~MergingAnalyzer(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + + private: + virtual void beginJob() override; + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; + + void setup_variables(const edm::Event& iEvent); + + // ----------member data --------------------------- + std::string tag_; + bool isMiniaod_; + std::vector scaleWeightOrder_; + + edm::EDGetTokenT genParticleToken_; + edm::EDGetTokenT genJetToken_; + edm::EDGetTokenT LHEToken_; + edm::EDGetTokenT GenToken_; + edm::Service fileservice; + + std::map histograms2d; + std::map histograms1d; + + TTree * tree; + std::map variables; + + TNamed * filelist; + + TH1D * h_count_event; + TH1D * h_count_sumw; +}; + +// +// constants, enums and typedefs +// + +// +// static data member definitions +// + +// +// constructors and destructor +// +MergingAnalyzer::MergingAnalyzer(const edm::ParameterSet& iConfig) : + tag_(iConfig.getParameter("tag")), + isMiniaod_(iConfig.getParameter("miniaod")), + genParticleToken_(consumes(iConfig.getParameter("genParticleSrc"))), + genJetToken_(consumes(iConfig.getParameter("genJetSrc"))), + LHEToken_(consumes(iConfig.getParameter("LHESrc"))), + GenToken_(consumes(iConfig.getParameter("GenSrc"))) + + +{ + //now do what ever initialization is needed + usesResource("TFileService"); + TFileDirectory subdirectory = fileservice->mkdir( tag_ ); + + h_count_event = subdirectory.make("h_count_event", "h_count_event;Dummy;Events", 1,0,1); + h_count_sumw = subdirectory.make("h_count_sumw", "h_count_sumw;Weight index;Events", 1,0,1); + + int nweights = 1200; + histograms2d["pt_jet1"] = subdirectory.make("pt_jet1", "Leading jet pt;pt_{jet};weight;Events",200,0,1000, nweights, -0.5, nweights-0.5); + histograms2d["pt_jet2"] = subdirectory.make("pt_jet2", "Trailing jet pt;pt_{jet};weight;Events",200,0,1000, nweights, -0.5, nweights-0.5); + histograms2d["pt_jet3"] = subdirectory.make("pt_jet3", "3rd jet pt;pt_{jet};weight;Events",200,0,1000, nweights, -0.5, nweights-0.5); + histograms2d["pt_jet4"] = subdirectory.make("pt_jet4", "4th jet pt;pt_{jet};weight;Events",200,0,1000, nweights, -0.5, nweights-0.5); + histograms2d["ht"] = subdirectory.make("ht", "HT;HT (GeV);weight;Events",200,0,2000, nweights, -0.5, nweights-0.5); + histograms2d["dilepton_pt"] = subdirectory.make("dilepton_pt", "Dilepton p_{T}; p_{T} (GeV);weight;Events",200,0,2000, nweights, -0.5, nweights-0.5); + histograms2d["n_leptons"] = subdirectory.make("n_leptons", "number of leptons;n_lep;weight;Events",10,-0.5,9.5, nweights, -0.5, nweights-0.5); + + // histograms2d["njet"] = subdirectory.make("njet_over_pt", "pt threshold;njet;Events",10,-5,95,10,-0.5,9.5); + + tree = subdirectory.make("events","events"); + for(auto const entry : histograms1d){ + tree->Branch(entry.first, &variables[entry.first],(entry.first+"/D").Data()); + } + filelist = subdirectory.make(tag_,tag_); +} + + +MergingAnalyzer::~MergingAnalyzer() +{ + + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) + +} + + +// +// member functions +// +bool compare_pt(reco::GenParticle p1, reco::GenParticle p2){ + return p2.pt() < p1.pt(); +} +std::vector select_leptons(const std::vector genParticles) { + std::vector leptons; + for (auto const p : genParticles){ + unsigned const int id = abs(p.pdgId()); + if(p.numberOfDaughters() > 0) continue; + else if(p.pt()<20) continue; + else if(not ((id==11)||(id==13)) ) continue; + else leptons.push_back(p); + } + std::sort(leptons.begin(), leptons.end(), compare_pt ); + return leptons; +} +std::vector select_neutrinos(const std::vector genParticles) { + std::vector neutrinos; + for (auto const p : genParticles){ + unsigned const int id = abs(p.pdgId()); + if(p.pt() < 25) continue; + else if(p.numberOfDaughters() > 0) continue; + else if(not ((id==12)||(id==14)||(id==16)) ) continue; + else neutrinos.push_back(p); + } + std::sort(neutrinos.begin(), neutrinos.end(), compare_pt ); + return neutrinos; +} + +std::vector select_jets(const std::vector genJets) { + std::vector jets; + for (auto const p : genJets){ + if(fabs(p.pt()) < 10) continue; + else jets.push_back(p); + } + std::sort(jets.begin(), jets.end(), compare_pt ); + return jets; +} + +std::pair find_z_candidate(std::vector & genParticles) { + double delta_mass_min = 9999; + double m_z = 91; + reco::GenParticle p1,p2; + for( unsigned int i = 0; i < genParticles.size(); i++ ) { + for( unsigned int j = i+1; j < genParticles.size(); j++ ) { + auto candidate_p4 = genParticles.at(i).p4() + genParticles.at(j).p4(); + double dm = fabs(candidate_p4.mass()-m_z); + if(dm < delta_mass_min ) { + delta_mass_min = dm; + p1 = genParticles.at(i); + p2 = genParticles.at(j); + } + } + } + return std::make_pair(p1,p2); +} +reco::Candidate const * find_first_mother_with_different_id( reco::Candidate const * daughter ){ + reco::Candidate const * mother = daughter->mother(0); + if(abs(mother->pdgId()) != abs(daughter->pdgId())) { + return mother; + }else{ + return find_first_mother_with_different_id(mother); + } +} + +std::vector clean_jets(const std::vector genJets, const std::vector leptons){ + std::vector cleaned_jets; + cleaned_jets.reserve(genJets.size()); + for( auto const jet : genJets ) { + double delta_r_min = 999; + double eta = jet.eta(); + double phi = jet.phi(); + for( auto const lep : leptons ) { + double delta_r = pow((pow(lep.eta() - eta,2) + pow(lep.phi() - phi,2)),0.5); + if (delta_r < delta_r_min){ + delta_r_min = delta_r; + } + } + if(delta_r_min < 0.4) { + continue; + } else { + cleaned_jets.push_back(jet); + } + } + return cleaned_jets; +} +void print_variables(std::map variables) { + +} +double delta_phi(reco::Candidate::LorentzVector const & p1,reco::Candidate::LorentzVector const & p2) { + double dphi_raw = fabs(p1.phi() - p2.phi()); + if(dphi_raw > M_PI){ + return 2*M_PI - dphi_raw; + } else { + return dphi_raw; + } +} +//// Parse generator history of particle and look for +bool has_v_in_history(reco::GenParticle const & part){ + size_t nmothers = part.numberOfMothers(); + if(nmothers == 0) { + return false; + } else { + for( size_t im = 0; im < nmothers; im++ ){ + auto const & mother = *(part.motherRef(im)); + + if(mother.pdgId() == 23 or mother.pdgId() == 24) { + return true; + } else if( has_v_in_history(*(part.motherRef(im))) ) { + return true; + } + } + return false; + } +} +std::vector clean_v_jets(const std::vector & genJets){ + std::vector cleaned; + for( auto const & j : genJets ) { + bool found = false; + for( auto const & c: j.getGenConstituents() ) { + found |= has_v_in_history(*c); + if(found) break; + } + if(not found){ + cleaned.push_back(j); + } + } + + return cleaned; +} + + +void MergingAnalyzer::setup_variables(const edm::Event& iEvent) { + using namespace edm; + + + //// Initialize with dummy values + for ( auto pair : variables ) { + variables[pair.first] = -9999; + } + + Handle> genParticleHandle; + iEvent.getByToken(genParticleToken_, genParticleHandle); + const std::vector * genParticles = genParticleHandle.product(); + + Handle> genJetHandle; + iEvent.getByToken(genJetToken_, genJetHandle); + const std::vector * genJets = genJetHandle.product(); + + edm::Handle lheHandle; + iEvent.getByLabel("externalLHEProducer", lheHandle); + const LHEEventProduct * lhe = lheHandle.product(); + + + + + variables["weight"] = lhe->originalXWGTUP(); + + //~ //// Leptons + std::vector leptons = select_leptons(*genParticles); + variables["n_leptons"] = leptons.size(); + + if(leptons.size() >= 2) { + auto z_cand = find_z_candidate(leptons); + variables["dilepton_pt"] = (z_cand.first.p4() + z_cand.second.p4()).pt(); + } + //// Jets + std::vector jets = clean_v_jets(clean_jets(select_jets(*genJets),leptons)); + int njets = jets.size(); + variables["n_jets"] = njets; + if(njets>0){ + variables["pt_jet1"] = jets.at(0).pt() ; + } + if(njets>1){ + variables["pt_jet2"] = jets.at(1).pt() ; + } + if(njets>2){ + variables["pt_jet3"] = jets.at(2).pt() ; + } + if(njets>3){ + variables["pt_jet4"] = jets.at(3).pt() ; + } + + + // for (unsigned int i = 0; i<=10; i++){ + + // float threshold = i*10; + // int njet = 0; + // for ( auto const & j : jets ) { + // if(j.pt() > threshold){ + // njet++; + // } + // } + // histograms2d["njet"]->Fill(threshold,njet,variables["weight"]); + // } + + double ht = 0; + for(auto const & j : jets){ + ht += j.pt(); + } + variables["ht"] = ht; + +} +std::vector setup_weights(const edm::Event& iEvent) { + edm::Handle lheHandle; + iEvent.getByLabel("testWeights", lheHandle); + const LHEWeightProduct * lheWeights = lheHandle.product(); + std::vector weights = lheWeights.weights(); + + for(auto i : scaleWeightOrder_){ + weights.push_back(weights[i]); + } + return weights; +} + + +// ------------ method called for each event ------------ +void +MergingAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + + setup_variables(iEvent); + tree->Fill(); + auto weights = setup_weights(iEvent); + h_count_event->Fill(0.5); + h_count_sumw->Fill(0.5,weights.at(0)); + + for( auto pair : histograms2d ) { + for(uint i=0; i -9998){ + pair.second->Fill(value,i,weights.at(i)); + } + } + } +} + + +// ------------ method called once each job just before starting event loop ------------ +void +MergingAnalyzer::beginJob() +{ +} + +// ------------ method called once each job just after ending the event loop ------------ +void +MergingAnalyzer::endJob() +{ +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +MergingAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +void +LHEWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) { + edm::Handle lheWeightInfoHandle; + // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) + run.getByLabel("testWeights", lheWeightInfoHandle); + + // Should add a search by name function + gen::ScaleWeightGroup scaleWeightInfo; + for (const auto& group : lheWeightInfoHandle->allWeightGroupsInfo()) { + if (std::find("scale", group.name()) != std::string::npos) { + scaleWeightInfo = group; + break; + } + } + + // nano ordering of mur=0.5 muf=0.5 ; [1] is mur=0.5 muf=1 ; [2] is mur=0.5 muf=2 ; [3] is mur=1 muf=0.5 ; + // [4] is mur=1 muf=1 ; [5] is mur=1 muf=2 ; [6] is mur=2 muf=0.5 ; [7] is mur=2 muf=1 ; [8] is mur=2 muf=2 * + scaleWeightOrder_ = { group.muR05muF05Index(), + group.muR05muF1Index(), + group.muR05muF2Index(), + group.muR1muF05Index(), + group.centralIndex(), + group.muR1muF2Index(), + group.muR2muF05Index(), + group.muR2muF1Index(), + group.muR2muF2Index(), + } + +} + +//define this as a plug-in +DEFINE_FWK_MODULE(MergingAnalyzer); + From ffd0503039329ada0dc9713ba88ef6b83dfcf8ed Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Tue, 24 Sep 2019 19:36:57 -0400 Subject: [PATCH 39/75] Working example of plotting code reading weight products --- .../Core/plugins/LHEWeightProductProducer.cc | 12 +- .../Core/test/testLHEWeightProducer_cfg.py | 4 +- .../LHEInterface/plugins/BuildFile.xml | 11 ++ .../LHEInterface/plugins/LHEWeightsTest.cc | 154 +++++++++--------- .../test/test_ZPlotting_LHEweights_cfg.py | 77 +++++++++ .../interface/LHEWeightInfoProduct.h | 2 + .../src/LHEWeightInfoProduct.cc | 18 ++ .../src/ScaleWeightGroupInfo.cc | 3 +- 8 files changed, 192 insertions(+), 89 deletions(-) create mode 100644 GeneratorInterface/LHEInterface/test/test_ZPlotting_LHEweights_cfg.py diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index 3e17e7f181879..a3bc3b5faf1c4 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -52,7 +52,7 @@ LHEWeightProductProducer::LHEWeightProductProducer(const edm::ParameterSet& iCon //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) { produces(); - produces(); + produces(); } @@ -88,17 +88,17 @@ LHEWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& } weightHelper_.parseWeightGroupsFromHeader(headerWeightInfo.lines()); + auto weightInfoProduct = std::make_unique(); + for (auto& weightGroup : weightHelper_.weightGroups()) { + weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); + } + run.put(std::move(weightInfoProduct)); } // ------------ method called when ending the processing of a run ------------ void LHEWeightProductProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) { - auto weightInfoProduct = std::make_unique(); - for (auto& weightGroup : weightHelper_.weightGroups()) { - weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); - } - run.put(std::move(weightInfoProduct)); } DEFINE_FWK_MODULE(LHEWeightProductProducer); diff --git a/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py b/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py index 72b9ed16248f3..2330e55313fb1 100644 --- a/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py +++ b/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py @@ -4,8 +4,8 @@ process.source = cms.Source("PoolSource", # replace 'myfile.root' with the source file you want to use - #fileNames = cms.untracked.vstring("/store/mc/RunIISummer16MiniAODv3/WJetsToLNu_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_94X_mcRun2_asymptotic_v3-v2/20000/CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root") - fileNames = cms.untracked.vstring("file:CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root"), + fileNames = cms.untracked.vstring("/store/mc/RunIISummer16MiniAODv3/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_94X_mcRun2_asymptotic_v3_ext1-v2/120000/CC675D46-5EDF-E811-B537-3CFDFE63DF40.root") + #fileNames = cms.untracked.vstring("file:CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root"), ) process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(100)) diff --git a/GeneratorInterface/LHEInterface/plugins/BuildFile.xml b/GeneratorInterface/LHEInterface/plugins/BuildFile.xml index e585d6c7a8f48..c9f6865d98d5a 100644 --- a/GeneratorInterface/LHEInterface/plugins/BuildFile.xml +++ b/GeneratorInterface/LHEInterface/plugins/BuildFile.xml @@ -23,3 +23,14 @@ + + + + + + + + + + + diff --git a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc index 799a56d7426d4..d3201a85f97ee 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc @@ -1,9 +1,9 @@ // -*- C++ -*- // -// Package: GenAnalysis/MergingAnalyzer -// Class: MergingAnalyzer +// Package: GenAnalysis/LHEWeightsTest +// Class: LHEWeightsTest // -/**\class MergingAnalyzer MergingAnalyzer.cc GenAnalysis/MergingAnalyzer/plugins/MergingAnalyzer.cc +/**\class LHEWeightsTest LHEWeightsTest.cc GenAnalysis/LHEWeightsTest/plugins/LHEWeightsTest.cc Description: [one line class summary] @@ -26,6 +26,7 @@ #include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Run.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -42,6 +43,13 @@ #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" + +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" + #include "Math/VectorUtil.h" #include @@ -58,30 +66,36 @@ // constructor "usesResource("TFileService");" // This will improve performance in multithreaded jobs. -class MergingAnalyzer : public edm::one::EDAnalyzer { +class LHEWeightsTest : public edm::one::EDAnalyzer { public: - explicit MergingAnalyzer(const edm::ParameterSet&); - ~MergingAnalyzer(); + explicit LHEWeightsTest(const edm::ParameterSet&); + ~LHEWeightsTest(); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: virtual void beginJob() override; + virtual void endRun(edm::Run const& iRun, edm::EventSetup const&) {} + virtual void beginRun(edm::Run const& iRun, edm::EventSetup const&) override; virtual void analyze(const edm::Event&, const edm::EventSetup&) override; virtual void endJob() override; void setup_variables(const edm::Event& iEvent); + std::vector setup_weights(const edm::Event& iEvent); // ----------member data --------------------------- std::string tag_; bool isMiniaod_; - std::vector scaleWeightOrder_; + std::vector scaleWeightsOrder_; + unsigned int scaleWeightsIndex_; edm::EDGetTokenT genParticleToken_; edm::EDGetTokenT genJetToken_; edm::EDGetTokenT LHEToken_; edm::EDGetTokenT GenToken_; + edm::EDGetTokenT lheWeightToken_; + edm::EDGetTokenT lheWeightInfoToken_; edm::Service fileservice; std::map histograms2d; @@ -107,18 +121,19 @@ class MergingAnalyzer : public edm::one::EDAnalyzer // // constructors and destructor // -MergingAnalyzer::MergingAnalyzer(const edm::ParameterSet& iConfig) : +LHEWeightsTest::LHEWeightsTest(const edm::ParameterSet& iConfig) : tag_(iConfig.getParameter("tag")), isMiniaod_(iConfig.getParameter("miniaod")), genParticleToken_(consumes(iConfig.getParameter("genParticleSrc"))), genJetToken_(consumes(iConfig.getParameter("genJetSrc"))), LHEToken_(consumes(iConfig.getParameter("LHESrc"))), - GenToken_(consumes(iConfig.getParameter("GenSrc"))) - + GenToken_(consumes(iConfig.getParameter("GenSrc"))), + lheWeightToken_(consumes(edm::InputTag("testWeights"))), + lheWeightInfoToken_(consumes(edm::InputTag("testWeights"))) { //now do what ever initialization is needed - usesResource("TFileService"); + //usesResource("TFileService"); TFileDirectory subdirectory = fileservice->mkdir( tag_ ); h_count_event = subdirectory.make("h_count_event", "h_count_event;Dummy;Events", 1,0,1); @@ -133,8 +148,6 @@ MergingAnalyzer::MergingAnalyzer(const edm::ParameterSet& iConfig) : histograms2d["dilepton_pt"] = subdirectory.make("dilepton_pt", "Dilepton p_{T}; p_{T} (GeV);weight;Events",200,0,2000, nweights, -0.5, nweights-0.5); histograms2d["n_leptons"] = subdirectory.make("n_leptons", "number of leptons;n_lep;weight;Events",10,-0.5,9.5, nweights, -0.5, nweights-0.5); - // histograms2d["njet"] = subdirectory.make("njet_over_pt", "pt threshold;njet;Events",10,-5,95,10,-0.5,9.5); - tree = subdirectory.make("events","events"); for(auto const entry : histograms1d){ tree->Branch(entry.first, &variables[entry.first],(entry.first+"/D").Data()); @@ -143,7 +156,7 @@ MergingAnalyzer::MergingAnalyzer(const edm::ParameterSet& iConfig) : } -MergingAnalyzer::~MergingAnalyzer() +LHEWeightsTest::~LHEWeightsTest() { // do anything here that needs to be done at desctruction time @@ -286,10 +299,9 @@ std::vector clean_v_jets(const std::vector & genJets } -void MergingAnalyzer::setup_variables(const edm::Event& iEvent) { +void LHEWeightsTest::setup_variables(const edm::Event& iEvent) { using namespace edm; - //// Initialize with dummy values for ( auto pair : variables ) { variables[pair.first] = -9999; @@ -320,35 +332,18 @@ void MergingAnalyzer::setup_variables(const edm::Event& iEvent) { auto z_cand = find_z_candidate(leptons); variables["dilepton_pt"] = (z_cand.first.p4() + z_cand.second.p4()).pt(); } + else + variables["dilepton_pt"] = 0; + //// Jets - std::vector jets = clean_v_jets(clean_jets(select_jets(*genJets),leptons)); + std::vector jets = clean_jets(select_jets(*genJets),leptons); + //std::vector jets = clean_v_jets(clean_jets(select_jets(*genJets),leptons)); int njets = jets.size(); variables["n_jets"] = njets; - if(njets>0){ - variables["pt_jet1"] = jets.at(0).pt() ; - } - if(njets>1){ - variables["pt_jet2"] = jets.at(1).pt() ; - } - if(njets>2){ - variables["pt_jet3"] = jets.at(2).pt() ; - } - if(njets>3){ - variables["pt_jet4"] = jets.at(3).pt() ; - } - - - // for (unsigned int i = 0; i<=10; i++){ - - // float threshold = i*10; - // int njet = 0; - // for ( auto const & j : jets ) { - // if(j.pt() > threshold){ - // njet++; - // } - // } - // histograms2d["njet"]->Fill(threshold,njet,variables["weight"]); - // } + variables["pt_jet1"] = njets > 0 ? jets.at(0).pt() : -999; + variables["pt_jet2"] = njets > 1 ? jets.at(1).pt() : -999; + variables["pt_jet3"] = njets > 2 ? jets.at(2).pt() : -999; + variables["pt_jet4"] = njets > 3 ? jets.at(3).pt() : -999; double ht = 0; for(auto const & j : jets){ @@ -357,22 +352,24 @@ void MergingAnalyzer::setup_variables(const edm::Event& iEvent) { variables["ht"] = ht; } -std::vector setup_weights(const edm::Event& iEvent) { - edm::Handle lheHandle; - iEvent.getByLabel("testWeights", lheHandle); - const LHEWeightProduct * lheWeights = lheHandle.product(); - std::vector weights = lheWeights.weights(); - - for(auto i : scaleWeightOrder_){ - weights.push_back(weights[i]); +std::vector LHEWeightsTest::setup_weights(const edm::Event& iEvent) { + edm::Handle lheWeightHandle; + iEvent.getByToken(lheWeightToken_, lheWeightHandle); + const LHEWeightProduct * lheWeights = lheWeightHandle.product(); + WeightsContainer weights = lheWeights->weights(); + auto scaleWeights = weights.at(scaleWeightsIndex_); + std::vector keepWeights; + + for(auto i : scaleWeightsOrder_){ + keepWeights.push_back(scaleWeights[i]); } - return weights; + return keepWeights; } // ------------ method called for each event ------------ void -MergingAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) +LHEWeightsTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; @@ -380,11 +377,10 @@ MergingAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup tree->Fill(); auto weights = setup_weights(iEvent); h_count_event->Fill(0.5); - h_count_sumw->Fill(0.5,weights.at(0)); + h_count_sumw->Fill(0.5,weights.at(4)); for( auto pair : histograms2d ) { for(uint i=0; i -9998){ pair.second->Fill(value,i,weights.at(i)); @@ -396,19 +392,19 @@ MergingAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup // ------------ method called once each job just before starting event loop ------------ void -MergingAnalyzer::beginJob() +LHEWeightsTest::beginJob() { } // ------------ method called once each job just after ending the event loop ------------ void -MergingAnalyzer::endJob() +LHEWeightsTest::endJob() { } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void -MergingAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +LHEWeightsTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { //The following says we do not know what parameters are allowed so do no validation // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; @@ -417,35 +413,33 @@ MergingAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) } void -LHEWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) { - edm::Handle lheWeightInfoHandle; +LHEWeightsTest::beginRun(edm::Run const& run, edm::EventSetup const& es) { + //edm::Handle lheWeightsInfoHandle; // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) - run.getByLabel("testWeights", lheWeightInfoHandle); + //run.getByLabel("testWeights", lheWeightsInfoHandle); + //edm::Handle lheWeightsInfoHandle; + //run.getByLabel("generator", lheWeightsInfoHandle); + edm::Handle lheWeightInfoHandle; + run.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); // Should add a search by name function - gen::ScaleWeightGroup scaleWeightInfo; - for (const auto& group : lheWeightInfoHandle->allWeightGroupsInfo()) { - if (std::find("scale", group.name()) != std::string::npos) { - scaleWeightInfo = group; - break; - } - } - + scaleWeightsIndex_ = lheWeightInfoHandle->weightGroupIndicesByType(gen::kScaleWeights).front(); + auto scaleWeights = static_cast( + lheWeightInfoHandle->orderedWeightGroupInfo(scaleWeightsIndex_)); // nano ordering of mur=0.5 muf=0.5 ; [1] is mur=0.5 muf=1 ; [2] is mur=0.5 muf=2 ; [3] is mur=1 muf=0.5 ; // [4] is mur=1 muf=1 ; [5] is mur=1 muf=2 ; [6] is mur=2 muf=0.5 ; [7] is mur=2 muf=1 ; [8] is mur=2 muf=2 * - scaleWeightOrder_ = { group.muR05muF05Index(), - group.muR05muF1Index(), - group.muR05muF2Index(), - group.muR1muF05Index(), - group.centralIndex(), - group.muR1muF2Index(), - group.muR2muF05Index(), - group.muR2muF1Index(), - group.muR2muF2Index(), - } - + scaleWeightsOrder_.clear(); + scaleWeightsOrder_.push_back(scaleWeights->muR05muF05Index()); + scaleWeightsOrder_.push_back(scaleWeights->muR05muF1Index()); + scaleWeightsOrder_.push_back(scaleWeights->muR05muF2Index()); + scaleWeightsOrder_.push_back(scaleWeights->muR1muF05Index()); + scaleWeightsOrder_.push_back(scaleWeights->centralIndex()); + scaleWeightsOrder_.push_back(scaleWeights->muR1muF2Index()); + scaleWeightsOrder_.push_back(scaleWeights->muR2muF05Index()); + scaleWeightsOrder_.push_back(scaleWeights->muR2muF1Index()); + scaleWeightsOrder_.push_back(scaleWeights->muR2muF2Index()); } //define this as a plug-in -DEFINE_FWK_MODULE(MergingAnalyzer); +DEFINE_FWK_MODULE(LHEWeightsTest); diff --git a/GeneratorInterface/LHEInterface/test/test_ZPlotting_LHEweights_cfg.py b/GeneratorInterface/LHEInterface/test/test_ZPlotting_LHEweights_cfg.py new file mode 100644 index 0000000000000..a0acb131f23c4 --- /dev/null +++ b/GeneratorInterface/LHEInterface/test/test_ZPlotting_LHEweights_cfg.py @@ -0,0 +1,77 @@ +import FWCore.ParameterSet.Config as cms +import sys +import os +import re +from FWCore.ParameterSet.VarParsing import VarParsing + +def commandline(): + options = VarParsing('analysis') + + options.register( + "fileList", + "", + VarParsing.multiplicity.singleton, + VarParsing.varType.string, + "List of files to run on." + ) + options.register( + "isMiniAOD", + False, + VarParsing.multiplicity.singleton, + VarParsing.varType.bool, + "Sample is miniAOD" + ) + options.register( + "path", + None, + VarParsing.multiplicity.singleton, + VarParsing.varType.string, + "Path for input files" + ) + + options.parseArguments() + + + print "OPTIONS: MiniAOD ---> " + ("Yes" if options.isMiniAOD else "No") + print "OPTIONS: Tag ---> {TAG}".format(TAG=options.tag) + + + if(len(options.inputFiles) and options.fileList != ""): + print "ERROR: Please provide either fileList or inputFiles but not both." + sys.exit(1) + elif(options.fileList != ""): + options.inputFiles.extend(read_list_from_file(options.fileList)) + elif(options.path): + options.inputFiles.extend(find_files(options.path,'.*\.root')) + print "Found {N} files.".format(N=len(options.inputFiles)) + + return options +# Define the CMSSW process +process = cms.Process("demo") +options = commandline() + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.MessageLogger.cerr.FwkReport.reportEvery = 1000 + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) ) + +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( options.inputFiles ) +) + +process.testWeights = cms.EDProducer("LHEWeightProductProducer") + +process.demo = cms.EDAnalyzer('LHEWeightsTest', + tag = cms.string(options.tag), + miniaod = cms.bool(options.isMiniAOD), + genParticleSrc = cms.InputTag("prunedGenParticles" if options.isMiniAOD else "genParticles"), + genJetSrc = cms.InputTag( "slimmedGenJets" if options.isMiniAOD else "ak4GenJetsNoNu"), + genMETSrc = cms.InputTag( "slimmedMETs" if options.isMiniAOD else "genMetTrue"), + LHESrc = cms.InputTag("externalLHEProducer"), + GenSrc = cms.InputTag("generator") +) + +process.TFileService = cms.Service("TFileService", fileName = cms.string("analysis_{TAG}.root".format(TAG=options.tag)) ) + +process.p = cms.Path(process.testWeights*process.demo) + diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h index 9ed6c8b1927e9..c18b0eb4c3426 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h @@ -25,6 +25,8 @@ class LHEWeightInfoProduct { const edm::OwnVector& allWeightGroupsInfo() const; const gen::WeightGroupInfo* containingWeightGroupInfo(int index) const; const gen::WeightGroupInfo* orderedWeightGroupInfo(int index) const; + std::vector weightGroupsByType(gen::WeightType type) const; + std::vector weightGroupIndicesByType(gen::WeightType type) const; void addWeightGroupInfo(gen::WeightGroupInfo* info); const int numberOfGroups() const { return weightGroupsInfo_.size(); } diff --git a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc index 9e1f666325a75..77fb718f8df65 100644 --- a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc @@ -35,6 +35,24 @@ const gen::WeightGroupInfo* LHEWeightInfoProduct::orderedWeightGroupInfo(int wei return &weightGroupsInfo_[weightGroupIndex]; } +std::vector LHEWeightInfoProduct::weightGroupsByType(gen::WeightType type) const { + std::vector matchingGroups; + for (size_t i = 0; i < weightGroupsInfo_.size(); i++) { + if (weightGroupsInfo_[i].weightType() == type) + matchingGroups.push_back(weightGroupsInfo_[i].clone()); + } + return matchingGroups; +} + +std::vector LHEWeightInfoProduct::weightGroupIndicesByType(gen::WeightType type) const { + std::vector matchingGroupIndices; + for (size_t i = 0; i < weightGroupsInfo_.size(); i++) { + if (weightGroupsInfo_[i].weightType() == type) + matchingGroupIndices.push_back(i); + } + return matchingGroupIndices; +} + void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo* info) { weightGroupsInfo_.push_back(info); } diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc index 5fd94f70aca3f..64215f7ad6f2d 100644 --- a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc @@ -1,5 +1,6 @@ #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include +#include namespace gen { void ScaleWeightGroupInfo::copy(const ScaleWeightGroupInfo &other) { @@ -9,7 +10,7 @@ namespace gen { muR2muF05Index_ = other.muR2muF05Index_; muR2muF1Index_ = other.muR2muF1Index_; muR2muF2Index_ = other.muR2muF2Index_; - muR2muF05Index_ = other.muR2muF05Index_; + muR05muF05Index_ = other.muR2muF05Index_; muR05muF1Index_ = other.muR05muF1Index_; muR05muF2Index_ = other.muR05muF2Index_; WeightGroupInfo::copy(other); From c535b5555a10d4e577de6348a79fe364f4d4a572 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 3 Oct 2019 08:59:34 -0400 Subject: [PATCH 40/75] Rename LHEWeight-->GenWeight to have same product for LHE and GEN --- .../Core/interface/WeightHelper.h | 4 ++-- .../Core/plugins/LHEWeightProductProducer.cc | 8 +++---- GeneratorInterface/Core/src/WeightHelper.cc | 4 ++-- .../plugins/ExternalLHEProducer.cc | 12 +++++----- .../LHEInterface/plugins/LHESource.cc | 8 +++---- .../LHEInterface/plugins/LHEWeightsTest.cc | 20 ++++++++--------- .../LHEInterface/test/testWeights.py | 12 +++++----- ...htInfoProduct.h => GenWeightInfoProduct.h} | 22 +++++++++---------- ...{LHEWeightProduct.h => GenWeightProduct.h} | 14 ++++++------ ...InfoProduct.cc => GenWeightInfoProduct.cc} | 20 ++++++++--------- .../GeneratorProducts/src/classes.h | 4 ++-- .../GeneratorProducts/src/classes_def.xml | 8 +++---- .../TestAnalyzer/plugins/TestAnalyzer.cc | 10 ++++----- 13 files changed, 73 insertions(+), 73 deletions(-) rename SimDataFormats/GeneratorProducts/interface/{LHEWeightInfoProduct.h => GenWeightInfoProduct.h} (61%) rename SimDataFormats/GeneratorProducts/interface/{LHEWeightProduct.h => GenWeightProduct.h} (77%) rename SimDataFormats/GeneratorProducts/src/{LHEWeightInfoProduct.cc => GenWeightInfoProduct.cc} (70%) diff --git a/GeneratorInterface/Core/interface/WeightHelper.h b/GeneratorInterface/Core/interface/WeightHelper.h index 64e1fb196d5d7..f1d8d2c38f283 100644 --- a/GeneratorInterface/Core/interface/WeightHelper.h +++ b/GeneratorInterface/Core/interface/WeightHelper.h @@ -2,7 +2,7 @@ #define GeneratorInterface_LHEInterface_WeightHelper_h #include "DataFormats/Common/interface/OwnVector.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/WeightsInfo.h" @@ -11,7 +11,7 @@ namespace gen { public: WeightHelper() {} edm::OwnVector weightGroups() {return weightGroups_;} - std::unique_ptr weightProduct(std::vector); + std::unique_ptr weightProduct(std::vector); int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex); protected: edm::OwnVector weightGroups_; diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index a3bc3b5faf1c4..6b73575c98c4c 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -16,7 +16,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" @@ -51,8 +51,8 @@ LHEWeightProductProducer::LHEWeightProductProducer(const edm::ParameterSet& iCon lheEventToken_(consumes(edm::InputTag("externalLHEProducer"))) //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) { - produces(); - produces(); + produces(); + produces(); } @@ -88,7 +88,7 @@ LHEWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& } weightHelper_.parseWeightGroupsFromHeader(headerWeightInfo.lines()); - auto weightInfoProduct = std::make_unique(); + auto weightInfoProduct = std::make_unique(); for (auto& weightGroup : weightHelper_.weightGroups()) { weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); } diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index 98a38a34e9c5d..acd1557f332e6 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -1,8 +1,8 @@ #include "GeneratorInterface/Core/interface/WeightHelper.h" namespace gen { - std::unique_ptr WeightHelper::weightProduct(std::vector weights) { - auto weightProduct = std::make_unique(); + std::unique_ptr WeightHelper::weightProduct(std::vector weights) { + auto weightProduct = std::make_unique(); weightProduct->setNumWeightSets(weightGroups_.size()); int weightGroupIndex = 0; int weightNum = 0; diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index d9d8c710ff16c..a07e650b4c7f0 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -49,16 +49,16 @@ Description: [one line class summary] #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" #include "GeneratorInterface/LHEInterface/interface/LHEReader.h" #include "GeneratorInterface/LHEInterface/interface/TestWeightInfo.h" -//#include "GeneratorInterface/Core/interface/LHEWeightGroupReaderHelper.h" +//#include "GeneratorInterface/Core/interface/GenWeightGroupReaderHelper.h" #include "GeneratorInterface/Core/interface/LHEWeightHelper.h" #include "FWCore/ServiceRegistry/interface/Service.h" @@ -163,10 +163,10 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig) : produces("LHEScriptOutput"); produces(); - produces(); + produces(); produces(); produces(); - produces(); + produces(); } @@ -386,7 +386,7 @@ ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) reader_.reset(); - auto weightInfoProduct = std::make_unique(); + auto weightInfoProduct = std::make_unique(); for (auto& weightGroup : weightHelper_.weightGroups()) { weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); } diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.cc b/GeneratorInterface/LHEInterface/plugins/LHESource.cc index 03402f473651f..aeb78dee92193 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.cc @@ -23,7 +23,7 @@ #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" @@ -37,7 +37,7 @@ LHESource::LHESource(const edm::ParameterSet ¶ms, const edm::InputSourceDescription &desc) : ProducerSourceFromFiles(params, desc, false), reader_(new LHEReader(fileNames(), params.getUntrackedParameter("skipEvents", 0))), - lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), edm::TypeID(typeid(LHEWeightInfoProduct)), productRegistryUpdate()), + lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), edm::TypeID(typeid(GenWeightInfoProduct)), productRegistryUpdate()), phid_() { nextEvent(); @@ -136,7 +136,7 @@ void LHESource::putRunInfoProduct(edm::RunPrincipal& iRunPrincipal) { void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { if (runInfoProductLast_) { - auto product = std::make_unique(); + auto product = std::make_unique(); gen::WeightGroupInfo scaleInfo( "" ); @@ -149,7 +149,7 @@ void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { product->addWeightGroupInfo(&scaleInfo); product->addWeightGroupInfo(&cenPdfInfo); - std::unique_ptr rdp(new edm::Wrapper(std::move(product))); + std::unique_ptr rdp(new edm::Wrapper(std::move(product))); iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp)); } } diff --git a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc index d3201a85f97ee..8af5fc7c017e4 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc @@ -43,8 +43,8 @@ #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" @@ -94,8 +94,8 @@ class LHEWeightsTest : public edm::one::EDAnalyzer { edm::EDGetTokenT genJetToken_; edm::EDGetTokenT LHEToken_; edm::EDGetTokenT GenToken_; - edm::EDGetTokenT lheWeightToken_; - edm::EDGetTokenT lheWeightInfoToken_; + edm::EDGetTokenT lheWeightToken_; + edm::EDGetTokenT lheWeightInfoToken_; edm::Service fileservice; std::map histograms2d; @@ -128,8 +128,8 @@ LHEWeightsTest::LHEWeightsTest(const edm::ParameterSet& iConfig) : genJetToken_(consumes(iConfig.getParameter("genJetSrc"))), LHEToken_(consumes(iConfig.getParameter("LHESrc"))), GenToken_(consumes(iConfig.getParameter("GenSrc"))), - lheWeightToken_(consumes(edm::InputTag("testWeights"))), - lheWeightInfoToken_(consumes(edm::InputTag("testWeights"))) + lheWeightToken_(consumes(edm::InputTag("testWeights"))), + lheWeightInfoToken_(consumes(edm::InputTag("testWeights"))) { //now do what ever initialization is needed @@ -353,9 +353,9 @@ void LHEWeightsTest::setup_variables(const edm::Event& iEvent) { } std::vector LHEWeightsTest::setup_weights(const edm::Event& iEvent) { - edm::Handle lheWeightHandle; + edm::Handle lheWeightHandle; iEvent.getByToken(lheWeightToken_, lheWeightHandle); - const LHEWeightProduct * lheWeights = lheWeightHandle.product(); + const GenWeightProduct * lheWeights = lheWeightHandle.product(); WeightsContainer weights = lheWeights->weights(); auto scaleWeights = weights.at(scaleWeightsIndex_); std::vector keepWeights; @@ -414,12 +414,12 @@ LHEWeightsTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { void LHEWeightsTest::beginRun(edm::Run const& run, edm::EventSetup const& es) { - //edm::Handle lheWeightsInfoHandle; + //edm::Handle lheWeightsInfoHandle; // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) //run.getByLabel("testWeights", lheWeightsInfoHandle); //edm::Handle lheWeightsInfoHandle; //run.getByLabel("generator", lheWeightsInfoHandle); - edm::Handle lheWeightInfoHandle; + edm::Handle lheWeightInfoHandle; run.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); // Should add a search by name function diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/LHEInterface/test/testWeights.py index 2140372c5c5f0..131dc483b24ab 100644 --- a/GeneratorInterface/LHEInterface/test/testWeights.py +++ b/GeneratorInterface/LHEInterface/test/testWeights.py @@ -1,20 +1,20 @@ from DataFormats.FWLite import Events,Handle,Runs import ROOT -#source = "externalLHEProducer" -source = "testWeights" +source = "externalLHEProducer" +#source = "testWeights" #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: -#for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: -for filename in ["test.root"]: +for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: +#for filename in ["test.root"]: runs = Runs(filename) run = runs.__iter__().next() - weightInfoHandle = Handle("LHEWeightInfoProduct") + weightInfoHandle = Handle("GenWeightInfoProduct") run.getByLabel(source, weightInfoHandle) weightInfoProd = weightInfoHandle.product() events = Events(filename) event = events.__iter__().next() - weightHandle = Handle("LHEWeightProduct") + weightHandle = Handle("GenWeightProduct") event.getByLabel(source, weightHandle) weightInfo = weightHandle.product() print "Content of the weights" diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h similarity index 61% rename from SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h rename to SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h index c18b0eb4c3426..0152710f8fd56 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h @@ -1,5 +1,5 @@ -#ifndef SimDataFormats_GeneratorProducts_LHEWeightInfoProduct_h -#define SimDataFormats_GeneratorProducts_LHEWeightInfoProduct_h +#ifndef SimDataFormats_GeneratorProducts_GenWeightInfoProduct_h +#define SimDataFormats_GeneratorProducts_GenWeightInfoProduct_h #include #include @@ -12,15 +12,15 @@ #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" -class LHEWeightInfoProduct { +class GenWeightInfoProduct { public: - LHEWeightInfoProduct() {} - LHEWeightInfoProduct(edm::OwnVector& weightGroups); - LHEWeightInfoProduct(const LHEWeightInfoProduct& other); - LHEWeightInfoProduct(LHEWeightInfoProduct&& other); - ~LHEWeightInfoProduct() {} - LHEWeightInfoProduct& operator=(const LHEWeightInfoProduct &other); - LHEWeightInfoProduct& operator=(LHEWeightInfoProduct &&other); + GenWeightInfoProduct() {} + GenWeightInfoProduct(edm::OwnVector& weightGroups); + GenWeightInfoProduct(const GenWeightInfoProduct& other); + GenWeightInfoProduct(GenWeightInfoProduct&& other); + ~GenWeightInfoProduct() {} + GenWeightInfoProduct& operator=(const GenWeightInfoProduct &other); + GenWeightInfoProduct& operator=(GenWeightInfoProduct &&other); const edm::OwnVector& allWeightGroupsInfo() const; const gen::WeightGroupInfo* containingWeightGroupInfo(int index) const; @@ -36,5 +36,5 @@ class LHEWeightInfoProduct { }; -#endif // GeneratorWeightInfo_LHEInterface_LHEWeightInfoProduct_h +#endif // GeneratorWeightInfo_LHEInterface_GenWeightInfoProduct_h diff --git a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h b/SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h similarity index 77% rename from SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h rename to SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h index 5c5fa132b4ee7..e09f2541f8601 100644 --- a/SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h @@ -1,5 +1,5 @@ -#ifndef SimDataFormats_GeneratorProducts_LHEWeightProduct_h -#define SimDataFormats_GeneratorProducts_LHEWeightProduct_h +#ifndef SimDataFormats_GeneratorProducts_GenWeightProduct_h +#define SimDataFormats_GeneratorProducts_GenWeightProduct_h #include #include @@ -11,14 +11,14 @@ typedef std::vector> WeightsContainer; -class LHEWeightProduct { +class GenWeightProduct { public: - LHEWeightProduct() { weightsVector_ = {}; } - LHEWeightProduct& operator=(LHEWeightProduct&& other) { + GenWeightProduct() { weightsVector_ = {}; } + GenWeightProduct& operator=(GenWeightProduct&& other) { weightsVector_ = std::move(other.weightsVector_); return *this; } - ~LHEWeightProduct() {} + ~GenWeightProduct() {} void setNumWeightSets(int num) { weightsVector_.resize(num); } void addWeightSet() { weightsVector_.push_back({}); } @@ -39,5 +39,5 @@ class LHEWeightProduct { WeightsContainer weightsVector_; }; -#endif // GeneratorEvent_LHEInterface_LHEWeightProduct_h +#endif // GeneratorEvent_LHEInterface_GenWeightProduct_h diff --git a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc similarity index 70% rename from SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc rename to SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc index 77fb718f8df65..8a76e4d173b85 100644 --- a/SimDataFormats/GeneratorProducts/src/LHEWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc @@ -1,27 +1,27 @@ #include #include -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" -LHEWeightInfoProduct::LHEWeightInfoProduct(edm::OwnVector& weightGroups) { +GenWeightInfoProduct::GenWeightInfoProduct(edm::OwnVector& weightGroups) { weightGroupsInfo_ = weightGroups; } -LHEWeightInfoProduct& LHEWeightInfoProduct::operator=(const LHEWeightInfoProduct &other) { +GenWeightInfoProduct& GenWeightInfoProduct::operator=(const GenWeightInfoProduct &other) { weightGroupsInfo_ = other.weightGroupsInfo_; return * this; } -LHEWeightInfoProduct& LHEWeightInfoProduct::operator=(LHEWeightInfoProduct &&other) { +GenWeightInfoProduct& GenWeightInfoProduct::operator=(GenWeightInfoProduct &&other) { weightGroupsInfo_ = std::move(other.weightGroupsInfo_); return *this; } -const edm::OwnVector& LHEWeightInfoProduct::allWeightGroupsInfo() const { +const edm::OwnVector& GenWeightInfoProduct::allWeightGroupsInfo() const { return weightGroupsInfo_; } -const gen::WeightGroupInfo* LHEWeightInfoProduct::containingWeightGroupInfo(int index) const { +const gen::WeightGroupInfo* GenWeightInfoProduct::containingWeightGroupInfo(int index) const { for (const auto& weightGroup : weightGroupsInfo_) { if (weightGroup.indexInRange(index)) return &weightGroup; @@ -29,13 +29,13 @@ const gen::WeightGroupInfo* LHEWeightInfoProduct::containingWeightGroupInfo(int throw std::domain_error("Failed to find containing weight group"); } -const gen::WeightGroupInfo* LHEWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { +const gen::WeightGroupInfo* GenWeightInfoProduct::orderedWeightGroupInfo(int weightGroupIndex) const { if (weightGroupIndex >= static_cast(weightGroupsInfo_.size())) throw std::range_error("Weight index out of range!"); return &weightGroupsInfo_[weightGroupIndex]; } -std::vector LHEWeightInfoProduct::weightGroupsByType(gen::WeightType type) const { +std::vector GenWeightInfoProduct::weightGroupsByType(gen::WeightType type) const { std::vector matchingGroups; for (size_t i = 0; i < weightGroupsInfo_.size(); i++) { if (weightGroupsInfo_[i].weightType() == type) @@ -44,7 +44,7 @@ std::vector LHEWeightInfoProduct::weightGroupsByType(gen: return matchingGroups; } -std::vector LHEWeightInfoProduct::weightGroupIndicesByType(gen::WeightType type) const { +std::vector GenWeightInfoProduct::weightGroupIndicesByType(gen::WeightType type) const { std::vector matchingGroupIndices; for (size_t i = 0; i < weightGroupsInfo_.size(); i++) { if (weightGroupsInfo_[i].weightType() == type) @@ -53,6 +53,6 @@ std::vector LHEWeightInfoProduct::weightGroupIndicesByType(gen::WeightType return matchingGroupIndices; } -void LHEWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo* info) { +void GenWeightInfoProduct::addWeightGroupInfo(gen::WeightGroupInfo* info) { weightGroupsInfo_.push_back(info); } diff --git a/SimDataFormats/GeneratorProducts/src/classes.h b/SimDataFormats/GeneratorProducts/src/classes.h index 5629d5765059d..f3b559410999f 100644 --- a/SimDataFormats/GeneratorProducts/src/classes.h +++ b/SimDataFormats/GeneratorProducts/src/classes.h @@ -12,8 +12,8 @@ #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/LHEWeightProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index b52e0f7851b2a..ce45759b98a1b 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -197,8 +197,8 @@ - - + + @@ -238,8 +238,8 @@ - - + + diff --git a/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc b/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc index 3c8d7065faf6c..1cb1c7ca73e9a 100644 --- a/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc +++ b/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc @@ -32,7 +32,7 @@ #include "FWCore/Utilities/interface/InputTag.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" - #include "SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h" + #include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" // @@ -56,7 +56,7 @@ class TestAnalyzer : public edm::one::EDAnalyzer { private: - edm::EDGetTokenT lheWeightInfoToken_; + edm::EDGetTokenT lheWeightInfoToken_; virtual void beginJob() override; void beginRun(edm::Run const& iRun, edm::EventSetup const&) override; void endRun(edm::Run const& iRun, edm::EventSetup const&) override; @@ -78,7 +78,7 @@ class TestAnalyzer : public edm::one::EDAnalyzer { // constructors and destructor // TestAnalyzer::TestAnalyzer(const edm::ParameterSet& iConfig) : - lheWeightInfoToken_(consumes(edm::InputTag("externalLHEProducer"))) + lheWeightInfoToken_(consumes(edm::InputTag("externalLHEProducer"))) { //now do what ever initialization is needed @@ -127,10 +127,10 @@ void TestAnalyzer::endRun(edm::Run const& iRun, edm::EventSetup const&) {} void TestAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const&) { - edm::Handle lheWeightInfoHandle; + edm::Handle lheWeightInfoHandle; iRun.getByToken( lheWeightInfoToken_, lheWeightInfoHandle ); - const LHEWeightInfoProduct* lheProd = lheWeightInfoHandle.product(); + const GenWeightInfoProduct* lheProd = lheWeightInfoHandle.product(); edm::OwnVector groups = lheProd->allWeightGroupsInfo(); for (const auto& group : groups) { std::cout << "Type of the weight is " << group.weightType() << " name is " << group.name() << std::endl; From 3e4861786d64c142e076e4d6c8b9d20bfd143f9d Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 3 Oct 2019 09:56:35 -0400 Subject: [PATCH 41/75] Add parton shower weights class --- .../interface/PartonShowerWeightGroupInfo.h | 29 +++++++++++++++++++ .../interface/ScaleWeightGroupInfo.h | 4 +-- .../interface/WeightGroupInfo.h | 2 +- .../src/PartonShowerWeights.cc | 12 ++++++++ .../GeneratorProducts/src/classes.h | 1 + .../GeneratorProducts/src/classes_def.xml | 2 ++ 6 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h create mode 100644 SimDataFormats/GeneratorProducts/src/PartonShowerWeights.cc diff --git a/SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h new file mode 100644 index 0000000000000..e9bb539bcb185 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h @@ -0,0 +1,29 @@ +#ifndef SimDataFormats_GeneratorProducts_PartonShowerWeightGroupInfo_h +#define SimDataFormats_GeneratorProducts_PartonShowerWeightGroupInfo_h + +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" + +namespace gen { + class PartonShowerWeightGroupInfo : public WeightGroupInfo { + public: + PartonShowerWeightGroupInfo() : PartonShowerWeightGroupInfo("") {} + PartonShowerWeightGroupInfo(std::string header, std::string name) : + WeightGroupInfo(header, name) { + weightType_ = kPartonShowerWeights; + } + PartonShowerWeightGroupInfo(std::string header) : + PartonShowerWeightGroupInfo(header, header) { } + PartonShowerWeightGroupInfo(const PartonShowerWeightGroupInfo &other) { + copy(other); + } + virtual ~PartonShowerWeightGroupInfo() override {} + void copy(const PartonShowerWeightGroupInfo &other); + virtual PartonShowerWeightGroupInfo* clone() const override; + + // Is a variation of the functional form of the dynamic scale + }; +} + +#endif + + diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index 00891a219db23..994c1235963dd 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -42,8 +42,8 @@ namespace gen { void copy(const ScaleWeightGroupInfo &other); virtual ScaleWeightGroupInfo* clone() const override; - void setMuRMuFIndex(WeightMetaInfo info, float muR, float muF); - void addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF); + void setMuRMuFIndex(WeightMetaInfo info, float muR, float muF); + void addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF); // Is a variation of the functional form of the dynamic scale bool isFunctionalFormVariation(); diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index cc56681a7bfbf..973e88f10e73d 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -21,7 +21,7 @@ namespace gen { kScaleWeights, kMatrixElementWeights, kUnknownWeights, - kShowerWeights, + kPartonShowerWeights, }; class WeightGroupInfo { diff --git a/SimDataFormats/GeneratorProducts/src/PartonShowerWeights.cc b/SimDataFormats/GeneratorProducts/src/PartonShowerWeights.cc new file mode 100644 index 0000000000000..893db2f20433e --- /dev/null +++ b/SimDataFormats/GeneratorProducts/src/PartonShowerWeights.cc @@ -0,0 +1,12 @@ +#include "SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h" + +namespace gen { + void PartonShowerWeightGroupInfo::copy(const PartonShowerWeightGroupInfo &other) { + WeightGroupInfo::copy(other); + } + + PartonShowerWeightGroupInfo* PartonShowerWeightGroupInfo::clone() const { + return new PartonShowerWeightGroupInfo(*this); + } +} + diff --git a/SimDataFormats/GeneratorProducts/src/classes.h b/SimDataFormats/GeneratorProducts/src/classes.h index f3b559410999f..8bc509d9738ec 100644 --- a/SimDataFormats/GeneratorProducts/src/classes.h +++ b/SimDataFormats/GeneratorProducts/src/classes.h @@ -12,6 +12,7 @@ #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index ce45759b98a1b..3f4ef536a9e68 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -226,6 +226,7 @@ + @@ -234,6 +235,7 @@ + From 176adbfe905a4c7c7503856b77cb7ba617aabe67 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 3 Oct 2019 18:13:32 -0400 Subject: [PATCH 42/75] Simple version of GEN producer working --- .../Core/interface/GenWeightHelper.h | 30 +++++ .../Core/interface/WeightHelper.h | 2 + .../Core/plugins/GenWeightProductProducer.cc | 107 ++++++++++++++++++ .../Core/src/GenWeightHelper.cc | 32 ++++++ GeneratorInterface/Core/src/WeightHelper.cc | 35 ++++-- ...er_cfg.py => testGenWeightProducer_cfg.py} | 7 +- .../GeneratorProducts/src/WeightGroupInfo.cc | 2 +- 7 files changed, 200 insertions(+), 15 deletions(-) create mode 100644 GeneratorInterface/Core/interface/GenWeightHelper.h create mode 100644 GeneratorInterface/Core/plugins/GenWeightProductProducer.cc create mode 100644 GeneratorInterface/Core/src/GenWeightHelper.cc rename GeneratorInterface/Core/test/{testLHEWeightProducer_cfg.py => testGenWeightProducer_cfg.py} (59%) diff --git a/GeneratorInterface/Core/interface/GenWeightHelper.h b/GeneratorInterface/Core/interface/GenWeightHelper.h new file mode 100644 index 0000000000000..4836ac90b5332 --- /dev/null +++ b/GeneratorInterface/Core/interface/GenWeightHelper.h @@ -0,0 +1,30 @@ +#ifndef GeneratorInterface_Core_GenWeightHelper_h +#define GeneratorInterface_Core_GenWeightHelper_h + +#include +#include +#include +#include +#include + +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoProduct.h" +#include "GeneratorInterface/Core/interface/WeightHelper.h" + +#include + +namespace gen { + class GenWeightHelper : public WeightHelper { + public: + GenWeightHelper(); + + void parseWeightGroupsFromNames(std::vector weightNames); + private: + }; +} + +#endif + + diff --git a/GeneratorInterface/Core/interface/WeightHelper.h b/GeneratorInterface/Core/interface/WeightHelper.h index f1d8d2c38f283..1540f9404c42f 100644 --- a/GeneratorInterface/Core/interface/WeightHelper.h +++ b/GeneratorInterface/Core/interface/WeightHelper.h @@ -12,6 +12,8 @@ namespace gen { WeightHelper() {} edm::OwnVector weightGroups() {return weightGroups_;} std::unique_ptr weightProduct(std::vector); + std::unique_ptr weightProduct(std::vector); + int addWeightToProduct(std::unique_ptr& product, double weight, std::string name, int weightNum, int groupIndex); int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex); protected: edm::OwnVector weightGroups_; diff --git a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc new file mode 100644 index 0000000000000..c08f3258579b8 --- /dev/null +++ b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc @@ -0,0 +1,107 @@ +#include +#include +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDProducer.h" +#include "FWCore/Framework/interface/LuminosityBlock.h" + +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/FileInPath.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoHeader.h" + +#include "GeneratorInterface/Core/interface/GenWeightHelper.h" + +#include "FWCore/ServiceRegistry/interface/Service.h" + +class GenWeightProductProducer : public edm::one::EDProducer { +public: + explicit GenWeightProductProducer(const edm::ParameterSet& iConfig); + ~GenWeightProductProducer() override; + +private: + std::vector weightNames_; + gen::GenWeightHelper weightHelper_; + edm::EDGetTokenT genLumiInfoToken_; + edm::EDGetTokenT genEventToken_; + + void produce(edm::Event&, const edm::EventSetup&) override; + void beginRunProduce(edm::Run& run, edm::EventSetup const& es) override; + void endRunProduce(edm::Run&, edm::EventSetup const&) override; + void beginLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) override; + void endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) override; + +}; + +// +// constructors and destructor +// +GenWeightProductProducer::GenWeightProductProducer(const edm::ParameterSet& iConfig) : + genLumiInfoToken_(consumes(edm::InputTag("generator"))), + //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))), + genEventToken_(consumes(edm::InputTag("generator"))) + //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) +{ + produces(); + produces(); +} + + +GenWeightProductProducer::~GenWeightProductProducer() +{ +} + + +// ------------ method called to produce the data ------------ +void +GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + edm::Handle genEventInfo; + iEvent.getByToken(genEventToken_, genEventInfo); + // Read weights from LHEEventProduct + auto weightProduct = weightHelper_.weightProduct(genEventInfo->weights()); + iEvent.put(std::move(weightProduct)); +} + +void +GenWeightProductProducer::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) {} + +void +GenWeightProductProducer::beginLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) { + edm::Handle genLumiInfoHandle; + iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle); + + weightNames_ = genLumiInfoHandle->weightNames(); +} + +// ------------ method called when starting to processes a run ------------ +void +GenWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) { + weightHelper_.parseWeightGroupsFromNames(weightNames_); + auto weightInfoProduct = std::make_unique(); + for (auto& weightGroup : weightHelper_.weightGroups()) { + weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); + } + run.put(std::move(weightInfoProduct)); +} + + +// ------------ method called when ending the processing of a run ------------ +void +GenWeightProductProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) { +} + +DEFINE_FWK_MODULE(GenWeightProductProducer); + + diff --git a/GeneratorInterface/Core/src/GenWeightHelper.cc b/GeneratorInterface/Core/src/GenWeightHelper.cc new file mode 100644 index 0000000000000..197f804012b92 --- /dev/null +++ b/GeneratorInterface/Core/src/GenWeightHelper.cc @@ -0,0 +1,32 @@ +#include "GeneratorInterface/Core/interface/GenWeightHelper.h" +#include + +using namespace tinyxml2; + +namespace gen { + GenWeightHelper::GenWeightHelper() { + } + + void + GenWeightHelper::parseWeightGroupsFromNames(std::vector weightNames) { + int index = 0; + + if (weightNames.size() <= 1) + return; + + for (std::string weightName : weightNames) { + if(weightName.find("LHE") != std::string::npos) { + // Parse as usual, this is the SUSY workflow + } + // Working on the not-so-nice assumption that all non-LHE gen weights are PS weights + else if (weightGroups_.size() == 0) { + weightGroups_.push_back(new gen::PartonShowerWeightGroupInfo(weightName)); + auto& group = weightGroups_.back(); + // No IDs for Gen weights + group.addContainedId(index, "", weightName); + } + } + } +} + + diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index acd1557f332e6..35617c1c007bc 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -1,25 +1,37 @@ #include "GeneratorInterface/Core/interface/WeightHelper.h" namespace gen { + // TODO: Could probably recycle this code better + std::unique_ptr WeightHelper::weightProduct(std::vector weights) { + auto weightProduct = std::make_unique(); + weightProduct->setNumWeightSets(weightGroups_.size()); + int weightGroupIndex = 0; + for (unsigned int i = 0; i < weightGroups_.size(); i++) { + addWeightToProduct(weightProduct, weights.at(i), "", i, weightGroupIndex); + } + return std::move(weightProduct); + } + std::unique_ptr WeightHelper::weightProduct(std::vector weights) { auto weightProduct = std::make_unique(); weightProduct->setNumWeightSets(weightGroups_.size()); int weightGroupIndex = 0; - int weightNum = 0; + int i = 0; for (const auto& weight : weights) { - weightGroupIndex = findContainingWeightGroup(weight.id, weightNum, weightGroupIndex); - if (weightGroupIndex < 0 || weightGroupIndex >= static_cast(weightGroups_.size())) { - // Needs to be properly handled - throw std::range_error("Unmatched weight"); - } - auto group = weightGroups_[weightGroupIndex]; - int entry = group.weightVectorEntry(weight.id, weightNum); - weightProduct->addWeight(weight.wgt, weightGroupIndex, entry); - weightNum++; + weightGroupIndex = addWeightToProduct(weightProduct, weight.wgt, weight.id, i++, weightGroupIndex); } return std::move(weightProduct); } + int WeightHelper::addWeightToProduct(std::unique_ptr& product, + double weight, std::string name, int weightNum, int groupIndex) { + groupIndex = findContainingWeightGroup(name, weightNum, groupIndex); + auto group = weightGroups_[groupIndex]; + int entry = group.weightVectorEntry(name, weightNum); + product->addWeight(weight, groupIndex, entry); + return groupIndex; + } + int WeightHelper::findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex) { // Start search at previous index, under expectation of ordered weights previousGroupIndex = previousGroupIndex >=0 ? previousGroupIndex : 0; @@ -38,7 +50,8 @@ namespace gen { return counter; counter++; } - return -1; + // Needs to be properly handled + throw std::range_error("Unmatched weight"); } } diff --git a/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py similarity index 59% rename from GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py rename to GeneratorInterface/Core/test/testGenWeightProducer_cfg.py index 2330e55313fb1..7eba1fb2543dd 100644 --- a/GeneratorInterface/Core/test/testLHEWeightProducer_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py @@ -4,7 +4,7 @@ process.source = cms.Source("PoolSource", # replace 'myfile.root' with the source file you want to use - fileNames = cms.untracked.vstring("/store/mc/RunIISummer16MiniAODv3/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_94X_mcRun2_asymptotic_v3_ext1-v2/120000/CC675D46-5EDF-E811-B537-3CFDFE63DF40.root") + fileNames = cms.untracked.vstring("/store/mc/RunIIAutumn18MiniAOD/DYJetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8/MINIAODSIM/102X_upgrade2018_realistic_v15-v1/80000/E53E0D52-39FF-6F42-A8B2-EEF28EEB4C43.root") #fileNames = cms.untracked.vstring("file:CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root"), ) @@ -15,9 +15,10 @@ outputCommands = cms.untracked.vstring(['keep *']) ) -process.testWeights = cms.EDProducer("LHEWeightProductProducer") +process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer") +process.testGenWeights = cms.EDProducer("GenWeightProductProducer") -process.p = cms.Path(process.testWeights) +process.p = cms.Path(process.testLHEWeights*process.testGenWeights) process.output = cms.EndPath(process.out) process.schedule = cms.Schedule(process.p,process.output) diff --git a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc index 718447db14b96..a5284f5fd3c15 100644 --- a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc @@ -40,7 +40,7 @@ namespace gen { if (!indexInRange(weightEntry)) { size_t orderedEntry = weightEntry - firstId_; if (orderedEntry < idsContained_.size()) - if (idsContained_.at(orderedEntry).id == wgtId) + if (!wgtId.empty() && idsContained_.at(orderedEntry).id == wgtId) return orderedEntry; } auto it = std::find_if(idsContained_.begin(), idsContained_.end(), From acc3817b6f810b8f2fdd40e0c0c66ed86d989a13 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 3 Oct 2019 19:34:38 -0400 Subject: [PATCH 43/75] Fix nasty bug searching for weights by index TODO: Still need to find out how to get the weightgroupinfo into the beginrun --- .../Core/plugins/GenWeightProductProducer.cc | 15 +++++------ .../Core/src/GenWeightHelper.cc | 9 ++++--- GeneratorInterface/Core/src/WeightHelper.cc | 2 +- .../Core/test/testGenWeightProducer_cfg.py | 3 ++- .../LHEInterface/test/testWeights.py | 15 +++++++---- .../GeneratorProducts/src/WeightGroupInfo.cc | 26 ++++++++++++------- 6 files changed, 41 insertions(+), 29 deletions(-) diff --git a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc index c08f3258579b8..03d57297dc703 100644 --- a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc @@ -55,7 +55,7 @@ GenWeightProductProducer::GenWeightProductProducer(const edm::ParameterSet& iCon //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) { produces(); - produces(); + produces(); } @@ -83,23 +83,22 @@ GenWeightProductProducer::beginLuminosityBlock(const edm::LuminosityBlock& iLumi iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle); weightNames_ = genLumiInfoHandle->weightNames(); + weightHelper_.parseWeightGroupsFromNames(weightNames_); } // ------------ method called when starting to processes a run ------------ void GenWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) { - weightHelper_.parseWeightGroupsFromNames(weightNames_); - auto weightInfoProduct = std::make_unique(); - for (auto& weightGroup : weightHelper_.weightGroups()) { - weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); - } - run.put(std::move(weightInfoProduct)); } - // ------------ method called when ending the processing of a run ------------ void GenWeightProductProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) { + auto weightInfoProduct = std::make_unique(); + for (auto& weightGroup : weightHelper_.weightGroups()) { + weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); + } + run.put(std::move(weightInfoProduct)); } DEFINE_FWK_MODULE(GenWeightProductProducer); diff --git a/GeneratorInterface/Core/src/GenWeightHelper.cc b/GeneratorInterface/Core/src/GenWeightHelper.cc index 197f804012b92..182040728a752 100644 --- a/GeneratorInterface/Core/src/GenWeightHelper.cc +++ b/GeneratorInterface/Core/src/GenWeightHelper.cc @@ -17,14 +17,15 @@ namespace gen { for (std::string weightName : weightNames) { if(weightName.find("LHE") != std::string::npos) { // Parse as usual, this is the SUSY workflow + continue; } // Working on the not-so-nice assumption that all non-LHE gen weights are PS weights else if (weightGroups_.size() == 0) { - weightGroups_.push_back(new gen::PartonShowerWeightGroupInfo(weightName)); - auto& group = weightGroups_.back(); - // No IDs for Gen weights - group.addContainedId(index, "", weightName); + weightGroups_.push_back(new gen::PartonShowerWeightGroupInfo("shower")); } + auto& group = weightGroups_.back(); + // No IDs for Gen weights + group.addContainedId(index++, "", weightName); } } } diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index 35617c1c007bc..990c471e675a4 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -6,7 +6,7 @@ namespace gen { auto weightProduct = std::make_unique(); weightProduct->setNumWeightSets(weightGroups_.size()); int weightGroupIndex = 0; - for (unsigned int i = 0; i < weightGroups_.size(); i++) { + for (unsigned int i = 0; i < weights.size(); i++) { addWeightToProduct(weightProduct, weights.at(i), "", i, weightGroupIndex); } return std::move(weightProduct); diff --git a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py index 7eba1fb2543dd..79648fa6fce33 100644 --- a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py @@ -18,7 +18,8 @@ process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer") process.testGenWeights = cms.EDProducer("GenWeightProductProducer") -process.p = cms.Path(process.testLHEWeights*process.testGenWeights) +#process.p = cms.Path(process.testLHEWeights*process.testGenWeights) +process.p = cms.Path(process.testGenWeights) process.output = cms.EndPath(process.out) process.schedule = cms.Schedule(process.p,process.output) diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/LHEInterface/test/testWeights.py index 131dc483b24ab..26f858ec1431c 100644 --- a/GeneratorInterface/LHEInterface/test/testWeights.py +++ b/GeneratorInterface/LHEInterface/test/testWeights.py @@ -1,11 +1,12 @@ from DataFormats.FWLite import Events,Handle,Runs import ROOT -source = "externalLHEProducer" -#source = "testWeights" +#source = "externalLHEProducer" +#source = "testLHEWeights" +source = "testGenWeights" #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: -for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: -#for filename in ["test.root"]: +#for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: +for filename in ["test.root"]: runs = Runs(filename) run = runs.__iter__().next() weightInfoHandle = Handle("GenWeightInfoProduct") @@ -17,6 +18,10 @@ weightHandle = Handle("GenWeightProduct") event.getByLabel(source, weightHandle) weightInfo = weightHandle.product() + print weightInfo + print len(weightInfo.weights()) + print weightInfoProd.allWeightGroupsInfo() + print len(weightInfoProd.allWeightGroupsInfo()) print "Content of the weights" for j, weights in enumerate(weightInfo.weights()): print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 @@ -26,7 +31,7 @@ for var in [(x, y) for x in ["05", "1", "2"] for y in ["05", "1", "2"]]: name = "muR%smuF%sIndex" % (var[0], var[1]) if not (var[0] == "1" and var[1] == "1") else "centralIndex" print name, getattr(matching, name)() - else: + elif matching.weightType() == 0: print "uncertaintyType", "Hessian" if matching.uncertaintyType() == ROOT.gen.kHessianUnc else "MC" print "Weights length?", len(weights), "Contained ids lenths?", len(matching.containedIds()) print "-"*80 diff --git a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc index a5284f5fd3c15..86940ae70a9f0 100644 --- a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc @@ -3,6 +3,8 @@ #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "FWCore/Utilities/interface/Exception.h" +#include + namespace gen { void WeightGroupInfo::copy(const WeightGroupInfo &other) { isWellFormed_ = true; @@ -36,26 +38,30 @@ namespace gen { } int WeightGroupInfo::weightVectorEntry(const std::string& wgtId, int weightEntry) const { - int entry = -1; - if (!indexInRange(weightEntry)) { + // First try ordered search + if (indexInRange(weightEntry)) { size_t orderedEntry = weightEntry - firstId_; if (orderedEntry < idsContained_.size()) - if (!wgtId.empty() && idsContained_.at(orderedEntry).id == wgtId) + if (wgtId.empty() || idsContained_.at(orderedEntry).id == wgtId) { return orderedEntry; + } + } + // Fall back to search on ID + else if (!wgtId.empty()) { + auto it = std::find_if(idsContained_.begin(), idsContained_.end(), + [wgtId] (const WeightMetaInfo& w) { return w.id == wgtId; }); + if (it != idsContained_.end()) + return std::distance(idsContained_.begin(), it); } - auto it = std::find_if(idsContained_.begin(), idsContained_.end(), - [wgtId] (const WeightMetaInfo& w) { return w.id == wgtId; }); - if (it != idsContained_.end()) - return std::distance(idsContained_.begin(), it); - return entry; + return -1; } void WeightGroupInfo::addContainedId(int weightEntry, std::string id, std::string label="") { if (firstId_ == -1 || weightEntry < firstId_) { firstId_ = weightEntry; // Reset to reflect that indices will be shifted - for (auto& id : idsContained_) - id.localIndex = id.globalIndex - firstId_; + for (auto& entry : idsContained_) + entry.localIndex = entry.globalIndex - firstId_; } if (weightEntry > lastId_) lastId_ = weightEntry; From 27a923953edc24c3909ee96ffcc59c48150d3625 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 4 Oct 2019 07:36:32 -0400 Subject: [PATCH 44/75] Clean up test script for LHE weights a bit --- .../Core/test/testGenWeightProducer_cfg.py | 4 +-- .../LHEInterface/plugins/LHEWeightsTest.cc | 25 ------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py index 79648fa6fce33..0634cd548d0f7 100644 --- a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py @@ -18,8 +18,8 @@ process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer") process.testGenWeights = cms.EDProducer("GenWeightProductProducer") -#process.p = cms.Path(process.testLHEWeights*process.testGenWeights) -process.p = cms.Path(process.testGenWeights) +process.p = cms.Path(process.testLHEWeights*process.testGenWeights) +#process.p = cms.Path(process.testGenWeights) process.output = cms.EndPath(process.out) process.schedule = cms.Schedule(process.p,process.output) diff --git a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc index 8af5fc7c017e4..db453a9009945 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc @@ -223,14 +223,6 @@ std::pair find_z_candidate(std::vectormother(0); - if(abs(mother->pdgId()) != abs(daughter->pdgId())) { - return mother; - }else{ - return find_first_mother_with_different_id(mother); - } -} std::vector clean_jets(const std::vector genJets, const std::vector leptons){ std::vector cleaned_jets; @@ -282,22 +274,6 @@ bool has_v_in_history(reco::GenParticle const & part){ return false; } } -std::vector clean_v_jets(const std::vector & genJets){ - std::vector cleaned; - for( auto const & j : genJets ) { - bool found = false; - for( auto const & c: j.getGenConstituents() ) { - found |= has_v_in_history(*c); - if(found) break; - } - if(not found){ - cleaned.push_back(j); - } - } - - return cleaned; -} - void LHEWeightsTest::setup_variables(const edm::Event& iEvent) { using namespace edm; @@ -337,7 +313,6 @@ void LHEWeightsTest::setup_variables(const edm::Event& iEvent) { //// Jets std::vector jets = clean_jets(select_jets(*genJets),leptons); - //std::vector jets = clean_v_jets(clean_jets(select_jets(*genJets),leptons)); int njets = jets.size(); variables["n_jets"] = njets; variables["pt_jet1"] = njets > 0 ? jets.at(0).pt() : -999; From 7402487d89a5c1d1dd40bda529e4d0089bc5b4e6 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 4 Oct 2019 09:28:44 -0400 Subject: [PATCH 45/75] Start to implement useful functions for PdfGroupInfo --- .../LHEInterface/plugins/LHEWeightsTest.cc | 10 +++++++++ .../interface/PdfWeightGroupInfo.h | 21 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc index db453a9009945..2109529e9abc0 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc @@ -108,6 +108,10 @@ class LHEWeightsTest : public edm::one::EDAnalyzer { TH1D * h_count_event; TH1D * h_count_sumw; + + const unsigned int KEEP_LHAPDFID_ = 23000; + int keepPdfSetIndex_ = 0; + int keepPdfIndexInSet_ = -1; }; // @@ -413,6 +417,12 @@ LHEWeightsTest::beginRun(edm::Run const& run, edm::EventSetup const& es) { scaleWeightsOrder_.push_back(scaleWeights->muR2muF05Index()); scaleWeightsOrder_.push_back(scaleWeights->muR2muF1Index()); scaleWeightsOrder_.push_back(scaleWeights->muR2muF2Index()); + + //auto pdfSets = lheWeightInfoHandle->weightGroupIndicesByType(gen::kPdfWeights); + + //for (const auto& pdfSet : pdfSets) { + // keepPdfIndex_ = pdfSet.indexOfLhapdfId(KEEP_LHAPDFID_); + // if (keepPdfIdex = -1) } //define this as a plug-in diff --git a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h index 4f853103d4241..fd81e15687daf 100644 --- a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h @@ -16,7 +16,7 @@ namespace gen { bool hasAlphasVars_; int alphasUpIndex_; int alphasDownIndex_; - std::vector lhapdfIdsContained_; + std::vector> lhapdfIdsContained_; public: PdfWeightGroupInfo() : WeightGroupInfo() { weightType_ = kPdfWeights; } PdfWeightGroupInfo(std::string header, std::string name) : @@ -37,10 +37,25 @@ namespace gen { PdfUncertaintyType uncertaintyType() const { return uncertaintyType_; } bool hasAlphasVariations() const { return hasAlphasVars_; } bool containsMultipleSets() const { return lhapdfIdsContained_.size() > 1; } + bool containsLhapdfId(size_t lhaid) const { return indexOfLhapdfId(lhaid) != -1; } + int indexOfLhapdfId(size_t lhaid) const { + for (const auto& id : lhapdfIdsContained_) { + if (id.first == lhaid) + return id.second; + } + return -1; + } int alphasUpIndex() const { return alphasUpIndex_; } int alphasDownIndex() const { return alphasDownIndex_; } - void addLhapdfId(int lhaid) { lhapdfIdsContained_.push_back(lhaid); } - std::vector getLhapdfIdsContained() const { return lhapdfIdsContained_; } + void addLhapdfId(size_t lhaid, size_t index) { + lhapdfIdsContained_.push_back(std::make_pair(lhaid, index)); + } + std::vector getLhapdfIdsContained() const { + std::vector lhaids; + for (const auto& id : lhapdfIdsContained_) + lhaids.push_back(id.first); + return lhaids; + } }; } From b744a77cacdc520c1d7da23ead44966c5ddc6e99 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 4 Oct 2019 10:46:16 -0400 Subject: [PATCH 46/75] Put product in lumi instead of run Still need to fix for LHESource (which has been neglected in any case) --- .../Core/plugins/GenWeightProductProducer.cc | 40 ++++++------------- .../Core/plugins/LHEWeightProductProducer.cc | 29 +++++++------- .../plugins/ExternalLHEProducer.cc | 19 +++++---- .../LHEInterface/plugins/LHEWeightsTest.cc | 14 +++---- 4 files changed, 46 insertions(+), 56 deletions(-) diff --git a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc index 03d57297dc703..7c7f90cdba0df 100644 --- a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc @@ -24,9 +24,7 @@ #include "FWCore/ServiceRegistry/interface/Service.h" -class GenWeightProductProducer : public edm::one::EDProducer { +class GenWeightProductProducer : public edm::one::EDProducer { public: explicit GenWeightProductProducer(const edm::ParameterSet& iConfig); ~GenWeightProductProducer() override; @@ -38,11 +36,7 @@ class GenWeightProductProducer : public edm::one::EDProducer genEventToken_; void produce(edm::Event&, const edm::EventSetup&) override; - void beginRunProduce(edm::Run& run, edm::EventSetup const& es) override; - void endRunProduce(edm::Run&, edm::EventSetup const&) override; - void beginLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) override; - void endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) override; - + void beginLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const& c) override; }; // @@ -55,7 +49,7 @@ GenWeightProductProducer::GenWeightProductProducer(const edm::ParameterSet& iCon //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) { produces(); - produces(); + produces(); } @@ -74,31 +68,23 @@ GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe iEvent.put(std::move(weightProduct)); } -void -GenWeightProductProducer::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) {} +//void +//GenWeightProductProducer::endLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) {} void -GenWeightProductProducer::beginLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) { - edm::Handle genLumiInfoHandle; - iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle); - - weightNames_ = genLumiInfoHandle->weightNames(); - weightHelper_.parseWeightGroupsFromNames(weightNames_); -} +GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) { + if (weightNames_.size() == 0) { + edm::Handle genLumiInfoHandle; + iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle); -// ------------ method called when starting to processes a run ------------ -void -GenWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) { -} - -// ------------ method called when ending the processing of a run ------------ -void -GenWeightProductProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) { + weightNames_ = genLumiInfoHandle->weightNames(); + weightHelper_.parseWeightGroupsFromNames(weightNames_); + } auto weightInfoProduct = std::make_unique(); for (auto& weightGroup : weightHelper_.weightGroups()) { weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); } - run.put(std::move(weightInfoProduct)); + iLumi.put(std::move(weightInfoProduct)); } DEFINE_FWK_MODULE(GenWeightProductProducer); diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index 6b73575c98c4c..3310410615b59 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -25,8 +25,8 @@ #include "FWCore/ServiceRegistry/interface/Service.h" -class LHEWeightProductProducer : public edm::one::EDProducer { +class LHEWeightProductProducer : public edm::one::EDProducer { public: explicit LHEWeightProductProducer(const edm::ParameterSet& iConfig); ~LHEWeightProductProducer() override; @@ -37,8 +37,9 @@ class LHEWeightProductProducer : public edm::one::EDProducer lheEventToken_; void produce(edm::Event&, const edm::EventSetup&) override; - void beginRunProduce(edm::Run& run, edm::EventSetup const& es) override; - void endRunProduce(edm::Run&, edm::EventSetup const&) override; + void beginLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& es) override; + void beginRun(edm::Run const& run, edm::EventSetup const& es) override; + void endRun(edm::Run const& run, edm::EventSetup const& es) override; }; @@ -52,7 +53,7 @@ LHEWeightProductProducer::LHEWeightProductProducer(const edm::ParameterSet& iCon //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) { produces(); - produces(); + produces(); } @@ -73,7 +74,7 @@ LHEWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe // ------------ method called when starting to processes a run ------------ void -LHEWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) { +LHEWeightProductProducer::beginRun(edm::Run const& run, edm::EventSetup const& es) { edm::Handle lheRunInfoHandle; //run.getByToken(lheRunInfoToken_, lheRunInfoHandle); // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) @@ -82,23 +83,23 @@ LHEWeightProductProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& typedef std::vector::const_iterator header_cit; LHERunInfoProduct::Header headerWeightInfo; for (header_cit iter=lheRunInfoHandle->headers_begin(); iter!=lheRunInfoHandle->headers_end(); iter++) { - //for (header_cit iter=lheRunInfoProduct.headers_begin(); iter!=lheRunInfoProduct.headers_end(); iter++) { if (iter->tag() == "initrwgt") headerWeightInfo = *iter; } weightHelper_.parseWeightGroupsFromHeader(headerWeightInfo.lines()); +} + +void +LHEWeightProductProducer::endRun(edm::Run const& run, edm::EventSetup const& es) { } + +void +LHEWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& es) { auto weightInfoProduct = std::make_unique(); for (auto& weightGroup : weightHelper_.weightGroups()) { weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); } - run.put(std::move(weightInfoProduct)); -} - - -// ------------ method called when ending the processing of a run ------------ -void -LHEWeightProductProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) { + lumi.put(std::move(weightInfoProduct)); } DEFINE_FWK_MODULE(LHEWeightProductProducer); diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index a07e650b4c7f0..9acc5ff473b28 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -71,7 +71,8 @@ Description: [one line class summary] // class ExternalLHEProducer : public edm::one::EDProducer { + edm::EndRunProducer, + edm::EndLuminosityBlockProducer> { public: explicit ExternalLHEProducer(const edm::ParameterSet& iConfig); ~ExternalLHEProducer() override; @@ -83,6 +84,7 @@ class ExternalLHEProducer : public edm::one::EDProducer(); produces(); produces(); - produces(); + produces(); } @@ -386,15 +388,18 @@ ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es) reader_.reset(); + if (unlink(outputFile_.c_str())) { + throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ")."; + } +} + +void +ExternalLHEProducer::endLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& es) { auto weightInfoProduct = std::make_unique(); for (auto& weightGroup : weightHelper_.weightGroups()) { weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); } - run.put(std::move(weightInfoProduct)); - - if (unlink(outputFile_.c_str())) { - throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ")."; - } + lumi.put(std::move(weightInfoProduct)); } // ------------ Close all the open file descriptors ------------ diff --git a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc index 2109529e9abc0..c0af4f32791fc 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc @@ -66,7 +66,7 @@ // constructor "usesResource("TFileService");" // This will improve performance in multithreaded jobs. -class LHEWeightsTest : public edm::one::EDAnalyzer { +class LHEWeightsTest : public edm::one::EDAnalyzer { public: explicit LHEWeightsTest(const edm::ParameterSet&); ~LHEWeightsTest(); @@ -76,8 +76,8 @@ class LHEWeightsTest : public edm::one::EDAnalyzer { private: virtual void beginJob() override; - virtual void endRun(edm::Run const& iRun, edm::EventSetup const&) {} - virtual void beginRun(edm::Run const& iRun, edm::EventSetup const&) override; + virtual void beginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) override; + virtual void endLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) override {} virtual void analyze(const edm::Event&, const edm::EventSetup&) override; virtual void endJob() override; @@ -133,7 +133,7 @@ LHEWeightsTest::LHEWeightsTest(const edm::ParameterSet& iConfig) : LHEToken_(consumes(iConfig.getParameter("LHESrc"))), GenToken_(consumes(iConfig.getParameter("GenSrc"))), lheWeightToken_(consumes(edm::InputTag("testWeights"))), - lheWeightInfoToken_(consumes(edm::InputTag("testWeights"))) + lheWeightInfoToken_(consumes(edm::InputTag("testWeights"))) { //now do what ever initialization is needed @@ -392,14 +392,12 @@ LHEWeightsTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { } void -LHEWeightsTest::beginRun(edm::Run const& run, edm::EventSetup const& es) { +LHEWeightsTest::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const& es) { //edm::Handle lheWeightsInfoHandle; - // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) - //run.getByLabel("testWeights", lheWeightsInfoHandle); //edm::Handle lheWeightsInfoHandle; //run.getByLabel("generator", lheWeightsInfoHandle); edm::Handle lheWeightInfoHandle; - run.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); + iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); // Should add a search by name function scaleWeightsIndex_ = lheWeightInfoHandle->weightGroupIndicesByType(gen::kScaleWeights).front(); From a30dacf9518651c94a251e3ff3c8f4d7a46f4ad3 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sun, 6 Oct 2019 19:40:25 -0400 Subject: [PATCH 47/75] Some cleanup + nasty bug fix in lhapdfIds Make sure to copy everything in the copy functions or horrible things happen --- .../Core/interface/LHEWeightHelper.h | 6 +- .../Core/interface/WeightHelper.h | 20 ++- .../Core/src/LHEWeightHelper.cc | 165 ++++++++---------- GeneratorInterface/Core/src/WeightHelper.cc | 77 ++++++++ .../Core/test/testGenWeightProducer_cfg.py | 2 +- .../LHEInterface/test/testWeights.py | 70 ++++---- .../interface/PdfWeightGroupInfo.h | 16 +- .../src/PdfWeightGroupInfo.cc | 1 + 8 files changed, 214 insertions(+), 143 deletions(-) diff --git a/GeneratorInterface/Core/interface/LHEWeightHelper.h b/GeneratorInterface/Core/interface/LHEWeightHelper.h index 8beb9dbbca21e..8a54f71bb6c6e 100644 --- a/GeneratorInterface/Core/interface/LHEWeightHelper.h +++ b/GeneratorInterface/Core/interface/LHEWeightHelper.h @@ -7,6 +7,7 @@ #include #include +#include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" @@ -23,9 +24,8 @@ namespace gen { void parseLHEFile(std::string filename); void parseWeightGroupsFromHeader(std::vector lheHeader); private: + std::map weightAttributeMapFromHeaderLine(std::string line); void loadAttributeNames(std::string baseName, std::vector altNames ={}); - std::string toLowerCase(const char*); - std::string toLowerCase(const std::string); std::map getAttributeMap(std::string); std::string sanitizeText(std::string); bool isAWeight(std::string); @@ -34,7 +34,7 @@ namespace gen { std::regex weightGroupEnd_; std::regex weightContent_; - std::map nameConvMap; + std::map nameConversionMap_; }; } diff --git a/GeneratorInterface/Core/interface/WeightHelper.h b/GeneratorInterface/Core/interface/WeightHelper.h index 1540f9404c42f..da6084fcca18c 100644 --- a/GeneratorInterface/Core/interface/WeightHelper.h +++ b/GeneratorInterface/Core/interface/WeightHelper.h @@ -4,18 +4,34 @@ #include "DataFormats/Common/interface/OwnVector.h" #include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/WeightsInfo.h" +#include namespace gen { + struct PdfSetInfo { + std::string name; + int lhapdfId; + PdfUncertaintyType uncertaintyType; + }; + class WeightHelper { public: - WeightHelper() {} - edm::OwnVector weightGroups() {return weightGroups_;} + WeightHelper(); + edm::OwnVector weightGroups() { + return weightGroups_; + } std::unique_ptr weightProduct(std::vector); std::unique_ptr weightProduct(std::vector); + void setGroupInfo(); + bool currentGroupIsScale(); + bool currentGroupIsPdf(); int addWeightToProduct(std::unique_ptr& product, double weight, std::string name, int weightNum, int groupIndex); int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex); protected: + const std::vector pdfSetsInfo; + std::map currWeightAttributeMap_; + std::map currGroupAttributeMap_; edm::OwnVector weightGroups_; }; } diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index 63966dc5ccb79..ddaea95dd75bb 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -4,28 +4,11 @@ using namespace tinyxml2; namespace gen { - std::string - LHEWeightHelper::toLowerCase(const char* name) { - std::string returnStr; - for (size_t i = 0; i < strlen(name); ++i) - returnStr.push_back(tolower(name[i])); - return returnStr; - } - - std::string - LHEWeightHelper::toLowerCase(const std::string name) { - std::string returnStr = name; - transform(name.begin(), name.end(), returnStr.begin(), ::tolower); - return returnStr; - - - } - void LHEWeightHelper::loadAttributeNames(std::string baseName, std::vector altNames) { for(auto altname : altNames) { - nameConvMap[altname] = baseName; + nameConversionMap_[altname] = baseName; } - nameConvMap[baseName] = baseName; + nameConversionMap_[baseName] = baseName; } std::string @@ -48,8 +31,6 @@ namespace gen { weightGroupStart_ = std::regex(".*.*\n*"); weightGroupEnd_ = std::regex(".*.*\n*"); - std::cout << "Init" << "\n"; - /// Might change later, order matters and code doesn't pick choices // Used for translating different naming convention to a common one @@ -69,44 +50,35 @@ namespace gen { XMLDocument xmlParser; int error = xmlParser.Parse(line.c_str()); if (error) { - std::cout << "we have a problem!" << "\n"; - return std::map(); - //do something.... + return std::map(); } - std::map attMap; + std::map attributeMap; XMLElement* element = xmlParser.FirstChildElement(); for( const XMLAttribute* a = element->FirstAttribute(); a; a=a->Next()) { - attMap[nameConvMap[toLowerCase(a->Name())]] = a->Value(); + auto name = boost::algorithm::to_lower_copy(std::string(a->Name())); + attributeMap[nameConversionMap_[name]] = a->Value(); } // get stuff from content of tag if it has anything. // always assume format is AAAAA=( )BBBB ( ) => optional space if (element->GetText() == nullptr) { - return attMap; + return attributeMap; } // This adds "content: " to the beginning of the content. not sure if its a big deal or? std::string content = element->GetText(); - attMap["content"] = content; + attributeMap["content"] = content; - std::regex reg("(?:(\\S+)=\\s*(\\S+))"); - std::smatch m; - while(std::regex_search(content, m, reg)) { - std::string key = nameConvMap[toLowerCase(m.str(1))]; - if (attMap[key] != std::string()) { - if (m[2] != attMap[key]) { - std::cout << m.str(2) << " vs " << attMap[key]; - // might do something if content and attribute don't match? - // but need to be careful since some are purposefully different - // eg dyn_scale is described in content but just given a number - } + for (const auto& entry : weightAttributeMapFromHeaderLine(content)) { + auto rawLabel = boost::algorithm::to_lower_copy(entry.first); + std::string label = nameConversionMap_[rawLabel]; + if (nameConversionMap_.find(label) != nameConversionMap_.end()) + attributeMap.at(nameConversionMap_[label]) = entry.second; + else + attributeMap[label] = entry.second; } - else { - attMap[key] = m.str(2); - } - content = m.suffix().str(); - } - return attMap; + + return attributeMap; } @@ -122,85 +94,86 @@ namespace gen { return element; } + std::map + LHEWeightHelper::weightAttributeMapFromHeaderLine(std::string line) { + std::regex reg("(?:(\\S+)=\\s*(\\S+))"); + std::smatch match; + std::map weightAttributeMap; + while(std::regex_search(line, match, reg)) { + weightAttributeMap[match.str(1)] = match.str(2); + line = match.suffix().str(); + } + return weightAttributeMap; + } + void LHEWeightHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { // TODO: Not sure the weight indexing is right here, this seems to more or less // count the lines which isn't quite the goal. TOCHECK! int index = 0; - bool foundGroup = false; + currGroupAttributeMap_.clear(); + currWeightAttributeMap_.clear(); for (std::string headerLine : lheHeader) { - std::cout << "Header line is:" << headerLine; headerLine = sanitizeText(headerLine); - std::cout << "Header line is:" << weightGroups_.size() << " "<< headerLine; - //TODO: Fine for now, but in general there should also be a check on the PDF weights, - // e.g., it could be an unknown weight if (std::regex_match(headerLine, weightGroupStart_)) { - //std::cout << "Adding new group for headerLine" << std::endl; - foundGroup = true; + if (!currGroupAttributeMap_.empty()) + setGroupInfo(); std::string fullTag = headerLine + ""; - auto groupMap = getAttributeMap(fullTag); - std::string name = groupMap["name"]; + currGroupAttributeMap_ = getAttributeMap(fullTag); + auto name = currGroupAttributeMap_["name"]; - if(name.find("Central scale variation") != std::string::npos || - name.find("scale_variation") != std::string::npos) { - weightGroups_.push_back(new gen::ScaleWeightGroupInfo(name)); + if (currentGroupIsScale()) + weightGroups_.push_back(std::make_unique(name)); + else if (currentGroupIsPdf()) { + weightGroups_.push_back(std::make_unique(name)); } - else - weightGroups_.push_back(new gen::PdfWeightGroupInfo(name)); + else + weightGroups_.push_back(std::make_unique(name)); } - /// file weights - else if (foundGroup && isAWeight(headerLine)) { - //std::cout << "Adding new weight for headerLine" << std::endl; - auto tagsMap = getAttributeMap(headerLine); - for(auto pair: tagsMap) { - std::cout << pair.first << ": " << pair.second << " | "; - } - std::cout << "\n"; + else if (isAWeight(headerLine)) { + currWeightAttributeMap_.clear(); + // This shouldn't really happen, but perhaps we find weights outside of weight groups? + if (currGroupAttributeMap_.empty()) + weightGroups_.push_back(std::make_unique("Unknown")); + currWeightAttributeMap_ = getAttributeMap(headerLine); - std::string content = tagsMap["content"]; - if (tagsMap["id"].empty()) { + std::string content = currWeightAttributeMap_["content"]; + if (currWeightAttributeMap_["id"].empty()) { std::cout << "error" << "\n"; // should do something } auto& group = weightGroups_.back(); if (group.weightType() == gen::kScaleWeights) { - if (tagsMap["mur"].empty() || tagsMap["muf"].empty()) { - std::cout << "error" << "\n"; - // something should happen here - continue; + if (currWeightAttributeMap_["mur"].empty() || currWeightAttributeMap_["muf"].empty()) + group.setIsWellFormed(false); + else { + try { + float muR = std::stof(currWeightAttributeMap_["mur"]); + float muF = std::stof(currWeightAttributeMap_["muf"]); + auto& scaleGroup = dynamic_cast(group); + scaleGroup.addContainedId(index, currWeightAttributeMap_["id"], headerLine, muR, muF); + } + catch(std::invalid_argument& e) { + group.setIsWellFormed(false); + group.addContainedId(index, currWeightAttributeMap_["id"], headerLine); + } } - float muR = std::stof(tagsMap["mur"]); - float muF = std::stof(tagsMap["muf"]); - std::cout << tagsMap["id"] << " " << muR << " " << muF << " " << content << "\n"; - auto& scaleGroup = static_cast(group); - scaleGroup.addContainedId(index, tagsMap["id"], headerLine, muR, muF); } else - group.addContainedId(index, tagsMap["id"], headerLine); + group.addContainedId(index, currWeightAttributeMap_["id"], headerLine); index++; } - // commented out since code doesn't work with this in.... - // else if(isAWeight(headerLine)) { - // // found header. Don't know what to do with it so just shove it into a new weightgroup for now - // // do minimum work for it - // weightGroups_.push_back(new gen::PdfWeightGroupInfo(headerLine)); - // auto& group = weightGroups_.back(); - // auto tagsMap = getAttributeMap(headerLine); - // group.addContainedId(index, tagsMap["id"], headerLine); - // foundGroup = true; - // index++; - // } - - else if(std::regex_match(headerLine, weightGroupEnd_)) { - foundGroup = false; - } - else { - std::cout << "problem!!!" << "\n"; + else if (std::regex_match(headerLine, weightGroupEnd_)) { + if (!currGroupAttributeMap_.empty()) + setGroupInfo(); + currGroupAttributeMap_.clear(); + currWeightAttributeMap_.clear(); } + // Should be fine to ignore all other lines? Tend to be either empty or closing tag } } } diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index 990c471e675a4..8caacc6c4edae 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -1,6 +1,83 @@ #include "GeneratorInterface/Core/interface/WeightHelper.h" namespace gen { + WeightHelper::WeightHelper() : + pdfSetsInfo({ + // In principle this can be parsed from $LHAPDF_DATA_PATH/pdfsets.index, + // but do we really want to do that? Can also just hardcode a subset... + {"NNPDF31_nnlo_hessian_pdfas", 306000, kHessianUnc}, + {"NNPDF31_nnlo_as_0118", 303600, kMonteCarloUnc}, + {"NNPDF31_nlo_as_0118", 303400, kMonteCarloUnc}, + {"NNPDF31_nlo_hessian_pdfas", 305800, kHessianUnc}, + {"NNPDF31_nnlo_as_0108", 322500, kVariationSet}, + {"NNPDF31_nnlo_as_0110", 322700, kVariationSet}, + {"NNPDF31_nnlo_as_0112", 322900, kVariationSet}, + {"NNPDF31_nnlo_as_0114", 323100, kVariationSet}, + {"NNPDF31_nnlo_as_0117", 323300, kVariationSet}, + {"NNPDF31_nnlo_as_0119", 323500, kVariationSet}, + {"NNPDF31_nnlo_as_0122", 323700, kVariationSet}, + {"NNPDF31_nnlo_as_0124", 323900, kVariationSet}, + {"NNPDF31_nlo_as_0118_nf_4", 320500, kMonteCarloUnc}, + {"NNPDF31_nnlo_as_0118_nf_4", 320900, kMonteCarloUnc}, + {"NNPDF30_nlo_nf_5_pdfas", 292200, kMonteCarloUnc}, + {"NNPDF30_nnlo_nf_5_pdfas", 292600, kMonteCarloUnc}, + {"NNPDF30_nnlo_nf_4_pdfas", 292400, kMonteCarloUnc}, + {"NNPDF30_nlo_nf_4_pdfas", 292000, kMonteCarloUnc}, + {"NNPDF30_lo_as_0130", 263000, kMonteCarloUnc}, + {"NNPDF30_lo_as_0118", 262000, kMonteCarloUnc}, + {"CT14nnlo", 13000, kHessianUnc}, + {"CT14nlo", 13100, kHessianUnc}, + {"CT14nnlo_as_0116", 13065, kVariationSet}, + {"CT14nnlo_as_0120", 13069, kVariationSet}, + {"CT14nlo_as_0116", 13163, kVariationSet}, + {"CT14nlo_as_0120", 13167, kVariationSet}, + {"CT14lo", 13200, kVariationSet}, + {"MMHT2014nlo68clas118", 25200, kHessianUnc}, + {"MMHT2014nnlo68cl", 25300, kHessianUnc}, + {"MMHT2014lo68cl", 25000, kHessianUnc}, + {"PDF4LHC15_nlo_100_pdfas", 90200, kMonteCarloUnc}, + {"PDF4LHC15_nnlo_100_pdfas", 91200, kMonteCarloUnc}, + {"PDF4LHC15_nlo_30_pdfas", 90400, kMonteCarloUnc}, + {"PDF4LHC15_nnlo_30_pdfas", 91400, kMonteCarloUnc}, + {"ABMP16als118_5_nnlo", 42780, kHessianUnc}, + {"HERAPDF20_NLO_EIG", 61130, kHessianUnc}, + {"HERAPDF20_NNLO_EIG", 61200, kHessianUnc}, + {"HERAPDF20_NLO_VAR", 61130, kHessianUnc}, + {"HERAPDF20_NNLO_VAR", 61230, kHessianUnc}, + {"CT14qed_inc_proton", 13400, kHessianUnc}, + {"LUXqed17_plus_PDF4LHC15_nnlo_100", 82200, kMonteCarloUnc}, + }) + {} + + void WeightHelper::setGroupInfo() { + auto& group = weightGroups_.back(); + const std::string& name = group.name(); + if (group.weightType() == kPdfWeights) { + PdfWeightGroupInfo* pdfGroup = dynamic_cast(&group); + auto pdfInfo = std::find_if(pdfSetsInfo.begin(), pdfSetsInfo.end(), + [name] (const PdfSetInfo& setInfo) { return setInfo.name == name; }); + if (pdfInfo != pdfSetsInfo.end()) { + pdfGroup->setUncertaintyType(pdfInfo->uncertaintyType); + pdfGroup->addLhapdfId(pdfInfo->lhapdfId, 0); + } + else + pdfGroup->setIsWellFormed(false); + } + } + + bool WeightHelper::currentGroupIsScale() { + std::string name = boost::algorithm::to_lower_copy(currGroupAttributeMap_["name"]); + return (name.find("scale") != std::string::npos); + } + + bool WeightHelper::currentGroupIsPdf() { + std::string name = currGroupAttributeMap_["name"]; + if (boost::algorithm::to_lower_copy(name).find("pdf") != std::string::npos) + return true; + return std::find_if(pdfSetsInfo.begin(), pdfSetsInfo.end(), + [name] (const PdfSetInfo& setInfo) { return setInfo.name == name; }) != pdfSetsInfo.end(); + } + // TODO: Could probably recycle this code better std::unique_ptr WeightHelper::weightProduct(std::vector weights) { auto weightProduct = std::make_unique(); diff --git a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py index 0634cd548d0f7..e856a9a34e876 100644 --- a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py @@ -19,7 +19,7 @@ process.testGenWeights = cms.EDProducer("GenWeightProductProducer") process.p = cms.Path(process.testLHEWeights*process.testGenWeights) -#process.p = cms.Path(process.testGenWeights) +#process.p = cms.Path(process.testLHEWeights) process.output = cms.EndPath(process.out) process.schedule = cms.Schedule(process.p,process.output) diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/LHEInterface/test/testWeights.py index 26f858ec1431c..24e7c99e2465b 100644 --- a/GeneratorInterface/LHEInterface/test/testWeights.py +++ b/GeneratorInterface/LHEInterface/test/testWeights.py @@ -1,45 +1,45 @@ -from DataFormats.FWLite import Events,Handle,Runs +from DataFormats.FWLite import Events,Handle,Runs,Lumis import ROOT #source = "externalLHEProducer" -#source = "testLHEWeights" -source = "testGenWeights" +sources = ["testLHEWeights", "testGenWeights"] +#source = "testGenWeights" #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: for filename in ["test.root"]: - runs = Runs(filename) - run = runs.__iter__().next() - weightInfoHandle = Handle("GenWeightInfoProduct") - run.getByLabel(source, weightInfoHandle) - weightInfoProd = weightInfoHandle.product() + for source in sources: + lumis = Lumis(filename) + lumi = lumis.__iter__().next() + weightInfoHandle = Handle("GenWeightInfoProduct") + lumi.getByLabel(source, weightInfoHandle) + weightInfoProd = weightInfoHandle.product() - events = Events(filename) - event = events.__iter__().next() - weightHandle = Handle("GenWeightProduct") - event.getByLabel(source, weightHandle) - weightInfo = weightHandle.product() - print weightInfo - print len(weightInfo.weights()) - print weightInfoProd.allWeightGroupsInfo() - print len(weightInfoProd.allWeightGroupsInfo()) - print "Content of the weights" - for j, weights in enumerate(weightInfo.weights()): - print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 - matching = weightInfoProd.orderedWeightGroupInfo(j) - print "Group is", matching - if matching.weightType() == 1: - for var in [(x, y) for x in ["05", "1", "2"] for y in ["05", "1", "2"]]: - name = "muR%smuF%sIndex" % (var[0], var[1]) if not (var[0] == "1" and var[1] == "1") else "centralIndex" - print name, getattr(matching, name)() - elif matching.weightType() == 0: - print "uncertaintyType", "Hessian" if matching.uncertaintyType() == ROOT.gen.kHessianUnc else "MC" - print "Weights length?", len(weights), "Contained ids lenths?", len(matching.containedIds()) - print "-"*80 - for i,weight in enumerate(weights): - print i, weight - info = matching.weightMetaInfo(i) - print " ID, localIndex, globalIndex, label, set:", info.id, info.localIndex, info.globalIndex, info.label, matching.name() - print "-"*80 + events = Events(filename) + event = events.__iter__().next() + weightHandle = Handle("GenWeightProduct") + event.getByLabel(source, weightHandle) + weightInfo = weightHandle.product() + print weightInfoProd.allWeightGroupsInfo(), len(weightInfoProd.allWeightGroupsInfo()) + print "Content of the weights" + for j, weights in enumerate(weightInfo.weights()): + print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 + matching = weightInfoProd.orderedWeightGroupInfo(j) + print "Group is", matching, "name is", matching.name(), "well formed?", matching.isWellFormed() + if matching.weightType() == 1: + for var in [(x, y) for x in ["05", "1", "2"] for y in ["05", "1", "2"]]: + name = "muR%smuF%sIndex" % (var[0], var[1]) if not (var[0] == "1" and var[1] == "1") else "centralIndex" + print name, getattr(matching, name)() + elif matching.weightType() == 0: + print "uncertaintyType", "Hessian" if matching.uncertaintyType() == ROOT.gen.kHessianUnc else "MC" + print "contains LHAPDFIds", len(matching.lhapdfIdsContained()), [i for i in matching.lhapdfIdsContained()], + print "Has alphas? ", matching.hasAlphasVariations() + print "Weights length?", len(weights), "Contained ids lenths?", len(matching.containedIds()) + print "-"*80 + for i,weight in enumerate(weights): + print i, weight + info = matching.weightMetaInfo(i) + print " ID, localIndex, globalIndex, label, set:", info.id, info.localIndex, info.globalIndex, info.label, matching.name() + print "-"*80 diff --git a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h index fd81e15687daf..54556811ac4d8 100644 --- a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h @@ -2,11 +2,13 @@ #define SimDataFormats_GeneratorProducts_PdfWeightGroupInfo_h #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include namespace gen { enum PdfUncertaintyType { kHessianUnc, kMonteCarloUnc, + kVariationSet, kUnknownUnc, }; @@ -16,7 +18,7 @@ namespace gen { bool hasAlphasVars_; int alphasUpIndex_; int alphasDownIndex_; - std::vector> lhapdfIdsContained_; + std::vector> lhapdfIdsContained_; public: PdfWeightGroupInfo() : WeightGroupInfo() { weightType_ = kPdfWeights; } PdfWeightGroupInfo(std::string header, std::string name) : @@ -37,8 +39,8 @@ namespace gen { PdfUncertaintyType uncertaintyType() const { return uncertaintyType_; } bool hasAlphasVariations() const { return hasAlphasVars_; } bool containsMultipleSets() const { return lhapdfIdsContained_.size() > 1; } - bool containsLhapdfId(size_t lhaid) const { return indexOfLhapdfId(lhaid) != -1; } - int indexOfLhapdfId(size_t lhaid) const { + bool containsLhapdfId(int lhaid) const { return indexOfLhapdfId(lhaid) != -1; } + int indexOfLhapdfId(int lhaid) const { for (const auto& id : lhapdfIdsContained_) { if (id.first == lhaid) return id.second; @@ -47,17 +49,19 @@ namespace gen { } int alphasUpIndex() const { return alphasUpIndex_; } int alphasDownIndex() const { return alphasDownIndex_; } - void addLhapdfId(size_t lhaid, size_t index) { + void addLhapdfId(int lhaid, int index) { lhapdfIdsContained_.push_back(std::make_pair(lhaid, index)); } - std::vector getLhapdfIdsContained() const { + std::vector lhapdfIdsContained() const { std::vector lhaids; - for (const auto& id : lhapdfIdsContained_) + for (const auto& id : lhapdfIdsContained_) { lhaids.push_back(id.first); + } return lhaids; } }; } + #endif // SimDataFormats_GeneratorProducts_PdfWeightGroupInfo_h diff --git a/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc index 4e0175bf9629c..5dfbf814f323e 100644 --- a/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/PdfWeightGroupInfo.cc @@ -6,6 +6,7 @@ namespace gen { hasAlphasVars_ = other.hasAlphasVariations(); alphasUpIndex_ = other.alphasDownIndex(); alphasDownIndex_ = other.alphasDownIndex(); + lhapdfIdsContained_ = other.lhapdfIdsContained_; WeightGroupInfo::copy(other); } From 2b1b520300ec3465bb7cf26a6467d257ac647bf5 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 7 Oct 2019 08:52:49 -0400 Subject: [PATCH 48/75] Remove dummy analyzer --- GeneratorInterface/Core/src/WeightHelper.cc | 1 + .../test/dumpWeightInfo.py} | 0 .../TestAnalyzer/plugins/BuildFile.xml | 6 - .../TestAnalyzer/plugins/TestAnalyzer.cc | 162 ------------------ .../TestAnalyzer/test/BuildFile.xml | 4 - .../test/test_catch2_TestAnalyzer.cc | 51 ------ .../TestAnalyzer/test/test_catch2_main.cc | 2 - TestWeightInfo/TestAnalyzer/test/test_cfg.py | 17 -- 8 files changed, 1 insertion(+), 242 deletions(-) rename GeneratorInterface/{LHEInterface/test/testWeights.py => Core/test/dumpWeightInfo.py} (100%) delete mode 100644 TestWeightInfo/TestAnalyzer/plugins/BuildFile.xml delete mode 100644 TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc delete mode 100644 TestWeightInfo/TestAnalyzer/test/BuildFile.xml delete mode 100644 TestWeightInfo/TestAnalyzer/test/test_catch2_TestAnalyzer.cc delete mode 100644 TestWeightInfo/TestAnalyzer/test/test_catch2_main.cc delete mode 100644 TestWeightInfo/TestAnalyzer/test/test_cfg.py diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index 8caacc6c4edae..fbf58491198de 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -5,6 +5,7 @@ namespace gen { pdfSetsInfo({ // In principle this can be parsed from $LHAPDF_DATA_PATH/pdfsets.index, // but do we really want to do that? Can also just hardcode a subset... + // TODO: Actually we can just take this from LHAPDF {"NNPDF31_nnlo_hessian_pdfas", 306000, kHessianUnc}, {"NNPDF31_nnlo_as_0118", 303600, kMonteCarloUnc}, {"NNPDF31_nlo_as_0118", 303400, kMonteCarloUnc}, diff --git a/GeneratorInterface/LHEInterface/test/testWeights.py b/GeneratorInterface/Core/test/dumpWeightInfo.py similarity index 100% rename from GeneratorInterface/LHEInterface/test/testWeights.py rename to GeneratorInterface/Core/test/dumpWeightInfo.py diff --git a/TestWeightInfo/TestAnalyzer/plugins/BuildFile.xml b/TestWeightInfo/TestAnalyzer/plugins/BuildFile.xml deleted file mode 100644 index 29ffa306d8174..0000000000000 --- a/TestWeightInfo/TestAnalyzer/plugins/BuildFile.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc b/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc deleted file mode 100644 index 1cb1c7ca73e9a..0000000000000 --- a/TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc +++ /dev/null @@ -1,162 +0,0 @@ -// -*- C++ -*- -// -// Package: TestWeightInfo/TestAnalyzer -// Class: TestAnalyzer -// -/**\class TestAnalyzer TestAnalyzer.cc TestWeightInfo/TestAnalyzer/plugins/TestAnalyzer.cc - - Description: [one line class summary] - - Implementation: - [Notes on implementation] -*/ -// -// Original Author: Kenneth David Long -// Created: Wed, 18 Sep 2019 13:44:58 GMT -// -// - - -// system include files -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/Run.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" - #include "FWCore/Utilities/interface/InputTag.h" - #include "DataFormats/TrackReco/interface/Track.h" - #include "DataFormats/TrackReco/interface/TrackFwd.h" - #include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" - #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" - #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" -// -// class declaration -// - -// If the analyzer does not use TFileService, please remove -// the template argument to the base class so the class inherits -// from edm::one::EDAnalyzer<> -// This will improve performance in multithreaded jobs. - - -using reco::TrackCollection; - -class TestAnalyzer : public edm::one::EDAnalyzer { - public: - explicit TestAnalyzer(const edm::ParameterSet&); - ~TestAnalyzer(); - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - - private: - edm::EDGetTokenT lheWeightInfoToken_; - virtual void beginJob() override; - void beginRun(edm::Run const& iRun, edm::EventSetup const&) override; - void endRun(edm::Run const& iRun, edm::EventSetup const&) override; - virtual void analyze(const edm::Event&, const edm::EventSetup&) override; - virtual void endJob() override; - - // ----------member data --------------------------- -}; - -// -// constants, enums and typedefs -// - -// -// static data member definitions -// - -// -// constructors and destructor -// -TestAnalyzer::TestAnalyzer(const edm::ParameterSet& iConfig) : - lheWeightInfoToken_(consumes(edm::InputTag("externalLHEProducer"))) -{ - //now do what ever initialization is needed - -} - - -TestAnalyzer::~TestAnalyzer() -{ - - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) - -} - - -// -// member functions -// - -// ------------ method called for each event ------------ -void -TestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - std::cerr << "Event" << std::endl; -} - -#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE - ESHandle pSetup; - iSetup.get().get(pSetup); -#endif - - -// ------------ method called once each job just before starting event loop ------------ -void -TestAnalyzer::beginJob() -{ -} - -// ------------ method called once each job just after ending the event loop ------------ -void -TestAnalyzer::endJob() -{ -} - -void TestAnalyzer::endRun(edm::Run const& iRun, edm::EventSetup const&) {} - -void TestAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const&) -{ - edm::Handle lheWeightInfoHandle; - iRun.getByToken( lheWeightInfoToken_, lheWeightInfoHandle ); - - const GenWeightInfoProduct* lheProd = lheWeightInfoHandle.product(); - edm::OwnVector groups = lheProd->allWeightGroupsInfo(); - for (const auto& group : groups) { - std::cout << "Type of the weight is " << group.weightType() << " name is " << group.name() << std::endl; - if (group.weightType() == 1) { - //gen::ScaleWeightGroupInfo* scaleInfo = group.clone();//static_cast(group); - const gen::ScaleWeightGroupInfo* scaleInfo = dynamic_cast(&group); - std::cout << "muR05muF1 " << scaleInfo->muR05muF1Index() << std::endl; - std::cout << "muR05muF05 " << scaleInfo->muR05muF05Index() << std::endl; - } - } -} -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void -TestAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); - - //Specify that only 'tracks' is allowed - //To use, remove the default given above and uncomment below - //ParameterSetDescription desc; - //desc.addUntracked("tracks","ctfWithMaterialTracks"); - //descriptions.addDefault(desc); -} - -//define this as a plug-in -DEFINE_FWK_MODULE(TestAnalyzer); diff --git a/TestWeightInfo/TestAnalyzer/test/BuildFile.xml b/TestWeightInfo/TestAnalyzer/test/BuildFile.xml deleted file mode 100644 index 853ca18422452..0000000000000 --- a/TestWeightInfo/TestAnalyzer/test/BuildFile.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/TestWeightInfo/TestAnalyzer/test/test_catch2_TestAnalyzer.cc b/TestWeightInfo/TestAnalyzer/test/test_catch2_TestAnalyzer.cc deleted file mode 100644 index fa1c318a56534..0000000000000 --- a/TestWeightInfo/TestAnalyzer/test/test_catch2_TestAnalyzer.cc +++ /dev/null @@ -1,51 +0,0 @@ -#include "catch.hpp" -#include "FWCore/TestProcessor/interface/TestProcessor.h" -#include "FWCore/Utilities/interface/Exception.h" - -static constexpr auto s_tag = "[TestAnalyzer]"; - -TEST_CASE("Standard checks of TestAnalyzer", s_tag) { - const std::string baseConfig{ -R"_(from FWCore.TestProcessor.TestProcess import * -process = TestProcess() -process.toTest = cms.EDProducer("TestAnalyzer" -#necessary configuration parameters - ) -process.moduleToTest(process.toTest) -)_" - }; - - edm::test::TestProcessor::Config config{ baseConfig }; - SECTION("base configuration is OK") { - REQUIRE_NOTHROW(edm::test::TestProcessor(config)); - } - - SECTION("No event data") { - edm::test::TestProcessor tester(config); - - REQUIRE_THROWS_AS(tester.test(), cms::Exception); - //If the module does not throw when given no data, substitute - //REQUIRE_NOTHROW for REQUIRE_THROWS_AS - } - - SECTION("beginJob and endJob only") { - edm::test::TestProcessor tester(config); - - REQUIRE_NOTHROW(tester.testBeginAndEndJobOnly()); - } - - SECTION("Run with no LuminosityBlocks") { - edm::test::TestProcessor tester(config); - - REQUIRE_NOTHROW(tester.testRunWithNoLuminosityBlocks()); - } - - SECTION("LuminosityBlock with no Events") { - edm::test::TestProcessor tester(config); - - REQUIRE_NOTHROW(tester.testLuminosityBlockWithNoEvents()); - } - -} - -//Add additional TEST_CASEs to exercise the modules capabilities diff --git a/TestWeightInfo/TestAnalyzer/test/test_catch2_main.cc b/TestWeightInfo/TestAnalyzer/test/test_catch2_main.cc deleted file mode 100644 index 0c7c351f437f5..0000000000000 --- a/TestWeightInfo/TestAnalyzer/test/test_catch2_main.cc +++ /dev/null @@ -1,2 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include "catch.hpp" diff --git a/TestWeightInfo/TestAnalyzer/test/test_cfg.py b/TestWeightInfo/TestAnalyzer/test/test_cfg.py deleted file mode 100644 index f856a8ce87a42..0000000000000 --- a/TestWeightInfo/TestAnalyzer/test/test_cfg.py +++ /dev/null @@ -1,17 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -process = cms.Process("test") - -process.source = cms.Source("PoolSource", - # replace 'myfile.root' with the source file you want to use - fileNames = cms.untracked.vstring("/store/mc/RunIISummer16MiniAODv3/WJetsToLNu_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_94X_mcRun2_asymptotic_v3-v2/20000/CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root") - ) - -process.TFileService = cms.Service("TFileService", - fileName = cms.string("test.root") -) - -process.testWeights = cms.EDAnalyzer("LHEWeightProductProducer") - -process.p = cms.Path(process.testWeights) - From d307670532843a19d40b326ed6676f918c46c92e Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 7 Oct 2019 12:42:22 -0400 Subject: [PATCH 49/75] Move example weight test producer --- GeneratorInterface/Core/plugins/BuildFile.xml | 9 ++++-- .../plugins/GenWeightsTestAnalyzer.cc} | 32 +++++++++---------- .../Core/src/LHEWeightHelper.cc | 2 +- .../testGenWeights_simpleZanalyzer_cfg.py} | 2 +- .../LHEInterface/plugins/BuildFile.xml | 17 ---------- 5 files changed, 25 insertions(+), 37 deletions(-) rename GeneratorInterface/{LHEInterface/plugins/LHEWeightsTest.cc => Core/plugins/GenWeightsTestAnalyzer.cc} (93%) rename GeneratorInterface/{LHEInterface/test/test_ZPlotting_LHEweights_cfg.py => Core/test/testGenWeights_simpleZanalyzer_cfg.py} (97%) diff --git a/GeneratorInterface/Core/plugins/BuildFile.xml b/GeneratorInterface/Core/plugins/BuildFile.xml index af12a8119d35c..83ce8d6a7c13d 100644 --- a/GeneratorInterface/Core/plugins/BuildFile.xml +++ b/GeneratorInterface/Core/plugins/BuildFile.xml @@ -6,7 +6,12 @@ + + + + + + + - - diff --git a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc b/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc similarity index 93% rename from GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc rename to GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc index c0af4f32791fc..7c87b477e962b 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEWeightsTest.cc +++ b/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc @@ -1,9 +1,9 @@ // -*- C++ -*- // -// Package: GenAnalysis/LHEWeightsTest -// Class: LHEWeightsTest +// Package: GenAnalysis/GenWeightsTestAnalyzer +// Class: GenWeightsTestAnalyzer // -/**\class LHEWeightsTest LHEWeightsTest.cc GenAnalysis/LHEWeightsTest/plugins/LHEWeightsTest.cc +/**\class GenWeightsTestAnalyzer GenWeightsTestAnalyzer.cc GenAnalysis/GenWeightsTestAnalyzer/plugins/GenWeightsTestAnalyzer.cc Description: [one line class summary] @@ -66,10 +66,10 @@ // constructor "usesResource("TFileService");" // This will improve performance in multithreaded jobs. -class LHEWeightsTest : public edm::one::EDAnalyzer { +class GenWeightsTestAnalyzer : public edm::one::EDAnalyzer { public: - explicit LHEWeightsTest(const edm::ParameterSet&); - ~LHEWeightsTest(); + explicit GenWeightsTestAnalyzer(const edm::ParameterSet&); + ~GenWeightsTestAnalyzer(); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); @@ -125,7 +125,7 @@ class LHEWeightsTest : public edm::one::EDAnalyzer("tag")), isMiniaod_(iConfig.getParameter("miniaod")), genParticleToken_(consumes(iConfig.getParameter("genParticleSrc"))), @@ -160,7 +160,7 @@ LHEWeightsTest::LHEWeightsTest(const edm::ParameterSet& iConfig) : } -LHEWeightsTest::~LHEWeightsTest() +GenWeightsTestAnalyzer::~GenWeightsTestAnalyzer() { // do anything here that needs to be done at desctruction time @@ -279,7 +279,7 @@ bool has_v_in_history(reco::GenParticle const & part){ } } -void LHEWeightsTest::setup_variables(const edm::Event& iEvent) { +void GenWeightsTestAnalyzer::setup_variables(const edm::Event& iEvent) { using namespace edm; //// Initialize with dummy values @@ -331,7 +331,7 @@ void LHEWeightsTest::setup_variables(const edm::Event& iEvent) { variables["ht"] = ht; } -std::vector LHEWeightsTest::setup_weights(const edm::Event& iEvent) { +std::vector GenWeightsTestAnalyzer::setup_weights(const edm::Event& iEvent) { edm::Handle lheWeightHandle; iEvent.getByToken(lheWeightToken_, lheWeightHandle); const GenWeightProduct * lheWeights = lheWeightHandle.product(); @@ -348,7 +348,7 @@ std::vector LHEWeightsTest::setup_weights(const edm::Event& iEvent) { // ------------ method called for each event ------------ void -LHEWeightsTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) +GenWeightsTestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; @@ -371,19 +371,19 @@ LHEWeightsTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) // ------------ method called once each job just before starting event loop ------------ void -LHEWeightsTest::beginJob() +GenWeightsTestAnalyzer::beginJob() { } // ------------ method called once each job just after ending the event loop ------------ void -LHEWeightsTest::endJob() +GenWeightsTestAnalyzer::endJob() { } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void -LHEWeightsTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +GenWeightsTestAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { //The following says we do not know what parameters are allowed so do no validation // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; @@ -392,7 +392,7 @@ LHEWeightsTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { } void -LHEWeightsTest::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const& es) { +GenWeightsTestAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const& es) { //edm::Handle lheWeightsInfoHandle; //edm::Handle lheWeightsInfoHandle; //run.getByLabel("generator", lheWeightsInfoHandle); @@ -424,5 +424,5 @@ LHEWeightsTest::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::Eve } //define this as a plug-in -DEFINE_FWK_MODULE(LHEWeightsTest); +DEFINE_FWK_MODULE(GenWeightsTestAnalyzer); diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index ddaea95dd75bb..f63120b427400 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -73,7 +73,7 @@ namespace gen { auto rawLabel = boost::algorithm::to_lower_copy(entry.first); std::string label = nameConversionMap_[rawLabel]; if (nameConversionMap_.find(label) != nameConversionMap_.end()) - attributeMap.at(nameConversionMap_[label]) = entry.second; + attributeMap[nameConversionMap_[label]] = entry.second; else attributeMap[label] = entry.second; } diff --git a/GeneratorInterface/LHEInterface/test/test_ZPlotting_LHEweights_cfg.py b/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py similarity index 97% rename from GeneratorInterface/LHEInterface/test/test_ZPlotting_LHEweights_cfg.py rename to GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py index a0acb131f23c4..0a6bfe3336233 100644 --- a/GeneratorInterface/LHEInterface/test/test_ZPlotting_LHEweights_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py @@ -61,7 +61,7 @@ def commandline(): process.testWeights = cms.EDProducer("LHEWeightProductProducer") -process.demo = cms.EDAnalyzer('LHEWeightsTest', +process.demo = cms.EDAnalyzer('GenWeightsTestAnalyzer', tag = cms.string(options.tag), miniaod = cms.bool(options.isMiniAOD), genParticleSrc = cms.InputTag("prunedGenParticles" if options.isMiniAOD else "genParticles"), diff --git a/GeneratorInterface/LHEInterface/plugins/BuildFile.xml b/GeneratorInterface/LHEInterface/plugins/BuildFile.xml index c9f6865d98d5a..96e1834824f70 100644 --- a/GeneratorInterface/LHEInterface/plugins/BuildFile.xml +++ b/GeneratorInterface/LHEInterface/plugins/BuildFile.xml @@ -17,20 +17,3 @@ - - - - - - - - - - - - - - - - - From bbdd4626eed90e045dfdc0a1826da10673187d4a Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 7 Oct 2019 18:09:32 -0400 Subject: [PATCH 50/75] Add PDF and PS weights in example --- .../Core/plugins/GenWeightsTestAnalyzer.cc | 54 ++++++++++++++----- .../Core/src/LHEWeightHelper.cc | 4 +- .../testGenWeights_simpleZanalyzer_cfg.py | 5 +- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc b/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc index 7c87b477e962b..aead5ad2baff4 100644 --- a/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc +++ b/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc @@ -88,13 +88,15 @@ class GenWeightsTestAnalyzer : public edm::one::EDAnalyzer scaleWeightsOrder_; - unsigned int scaleWeightsIndex_; + int scaleWeightsIndex_; + int pdfWeightsIndex_; edm::EDGetTokenT genParticleToken_; edm::EDGetTokenT genJetToken_; edm::EDGetTokenT LHEToken_; edm::EDGetTokenT GenToken_; edm::EDGetTokenT lheWeightToken_; + edm::EDGetTokenT genWeightToken_; edm::EDGetTokenT lheWeightInfoToken_; edm::Service fileservice; @@ -128,12 +130,15 @@ class GenWeightsTestAnalyzer : public edm::one::EDAnalyzer("tag")), isMiniaod_(iConfig.getParameter("miniaod")), + scaleWeightsIndex_(-1), + pdfWeightsIndex_(-1), genParticleToken_(consumes(iConfig.getParameter("genParticleSrc"))), genJetToken_(consumes(iConfig.getParameter("genJetSrc"))), LHEToken_(consumes(iConfig.getParameter("LHESrc"))), GenToken_(consumes(iConfig.getParameter("GenSrc"))), - lheWeightToken_(consumes(edm::InputTag("testWeights"))), - lheWeightInfoToken_(consumes(edm::InputTag("testWeights"))) + lheWeightToken_(consumes(edm::InputTag("testLheWeights"))), + genWeightToken_(consumes(edm::InputTag("testGenWeights"))), + lheWeightInfoToken_(consumes(edm::InputTag("testLheWeights"))) { //now do what ever initialization is needed @@ -333,15 +338,32 @@ void GenWeightsTestAnalyzer::setup_variables(const edm::Event& iEvent) { } std::vector GenWeightsTestAnalyzer::setup_weights(const edm::Event& iEvent) { edm::Handle lheWeightHandle; + edm::Handle genWeightHandle; iEvent.getByToken(lheWeightToken_, lheWeightHandle); - const GenWeightProduct * lheWeights = lheWeightHandle.product(); - WeightsContainer weights = lheWeights->weights(); - auto scaleWeights = weights.at(scaleWeightsIndex_); + iEvent.getByToken(genWeightToken_, genWeightHandle); + const GenWeightProduct * lheWeightProduct = lheWeightHandle.product(); + const GenWeightProduct * genWeightProduct = genWeightHandle.product(); + WeightsContainer lheWeights = lheWeightProduct->weights(); + WeightsContainer genWeights = genWeightProduct->weights(); + + auto scaleWeights = scaleWeightsIndex_ >= 0 ? lheWeights.at(scaleWeightsIndex_) : std::vector(); + auto pdfWeights = pdfWeightsIndex_ > 0 ? lheWeights.at(pdfWeightsIndex_) : std::vector(); std::vector keepWeights; for(auto i : scaleWeightsOrder_){ - keepWeights.push_back(scaleWeights[i]); + keepWeights.push_back(scaleWeights.at(i)); } + + for(auto& weight : pdfWeights){ + keepWeights.push_back(weight); + } + + if (genWeights.size() > 0) { + for(auto& weight : genWeights.front()){ + keepWeights.push_back(weight); + } + } + return keepWeights; } @@ -400,7 +422,10 @@ GenWeightsTestAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); // Should add a search by name function - scaleWeightsIndex_ = lheWeightInfoHandle->weightGroupIndicesByType(gen::kScaleWeights).front(); + auto allScaleWeights = lheWeightInfoHandle->weightGroupIndicesByType(gen::kScaleWeights); + if (allScaleWeights.size() > 0) + scaleWeightsIndex_ = allScaleWeights.front(); + auto scaleWeights = static_cast( lheWeightInfoHandle->orderedWeightGroupInfo(scaleWeightsIndex_)); // nano ordering of mur=0.5 muf=0.5 ; [1] is mur=0.5 muf=1 ; [2] is mur=0.5 muf=2 ; [3] is mur=1 muf=0.5 ; @@ -416,11 +441,14 @@ GenWeightsTestAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, scaleWeightsOrder_.push_back(scaleWeights->muR2muF1Index()); scaleWeightsOrder_.push_back(scaleWeights->muR2muF2Index()); - //auto pdfSets = lheWeightInfoHandle->weightGroupIndicesByType(gen::kPdfWeights); - - //for (const auto& pdfSet : pdfSets) { - // keepPdfIndex_ = pdfSet.indexOfLhapdfId(KEEP_LHAPDFID_); - // if (keepPdfIdex = -1) + auto pdfGroups = lheWeightInfoHandle->weightGroupsByType(gen::kPdfWeights); + auto ct14Set = std::find_if(pdfGroups.begin(), pdfGroups.end(), + [] (gen::WeightGroupInfo* group) { + auto pdfGroup = dynamic_cast(group); + return pdfGroup->containsLhapdfId(1300); + }); + if (ct14Set != pdfGroups.end()) + pdfWeightsIndex_ = std::distance(pdfGroups.begin(), ct14Set); } //define this as a plug-in diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index f63120b427400..73fb67b19b195 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -135,8 +135,8 @@ namespace gen { else if (isAWeight(headerLine)) { currWeightAttributeMap_.clear(); // This shouldn't really happen, but perhaps we find weights outside of weight groups? - if (currGroupAttributeMap_.empty()) - weightGroups_.push_back(std::make_unique("Unknown")); + //if (weightGroups_.empty()) + // weightGroups_.push_back(std::make_unique("Unknown")); currWeightAttributeMap_ = getAttributeMap(headerLine); std::string content = currWeightAttributeMap_["content"]; diff --git a/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py b/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py index 0a6bfe3336233..4e364b0aa2557 100644 --- a/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py @@ -59,7 +59,8 @@ def commandline(): fileNames = cms.untracked.vstring( options.inputFiles ) ) -process.testWeights = cms.EDProducer("LHEWeightProductProducer") +process.testLheWeights = cms.EDProducer("LHEWeightProductProducer") +process.testGenWeights = cms.EDProducer("GenWeightProductProducer") process.demo = cms.EDAnalyzer('GenWeightsTestAnalyzer', tag = cms.string(options.tag), @@ -73,5 +74,5 @@ def commandline(): process.TFileService = cms.Service("TFileService", fileName = cms.string("analysis_{TAG}.root".format(TAG=options.tag)) ) -process.p = cms.Path(process.testWeights*process.demo) +process.p = cms.Path(process.testLheWeights*process.testGenWeights*process.demo) From 916af263127388c664ff9ab32f70448a3bdf3b9e Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Tue, 8 Oct 2019 11:16:58 -0400 Subject: [PATCH 51/75] Make the test script more general --- .../Core/plugins/LHEWeightProductProducer.cc | 12 ++++++----- .../Core/test/testGenWeightProducer_cfg.py | 21 ++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index 3310410615b59..0c98c2832d1a4 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -33,6 +33,7 @@ class LHEWeightProductProducer : public edm::one::EDProducer lheRunInfoToken_; edm::EDGetTokenT lheEventToken_; @@ -47,10 +48,11 @@ class LHEWeightProductProducer : public edm::one::EDProducer(edm::InputTag("externalLHEProducer"))), - //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))), - lheEventToken_(consumes(edm::InputTag("externalLHEProducer"))) - //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) + lheLabel_(iConfig.getUntrackedParameter("lheSourceLabel")), + lheRunInfoToken_(consumes( + iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))), + lheEventToken_(consumes( + iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) { produces(); produces(); @@ -78,7 +80,7 @@ LHEWeightProductProducer::beginRun(edm::Run const& run, edm::EventSetup const& e edm::Handle lheRunInfoHandle; //run.getByToken(lheRunInfoToken_, lheRunInfoHandle); // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) - run.getByLabel("externalLHEProducer", lheRunInfoHandle); + run.getByLabel(lheLabel_, lheRunInfoHandle); typedef std::vector::const_iterator header_cit; LHERunInfoProduct::Header headerWeightInfo; diff --git a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py index e856a9a34e876..cc1e1830d2d68 100644 --- a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py @@ -1,21 +1,32 @@ import FWCore.ParameterSet.Config as cms +from FWCore.ParameterSet.VarParsing import VarParsing + +options = VarParsing('analysis') +options.register( + "lheSource", + "externalLHEProducer", + VarParsing.multiplicity.singleton, + VarParsing.varType.string, + "LHE source (default externalLHEProducer)" +) +options.parseArguments() process = cms.Process("test") process.source = cms.Source("PoolSource", - # replace 'myfile.root' with the source file you want to use - fileNames = cms.untracked.vstring("/store/mc/RunIIAutumn18MiniAOD/DYJetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8/MINIAODSIM/102X_upgrade2018_realistic_v15-v1/80000/E53E0D52-39FF-6F42-A8B2-EEF28EEB4C43.root") - #fileNames = cms.untracked.vstring("file:CCC44F9F-64EF-E811-8F69-7845C4FBBD07.root"), + fileNames = cms.untracked.vstring(options.inputFiles) ) -process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(100)) +process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(options.maxEvents)) process.out = cms.OutputModule("PoolOutputModule", fileName = cms.untracked.string('test.root'), outputCommands = cms.untracked.vstring(['keep *']) ) -process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer") +process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer", + lheSource=cms.untracked.InputTag(options.lheSource), + lheSourceLabel=cms.untracked.string(options.lheSource)) process.testGenWeights = cms.EDProducer("GenWeightProductProducer") process.p = cms.Path(process.testLHEWeights*process.testGenWeights) From 70cdb973eb995bd020db9d8830f0ef53bb3fd043 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 19 Dec 2019 17:06:45 +0100 Subject: [PATCH 52/75] New LHEWeightsTableProducer --- PhysicsTools/NanoAOD/BuildFile.xml | 1 + .../plugins/GenWeightsTableProducer.cc | 45 +----- .../plugins/LHEWeightsTableProducer.cc | 138 ++++++++++++++++++ PhysicsTools/NanoAOD/python/nanogen_cff.py | 114 +++++++++++++++ 4 files changed, 254 insertions(+), 44 deletions(-) create mode 100644 PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc create mode 100644 PhysicsTools/NanoAOD/python/nanogen_cff.py diff --git a/PhysicsTools/NanoAOD/BuildFile.xml b/PhysicsTools/NanoAOD/BuildFile.xml index c36ed4184624a..1d6f1f6d5dccb 100644 --- a/PhysicsTools/NanoAOD/BuildFile.xml +++ b/PhysicsTools/NanoAOD/BuildFile.xml @@ -5,6 +5,7 @@ + diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc index 77c8989defef1..9a86e108bc1b8 100644 --- a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -233,10 +233,6 @@ class GenWeightsTableProducer : public edm::global::EDProducer(); produces("genModel"); - produces("LHEScale"); - produces("LHEPdf"); - produces("LHEReweighting"); - produces("LHENamed"); produces("PS"); produces(); if (namedWeightIDs_.size() != namedWeightLabels_.size()) { @@ -273,7 +269,6 @@ class GenWeightsTableProducer : public edm::global::EDProducer lheScaleTab, lhePdfTab, lheRwgtTab, lheNamedTab; std::unique_ptr genPSTab; edm::Handle lheInfo; @@ -287,25 +282,16 @@ class GenWeightsTableProducer : public edm::global::EDProducer& outScale, - std::unique_ptr& outPdf, - std::unique_ptr& outRwgt, - std::unique_ptr& outNamed, std::unique_ptr& outPS) const { bool lheDebug = debug_.exchange( false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind) @@ -367,31 +349,6 @@ class GenWeightsTableProducer : public edm::global::EDProduceraddColumn( - "", wScale, weightChoice->scaleWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); - - outPdf.reset(new nanoaod::FlatTable(wPDF.size(), "LHEPdfWeight", false)); - outPdf->addColumn( - "", wPDF, weightChoice->pdfWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); - - outRwgt.reset(new nanoaod::FlatTable(wRwgt.size(), "LHEReweightingWeight", false)); - outRwgt->addColumn( - "", wRwgt, weightChoice->rwgtWeightDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); - - outNamed.reset(new nanoaod::FlatTable(1, "LHEWeight", true)); - outNamed->addColumnValue("originalXWGTUP", - lheProd.originalXWGTUP(), - "Nominal event weight in the LHE file", - nanoaod::FlatTable::FloatColumn); - for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) { - outNamed->addColumnValue(namedWeightLabels_[i], - wNamed[i], - "LHE weight for id " + namedWeightIDs_[i] + ", relative to nominal", - nanoaod::FlatTable::FloatColumn, - lheWeightPrecision_); - } - counter->incLHE(genWeight, wScale, wPDF, wRwgt, wNamed, wPS); } diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc new file mode 100644 index 0000000000000..f3584332186c9 --- /dev/null +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -0,0 +1,138 @@ +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/NanoAOD/interface/FlatTable.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include +#include + +namespace { + + // join vector of strings to one string + std::string join(const std::vector& vec, const char* delim) { + std::stringstream res; + std::copy(vec.begin(), vec.end(), std::ostream_iterator(res, delim)); + return res.str(); + } + + struct LHEWeightInfo { + std::string id; + std::string text; + std::optional group = std::nullopt; + }; + + + std::vector getLHEWeightInfos(LHERunInfoProduct const& lheInfo) { + std::vector out; + + for (auto iter = lheInfo.headers_begin(), end = lheInfo.headers_end(); iter != end; ++iter) { + if (iter->tag() != "initrwgt") { + continue; + } + + tinyxml2::XMLDocument xmlDoc; + xmlDoc.Parse(("" + join(iter->lines(), "") + "").c_str()); + tinyxml2::XMLElement* root = xmlDoc.FirstChildElement("root"); + + for (auto* e = root->FirstChildElement(); e != nullptr; e = e->NextSiblingElement()) { + if (strcmp(e->Name(), "weight") == 0) { + // we are here if there is a weight that does not belong to any group + std::string text = ""; + if(e->GetText()) text = e->GetText(); + out.push_back({e->Attribute("id"), text}); + } + if (strcmp(e->Name(), "weightgroup") == 0) { + std::string groupName = e->Attribute("name"); + for (auto* inner = e->FirstChildElement("weight"); inner != nullptr; + inner = inner->NextSiblingElement("weight")) { + // we are here if there is a weight in a weightgroup + std::string text = ""; + if(inner->GetText()) text = inner->GetText(); + out.push_back({inner->Attribute("id"), text, groupName}); + } + } + } + } + + return out; + } + +} + +class LHEWeightsTableProducer : public edm::global::EDProducer>> { + public: + LHEWeightsTableProducer( edm::ParameterSet const & params ) : + lheInputTag_(params.getParameter("lheInfo")), + lheToken_(consumes(params.getParameter("lheInfo"))), + lheWeightPrecision_(params.getParameter("lheWeightPrecision")) + { + consumes(lheInputTag_); + produces(); + } + + void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { + // tables for LHE weights, may not be filled + auto const& lheInfo = iEvent.get(lheToken_); + + auto lheWeightsTab = std::make_unique(1, "LHEWeight", true); + + auto const& weightInfos = *runCache(iEvent.getRun().index()); + + double w0 = lheInfo.originalXWGTUP(); + + int i = 0; + if(lheInfo.weights().size() != weightInfos.size()) { + throw cms::Exception("LogicError", "Weight labels don't have the same size as weights!\n"); + } + for(auto const& weight : lheInfo.weights()) { + if(!weightInfos[i].group) { + // for now we ignore the ungrouped weights + continue; + } + auto const& label = (*weightInfos[i].group) + "__" + weightInfos[i].id; + lheWeightsTab->addColumnValue(label, weight.wgt / w0, weightInfos[i].text + " (w_var / w_nominal)", nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + ++i; + } + + iEvent.put(std::move(lheWeightsTab)); + } + + std::shared_ptr> globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const override { + edm::Handle lheInfo; + + auto weightChoice = std::make_shared>(); + + // getByToken throws since we're not in the endRun (see https://github.com/cms-sw/cmssw/pull/18499) + iRun.getByLabel(lheInputTag_, lheInfo); + if (lheInfo.isValid()) { + getLHEWeightInfos(*lheInfo).swap(*weightChoice); + } + + return weightChoice; + } + + // nothing to do here + void globalEndRun(edm::Run const&, edm::EventSetup const&) const override {} + + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { + edm::ParameterSetDescription desc; + desc.add("lheInfo", {"externalLHEProducer"})->setComment("tag(s) for the LHE information (LHEEventProduct and LHERunInfoProduct)"); + desc.add("lheWeightPrecision", -1)->setComment("Number of bits in the mantissa for LHE weights"); + descriptions.addDefault(desc); + } + + + protected: + const edm::InputTag lheInputTag_; + const edm::EDGetTokenT lheToken_; + int lheWeightPrecision_; +}; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(LHEWeightsTableProducer); diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py new file mode 100644 index 0000000000000..d5efb1ced3282 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -0,0 +1,114 @@ +from PhysicsTools.NanoAOD.common_cff import * +from PhysicsTools.NanoAOD.taus_cff import * +from PhysicsTools.NanoAOD.jets_cff import * +from PhysicsTools.NanoAOD.globals_cff import * +from PhysicsTools.NanoAOD.genparticles_cff import * +from PhysicsTools.NanoAOD.particlelevel_cff import * +from PhysicsTools.NanoAOD.lheInfoTable_cfi import * + +# duplicate definition with nano_cff right now +genWeightsTable = cms.EDProducer( + "GenWeightsTableProducer", + genEvent = cms.InputTag("generator"), + genLumiInfoHeader = cms.InputTag("generator"), + lheInfo = cms.VInputTag(cms.InputTag("externalLHEProducer"), cms.InputTag("source")), + preferredPDFs = cms.VPSet( # see https://lhapdf.hepforge.org/pdfsets.html + cms.PSet(name = cms.string("PDF4LHC15_nnlo_30_pdfas"), lhaid = cms.uint32(91400)), + cms.PSet(name = cms.string("NNPDF31_nnlo_hessian_pdfas"), lhaid = cms.uint32(306000)), + # for some 92X samples. Note that the nominal weight, 260000, is not included in the LHE ... + cms.PSet(name = cms.string("NNPDF30_nlo_as_0118"), lhaid = cms.uint32(260000)), + # some MLM 80X samples have only this (e.g. /store/mc/RunIISummer16MiniAODv2/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6_ext1-v2/120000/02A210D6-F5C3-E611-B570-008CFA197BD4.root ) + cms.PSet(name = cms.string("NNPDF30_lo_as_0130"), lhaid = cms.uint32(262000)), + # some FXFX 80X samples have only this (e.g. WWTo1L1Nu2Q, WWTo4Q) + cms.PSet(name = cms.string("NNPDF30_nlo_nf_4_pdfas"), lhaid = cms.uint32(292000)), + # some FXFX 80X samples have only this (e.g. DYJetsToLL_Pt, WJetsToLNu_Pt, DYJetsToNuNu_Pt) + cms.PSet(name = cms.string("NNPDF30_nlo_nf_5_pdfas"), lhaid = cms.uint32(292200)), + ), + namedWeightIDs = cms.vstring(), + namedWeightLabels = cms.vstring(), + lheWeightPrecision = cms.int32(14), + maxPdfWeights = cms.uint32(150), + debug = cms.untracked.bool(False), +) + +lheWeightsTable = cms.EDProducer( + "LHEWeightsTableProducer", + lheInfo = cms.InputTag("externalLHEProducer"), + lheWeightPrecision = cms.int32(14), +) + +nanoMetadata = cms.EDProducer("UniqueStringProducer", + strings = cms.PSet( + tag = cms.string("untagged"), + ) +) + +metGenTable = cms.EDProducer("SimpleCandidateFlatTableProducer", + src = cms.InputTag("genMetTrue"), + name = cms.string("GenMET"), + doc = cms.string("Gen MET"), + singleton = cms.bool(True), + extension = cms.bool(False), + variables = cms.PSet( + pt = Var("pt", float, doc="pt", precision=10), + phi = Var("phi", float, doc="phi", precision=10), + ), +) + +nanogenSequence = cms.Sequence( + nanoMetadata+ + particleLevel+ + genJetTable+ + patJetPartons+ + genJetFlavourAssociation+ + genJetFlavourTable+ + genJetAK8Table+ + genJetAK8FlavourAssociation+ + genJetAK8FlavourTable+ + tauGenJets+ + tauGenJetsSelectorAllHadrons+ + genVisTaus+ + genVisTauTable+ + genTable+ + genWeightsTable+ + lheWeightsTable+ + genParticleTables+ + tautagger+ + rivetProducerHTXS+ + particleLevelTables+ + metGenTable+ + lheInfoTable +) + +NANOAODGENoutput = cms.OutputModule("NanoAODOutputModule", + compressionAlgorithm = cms.untracked.string('LZMA'), + compressionLevel = cms.untracked.int32(9), + dataset = cms.untracked.PSet( + dataTier = cms.untracked.string('NANOAODSIM'), + filterName = cms.untracked.string('') + ), + fileName = cms.untracked.string('nanogen.root'), + outputCommands = cms.untracked.vstring( + 'drop *', + "keep nanoaodFlatTable_*Table_*_*", # event data + "keep String_*_genModel_*", # generator model data + "keep nanoaodMergeableCounterTable_*Table_*_*", # accumulated per/run or per/lumi data + "keep nanoaodUniqueString_nanoMetadata_*_*", # basic metadata + ) +) + +def customizeNanoGEN(process): + process.genParticleTable.src = "genParticles" + process.patJetPartons.particles = "genParticles" + process.particleLevel.src = "generatorSmeared" + process.rivetProducerHTXS.HepMCCollection = "generatorSmeared" + + process.genJetTable.src = "ak4GenJetsNoNu" + process.genJetFlavourAssociation.jets = process.genJetTable.src + process.genJetFlavourTable.src = process.genJetTable.src + process.genJetFlavourTable.jetFlavourInfos = "genJetFlavourAssociation" + process.genJetAK8Table.src = "ak8GenJetsNoNu" + process.genJetAK8FlavourAssociation.jets = process.genJetAK8Table.src + process.genJetAK8FlavourTable.src = process.genJetAK8Table.src + process.tauGenJets.GenParticles = "genParticles" + process.genVisTaus.srcGenParticles = "genParticles" From 205de35015c23df0523b8c1b52c7c857754b3c31 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 19 Dec 2019 18:59:47 +0100 Subject: [PATCH 53/75] Variable number of produced flat tables --- DataFormats/NanoAOD/src/classes_def.xml | 3 + .../plugins/LHEWeightsTableProducer.cc | 131 +++++++++--------- .../NanoAOD/plugins/NanoAODOutputModule.cc | 39 ++++-- .../NanoAOD/plugins/TableOutputBranches.cc | 5 +- .../NanoAOD/plugins/TableOutputBranches.h | 14 +- PhysicsTools/NanoAOD/python/nanogen_cff.py | 1 + 6 files changed, 108 insertions(+), 85 deletions(-) diff --git a/DataFormats/NanoAOD/src/classes_def.xml b/DataFormats/NanoAOD/src/classes_def.xml index 32c077349ff95..24d6da6064c73 100644 --- a/DataFormats/NanoAOD/src/classes_def.xml +++ b/DataFormats/NanoAOD/src/classes_def.xml @@ -9,6 +9,9 @@ + + + diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index f3584332186c9..66402e40bda4c 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -10,6 +10,7 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include +#include #include namespace { @@ -22,12 +23,11 @@ namespace { } struct LHEWeightInfo { - std::string id; - std::string text; - std::optional group = std::nullopt; + std::string id; + std::string text; + std::optional group = std::nullopt; }; - std::vector getLHEWeightInfos(LHERunInfoProduct const& lheInfo) { std::vector out; @@ -42,18 +42,20 @@ namespace { for (auto* e = root->FirstChildElement(); e != nullptr; e = e->NextSiblingElement()) { if (strcmp(e->Name(), "weight") == 0) { - // we are here if there is a weight that does not belong to any group - std::string text = ""; - if(e->GetText()) text = e->GetText(); + // we are here if there is a weight that does not belong to any group + std::string text = ""; + if (e->GetText()) + text = e->GetText(); out.push_back({e->Attribute("id"), text}); } if (strcmp(e->Name(), "weightgroup") == 0) { - std::string groupName = e->Attribute("name"); + std::string groupName = e->Attribute("name"); for (auto* inner = e->FirstChildElement("weight"); inner != nullptr; inner = inner->NextSiblingElement("weight")) { // we are here if there is a weight in a weightgroup std::string text = ""; - if(inner->GetText()) text = inner->GetText(); + if (inner->GetText()) + text = inner->GetText(); out.push_back({inner->Attribute("id"), text, groupName}); } } @@ -63,75 +65,80 @@ namespace { return out; } -} +} // namespace class LHEWeightsTableProducer : public edm::global::EDProducer>> { - public: - LHEWeightsTableProducer( edm::ParameterSet const & params ) : - lheInputTag_(params.getParameter("lheInfo")), - lheToken_(consumes(params.getParameter("lheInfo"))), - lheWeightPrecision_(params.getParameter("lheWeightPrecision")) - { - consumes(lheInputTag_); - produces(); - } - - void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { - // tables for LHE weights, may not be filled - auto const& lheInfo = iEvent.get(lheToken_); +public: + LHEWeightsTableProducer(edm::ParameterSet const& params) + : lheInputTag_(params.getParameter("lheInfo")), + lheToken_(consumes(params.getParameter("lheInfo"))), + lheWeightPrecision_(params.getParameter("lheWeightPrecision")) { + consumes(lheInputTag_); + produces>(); + } - auto lheWeightsTab = std::make_unique(1, "LHEWeight", true); + void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { + // tables for LHE weights, may not be filled + auto const& lheInfo = iEvent.get(lheToken_); - auto const& weightInfos = *runCache(iEvent.getRun().index()); + auto lheWeightTables = std::make_unique>(); + auto const& weightInfos = *runCache(iEvent.getRun().index()); - double w0 = lheInfo.originalXWGTUP(); + double w0 = lheInfo.originalXWGTUP(); - int i = 0; - if(lheInfo.weights().size() != weightInfos.size()) { - throw cms::Exception("LogicError", "Weight labels don't have the same size as weights!\n"); - } - for(auto const& weight : lheInfo.weights()) { - if(!weightInfos[i].group) { - // for now we ignore the ungrouped weights - continue; - } - auto const& label = (*weightInfos[i].group) + "__" + weightInfos[i].id; - lheWeightsTab->addColumnValue(label, weight.wgt / w0, weightInfos[i].text + " (w_var / w_nominal)", nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); - ++i; - } + int i = 0; + if (lheInfo.weights().size() != weightInfos.size()) { + throw cms::Exception("LogicError", "Weight labels don't have the same size as weights!\n"); + } + std::unordered_map> groupsWithWeights; + for (auto const& weight : lheInfo.weights()) { + if (!weightInfos[i].group) { + groupsWithWeights["ungrouped"].push_back(weight.wgt / w0); + } + groupsWithWeights[*weightInfos[i].group].push_back(weight.wgt / w0); + ++i; + } + for (auto const& group : groupsWithWeights) { + std::string name = std::string("LHEWeight_") + group.first; + std::transform(name.begin(), name.end(), name.begin(), [](char ch) { return ch == ' ' ? '_' : ch; }); + lheWeightTables->emplace_back(group.second.size(), name, false); + lheWeightTables->back().addColumn( + "", group.second, group.first + " (w_var / w_nominal)", nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + } - iEvent.put(std::move(lheWeightsTab)); - } + iEvent.put(std::move(lheWeightTables)); + } - std::shared_ptr> globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const override { - edm::Handle lheInfo; + std::shared_ptr> globalBeginRun(edm::Run const& iRun, + edm::EventSetup const&) const override { + edm::Handle lheInfo; - auto weightChoice = std::make_shared>(); + auto weightChoice = std::make_shared>(); - // getByToken throws since we're not in the endRun (see https://github.com/cms-sw/cmssw/pull/18499) - iRun.getByLabel(lheInputTag_, lheInfo); - if (lheInfo.isValid()) { - getLHEWeightInfos(*lheInfo).swap(*weightChoice); - } + // getByToken throws since we're not in the endRun (see https://github.com/cms-sw/cmssw/pull/18499) + iRun.getByLabel(lheInputTag_, lheInfo); + if (lheInfo.isValid()) { + getLHEWeightInfos(*lheInfo).swap(*weightChoice); + } - return weightChoice; - } + return weightChoice; + } // nothing to do here void globalEndRun(edm::Run const&, edm::EventSetup const&) const override {} - static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { - edm::ParameterSetDescription desc; - desc.add("lheInfo", {"externalLHEProducer"})->setComment("tag(s) for the LHE information (LHEEventProduct and LHERunInfoProduct)"); - desc.add("lheWeightPrecision", -1)->setComment("Number of bits in the mantissa for LHE weights"); - descriptions.addDefault(desc); - } - + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("lheInfo", {"externalLHEProducer"}) + ->setComment("tag(s) for the LHE information (LHEEventProduct and LHERunInfoProduct)"); + desc.add("lheWeightPrecision", -1)->setComment("Number of bits in the mantissa for LHE weights"); + descriptions.addDefault(desc); + } - protected: - const edm::InputTag lheInputTag_; - const edm::EDGetTokenT lheToken_; - int lheWeightPrecision_; +protected: + const edm::InputTag lheInputTag_; + const edm::EDGetTokenT lheToken_; + int lheWeightPrecision_; }; #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index 4499a23ef8cfb..f2a136a17f788 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -46,7 +46,6 @@ class NanoAODOutputModule : public edm::one::OutputModule<> { public: NanoAODOutputModule(edm::ParameterSet const& pset); - ~NanoAODOutputModule() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); @@ -118,6 +117,8 @@ class NanoAODOutputModule : public edm::one::OutputModule<> { } m_commonRunBranches; std::vector m_tables; + std::vector m_tableTokens; + std::vector m_tableVectorTokens; std::vector m_triggers; std::vector m_evstrings; @@ -149,8 +150,6 @@ NanoAODOutputModule::NanoAODOutputModule(edm::ParameterSet const& pset) m_autoFlush(pset.getUntrackedParameter("autoFlush", -10000000)), m_processHistoryRegistry() {} -NanoAODOutputModule::~NanoAODOutputModule() {} - void NanoAODOutputModule::write(edm::EventForOutput const& iEvent) { //Get data from 'e' and write it to the file edm::Service jr; @@ -191,9 +190,29 @@ void NanoAODOutputModule::write(edm::EventForOutput const& iEvent) { m_commonBranches.fill(iEvent.id()); // fill all tables, starting from main tables and then doing extension tables + std::vector tables; + for (auto& tableToken : m_tableTokens) { + edm::Handle handle; + iEvent.getByToken(tableToken, handle); + tables.push_back(&(*handle)); + } + for (auto& tableToken : m_tableVectorTokens) { + edm::Handle> handle; + iEvent.getByToken(tableToken, handle); + for (auto const& table : *handle) { + tables.push_back(&table); + } + } + + if (m_tables.empty()) { + m_tables.resize(tables.size()); + } for (unsigned int extensions = 0; extensions <= 1; ++extensions) { - for (auto& t : m_tables) - t.fill(iEvent, *m_tree, extensions); + size_t iTable = 0; + for (auto& table : tables) { + m_tables[iTable].fill(*table, *m_tree, extensions); + ++iTable; + } } // fill triggers for (auto& t : m_triggers) @@ -270,14 +289,18 @@ void NanoAODOutputModule::openFile(edm::FileBlock const&) { } /* Setup file structure here */ m_tables.clear(); + m_tableTokens.clear(); m_triggers.clear(); m_evstrings.clear(); m_runTables.clear(); const auto& keeps = keptProducts(); for (const auto& keep : keeps[edm::InEvent]) { - if (keep.first->className() == "nanoaod::FlatTable") - m_tables.emplace_back(keep.first, keep.second); - else if (keep.first->className() == "edm::TriggerResults") { + std::cout << keep.first->className() << std::endl; + if (keep.first->className() == "nanoaod::FlatTable") { + m_tableTokens.emplace_back(keep.second); + } else if (keep.first->className() == "std::vector") { + m_tableVectorTokens.emplace_back(keep.second); + } else if (keep.first->className() == "edm::TriggerResults") { m_triggers.emplace_back(keep.first, keep.second); } else if (keep.first->className() == "std::basic_string >" && keep.first->productInstanceName() == "genModel") { // friendlyClassName == "String" diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc index 1c72a63cb4fdb..4f411b12dfe55 100644 --- a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.cc @@ -57,15 +57,12 @@ void TableOutputBranches::branch(TTree &tree) { } } -void TableOutputBranches::fill(const edm::EventForOutput &iEvent, TTree &tree, bool extensions) { +void TableOutputBranches::fill(const nanoaod::FlatTable &tab, TTree &tree, bool extensions) { if (m_extension != DontKnowYetIfMainOrExtension) { if (extensions != m_extension) return; // do nothing, wait to be called with the proper flag } - edm::Handle handle; - iEvent.getByToken(m_token, handle); - const nanoaod::FlatTable &tab = *handle; m_counter = tab.size(); m_singleton = tab.singleton(); if (!m_branchesBooked) { diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h index df843bb6f4216..c8e4366e48539 100644 --- a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h @@ -4,31 +4,23 @@ #include #include #include -#include "FWCore/Framework/interface/EventForOutput.h" #include "DataFormats/NanoAOD/interface/FlatTable.h" #include "DataFormats/Provenance/interface/BranchDescription.h" #include "FWCore/Utilities/interface/EDGetToken.h" class TableOutputBranches { public: - TableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token) - : m_token(token), m_extension(DontKnowYetIfMainOrExtension), m_branchesBooked(false) { - if (desc->className() != "nanoaod::FlatTable") - throw cms::Exception("Configuration", "NanoAODOutputModule can only write out nanoaod::FlatTable objects"); - } - void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab); void branch(TTree &tree); /// Fill the current table, if extensions == table.extension(). /// This parameter is used so that the fill is called first for non-extensions and then for extensions - void fill(const edm::EventForOutput &iEvent, TTree &tree, bool extensions); + void fill(const nanoaod::FlatTable &tab, TTree &tree, bool extensions); private: - edm::EDGetToken m_token; std::string m_baseName; bool m_singleton; - enum { IsMain = 0, IsExtension = 1, DontKnowYetIfMainOrExtension = 2 } m_extension; + enum { IsMain = 0, IsExtension = 1, DontKnowYetIfMainOrExtension = 2 } m_extension = DontKnowYetIfMainOrExtension; std::string m_doc; UInt_t m_counter; struct NamedBranchPtr { @@ -44,7 +36,7 @@ class TableOutputBranches { std::vector m_floatBranches; std::vector m_intBranches; std::vector m_uint8Branches; - bool m_branchesBooked; + bool m_branchesBooked = false; template void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab) { diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index d5efb1ced3282..00deb5a6613ec 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -90,6 +90,7 @@ fileName = cms.untracked.string('nanogen.root'), outputCommands = cms.untracked.vstring( 'drop *', + "keep *_lheWeightsTable_*_*", # event data "keep nanoaodFlatTable_*Table_*_*", # event data "keep String_*_genModel_*", # generator model data "keep nanoaodMergeableCounterTable_*Table_*_*", # accumulated per/run or per/lumi data From d663d2f5cb2d2b9bf1dbcbe66845b4844a7c34de Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 19 Dec 2019 20:10:58 +0100 Subject: [PATCH 54/75] select specific weight groups --- .../plugins/LHEWeightsTableProducer.cc | 21 +++++++++++++------ .../NanoAOD/plugins/NanoAODOutputModule.cc | 1 - PhysicsTools/NanoAOD/python/nanogen_cff.py | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index 66402e40bda4c..b8f00280ac436 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -72,6 +72,7 @@ class LHEWeightsTableProducer : public edm::global::EDProducer("lheInfo")), lheToken_(consumes(params.getParameter("lheInfo"))), + weightgroups_(params.getParameter>("weightgroups")), lheWeightPrecision_(params.getParameter("lheWeightPrecision")) { consumes(lheInputTag_); produces>(); @@ -90,20 +91,26 @@ class LHEWeightsTableProducer : public edm::global::EDProducer> groupsWithWeights; + std::unordered_map>> groupsWithWeights; for (auto const& weight : lheInfo.weights()) { - if (!weightInfos[i].group) { - groupsWithWeights["ungrouped"].push_back(weight.wgt / w0); + auto& val = weightInfos[i].group ? groupsWithWeights[*weightInfos[i].group] : groupsWithWeights["ungrouped"]; + if(val.first.empty()) { + val.first += ";id,text"; } - groupsWithWeights[*weightInfos[i].group].push_back(weight.wgt / w0); + val.first += ";" + weightInfos[i].id + "," + weightInfos[i].text; + val.second.push_back(weight.wgt / w0); ++i; } for (auto const& group : groupsWithWeights) { + if(std::find(weightgroups_.begin(), weightgroups_.end(), group.first) == weightgroups_.end()) { + continue; + } std::string name = std::string("LHEWeight_") + group.first; std::transform(name.begin(), name.end(), name.begin(), [](char ch) { return ch == ' ' ? '_' : ch; }); - lheWeightTables->emplace_back(group.second.size(), name, false); + std::string doc = group.first + " (w_var / w_nominal)" + group.second.first; + lheWeightTables->emplace_back(group.second.second.size(), name, false); lheWeightTables->back().addColumn( - "", group.second, group.first + " (w_var / w_nominal)", nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + "", group.second.second, doc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); } iEvent.put(std::move(lheWeightTables)); @@ -131,6 +138,7 @@ class LHEWeightsTableProducer : public edm::global::EDProducer("lheInfo", {"externalLHEProducer"}) ->setComment("tag(s) for the LHE information (LHEEventProduct and LHERunInfoProduct)"); + desc.add>("weightgroups"); desc.add("lheWeightPrecision", -1)->setComment("Number of bits in the mantissa for LHE weights"); descriptions.addDefault(desc); } @@ -138,6 +146,7 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheToken_; + const std::vector weightgroups_; int lheWeightPrecision_; }; diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index f2a136a17f788..8f6464c095d6b 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -295,7 +295,6 @@ void NanoAODOutputModule::openFile(edm::FileBlock const&) { m_runTables.clear(); const auto& keeps = keptProducts(); for (const auto& keep : keeps[edm::InEvent]) { - std::cout << keep.first->className() << std::endl; if (keep.first->className() == "nanoaod::FlatTable") { m_tableTokens.emplace_back(keep.second); } else if (keep.first->className() == "std::vector") { diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index 00deb5a6613ec..a02d32c3ee76d 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -34,6 +34,7 @@ lheWeightsTable = cms.EDProducer( "LHEWeightsTableProducer", lheInfo = cms.InputTag("externalLHEProducer"), + weightgroups = cms.vstring(["mg_reweighting"]), lheWeightPrecision = cms.int32(14), ) From 45be54a91e93c7aefdfdda3c49dc4135b40e34b2 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Fri, 20 Dec 2019 16:25:33 +0100 Subject: [PATCH 55/75] give a bit more structure to weight counter class --- .../plugins/GenWeightsTableProducer.cc | 191 +++++++++--------- .../plugins/LHEWeightsTableProducer.cc | 8 +- .../NanoAOD/python/genWeightsTable_cfi.py | 20 ++ PhysicsTools/NanoAOD/python/nano_cff.py | 1 + PhysicsTools/NanoAOD/python/nanogen_cff.py | 26 +-- 5 files changed, 120 insertions(+), 126 deletions(-) create mode 100644 PhysicsTools/NanoAOD/python/genWeightsTable_cfi.py diff --git a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc index 9a86e108bc1b8..6b678099e98b8 100644 --- a/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc @@ -20,39 +20,42 @@ #include namespace { - /// ---- Cache object for running sums of weights ---- - struct Counter { - Counter() : num(0), sumw(0), sumw2(0), sumPDF(), sumScale(), sumRwgt(), sumNamed(), sumPS() {} - // the counters - long long num; - long double sumw; - long double sumw2; - std::vector sumPDF, sumScale, sumRwgt, sumNamed, sumPS; + void mergeSumVectors(std::vector& v1, std::vector const& v2) { + if (v1.empty() && !v2.empty()) + v1.resize(v2.size(), 0); + if (!v2.empty()) + for (unsigned int i = 0, n = v1.size(); i < n; ++i) + v1[i] += v2[i]; + } + /// ---- Cache object for running sums of weights ---- + class Counter { + public: void clear() { - num = 0; - sumw = 0; - sumw2 = 0; - sumPDF.clear(); - sumScale.clear(); - sumRwgt.clear(); - sumNamed.clear(), sumPS.clear(); + num_ = 0; + sumw_ = 0; + sumw2_ = 0; + sumPDF_.clear(); + sumScale_.clear(); + sumRwgt_.clear(); + sumNamed_.clear(); + sumPS_.clear(); } // inc the counters void incGenOnly(double w) { - num++; - sumw += w; - sumw2 += (w * w); + num_++; + sumw_ += w; + sumw2_ += (w * w); } void incPSOnly(double w0, const std::vector& wPS) { if (!wPS.empty()) { - if (sumPS.empty()) - sumPS.resize(wPS.size(), 0); + if (sumPS_.empty()) + sumPS_.resize(wPS.size(), 0); for (unsigned int i = 0, n = wPS.size(); i < n; ++i) - sumPS[i] += (w0 * wPS[i]); + sumPS_[i] += (w0 * wPS[i]); } } @@ -66,62 +69,55 @@ namespace { incGenOnly(w0); // then add up variations if (!wScale.empty()) { - if (sumScale.empty()) - sumScale.resize(wScale.size(), 0); + if (sumScale_.empty()) + sumScale_.resize(wScale.size(), 0); for (unsigned int i = 0, n = wScale.size(); i < n; ++i) - sumScale[i] += (w0 * wScale[i]); + sumScale_[i] += (w0 * wScale[i]); } if (!wPDF.empty()) { - if (sumPDF.empty()) - sumPDF.resize(wPDF.size(), 0); + if (sumPDF_.empty()) + sumPDF_.resize(wPDF.size(), 0); for (unsigned int i = 0, n = wPDF.size(); i < n; ++i) - sumPDF[i] += (w0 * wPDF[i]); + sumPDF_[i] += (w0 * wPDF[i]); } if (!wRwgt.empty()) { - if (sumRwgt.empty()) - sumRwgt.resize(wRwgt.size(), 0); + if (sumRwgt_.empty()) + sumRwgt_.resize(wRwgt.size(), 0); for (unsigned int i = 0, n = wRwgt.size(); i < n; ++i) - sumRwgt[i] += (w0 * wRwgt[i]); + sumRwgt_[i] += (w0 * wRwgt[i]); } if (!wNamed.empty()) { - if (sumNamed.empty()) - sumNamed.resize(wNamed.size(), 0); + if (sumNamed_.empty()) + sumNamed_.resize(wNamed.size(), 0); for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) - sumNamed[i] += (w0 * wNamed[i]); + sumNamed_[i] += (w0 * wNamed[i]); } incPSOnly(w0, wPS); } void merge(const Counter& other) { - num += other.num; - sumw += other.sumw; - sumw2 += other.sumw2; - if (sumScale.empty() && !other.sumScale.empty()) - sumScale.resize(other.sumScale.size(), 0); - if (sumPDF.empty() && !other.sumPDF.empty()) - sumPDF.resize(other.sumPDF.size(), 0); - if (sumRwgt.empty() && !other.sumRwgt.empty()) - sumRwgt.resize(other.sumRwgt.size(), 0); - if (sumNamed.empty() && !other.sumNamed.empty()) - sumNamed.resize(other.sumNamed.size(), 0); - if (sumPS.empty() && !other.sumPS.empty()) - sumPS.resize(other.sumPS.size(), 0); - if (!other.sumScale.empty()) - for (unsigned int i = 0, n = sumScale.size(); i < n; ++i) - sumScale[i] += other.sumScale[i]; - if (!other.sumPDF.empty()) - for (unsigned int i = 0, n = sumPDF.size(); i < n; ++i) - sumPDF[i] += other.sumPDF[i]; - if (!other.sumRwgt.empty()) - for (unsigned int i = 0, n = sumRwgt.size(); i < n; ++i) - sumRwgt[i] += other.sumRwgt[i]; - if (!other.sumNamed.empty()) - for (unsigned int i = 0, n = sumNamed.size(); i < n; ++i) - sumNamed[i] += other.sumNamed[i]; - if (!other.sumPS.empty()) - for (unsigned int i = 0, n = sumPS.size(); i < n; ++i) - sumPS[i] += other.sumPS[i]; + num_ += other.num_; + sumw_ += other.sumw_; + sumw2_ += other.sumw2_; + + mergeSumVectors(sumScale_, other.sumScale_); + mergeSumVectors(sumPDF_, other.sumPDF_); + mergeSumVectors(sumRwgt_, other.sumRwgt_); + mergeSumVectors(sumNamed_, other.sumNamed_); + mergeSumVectors(sumPS_, other.sumPS_); } + + //private: + // the counters + long long num_ = 0; + long double sumw_ = 0; + long double sumw2_ = 0; + + std::vector sumPDF_; + std::vector sumScale_; + std::vector sumRwgt_; + std::vector sumNamed_; + std::vector sumPS_; }; struct CounterMap { @@ -251,17 +247,15 @@ class GenWeightsTableProducer : public edm::global::EDProducerget(); + Counter& counter = *streamCache(id)->get(); // generator information (always available) - edm::Handle genInfo; - iEvent.getByToken(genTag_, genInfo); - double weight = genInfo->weight(); + auto const& genInfo = iEvent.get(genTag_); // table for gen info, always available auto out = std::make_unique(1, "genWeight", true); out->setDoc("generator weight"); - out->addColumnValue("", weight, "generator weight", nanoaod::FlatTable::FloatColumn); + out->addColumnValue("", genInfo.weight(), "generator weight", nanoaod::FlatTable::FloatColumn); iEvent.put(std::move(out)); std::string model_label = streamCache(id)->getLabel(); @@ -280,12 +274,12 @@ class GenWeightsTableProducer : public edm::global::EDProducer& outPS) const { - bool lheDebug = debug_.exchange( - false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind) + // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind) + bool lheDebug = debug_.exchange(false); - const std::vector& scaleWeightIDs = weightChoice->scaleWeightIDs; - const std::vector& pdfWeightIDs = weightChoice->pdfWeightIDs; - const std::vector& rwgtWeightIDs = weightChoice->rwgtIDs; + const std::vector& scaleWeightIDs = weightChoice.scaleWeightIDs; + const std::vector& pdfWeightIDs = weightChoice.pdfWeightIDs; + const std::vector& rwgtWeightIDs = weightChoice.rwgtIDs; double w0 = lheProd.originalXWGTUP(); - std::vector wScale(scaleWeightIDs.size(), 1), wPDF(pdfWeightIDs.size(), 1), wRwgt(rwgtWeightIDs.size(), 1), - wNamed(namedWeightIDs_.size(), 1); + std::vector wScale(scaleWeightIDs.size(), 1); + std::vector wPDF(pdfWeightIDs.size(), 1); + std::vector wRwgt(rwgtWeightIDs.size(), 1); + std::vector wNamed(namedWeightIDs_.size(), 1); + for (auto& weight : lheProd.weights()) { if (lheDebug) printf("Weight %+9.5f rel %+9.5f for id %s\n", weight.wgt, weight.wgt / w0, weight.id.c_str()); @@ -340,7 +337,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer(wPS.size(), "PSWeight", false); outPS->addColumn("", wPS, vectorSize > 1 ? "PS weights (w_var / w_nominal); [0] is ISR=0.5 FSR=1; [1] is ISR=1 " @@ -349,10 +346,10 @@ class GenWeightsTableProducer : public edm::global::EDProducerincLHE(genWeight, wScale, wPDF, wRwgt, wNamed, wPS); + counter.incLHE(genWeight, wScale, wPDF, wRwgt, wNamed, wPS); } - void fillOnlyPSWeightTable(Counter* counter, + void fillOnlyPSWeightTable(Counter& counter, double genWeight, const GenEventInfoProduct& genProd, std::unique_ptr& outPS) const { @@ -365,7 +362,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer(wPS.size(), "PSWeight", false); outPS->addColumn("", wPS, vectorSize > 1 ? "PS weights (w_var / w_nominal); [0] is ISR=0.5 FSR=1; [1] is ISR=1 " @@ -374,16 +371,16 @@ class GenWeightsTableProducer : public edm::global::EDProducerincGenOnly(genWeight); - counter->incPSOnly(genWeight, wPS); + counter.incGenOnly(genWeight); + counter.incPSOnly(genWeight, wPS); } // create an empty counter std::shared_ptr globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const override { edm::Handle lheInfo; - bool lheDebug = debugRun_.exchange( - false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind) + // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind) + bool lheDebug = debugRun_.exchange(false); auto weightChoice = std::make_shared(); // getByToken throws since we're not in the endRun (see https://github.com/cms-sw/cmssw/pull/18499) @@ -754,40 +751,40 @@ class GenWeightsTableProducer : public edm::global::EDProducer(); for (auto x : runCounterMap->countermap) { - auto runCounter = &(x.second); + auto& runCounter = x.second; std::string label = std::string("_") + x.first; std::string doclabel = (!x.first.empty()) ? (std::string(", for model label ") + x.first) : ""; - out->addInt("genEventCount" + label, "event count" + doclabel, runCounter->num); - out->addFloat("genEventSumw" + label, "sum of gen weights" + doclabel, runCounter->sumw); - out->addFloat("genEventSumw2" + label, "sum of gen (weight^2)" + doclabel, runCounter->sumw2); + out->addInt("genEventCount" + label, "event count" + doclabel, runCounter.num_); + out->addFloat("genEventSumw" + label, "sum of gen weights" + doclabel, runCounter.sumw_); + out->addFloat("genEventSumw2" + label, "sum of gen (weight^2)" + doclabel, runCounter.sumw2_); - double norm = runCounter->sumw ? 1.0 / runCounter->sumw : 1; - auto sumScales = runCounter->sumScale; + double norm = runCounter.sumw_ ? 1.0 / runCounter.sumw_ : 1; + auto sumScales = runCounter.sumScale_; for (auto& val : sumScales) val *= norm; out->addVFloat("LHEScaleSumw" + label, "Sum of genEventWeight * LHEScaleWeight[i], divided by genEventSumw" + doclabel, sumScales); - auto sumPDFs = runCounter->sumPDF; + auto sumPDFs = runCounter.sumPDF_; for (auto& val : sumPDFs) val *= norm; out->addVFloat( "LHEPdfSumw" + label, "Sum of genEventWeight * LHEPdfWeight[i], divided by genEventSumw" + doclabel, sumPDFs); - if (!runCounter->sumRwgt.empty()) { - auto sumRwgts = runCounter->sumRwgt; + if (!runCounter.sumRwgt_.empty()) { + auto sumRwgts = runCounter.sumRwgt_; for (auto& val : sumRwgts) val *= norm; out->addVFloat("LHEReweightingSumw" + label, "Sum of genEventWeight * LHEReweightingWeight[i], divided by genEventSumw" + doclabel, sumRwgts); } - if (!runCounter->sumNamed.empty()) { // it could be empty if there's no LHE info in the sample + if (!runCounter.sumNamed_.empty()) { // it could be empty if there's no LHE info in the sample for (unsigned int i = 0, n = namedWeightLabels_.size(); i < n; ++i) { out->addFloat( "LHESumw_" + namedWeightLabels_[i] + label, "Sum of genEventWeight * LHEWeight_" + namedWeightLabels_[i] + ", divided by genEventSumw" + doclabel, - runCounter->sumNamed[i] * norm); + runCounter.sumNamed_[i] * norm); } } } diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index b8f00280ac436..5a49f8f47290c 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -94,16 +94,16 @@ class LHEWeightsTableProducer : public edm::global::EDProducer>> groupsWithWeights; for (auto const& weight : lheInfo.weights()) { auto& val = weightInfos[i].group ? groupsWithWeights[*weightInfos[i].group] : groupsWithWeights["ungrouped"]; - if(val.first.empty()) { - val.first += ";id,text"; + if (val.first.empty()) { + val.first += ";id,text"; } val.first += ";" + weightInfos[i].id + "," + weightInfos[i].text; val.second.push_back(weight.wgt / w0); ++i; } for (auto const& group : groupsWithWeights) { - if(std::find(weightgroups_.begin(), weightgroups_.end(), group.first) == weightgroups_.end()) { - continue; + if (std::find(weightgroups_.begin(), weightgroups_.end(), group.first) == weightgroups_.end()) { + continue; } std::string name = std::string("LHEWeight_") + group.first; std::transform(name.begin(), name.end(), name.begin(), [](char ch) { return ch == ' ' ? '_' : ch; }); diff --git a/PhysicsTools/NanoAOD/python/genWeightsTable_cfi.py b/PhysicsTools/NanoAOD/python/genWeightsTable_cfi.py new file mode 100644 index 0000000000000..15c2ea05d814b --- /dev/null +++ b/PhysicsTools/NanoAOD/python/genWeightsTable_cfi.py @@ -0,0 +1,20 @@ +import FWCore.ParameterSet.Config as cms + +genWeightsTable = cms.EDProducer("GenWeightsTableProducer", + genEvent = cms.InputTag("generator"), + genLumiInfoHeader = cms.InputTag("generator"), + lheInfo = cms.VInputTag(cms.InputTag("externalLHEProducer"), cms.InputTag("source")), + preferredPDFs = cms.VPSet( # see https://lhapdf.hepforge.org/pdfsets.html + cms.PSet( name = cms.string("PDF4LHC15_nnlo_30_pdfas"), lhaid = cms.uint32(91400) ), + cms.PSet( name = cms.string("NNPDF31_nnlo_hessian_pdfas"), lhaid = cms.uint32(306000) ), + cms.PSet( name = cms.string("NNPDF30_nlo_as_0118"), lhaid = cms.uint32(260000) ), # for some 92X samples. Note that the nominal weight, 260000, is not included in the LHE ... + cms.PSet( name = cms.string("NNPDF30_lo_as_0130"), lhaid = cms.uint32(262000) ), # some MLM 80X samples have only this (e.g. /store/mc/RunIISummer16MiniAODv2/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6_ext1-v2/120000/02A210D6-F5C3-E611-B570-008CFA197BD4.root ) + cms.PSet( name = cms.string("NNPDF30_nlo_nf_4_pdfas"), lhaid = cms.uint32(292000) ), # some FXFX 80X samples have only this (e.g. WWTo1L1Nu2Q, WWTo4Q) + cms.PSet( name = cms.string("NNPDF30_nlo_nf_5_pdfas"), lhaid = cms.uint32(292200) ), # some FXFX 80X samples have only this (e.g. DYJetsToLL_Pt, WJetsToLNu_Pt, DYJetsToNuNu_Pt) + ), + namedWeightIDs = cms.vstring(), + namedWeightLabels = cms.vstring(), + lheWeightPrecision = cms.int32(14), + maxPdfWeights = cms.uint32(150), + debug = cms.untracked.bool(False), +) diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 466b4c4554040..bfc9951ebb39e 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -16,6 +16,7 @@ from PhysicsTools.NanoAOD.triggerObjects_cff import * from PhysicsTools.NanoAOD.isotracks_cff import * from PhysicsTools.NanoAOD.NanoAODEDMEventContent_cff import * +from PhysicsTools.NanoAOD.genWeightsTable_cfi import * from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff import run2_nanoAOD_94X2016 diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index a02d32c3ee76d..496a525837f00 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -5,31 +5,7 @@ from PhysicsTools.NanoAOD.genparticles_cff import * from PhysicsTools.NanoAOD.particlelevel_cff import * from PhysicsTools.NanoAOD.lheInfoTable_cfi import * - -# duplicate definition with nano_cff right now -genWeightsTable = cms.EDProducer( - "GenWeightsTableProducer", - genEvent = cms.InputTag("generator"), - genLumiInfoHeader = cms.InputTag("generator"), - lheInfo = cms.VInputTag(cms.InputTag("externalLHEProducer"), cms.InputTag("source")), - preferredPDFs = cms.VPSet( # see https://lhapdf.hepforge.org/pdfsets.html - cms.PSet(name = cms.string("PDF4LHC15_nnlo_30_pdfas"), lhaid = cms.uint32(91400)), - cms.PSet(name = cms.string("NNPDF31_nnlo_hessian_pdfas"), lhaid = cms.uint32(306000)), - # for some 92X samples. Note that the nominal weight, 260000, is not included in the LHE ... - cms.PSet(name = cms.string("NNPDF30_nlo_as_0118"), lhaid = cms.uint32(260000)), - # some MLM 80X samples have only this (e.g. /store/mc/RunIISummer16MiniAODv2/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6_ext1-v2/120000/02A210D6-F5C3-E611-B570-008CFA197BD4.root ) - cms.PSet(name = cms.string("NNPDF30_lo_as_0130"), lhaid = cms.uint32(262000)), - # some FXFX 80X samples have only this (e.g. WWTo1L1Nu2Q, WWTo4Q) - cms.PSet(name = cms.string("NNPDF30_nlo_nf_4_pdfas"), lhaid = cms.uint32(292000)), - # some FXFX 80X samples have only this (e.g. DYJetsToLL_Pt, WJetsToLNu_Pt, DYJetsToNuNu_Pt) - cms.PSet(name = cms.string("NNPDF30_nlo_nf_5_pdfas"), lhaid = cms.uint32(292200)), - ), - namedWeightIDs = cms.vstring(), - namedWeightLabels = cms.vstring(), - lheWeightPrecision = cms.int32(14), - maxPdfWeights = cms.uint32(150), - debug = cms.untracked.bool(False), -) +from PhysicsTools.NanoAOD.genWeightsTable_cfi import * lheWeightsTable = cms.EDProducer( "LHEWeightsTableProducer", From c545dec27ff1ea783f24037d55a27c77f7fecc65 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 25 Dec 2019 02:02:29 +0100 Subject: [PATCH 56/75] Remove some customization to make it compile --- .../plugins/ExternalLHEProducer.cc | 22 ------------------- .../plugins/LHEProvenanceHelper.cc | 2 -- .../plugins/LHEProvenanceHelper.h | 2 -- .../LHEInterface/plugins/LHESource.cc | 15 ++++++------- 4 files changed, 7 insertions(+), 34 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 11b252504c698..330669a6c8c62 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -311,28 +311,6 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) p->fillCompressedContent(instream, 0.25 * insize); instream.close(); } - run.put(std::move(p), "LHEScriptOutput"); - for ( unsigned int iArg = 0; iArg < args_.size() ; iArg++ ) { - LogDebug("LHEInputArgs") << "arg [" << iArg << "] = " << args_[iArg]; - } - - executeScript(); - - //fill LHEXMLProduct (streaming read directly into compressed buffer to save memory) - std::unique_ptr p(new LHEXMLStringProduct); - - //store the XML file only if explictly requested - if (storeXML_) { - std::ifstream instream(outputFile_); - if (!instream) { - throw cms::Exception("OutputOpenError") << "Unable to open script output file " << outputFile_ << "."; - } - instream.seekg (0, instream.end); - int insize = instream.tellg(); - instream.seekg (0, instream.beg); - p->fillCompressedContent(instream, 0.25*insize); - instream.close(); - } run.put(std::move(p), "LHEScriptOutput"); // LHE C++ classes translation diff --git a/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc b/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc index cdcac41a36447..b9de5e6099f46 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc @@ -2,7 +2,6 @@ #include #include "GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h" #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" -#include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" #include "DataFormats/Provenance/interface/ProcessHistory.h" #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h" @@ -48,7 +47,6 @@ namespace edm { processParameterSet_() { // Add the products to the product registry productRegistry.copyProduct(eventProductBranchDescription_); - productRegistry.copyProduct(weightProductBranchDescription_); productRegistry.copyProduct(runProductBranchDescription_); } diff --git a/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h b/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h index a966dbc9ad9d6..5d3bc4b67ad01 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h +++ b/GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h @@ -17,14 +17,12 @@ namespace edm { struct LHEProvenanceHelper { explicit LHEProvenanceHelper(TypeID const& eventProductType, TypeID const& runProductType, - TypeID const& weightProductType, ProductRegistry& productRegistry); ParameterSet fillCommonProcessParameterSet(); void lheAugment(lhef::LHERunInfo const* runInfo); ProcessHistoryID lheInit(ProcessHistoryRegistry& processHistoryRegistry); BranchDescription const eventProductBranchDescription_; BranchDescription const runProductBranchDescription_; - BranchDescription const weightProductBranchDescription_; ProductProvenance eventProductProvenance_; ParameterSet const commonProcessParameterSet_; ParameterSet processParameterSet_; diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.cc b/GeneratorInterface/LHEInterface/plugins/LHESource.cc index e3802a7f4ca8e..f045da892bb94 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.cc @@ -33,13 +33,12 @@ using namespace lhef; -LHESource::LHESource(const edm::ParameterSet ¶ms, - const edm::InputSourceDescription &desc) : - ProducerSourceFromFiles(params, desc, false), - reader_(new LHEReader(fileNames(), params.getUntrackedParameter("skipEvents", 0))), - lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), edm::TypeID(typeid(GenWeightInfoProduct)), productRegistryUpdate()), - phid_() -{ +LHESource::LHESource(const edm::ParameterSet& params, const edm::InputSourceDescription& desc) + : ProducerSourceFromFiles(params, desc, false), + reader_(new LHEReader(fileNames(), params.getUntrackedParameter("skipEvents", 0))), + lheProvenanceHelper_( + edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()), + phid_() { nextEvent(); lheProvenanceHelper_.lheAugment(nullptr); // Initialize metadata, and save the process history ID for use every event. @@ -139,7 +138,7 @@ void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { product->addWeightGroupInfo(&scaleInfo); product->addWeightGroupInfo(&cenPdfInfo); std::unique_ptr rdp(new edm::Wrapper(std::move(product))); - iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp)); + //iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp)); } } From d6c2452601abe4d59950ad790612f187fe2eeb3e Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 26 Dec 2019 02:05:57 +0100 Subject: [PATCH 57/75] Remove duplicate text from merge --- .../LHEInterface/plugins/ExternalLHEProducer.cc | 15 --------------- .../LHEInterface/test/test_Weights_cfg.py | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 330669a6c8c62..3dc92f7aae051 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -375,21 +375,6 @@ void ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es run.put(std::move(product)); } - nextEvent(); - if (partonLevel) { - throw edm::Exception(edm::errors::EventGenerationFailure) - << "Error in ExternalLHEProducer::endRunProduce(). " - << "Event loop is over, but there are still lhe events to process." - << "This could happen if lhe file contains more events than requested. This is never expected to happen."; - } - - reader_.reset(); - - if (unlink(outputFile_.c_str())) { - throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ - << " (errno=" << errno << ", " << strerror(errno) << ")."; - } - nextEvent(); if (partonLevel) { throw edm::Exception(edm::errors::EventGenerationFailure) << "Error in ExternalLHEProducer::endRunProduce(). " diff --git a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py index 24846755a78be..b70c90b3ca2d0 100644 --- a/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py +++ b/GeneratorInterface/LHEInterface/test/test_Weights_cfg.py @@ -50,7 +50,7 @@ process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", #args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/WLLJJ_WToLNu_EWK_4F_MLL-60_slc6_amd64_gcc481_CMSSW_7_1_30_tarball_Dummy.tgz'), - args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/ZZ_4L_NNPDF30_13TeV_tarballDummy.tar.gz'), + args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/VVV_aQGCfs_dummy.tgz'), nEvents = cms.untracked.uint32(10), numberOfParameters = cms.uint32(1), outputFile = cms.string('cmsgrid_final.lhe'), From a4e2b7ae76707be16dd1bb41705a3f30ebfdb06a Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sun, 29 Dec 2019 00:43:19 +0100 Subject: [PATCH 58/75] Fix mistake in getting weightMetaInfo by index --- .../Core/src/LHEWeightHelper.cc | 23 ++++++++++++------- GeneratorInterface/Core/src/WeightHelper.cc | 2 +- .../Core/test/dumpWeightInfo.py | 4 ++-- .../interface/WeightGroupInfo.h | 2 +- .../src/ScaleWeightGroupInfo.cc | 2 +- .../GeneratorProducts/src/WeightGroupInfo.cc | 10 +++++--- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index 73fb67b19b195..66c6c894e4609 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -88,7 +88,7 @@ namespace gen { int error = xmlParser.Parse(line.c_str()); if (error) { return false; - //do something.... + //throw std::invalid_argument("Failed to parse weight info from header! Line was " + line); } XMLElement* element = xmlParser.FirstChildElement(); return element; @@ -124,20 +124,23 @@ namespace gen { currGroupAttributeMap_ = getAttributeMap(fullTag); auto name = currGroupAttributeMap_["name"]; - if (currentGroupIsScale()) + if (currentGroupIsScale()) { weightGroups_.push_back(std::make_unique(name)); + } else if (currentGroupIsPdf()) { weightGroups_.push_back(std::make_unique(name)); } - else + else { weightGroups_.push_back(std::make_unique(name)); + } } - else if (isAWeight(headerLine)) { + else if (std::regex_match(headerLine, std::regex(".*.*\n*"))) { + std::string fullTag = headerLine; + if (!std::regex_match(headerLine, std::regex(".*.*\n*"))) + fullTag = headerLine + ""; currWeightAttributeMap_.clear(); // This shouldn't really happen, but perhaps we find weights outside of weight groups? - //if (weightGroups_.empty()) - // weightGroups_.push_back(std::make_unique("Unknown")); - currWeightAttributeMap_ = getAttributeMap(headerLine); + currWeightAttributeMap_ = getAttributeMap(fullTag); std::string content = currWeightAttributeMap_["content"]; if (currWeightAttributeMap_["id"].empty()) { @@ -145,10 +148,14 @@ namespace gen { // should do something } + if (weightGroups_.empty()) { + weightGroups_.push_back(std::make_unique("Unknown")); + } auto& group = weightGroups_.back(); if (group.weightType() == gen::kScaleWeights) { - if (currWeightAttributeMap_["mur"].empty() || currWeightAttributeMap_["muf"].empty()) + if (currWeightAttributeMap_["mur"].empty() || currWeightAttributeMap_["muf"].empty()) { group.setIsWellFormed(false); + } else { try { float muR = std::stof(currWeightAttributeMap_["mur"]); diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index fbf58491198de..efc21457c4231 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -129,7 +129,7 @@ namespace gen { counter++; } // Needs to be properly handled - throw std::range_error("Unmatched weight"); + throw std::range_error("Unmatched Generator weight! ID was " + wgtId + " index was " + std::to_string(weightIndex)); } } diff --git a/GeneratorInterface/Core/test/dumpWeightInfo.py b/GeneratorInterface/Core/test/dumpWeightInfo.py index 24e7c99e2465b..1a148dd4ca39c 100644 --- a/GeneratorInterface/Core/test/dumpWeightInfo.py +++ b/GeneratorInterface/Core/test/dumpWeightInfo.py @@ -1,7 +1,7 @@ from DataFormats.FWLite import Events,Handle,Runs,Lumis import ROOT -#source = "externalLHEProducer" -sources = ["testLHEWeights", "testGenWeights"] +sources = ["externalLHEProducer"] +#sources = ["testLHEWeights", "testGenWeights"] #source = "testGenWeights" #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index 973e88f10e73d..1746e575c2c45 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -42,7 +42,7 @@ namespace gen { void copy(const WeightGroupInfo &other); virtual WeightGroupInfo* clone() const; WeightMetaInfo weightMetaInfo(int weightEntry) const; - WeightMetaInfo weightMetaInfo(std::string wgtId) const; + WeightMetaInfo weightMetaInfoByGlobalIndex(std::string wgtId, int weightEntry) const; int weightVectorEntry(const std::string& wgtId) const; int containsWeight(const std::string& wgtId, int weightEntry) const; int weightVectorEntry(const std::string& wgtId, int weightEntry) const; diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc index 64215f7ad6f2d..155d3981e00a6 100644 --- a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc @@ -22,7 +22,7 @@ namespace gen { void ScaleWeightGroupInfo::addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF) { WeightGroupInfo::addContainedId(weightEntry, id, label); - auto metaInfo = weightMetaInfo(weightEntry); + auto metaInfo = weightMetaInfoByGlobalIndex(id, weightEntry); setMuRMuFIndex(metaInfo, muR, muF); } diff --git a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc index 86940ae70a9f0..aeb877bfb7b29 100644 --- a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc @@ -24,9 +24,13 @@ namespace gen { return idsContained_.at(weightEntry); } - WeightMetaInfo WeightGroupInfo::weightMetaInfo(std::string wgtId) const { - int weightEntry = weightVectorEntry(wgtId); - return idsContained_.at(weightEntry); + WeightMetaInfo WeightGroupInfo::weightMetaInfoByGlobalIndex(std::string wgtId, int weightEntry) const { + int entry = weightVectorEntry(wgtId, weightEntry); + if (entry < 0 || entry >= static_cast(idsContained_.size())) + throw std::range_error("Weight entry " + std::to_string(weightEntry) + + " is not a member of group " + name_ + + ". \n firstID = " + std::to_string(firstId_) + " lastId = " + std::to_string(lastId_)); + return idsContained_.at(entry); } int WeightGroupInfo::weightVectorEntry(const std::string& wgtId) const { From 9f6b791b13bc3317bf1f516648602bc4bac95a75 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sun, 29 Dec 2019 02:19:36 +0100 Subject: [PATCH 59/75] Add outline of ME reweight weightinfo class --- GeneratorInterface/Core/interface/LHEWeightHelper.h | 1 + GeneratorInterface/Core/interface/WeightHelper.h | 1 + GeneratorInterface/Core/src/LHEWeightHelper.cc | 3 +++ GeneratorInterface/Core/src/WeightHelper.cc | 5 +++++ GeneratorInterface/Core/test/dumpWeightInfo.py | 4 ++-- SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h | 2 +- SimDataFormats/GeneratorProducts/src/classes.h | 1 + SimDataFormats/GeneratorProducts/src/classes_def.xml | 2 ++ 8 files changed, 16 insertions(+), 3 deletions(-) diff --git a/GeneratorInterface/Core/interface/LHEWeightHelper.h b/GeneratorInterface/Core/interface/LHEWeightHelper.h index 8a54f71bb6c6e..6b37f56403ce4 100644 --- a/GeneratorInterface/Core/interface/LHEWeightHelper.h +++ b/GeneratorInterface/Core/interface/LHEWeightHelper.h @@ -8,6 +8,7 @@ #include #include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" diff --git a/GeneratorInterface/Core/interface/WeightHelper.h b/GeneratorInterface/Core/interface/WeightHelper.h index da6084fcca18c..64c284fb4d7b5 100644 --- a/GeneratorInterface/Core/interface/WeightHelper.h +++ b/GeneratorInterface/Core/interface/WeightHelper.h @@ -25,6 +25,7 @@ namespace gen { std::unique_ptr weightProduct(std::vector); void setGroupInfo(); bool currentGroupIsScale(); + bool currentGroupIsMEParam(); bool currentGroupIsPdf(); int addWeightToProduct(std::unique_ptr& product, double weight, std::string name, int weightNum, int groupIndex); int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex); diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index 66c6c894e4609..e715e38f78fc3 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -130,6 +130,9 @@ namespace gen { else if (currentGroupIsPdf()) { weightGroups_.push_back(std::make_unique(name)); } + else if (currentGroupIsMEParam()) { + weightGroups_.push_back(std::make_unique(name)); + } else { weightGroups_.push_back(std::make_unique(name)); } diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index efc21457c4231..0d88d2c55fb80 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -79,6 +79,11 @@ namespace gen { [name] (const PdfSetInfo& setInfo) { return setInfo.name == name; }) != pdfSetsInfo.end(); } + bool WeightHelper::currentGroupIsMEParam() { + std::string name = boost::algorithm::to_lower_copy(currGroupAttributeMap_["name"]); + return (name.find("mg_reweighting") != std::string::npos); + } + // TODO: Could probably recycle this code better std::unique_ptr WeightHelper::weightProduct(std::vector weights) { auto weightProduct = std::make_unique(); diff --git a/GeneratorInterface/Core/test/dumpWeightInfo.py b/GeneratorInterface/Core/test/dumpWeightInfo.py index 1a148dd4ca39c..d10a86c6b53bd 100644 --- a/GeneratorInterface/Core/test/dumpWeightInfo.py +++ b/GeneratorInterface/Core/test/dumpWeightInfo.py @@ -5,8 +5,8 @@ #source = "testGenWeights" #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: -#for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: -for filename in ["test.root"]: +for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: +#for filename in ["test.root"]: for source in sources: lumis = Lumis(filename) lumi = lumis.__iter__().next() diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index 1746e575c2c45..e0fc9b2bdfb87 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -19,7 +19,7 @@ namespace gen { enum WeightType { kPdfWeights, kScaleWeights, - kMatrixElementWeights, + kMEParamWeights, kUnknownWeights, kPartonShowerWeights, }; diff --git a/SimDataFormats/GeneratorProducts/src/classes.h b/SimDataFormats/GeneratorProducts/src/classes.h index c806f021b6cb3..c83887ba46e43 100644 --- a/SimDataFormats/GeneratorProducts/src/classes.h +++ b/SimDataFormats/GeneratorProducts/src/classes.h @@ -11,6 +11,7 @@ #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" diff --git a/SimDataFormats/GeneratorProducts/src/classes_def.xml b/SimDataFormats/GeneratorProducts/src/classes_def.xml index 58ce9fb157e36..2ba9fe119446e 100644 --- a/SimDataFormats/GeneratorProducts/src/classes_def.xml +++ b/SimDataFormats/GeneratorProducts/src/classes_def.xml @@ -231,6 +231,7 @@ + @@ -240,6 +241,7 @@ + From afe662adbe2679072ca219b6a606c4462962301d Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sun, 29 Dec 2019 03:38:46 +0100 Subject: [PATCH 60/75] Add MEParams class, nanogen example config --- PhysicsTools/NanoAOD/python/nanogen_cff.py | 2 +- PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py | 169 ++++++++++++++++++ .../interface/MEParamWeightGroupInfo.h | 23 +++ .../src/MEParamWeightGroupInfo.cc | 12 ++ 4 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py create mode 100644 SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h create mode 100644 SimDataFormats/GeneratorProducts/src/MEParamWeightGroupInfo.cc diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index 496a525837f00..08c97b781f22c 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -1,4 +1,3 @@ -from PhysicsTools.NanoAOD.common_cff import * from PhysicsTools.NanoAOD.taus_cff import * from PhysicsTools.NanoAOD.jets_cff import * from PhysicsTools.NanoAOD.globals_cff import * @@ -90,3 +89,4 @@ def customizeNanoGEN(process): process.genJetAK8FlavourTable.src = process.genJetAK8Table.src process.tauGenJets.GenParticles = "genParticles" process.genVisTaus.srcGenParticles = "genParticles" + return process diff --git a/PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py b/PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py new file mode 100644 index 0000000000000..a1694745e2051 --- /dev/null +++ b/PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py @@ -0,0 +1,169 @@ +import FWCore.ParameterSet.Config as cms + + + +process = cms.Process('GEN') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.EventContent.EventContent_cff') +process.load('SimGeneral.MixingModule.mixNoPU_cfi') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.StandardSequences.Generator_cff') +process.load('IOMC.EventVertexGenerators.VtxSmearedRealistic50ns13TeVCollision_cfi') +process.load('GeneratorInterface.Core.genFilterSummary_cff') +process.load('PhysicsTools.NanoAOD.nanogen_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(10), + output = cms.optional.untracked.allowed(cms.int32,cms.PSet) +) + +# Input source +process.source = cms.Source("EmptySource") + +process.options = cms.untracked.PSet( + FailPath = cms.untracked.vstring(), + IgnoreCompletely = cms.untracked.vstring(), + Rethrow = cms.untracked.vstring(), + SkipEvent = cms.untracked.vstring(), + allowUnscheduled = cms.obsolete.untracked.bool, + canDeleteEarly = cms.untracked.vstring(), + emptyRunLumiMode = cms.obsolete.untracked.string, + eventSetup = cms.untracked.PSet( + forceNumberOfConcurrentIOVs = cms.untracked.PSet( + + ), + numberOfConcurrentIOVs = cms.untracked.uint32(1) + ), + fileMode = cms.untracked.string('FULLMERGE'), + forceEventSetupCacheClearOnNewRun = cms.untracked.bool(False), + makeTriggerResults = cms.obsolete.untracked.bool, + numberOfConcurrentLuminosityBlocks = cms.untracked.uint32(1), + numberOfConcurrentRuns = cms.untracked.uint32(1), + numberOfStreams = cms.untracked.uint32(0), + numberOfThreads = cms.untracked.uint32(1), + printDependencies = cms.untracked.bool(False), + sizeOfStackForThreadsInKB = cms.optional.untracked.uint32, + throwIfIllegalParameter = cms.untracked.bool(True), + wantSummary = cms.untracked.bool(False) +) + +# Production Info +process.configurationMetadata = cms.untracked.PSet( + annotation = cms.untracked.string('Configuration/GenProduction/python/SMP-RunIISummer15wmLHEGS-00344-fragment.py nevts:10'), + name = cms.untracked.string('Applications'), + version = cms.untracked.string('$Revision: 1.19 $') +) + +# Other statements +process.genstepfilter.triggerConditions=cms.vstring("generation_step") + +process.generator = cms.EDFilter("Pythia8HadronizerFilter", + PythiaParameters = cms.PSet( + parameterSets = cms.vstring( + 'pythia8CommonSettings', + 'pythia8CUEP8M1Settings', + 'pythia8PowhegEmissionVetoSettings', + 'pythia8PSweightsSettings', + 'processParameters' + ), + processParameters = cms.vstring( + 'POWHEG:nFinal = 2', + 'ParticleDecays:allowPhotonRadiation = on', + 'TimeShower:QEDshowerByL = on' + ), + pythia8CUEP8M1Settings = cms.vstring( + 'Tune:pp 14', + 'Tune:ee 7', + 'MultipartonInteractions:pT0Ref=2.4024', + 'MultipartonInteractions:ecmPow=0.25208', + 'MultipartonInteractions:expPow=1.6' + ), + pythia8CommonSettings = cms.vstring( + 'Tune:preferLHAPDF = 2', + 'Main:timesAllowErrors = 10000', + 'Check:epTolErr = 0.01', + 'Beams:setProductionScalesFromLHEF = off', + 'SLHA:keepSM = on', + 'SLHA:minMassSM = 1000.', + 'ParticleDecays:limitTau0 = on', + 'ParticleDecays:tau0Max = 10', + 'ParticleDecays:allowPhotonRadiation = on' + ), + pythia8PSweightsSettings = cms.vstring( + 'UncertaintyBands:doVariations = on', + 'UncertaintyBands:List = {isrRedHi isr:muRfac=0.707,fsrRedHi fsr:muRfac=0.707,isrRedLo isr:muRfac=1.414,fsrRedLo fsr:muRfac=1.414,isrDefHi isr:muRfac=0.5,fsrDefHi fsr:muRfac=0.5,isrDefLo isr:muRfac=2.0,fsrDefLo fsr:muRfac=2.0,isrConHi isr:muRfac=0.25,fsrConHi fsr:muRfac=0.25,isrConLo isr:muRfac=4.0,fsrConLo fsr:muRfac=4.0,fsr_G2GG_muR_dn fsr:G2GG:muRfac=0.5,fsr_G2GG_muR_up fsr:G2GG:muRfac=2.0,fsr_G2QQ_muR_dn fsr:G2QQ:muRfac=0.5,fsr_G2QQ_muR_up fsr:G2QQ:muRfac=2.0,fsr_Q2QG_muR_dn fsr:Q2QG:muRfac=0.5,fsr_Q2QG_muR_up fsr:Q2QG:muRfac=2.0,fsr_X2XG_muR_dn fsr:X2XG:muRfac=0.5,fsr_X2XG_muR_up fsr:X2XG:muRfac=2.0,fsr_G2GG_cNS_dn fsr:G2GG:cNS=-2.0,fsr_G2GG_cNS_up fsr:G2GG:cNS=2.0,fsr_G2QQ_cNS_dn fsr:G2QQ:cNS=-2.0,fsr_G2QQ_cNS_up fsr:G2QQ:cNS=2.0,fsr_Q2QG_cNS_dn fsr:Q2QG:cNS=-2.0,fsr_Q2QG_cNS_up fsr:Q2QG:cNS=2.0,fsr_X2XG_cNS_dn fsr:X2XG:cNS=-2.0,fsr_X2XG_cNS_up fsr:X2XG:cNS=2.0,isr_G2GG_muR_dn isr:G2GG:muRfac=0.5,isr_G2GG_muR_up isr:G2GG:muRfac=2.0,isr_G2QQ_muR_dn isr:G2QQ:muRfac=0.5,isr_G2QQ_muR_up isr:G2QQ:muRfac=2.0,isr_Q2QG_muR_dn isr:Q2QG:muRfac=0.5,isr_Q2QG_muR_up isr:Q2QG:muRfac=2.0,isr_X2XG_muR_dn isr:X2XG:muRfac=0.5,isr_X2XG_muR_up isr:X2XG:muRfac=2.0,isr_G2GG_cNS_dn isr:G2GG:cNS=-2.0,isr_G2GG_cNS_up isr:G2GG:cNS=2.0,isr_G2QQ_cNS_dn isr:G2QQ:cNS=-2.0,isr_G2QQ_cNS_up isr:G2QQ:cNS=2.0,isr_Q2QG_cNS_dn isr:Q2QG:cNS=-2.0,isr_Q2QG_cNS_up isr:Q2QG:cNS=2.0,isr_X2XG_cNS_dn isr:X2XG:cNS=-2.0,isr_X2XG_cNS_up isr:X2XG:cNS=2.0}', + 'UncertaintyBands:nFlavQ = 4', + 'UncertaintyBands:MPIshowers = on', + 'UncertaintyBands:overSampleFSR = 10.0', + 'UncertaintyBands:overSampleISR = 10.0', + 'UncertaintyBands:FSRpTmin2Fac = 20', + 'UncertaintyBands:ISRpTmin2Fac = 1' + ), + pythia8PowhegEmissionVetoSettings = cms.vstring( + 'POWHEG:veto = 1', + 'POWHEG:pTdef = 1', + 'POWHEG:emitted = 0', + 'POWHEG:pTemt = 0', + 'POWHEG:pThard = 0', + 'POWHEG:vetoCount = 100', + 'SpaceShower:pTmaxMatch = 2', + 'TimeShower:pTmaxMatch = 2' + ) + ), + comEnergy = cms.double(13000.0), + filterEfficiency = cms.untracked.double(1.0), + maxEventsToPrint = cms.untracked.int32(1), + pythiaHepMCVerbosity = cms.untracked.bool(False), + pythiaPylistVerbosity = cms.untracked.int32(1) +) + +process.externalLHEProducer = cms.EDProducer("ExternalLHEProducer", + args = cms.vstring('/afs/cern.ch/user/k/kelong/work/public/DummyGridpacks/VVV_aQGCfs_dummy.tgz'), + nEvents = cms.untracked.uint32(10), + numberOfParameters = cms.uint32(1), + outputFile = cms.string('cmsgrid_final.lhe'), + scriptName = cms.FileInPath('GeneratorInterface/LHEInterface/data/run_generic_tarball_cvmfs.sh') +) + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '') + +process.ProductionFilterSequence = cms.Sequence(process.generator) + +# Path and EndPath definitions +process.lhe_step = cms.Path(process.externalLHEProducer) +process.generation_step = cms.Path(process.pgen) +process.genfiltersummary_step = cms.EndPath(process.genFilterSummary) + +# Path and EndPath definitions +process.nanoGEN_step = cms.Path(process.nanogenSequence) +process.endjob_step = cms.EndPath(process.endOfProcess) +process.NANOAODGENoutput_step = cms.EndPath(process.NANOAODGENoutput) + +# Schedule definition +process.schedule = cms.Schedule(process.lhe_step,process.generation_step,process.genfiltersummary_step,process.nanoGEN_step,process.endjob_step,process.NANOAODGENoutput_step) + +# filter all path with the production filter sequence +for path in process.paths: + if path in ['lhe_step']: continue + getattr(process,path).insert(0, process.ProductionFilterSequence) + + +process.RandomNumberGeneratorService.externalLHEProducer.initialSeed=int(96) +# Customisation from command line +from PhysicsTools.NanoAOD.nanogen_cff import customizeNanoGEN +process = customizeNanoGEN(process) + + +# Add early deletion of temporary data products to reduce peak memory need +from Configuration.StandardSequences.earlyDeleteSettings_cff import customiseEarlyDelete +process = customiseEarlyDelete(process) +# End adding early deletion + diff --git a/SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h new file mode 100644 index 0000000000000..9a1def0700e21 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h @@ -0,0 +1,23 @@ +#ifndef SimDataFormats_GeneratorProducts_MEParamWeightGroupInfo_h +#define SimDataFormats_GeneratorProducts_MEParamWeightGroupInfo_h + +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" + +namespace gen { + class MEParamWeightGroupInfo : public WeightGroupInfo { + public: + MEParamWeightGroupInfo() : WeightGroupInfo() { weightType_ = kMEParamWeights; } + MEParamWeightGroupInfo(std::string header, std::string name) : + WeightGroupInfo(header, name) { weightType_ = kMEParamWeights; } + MEParamWeightGroupInfo(std::string header) : + MEParamWeightGroupInfo(header, header) {} + virtual ~MEParamWeightGroupInfo() override {} + void copy(const MEParamWeightGroupInfo &other); + virtual MEParamWeightGroupInfo* clone() const override; + }; +} + +#endif // SimDataFormats_GeneratorProducts_MEParamWeightGroupInfo_h + + + diff --git a/SimDataFormats/GeneratorProducts/src/MEParamWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/MEParamWeightGroupInfo.cc new file mode 100644 index 0000000000000..8d75b537cf890 --- /dev/null +++ b/SimDataFormats/GeneratorProducts/src/MEParamWeightGroupInfo.cc @@ -0,0 +1,12 @@ +#include "SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h" + +namespace gen { + void MEParamWeightGroupInfo::copy(const MEParamWeightGroupInfo &other) { + WeightGroupInfo::copy(other); + } + + MEParamWeightGroupInfo* MEParamWeightGroupInfo::clone() const { + return new MEParamWeightGroupInfo(*this); + } +} + From 6c5900c5e79cb695aa803c3d6c80ec5efe627601 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sun, 5 Jan 2020 00:55:15 +0100 Subject: [PATCH 61/75] Roughly working with Run, need to move to lumi --- .../plugins/LHEWeightsTableProducer.cc | 140 ++++++++---------- PhysicsTools/NanoAOD/python/nanogen_cff.py | 1 + 2 files changed, 59 insertions(+), 82 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index 5a49f8f47290c..aaf7d71920de0 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -8,70 +8,33 @@ #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" + #include #include #include namespace { - - // join vector of strings to one string - std::string join(const std::vector& vec, const char* delim) { - std::stringstream res; - std::copy(vec.begin(), vec.end(), std::ostream_iterator(res, delim)); - return res.str(); - } - - struct LHEWeightInfo { - std::string id; - std::string text; - std::optional group = std::nullopt; + struct WeightGroupData { + size_t index; + const gen::WeightGroupInfo* group; }; - std::vector getLHEWeightInfos(LHERunInfoProduct const& lheInfo) { - std::vector out; - - for (auto iter = lheInfo.headers_begin(), end = lheInfo.headers_end(); iter != end; ++iter) { - if (iter->tag() != "initrwgt") { - continue; - } - - tinyxml2::XMLDocument xmlDoc; - xmlDoc.Parse(("" + join(iter->lines(), "") + "").c_str()); - tinyxml2::XMLElement* root = xmlDoc.FirstChildElement("root"); - - for (auto* e = root->FirstChildElement(); e != nullptr; e = e->NextSiblingElement()) { - if (strcmp(e->Name(), "weight") == 0) { - // we are here if there is a weight that does not belong to any group - std::string text = ""; - if (e->GetText()) - text = e->GetText(); - out.push_back({e->Attribute("id"), text}); - } - if (strcmp(e->Name(), "weightgroup") == 0) { - std::string groupName = e->Attribute("name"); - for (auto* inner = e->FirstChildElement("weight"); inner != nullptr; - inner = inner->NextSiblingElement("weight")) { - // we are here if there is a weight in a weightgroup - std::string text = ""; - if (inner->GetText()) - text = inner->GetText(); - out.push_back({inner->Attribute("id"), text, groupName}); - } - } - } - } - - return out; - } - + typedef std::unordered_map WeightGroupsToStore; } // namespace -class LHEWeightsTableProducer : public edm::global::EDProducer>> { +class LHEWeightsTableProducer : public edm::global::EDProducer> { public: LHEWeightsTableProducer(edm::ParameterSet const& params) : lheInputTag_(params.getParameter("lheInfo")), lheToken_(consumes(params.getParameter("lheInfo"))), + lheWeightToken_(consumes(params.getParameter("lheInfo"))), + //lheWeightInfoToken_(consumes(params.getParameter("lheWeightInfo"))), weightgroups_(params.getParameter>("weightgroups")), lheWeightPrecision_(params.getParameter("lheWeightPrecision")) { consumes(lheInputTag_); @@ -82,53 +45,61 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheWeightHandle; + iEvent.getByToken(lheWeightToken_, lheWeightHandle); + const GenWeightProduct* lheWeightProduct = lheWeightHandle.product(); + WeightsContainer lheWeights = lheWeightProduct->weights(); + auto lheWeightTables = std::make_unique>(); auto const& weightInfos = *runCache(iEvent.getRun().index()); double w0 = lheInfo.originalXWGTUP(); - int i = 0; - if (lheInfo.weights().size() != weightInfos.size()) { - throw cms::Exception("LogicError", "Weight labels don't have the same size as weights!\n"); - } - std::unordered_map>> groupsWithWeights; - for (auto const& weight : lheInfo.weights()) { - auto& val = weightInfos[i].group ? groupsWithWeights[*weightInfos[i].group] : groupsWithWeights["ungrouped"]; - if (val.first.empty()) { - val.first += ";id,text"; - } - val.first += ";" + weightInfos[i].id + "," + weightInfos[i].text; - val.second.push_back(weight.wgt / w0); - ++i; - } - for (auto const& group : groupsWithWeights) { - if (std::find(weightgroups_.begin(), weightgroups_.end(), group.first) == weightgroups_.end()) { - continue; - } - std::string name = std::string("LHEWeight_") + group.first; - std::transform(name.begin(), name.end(), name.begin(), [](char ch) { return ch == ' ' ? '_' : ch; }); - std::string doc = group.first + " (w_var / w_nominal)" + group.second.first; - lheWeightTables->emplace_back(group.second.second.size(), name, false); - lheWeightTables->back().addColumn( - "", group.second.second, doc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); - } + size_t scaleGroupIndex = weightInfos.at("Scale").index; + const gen::ScaleWeightGroupInfo* scaleGroupInfo_ = static_cast(weightInfos.at("Scale").group); + + std::vector normalizedWeights; + std::vector& scaleWeights = lheWeights.at(scaleGroupIndex); + + // nano ordering of mur=0.5 muf=0.5 ; [1] is mur=0.5 muf=1 ; [2] is mur=0.5 muf=2 ; [3] is mur=1 muf=0.5 ; + // [4] is mur=1 muf=1 ; [5] is mur=1 muf=2 ; [6] is mur=2 muf=0.5 ; [7] is mur=2 muf=1 ; [8] is mur=2 muf=2 * + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR05muF05Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR05muF1Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR05muF2Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR1muF05Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->centralIndex())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR1muF2Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR2muF05Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR2muF1Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR2muF2Index())/w0); + + lheWeightTables->emplace_back(normalizedWeights.size(), "LHEScaleWeight", false); + lheWeightTables->back().addColumn( + "", normalizedWeights, scaleGroupInfo_->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); iEvent.put(std::move(lheWeightTables)); } - std::shared_ptr> globalBeginRun(edm::Run const& iRun, + std::shared_ptr globalBeginRun(edm::Run const& iRun, edm::EventSetup const&) const override { edm::Handle lheInfo; - auto weightChoice = std::make_shared>(); // getByToken throws since we're not in the endRun (see https://github.com/cms-sw/cmssw/pull/18499) iRun.getByLabel(lheInputTag_, lheInfo); - if (lheInfo.isValid()) { - getLHEWeightInfos(*lheInfo).swap(*weightChoice); - } - - return weightChoice; + //if (lheInfo.isValid()) { + //} + //iRun.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); + edm::Handle lheWeightInfoHandle; + iRun.getByLabel(lheInputTag_, lheWeightInfoHandle); + + // Should add a search by name function + auto scaleGroupIndices = lheWeightInfoHandle->weightGroupIndicesByType(gen::kScaleWeights); + size_t scaleGroupIndex = scaleGroupIndices.front(); + const gen::WeightGroupInfo* scaleGroupInfo = lheWeightInfoHandle->orderedWeightGroupInfo(scaleGroupIndex); + WeightGroupsToStore weightsToStore = { {"Scale", {scaleGroupIndex, scaleGroupInfo}} }; + + return std::make_shared(weightsToStore); } // nothing to do here @@ -146,7 +117,12 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheToken_; + const edm::EDGetTokenT lheWeightToken_; + const edm::EDGetTokenT lheWeightInfoToken_; + const std::vector weightgroups_; + + //std::unordered_map weightGroupIndices_; int lheWeightPrecision_; }; diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index 08c97b781f22c..951b76216ed7a 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -9,6 +9,7 @@ lheWeightsTable = cms.EDProducer( "LHEWeightsTableProducer", lheInfo = cms.InputTag("externalLHEProducer"), + #lheWeights = cms.InputTag("externalLHEProducer"), weightgroups = cms.vstring(["mg_reweighting"]), lheWeightPrecision = cms.int32(14), ) From fb19c05ff6a881b79291269911a376709d20c2c3 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sun, 5 Jan 2020 20:36:19 +0100 Subject: [PATCH 62/75] Produce in beginLumi, working with scale and NanoGen --- .../plugins/ExternalLHEProducer.cc | 8 +-- .../plugins/LHEWeightsTableProducer.cc | 68 +++++++++---------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 3dc92f7aae051..88d0d3cb9ed08 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -70,7 +70,7 @@ Description: [one line class summary] class ExternalLHEProducer : public edm::one::EDProducer { + edm::BeginLuminosityBlockProducer> { public: explicit ExternalLHEProducer(const edm::ParameterSet& iConfig); ~ExternalLHEProducer() override; @@ -81,7 +81,7 @@ class ExternalLHEProducer : public edm::one::EDProducer(); produces(); produces(); - produces(); + produces(); } ExternalLHEProducer::~ExternalLHEProducer() {} @@ -390,7 +390,7 @@ void ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es } void -ExternalLHEProducer::endLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& es) { +ExternalLHEProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& es) { auto weightInfoProduct = std::make_unique(); for (auto& weightGroup : weightHelper_.weightGroups()) { weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index aaf7d71920de0..44f958517b122 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -28,16 +28,16 @@ namespace { typedef std::unordered_map WeightGroupsToStore; } // namespace -class LHEWeightsTableProducer : public edm::global::EDProducer> { +class LHEWeightsTableProducer : public edm::global::EDProducer> { public: LHEWeightsTableProducer(edm::ParameterSet const& params) : lheInputTag_(params.getParameter("lheInfo")), lheToken_(consumes(params.getParameter("lheInfo"))), lheWeightToken_(consumes(params.getParameter("lheInfo"))), - //lheWeightInfoToken_(consumes(params.getParameter("lheWeightInfo"))), + lheWeightInfoToken_(consumes(params.getParameter("lheInfo"))), weightgroups_(params.getParameter>("weightgroups")), lheWeightPrecision_(params.getParameter("lheWeightPrecision")) { - consumes(lheInputTag_); + //consumes(lheInputTag_); produces>(); } @@ -51,47 +51,25 @@ class LHEWeightsTableProducer : public edm::global::EDProducerweights(); auto lheWeightTables = std::make_unique>(); - auto const& weightInfos = *runCache(iEvent.getRun().index()); + auto const& weightInfos = *luminosityBlockCache(iEvent.getLuminosityBlock().index()); double w0 = lheInfo.originalXWGTUP(); - size_t scaleGroupIndex = weightInfos.at("Scale").index; - const gen::ScaleWeightGroupInfo* scaleGroupInfo_ = static_cast(weightInfos.at("Scale").group); - - std::vector normalizedWeights; - std::vector& scaleWeights = lheWeights.at(scaleGroupIndex); - - // nano ordering of mur=0.5 muf=0.5 ; [1] is mur=0.5 muf=1 ; [2] is mur=0.5 muf=2 ; [3] is mur=1 muf=0.5 ; - // [4] is mur=1 muf=1 ; [5] is mur=1 muf=2 ; [6] is mur=2 muf=0.5 ; [7] is mur=2 muf=1 ; [8] is mur=2 muf=2 * - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR05muF05Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR05muF1Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR05muF2Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR1muF05Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->centralIndex())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR1muF2Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR2muF05Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR2muF1Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroupInfo_->muR2muF2Index())/w0); - - lheWeightTables->emplace_back(normalizedWeights.size(), "LHEScaleWeight", false); + auto scaleWeights = orderedScaleWeights(lheWeights, weightInfos.at("Scale"), w0); + lheWeightTables->emplace_back(scaleWeights.size(), "LHEScaleWeight", false); lheWeightTables->back().addColumn( - "", normalizedWeights, scaleGroupInfo_->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + "", scaleWeights, weightInfos.at("Scale").group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); iEvent.put(std::move(lheWeightTables)); } - std::shared_ptr globalBeginRun(edm::Run const& iRun, - edm::EventSetup const&) const override { - edm::Handle lheInfo; + + std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& iLumi, + edm::EventSetup const&) const override { - // getByToken throws since we're not in the endRun (see https://github.com/cms-sw/cmssw/pull/18499) - iRun.getByLabel(lheInputTag_, lheInfo); - //if (lheInfo.isValid()) { - //} - //iRun.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); edm::Handle lheWeightInfoHandle; - iRun.getByLabel(lheInputTag_, lheWeightInfoHandle); + iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); // Should add a search by name function auto scaleGroupIndices = lheWeightInfoHandle->weightGroupIndicesByType(gen::kScaleWeights); @@ -102,8 +80,30 @@ class LHEWeightsTableProducer : public edm::global::EDProducer(weightsToStore); } + std::vector orderedScaleWeights(WeightsContainer& lheWeights, const WeightGroupData& scaleGroupInfo, double w0) const { + const gen::ScaleWeightGroupInfo* scaleGroup = static_cast(scaleGroupInfo.group); + size_t scaleGroupIndex = scaleGroupInfo.index; + + std::vector normalizedWeights; + std::vector& scaleWeights = lheWeights.at(scaleGroupIndex); + + // nano ordering of mur=0.5 muf=0.5 ; [1] is mur=0.5 muf=1 ; [2] is mur=0.5 muf=2 ; [3] is mur=1 muf=0.5 ; + // [4] is mur=1 muf=1 ; [5] is mur=1 muf=2 ; [6] is mur=2 muf=0.5 ; [7] is mur=2 muf=1 ; [8] is mur=2 muf=2 * + normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR05muF05Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR05muF1Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR05muF2Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR1muF05Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroup->centralIndex())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR1muF2Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR2muF05Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR2muF1Index())/w0); + normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR2muF2Index())/w0); + + return normalizedWeights; + } + // nothing to do here - void globalEndRun(edm::Run const&, edm::EventSetup const&) const override {} + virtual void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const override {} static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; From ae40865dd6c1a0d3488eba13abf7c6669110867f Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 6 Jan 2020 00:08:40 +0100 Subject: [PATCH 63/75] Example with both scale and ME weights --- .../plugins/LHEWeightsTableProducer.cc | 41 +++++++++++++------ .../interface/GenWeightInfoProduct.h | 8 ++++ .../src/GenWeightInfoProduct.cc | 9 ++++ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index 44f958517b122..b9efcaf62f9c7 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -20,12 +20,7 @@ #include namespace { - struct WeightGroupData { - size_t index; - const gen::WeightGroupInfo* group; - }; - - typedef std::unordered_map WeightGroupsToStore; + typedef std::unordered_map WeightGroupsToStore; } // namespace class LHEWeightsTableProducer : public edm::global::EDProducer> { @@ -60,6 +55,12 @@ class LHEWeightsTableProducer : public edm::global::EDProducerback().addColumn( "", scaleWeights, weightInfos.at("Scale").group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + auto meWeights = meReweightWeights(lheWeights, weightInfos.at("MEReweight"), w0); + lheWeightTables->emplace_back(meWeights.size(), "LHEMEReweightWeight", false); + lheWeightTables->back().addColumn( + "", meWeights, weightInfos.at("MEReweight").group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + + iEvent.put(std::move(lheWeightTables)); } @@ -71,16 +72,32 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheWeightInfoHandle; iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); - // Should add a search by name function - auto scaleGroupIndices = lheWeightInfoHandle->weightGroupIndicesByType(gen::kScaleWeights); - size_t scaleGroupIndex = scaleGroupIndices.front(); - const gen::WeightGroupInfo* scaleGroupInfo = lheWeightInfoHandle->orderedWeightGroupInfo(scaleGroupIndex); - WeightGroupsToStore weightsToStore = { {"Scale", {scaleGroupIndex, scaleGroupInfo}} }; + std::vector scaleGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kScaleWeights); + auto meGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kMEParamWeights); + + WeightGroupsToStore weightsToStore; + weightsToStore.insert({"Scale", scaleGroups.front()}); + weightsToStore.insert({"MEReweight", meGroups.front()}); + // {"MEReweight", meGroups.at(0)}, + //}; + //i = 0; + //for (const auto& meGroup : meGroups) { + // std::string label = "MEReweight"; + // label = scaleGroups.size() > 1 ? label + i : label; + // weightsToStore[label] = meGroup; + //} return std::make_shared(weightsToStore); } - std::vector orderedScaleWeights(WeightsContainer& lheWeights, const WeightGroupData& scaleGroupInfo, double w0) const { + std::vector meReweightWeights(WeightsContainer& lheWeights, const gen::WeightGroupData& meGroupInfo, double w0) const { + std::vector normalizedWeights; + for (const auto& weight : lheWeights.at(meGroupInfo.index)) + normalizedWeights.push_back(weight/w0); + return normalizedWeights; + } + + std::vector orderedScaleWeights(WeightsContainer& lheWeights, const gen::WeightGroupData& scaleGroupInfo, double w0) const { const gen::ScaleWeightGroupInfo* scaleGroup = static_cast(scaleGroupInfo.group); size_t scaleGroupIndex = scaleGroupInfo.index; diff --git a/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h index 0152710f8fd56..b46120b0d786b 100644 --- a/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h @@ -12,6 +12,13 @@ #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" +namespace gen { + struct WeightGroupData { + size_t index; + const gen::WeightGroupInfo* group; + }; +} // namespace + class GenWeightInfoProduct { public: GenWeightInfoProduct() {} @@ -27,6 +34,7 @@ class GenWeightInfoProduct { const gen::WeightGroupInfo* orderedWeightGroupInfo(int index) const; std::vector weightGroupsByType(gen::WeightType type) const; std::vector weightGroupIndicesByType(gen::WeightType type) const; + std::vector weightGroupsAndIndicesByType(gen::WeightType type) const; void addWeightGroupInfo(gen::WeightGroupInfo* info); const int numberOfGroups() const { return weightGroupsInfo_.size(); } diff --git a/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc index 8a76e4d173b85..1eb25563b09ec 100644 --- a/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc @@ -35,6 +35,15 @@ const gen::WeightGroupInfo* GenWeightInfoProduct::orderedWeightGroupInfo(int wei return &weightGroupsInfo_[weightGroupIndex]; } +std::vector GenWeightInfoProduct::weightGroupsAndIndicesByType(gen::WeightType type) const { + std::vector matchingGroups; + for (size_t i = 0; i < weightGroupsInfo_.size(); i++) { + if (weightGroupsInfo_[i].weightType() == type) + matchingGroups.push_back({i, weightGroupsInfo_[i].clone()}); + } + return matchingGroups; +} + std::vector GenWeightInfoProduct::weightGroupsByType(gen::WeightType type) const { std::vector matchingGroups; for (size_t i = 0; i < weightGroupsInfo_.size(); i++) { From e542eaa66bc0cdff977f45bfe3d1aa58647bdb2c Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 6 Jan 2020 04:27:57 +0100 Subject: [PATCH 64/75] Improve organization of adding different weight types --- .../plugins/LHEWeightsTableProducer.cc | 51 +++++++++++-------- .../interface/GenWeightInfoProduct.h | 2 + .../src/GenWeightInfoProduct.cc | 13 +++++ 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index b9efcaf62f9c7..744f6a68ee4aa 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -50,21 +50,29 @@ class LHEWeightsTableProducer : public edm::global::EDProduceremplace_back(scaleWeights.size(), "LHEScaleWeight", false); - lheWeightTables->back().addColumn( - "", scaleWeights, weightInfos.at("Scale").group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); - - auto meWeights = meReweightWeights(lheWeights, weightInfos.at("MEReweight"), w0); - lheWeightTables->emplace_back(meWeights.size(), "LHEMEReweightWeight", false); - lheWeightTables->back().addColumn( - "", meWeights, weightInfos.at("MEReweight").group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + addWeightGroupToTable("Scale", lheWeightTables, weightInfos, lheWeights, w0); + addWeightGroupToTable("MEParam", lheWeightTables, weightInfos, lheWeights, w0); + addWeightGroupToTable("Pdf", lheWeightTables, weightInfos, lheWeights, w0); iEvent.put(std::move(lheWeightTables)); } - + void addWeightGroupToTable(std::string name, std::unique_ptr>& lheWeightTables, + const WeightGroupsToStore& weightInfos, WeightsContainer& lheWeights, double w0) const { + if (weightInfos.count(name)) { + const auto& groupInfo = weightInfos.at(name); + auto weights = groupInfo.group->weightType() != gen::kScaleWeights ? normalizedWeights(lheWeights, groupInfo, w0) : + orderedScaleWeights(lheWeights, groupInfo, w0); + std::string entryName = "LHE"; + entryName.append(name); + entryName.append("Weight"); + lheWeightTables->emplace_back(weights.size(), entryName, false); + lheWeightTables->back().addColumn( + "", weights, weightInfos.at(name).group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + } + } + std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) const override { @@ -72,25 +80,26 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheWeightInfoHandle; iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); - std::vector scaleGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kScaleWeights); + auto scaleGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kScaleWeights); auto meGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kMEParamWeights); WeightGroupsToStore weightsToStore; weightsToStore.insert({"Scale", scaleGroups.front()}); - weightsToStore.insert({"MEReweight", meGroups.front()}); - // {"MEReweight", meGroups.at(0)}, - //}; - //i = 0; - //for (const auto& meGroup : meGroups) { - // std::string label = "MEReweight"; - // label = scaleGroups.size() > 1 ? label + i : label; - // weightsToStore[label] = meGroup; - //} + + for (auto lhaid : {306000, 29000}) { + if (auto pdfGroup = lheWeightInfoHandle->pdfGroupWithIndexByLHAID(lhaid)) { + weightsToStore.insert({"Pdf", pdfGroup.value()}); + break; + } + } + + if (meGroups.size() > 0) + weightsToStore.insert({"MEParam", meGroups.front()}); return std::make_shared(weightsToStore); } - std::vector meReweightWeights(WeightsContainer& lheWeights, const gen::WeightGroupData& meGroupInfo, double w0) const { + std::vector normalizedWeights(WeightsContainer& lheWeights, const gen::WeightGroupData& meGroupInfo, double w0) const { std::vector normalizedWeights; for (const auto& weight : lheWeights.at(meGroupInfo.index)) normalizedWeights.push_back(weight/w0); diff --git a/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h index b46120b0d786b..06a3ff7907287 100644 --- a/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h @@ -5,6 +5,7 @@ #include #include #include +#include //#include @@ -35,6 +36,7 @@ class GenWeightInfoProduct { std::vector weightGroupsByType(gen::WeightType type) const; std::vector weightGroupIndicesByType(gen::WeightType type) const; std::vector weightGroupsAndIndicesByType(gen::WeightType type) const; + std::optional pdfGroupWithIndexByLHAID(size_t lhaid) const; void addWeightGroupInfo(gen::WeightGroupInfo* info); const int numberOfGroups() const { return weightGroupsInfo_.size(); } diff --git a/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc index 1eb25563b09ec..d6b42e3cc1f0e 100644 --- a/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc @@ -2,6 +2,7 @@ #include #include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" GenWeightInfoProduct::GenWeightInfoProduct(edm::OwnVector& weightGroups) { weightGroupsInfo_ = weightGroups; @@ -53,6 +54,18 @@ std::vector GenWeightInfoProduct::weightGroupsByType(gen: return matchingGroups; } +std::optional GenWeightInfoProduct::pdfGroupWithIndexByLHAID(size_t lhaid) const { + auto pdfGroups = weightGroupsAndIndicesByType(gen::kPdfWeights); + + auto matchingPdfSet = std::find_if(pdfGroups.begin(), pdfGroups.end(), + [lhaid] (gen::WeightGroupData& data) { + auto pdfGroup = dynamic_cast(data.group); + return pdfGroup->containsLhapdfId(lhaid); + }); + return matchingPdfSet != pdfGroups.end() ? std::optional(*matchingPdfSet) : std::nullopt; +} + + std::vector GenWeightInfoProduct::weightGroupIndicesByType(gen::WeightType type) const { std::vector matchingGroupIndices; for (size_t i = 0; i < weightGroupsInfo_.size(); i++) { From ca22fc5b12d786f48a74678a7fee1a1dd5eb3f10 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 10 Jan 2020 19:18:54 +0100 Subject: [PATCH 65/75] Close to working, but segfaulting --- .../Core/test/dumpWeightInfo.py | 1 + .../plugins/LHEWeightsTableProducer.cc | 87 +++++++++++++------ PhysicsTools/NanoAOD/python/nanogen_cff.py | 12 ++- PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py | 2 +- 4 files changed, 73 insertions(+), 29 deletions(-) diff --git a/GeneratorInterface/Core/test/dumpWeightInfo.py b/GeneratorInterface/Core/test/dumpWeightInfo.py index d10a86c6b53bd..cdb47e9b60fde 100644 --- a/GeneratorInterface/Core/test/dumpWeightInfo.py +++ b/GeneratorInterface/Core/test/dumpWeightInfo.py @@ -25,6 +25,7 @@ print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 matching = weightInfoProd.orderedWeightGroupInfo(j) print "Group is", matching, "name is", matching.name(), "well formed?", matching.isWellFormed() + print type(matching.weightType()), matching.weightType() if matching.weightType() == 1: for var in [(x, y) for x in ["05", "1", "2"] for y in ["05", "1", "2"]]: name = "muR%smuF%sIndex" % (var[0], var[1]) if not (var[0] == "1" and var[1] == "1") else "centralIndex" diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index 744f6a68ee4aa..9e074c4912c74 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -20,7 +20,13 @@ #include namespace { - typedef std::unordered_map WeightGroupsToStore; + typedef std::pair, std::vector> WeightGroupsToStore; + //struct WeightGroupToStore { + // gen::WeightType type; + // std::string name; + // bool inLHE; + // gen::WeightGroupData groupInfo; + //} } // namespace class LHEWeightsTableProducer : public edm::global::EDProducer> { @@ -28,11 +34,12 @@ class LHEWeightsTableProducer : public edm::global::EDProducer("lheInfo")), lheToken_(consumes(params.getParameter("lheInfo"))), - lheWeightToken_(consumes(params.getParameter("lheInfo"))), - lheWeightInfoToken_(consumes(params.getParameter("lheInfo"))), - weightgroups_(params.getParameter>("weightgroups")), + lheWeightToken_(consumes(params.getParameter("lheWeights"))), + lheWeightInfoToken_(consumes(params.getParameter("lheWeights"))), + genWeightToken_(consumes(params.getParameter("genWeights"))), + genWeightInfoToken_(consumes(params.getParameter("genWeights"))), + //weightgroups_(params.getParameter>("weightgroups")), lheWeightPrecision_(params.getParameter("lheWeightPrecision")) { - //consumes(lheInputTag_); produces>(); } @@ -45,31 +52,44 @@ class LHEWeightsTableProducer : public edm::global::EDProducerweights(); - auto lheWeightTables = std::make_unique>(); - auto const& weightInfos = *luminosityBlockCache(iEvent.getLuminosityBlock().index()); + edm::Handle genWeightHandle; + iEvent.getByToken(genWeightToken_, genWeightHandle); + const GenWeightProduct* genWeightProduct = genWeightHandle.product(); + WeightsContainer genWeights = genWeightProduct->weights(); + auto lheWeightTables = std::make_unique>(); double w0 = lheInfo.originalXWGTUP(); + auto const& weightInfos = *luminosityBlockCache(iEvent.getLuminosityBlock().index()); - addWeightGroupToTable("Scale", lheWeightTables, weightInfos, lheWeights, w0); - addWeightGroupToTable("MEParam", lheWeightTables, weightInfos, lheWeights, w0); - addWeightGroupToTable("Pdf", lheWeightTables, weightInfos, lheWeights, w0); - + addWeightGroupToTable(lheWeightTables, "Lhe", weightInfos.first, lheWeights, w0); + addWeightGroupToTable(lheWeightTables, "Gen", weightInfos.second, genWeights, w0); iEvent.put(std::move(lheWeightTables)); } - void addWeightGroupToTable(std::string name, std::unique_ptr>& lheWeightTables, - const WeightGroupsToStore& weightInfos, WeightsContainer& lheWeights, double w0) const { - if (weightInfos.count(name)) { - const auto& groupInfo = weightInfos.at(name); - auto weights = groupInfo.group->weightType() != gen::kScaleWeights ? normalizedWeights(lheWeights, groupInfo, w0) : + void addWeightGroupToTable(std::unique_ptr>& lheWeightTables, std::string entryName, + const std::vector& weightInfos, WeightsContainer& lheWeights, double w0) const { + size_t typeCount = 0; + gen::WeightType currentGroup = gen::kUnknownWeights; + + for (const auto& groupInfo : weightInfos) { + gen::WeightType weightType = groupInfo.group->weightType(); + std::string name = weightTypeNames_.at(weightType); + auto weights = weightType != gen::kScaleWeights ? normalizedWeights(lheWeights, groupInfo, w0) : orderedScaleWeights(lheWeights, groupInfo, w0); - std::string entryName = "LHE"; + if (typeCount > 0) + entryName.append(std::to_string(typeCount)); entryName.append(name); entryName.append("Weight"); + lheWeightTables->emplace_back(weights.size(), entryName, false); lheWeightTables->back().addColumn( - "", weights, weightInfos.at(name).group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + "", weights, groupInfo.group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + + typeCount++; + if (currentGroup != weightType) + typeCount = 0; + currentGroup = weightType; } } @@ -77,24 +97,30 @@ class LHEWeightsTableProducer : public edm::global::EDProducer globalBeginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) const override { + // Set equal to the max number of groups + // subtrack 1 for each weight group you find edm::Handle lheWeightInfoHandle; iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); + edm::Handle genWeightInfoHandle; + iLumi.getByToken(genWeightInfoToken_, genWeightInfoHandle); + auto scaleGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kScaleWeights); auto meGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kMEParamWeights); WeightGroupsToStore weightsToStore; - weightsToStore.insert({"Scale", scaleGroups.front()}); + weightsToStore.first.insert(weightsToStore.first.end(), scaleGroups.begin(), scaleGroups.end()); + weightsToStore.first.insert(weightsToStore.first.end(), meGroups.begin(), meGroups.end()); - for (auto lhaid : {306000, 29000}) { + for (auto lhaid : {306000, 91400, 260000}) { if (auto pdfGroup = lheWeightInfoHandle->pdfGroupWithIndexByLHAID(lhaid)) { - weightsToStore.insert({"Pdf", pdfGroup.value()}); + weightsToStore.first.push_back(pdfGroup.value()); break; } } - if (meGroups.size() > 0) - weightsToStore.insert({"MEParam", meGroups.front()}); + auto psGroups = genWeightInfoHandle->weightGroupsAndIndicesByType(gen::kPartonShowerWeights); + weightsToStore.second.insert(weightsToStore.second.end(), psGroups.begin(), psGroups.end()); return std::make_shared(weightsToStore); } @@ -135,7 +161,9 @@ class LHEWeightsTableProducer : public edm::global::EDProducer("lheInfo", {"externalLHEProducer"}) ->setComment("tag(s) for the LHE information (LHEEventProduct and LHERunInfoProduct)"); - desc.add>("weightgroups"); + //desc.add>("weightgroups"); + desc.add("lheWeights"); + desc.add("genWeights"); desc.add("lheWeightPrecision", -1)->setComment("Number of bits in the mantissa for LHE weights"); descriptions.addDefault(desc); } @@ -145,8 +173,15 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheToken_; const edm::EDGetTokenT lheWeightToken_; const edm::EDGetTokenT lheWeightInfoToken_; - - const std::vector weightgroups_; + const edm::EDGetTokenT genWeightToken_; + const edm::EDGetTokenT genWeightInfoToken_; + //const std::vector weightgroups_; + const std::unordered_map weightTypeNames_ = { + {gen::kScaleWeights, "Scale"}, + {gen::kPdfWeights, "Pdf"}, + {gen::kMEParamWeights, "MEParam"}, + {gen::kUnknownWeights, "Unknown"}, + }; //std::unordered_map weightGroupIndices_; int lheWeightPrecision_; diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index 951b76216ed7a..331880c6ba6c9 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -5,12 +5,19 @@ from PhysicsTools.NanoAOD.particlelevel_cff import * from PhysicsTools.NanoAOD.lheInfoTable_cfi import * from PhysicsTools.NanoAOD.genWeightsTable_cfi import * +import ROOT + +genWeights = cms.EDProducer("GenWeightProductProducer") lheWeightsTable = cms.EDProducer( "LHEWeightsTableProducer", lheInfo = cms.InputTag("externalLHEProducer"), - #lheWeights = cms.InputTag("externalLHEProducer"), - weightgroups = cms.vstring(["mg_reweighting"]), + lheWeights = cms.InputTag("externalLHEProducer"), + genWeights = cms.InputTag("genWeights"), + #weightgroups = cms.vint32([ROOT.gen.kScaleWeights, ROOT.gen.kMEParamWeights, ROOT.gen.kPdfWeights, ROOT.UnknownWeights]), + #weightgroups = cms.vint32([0,1,2,3,4]), + #numWeightgroups = cms.vint([1, -1, 1, 2, 1]), + #pdfs = cms.vint([91400, 306000, 260000]), lheWeightPrecision = cms.int32(14), ) @@ -33,6 +40,7 @@ ) nanogenSequence = cms.Sequence( + genWeights+ nanoMetadata+ particleLevel+ genJetTable+ diff --git a/PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py b/PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py index a1694745e2051..bf6124b75a66f 100644 --- a/PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py +++ b/PhysicsTools/NanoAOD/test/nanoGen_test_cfg.py @@ -143,7 +143,7 @@ process.genfiltersummary_step = cms.EndPath(process.genFilterSummary) # Path and EndPath definitions -process.nanoGEN_step = cms.Path(process.nanogenSequence) +process.nanoGEN_step = cms.Path(process.genWeights*process.nanogenSequence) process.endjob_step = cms.EndPath(process.endOfProcess) process.NANOAODGENoutput_step = cms.EndPath(process.NANOAODGENoutput) From 8fcc2305c2f0c46e180f9acb8e641640d0b024bb Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sat, 11 Jan 2020 12:44:51 +0100 Subject: [PATCH 66/75] Update weighttype, read storage info from config --- .../Core/plugins/GenWeightsTestAnalyzer.cc | 4 +- .../Core/src/LHEWeightHelper.cc | 2 +- GeneratorInterface/Core/src/WeightHelper.cc | 2 +- .../LHEInterface/interface/TestWeightInfo.h | 4 +- .../LHEInterface/plugins/LHESource.cc | 4 +- .../plugins/LHEWeightsTableProducer.cc | 105 +++++++++++------- PhysicsTools/NanoAOD/python/nanogen_cff.py | 11 +- .../interface/MEParamWeightGroupInfo.h | 4 +- .../interface/PartonShowerWeightGroupInfo.h | 2 +- .../interface/PdfWeightGroupInfo.h | 6 +- .../interface/ScaleWeightGroupInfo.h | 2 +- .../interface/UnknownWeightGroupInfo.h | 6 +- .../interface/WeightGroupInfo.h | 18 ++- .../src/GenWeightInfoProduct.cc | 2 +- 14 files changed, 104 insertions(+), 68 deletions(-) diff --git a/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc b/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc index aead5ad2baff4..492bdcd6a028f 100644 --- a/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc +++ b/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc @@ -422,7 +422,7 @@ GenWeightsTestAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); // Should add a search by name function - auto allScaleWeights = lheWeightInfoHandle->weightGroupIndicesByType(gen::kScaleWeights); + auto allScaleWeights = lheWeightInfoHandle->weightGroupIndicesByType(gen::WeightType::kScaleWeights); if (allScaleWeights.size() > 0) scaleWeightsIndex_ = allScaleWeights.front(); @@ -441,7 +441,7 @@ GenWeightsTestAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, scaleWeightsOrder_.push_back(scaleWeights->muR2muF1Index()); scaleWeightsOrder_.push_back(scaleWeights->muR2muF2Index()); - auto pdfGroups = lheWeightInfoHandle->weightGroupsByType(gen::kPdfWeights); + auto pdfGroups = lheWeightInfoHandle->weightGroupsByType(gen::WeightType::kPdfWeights); auto ct14Set = std::find_if(pdfGroups.begin(), pdfGroups.end(), [] (gen::WeightGroupInfo* group) { auto pdfGroup = dynamic_cast(group); diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index e715e38f78fc3..55952e28210ed 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -155,7 +155,7 @@ namespace gen { weightGroups_.push_back(std::make_unique("Unknown")); } auto& group = weightGroups_.back(); - if (group.weightType() == gen::kScaleWeights) { + if (group.weightType() == gen::WeightType::kScaleWeights) { if (currWeightAttributeMap_["mur"].empty() || currWeightAttributeMap_["muf"].empty()) { group.setIsWellFormed(false); } diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index 0d88d2c55fb80..091feab7d6265 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -53,7 +53,7 @@ namespace gen { void WeightHelper::setGroupInfo() { auto& group = weightGroups_.back(); const std::string& name = group.name(); - if (group.weightType() == kPdfWeights) { + if (group.weightType() == WeightType::kPdfWeights) { PdfWeightGroupInfo* pdfGroup = dynamic_cast(&group); auto pdfInfo = std::find_if(pdfSetsInfo.begin(), pdfSetsInfo.end(), [name] (const PdfSetInfo& setInfo) { return setInfo.name == name; }); diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h index 7e386bf1cd4ce..b0c52f6671077 100644 --- a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h +++ b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h @@ -25,7 +25,7 @@ gen::WeightGroupInfo getExampleScaleWeights() { R"( mur=0.5 muf=2 )", R"( mur=0.5 muf=0.5 )", }; - scaleInfo.setWeightType(gen::kScaleWeights); + scaleInfo.setWeightType(gen::WeightType::kScaleWeights); for (size_t i = 0; i < entries.size(); i++) { scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); @@ -49,7 +49,7 @@ gen::WeightGroupInfo getExampleScaleWeightsOutOfOrder() { R"( mur=0.5 muf=1 )", R"( mur=0.5 muf=0.5 )", }; - scaleInfo.setWeightType(gen::kScaleWeights); + scaleInfo.setWeightType(gen::WeightType::kScaleWeights); for (size_t i = 0; i < entries.size(); i++) { scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); diff --git a/GeneratorInterface/LHEInterface/plugins/LHESource.cc b/GeneratorInterface/LHEInterface/plugins/LHESource.cc index f045da892bb94..a29960d0a0a1b 100644 --- a/GeneratorInterface/LHEInterface/plugins/LHESource.cc +++ b/GeneratorInterface/LHEInterface/plugins/LHESource.cc @@ -128,12 +128,12 @@ void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) { gen::WeightGroupInfo scaleInfo( "" ); - scaleInfo.setWeightType(gen::kScaleWeights); + scaleInfo.setWeightType(gen::WeightType::kScaleWeights); gen::WeightGroupInfo cenPdfInfo( "" ); - cenPdfInfo.setWeightType(gen::kPdfWeights); + cenPdfInfo.setWeightType(gen::WeightType::kPdfWeights); product->addWeightGroupInfo(&scaleInfo); product->addWeightGroupInfo(&cenPdfInfo); diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index 9e074c4912c74..4be52b8da8b62 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -13,6 +13,7 @@ #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" +#include "FWCore/Utilities/interface/transform.h" #include @@ -21,25 +22,23 @@ namespace { typedef std::pair, std::vector> WeightGroupsToStore; - //struct WeightGroupToStore { - // gen::WeightType type; - // std::string name; - // bool inLHE; - // gen::WeightGroupData groupInfo; - //} } // namespace class LHEWeightsTableProducer : public edm::global::EDProducer> { public: - LHEWeightsTableProducer(edm::ParameterSet const& params) - : lheInputTag_(params.getParameter("lheInfo")), + LHEWeightsTableProducer(edm::ParameterSet const& params) : lheToken_(consumes(params.getParameter("lheInfo"))), lheWeightToken_(consumes(params.getParameter("lheWeights"))), lheWeightInfoToken_(consumes(params.getParameter("lheWeights"))), genWeightToken_(consumes(params.getParameter("genWeights"))), genWeightInfoToken_(consumes(params.getParameter("genWeights"))), - //weightgroups_(params.getParameter>("weightgroups")), + weightgroups_(edm::vector_transform(params.getParameter>("weightgroups"), + [](auto& c) { return gen::WeightType(c.at(0)); } )), + maxGroupsPerType_(params.getParameter>("maxGroupsPerType")), + pdfIds_(params.getParameter>("pdfIds")), lheWeightPrecision_(params.getParameter("lheWeightPrecision")) { + if (weightgroups_.size() != maxGroupsPerType_.size()) + throw std::invalid_argument("Inputs 'weightgroups' and 'weightgroupNums' must have equal size"); produces>(); } @@ -61,35 +60,39 @@ class LHEWeightsTableProducer : public edm::global::EDProducer>& lheWeightTables, std::string entryName, + void addWeightGroupToTable(std::unique_ptr>& lheWeightTables, const char* typeName, const std::vector& weightInfos, WeightsContainer& lheWeights, double w0) const { size_t typeCount = 0; - gen::WeightType currentGroup = gen::kUnknownWeights; + gen::WeightType previousType = gen::WeightType::kUnknownWeights; + size_t index = 0; for (const auto& groupInfo : weightInfos) { + std::string entryName = typeName; gen::WeightType weightType = groupInfo.group->weightType(); + if (previousType != weightType) + typeCount = 0; std::string name = weightTypeNames_.at(weightType); - auto weights = weightType != gen::kScaleWeights ? normalizedWeights(lheWeights, groupInfo, w0) : + auto weights = weightType != gen::WeightType::kScaleWeights ? normalizedWeights(lheWeights, groupInfo, w0) : orderedScaleWeights(lheWeights, groupInfo, w0); - if (typeCount > 0) - entryName.append(std::to_string(typeCount)); entryName.append(name); entryName.append("Weight"); + if (typeCount > 0) { + entryName.append("AltSet"); + entryName.append(std::to_string(typeCount)); + } lheWeightTables->emplace_back(weights.size(), entryName, false); lheWeightTables->back().addColumn( "", weights, groupInfo.group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); typeCount++; - if (currentGroup != weightType) - typeCount = 0; - currentGroup = weightType; + previousType = weightType; } } @@ -105,26 +108,48 @@ class LHEWeightsTableProducer : public edm::global::EDProducer genWeightInfoHandle; iLumi.getByToken(genWeightInfoToken_, genWeightInfoHandle); - auto scaleGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kScaleWeights); - auto meGroups = lheWeightInfoHandle->weightGroupsAndIndicesByType(gen::kMEParamWeights); + std::unordered_map storePerType; + for (size_t i = 0; i < weightgroups_.size(); i++) + storePerType[weightgroups_.at(i)] = maxGroupsPerType_.at(i); WeightGroupsToStore weightsToStore; - weightsToStore.first.insert(weightsToStore.first.end(), scaleGroups.begin(), scaleGroups.end()); - weightsToStore.first.insert(weightsToStore.first.end(), meGroups.begin(), meGroups.end()); + for (auto weightType : gen::allGenWeightTypes) { + auto lheWeights = weightDataPerType(lheWeightInfoHandle, weightType, storePerType[weightType]); + weightsToStore.first.insert(weightsToStore.first.end(), lheWeights.begin(), lheWeights.end()); - for (auto lhaid : {306000, 91400, 260000}) { - if (auto pdfGroup = lheWeightInfoHandle->pdfGroupWithIndexByLHAID(lhaid)) { - weightsToStore.first.push_back(pdfGroup.value()); - break; - } + auto genWeights = weightDataPerType(genWeightInfoHandle, weightType, storePerType[weightType]); + weightsToStore.second.insert(weightsToStore.second.end(), genWeights.begin(), genWeights.end()); } - auto psGroups = genWeightInfoHandle->weightGroupsAndIndicesByType(gen::kPartonShowerWeights); - weightsToStore.second.insert(weightsToStore.second.end(), psGroups.begin(), psGroups.end()); - return std::make_shared(weightsToStore); } + std::vector weightDataPerType(edm::Handle& weightsHandle, + gen::WeightType weightType, int& maxStore) const { + std::vector group; + if (weightType == gen::WeightType::kPdfWeights) { + for (auto lhaid : pdfIds_) { + if (auto pdfGroup = weightsHandle->pdfGroupWithIndexByLHAID(lhaid)) { + group.push_back(pdfGroup.value()); + maxStore--; + if (maxStore == 0) + break; + } + } + return group; + } + + group = weightsHandle->weightGroupsAndIndicesByType(weightType); + + if (maxStore < 0 || static_cast(group.size()) < maxStore) { + // Modify size in case one type of weight is present in multiple products + maxStore -= group.size(); + return group; + } + return std::vector(group.begin(), group.begin()+maxStore); + } + + std::vector normalizedWeights(WeightsContainer& lheWeights, const gen::WeightGroupData& meGroupInfo, double w0) const { std::vector normalizedWeights; for (const auto& weight : lheWeights.at(meGroupInfo.index)) @@ -161,26 +186,30 @@ class LHEWeightsTableProducer : public edm::global::EDProducer("lheInfo", {"externalLHEProducer"}) ->setComment("tag(s) for the LHE information (LHEEventProduct and LHERunInfoProduct)"); - //desc.add>("weightgroups"); desc.add("lheWeights"); desc.add("genWeights"); + desc.add>("weightgroups"); + desc.add>("maxGroupsPerType"); + desc.add>("pdfIds"); desc.add("lheWeightPrecision", -1)->setComment("Number of bits in the mantissa for LHE weights"); descriptions.addDefault(desc); } protected: - const edm::InputTag lheInputTag_; const edm::EDGetTokenT lheToken_; const edm::EDGetTokenT lheWeightToken_; const edm::EDGetTokenT lheWeightInfoToken_; const edm::EDGetTokenT genWeightToken_; const edm::EDGetTokenT genWeightInfoToken_; - //const std::vector weightgroups_; + const std::vector weightgroups_; + const std::vector maxGroupsPerType_; + const std::vector pdfIds_; const std::unordered_map weightTypeNames_ = { - {gen::kScaleWeights, "Scale"}, - {gen::kPdfWeights, "Pdf"}, - {gen::kMEParamWeights, "MEParam"}, - {gen::kUnknownWeights, "Unknown"}, + {gen::WeightType::kScaleWeights, "Scale"}, + {gen::WeightType::kPdfWeights, "Pdf"}, + {gen::WeightType::kMEParamWeights, "MEParam"}, + {gen::WeightType::kPartonShowerWeights, "PartonShower"}, + {gen::WeightType::kUnknownWeights, "Unknown"}, }; //std::unordered_map weightGroupIndices_; diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index 331880c6ba6c9..d2c155a48a5a6 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -5,7 +5,6 @@ from PhysicsTools.NanoAOD.particlelevel_cff import * from PhysicsTools.NanoAOD.lheInfoTable_cfi import * from PhysicsTools.NanoAOD.genWeightsTable_cfi import * -import ROOT genWeights = cms.EDProducer("GenWeightProductProducer") @@ -14,10 +13,12 @@ lheInfo = cms.InputTag("externalLHEProducer"), lheWeights = cms.InputTag("externalLHEProducer"), genWeights = cms.InputTag("genWeights"), - #weightgroups = cms.vint32([ROOT.gen.kScaleWeights, ROOT.gen.kMEParamWeights, ROOT.gen.kPdfWeights, ROOT.UnknownWeights]), - #weightgroups = cms.vint32([0,1,2,3,4]), - #numWeightgroups = cms.vint([1, -1, 1, 2, 1]), - #pdfs = cms.vint([91400, 306000, 260000]), + # Warning: you can use a full string, but only the first character is read. + # Note also that the capitalization is important! For example, 'parton shower' + # must be lower case and 'PDF' must be capital + weightgroups = cms.vstring(['scale', 'PDF', 'matrix element', 'unknown', 'shower']), + maxGroupsPerType = cms.vint32([1, -1, 1, 2, 1]), + pdfIds = cms.vint32([91400, 306000, 260000]), lheWeightPrecision = cms.int32(14), ) diff --git a/SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h index 9a1def0700e21..3b2dd09d37609 100644 --- a/SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h @@ -6,9 +6,9 @@ namespace gen { class MEParamWeightGroupInfo : public WeightGroupInfo { public: - MEParamWeightGroupInfo() : WeightGroupInfo() { weightType_ = kMEParamWeights; } + MEParamWeightGroupInfo() : WeightGroupInfo() { weightType_ = WeightType::kMEParamWeights; } MEParamWeightGroupInfo(std::string header, std::string name) : - WeightGroupInfo(header, name) { weightType_ = kMEParamWeights; } + WeightGroupInfo(header, name) { weightType_ = WeightType::kMEParamWeights; } MEParamWeightGroupInfo(std::string header) : MEParamWeightGroupInfo(header, header) {} virtual ~MEParamWeightGroupInfo() override {} diff --git a/SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h index e9bb539bcb185..ea6c1b1fba683 100644 --- a/SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/PartonShowerWeightGroupInfo.h @@ -9,7 +9,7 @@ namespace gen { PartonShowerWeightGroupInfo() : PartonShowerWeightGroupInfo("") {} PartonShowerWeightGroupInfo(std::string header, std::string name) : WeightGroupInfo(header, name) { - weightType_ = kPartonShowerWeights; + weightType_ = WeightType::kPartonShowerWeights; } PartonShowerWeightGroupInfo(std::string header) : PartonShowerWeightGroupInfo(header, header) { } diff --git a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h index 54556811ac4d8..aa69dc4bcb7b8 100644 --- a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h @@ -20,11 +20,11 @@ namespace gen { int alphasDownIndex_; std::vector> lhapdfIdsContained_; public: - PdfWeightGroupInfo() : WeightGroupInfo() { weightType_ = kPdfWeights; } + PdfWeightGroupInfo() : WeightGroupInfo() { weightType_ = WeightType::kPdfWeights; } PdfWeightGroupInfo(std::string header, std::string name) : - WeightGroupInfo(header, name) { weightType_ = kPdfWeights; } + WeightGroupInfo(header, name) { weightType_ = WeightType::kPdfWeights; } PdfWeightGroupInfo(std::string header) : - WeightGroupInfo(header) { weightType_ = kPdfWeights; } + WeightGroupInfo(header) { weightType_ = WeightType::kPdfWeights; } PdfWeightGroupInfo(const PdfWeightGroupInfo &other) { copy(other); } diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index 994c1235963dd..d3feee93811be 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -20,7 +20,7 @@ namespace gen { ScaleWeightGroupInfo() : ScaleWeightGroupInfo("") {} ScaleWeightGroupInfo(std::string header, std::string name) : WeightGroupInfo(header, name) { - weightType_ = kScaleWeights; + weightType_ = WeightType::kScaleWeights; isFunctionalFormVar_ = false; centralIndex_ = 0; muR1muF2Index_ = 0; diff --git a/SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h index 37f68289633d7..66152d8840434 100644 --- a/SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h @@ -6,11 +6,11 @@ namespace gen { class UnknownWeightGroupInfo : public WeightGroupInfo { public: - UnknownWeightGroupInfo() : WeightGroupInfo() { weightType_ = kUnknownWeights; } + UnknownWeightGroupInfo() : WeightGroupInfo() { weightType_ = WeightType::kUnknownWeights; } UnknownWeightGroupInfo(std::string header, std::string name) : - WeightGroupInfo(header, name) { weightType_ = kUnknownWeights; isWellFormed_ = false;} + WeightGroupInfo(header, name) { weightType_ = WeightType::kUnknownWeights; isWellFormed_ = false;} UnknownWeightGroupInfo(std::string header) : - WeightGroupInfo(header) { weightType_ = kUnknownWeights; isWellFormed_ = false;} + WeightGroupInfo(header) { weightType_ = WeightType::kUnknownWeights; isWellFormed_ = false;} virtual ~UnknownWeightGroupInfo() override {} void copy(const UnknownWeightGroupInfo &other); virtual UnknownWeightGroupInfo* clone() const override; diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index e0fc9b2bdfb87..fc71436bd5ed6 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace gen { struct WeightMetaInfo { @@ -16,14 +17,19 @@ namespace gen { std::string label; }; - enum WeightType { - kPdfWeights, - kScaleWeights, - kMEParamWeights, - kUnknownWeights, - kPartonShowerWeights, + enum class WeightType : char { + kPdfWeights = 'P', + kScaleWeights = 's', + kMEParamWeights = 'm', + kPartonShowerWeights = 'p', + kUnknownWeights = 'u', }; + const std::array allGenWeightTypes = {{WeightType::kPdfWeights, + WeightType::kScaleWeights, WeightType::kMEParamWeights, + WeightType::kPartonShowerWeights, WeightType::kUnknownWeights, + }}; + class WeightGroupInfo { public: WeightGroupInfo() : WeightGroupInfo("") {} diff --git a/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc index d6b42e3cc1f0e..2b08fce3ef09e 100644 --- a/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc @@ -55,7 +55,7 @@ std::vector GenWeightInfoProduct::weightGroupsByType(gen: } std::optional GenWeightInfoProduct::pdfGroupWithIndexByLHAID(size_t lhaid) const { - auto pdfGroups = weightGroupsAndIndicesByType(gen::kPdfWeights); + auto pdfGroups = weightGroupsAndIndicesByType(gen::WeightType::kPdfWeights); auto matchingPdfSet = std::find_if(pdfGroups.begin(), pdfGroups.end(), [lhaid] (gen::WeightGroupData& data) { From 3dbdd4c2515791462b43bf4d3f346456a4c366dd Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sat, 11 Jan 2020 16:35:26 +0100 Subject: [PATCH 67/75] Correct name of shower weights so they're stored --- GeneratorInterface/Core/plugins/GenWeightProductProducer.cc | 1 + PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc | 3 +-- PhysicsTools/NanoAOD/python/nanogen_cff.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc index 7c7f90cdba0df..2cbb6748a08de 100644 --- a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc @@ -78,6 +78,7 @@ GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLum iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle); weightNames_ = genLumiInfoHandle->weightNames(); + weightHelper_.parseWeightGroupsFromNames(weightNames_); } auto weightInfoProduct = std::make_unique(); diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index 4be52b8da8b62..f200d31ded731 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -71,7 +71,6 @@ class LHEWeightsTableProducer : public edm::global::EDProducerweightType(); @@ -141,7 +140,7 @@ class LHEWeightsTableProducer : public edm::global::EDProducerweightGroupsAndIndicesByType(weightType); - if (maxStore < 0 || static_cast(group.size()) < maxStore) { + if (maxStore < 0 || static_cast(group.size()) <= maxStore) { // Modify size in case one type of weight is present in multiple products maxStore -= group.size(); return group; diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index d2c155a48a5a6..b86f63905d6c9 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -16,7 +16,7 @@ # Warning: you can use a full string, but only the first character is read. # Note also that the capitalization is important! For example, 'parton shower' # must be lower case and 'PDF' must be capital - weightgroups = cms.vstring(['scale', 'PDF', 'matrix element', 'unknown', 'shower']), + weightgroups = cms.vstring(['scale', 'PDF', 'matrix element', 'unknown', 'parton shower']), maxGroupsPerType = cms.vint32([1, -1, 1, 2, 1]), pdfIds = cms.vint32([91400, 306000, 260000]), lheWeightPrecision = cms.int32(14), From 265e6a0463c2712017d231cafc9db23850c9897c Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 16 Jan 2020 23:46:35 +0100 Subject: [PATCH 68/75] Store normalized weights from the start, cleanup --- .../Core/interface/WeightHelper.h | 4 +- .../Core/plugins/GenWeightProductProducer.cc | 14 +-- .../Core/plugins/LHEWeightProductProducer.cc | 2 +- .../Core/src/LHEWeightHelper.cc | 2 + GeneratorInterface/Core/src/WeightHelper.cc | 8 +- .../plugins/ExternalLHEProducer.cc | 3 +- .../plugins/LHEWeightsTableProducer.cc | 101 ++++++++---------- PhysicsTools/NanoAOD/python/nanogen_cff.py | 5 +- .../interface/GenWeightInfoProduct.h | 3 +- .../interface/GenWeightProduct.h | 12 ++- .../interface/WeightGroupInfo.h | 8 +- .../src/GenWeightInfoProduct.cc | 18 +++- .../GeneratorProducts/src/WeightGroupInfo.cc | 3 +- 13 files changed, 99 insertions(+), 84 deletions(-) diff --git a/GeneratorInterface/Core/interface/WeightHelper.h b/GeneratorInterface/Core/interface/WeightHelper.h index 64c284fb4d7b5..5e3102aa60ea4 100644 --- a/GeneratorInterface/Core/interface/WeightHelper.h +++ b/GeneratorInterface/Core/interface/WeightHelper.h @@ -21,8 +21,8 @@ namespace gen { edm::OwnVector weightGroups() { return weightGroups_; } - std::unique_ptr weightProduct(std::vector); - std::unique_ptr weightProduct(std::vector); + std::unique_ptr weightProduct(std::vector, float w0); + std::unique_ptr weightProduct(std::vector, float w0); void setGroupInfo(); bool currentGroupIsScale(); bool currentGroupIsMEParam(); diff --git a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc index 2cbb6748a08de..104083173e6be 100644 --- a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc @@ -43,10 +43,8 @@ class GenWeightProductProducer : public edm::one::EDProducer(edm::InputTag("generator"))), - //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))), - genEventToken_(consumes(edm::InputTag("generator"))) - //iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) + genLumiInfoToken_(consumes(iConfig.getParameter("genInfo"))), + genEventToken_(consumes(iConfig.getParameter("genInfo"))) { produces(); produces(); @@ -63,14 +61,12 @@ void GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { edm::Handle genEventInfo; iEvent.getByToken(genEventToken_, genEventInfo); - // Read weights from LHEEventProduct - auto weightProduct = weightHelper_.weightProduct(genEventInfo->weights()); + + float centralWeight = genEventInfo->weights().size() > 0 ? genEventInfo->weights().at(0) : 1.; + auto weightProduct = weightHelper_.weightProduct(genEventInfo->weights(), centralWeight); iEvent.put(std::move(weightProduct)); } -//void -//GenWeightProductProducer::endLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) {} - void GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) { if (weightNames_.size() == 0) { diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index 0c98c2832d1a4..a4f0836314460 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -70,7 +70,7 @@ LHEWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe edm::Handle lheEventInfo; iEvent.getByToken(lheEventToken_, lheEventInfo); // Read weights from LHEEventProduct - auto weightProduct = weightHelper_.weightProduct(lheEventInfo->weights()); + auto weightProduct = weightHelper_.weightProduct(lheEventInfo->weights(), lheEventInfo->originalXWGTUP()); iEvent.put(std::move(weightProduct)); } diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index 55952e28210ed..1b3a7f4ee1039 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -136,6 +136,8 @@ namespace gen { else { weightGroups_.push_back(std::make_unique(name)); } + auto& group = weightGroups_.back(); + group.setDescription("Test description"); } else if (std::regex_match(headerLine, std::regex(".*.*\n*"))) { std::string fullTag = headerLine; diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index 091feab7d6265..fe96bd7298735 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -85,8 +85,8 @@ namespace gen { } // TODO: Could probably recycle this code better - std::unique_ptr WeightHelper::weightProduct(std::vector weights) { - auto weightProduct = std::make_unique(); + std::unique_ptr WeightHelper::weightProduct(std::vector weights, float w0) { + auto weightProduct = std::make_unique(w0); weightProduct->setNumWeightSets(weightGroups_.size()); int weightGroupIndex = 0; for (unsigned int i = 0; i < weights.size(); i++) { @@ -95,8 +95,8 @@ namespace gen { return std::move(weightProduct); } - std::unique_ptr WeightHelper::weightProduct(std::vector weights) { - auto weightProduct = std::make_unique(); + std::unique_ptr WeightHelper::weightProduct(std::vector weights, float w0) { + auto weightProduct = std::make_unique(w0); weightProduct->setNumWeightSets(weightGroups_.size()); int weightGroupIndex = 0; int i = 0; diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 88d0d3cb9ed08..49aaa321f9702 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -197,7 +197,8 @@ void ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe product.get(), _1)); // Should also zero out the weights in the GenInfoProduct - auto weightProduct = weightHelper_.weightProduct(partonLevel->weights()); + auto weightProduct = weightHelper_.weightProduct(partonLevel->weights(), + partonLevel->originalXWGTUP()); iEvent.put(std::move(weightProduct)); product->setScales(partonLevel->scales()); diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index f200d31ded731..cc4dc25809135 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -21,13 +21,13 @@ #include namespace { - typedef std::pair, std::vector> WeightGroupsToStore; + typedef std::vector WeightGroupDataContainer; + typedef std::array, 2> WeightGroupsToStore; } // namespace class LHEWeightsTableProducer : public edm::global::EDProducer> { public: LHEWeightsTableProducer(edm::ParameterSet const& params) : - lheToken_(consumes(params.getParameter("lheInfo"))), lheWeightToken_(consumes(params.getParameter("lheWeights"))), lheWeightInfoToken_(consumes(params.getParameter("lheWeights"))), genWeightToken_(consumes(params.getParameter("genWeights"))), @@ -44,8 +44,6 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheWeightHandle; iEvent.getByToken(lheWeightToken_, lheWeightHandle); const GenWeightProduct* lheWeightProduct = lheWeightHandle.product(); @@ -57,17 +55,16 @@ class LHEWeightsTableProducer : public edm::global::EDProducerweights(); auto lheWeightTables = std::make_unique>(); - double w0 = lheInfo.originalXWGTUP(); auto const& weightInfos = *luminosityBlockCache(iEvent.getLuminosityBlock().index()); - addWeightGroupToTable(lheWeightTables, "LHE", weightInfos.first, lheWeights, w0); - addWeightGroupToTable(lheWeightTables, "GEN", weightInfos.second, genWeights, w0); + addWeightGroupToTable(lheWeightTables, "LHE", weightInfos.at(inLHE), lheWeights); + addWeightGroupToTable(lheWeightTables, "Gen", weightInfos.at(inGen), genWeights); iEvent.put(std::move(lheWeightTables)); } void addWeightGroupToTable(std::unique_ptr>& lheWeightTables, const char* typeName, - const std::vector& weightInfos, WeightsContainer& lheWeights, double w0) const { + const WeightGroupDataContainer& weightInfos, WeightsContainer& allWeights) const { size_t typeCount = 0; gen::WeightType previousType = gen::WeightType::kUnknownWeights; @@ -76,9 +73,23 @@ class LHEWeightsTableProducer : public edm::global::EDProducerweightType(); if (previousType != weightType) typeCount = 0; + std::string name = weightTypeNames_.at(weightType); - auto weights = weightType != gen::WeightType::kScaleWeights ? normalizedWeights(lheWeights, groupInfo, w0) : - orderedScaleWeights(lheWeights, groupInfo, w0); + std::string label = groupInfo.group->name(); + + auto& weights = allWeights.at(groupInfo.index); + label.append("; "); + if (weightType == gen::WeightType::kScaleWeights && groupInfo.group->isWellFormed() + && groupInfo.group->nIdsContained() < 10) { + weights = orderedScaleWeights(weights, + dynamic_cast(groupInfo.group)); + label.append("[1] is mur=0.5 muf=1; [2] is mur=0.5 muf=2; [3] is mur=1 muf=0.5 ;" + " [4] is mur=1 muf=1; [5] is mur=1 muf=2; [6] is mur=2 muf=0.5;" + " [7] is mur=2 muf=1 ; [8] is mur=2 muf=2)"); + } + else + label.append(groupInfo.group->description()); + entryName.append(name); entryName.append("Weight"); if (typeCount > 0) { @@ -88,7 +99,7 @@ class LHEWeightsTableProducer : public edm::global::EDProduceremplace_back(weights.size(), entryName, false); lheWeightTables->back().addColumn( - "", weights, groupInfo.group->name(), nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); + "", weights, label, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_); typeCount++; previousType = weightType; @@ -112,33 +123,25 @@ class LHEWeightsTableProducer : public edm::global::EDProducer(weightsToStore); } - std::vector weightDataPerType(edm::Handle& weightsHandle, + WeightGroupDataContainer weightDataPerType(edm::Handle& weightsHandle, gen::WeightType weightType, int& maxStore) const { - std::vector group; - if (weightType == gen::WeightType::kPdfWeights) { - for (auto lhaid : pdfIds_) { - if (auto pdfGroup = weightsHandle->pdfGroupWithIndexByLHAID(lhaid)) { - group.push_back(pdfGroup.value()); - maxStore--; - if (maxStore == 0) - break; - } - } - return group; + WeightGroupDataContainer group; + if (weightType == gen::WeightType::kPdfWeights && pdfIds_.size() > 0) { + group = weightsHandle->pdfGroupsWithIndicesByLHAIDs(pdfIds_); } - - group = weightsHandle->weightGroupsAndIndicesByType(weightType); + else + group = weightsHandle->weightGroupsAndIndicesByType(weightType); if (maxStore < 0 || static_cast(group.size()) <= maxStore) { // Modify size in case one type of weight is present in multiple products @@ -149,33 +152,20 @@ class LHEWeightsTableProducer : public edm::global::EDProducer normalizedWeights(WeightsContainer& lheWeights, const gen::WeightGroupData& meGroupInfo, double w0) const { - std::vector normalizedWeights; - for (const auto& weight : lheWeights.at(meGroupInfo.index)) - normalizedWeights.push_back(weight/w0); - return normalizedWeights; - } + std::vector orderedScaleWeights(const std::vector& scaleWeights, const gen::ScaleWeightGroupInfo* scaleGroup) const { + + std::vector weights; + weights.push_back(scaleWeights.at(scaleGroup->muR05muF05Index())); + weights.push_back(scaleWeights.at(scaleGroup->muR05muF1Index())); + weights.push_back(scaleWeights.at(scaleGroup->muR05muF2Index())); + weights.push_back(scaleWeights.at(scaleGroup->muR1muF05Index())); + weights.push_back(scaleWeights.at(scaleGroup->centralIndex())); + weights.push_back(scaleWeights.at(scaleGroup->muR1muF2Index())); + weights.push_back(scaleWeights.at(scaleGroup->muR2muF05Index())); + weights.push_back(scaleWeights.at(scaleGroup->muR2muF1Index())); + weights.push_back(scaleWeights.at(scaleGroup->muR2muF2Index())); - std::vector orderedScaleWeights(WeightsContainer& lheWeights, const gen::WeightGroupData& scaleGroupInfo, double w0) const { - const gen::ScaleWeightGroupInfo* scaleGroup = static_cast(scaleGroupInfo.group); - size_t scaleGroupIndex = scaleGroupInfo.index; - - std::vector normalizedWeights; - std::vector& scaleWeights = lheWeights.at(scaleGroupIndex); - - // nano ordering of mur=0.5 muf=0.5 ; [1] is mur=0.5 muf=1 ; [2] is mur=0.5 muf=2 ; [3] is mur=1 muf=0.5 ; - // [4] is mur=1 muf=1 ; [5] is mur=1 muf=2 ; [6] is mur=2 muf=0.5 ; [7] is mur=2 muf=1 ; [8] is mur=2 muf=2 * - normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR05muF05Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR05muF1Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR05muF2Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR1muF05Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroup->centralIndex())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR1muF2Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR2muF05Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR2muF1Index())/w0); - normalizedWeights.push_back(scaleWeights.at(scaleGroup->muR2muF2Index())/w0); - - return normalizedWeights; + return weights; } // nothing to do here @@ -183,8 +173,6 @@ class LHEWeightsTableProducer : public edm::global::EDProducer("lheInfo", {"externalLHEProducer"}) - ->setComment("tag(s) for the LHE information (LHEEventProduct and LHERunInfoProduct)"); desc.add("lheWeights"); desc.add("genWeights"); desc.add>("weightgroups"); @@ -213,6 +201,7 @@ class LHEWeightsTableProducer : public edm::global::EDProducer weightGroupIndices_; int lheWeightPrecision_; + enum {inLHE, inGen}; }; #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index b86f63905d6c9..aed174dbf7a2b 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -6,11 +6,11 @@ from PhysicsTools.NanoAOD.lheInfoTable_cfi import * from PhysicsTools.NanoAOD.genWeightsTable_cfi import * -genWeights = cms.EDProducer("GenWeightProductProducer") +genWeights = cms.EDProducer("GenWeightProductProducer", + genInfo = cms.InputTag("generator")) lheWeightsTable = cms.EDProducer( "LHEWeightsTableProducer", - lheInfo = cms.InputTag("externalLHEProducer"), lheWeights = cms.InputTag("externalLHEProducer"), genWeights = cms.InputTag("genWeights"), # Warning: you can use a full string, but only the first character is read. @@ -18,6 +18,7 @@ # must be lower case and 'PDF' must be capital weightgroups = cms.vstring(['scale', 'PDF', 'matrix element', 'unknown', 'parton shower']), maxGroupsPerType = cms.vint32([1, -1, 1, 2, 1]), + # If empty or not specified, all pdf weights are stored pdfIds = cms.vint32([91400, 306000, 260000]), lheWeightPrecision = cms.int32(14), ) diff --git a/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h b/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h index 06a3ff7907287..f990ed1931ea5 100644 --- a/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h @@ -36,7 +36,8 @@ class GenWeightInfoProduct { std::vector weightGroupsByType(gen::WeightType type) const; std::vector weightGroupIndicesByType(gen::WeightType type) const; std::vector weightGroupsAndIndicesByType(gen::WeightType type) const; - std::optional pdfGroupWithIndexByLHAID(size_t lhaid) const; + std::optional pdfGroupWithIndexByLHAID(int lhaid) const; + std::vector pdfGroupsWithIndicesByLHAIDs(const std::vector& lhaids) const; void addWeightGroupInfo(gen::WeightGroupInfo* info); const int numberOfGroups() const { return weightGroupsInfo_.size(); } diff --git a/SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h b/SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h index e09f2541f8601..4675e17c6c80d 100644 --- a/SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h +++ b/SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h @@ -13,10 +13,12 @@ typedef std::vector> WeightsContainer; class GenWeightProduct { public: - GenWeightProduct() { weightsVector_ = {}; } + GenWeightProduct() { weightsVector_ = {}; centralWeight_ = 1.; } + GenWeightProduct(double w0) { weightsVector_ = {}; centralWeight_ = w0; } GenWeightProduct& operator=(GenWeightProduct&& other) { - weightsVector_ = std::move(other.weightsVector_); - return *this; + weightsVector_ = std::move(other.weightsVector_); + centralWeight_ = other.centralWeight_; + return *this; } ~GenWeightProduct() {} @@ -31,12 +33,14 @@ class GenWeightProduct { if (static_cast(weights.size()) <= weightNum) { weights.resize(weightNum+1); } - weights[weightNum] = weight; + weights[weightNum] = weight/centralWeight_; } const WeightsContainer& weights() const { return weightsVector_; } + double centralWeight() const { return centralWeight_; } private: WeightsContainer weightsVector_; + double centralWeight_; }; #endif // GeneratorEvent_LHEInterface_GenWeightProduct_h diff --git a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h index fc71436bd5ed6..aa097b399cf12 100644 --- a/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h @@ -25,7 +25,7 @@ namespace gen { kUnknownWeights = 'u', }; - const std::array allGenWeightTypes = {{WeightType::kPdfWeights, + const std::array allWeightTypes = {{WeightType::kPdfWeights, WeightType::kScaleWeights, WeightType::kMEParamWeights, WeightType::kPartonShowerWeights, WeightType::kUnknownWeights, }}; @@ -50,22 +50,25 @@ namespace gen { WeightMetaInfo weightMetaInfo(int weightEntry) const; WeightMetaInfo weightMetaInfoByGlobalIndex(std::string wgtId, int weightEntry) const; int weightVectorEntry(const std::string& wgtId) const; - int containsWeight(const std::string& wgtId, int weightEntry) const; + bool containsWeight(const std::string& wgtId, int weightEntry) const; int weightVectorEntry(const std::string& wgtId, int weightEntry) const; void addContainedId(int weightEntry, std::string id, std::string label); std::vector containedIds() const; bool indexInRange(int index) const; void setName(std::string name) { name_ = name; } + void setDescription(std::string description) { description_ = description; } void setHeaderEntry(std::string header) { headerEntry_ = header; } void setWeightType(WeightType type) { weightType_ = type; } void setFirstId(int firstId) { firstId_ = firstId; } void setLastId(int lastId) { lastId_ = lastId; } std::string name() const { return name_; } + std::string description() const { return description_; } std::string headerEntry() const { return headerEntry_; } WeightType weightType() const { return weightType_; } std::vector idsContained() const { return idsContained_; } + size_t nIdsContained() const { return idsContained_.size(); } int firstId() const { return firstId_; } int lastId() const { return lastId_; } // Store whether the group was fully parsed succesfully @@ -76,6 +79,7 @@ namespace gen { bool isWellFormed_; std::string headerEntry_; std::string name_; + std::string description_; WeightType weightType_; std::vector idsContained_; int firstId_; diff --git a/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc index 2b08fce3ef09e..e16bbebcc27da 100644 --- a/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc +++ b/SimDataFormats/GeneratorProducts/src/GenWeightInfoProduct.cc @@ -54,7 +54,7 @@ std::vector GenWeightInfoProduct::weightGroupsByType(gen: return matchingGroups; } -std::optional GenWeightInfoProduct::pdfGroupWithIndexByLHAID(size_t lhaid) const { +std::optional GenWeightInfoProduct::pdfGroupWithIndexByLHAID(int lhaid) const { auto pdfGroups = weightGroupsAndIndicesByType(gen::WeightType::kPdfWeights); auto matchingPdfSet = std::find_if(pdfGroups.begin(), pdfGroups.end(), @@ -65,6 +65,22 @@ std::optional GenWeightInfoProduct::pdfGroupWithIndexByLHA return matchingPdfSet != pdfGroups.end() ? std::optional(*matchingPdfSet) : std::nullopt; } +std::vector GenWeightInfoProduct::pdfGroupsWithIndicesByLHAIDs(const std::vector& lhaids) const { + auto pdfGroups = weightGroupsAndIndicesByType(gen::WeightType::kPdfWeights); + std::vector groups; + + for (auto lhaid : lhaids) { + auto matchingPdfSet = std::find_if(pdfGroups.begin(), pdfGroups.end(), + [lhaid] (gen::WeightGroupData& data) { + auto pdfGroup = dynamic_cast(data.group); + return pdfGroup->containsLhapdfId(lhaid); + }); + if (matchingPdfSet != pdfGroups.end()) + pdfGroups.push_back(*matchingPdfSet); + } + + return pdfGroups; +} std::vector GenWeightInfoProduct::weightGroupIndicesByType(gen::WeightType type) const { std::vector matchingGroupIndices; diff --git a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc index aeb877bfb7b29..23c22b2342838 100644 --- a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc @@ -10,6 +10,7 @@ namespace gen { isWellFormed_ = true; headerEntry_ = other.headerEntry(); name_ = other.name(); + description_ = other.description(); weightType_ = other.weightType(); idsContained_ = other.idsContained(); firstId_ = other.firstId(); @@ -37,7 +38,7 @@ namespace gen { return weightVectorEntry(wgtId, 0); } - int WeightGroupInfo::containsWeight(const std::string& wgtId, int weightEntry) const { + bool WeightGroupInfo::containsWeight(const std::string& wgtId, int weightEntry) const { return weightVectorEntry(wgtId, weightEntry) != -1; } From 6aaef397110c974d83ba52e75c65e5819dd9fc1d Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 17 Jan 2020 11:31:23 +0100 Subject: [PATCH 69/75] Make pdfIds untracked --- PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc | 5 ++--- PhysicsTools/NanoAOD/python/nanogen_cff.py | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index cc4dc25809135..ed26af86897bc 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -35,7 +35,7 @@ class LHEWeightsTableProducer : public edm::global::EDProducer>("weightgroups"), [](auto& c) { return gen::WeightType(c.at(0)); } )), maxGroupsPerType_(params.getParameter>("maxGroupsPerType")), - pdfIds_(params.getParameter>("pdfIds")), + pdfIds_(params.getUntrackedParameter>("pdfIds", {})), lheWeightPrecision_(params.getParameter("lheWeightPrecision")) { if (weightgroups_.size() != maxGroupsPerType_.size()) throw std::invalid_argument("Inputs 'weightgroups' and 'weightgroupNums' must have equal size"); @@ -177,7 +177,7 @@ class LHEWeightsTableProducer : public edm::global::EDProducer("genWeights"); desc.add>("weightgroups"); desc.add>("maxGroupsPerType"); - desc.add>("pdfIds"); + desc.addOptionalUntracked>("pdfIds"); desc.add("lheWeightPrecision", -1)->setComment("Number of bits in the mantissa for LHE weights"); descriptions.addDefault(desc); } @@ -203,6 +203,5 @@ class LHEWeightsTableProducer : public edm::global::EDProducer store all found maxGroupsPerType = cms.vint32([1, -1, 1, 2, 1]), - # If empty or not specified, all pdf weights are stored - pdfIds = cms.vint32([91400, 306000, 260000]), + # If empty or not specified, no critieria is applied to filter on LHAPDF IDs + pdfIds = cms.untracked.vint32([91400, 306000, 260000]), lheWeightPrecision = cms.int32(14), ) From 6ccee5d97cb552ffbad85a773e833fc8e6ef658b Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 17 Jan 2020 20:57:33 +0100 Subject: [PATCH 70/75] Working implementation producing new prod if needed --- .../Core/plugins/LHEWeightProductProducer.cc | 24 ++++++++++----- .../plugins/LHEWeightsTableProducer.cc | 29 ++++++++++++++----- PhysicsTools/NanoAOD/python/nanogen_cff.py | 7 ++++- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index a4f0836314460..db74a3b25730b 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -36,6 +36,8 @@ class LHEWeightProductProducer : public edm::one::EDProducer lheRunInfoToken_; edm::EDGetTokenT lheEventToken_; + const edm::EDGetTokenT lheWeightInfoToken_; + bool foundWeightProduct_; void produce(edm::Event&, const edm::EventSetup&) override; void beginLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& es) override; @@ -48,11 +50,10 @@ class LHEWeightProductProducer : public edm::one::EDProducer("lheSourceLabel")), - lheRunInfoToken_(consumes( - iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))), - lheEventToken_(consumes( - iConfig.getUntrackedParameter("lheSource", edm::InputTag("externalLHEProducer")))) + lheLabel_(iConfig.getParameter("lheSourceLabel")), + lheRunInfoToken_(consumes(lheLabel_)), + lheEventToken_(consumes(lheLabel_)), + lheWeightInfoToken_(consumes(lheLabel_)) { produces(); produces(); @@ -67,6 +68,9 @@ LHEWeightProductProducer::~LHEWeightProductProducer() // ------------ method called to produce the data ------------ void LHEWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + if (foundWeightProduct_) + return; + edm::Handle lheEventInfo; iEvent.getByToken(lheEventToken_, lheEventInfo); // Read weights from LHEEventProduct @@ -74,12 +78,9 @@ LHEWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe iEvent.put(std::move(weightProduct)); } -// ------------ method called when starting to processes a run ------------ void LHEWeightProductProducer::beginRun(edm::Run const& run, edm::EventSetup const& es) { edm::Handle lheRunInfoHandle; - //run.getByToken(lheRunInfoToken_, lheRunInfoHandle); - // get by token gives an error (the same one that's been in the ExternalLHEProducer for ages) run.getByLabel(lheLabel_, lheRunInfoHandle); typedef std::vector::const_iterator header_cit; @@ -97,6 +98,13 @@ LHEWeightProductProducer::endRun(edm::Run const& run, edm::EventSetup const& es) void LHEWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& es) { + edm::Handle lheWeightInfoHandle; + lumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); + if (lheWeightInfoHandle.isValid()) { + foundWeightProduct_ = true; + return; + } + auto weightInfoProduct = std::make_unique(); for (auto& weightGroup : weightHelper_.weightGroups()) { weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); diff --git a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc index ed26af86897bc..5587cbd3d31e6 100644 --- a/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc @@ -28,8 +28,10 @@ namespace { class LHEWeightsTableProducer : public edm::global::EDProducer> { public: LHEWeightsTableProducer(edm::ParameterSet const& params) : - lheWeightToken_(consumes(params.getParameter("lheWeights"))), - lheWeightInfoToken_(consumes(params.getParameter("lheWeights"))), + lheWeightTokens_(edm::vector_transform(params.getParameter>("lheWeights"), + [this](const edm::InputTag& tag) { return mayConsume(tag); })), + lheWeightInfoTokens_(edm::vector_transform(params.getParameter>("lheWeights"), + [this](const edm::InputTag& tag) { return mayConsume(tag); })), genWeightToken_(consumes(params.getParameter("genWeights"))), genWeightInfoToken_(consumes(params.getParameter("genWeights"))), weightgroups_(edm::vector_transform(params.getParameter>("weightgroups"), @@ -43,9 +45,14 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheWeightHandle; - iEvent.getByToken(lheWeightToken_, lheWeightHandle); + for (auto& token : lheWeightTokens_) { + iEvent.getByToken(token, lheWeightHandle); + if (lheWeightHandle.isValid()) { + break; + } + } + const GenWeightProduct* lheWeightProduct = lheWeightHandle.product(); WeightsContainer lheWeights = lheWeightProduct->weights(); @@ -113,7 +120,12 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheWeightInfoHandle; - iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); + for (auto& token : lheWeightInfoTokens_) { + iLumi.getByToken(token, lheWeightInfoHandle); + if (lheWeightInfoHandle.isValid()) { + break; + } + } edm::Handle genWeightInfoHandle; iLumi.getByToken(genWeightInfoToken_, genWeightInfoHandle); @@ -173,7 +185,8 @@ class LHEWeightsTableProducer : public edm::global::EDProducer("lheWeights"); + desc.add>("lheWeights"); + //desc.add>("genWeights"); desc.add("genWeights"); desc.add>("weightgroups"); desc.add>("maxGroupsPerType"); @@ -184,8 +197,8 @@ class LHEWeightsTableProducer : public edm::global::EDProducer lheToken_; - const edm::EDGetTokenT lheWeightToken_; - const edm::EDGetTokenT lheWeightInfoToken_; + const std::vector> lheWeightTokens_; + const std::vector> lheWeightInfoTokens_; const edm::EDGetTokenT genWeightToken_; const edm::EDGetTokenT genWeightInfoToken_; const std::vector weightgroups_; diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index b79d0d61c0b39..88d8ebe03c18f 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -9,9 +9,13 @@ genWeights = cms.EDProducer("GenWeightProductProducer", genInfo = cms.InputTag("generator")) +lheWeights = cms.EDProducer("LHEWeightProductProducer", + lheSourceLabel = cms.string("externalLHEProducer"), + lheSource = cms.InputTag("externalLHEProducer")) + lheWeightsTable = cms.EDProducer( "LHEWeightsTableProducer", - lheWeights = cms.InputTag("externalLHEProducer"), + lheWeights = cms.VInputTag(["externalLHEProducer", "lheWeights"]), genWeights = cms.InputTag("genWeights"), # Warning: you can use a full string, but only the first character is read. # Note also that the capitalization is important! For example, 'parton shower' @@ -44,6 +48,7 @@ nanogenSequence = cms.Sequence( genWeights+ + lheWeights+ nanoMetadata+ particleLevel+ genJetTable+ From 884dc84cf36c5578e59c7300e2f63c11403f07b2 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 17 Jan 2020 21:20:32 +0100 Subject: [PATCH 71/75] Remove test analyzers --- .../Core/plugins/GenWeightsTestAnalyzer.cc | 456 ------------------ .../testGenWeights_simpleZanalyzer_cfg.py | 78 --- 2 files changed, 534 deletions(-) delete mode 100644 GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc delete mode 100644 GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py diff --git a/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc b/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc deleted file mode 100644 index 492bdcd6a028f..0000000000000 --- a/GeneratorInterface/Core/plugins/GenWeightsTestAnalyzer.cc +++ /dev/null @@ -1,456 +0,0 @@ -// -*- C++ -*- -// -// Package: GenAnalysis/GenWeightsTestAnalyzer -// Class: GenWeightsTestAnalyzer -// -/**\class GenWeightsTestAnalyzer GenWeightsTestAnalyzer.cc GenAnalysis/GenWeightsTestAnalyzer/plugins/GenWeightsTestAnalyzer.cc - - Description: [one line class summary] - - Implementation: - [Notes on implementation] -*/ -// -// Original Author: Andreas Artur Eugen Albert -// Created: Fri, 21 Jul 2017 11:42:52 GMT -// -// - - -// system include files -#include -#include // std::pair -// user include files -#include -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/Run.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/HepMCCandidate/interface/GenParticle.h" -#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "DataFormats/METReco/interface/GenMET.h" -#include "DataFormats/METReco/interface/GenMETCollection.h" -#include "DataFormats/JetReco/interface/GenJetCollection.h" - -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "CommonTools/UtilAlgos/interface/TFileService.h" - -#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" - -#include "SimDataFormats/GeneratorProducts/interface/GenWeightInfoProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/GenWeightProduct.h" - -#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" -#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" -#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" - -#include "Math/VectorUtil.h" - -#include -#include -#include -#include -// -// class declaration -// - -// If the analyzer does not use TFileService, please remove -// the template argument to the base class so the class inherits -// from edm::one::EDAnalyzer<> and also remove the line from -// constructor "usesResource("TFileService");" -// This will improve performance in multithreaded jobs. - -class GenWeightsTestAnalyzer : public edm::one::EDAnalyzer { - public: - explicit GenWeightsTestAnalyzer(const edm::ParameterSet&); - ~GenWeightsTestAnalyzer(); - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - - private: - virtual void beginJob() override; - virtual void beginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) override; - virtual void endLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const&) override {} - virtual void analyze(const edm::Event&, const edm::EventSetup&) override; - virtual void endJob() override; - - void setup_variables(const edm::Event& iEvent); - std::vector setup_weights(const edm::Event& iEvent); - - // ----------member data --------------------------- - std::string tag_; - bool isMiniaod_; - std::vector scaleWeightsOrder_; - int scaleWeightsIndex_; - int pdfWeightsIndex_; - - edm::EDGetTokenT genParticleToken_; - edm::EDGetTokenT genJetToken_; - edm::EDGetTokenT LHEToken_; - edm::EDGetTokenT GenToken_; - edm::EDGetTokenT lheWeightToken_; - edm::EDGetTokenT genWeightToken_; - edm::EDGetTokenT lheWeightInfoToken_; - edm::Service fileservice; - - std::map histograms2d; - std::map histograms1d; - - TTree * tree; - std::map variables; - - TNamed * filelist; - - TH1D * h_count_event; - TH1D * h_count_sumw; - - const unsigned int KEEP_LHAPDFID_ = 23000; - int keepPdfSetIndex_ = 0; - int keepPdfIndexInSet_ = -1; -}; - -// -// constants, enums and typedefs -// - -// -// static data member definitions -// - -// -// constructors and destructor -// -GenWeightsTestAnalyzer::GenWeightsTestAnalyzer(const edm::ParameterSet& iConfig) : - tag_(iConfig.getParameter("tag")), - isMiniaod_(iConfig.getParameter("miniaod")), - scaleWeightsIndex_(-1), - pdfWeightsIndex_(-1), - genParticleToken_(consumes(iConfig.getParameter("genParticleSrc"))), - genJetToken_(consumes(iConfig.getParameter("genJetSrc"))), - LHEToken_(consumes(iConfig.getParameter("LHESrc"))), - GenToken_(consumes(iConfig.getParameter("GenSrc"))), - lheWeightToken_(consumes(edm::InputTag("testLheWeights"))), - genWeightToken_(consumes(edm::InputTag("testGenWeights"))), - lheWeightInfoToken_(consumes(edm::InputTag("testLheWeights"))) - -{ - //now do what ever initialization is needed - //usesResource("TFileService"); - TFileDirectory subdirectory = fileservice->mkdir( tag_ ); - - h_count_event = subdirectory.make("h_count_event", "h_count_event;Dummy;Events", 1,0,1); - h_count_sumw = subdirectory.make("h_count_sumw", "h_count_sumw;Weight index;Events", 1,0,1); - - int nweights = 1200; - histograms2d["pt_jet1"] = subdirectory.make("pt_jet1", "Leading jet pt;pt_{jet};weight;Events",200,0,1000, nweights, -0.5, nweights-0.5); - histograms2d["pt_jet2"] = subdirectory.make("pt_jet2", "Trailing jet pt;pt_{jet};weight;Events",200,0,1000, nweights, -0.5, nweights-0.5); - histograms2d["pt_jet3"] = subdirectory.make("pt_jet3", "3rd jet pt;pt_{jet};weight;Events",200,0,1000, nweights, -0.5, nweights-0.5); - histograms2d["pt_jet4"] = subdirectory.make("pt_jet4", "4th jet pt;pt_{jet};weight;Events",200,0,1000, nweights, -0.5, nweights-0.5); - histograms2d["ht"] = subdirectory.make("ht", "HT;HT (GeV);weight;Events",200,0,2000, nweights, -0.5, nweights-0.5); - histograms2d["dilepton_pt"] = subdirectory.make("dilepton_pt", "Dilepton p_{T}; p_{T} (GeV);weight;Events",200,0,2000, nweights, -0.5, nweights-0.5); - histograms2d["n_leptons"] = subdirectory.make("n_leptons", "number of leptons;n_lep;weight;Events",10,-0.5,9.5, nweights, -0.5, nweights-0.5); - - tree = subdirectory.make("events","events"); - for(auto const entry : histograms1d){ - tree->Branch(entry.first, &variables[entry.first],(entry.first+"/D").Data()); - } - filelist = subdirectory.make(tag_,tag_); -} - - -GenWeightsTestAnalyzer::~GenWeightsTestAnalyzer() -{ - - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) - -} - - -// -// member functions -// -bool compare_pt(reco::GenParticle p1, reco::GenParticle p2){ - return p2.pt() < p1.pt(); -} -std::vector select_leptons(const std::vector genParticles) { - std::vector leptons; - for (auto const p : genParticles){ - unsigned const int id = abs(p.pdgId()); - if(p.numberOfDaughters() > 0) continue; - else if(p.pt()<20) continue; - else if(not ((id==11)||(id==13)) ) continue; - else leptons.push_back(p); - } - std::sort(leptons.begin(), leptons.end(), compare_pt ); - return leptons; -} -std::vector select_neutrinos(const std::vector genParticles) { - std::vector neutrinos; - for (auto const p : genParticles){ - unsigned const int id = abs(p.pdgId()); - if(p.pt() < 25) continue; - else if(p.numberOfDaughters() > 0) continue; - else if(not ((id==12)||(id==14)||(id==16)) ) continue; - else neutrinos.push_back(p); - } - std::sort(neutrinos.begin(), neutrinos.end(), compare_pt ); - return neutrinos; -} - -std::vector select_jets(const std::vector genJets) { - std::vector jets; - for (auto const p : genJets){ - if(fabs(p.pt()) < 10) continue; - else jets.push_back(p); - } - std::sort(jets.begin(), jets.end(), compare_pt ); - return jets; -} - -std::pair find_z_candidate(std::vector & genParticles) { - double delta_mass_min = 9999; - double m_z = 91; - reco::GenParticle p1,p2; - for( unsigned int i = 0; i < genParticles.size(); i++ ) { - for( unsigned int j = i+1; j < genParticles.size(); j++ ) { - auto candidate_p4 = genParticles.at(i).p4() + genParticles.at(j).p4(); - double dm = fabs(candidate_p4.mass()-m_z); - if(dm < delta_mass_min ) { - delta_mass_min = dm; - p1 = genParticles.at(i); - p2 = genParticles.at(j); - } - } - } - return std::make_pair(p1,p2); -} - -std::vector clean_jets(const std::vector genJets, const std::vector leptons){ - std::vector cleaned_jets; - cleaned_jets.reserve(genJets.size()); - for( auto const jet : genJets ) { - double delta_r_min = 999; - double eta = jet.eta(); - double phi = jet.phi(); - for( auto const lep : leptons ) { - double delta_r = pow((pow(lep.eta() - eta,2) + pow(lep.phi() - phi,2)),0.5); - if (delta_r < delta_r_min){ - delta_r_min = delta_r; - } - } - if(delta_r_min < 0.4) { - continue; - } else { - cleaned_jets.push_back(jet); - } - } - return cleaned_jets; -} -void print_variables(std::map variables) { - -} -double delta_phi(reco::Candidate::LorentzVector const & p1,reco::Candidate::LorentzVector const & p2) { - double dphi_raw = fabs(p1.phi() - p2.phi()); - if(dphi_raw > M_PI){ - return 2*M_PI - dphi_raw; - } else { - return dphi_raw; - } -} -//// Parse generator history of particle and look for -bool has_v_in_history(reco::GenParticle const & part){ - size_t nmothers = part.numberOfMothers(); - if(nmothers == 0) { - return false; - } else { - for( size_t im = 0; im < nmothers; im++ ){ - auto const & mother = *(part.motherRef(im)); - - if(mother.pdgId() == 23 or mother.pdgId() == 24) { - return true; - } else if( has_v_in_history(*(part.motherRef(im))) ) { - return true; - } - } - return false; - } -} - -void GenWeightsTestAnalyzer::setup_variables(const edm::Event& iEvent) { - using namespace edm; - - //// Initialize with dummy values - for ( auto pair : variables ) { - variables[pair.first] = -9999; - } - - Handle> genParticleHandle; - iEvent.getByToken(genParticleToken_, genParticleHandle); - const std::vector * genParticles = genParticleHandle.product(); - - Handle> genJetHandle; - iEvent.getByToken(genJetToken_, genJetHandle); - const std::vector * genJets = genJetHandle.product(); - - edm::Handle lheHandle; - iEvent.getByLabel("externalLHEProducer", lheHandle); - const LHEEventProduct * lhe = lheHandle.product(); - - - - - variables["weight"] = lhe->originalXWGTUP(); - - //~ //// Leptons - std::vector leptons = select_leptons(*genParticles); - variables["n_leptons"] = leptons.size(); - - if(leptons.size() >= 2) { - auto z_cand = find_z_candidate(leptons); - variables["dilepton_pt"] = (z_cand.first.p4() + z_cand.second.p4()).pt(); - } - else - variables["dilepton_pt"] = 0; - - //// Jets - std::vector jets = clean_jets(select_jets(*genJets),leptons); - int njets = jets.size(); - variables["n_jets"] = njets; - variables["pt_jet1"] = njets > 0 ? jets.at(0).pt() : -999; - variables["pt_jet2"] = njets > 1 ? jets.at(1).pt() : -999; - variables["pt_jet3"] = njets > 2 ? jets.at(2).pt() : -999; - variables["pt_jet4"] = njets > 3 ? jets.at(3).pt() : -999; - - double ht = 0; - for(auto const & j : jets){ - ht += j.pt(); - } - variables["ht"] = ht; - -} -std::vector GenWeightsTestAnalyzer::setup_weights(const edm::Event& iEvent) { - edm::Handle lheWeightHandle; - edm::Handle genWeightHandle; - iEvent.getByToken(lheWeightToken_, lheWeightHandle); - iEvent.getByToken(genWeightToken_, genWeightHandle); - const GenWeightProduct * lheWeightProduct = lheWeightHandle.product(); - const GenWeightProduct * genWeightProduct = genWeightHandle.product(); - WeightsContainer lheWeights = lheWeightProduct->weights(); - WeightsContainer genWeights = genWeightProduct->weights(); - - auto scaleWeights = scaleWeightsIndex_ >= 0 ? lheWeights.at(scaleWeightsIndex_) : std::vector(); - auto pdfWeights = pdfWeightsIndex_ > 0 ? lheWeights.at(pdfWeightsIndex_) : std::vector(); - std::vector keepWeights; - - for(auto i : scaleWeightsOrder_){ - keepWeights.push_back(scaleWeights.at(i)); - } - - for(auto& weight : pdfWeights){ - keepWeights.push_back(weight); - } - - if (genWeights.size() > 0) { - for(auto& weight : genWeights.front()){ - keepWeights.push_back(weight); - } - } - - return keepWeights; -} - - -// ------------ method called for each event ------------ -void -GenWeightsTestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - using namespace edm; - - setup_variables(iEvent); - tree->Fill(); - auto weights = setup_weights(iEvent); - h_count_event->Fill(0.5); - h_count_sumw->Fill(0.5,weights.at(4)); - - for( auto pair : histograms2d ) { - for(uint i=0; i -9998){ - pair.second->Fill(value,i,weights.at(i)); - } - } - } -} - - -// ------------ method called once each job just before starting event loop ------------ -void -GenWeightsTestAnalyzer::beginJob() -{ -} - -// ------------ method called once each job just after ending the event loop ------------ -void -GenWeightsTestAnalyzer::endJob() -{ -} - -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void -GenWeightsTestAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); -} - -void -GenWeightsTestAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const& iLumi, edm::EventSetup const& es) { - //edm::Handle lheWeightsInfoHandle; - //edm::Handle lheWeightsInfoHandle; - //run.getByLabel("generator", lheWeightsInfoHandle); - edm::Handle lheWeightInfoHandle; - iLumi.getByToken(lheWeightInfoToken_, lheWeightInfoHandle); - - // Should add a search by name function - auto allScaleWeights = lheWeightInfoHandle->weightGroupIndicesByType(gen::WeightType::kScaleWeights); - if (allScaleWeights.size() > 0) - scaleWeightsIndex_ = allScaleWeights.front(); - - auto scaleWeights = static_cast( - lheWeightInfoHandle->orderedWeightGroupInfo(scaleWeightsIndex_)); - // nano ordering of mur=0.5 muf=0.5 ; [1] is mur=0.5 muf=1 ; [2] is mur=0.5 muf=2 ; [3] is mur=1 muf=0.5 ; - // [4] is mur=1 muf=1 ; [5] is mur=1 muf=2 ; [6] is mur=2 muf=0.5 ; [7] is mur=2 muf=1 ; [8] is mur=2 muf=2 * - scaleWeightsOrder_.clear(); - scaleWeightsOrder_.push_back(scaleWeights->muR05muF05Index()); - scaleWeightsOrder_.push_back(scaleWeights->muR05muF1Index()); - scaleWeightsOrder_.push_back(scaleWeights->muR05muF2Index()); - scaleWeightsOrder_.push_back(scaleWeights->muR1muF05Index()); - scaleWeightsOrder_.push_back(scaleWeights->centralIndex()); - scaleWeightsOrder_.push_back(scaleWeights->muR1muF2Index()); - scaleWeightsOrder_.push_back(scaleWeights->muR2muF05Index()); - scaleWeightsOrder_.push_back(scaleWeights->muR2muF1Index()); - scaleWeightsOrder_.push_back(scaleWeights->muR2muF2Index()); - - auto pdfGroups = lheWeightInfoHandle->weightGroupsByType(gen::WeightType::kPdfWeights); - auto ct14Set = std::find_if(pdfGroups.begin(), pdfGroups.end(), - [] (gen::WeightGroupInfo* group) { - auto pdfGroup = dynamic_cast(group); - return pdfGroup->containsLhapdfId(1300); - }); - if (ct14Set != pdfGroups.end()) - pdfWeightsIndex_ = std::distance(pdfGroups.begin(), ct14Set); -} - -//define this as a plug-in -DEFINE_FWK_MODULE(GenWeightsTestAnalyzer); - diff --git a/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py b/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py deleted file mode 100644 index 4e364b0aa2557..0000000000000 --- a/GeneratorInterface/Core/test/testGenWeights_simpleZanalyzer_cfg.py +++ /dev/null @@ -1,78 +0,0 @@ -import FWCore.ParameterSet.Config as cms -import sys -import os -import re -from FWCore.ParameterSet.VarParsing import VarParsing - -def commandline(): - options = VarParsing('analysis') - - options.register( - "fileList", - "", - VarParsing.multiplicity.singleton, - VarParsing.varType.string, - "List of files to run on." - ) - options.register( - "isMiniAOD", - False, - VarParsing.multiplicity.singleton, - VarParsing.varType.bool, - "Sample is miniAOD" - ) - options.register( - "path", - None, - VarParsing.multiplicity.singleton, - VarParsing.varType.string, - "Path for input files" - ) - - options.parseArguments() - - - print "OPTIONS: MiniAOD ---> " + ("Yes" if options.isMiniAOD else "No") - print "OPTIONS: Tag ---> {TAG}".format(TAG=options.tag) - - - if(len(options.inputFiles) and options.fileList != ""): - print "ERROR: Please provide either fileList or inputFiles but not both." - sys.exit(1) - elif(options.fileList != ""): - options.inputFiles.extend(read_list_from_file(options.fileList)) - elif(options.path): - options.inputFiles.extend(find_files(options.path,'.*\.root')) - print "Found {N} files.".format(N=len(options.inputFiles)) - - return options -# Define the CMSSW process -process = cms.Process("demo") -options = commandline() - -process.load("FWCore.MessageService.MessageLogger_cfi") -process.MessageLogger.cerr.FwkReport.reportEvery = 1000 - -process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) ) - -process.source = cms.Source("PoolSource", - fileNames = cms.untracked.vstring( options.inputFiles ) -) - -process.testLheWeights = cms.EDProducer("LHEWeightProductProducer") -process.testGenWeights = cms.EDProducer("GenWeightProductProducer") - -process.demo = cms.EDAnalyzer('GenWeightsTestAnalyzer', - tag = cms.string(options.tag), - miniaod = cms.bool(options.isMiniAOD), - genParticleSrc = cms.InputTag("prunedGenParticles" if options.isMiniAOD else "genParticles"), - genJetSrc = cms.InputTag( "slimmedGenJets" if options.isMiniAOD else "ak4GenJetsNoNu"), - genMETSrc = cms.InputTag( "slimmedMETs" if options.isMiniAOD else "genMetTrue"), - LHESrc = cms.InputTag("externalLHEProducer"), - GenSrc = cms.InputTag("generator") -) - -process.TFileService = cms.Service("TFileService", fileName = cms.string("analysis_{TAG}.root".format(TAG=options.tag)) ) - -process.p = cms.Path(process.testLheWeights*process.testGenWeights*process.demo) - From 9bd87c7b4ddfb64cb93fc814b580458197132ac9 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Sat, 18 Jan 2020 11:07:52 +0100 Subject: [PATCH 72/75] Remove dummy weights function --- .../LHEInterface/interface/TestWeightInfo.h | 1005 ----------------- 1 file changed, 1005 deletions(-) delete mode 100644 GeneratorInterface/LHEInterface/interface/TestWeightInfo.h diff --git a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h b/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h deleted file mode 100644 index b0c52f6671077..0000000000000 --- a/GeneratorInterface/LHEInterface/interface/TestWeightInfo.h +++ /dev/null @@ -1,1005 +0,0 @@ -#include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" -#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" -#include - -std::string parseId(std::string label) { - auto re = std::regex("id=\"([0-9]*)\""); - std::smatch matches; - std::regex_search(label, matches, re); - return std::string(matches.str(1)); -} - -gen::WeightGroupInfo getExampleScaleWeights() { - gen::WeightGroupInfo scaleInfo = gen::WeightGroupInfo( - "", - "centralScaleVariations" - ); - std::vector entries = { - R"( mur=1 muf=1 )", - R"( mur=1 muf=2 )", - R"( mur=1 muf=0.5 )", - R"( mur=2 muf=1 )", - R"( mur=2 muf=2 )", - R"( mur=2 muf=0.5 )", - R"( mur=0.5 muf=1 )", - R"( mur=0.5 muf=2 )", - R"( mur=0.5 muf=0.5 )", - }; - scaleInfo.setWeightType(gen::WeightType::kScaleWeights); - - for (size_t i = 0; i < entries.size(); i++) { - scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); - } - return scaleInfo; -} - -gen::WeightGroupInfo getExampleScaleWeightsOutOfOrder() { - gen::WeightGroupInfo scaleInfo = gen::WeightGroupInfo( - "", - "centralScaleVariations" - ); - std::vector entries = { - R"( mur=1 muf=1 )", - R"( mur=1 muf=2 )", - R"( mur=1 muf=0.5 )", - R"( mur=2 muf=2 )", - R"( mur=2 muf=1 )", - R"( mur=2 muf=0.5 )", - R"( mur=0.5 muf=2 )", - R"( mur=0.5 muf=1 )", - R"( mur=0.5 muf=0.5 )", - }; - scaleInfo.setWeightType(gen::WeightType::kScaleWeights); - - for (size_t i = 0; i < entries.size(); i++) { - scaleInfo.addContainedId(i, parseId(entries[i]), entries[i]); - } - return scaleInfo; -} - -edm::OwnVector getExamplePdfWeights() { - std::vector entries = { - R"()", - R"( Member 0 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 1 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 2 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 3 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 4 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 5 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 6 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 7 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 8 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 9 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 10 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 11 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 12 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 13 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 14 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 15 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 16 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 17 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 18 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 19 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 20 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 21 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 22 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 23 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 24 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 25 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 26 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 27 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 28 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 29 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 30 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 31 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 32 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 33 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 34 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 35 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 36 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 37 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 38 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 39 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 40 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 41 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 42 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 43 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 44 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 45 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 46 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 47 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 48 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 49 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 50 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 51 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 52 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 53 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 54 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 55 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 56 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 57 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 58 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 59 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 60 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 61 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 62 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 63 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 64 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 65 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 66 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 67 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 68 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 69 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 70 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 71 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 72 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 73 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 74 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 75 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 76 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 77 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 78 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 79 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 80 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 81 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 82 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 83 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 84 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 85 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 86 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 87 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 88 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 89 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 90 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 91 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 92 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 93 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 94 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 95 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 96 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 97 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 98 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 99 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 100 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 101 of sets NNPDF31_nnlo_hessian_pdfas)", - R"( Member 102 of sets NNPDF31_nnlo_hessian_pdfas)", - R"()", - R"()", - R"( Member 0 of sets CT10nlo_nf4)", - R"()", - R"()", - R"( Member 0 of sets CT14nnlo_NF4)", - R"()", - R"()", - R"( Member 0 of sets CT14nlo_NF4)", - R"()", - R"()", - R"( Member 0 of sets CT14lo_NF4)", - R"()", - R"()", - R"( Member 0 of sets MSTW2008lo68cl_nf4)", - R"( Member 1 of sets MSTW2008lo68cl_nf4)", - R"( Member 2 of sets MSTW2008lo68cl_nf4)", - R"( Member 3 of sets MSTW2008lo68cl_nf4)", - R"( Member 4 of sets MSTW2008lo68cl_nf4)", - R"( Member 5 of sets MSTW2008lo68cl_nf4)", - R"( Member 6 of sets MSTW2008lo68cl_nf4)", - R"( Member 7 of sets MSTW2008lo68cl_nf4)", - R"( Member 8 of sets MSTW2008lo68cl_nf4)", - R"( Member 9 of sets MSTW2008lo68cl_nf4)", - R"( Member 10 of sets MSTW2008lo68cl_nf4)", - R"( Member 11 of sets MSTW2008lo68cl_nf4)", - R"( Member 12 of sets MSTW2008lo68cl_nf4)", - R"( Member 13 of sets MSTW2008lo68cl_nf4)", - R"( Member 14 of sets MSTW2008lo68cl_nf4)", - R"( Member 15 of sets MSTW2008lo68cl_nf4)", - R"( Member 16 of sets MSTW2008lo68cl_nf4)", - R"( Member 17 of sets MSTW2008lo68cl_nf4)", - R"( Member 18 of sets MSTW2008lo68cl_nf4)", - R"( Member 19 of sets MSTW2008lo68cl_nf4)", - R"( Member 20 of sets MSTW2008lo68cl_nf4)", - R"( Member 21 of sets MSTW2008lo68cl_nf4)", - R"( Member 22 of sets MSTW2008lo68cl_nf4)", - R"( Member 23 of sets MSTW2008lo68cl_nf4)", - R"( Member 24 of sets MSTW2008lo68cl_nf4)", - R"( Member 25 of sets MSTW2008lo68cl_nf4)", - R"( Member 26 of sets MSTW2008lo68cl_nf4)", - R"( Member 27 of sets MSTW2008lo68cl_nf4)", - R"( Member 28 of sets MSTW2008lo68cl_nf4)", - R"( Member 29 of sets MSTW2008lo68cl_nf4)", - R"( Member 30 of sets MSTW2008lo68cl_nf4)", - R"( Member 31 of sets MSTW2008lo68cl_nf4)", - R"( Member 32 of sets MSTW2008lo68cl_nf4)", - R"( Member 33 of sets MSTW2008lo68cl_nf4)", - R"( Member 34 of sets MSTW2008lo68cl_nf4)", - R"( Member 35 of sets MSTW2008lo68cl_nf4)", - R"( Member 36 of sets MSTW2008lo68cl_nf4)", - R"( Member 37 of sets MSTW2008lo68cl_nf4)", - R"( Member 38 of sets MSTW2008lo68cl_nf4)", - R"( Member 39 of sets MSTW2008lo68cl_nf4)", - R"( Member 40 of sets MSTW2008lo68cl_nf4)", - R"()", - R"()", - R"( Member 0 of sets MSTW2008nlo68cl_nf4)", - R"( Member 1 of sets MSTW2008nlo68cl_nf4)", - R"( Member 2 of sets MSTW2008nlo68cl_nf4)", - R"( Member 3 of sets MSTW2008nlo68cl_nf4)", - R"( Member 4 of sets MSTW2008nlo68cl_nf4)", - R"( Member 5 of sets MSTW2008nlo68cl_nf4)", - R"( Member 6 of sets MSTW2008nlo68cl_nf4)", - R"( Member 7 of sets MSTW2008nlo68cl_nf4)", - R"( Member 8 of sets MSTW2008nlo68cl_nf4)", - R"( Member 9 of sets MSTW2008nlo68cl_nf4)", - R"( Member 10 of sets MSTW2008nlo68cl_nf4)", - R"( Member 11 of sets MSTW2008nlo68cl_nf4)", - R"( Member 12 of sets MSTW2008nlo68cl_nf4)", - R"( Member 13 of sets MSTW2008nlo68cl_nf4)", - R"( Member 14 of sets MSTW2008nlo68cl_nf4)", - R"( Member 15 of sets MSTW2008nlo68cl_nf4)", - R"( Member 16 of sets MSTW2008nlo68cl_nf4)", - R"( Member 17 of sets MSTW2008nlo68cl_nf4)", - R"( Member 18 of sets MSTW2008nlo68cl_nf4)", - R"( Member 19 of sets MSTW2008nlo68cl_nf4)", - R"( Member 20 of sets MSTW2008nlo68cl_nf4)", - R"( Member 21 of sets MSTW2008nlo68cl_nf4)", - R"( Member 22 of sets MSTW2008nlo68cl_nf4)", - R"( Member 23 of sets MSTW2008nlo68cl_nf4)", - R"( Member 24 of sets MSTW2008nlo68cl_nf4)", - R"( Member 25 of sets MSTW2008nlo68cl_nf4)", - R"( Member 26 of sets MSTW2008nlo68cl_nf4)", - R"( Member 27 of sets MSTW2008nlo68cl_nf4)", - R"( Member 28 of sets MSTW2008nlo68cl_nf4)", - R"( Member 29 of sets MSTW2008nlo68cl_nf4)", - R"( Member 30 of sets MSTW2008nlo68cl_nf4)", - R"( Member 31 of sets MSTW2008nlo68cl_nf4)", - R"( Member 32 of sets MSTW2008nlo68cl_nf4)", - R"( Member 33 of sets MSTW2008nlo68cl_nf4)", - R"( Member 34 of sets MSTW2008nlo68cl_nf4)", - R"( Member 35 of sets MSTW2008nlo68cl_nf4)", - R"( Member 36 of sets MSTW2008nlo68cl_nf4)", - R"( Member 37 of sets MSTW2008nlo68cl_nf4)", - R"( Member 38 of sets MSTW2008nlo68cl_nf4)", - R"( Member 39 of sets MSTW2008nlo68cl_nf4)", - R"( Member 40 of sets MSTW2008nlo68cl_nf4)", - R"()", - R"()", - R"( Member 0 of sets MSTW2008nlo_mbrange_nf4)", - R"( Member 1 of sets MSTW2008nlo_mbrange_nf4)", - R"( Member 2 of sets MSTW2008nlo_mbrange_nf4)", - R"( Member 3 of sets MSTW2008nlo_mbrange_nf4)", - R"( Member 4 of sets MSTW2008nlo_mbrange_nf4)", - R"( Member 5 of sets MSTW2008nlo_mbrange_nf4)", - R"( Member 6 of sets MSTW2008nlo_mbrange_nf4)", - R"()", - R"()", - R"( Member 0 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 1 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 2 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 3 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 4 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 5 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 6 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 7 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 8 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 9 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 10 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 11 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 12 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 13 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 14 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 15 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 16 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 17 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 18 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 19 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 20 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 21 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 22 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 23 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 24 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 25 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 26 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 27 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 28 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 29 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 30 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 31 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 32 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 33 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 34 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 35 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 36 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 37 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 38 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 39 of sets MSTW2008nnlo68cl_nf4)", - R"( Member 40 of sets MSTW2008nnlo68cl_nf4)", - R"()", - R"()", - R"( Member 0 of sets MSTW2008nnlo_mbrange_nf4)", - R"( Member 1 of sets MSTW2008nnlo_mbrange_nf4)", - R"( Member 2 of sets MSTW2008nnlo_mbrange_nf4)", - R"( Member 3 of sets MSTW2008nnlo_mbrange_nf4)", - R"( Member 4 of sets MSTW2008nnlo_mbrange_nf4)", - R"( Member 5 of sets MSTW2008nnlo_mbrange_nf4)", - R"( Member 6 of sets MSTW2008nnlo_mbrange_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nlo68cl_nf4)", - R"( Member 1 of sets MMHT2014nlo68cl_nf4)", - R"( Member 2 of sets MMHT2014nlo68cl_nf4)", - R"( Member 3 of sets MMHT2014nlo68cl_nf4)", - R"( Member 4 of sets MMHT2014nlo68cl_nf4)", - R"( Member 5 of sets MMHT2014nlo68cl_nf4)", - R"( Member 6 of sets MMHT2014nlo68cl_nf4)", - R"( Member 7 of sets MMHT2014nlo68cl_nf4)", - R"( Member 8 of sets MMHT2014nlo68cl_nf4)", - R"( Member 9 of sets MMHT2014nlo68cl_nf4)", - R"( Member 10 of sets MMHT2014nlo68cl_nf4)", - R"( Member 11 of sets MMHT2014nlo68cl_nf4)", - R"( Member 12 of sets MMHT2014nlo68cl_nf4)", - R"( Member 13 of sets MMHT2014nlo68cl_nf4)", - R"( Member 14 of sets MMHT2014nlo68cl_nf4)", - R"( Member 15 of sets MMHT2014nlo68cl_nf4)", - R"( Member 16 of sets MMHT2014nlo68cl_nf4)", - R"( Member 17 of sets MMHT2014nlo68cl_nf4)", - R"( Member 18 of sets MMHT2014nlo68cl_nf4)", - R"( Member 19 of sets MMHT2014nlo68cl_nf4)", - R"( Member 20 of sets MMHT2014nlo68cl_nf4)", - R"( Member 21 of sets MMHT2014nlo68cl_nf4)", - R"( Member 22 of sets MMHT2014nlo68cl_nf4)", - R"( Member 23 of sets MMHT2014nlo68cl_nf4)", - R"( Member 24 of sets MMHT2014nlo68cl_nf4)", - R"( Member 25 of sets MMHT2014nlo68cl_nf4)", - R"( Member 26 of sets MMHT2014nlo68cl_nf4)", - R"( Member 27 of sets MMHT2014nlo68cl_nf4)", - R"( Member 28 of sets MMHT2014nlo68cl_nf4)", - R"( Member 29 of sets MMHT2014nlo68cl_nf4)", - R"( Member 30 of sets MMHT2014nlo68cl_nf4)", - R"( Member 31 of sets MMHT2014nlo68cl_nf4)", - R"( Member 32 of sets MMHT2014nlo68cl_nf4)", - R"( Member 33 of sets MMHT2014nlo68cl_nf4)", - R"( Member 34 of sets MMHT2014nlo68cl_nf4)", - R"( Member 35 of sets MMHT2014nlo68cl_nf4)", - R"( Member 36 of sets MMHT2014nlo68cl_nf4)", - R"( Member 37 of sets MMHT2014nlo68cl_nf4)", - R"( Member 38 of sets MMHT2014nlo68cl_nf4)", - R"( Member 39 of sets MMHT2014nlo68cl_nf4)", - R"( Member 40 of sets MMHT2014nlo68cl_nf4)", - R"( Member 41 of sets MMHT2014nlo68cl_nf4)", - R"( Member 42 of sets MMHT2014nlo68cl_nf4)", - R"( Member 43 of sets MMHT2014nlo68cl_nf4)", - R"( Member 44 of sets MMHT2014nlo68cl_nf4)", - R"( Member 45 of sets MMHT2014nlo68cl_nf4)", - R"( Member 46 of sets MMHT2014nlo68cl_nf4)", - R"( Member 47 of sets MMHT2014nlo68cl_nf4)", - R"( Member 48 of sets MMHT2014nlo68cl_nf4)", - R"( Member 49 of sets MMHT2014nlo68cl_nf4)", - R"( Member 50 of sets MMHT2014nlo68cl_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 1 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 2 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 3 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 4 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 5 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 6 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 7 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 8 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 9 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 10 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 11 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 12 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 13 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 14 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 15 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 16 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 17 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 18 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 19 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 20 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 21 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 22 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 23 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 24 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 25 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 26 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 27 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 28 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 29 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 30 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 31 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 32 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 33 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 34 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 35 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 36 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 37 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 38 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 39 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 40 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 41 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 42 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 43 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 44 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 45 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 46 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 47 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 48 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 49 of sets MMHT2014nlo68clas118_nf4)", - R"( Member 50 of sets MMHT2014nlo68clas118_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nlo_asmzsmallrange_nf4)", - R"( Member 1 of sets MMHT2014nlo_asmzsmallrange_nf4)", - R"( Member 2 of sets MMHT2014nlo_asmzsmallrange_nf4)", - R"( Member 3 of sets MMHT2014nlo_asmzsmallrange_nf4)", - R"( Member 4 of sets MMHT2014nlo_asmzsmallrange_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nlo_mcrange_nf4)", - R"( Member 1 of sets MMHT2014nlo_mcrange_nf4)", - R"( Member 2 of sets MMHT2014nlo_mcrange_nf4)", - R"( Member 3 of sets MMHT2014nlo_mcrange_nf4)", - R"( Member 4 of sets MMHT2014nlo_mcrange_nf4)", - R"( Member 5 of sets MMHT2014nlo_mcrange_nf4)", - R"( Member 6 of sets MMHT2014nlo_mcrange_nf4)", - R"( Member 7 of sets MMHT2014nlo_mcrange_nf4)", - R"( Member 8 of sets MMHT2014nlo_mcrange_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nlo_mbrange_nf4)", - R"( Member 1 of sets MMHT2014nlo_mbrange_nf4)", - R"( Member 2 of sets MMHT2014nlo_mbrange_nf4)", - R"( Member 3 of sets MMHT2014nlo_mbrange_nf4)", - R"( Member 4 of sets MMHT2014nlo_mbrange_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 1 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 2 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 3 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 4 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 5 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 6 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 7 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 8 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 9 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 10 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 11 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 12 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 13 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 14 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 15 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 16 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 17 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 18 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 19 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 20 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 21 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 22 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 23 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 24 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 25 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 26 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 27 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 28 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 29 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 30 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 31 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 32 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 33 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 34 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 35 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 36 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 37 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 38 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 39 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 40 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 41 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 42 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 43 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 44 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 45 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 46 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 47 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 48 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 49 of sets MMHT2014nnlo68cl_nf4)", - R"( Member 50 of sets MMHT2014nnlo68cl_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nnlo_asmzsmallrange_nf4)", - R"( Member 1 of sets MMHT2014nnlo_asmzsmallrange_nf4)", - R"( Member 2 of sets MMHT2014nnlo_asmzsmallrange_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nnlo_mcrange_nf4)", - R"( Member 1 of sets MMHT2014nnlo_mcrange_nf4)", - R"( Member 2 of sets MMHT2014nnlo_mcrange_nf4)", - R"( Member 3 of sets MMHT2014nnlo_mcrange_nf4)", - R"( Member 4 of sets MMHT2014nnlo_mcrange_nf4)", - R"( Member 5 of sets MMHT2014nnlo_mcrange_nf4)", - R"( Member 6 of sets MMHT2014nnlo_mcrange_nf4)", - R"( Member 7 of sets MMHT2014nnlo_mcrange_nf4)", - R"( Member 8 of sets MMHT2014nnlo_mcrange_nf4)", - R"()", - R"()", - R"( Member 0 of sets MMHT2014nnlo_mbrange_nf4)", - R"( Member 1 of sets MMHT2014nnlo_mbrange_nf4)", - R"( Member 2 of sets MMHT2014nnlo_mbrange_nf4)", - R"( Member 3 of sets MMHT2014nnlo_mbrange_nf4)", - R"( Member 4 of sets MMHT2014nnlo_mbrange_nf4)", - R"()", - R"()", - R"( Member 0 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 1 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 2 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 3 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 4 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 5 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 6 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 7 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 8 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 9 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 10 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 11 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 12 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 13 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 14 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 15 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 16 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 17 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 18 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 19 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 20 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 21 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 22 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 23 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 24 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 25 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 26 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 27 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 28 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 29 of sets PDF4LHC15_nlo_nf4_30)", - R"( Member 30 of sets PDF4LHC15_nlo_nf4_30)", - R"()", - R"()", - R"( Member 0 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 1 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 2 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 3 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 4 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 5 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 6 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 7 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 8 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 9 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 10 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 11 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 12 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 13 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 14 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 15 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 16 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 17 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 18 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 19 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 20 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 21 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 22 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 23 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 24 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 25 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 26 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 27 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 28 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 29 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 30 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 31 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 32 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 33 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 34 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 35 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 36 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 37 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 38 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 39 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 40 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 41 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 42 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 43 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 44 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 45 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 46 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 47 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 48 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 49 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 50 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 51 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 52 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 53 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 54 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 55 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 56 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 57 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 58 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 59 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 60 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 61 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 62 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 63 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 64 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 65 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 66 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 67 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 68 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 69 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 70 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 71 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 72 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 73 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 74 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 75 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 76 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 77 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 78 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 79 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 80 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 81 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 82 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 83 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 84 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 85 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 86 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 87 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 88 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 89 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 90 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 91 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 92 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 93 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 94 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 95 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 96 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 97 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 98 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 99 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"( Member 100 of sets NNPDF31_nnlo_as_0118_nf_4)", - R"()", - R"()", - R"( Member 0 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 1 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 2 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 3 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 4 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 5 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 6 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 7 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 8 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 9 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 10 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 11 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 12 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 13 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 14 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 15 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 16 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 17 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 18 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 19 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 20 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 21 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 22 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 23 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 24 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 25 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 26 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 27 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 28 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 29 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 30 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 31 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 32 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 33 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 34 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 35 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 36 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 37 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 38 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 39 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 40 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 41 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 42 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 43 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 44 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 45 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 46 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 47 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 48 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 49 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 50 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 51 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 52 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 53 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 54 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 55 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 56 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 57 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 58 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 59 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 60 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 61 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 62 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 63 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 64 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 65 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 66 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 67 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 68 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 69 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 70 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 71 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 72 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 73 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 74 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 75 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 76 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 77 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 78 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 79 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 80 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 81 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 82 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 83 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 84 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 85 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 86 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 87 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 88 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 89 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 90 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 91 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 92 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 93 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 94 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 95 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 96 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 97 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 98 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 99 of sets NNPDF31_nlo_as_0118_nf_4)", - R"( Member 100 of sets NNPDF31_nlo_as_0118_nf_4)", - R"()", - R"()", - R"( Member 0 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 1 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 2 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 3 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 4 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 5 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 6 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 7 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 8 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 9 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 10 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 11 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 12 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 13 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 14 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 15 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 16 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 17 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 18 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 19 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 20 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 21 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 22 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 23 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 24 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 25 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 26 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 27 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 28 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 29 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 30 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 31 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 32 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 33 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 34 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 35 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 36 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 37 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 38 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 39 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 40 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 41 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 42 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 43 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 44 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 45 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 46 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 47 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 48 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 49 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 50 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 51 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 52 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 53 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 54 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 55 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 56 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 57 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 58 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 59 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 60 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 61 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 62 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 63 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 64 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 65 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 66 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 67 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 68 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 69 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 70 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 71 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 72 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 73 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 74 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 75 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 76 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 77 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 78 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 79 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 80 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 81 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 82 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 83 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 84 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 85 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 86 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 87 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 88 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 89 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 90 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 91 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 92 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 93 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 94 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 95 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 96 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 97 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 98 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 99 of sets NNPDF30_nlo_as_0118_nf_4)", - R"( Member 100 of sets NNPDF30_nlo_as_0118_nf_4)", - R"()", - R"()", - R"( Member 0 of sets NNPDF30_lo_as_0118_nf_4)", - R"()", - R"()", - R"( Member 0 of sets NNPDF30_lo_as_0130_nf_4)", - R"()", - R"()", - R"( Member 0 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 1 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 2 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 3 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 4 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 5 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 6 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 7 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 8 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 9 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 10 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 11 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 12 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 13 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 14 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 15 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 16 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 17 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 18 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 19 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 20 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 21 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 22 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 23 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 24 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 25 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 26 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 27 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 28 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 29 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 30 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 31 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 32 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 33 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 34 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 35 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 36 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 37 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 38 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 39 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 40 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 41 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 42 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 43 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 44 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 45 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 46 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 47 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 48 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 49 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 50 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 51 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 52 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 53 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 54 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 55 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 56 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 57 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 58 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 59 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 60 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 61 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 62 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 63 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 64 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 65 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 66 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 67 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 68 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 69 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 70 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 71 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 72 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 73 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 74 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 75 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 76 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 77 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 78 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 79 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 80 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 81 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 82 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 83 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 84 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 85 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 86 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 87 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 88 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 89 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 90 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 91 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 92 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 93 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 94 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 95 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 96 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 97 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 98 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 99 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 100 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 101 of sets NNPDF30_nlo_nf_4_pdfas)", - R"( Member 102 of sets NNPDF30_nlo_nf_4_pdfas)", - R"()", - R"()", - R"( Member 0 of sets NNPDF30_nnlo_nf_4_pdfas)", - R"()", - }; - - edm::OwnVector pdfWeights; - - //Don't forget about the scale weights - int counter = 8; - for (const auto& entry : entries) { - if (entry.find(" Date: Sun, 19 Jan 2020 04:50:16 +0100 Subject: [PATCH 73/75] Significant restructure of parsing --- .../Core/interface/LHEWeightHelper.h | 22 +- .../Core/interface/WeightHelper.h | 32 ++- .../Core/plugins/GenWeightProductProducer.cc | 13 +- .../Core/plugins/LHEWeightProductProducer.cc | 6 +- .../Core/src/GenWeightHelper.cc | 4 +- .../Core/src/LHEWeightHelper.cc | 228 +++++------------- GeneratorInterface/Core/src/WeightHelper.cc | 105 +++++--- .../Core/test/dumpWeightInfo.py | 7 +- .../Core/test/testGenWeightProducer_cfg.py | 18 +- .../plugins/ExternalLHEProducer.cc | 6 +- PhysicsTools/NanoAOD/python/nanogen_cff.py | 3 +- .../interface/PdfWeightGroupInfo.h | 11 +- .../interface/ScaleWeightGroupInfo.h | 3 +- .../src/ScaleWeightGroupInfo.cc | 12 +- .../GeneratorProducts/src/WeightGroupInfo.cc | 16 +- 15 files changed, 231 insertions(+), 255 deletions(-) diff --git a/GeneratorInterface/Core/interface/LHEWeightHelper.h b/GeneratorInterface/Core/interface/LHEWeightHelper.h index 6b37f56403ce4..12f973ca45fcc 100644 --- a/GeneratorInterface/Core/interface/LHEWeightHelper.h +++ b/GeneratorInterface/Core/interface/LHEWeightHelper.h @@ -19,23 +19,13 @@ namespace gen { class LHEWeightHelper : public WeightHelper { public: - LHEWeightHelper(); - - //// possibly add more versions of this functions for different inputs - void parseLHEFile(std::string filename); - void parseWeightGroupsFromHeader(std::vector lheHeader); + LHEWeightHelper() : WeightHelper() {}; + void setHeaderLines(std::vector headerLines); + void parseWeights(); + void buildGroups(); + std::unique_ptr buildGroup(const ParsedWeight& weight); private: - std::map weightAttributeMapFromHeaderLine(std::string line); - void loadAttributeNames(std::string baseName, std::vector altNames ={}); - std::map getAttributeMap(std::string); - std::string sanitizeText(std::string); - bool isAWeight(std::string); - - std::regex weightGroupStart_; - std::regex weightGroupEnd_; - std::regex weightContent_; - - std::map nameConversionMap_; + std::vector headerLines_; }; } diff --git a/GeneratorInterface/Core/interface/WeightHelper.h b/GeneratorInterface/Core/interface/WeightHelper.h index 5e3102aa60ea4..66cfbfd547155 100644 --- a/GeneratorInterface/Core/interface/WeightHelper.h +++ b/GeneratorInterface/Core/interface/WeightHelper.h @@ -6,6 +6,10 @@ #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" #include "SimDataFormats/GeneratorProducts/interface/WeightsInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/UnknownWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h" +#include "SimDataFormats/GeneratorProducts/interface/MEParamWeightGroupInfo.h" #include namespace gen { @@ -15,6 +19,14 @@ namespace gen { PdfUncertaintyType uncertaintyType; }; + struct ParsedWeight { + std::string id; + size_t index; + std::string groupname; + std::string content; + std::unordered_map attributes; + }; + class WeightHelper { public: WeightHelper(); @@ -23,17 +35,29 @@ namespace gen { } std::unique_ptr weightProduct(std::vector, float w0); std::unique_ptr weightProduct(std::vector, float w0); - void setGroupInfo(); - bool currentGroupIsScale(); - bool currentGroupIsMEParam(); - bool currentGroupIsPdf(); + void setModel(std::string model) { model_ = model; } int addWeightToProduct(std::unique_ptr& 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 parsedWeights_; const std::vector pdfSetsInfo; std::map currWeightAttributeMap_; std::map currGroupAttributeMap_; edm::OwnVector 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); + std::string searchAttributes(const std::string& label, const ParsedWeight& weight); + + // Possible names for the same thing + const std::unordered_map> attributeNames_ = { + {"muf", {"muR", "MUR", "muf","facscfact"}}, + {"mur", {"muF", "MUF", "mur","renscfact"}}, + {"pdf", {"PDF", "PDF set", "lhapdf", "pdf", "pdf set", "pdfset"}} + }; }; } diff --git a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc index 104083173e6be..e8d18a93e5878 100644 --- a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc @@ -23,6 +23,7 @@ #include "GeneratorInterface/Core/interface/GenWeightHelper.h" #include "FWCore/ServiceRegistry/interface/Service.h" +#include class GenWeightProductProducer : public edm::one::EDProducer { public: @@ -34,6 +35,7 @@ class GenWeightProductProducer : public edm::one::EDProducer genLumiInfoToken_; edm::EDGetTokenT genEventToken_; + const edm::EDGetTokenT genLumiInfoHeadTag_; void produce(edm::Event&, const edm::EventSetup&) override; void beginLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const& c) override; @@ -44,7 +46,8 @@ class GenWeightProductProducer : public edm::one::EDProducer(iConfig.getParameter("genInfo"))), - genEventToken_(consumes(iConfig.getParameter("genInfo"))) + genEventToken_(consumes(iConfig.getParameter("genInfo"))), + genLumiInfoHeadTag_(mayConsume(iConfig.getParameter("genLumiInfoHeader"))) { produces(); produces(); @@ -69,6 +72,14 @@ GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe void GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) { + edm::Handle 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 genLumiInfoHandle; iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle); diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index db74a3b25730b..f259540d79b59 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -46,9 +46,7 @@ class LHEWeightProductProducer : public edm::one::EDProducer("lheSourceLabel")), lheRunInfoToken_(consumes(lheLabel_)), @@ -90,7 +88,7 @@ LHEWeightProductProducer::beginRun(edm::Run const& run, edm::EventSetup const& e headerWeightInfo = *iter; } - weightHelper_.parseWeightGroupsFromHeader(headerWeightInfo.lines()); + //weightHelper_.parseWeightGroupsFromHeader(headerWeightInfo.lines()); } void diff --git a/GeneratorInterface/Core/src/GenWeightHelper.cc b/GeneratorInterface/Core/src/GenWeightHelper.cc index 182040728a752..74bad0d66781a 100644 --- a/GeneratorInterface/Core/src/GenWeightHelper.cc +++ b/GeneratorInterface/Core/src/GenWeightHelper.cc @@ -17,7 +17,9 @@ namespace gen { for (std::string weightName : weightNames) { if(weightName.find("LHE") != std::string::npos) { // Parse as usual, this is the SUSY workflow - continue; + // std::vector info; + // boost::split(info, weightName, boost::is_any_of(",")); + weightGroups_.push_back(new gen::UnknownWeightGroupInfo("inGen")); } // Working on the not-so-nice assumption that all non-LHE gen weights are PS weights else if (weightGroups_.size() == 0) { diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index 1b3a7f4ee1039..7a882e07ea84e 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -1,192 +1,78 @@ #include "GeneratorInterface/Core/interface/LHEWeightHelper.h" +#include #include using namespace tinyxml2; namespace gen { - void LHEWeightHelper::loadAttributeNames(std::string baseName, std::vector altNames) { - for(auto altname : altNames) { - nameConversionMap_[altname] = baseName; - } - nameConversionMap_[baseName] = baseName; + void LHEWeightHelper::setHeaderLines(std::vector headerLines) { + headerLines_ = headerLines; } - std::string - LHEWeightHelper::sanitizeText(std::string line) { - std::map replaceMap = {{"<", "<"}, {">", ">"}}; + void LHEWeightHelper::parseWeights() { + tinyxml2::XMLDocument xmlDoc; + xmlDoc.Parse(("" + boost::algorithm::join(headerLines_, "") + "").c_str()); + tinyxml2::XMLElement* root = xmlDoc.FirstChildElement("root"); - for(auto pair: replaceMap) { - std::string badText = pair.first; - std::string goodText = pair.second; - while(line.find(badText) != std::string::npos) { - size_t spot = line.find(badText); - line.replace(spot, badText.size(), goodText); + size_t weightIndex = 0; + for (auto* e = root->FirstChildElement(); e != nullptr; e = e->NextSiblingElement()) { + std::string groupName = ""; + if (strcmp(e->Name(), "weight") == 0) { + // we are here if there is a weight that does not belong to any group + std::string text = ""; + if (e->GetText()) + text = e->GetText(); + parsedWeights_.push_back({e->Attribute("id"), weightIndex++, groupName, text}); } + if (strcmp(e->Name(), "weightgroup") == 0) { + groupName = e->Attribute("name"); + for (auto* inner = e->FirstChildElement("weight"); inner != nullptr; + inner = inner->NextSiblingElement("weight")) { + // we are here if there is a weight in a weightgroup + std::string text = ""; + if (inner->GetText()) + text = inner->GetText(); + std::unordered_map attributes; + for (auto* att = inner->FirstAttribute(); att != nullptr; att = att->Next()) + attributes[att->Name()] = att->Value(); + parsedWeights_.push_back({inner->Attribute("id"), weightIndex++, groupName, text, attributes}); + } } - return line; - } - - - LHEWeightHelper::LHEWeightHelper() { - weightGroupStart_ = std::regex(".*.*\n*"); - weightGroupEnd_ = std::regex(".*.*\n*"); - - /// Might change later, order matters and code doesn't pick choices - - // Used for translating different naming convention to a common one - loadAttributeNames("muf", {"facscfact"}); - loadAttributeNames("mur", {"renscfact"}); - loadAttributeNames("id"); - loadAttributeNames("pdf", {"pdf set", "lhapdf", "pdfset"}); - loadAttributeNames("dyn_scale"); - - loadAttributeNames("combine"); - loadAttributeNames("name", {"type"}); - + } + buildGroups(); } - std::map - LHEWeightHelper::getAttributeMap(std::string line) { - XMLDocument xmlParser; - int error = xmlParser.Parse(line.c_str()); - if (error) { - return std::map(); - } + //void LHEWeightHelper::setGroupPriority() { + // groupCheckOrder_ = {gen::WeightType::kScaleWeights, gen::WeightType::kPdfWeights, + // gen::WeightType::kMEParamWeights + // }; + //} - std::map attributeMap; - XMLElement* element = xmlParser.FirstChildElement(); - - for( const XMLAttribute* a = element->FirstAttribute(); a; a=a->Next()) { - auto name = boost::algorithm::to_lower_copy(std::string(a->Name())); - attributeMap[nameConversionMap_[name]] = a->Value(); - } - // get stuff from content of tag if it has anything. - // always assume format is AAAAA=( )BBBB ( ) => optional space - if (element->GetText() == nullptr) { - return attributeMap; - } - // This adds "content: " to the beginning of the content. not sure if its a big deal or? - std::string content = element->GetText(); - attributeMap["content"] = content; - - for (const auto& entry : weightAttributeMapFromHeaderLine(content)) { - auto rawLabel = boost::algorithm::to_lower_copy(entry.first); - std::string label = nameConversionMap_[rawLabel]; - if (nameConversionMap_.find(label) != nameConversionMap_.end()) - attributeMap[nameConversionMap_[label]] = entry.second; - else - attributeMap[label] = entry.second; - } - - return attributeMap; - - } + void LHEWeightHelper::buildGroups() { + std::string currentGroupName; + for (const auto& weight : parsedWeights_) { + if (weight.groupname != currentGroupName) { + weightGroups_.push_back(*buildGroup(weight)); + } + currentGroupName = weight.groupname; + WeightGroupInfo& group = weightGroups_.back(); + group.addContainedId(weight.index, weight.id, weight.content); - bool - LHEWeightHelper::isAWeight(std::string line) { - XMLDocument xmlParser; - int error = xmlParser.Parse(line.c_str()); - if (error) { - return false; - //throw std::invalid_argument("Failed to parse weight info from header! Line was " + line); + if (group.weightType() == gen::WeightType::kScaleWeights) + updateScaleInfo(weight); + else if (group.weightType() == gen::WeightType::kPdfWeights) + updatePdfInfo(weight); } - XMLElement* element = xmlParser.FirstChildElement(); - return element; } - std::map - LHEWeightHelper::weightAttributeMapFromHeaderLine(std::string line) { - std::regex reg("(?:(\\S+)=\\s*(\\S+))"); - std::smatch match; - std::map weightAttributeMap; - while(std::regex_search(line, match, reg)) { - weightAttributeMap[match.str(1)] = match.str(2); - line = match.suffix().str(); - } - return weightAttributeMap; - } + std::unique_ptr LHEWeightHelper::buildGroup(const ParsedWeight& weight) { + if (isScaleWeightGroup(weight)) + return std::make_unique(weight.groupname); + else if (isPdfWeightGroup(weight)) + return std::make_unique(weight.groupname); + else if (isMEParamWeightGroup(weight)) + return std::make_unique(weight.groupname); - void - LHEWeightHelper::parseWeightGroupsFromHeader(std::vector lheHeader) { - // TODO: Not sure the weight indexing is right here, this seems to more or less - // count the lines which isn't quite the goal. TOCHECK! - int index = 0; - currGroupAttributeMap_.clear(); - currWeightAttributeMap_.clear(); - - for (std::string headerLine : lheHeader) { - headerLine = sanitizeText(headerLine); - - if (std::regex_match(headerLine, weightGroupStart_)) { - if (!currGroupAttributeMap_.empty()) - setGroupInfo(); - std::string fullTag = headerLine + ""; - currGroupAttributeMap_ = getAttributeMap(fullTag); - auto name = currGroupAttributeMap_["name"]; - - if (currentGroupIsScale()) { - weightGroups_.push_back(std::make_unique(name)); - } - else if (currentGroupIsPdf()) { - weightGroups_.push_back(std::make_unique(name)); - } - else if (currentGroupIsMEParam()) { - weightGroups_.push_back(std::make_unique(name)); - } - else { - weightGroups_.push_back(std::make_unique(name)); - } - auto& group = weightGroups_.back(); - group.setDescription("Test description"); - } - else if (std::regex_match(headerLine, std::regex(".*.*\n*"))) { - std::string fullTag = headerLine; - if (!std::regex_match(headerLine, std::regex(".*.*\n*"))) - fullTag = headerLine + ""; - currWeightAttributeMap_.clear(); - // This shouldn't really happen, but perhaps we find weights outside of weight groups? - currWeightAttributeMap_ = getAttributeMap(fullTag); - - std::string content = currWeightAttributeMap_["content"]; - if (currWeightAttributeMap_["id"].empty()) { - std::cout << "error" << "\n"; - // should do something - } - - if (weightGroups_.empty()) { - weightGroups_.push_back(std::make_unique("Unknown")); - } - auto& group = weightGroups_.back(); - if (group.weightType() == gen::WeightType::kScaleWeights) { - if (currWeightAttributeMap_["mur"].empty() || currWeightAttributeMap_["muf"].empty()) { - group.setIsWellFormed(false); - } - else { - try { - float muR = std::stof(currWeightAttributeMap_["mur"]); - float muF = std::stof(currWeightAttributeMap_["muf"]); - auto& scaleGroup = dynamic_cast(group); - scaleGroup.addContainedId(index, currWeightAttributeMap_["id"], headerLine, muR, muF); - } - catch(std::invalid_argument& e) { - group.setIsWellFormed(false); - group.addContainedId(index, currWeightAttributeMap_["id"], headerLine); - } - } - } - else - group.addContainedId(index, currWeightAttributeMap_["id"], headerLine); - - index++; - } - else if (std::regex_match(headerLine, weightGroupEnd_)) { - if (!currGroupAttributeMap_.empty()) - setGroupInfo(); - currGroupAttributeMap_.clear(); - currWeightAttributeMap_.clear(); - } - // Should be fine to ignore all other lines? Tend to be either empty or closing tag - } + return std::make_unique(weight.groupname); } } - diff --git a/GeneratorInterface/Core/src/WeightHelper.cc b/GeneratorInterface/Core/src/WeightHelper.cc index fe96bd7298735..b178134a7b156 100644 --- a/GeneratorInterface/Core/src/WeightHelper.cc +++ b/GeneratorInterface/Core/src/WeightHelper.cc @@ -18,6 +18,7 @@ namespace gen { {"NNPDF31_nnlo_as_0119", 323500, kVariationSet}, {"NNPDF31_nnlo_as_0122", 323700, kVariationSet}, {"NNPDF31_nnlo_as_0124", 323900, kVariationSet}, + {"NNPDF31_nnlo_as_0118_nf_4_mc_hessian", 325500, kHessianUnc}, {"NNPDF31_nlo_as_0118_nf_4", 320500, kMonteCarloUnc}, {"NNPDF31_nnlo_as_0118_nf_4", 320900, kMonteCarloUnc}, {"NNPDF30_nlo_nf_5_pdfas", 292200, kMonteCarloUnc}, @@ -48,40 +49,89 @@ namespace gen { {"CT14qed_inc_proton", 13400, kHessianUnc}, {"LUXqed17_plus_PDF4LHC15_nnlo_100", 82200, kMonteCarloUnc}, }) - {} + { model_ = ""; } - void WeightHelper::setGroupInfo() { - auto& group = weightGroups_.back(); - const std::string& name = group.name(); - if (group.weightType() == WeightType::kPdfWeights) { - PdfWeightGroupInfo* pdfGroup = dynamic_cast(&group); - auto pdfInfo = std::find_if(pdfSetsInfo.begin(), pdfSetsInfo.end(), - [name] (const PdfSetInfo& setInfo) { return setInfo.name == name; }); - if (pdfInfo != pdfSetsInfo.end()) { - pdfGroup->setUncertaintyType(pdfInfo->uncertaintyType); - pdfGroup->addLhapdfId(pdfInfo->lhapdfId, 0); - } - else - pdfGroup->setIsWellFormed(false); - } + bool WeightHelper::isScaleWeightGroup(const ParsedWeight& weight) { + return (weight.groupname.find("scale_variation") != std::string::npos + || weight.groupname.find("Central scale variation") != std::string::npos); } - bool WeightHelper::currentGroupIsScale() { - std::string name = boost::algorithm::to_lower_copy(currGroupAttributeMap_["name"]); - return (name.find("scale") != std::string::npos); - } - - bool WeightHelper::currentGroupIsPdf() { - std::string name = currGroupAttributeMap_["name"]; - if (boost::algorithm::to_lower_copy(name).find("pdf") != std::string::npos) + bool WeightHelper::isPdfWeightGroup(const ParsedWeight& weight) { + const std::string& name = weight.groupname; + if (name.find("PDF_variation") != std::string::npos) return true; + return std::find_if(pdfSetsInfo.begin(), pdfSetsInfo.end(), [name] (const PdfSetInfo& setInfo) { return setInfo.name == name; }) != pdfSetsInfo.end(); } - bool WeightHelper::currentGroupIsMEParam() { - std::string name = boost::algorithm::to_lower_copy(currGroupAttributeMap_["name"]); - return (name.find("mg_reweighting") != std::string::npos); + bool WeightHelper::isMEParamWeightGroup(const ParsedWeight& weight) { + return (weight.groupname.find("mg_reweighting") != std::string::npos); + } + + std::string WeightHelper::searchAttributes(const std::string& label, const ParsedWeight& weight) { + for (const auto& lab : attributeNames_.at(label)) { + auto& attributes = weight.attributes; + if (attributes.find(lab) != attributes.end()) { + return boost::algorithm::trim_copy_if(attributes.at(lab), boost::is_any_of("\"")); + } + } + // Next regexes + return ""; + } + + void WeightHelper::updateScaleInfo(const ParsedWeight& weight) { + auto& group = weightGroups_.back(); + auto& scaleGroup = dynamic_cast(group); + std::string muRText = searchAttributes("mur", weight); + std::string muFText = searchAttributes("mur", weight); + if (muRText.empty() || muFText.empty()) { + scaleGroup.setIsWellFormed(false); + return; + } + + try { + float muR = std::stof(muRText); + float muF = std::stof(muFText); + scaleGroup.setMuRMuFIndex(weight.index, weight.id, muR, muF); + } + catch(std::invalid_argument& e) { + scaleGroup.setIsWellFormed(false); + } + } + + void WeightHelper::updatePdfInfo(const ParsedWeight& weight) { + auto& pdfGroup = dynamic_cast(weightGroups_.back()); + std::string lhaidText = searchAttributes("pdf", weight); + int lhaid = 0; + if (!lhaidText.empty()) { + try { + lhaid = std::stoi(lhaidText); + } + catch(std::invalid_argument& e) { + pdfGroup.setIsWellFormed(false); + } + + if (!pdfGroup.containsParentLhapdfId(lhaid, weight.index)) { + std::string description; + auto pdfInfo = std::find_if(pdfSetsInfo.begin(), pdfSetsInfo.end(), + [lhaid] (const PdfSetInfo& setInfo) { return setInfo.lhapdfId == lhaid; }); + if (pdfInfo != pdfSetsInfo.end()) { + pdfGroup.setUncertaintyType(pdfInfo->uncertaintyType); + if (pdfInfo->uncertaintyType == gen::kHessianUnc) + description = "Hessian "; + else if (pdfInfo->uncertaintyType == gen::kMonteCarloUnc) + description = "Monte Carlo "; + description += "Uncertainty sets for LHAPDF set " + pdfInfo->name; + description += " with LHAID = " + std::to_string(lhaid); + } + description = "Uncertainty sets for LHAPDF set with LHAID = " + std::to_string(lhaid); + pdfGroup.addLhapdfId(lhaid, weight.index); + pdfGroup.setDescription(description); + } + } + else + pdfGroup.setIsWellFormed(false); } // TODO: Could probably recycle this code better @@ -134,7 +184,8 @@ namespace gen { counter++; } // Needs to be properly handled - throw std::range_error("Unmatched Generator weight! ID was " + wgtId + " index was " + std::to_string(weightIndex)); + throw std::range_error("Unmatched Generator weight! ID was " + wgtId + " index was " + std::to_string(weightIndex) + + "\nNot found in any of " + std::to_string(weightGroups_.size()) + " weightGroups."); } } diff --git a/GeneratorInterface/Core/test/dumpWeightInfo.py b/GeneratorInterface/Core/test/dumpWeightInfo.py index cdb47e9b60fde..2ee498c9fb383 100644 --- a/GeneratorInterface/Core/test/dumpWeightInfo.py +++ b/GeneratorInterface/Core/test/dumpWeightInfo.py @@ -2,7 +2,6 @@ import ROOT sources = ["externalLHEProducer"] #sources = ["testLHEWeights", "testGenWeights"] -#source = "testGenWeights" #for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"," HIG-RunIIFall18wmLHEGS-00509_ordered.root","HIG-RunIIFall18wmLHEGS-00509_unordered.root"]: for filename in ["HIG-RunIIFall18wmLHEGS-00509.root"]: @@ -20,17 +19,17 @@ event.getByLabel(source, weightHandle) weightInfo = weightHandle.product() print weightInfoProd.allWeightGroupsInfo(), len(weightInfoProd.allWeightGroupsInfo()) - print "Content of the weights" for j, weights in enumerate(weightInfo.weights()): print "-"*10, "Looking at entry", j, "length is", len(weights),"-"*10 matching = weightInfoProd.orderedWeightGroupInfo(j) print "Group is", matching, "name is", matching.name(), "well formed?", matching.isWellFormed() + print "Group description", matching.description() print type(matching.weightType()), matching.weightType() - if matching.weightType() == 1: + if matching.weightType() == 's': for var in [(x, y) for x in ["05", "1", "2"] for y in ["05", "1", "2"]]: name = "muR%smuF%sIndex" % (var[0], var[1]) if not (var[0] == "1" and var[1] == "1") else "centralIndex" print name, getattr(matching, name)() - elif matching.weightType() == 0: + elif matching.weightType() == 'P': print "uncertaintyType", "Hessian" if matching.uncertaintyType() == ROOT.gen.kHessianUnc else "MC" print "contains LHAPDFIds", len(matching.lhapdfIdsContained()), [i for i in matching.lhapdfIdsContained()], print "Has alphas? ", matching.hasAlphasVariations() diff --git a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py index cc1e1830d2d68..0c0925dc2e46e 100644 --- a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py @@ -21,16 +21,20 @@ process.out = cms.OutputModule("PoolOutputModule", fileName = cms.untracked.string('test.root'), - outputCommands = cms.untracked.vstring(['keep *']) + outputCommands = cms.untracked.vstring(['drop *', + 'keep GenWeightProduct_test*Weights*_*_*', + 'keep GenWeightInfoProduct_test*Weights*_*_*',]) ) -process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer", - lheSource=cms.untracked.InputTag(options.lheSource), - lheSourceLabel=cms.untracked.string(options.lheSource)) -process.testGenWeights = cms.EDProducer("GenWeightProductProducer") +#process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer", +# lheSourceLabel = cms.string("externalLHEProducer")) -process.p = cms.Path(process.testLHEWeights*process.testGenWeights) -#process.p = cms.Path(process.testLHEWeights) +process.testGenWeights = cms.EDProducer("GenWeightProductProducer", + genInfo = cms.InputTag("generator"), + genLumiInfoHeader = cms.InputTag("generator")) + +#process.p = cms.Path(process.testLHEWeights*process.testGenWeights) +process.p = cms.Path(process.testGenWeights) process.output = cms.EndPath(process.out) process.schedule = cms.Schedule(process.p,process.output) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 49aaa321f9702..eb2ffa677c3fa 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -55,8 +55,6 @@ Description: [one line class summary] #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" #include "GeneratorInterface/LHEInterface/interface/LHEReader.h" -#include "GeneratorInterface/LHEInterface/interface/TestWeightInfo.h" -//#include "GeneratorInterface/Core/interface/GenWeightGroupReaderHelper.h" #include "GeneratorInterface/Core/interface/LHEWeightHelper.h" #include "FWCore/ServiceRegistry/interface/Service.h" @@ -362,7 +360,9 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) run.put(std::move(product)); - weightHelper_.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); + //weightHelper_.parseWeightGroupsFromHeader(runInfo->findHeader("initrwgt")); + weightHelper_.setHeaderLines(runInfo->findHeader("initrwgt")); + weightHelper_.parseWeights(); runInfo.reset(); } diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index 88d8ebe03c18f..8fba40c06dfb1 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -10,8 +10,7 @@ genInfo = cms.InputTag("generator")) lheWeights = cms.EDProducer("LHEWeightProductProducer", - lheSourceLabel = cms.string("externalLHEProducer"), - lheSource = cms.InputTag("externalLHEProducer")) + lheSourceLabel = cms.string("externalLHEProducer")) lheWeightsTable = cms.EDProducer( "LHEWeightsTableProducer", diff --git a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h index aa69dc4bcb7b8..18dc88fdbd067 100644 --- a/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/PdfWeightGroupInfo.h @@ -3,6 +3,7 @@ #include "SimDataFormats/GeneratorProducts/interface/WeightGroupInfo.h" #include +#include namespace gen { enum PdfUncertaintyType { @@ -39,6 +40,12 @@ namespace gen { PdfUncertaintyType uncertaintyType() const { return uncertaintyType_; } bool hasAlphasVariations() const { return hasAlphasVars_; } bool containsMultipleSets() const { return lhapdfIdsContained_.size() > 1; } + bool containsParentLhapdfId(int lhaid, int globalIndex) const { + if (indexOfLhapdfId(lhaid) != -1) + return true; + int parentid = lhaid - (globalIndex - firstId_); + return indexOfLhapdfId(parentid) != -1; + } bool containsLhapdfId(int lhaid) const { return indexOfLhapdfId(lhaid) != -1; } int indexOfLhapdfId(int lhaid) const { for (const auto& id : lhapdfIdsContained_) { @@ -49,8 +56,8 @@ namespace gen { } int alphasUpIndex() const { return alphasUpIndex_; } int alphasDownIndex() const { return alphasDownIndex_; } - void addLhapdfId(int lhaid, int index) { - lhapdfIdsContained_.push_back(std::make_pair(lhaid, index)); + void addLhapdfId(int lhaid, int globalIndex) { + lhapdfIdsContained_.push_back(std::make_pair(lhaid, globalIndex-firstId_)); } std::vector lhapdfIdsContained() const { std::vector lhaids; diff --git a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h index d3feee93811be..71b6a6b0a987a 100644 --- a/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h +++ b/SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h @@ -42,7 +42,8 @@ namespace gen { void copy(const ScaleWeightGroupInfo &other); virtual ScaleWeightGroupInfo* clone() const override; - void setMuRMuFIndex(WeightMetaInfo info, float muR, float muF); + void setMuRMuFIndex(WeightMetaInfo& info, float muR, float muF); + void setMuRMuFIndex(int globalIndex, std::string id, float muR, float muF); void addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF); // Is a variation of the functional form of the dynamic scale diff --git a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc index 155d3981e00a6..575871de6f101 100644 --- a/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc @@ -20,13 +20,17 @@ namespace gen { return new ScaleWeightGroupInfo(*this); } - void ScaleWeightGroupInfo::addContainedId(int weightEntry, std::string id, std::string label, float muR, float muF) { - WeightGroupInfo::addContainedId(weightEntry, id, label); - auto metaInfo = weightMetaInfoByGlobalIndex(id, weightEntry); + void ScaleWeightGroupInfo::addContainedId(int globalIndex, std::string id, std::string label, float muR, float muF) { + WeightGroupInfo::addContainedId(globalIndex, id, label); + setMuRMuFIndex(globalIndex, id, muR, muF); + } + + void ScaleWeightGroupInfo::setMuRMuFIndex(int globalIndex, std::string id, float muR, float muF) { + auto metaInfo = weightMetaInfoByGlobalIndex(id, globalIndex); setMuRMuFIndex(metaInfo, muR, muF); } - void ScaleWeightGroupInfo::setMuRMuFIndex(WeightMetaInfo info, float muR, float muF) { + void ScaleWeightGroupInfo::setMuRMuFIndex(WeightMetaInfo& info, float muR, float muF) { if (muR == 0.5 && muF == 0.5) muR05muF05Index_ = info.localIndex; else if (muR == 0.5 && muF == 1.0) diff --git a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc index 23c22b2342838..2b8c5079a443f 100644 --- a/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc +++ b/SimDataFormats/GeneratorProducts/src/WeightGroupInfo.cc @@ -7,14 +7,14 @@ namespace gen { void WeightGroupInfo::copy(const WeightGroupInfo &other) { - isWellFormed_ = true; - headerEntry_ = other.headerEntry(); - name_ = other.name(); - description_ = other.description(); - weightType_ = other.weightType(); - idsContained_ = other.idsContained(); - firstId_ = other.firstId(); - lastId_ = other.lastId(); + isWellFormed_ = other.isWellFormed_; + headerEntry_ = other.headerEntry_; + name_ = other.name_; + description_ = other.description_; + weightType_ = other.weightType_; + idsContained_ = other.idsContained_; + firstId_ = other.firstId_; + lastId_ = other.lastId_; } WeightGroupInfo* WeightGroupInfo::clone() const { From 419a1cde6629d3a1666b4abe9a02328a38926d61 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Mon, 20 Jan 2020 09:26:54 +0100 Subject: [PATCH 74/75] Update lheWeights config --- .../Core/plugins/GenWeightProductProducer.cc | 3 +-- PhysicsTools/NanoAOD/python/nanogen_cff.py | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc index e8d18a93e5878..98075bedd6a3b 100644 --- a/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/GenWeightProductProducer.cc @@ -85,8 +85,7 @@ GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock& iLum iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle); weightNames_ = genLumiInfoHandle->weightNames(); - - weightHelper_.parseWeightGroupsFromNames(weightNames_); + weightHelper_.parseWeightGroupsFromNames(weightNames_); } auto weightInfoProduct = std::make_unique(); for (auto& weightGroup : weightHelper_.weightGroups()) { diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index 8fba40c06dfb1..96ebd22e0b5f7 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -7,7 +7,8 @@ from PhysicsTools.NanoAOD.genWeightsTable_cfi import * genWeights = cms.EDProducer("GenWeightProductProducer", - genInfo = cms.InputTag("generator")) + genInfo = cms.InputTag("generator"), + genLumiInfoHeader = cms.InputTag("generator")) lheWeights = cms.EDProducer("LHEWeightProductProducer", lheSourceLabel = cms.string("externalLHEProducer")) @@ -15,6 +16,7 @@ lheWeightsTable = cms.EDProducer( "LHEWeightsTableProducer", lheWeights = cms.VInputTag(["externalLHEProducer", "lheWeights"]), + lheWeightPrecision = cms.int32(14), genWeights = cms.InputTag("genWeights"), # Warning: you can use a full string, but only the first character is read. # Note also that the capitalization is important! For example, 'parton shower' @@ -24,7 +26,8 @@ maxGroupsPerType = cms.vint32([1, -1, 1, 2, 1]), # If empty or not specified, no critieria is applied to filter on LHAPDF IDs pdfIds = cms.untracked.vint32([91400, 306000, 260000]), - lheWeightPrecision = cms.int32(14), + unknownOnlyIfEmpty = cms.untracked.vstring(['scale', 'PDF']), + unknownOnlyIfAllEmpty = cms.untracked.bool(False), ) nanoMetadata = cms.EDProducer("UniqueStringProducer", From a2912ec22d2685d674007d9cbfa88077dffb7dd4 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Thu, 23 Jan 2020 20:44:40 +0100 Subject: [PATCH 75/75] First stab at cmsDriver NanoGEN Fix customize call, remove unimplimented args --- Configuration/Applications/python/ConfigBuilder.py | 11 +++++++++++ PhysicsTools/NanoAOD/python/nanogen_cff.py | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Configuration/Applications/python/ConfigBuilder.py b/Configuration/Applications/python/ConfigBuilder.py index 608651f121385..375ac04f59e7d 100644 --- a/Configuration/Applications/python/ConfigBuilder.py +++ b/Configuration/Applications/python/ConfigBuilder.py @@ -938,6 +938,7 @@ def define_Configs(self): self.RECOSIMDefaultCFF="Configuration/StandardSequences/RecoSim_cff" self.PATDefaultCFF="Configuration/StandardSequences/PAT_cff" self.NANODefaultCFF="PhysicsTools/NanoAOD/nano_cff" + self.NANOGENDefaultCFF="PhysicsTools/NanoAOD/nanogen_cff" self.EIDefaultCFF=None self.SKIMDefaultCFF="Configuration/StandardSequences/Skims_cff" self.POSTRECODefaultCFF="Configuration/StandardSequences/PostRecoGenerator_cff" @@ -987,6 +988,7 @@ def define_Configs(self): self.REPACKDefaultSeq='DigiToRawRepack' self.PATDefaultSeq='miniAOD' self.PATGENDefaultSeq='miniGEN' + self.NANOGENDefaultSeq='nanogenSequence' self.NANODefaultSeq='nanoSequence' self.EVTCONTDefaultCFF="Configuration/EventContent/EventContent_cff" @@ -1690,6 +1692,15 @@ def prepare_NANO(self, sequence = "nanoAOD"): self._options.customise_commands = self._options.customise_commands + " \n" self._options.customise_commands = self._options.customise_commands + "process.unpackedPatTrigger.triggerResults= cms.InputTag( 'TriggerResults::"+self._options.hltProcess+"' )\n" + def prepare_NANOGEN(self, sequence = "nanoAOD"): + ''' Enrich the schedule with NANO ''' + self.loadDefaultOrSpecifiedCFF(sequence,self.NANOGENDefaultCFF) + self.scheduleSequence(sequence.split('.')[-1],'nanoAOD_step') + custom = "customizeNanoGEN" + if self._options.runUnscheduled: + self._options.customisation_file_unsch.insert(0, '.'.join([self.NANOGENDefaultCFF, custom])) + else: + self._options.customisation_file.insert(0, '.'.join([self.NANOGENDefaultCFF, custom])) def prepare_EI(self, sequence = None): ''' Enrich the schedule with event interpretation ''' diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index 96ebd22e0b5f7..66c938ac408ae 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -26,8 +26,8 @@ maxGroupsPerType = cms.vint32([1, -1, 1, 2, 1]), # If empty or not specified, no critieria is applied to filter on LHAPDF IDs pdfIds = cms.untracked.vint32([91400, 306000, 260000]), - unknownOnlyIfEmpty = cms.untracked.vstring(['scale', 'PDF']), - unknownOnlyIfAllEmpty = cms.untracked.bool(False), + #unknownOnlyIfEmpty = cms.untracked.vstring(['scale', 'PDF']), + #unknownOnlyIfAllEmpty = cms.untracked.bool(False), ) nanoMetadata = cms.EDProducer("UniqueStringProducer",