File indexing completed on 2024-04-06 11:56:55
0001 #ifndef ALIGNMENT_OFFLINEVALIDATION_PREPAREPVTRENDS_H_
0002 #define ALIGNMENT_OFFLINEVALIDATION_PREPAREPVTRENDS_H_
0003
0004 #include "TArrow.h"
0005 #include "TAxis.h"
0006 #include "TCanvas.h"
0007 #include "TF1.h"
0008 #include "TFile.h"
0009 #include "TGaxis.h"
0010 #include "TGraph.h"
0011 #include "TGraphAsymmErrors.h"
0012 #include "TGraphErrors.h"
0013 #include "TH1F.h"
0014 #include "TH2F.h"
0015 #include "TLatex.h"
0016 #include "TLegend.h"
0017 #include "TList.h"
0018 #include "TMath.h"
0019 #include "TObjArray.h"
0020 #include "TObjString.h"
0021 #include "TPad.h"
0022 #include "TPaveText.h"
0023 #include "TProcPool.h"
0024 #include "TProfile.h"
0025 #include "TROOT.h"
0026 #include "TStyle.h"
0027 #include "TSystem.h"
0028 #include "TSystemDirectory.h"
0029 #include "TSystemFile.h"
0030 #include <TStopwatch.h>
0031 #include <algorithm>
0032 #include <bitset>
0033 #include <fstream>
0034 #include <functional>
0035 #include <iostream>
0036 #include <iterator>
0037 #include <map>
0038 #include <sstream>
0039 #include <vector>
0040 #include "boost/property_tree/ptree.hpp"
0041 #include "boost/property_tree/json_parser.hpp"
0042
0043 #include "Alignment/OfflineValidation/interface/OutPVtrends.h"
0044
0045
0046
0047
0048 #define logInfo std::cout << "INFO: "
0049 #define logWarning std::cout << "WARNING: "
0050 #define logError std::cout << "ERROR!!! "
0051
0052
0053
0054
0055 #define VERBOSE false
0056
0057 namespace pv {
0058 enum view { dxyphi, dzphi, dxyeta, dzeta, pT, generic };
0059
0060
0061
0062
0063
0064 inline int closest(std::vector<int> const &vec, int value) {
0065 auto const it = std::lower_bound(vec.begin(), vec.end(), value);
0066 if (it == vec.end()) {
0067 return -1;
0068 }
0069 return *it;
0070 }
0071
0072 const Int_t markers[8] = {kFullSquare,
0073 kFullCircle,
0074 kFullTriangleDown,
0075 kOpenSquare,
0076 kOpenCircle,
0077 kFullTriangleUp,
0078 kOpenTriangleDown,
0079 kOpenTriangleUp};
0080 const Int_t colors[8] = {kBlack, kRed, kBlue, kGreen + 2, kMagenta, kViolet, kCyan, kYellow};
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 struct biases {
0098
0099 biases(double mean, double rms, double wmean, double wrms, double min, double max, double chi2, int ndf, double ks) {
0100 m_mean = mean;
0101 m_rms = rms;
0102 m_w_mean = wmean;
0103 m_w_rms = wrms;
0104 m_min = min;
0105 m_max = max;
0106 m_chi2 = chi2;
0107 m_ndf = ndf;
0108 m_ks = ks;
0109 }
0110
0111
0112 biases() { init(); }
0113
0114
0115
0116
0117
0118 void init() {
0119 m_mean = 0;
0120 m_rms = 0.;
0121 m_min = +999.;
0122 m_max = -999.;
0123 m_w_mean = 0.;
0124 m_w_rms = 0.;
0125 m_chi2 = -1.;
0126 m_ndf = 0.;
0127 m_ks = 9999.;
0128 }
0129
0130 double getMean() { return m_mean; }
0131 double getWeightedMean() { return m_w_mean; }
0132 double getRMS() { return m_rms; }
0133 double getWeightedRMS() { return m_w_rms; }
0134 double getMin() { return m_min; }
0135 double getMax() { return m_max; }
0136 double getChi2() { return m_chi2; }
0137 double getNDF() { return m_ndf; }
0138 double getNormChi2() { return double(m_chi2) / double(m_ndf); }
0139 double getChi2Prob() { return TMath::Prob(m_chi2, m_ndf); }
0140 double getKSScore() { return m_ks; }
0141
0142 private:
0143 double m_mean;
0144 double m_min;
0145 double m_max;
0146 double m_rms;
0147 double m_w_mean;
0148 double m_w_rms;
0149 double m_chi2;
0150 int m_ndf;
0151 double m_ks;
0152 };
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 struct wrappedTrends {
0168
0169
0170
0171
0172 wrappedTrends(alignmentTrend mean,
0173 alignmentTrend low,
0174 alignmentTrend high,
0175 alignmentTrend lowerr,
0176 alignmentTrend higherr,
0177 alignmentTrend chi2,
0178 alignmentTrend KS) {
0179 logInfo << "pv::wrappedTrends c'tor" << std::endl;
0180
0181 m_mean = mean;
0182 m_low = low;
0183 m_high = high;
0184 m_lowerr = lowerr;
0185 m_higherr = higherr;
0186 m_chi2 = chi2;
0187 m_KS = KS;
0188 }
0189
0190 alignmentTrend getMean() const { return m_mean; }
0191 alignmentTrend getLow() const { return m_low; }
0192 alignmentTrend getHigh() const { return m_high; }
0193 alignmentTrend getLowErr() const { return m_lowerr; }
0194 alignmentTrend getHighErr() const { return m_higherr; }
0195 alignmentTrend getChi2() const { return m_chi2; }
0196 alignmentTrend getKS() const { return m_KS; }
0197
0198 private:
0199 alignmentTrend m_mean;
0200 alignmentTrend m_low;
0201 alignmentTrend m_high;
0202 alignmentTrend m_lowerr;
0203 alignmentTrend m_higherr;
0204 alignmentTrend m_chi2;
0205 alignmentTrend m_KS;
0206 };
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217 struct bundle {
0218 bundle(int nObjects, const TString &dataType, const TString &dataTypeLabel, const bool &useRMS) {
0219 m_nObjects = nObjects;
0220 m_datatype = dataType.Data();
0221 m_datatypelabel = dataTypeLabel.Data();
0222 m_useRMS = useRMS;
0223
0224 logInfo << "pv::bundle c'tor: " << dataTypeLabel << " member: " << m_datatypelabel << std::endl;
0225
0226 logInfo << m_axis_types << std::endl;
0227 }
0228
0229 int getNObjects() const { return m_nObjects; }
0230 const char *getDataType() const { return m_datatype; }
0231 const char *getDataTypeLabel() const { return m_datatypelabel; }
0232 bool isUsingRMS() const { return m_useRMS; }
0233 void printAll() {
0234 logInfo << "dataType " << m_datatype << std::endl;
0235 logInfo << "dataTypeLabel " << m_datatypelabel << std::endl;
0236 }
0237
0238 private:
0239 int m_nObjects;
0240 const char *m_datatype;
0241 const char *m_datatypelabel;
0242 std::bitset<2> m_axis_types;
0243 bool m_useRMS;
0244 };
0245
0246 }
0247
0248 class PreparePVTrends {
0249 public:
0250 PreparePVTrends(const char *outputFileName, int nWorkers, boost::property_tree::ptree &json);
0251 ~PreparePVTrends() {}
0252
0253 void setDirsAndLabels(boost::property_tree::ptree &json);
0254
0255 void multiRunPVValidation(bool useRMS = true, TString lumiInputFile = "", bool doUnitTest = false);
0256
0257 static pv::biases getBiases(TH1F *hist);
0258 static unrolledHisto getUnrolledHisto(TH1F *hist);
0259 static TH1F *drawConstantWithErr(TH1F *hist, Int_t iter, Double_t theConst);
0260 static outPVtrends processData(size_t iter,
0261 std::vector<int> intersection,
0262 const Int_t nDirs_,
0263 const char *dirs[10],
0264 TString LegLabels[10],
0265 bool useRMS,
0266 const size_t nWorkers,
0267 bool doUnitTest);
0268 std::vector<int> list_files(const char *dirname = ".", const char *ext = ".root");
0269 void outputGraphs(const pv::wrappedTrends &allInputs,
0270 const std::vector<double> &ticks,
0271 const std::vector<double> &ex_ticks,
0272 TGraph *&g_mean,
0273 TGraph *&g_chi2,
0274 TGraph *&g_KS,
0275 TGraph *&g_low,
0276 TGraph *&g_high,
0277 TGraphAsymmErrors *&g_asym,
0278 TH1F *h_RMS[],
0279 const pv::bundle &mybundle,
0280 const pv::view &theView,
0281 const int index,
0282 const TString &label);
0283
0284 private:
0285 const char *outputFileName_;
0286 const size_t nWorkers_;
0287 std::vector<std::string> DirList;
0288 std::vector<std::string> LabelList;
0289 };
0290
0291 #endif