CMS 3D CMS Logo

PlotAlignmentValidation.h
Go to the documentation of this file.
1 #ifndef PLOTALIGNNMENTVALIDATION_H_
2 #define PLOTALIGNNMENTVALIDATION_H_
3 
4 #include <TStyle.h>
5 #include <TSystem.h>
6 #include <vector>
7 #include <memory>
8 #include <string>
9 #include <fstream>
10 #include <iostream>
11 #include <sstream>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include "TTree.h"
15 #include "TString.h"
16 #include "TDirectory.h"
17 #include "TCanvas.h"
18 #include "TFile.h"
19 #include "TDirectoryFile.h"
20 #include "TLegend.h"
21 #include "THStack.h"
22 #include <exception>
23 
24 // This line works only if we have a CMSSW environment...
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  // These are helpers for DMR plotting
108 
109  struct DMRPlotInfo {
111  int nbins;
112  double min, max;
113  int minHits;
114  bool plotPlain, plotSplits, plotLayers;
116  THStack* hstack;
117  TLegend* legend;
119  float maxY;
120  TH1F* h;
121  TH1F* h1;
122  TH1F* h2;
124  };
125 
126 private :
127  TList* getTreeList();
129 
130  bool useFit_;
131  bool showMean_;
132  bool showRMS_;
137  bool twolines_;
138  bool bigtext_;
139  const static TString summaryfilename;
140  ofstream summaryfile;
141  bool openedsummaryfile = false;
142 
143  std::vector<double> vmean, vdeltamean, vrms;
144 
145  TF1 *fitGauss(TH1 *hist,int color);
146  //void plotBoxOverview(TCanvas &c1, TList &treeList,std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t filenumber,Int_t minHits);
147  //void plot1DDetailsSubDet(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t minHits);
148  //void plot1DDetailsBarrelLayer(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
149  //void plot1DDetailsDiskWheel(TCanvas &c1, TList &treelist, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
150  void plotSS(const std::string& options = "layers",const std::string& variable="");
151  void setHistStyle( TH1& hist,const char* titleX, const char* titleY, int color);
152  void setTitleStyle( TNamed& h,const char* titleX, const char* titleY, int subDetId, bool isSurfaceDeformation=false, TString secondline="");
153  void setNiceStyle();
154  void setCanvasStyle( TCanvas& canv );
155  void setLegendStyle( TLegend& leg );
156  void scaleXaxis(TH1* hist, Int_t scale);
157  TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n=1);
158 
159  TString outputFile;
161  TList *sourcelist;
162  std::vector<TkOfflineVariables*> sourceList;
166 
167  std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
168  std::string getVariableForDMRPlot(const std::string& histoname, const std::string& variable,
169  int nbins, double min, double max);
170  void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
171  void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
172  void modifySSHistAndLegend(THStack* hs, TLegend* legend);
173  void openSummaryFile();
174 };
175 
176 #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