69 MACH3LOG_ERROR(
"No arguments! Usage: {} <config.yaml> <file1.root> <file2.root> ...", argv[0]);
74 YAML::Node Settings =
M3OpenConfig(std::string(argv[1]));
75 auto OutFileName = GetFromManager<std::string>(Settings[
"General"][
"OutputFile"],
"LLHMap.root");
77 auto OutFile =
new TFile(
OutFileName.c_str(),
"UPDATE");
81 TDirectory* DirProfile1D = OutFile->mkdir(
"Profiled1D_LLH",
"profile1D",
true);
82 TDirectory* DirProfile2D = OutFile->mkdir(
"Profiled2D_LLH",
"profile2D",
true);
86 for(
int i = 2; i < argc; ++i)
96 auto ParamsOfInterest = GetFromManager<std::vector<std::string>>(Settings[
"LLHScan"][
"LLHParameters"],{});
97 std::vector<std::string> ParamsToProfile =
GetParams(ParamsOfInterest, LLHMap);
101 MACH3LOG_INFO(
"!!Assuming a uniform binning of the LLHScan!!");
103 MACH3LOG_INFO(
"... Starting generating 1D profiled log likelihoods ...");
106 for(
auto p : ParamsToProfile)
111 int nExpBins = GetFromManager<int>(Settings[
"LLHScan"][
"LLHScanPoints"], 20, __FILE__, __LINE__);
113 nExpBins = GetFromManager<int>(Settings[
"LLHScan"][
"ScanPoints"][p], nExpBins, __FILE__, __LINE__);
116 std::set<double> cBins;
117 auto checkBin = [&cBins](
double var) {
118 if(!(std::find(cBins.begin(), cBins.end(), var) != cBins.end())) cBins.emplace(var);
121 LLHMap.Foreach(checkBin, {p.c_str()});
123 if(nExpBins !=
int(cBins.size())) {
124 MACH3LOG_WARN(
"The config expects different number of {} bins for parameter {} than {} values included in LLHMap!", nExpBins, p, cBins.size());
125 nExpBins = int(cBins.size());
128 MACH3LOG_INFO(
"There are {} values (bins) for parameter {} inside LLHMap.", nExpBins, p);
131 double minx = LLHMap.Min(p.c_str()).GetValue();
132 double maxx = LLHMap.Max(p.c_str()).GetValue();
133 double binw = std::abs(maxx-minx)/double(nExpBins-1);
138 MACH3LOG_INFO(
"Generating a Profile1DLLH histogram for {} of {} bins from {} to {} (bin center at {} and {})", p, nExpBins, minx, maxx, minx+.5*binw, maxx-.5*binw);
140 std::string hTitle = p+
" profiled LLH";
141 std::string hName = p+
"_LLHProf1D";
142 TH1D* hprof1d =
new TH1D(hName.c_str(), hTitle.c_str(), nExpBins, minx, maxx);
146 for(
int bidx = 1; bidx < hprof1d->GetNbinsX() + 1; ++bidx)
148 const int count = int(
double(hprof1d->GetNbinsX())/
double(5));
149 if (bidx % count == 0)
152 auto b_lo = hprof1d->GetXaxis()->GetBinLowEdge(bidx);
153 auto b_hi = b_lo + hprof1d->GetXaxis()->GetBinWidth(bidx);
155 double llhmin = LLHMap.Filter(p+
">"+std::to_string(b_lo)+
"&&"+p+
"<"+std::to_string(b_hi)).Min(
"Total_LLH").GetValue();
158 hprof1d->SetBinContent(bidx, llhmin);
162 hprof1d->Write(hName.c_str(), TObject::kOverwrite);
165 MACH3LOG_INFO(
"... Starting generating 2D profiled log likelihoods ...");
168 std::vector<std::string> Strings2D;
171 for(
auto p1 : ParamsToProfile)
173 for(
auto p2 : ParamsToProfile)
178 if(std::find(Strings2D.begin(), Strings2D.end(), p2+
"_"+p1) != Strings2D.end())
181 std::string h1Name = p1+
"_LLHProf1D";
182 std::string h2Name = p2+
"_LLHProf1D";
185 auto h1 = DirProfile1D->Get<TH1D>(h1Name.c_str());
186 auto h2 = DirProfile1D->Get<TH1D>(h2Name.c_str());
189 int nx = h1->GetNbinsX();
190 double minx = h1->GetBinLowEdge(1);
191 double maxx = h1->GetBinLowEdge(nx)+h1->GetBinWidth(nx);
193 int ny = h2->GetNbinsX();
194 double miny = h2->GetBinLowEdge(1);
195 double maxy = h2->GetBinLowEdge(ny)+h2->GetBinWidth(ny);
197 std::string hTitle = p1+
" vs. "+p2+
" profiled LLH";
198 std::string hName = p1+
"_"+p2+
"_LLHProf2D";
199 TH2D* hprof2d =
new TH2D(hName.c_str(), hTitle.c_str(), nx, minx, maxx, ny, miny, maxy);
201 MACH3LOG_INFO(
"The 2D histogram has {} x-bins from {} to {} and {} y-bins from {} to {}", nx, minx, maxx, ny, miny, maxy);
203 for(
int bidx = 1; bidx < hprof2d->GetNbinsX() + 1; ++bidx)
205 for(
int bidy = 1; bidy < hprof2d->GetNbinsY() + 1; ++bidy)
207 const int count = int(
double(hprof2d->GetNbinsX()*hprof2d->GetNbinsY())/
double(5));
208 if ( ((bidx-1)*hprof2d->GetNbinsY() + bidy) % count == 0)
211 auto bx_lo = hprof2d->GetXaxis()->GetBinLowEdge(bidx);
212 auto bx_hi = bx_lo + hprof2d->GetXaxis()->GetBinWidth(bidx);
214 auto by_lo = hprof2d->GetYaxis()->GetBinLowEdge(bidy);
215 auto by_hi = by_lo + hprof2d->GetYaxis()->GetBinWidth(bidy);
217 double llhmin = LLHMap.Filter(p1+
">"+std::to_string(bx_lo)+
"&&"+p1+
"<"+std::to_string(bx_hi)+
"&&"+p2+
">"+std::to_string(by_lo)+
"&&"+p2+
"<"+std::to_string(by_hi)).Min(
"Total_LLH").GetValue();
220 hprof2d->SetBinContent(bidx, bidy, llhmin);
224 hprof2d->Write(hName.c_str(), TObject::kOverwrite);
226 Strings2D.push_back(p1+
"_"+p2);
std::vector< std::string > inpFileList
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
std::vector< std::string > GetParams(std::vector< std::string > &PoIs, ROOT::RDataFrame Map)
bool CheckNodeExists(const YAML::Node &node, Args... args)
KS: Wrapper function to call the recursive helper.
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Custom exception class used throughout MaCh3.
constexpr static const double _LARGE_LOGL_
Large Likelihood is used it parameter go out of physical boundary, this indicates in MCMC that such s...
void PrintProgressBar(const Long64_t Done, const Long64_t All)
KS: Simply print progress bar.
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.