23 (it->second) =
nullptr;
32 (it->second) =
nullptr;
41 (it->second) =
nullptr;
53 if (
debug_ > 0) std::cout <<
"[HistoManager] DefineHistos" << std::endl;
54 std::string h_name =
"";
56 h_name =
m_name+
"_" + hist.key() ;
57 std::size_t found = (hist.key()).find_last_of(
"_");
58 std::string extension = hist.key().substr(found+1);
60 if (extension ==
"h") {
62 hist.value().at(
"bins"),
63 hist.value().at(
"minX"),
64 hist.value().at(
"maxX"));
66 std::string ytitle = hist.value().at(
"ytitle");
68 histos1d[h_name]->GetYaxis()->SetTitle(ytitle.c_str());
70 if (hist.value().contains(
"labels")) {
71 std::vector<std::string> labels = hist.value().at(
"labels").get<std::vector<std::string> >();
73 if (labels.size() < hist.value().at(
"bins")) {
74 std::cout<<
"Cannot apply labels to histogram:"<<h_name<<std::endl;
77 for (
int i = 1; i<=hist.value().at(
"bins");++i)
78 histos1d[h_name]->GetXaxis()->SetBinLabel(i,labels[i-1].c_str());
83 else if (extension ==
"hh") {
85 hist.value().at(
"xtitle"),hist.value().at(
"binsX"),hist.value().at(
"minX"),hist.value().at(
"maxX"),
86 hist.value().at(
"ytitle"),hist.value().at(
"binsY"),hist.value().at(
"minY"),hist.value().at(
"maxY"));
90 else if (extension ==
"hhh") {
92 hist.value().at(
"xtitle"),
93 hist.value().at(
"binsX"),
94 hist.value().at(
"minX"),
95 hist.value().at(
"maxX"),
96 hist.value().at(
"ytitle"),
97 hist.value().at(
"binsY"),
98 hist.value().at(
"minY"),
99 hist.value().at(
"maxY"),
100 hist.value().at(
"ztitle"),
101 hist.value().at(
"binsZ"),
102 hist.value().at(
"minZ"),
103 hist.value().at(
"maxZ"));
112 if (
debug_ > 0) std::cout <<
"[HistoManager] DefineHistos" << std::endl;
113 std::string h_name =
"";
116 std::cout<<hist.key()<<std::endl;
121 bool singleCopy =
true;
122 std::cout <<
"hist copy list size " << histoCopyNames.size() << std::endl;
123 for(
int i = 0; i < histoCopyNames.size(); i++){
124 h_name =
m_name+
"_" + hist.key() ;
125 if (histoCopyNames.size() > 1 && std::string(hist.key()).find(makeCopyJsonTag) != std::string::npos){
126 h_name =
m_name+
"_"+ histoCopyNames.at(i) +
"_" + hist.key() ;
129 std::size_t found = (hist.key()).find_last_of(
"_");
130 std::string extension = hist.key().substr(found+1);
132 std::cout <<
"DefineHisto: " << h_name << std::endl;
133 std::cout << extension << hist.value().at(
"xtitle") << std::endl;
135 if (extension ==
"h") {
137 hist.value().at(
"bins"),
138 hist.value().at(
"minX"),
139 hist.value().at(
"maxX"));
141 std::string ytitle = hist.value().at(
"ytitle");
143 histos1d[h_name]->GetYaxis()->SetTitle(ytitle.c_str());
145 if (hist.value().contains(
"labels")) {
146 std::vector<std::string> labels = hist.value().at(
"labels").get<std::vector<std::string> >();
148 if (labels.size() < hist.value().at(
"bins")) {
149 std::cout<<
"Cannot apply labels to histogram:"<<h_name<<std::endl;
152 for (
int i = 1; i<=hist.value().at(
"bins");++i)
153 histos1d[h_name]->GetXaxis()->SetBinLabel(i,labels[i-1].c_str());
158 else if (extension ==
"hh") {
160 hist.value().at(
"xtitle"),hist.value().at(
"binsX"),hist.value().at(
"minX"),hist.value().at(
"maxX"),
161 hist.value().at(
"ytitle"),hist.value().at(
"binsY"),hist.value().at(
"minY"),hist.value().at(
"maxY"));
175 TIter next(inFile->GetListOfKeys());
177 while ((key = (TKey*)next())) {
178 std::string classType = key->GetClassName();
179 if (classType.find(
"TH1")!=std::string::npos)
180 histos1d[key->GetName()] = (TH1F*) key->ReadObj();
181 if (classType.find(
"TH2")!=std::string::npos)
182 histos2d[key->GetName()] = (TH2F*) key->ReadObj();
183 if (classType.find(
"TH3")!=std::string::npos)
184 histos3d[key->GetName()] = (TH3F*) key->ReadObj();
189TH1F*
HistoManager::plot1D(
const std::string& name,
const std::string& xtitle,
int nbinsX,
float xmin,
float xmax) {
190 TH1F* h=
new TH1F(name.c_str(),name.c_str(),nbinsX,xmin,xmax);
191 h->GetXaxis()->SetTitle(xtitle.c_str());
189TH1F*
HistoManager::plot1D(
const std::string& name,
const std::string& xtitle,
int nbinsX,
float xmin,
float xmax) {
…}
197 TH1F* h=
new TH1F(name.c_str(),name.c_str(),nbinsX,axisX);
198 h->GetXaxis()->SetTitle(xtitle.c_str());
204 std::string xtitle,
int nbinsX,
float xmin,
float xmax,
205 std::string ytitle,
int nbinsY,
float ymin,
float ymax) {
207 TH2F* h =
new TH2F(name.c_str(),name.c_str(),
210 h->GetXaxis()->SetTitle(xtitle.c_str());
211 h->GetYaxis()->SetTitle(ytitle.c_str());
217 std::string xtitle,
int nbinsX,
double* axisX,
218 std::string ytitle,
int nbinsY,
double* axisY) {
220 TH2F * h =
new TH2F(name.c_str(),name.c_str(),
223 h->GetXaxis()->SetTitle(xtitle.c_str());
224 h->GetYaxis()->SetTitle(ytitle.c_str());
230 std::string xtitle,
int nbinsX,
const double* axisX,
231 std::string ytitle,
int nbinsY,
const double* axisY) {
233 TH2F * h =
new TH2F(name.c_str(),name.c_str(),
236 h->GetXaxis()->SetTitle(xtitle.c_str());
237 h->GetYaxis()->SetTitle(ytitle.c_str());
245 std::string xtitle,
int nbinsX,
double* axisX,
246 std::string ytitle,
int nbinsY,
float ymin,
float ymax) {
248 TH2F * h =
new TH2F(name.c_str(),name.c_str(),
251 h->GetXaxis()->SetTitle(xtitle.c_str());
252 h->GetYaxis()->SetTitle(ytitle.c_str());
259 std::string xtitle,
int nbinsX,
double* axisX,
260 std::string ytitle,
int nbinsY,
double* axisY,
261 std::string ztitle,
int nbinsZ,
double* axisZ) {
264 TH3F* h =
new TH3F(name.c_str(),name.c_str(),
270 h->GetXaxis()->SetTitle(xtitle.c_str());
271 h->GetYaxis()->SetTitle(ytitle.c_str());
272 h->GetZaxis()->SetTitle(ztitle.c_str());
281 std::string xtitle,
int nbinsX,
float xmin,
float xmax,
282 std::string ytitle,
int nbinsY,
float ymin,
float ymax,
283 std::string ztitle,
int nbinsZ,
float zmin,
float zmax) {
286 TH3F* h =
new TH3F(name.c_str(),name.c_str(),
291 h->GetXaxis()->SetTitle(xtitle.c_str());
292 h->GetYaxis()->SetTitle(ytitle.c_str());
293 h->GetZaxis()->SetTitle(ztitle.c_str());
304 std::cout<<it->first<<
" Null ptr in saving.."<<std::endl;
312 std::cout<<it->first<<
" Null ptr in saving.."<<std::endl;
320 std::cout<<it->first<<
" Null ptr in saving.."<<std::endl;
335 std::cout<<
"ERROR::Fill2DHisto Histogram not found! "<<
m_name+
"_"+histoName<<std::endl;
337 std::cout<<
"Fill2DHisto::Printed max number of warnings " <<
maxWarnings_ <<
". Stop"<<std::endl;
346 histos3d[
m_name+
"_"+histoName]->Fill(valuex,valuey,valuez, weight);
351 std::cout<<
"ERROR::Fill3DHisto Histogram not found! "<<
m_name+
"_"+histoName<<std::endl;
353 std::cout<<
"Fill3DHisto::Printed max number of warnings " <<
maxWarnings_ <<
". Stop"<<std::endl;
370 std::cout<<
"ERROR::Fill1DHisto Histogram not found! "<<
m_name+
"_"+histoName<<std::endl;
372 std::cout<<
"Fill1DHisto::Printed max number of warnings " <<
maxWarnings_ <<
". Stop"<<std::endl;
382 std::ifstream i_file(histoConfigFile);
386 std::cout << el.key() <<
" : " << el.value() <<
"\n";
396 if (outF) outF->cd();
397 TDirectory* dir{
nullptr};
398 std::cout<<folder.c_str()<<std::endl;
399 if (!folder.empty()) {
400 dir = outF->mkdir(folder.c_str());
405 std::cout<<it->first<<
" Null ptr in saving.."<<std::endl;
412 std::cout<<it->first<<
" Null ptr in saving.."<<std::endl;
420 std::cout<<it->first<<
" Null ptr in saving.."<<std::endl;
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.
bool doPrintWarnings_
description
virtual void GetHistosFromFile(TFile *inFile, const std::string &name, const std::string &folder="")
Get histograms from input file.
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
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
int maxWarnings_
description
std::map< std::string, TH3F * > histos3d
description
std::map< std::string, TH1F * > histos1d
description
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
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
std::string m_name
description
int printWarnings_
description
virtual void saveHistos(TFile *outF=nullptr, std::string folder="")
save histograms