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 = "");
133  void plotSurfaceShapes(const std::string& options = "layers", const std::string& variable = "");
134  void plotChi2(const char* inputFile);
136  void plotHitMaps();
138  void setTreeBaseDir(std::string dir = "TrackerOfflineValidation");
139 
140  void residual_by_moduleID(unsigned int moduleid);
141  int numberOfLayers(int phase, int subdetector);
143 
144  THStack* addHists(
145  const TString& selection,
146  const TString& residType = "xPrime",
147  TLegend** myLegend = nullptr,
148  bool printModuleIds = false,
149  bool validforphase0 =
150  false);
152  float twotailedStudentTTestEqualMean(float t, float v);
153 
156  struct DMRPlotInfo {
158  int nbins;
159  double min, max;
160  int minHits;
163  THStack* hstack;
164  TLegend* legend;
166  float maxY;
167  TH1F* h;
168  TH1F* h1;
169  TH1F* h2;
172  };
173 
174 private:
175  TList* getTreeList();
177 
178  bool useFit_;
179  bool showMean_;
180  bool showRMS_;
185  bool twolines_;
186  bool bigtext_;
187  const static TString summaryfilename;
188  std::ofstream summaryfile;
189  bool openedsummaryfile = false;
191 
194  double resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples);
195  double resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples);
196 
197  void storeHistogramInRootfile(TH1* hist);
198  TF1* fitGauss(TH1* hist, int color);
205  void plotSS(const std::string& options = "layers", const std::string& variable = "");
206  void setHistStyle(TH1& hist, const char* titleX, const char* titleY, int color);
207  void setTitleStyle(TNamed& h,
208  const char* titleX,
209  const char* titleY,
210  int subDetId,
211  bool isSurfaceDeformation = false,
212  TString secondline = "");
213  void setNiceStyle();
214  void setCanvasStyle(TCanvas& canv);
215  void setLegendStyle(TLegend& leg);
216  void scaleXaxis(TH1* hist, Int_t scale);
217  TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n = 1);
218 
219  TString outputFile;
221  TList* sourcelist;
222  std::vector<TkOfflineVariables*> sourceList;
226 
227  std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
229  const std::string& histoname, const std::string& variable, int nbins, double min, double max);
230  void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
231  void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0, std::string subdet = "");
232  void modifySSHistAndLegend(THStack* hs, TLegend* legend);
233  void openSummaryFile();
234  std::vector<TH1*> findmodule(TFile* f, unsigned int moduleid);
235 };
236 
237 #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)
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
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)
void plotDMR(const std::string &plotVar="medianX", Int_t minHits=50, const std::string &options="plain", const std::string &filterName="")
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 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