PandaRoot
PndHistoCombiner.h
Go to the documentation of this file.
1 
16 #ifndef TOOLS_PNDHISTOCOMBINER_H_
17 #define TOOLS_PNDHISTOCOMBINER_H_
18 
19 #include <TObject.h>
20 #include <TString.h>
21 
22 #include <vector>
23 #include <map>
24 
25 #include "PndMultiCanvasCreator.h"
26 
27 #include "FairLogger.h"
28 
29 class TFile;
30 class TH1;
31 
32 class PndHistoCombiner : public TObject {
33  public:
34  struct fileData {
35  fileData(){};
36  fileData(TString fileName, TString shortName) : fFileName(fileName), fShortName(shortName){};
37  TString fFileName;
38  TString fShortName;
39  TFile *fFile = nullptr;
40 // Double_t fP = -1.;
41  };
42 
44  Double_t fChi2 = -1.; //< result/threshold for Chi2
45  Double_t fKol = -1.; //< result/threshold for Kolmogorov-Smirnov test
46  Double_t fAD = -1.; //< result/threshold for Anderson-Darling test
47  };
48 
50  virtual ~PndHistoCombiner();
51 
58  void AddFileNamesAndShortName(TString fileName, TString shortName)
59  {
60  fileData myData(fileName, shortName);
61  fFileData.push_back(myData);
62  }
63 
67  int GenerateHistos();
68 
72  int GenerateBranches();
73 
78  void AddHistoSelector(TString histoName) { fHistoSelector.push_back(histoName); }
79 
84  void AddBranchSelector(TString branchName) { fBranchSelector.push_back(branchName); }
85 
91  void SetPicPerCan(int val) { fCanCreator.SetPicPerCan(val); }
92  void SetCanvasPrefix(TString val) { fCanCreator.SetPrefix(val); }
93  void SetCanvasOutputDir(TString val) { fCanCreator.SetOutputDir(val); }
94  void SetCanvasOutputFormat(TString val) { fCanCreator.SetOutputFormat(val); }
95 
96  void SetPulls(bool dopulls = true)
97  {
98  fDoPulls = dopulls;
99 // SetDimensions(400, 400);
100  }
101 
102  void SetDimensions(int x = 400, int y = 300) { fCanCreator.SetDimensions(x, y); }
103 
109  void SetGlobalThresholds(double thresholdKol = 0.03, double thresholdChi2 = -1.0, double thresholdAD = -1.0)
110  {
111  fThresholds.clear();
112  AddHistoThresholds("", thresholdKol, thresholdChi2, thresholdAD);
113  }
114 
115  void AddHistoThresholds(TString histoName, double thresholdKol = 0.03, double thresholdChi2 = -1.0, double thresholdAD = -1.0){
116  histoComparisonValues thresholds;
117  thresholds.fKol = thresholdKol;
118  thresholds.fChi2 = thresholdChi2;
119  thresholds.fAD = thresholdAD;
120  fThresholds.push_back(std::make_pair(histoName, thresholds));
121  }
122 
123  void AddHistoThresholds(TString histoName, std::vector<double> thresholds){
124  if (thresholds.size() == 3)
125  AddHistoThresholds(histoName, thresholds[0], thresholds[1], thresholds[2]);
126  else {
127  LOG(warning) << "Wrong number of threshold values: " << histoName << " : " << thresholds.size();
128  }
129  }
130 
134  void SetCDashOutput(bool val = true) { fCreateCDashOutput = val; }
139  void CreateCDashOutput();
140 
141  protected:
142  void InitFiles();
143  bool CheckHistoName(TString histoName);
144  bool CheckBranchName(TString branchName);
145  bool CheckBranchType(TString branchType);
146  void DrawAndTestHistoStack(std::vector<TH1 *> &histos);
147  void DrawAndTest2DHistoStack(std::vector<TH1 *> &histos);
148  std::pair<TPad *, TPad *> SplitPadForPulls();
149  void DrawPulls(std::vector<TH1 *> &histos);
150  void CreateLegend(std::vector<TH1 *> &histos);
151  histoComparisonValues PerformTest(TH1 *h1, TH1 *h2);
152  bool TestPassed(TString& histoTitle, histoComparisonValues results, histoComparisonValues thresholds)
153  {
154  bool result = true;
155  if (thresholds.fKol > 0){
156  if (results.fKol < thresholds.fKol)
157  result = false;
158  histoTitle += " P(K)= ";
159  histoTitle += (TString::Format("%.2f", results.fKol));
160  }
161  if (thresholds.fChi2 > 0){
162  if (results.fChi2 < thresholds.fChi2)
163  result = false;
164  histoTitle += " /P(#Chi^{2})= ";
165  histoTitle += (TString::Format("%.2f", results.fChi2));
166  }
167  if (thresholds.fAD > 0){
168  if (results.fAD < thresholds.fAD)
169  result = false;
170  histoTitle += " /P(AD)= ";
171  histoTitle += (TString::Format("%.2f", results.fAD));
172  }
173  return result;
174  }
175 
179  void AddCDashOutput(TString prefix, TString histoName, histoComparisonValues value);
180 
181  TString RemoveSpecialCharacters(TString input);
182 
183  private:
184  std::vector<std::pair<TString, histoComparisonValues>> fThresholds; //< (part of) histogram name, thresholds for comaprison
185  std::vector<fileData> fFileData;
186  std::vector<TString> fHistoSelector;
187  std::vector<TString> fBranchSelector;
188  std::vector<TString> fCDashOutput;
189  PndMultiCanvasCreator fCanCreator;
190  bool fCreateCDashOutput = false;
191  int fFailCount = 0;
192  int fPadNumber = 0;
193  bool fDoPulls = false;
194 
195  ClassDef(PndHistoCombiner, 1);
196 };
197 
198 #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)