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);
30  int getLineColor(){ return lineColor; }
31  int getLineStyle(){ return lineStyle; }
33  TTree* getTree(){ return tree; }
34  TFile* getFile(){ return file; }
35  int getPhase(){ return phase; }
36 private:
37  TFile* file;
38  TTree* tree;
39  int lineColor;
40  int lineStyle;
41  int phase;
43 };
44 
45 
47 {
48  lineColor = lColor;
49  lineStyle = lStyle % 100;
50  if (legName=="") {
51  int start = 0;
52  if (fileName.find('/') ) start =fileName.find_last_of('/')+1;
53  int stop = fileName.find_last_of('.');
54  legendName = fileName.substr(start,stop-start);
55  } else {
56  legendName = legName;
57  }
58 
59  //fill the tree pointer
60  file = TFile::Open( fileName.c_str() );
61  TDirectoryFile *d = 0;
62  if (file->Get( baseDir.c_str() ) ) {
63  d = (TDirectoryFile*)file->Get( baseDir.c_str() );
64  if ((*d).Get("TkOffVal")) {
65  tree = (TTree*)(*d).Get("TkOffVal");
66  } else {
67  std::cout<<"no tree named TkOffVal"<<std::endl;
68  assert(false);
69  }
70  TDirectoryFile *d2 = (TDirectoryFile*)d->Get("Pixel");
71  assert(d2);
72  phase = (int)((bool)d2->Get("P1PXBBarrel_1"));
73  } else {
74  std::cout<<"no directory named "<<baseDir.c_str()<<std::endl;
75  assert(false);
76  }
77 }
78 
80 public:
81  //PlotAlignmentValidation(TString *tmp);
83  PlotAlignmentValidation(const char *inputFile,std::string fileName="", int lineColor=1, int lineStyle=1, bool bigtext=false);
85  void loadFileList(const char *inputFile, std::string fileName="", int lineColor=2, int lineStyle=1);
86  void useFitForDMRplots(bool usefit = false);
87  void legendOptions(TString options);
88  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
89  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-
90  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")
91  void plotSurfaceShapes(const std::string& options = "layers",const std::string& variable="");
92  void plotChi2(const char *inputFile);
93  // plotSurfaceShapes: options="split","layers"/"layer","subdet"
94  void plotHitMaps();
95  void setOutputDir( std::string dir );
96  void setTreeBaseDir( std::string dir = "TrackerOfflineValidationStandalone");
97  int numberOfLayers(int phase, int subdetector);
98  int maxNumberOfLayers(int subdetector);
99 
100  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
101 
102  // These are helpers for DMR plotting
103 
104  struct DMRPlotInfo {
106  int nbins;
107  double min, max;
108  int minHits;
109  bool plotPlain, plotSplits, plotLayers;
111  THStack* hstack;
112  TLegend* legend;
114  float maxY;
115  TH1F* h;
116  TH1F* h1;
117  TH1F* h2;
119  };
120 
121 private :
122  TList* getTreeList();
124 
125  bool useFit_;
126  bool showMean_;
127  bool showRMS_;
132  bool twolines_;
133  bool bigtext_;
134 
135  TF1 *fitGauss(TH1 *hist,int color);
136  //void plotBoxOverview(TCanvas &c1, TList &treeList,std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t filenumber,Int_t minHits);
137  //void plot1DDetailsSubDet(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t minHits);
138  //void plot1DDetailsBarrelLayer(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
139  //void plot1DDetailsDiskWheel(TCanvas &c1, TList &treelist, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
140  void plotSS(const std::string& options = "layers",const std::string& variable="");
141  void setHistStyle( TH1& hist,const char* titleX, const char* titleY, int color);
142  void setTitleStyle( TNamed& h,const char* titleX, const char* titleY, int subDetId, bool isSurfaceDeformation=false, TString secondline="");
143  void setNiceStyle();
144  void setCanvasStyle( TCanvas& canv );
145  void setLegendStyle( TLegend& leg );
146  void scaleXaxis(TH1* hist, Int_t scale);
147  TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n=1);
148 
149  TString outputFile;
151  TList *sourcelist;
152  std::vector<TkOfflineVariables*> sourceList;
156 
157  std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
158  std::string getVariableForDMRPlot(const std::string& histoname, const std::string& variable,
159  int nbins, double min, double max);
160  void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
161  void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
162  void modifySSHistAndLegend(THStack* hs, TLegend* legend);
163 };
164 
165 #endif // PLOTALIGNNMENTVALIDATION_H_
Definition: start.py:1
void setNiceStyle()
Definition: NiceStyle.cc:3
TString subdetector
selection
main part
Definition: corrVsCorr.py:98
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
unsigned int subDetId[20]
std::string className(const T &t)
Definition: ClassName.h:30