From 5668f0da242c77aa8e6a38aa25d59e9263d500cd Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Fri, 20 Sep 2019 17:14:32 -0400 Subject: [PATCH] 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 @@ - + + + + + + + +