1 #include "HistoStack.hxx" 29 _currentSystGroup =
"default";
43 std::map<std::string, TH1_h*>::iterator itm1;
44 std::map<std::string, TH2_h*>::iterator itm2;
45 for (itm2 = _h1.begin(); itm2 != _h1.end(); itm2++)
46 if (itm2->second)
delete itm2->second;
49 for (itm2 = _h2.begin(); itm2 != _h2.end(); itm2++)
50 if (itm2->second)
delete itm2->second;
53 for (itm2 = _h1w.begin(); itm2 != _h1w.end(); itm2++)
54 if (itm2->second)
delete itm2->second;
59 std::vector<TH1_h*>::iterator it1;
63 std::vector<TH2_h*>::iterator it2;
91 std::vector<TH1_h*>::reverse_iterator rit1;
93 if (strcmp((*rit1)->GetTitle(), title.c_str())==0)
105 if (index >= 0 && (UInt_t)index <
_histos1D.size()) {
118 std::vector<TH2_h*>::reverse_iterator rit1;
120 if (strcmp((*rit1)->GetTitle(), title.c_str())==0)
131 if (index >=0 && (UInt_t)index <
_histos2D.size()) {
143 Draw(1,1,1,0,root_opt,opt,
"",0);
148 void HistoStack::Draw(
int lc,
int lw,
int fc,
int fs,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_opt,
int mode) {
160 std::vector<TH1_h*>::reverse_iterator rit1;
168 _hall1D->SetName((std::string(ht->GetName()) +
"_cum").c_str());
169 _hall1D->SetTitle(ht->GetTitle());
176 _stack =
new THStack((std::string(ht->GetName()) +
"_stack").c_str(),
_title.c_str());
188 TH1_h* htp =
new TH1_h(*ht);
209 if (root_opt.find(
"same") == std::string::npos) {
210 _stack->Draw((
"HIST"+root_opt).c_str());
213 _stack->Draw((
"HIST"+root_opt).c_str());
215 _stack->Draw(
"HIST same");
226 _hall1D->Draw((root_opt+
"sames AXIS").c_str());
228 _hall1D->Draw((root_opt+
"AXIS").c_str());
232 _hall1D_draw->SetLineColor(lc);
233 _hall1D_draw->SetMarkerColor(lc);
234 _hall1D_draw->SetLineWidth(lw);
235 _hall1D_draw->SetFillColor(fc);
236 _hall1D_draw->SetFillStyle(fs);
240 _hall1D_draw->Draw(
"same e2");
244 _hall1D_draw->SetMarkerStyle(20);
245 _hall1D_draw->SetMarkerSize(1);
246 _hall1D_draw->Draw((root_opt+
"same").c_str());
258 std::vector<TH2_h*>::reverse_iterator rit1;
266 _hall2D->SetName((std::string(ht->GetName()) +
"_cum").c_str());
267 _hall2D->SetTitle(ht->GetTitle());
274 _stack =
new THStack((std::string(ht->GetName()) +
"_stack").c_str(),
_title.c_str());
289 if (root_opt.find(
"same") == std::string::npos) {
290 _stack->Draw((
"HIST "+root_opt).c_str());
293 _stack->Draw((
"HIST "+root_opt).c_str());
295 _stack->Draw(
"HIST same");
299 _hall2D->Draw(root_opt.c_str());
312 std::vector<TH1_h*>::iterator it1;
318 std::vector<TH2_h*>::iterator it1;
336 if (_currentSystGroup ==
"default"){
355 for (
int i=0;i<hsyst->GetNbinsX();i++){
357 double err_syst = hsyst->GetBinError(i+1)*
_hall1D_stat->GetBinContent(i+1);
362 _hall1D->SetBinError(i+1,err_total);
394 std::string group = _currentSystGroup;
397 std::cout <<
"Error in HistoStack::AddSystHistos !!! Current Systematics Group not specified !!!" << std::endl;
401 if (_h1.find(group)!=_h1.end()){
403 _h1w[group]->Add(h1w);
410 _h1[group] =
new TH2_h(*h1);
411 _h1[group]->SetName(
"h1p");
413 _h1w[group] =
new TH2_h(*h1w);
414 _h1w[group]->SetName(
"h1wp");
416 _h2[group] =
new TH2_h(*h2);
417 _h2[group]->SetName(
"h2p");
431 void HistoStack::Add(TH1_h* h1,
int lc,
int lw,
int fc,
int fs,
const std::string& leg) {
447 TH1_h* h1pp =
new TH1_h(*h1);
450 h1pp->SetFillColor(fc);
451 h1pp->SetLineColor(lc);
452 h1pp->SetLineWidth(lw);
453 h1pp->SetFillStyle(fs);
456 h1pp->SetMarkerStyle(21);
460 h1pp->SetTitle(leg.c_str());
483 TH2_h* h2pp =
new TH2_h(*h2);
486 h2pp->SetFillColor(fc);
487 h2pp->SetLineColor(lc);
488 h2pp->SetMarkerColor(lc);
492 h2pp->SetTitle(leg.c_str());
505 double integral =
_hall1D->GetSumOfWeights();
509 else if (area==1)
return;
525 std::vector<TH1_h*>::iterator it1;
528 ht->Scale(area/integral);
593 std::cout <<
"---------- Dumping HistoStack -----------" << std::endl;
595 std::vector<TH1_h*>::const_iterator rit1;
597 std::cout <<
" - " << (*rit1)->GetTitle() <<
" " << (*rit1)->GetEntries() << std::endl;
void Draw(int lc, int lw, int fc, int fs, const std::string &root_opt="", const std::string &opt="", const std::string &leg_opt="", int mode=0)
TH2_h * GetHisto2D(const std::string &title)
Returns one of the histos in the 2D stack. The title is used for comparison.
void ResetDrawHistos()
delete all temporary histos used for drawing the stak (with variable binning normalization) ...
void AddTotal(TH1_h *h1, TH1_h *hsyst=NULL)
Sets the total 1D histo if it does not exists or adds to the previous one when it exists...
TH1_h * GetHisto1D(const std::string &title)
Returns one of the histos in the 1D stack. The title is used for comparison.
void AddLegendEntry(TLegend *leg, TObject *ht, const std::string &type, const std::string &opt)
Add an entry to the Legend and resize it.
THStack * _stack
The root stack.
TH1_h * _hall1D_stat
The "total" 1D histogram with only stat errors.
void NormalizeVariableBinning(TH1 *h, int mode, const std::string &opt, Double_t &minwidth)
Normalize bin contents by bin width. return the with of the bin with minimum width.
void FillLegend(TLegend *leg)
Fill the legend with info in the HistoStack.
void AddSystHistosGroup(const std::string &group)
Add a new group of systemtic histos.
std::string _title
The title of the plot.
double GetMaximum(const std::string &opt="")
Get the maximum for the HistoStack.
void SetMinimum(double min)
Set the minimum for the HistoStack.
void NormalizeByArea(const std::string &uopt, double area=1)
normalize all histos in the stack by area
std::vector< std::string > _systHistosGroups
Histos for updating systematics when using several files.
HistoStack(const std::string &title, const std::string &titleX, const std::string &titleY)
std::vector< TH1_h * > _histos1D_draw
The TH1_hs that were added to the stack. Temporary histos used for drawing the stack (with variable b...
void SetMaximum(double max)
Set the maximum for the HistoStack.
TH1_h * _hall1D_syst
The "total" 1D histogram with only systematic errors.
void Add(TH1_h *h1, int lc, int lw, int fc, int fs, const std::string &leg)
Add a new 1D histogram to the stack, with fill colour "fc", line colour "lc".
void Print() const
Dump the stack contents.
TH1_h * _hall1D_draw
temporary histo used for drawing the total (with variable binning normalization)
std::vector< TH2_h * > _histos2D
The TH2_hs that were added to the stack.
void AddSystHistos(TH2_h *h1, TH2_h *h2, TH2_h *h1w)
Add histos for updating systematics when using several files.
double GetMaximumWithError(const std::string &opt="")
Get the maximum for the HistoStack taking into account the upper error.
void GetSystHistos(const std::string &group, TH2_h *&h1, TH2_h *&h2, TH2_h *&h1w)
Get Histos for updating systematics when using several files.
std::string _titleY
The title of the Y axis.
std::string _titleX
The title of the X axis.
bool CheckInternalOption(const std::string &uopt, const std::string &this_opt)
Check if specific option appears in option field (don't check if it exists: Added with AddOption) ...
std::vector< TH1_h * > _histos1D
The TH1_hs that were added to the stack.
bool CheckOption(const std::string &uopt, const std::string &this_opt)
Check if specific option exists, and if so if it appears in option field.