Skip to content

Commit

Permalink
Working on parsing integration with scale/pdf weights
Browse files Browse the repository at this point in the history
  • Loading branch information
kdlong committed Aug 15, 2019
1 parent 9696885 commit f62468c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@

class LHEWeightGroupReaderHelper {
public:
LHEWeightGroupReaderHelper() : curWeight(gen::kUnknownWeights) {}
LHEWeightGroupReaderHelper() : curWeight_(gen::kUnknownWeights) {
weightGroupStart_ = std::regex(".*<weightgroup.+>.*");
weightGroupEnd_ = std::regex(".*</weightgroup>.*");
weightContent_ = std::regex("<weight.*>\\s*(.+)</weight>");
}

//// possibly add more versions of this functions for different inputs
void parseLHEFile(std::string filename);


gen::WeightGroupInfo* getScaleInfo() {return scaleInfo;}
edm::OwnVector<gen::WeightGroupInfo> getPdfVector() {return pdfVector;}
edm::OwnVector<gen::WeightGroupInfo> getWeightGroups() {return weightGroups_;}

private:
// Functions
std::regex createRegexSearch(std::vector<std::string>);
std::map<std::string, std::string> getTagsMap(std::string, std::regex);

// Variables
gen::WeightType curWeight;
gen::WeightGroupInfo* scaleInfo;
edm::OwnVector<gen::WeightGroupInfo> pdfVector;
std::regex weightStart = std::regex(".*<weightgroup.+>.*");
std::regex weightEnd = std::regex(".*</weightgroup>.*");
std::regex weightContent = std::regex("<weight.*>\\s*(.+)</weight>");
gen::WeightType curWeight_;
edm::OwnVector<gen::WeightGroupInfo> weightGroups_;
std::regex weightGroupStart_;
std::regex weightGroupEnd_;
std::regex weightContent_;

};

Expand All @@ -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<gen::ScaleWeightGroupInfo&>(group);
scaleGroup.addContainedId(index, tagsMap["id"], line, muR, muF);
}
else
group.addContainedId(index, tagsMap["id"], line);

index++;

curWeight_ = gen::kUnknownWeights;
}
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,16 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es)


std::unique_ptr<LHEWeightInfoProduct> weightInfoProduct(new LHEWeightInfoProduct);
gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights();
edm::OwnVector<gen::WeightGroupInfo> pdfSets;// = getExamplePdfWeights();
//gen::WeightGroupInfo scaleInfo;// = getExampleScaleWeights();
//edm::OwnVector<gen::WeightGroupInfo> 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));
Expand Down
58 changes: 29 additions & 29 deletions SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand All @@ -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
Expand Down
36 changes: 18 additions & 18 deletions SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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");
}
Expand Down
16 changes: 0 additions & 16 deletions SimDataFormats/GeneratorProducts/src/ScaleWeightGroupInfo.h

This file was deleted.

7 changes: 7 additions & 0 deletions SimDataFormats/GeneratorProducts/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,19 @@
</class>
<class name="gen::WeightGroupInfo"/>
<class name="gen::PdfWeightGroupInfo"/>
<class name="gen::ScaleWeightGroupInfo"/>
<class name="gen::WeightMetaInfo"/>
<class name="std::vector<gen::WeightsInfo>"/>
<class name="std::vector<gen::WeightGroupInfo>"/>
<class name="std::vector<gen::WeightGroupInfo*>"/>
<class name="std::vector<gen::PdfWeightGroupInfo>"/>
<class name="std::vector<gen::PdfWeightGroupInfo*>"/>
<class name="std::vector<gen::ScaleWeightGroupInfo>"/>
<class name="std::vector<gen::ScaleWeightGroupInfo*>"/>
<class name="edm::OwnVector<gen::WeightGroupInfo>"/>
<class name="edm::Wrapper<gen::WeightGroupInfo>"/>
<class name="edm::Wrapper<gen::PdfWeightGroupInfo>"/>
<class name="edm::Wrapper<gen::ScaleWeightGroupInfo>"/>
<class name="edm::Wrapper&lt;LHERunInfoProduct&gt;"/>
<class name="edm::Wrapper&lt;LHEWeightInfoProduct&gt;"/>
<class name="edm::Wrapper&lt;LHEWeightProduct&gt;"/>
Expand Down

0 comments on commit f62468c

Please sign in to comment.