-
Notifications
You must be signed in to change notification settings - Fork 1
Gen weight restructure + nano (nanogen) integration #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
208a4a3
0a8810e
7cfc2fe
444dbc3
49c25ba
bb431b7
df84164
23bee66
0ba28e0
9ba9510
338a979
8397fca
9e06271
071c069
f44363c
6bfea57
9696885
f62468c
28f0ba2
db06b18
71629cd
cf10a6b
fbf495c
c98a078
de0ad7a
59691bc
1c1da76
057cb83
80cde77
41f2e17
33e2466
f1bcab0
9baeee2
1038e0d
b4b08c9
f1a3ae4
1bb40ac
1e81c15
79efbe6
07eb97a
5668f0d
8c0c98e
8744839
682ac14
037f6f9
a78163b
b6e3285
c82792f
ffd0503
c535b55
3e48617
176adbf
acc3817
27a9239
7402487
b744a77
a30dacf
2b1b520
d307670
bbdd462
916af26
70cdb97
205de35
d663d2f
45be54a
c4cd203
dd34a14
c545dec
d6c2452
a4e2b7a
9f6b791
afe662a
6c5900c
fb19c05
ae40865
e542eaa
ca22fc5
8fcc230
3dbdd4c
265e6a0
6aaef39
6ccee5d
884dc84
9bd87c7
7daba24
419a1cd
a2912ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #ifndef GeneratorInterface_Core_GenWeightHelper_h | ||
| #define GeneratorInterface_Core_GenWeightHelper_h | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
| #include <map> | ||
| #include <regex> | ||
| #include <fstream> | ||
|
|
||
| #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 <tinyxml2.h> | ||
|
|
||
| namespace gen { | ||
| class GenWeightHelper : public WeightHelper { | ||
| public: | ||
| GenWeightHelper(); | ||
|
|
||
| void parseWeightGroupsFromNames(std::vector<std::string> weightNames); | ||
| private: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove private if unused |
||
| }; | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #ifndef GeneratorInterface_Core_LHEWeightHelper_h | ||
| #define GeneratorInterface_Core_LHEWeightHelper_h | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
| #include <map> | ||
| #include <regex> | ||
| #include <fstream> | ||
|
|
||
| #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" | ||
| #include "GeneratorInterface/Core/interface/WeightHelper.h" | ||
|
|
||
| #include <tinyxml2.h> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "" not <> |
||
|
|
||
| namespace gen { | ||
| class LHEWeightHelper : public WeightHelper { | ||
| public: | ||
| LHEWeightHelper() : WeightHelper() {}; | ||
| void setHeaderLines(std::vector<std::string> headerLines); | ||
| void parseWeights(); | ||
| void buildGroups(); | ||
| std::unique_ptr<WeightGroupInfo> buildGroup(const ParsedWeight& weight); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function could be |
||
| private: | ||
| std::vector<std::string> headerLines_; | ||
| }; | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #ifndef GeneratorInterface_LHEInterface_WeightHelper_h | ||
| #define GeneratorInterface_LHEInterface_WeightHelper_h | ||
|
|
||
| #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 "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> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this include needed? |
||
|
|
||
| namespace gen { | ||
| struct PdfSetInfo { | ||
| std::string name; | ||
| int lhapdfId; | ||
| PdfUncertaintyType uncertaintyType; | ||
| }; | ||
|
|
||
| struct ParsedWeight { | ||
| std::string id; | ||
| size_t index; | ||
| std::string groupname; | ||
| std::string content; | ||
| std::unordered_map<std::string, std::string> attributes; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
| }; | ||
|
|
||
| class WeightHelper { | ||
| public: | ||
| WeightHelper(); | ||
| edm::OwnVector<gen::WeightGroupInfo> weightGroups() { | ||
| return weightGroups_; | ||
| } | ||
| std::unique_ptr<GenWeightProduct> weightProduct(std::vector<gen::WeightsInfo>, float w0); | ||
| std::unique_ptr<GenWeightProduct> weightProduct(std::vector<double>, float w0); | ||
| void setModel(std::string model) { model_ = model; } | ||
| int addWeightToProduct(std::unique_ptr<GenWeightProduct>& product, double weight, std::string name, int weightNum, int groupIndex); | ||
| int findContainingWeightGroup(std::string wgtId, int weightIndex, int previousGroupIndex); | ||
| protected: | ||
| std::string model_; | ||
| std::vector<ParsedWeight> parsedWeights_; | ||
| const std::vector<PdfSetInfo> pdfSetsInfo; | ||
| std::map<std::string, std::string> currWeightAttributeMap_; | ||
| std::map<std::string, std::string> currGroupAttributeMap_; | ||
| edm::OwnVector<gen::WeightGroupInfo> weightGroups_; | ||
| bool isScaleWeightGroup(const ParsedWeight& weight); | ||
| bool isMEParamWeightGroup(const ParsedWeight& weight); | ||
| bool isPdfWeightGroup(const ParsedWeight& weight); | ||
| void updateScaleInfo(const ParsedWeight& weight); | ||
| void updatePdfInfo(const ParsedWeight& weight); | ||
| 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"}} | ||
| }; | ||
| }; | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #include <cstdio> | ||
| #include <memory> | ||
| #include <vector> | ||
| #include <string> | ||
|
|
||
| // 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" | ||
| #include <boost/algorithm/string.hpp> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this include needed? |
||
|
|
||
| class GenWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosityBlockProducer> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need to be a |
||
| public: | ||
| explicit GenWeightProductProducer(const edm::ParameterSet& iConfig); | ||
| ~GenWeightProductProducer() override; | ||
|
|
||
| private: | ||
| std::vector<std::string> weightNames_; | ||
| 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; | ||
| }; | ||
|
|
||
| // | ||
| // constructors and destructor | ||
| // | ||
| GenWeightProductProducer::GenWeightProductProducer(const edm::ParameterSet& iConfig) : | ||
| genLumiInfoToken_(consumes<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genInfo"))), | ||
| genEventToken_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("genInfo"))), | ||
| genLumiInfoHeadTag_(mayConsume<GenLumiInfoHeader, edm::InLumi>(iConfig.getParameter<edm::InputTag>("genLumiInfoHeader"))) | ||
| { | ||
| produces<GenWeightProduct>(); | ||
| produces<GenWeightInfoProduct, edm::Transition::BeginLuminosityBlock>(); | ||
| } | ||
|
|
||
|
|
||
| GenWeightProductProducer::~GenWeightProductProducer() | ||
| { | ||
| } | ||
|
|
||
|
|
||
| // ------------ method called to produce the data ------------ | ||
| void | ||
| GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { | ||
| edm::Handle<GenEventInfoProduct> genEventInfo; | ||
| iEvent.getByToken(genEventToken_, genEventInfo); | ||
|
|
||
| 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::beginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) { | ||
| edm::Handle<GenLumiInfoHeader> genLumiInfoHead; | ||
| iLumi.getByToken(genLumiInfoHeadTag_, genLumiInfoHead); | ||
| if (genLumiInfoHead.isValid()) { | ||
| std::string label = genLumiInfoHead->configDescription(); | ||
| boost::replace_all(label,"-","_"); | ||
| weightHelper_.setModel(label); | ||
| } | ||
|
|
||
| if (weightNames_.size() == 0) { | ||
| edm::Handle<GenLumiInfoHeader> genLumiInfoHandle; | ||
| iLumi.getByToken(genLumiInfoToken_, genLumiInfoHandle); | ||
|
|
||
| weightNames_ = genLumiInfoHandle->weightNames(); | ||
| weightHelper_.parseWeightGroupsFromNames(weightNames_); | ||
| } | ||
| auto weightInfoProduct = std::make_unique<GenWeightInfoProduct>(); | ||
| for (auto& weightGroup : weightHelper_.weightGroups()) { | ||
| weightInfoProduct->addWeightGroupInfo(weightGroup.clone()); | ||
| } | ||
| iLumi.put(std::move(weightInfoProduct)); | ||
| } | ||
|
|
||
| DEFINE_FWK_MODULE(GenWeightProductProducer); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be in "" not <>