CMS 3D CMS Logo

PlotAlignmentValidation.h
Go to the documentation of this file.
1 #ifndef ALIGNMENT_OFFLINEVALIDATION_PLOTALIGNNMENTVALIDATION_H_
2 #define ALIGNMENT_OFFLINEVALIDATION_PLOTALIGNNMENTVALIDATION_H_
3 
7 
8 #include "Math/ProbFunc.h"
9 
10 #include "TAxis.h"
11 #include "TCanvas.h"
12 #include "TDirectory.h"
13 #include "TDirectoryFile.h"
14 #include "TF1.h"
15 #include "TFile.h"
16 #include "TFrame.h"
17 #include "TGaxis.h"
18 #include "TH2F.h"
19 #include "THStack.h"
20 #include "TKey.h"
21 #include "TLatex.h"
22 #include "TLegend.h"
23 #include "TLegendEntry.h"
24 #include "TPad.h"
25 #include "TPaveStats.h"
26 #include "TPaveText.h"
27 #include "TProfile.h"
28 #include "TRandom3.h"
29 #include "TRegexp.h"
30 #include "TROOT.h"
31 #include "TString.h"
32 #include "TStyle.h"
33 #include "TSystem.h"
34 #include "TTree.h"
35 #include "TTreeReader.h"
36 
37 #include <algorithm>
38 #include <cmath>
39 #include <cstdio>
40 #include <cstdlib>
41 #include <exception>
42 #include <fstream>
43 #include <iostream>
44 #include <memory>
45 #include <sstream>
46 #include <string>
47 #include <vector>
48 
50 public:
51  TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName = "", int color = 1, int style = 1);
53  int getLineColor() { return lineColor; }
54  int getLineStyle() { return lineStyle; }
56  TTree* getTree() { return tree; }
57  TFile* getFile() { return file; }
58  int getPhase() { return phase; }
59 
60 private:
61  TFile* file;
62  TTree* tree;
63  int lineColor;
64  int lineStyle;
65  int phase;
67 };
68 
70  std::string fileName, std::string baseDir, std::string legName, int lColor, int lStyle) {
71  lineColor = lColor;
72  lineStyle = lStyle % 100;
73  if (legName.empty()) {
74  int start = 0;
75  if (fileName.find('/'))
76  start = fileName.find_last_of('/') + 1;
77  int stop = fileName.find_last_of('.');
78  legendName = fileName.substr(start, stop - start);
79  } else {
80  legendName = legName;
81  }
82 
83  //fill the tree pointer
84  file = TFile::Open(fileName.c_str());
85  TDirectoryFile* d = nullptr;
86  if (file->Get(baseDir.c_str())) {
87  d = (TDirectoryFile*)file->Get(baseDir.c_str());
88  if ((*d).Get("TkOffVal")) {
89  tree = (TTree*)(*d).Get("TkOffVal");
90  } else {
91  std::cout << "no tree named TkOffVal" << std::endl;
92  assert(false);
93  }
94  TDirectoryFile* d2 = (TDirectoryFile*)d->Get("Pixel");
95  assert(d2);
96  phase = (int)((bool)d2->Get("P1PXBBarrel_1"));
97  } else {
98  std::cout << "no directory named " << baseDir.c_str() << std::endl;
99  assert(false);
100  }
101 }
102 
104 
106 public:
107  //PlotAlignmentValidation(TString *tmp);
108  PlotAlignmentValidation(bool bigtext = false);
110  const char* inputFile, std::string fileName = "", int lineColor = 1, int lineStyle = 1, bool bigtext = false);
112  void loadFileList(const char* inputFile, std::string fileName = "", int lineColor = 2, int lineStyle = 1);
113  void useFitForDMRplots(bool usefit = false);
114  void legendOptions(TString options);
115  void plotOutlierModules(const char* outputFileName = "OutlierModules.ps",
116  std::string plotVariable = "chi2PerDofX",
117  float chi2_cut = 10,
118  unsigned int minHits = 50); //method dumps selected modules into ps file
119  void plotSubDetResiduals(
120  bool plotNormHisto = false,
121  unsigned int subDetId =
122  7);
123  void plotDMR(const std::string& plotVar = "medianX",
124  Int_t minHits = 50,
125  const std::string& options = "plain",
126  const std::string& filterName = "",
127  Float_t maxBadLumiPixel = 0.5,
128  Float_t maxBadLumiStrip = 7.0);
136  void plotSurfaceShapes(const std::string& options = "layers", const std::string& variable = "");
137  void plotChi2(const char* inputFile);
139  void plotHitMaps();
141  void setTreeBaseDir(std::string dir = "TrackerOfflineValidation");
142 
143  void residual_by_moduleID(unsigned int moduleid);
144  int numberOfLayers(int phase, int subdetector);
146 
147  THStack* addHists(
148  const TString& selection,
149  const TString& residType = "xPrime",
150  TLegend** myLegend = nullptr,
151  bool printModuleIds = false,
152  bool validforphase0 =
153  false);
155  float twotailedStudentTTestEqualMean(float t, float v);
156 
159  struct DMRPlotInfo {
161  int nbins;
162  double min, max;
163  int minHits;
166  THStack* hstack;
167  TLegend* legend;
169  float maxY;
170  TH1F* h;
171  TH1F* h1;
172  TH1F* h2;
177  };
178 
179 private:
180  TList* getTreeList();
182 
183  bool useFit_;
184  bool showMean_;
185  bool showRMS_;
190  bool twolines_;
191  bool bigtext_;
192  const static TString summaryfilename;
193  std::ofstream summaryfile;
194  bool openedsummaryfile = false;
196 
199  double resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples);
200  double resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples);
201 
202  void storeHistogramInRootfile(TH1* hist);
203  TF1* fitGauss(TH1* hist, int color);
210  void plotSS(const std::string& options = "layers", const std::string& variable = "");
211  void setHistStyle(TH1& hist, const char* titleX, const char* titleY, int color);
212  void setTitleStyle(TNamed& h,
213  const char* titleX,
214  const char* titleY,
215  int subDetId,
216  bool isSurfaceDeformation = false,
217  TString secondline = "");
218  void setNiceStyle();
219  void setCanvasStyle(TCanvas& canv);
220  void setLegendStyle(TLegend& leg);
221  void scaleXaxis(TH1* hist, Int_t scale);
222  TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n = 1);
223 
224  TString outputFile;
226  TList* sourcelist;
227  std::vector<TkOfflineVariables*> sourceList;
231 
232  std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
234  const std::string& histoname, const std::string& variable, int nbins, double min, double max);
235  void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
236  void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0, std::string subdet = "");
237  void modifySSHistAndLegend(THStack* hs, TLegend* legend);
238  void openSummaryFile();
239  std::vector<TH1*> findmodule(TFile* f, unsigned int moduleid);
240 };
241 
242 #endif // ALIGNMENT_OFFLINEVALIDATION_PLOTALIGNNMENTVALIDATION_H_
Definition: start.py:1
std::vector< double > vAlignmentUncertainty
void plotSurfaceShapes(const std::string &options="layers", const std::string &variable="")
std::vector< double > vmeanerror
void scaleXaxis(TH1 *hist, Int_t scale)
void setHistStyle(TH1 &hist, const char *titleX, const char *titleY, int color)
std::vector< double > vPValueMeanEqualIdeal
TString subdetector
void residual_by_moduleID(unsigned int moduleid)
constexpr unsigned int subDetId[21]
void legendOptions(TString options)
selection
main part
Definition: corrVsCorr.py:100
void plotSS(const std::string &options="layers", const std::string &variable="")
std::vector< double > vPValueRMSEqualIdeal
std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction=0, int layer=0)
void loadFileList(const char *inputFile, std::string fileName="", int lineColor=2, int lineStyle=1)
float twotailedStudentTTestEqualMean(float t, float v)
void plotOutlierModules(const char *outputFileName="OutlierModules.ps", std::string plotVariable="chi2PerDofX", float chi2_cut=10, unsigned int minHits=50)
std::vector< TH1 * > findmodule(TFile *f, unsigned int moduleid)
int maxNumberOfLayers(int subdetector)
void setTitleStyle(TNamed &h, const char *titleX, const char *titleY, int subDetId, bool isSurfaceDeformation=false, TString secondline="")
assert(be >=bs)
TF1 * fitGauss(TH1 *hist, int color)
void plotChi2(const char *inputFile)
void setLegendStyle(TLegend &leg)
static const TString summaryfilename
void plotSubDetResiduals(bool plotNormHisto=false, unsigned int subDetId=7)
std::string getVariableForDMRPlot(const std::string &histoname, const std::string &variable, int nbins, double min, double max)
THStack * addHists(const TString &selection, const TString &residType="xPrime", TLegend **myLegend=nullptr, bool printModuleIds=false, bool validforphase0=false)
TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName="", int color=1, int style=1)
void modifySSHistAndLegend(THStack *hs, TLegend *legend)
Definition: style.py:1
void useFitForDMRplots(bool usefit=false)
double resampleTestOfEqualMeans(TH1F *h1, TH1F *h2, int numSamples)
double f[11][100]
void setDMRHistStyleAndLegend(TH1F *h, DMRPlotInfo &plotinfo, int direction=0, int layer=0)
d
Definition: ztail.py:151
std::vector< double > vPValueEqualSplitMeans
Class PlotAlignmentValidation Class used as the last step for Offline Track Validation tool...
TObject * findObjectFromCanvas(TCanvas *canv, const char *className, Int_t n=1)
std::vector< TkOfflineVariables * > sourceList
void plotDMR(const std::string &plotVar="medianX", Int_t minHits=50, const std::string &options="plain", const std::string &filterName="", Float_t maxBadLumiPixel=0.5, Float_t maxBadLumiStrip=7.0)
void setCanvasStyle(TCanvas &canv)
void setOutputDir(std::string dir)
PlotAlignmentValidation(bool bigtext=false)
Definition: tree.py:1
int numberOfLayers(int phase, int subdetector)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void plotDMRHistogram(DMRPlotInfo &plotinfo, int direction=0, int layer=0, std::string subdet="")
std::vector< double > vdeltamean
double resampleTestOfEqualRMS(TH1F *h1, TH1F *h2, int numSamples)
void setTreeBaseDir(std::string dir="TrackerOfflineValidation")
std::string className(const T &t)
Definition: ClassName.h:31