CMS 3D CMS Logo

PreparePVTrends.h
Go to the documentation of this file.
1 #ifndef ALIGNMENT_OFFLINEVALIDATION_PREPAREPVTRENDS_H_
2 #define ALIGNMENT_OFFLINEVALIDATION_PREPAREPVTRENDS_H_
3 
4 #include "TArrow.h"
5 #include "TAxis.h"
6 #include "TCanvas.h"
7 #include "TF1.h"
8 #include "TFile.h"
9 #include "TGaxis.h"
10 #include "TGraph.h"
11 #include "TGraphAsymmErrors.h"
12 #include "TGraphErrors.h"
13 #include "TH1F.h"
14 #include "TH2F.h"
15 #include "TLatex.h"
16 #include "TLegend.h"
17 #include "TList.h"
18 #include "TMath.h"
19 #include "TObjArray.h"
20 #include "TObjString.h"
21 #include "TPad.h"
22 #include "TPaveText.h"
23 #include "TProcPool.h"
24 #include "TProfile.h"
25 #include "TROOT.h"
26 #include "TStyle.h"
27 #include "TSystem.h"
28 #include "TSystemDirectory.h"
29 #include "TSystemFile.h"
30 #include <TStopwatch.h>
31 #include <algorithm>
32 #include <bitset>
33 #include <fstream>
34 #include <functional>
35 #include <iostream>
36 #include <iterator>
37 #include <map>
38 #include <sstream>
39 #include <vector>
40 #include "boost/property_tree/ptree.hpp"
41 #include "boost/property_tree/json_parser.hpp"
42 
44 
48 #define logInfo std::cout << "INFO: "
49 #define logWarning std::cout << "WARNING: "
50 #define logError std::cout << "ERROR!!! "
51 
55 #define VERBOSE false
56 
57 namespace pv {
58  enum view { dxyphi, dzphi, dxyeta, dzeta, pT, generic };
59 
64  inline int closest(std::vector<int> const &vec, int value) {
65  auto const it = std::lower_bound(vec.begin(), vec.end(), value);
66  if (it == vec.end()) {
67  return -1;
68  }
69  return *it;
70  }
71 
72  const Int_t markers[8] = {kFullSquare,
73  kFullCircle,
74  kFullTriangleDown,
75  kOpenSquare,
76  kOpenCircle,
77  kFullTriangleUp,
78  kOpenTriangleDown,
79  kOpenTriangleUp};
80  const Int_t colors[8] = {kBlack, kRed, kBlue, kGreen + 2, kMagenta, kViolet, kCyan, kYellow};
81 
97  struct biases {
98  // contructor
99  biases(double mean, double rms, double wmean, double wrms, double min, double max, double chi2, int ndf, double ks) {
100  m_mean = mean;
101  m_rms = rms;
102  m_w_mean = wmean;
103  m_w_rms = wrms;
104  m_min = min;
105  m_max = max;
106  m_chi2 = chi2;
107  m_ndf = ndf;
108  m_ks = ks;
109  }
110 
111  // empty constructor
112  biases() { init(); }
113 
118  void init() {
119  m_mean = 0;
120  m_rms = 0.;
121  m_min = +999.;
122  m_max = -999.;
123  m_w_mean = 0.;
124  m_w_rms = 0.;
125  m_chi2 = -1.;
126  m_ndf = 0.;
127  m_ks = 9999.;
128  }
129 
130  double getMean() { return m_mean; }
131  double getWeightedMean() { return m_w_mean; }
132  double getRMS() { return m_rms; }
133  double getWeightedRMS() { return m_w_rms; }
134  double getMin() { return m_min; }
135  double getMax() { return m_max; }
136  double getChi2() { return m_chi2; }
137  double getNDF() { return m_ndf; }
138  double getNormChi2() { return double(m_chi2) / double(m_ndf); }
139  double getChi2Prob() { return TMath::Prob(m_chi2, m_ndf); }
140  double getKSScore() { return m_ks; }
141 
142  private:
143  double m_mean;
144  double m_min;
145  double m_max;
146  double m_rms;
147  double m_w_mean;
148  double m_w_rms;
149  double m_chi2;
150  int m_ndf;
151  double m_ks;
152  };
153 
167  struct wrappedTrends {
175  alignmentTrend lowerr,
176  alignmentTrend higherr,
178  alignmentTrend KS) {
179  logInfo << "pv::wrappedTrends c'tor" << std::endl;
180 
181  m_mean = mean;
182  m_low = low;
183  m_high = high;
184  m_lowerr = lowerr;
185  m_higherr = higherr;
186  m_chi2 = chi2;
187  m_KS = KS;
188  }
189 
190  alignmentTrend getMean() const { return m_mean; }
191  alignmentTrend getLow() const { return m_low; }
192  alignmentTrend getHigh() const { return m_high; }
193  alignmentTrend getLowErr() const { return m_lowerr; }
194  alignmentTrend getHighErr() const { return m_higherr; }
195  alignmentTrend getChi2() const { return m_chi2; }
196  alignmentTrend getKS() const { return m_KS; }
197 
198  private:
206  };
207 
217  struct bundle {
218  bundle(int nObjects, const TString &dataType, const TString &dataTypeLabel, const bool &useRMS) {
219  m_nObjects = nObjects;
220  m_datatype = dataType.Data();
221  m_datatypelabel = dataTypeLabel.Data();
222  m_useRMS = useRMS;
223 
224  logInfo << "pv::bundle c'tor: " << dataTypeLabel << " member: " << m_datatypelabel << std::endl;
225 
226  logInfo << m_axis_types << std::endl;
227  }
228 
229  int getNObjects() const { return m_nObjects; }
230  const char *getDataType() const { return m_datatype; }
231  const char *getDataTypeLabel() const { return m_datatypelabel; }
232  bool isUsingRMS() const { return m_useRMS; }
233  void printAll() {
234  logInfo << "dataType " << m_datatype << std::endl;
235  logInfo << "dataTypeLabel " << m_datatypelabel << std::endl;
236  }
237 
238  private:
240  const char *m_datatype;
241  const char *m_datatypelabel;
242  std::bitset<2> m_axis_types;
243  bool m_useRMS;
244  };
245 
246 } // namespace pv
247 
249 public:
250  PreparePVTrends(const char *outputFileName, int nWorkers, boost::property_tree::ptree &json);
252 
253  void setDirsAndLabels(boost::property_tree::ptree &json);
254 
255  void multiRunPVValidation(bool useRMS = true, TString lumiInputFile = "", bool doUnitTest = false);
256 
257  static pv::biases getBiases(TH1F *hist);
258  static unrolledHisto getUnrolledHisto(TH1F *hist);
259  static TH1F *drawConstantWithErr(TH1F *hist, Int_t iter, Double_t theConst);
260  static outPVtrends processData(size_t iter,
261  std::vector<int> intersection,
262  const Int_t nDirs_,
263  const char *dirs[10],
264  TString LegLabels[10],
265  bool useRMS,
266  const size_t nWorkers,
267  bool doUnitTest);
268  std::vector<int> list_files(const char *dirname = ".", const char *ext = ".root");
269  void outputGraphs(const pv::wrappedTrends &allInputs,
270  const std::vector<double> &ticks,
271  const std::vector<double> &ex_ticks,
272  TGraph *&g_mean,
273  TGraph *&g_chi2,
274  TGraph *&g_KS,
275  TGraph *&g_low,
276  TGraph *&g_high,
277  TGraphAsymmErrors *&g_asym,
278  TH1F *h_RMS[],
279  const pv::bundle &mybundle,
280  const pv::view &theView,
281  const int index,
282  const TString &label);
283 
284 private:
285  const char *outputFileName_;
286  const size_t nWorkers_; //def number of workers
287  std::vector<std::string> DirList;
288  std::vector<std::string> LabelList;
289 };
290 
291 #endif // ALIGNMENT_OFFLINEVALIDATION_PREPAREPVTRENDS_H_
bundle(int nObjects, const TString &dataType, const TString &dataTypeLabel, const bool &useRMS)
Structure biases Contains characterization of a single run PV bias plot.
Structure outPVtrends Contains the ensemble of all the alignmentTrends built by the functor...
Definition: OutPVtrends.h:88
double getMin()
alignmentTrend getHighErr() const
wrappedTrends(alignmentTrend mean, alignmentTrend low, alignmentTrend high, alignmentTrend lowerr, alignmentTrend higherr, alignmentTrend chi2, alignmentTrend KS)
Constructor of structure wrappedTrends, initialising all members from DMRs directly (with split) ...
std::vector< std::string > LabelList
double getWeightedRMS()
alignmentTrend m_low
nlohmann::json json
int closest(std::vector< int > const &vec, int value)
std::bitset< 2 > m_axis_types
double getChi2Prob()
int init
Definition: HydjetWrapper.h:66
alignmentTrend getMean() const
alignmentTrend getLowErr() const
double getMean()
alignmentTrend m_high
const char * m_datatype
Structure wrappedTrends Contains the ensemble vs run number of the alignmentTrend characterization...
double getNDF()
double getNormChi2()
biases(double mean, double rms, double wmean, double wrms, double min, double max, double chi2, int ndf, double ks)
double getKSScore()
#define logInfo
char const * label
Structure bundle Contains the ensemble of all the information to build the graphs alignmentTrends...
alignmentTrend m_higherr
alignmentTrend getHigh() const
double getMax()
alignmentTrend m_lowerr
const char * outputFileName_
alignmentTrend m_chi2
alignmentTrend getKS() const
Definition: value.py:1
double getRMS()
const char * getDataType() const
std::map< TString, std::vector< double > > alignmentTrend
Definition: OutPVtrends.h:44
std::vector< std::string > DirList
double getWeightedMean()
const size_t nWorkers_
alignmentTrend m_mean
void init()
initialising all members one by one
int getNObjects() const
Definition: colors.py:1
const char * m_datatypelabel
alignmentTrend getChi2() const
const Int_t markers[8]
def wmean(xlist)
Definition: plotscripts.py:77
alignmentTrend getLow() const
bool isUsingRMS() const
Definition: memstream.h:15
alignmentTrend m_KS
const char * getDataTypeLabel() const
double getChi2()