130 auto canvas = std::make_unique<TCanvas>(
"canvas",
"canvas", 0, 0, 1024, 1024);
135 canvas->SetBottomMargin(0.1f);
136 canvas->SetTopMargin(0.02f);
137 canvas->SetRightMargin(0.08f);
138 canvas->SetLeftMargin(0.15f);
140 gStyle->SetOptTitle(0);
141 gStyle->SetOptStat(0);
142 gStyle->SetPalette(51);
147 TChain* Chain =
new TChain(
"posteriors",
"");
148 Chain->Add(inputFile.c_str());
151 TObjArray* brlis = Chain->GetListOfBranches();
154 int nBranches = brlis->GetEntries();
155 int RelevantBranches = 0;
156 for (
int i = 0; i < nBranches; i++)
159 TBranch* br =
static_cast<TBranch*
>(brlis->At(i));
164 TString bname = br->GetName();
167 if(bname.BeginsWith(
"xsec_"))
175 Chain->SetBranchStatus(
"*",
false);
177 std::vector<double> fParProp(RelevantBranches);
179 for (
int i = 0; i < RelevantBranches; ++i)
181 Chain->SetBranchStatus(
BranchNames[i].Data(),
true);
182 Chain->SetBranchAddress(
BranchNames[i].Data(), &fParProp[i]);
186 std::vector<std::string> SetsNames;
187 std::vector<std::vector<std::string>> RemoveNames;
188 std::vector<bool> Exclude;
189 std::vector<std::string> FancyTitle;
191 std::vector<std::vector<bool>> isRelevantParam;
192 std::vector<std::string> node = Settings[
"GetPenaltyTerm"][
"PenaltySets"].as<std::vector<std::string>>();
193 for (
unsigned int i = 0; i < node.size(); i++)
195 std::string ParName = node[i];
196 SetsNames.push_back(ParName);
198 const auto& Set = Settings[
"GetPenaltyTerm"][ParName];
200 RemoveNames.push_back(Set[0].as<std::vector<std::string>>());
201 Exclude.push_back(Set[1].as<bool>());
202 FancyTitle.push_back(Set[2].as<std::string>());
205 const int NSets = int(SetsNames.size());
207 isRelevantParam.resize(NSets);
209 for(
int i = 0; i < NSets; i++)
211 isRelevantParam[i].resize(
size);
214 for (
int j = 0; j <
size; j++)
216 isRelevantParam[i][j] =
false;
222 for (
unsigned int k = 0; k < RemoveNames[i].size(); k++)
224 if (
ParamNames[j].rfind(RemoveNames[i][k], 0) == 0)
231 isRelevantParam[i][j] =
true;
238 for (
unsigned int k = 0; k < RemoveNames[i].size(); k++)
240 if (
ParamNames[j].rfind(RemoveNames[i][k], 0) == 0)
242 isRelevantParam[i][j] =
true;
249 MACH3LOG_INFO(
" Found {} params for set {}", counter, SetsNames[i]);
252 int AllEvents = int(Chain->GetEntries());
253 std::vector<std::unique_ptr<TH1D>> hLogL(NSets);
254 for (
int i = 0; i < NSets; i++) {
255 std::string NameTemp =
"LogL_" + SetsNames[i];
256 hLogL[i] = std::make_unique<TH1D>(NameTemp.c_str(), NameTemp.c_str(), AllEvents, 0, AllEvents);
257 hLogL[i]->SetLineColor(kBlue);
259 std::vector<double> logL(NSets, 0.0);
260 for(
int n = 0; n < AllEvents; ++n)
266 for(
int k = 0; k < NSets; ++k) logL[k] = 0.;
269 double *logL_private =
nullptr;
273 #pragma omp parallel private(logL_private)
275 logL_private =
new double[NSets]();
276 for(
int k = 0; k < NSets; ++k) logL_private[k] = 0.;
279 for (
int i = 0; i <
size; i++)
281 for (
int j = 0; j <= i; ++j)
286 for(
int k = 0; k < NSets; ++k)
289 if (isRelevantParam[k][i] && isRelevantParam[k][j])
293 if(i != j) scale = 2;
301 for(
int k = 0; k < NSets; ++k)
304 logL[k] += logL_private[k];
307 delete[] logL_private;
311 for (
int i = 0; i <
size; i++)
313 for (
int j = 0; j <= i; ++j)
318 for(
int k = 0; k < NSets; ++k)
321 if (isRelevantParam[k][i] && isRelevantParam[k][j])
325 if(i != j) scale = 2;
333 for(
int k = 0; k < NSets; ++k)
335 hLogL[k]->SetBinContent(n, logL[k]);
340 std::string OutputName = inputFile +
"_PenaltyTerm" +
".root";
341 TFile* OutputFile =
new TFile(OutputName.c_str(),
"recreate");
342 TDirectory *PenaltyTermDir = OutputFile->mkdir(
"PenaltyTerm");
344 canvas->Print(Form(
"%s_PenaltyTerm.pdf[",inputFile.c_str()),
"pdf");
345 for(
int i = 0; i < NSets; i++)
347 const double Maximum = hLogL[i]->GetMaximum();
348 hLogL[i]->GetYaxis()->SetRangeUser(0., Maximum*1.2);
349 hLogL[i]->SetTitle(FancyTitle[i].c_str());
350 hLogL[i]->GetXaxis()->SetTitle(
"Step");
351 hLogL[i]->GetYaxis()->SetTitle(FancyTitle[i].c_str());
352 hLogL[i]->GetYaxis()->SetTitleOffset(1.4f);
356 PenaltyTermDir->cd();
359 canvas->Print(Form(
"%s_PenaltyTerm.pdf",inputFile.c_str()),
"pdf");
361 canvas->Print(Form(
"%s_PenaltyTerm.pdf]",inputFile.c_str()),
"pdf");
364 for (
int i = 0; i <
size; i++)
std::vector< double > nominal
std::vector< std::string > ParamNames
void ReadXSecFile(const std::string &inputFile)
std::vector< TString > BranchNames
std::vector< bool > isFlat
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Custom exception class for MaCh3 errors.
void PrintProgressBar(const Long64_t Done, const Long64_t All)
KS: Simply print progress bar.