00001 #ifndef PLOTALIGNNMENTVALIDATION_H_
00002 #define PLOTALIGNNMENTVALIDATION_H_
00003
00004 #include <TStyle.h>
00005 #include <TSystem.h>
00006 #include <vector>
00007 #include <memory>
00008 #include <string>
00009 #include <fstream>
00010 #include <iostream>
00011 #include <sstream>
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include "TTree.h"
00015 #include "TString.h"
00016 #include "TDirectory.h"
00017 #include "TCanvas.h"
00018 #include "TFile.h"
00019 #include "TDirectoryFile.h"
00020 #include "TLegend.h"
00021 #include "THStack.h"
00022 #include <exception>
00023
00024
00025 #include "Alignment/OfflineValidation/interface/TkOffTreeVariables.h"
00026
00027 class TkOfflineVariables {
00028 public:
00029 TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName="", int color=1, int style=1);
00030 int getLineColor(){ return lineColor; };
00031 int getLineStyle(){ return lineStyle; };
00032 std::string getName(){ return legendName; }
00033 TTree* getTree(){ return tree; };
00034 TFile* getFile(){ return file; };
00035 private:
00036 TFile* file;
00037 TTree* tree;
00038 int lineColor;
00039 int lineStyle;
00040 std::string legendName;
00041 };
00042
00043
00044 TkOfflineVariables::TkOfflineVariables(std::string fileName, std::string baseDir, std::string legName, int lColor, int lStyle)
00045 {
00046 lineColor = lColor;
00047 lineStyle = lStyle;
00048 if (legName=="") {
00049 int start = 0;
00050 if (fileName.find('/') ) start =fileName.find_last_of('/')+1;
00051 int stop = fileName.find_last_of('.');
00052 legendName = fileName.substr(start,stop-start);
00053 } else {
00054 legendName = legName;
00055 }
00056
00057
00058 file = TFile::Open( fileName.c_str() );
00059 TDirectoryFile *d = 0;
00060 if (file->Get( baseDir.c_str() ) ) {
00061 d = (TDirectoryFile*)file->Get( baseDir.c_str() );
00062 if ((*d).Get("TkOffVal")) {
00063 tree = (TTree*)(*d).Get("TkOffVal");
00064 } else {
00065 std::cout<<"no tree named TkOffVal"<<std::endl;
00066 }
00067 } else {
00068 std::cout<<"no directory named "<<baseDir.c_str()<<std::endl;
00069 }
00070 }
00071
00072 class PlotAlignmentValidation {
00073 public:
00074
00075 PlotAlignmentValidation(const char *inputFile,std::string fileName="", int lineColor=1, int lineStyle=1);
00076 ~PlotAlignmentValidation();
00077 void loadFileList(const char *inputFile, std::string fileName="", int lineColor=2, int lineStyle=1);
00078 void useFitForDMRplots(bool usefit = false);
00079 void plotOutlierModules(const char *outputFileName="OutlierModules.ps",std::string plotVariable = "chi2PerDofX" ,float chi2_cut = 10,unsigned int minHits = 50);
00080 void plotSubDetResiduals(bool plotNormHisto=false, unsigned int subDetId=7);
00081 void plotDMR(const std::string& plotVar="medianX",Int_t minHits = 50, const std::string& options = "plain");
00082 void plotSurfaceShapes(const std::string& options = "layers",const std::string& variable="");
00083
00084 void plotHitMaps();
00085 void setOutputDir( std::string dir );
00086 void setTreeBaseDir( std::string dir = "TrackerOfflineValidationStandalone");
00087
00088 THStack* addHists(const char *selection, const TString &residType = "xPrime", bool printModuleIds = false);
00089
00090 private :
00091 TList getTreeList();
00092 std::string treeBaseDir;
00093
00094 bool useFit_;
00095
00096 std::pair<float,float> fitGauss(TH1 *hist,int color);
00097
00098
00099
00100
00101 void plotSS(const std::string& options = "layers",const std::string& variable="");
00102 void setHistStyle( TH1& hist,const char* titleX, const char* titleY, int color);
00103 void setTitleStyle( TNamed& h,const char* titleX, const char* titleY, int subDetId);
00104 void setNiceStyle();
00105 void setCanvasStyle( TCanvas& canv );
00106 void setLegendStyle( TLegend& leg );
00107
00108 TString outputFile;
00109 std::string outputDir;
00110 TList *sourcelist;
00111 std::vector<TkOfflineVariables*> sourceList;
00112 bool moreThanOneSource;
00113 std::string fileNames[10];
00114 int fileCounter;
00115
00116
00117
00118 struct DMRPlotInfo {
00119 std::string variable;
00120 int nbins;
00121 double min, max;
00122 int minHits;
00123 bool plotPlain, plotSplits, plotLayers;
00124 int subDetId, nLayers;
00125 THStack* hstack;
00126 TLegend* legend;
00127 TkOfflineVariables* vars;
00128 float maxY;
00129 TH1F* h;
00130 TH1F* h1;
00131 TH1F* h2;
00132 bool firsthisto;
00133 };
00134
00135 std::string getSelectionForDMRPlot(int minHits, int subDetId, int direction = 0, int layer = 0);
00136 std::string getVariableForDMRPlot(const std::string& histoname, const std::string& variable,
00137 int nbins, double min, double max);
00138 void setDMRHistStyleAndLegend(TH1F* h, DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
00139 void plotDMRHistogram(DMRPlotInfo& plotinfo, int direction = 0, int layer = 0);
00140
00141 };
00142
00143 #endif // PLOTALIGNNMENTVALIDATION_H_