hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HistoManager.h
Go to the documentation of this file.
1#ifndef HISTOMANAGER_H
2#define HISTOMANAGER_H
3
4#include "TH3.h"
5#include "TH2.h"
6#include "TH1.h"
7#include "TFile.h"
8#include "TDirectoryFile.h"
9#include <string>
10#include <map>
11#include <vector>
12#include "json.hpp"
13
14//for convenience
15using json = nlohmann::json;
16
23
24 public:
30
36 HistoManager(const std::string& inputName);
37
39 virtual ~HistoManager();
40
47 TH3F* get3dHisto(const std::string& str) {
48 return histos3d[str];
49 }
50
57 TH2F* get2dHisto(const std::string& str) {
58 return histos2d[str];
59 }
60
67 TH1F* get1dHisto(const std::string& str) {
68 return histos1d[str];
69 }
70
81 TH1F* plot1D(const std::string& name, const std::string& xtitle,
82 int nbinsX, float xmin, float xmax);
83
93 TH1F* plot1D(const std::string& name, const std::string& xtitle,
94 int nbinsX, double* axisX);
95
110 TH2F* plot2D(std::string name,
111 std::string xtitle, int nbinsX, float xmin, float xmax,
112 std::string ytitle, int nbinsY, float ymin, float ymax);
113
126 TH2F* plot2D(std::string name,
127 std::string xtitle, int nbinsX, double* axisX,
128 std::string ytitle, int nbinsY, double* axisY);
129
142 TH2F* plot2D(std::string name,
143 std::string xtitle, int nbinsX, const double* axisX,
144 std::string ytitle, int nbinsY, const double* axisY);
145
159 TH2F* plot2D(std::string name,
160 std::string xtitle, int nbinsX, double* axisX,
161 std::string ytitle, int nbinsY, float ymin, float ymax);
162
181 TH3F* plot3D(std::string name,
182 std::string xtitle, int nbinsX, float xmin, float xmax,
183 std::string ytitle, int nbinsY, float ymin, float ymax,
184 std::string ztitle, int nbinsZ, float zmin, float zmax);
185
201 TH3F* plot3D(std::string name,
202 std::string xtitle, int nbinsX, double* axisX,
203 std::string ytitle, int nbinsY, double* axisY,
204 std::string ztitle, int nbinsZ, double* axisZ);
205
206 // Additional histograms that might be defined by hand
211 virtual void Define3DHistos(){};
212
217 virtual void Define2DHistos(){};
218
223 virtual void Define1DHistos(){};
224
225 // Definition of histograms from json config
230 virtual void DefineHistos();
231
238 virtual void DefineHistos(std::vector<std::string> histoCopyNames,
239 std::string makeCopyJsonTag = "default=single_copy");
240
248 void Fill1DHisto(const std::string& histoName, float value, float weight=1.);
249
258 void Fill2DHisto(const std::string& histoName, float valuex, float valuey, float weight=1.);
259
260
270 void Fill3DHisto(const std::string& histoName, float valuex, float valuey, float valuez, float weight=1.);
271
272
273
281 virtual void GetHistosFromFile(TFile* inFile, const std::string& name,
282 const std::string& folder = "");
283
290 virtual void saveHistos(TFile* outF = nullptr, std::string folder = "");
291
297 virtual void loadHistoConfig(const std::string histoConfigFile);
298
303 virtual void sumw2();
304
309 virtual void Clear();
310
316 virtual std::string getName(){return m_name;}
317
323 void debugMode(bool debug) {debug_ = debug;}
324
325 std::vector<std::string> histos1dNamesfromTFile;
326 std::vector<std::string> histos2dNamesfromTFile;
327 std::vector<std::string> histos1dNamesfromJson;
328
329 protected:
330
331 std::string m_name;
332 std::map<std::string, std::vector<double>> Axes;
333 std::map<std::string, TH1F*> histos1d;
334 typedef std::map<std::string, TH1F*>::iterator it1d;
335 std::map<std::string, TH2F*> histos2d;
336 typedef std::map<std::string, TH2F*>::iterator it2d;
337 std::map<std::string, TH3F*> histos3d;
338 typedef std::map<std::string, TH3F*>::iterator it3d;
339
340 bool debug_{false};
342 int maxWarnings_{10};
344 bool doPrintWarnings_{true};
345
346};
347
348#endif
nlohmann::json json
nlohmann::json json
description
virtual ~HistoManager()
void Fill2DHisto(const std::string &histoName, float valuex, float valuey, float weight=1.)
description
std::map< std::string, TH2F * > histos2d
description
virtual void DefineHistos()
Definition of histograms from json config.
virtual void Define3DHistos()
define additional 3D histo by hand
TH1F * get1dHisto(const std::string &str)
description
bool doPrintWarnings_
description
virtual void GetHistosFromFile(TFile *inFile, const std::string &name, const std::string &folder="")
Get histograms from input file.
std::map< std::string, std::vector< double > > Axes
description
TH2F * plot2D(std::string name, std::string xtitle, int nbinsX, float xmin, float xmax, std::string ytitle, int nbinsY, float ymin, float ymax)
description
std::map< std::string, TH3F * >::iterator it3d
description
TH2F * get2dHisto(const std::string &str)
description
virtual void Define2DHistos()
define additional 2D histo by hand
HistoManager()
default constructor
std::map< std::string, TH1F * >::iterator it1d
description
void Fill3DHisto(const std::string &histoName, float valuex, float valuey, float valuez, float weight=1.)
description
void debugMode(bool debug)
set debug
int maxWarnings_
description
std::map< std::string, TH3F * > histos3d
description
virtual void Define1DHistos()
define additional 1D histo by hand
std::map< std::string, TH1F * > histos1d
description
virtual std::string getName()
get name
std::map< std::string, TH2F * >::iterator it2d
description
TH3F * plot3D(std::string name, std::string xtitle, int nbinsX, float xmin, float xmax, std::string ytitle, int nbinsY, float ymin, float ymax, std::string ztitle, int nbinsZ, float zmin, float zmax)
description
std::vector< std::string > histos2dNamesfromTFile
description
virtual void Clear()
description
void Fill1DHisto(const std::string &histoName, float value, float weight=1.)
description
virtual void sumw2()
description
TH1F * plot1D(const std::string &name, const std::string &xtitle, int nbinsX, float xmin, float xmax)
description
json _h_configs
description
TH3F * get3dHisto(const std::string &str)
description
virtual void loadHistoConfig(const std::string histoConfigFile)
load histogram config
std::vector< std::string > histos1dNamesfromTFile
description
std::string m_name
description
int printWarnings_
description
virtual void saveHistos(TFile *outF=nullptr, std::string folder="")
save histograms
bool debug_
description
std::vector< std::string > histos1dNamesfromJson
description