File indexing completed on 2024-11-06 06:06:08
0001 #ifndef ALIGNMENT_OFFLINEVALIDATION_PLOTALIGNNMENTVALIDATION_H_
0002 #define ALIGNMENT_OFFLINEVALIDATION_PLOTALIGNNMENTVALIDATION_H_
0003
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "Alignment/OfflineValidation/interface/TkAlStyle.h"
0006 #include "Alignment/OfflineValidation/interface/TkOffTreeVariables.h"
0007
0008 #include "Math/ProbFunc.h"
0009
0010 #include "TAxis.h"
0011 #include "TCanvas.h"
0012 #include "TDirectory.h"
0013 #include "TDirectoryFile.h"
0014 #include "TF1.h"
0015 #include "TFile.h"
0016 #include "TFrame.h"
0017 #include "TGaxis.h"
0018 #include "TH2F.h"
0019 #include "THStack.h"
0020 #include "TKey.h"
0021 #include "TLatex.h"
0022 #include "TLegend.h"
0023 #include "TLegendEntry.h"
0024 #include "TPad.h"
0025 #include "TPaveStats.h"
0026 #include "TPaveText.h"
0027 #include "TProfile.h"
0028 #include "TRandom3.h"
0029 #include "TRegexp.h"
0030 #include "TROOT.h"
0031 #include "TString.h"
0032 #include "TStyle.h"
0033 #include "TSystem.h"
0034 #include "TTree.h"
0035 #include "TTreeReader.h"
0036
0037 #include <algorithm>
0038 #include <cmath>
0039 #include <cstdio>
0040 #include <cstdlib>
0041 #include <exception>
0042 #include <fstream>
0043 #include <iostream>
0044 #include <memory>
0045 #include <sstream>
0046 #include <string>
0047 #include <vector>
0048
0049 class TkOfflineVariables {
0050 public:
0051 TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName = "", int color = 1, int style = 1);
0052 ~TkOfflineVariables();
0053 int getLineColor() { return lineColor; }
0054 int getLineStyle() { return lineStyle; }
0055 std::string getName() { return legendName; }
0056 TTree* getTree() { return tree; }
0057 TFile* getFile() { return file; }
0058 int getPhase() { return phase; }
0059
0060 private:
0061 TFile* file;
0062 TTree* tree;
0063 int lineColor;
0064 int lineStyle;
0065 int phase;
0066 std::string legendName;
0067 };
0068
0069 inline TkOfflineVariables::TkOfflineVariables(
0070 std::string fileName, std::string baseDir, std::string legName, int lColor, int lStyle) {
0071 lineColor = lColor;
0072 lineStyle = lStyle % 100;
0073 if (legName.empty()) {
0074 int start = 0;
0075 if (fileName.find('/'))
0076 start = fileName.find_last_of('/') + 1;
0077 int stop = fileName.find_last_of('.');
0078 legendName = fileName.substr(start, stop - start);
0079 } else {
0080 legendName = legName;
0081 }
0082
0083
0084 file = TFile::Open(fileName.c_str());
0085 TDirectoryFile* d = nullptr;
0086 if (file->Get(baseDir.c_str())) {
0087 d = (TDirectoryFile*)file->Get(baseDir.c_str());
0088 if ((*d).Get("TkOffVal")) {
0089 tree = (TTree*)(*d).Get("TkOffVal");
0090 } else {
0091 std::cout << "no tree named TkOffVal" << std::endl;
0092 assert(false);
0093 }
0094 TDirectoryFile* d2 = (TDirectoryFile*)d->Get("Pixel");
0095 assert(d2);
0096 phase = (int)((bool)d2->Get("P1PXBBarrel_1"));
0097 } else {
0098 std::cout << "no directory named " << baseDir.c_str() << std::endl;
0099 assert(false);
0100 }
0101 }
0102
0103 inline TkOfflineVariables::~TkOfflineVariables() { delete file; }
0104
0105 class PlotAlignmentValidation {
0106 public:
0107
0108 PlotAlignmentValidation(bool bigtext = false);
0109 PlotAlignmentValidation(
0110 const char* inputFile, std::string fileName = "", int lineColor = 1, int lineStyle = 1, bool bigtext = false);
0111 ~PlotAlignmentValidation();
0112 void loadFileList(const char* inputFile, std::string fileName = "", int lineColor = 2, int lineStyle = 1);
0113 void useFitForDMRplots(bool usefit = false);
0114 void legendOptions(TString options);
0115 void plotOutlierModules(const char* outputFileName = "OutlierModules.ps",
0116 std::string plotVariable = "chi2PerDofX",
0117 float chi2_cut = 10,
0118 unsigned int minHits = 50);
0119 void plotSubDetResiduals(
0120 bool plotNormHisto = false,
0121 unsigned int subDetId =
0122 7);
0123 void plotDMR(const std::string& plotVar = "medianX",
0124 Int_t minHits = 50,
0125 const std::string& options = "plain",
0126 const std::string& filterName = "",
0127 Float_t maxBadLumiPixel = 0.5,
0128 Float_t maxBadLumiStrip = 7.0);
0129
0130
0131
0132
0133
0134
0135
0136 void plotSurfaceShapes(const std::string& options = "layers", const std::string& variable = "");
0137 void plotChi2(const char* inputFile);
0138
0139 void plotHitMaps();
0140 void setOutputDir(std::string dir);
0141 void setTreeBaseDir(std::string dir = "TrackerOfflineValidation");
0142
0143 void residual_by_moduleID(unsigned int moduleid);
0144 int numberOfLayers(int phase, int subdetector);
0145 int maxNumberOfLayers(int subdetector);
0146
0147 THStack* addHists(
0148 const TString& selection,
0149 const TString& residType = "xPrime",
0150 TLegend** myLegend = nullptr,
0151 bool printModuleIds = false,
0152 bool validforphase0 =
0153 false);
0154
0155 float twotailedStudentTTestEqualMean(float t, float v);
0156
0157
0158
0159 struct DMRPlotInfo {
0160 std::string variable;
0161 int nbins;
0162 double min, max;
0163 int minHits;
0164 bool plotPlain, plotSplits, plotLayers;
0165 int subDetId, nLayers;
0166 THStack* hstack;
0167 TLegend* legend;
0168 TkOfflineVariables* vars;
0169 float maxY;
0170 TH1F* h;
0171 TH1F* h1;
0172 TH1F* h2;
0173 bool firsthisto;
0174 std::string filterName;
0175 float maxBadLumiPixel;
0176 float maxBadLumiStrip;
0177 };
0178
0179 private:
0180 TList* getTreeList();
0181 std::string treeBaseDir;
0182
0183 bool useFit_;
0184 bool showMean_;
0185 bool showRMS_;
0186 bool showMeanError_;
0187 bool showRMSError_;
0188 bool showModules_;
0189 bool showUnderOverFlow_;
0190 bool twolines_;
0191 bool bigtext_;
0192 const static TString summaryfilename;
0193 std::ofstream summaryfile;
0194 bool openedsummaryfile = false;
0195 TFile* rootsummaryfile;
0196
0197 std::vector<double> vmean, vdeltamean, vrms, vmeanerror, vPValueEqualSplitMeans, vPValueMeanEqualIdeal,
0198 vPValueRMSEqualIdeal, vAlignmentUncertainty;
0199 double resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples);
0200 double resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples);
0201
0202 void storeHistogramInRootfile(TH1* hist);
0203 TF1* fitGauss(TH1* hist, int color);
0204
0205
0206
0207
0208
0209
0210 void plotSS(const std::string& options = "layers", const std::string& variable = "");
0211 void setHistStyle(TH1& hist, const char* titleX, const char* titleY, int color);
0212 void setTitleStyle(TNamed& h,
0213 const char* titleX,
0214 const char* titleY,
0215 int subDetId,
0216 bool isSurfaceDeformation = false,
0217 TString secondline = "");
0218 void setNiceStyle();
0219 void setCanvasStyle(TCanvas& canv);
0220 void setLegendStyle(TLegend& leg);
0221 void scaleXaxis(TH1* hist, Int_t scale);
0222 TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n = 1);
0223
0224 TString outputFile;
0225 std::string outputDir;
0226 TList* sourcelist;
0227 std::vector<TkOfflineVariables*> sourceList;
0228 bool moreThanOneSource;
0229 std::string fileNames[10];
0230 int fileCounter;
0231
0232 std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
0233 std::string getVariableForDMRPlot(
0234 const std::string& histoname, const std::string& variable, int nbins, double min, double max);
0235 void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
0236 void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0, std::string subdet = "");
0237 void modifySSHistAndLegend(THStack* hs, TLegend* legend);
0238 void openSummaryFile();
0239 std::vector<TH1*> findmodule(TFile* f, unsigned int moduleid);
0240 };
0241
0242 #endif