Skip to content

Commit ae5dda7

Browse files
committed
The pattern for SetStandardBinName is no longer hard-coded
- Cleaned up related functions in Utilities - fixes #607
1 parent 7ed1564 commit ae5dda7

File tree

8 files changed

+50
-58
lines changed

8 files changed

+50
-58
lines changed

CombineHarvester/CombineTools/interface/Utilities.h

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,11 @@ std::vector<ch::Parameter> ExtractSampledFitParameters(RooFitResult const& res);
2929
// ---------------------------------------------------------------------------
3030
// Property matching & editing
3131
// ---------------------------------------------------------------------------
32-
void SetStandardBinNames(CombineHarvester & cb);
32+
void SetStandardBinNames(
33+
CombineHarvester& cb,
34+
std::string const& pattern = "$ANALYSIS_$CHANNEL_$BINID_$ERA");
3335

34-
template<class T>
35-
void SetStandardBinName(T *input) {
36-
std::string newname;
37-
newname = input->analysis() + "_"
38-
+ input->channel() + "_"
39-
+ boost::lexical_cast<std::string>(input->bin_id()) + "_"
40-
+ input->era();
41-
input->set_bin(newname);
42-
}
36+
void SetStandardBinName(ch::Object* obj, std::string pattern);
4337

4438
template<class T, class U>
4539
bool MatchingProcess(T const& first, U const& second) {
@@ -69,28 +63,7 @@ void SetProperties(T * first, U const* second) {
6963
first->set_mass(second->mass());
7064
}
7165

72-
73-
template<class T>
74-
void SetFromBinName(T *input, std::string parse_rules) {
75-
boost::replace_all(parse_rules, "$ANALYSIS", "(?<ANALYSIS>\\w+)");
76-
boost::replace_all(parse_rules, "$ERA", "(?<ERA>\\w+)");
77-
boost::replace_all(parse_rules, "$CHANNEL", "(?<CHANNEL>\\w+)");
78-
boost::replace_all(parse_rules, "$BINID", "(?<BINID>\\w+)");
79-
boost::replace_all(parse_rules, "$MASS", "(?<MASS>\\w+)");
80-
boost::regex rgx(parse_rules);
81-
boost::smatch matches;
82-
boost::regex_search(input->bin(), matches, rgx);
83-
if (matches.str("ANALYSIS").length())
84-
input->set_analysis(matches.str("ANALYSIS"));
85-
if (matches.str("ERA").length())
86-
input->set_era(matches.str("ERA"));
87-
if (matches.str("CHANNEL").length())
88-
input->set_channel(matches.str("CHANNEL"));
89-
if (matches.str("BINID").length())
90-
input->set_bin_id(boost::lexical_cast<int>(matches.str("BINID")));
91-
if (matches.str("MASS").length())
92-
input->set_mass(matches.str("MASS"));
93-
}
66+
void SetFromBinName(ch::Object *input, std::string parse_rules);
9467

9568
// ---------------------------------------------------------------------------
9669
// Rate scaling

CombineHarvester/CombineTools/src/Utilities.cc

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,46 @@ std::vector<ch::Parameter> ExtractSampledFitParameters(
4747
// ---------------------------------------------------------------------------
4848
// Property matching & editing
4949
// ---------------------------------------------------------------------------
50-
void SetStandardBinNames(CombineHarvester & cb) {
51-
cb.ForEachObs(ch::SetStandardBinName<ch::Observation>);
52-
cb.ForEachProc(ch::SetStandardBinName<ch::Process>);
53-
cb.ForEachSyst(ch::SetStandardBinName<ch::Systematic>);
50+
void SetStandardBinNames(CombineHarvester& cb, std::string const& pattern) {
51+
cb.ForEachObj([&](ch::Object* obj) {
52+
ch::SetStandardBinName(obj, pattern);
53+
});
5454
}
5555

56+
void SetStandardBinName(ch::Object* obj, std::string pattern) {
57+
boost::replace_all(pattern, "$BINID",
58+
boost::lexical_cast<std::string>(obj->bin_id()));
59+
boost::replace_all(pattern, "$BIN", obj->bin());
60+
boost::replace_all(pattern, "$PROCESS", obj->process());
61+
boost::replace_all(pattern, "$MASS", obj->mass());
62+
boost::replace_all(pattern, "$ERA", obj->era());
63+
boost::replace_all(pattern, "$CHANNEL", obj->channel());
64+
boost::replace_all(pattern, "$ANALYSIS", obj->analysis());
65+
obj->set_bin(pattern);
66+
}
67+
68+
void SetFromBinName(ch::Object *input, std::string parse_rules) {
69+
boost::replace_all(parse_rules, "$ANALYSIS", "(?<ANALYSIS>\\w+)");
70+
boost::replace_all(parse_rules, "$ERA", "(?<ERA>\\w+)");
71+
boost::replace_all(parse_rules, "$CHANNEL", "(?<CHANNEL>\\w+)");
72+
boost::replace_all(parse_rules, "$BINID", "(?<BINID>\\w+)");
73+
boost::replace_all(parse_rules, "$MASS", "(?<MASS>\\w+)");
74+
boost::regex rgx(parse_rules);
75+
boost::smatch matches;
76+
boost::regex_search(input->bin(), matches, rgx);
77+
if (matches.str("ANALYSIS").length())
78+
input->set_analysis(matches.str("ANALYSIS"));
79+
if (matches.str("ERA").length())
80+
input->set_era(matches.str("ERA"));
81+
if (matches.str("CHANNEL").length())
82+
input->set_channel(matches.str("CHANNEL"));
83+
if (matches.str("BINID").length())
84+
input->set_bin_id(boost::lexical_cast<int>(matches.str("BINID")));
85+
if (matches.str("MASS").length())
86+
input->set_mass(matches.str("MASS"));
87+
}
88+
89+
5690
// ---------------------------------------------------------------------------
5791
// Rate scaling
5892
// ---------------------------------------------------------------------------

CombineHarvester/CombineTools/test/MSSMYieldTable.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,8 @@ int main(int argc, char* argv[]) {
164164
cmb.ParseDatacard(d, "", "", "", 0, signal_mass);
165165
}
166166

167-
cmb.ForEachSyst(boost::bind(ch::SetFromBinName<ch::Systematic>, _1,
167+
cmb.ForEachObj(boost::bind(ch::SetFromBinName, _1,
168168
"$ANALYSIS_$CHANNEL_$BINID_$ERA"));
169-
cmb.ForEachObs(boost::bind(ch::SetFromBinName<ch::Observation>, _1,
170-
"$ANALYSIS_$CHANNEL_$BINID_$ERA"));
171-
cmb.ForEachProc(boost::bind(ch::SetFromBinName<ch::Process>, _1,
172-
"$ANALYSIS_$CHANNEL_$BINID_$ERA"));
173169

174170
cmb.cp().signals().ForEachProc([&](ch::Process *p) {
175171
p->set_rate(p->rate() * d_tanb);

CombineHarvester/CombineTools/test/MSSMtauptYieldTable.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,8 @@ int main(int argc, char* argv[]) {
179179
cmb.ParseDatacard(d, "", "", "", 0, signal_mass);
180180
}
181181

182-
cmb.ForEachSyst(boost::bind(ch::SetFromBinName<ch::Systematic>, _1,
182+
cmb.ForEachObj(boost::bind(ch::SetFromBinName, _1,
183183
"$ANALYSIS_$CHANNEL_$BINID_$ERA"));
184-
cmb.ForEachObs(boost::bind(ch::SetFromBinName<ch::Observation>, _1,
185-
"$ANALYSIS_$CHANNEL_$BINID_$ERA"));
186-
cmb.ForEachProc(boost::bind(ch::SetFromBinName<ch::Process>, _1,
187-
"$ANALYSIS_$CHANNEL_$BINID_$ERA"));
188184

189185
cmb.cp().signals().ForEachProc([&](ch::Process *p) {
190186
p->set_rate(p->rate() * d_tanb);

CombineHarvester/CombineTools/test/NuisanceSummary.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ int main(int argc, char* argv[]) {
4040
cmb.ParseDatacard(d, parse_rule);
4141
}
4242

43-
cmb.ForEachSyst(ch::SetStandardBinName<ch::Systematic>);
44-
cmb.ForEachObs(ch::SetStandardBinName<ch::Observation>);
45-
cmb.ForEachProc(ch::SetStandardBinName<ch::Process>);
43+
ch::SetStandardBinNames(cmb);
4644
// cmb.PrintAll();
4745

4846
if (fitresult_file.length()) {

CombineHarvester/CombineTools/test/SBWeighted.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ int main(int argc, char* argv[]){
6565
for (auto const& d : datacards) {
6666
cmb.ParseDatacard(d, parse_rule);
6767
}
68-
cmb.ForEachSyst(ch::SetStandardBinName<ch::Systematic>);
69-
cmb.ForEachObs(ch::SetStandardBinName<ch::Observation>);
70-
cmb.ForEachProc(ch::SetStandardBinName<ch::Process>);
68+
ch::SetStandardBinNames(cmb);
7169

7270
RooFitResult* fitresult = nullptr;
7371
if (fitresult_file.length() && postfit) {

CombineHarvester/CombineTools/test/SOBPlot.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ int main(int argc, char* argv[]){
147147
for (auto const& d : datacards) {
148148
cmb.ParseDatacard(d, parse_rule);
149149
}
150-
cmb.ForEachSyst(ch::SetStandardBinName<ch::Systematic>);
151-
cmb.ForEachObs(ch::SetStandardBinName<ch::Observation>);
152-
cmb.ForEachProc(ch::SetStandardBinName<ch::Process>);
150+
ch::SetStandardBinNames(cmb);
153151

154152
RooFitResult *fitresult = nullptr;
155153
if (fitresult_file.length() && postfit) {

CombineHarvester/CombineTools/test/YieldTable.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ int main(int argc, char* argv[]){
6969
for (auto const& d : datacards) {
7070
cmb.ParseDatacard(d, parse_rule);
7171
}
72-
cmb.ForEachSyst(ch::SetStandardBinName<ch::Systematic>);
73-
cmb.ForEachObs(ch::SetStandardBinName<ch::Observation>);
74-
cmb.ForEachProc(ch::SetStandardBinName<ch::Process>);
72+
ch::SetStandardBinNames(cmb);
73+
7574

7675
RooFitResult *fitresult = nullptr;
7776
if (fitresult_file.length() && postfit) {

0 commit comments

Comments
 (0)