PandaRoot
PndHistoCombiner.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
28 #ifndef TOOLS_PNDHISTOCOMBINER_H_
29 #define TOOLS_PNDHISTOCOMBINER_H_
30 
31 #include <TObject.h>
32 #include <TString.h>
33 
34 #include <vector>
35 #include <map>
36 
37 #include "PndMultiCanvasCreator.h"
38 
39 #include "FairLogger.h"
40 
41 class TFile;
42 class TH1;
43 
44 class PndHistoCombiner : public TObject {
45  public:
46  struct fileData {
47  fileData(){};
48  fileData(TString fileName, TString shortName) : fFileName(fileName), fShortName(shortName){};
49  TString fFileName;
50  TString fShortName;
51  TFile *fFile = nullptr;
52 // Double_t fP = -1.;
53  };
54 
56  Double_t fChi2 = -1.; //< result/threshold for Chi2
57  Double_t fKol = -1.; //< result/threshold for Kolmogorov-Smirnov test
58  Double_t fAD = -1.; //< result/threshold for Anderson-Darling test
59  };
60 
62  virtual ~PndHistoCombiner();
63 
70  void AddFileNamesAndShortName(TString fileName, TString shortName)
71  {
72  fileData myData(fileName, shortName);
73  fFileData.push_back(myData);
74  }
75 
79  int GenerateHistos();
80 
84  int GenerateBranches();
85 
90  void AddHistoSelector(TString histoName) { fHistoSelector.push_back(histoName); }
91 
96  void AddBranchSelector(TString branchName) { fBranchSelector.push_back(branchName); }
97 
103  void SetPicPerCan(int val) { fCanCreator.SetPicPerCan(val); }
104  void SetCanvasPrefix(TString val) { fCanCreator.SetPrefix(val); }
105  void SetCanvasOutputDir(TString val) { fCanCreator.SetOutputDir(val); }
106  void SetCanvasOutputFormat(TString val) { fCanCreator.SetOutputFormat(val); }
107 
108  void SetPulls(bool dopulls = true)
109  {
110  fDoPulls = dopulls;
111 // SetDimensions(400, 400);
112  }
113 
114  void SetDimensions(int x = 400, int y = 300) { fCanCreator.SetDimensions(x, y); }
115 
121  void SetGlobalThresholds(double thresholdKol = 0.03, double thresholdChi2 = -1.0, double thresholdAD = -1.0)
122  {
123  fThresholds.clear();
124  AddHistoThresholds("", thresholdKol, thresholdChi2, thresholdAD);
125  }
126 
127  void AddHistoThresholds(TString histoName, double thresholdKol = 0.03, double thresholdChi2 = -1.0, double thresholdAD = -1.0){
128  histoComparisonValues thresholds;
129  thresholds.fKol = thresholdKol;
130  thresholds.fChi2 = thresholdChi2;
131  thresholds.fAD = thresholdAD;
132  fThresholds.push_back(std::make_pair(histoName, thresholds));
133  }
134 
135  void AddHistoThresholds(TString histoName, std::vector<double> thresholds){
136  if (thresholds.size() == 3)
137  AddHistoThresholds(histoName, thresholds[0], thresholds[1], thresholds[2]);
138  else {
139  LOG(warning) << "Wrong number of threshold values: " << histoName << " : " << thresholds.size();
140  }
141  }
142 
146  void SetCDashOutput(bool val = true) { fCreateCDashOutput = val; }
151  void CreateCDashOutput();
152 
153  protected:
154  void InitFiles();
155  bool CheckHistoName(TString histoName);
156  bool CheckBranchName(TString branchName);
157  bool CheckBranchType(TString branchType);
158  void DrawAndTestHistoStack(std::vector<TH1 *> &histos);
159  void DrawAndTest2DHistoStack(std::vector<TH1 *> &histos);
160  std::pair<TPad *, TPad *> SplitPadForPulls();
161  void DrawPulls(std::vector<TH1 *> &histos);
162  void CreateLegend(std::vector<TH1 *> &histos);
163  histoComparisonValues PerformTest(TH1 *h1, TH1 *h2);
164  bool TestPassed(TString& histoTitle, histoComparisonValues results, histoComparisonValues thresholds)
165  {
166  bool result = true;
167  if (thresholds.fKol > 0){
168  if (results.fKol < thresholds.fKol)
169  result = false;
170  histoTitle += " P(K)= ";
171  histoTitle += (TString::Format("%.2f", results.fKol));
172  }
173  if (thresholds.fChi2 > 0){
174  if (results.fChi2 < thresholds.fChi2)
175  result = false;
176  histoTitle += " /P(#Chi^{2})= ";
177  histoTitle += (TString::Format("%.2f", results.fChi2));
178  }
179  if (thresholds.fAD > 0){
180  if (results.fAD < thresholds.fAD)
181  result = false;
182  histoTitle += " /P(AD)= ";
183  histoTitle += (TString::Format("%.2f", results.fAD));
184  }
185  return result;
186  }
187 
191  void AddCDashOutput(TString prefix, TString histoName, histoComparisonValues value);
192 
193  TString RemoveSpecialCharacters(TString input);
194 
195  private:
196  std::vector<std::pair<TString, histoComparisonValues>> fThresholds; //< (part of) histogram name, thresholds for comaprison
197  std::vector<fileData> fFileData;
198  std::vector<TString> fHistoSelector;
199  std::vector<TString> fBranchSelector;
200  std::vector<TString> fCDashOutput;
201  PndMultiCanvasCreator fCanCreator;
202  bool fCreateCDashOutput = false;
203  int fFailCount = 0;
204  int fPadNumber = 0;
205  bool fDoPulls = false;
206 
207  ClassDef(PndHistoCombiner, 1);
208 };
209 
210 #endif /* TOOLS_PNDHISTOCOMBINER_H_ */
std::pair< TPad *, TPad * > SplitPadForPulls()
int GenerateHistos()
Main method to generate histograms.
TString RemoveSpecialCharacters(TString input)
histoComparisonValues PerformTest(TH1 *h1, TH1 *h2)
void DrawAndTest2DHistoStack(std::vector< TH1 *> &histos)
void SetPicPerCan(int val)
pictures per canvas. They will be organized in a quadratic way
void SetCanvasPrefix(TString val)
fileData(TString fileName, TString shortName)
Combines histograms with the same name from different files in one overlay histogram.
void AddHistoThresholds(TString histoName, std::vector< double > thresholds)
void SetGlobalThresholds(double thresholdKol=0.03, double thresholdChi2=-1.0, double thresholdAD=-1.0)
perform Kolmogorov or chi2 test between histograms of first file and all others.
void SetCDashOutput(bool val=true)
Select to generate output string automatically to upload data to CDASH server.
void CreateCDashOutput()
Generate output string to upload data to CDASH server This can be called automatically or by hand...
void AddCDashOutput(TString prefix, TString histoName, histoComparisonValues value)
Add to output string to upload data to CDASH server.
void AddHistoThresholds(TString histoName, double thresholdKol=0.03, double thresholdChi2=-1.0, double thresholdAD=-1.0)
bool CheckBranchName(TString branchName)
void AddFileNamesAndShortName(TString fileName, TString shortName)
Adds the file which contain the histos to be plotted together. First file is the one comparisons are ...
void SetCanvasOutputFormat(TString val)
Creates new canvasses once the number of histograms per canvas exceeds a setable threshold Automatic...
void AddHistoSelector(TString histoName)
Only those histograms are combined with part of their matching the histoName.
bool CheckHistoName(TString histoName)
void CreateLegend(std::vector< TH1 *> &histos)
void AddBranchSelector(TString branchName)
Only those branches are combined with part of their matching the branchName.
bool TestPassed(TString &histoTitle, histoComparisonValues results, histoComparisonValues thresholds)
void SetDimensions(int x=400, int y=300)
int GenerateBranches()
Main method to generate histograms from branches.
void SetCanvasOutputDir(TString val)
void SetPulls(bool dopulls=true)
bool CheckBranchType(TString branchType)
void DrawPulls(std::vector< TH1 *> &histos)
virtual ~PndHistoCombiner()
void DrawAndTestHistoStack(std::vector< TH1 *> &histos)