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  void residual_by_moduleID(unsigned int moduleid);
103  int numberOfLayers(int phase, int subdetector);
104  int maxNumberOfLayers(int subdetector);
105 
106  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
107 
108  float twotailedStudentTTestEqualMean(float t, float v);
109 
110  // These are helpers for DMR plotting
111 
112  struct DMRPlotInfo {
114  int nbins;
115  double min, max;
116  int minHits;
117  bool plotPlain, plotSplits, plotLayers;
119  THStack* hstack;
120  TLegend* legend;
122  float maxY;
123  TH1F* h;
124  TH1F* h1;
125  TH1F* h2;
127  };
128 
129 private :
130  TList* getTreeList();
132 
133  bool useFit_;
134  bool showMean_;
135  bool showRMS_;
140  bool twolines_;
141  bool bigtext_;
142  const static TString summaryfilename;
143  ofstream summaryfile;
144  bool openedsummaryfile = false;
146 
147  std::vector<double> vmean, vdeltamean, vrms, vmeanerror, vPValueEqualSplitMeans, vPValueMeanEqualIdeal, vPValueRMSEqualIdeal, vAlignmentUncertainty;
148  double resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples);
149  double resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples);
150 
151  void storeHistogramInRootfile(TH1* hist, TF1* func);
152  TF1 *fitGauss(TH1 *hist,int color);
153  //void plotBoxOverview(TCanvas &c1, TList &treeList,std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t filenumber,Int_t minHits);
154  //void plot1DDetailsSubDet(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t minHits);
155  //void plot1DDetailsBarrelLayer(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
156  //void plot1DDetailsDiskWheel(TCanvas &c1, TList &treelist, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
157  void plotSS(const std::string& options = "layers",const std::string& variable="");
158  void setHistStyle( TH1& hist,const char* titleX, const char* titleY, int color);
159  void setTitleStyle( TNamed& h,const char* titleX, const char* titleY, int subDetId, bool isSurfaceDeformation=false, TString secondline="");
160  void setNiceStyle();
161  void setCanvasStyle( TCanvas& canv );
162  void setLegendStyle( TLegend& leg );
163  void scaleXaxis(TH1* hist, Int_t scale);
164  TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n=1);
165 
166  TString outputFile;
168  TList *sourcelist;
169  std::vector<TkOfflineVariables*> sourceList;
173 
174  std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
175  std::string getVariableForDMRPlot(const std::string& histoname, const std::string& variable,
176  int nbins, double min, double max);
177  void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
178  void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0, std::string subdet= "");
179  void modifySSHistAndLegend(THStack* hs, TLegend* legend);
180  void openSummaryFile();
181  vector <TH1*> findmodule (TFile* f, unsigned int moduleid);
182 
183 };
184 
185 #endif // PLOTALIGNNMENTVALIDATION_H_
Definition: start.py:1
void setNiceStyle()
Definition: NiceStyle.cc:3
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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
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