Skip to content

Commit

Permalink
Close to an outline, not working for LHESource
Browse files Browse the repository at this point in the history
  • Loading branch information
kdlong committed May 29, 2019
1 parent 208a4a3 commit 0a8810e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 25 deletions.
24 changes: 20 additions & 4 deletions GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -158,6 +159,7 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig) :
produces<LHEEventProduct>();
produces<LHERunInfoProduct, edm::Transition::BeginRun>();
produces<LHERunInfoProduct, edm::Transition::EndRun>();
produces<LHEWeightInfoProduct>();
}


Expand Down Expand Up @@ -326,6 +328,22 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es)
unsigned int skip = 0;
reader_ = std::make_unique<lhef::LHEReader>(infiles, skip);

std::cout << "Adding the Weight product!";
std::unique_ptr<LHEWeightInfoProduct> weightInfoProduct(new LHEWeightInfoProduct);
gen::WeightGroupInfo scaleInfo(
"<weightgroup name=\"Central scale variation\" combine=\"envelope\">"
);
scaleInfo.setWeightType(gen::scaleWeights);

gen::WeightGroupInfo cenPdfInfo(
"<weightgroup name=\"NNPDF31_nnlo_hessian_pdfas\" combine=\"hessian\">"
);
cenPdfInfo.setWeightType(gen::pdfWeights);

weightInfoProduct->addWeightGroupInfo(scaleInfo);
weightInfoProduct->addWeightGroupInfo(cenPdfInfo);
run.put(std::move(weightInfoProduct));

nextEvent();
if (runInfoLast) {
runInfo = runInfoLast;
Expand All @@ -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 ------------
Expand All @@ -360,7 +377,7 @@ ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es)
std::unique_ptr<LHERunInfoProduct> product(runInfoProducts.pop_front().release());
run.put(std::move(product));
}

nextEvent();
if (partonLevel) {
throw edm::Exception(edm::errors::EventGenerationFailure) << "Error in ExternalLHEProducer::endRunProduce(). "
Expand All @@ -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 ------------
Expand Down
17 changes: 16 additions & 1 deletion GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <vector>
#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"
Expand All @@ -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"
Expand All @@ -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_);
}

Expand Down
2 changes: 2 additions & 0 deletions GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
24 changes: 23 additions & 1 deletion GeneratorInterface/LHEInterface/plugins/LHESource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -36,7 +37,7 @@ LHESource::LHESource(const edm::ParameterSet &params,
const edm::InputSourceDescription &desc) :
ProducerSourceFromFiles(params, desc, false),
reader_(new LHEReader(fileNames(), params.getUntrackedParameter<unsigned int>("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();
Expand Down Expand Up @@ -116,6 +117,7 @@ LHESource::readRun_(edm::RunPrincipal& runPrincipal) {
runPrincipal.fillRunPrincipal(processHistoryRegistryForUpdate());

putRunInfoProduct(runPrincipal);
putWeightInfoProduct(runPrincipal);
}

void
Expand All @@ -132,6 +134,26 @@ void LHESource::putRunInfoProduct(edm::RunPrincipal& iRunPrincipal) {
}
}

void LHESource::putWeightInfoProduct(edm::RunPrincipal& iRunPrincipal) {
if (runInfoProductLast_) {
auto product = std::make_unique<LHEWeightInfoProduct>();
gen::WeightGroupInfo scaleInfo(
"<weightgroup name=\"Central scale variation\" combine=\"envelope\">"
);
scaleInfo.setWeightType(gen::scaleWeights);

gen::WeightGroupInfo cenPdfInfo(
"<weightgroup name=\"NNPDF31_nnlo_hessian_pdfas\" combine=\"hessian\">"
);
cenPdfInfo.setWeightType(gen::pdfWeights);

product->addWeightGroupInfo(scaleInfo);
product->addWeightGroupInfo(cenPdfInfo);
std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHEWeightInfoProduct>(std::move(product)));
iRunPrincipal.put(lheProvenanceHelper_.weightProductBranchDescription_, std::move(rdp));
}
}

bool LHESource::setRunAndEventInfo(edm::EventID&, edm::TimeValue_t&, edm::EventAuxiliary::ExperimentType&)
{
nextEvent();
Expand Down
1 change: 1 addition & 0 deletions GeneratorInterface/LHEInterface/plugins/LHESource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<lhef::LHEReader> reader_;
Expand Down
29 changes: 10 additions & 19 deletions SimDataFormats/GeneratorProducts/interface/LHEWeightInfoProduct.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,16 @@

class LHEWeightInfoProduct {
public:
LHEWeightInfoProduct() {
gen::WeightGroupInfo scaleInfo(
"<weightgroup name=\"Central scale variation\" combine=\"envelope\">"
);
//scaleInfo.isPDF = false;
//scaleInfo.pdfLabel = "";
//scaleInfo.pdfLHAID = "";

gen::WeightGroupInfo cenPdfInfo(
"<weightgroup name=\"NNPDF31_nnlo_hessian_pdfas\" combine=\"hessian\">"
);

//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<gen::WeightGroupInfo>& 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<gen::WeightGroupInfo> getWeightGroupsInfo() { return weightGroupsInfo_; }
void addWeightGroupInfo(gen::WeightGroupInfo info) {
weightGroupsInfo_.push_back(info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions SimDataFormats/GeneratorProducts/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 5 additions & 0 deletions SimDataFormats/GeneratorProducts/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
<class name="LHERunInfoProduct::Header" ClassVersion="10">
<version ClassVersion="10" checksum="1310911082"/>
</class>
<class name="LHEWeightInfoProduct" ClassVersion="4">
<version ClassVersion="4" checksum="829980141"/>
</class>
<class name="LHEXMLStringProduct" ClassVersion="11">
<version ClassVersion="10" checksum="4158740350"/>
<version ClassVersion="11" checksum="3778311764"/>
Expand Down Expand Up @@ -225,7 +228,9 @@
<version ClassVersion="4" checksum="4219107434"/>
</class>
<class name="std::vector<gen::WeightsInfo>"/>
<class name="std::vector<gen::WeightGroupInfo>"/>
<class name="edm::Wrapper&lt;LHERunInfoProduct&gt;"/>
<class name="edm::Wrapper&lt;LHEWeightInfoProduct&gt;"/>
<class name="edm::Wrapper&lt;LHEEventProduct&gt;"/>

<!--needed for backward compatibility between HepMC 2.06.xx and 2.05.yy-->
Expand Down

0 comments on commit 0a8810e

Please sign in to comment.