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 private:
38  TFile* file;
39  TTree* tree;
40  int lineColor;
41  int lineStyle;
42  int phase;
44 };
45 
46 
48 {
49  lineColor = lColor;
50  lineStyle = lStyle % 100;
51  if (legName=="") {
52  int start = 0;
53  if (fileName.find('/') ) start =fileName.find_last_of('/')+1;
54  int stop = fileName.find_last_of('.');
55  legendName = fileName.substr(start,stop-start);
56  } else {
57  legendName = legName;
58  }
59 
60  //fill the tree pointer
61  file = TFile::Open( fileName.c_str() );
62  TDirectoryFile *d = 0;
63  if (file->Get( baseDir.c_str() ) ) {
64  d = (TDirectoryFile*)file->Get( baseDir.c_str() );
65  if ((*d).Get("TkOffVal")) {
66  tree = (TTree*)(*d).Get("TkOffVal");
67  } else {
68  std::cout<<"no tree named TkOffVal"<<std::endl;
69  assert(false);
70  }
71  TDirectoryFile *d2 = (TDirectoryFile*)d->Get("Pixel");
72  assert(d2);
73  phase = (int)((bool)d2->Get("P1PXBBarrel_1"));
74  } else {
75  std::cout<<"no directory named "<<baseDir.c_str()<<std::endl;
76  assert(false);
77  }
78 }
79 
81  delete file;
82 }
83 
85 public:
86  //PlotAlignmentValidation(TString *tmp);
87  PlotAlignmentValidation(bool bigtext=false);
88  PlotAlignmentValidation(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",std::string plotVariable = "chi2PerDofX" ,float chi2_cut = 10,unsigned int minHits = 50);//method dumps selected modules into ps file
94  void plotSubDetResiduals(bool plotNormHisto=false, unsigned int subDetId=7);//subDetector number :1.TPB, 2.TBE+, 3.TBE-, 4.TIB, 5.TID+, 6.TID-, 7.TOB, 8.TEC+ or 9.TEC-
95  void plotDMR(const std::string& plotVar="medianX",Int_t minHits = 50, const std::string& options = "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")
96  void plotSurfaceShapes(const std::string& options = "layers",const std::string& variable="");
97  void plotChi2(const char *inputFile);
98  // plotSurfaceShapes: options="split","layers"/"layer","subdet"
99  void plotHitMaps();
100  void setOutputDir( std::string dir );
101  void setTreeBaseDir( std::string dir = "TrackerOfflineValidationStandalone");
102  int numberOfLayers(int phase, int subdetector);
103  int maxNumberOfLayers(int subdetector);
104 
105  THStack* addHists(const TString& selection, const TString &residType = "xPrime", TLegend **myLegend = 0, bool printModuleIds = false, bool validforphase0 = false);//add hists fulfilling 'selection' on TTree; residType: xPrime,yPrime,xPrimeNorm,yPrimeNorm,x,y,xNorm; if (printModuleIds): cout DetIds
106 
107  float twotailedStudentTTestEqualMean(float t, float v);
108 
109  // These are helpers for DMR plotting
110 
111  struct DMRPlotInfo {
113  int nbins;
114  double min, max;
115  int minHits;
116  bool plotPlain, plotSplits, plotLayers;
118  THStack* hstack;
119  TLegend* legend;
121  float maxY;
122  TH1F* h;
123  TH1F* h1;
124  TH1F* h2;
126  };
127 
128 private :
129  TList* getTreeList();
131 
132  bool useFit_;
133  bool showMean_;
134  bool showRMS_;
139  bool twolines_;
140  bool bigtext_;
141  const static TString summaryfilename;
142  ofstream summaryfile;
143  bool openedsummaryfile = false;
144 
145  std::vector<double> vmean, vdeltamean, vrms, vmeanerror, vPValueEqualSplitMeans, vPValueMeanEqualIdeal, vPValueRMSEqualIdeal, vAlignmentUncertainty;
146  double resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples);
147  double resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples);
148 
149  TF1 *fitGauss(TH1 *hist,int color);
150  //void plotBoxOverview(TCanvas &c1, TList &treeList,std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t filenumber,Int_t minHits);
151  //void plot1DDetailsSubDet(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t minHits);
152  //void plot1DDetailsBarrelLayer(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
153  //void plot1DDetailsDiskWheel(TCanvas &c1, TList &treelist, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
154  void plotSS(const std::string& options = "layers",const std::string& variable="");
155  void setHistStyle( TH1& hist,const char* titleX, const char* titleY, int color);
156  void setTitleStyle( TNamed& h,const char* titleX, const char* titleY, int subDetId, bool isSurfaceDeformation=false, TString secondline="");
157  void setNiceStyle();
158  void setCanvasStyle( TCanvas& canv );
159  void setLegendStyle( TLegend& leg );
160  void scaleXaxis(TH1* hist, Int_t scale);
161  TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n=1);
162 
163  TString outputFile;
165  TList *sourcelist;
166  std::vector<TkOfflineVariables*> sourceList;
170 
171  std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
172  std::string getVariableForDMRPlot(const std::string& histoname, const std::string& variable,
173  int nbins, double min, double max);
174  void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
175  void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
176  void modifySSHistAndLegend(THStack* hs, TLegend* legend);
177  void openSummaryFile();
178 };
179 
180 #endif // PLOTALIGNNMENTVALIDATION_H_
Definition: start.py:1
void setNiceStyle()
Definition: NiceStyle.cc:3
TString subdetector
selection
main part
Definition: corrVsCorr.py:98
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
T min(T a, T b)
Definition: MathUtil.h:58
void setLegendStyle(TLegend *l, const unsigned int nColumns)
Definition: makePlots.cc:496
std::vector< TkOfflineVariables * > sourceList
dbl *** dir
Definition: mlp_gen.cc:35
Definition: tree.py:1
std::string className(const T &t)
Definition: ClassName.h:30