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.
Loading...
Searching...
No Matches
HistoManager.h
Go to the documentation of this file.
1#ifndef HISTOMANAGER_H
2#define HISTOMANAGER_H
3
4#include <map>
5#include <string>
6#include <vector>
7
8#include "TDirectoryFile.h"
9#include "TFile.h"
10#include "TH1.h"
11#include "TH2.h"
12#include "TH3.h"
13#include "json.hpp"
14
15// for convenience
16using json = nlohmann::json;
17
24 public:
30
36 HistoManager(const std::string& inputName);
37
39 virtual ~HistoManager();
40
47 TH3* get3dHisto(const std::string& str) { return histos3d[str]; }
48
55 TH2* get2dHisto(const std::string& str) { return histos2d[str]; }
56
63 TH1* get1dHisto(const std::string& str) { return histos1d[str]; }
64
75 TH1F* plot1D(const std::string& name, const std::string& xtitle, int nbinsX, float xmin, float xmax);
76
86 TH1F* plot1D(const std::string& name, const std::string& xtitle, int nbinsX, double* axisX);
87
102 TH2F* plot2D(std::string name, std::string xtitle, int nbinsX, float xmin, float xmax, std::string ytitle,
103 int nbinsY, float ymin, float ymax);
104
117 TH2F* plot2D(std::string name, std::string xtitle, int nbinsX, double* axisX, std::string ytitle, int nbinsY,
118 double* axisY);
119
132 TH2F* plot2D(std::string name, std::string xtitle, int nbinsX, const double* axisX, std::string ytitle, int nbinsY,
133 const double* axisY);
134
148 TH2F* plot2D(std::string name, std::string xtitle, int nbinsX, double* axisX, std::string ytitle, int nbinsY,
149 float ymin, float ymax);
150
169 TH3F* plot3D(std::string name, std::string xtitle, int nbinsX, float xmin, float xmax, std::string ytitle,
170 int nbinsY, float ymin, float ymax, std::string ztitle, int nbinsZ, float zmin, float zmax);
171
187 TH3F* plot3D(std::string name, std::string xtitle, int nbinsX, double* axisX, std::string ytitle, int nbinsY,
188 double* axisY, std::string ztitle, int nbinsZ, double* axisZ);
189
190 // Additional histograms that might be defined by hand
195 virtual void Define3DHistos() {};
196
201 virtual void Define2DHistos() {};
202
207 virtual void Define1DHistos() {};
208
209 // Definition of histograms from json config
214 virtual void DefineHistos();
215
222 virtual void DefineHistos(std::vector<std::string> histoCopyNames,
223 std::string makeCopyJsonTag = "default=single_copy");
224
232 void Fill1DHisto(const std::string& histoName, float value, float weight = 1.);
233
242 void Fill2DHisto(const std::string& histoName, float valuex, float valuey, float weight = 1.);
243
253 void Fill3DHisto(const std::string& histoName, float valuex, float valuey, float valuez, float weight = 1.);
254
262 virtual void GetHistosFromFile(TFile* inFile, const std::string& name, const std::string& folder = "");
263
270 virtual void saveHistos(TFile* outF = nullptr, std::string folder = "");
271
277 virtual void loadHistoConfig(const std::string histoConfigFile);
278
283 virtual void sumw2();
284
289 virtual void Clear();
290
296 virtual std::string getName() { return m_name; }
297
303 void debugMode(bool debug) { debug_ = debug; }
304
305 std::vector<std::string> histos1dNamesfromTFile;
306 std::vector<std::string> histos2dNamesfromTFile;
307 std::vector<std::string> histos1dNamesfromJson;
308
309 protected:
310 std::string m_name;
311 std::map<std::string, std::vector<double>> Axes;
312 std::map<std::string, TH1*> histos1d;
313 typedef std::map<std::string, TH1*>::iterator it1d;
314 std::map<std::string, TH2*> histos2d;
315 typedef std::map<std::string, TH2*>::iterator it2d;
316 std::map<std::string, TH3*> histos3d;
317 typedef std::map<std::string, TH3*>::iterator it3d;
318
319 bool debug_{false};
321 int maxWarnings_{10};
323 bool doPrintWarnings_{true};
324};
325
326#endif
nlohmann::json json
virtual ~HistoManager()
std::map< std::string, TH2 * >::iterator it2d
description
void Fill2DHisto(const std::string &histoName, float valuex, float valuey, float weight=1.)
description
virtual void DefineHistos()
Definition of histograms from json config.
virtual void Define3DHistos()
define additional 3D histo by hand
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
TH1 * get1dHisto(const std::string &str)
description
virtual void Define2DHistos()
define additional 2D histo by hand
HistoManager()
default constructor
void Fill3DHisto(const std::string &histoName, float valuex, float valuey, float valuez, float weight=1.)
description
void debugMode(bool debug)
set debug
std::map< std::string, TH1 * >::iterator it1d
description
int maxWarnings_
description
std::map< std::string, TH1 * > histos1d
description
std::map< std::string, TH3 * >::iterator it3d
description
virtual void Define1DHistos()
define additional 1D histo by hand
virtual std::string getName()
get name
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
virtual void loadHistoConfig(const std::string histoConfigFile)
load histogram config
TH2 * get2dHisto(const std::string &str)
description
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
std::map< std::string, TH2 * > histos2d
description
TH3 * get3dHisto(const std::string &str)
description
bool debug_
description
std::map< std::string, TH3 * > histos3d
description
std::vector< std::string > histos1dNamesfromJson
description