MaCh3  2.8.0
Reference Guide
Functions
NuDockServerBase.cpp File Reference
#include "NuDockServerBase.h"
#include "Samples/SampleHandlerBase.h"
Include dependency graph for NuDockServerBase.cpp:

Go to the source code of this file.

Functions

void TH1toResponse (const TH1 *mc_hist, const std::string &sample_title, nlohmann::json &response)
 
void TH2toResponse (const TH2 *mc_hist, const std::string &sample_title, nlohmann::json &response)
 

Function Documentation

◆ TH1toResponse()

void TH1toResponse ( const TH1 *  mc_hist,
const std::string &  sample_title,
nlohmann::json &  response 
)

Definition at line 149 of file NuDockServerBase.cpp.

149  {
150 // ***************************************************************************
151  auto hist1d = dynamic_cast<const TH1D*>(mc_hist);
152  if (!hist1d) {
153  MACH3LOG_ERROR("{}: input histogram is not TH1D", __func__);
154  throw MaCh3Exception(__FILE__,__LINE__);
155  }
156  const TAxis *ax = mc_hist->GetXaxis();
157  std::string xtitle = ax->GetTitle();
158  int nxbins = ax->GetNbins();
159  std::vector<double> xbins(nxbins+1);
160  std::vector<double> binvals(nxbins);
161 
162  xbins[0] = ax->GetBinLowEdge(1);
163  for (int ix = 1; ix <= nxbins; ++ix) {
164  xbins[ix] = ax->GetBinUpEdge(ix);
165  binvals[ix-1] = mc_hist->GetBinContent(ix);
166  }
167  response["axis_titles"][sample_title] = {xtitle};
168  response["bin_edges"][sample_title] = {xbins};
169  response["bin_values"][sample_title] = binvals;
170 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
Custom exception class used throughout MaCh3.

◆ TH2toResponse()

void TH2toResponse ( const TH2 *  mc_hist,
const std::string &  sample_title,
nlohmann::json &  response 
)

Definition at line 173 of file NuDockServerBase.cpp.

173  {
174 // ***************************************************************************
175  auto hist2d = dynamic_cast<const TH2D*>(mc_hist);
176  if (!hist2d) {
177  MACH3LOG_ERROR("{}: input histogram is not TH2D", __func__);
178  throw MaCh3Exception(__FILE__,__LINE__);
179  }
180  const TAxis *x_axis = mc_hist->GetXaxis();
181  std::string xtitle = x_axis->GetTitle();
182  int nxbins = x_axis->GetNbins();
183  std::vector<double> xbins(nxbins+1);
184 
185  const TAxis *y_axis = mc_hist->GetYaxis();
186  std::string ytitle = y_axis->GetTitle();
187  int nybins = y_axis->GetNbins();
188  std::vector<double> ybins(nybins+1);
189 
190  std::vector<std::vector<double>> binvals(nxbins, std::vector<double>(nybins));
191 
192  xbins[0] = x_axis->GetBinLowEdge(1);
193  ybins[0] = y_axis->GetBinLowEdge(1);
194  for (int ix = 1; ix <= nxbins; ++ix) {
195  for (int iy = 1; iy <= nybins; ++iy) {
196  xbins[ix] = x_axis->GetBinUpEdge(ix);
197  ybins[iy] = y_axis->GetBinUpEdge(iy);
198  binvals[ix-1][iy-1] = mc_hist->GetBinContent(ix, iy);
199  }
200  }
201  response["axis_titles"][sample_title] = {xtitle, ytitle};
202  response["bin_edges"][sample_title] = {xbins, ybins};
203  response["bin_values"][sample_title] = binvals;
204 }