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
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();
111  void setTreeBaseDir(std::string dir = "TrackerOfflineValidationStandalone");
112  void residual_by_moduleID(unsigned int moduleid);
113  int numberOfLayers(int phase, 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;
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 
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);
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_
PlotAlignmentValidation::residual_by_moduleID
void residual_by_moduleID(unsigned int moduleid)
PlotAlignmentValidation::twolines_
bool twolines_
Definition: PlotAlignmentValidation.h:156
TkOfflineVariables::getLineColor
int getLineColor()
Definition: PlotAlignmentValidation.h:31
PlotAlignmentValidation::DMRPlotInfo::firsthisto
bool firsthisto
Definition: PlotAlignmentValidation.h:142
PlotAlignmentValidation::DMRPlotInfo::plotSplits
bool plotSplits
Definition: PlotAlignmentValidation.h:133
PlotAlignmentValidation::numberOfLayers
int numberOfLayers(int phase, int subdetector)
PlotAlignmentValidation::showMeanError_
bool showMeanError_
Definition: PlotAlignmentValidation.h:152
start
Definition: start.py:1
PlotAlignmentValidation::plotHitMaps
void plotHitMaps()
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PlotAlignmentValidation::plotSurfaceShapes
void plotSurfaceShapes(const std::string &options="layers", const std::string &variable="")
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
PlotAlignmentValidation::setHistStyle
void setHistStyle(TH1 &hist, const char *titleX, const char *titleY, int color)
PlotAlignmentValidation::findObjectFromCanvas
TObject * findObjectFromCanvas(TCanvas *canv, const char *className, Int_t n=1)
min
T min(T a, T b)
Definition: MathUtil.h:58
TkOfflineVariables::getName
std::string getName()
Definition: PlotAlignmentValidation.h:33
tree
Definition: tree.py:1
gather_cfg.cout
cout
Definition: gather_cfg.py:144
PlotAlignmentValidation
Definition: PlotAlignmentValidation.h:83
PlotAlignmentValidation::useFit_
bool useFit_
Definition: PlotAlignmentValidation.h:149
PlotAlignmentValidation::outputDir
std::string outputDir
Definition: PlotAlignmentValidation.h:189
PlotAlignmentValidation::summaryfile
ofstream summaryfile
Definition: PlotAlignmentValidation.h:159
cms::cuda::assert
assert(be >=bs)
PlotAlignmentValidation::scaleXaxis
void scaleXaxis(TH1 *hist, Int_t scale)
TkOfflineVariables::file
TFile * file
Definition: PlotAlignmentValidation.h:39
PlotAlignmentValidation::twotailedStudentTTestEqualMean
float twotailedStudentTTestEqualMean(float t, float v)
TkOfflineVariables
Definition: PlotAlignmentValidation.h:27
ALCARECODTCalibSynchDQM_cff.baseDir
baseDir
Definition: ALCARECODTCalibSynchDQM_cff.py:14
PlotAlignmentValidation::plotOutlierModules
void plotOutlierModules(const char *outputFileName="OutlierModules.ps", std::string plotVariable="chi2PerDofX", float chi2_cut=10, unsigned int minHits=50)
PlotAlignmentValidation::DMRPlotInfo::vars
TkOfflineVariables * vars
Definition: PlotAlignmentValidation.h:137
PlotAlignmentValidation::maxNumberOfLayers
int maxNumberOfLayers(int subdetector)
PlotAlignmentValidation::DMRPlotInfo::legend
TLegend * legend
Definition: PlotAlignmentValidation.h:136
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
TkOffTreeVariables.h
PVValHelper::plotVariable
plotVariable
Definition: PVValidationHelpers.h:67
findQualityFiles.v
v
Definition: findQualityFiles.py:179
PlotAlignmentValidation::sourcelist
TList * sourcelist
Definition: PlotAlignmentValidation.h:190
TkOfflineVariables::getTree
TTree * getTree()
Definition: PlotAlignmentValidation.h:34
tools.TF1
TF1
Definition: tools.py:23
PlotAlignmentValidation::vPValueRMSEqualIdeal
std::vector< double > vPValueRMSEqualIdeal
Definition: PlotAlignmentValidation.h:163
PlotAlignmentValidation::DMRPlotInfo::minHits
int minHits
Definition: PlotAlignmentValidation.h:132
TkOfflineVariables::~TkOfflineVariables
~TkOfflineVariables()
Definition: PlotAlignmentValidation.h:81
PlotAlignmentValidation::summaryfilename
const static TString summaryfilename
Definition: PlotAlignmentValidation.h:158
PlotAlignmentValidation::setLegendStyle
void setLegendStyle(TLegend &leg)
PlotAlignmentValidation::DMRPlotInfo::plotPlain
bool plotPlain
Definition: PlotAlignmentValidation.h:133
PlotAlignmentValidation::loadFileList
void loadFileList(const char *inputFile, std::string fileName="", int lineColor=2, int lineStyle=1)
TkOfflineVariables::legendName
std::string legendName
Definition: PlotAlignmentValidation.h:44
PlotAlignmentValidation::useFitForDMRplots
void useFitForDMRplots(bool usefit=false)
PlotAlignmentValidation::plotSubDetResiduals
void plotSubDetResiduals(bool plotNormHisto=false, unsigned int subDetId=7)
options
Definition: options.py:1
PlotAlignmentValidation::getVariableForDMRPlot
std::string getVariableForDMRPlot(const std::string &histoname, const std::string &variable, int nbins, double min, double max)
PlotAlignmentValidation::legendOptions
void legendOptions(TString options)
PlotAlignmentValidation::DMRPlotInfo::subDetId
int subDetId
Definition: PlotAlignmentValidation.h:134
PlotAlignmentValidation::DMRPlotInfo::nbins
int nbins
Definition: PlotAlignmentValidation.h:130
PlotAlignmentValidation::fileCounter
int fileCounter
Definition: PlotAlignmentValidation.h:194
PlotAlignmentValidation::DMRPlotInfo::min
double min
Definition: PlotAlignmentValidation.h:131
PlotAlignmentValidation::moreThanOneSource
bool moreThanOneSource
Definition: PlotAlignmentValidation.h:192
PlotAlignmentValidation::plotSS
void plotSS(const std::string &options="layers", const std::string &variable="")
PlotAlignmentValidation::modifySSHistAndLegend
void modifySSHistAndLegend(THStack *hs, TLegend *legend)
PlotAlignmentValidation::outputFile
TString outputFile
Definition: PlotAlignmentValidation.h:188
compare.hist
hist
Definition: compare.py:376
PlotAlignmentValidation::getSelectionForDMRPlot
std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction=0, int layer=0)
PlotAlignmentValidation::storeHistogramInRootfile
void storeHistogramInRootfile(TH1 *hist)
TkOfflineVariables::getFile
TFile * getFile()
Definition: PlotAlignmentValidation.h:35
PlotAlignmentValidation::plotDMR
void plotDMR(const std::string &plotVar="medianX", Int_t minHits=50, const std::string &options="plain")
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
PlotAlignmentValidation::DMRPlotInfo::max
double max
Definition: PlotAlignmentValidation.h:131
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
PlotAlignmentValidation::setTitleStyle
void setTitleStyle(TNamed &h, const char *titleX, const char *titleY, int subDetId, bool isSurfaceDeformation=false, TString secondline="")
PlotAlignmentValidation::bigtext_
bool bigtext_
Definition: PlotAlignmentValidation.h:157
PlotAlignmentValidation::openSummaryFile
void openSummaryFile()
PlotAlignmentValidation::showRMS_
bool showRMS_
Definition: PlotAlignmentValidation.h:151
reco_skim_cfg_mod.outputFileName
outputFileName
Definition: reco_skim_cfg_mod.py:15
h
PlotAlignmentValidation::resampleTestOfEqualMeans
double resampleTestOfEqualMeans(TH1F *h1, TH1F *h2, int numSamples)
TkOfflineVariables::lineColor
int lineColor
Definition: PlotAlignmentValidation.h:41
PlotAlignmentValidation::setTreeBaseDir
void setTreeBaseDir(std::string dir="TrackerOfflineValidationStandalone")
RecoTauValidation_cfi.lineStyle
lineStyle
Definition: RecoTauValidation_cfi.py:304
PlotAlignmentValidation::DMRPlotInfo::h
TH1F * h
Definition: PlotAlignmentValidation.h:139
PlotAlignmentValidation::~PlotAlignmentValidation
~PlotAlignmentValidation()
PlotAlignmentValidation::plotChi2
void plotChi2(const char *inputFile)
style
Definition: style.py:1
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiPixelPI::phase
phase
Definition: SiPixelPayloadInspectorHelper.h:39
PlotAlignmentValidation::DMRPlotInfo::variable
std::string variable
Definition: PlotAlignmentValidation.h:129
PlotAlignmentValidation::getTreeList
TList * getTreeList()
PlotAlignmentValidation::setDMRHistStyleAndLegend
void setDMRHistStyleAndLegend(TH1F *h, DMRPlotInfo &plotinfo, int direction=0, int layer=0)
PlotAlignmentValidation::DMRPlotInfo::hstack
THStack * hstack
Definition: PlotAlignmentValidation.h:135
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
PlotAlignmentValidation::sourceList
std::vector< TkOfflineVariables * > sourceList
Definition: PlotAlignmentValidation.h:191
TkOfflineVariables::tree
TTree * tree
Definition: PlotAlignmentValidation.h:40
listHistos.legend
legend
Definition: listHistos.py:41
PlotAlignmentValidation::vmean
std::vector< double > vmean
Definition: PlotAlignmentValidation.h:163
PlotAlignmentValidation::openedsummaryfile
bool openedsummaryfile
Definition: PlotAlignmentValidation.h:160
createfilelist.int
int
Definition: createfilelist.py:10
TkOfflineVariables::getPhase
int getPhase()
Definition: PlotAlignmentValidation.h:36
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
TkOfflineVariables::phase
int phase
Definition: PlotAlignmentValidation.h:43
PlotAlignmentValidation::rootsummaryfile
TFile * rootsummaryfile
Definition: PlotAlignmentValidation.h:161
PlotAlignmentValidation::addHists
THStack * addHists(const TString &selection, const TString &residType="xPrime", TLegend **myLegend=0, bool printModuleIds=false, bool validforphase0=false)
PlotAlignmentValidation::PlotAlignmentValidation
PlotAlignmentValidation(bool bigtext=false)
PlotAlignmentValidation::fileNames
std::string fileNames[10]
Definition: PlotAlignmentValidation.h:193
PlotAlignmentValidation::treeBaseDir
std::string treeBaseDir
Definition: PlotAlignmentValidation.h:147
PlotAlignmentValidation::DMRPlotInfo::nLayers
int nLayers
Definition: PlotAlignmentValidation.h:134
PlotAlignmentValidation::setCanvasStyle
void setCanvasStyle(TCanvas &canv)
taus_updatedMVAIds_cff.variable
variable
Definition: taus_updatedMVAIds_cff.py:33
PlotAlignmentValidation::DMRPlotInfo::plotLayers
bool plotLayers
Definition: PlotAlignmentValidation.h:133
PlotAlignmentValidation::DMRPlotInfo
Definition: PlotAlignmentValidation.h:128
PlotAlignmentValidation::plotDMRHistogram
void plotDMRHistogram(DMRPlotInfo &plotinfo, int direction=0, int layer=0, std::string subdet="")
TkOfflineVariables::TkOfflineVariables
TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName="", int color=1, int style=1)
Definition: PlotAlignmentValidation.h:47
PlotAlignmentValidation::vPValueEqualSplitMeans
std::vector< double > vPValueEqualSplitMeans
Definition: PlotAlignmentValidation.h:163
GeomDetEnumerators::subDetId
constexpr unsigned int subDetId[21]
Definition: GeomDetEnumerators.h:34
RecoTauValidation_cfi.lineColor
lineColor
Definition: RecoTauValidation_cfi.py:303
className
std::string className(const T &t)
Definition: ClassName.h:31
PlotAlignmentValidation::showRMSError_
bool showRMSError_
Definition: PlotAlignmentValidation.h:153
ztail.d
d
Definition: ztail.py:151
PlotAlignmentValidation::vAlignmentUncertainty
std::vector< double > vAlignmentUncertainty
Definition: PlotAlignmentValidation.h:163
PlotAlignmentValidation::showUnderOverFlow_
bool showUnderOverFlow_
Definition: PlotAlignmentValidation.h:155
PlotAlignmentValidation::vdeltamean
std::vector< double > vdeltamean
Definition: PlotAlignmentValidation.h:163
PlotAlignmentValidation::setOutputDir
void setOutputDir(std::string dir)
PlotAlignmentValidation::resampleTestOfEqualRMS
double resampleTestOfEqualRMS(TH1F *h1, TH1F *h2, int numSamples)
PlotAlignmentValidation::fitGauss
TF1 * fitGauss(TH1 *hist, int color)
PlotAlignmentValidation::DMRPlotInfo::h2
TH1F * h2
Definition: PlotAlignmentValidation.h:141
TkOfflineVariables::lineStyle
int lineStyle
Definition: PlotAlignmentValidation.h:42
PlotAlignmentValidation::vPValueMeanEqualIdeal
std::vector< double > vPValueMeanEqualIdeal
Definition: PlotAlignmentValidation.h:163
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
PlotAlignmentValidation::DMRPlotInfo::maxY
float maxY
Definition: PlotAlignmentValidation.h:138
PlotAlignmentValidation::setNiceStyle
void setNiceStyle()
PlotAlignmentValidation::showMean_
bool showMean_
Definition: PlotAlignmentValidation.h:150
PlotAlignmentValidation::findmodule
vector< TH1 * > findmodule(TFile *f, unsigned int moduleid)
reco_skim_cfg_mod.minHits
minHits
Definition: reco_skim_cfg_mod.py:177
PlotAlignmentValidation::showModules_
bool showModules_
Definition: PlotAlignmentValidation.h:154
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
TkOfflineVariables::getLineStyle
int getLineStyle()
Definition: PlotAlignmentValidation.h:32
PlotAlignmentValidation::DMRPlotInfo::h1
TH1F * h1
Definition: PlotAlignmentValidation.h:140
PlotAlignmentValidation::vmeanerror
std::vector< double > vmeanerror
Definition: PlotAlignmentValidation.h:163
PlotAlignmentValidation::vrms
std::vector< double > vrms
Definition: PlotAlignmentValidation.h:163
subdetector
TString subdetector
Definition: trackSplitPlot.h:54