Skip to content

Commit

Permalink
Add isWellFormed check for scale weights to helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
kdlong committed Oct 4, 2020
1 parent 8ca625f commit f46cc33
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
6 changes: 6 additions & 0 deletions GeneratorInterface/Core/src/WeightHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ namespace gen {
scaleGroup.setLhaid(-2);
}
}
if (!(scaleGroup.centralIndex() >= 0 && scaleGroup.muR05muF05Index() >= 0 &&
scaleGroup.muR1muF05Index() >= 0 && scaleGroup.muR2muF05Index() >= 0 &&
scaleGroup.muR05muF1Index() >= 0 && scaleGroup.muR05muF2Index() >= 0 &&
scaleGroup.muR1muF2Index() >= 0 && scaleGroup.muR2muF2Index() >= 0 &&
scaleGroup.muR2muF2Index() >= 0))
scaleGroup.setIsWellFormed(true);
}

int WeightHelper::lhapdfId(const ParsedWeight& weight, gen::PdfWeightGroupInfo& pdfGroup) {
Expand Down
15 changes: 10 additions & 5 deletions PhysicsTools/NanoAOD/plugins/LHEWeightsTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,27 @@ void LHEWeightsTableProducer::addWeightGroupToTable(std::map<gen::WeightType, st
label.append(std::to_string(lheWeightTables[weightType].size()));//to append the start index of this set
label.append("]; ");
auto& weights = allWeights.at(groupInfo.index);
if (weightType == gen::WeightType::kScaleWeights && groupInfo.group->isWellFormed() &&
groupInfo.group->nIdsContained() < 10) {
if (weightType == gen::WeightType::kScaleWeights)
if (groupInfo.group->isWellFormed()) {
weights = orderedScaleWeights(weights, dynamic_cast<const gen::ScaleWeightGroupInfo*>(groupInfo.group));
label.append(
"[1] is mur=0.5 muf=1; [2] is mur=0.5 muf=2; [3] is mur=1 muf=0.5 ;"
" [4] is mur=1 muf=1; [5] is mur=1 muf=2; [6] is mur=2 muf=0.5;"
" [7] is mur=2 muf=1 ; [8] is mur=2 muf=2)");
} else {
size_t nstore = std::min<size_t>(gen::ScaleWeightGroupInfo::MIN_SCALE_VARIATIONS, weights.size());
weights = std::vector(weights.begin(), weights.begin()+nstore);
label.append("WARNING: Unexpected format found. Contains first " + std::to_string(nstore) + " elements of weights vector, unordered");
} else if (!storeAllPSweights_ && weightType == gen::WeightType::kPartonShowerWeights && groupInfo.group->isWellFormed()) {
weights = getPreferredPSweights(weights, dynamic_cast<const gen::PartonShowerWeightGroupInfo*>(groupInfo.group));
label.append("PS weights (w_var / w_nominal); [0] is ISR=0.5 FSR=1; [1] is ISR=1 FSR=0.5; [2] is ISR=2 FSR=1; [3] is ISR=1 FSR=2");
}
lheWeightTables[weightType].insert(lheWeightTables[weightType].end(), weights.begin(), weights.end());
weightVecsizes[weightType].emplace_back(weights.size());
//else
// label.append(groupInfo.group->description());
if(weightlabels[weightType] == "")
lheWeightTables[weightType].insert(lheWeightTables[weightType].end(), weights.begin(), weights.end());
weightVecsizes[weightType].emplace_back(weights.size());

if (weightlabels[weightType].empty())
weightlabels[weightType].append("[idx in AltSetSizes array] Name [start idx in weight array];\n");

weightlabels[weightType].append(label);
Expand Down
19 changes: 10 additions & 9 deletions SimDataFormats/GeneratorProducts/interface/ScaleWeightGroupInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace gen {
inline bool isValidValue(float mu) const { return mu == 0.5 || mu == 1.0 || mu == 2.0; }

public:
static const unsigned int MIN_SCALE_VARIATIONS = 9;
ScaleWeightGroupInfo() : ScaleWeightGroupInfo("") {}
ScaleWeightGroupInfo(std::string header, std::string name)
: WeightGroupInfo(header, name), muIndices_(9, -1), dynVec_(9) {
Expand All @@ -43,15 +44,15 @@ namespace gen {
// Is a variation of the functional form of the dynamic scale
bool isFunctionalFormVariation();
void setIsFunctionalFormVariation(bool functionalVar) { isFunctionalFormVar_ = functionalVar; }
size_t centralIndex() const { return muIndices_.at(4); }
size_t muR1muF2Index() const { return muIndices_.at(5); }
size_t muR1muF05Index() const { return muIndices_.at(3); }
size_t muR2muF05Index() const { return muIndices_.at(6); }
size_t muR2muF1Index() const { return muIndices_.at(7); }
size_t muR2muF2Index() const { return muIndices_.at(8); }
size_t muR05muF05Index() const { return muIndices_.at(0); }
size_t muR05muF1Index() const { return muIndices_.at(1); }
size_t muR05muF2Index() const { return muIndices_.at(2); }
int centralIndex() const { return muIndices_.at(4); }
int muR1muF2Index() const { return muIndices_.at(5); }
int muR1muF05Index() const { return muIndices_.at(3); }
int muR2muF05Index() const { return muIndices_.at(6); }
int muR2muF1Index() const { return muIndices_.at(7); }
int muR2muF2Index() const { return muIndices_.at(8); }
int muR05muF05Index() const { return muIndices_.at(0); }
int muR05muF1Index() const { return muIndices_.at(1); }
int muR05muF2Index() const { return muIndices_.at(2); }
// dynweight version
size_t centralIndex(std::string& dynName) const { return getScaleIndex(4, dynName); }
size_t muR1muF2Index(std::string& dynName) const { return getScaleIndex(5, dynName); }
Expand Down

0 comments on commit f46cc33

Please sign in to comment.