Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:45:45

0001 #ifndef PLOTALIGNNMENTVALIDATION_H_
0002 #define PLOTALIGNNMENTVALIDATION_H_
0003 
0004 #include "Alignment/OfflineValidation/interface/TkOffTreeVariables.h"
0005 
0006 #include "TCanvas.h"
0007 #include "TDirectory.h"
0008 #include "TDirectoryFile.h"
0009 #include "TFile.h"
0010 #include "THStack.h"
0011 #include "TLegend.h"
0012 #include "TString.h"
0013 #include "TStyle.h"
0014 #include "TSystem.h"
0015 #include "TTree.h"
0016 
0017 #include <cstdio>
0018 #include <cstdlib>
0019 #include <exception>
0020 #include <fstream>
0021 #include <iostream>
0022 #include <memory>
0023 #include <sstream>
0024 #include <string>
0025 #include <vector>
0026 
0027 class TkOfflineVariables {
0028 public:
0029   TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName = "", int color = 1, int style = 1);
0030   ~TkOfflineVariables();
0031   int getLineColor() { return lineColor; }
0032   int getLineStyle() { return lineStyle; }
0033   std::string getName() { return legendName; }
0034   TTree* getTree() { return tree; }
0035   TFile* getFile() { return file; }
0036   int getPhase() { return phase; }
0037 
0038 private:
0039   TFile* file;
0040   TTree* tree;
0041   int lineColor;
0042   int lineStyle;
0043   int phase;
0044   std::string legendName;
0045 };
0046 
0047 TkOfflineVariables::TkOfflineVariables(
0048     std::string fileName, std::string baseDir, std::string legName, int lColor, int lStyle) {
0049   lineColor = lColor;
0050   lineStyle = lStyle % 100;
0051   if (legName == "") {
0052     int start = 0;
0053     if (fileName.find('/'))
0054       start = fileName.find_last_of('/') + 1;
0055     int stop = fileName.find_last_of('.');
0056     legendName = fileName.substr(start, stop - start);
0057   } else {
0058     legendName = legName;
0059   }
0060 
0061   //fill the tree pointer
0062   file = TFile::Open(fileName.c_str());
0063   TDirectoryFile* d = 0;
0064   if (file->Get(baseDir.c_str())) {
0065     d = (TDirectoryFile*)file->Get(baseDir.c_str());
0066     if ((*d).Get("TkOffVal")) {
0067       tree = (TTree*)(*d).Get("TkOffVal");
0068     } else {
0069       std::cout << "no tree named TkOffVal" << std::endl;
0070       assert(false);
0071     }
0072     TDirectoryFile* d2 = (TDirectoryFile*)d->Get("Pixel");
0073     assert(d2);
0074     phase = (int)((bool)d2->Get("P1PXBBarrel_1"));
0075   } else {
0076     std::cout << "no directory named " << baseDir.c_str() << std::endl;
0077     assert(false);
0078   }
0079 }
0080 
0081 TkOfflineVariables::~TkOfflineVariables() { delete file; }
0082 
0083 class PlotAlignmentValidation {
0084 public:
0085   //PlotAlignmentValidation(TString *tmp);
0086   PlotAlignmentValidation(bool bigtext = false);
0087   PlotAlignmentValidation(
0088       const char* inputFile, std::string fileName = "", int lineColor = 1, int lineStyle = 1, bool bigtext = false);
0089   ~PlotAlignmentValidation();
0090   void loadFileList(const char* inputFile, std::string fileName = "", int lineColor = 2, int lineStyle = 1);
0091   void useFitForDMRplots(bool usefit = false);
0092   void legendOptions(TString options);
0093   void plotOutlierModules(const char* outputFileName = "OutlierModules.ps",
0094                           std::string plotVariable = "chi2PerDofX",
0095                           float chi2_cut = 10,
0096                           unsigned int minHits = 50);  //method dumps selected modules into ps file
0097   void plotSubDetResiduals(
0098       bool plotNormHisto = false,
0099       unsigned int subDetId =
0100           7);  //subDetector number :1.TPB, 2.TBE+, 3.TBE-, 4.TIB, 5.TID+, 6.TID-, 7.TOB, 8.TEC+ or 9.TEC-
0101   void plotDMR(
0102       const std::string& plotVar = "medianX",
0103       Int_t minHits = 50,
0104       const std::string& options =
0105           "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")
0106   void plotSurfaceShapes(const std::string& options = "layers", const std::string& variable = "");
0107   void plotChi2(const char* inputFile);
0108   // plotSurfaceShapes: options="split","layers"/"layer","subdet"
0109   void plotHitMaps();
0110   void setOutputDir(std::string dir);
0111   void setTreeBaseDir(std::string dir = "TrackerOfflineValidationStandalone");
0112   void residual_by_moduleID(unsigned int moduleid);
0113   int numberOfLayers(int phase, int subdetector);
0114   int maxNumberOfLayers(int subdetector);
0115 
0116   THStack* addHists(
0117       const TString& selection,
0118       const TString& residType = "xPrime",
0119       TLegend** myLegend = 0,
0120       bool printModuleIds = false,
0121       bool validforphase0 =
0122           false);  //add hists fulfilling 'selection' on TTree; residType: xPrime,yPrime,xPrimeNorm,yPrimeNorm,x,y,xNorm; if (printModuleIds): cout DetIds
0123 
0124   float twotailedStudentTTestEqualMean(float t, float v);
0125 
0126   // These are helpers for DMR plotting
0127 
0128   struct DMRPlotInfo {
0129     std::string variable;
0130     int nbins;
0131     double min, max;
0132     int minHits;
0133     bool plotPlain, plotSplits, plotLayers;
0134     int subDetId, nLayers;
0135     THStack* hstack;
0136     TLegend* legend;
0137     TkOfflineVariables* vars;
0138     float maxY;
0139     TH1F* h;
0140     TH1F* h1;
0141     TH1F* h2;
0142     bool firsthisto;
0143   };
0144 
0145 private:
0146   TList* getTreeList();
0147   std::string treeBaseDir;
0148 
0149   bool useFit_;
0150   bool showMean_;
0151   bool showRMS_;
0152   bool showMeanError_;
0153   bool showRMSError_;
0154   bool showModules_;
0155   bool showUnderOverFlow_;
0156   bool twolines_;
0157   bool bigtext_;
0158   const static TString summaryfilename;
0159   ofstream summaryfile;
0160   bool openedsummaryfile = false;
0161   TFile* rootsummaryfile;
0162 
0163   std::vector<double> vmean, vdeltamean, vrms, vmeanerror, vPValueEqualSplitMeans, vPValueMeanEqualIdeal,
0164       vPValueRMSEqualIdeal, vAlignmentUncertainty;
0165   double resampleTestOfEqualMeans(TH1F* h1, TH1F* h2, int numSamples);
0166   double resampleTestOfEqualRMS(TH1F* h1, TH1F* h2, int numSamples);
0167 
0168   void storeHistogramInRootfile(TH1* hist);
0169   TF1* fitGauss(TH1* hist, int color);
0170   //void plotBoxOverview(TCanvas &c1, TList &treeList,std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t filenumber,Int_t minHits);
0171   //void plot1DDetailsSubDet(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, std::string plot_Var2, Int_t minHits);
0172   //void plot1DDetailsBarrelLayer(TCanvas &c1, TList &treeList, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
0173   //void plot1DDetailsDiskWheel(TCanvas &c1, TList &treelist, std::string plot_Var1a,std::string plot_Var1b, Int_t minHits);
0174   void plotSS(const std::string& options = "layers", const std::string& variable = "");
0175   void setHistStyle(TH1& hist, const char* titleX, const char* titleY, int color);
0176   void setTitleStyle(TNamed& h,
0177                      const char* titleX,
0178                      const char* titleY,
0179                      int subDetId,
0180                      bool isSurfaceDeformation = false,
0181                      TString secondline = "");
0182   void setNiceStyle();
0183   void setCanvasStyle(TCanvas& canv);
0184   void setLegendStyle(TLegend& leg);
0185   void scaleXaxis(TH1* hist, Int_t scale);
0186   TObject* findObjectFromCanvas(TCanvas* canv, const char* className, Int_t n = 1);
0187 
0188   TString outputFile;
0189   std::string outputDir;
0190   TList* sourcelist;
0191   std::vector<TkOfflineVariables*> sourceList;
0192   bool moreThanOneSource;
0193   std::string fileNames[10];
0194   int fileCounter;
0195 
0196   std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
0197   std::string getVariableForDMRPlot(
0198       const std::string& histoname, const std::string& variable, int nbins, double min, double max);
0199   void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
0200   void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0, std::string subdet = "");
0201   void modifySSHistAndLegend(THStack* hs, TLegend* legend);
0202   void openSummaryFile();
0203   vector<TH1*> findmodule(TFile* f, unsigned int moduleid);
0204 };
0205 
0206 #endif  // PLOTALIGNNMENTVALIDATION_H_