MaCh3  2.5.1
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 150 of file NuDockServerBase.cpp.

150  {
151 // ***************************************************************************
152  auto hist1d = dynamic_cast<const TH1D*>(mc_hist);
153  if (!hist1d) {
154  MACH3LOG_ERROR("{}: input histogram is not TH1D", __func__);
155  throw MaCh3Exception(__FILE__,__LINE__);
156  }
157  const TAxis *ax = mc_hist->GetXaxis();
158  std::string xtitle = ax->GetTitle();
159  int nxbins = ax->GetNbins();
160  std::vector<double> xbins(nxbins+1);
161  std::vector<double> binvals(nxbins);
162 
163  xbins[0] = ax->GetBinLowEdge(1);
164  for (int ix = 1; ix <= nxbins; ++ix) {
165  xbins[ix] = ax->GetBinUpEdge(ix);
166  binvals[ix-1] = mc_hist->GetBinContent(ix);
167  }
168  response["axis_titles"][sample_title] = {xtitle};
169  response["bin_edges"][sample_title] = {xbins};
170  response["bin_values"][sample_title] = binvals;
171 }
#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 174 of file NuDockServerBase.cpp.

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