Skip to content

Commit

Permalink
Significant restructure of parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
kdlong committed Jan 19, 2020
1 parent 9bd87c7 commit 7daba24
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 255 deletions.
22 changes: 6 additions & 16 deletions GeneratorInterface/Core/interface/LHEWeightHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> lheHeader);
LHEWeightHelper() : WeightHelper() {};
void setHeaderLines(std::vector<std::string> headerLines);
void parseWeights();
void buildGroups();
std::unique_ptr<WeightGroupInfo> buildGroup(const ParsedWeight& weight);
private:
std::map<std::string, std::string> weightAttributeMapFromHeaderLine(std::string line);
void loadAttributeNames(std::string baseName, std::vector<std::string> altNames ={});
std::map<std::string, std::string> getAttributeMap(std::string);
std::string sanitizeText(std::string);
bool isAWeight(std::string);

std::regex weightGroupStart_;
std::regex weightGroupEnd_;
std::regex weightContent_;

std::map<std::string, std::string> nameConversionMap_;
std::vector<std::string> headerLines_;
};
}

Expand Down
32 changes: 28 additions & 4 deletions GeneratorInterface/Core/interface/WeightHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/algorithm/string.hpp>

namespace gen {
Expand All @@ -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<std::string, std::string> attributes;
};

class WeightHelper {
public:
WeightHelper();
Expand All @@ -23,17 +35,29 @@ namespace gen {
}
std::unique_ptr<GenWeightProduct> weightProduct(std::vector<gen::WeightsInfo>, float w0);
std::unique_ptr<GenWeightProduct> weightProduct(std::vector<double>, float w0);
void setGroupInfo();
bool currentGroupIsScale();
bool currentGroupIsMEParam();
bool currentGroupIsPdf();
void setModel(std::string model) { model_ = model; }
int addWeightToProduct(std::unique_ptr<GenWeightProduct>& product, double weight, std::string name, int weightNum, int groupIndex);
int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex);
protected:
std::string model_;
std::vector<ParsedWeight> parsedWeights_;
const std::vector<PdfSetInfo> pdfSetsInfo;
std::map<std::string, std::string> currWeightAttributeMap_;
std::map<std::string, std::string> currGroupAttributeMap_;
edm::OwnVector<gen::WeightGroupInfo> weightGroups_;
bool isScaleWeightGroup(const ParsedWeight& weight);
bool isMEParamWeightGroup(const ParsedWeight& weight);
bool isPdfWeightGroup(const ParsedWeight& weight);
void updateScaleInfo(const ParsedWeight& weight);
void updatePdfInfo(const ParsedWeight& weight);
std::string searchAttributes(const std::string& label, const ParsedWeight& weight);

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

Expand Down
13 changes: 12 additions & 1 deletion GeneratorInterface/Core/plugins/GenWeightProductProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "GeneratorInterface/Core/interface/GenWeightHelper.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include <boost/algorithm/string.hpp>

class GenWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosityBlockProducer> {
public:
Expand All @@ -34,6 +35,7 @@ class GenWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosit
gen::GenWeightHelper weightHelper_;
edm::EDGetTokenT<GenLumiInfoHeader> genLumiInfoToken_;
edm::EDGetTokenT<GenEventInfoProduct> genEventToken_;
const edm::EDGetTokenT<GenLumiInfoHeader> genLumiInfoHeadTag_;

void produce(edm::Event&, const edm::EventSetup&) override;
void beginLuminosityBlockProduce(edm::LuminosityBlock& lb, edm::EventSetup const& c) override;
Expand All @@ -44,7 +46,8 @@ class GenWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosit
//
GenWeightProductProducer::GenWeightProductProducer(const edm::ParameterSet& iConfig) :
genLumiInfoToken_(consumes<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genInfo"))),
genEventToken_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("genInfo")))
genEventToken_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("genInfo"))),
genLumiInfoHeadTag_(mayConsume<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genLumiInfoHeader")))
{
produces<GenWeightProduct>();
produces<GenWeightInfoProduct, edm::Transition::BeginLuminosityBlock>();
Expand All @@ -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<GenLumiInfoHeader> genLumiInfoHead;
iLumi.getByToken(genLumiInfoHeadTag_, genLumiInfoHead);
if (genLumiInfoHead.isValid()) {
std::string label = genLumiInfoHead->configDescription();
boost::replace_all(label,"-","_");
weightHelper_.setModel(label);
}

if (weightNames_.size() == 0) {
edm::Handle<GenLumiInfoHeader> genLumiInfoHandle;
iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle);
Expand Down
6 changes: 2 additions & 4 deletions GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class LHEWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosit

};

//
// constructors and destructor
//
// TODO: Accept a vector of strings (source, externalLHEProducer) exit if neither are found
LHEWeightProductProducer::LHEWeightProductProducer(const edm::ParameterSet& iConfig) :
lheLabel_(iConfig.getParameter<std::string>("lheSourceLabel")),
lheRunInfoToken_(consumes<LHERunInfoProduct, edm::InRun>(lheLabel_)),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion GeneratorInterface/Core/src/GenWeightHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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) {
Expand Down
Loading

0 comments on commit 7daba24

Please sign in to comment.