CMS 3D CMS Logo

PlotAlignmentValidation.h
Go to the documentation of this file.
1 #ifndef PLOTALIGNNMENTVALIDATION_H_
2 #define PLOTALIGNNMENTVALIDATION_H_
3 
5 
6 #include "TCanvas.h"
7 #include "TDirectory.h"
8 #include "TDirectoryFile.h"
9 #include "TFile.h"
10 #include "THStack.h"
11 #include "TLegend.h"
12 #include "TString.h"
13 #include "TStyle.h"
14 #include "TSystem.h"
15 #include "TTree.h"
16 
17 #include <cstdio>
18 #include <cstdlib>
19 #include <exception>
20 #include <fstream>
21 #include <iostream>
22 #include <memory>
23 #include <sstream>
24 #include <string>
25 #include <vector>
26 
28 public:
29  TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName = "", int color = 1, int style = 1);
31  int getLineColor() { return lineColor; }
32  int getLineStyle() { return lineStyle; }
34  TTree* getTree() { return tree; }
35  TFile* getFile() { return file; }
36  int getPhase() { return phase; }
37 
38 private:
39  TFile* file;
40  TTree* tree;
41  int lineColor;
42  int lineStyle;
43  int phase;
45 };
46 
48  std::string fileName, std::string baseDir, std::string legName, int lColor, int lStyle) {
49  lineColor = lColor;
50  lineStyle = lStyle % 100;
51  if (legName == "") {
52  int start = 0;
53  if (fileName.find('/'))
54  start = fileName.find_last_of('/') + 1;
55  int stop = fileName.find_last_of('.');
56  legendName = fileName.substr(start, stop - start);
57  } else {
58  legendName = legName;
59  }
60 
61  //fill the tree pointer
62  file = TFile::Open(fileName.c_str());
63  TDirectoryFile* d = 0;
64  if (file->Get(baseDir.c_str())) {
65  d = (TDirectoryFile*)file->Get(baseDir.c_str());
66  if ((*d).Get("TkOffVal")) {
67  tree = (TTree*)(*d).Get("TkOffVal");
68  } else {
69  std::cout << "no tree named TkOffVal" << std::endl;
70  assert(false);
71  }
72  TDirectoryFile* d2 = (TDirectoryFile*)d->Get("Pixel");
73  assert(d2);
74  phase = (int)((bool)d2->Get("P1PXBBarrel_1"));
75  } else {
76  std::cout << "no directory named " << baseDir.c_str() << std::endl;
77  assert(false);
78  }
79 }
80 
82 
84 public:
85  //PlotAlignmentValidation(TString *tmp);
86  PlotAlignmentValidation(bool bigtext = false);
88  const char* inputFile, std::string fileName = "", int lineColor = 1, int lineStyle = 1, bool bigtext = false);
90  void loadFileList(const char* inputFile, std::string fileName = "", int lineColor = 2, int lineStyle = 1);
91  void useFitForDMRplots(bool usefit = false);
92  void legendOptions(TString options);
93  void plotOutlierModules(const char* outputFileName = "OutlierModules.ps",
94  std::string plotVariable = "chi2PerDofX",
95  float chi2_cut = 10,
96  unsigned int minHits = 50); //method dumps selected modules into ps file
97  void plotSubDetResiduals(
98  bool plotNormHisto = false,
99  unsigned int subDetId =
100  7); //subDetector number :1.TPB, 2.TBE+, 3.TBE-, 4.TIB, 5.TID+, 6.TID-, 7.TOB, 8.TEC+ or 9.TEC-
101  void plotDMR(
102  const std::string& plotVar = "medianX",
103  Int_t minHits = 50,
104  const std::string& options =
105  "plain"); // plotVar=mean,meanX,meanY,median,rms etc., comma-separated list can be given; minHits=the minimum hits needed for module to appear in plot; options="plain" for regular DMR, "split" for inwards/outwards split, "layers" for layerwise DMR, "layer=N" for Nth layer, or combination of the previous (e.g. "split layers")
106  void plotSurfaceShapes(const std::string& options = "layers", const std::string& variable = "");
107  void plotChi2(const char* inputFile);
108  // plotSurfaceShapes: options="split","layers"/"layer","subdet"
109  void plotHitMaps();
110  void setOutputDir(std::string dir);
111  void setTreeBaseDir(std::string dir = "TrackerOfflineValidationStandalone");
112  void residual_by_moduleID(unsigned int moduleid);
113  int numberOfLayers(int phase, int subdetector);
114  int maxNumberOfLayers(int subdetector);
115 
116  THStack* addHists(
117  const TString& selection,
118  const TString& residType = "xPrime",
119  TLegend** myLegend = 0,
120  bool printModuleIds = false,
121  bool validforphase0 =
122  false); //add hists fulfilling 'selection' on TTree; residType: xPrime,yPrime,xPrimeNorm,yPrimeNorm,x,y,xNorm; if (printModuleIds): cout DetIds
123 
124  float twotailedStudentTTestEqualMean(float t, float v);
125 
126  // These are helpers for DMR plotting
127 
128  struct DMRPlotInfo {
130  int nbins;
131  double min, max;
132  int minHits;
133  bool plotPlain, plotSplits, plotLayers;
135  THStack* hstack;
136  TLegend* legend;
138  float maxY;
139  TH1F* h;
140  TH1F* h1;
141  TH1F* h2;
143  };
144 
145 private:
146  TList* getTreeList();
148 
149  bool useFit_;
150  bool showMean_;
151  bool showRMS_;
156  bool twolines_;
157  bool bigtext_;
158  const static TString summaryfilename;
159  ofstream summaryfile;
160  bool openedsummaryfile = false;
162 
163  std::vector<double> vmean, vdeltamean, vrms, vmeanerror, vPValueEqualSplitMeans, vPValueMeanEqualIdeal,
164  vPValueRMSEqualIdeal, vAlignmentUncertainty;
165  double resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples);
166  double resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples);
167 
168  void storeHistogramInRootfile(TH1* hist);
169  TF1* fitGauss(TH1* hist, int color);
170  //void plotBoxOverview(TCanvas &c1, TList &treeList,std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t filenumber,Int_t minHits);
171  //void plot1DDetailsSubDet(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t minHits);
172  //void plot1DDetailsBarrelLayer(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
173  //void plot1DDetailsDiskWheel(TCanvas &c1, TList &treelist, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
174  void plotSS(const std::string& options = "layers", const std::string& variable = "");
175  void setHistStyle(TH1& hist, const char* titleX, const char* titleY, int color);
176  void setTitleStyle(TNamed& h,
177  const char* titleX,
178  const char* titleY,
179  int subDetId,
180  bool isSurfaceDeformation = false,
181  TString secondline = "");
182  void setNiceStyle();
183  void setCanvasStyle(TCanvas& canv);
184  void setLegendStyle(TLegend& leg);
185  void scaleXaxis(TH1* hist, Int_t scale);
186  TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n = 1);
187 
188  TString outputFile;
190  TList* sourcelist;
191  std::vector<TkOfflineVariables*> sourceList;
195 
196  std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
197  std::string getVariableForDMRPlot(
198  const std::string& histoname, const std::string& variable, int nbins, double min, double max);
199  void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
200  void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0, std::string subdet = "");
201  void modifySSHistAndLegend(THStack* hs, TLegend* legend);
202  void openSummaryFile();
203  vector<TH1*> findmodule(TFile* f, unsigned int moduleid);
204 };
205 
206 #endif // PLOTALIGNNMENTVALIDATION_H_
Definition: start.py:1
void setNiceStyle()
Definition: NiceStyle.cc:3
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
constexpr int nLayers
Definition: Common.h:13
TString subdetector
selection
main part
Definition: corrVsCorr.py:100
static const TString summaryfilename
unsigned int subDetId[21]
void setCanvasStyle(TCanvas *c, const bool logScale)
Definition: makePlots.cc:439
TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName="", int color=1, int style=1)
Definition: style.py:1
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
d
Definition: ztail.py:151
void setLegendStyle(TLegend *l, const unsigned int nColumns)
Definition: makePlots.cc:496
const map< TString, int > numberOfLayers(TString Year="2018")
Definition: DMRtrends.cc:254
std::vector< TkOfflineVariables * > sourceList
Definition: tree.py:1
std::string className(const T &t)
Definition: ClassName.h:31