Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:01

0001 #ifndef ALIGNMENT_OFFLINEVALIDATION_TRACKSPLITPLOT_H
0002 #define ALIGNMENT_OFFLINEVALIDATION_TRACKSPLITPLOT_H
0003 
0004 #include <fstream>
0005 #include <iostream>
0006 #include <sstream>
0007 #include <cmath>
0008 #include "TCanvas.h"
0009 #include "TClass.h"
0010 #include "TColor.h"
0011 #include "TFile.h"
0012 #include "TF1.h"
0013 #include "TGaxis.h"
0014 #include "TGraph2DErrors.h"
0015 #include "TGraphErrors.h"
0016 #include "TH1.h"
0017 #include "TH1F.h"
0018 #include "TH2F.h"
0019 #include "TLegend.h"
0020 #include "TLegendEntry.h"
0021 #include "TList.h"
0022 #include "TMath.h"
0023 #include "TMultiGraph.h"
0024 #include "TObject.h"
0025 #include "TProfile.h"
0026 #include "TROOT.h"
0027 #include "TString.h"
0028 #include "TStyle.h"
0029 #include "TSystem.h"
0030 #include "TText.h"
0031 #include "TTree.h"
0032 
0033 enum PlotType { ScatterPlot, Profile, Histogram, OrgHistogram, Resolution };
0034 enum Statistic { Minimum, Maximum, Average, RMS };
0035 
0036 const Double_t pi = TMath::Pi();
0037 std::vector<Color_t> colors;
0038 std::vector<Style_t> styles;
0039 bool colorsset = false;
0040 Int_t minrun = -1;
0041 Int_t maxrun = -1;
0042 const Int_t xsize = 8;
0043 const Int_t ysize = 9;
0044 Int_t legendGrid = 100;
0045 Double_t margin = .1;
0046 Double_t increaseby = .1;
0047 
0048 TString xvariables[xsize] = {"", "pt", "eta", "phi", "dz", "dxy", "theta", "qoverpt"};
0049 TString yvariables[ysize] = {"pt", "pt", "eta", "phi", "dz", "dxy", "theta", "qoverpt", ""};
0050 Bool_t relativearray[ysize] = {true, false, false, false, false, false, false, false, false};
0051 
0052 TList *stufftodelete = new TList();
0053 
0054 TString subdetector = "PIXEL";
0055 double outliercut = 0.99;  //use the middle 99% of tracks to find the mean and RMS
0056                            //(a few tracks are fit badly and skew them otherwise)
0057 
0058 /***********************************
0059 Table Of Contents
0060 0. Track Split Plot
0061 1. Misalignment Dependence
0062 2. Make Plots
0063 3. Axis Label
0064 4. Axis Limits
0065 5. Place Legend
0066 ***********************************/
0067 
0068 #include "trackSplitPlot.h"
0069 
0070 std::ofstream devnull("/dev/null");
0071 template <typename T>
0072 T identity(T t) {
0073   return t;
0074 }
0075 
0076 //===================
0077 //0. Track Split Plot
0078 //===================
0079 
0080 TCanvas *trackSplitPlot(Int_t nFiles,
0081                         TString *files,
0082                         TString *names,
0083                         TString xvar,
0084                         TString yvar,
0085                         Bool_t relative = false,
0086                         Bool_t resolution = false,
0087                         Bool_t pull = false,
0088                         TString saveas = "",
0089                         std::ostream &summaryfile = devnull);
0090 TCanvas *trackSplitPlot(Int_t nFiles,
0091                         TString *files,
0092                         TString *names,
0093                         TString var,
0094                         Bool_t relative = false,
0095                         Bool_t pull = false,
0096                         TString saveas = "",
0097                         std::ostream &summaryfile = devnull);
0098 TCanvas *trackSplitPlot(TString file,
0099                         TString xvar,
0100                         TString yvar,
0101                         Bool_t profile = false,
0102                         Bool_t relative = false,
0103                         Bool_t resolution = false,
0104                         Bool_t pull = false,
0105                         TString saveas = "",
0106                         std::ostream &summaryfile = devnull);
0107 TCanvas *trackSplitPlot(TString file,
0108                         TString var,
0109                         Bool_t relative = false,
0110                         Bool_t pull = false,
0111                         TString saveas = "",
0112                         std::ostream &summaryfile = devnull);
0113 void placeholder(TString saveas = "", Bool_t wide = false);
0114 void saveplot(TCanvas *c1, TString saveas);
0115 void deleteCanvas(TObject *canvas);
0116 void setupcolors();
0117 void runNumberZoomed(Int_t nFiles,
0118                      TString *files,
0119                      TString *names,
0120                      TString yvar,
0121                      Bool_t relative = false,
0122                      Bool_t resolution = false,
0123                      Bool_t pull = false,
0124                      Int_t firstRun = -1,
0125                      Int_t lastRun = -1,
0126                      TString saveas = "");
0127 
0128 //==========================
0129 //1. Misalignment Dependence
0130 //==========================
0131 
0132 void misalignmentDependence(TCanvas *c1old,
0133                             Int_t nFiles,
0134                             TString *names,
0135                             TString misalignment,
0136                             Double_t *values,
0137                             Double_t *phases,
0138                             TString xvar,
0139                             TString yvar,
0140                             TF1 *function,
0141                             Int_t parameter,
0142                             TString parametername = "",
0143                             TString functionname = "",
0144                             Bool_t relative = false,
0145                             Bool_t resolution = false,
0146                             Bool_t pull = false,
0147                             TString saveas = "");
0148 void misalignmentDependence(TCanvas *c1old,
0149                             Int_t nFiles,
0150                             TString *names,
0151                             TString misalignment,
0152                             Double_t *values,
0153                             Double_t *phases,
0154                             TString xvar,
0155                             TString yvar,
0156                             TF1 *function,
0157                             Int_t nParameters,
0158                             Int_t *parameters,
0159                             TString *parameternames,
0160                             TString functionname = "",
0161                             Bool_t relative = false,
0162                             Bool_t resolution = false,
0163                             Bool_t pull = false,
0164                             TString saveas = "");
0165 void misalignmentDependence(Int_t nFiles,
0166                             TString *files,
0167                             TString *names,
0168                             TString misalignment,
0169                             Double_t *values,
0170                             Double_t *phases,
0171                             TString xvar,
0172                             TString yvar,
0173                             TF1 *function,
0174                             Int_t parameter,
0175                             TString parametername = "",
0176                             TString functionname = "",
0177                             Bool_t relative = false,
0178                             Bool_t resolution = false,
0179                             Bool_t pull = false,
0180                             TString saveas = "");
0181 void misalignmentDependence(Int_t nFiles,
0182                             TString *files,
0183                             TString *names,
0184                             TString misalignment,
0185                             Double_t *values,
0186                             Double_t *phases,
0187                             TString xvar,
0188                             TString yvar,
0189                             TF1 *function,
0190                             Int_t nParameters,
0191                             Int_t *parameters,
0192                             TString *parameternames,
0193                             TString functionname = "",
0194                             Bool_t relative = false,
0195                             Bool_t resolution = false,
0196                             Bool_t pull = false,
0197                             TString saveas = "");
0198 void misalignmentDependence(TCanvas *c1old,
0199                             Int_t nFiles,
0200                             TString *names,
0201                             TString misalignment,
0202                             Double_t *values,
0203                             Double_t *phases,
0204                             TString xvar,
0205                             TString yvar,
0206                             TString function,
0207                             Int_t parameter,
0208                             TString parametername = "",
0209                             TString functionname = "",
0210                             Bool_t relative = false,
0211                             Bool_t resolution = false,
0212                             Bool_t pull = false,
0213                             TString saveas = "");
0214 void misalignmentDependence(TCanvas *c1old,
0215                             Int_t nFiles,
0216                             TString *names,
0217                             TString misalignment,
0218                             Double_t *values,
0219                             Double_t *phases,
0220                             TString xvar,
0221                             TString yvar,
0222                             TString function,
0223                             Int_t nParameters,
0224                             Int_t *parameters,
0225                             TString *parameternames,
0226                             TString functionname = "",
0227                             Bool_t relative = false,
0228                             Bool_t resolution = false,
0229                             Bool_t pull = false,
0230                             TString saveas = "");
0231 void misalignmentDependence(Int_t nFiles,
0232                             TString *files,
0233                             TString *names,
0234                             TString misalignment,
0235                             Double_t *values,
0236                             Double_t *phases,
0237                             TString xvar,
0238                             TString yvar,
0239                             TString function,
0240                             Int_t parameter,
0241                             TString parametername = "",
0242                             TString functionname = "",
0243                             Bool_t relative = false,
0244                             Bool_t resolution = false,
0245                             Bool_t pull = false,
0246                             TString saveas = "");
0247 void misalignmentDependence(Int_t nFiles,
0248                             TString *files,
0249                             TString *names,
0250                             TString misalignment,
0251                             Double_t *values,
0252                             Double_t *phases,
0253                             TString xvar,
0254                             TString yvar,
0255                             TString function,
0256                             Int_t nParameters,
0257                             Int_t *parameters,
0258                             TString *parameternames,
0259                             TString functionname = "",
0260                             Bool_t relative = false,
0261                             Bool_t resolution = false,
0262                             Bool_t pull = false,
0263                             TString saveas = "");
0264 Bool_t misalignmentDependence(TCanvas *c1old,
0265                               Int_t nFiles,
0266                               TString *names,
0267                               TString misalignment,
0268                               Double_t *values,
0269                               Double_t *phases,
0270                               TString xvar,
0271                               TString yvar,
0272                               Bool_t drawfits = true,
0273                               Bool_t relative = false,
0274                               Bool_t resolution = false,
0275                               Bool_t pull = false,
0276                               TString saveas = "");
0277 Bool_t misalignmentDependence(Int_t nFiles,
0278                               TString *files,
0279                               TString *names,
0280                               TString misalignment,
0281                               Double_t *values,
0282                               Double_t *phases,
0283                               TString xvar,
0284                               TString yvar,
0285                               Bool_t drawfits = true,
0286                               Bool_t relative = false,
0287                               Bool_t resolution = false,
0288                               Bool_t pull = false,
0289                               TString saveas = "");
0290 Bool_t hasFit(TString misalignment,
0291               TString xvar,
0292               TString yvar,
0293               Bool_t relative = false,
0294               Bool_t resolution = false,
0295               Bool_t pull = false);
0296 
0297 //=============
0298 //2. Make Plots
0299 //=============
0300 
0301 void makePlots(Int_t nFiles,
0302                TString *files,
0303                TString *names,
0304                TString misalignment,
0305                Double_t *values,
0306                Double_t *phases,
0307                TString directory,
0308                Bool_t matrix[xsize][ysize]);
0309 void makePlots(Int_t nFiles, TString *files, TString *names, TString directory, Bool_t matrix[xsize][ysize]);
0310 void makePlots(TString file,
0311                TString misalignment,
0312                Double_t *values,
0313                Double_t *phases,
0314                TString directory,
0315                Bool_t matrix[xsize][ysize]);
0316 void makePlots(TString file, TString directory, Bool_t matrix[xsize][ysize]);
0317 void makePlots(Int_t nFiles,
0318                TString *files,
0319                TString *names,
0320                TString misalignment,
0321                Double_t *values,
0322                Double_t *phases,
0323                TString directory,
0324                TString xvar,
0325                TString yvar);
0326 void makePlots(Int_t nFiles, TString *files, TString *names, TString directory, TString xvar, TString yvar);
0327 void makePlots(TString file,
0328                TString misalignment,
0329                Double_t *values,
0330                Double_t *phases,
0331                TString directory,
0332                TString xvar,
0333                TString yvar);
0334 void makePlots(TString file, TString directory, TString xvar, TString yvar);
0335 void makePlots(Int_t nFiles,
0336                TString *files,
0337                TString *names,
0338                TString misalignment,
0339                Double_t *values,
0340                Double_t *phases,
0341                TString directory);
0342 void makePlots(Int_t nFiles, TString *files, TString *names, TString directory);
0343 void makePlots(TString file, TString misalignment, Double_t *values, Double_t *phases, TString directory);
0344 void makePlots(TString file, TString directory);
0345 
0346 //=============
0347 //3. Axis Label
0348 //=============
0349 
0350 TString fancyname(TString variable);
0351 TString units(TString variable, Char_t axis);
0352 TString plainunits(TString variable, Char_t axis);
0353 TString latexunits(TString variable, Char_t axis);
0354 TString axislabel(
0355     TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false);
0356 TString latexlabel(
0357     TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false);
0358 void setAxisLabels(TH1 *p, PlotType type, TString xvar, TString yvar, Bool_t relative, Bool_t pull);
0359 void setAxisLabels(TMultiGraph *p, PlotType type, TString xvar, TString yvar, Bool_t relative, Bool_t pull);
0360 TString nPart(Int_t part, TString string, TString delimit = ";", Bool_t removerest = true);
0361 
0362 //==============
0363 //4. Axis Limits
0364 //==============
0365 
0366 Double_t findStatistic(Statistic what,
0367                        Int_t nFiles,
0368                        TString *files,
0369                        TString var,
0370                        Char_t axis,
0371                        Bool_t relative = false,
0372                        Bool_t pull = false);
0373 Double_t findAverage(
0374     Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0375 Double_t findMin(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0376 Double_t findMax(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0377 Double_t findRMS(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0378 Double_t findStatistic(
0379     Statistic what, TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0380 Double_t findAverage(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0381 Double_t findMin(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0382 Double_t findMax(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0383 Double_t findRMS(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
0384 void axislimits(Int_t nFiles,
0385                 TString *files,
0386                 TString var,
0387                 Char_t axis,
0388                 Bool_t relative,
0389                 Bool_t pull,
0390                 Double_t &min,
0391                 Double_t &max,
0392                 Double_t &bins);
0393 
0394 //===============
0395 //5. Place Legend
0396 //===============
0397 
0398 Double_t placeLegend(
0399     TLegend *l, Double_t width, Double_t height, Double_t x1min, Double_t y1min, Double_t x2max, Double_t y2max);
0400 Bool_t fitsHere(TLegend *l, Double_t x1, Double_t y1, Double_t x2, Double_t y2);
0401 
0402 #endif