Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:09

0001 // ----------------------------------------------------------------------------------------------------------------
0002 // Basic example ROOT script for making tracking performance plots using the ntuples produced by L1TrackNtupleMaker.cc
0003 //
0004 // e.g. in ROOT do: .L L1TrackNtuplePlot.C++, L1TrackNtuplePlot("L1TrkNtuple")
0005 //
0006 // By Louise Skinnari, June 2013
0007 // ----------------------------------------------------------------------------------------------------------------
0008 
0009 #include "TROOT.h"
0010 #include "TStyle.h"
0011 #include "TLatex.h"
0012 #include "TFile.h"
0013 #include "TTree.h"
0014 #include "TChain.h"
0015 #include "TBranch.h"
0016 #include "TLeaf.h"
0017 #include "TCanvas.h"
0018 #include "TLegend.h"
0019 #include "TH1.h"
0020 #include "TH2.h"
0021 #include "TF1.h"
0022 #include "TProfile.h"
0023 #include "TProfile2D.h"
0024 #include "TMath.h"
0025 #include <TError.h>
0026 #include "TSystem.h"
0027 
0028 #include <iostream>
0029 #include <string>
0030 #include <vector>
0031 #include <algorithm>
0032 
0033 using namespace std;
0034 
0035 void SetPlotStyle();
0036 void mySmallText(Double_t x, Double_t y, Color_t color, char* text);
0037 
0038 double getIntervalContainingFractionOfEntries(TH1* histogram, double interval, int minEntries = 5);
0039 void makeResidualIntervalPlot(
0040     TString type, TString dir, TString variable, TH1F* h_68, TH1F* h_90, TH1F* h_99, double minY, double maxY);
0041 
0042 // ----------------------------------------------------------------------------------------------------------------
0043 // Main script
0044 // ----------------------------------------------------------------------------------------------------------------
0045 
0046 void L1TrackNtuplePlot(TString type,
0047                        TString type_dir = "",
0048                        TString treeName = "",
0049                        int TP_select_injet = 0,
0050                        int TP_select_pdgid = 0,
0051                        int TP_select_eventid = 0,
0052                        bool useTightCuts = false,
0053                        bool useDeadRegion = false,
0054                        float TP_minPt = 2.0,
0055                        float TP_maxPt = 100.0,
0056                        float TP_maxEta = 2.4,
0057                        float TP_maxDxy = 1.0,
0058                        float TP_maxD0 = 1.0,
0059                        bool doDetailedPlots = false) {
0060   // type:              this is the name of the input file you want to process (minus ".root" extension)
0061   // type_dir:          this is the directory containing the input file you want to process. Note that this must end with a "/", as in "EventSets/"
0062   // TP_select_pdgid:   if non-zero, only select TPs with a given PDG ID
0063   // TP_select_eventid: if zero, only look at TPs from primary interaction, else, include TPs from pileup
0064   // TP_minPt:          only look at TPs with pt > X GeV
0065   // TP_maxPt:          only look at TPs with pt < X GeV
0066   // TP_maxEta:         only look at TPs with |eta| < X
0067   // doDetailedPlots:   includes extra plots, such as  performance vs d0.
0068 
0069   // TP_select_injet: only look at TPs that are within a jet with pt > 30 GeV (==1) or within a jet with pt > 100 GeV (==2), >200 GeV (==3) or all TPs (==0)
0070 
0071   //--  N.B. For standard displaced tracking plots, set TP_minPt=3.0, TP_maxEta=2.0, TP_maxDxy=10.0,
0072   //--  TO_maxD0=10.0, doDetailedPlots=true. (Efficiency plots vs eta also usually made for d0 < 5).
0073 
0074   gROOT->SetBatch();
0075   gErrorIgnoreLevel = kWarning;
0076 
0077   SetPlotStyle();
0078 
0079   // ----------------------------------------------------------------------------------------------------------------
0080   // define input options
0081 
0082   // these are the LOOSE cuts, baseline scenario for efficiency and rate plots ==> configure as appropriate
0083   int L1Tk_minNstub = 4;
0084   float L1Tk_maxChi2 = 999999;
0085   float L1Tk_maxChi2dof = 999999.;
0086 
0087   // TIGHT cuts (separate plots / rates) ==> configure as appropriate
0088   // this is currently set up as an either or for performance plots, to not duplicate a ton of code.
0089   int L1Tk_TIGHT_minNstub = 4;
0090   float L1Tk_TIGHT_maxChi2 = 999999;
0091   float L1Tk_TIGHT_maxChi2dof = 999999.;
0092   if (useTightCuts) {
0093     L1Tk_minNstub = L1Tk_TIGHT_minNstub;
0094     L1Tk_maxChi2 = L1Tk_TIGHT_maxChi2;
0095     L1Tk_maxChi2dof = L1Tk_TIGHT_maxChi2dof;
0096   }
0097 
0098   bool doGausFit = false;     //do gaussian fit for resolution vs eta/pt plots
0099   bool doLooseMatch = false;  //looser MC truth matching
0100 
0101   // tracklet variables
0102   int L1Tk_seed = 0;
0103 
0104   //some counters for integrated efficiencies
0105   int n_all_eta2p5 = 0;
0106   int n_all_eta1p75 = 0;
0107   int n_all_eta1p0 = 0;
0108   int n_match_eta2p5 = 0;
0109   int n_match_eta1p75 = 0;
0110   int n_match_eta1p0 = 0;
0111   int n_all_ptg2 = 0;
0112   int n_all_ptg8 = 0;
0113   int n_all_pt2to8 = 0;
0114   int n_all_ptg40 = 0;
0115   int n_match_ptg2 = 0;
0116   int n_match_ptg8 = 0;
0117   int n_match_pt2to8 = 0;
0118   int n_match_ptg40 = 0;
0119 
0120   // counters for total track rates
0121   int ntrk = 0;
0122   int ntrk_pt2 = 0;
0123   int ntrk_pt3 = 0;
0124   int ntrk_pt10 = 0;
0125   int ntp_pt2 = 0;
0126   int ntp_pt3 = 0;
0127   int ntp_pt10 = 0;
0128 
0129   // ----------------------------------------------------------------------------------------------------------------
0130   // read ntuples
0131   TChain* tree = new TChain("L1TrackNtuple" + treeName + "/eventTree");
0132   tree->Add(type_dir + type + ".root");
0133 
0134   if (tree->GetEntries() == 0) {
0135     cout << "File doesn't exist or is empty, returning..."
0136          << endl;  //cout's kept in this file as it is an example standalone plotting script, not running in central CMSSW
0137     return;
0138   }
0139 
0140   // ----------------------------------------------------------------------------------------------------------------
0141   // define leafs & branches
0142 
0143   // tracking particles
0144   vector<float>* tp_pt;
0145   vector<float>* tp_eta;
0146   vector<float>* tp_phi;
0147   vector<float>* tp_dxy;
0148   vector<float>* tp_z0;
0149   vector<float>* tp_d0;
0150   vector<int>* tp_pdgid;
0151   vector<int>* tp_nmatch;
0152   vector<int>* tp_nstub;
0153   vector<int>* tp_eventid;
0154   vector<int>* tp_injet;
0155   vector<int>* tp_injet_highpt;
0156   vector<int>* tp_injet_vhighpt;
0157 
0158   // *L1 track* properties, for tracking particles matched to a L1 track
0159   vector<float>* matchtrk_pt;
0160   vector<float>* matchtrk_eta;
0161   vector<float>* matchtrk_phi;
0162   vector<float>* matchtrk_d0;
0163   vector<float>* matchtrk_z0;
0164   vector<float>* matchtrk_chi2;
0165   vector<float>* matchtrk_chi2_dof;
0166   vector<float>* matchtrk_chi2rphi;
0167   vector<float>* matchtrk_chi2rphi_dof;
0168   vector<float>* matchtrk_chi2rz;
0169   vector<float>* matchtrk_chi2rz_dof;
0170   vector<int>* matchtrk_nstub;
0171   vector<int>* matchtrk_lhits;
0172   vector<int>* matchtrk_dhits;
0173   vector<int>* matchtrk_seed;
0174   vector<int>* matchtrk_hitpattern;
0175   vector<int>* matchtrk_injet;
0176   vector<int>* matchtrk_injet_highpt;
0177   vector<int>* matchtrk_injet_vhighpt;
0178 
0179   // all L1 tracks
0180   vector<float>* trk_pt;
0181   vector<float>* trk_eta;
0182   vector<float>* trk_phi;
0183   vector<float>* trk_chi2;
0184   vector<float>* trk_chi2_dof;
0185   vector<float>* trk_chi2rphi;
0186   vector<float>* trk_chi2rphi_dof;
0187   vector<float>* trk_chi2rz;
0188   vector<float>* trk_chi2rz_dof;
0189   vector<int>* trk_nstub;
0190   vector<int>* trk_lhits;
0191   vector<int>* trk_dhits;
0192   vector<int>* trk_seed;
0193   vector<int>* trk_hitpattern;
0194   vector<unsigned int>* trk_phiSector;
0195   vector<int>* trk_injet;
0196   vector<int>* trk_injet_highpt;
0197   vector<int>* trk_injet_vhighpt;
0198   vector<int>* trk_fake;
0199   vector<int>* trk_genuine;
0200   vector<int>* trk_loose;
0201 
0202   TBranch* b_tp_pt;
0203   TBranch* b_tp_eta;
0204   TBranch* b_tp_phi;
0205   TBranch* b_tp_dxy;
0206   TBranch* b_tp_z0;
0207   TBranch* b_tp_d0;
0208   TBranch* b_tp_pdgid;
0209   TBranch* b_tp_nmatch;
0210   TBranch* b_tp_nstub;
0211   TBranch* b_tp_eventid;
0212   TBranch* b_tp_injet;
0213   TBranch* b_tp_injet_highpt;
0214   TBranch* b_tp_injet_vhighpt;
0215 
0216   TBranch* b_matchtrk_pt;
0217   TBranch* b_matchtrk_eta;
0218   TBranch* b_matchtrk_phi;
0219   TBranch* b_matchtrk_d0;
0220   TBranch* b_matchtrk_z0;
0221   TBranch* b_matchtrk_chi2;
0222   TBranch* b_matchtrk_chi2_dof;
0223   TBranch* b_matchtrk_chi2rphi;
0224   TBranch* b_matchtrk_chi2rphi_dof;
0225   TBranch* b_matchtrk_chi2rz;
0226   TBranch* b_matchtrk_chi2rz_dof;
0227   TBranch* b_matchtrk_nstub;
0228   TBranch* b_matchtrk_lhits;
0229   TBranch* b_matchtrk_dhits;
0230   TBranch* b_matchtrk_seed;
0231   TBranch* b_matchtrk_hitpattern;
0232   TBranch* b_matchtrk_injet;
0233   TBranch* b_matchtrk_injet_highpt;
0234   TBranch* b_matchtrk_injet_vhighpt;
0235 
0236   TBranch* b_trk_pt;
0237   TBranch* b_trk_eta;
0238   TBranch* b_trk_phi;
0239   TBranch* b_trk_chi2;
0240   TBranch* b_trk_chi2_dof;
0241   TBranch* b_trk_chi2rphi;
0242   TBranch* b_trk_chi2rphi_dof;
0243   TBranch* b_trk_chi2rz;
0244   TBranch* b_trk_chi2rz_dof;
0245   TBranch* b_trk_nstub;
0246   TBranch* b_trk_lhits;
0247   TBranch* b_trk_dhits;
0248   TBranch* b_trk_phiSector;
0249   TBranch* b_trk_seed;
0250   TBranch* b_trk_hitpattern;
0251   TBranch* b_trk_injet;
0252   TBranch* b_trk_injet_highpt;
0253   TBranch* b_trk_injet_vhighpt;
0254   TBranch* b_trk_fake;
0255   TBranch* b_trk_genuine;
0256   TBranch* b_trk_loose;
0257 
0258   tp_pt = 0;
0259   tp_eta = 0;
0260   tp_phi = 0;
0261   tp_dxy = 0;
0262   tp_z0 = 0;
0263   tp_d0 = 0;
0264   tp_pdgid = 0;
0265   tp_nmatch = 0;
0266   tp_nstub = 0;
0267   tp_eventid = 0;
0268   tp_injet = 0;
0269   tp_injet_highpt = 0;
0270   tp_injet_vhighpt = 0;
0271 
0272   matchtrk_pt = 0;
0273   matchtrk_eta = 0;
0274   matchtrk_phi = 0;
0275   matchtrk_d0 = 0;
0276   matchtrk_z0 = 0;
0277   matchtrk_chi2 = 0;
0278   matchtrk_chi2_dof = 0;
0279   matchtrk_chi2rphi = 0;
0280   matchtrk_chi2rphi_dof = 0;
0281   matchtrk_chi2rz = 0;
0282   matchtrk_chi2rz_dof = 0;
0283   matchtrk_nstub = 0;
0284   matchtrk_lhits = 0;
0285   matchtrk_dhits = 0;
0286   matchtrk_seed = 0;
0287   matchtrk_hitpattern = 0;
0288   matchtrk_injet = 0;
0289   matchtrk_injet_highpt = 0;
0290   matchtrk_injet_vhighpt = 0;
0291 
0292   trk_pt = 0;
0293   trk_eta = 0;
0294   trk_phi = 0;
0295   trk_chi2 = 0;
0296   trk_chi2_dof = 0;
0297   trk_chi2rphi = 0;
0298   trk_chi2rphi_dof = 0;
0299   trk_chi2rz = 0;
0300   trk_chi2rz_dof = 0;
0301   trk_nstub = 0;
0302   trk_lhits = 0;
0303   trk_dhits = 0;
0304   trk_phiSector = 0;
0305   trk_seed = 0;
0306   trk_hitpattern = 0;
0307   trk_injet = 0;
0308   trk_injet_highpt = 0;
0309   trk_injet_vhighpt = 0;
0310   trk_fake = 0;
0311   trk_genuine = 0;
0312   trk_loose = 0;
0313 
0314   tree->SetBranchAddress("tp_pt", &tp_pt, &b_tp_pt);
0315   tree->SetBranchAddress("tp_eta", &tp_eta, &b_tp_eta);
0316   tree->SetBranchAddress("tp_phi", &tp_phi, &b_tp_phi);
0317   tree->SetBranchAddress("tp_dxy", &tp_dxy, &b_tp_dxy);
0318   tree->SetBranchAddress("tp_z0", &tp_z0, &b_tp_z0);
0319   tree->SetBranchAddress("tp_d0", &tp_d0, &b_tp_d0);
0320   tree->SetBranchAddress("tp_pdgid", &tp_pdgid, &b_tp_pdgid);
0321   if (doLooseMatch)
0322     tree->SetBranchAddress("tp_nloosematch", &tp_nmatch, &b_tp_nmatch);
0323   else
0324     tree->SetBranchAddress("tp_nmatch", &tp_nmatch, &b_tp_nmatch);
0325   tree->SetBranchAddress("tp_nstub", &tp_nstub, &b_tp_nstub);
0326   tree->SetBranchAddress("tp_eventid", &tp_eventid, &b_tp_eventid);
0327   if (TP_select_injet > 0) {
0328     tree->SetBranchAddress("tp_injet", &tp_injet, &b_tp_injet);
0329     tree->SetBranchAddress("tp_injet_highpt", &tp_injet_highpt, &b_tp_injet_highpt);
0330     tree->SetBranchAddress("tp_injet_vhighpt", &tp_injet_vhighpt, &b_tp_injet_vhighpt);
0331   }
0332 
0333   if (doLooseMatch) {
0334     tree->SetBranchAddress("loosematchtrk_pt", &matchtrk_pt, &b_matchtrk_pt);
0335     tree->SetBranchAddress("loosematchtrk_eta", &matchtrk_eta, &b_matchtrk_eta);
0336     tree->SetBranchAddress("loosematchtrk_phi", &matchtrk_phi, &b_matchtrk_phi);
0337     tree->SetBranchAddress("loosematchtrk_d0", &matchtrk_d0, &b_matchtrk_d0);
0338     tree->SetBranchAddress("loosematchtrk_z0", &matchtrk_z0, &b_matchtrk_z0);
0339     tree->SetBranchAddress("loosematchtrk_chi2", &matchtrk_chi2, &b_matchtrk_chi2);
0340     tree->SetBranchAddress("loosematchtrk_chi2_dof", &matchtrk_chi2_dof, &b_matchtrk_chi2_dof);
0341     tree->SetBranchAddress("loosematchtrk_chi2rphi", &matchtrk_chi2rphi, &b_matchtrk_chi2rphi);
0342     tree->SetBranchAddress("loosematchtrk_chi2rphi_dof", &matchtrk_chi2rphi_dof, &b_matchtrk_chi2rphi_dof);
0343     tree->SetBranchAddress("loosematchtrk_chi2rz", &matchtrk_chi2rz, &b_matchtrk_chi2rz);
0344     tree->SetBranchAddress("loosematchtrk_chi2rz_dof", &matchtrk_chi2rz_dof, &b_matchtrk_chi2rz_dof);
0345     tree->SetBranchAddress("loosematchtrk_nstub", &matchtrk_nstub, &b_matchtrk_nstub);
0346     tree->SetBranchAddress("loosematchtrk_seed", &matchtrk_seed, &b_matchtrk_seed);
0347     tree->SetBranchAddress("loosematchtrk_hitpattern", &matchtrk_hitpattern, &b_matchtrk_hitpattern);
0348     if (TP_select_injet > 0) {
0349       tree->SetBranchAddress("loosematchtrk_injet", &matchtrk_injet, &b_matchtrk_injet);
0350       tree->SetBranchAddress("loosematchtrk_injet_highpt", &matchtrk_injet_highpt, &b_matchtrk_injet_highpt);
0351       tree->SetBranchAddress("loosematchtrk_injet_vhighpt", &matchtrk_injet_vhighpt, &b_matchtrk_injet_vhighpt);
0352     }
0353   } else {
0354     tree->SetBranchAddress("matchtrk_pt", &matchtrk_pt, &b_matchtrk_pt);
0355     tree->SetBranchAddress("matchtrk_eta", &matchtrk_eta, &b_matchtrk_eta);
0356     tree->SetBranchAddress("matchtrk_phi", &matchtrk_phi, &b_matchtrk_phi);
0357     tree->SetBranchAddress("matchtrk_d0", &matchtrk_d0, &b_matchtrk_d0);
0358     tree->SetBranchAddress("matchtrk_z0", &matchtrk_z0, &b_matchtrk_z0);
0359     tree->SetBranchAddress("matchtrk_chi2", &matchtrk_chi2, &b_matchtrk_chi2);
0360     tree->SetBranchAddress("matchtrk_chi2_dof", &matchtrk_chi2_dof, &b_matchtrk_chi2_dof);
0361     tree->SetBranchAddress("matchtrk_chi2rphi", &matchtrk_chi2rphi, &b_matchtrk_chi2rphi);
0362     tree->SetBranchAddress("matchtrk_chi2rphi_dof", &matchtrk_chi2rphi_dof, &b_matchtrk_chi2rphi_dof);
0363     tree->SetBranchAddress("matchtrk_chi2rz", &matchtrk_chi2rz, &b_matchtrk_chi2rz);
0364     tree->SetBranchAddress("matchtrk_chi2rz_dof", &matchtrk_chi2rz_dof, &b_matchtrk_chi2rz_dof);
0365     tree->SetBranchAddress("matchtrk_nstub", &matchtrk_nstub, &b_matchtrk_nstub);
0366     tree->SetBranchAddress("matchtrk_lhits", &matchtrk_lhits, &b_matchtrk_lhits);
0367     tree->SetBranchAddress("matchtrk_dhits", &matchtrk_dhits, &b_matchtrk_dhits);
0368     tree->SetBranchAddress("matchtrk_seed", &matchtrk_seed, &b_matchtrk_seed);
0369     tree->SetBranchAddress("matchtrk_hitpattern", &matchtrk_hitpattern, &b_matchtrk_hitpattern);
0370     if (TP_select_injet > 0) {
0371       tree->SetBranchAddress("matchtrk_injet", &matchtrk_injet, &b_matchtrk_injet);
0372       tree->SetBranchAddress("matchtrk_injet_highpt", &matchtrk_injet_highpt, &b_matchtrk_injet_highpt);
0373       tree->SetBranchAddress("matchtrk_injet_vhighpt", &matchtrk_injet_vhighpt, &b_matchtrk_injet_vhighpt);
0374     }
0375   }
0376 
0377   tree->SetBranchAddress("trk_pt", &trk_pt, &b_trk_pt);
0378   tree->SetBranchAddress("trk_eta", &trk_eta, &b_trk_eta);
0379   tree->SetBranchAddress("trk_phi", &trk_phi, &b_trk_phi);
0380   tree->SetBranchAddress("trk_chi2", &trk_chi2, &b_trk_chi2);
0381   tree->SetBranchAddress("trk_chi2_dof", &trk_chi2_dof, &b_trk_chi2_dof);
0382   tree->SetBranchAddress("trk_chi2rphi", &trk_chi2rphi, &b_trk_chi2rphi);
0383   tree->SetBranchAddress("trk_chi2rphi_dof", &trk_chi2rphi_dof, &b_trk_chi2rphi_dof);
0384   tree->SetBranchAddress("trk_chi2rz", &trk_chi2rz, &b_trk_chi2rz);
0385   tree->SetBranchAddress("trk_chi2rz_dof", &trk_chi2rz_dof, &b_trk_chi2rz_dof);
0386   tree->SetBranchAddress("trk_nstub", &trk_nstub, &b_trk_nstub);
0387   tree->SetBranchAddress("trk_lhits", &trk_lhits, &b_trk_lhits);
0388   tree->SetBranchAddress("trk_dhits", &trk_dhits, &b_trk_dhits);
0389   tree->SetBranchAddress("trk_phiSector", &trk_phiSector, &b_trk_phiSector);
0390   tree->SetBranchAddress("trk_seed", &trk_seed, &b_trk_seed);
0391   tree->SetBranchAddress("trk_hitpattern", &trk_hitpattern, &b_trk_hitpattern);
0392   tree->SetBranchAddress("trk_fake", &trk_fake, &b_trk_fake);
0393   tree->SetBranchAddress("trk_genuine", &trk_genuine, &b_trk_genuine);
0394   tree->SetBranchAddress("trk_loose", &trk_loose, &b_trk_loose);
0395   if (TP_select_injet > 0) {
0396     tree->SetBranchAddress("trk_injet", &trk_injet, &b_trk_injet);
0397     tree->SetBranchAddress("trk_injet_highpt", &trk_injet_highpt, &b_trk_injet_highpt);
0398     tree->SetBranchAddress("trk_injet_vhighpt", &trk_injet_vhighpt, &b_trk_injet_vhighpt);
0399   }
0400 
0401   // ----------------------------------------------------------------------------------------------------------------
0402   // histograms
0403   // ----------------------------------------------------------------------------------------------------------------
0404 
0405   /////////////////////////////////////////////////
0406   // NOTATION:                                   //
0407   // 'C' - Central eta range, |eta|<0.8          //
0408   // 'I' - Intermediate eta range, 0.8<|eta|<1.6 //
0409   // 'F' - Forward eta range, |eta|>1.6          //
0410   //                                             //
0411   // 'L' - Low pt range,  pt<8 GeV               //
0412   // 'H' - High pt range, pt>8 GeV               //
0413   /////////////////////////////////////////////////
0414 
0415   // ----------------------------------------------------------------------------------------------------------------
0416   // for efficiencies
0417 
0418   TH1F* h_tp_pt = new TH1F("tp_pt", ";Tracking particle p_{T} [GeV]; Tracking particles / 1.0 GeV", 100, 0, 100.0);
0419   TH1F* h_tp_pt_L = new TH1F("tp_pt_L", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 80, 0, 8.0);
0420   TH1F* h_tp_pt_LC = new TH1F("tp_pt_LC", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 80, 0, 8.0);
0421   TH1F* h_tp_pt_H = new TH1F("tp_pt_H", ";Tracking particle p_{T} [GeV]; Tracking particles / 1.0 GeV", 92, 8.0, 100.0);
0422   TH1F* h_tp_eta = new TH1F("tp_eta", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0423   TH1F* h_tp_eta_L = new TH1F("tp_eta_L", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0424   TH1F* h_tp_eta_H = new TH1F("tp_eta_H", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0425   TH1F* h_tp_eta_23 = new TH1F("tp_eta_23", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0426   TH1F* h_tp_eta_35 = new TH1F("tp_eta_35", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0427   TH1F* h_tp_eta_5 = new TH1F("tp_eta_5", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0428 
0429   TH1F* h_match_tp_pt =
0430       new TH1F("match_tp_pt", ";Tracking particle p_{T} [GeV]; Tracking particles / 1.0 GeV", 100, 0, 100.0);
0431   TH1F* h_match_tp_pt_L =
0432       new TH1F("match_tp_pt_L", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 80, 0, 8.0);
0433   TH1F* h_match_tp_pt_LC =
0434       new TH1F("match_tp_pt_LC", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 80, 0, 8.0);
0435   TH1F* h_match_tp_pt_H =
0436       new TH1F("match_tp_pt_H", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 92, 8.0, 100.0);
0437   TH1F* h_match_tp_eta = new TH1F("match_tp_eta", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0438   TH1F* h_match_tp_eta_L =
0439       new TH1F("match_tp_eta_L", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0440   TH1F* h_match_tp_eta_H =
0441       new TH1F("match_tp_eta_H", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0442   TH1F* h_match_tp_eta_23 =
0443       new TH1F("match_tp_eta_23", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0444   TH1F* h_match_tp_eta_35 =
0445       new TH1F("match_tp_eta_35", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0446   TH1F* h_match_tp_eta_5 =
0447       new TH1F("match_tp_eta_5", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5);
0448 
0449   // ----------------------------------------------------------------------------------------------------------------
0450   // Tracklet propogation efficiencies vs. eta for seeding layers
0451 
0452   int trackletEffEtaBins = 24;
0453   double trackletEffMaxEta = 2.4;
0454   int numLayers = 11;
0455   TH2F* h_trk_tracklet_hits = new TH2F("trk_tracklet_hits",
0456                                        ";Track |#eta|; Layer index (0-5 = L1-6, 6-10 = D1-5)",
0457                                        trackletEffEtaBins,
0458                                        0,
0459                                        trackletEffMaxEta,
0460                                        11,
0461                                        0,
0462                                        11);  //used to create below hist
0463   TH2F* h_trk_tracklet_eff = new TH2F("trk_tracklet_eff",
0464                                       ";Track |#eta|; Layer index (0-5 = L1-6, 6-10 = D1-5)",
0465                                       trackletEffEtaBins,
0466                                       0,
0467                                       trackletEffMaxEta,
0468                                       11,
0469                                       0,
0470                                       11);
0471 
0472   // ----------------------------------------------------------------------------------------------------------------
0473   // resolution vs. pt histograms
0474 
0475   // ----------------------------------------------
0476   // for new versions of resolution vs pt/eta plots
0477   unsigned int nBinsPtRes = 500;
0478   double maxPtRes = 30.;
0479 
0480   unsigned int nBinsPtRelRes = 1000;
0481   double maxPtRelRes = 10.;
0482 
0483   unsigned int nBinsEtaRes = 500;
0484   double maxEtaRes = 0.1;
0485 
0486   unsigned int nBinsPhiRes = 500;
0487   double maxPhiRes = 0.2;
0488 
0489   unsigned int nBinsZ0Res = 100;
0490   double maxZ0Res = 4.0;
0491   // ----------------------------------------------
0492 
0493   const int nRANGE = 20;
0494   TString ptrange[nRANGE] = {"0-5",   "5-10",  "10-15", "15-20", "20-25", "25-30", "30-35", "35-40", "40-45", "45-50",
0495                              "50-55", "55-60", "60-65", "65-70", "70-75", "75-80", "80-85", "85-90", "90-95", "95-100"};
0496 
0497   const float pt_resmin = 1.5;
0498   const int nRANGE_L = 13;
0499   TString ptrange_L[nRANGE_L] = {"1.5-2",
0500                                  "2-2.5",
0501                                  "2.5-3",
0502                                  "3-3.5",
0503                                  "3.5-4",
0504                                  "4-4.5",
0505                                  "4.5-5",
0506                                  "5-5.5",
0507                                  "5.5-6",
0508                                  "6-6.5",
0509                                  "6.5-7",
0510                                  "7-7.5",
0511                                  "7.5-8"};
0512 
0513   TH1F* h_absResVsPt_pt[nRANGE];
0514   TH1F* h_absResVsPt_ptRel[nRANGE];
0515   TH1F* h_absResVsPt_z0[nRANGE];
0516   TH1F* h_absResVsPt_phi[nRANGE];
0517   TH1F* h_absResVsPt_eta[nRANGE];
0518   TH1F* h_absResVsPt_d0[nRANGE];
0519 
0520   TH1F* h_absResVsPt_pt_L[nRANGE_L];
0521   TH1F* h_absResVsPt_ptRel_L[nRANGE_L];
0522   TH1F* h_absResVsPt_z0_L[nRANGE_L];
0523   TH1F* h_absResVsPt_phi_L[nRANGE_L];
0524   TH1F* h_absResVsPt_eta_L[nRANGE_L];
0525   TH1F* h_absResVsPt_d0_L[nRANGE_L];
0526 
0527   for (int i = 0; i < nRANGE; i++) {
0528     h_absResVsPt_pt[i] = new TH1F(
0529         "absResVsPt_pt_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPtRes, 0, maxPtRes);
0530     h_absResVsPt_ptRel[i] = new TH1F("absResVsPt_ptRel_" + ptrange[i],
0531                                      ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02",
0532                                      nBinsPtRelRes,
0533                                      0,
0534                                      maxPtRelRes);
0535     h_absResVsPt_z0[i] = new TH1F(
0536         "absResVsPt_z0_" + ptrange[i], ";z_{0} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsZ0Res, 0, maxZ0Res);
0537     h_absResVsPt_phi[i] = new TH1F(
0538         "absResVsPt_phi_" + ptrange[i], ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPhiRes, 0, maxPhiRes);
0539     h_absResVsPt_eta[i] = new TH1F(
0540         "absResVsPt_eta_" + ptrange[i], ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsEtaRes, 0, maxEtaRes);
0541     h_absResVsPt_d0[i] =
0542         new TH1F("absResVsPt_d0_" + ptrange[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02);
0543   }
0544 
0545   for (int i = 0; i < nRANGE_L; i++) {
0546     h_absResVsPt_pt_L[i] = new TH1F(
0547         "absResVsPt_L_pt_" + ptrange_L[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPtRes, 0, maxPtRes);
0548     h_absResVsPt_ptRel_L[i] = new TH1F("absResVsPt_L_ptRel_" + ptrange_L[i],
0549                                        ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02",
0550                                        nBinsPtRelRes,
0551                                        0,
0552                                        maxPtRelRes);
0553     h_absResVsPt_z0_L[i] = new TH1F(
0554         "absResVsPt_L_z0_" + ptrange_L[i], ";z_{0} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsZ0Res, 0, maxZ0Res);
0555     h_absResVsPt_phi_L[i] = new TH1F("absResVsPt_L_phi_" + ptrange_L[i],
0556                                      ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1",
0557                                      nBinsPhiRes,
0558                                      0,
0559                                      maxPhiRes);
0560     h_absResVsPt_eta_L[i] = new TH1F("absResVsPt_L_eta_" + ptrange_L[i],
0561                                      ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1",
0562                                      nBinsEtaRes,
0563                                      0,
0564                                      maxEtaRes);
0565     h_absResVsPt_d0_L[i] =
0566         new TH1F("absResVsPt_L_d0_" + ptrange_L[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02);
0567   }
0568 
0569   // resolution vs. eta histograms
0570 
0571   const float eta_resmax = 2.5;
0572   const int nETARANGE = 25;
0573   TString etarange[nETARANGE] = {"0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9",
0574                                  "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8",
0575                                  "1.9", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5"};
0576   /*
0577   const int nETARANGE = 12;
0578   TString etarange[nETARANGE] = {"0.2","0.4","0.6","0.8","1.0",
0579                  "1.2","1.4","1.6","1.8","2.0",
0580                  "2.2","2.4"};
0581   */
0582 
0583   TH1F* h_absResVsEta_eta[nETARANGE];
0584   TH1F* h_absResVsEta_z0[nETARANGE];
0585   TH1F* h_absResVsEta_phi[nETARANGE];
0586   TH1F* h_absResVsEta_ptRel[nETARANGE];
0587   TH1F* h_absResVsEta_d0[nETARANGE];
0588 
0589   TH1F* h_absResVsEta_eta_L[nETARANGE];
0590   TH1F* h_absResVsEta_z0_L[nETARANGE];
0591   TH1F* h_absResVsEta_phi_L[nETARANGE];
0592   TH1F* h_absResVsEta_ptRel_L[nETARANGE];
0593   TH1F* h_absResVsEta_d0_L[nETARANGE];
0594 
0595   TH1F* h_absResVsEta_eta_H[nETARANGE];
0596   TH1F* h_absResVsEta_z0_H[nETARANGE];
0597   TH1F* h_absResVsEta_phi_H[nETARANGE];
0598   TH1F* h_absResVsEta_ptRel_H[nETARANGE];
0599   TH1F* h_absResVsEta_d0_H[nETARANGE];
0600 
0601   for (int i = 0; i < nETARANGE; i++) {
0602     h_absResVsEta_eta[i] = new TH1F(
0603         "absResVsEta_eta_" + etarange[i], ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsEtaRes, 0, maxEtaRes);
0604     h_absResVsEta_z0[i] = new TH1F(
0605         "absResVsEta_z0_" + etarange[i], ";|z_{0} residual (L1 - sim)| [cm]; L1 tracks / 0.01", nBinsZ0Res, 0, maxZ0Res);
0606     h_absResVsEta_phi[i] = new TH1F(
0607         "absResVsEta_phi_" + etarange[i], ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPhiRes, 0, maxPhiRes);
0608     h_absResVsEta_ptRel[i] = new TH1F("absResVsEta_ptRel_" + etarange[i],
0609                                       ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02",
0610                                       nBinsPtRelRes,
0611                                       0,
0612                                       maxPtRelRes);
0613     h_absResVsEta_d0[i] =
0614         new TH1F("absResVsEta_d0_" + etarange[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02);
0615 
0616     h_absResVsEta_eta_L[i] = new TH1F("absResVsEta_eta_L_" + etarange[i],
0617                                       ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1",
0618                                       nBinsEtaRes,
0619                                       0,
0620                                       maxEtaRes);
0621     h_absResVsEta_z0_L[i] = new TH1F("absResVsEta_z0_L_" + etarange[i],
0622                                      ";|z_{0} residual (L1 - sim)| [cm]; L1 tracks / 0.01",
0623                                      nBinsZ0Res,
0624                                      0,
0625                                      maxZ0Res);
0626     h_absResVsEta_phi_L[i] = new TH1F("absResVsEta_phi_L_" + etarange[i],
0627                                       ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1",
0628                                       nBinsPhiRes,
0629                                       0,
0630                                       maxPhiRes);
0631     h_absResVsEta_ptRel_L[i] = new TH1F("absResVsEta_ptRel_L_" + etarange[i],
0632                                         ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02",
0633                                         nBinsPtRelRes,
0634                                         0,
0635                                         maxPtRelRes);
0636     h_absResVsEta_d0_L[i] =
0637         new TH1F("absResVsEta_d0_L_" + etarange[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02);
0638 
0639     h_absResVsEta_eta_H[i] = new TH1F("absResVsEta_eta_H_" + etarange[i],
0640                                       ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1",
0641                                       nBinsEtaRes,
0642                                       0,
0643                                       maxEtaRes);
0644     h_absResVsEta_z0_H[i] = new TH1F("absResVsEta_z0_H_" + etarange[i],
0645                                      ";|z_{0} residual (L1 - sim)| [cm]; L1 tracks / 0.01",
0646                                      nBinsZ0Res,
0647                                      0,
0648                                      maxZ0Res);
0649     h_absResVsEta_phi_H[i] = new TH1F("absResVsEta_phi_H_" + etarange[i],
0650                                       ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1",
0651                                       nBinsPhiRes,
0652                                       0,
0653                                       maxPhiRes);
0654     h_absResVsEta_ptRel_H[i] = new TH1F("absResVsEta_ptRel_H_" + etarange[i],
0655                                         ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02",
0656                                         nBinsPtRelRes,
0657                                         0,
0658                                         maxPtRelRes);
0659     h_absResVsEta_d0_H[i] =
0660         new TH1F("absResVsEta_d0_H_" + etarange[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02);
0661   }
0662 
0663   // resolution vs phi
0664 
0665   const int nPHIRANGE = 32;
0666   TString phirange[nPHIRANGE] = {"-3.0", "-2.8", "-2.6", "-2.4", "-2.2", "-2.0", "-1.8", "-1.6", "-1.4", "-1.2", "-1.0",
0667                                  "-0.8", "-0.6", "-0.4", "-0.2", "0.0",  "0.2",  "0.4",  "0.6",  "0.8",  "1.0",  "1.2",
0668                                  "1.4",  "1.6",  "1.8",  "2.0",  "2.2",  "2.4",  "2.6",  "2.8",  "3.0",  "3.2"};
0669 
0670   TH1F* h_absResVsPhi_pt[nPHIRANGE];
0671   TH1F* h_absResVsPhi_ptRel[nPHIRANGE];
0672 
0673   for (int i = 0; i < nPHIRANGE; i++) {
0674     h_absResVsPhi_pt[i] = new TH1F(
0675         "absResVsPt_pt_" + phirange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPtRes, 0, maxPtRes);
0676     h_absResVsPhi_ptRel[i] = new TH1F("absResVsPt_ptRel_" + phirange[i],
0677                                       ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02",
0678                                       nBinsPtRelRes,
0679                                       0,
0680                                       maxPtRelRes);
0681   }
0682 
0683   // ----------------------------------------------------------------------------------------------------------------
0684   // chi2 histograms (last bin is an overflow bin)
0685 
0686   TH1F* h_trk_chi2 = new TH1F("trk_chi2", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100);
0687   TH1F* h_trk_chi2_dof = new TH1F("trk_chi2_dof", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0688   TH1F* h_match_trk_chi2 = new TH1F("match_trk_chi2", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100);
0689   TH1F* h_match_trk_chi2_dof = new TH1F("match_trk_chi2_dof", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0690 
0691   TH1F* h_trk_chi2rphi = new TH1F("trk_chi2rphi", ";#chi^{2}_{r-#phi}; L1 tracks / 1.0", 100, 0, 100);
0692   TH1F* h_trk_chi2rphi_dof = new TH1F("trk_chi2rphi_dof", ";#chi^{2}_{r-#phi} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0693   TH1F* h_match_trk_chi2rphi = new TH1F("match_trk_chi2rphi", ";#chi^{2}_{r-#phi}; L1 tracks / 1.0", 100, 0, 100);
0694   TH1F* h_match_trk_chi2rphi_dof =
0695       new TH1F("match_trk_chi2rphi_dof", ";#chi^{2}_{r-#phi} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0696 
0697   TH1F* h_trk_chi2rz = new TH1F("trk_chi2rz", ";#chi^{2}_{r-z}; L1 tracks / 1.0", 100, 0, 100);
0698   TH1F* h_trk_chi2rz_dof = new TH1F("trk_chi2rz_dof", ";#chi^{2}_{r-z} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0699   TH1F* h_match_trk_chi2rz = new TH1F("match_trk_chi2rz", ";#chi^{2}_{r-z}; L1 tracks / 1.0", 100, 0, 100);
0700   TH1F* h_match_trk_chi2rz_dof =
0701       new TH1F("match_trk_chi2rz_dof", ";#chi^{2}_{r-z} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0702 
0703   // ----------------------------------------------------------------------------------------------------------------
0704   // total track rates
0705 
0706   TH1F* h_trk_all_vspt = new TH1F("trk_all_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25);
0707   TH1F* h_trk_loose_vspt = new TH1F("trk_loose_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25);
0708   TH1F* h_trk_genuine_vspt = new TH1F("trk_genuine_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25);
0709   TH1F* h_trk_notloose_vspt = new TH1F(
0710       "trk_notloose_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25);  //(same as "fake" according to the trk_fake labeling)
0711   TH1F* h_trk_notgenuine_vspt = new TH1F("trk_notgenuine_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25);
0712   TH1F* h_trk_duplicate_vspt = new TH1F("trk_duplicate_vspt",
0713                                         ";Track p_{T} [GeV]; ",
0714                                         50,
0715                                         0,
0716                                         25);  //where a TP is genuinely matched to more than one L1 track
0717   TH1F* h_tp_vspt = new TH1F("tp_vspt", ";TP p_{T} [GeV]; ", 50, 0, 25);
0718 
0719   // ----------------------------------------------------------------------------------------------------------------
0720 
0721   TH1F* h_tp_z0 = new TH1F("tp_z0", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0);
0722   TH1F* h_tp_z0_L = new TH1F("tp_z0_L", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0);
0723   TH1F* h_tp_z0_H = new TH1F("tp_z0_H", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0);
0724 
0725   TH1F* h_match_tp_z0 =
0726       new TH1F("match_tp_z0", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0);
0727   TH1F* h_match_tp_z0_L =
0728       new TH1F("match_tp_z0_L", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0);
0729   TH1F* h_match_tp_z0_H =
0730       new TH1F("match_tp_z0_H", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0);
0731 
0732   // ----------------------------------------------------------------------------------------------------------------
0733   //
0734   //       ******************   additional histograms drawn if using 'detailed' option   ******************
0735   //
0736   // ----------------------------------------------------------------------------------------------------------------
0737 
0738   const float maxD0plot = TP_maxD0;
0739 
0740   TH1F* h_tp_phi = new TH1F("tp_phi", ";Tracking particle #phi [rad]; Tracking particles / 0.1", 64, -3.2, 3.2);
0741   TH1F* h_tp_d0 =
0742       new TH1F("tp_d0", ";Tracking particle d_{0} [cm]; Tracking particles / 0.01 cm", 50, -maxD0plot, maxD0plot);
0743   TH1F* h_tp_absd0 =
0744       new TH1F("tp_absd0", ";Tracking particle |d_{0}| [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot);
0745   TH1F* h_tp_absd0_eta2 =
0746       new TH1F("tp_absd0_eta2", ";Tracking particle |d_{0}| [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot);
0747   TH1F* h_tp_absd0_eta2_pt3 =
0748       new TH1F("tp_absd0_eta2_pt3", ";Tracking particle |d_{0}| [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot);
0749 
0750   TH1F* h_match_tp_phi =
0751       new TH1F("match_tp_phi", ";Tracking particle #phi [rad]; Tracking particles / 0.1", 64, -3.2, 3.2);
0752   TH1F* h_match_tp_d0 =
0753       new TH1F("match_tp_d0", ";Tracking particle d_{0} [cm]; Tracking particles / 0.01 cm", 50, -maxD0plot, maxD0plot);
0754   TH1F* h_match_tp_absd0 =
0755       new TH1F("match_tp_absd0", ";Tracking particle d_{0} [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot);
0756   TH1F* h_match_tp_absd0_eta2 =
0757       new TH1F("match_tp_absd0_eta2", ";Tracking particle d_{0} [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot);
0758   TH1F* h_match_tp_absd0_eta2_pt3 = new TH1F(
0759       "match_tp_absd0_eta2_pt3", ";Tracking particle d_{0} [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot);
0760 
0761   TH1F* h_match_trk_nstub = new TH1F("match_trk_nstub", ";Number of stubs; L1 tracks / 1.0", 15, 0, 15);
0762   TH1F* h_match_trk_nstub_C = new TH1F("match_trk_nstub_C", ";Number of stubs; L1 tracks / 1.0", 15, 0, 15);
0763   TH1F* h_match_trk_nstub_I = new TH1F("match_trk_nstub_I", ";Number of stubs; L1 tracks / 1.0", 15, 0, 15);
0764   TH1F* h_match_trk_nstub_F = new TH1F("match_trk_nstub_F", ";Number of stubs; L1 tracks / 1.0", 15, 0, 15);
0765 
0766   // note that we are only making the below chi2 histograms using the joint chi2, not the separate chi2rphi and chi2rz
0767 
0768   // chi2 histograms
0769   // note: last bin is an overflow bin
0770   TH1F* h_match_trk_chi2_C_L = new TH1F("match_trk_chi2_C_L", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100);
0771   TH1F* h_match_trk_chi2_I_L = new TH1F("match_trk_chi2_I_L", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100);
0772   TH1F* h_match_trk_chi2_F_L = new TH1F("match_trk_chi2_F_L", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100);
0773   TH1F* h_match_trk_chi2_C_H = new TH1F("match_trk_chi2_C_H", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100);
0774   TH1F* h_match_trk_chi2_I_H = new TH1F("match_trk_chi2_I_H", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100);
0775   TH1F* h_match_trk_chi2_F_H = new TH1F("match_trk_chi2_F_H", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100);
0776 
0777   // chi2/dof histograms
0778   // note: lastbin is an overflow bin
0779   TH1F* h_match_trk_chi2_dof_C_L =
0780       new TH1F("match_trk_chi2_dof_C_L", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0781   TH1F* h_match_trk_chi2_dof_I_L =
0782       new TH1F("match_trk_chi2_dof_I_L", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0783   TH1F* h_match_trk_chi2_dof_F_L =
0784       new TH1F("match_trk_chi2_dof_F_L", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0785   TH1F* h_match_trk_chi2_dof_C_H =
0786       new TH1F("match_trk_chi2_dof_C_H", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0787   TH1F* h_match_trk_chi2_dof_I_H =
0788       new TH1F("match_trk_chi2_dof_I_H", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0789   TH1F* h_match_trk_chi2_dof_F_H =
0790       new TH1F("match_trk_chi2_dof_F_H", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20);
0791 
0792   // ----------------------------------------------------------------------------------------------------------------
0793   // resolution histograms
0794   TH1F* h_res_pt = new TH1F("res_pt", ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.05", 200, -5.0, 5.0);
0795   TH1F* h_res_ptRel = new TH1F("res_ptRel", ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.01", 200, -1.0, 1.0);
0796   TH1F* h_res_eta = new TH1F("res_eta", ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01);
0797   TH1F* h_res_phi = new TH1F("res_phi", ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005);
0798 
0799   TH1F* h_res_z0 = new TH1F("res_z0", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0);
0800   TH1F* h_res_z0_C = new TH1F("res_z0_C", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0);
0801   TH1F* h_res_z0_I = new TH1F("res_z0_I", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0);
0802   TH1F* h_res_z0_F = new TH1F("res_z0_F", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0);
0803   TH1F* h_res_z0_L = new TH1F("res_z0_L", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0);
0804   TH1F* h_res_z0_H = new TH1F("res_z0_H", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0);
0805 
0806   TH1F* h_res_z0_C_L =
0807       new TH1F("res_z0_C_L", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0);
0808   TH1F* h_res_z0_I_L =
0809       new TH1F("res_z0_I_L", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0);
0810   TH1F* h_res_z0_F_L =
0811       new TH1F("res_z0_F_L", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0);
0812   TH1F* h_res_z0_C_H =
0813       new TH1F("res_z0_C_H", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0);
0814   TH1F* h_res_z0_I_H =
0815       new TH1F("res_z0_I_H", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0);
0816   TH1F* h_res_z0_F_H =
0817       new TH1F("res_z0_F_H", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0);
0818 
0819   TH1F* h_res_d0 = new TH1F("res_d0", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0002 cm", 200, -0.02, 0.02);
0820   TH1F* h_res_d0_C = new TH1F("res_d0_C", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0821   TH1F* h_res_d0_I = new TH1F("res_d0_I", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0822   TH1F* h_res_d0_F = new TH1F("res_d0_F", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0823   TH1F* h_res_d0_L = new TH1F("res_d0_L", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0824   TH1F* h_res_d0_H = new TH1F("res_d0_H", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0825 
0826   TH1F* h_res_d0_C_L =
0827       new TH1F("res_d0_C_L", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0828   TH1F* h_res_d0_I_L =
0829       new TH1F("res_d0_I_L", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0830   TH1F* h_res_d0_F_L =
0831       new TH1F("res_d0_F_L", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0832   TH1F* h_res_d0_C_H =
0833       new TH1F("res_d0_C_H", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0834   TH1F* h_res_d0_I_H =
0835       new TH1F("res_d0_I_H", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0836   TH1F* h_res_d0_F_H =
0837       new TH1F("res_d0_F_H", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05);
0838 
0839   // ----------------------------------------------------------------------------------------------------------------
0840   // more resolution vs pt
0841 
0842   TH1F* h_resVsPt_pt[nRANGE];
0843   TH1F* h_resVsPt_pt_C[nRANGE];
0844   TH1F* h_resVsPt_pt_I[nRANGE];
0845   TH1F* h_resVsPt_pt_F[nRANGE];
0846 
0847   TH1F* h_resVsPt_ptRel[nRANGE];
0848   TH1F* h_resVsPt_ptRel_C[nRANGE];
0849   TH1F* h_resVsPt_ptRel_I[nRANGE];
0850   TH1F* h_resVsPt_ptRel_F[nRANGE];
0851 
0852   TH1F* h_resVsPt_z0[nRANGE];
0853   TH1F* h_resVsPt_z0_C[nRANGE];
0854   TH1F* h_resVsPt_z0_I[nRANGE];
0855   TH1F* h_resVsPt_z0_F[nRANGE];
0856 
0857   TH1F* h_resVsPt_phi[nRANGE];
0858   TH1F* h_resVsPt_phi_C[nRANGE];
0859   TH1F* h_resVsPt_phi_I[nRANGE];
0860   TH1F* h_resVsPt_phi_F[nRANGE];
0861 
0862   TH1F* h_resVsPt_eta[nRANGE];
0863   TH1F* h_resVsPt_d0[nRANGE];
0864 
0865   for (int i = 0; i < nRANGE; i++) {
0866     h_resVsPt_pt[i] =
0867         new TH1F("resVsPt_pt_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, -5.0, 5.0);
0868     h_resVsPt_pt_C[i] =
0869         new TH1F("resVsPt_pt_C_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, -5.0, 5.0);
0870     h_resVsPt_pt_I[i] =
0871         new TH1F("resVsPt_pt_I_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, -5.0, 5.0);
0872     h_resVsPt_pt_F[i] =
0873         new TH1F("resVsPt_pt_F_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, -5.0, 5.0);
0874 
0875     h_resVsPt_ptRel[i] = new TH1F(
0876         "resVsPt_ptRel_" + ptrange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 300, -0.15, 0.15);
0877     h_resVsPt_ptRel_C[i] = new TH1F(
0878         "resVsPt_ptRel_c_" + ptrange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 300, -0.15, 0.15);
0879     h_resVsPt_ptRel_I[i] = new TH1F(
0880         "resVsPt_ptRel_I_" + ptrange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 300, -0.15, 0.15);
0881     h_resVsPt_ptRel_F[i] = new TH1F(
0882         "resVsPt_ptRel_F_" + ptrange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 300, -0.15, 0.15);
0883 
0884     h_resVsPt_z0[i] =
0885         new TH1F("resVsPt_z0_" + ptrange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1, 1);
0886     h_resVsPt_z0_C[i] =
0887         new TH1F("resVsPt_z0_C_" + ptrange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1, 1);
0888     h_resVsPt_z0_I[i] =
0889         new TH1F("resVsPt_z0_I_" + ptrange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1, 1);
0890     h_resVsPt_z0_F[i] =
0891         new TH1F("resVsPt_z0_F_" + ptrange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1, 1);
0892 
0893     h_resVsPt_phi[i] = new TH1F(
0894         "resVsPt_phi_" + ptrange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005);
0895     h_resVsPt_phi_C[i] = new TH1F(
0896         "resVsPt_phi_C_" + ptrange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005);
0897     h_resVsPt_phi_I[i] = new TH1F(
0898         "resVsPt_phi_I_" + ptrange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005);
0899     h_resVsPt_phi_F[i] = new TH1F(
0900         "resVsPt_phi_F_" + ptrange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005);
0901 
0902     h_resVsPt_eta[i] =
0903         new TH1F("resVsPt_eta_" + ptrange[i], ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01);
0904 
0905     h_resVsPt_d0[i] =
0906         new TH1F("resVsPt_d0_" + ptrange[i], ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0004", 100, -0.02, 0.02);
0907   }
0908 
0909   // ----------------------------------------------------------------------------------------------------------------
0910   // more resolution vs eta
0911 
0912   TH1F* h_resVsEta_eta[nETARANGE];
0913   TH1F* h_resVsEta_eta_L[nETARANGE];
0914   TH1F* h_resVsEta_eta_H[nETARANGE];
0915 
0916   TH1F* h_resVsEta_z0[nETARANGE];
0917   TH1F* h_resVsEta_z0_L[nETARANGE];
0918   TH1F* h_resVsEta_z0_H[nETARANGE];
0919 
0920   TH1F* h_resVsEta_phi[nETARANGE];
0921   TH1F* h_resVsEta_phi_L[nETARANGE];
0922   TH1F* h_resVsEta_phi_H[nETARANGE];
0923 
0924   TH1F* h_resVsEta_ptRel[nETARANGE];
0925   TH1F* h_resVsEta_ptRel_L[nETARANGE];
0926   TH1F* h_resVsEta_ptRel_H[nETARANGE];
0927 
0928   TH1F* h_resVsEta_d0[nETARANGE];
0929   TH1F* h_resVsEta_d0_L[nETARANGE];
0930   TH1F* h_resVsEta_d0_H[nETARANGE];
0931 
0932   for (int i = 0; i < nETARANGE; i++) {
0933     h_resVsEta_eta[i] =
0934         new TH1F("resVsEta2_eta_" + etarange[i], ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01);
0935     h_resVsEta_eta_L[i] =
0936         new TH1F("resVsEta2_eta_L_" + etarange[i], ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01);
0937     h_resVsEta_eta_H[i] =
0938         new TH1F("resVsEta2_eta_H_" + etarange[i], ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01);
0939 
0940     h_resVsEta_z0[i] =
0941         new TH1F("resVsEta2_z0_" + etarange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.01", 100, -1, 1);
0942     h_resVsEta_z0_L[i] =
0943         new TH1F("resVsEta2_z0_L_" + etarange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.01", 100, -1, 1);
0944     h_resVsEta_z0_H[i] =
0945         new TH1F("resVsEta2_z0_H_" + etarange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.01", 100, -1, 1);
0946 
0947     h_resVsEta_phi[i] = new TH1F(
0948         "resVsEta2_phi_" + etarange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005);
0949     h_resVsEta_phi_L[i] = new TH1F(
0950         "resVsEta2_phi_L_" + etarange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005);
0951     h_resVsEta_phi_H[i] = new TH1F(
0952         "resVsEta2_phi_H_" + etarange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005);
0953 
0954     h_resVsEta_ptRel[i] = new TH1F(
0955         "resVsEta2_ptRel_" + etarange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.01", 100, -0.5, 0.5);
0956     h_resVsEta_ptRel_L[i] = new TH1F(
0957         "resVsEta2_ptRel_L_" + etarange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 100, -0.1, 0.1);
0958     h_resVsEta_ptRel_H[i] = new TH1F(
0959         "resVsEta2_ptRel_H_" + etarange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 100, -0.25, 0.25);
0960 
0961     h_resVsEta_d0[i] =
0962         new TH1F("resVsEta2_d0_" + etarange[i], ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.004", 100, -0.02, 0.02);
0963     h_resVsEta_d0_L[i] = new TH1F(
0964         "resVsEta2_d0_L_" + etarange[i], ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.004", 100, -0.02, 0.02);
0965     h_resVsEta_d0_H[i] = new TH1F(
0966         "resVsEta2_d0_H_" + etarange[i], ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.004", 100, -0.02, 0.02);
0967   }
0968   // ----------------------------------------------------------------------------------------------------------------
0969 
0970   // ----------------------------------------------------------------------------------------------------------------
0971   // additional ones for sum pt in jets
0972   /*
0973   TH1F* h_jet_tp_sumpt_vspt  = new TH1F("jet_tp_sumpt_vspt",  ";sum(TP p_{T}) [GeV]; Gen jets / 5.0 GeV", 20, 0, 200.0);
0974   TH1F* h_jet_trk_sumpt_vspt = new TH1F("jet_trk_sumpt_vspt", ";sum(TP p_{T}) [GeV]; Gen jets / 5.0 GeV", 20, 0, 200.0);
0975   TH1F* h_jet_matchtrk_sumpt_vspt = new TH1F("jet_matchtrk_sumpt_vspt", ";sum(TP p_{T}) [GeV]; Gen jets / 5.0 GeV", 20, 0, 200.0);
0976 
0977   TH1F* h_jet_tp_sumpt_vseta  = new TH1F("jet_tp_sumpt_vseta",  ";Gen jet #eta; Gen jets / 0.2", 24, -2.4, 2.4);
0978   TH1F* h_jet_trk_sumpt_vseta = new TH1F("jet_trk_sumpt_vseta", ";Gen jet #eta; Gen jets / 0.2", 24, -2.4, 2.4);
0979   TH1F* h_jet_matchtrk_sumpt_vseta = new TH1F("jet_matchtrk_sumpt_vseta", ";Gen jet #eta; Gen jets / 0.2", 24, -2.4, 2.4);
0980 
0981   h_jet_tp_sumpt_vseta->Sumw2();
0982   h_jet_tp_sumpt_vspt->Sumw2();
0983   h_jet_trk_sumpt_vseta->Sumw2();
0984   h_jet_trk_sumpt_vspt->Sumw2();
0985   h_jet_matchtrk_sumpt_vseta->Sumw2();
0986   h_jet_matchtrk_sumpt_vspt->Sumw2();
0987   */
0988 
0989   // ----------------------------------------------------------------------------------------------------------------
0990   // number of tracks per event
0991 
0992   // all tracks
0993   TH1F* h_ntrk_pt2 = new TH1F("ntrk_pt2", ";# tracks (p_{T} > 2 GeV) / event; Events", 400, 0, 400.0);
0994   TH1F* h_ntrk_pt3 = new TH1F("ntrk_pt3", ";# tracks (p_{T} > 3 GeV) / event; Events", 300, 0, 300.0);
0995   TH1F* h_ntrk_pt10 = new TH1F("ntrk_pt10", ";# tracks (p_{T} > 10 GeV) / event; Events", 100, 0, 100.0);
0996 
0997   // tracks flagged as genuine (this would include duplicates (?))
0998   TH1F* h_ntrk_genuine_pt2 =
0999       new TH1F("ntrk_genuine_pt2", ";# genuine tracks (p_{T} > 2 GeV) / event; Events", 400, 0, 400.0);
1000   TH1F* h_ntrk_genuine_pt3 =
1001       new TH1F("ntrk_genuine_pt3", ";# genuine tracks (p_{T} > 3 GeV) / event; Events", 300, 0, 300.0);
1002   TH1F* h_ntrk_genuine_pt10 =
1003       new TH1F("ntrk_genuine_pt10", ";# genuine tracks (p_{T} > 10 GeV) / event; Events", 100, 0, 100.0);
1004 
1005   // Max N tracks from a sector per event
1006   TH1F* h_ntrkPerSector_all =
1007       new TH1F("ntrkPerSector_all", ";Max. # tracks from a sector / event; Events", 50, 0, 100.0);
1008   TH1F* h_ntrkPerSector_pt2 =
1009       new TH1F("ntrkPerSector_pt2", ";Max. # tracks from a sector (p_{T} > 2 GeV) / event; Events", 50, 0, 100.0);
1010   TH1F* h_ntrkPerSector_pt3 =
1011       new TH1F("ntrkPerSector_pt3", ";Max. # tracks from a sector (p_{T} > 3 GeV) / event; Events", 50, 0, 100.0);
1012   TH1F* h_ntrkPerSector_pt4 =
1013       new TH1F("ntrkPerSector_pt4", ";Max. # tracks from a sector (p_{T} > 10 GeV) / event; Events", 50, 0, 100.0);
1014 
1015   // number of tracks vs. efficiency (eta, pT)
1016   TH1F* h_trk_pt = new TH1F("trk_pt", Form(";Track p_{T} (GeV);Tracks / 0.5 GeV"), 200, 0., 100.);
1017   TH1F* h_trk_eta = new TH1F("trk_eta", Form(";Track #eta;Tracks / 0.026"), 200, -2.6, 2.6);
1018 
1019   // ----------------------------------------------------------------------------------------------------------------
1020   //        * * * * *     S T A R T   O F   A C T U A L   R U N N I N G   O N   E V E N T S     * * * * *
1021   // ----------------------------------------------------------------------------------------------------------------
1022 
1023   int nevt = tree->GetEntries();
1024   cout << "number of events = " << nevt << endl;
1025 
1026   // ----------------------------------------------------------------------------------------------------------------
1027   // event loop
1028   for (int i = 0; i < nevt; i++) {
1029     tree->GetEntry(i, 0);
1030 
1031     /*
1032     // ----------------------------------------------------------------------------------------------------------------
1033     // sumpt in jets
1034     if (TP_select_injet > 0) {
1035       for (int ij=0; ij<(int)jet_tp_sumpt->size(); ij++) {
1036 
1037     float fraction = 0;
1038     float fractionMatch = 0;
1039     if (jet_tp_sumpt->at(ij) > 0) {
1040       fraction = jet_trk_sumpt->at(ij)/jet_tp_sumpt->at(ij);
1041       fractionMatch = jet_matchtrk_sumpt->at(ij)/jet_tp_sumpt->at(ij);
1042     }
1043 
1044     h_jet_tp_sumpt_vspt->Fill(jet_tp_sumpt->at(ij),1.0);
1045     h_jet_trk_sumpt_vspt->Fill(jet_tp_sumpt->at(ij),fraction);
1046     h_jet_matchtrk_sumpt_vspt->Fill(jet_tp_sumpt->at(ij),fractionMatch);
1047 
1048     h_jet_tp_sumpt_vseta->Fill(jet_eta->at(ij),1.0);
1049     h_jet_trk_sumpt_vseta->Fill(jet_eta->at(ij),fraction);
1050     h_jet_matchtrk_sumpt_vseta->Fill(jet_eta->at(ij),fractionMatch);
1051       }
1052     }
1053     */
1054 
1055     // ----------------------------------------------------------------------------------------------------------------
1056     // track loop for total rates & fake rates.
1057 
1058     int ntrkevt_pt2 = 0;
1059     int ntrkevt_pt3 = 0;
1060     int ntrkevt_pt10 = 0;
1061 
1062     int ntrkevt_genuine_pt2 = 0;
1063     int ntrkevt_genuine_pt3 = 0;
1064     int ntrkevt_genuine_pt10 = 0;
1065 
1066     vector<unsigned int> nTrksPerSector_all(9, 0);
1067     vector<unsigned int> nTrksPerSector_pt2(9, 0);
1068     vector<unsigned int> nTrksPerSector_pt3(9, 0);
1069     vector<unsigned int> nTrksPerSector_pt4(9, 0);
1070 
1071     for (int it = 0; it < (int)trk_pt->size(); it++) {
1072       // ----------------------------------------------------------------------------------------------------------------
1073       // track properties
1074 
1075       // ----------------------------------------------------------------------------------------------------------------
1076       // Fill number of tracks vs track param
1077       h_trk_pt->Fill(trk_pt->at(it));
1078       h_trk_eta->Fill(trk_eta->at(it));
1079 
1080       // fill all trk chi2 & chi2/dof histograms, including for chi2 r-phi and chi2 r-z
1081       float chi2 = trk_chi2->at(it);
1082       float chi2dof = trk_chi2_dof->at(it);
1083       float chi2rphi = trk_chi2rphi->at(it);
1084       float chi2rphidof = trk_chi2rphi_dof->at(it);
1085       float chi2rz = trk_chi2rz->at(it);
1086       float chi2rzdof = trk_chi2rz_dof->at(it);
1087 
1088       // create overflow bins by restricting range of chi2
1089       int chi2Overflow = 100;
1090       int chi2DOFOverflow = 20;  //apprx chi2Overflow / avg. nstubs
1091       double buffer = 0.1;
1092 
1093       if (chi2 > chi2Overflow)
1094         chi2 = chi2Overflow - buffer;
1095       if (chi2dof > chi2DOFOverflow)
1096         chi2dof = chi2DOFOverflow - buffer;
1097       if (chi2rphi > chi2Overflow)
1098         chi2rphi = chi2Overflow - buffer;
1099       if (chi2rphidof > chi2DOFOverflow)
1100         chi2rphidof = chi2DOFOverflow - buffer;
1101       if (chi2rz > chi2Overflow)
1102         chi2rz = chi2Overflow - buffer;
1103       if (chi2rzdof > chi2DOFOverflow)
1104         chi2rzdof = chi2DOFOverflow - buffer;
1105 
1106       if (trk_pt->at(it) > TP_minPt) {  //TRK pt > TP_minPt
1107 
1108         h_trk_chi2->Fill(chi2);
1109         h_trk_chi2_dof->Fill(chi2dof);
1110 
1111         h_trk_chi2rphi->Fill(chi2rphi);
1112         h_trk_chi2rphi_dof->Fill(chi2rphidof);
1113 
1114         h_trk_chi2rz->Fill(chi2rz);
1115         h_trk_chi2rz_dof->Fill(chi2rzdof);
1116 
1117       }  //end TRK pt > TP_minPt
1118 
1119       // ----------------------------------------------------------------------------------------------------------------
1120       // look at track rate and fake rate, etc.
1121 
1122       // only look at tracks in (ttbar) jets ?
1123       if (TP_select_injet > 0) {
1124         if (TP_select_injet == 1 && trk_injet->at(it) == 0)
1125           continue;
1126         if (TP_select_injet == 2 && trk_injet_highpt->at(it) == 0)
1127           continue;
1128         if (TP_select_injet == 3 && trk_injet_vhighpt->at(it) == 0)
1129           continue;
1130       }
1131       ntrk++;
1132       if (trk_pt->at(it) >= 0.0)
1133         ++nTrksPerSector_all.at(trk_phiSector->at(it) % 9);
1134       if (std::abs(trk_eta->at(it)) > TP_maxEta)
1135         continue;
1136       if (trk_pt->at(it) < TP_minPt)
1137         continue;
1138 
1139       // Uncomment these cuts to see effect on rate & fake rate.
1140       //if (trk_chi2->at(it) > L1Tk_maxChi2) continue;
1141       //if (trk_chi2_dof->at(it) > L1Tk_maxChi2dof) continue;
1142       //if (trk_nstub->at(it) < L1Tk_minNstub) continue;
1143 
1144       // Tracklet & Hybrid have 9 sectors, but TMTT has 18 (with sectors 0 & 1 in nonant 0 etc).
1145       // As don't know here with algo used, "% 9" added to prevent crash, but not correct for TMTT.
1146       if (trk_pt->at(it) > 2.0)
1147         ++nTrksPerSector_pt2.at(trk_phiSector->at(it) % 9);
1148       if (trk_pt->at(it) > 3.0)
1149         ++nTrksPerSector_pt3.at(trk_phiSector->at(it) % 9);
1150       if (trk_pt->at(it) > 4.0)
1151         ++nTrksPerSector_pt4.at(trk_phiSector->at(it) % 9);
1152 
1153       if (trk_pt->at(it) > 2.0) {
1154         ntrk_pt2++;
1155         ntrkevt_pt2++;
1156         h_trk_all_vspt->Fill(trk_pt->at(it));
1157         if (trk_genuine->at(it) == 1) {
1158           ntrkevt_genuine_pt2++;
1159           h_trk_genuine_vspt->Fill(trk_pt->at(it));
1160         } else
1161           h_trk_notgenuine_vspt->Fill(trk_pt->at(it));
1162         if (trk_loose->at(it) == 1)
1163           h_trk_loose_vspt->Fill(trk_pt->at(it));
1164         else
1165           h_trk_notloose_vspt->Fill(trk_pt->at(it));
1166       }
1167       if (trk_pt->at(it) > 3.0) {
1168         ntrk_pt3++;
1169         ntrkevt_pt3++;
1170         if (trk_genuine->at(it) == 1)
1171           ntrkevt_genuine_pt3++;
1172       }
1173       if (trk_pt->at(it) > 10.0) {
1174         ntrk_pt10++;
1175         ntrkevt_pt10++;
1176         if (trk_genuine->at(it) == 1)
1177           ntrkevt_genuine_pt10++;
1178       }
1179 
1180       // ----------------------------------------------------------------------------------------------------------------
1181       // Fill tracklet propogation efficiency histo
1182 
1183       // create an 11-bit long iterable from lhits and dhits
1184       int num_layers = 6;
1185       int num_discs = 5;
1186       int lhits = trk_lhits->at(it);
1187       int dhits = trk_dhits->at(it);
1188       std::vector<int> layers = {};
1189       for (int layer_index = 0; layer_index < num_layers + num_discs; layer_index++) {
1190         if (layer_index < num_layers) {
1191           layers.push_back(lhits % 10);
1192           lhits /= 10;
1193         } else {
1194           layers.push_back(dhits % 10);
1195           dhits /= 10;
1196         }
1197       }
1198 
1199       for (unsigned int layer = 0; layer < layers.size(); layer++) {
1200         if (layers.at(layer)) {                                         // if there was a hit at this layer...
1201           h_trk_tracklet_hits->Fill(std::abs(trk_eta->at(it)), layer);  // ...fill this bin with the layer of the track.
1202         }
1203       }
1204     }
1205 
1206     h_ntrk_pt2->Fill(ntrkevt_pt2);
1207     h_ntrk_pt3->Fill(ntrkevt_pt3);
1208     h_ntrk_pt10->Fill(ntrkevt_pt10);
1209 
1210     h_ntrk_genuine_pt2->Fill(ntrkevt_genuine_pt2);
1211     h_ntrk_genuine_pt3->Fill(ntrkevt_genuine_pt3);
1212     h_ntrk_genuine_pt10->Fill(ntrkevt_genuine_pt10);
1213 
1214     h_ntrkPerSector_all->Fill(*std::max_element(nTrksPerSector_all.begin(), nTrksPerSector_all.end()));
1215     h_ntrkPerSector_pt2->Fill(*std::max_element(nTrksPerSector_pt2.begin(), nTrksPerSector_pt2.end()));
1216     h_ntrkPerSector_pt3->Fill(*std::max_element(nTrksPerSector_pt3.begin(), nTrksPerSector_pt3.end()));
1217     h_ntrkPerSector_pt4->Fill(*std::max_element(nTrksPerSector_pt4.begin(), nTrksPerSector_pt4.end()));
1218 
1219     // ----------------------------------------------------------------------------------------------------------------
1220     // tracking particle loop
1221     for (int it = 0; it < (int)tp_pt->size(); it++) {
1222       // only look at TPs in (ttbar) jets ?
1223       if (TP_select_injet > 0) {
1224         if (TP_select_injet == 1 && tp_injet->at(it) == 0)
1225           continue;
1226         if (TP_select_injet == 2 && tp_injet_highpt->at(it) == 0)
1227           continue;
1228         if (TP_select_injet == 3 && tp_injet_vhighpt->at(it) == 0)
1229           continue;
1230       }
1231 
1232       // cut on PDG ID at plot stage?
1233       if (TP_select_pdgid != 0) {
1234         if (abs(tp_pdgid->at(it)) != abs(TP_select_pdgid))
1235           continue;
1236       }
1237 
1238       // kinematic cuts
1239       if (std::abs(tp_dxy->at(it)) > TP_maxDxy)
1240         continue;
1241       if (std::abs(tp_d0->at(it)) > TP_maxD0)
1242         continue;
1243       if (tp_pt->at(it) < 0.2)
1244         continue;
1245       if (tp_pt->at(it) > TP_maxPt)
1246         continue;
1247       if (std::abs(tp_eta->at(it)) > TP_maxEta)
1248         continue;
1249 
1250       // total track rates
1251       if (tp_pt->at(it) > TP_minPt) {
1252         if (tp_pt->at(it) > 2.0) {
1253           ntp_pt2++;
1254           h_tp_vspt->Fill(tp_pt->at(it));
1255           // duplicate rate
1256           if (tp_nmatch->at(it) > 1) {
1257             for (int inm = 1; inm < tp_nmatch->at(it); inm++)
1258               h_trk_duplicate_vspt->Fill(matchtrk_pt->at(it));
1259           }
1260         }
1261         if (tp_pt->at(it) > 3.0)
1262           ntp_pt3++;
1263         if (tp_pt->at(it) > 10.0)
1264           ntp_pt10++;
1265       }
1266 
1267       // cut on event ID (eventid=0 means the TP is from the primary interaction, so *not* selecting only eventid=0 means including stuff from pileup)
1268       if (TP_select_eventid == 0 && tp_eventid->at(it) != 0)
1269         continue;
1270 
1271       // look at failure scenarios?
1272       if (useDeadRegion) {
1273         if (tp_phi->at(it) < 0 || tp_phi->at(it) > 1)
1274           continue;
1275       }
1276 
1277       h_tp_pt->Fill(tp_pt->at(it));
1278       if (tp_pt->at(it) < 8.0)
1279         h_tp_pt_L->Fill(tp_pt->at(it));
1280       else
1281         h_tp_pt_H->Fill(tp_pt->at(it));
1282       if (tp_pt->at(it) < 8.0 && std::abs(tp_eta->at(it)) < 1.0)
1283         h_tp_pt_LC->Fill(tp_pt->at(it));
1284 
1285       if (tp_pt->at(it) > TP_minPt) {
1286         if (std::abs(tp_eta->at(it)) < 1.0)
1287           n_all_eta1p0++;
1288         else if (std::abs(tp_eta->at(it)) < 1.75)
1289           n_all_eta1p75++;
1290         else
1291           n_all_eta2p5++;
1292 
1293         if (std::abs(tp_pt->at(it)) > 2.0)
1294           n_all_ptg2++;
1295         if (std::abs(tp_pt->at(it)) > 2.0 && std::abs(tp_pt->at(it)) < 8.0)
1296           n_all_pt2to8++;
1297         if (std::abs(tp_pt->at(it)) > 8.0)
1298           n_all_ptg8++;
1299         if (std::abs(tp_pt->at(it)) > 40.0)
1300           n_all_ptg40++;
1301 
1302         h_tp_eta->Fill(tp_eta->at(it));
1303         h_tp_phi->Fill(tp_phi->at(it));
1304         h_tp_z0->Fill(tp_z0->at(it));
1305         h_tp_d0->Fill(tp_d0->at(it));
1306         h_tp_absd0->Fill(std::abs(tp_d0->at(it)));
1307         if (std::abs(tp_eta->at(it)) < 2.0)
1308           h_tp_absd0_eta2->Fill(std::abs(tp_d0->at(it)));
1309         if (std::abs(tp_eta->at(it)) < 2.0 && tp_pt->at(it) > 3.0)
1310           h_tp_absd0_eta2_pt3->Fill(std::abs(tp_d0->at(it)));
1311 
1312         if (tp_pt->at(it) < 3.0)
1313           h_tp_eta_23->Fill(tp_eta->at(it));
1314         else if (tp_pt->at(it) < 5.0)
1315           h_tp_eta_35->Fill(tp_eta->at(it));
1316         else
1317           h_tp_eta_5->Fill(tp_eta->at(it));
1318 
1319         if (tp_pt->at(it) < 8.0) {
1320           h_tp_eta_L->Fill(tp_eta->at(it));
1321           h_tp_z0_L->Fill(tp_z0->at(it));
1322         } else {
1323           h_tp_eta_H->Fill(tp_eta->at(it));
1324           h_tp_z0_H->Fill(tp_z0->at(it));
1325         }
1326       }
1327 
1328       // ----------------------------------------------------------------------------------------------------------------
1329       // was the tracking particle matched to a L1 track?
1330       if (tp_nmatch->at(it) < 1)
1331         continue;
1332 
1333       // ----------------------------------------------------------------------------------------------------------------
1334       // use only tracks with min X stubs
1335       if (matchtrk_nstub->at(it) < L1Tk_minNstub)
1336         continue;
1337 
1338       int thisseed = matchtrk_seed->at(it);
1339       if (thisseed > 25)
1340         thisseed = thisseed - 20;
1341       if ((L1Tk_seed != 0) && (thisseed != L1Tk_seed))
1342         continue;
1343 
1344       // ----------------------------------------------------------------------------------------------------------------
1345       // fill matchtrk chi2 & chi2/dof histograms before making chi2 cut
1346 
1347       float chi2 = matchtrk_chi2->at(it);
1348       float chi2dof = matchtrk_chi2_dof->at(it);
1349       float chi2rphi = matchtrk_chi2rphi->at(it);
1350       float chi2rphidof = matchtrk_chi2rphi_dof->at(it);
1351       float chi2rz = matchtrk_chi2rz->at(it);
1352       float chi2rzdof = matchtrk_chi2rz_dof->at(it);
1353 
1354       // create overflow bins by restricting range of chi2
1355       int chi2Overflow = 100;
1356       int chi2DOFOverflow = 20;  //apprx chi2Overflow / avg. nstubs
1357       double buffer = 0.1;
1358 
1359       if (chi2 > chi2Overflow)
1360         chi2 = chi2Overflow - buffer;
1361       if (chi2dof > chi2DOFOverflow)
1362         chi2dof = chi2DOFOverflow - buffer;
1363       if (chi2rphi > chi2Overflow)
1364         chi2rphi = chi2Overflow - buffer;
1365       if (chi2rphidof > chi2DOFOverflow)
1366         chi2rphidof = chi2DOFOverflow - buffer;
1367       if (chi2rz > chi2Overflow)
1368         chi2rz = chi2Overflow - buffer;
1369       if (chi2rzdof > chi2DOFOverflow)
1370         chi2rzdof = chi2DOFOverflow - buffer;
1371 
1372       if (tp_pt->at(it) > TP_minPt) {  //TP pt > TP_minPt
1373 
1374         h_match_trk_chi2->Fill(chi2);
1375         h_match_trk_chi2_dof->Fill(chi2dof);
1376 
1377         h_match_trk_chi2rphi->Fill(chi2rphi);
1378         h_match_trk_chi2rphi_dof->Fill(chi2rphidof);
1379 
1380         h_match_trk_chi2rz->Fill(chi2rz);
1381         h_match_trk_chi2rz_dof->Fill(chi2rzdof);
1382 
1383         // central eta
1384         if (std::abs(tp_eta->at(it)) < 0.8) {
1385           if (tp_pt->at(it) < 8.0) {
1386             h_match_trk_chi2_C_L->Fill(chi2);
1387             h_match_trk_chi2_dof_C_L->Fill(chi2dof);
1388           } else {
1389             h_match_trk_chi2_C_H->Fill(chi2);
1390             h_match_trk_chi2_dof_C_H->Fill(chi2dof);
1391           }
1392         }
1393         // intermediate eta
1394         else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8) {
1395           if (tp_pt->at(it) < 8.0) {
1396             h_match_trk_chi2_I_L->Fill(chi2);
1397             h_match_trk_chi2_dof_I_L->Fill(chi2dof);
1398           } else {
1399             h_match_trk_chi2_I_H->Fill(chi2);
1400             h_match_trk_chi2_dof_I_H->Fill(chi2dof);
1401           }
1402         }
1403         // forward eta
1404         else if (std::abs(tp_eta->at(it)) >= 1.6) {
1405           if (tp_pt->at(it) < 8.0) {
1406             h_match_trk_chi2_F_L->Fill(chi2);
1407             h_match_trk_chi2_dof_F_L->Fill(chi2dof);
1408           } else {
1409             h_match_trk_chi2_F_H->Fill(chi2);
1410             h_match_trk_chi2_dof_F_H->Fill(chi2dof);
1411           }
1412         }
1413       }  //end TP pt > TP_minPt
1414 
1415       // ----------------------------------------------------------------------------------------------------------------
1416       // cut on chi2?
1417       if (matchtrk_chi2->at(it) > L1Tk_maxChi2)
1418         continue;
1419       if (matchtrk_chi2_dof->at(it) > L1Tk_maxChi2dof)
1420         continue;
1421 
1422       // use tight quality cut selection?
1423       /*
1424       if (matchtrk_nstub->at(it)==4) {
1425     if (std::abs(matchtrk_eta->at(it))<2.2 && matchtrk_consistency->at(it)>10) continue;
1426     else if (std::abs(matchtrk_eta->at(it))>2.2 && chi2dof>5.0) continue;
1427       }
1428       if (matchtrk_pt->at(it)>10.0 && chi2dof>5.0) continue;
1429       */
1430 
1431       // ----------------------------------------------------------------------------------------------------------------
1432       // more plots
1433 
1434       // fill matched track histograms
1435       h_match_tp_pt->Fill(tp_pt->at(it));
1436       if (tp_pt->at(it) < 8.0)
1437         h_match_tp_pt_L->Fill(tp_pt->at(it));
1438       else
1439         h_match_tp_pt_H->Fill(tp_pt->at(it));
1440       if (tp_pt->at(it) < 8.0 && std::abs(tp_eta->at(it)) < 1.0)
1441         h_match_tp_pt_LC->Fill(tp_pt->at(it));
1442 
1443       if (tp_pt->at(it) > TP_minPt) {
1444         h_match_tp_eta->Fill(tp_eta->at(it));
1445         h_match_tp_phi->Fill(tp_phi->at(it));
1446         h_match_tp_z0->Fill(tp_z0->at(it));
1447         h_match_tp_d0->Fill(tp_d0->at(it));
1448         h_match_tp_absd0->Fill(std::abs(tp_d0->at(it)));
1449         if (std::abs(tp_eta->at(it)) < 2.0)
1450           h_match_tp_absd0_eta2->Fill(std::abs(tp_d0->at(it)));
1451         if (std::abs(tp_eta->at(it)) < 2.0 && tp_pt->at(it) > 3.0)
1452           h_match_tp_absd0_eta2_pt3->Fill(std::abs(tp_d0->at(it)));
1453 
1454         if (std::abs(tp_eta->at(it)) < 1.0)
1455           n_match_eta1p0++;
1456         else if (std::abs(tp_eta->at(it)) < 1.75)
1457           n_match_eta1p75++;
1458         else
1459           n_match_eta2p5++;
1460 
1461         if (std::abs(tp_pt->at(it)) > 2.0)
1462           n_match_ptg2++;
1463         if (std::abs(tp_pt->at(it)) > 2.0 && std::abs(tp_pt->at(it)) < 8.0)
1464           n_match_pt2to8++;
1465         if (std::abs(tp_pt->at(it)) > 8.0)
1466           n_match_ptg8++;
1467         if (std::abs(tp_pt->at(it)) > 40.0)
1468           n_match_ptg40++;
1469 
1470         if (tp_pt->at(it) < 3.0)
1471           h_match_tp_eta_23->Fill(tp_eta->at(it));
1472         else if (tp_pt->at(it) < 5.0)
1473           h_match_tp_eta_35->Fill(tp_eta->at(it));
1474         else
1475           h_match_tp_eta_5->Fill(tp_eta->at(it));
1476 
1477         if (tp_pt->at(it) < 8.0) {
1478           h_match_tp_eta_L->Fill(tp_eta->at(it));
1479           h_match_tp_z0_L->Fill(tp_z0->at(it));
1480         } else {
1481           h_match_tp_z0_H->Fill(tp_z0->at(it));
1482           h_match_tp_eta_H->Fill(tp_eta->at(it));
1483         }
1484       }
1485 
1486       // for the following, only consider TPs with pt > TP_minPt
1487       if (tp_pt->at(it) < TP_minPt)
1488         continue;
1489 
1490       // fill nstub histograms
1491       h_match_trk_nstub->Fill(matchtrk_nstub->at(it));
1492       if (std::abs(tp_eta->at(it)) < 0.8)
1493         h_match_trk_nstub_C->Fill(matchtrk_nstub->at(it));
1494       else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8)
1495         h_match_trk_nstub_I->Fill(matchtrk_nstub->at(it));
1496       else if (std::abs(tp_eta->at(it)) >= 1.6)
1497         h_match_trk_nstub_F->Fill(matchtrk_nstub->at(it));
1498 
1499       // ----------------------------------------------------------------------------------------------------------------
1500       // fill resolution histograms
1501 
1502       h_res_pt->Fill(matchtrk_pt->at(it) - tp_pt->at(it));
1503       h_res_ptRel->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it));
1504       h_res_eta->Fill(matchtrk_eta->at(it) - tp_eta->at(it));
1505       h_res_phi->Fill(matchtrk_phi->at(it) - tp_phi->at(it));
1506       h_res_z0->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1507       if (matchtrk_d0->at(it) < 999.)
1508         h_res_d0->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1509 
1510       if (std::abs(tp_eta->at(it)) < 0.8)
1511         h_res_z0_C->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1512       else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8)
1513         h_res_z0_I->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1514       else if (std::abs(tp_eta->at(it)) >= 1.6)
1515         h_res_z0_F->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1516 
1517       if (tp_pt->at(it) < 8.0) {
1518         h_res_z0_L->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1519         if (std::abs(tp_eta->at(it)) < 1.0)
1520           h_res_z0_C_L->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1521         else
1522           h_res_z0_F_L->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1523       } else {
1524         h_res_z0_H->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1525         if (std::abs(tp_eta->at(it)) < 1.0)
1526           h_res_z0_C_H->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1527         else
1528           h_res_z0_F_H->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1529       }
1530 
1531       if (matchtrk_d0->at(it) < 999.) {
1532         if (std::abs(tp_eta->at(it)) < 0.8)
1533           h_res_d0_C->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1534         else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8)
1535           h_res_d0_I->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1536         else if (std::abs(tp_eta->at(it)) >= 1.6)
1537           h_res_d0_F->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1538 
1539         if (tp_pt->at(it) < 8.0) {
1540           h_res_d0_L->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1541           if (std::abs(tp_eta->at(it)) < 1.0)
1542             h_res_d0_C_L->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1543           else
1544             h_res_d0_F_L->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1545         } else {
1546           h_res_d0_H->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1547           if (std::abs(tp_eta->at(it)) < 1.0)
1548             h_res_d0_C_H->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1549           else
1550             h_res_d0_F_H->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1551         }
1552       }
1553 
1554       // ----------------------------------------------------------------------------------------------------------------
1555       // fill resolution vs. pt histograms
1556       for (int im = 0; im < nRANGE; im++) {
1557         if ((tp_pt->at(it) > (float)im * 5.0) && (tp_pt->at(it) < (float)(im + 1) * 5.0)) {
1558           h_resVsPt_pt[im]->Fill(matchtrk_pt->at(it) - tp_pt->at(it));
1559           h_resVsPt_ptRel[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it));
1560           h_resVsPt_eta[im]->Fill(matchtrk_eta->at(it) - tp_eta->at(it));
1561           h_resVsPt_phi[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it));
1562           h_resVsPt_z0[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1563 
1564           h_absResVsPt_pt[im]->Fill(std::abs(matchtrk_pt->at(it) - tp_pt->at(it)));
1565           h_absResVsPt_ptRel[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it));
1566           h_absResVsPt_z0[im]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it)));
1567           h_absResVsPt_phi[im]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it)));
1568           h_absResVsPt_eta[im]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it)));
1569 
1570           if (std::abs(tp_eta->at(it)) < 0.8) {
1571             h_resVsPt_pt_C[im]->Fill(matchtrk_pt->at(it) - tp_pt->at(it));
1572             h_resVsPt_ptRel_C[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it));
1573             h_resVsPt_z0_C[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1574             h_resVsPt_phi_C[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it));
1575           } else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8) {
1576             h_resVsPt_pt_I[im]->Fill(matchtrk_pt->at(it) - tp_pt->at(it));
1577             h_resVsPt_ptRel_I[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it));
1578             h_resVsPt_z0_I[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1579             h_resVsPt_phi_I[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it));
1580           } else if (std::abs(tp_eta->at(it)) >= 1.6) {
1581             h_resVsPt_pt_F[im]->Fill(matchtrk_pt->at(it) - tp_pt->at(it));
1582             h_resVsPt_ptRel_F[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it));
1583             h_resVsPt_z0_F[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1584             h_resVsPt_phi_F[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it));
1585           }
1586 
1587           if (matchtrk_d0->at(it) < 999) {
1588             h_resVsPt_d0[im]->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1589             h_absResVsPt_d0[im]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it)));
1590           }
1591         }
1592       }
1593 
1594       for (int im = 3; im < nRANGE_L + 3; im++) {
1595         if ((tp_pt->at(it) > (float)im * 0.5) && (tp_pt->at(it) <= (float)(im + 1) * 0.5)) {
1596           h_absResVsPt_pt_L[im - 3]->Fill(std::abs(matchtrk_pt->at(it) - tp_pt->at(it)));
1597           h_absResVsPt_ptRel_L[im - 3]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it));
1598           h_absResVsPt_z0_L[im - 3]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it)));
1599           h_absResVsPt_phi_L[im - 3]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it)));
1600           h_absResVsPt_eta_L[im - 3]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it)));
1601           h_absResVsPt_d0_L[im - 3]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it)));
1602         }
1603       }
1604 
1605       // ----------------------------------------------------------------------------------------------------------------
1606       // fill resolution vs. eta histograms
1607       for (int im = 0; im < nETARANGE; im++) {
1608         if ((std::abs(tp_eta->at(it)) > (float)im * 0.1) && (std::abs(tp_eta->at(it)) < (float)(im + 1) * 0.1)) {
1609           h_resVsEta_ptRel[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it));
1610           h_resVsEta_eta[im]->Fill(matchtrk_eta->at(it) - tp_eta->at(it));
1611           h_resVsEta_phi[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it));
1612           h_resVsEta_z0[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1613 
1614           h_absResVsEta_ptRel[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it));
1615           h_absResVsEta_eta[im]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it)));
1616           h_absResVsEta_phi[im]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it)));
1617           h_absResVsEta_z0[im]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it)));
1618 
1619           if (tp_pt->at(it) < 8.0) {
1620             h_resVsEta_ptRel_L[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it));
1621             h_resVsEta_eta_L[im]->Fill(matchtrk_eta->at(it) - tp_eta->at(it));
1622             h_resVsEta_z0_L[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1623             h_resVsEta_phi_L[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it));
1624 
1625             h_absResVsEta_ptRel_L[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it));
1626             h_absResVsEta_eta_L[im]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it)));
1627             h_absResVsEta_phi_L[im]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it)));
1628             h_absResVsEta_z0_L[im]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it)));
1629 
1630             if (matchtrk_d0->at(it) < 999) {
1631               h_resVsEta_d0_L[im]->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1632               h_absResVsEta_d0_L[im]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it)));
1633             }
1634           } else {
1635             h_resVsEta_ptRel_H[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it));
1636             h_resVsEta_eta_H[im]->Fill(matchtrk_eta->at(it) - tp_eta->at(it));
1637             h_resVsEta_z0_H[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it));
1638             h_resVsEta_phi_H[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it));
1639 
1640             h_absResVsEta_ptRel_H[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it));
1641             h_absResVsEta_eta_H[im]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it)));
1642             h_absResVsEta_phi_H[im]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it)));
1643             h_absResVsEta_z0_H[im]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it)));
1644 
1645             if (matchtrk_d0->at(it) < 999) {
1646               h_resVsEta_d0_H[im]->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1647               h_absResVsEta_d0_H[im]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it)));
1648             }
1649           }
1650 
1651           if (matchtrk_d0->at(it) < 999) {
1652             h_resVsEta_d0[im]->Fill(matchtrk_d0->at(it) - tp_d0->at(it));
1653             h_absResVsEta_d0[im]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it)));
1654           }
1655         }
1656       }
1657 
1658       // ----------------------------------------------------------------------------------------------------------------
1659       // fill resolution vs. phi histograms
1660       for (int im = 0; im < nPHIRANGE; im++) {
1661         if ((tp_phi->at(it) > (float)im * 0.2 - 3.2) && (tp_phi->at(it) < (float)(im + 1) * 0.2 - 3.2)) {
1662           h_absResVsPhi_pt[im]->Fill(std::abs(matchtrk_pt->at(it) - tp_pt->at(it)));
1663           h_absResVsPhi_ptRel[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it));
1664         }
1665       }
1666 
1667     }  // end of matched track loop
1668 
1669   }  // end of event loop
1670 
1671   // ----------------------------------------------------------------------------------------------------------------
1672 
1673   // ----------------------------------------------------------------------------------------------------------------
1674   // Post-event-loop histogram normalization(s)
1675 
1676   // Normalize tracklet efficiency by each eta slice
1677   double maxBinContents;
1678   double etaRes = trackletEffMaxEta / trackletEffEtaBins;
1679   for (double etaBin = 0; etaBin < trackletEffEtaBins;
1680        etaBin++) {  //loop through eta bin values (constants defined with relevant hist defs)
1681     maxBinContents = 0;
1682     std::vector<double> binContents = {};
1683     for (int layer = 0; layer < numLayers; layer++) {
1684       binContents.push_back(h_trk_tracklet_hits->GetBinContent(etaBin + 1, layer + 1));
1685       maxBinContents = std::max(maxBinContents, binContents.back());
1686     }
1687     float binWeight;
1688     for (int layer = 0; layer < numLayers; layer++) {
1689       binWeight = (maxBinContents == 0) ? 0 : binContents.at(layer) / maxBinContents;
1690       h_trk_tracklet_eff->Fill((etaBin + 0.5) * etaRes, layer, binWeight);
1691     }
1692   }
1693 
1694   // Adjust tracklet hits and efficiency histograms for aesthetics
1695 
1696   // ----------------------------------------------------------------------------------------------------------------
1697   // 2D plots
1698   // ----------------------------------------------------------------------------------------------------------------
1699 
1700   TH1F* h2_resVsPt_pt = new TH1F("resVsPt2_pt", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100);
1701   TH1F* h2_resVsPt_pt_C =
1702       new TH1F("resVsPt2_pt_C", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100);
1703   TH1F* h2_resVsPt_pt_I =
1704       new TH1F("resVsPt2_pt_I", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100);
1705   TH1F* h2_resVsPt_pt_F =
1706       new TH1F("resVsPt2_pt_F", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100);
1707 
1708   TH1F* h2_resVsPt_ptRel =
1709       new TH1F("resVsPt2_ptRel", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100);
1710   TH1F* h2_resVsPt_ptRel_C =
1711       new TH1F("resVsPt2_ptRel_C", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100);
1712   TH1F* h2_resVsPt_ptRel_I =
1713       new TH1F("resVsPt2_ptRel_I", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100);
1714   TH1F* h2_resVsPt_ptRel_F =
1715       new TH1F("resVsPt2_ptRel_F", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100);
1716 
1717   TH1F* h2_mresVsPt_pt =
1718       new TH1F("mresVsPt2_pt", ";Tracking particle p_{T} [GeV]; Mean(p_{T} residual) [GeV]", 20, 0, 100);
1719   TH1F* h2_mresVsPt_pt_C =
1720       new TH1F("mresVsPt2_pt_C", ";Tracking particle p_{T} [GeV]; Mean(p_{T} residual) [GeV]", 20, 0, 100);
1721   TH1F* h2_mresVsPt_pt_I =
1722       new TH1F("mresVsPt2_pt_I", ";Tracking particle p_{T} [GeV]; Mean(p_{T} residual) [GeV]", 20, 0, 100);
1723   TH1F* h2_mresVsPt_pt_F =
1724       new TH1F("mresVsPt2_pt_F", ";Tracking particle p_{T} [GeV]; Mean(p_{T} residual) [GeV]", 20, 0, 100);
1725 
1726   TH1F* h2_resVsPt_z0 = new TH1F("resVsPt2_z0", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100);
1727   TH1F* h2_resVsPt_z0_C =
1728       new TH1F("resVsPt2_z0_C", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100);
1729   TH1F* h2_resVsPt_z0_I =
1730       new TH1F("resVsPt2_z0_I", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100);
1731   TH1F* h2_resVsPt_z0_F =
1732       new TH1F("resVsPt2_z0_F", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100);
1733 
1734   TH1F* h2_resVsPt_phi = new TH1F("resVsPt2_phi", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100);
1735   TH1F* h2_resVsPt_phi_C =
1736       new TH1F("resVsPt2_phi_C", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100);
1737   TH1F* h2_resVsPt_phi_I =
1738       new TH1F("resVsPt2_phi_I", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100);
1739   TH1F* h2_resVsPt_phi_F =
1740       new TH1F("resVsPt2_phi_F", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100);
1741 
1742   TH1F* h2_resVsPt_eta = new TH1F("resVsPt2_eta", ";Tracking particle p_{T} [GeV]; #eta resolution", 20, 0, 100);
1743 
1744   TH1F* h2_resVsPt_d0 = new TH1F("resVsPt2_d0", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", 20, 0, 100);
1745 
1746   TH1F* h2_resVsPt_pt_68 =
1747       new TH1F("resVsPt2_pt_68", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100);
1748   TH1F* h2_resVsPt_ptRel_68 =
1749       new TH1F("resVsPt2_ptRel_68", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100);
1750   TH1F* h2_resVsPt_z0_68 =
1751       new TH1F("resVsPt2_z0_68", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100);
1752   TH1F* h2_resVsPt_phi_68 =
1753       new TH1F("resVsPt2_phi_68", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100);
1754   TH1F* h2_resVsPt_eta_68 = new TH1F("resVsPt2_eta_68", ";Tracking particle p_{T} [GeV]; #eta resolution", 20, 0, 100);
1755   TH1F* h2_resVsPt_d0_68 =
1756       new TH1F("resVsPt2_d0_68", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", 20, 0, 100);
1757 
1758   TH1F* h2_resVsPt_pt_90 =
1759       new TH1F("resVsPt2_pt_90", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100);
1760   TH1F* h2_resVsPt_ptRel_90 =
1761       new TH1F("resVsPt2_ptRel_90", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100);
1762   TH1F* h2_resVsPt_z0_90 =
1763       new TH1F("resVsPt2_z0_90", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100);
1764   TH1F* h2_resVsPt_phi_90 =
1765       new TH1F("resVsPt2_phi_90", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100);
1766   TH1F* h2_resVsPt_eta_90 = new TH1F("resVsPt2_eta_90", ";Tracking particle p_{T} [GeV]; #eta resolution", 20, 0, 100);
1767   TH1F* h2_resVsPt_d0_90 =
1768       new TH1F("resVsPt2_d0_90", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", 20, 0, 100);
1769 
1770   TH1F* h2_resVsPt_pt_99 =
1771       new TH1F("resVsPt2_pt_99", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100);
1772   TH1F* h2_resVsPt_ptRel_99 =
1773       new TH1F("resVsPt2_ptRel_99", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100);
1774   TH1F* h2_resVsPt_z0_99 =
1775       new TH1F("resVsPt2_z0_99", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100);
1776   TH1F* h2_resVsPt_phi_99 =
1777       new TH1F("resVsPt2_phi_99", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100);
1778   TH1F* h2_resVsPt_eta_99 = new TH1F("resVsPt2_eta_99", ";Tracking particle p_{T} [GeV]; #eta resolution", 20, 0, 100);
1779   TH1F* h2_resVsPt_d0_99 =
1780       new TH1F("resVsPt2_d0_99", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", 20, 0, 100);
1781 
1782   TH1F* h2_resVsPt_pt_L_68 =
1783       new TH1F("resVsPt2_pt_L_68", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", nRANGE_L, pt_resmin, 8);
1784   TH1F* h2_resVsPt_ptRel_L_68 = new TH1F(
1785       "resVsPt2_ptRel_L_68", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", nRANGE_L, pt_resmin, 8);
1786   TH1F* h2_resVsPt_z0_L_68 =
1787       new TH1F("resVsPt2_z0_L_68", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", nRANGE_L, pt_resmin, 8);
1788   TH1F* h2_resVsPt_phi_L_68 =
1789       new TH1F("resVsPt2_phi_L_68", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", nRANGE_L, pt_resmin, 8);
1790   TH1F* h2_resVsPt_eta_L_68 =
1791       new TH1F("resVsPt2_eta_L_68", ";Tracking particle p_{T} [GeV]; #eta resolution", nRANGE_L, pt_resmin, 8);
1792   TH1F* h2_resVsPt_d0_L_68 =
1793       new TH1F("resVsPt2_d0_L_68", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", nRANGE_L, pt_resmin, 8);
1794 
1795   TH1F* h2_resVsPt_pt_L_90 =
1796       new TH1F("resVsPt2_pt_L_90", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", nRANGE_L, pt_resmin, 8);
1797   TH1F* h2_resVsPt_ptRel_L_90 = new TH1F(
1798       "resVsPt2_ptRel_L_90", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", nRANGE_L, pt_resmin, 8);
1799   TH1F* h2_resVsPt_z0_L_90 =
1800       new TH1F("resVsPt2_z0_L_90", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", nRANGE_L, pt_resmin, 8);
1801   TH1F* h2_resVsPt_phi_L_90 =
1802       new TH1F("resVsPt2_phi_L_90", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", nRANGE_L, pt_resmin, 8);
1803   TH1F* h2_resVsPt_eta_L_90 =
1804       new TH1F("resVsPt2_eta_L_90", ";Tracking particle p_{T} [GeV]; #eta resolution", nRANGE_L, pt_resmin, 8);
1805   TH1F* h2_resVsPt_d0_L_90 =
1806       new TH1F("resVsPt2_d0_L_90", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", nRANGE_L, pt_resmin, 8);
1807 
1808   TH1F* h2_resVsPt_pt_L_99 =
1809       new TH1F("resVsPt2_pt_L_99", ";Tracking particle p_{T} [GeV]; p_{T} resolution [cm]", nRANGE_L, pt_resmin, 8);
1810   TH1F* h2_resVsPt_ptRel_L_99 = new TH1F(
1811       "resVsPt2_ptRel_L_99", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", nRANGE_L, pt_resmin, 8);
1812   TH1F* h2_resVsPt_z0_L_99 =
1813       new TH1F("resVsPt2_z0_L_99", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", nRANGE_L, pt_resmin, 8);
1814   TH1F* h2_resVsPt_phi_L_99 =
1815       new TH1F("resVsPt2_phi_L_99", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", nRANGE_L, pt_resmin, 8);
1816   TH1F* h2_resVsPt_eta_L_99 =
1817       new TH1F("resVsPt2_eta_L_99", ";Tracking particle p_{T} [GeV]; #eta resolution", nRANGE_L, pt_resmin, 8);
1818   TH1F* h2_resVsPt_d0_L_99 =
1819       new TH1F("resVsPt2_d0_L_99", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", nRANGE_L, pt_resmin, 8);
1820 
1821   for (int i = 0; i < nRANGE; i++) {
1822     // set bin content and error
1823     h2_resVsPt_pt->SetBinContent(i + 1, h_resVsPt_pt[i]->GetRMS());
1824     h2_resVsPt_pt->SetBinError(i + 1, h_resVsPt_pt[i]->GetRMSError());
1825     h2_resVsPt_pt_C->SetBinContent(i + 1, h_resVsPt_pt_C[i]->GetRMS());
1826     h2_resVsPt_pt_C->SetBinError(i + 1, h_resVsPt_pt_C[i]->GetRMSError());
1827     h2_resVsPt_pt_I->SetBinContent(i + 1, h_resVsPt_pt_I[i]->GetRMS());
1828     h2_resVsPt_pt_I->SetBinError(i + 1, h_resVsPt_pt_I[i]->GetRMSError());
1829     h2_resVsPt_pt_F->SetBinContent(i + 1, h_resVsPt_pt_F[i]->GetRMS());
1830     h2_resVsPt_pt_F->SetBinError(i + 1, h_resVsPt_pt_F[i]->GetRMSError());
1831 
1832     h2_resVsPt_ptRel->SetBinContent(i + 1, h_resVsPt_ptRel[i]->GetRMS());
1833     h2_resVsPt_ptRel->SetBinError(i + 1, h_resVsPt_ptRel[i]->GetRMSError());
1834     h2_resVsPt_ptRel_C->SetBinContent(i + 1, h_resVsPt_ptRel_C[i]->GetRMS());
1835     h2_resVsPt_ptRel_C->SetBinError(i + 1, h_resVsPt_ptRel_C[i]->GetRMSError());
1836     h2_resVsPt_ptRel_I->SetBinContent(i + 1, h_resVsPt_ptRel_I[i]->GetRMS());
1837     h2_resVsPt_ptRel_I->SetBinError(i + 1, h_resVsPt_ptRel_I[i]->GetRMSError());
1838     h2_resVsPt_ptRel_F->SetBinContent(i + 1, h_resVsPt_ptRel_F[i]->GetRMS());
1839     h2_resVsPt_ptRel_F->SetBinError(i + 1, h_resVsPt_ptRel_F[i]->GetRMSError());
1840 
1841     h2_mresVsPt_pt->SetBinContent(i + 1, h_resVsPt_pt[i]->GetMean());
1842     h2_mresVsPt_pt->SetBinError(i + 1, h_resVsPt_pt[i]->GetMeanError());
1843     h2_mresVsPt_pt_C->SetBinContent(i + 1, h_resVsPt_pt_C[i]->GetMean());
1844     h2_mresVsPt_pt_C->SetBinError(i + 1, h_resVsPt_pt_C[i]->GetMeanError());
1845     h2_mresVsPt_pt_I->SetBinContent(i + 1, h_resVsPt_pt_I[i]->GetMean());
1846     h2_mresVsPt_pt_I->SetBinError(i + 1, h_resVsPt_pt_I[i]->GetMeanError());
1847     h2_mresVsPt_pt_F->SetBinContent(i + 1, h_resVsPt_pt_F[i]->GetMean());
1848     h2_mresVsPt_pt_F->SetBinError(i + 1, h_resVsPt_pt_F[i]->GetMeanError());
1849 
1850     h2_resVsPt_z0->SetBinContent(i + 1, h_resVsPt_z0[i]->GetRMS());
1851     h2_resVsPt_z0->SetBinError(i + 1, h_resVsPt_z0[i]->GetRMSError());
1852     h2_resVsPt_z0_C->SetBinContent(i + 1, h_resVsPt_z0_C[i]->GetRMS());
1853     h2_resVsPt_z0_C->SetBinError(i + 1, h_resVsPt_z0_C[i]->GetRMSError());
1854     h2_resVsPt_z0_I->SetBinContent(i + 1, h_resVsPt_z0_I[i]->GetRMS());
1855     h2_resVsPt_z0_I->SetBinError(i + 1, h_resVsPt_z0_I[i]->GetRMSError());
1856     h2_resVsPt_z0_F->SetBinContent(i + 1, h_resVsPt_z0_F[i]->GetRMS());
1857     h2_resVsPt_z0_F->SetBinError(i + 1, h_resVsPt_z0_F[i]->GetRMSError());
1858 
1859     h2_resVsPt_phi->SetBinContent(i + 1, h_resVsPt_phi[i]->GetRMS());
1860     h2_resVsPt_phi->SetBinError(i + 1, h_resVsPt_phi[i]->GetRMSError());
1861     h2_resVsPt_phi_C->SetBinContent(i + 1, h_resVsPt_phi_C[i]->GetRMS());
1862     h2_resVsPt_phi_C->SetBinError(i + 1, h_resVsPt_phi_C[i]->GetRMSError());
1863     h2_resVsPt_phi_I->SetBinContent(i + 1, h_resVsPt_phi_I[i]->GetRMS());
1864     h2_resVsPt_phi_I->SetBinError(i + 1, h_resVsPt_phi_I[i]->GetRMSError());
1865     h2_resVsPt_phi_F->SetBinContent(i + 1, h_resVsPt_phi_F[i]->GetRMS());
1866     h2_resVsPt_phi_F->SetBinError(i + 1, h_resVsPt_phi_F[i]->GetRMSError());
1867 
1868     h2_resVsPt_eta->SetBinContent(i + 1, h_resVsPt_eta[i]->GetRMS());
1869     h2_resVsPt_eta->SetBinError(i + 1, h_resVsPt_eta[i]->GetRMSError());
1870 
1871     h2_resVsPt_d0->SetBinContent(i + 1, h_resVsPt_d0[i]->GetRMS());
1872     h2_resVsPt_d0->SetBinError(i + 1, h_resVsPt_d0[i]->GetRMSError());
1873 
1874     h2_resVsPt_pt_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt[i], 0.68));
1875     h2_resVsPt_pt_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt[i], 0.90));
1876     h2_resVsPt_pt_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt[i], 0.99));
1877 
1878     h2_resVsPt_ptRel_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel[i], 0.68));
1879     h2_resVsPt_ptRel_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel[i], 0.90));
1880     h2_resVsPt_ptRel_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel[i], 0.99));
1881 
1882     h2_resVsPt_eta_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta[i], 0.68));
1883     h2_resVsPt_eta_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta[i], 0.90));
1884     h2_resVsPt_eta_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta[i], 0.99));
1885 
1886     h2_resVsPt_z0_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0[i], 0.68));
1887     h2_resVsPt_z0_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0[i], 0.90));
1888     h2_resVsPt_z0_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0[i], 0.99));
1889 
1890     h2_resVsPt_phi_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi[i], 0.68));
1891     h2_resVsPt_phi_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi[i], 0.90));
1892     h2_resVsPt_phi_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi[i], 0.99));
1893 
1894     h2_resVsPt_d0_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0[i], 0.68));
1895     h2_resVsPt_d0_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0[i], 0.90));
1896     h2_resVsPt_d0_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0[i], 0.99));
1897   }
1898 
1899   for (int i = 0; i < nRANGE_L; i++) {
1900     h2_resVsPt_pt_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt_L[i], 0.68));
1901     h2_resVsPt_pt_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt_L[i], 0.90));
1902     h2_resVsPt_pt_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt_L[i], 0.99));
1903 
1904     h2_resVsPt_ptRel_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel_L[i], 0.68));
1905     h2_resVsPt_ptRel_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel_L[i], 0.90));
1906     h2_resVsPt_ptRel_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel_L[i], 0.99));
1907 
1908     h2_resVsPt_eta_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta_L[i], 0.68));
1909     h2_resVsPt_eta_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta_L[i], 0.90));
1910     h2_resVsPt_eta_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta_L[i], 0.99));
1911 
1912     h2_resVsPt_z0_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0_L[i], 0.68));
1913     h2_resVsPt_z0_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0_L[i], 0.90));
1914     h2_resVsPt_z0_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0_L[i], 0.99));
1915 
1916     h2_resVsPt_phi_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi_L[i], 0.68));
1917     h2_resVsPt_phi_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi_L[i], 0.90));
1918     h2_resVsPt_phi_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi_L[i], 0.99));
1919 
1920     h2_resVsPt_d0_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0_L[i], 0.68));
1921     h2_resVsPt_d0_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0_L[i], 0.90));
1922     h2_resVsPt_d0_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0_L[i], 0.99));
1923   }
1924 
1925   // resolution vs. eta histograms
1926   TH1F* h2_resVsEta_eta =
1927       new TH1F("resVsEta_eta", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
1928   TH1F* h2_resVsEta_eta_L =
1929       new TH1F("resVsEta_eta_L", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
1930   TH1F* h2_resVsEta_eta_H =
1931       new TH1F("resVsEta_eta_H", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
1932 
1933   TH1F* h2_resVsEta_z0 =
1934       new TH1F("resVsEta_z0", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1935   TH1F* h2_resVsEta_z0_L =
1936       new TH1F("resVsEta_z0_L", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1937   TH1F* h2_resVsEta_z0_H =
1938       new TH1F("resVsEta_z0_H", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1939 
1940   TH1F* h2_resVsEta_phi =
1941       new TH1F("resVsEta_phi", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
1942   TH1F* h2_resVsEta_phi_L =
1943       new TH1F("resVsEta_phi_L", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
1944   TH1F* h2_resVsEta_phi_H =
1945       new TH1F("resVsEta_phi_H", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
1946 
1947   TH1F* h2_resVsEta_ptRel =
1948       new TH1F("resVsEta_ptRel", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
1949   TH1F* h2_resVsEta_ptRel_L =
1950       new TH1F("resVsEta_ptRel_L", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
1951   TH1F* h2_resVsEta_ptRel_H =
1952       new TH1F("resVsEta_ptRel_H", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
1953 
1954   TH1F* h2_resVsEta_d0 =
1955       new TH1F("resVsEta_d0", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1956   TH1F* h2_resVsEta_d0_L =
1957       new TH1F("resVsEta_d0_L", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1958   TH1F* h2_resVsEta_d0_H =
1959       new TH1F("resVsEta_d0_H", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1960 
1961   // mean of residuals
1962   TH1F* h2_mresVsEta_eta =
1963       new TH1F("mresVsEta_eta", ";Tracking particle |#eta|; Mean(#eta residual)", nETARANGE, 0, eta_resmax);
1964   TH1F* h2_mresVsEta_z0 =
1965       new TH1F("mresVsEta_z0", ";Tracking particle |#eta|; Mean(z_{0} residual) [cm]", nETARANGE, 0, eta_resmax);
1966   TH1F* h2_mresVsEta_phi =
1967       new TH1F("mresVsEta_phi", ";Tracking particle |#eta|; Mean(phi residual) [rad]", nETARANGE, 0, eta_resmax);
1968   TH1F* h2_mresVsEta_ptRel =
1969       new TH1F("mresVsEta_ptRel", ";Tracking particle |#eta|; Mean(ptrel residual)", nETARANGE, 0, eta_resmax);
1970 
1971   // 68 / 90 / 99% residuals
1972   TH1F* h2_resVsEta_eta_68 =
1973       new TH1F("resVsEta_eta_68", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
1974   TH1F* h2_resVsEta_eta_90 =
1975       new TH1F("resVsEta_eta_90", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
1976   TH1F* h2_resVsEta_eta_99 =
1977       new TH1F("resVsEta_eta_99", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
1978 
1979   TH1F* h2_resVsEta_z0_68 =
1980       new TH1F("resVsEta_z0_68", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1981   TH1F* h2_resVsEta_z0_90 =
1982       new TH1F("resVsEta_z0_90", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1983   TH1F* h2_resVsEta_z0_99 =
1984       new TH1F("resVsEta_z0_99", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
1985 
1986   TH1F* h2_resVsEta_phi_68 =
1987       new TH1F("resVsEta_phi_68", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
1988   TH1F* h2_resVsEta_phi_90 =
1989       new TH1F("resVsEta_phi_90", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
1990   TH1F* h2_resVsEta_phi_99 =
1991       new TH1F("resVsEta_phi_99", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
1992 
1993   TH1F* h2_resVsEta_ptRel_68 =
1994       new TH1F("resVsEta_ptRel_68", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
1995   TH1F* h2_resVsEta_ptRel_90 =
1996       new TH1F("resVsEta_ptRel_90", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
1997   TH1F* h2_resVsEta_ptRel_99 =
1998       new TH1F("resVsEta_ptRel_99", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
1999 
2000   TH1F* h2_resVsEta_d0_68 =
2001       new TH1F("resVsEta_d0_68", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2002   TH1F* h2_resVsEta_d0_90 =
2003       new TH1F("resVsEta_d0_90", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2004   TH1F* h2_resVsEta_d0_99 =
2005       new TH1F("resVsEta_d0_99", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2006 
2007   TH1F* h2_resVsEta_eta_L_68 =
2008       new TH1F("resVsEta_eta_L_68", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
2009   TH1F* h2_resVsEta_z0_L_68 =
2010       new TH1F("resVsEta_z0_L_68", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2011   TH1F* h2_resVsEta_phi_L_68 =
2012       new TH1F("resVsEta_phi_L_68", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
2013   TH1F* h2_resVsEta_ptRel_L_68 =
2014       new TH1F("resVsEta_ptRel_L_68", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
2015   TH1F* h2_resVsEta_d0_L_68 =
2016       new TH1F("resVsEta_d0_L_68", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2017 
2018   TH1F* h2_resVsEta_eta_L_90 =
2019       new TH1F("resVsEta_eta_L_90", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
2020   TH1F* h2_resVsEta_z0_L_90 =
2021       new TH1F("resVsEta_z0_L_90", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2022   TH1F* h2_resVsEta_phi_L_90 =
2023       new TH1F("resVsEta_phi_L_90", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
2024   TH1F* h2_resVsEta_ptRel_L_90 =
2025       new TH1F("resVsEta_ptRel_L_90", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
2026   TH1F* h2_resVsEta_d0_L_90 =
2027       new TH1F("resVsEta_d0_L_90", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2028 
2029   TH1F* h2_resVsEta_eta_L_99 =
2030       new TH1F("resVsEta_eta_L_99", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
2031   TH1F* h2_resVsEta_z0_L_99 =
2032       new TH1F("resVsEta_z0_L_99", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2033   TH1F* h2_resVsEta_phi_L_99 =
2034       new TH1F("resVsEta_phi_L_99", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
2035   TH1F* h2_resVsEta_ptRel_L_99 =
2036       new TH1F("resVsEta_ptRel_L_99", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
2037   TH1F* h2_resVsEta_d0_L_99 =
2038       new TH1F("resVsEta_d0_L_99", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2039 
2040   TH1F* h2_resVsEta_eta_H_68 =
2041       new TH1F("resVsEta_eta_H_68", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
2042   TH1F* h2_resVsEta_z0_H_68 =
2043       new TH1F("resVsEta_z0_H_68", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2044   TH1F* h2_resVsEta_phi_H_68 =
2045       new TH1F("resVsEta_phi_H_68", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
2046   TH1F* h2_resVsEta_ptRel_H_68 =
2047       new TH1F("resVsEta_ptRel_H_68", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
2048   TH1F* h2_resVsEta_d0_H_68 =
2049       new TH1F("resVsEta_d0_H_68", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2050 
2051   TH1F* h2_resVsEta_eta_H_90 =
2052       new TH1F("resVsEta_eta_H_90", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
2053   TH1F* h2_resVsEta_z0_H_90 =
2054       new TH1F("resVsEta_z0_H_90", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2055   TH1F* h2_resVsEta_phi_H_90 =
2056       new TH1F("resVsEta_phi_H_90", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
2057   TH1F* h2_resVsEta_ptRel_H_90 =
2058       new TH1F("resVsEta_ptRel_H_90", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
2059   TH1F* h2_resVsEta_d0_H_90 =
2060       new TH1F("resVsEta_d0_H_90", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2061 
2062   TH1F* h2_resVsEta_eta_H_99 =
2063       new TH1F("resVsEta_eta_H_99", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, eta_resmax);
2064   TH1F* h2_resVsEta_z0_H_99 =
2065       new TH1F("resVsEta_z0_H_99", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2066   TH1F* h2_resVsEta_phi_H_99 =
2067       new TH1F("resVsEta_phi_H_99", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, eta_resmax);
2068   TH1F* h2_resVsEta_ptRel_H_99 =
2069       new TH1F("resVsEta_ptRel_H_99", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, eta_resmax);
2070   TH1F* h2_resVsEta_d0_H_99 =
2071       new TH1F("resVsEta_d0_H_99", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, eta_resmax);
2072 
2073   // resolution vs. eta histograms (gaussian fit)
2074   TH1F* h3_resVsEta_eta_L = new TH1F("resVsEta_eta_L_gaus", ";|#eta|; #sigma(#eta)", nETARANGE, 0, eta_resmax);
2075   TH1F* h3_resVsEta_eta_H = new TH1F("resVsEta_eta_H_gaus", ";|#eta|; #sigma(#eta)", nETARANGE, 0, eta_resmax);
2076 
2077   TH1F* h3_resVsEta_z0_L = new TH1F("resVsEta_z0_L_gaus", ";|#eta|; #sigma(z_{0}) [cm]", nETARANGE, 0, eta_resmax);
2078   TH1F* h3_resVsEta_z0_H = new TH1F("resVsEta_z0_H_gaus", ";|#eta|; #sigma(z_{0}) [cm]", nETARANGE, 0, eta_resmax);
2079 
2080   TH1F* h3_resVsEta_phi_L = new TH1F("resVsEta_phi_L_gaus", ";|#eta|; #sigma(#phi) [rad]", nETARANGE, 0, eta_resmax);
2081   TH1F* h3_resVsEta_phi_H = new TH1F("resVsEta_phi_H_gaus", ";|#eta|; #sigma(#phi) [rad]", nETARANGE, 0, eta_resmax);
2082 
2083   TH1F* h3_resVsEta_ptRel_L =
2084       new TH1F("resVsEta_ptRel_L_gaus", ";|#eta|; #sigma(p_{T}) / p_{T}", nETARANGE, 0, eta_resmax);
2085   TH1F* h3_resVsEta_ptRel_H =
2086       new TH1F("resVsEta_ptRel_H_gaus", ";|#eta|; #sigma(p_{T}) / p_{T}", nETARANGE, 0, eta_resmax);
2087 
2088   gSystem->mkdir("FitResults");
2089   TString fitdir = "FitResults/";
2090 
2091   for (int i = 0; i < nETARANGE; i++) {
2092     // set bin content and error
2093     h2_resVsEta_eta->SetBinContent(i + 1, h_resVsEta_eta[i]->GetRMS());
2094     h2_resVsEta_eta->SetBinError(i + 1, h_resVsEta_eta[i]->GetRMSError());
2095     h2_resVsEta_eta_L->SetBinContent(i + 1, h_resVsEta_eta_L[i]->GetRMS());
2096     h2_resVsEta_eta_L->SetBinError(i + 1, h_resVsEta_eta_L[i]->GetRMSError());
2097     h2_resVsEta_eta_H->SetBinContent(i + 1, h_resVsEta_eta_H[i]->GetRMS());
2098     h2_resVsEta_eta_H->SetBinError(i + 1, h_resVsEta_eta_H[i]->GetRMSError());
2099 
2100     h2_resVsEta_z0->SetBinContent(i + 1, h_resVsEta_z0[i]->GetRMS());
2101     h2_resVsEta_z0->SetBinError(i + 1, h_resVsEta_z0[i]->GetRMSError());
2102     h2_resVsEta_z0_L->SetBinContent(i + 1, h_resVsEta_z0_L[i]->GetRMS());
2103     h2_resVsEta_z0_L->SetBinError(i + 1, h_resVsEta_z0_L[i]->GetRMSError());
2104     h2_resVsEta_z0_H->SetBinContent(i + 1, h_resVsEta_z0_H[i]->GetRMS());
2105     h2_resVsEta_z0_H->SetBinError(i + 1, h_resVsEta_z0_H[i]->GetRMSError());
2106 
2107     h2_resVsEta_phi->SetBinContent(i + 1, h_resVsEta_phi[i]->GetRMS());
2108     h2_resVsEta_phi->SetBinError(i + 1, h_resVsEta_phi[i]->GetRMSError());
2109     h2_resVsEta_phi_L->SetBinContent(i + 1, h_resVsEta_phi_L[i]->GetRMS());
2110     h2_resVsEta_phi_L->SetBinError(i + 1, h_resVsEta_phi_L[i]->GetRMSError());
2111     h2_resVsEta_phi_H->SetBinContent(i + 1, h_resVsEta_phi_H[i]->GetRMS());
2112     h2_resVsEta_phi_H->SetBinError(i + 1, h_resVsEta_phi_H[i]->GetRMSError());
2113 
2114     h2_resVsEta_ptRel->SetBinContent(i + 1, h_resVsEta_ptRel[i]->GetRMS());
2115     h2_resVsEta_ptRel->SetBinError(i + 1, h_resVsEta_ptRel[i]->GetRMSError());
2116     h2_resVsEta_ptRel_L->SetBinContent(i + 1, h_resVsEta_ptRel_L[i]->GetRMS());
2117     h2_resVsEta_ptRel_L->SetBinError(i + 1, h_resVsEta_ptRel_L[i]->GetRMSError());
2118     h2_resVsEta_ptRel_H->SetBinContent(i + 1, h_resVsEta_ptRel_H[i]->GetRMS());
2119     h2_resVsEta_ptRel_H->SetBinError(i + 1, h_resVsEta_ptRel_H[i]->GetRMSError());
2120 
2121     h2_mresVsEta_eta->SetBinContent(i + 1, h_resVsEta_eta[i]->GetMean());
2122     h2_mresVsEta_eta->SetBinError(i + 1, h_resVsEta_eta[i]->GetMeanError());
2123     h2_mresVsEta_z0->SetBinContent(i + 1, h_resVsEta_z0[i]->GetMean());
2124     h2_mresVsEta_z0->SetBinError(i + 1, h_resVsEta_z0[i]->GetMeanError());
2125     h2_mresVsEta_phi->SetBinContent(i + 1, h_resVsEta_phi[i]->GetMean());
2126     h2_mresVsEta_phi->SetBinError(i + 1, h_resVsEta_phi[i]->GetMeanError());
2127     h2_mresVsEta_ptRel->SetBinContent(i + 1, h_resVsEta_ptRel[i]->GetMean());
2128     h2_mresVsEta_ptRel->SetBinError(i + 1, h_resVsEta_ptRel[i]->GetMeanError());
2129 
2130     h2_resVsEta_d0->SetBinContent(i + 1, h_resVsEta_d0[i]->GetRMS());
2131     h2_resVsEta_d0->SetBinError(i + 1, h_resVsEta_d0[i]->GetRMSError());
2132     h2_resVsEta_d0_L->SetBinContent(i + 1, h_resVsEta_d0_L[i]->GetRMS());
2133     h2_resVsEta_d0_L->SetBinError(i + 1, h_resVsEta_d0_L[i]->GetRMSError());
2134     h2_resVsEta_d0_H->SetBinContent(i + 1, h_resVsEta_d0_H[i]->GetRMS());
2135     h2_resVsEta_d0_H->SetBinError(i + 1, h_resVsEta_d0_H[i]->GetRMSError());
2136 
2137     h2_resVsEta_eta_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta[i], 0.68));
2138     h2_resVsEta_eta_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta[i], 0.90));
2139     h2_resVsEta_eta_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta[i], 0.99));
2140 
2141     h2_resVsEta_z0_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0[i], 0.68));
2142     h2_resVsEta_z0_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0[i], 0.90));
2143     h2_resVsEta_z0_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0[i], 0.99));
2144 
2145     h2_resVsEta_phi_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi[i], 0.68));
2146     h2_resVsEta_phi_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi[i], 0.90));
2147     h2_resVsEta_phi_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi[i], 0.99));
2148 
2149     h2_resVsEta_ptRel_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel[i], 0.68));
2150     h2_resVsEta_ptRel_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel[i], 0.90));
2151     h2_resVsEta_ptRel_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel[i], 0.99));
2152 
2153     h2_resVsEta_d0_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0[i], 0.68));
2154     h2_resVsEta_d0_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0[i], 0.90));
2155     h2_resVsEta_d0_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0[i], 0.99));
2156 
2157     h2_resVsEta_eta_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_L[i], 0.68));
2158     h2_resVsEta_z0_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_L[i], 0.68));
2159     h2_resVsEta_phi_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_L[i], 0.68));
2160     h2_resVsEta_ptRel_L_68->SetBinContent(i + 1,
2161                                           getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_L[i], 0.68));
2162     h2_resVsEta_d0_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_L[i], 0.68));
2163 
2164     h2_resVsEta_eta_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_L[i], 0.90));
2165     h2_resVsEta_z0_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_L[i], 0.90));
2166     h2_resVsEta_phi_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_L[i], 0.90));
2167     h2_resVsEta_ptRel_L_90->SetBinContent(i + 1,
2168                                           getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_L[i], 0.90));
2169     h2_resVsEta_d0_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_L[i], 0.90));
2170 
2171     h2_resVsEta_eta_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_L[i], 0.99));
2172     h2_resVsEta_z0_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_L[i], 0.99));
2173     h2_resVsEta_phi_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_L[i], 0.99));
2174     h2_resVsEta_ptRel_L_99->SetBinContent(i + 1,
2175                                           getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_L[i], 0.99));
2176     h2_resVsEta_d0_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_L[i], 0.99));
2177 
2178     h2_resVsEta_eta_H_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_H[i], 0.68));
2179     h2_resVsEta_z0_H_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_H[i], 0.68));
2180     h2_resVsEta_phi_H_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_H[i], 0.68));
2181     h2_resVsEta_ptRel_H_68->SetBinContent(i + 1,
2182                                           getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_H[i], 0.68));
2183     h2_resVsEta_d0_H_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_H[i], 0.68));
2184 
2185     h2_resVsEta_eta_H_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_H[i], 0.90));
2186     h2_resVsEta_z0_H_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_H[i], 0.90));
2187     h2_resVsEta_phi_H_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_H[i], 0.90));
2188     h2_resVsEta_ptRel_H_90->SetBinContent(i + 1,
2189                                           getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_H[i], 0.90));
2190     h2_resVsEta_d0_H_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_H[i], 0.90));
2191 
2192     h2_resVsEta_eta_H_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_H[i], 0.99));
2193     h2_resVsEta_z0_H_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_H[i], 0.99));
2194     h2_resVsEta_phi_H_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_H[i], 0.99));
2195     h2_resVsEta_ptRel_H_99->SetBinContent(i + 1,
2196                                           getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_H[i], 0.99));
2197     h2_resVsEta_d0_H_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_H[i], 0.99));
2198 
2199     // ---------------------------------------------------------------------------------------------------
2200     // gaussian fit instead
2201     // ---------------------------------------------------------------------------------------------------
2202 
2203     if (doGausFit) {
2204       TCanvas cfit;
2205       char text[500];
2206 
2207       float sigma = 0;
2208       float esigma = 0;
2209       TF1* fit;
2210 
2211       float rms = 0;
2212       float erms = 0;
2213 
2214       fit = new TF1("fit", "gaus", -0.01, 0.01);
2215       h_resVsEta_eta_L[i]->Fit("fit", "R");
2216       sigma = fit->GetParameter(2);
2217       esigma = fit->GetParError(2);
2218       rms = h_resVsEta_eta_L[i]->GetRMS();
2219       erms = h_resVsEta_eta_L[i]->GetRMSError();
2220       h3_resVsEta_eta_L->SetBinContent(i + 1, sigma);
2221       h3_resVsEta_eta_L->SetBinError(i + 1, esigma);
2222       h_resVsEta_eta_L[i]->Draw();
2223       sprintf(text, "RMS: %.4f +/- %.4f", rms, erms);
2224       mySmallText(0.2, 0.86, 1, text);
2225       sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma);
2226       mySmallText(0.2, 0.8, 2, text);
2227       sprintf(text, "p_{T} < 5 GeV");
2228       mySmallText(0.2, 0.7, 1, text);
2229       cfit.SaveAs(fitdir + "resVsEta_eta_L_" + etarange[i] + ".pdf");
2230       delete fit;
2231 
2232       fit = new TF1("fit", "gaus", -0.01, 0.01);
2233       h_resVsEta_eta_H[i]->Fit("fit", "R");
2234       sigma = fit->GetParameter(2);
2235       esigma = fit->GetParError(2);
2236       rms = h_resVsEta_eta_H[i]->GetRMS();
2237       erms = h_resVsEta_eta_H[i]->GetRMSError();
2238       h3_resVsEta_eta_H->SetBinContent(i + 1, sigma);
2239       h3_resVsEta_eta_H->SetBinError(i + 1, esigma);
2240       h_resVsEta_eta_H[i]->Draw();
2241       sprintf(text, "RMS: %.4f +/- %.4f", rms, erms);
2242       mySmallText(0.2, 0.86, 1, text);
2243       sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma);
2244       mySmallText(0.2, 0.8, 2, text);
2245       sprintf(text, "p_{T} > 15 GeV");
2246       mySmallText(0.2, 0.7, 1, text);
2247       cfit.SaveAs(fitdir + "resVsEta_eta_H_" + etarange[i] + ".pdf");
2248       delete fit;
2249 
2250       fit = new TF1("fit", "gaus", -1, 1);
2251       h_resVsEta_z0_L[i]->Fit("fit", "R");
2252       sigma = fit->GetParameter(2);
2253       esigma = fit->GetParError(2);
2254       rms = h_resVsEta_z0_L[i]->GetRMS();
2255       erms = h_resVsEta_z0_L[i]->GetRMSError();
2256       h3_resVsEta_z0_L->SetBinContent(i + 1, sigma);
2257       h3_resVsEta_z0_L->SetBinError(i + 1, esigma);
2258       h_resVsEta_z0_L[i]->Draw();
2259       sprintf(text, "RMS: %.4f +/- %.4f", rms, erms);
2260       mySmallText(0.2, 0.86, 1, text);
2261       sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma);
2262       mySmallText(0.2, 0.8, 2, text);
2263       sprintf(text, "p_{T} < 5 GeV");
2264       mySmallText(0.2, 0.7, 1, text);
2265       cfit.SaveAs(fitdir + "resVsEta_z0_L_" + etarange[i] + ".pdf");
2266       delete fit;
2267 
2268       fit = new TF1("fit", "gaus", -1, 1);
2269       h_resVsEta_z0_H[i]->Fit("fit", "R");
2270       sigma = fit->GetParameter(2);
2271       esigma = fit->GetParError(2);
2272       rms = h_resVsEta_z0_H[i]->GetRMS();
2273       erms = h_resVsEta_z0_H[i]->GetRMSError();
2274       h3_resVsEta_z0_H->SetBinContent(i + 1, sigma);
2275       h3_resVsEta_z0_H->SetBinError(i + 1, esigma);
2276       h_resVsEta_z0_H[i]->Draw();
2277       sprintf(text, "RMS: %.4f +/- %.4f", rms, erms);
2278       mySmallText(0.2, 0.86, 1, text);
2279       sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma);
2280       mySmallText(0.2, 0.8, 2, text);
2281       sprintf(text, "p_{T} > 15 GeV");
2282       mySmallText(0.2, 0.7, 1, text);
2283       cfit.SaveAs(fitdir + "resVsEta_z0_H_" + etarange[i] + ".pdf");
2284       delete fit;
2285 
2286       fit = new TF1("fit", "gaus", -0.005, 0.005);
2287       h_resVsEta_phi_L[i]->Fit("fit", "R");
2288       sigma = fit->GetParameter(2);
2289       esigma = fit->GetParError(2);
2290       rms = h_resVsEta_phi_L[i]->GetRMS();
2291       erms = h_resVsEta_phi_L[i]->GetRMSError();
2292       h3_resVsEta_phi_L->SetBinContent(i + 1, sigma);
2293       h3_resVsEta_phi_L->SetBinError(i + 1, esigma);
2294       h_resVsEta_phi_L[i]->Draw();
2295       sprintf(text, "RMS: %.4f +/- %.4f", rms, erms);
2296       mySmallText(0.2, 0.86, 1, text);
2297       sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma);
2298       mySmallText(0.2, 0.8, 2, text);
2299       sprintf(text, "p_{T} < 5 GeV");
2300       mySmallText(0.2, 0.7, 1, text);
2301       cfit.SaveAs(fitdir + "resVsEta_phi_L_" + etarange[i] + ".pdf");
2302       delete fit;
2303 
2304       fit = new TF1("fit", "gaus", -0.005, 0.005);
2305       h_resVsEta_phi_H[i]->Fit("fit", "R");
2306       sigma = fit->GetParameter(2);
2307       esigma = fit->GetParError(2);
2308       rms = h_resVsEta_phi_H[i]->GetRMS();
2309       erms = h_resVsEta_phi_H[i]->GetRMSError();
2310       h3_resVsEta_phi_H->SetBinContent(i + 1, sigma);
2311       h3_resVsEta_phi_H->SetBinError(i + 1, esigma);
2312       h_resVsEta_phi_H[i]->Draw();
2313       sprintf(text, "RMS: %.4f +/- %.4f", rms, erms);
2314       mySmallText(0.2, 0.86, 1, text);
2315       sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma);
2316       mySmallText(0.2, 0.8, 2, text);
2317       sprintf(text, "p_{T} > 15 GeV");
2318       mySmallText(0.2, 0.7, 1, text);
2319       cfit.SaveAs(fitdir + "resVsEta_phi_H_" + etarange[i] + ".pdf");
2320       delete fit;
2321 
2322       fit = new TF1("fit", "gaus", -0.5, 0.5);
2323       h_resVsEta_ptRel_L[i]->Fit("fit", "R");
2324       sigma = fit->GetParameter(2);
2325       esigma = fit->GetParError(2);
2326       rms = h_resVsEta_ptRel_L[i]->GetRMS();
2327       erms = h_resVsEta_ptRel_L[i]->GetRMSError();
2328       h3_resVsEta_ptRel_L->SetBinContent(i + 1, sigma);
2329       h3_resVsEta_ptRel_L->SetBinError(i + 1, esigma);
2330       h_resVsEta_ptRel_L[i]->Draw();
2331       sprintf(text, "RMS: %.4f +/- %.4f", rms, erms);
2332       mySmallText(0.2, 0.86, 1, text);
2333       sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma);
2334       mySmallText(0.2, 0.8, 2, text);
2335       sprintf(text, "p_{T} < 5 GeV");
2336       mySmallText(0.2, 0.7, 1, text);
2337       cfit.SaveAs(fitdir + "resVsEta_ptRel_L_" + etarange[i] + ".pdf");
2338       delete fit;
2339 
2340       fit = new TF1("fit", "gaus", -0.5, 0.5);
2341       h_resVsEta_ptRel_H[i]->Fit("fit", "R");
2342       sigma = fit->GetParameter(2);
2343       esigma = fit->GetParError(2);
2344       rms = h_resVsEta_ptRel_H[i]->GetRMS();
2345       erms = h_resVsEta_ptRel_H[i]->GetRMSError();
2346       h3_resVsEta_ptRel_H->SetBinContent(i + 1, sigma);
2347       h3_resVsEta_ptRel_H->SetBinError(i + 1, esigma);
2348       h_resVsEta_ptRel_H[i]->Draw();
2349       sprintf(text, "RMS: %.4f +/- %.4f", rms, erms);
2350       mySmallText(0.2, 0.86, 1, text);
2351       sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma);
2352       mySmallText(0.2, 0.8, 2, text);
2353       sprintf(text, "p_{T} > 15 GeV");
2354       mySmallText(0.2, 0.7, 1, text);
2355       cfit.SaveAs(fitdir + "resVsEta_ptRel_H_" + etarange[i] + ".pdf");
2356       delete fit;
2357 
2358     }  //end doGausFit
2359   }
2360 
2361   TH1F* h2_resVsPhi_pt_68 =
2362       new TH1F("resVsPhi2_pt_68", ";Tracking particle #phi; p_{T} resolution [GeV]", 32, -3.2, 3.2);
2363   TH1F* h2_resVsPhi_pt_90 =
2364       new TH1F("resVsPhi2_pt_90", ";Tracking particle #phi; p_{T} resolution [GeV]", 32, -3.2, 3.2);
2365   TH1F* h2_resVsPhi_pt_99 =
2366       new TH1F("resVsPhi2_pt_99", ";Tracking particle #phi; p_{T} resolution [GeV]", 32, -3.2, 3.2);
2367   TH1F* h2_resVsPhi_ptRel_68 =
2368       new TH1F("resVsPhi2_ptRel_68", ";Tracking particle #phi; p_{T} resolution / p_{T}", 32, -3.2, 3.2);
2369   TH1F* h2_resVsPhi_ptRel_90 =
2370       new TH1F("resVsPhi2_ptRel_90", ";Tracking particle #phi; p_{T} resolution / p_{T}", 32, -3.2, 3.2);
2371   TH1F* h2_resVsPhi_ptRel_99 =
2372       new TH1F("resVsPhi2_ptRel_99", ";Tracking particle #phi; p_{T} resolution / p_{T}", 32, -3.2, 3.2);
2373 
2374   for (int i = 0; i < nPHIRANGE; i++) {
2375     h2_resVsPhi_pt_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_pt[i], 0.68));
2376     h2_resVsPhi_pt_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_pt[i], 0.90));
2377     h2_resVsPhi_pt_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_pt[i], 0.99));
2378 
2379     h2_resVsPhi_ptRel_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_ptRel[i], 0.68));
2380     h2_resVsPhi_ptRel_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_ptRel[i], 0.90));
2381     h2_resVsPhi_ptRel_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_ptRel[i], 0.99));
2382   }
2383 
2384   // set minimum to zero
2385   h2_resVsPt_pt->SetMinimum(0);
2386   h2_resVsPt_pt_C->SetMinimum(0);
2387   h2_resVsPt_pt_I->SetMinimum(0);
2388   h2_resVsPt_pt_F->SetMinimum(0);
2389 
2390   h2_resVsPt_ptRel->SetMinimum(0);
2391   h2_resVsPt_ptRel_C->SetMinimum(0);
2392   h2_resVsPt_ptRel_I->SetMinimum(0);
2393   h2_resVsPt_ptRel_F->SetMinimum(0);
2394 
2395   h2_resVsPt_z0->SetMinimum(0);
2396   h2_resVsPt_z0_C->SetMinimum(0);
2397   h2_resVsPt_z0_I->SetMinimum(0);
2398   h2_resVsPt_z0_F->SetMinimum(0);
2399 
2400   h2_resVsPt_phi->SetMinimum(0);
2401   h2_resVsPt_phi_C->SetMinimum(0);
2402   h2_resVsPt_phi_I->SetMinimum(0);
2403   h2_resVsPt_phi_F->SetMinimum(0);
2404 
2405   h2_resVsPt_eta->SetMinimum(0);
2406 
2407   h2_resVsEta_eta->SetMinimum(0);
2408   h2_resVsEta_eta_L->SetMinimum(0);
2409   h2_resVsEta_eta_H->SetMinimum(0);
2410 
2411   h2_resVsEta_z0->SetMinimum(0);
2412   h2_resVsEta_z0_L->SetMinimum(0);
2413   h2_resVsEta_z0_H->SetMinimum(0);
2414 
2415   h2_resVsEta_phi->SetMinimum(0);
2416   h2_resVsEta_phi_L->SetMinimum(0);
2417   h2_resVsEta_phi_H->SetMinimum(0);
2418 
2419   h2_resVsEta_ptRel->SetMinimum(0);
2420   h2_resVsEta_ptRel_L->SetMinimum(0);
2421   h2_resVsEta_ptRel_H->SetMinimum(0);
2422 
2423   h2_resVsPt_d0->SetMinimum(0);
2424   h2_resVsEta_d0->SetMinimum(0);
2425   h2_resVsEta_d0_L->SetMinimum(0);
2426   h2_resVsEta_d0_H->SetMinimum(0);
2427 
2428   // -------------------------------------------------------------------------------------------
2429   // output file for histograms
2430   // -------------------------------------------------------------------------------------------
2431 
2432   if (TP_select_pdgid != 0) {
2433     char pdgidtxt[500];
2434     sprintf(pdgidtxt, "_pdgid%i", TP_select_pdgid);
2435     type = type + pdgidtxt;
2436   } else if (TP_select_injet == 1)
2437     type = type + "_injet";
2438   else if (TP_select_injet == 2)
2439     type = type + "_injet_highpt";
2440   else if (TP_select_injet == 3)
2441     type = type + "_injet_vhighpt";
2442 
2443   if (TP_select_eventid != 0)
2444     type = type + "_wpu";
2445 
2446   if (useTightCuts)
2447     type = type + "_tight";
2448   if (useDeadRegion)
2449     type = type + "_dead";
2450 
2451   if (L1Tk_seed != 0) {
2452     char seedtxt[500];
2453     sprintf(seedtxt, "_seed%i", L1Tk_seed);
2454     type = type + seedtxt;
2455   }
2456 
2457   if (TP_minPt > 2.0) {
2458     char pttxt[500];
2459     sprintf(pttxt, "_pt%.0f", TP_minPt);
2460     type = type + pttxt;
2461   }
2462 
2463   TFile* fout;
2464   if (doLooseMatch)
2465     fout = new TFile("output_looseMatch_" + type + treeName + ".root", "recreate");
2466   else
2467     fout = new TFile(type_dir + "output_" + type + treeName + ".root", "recreate");
2468 
2469   // -------------------------------------------------------------------------------------------
2470   // draw and save plots
2471   // -------------------------------------------------------------------------------------------
2472 
2473   char ctxt[500];
2474   TCanvas c;
2475 
2476   gSystem->mkdir("TrkPlots");
2477   TString DIR = "TrkPlots/";
2478 
2479   // plots overlaying 68, 90, 99% confidence levels]
2480 
2481   float max_eta_ptRel = 0.2;
2482   float max_pt_ptRel = 0.2;
2483   float max_pt_pt = 20;
2484   float max_z0 = 2.0;
2485   float max_phi = 0.01;
2486   float max_eta = 0.03;
2487 
2488   if (type.Contains("El")) {
2489     max_pt_ptRel = 1.0;
2490     max_eta_ptRel = 1.0;
2491     max_phi = 0.1;
2492   }
2493 
2494   // makeResidualIntervalPlot will save the individual plots to the root file
2495   makeResidualIntervalPlot(
2496       type, DIR, "resVsPt_ptRel", h2_resVsPt_ptRel_68, h2_resVsPt_ptRel_90, h2_resVsPt_ptRel_99, 0, max_pt_ptRel);
2497   makeResidualIntervalPlot(type, DIR, "resVsPt_pt", h2_resVsPt_pt_68, h2_resVsPt_pt_90, h2_resVsPt_pt_99, 0, max_pt_pt);
2498   makeResidualIntervalPlot(type, DIR, "resVsPt_z0", h2_resVsPt_z0_68, h2_resVsPt_z0_90, h2_resVsPt_z0_99, 0, max_z0);
2499   makeResidualIntervalPlot(
2500       type, DIR, "resVsPt_phi", h2_resVsPt_phi_68, h2_resVsPt_phi_90, h2_resVsPt_phi_99, 0, max_phi);
2501   makeResidualIntervalPlot(
2502       type, DIR, "resVsPt_eta", h2_resVsPt_eta_68, h2_resVsPt_eta_90, h2_resVsPt_eta_99, 0, max_eta);
2503   //makeResidualIntervalPlot( type, DIR, "resVsPt_d0", h2_resVsPt_d0_68, h2_resVsPt_d0_90, h2_resVsPt_d0_99, 0, 0.02 );
2504 
2505   makeResidualIntervalPlot(type,
2506                            DIR,
2507                            "resVsPt_L_ptRel",
2508                            h2_resVsPt_ptRel_L_68,
2509                            h2_resVsPt_ptRel_L_90,
2510                            h2_resVsPt_ptRel_L_99,
2511                            0,
2512                            max_pt_ptRel);
2513   makeResidualIntervalPlot(type, DIR, "resVsPt_L_pt", h2_resVsPt_pt_L_68, h2_resVsPt_pt_L_90, h2_resVsPt_pt_L_99, 0, 4);
2514   makeResidualIntervalPlot(
2515       type, DIR, "resVsPt_L_z0", h2_resVsPt_z0_L_68, h2_resVsPt_z0_L_90, h2_resVsPt_z0_L_99, 0, max_z0);
2516   makeResidualIntervalPlot(
2517       type, DIR, "resVsPt_L_phi", h2_resVsPt_phi_L_68, h2_resVsPt_phi_L_90, h2_resVsPt_phi_L_99, 0, max_phi);
2518   makeResidualIntervalPlot(
2519       type, DIR, "resVsPt_L_eta", h2_resVsPt_eta_L_68, h2_resVsPt_eta_L_90, h2_resVsPt_eta_L_99, 0, max_eta);
2520   //makeResidualIntervalPlot( type, DIR, "resVsPt_L_d0", h2_resVsPt_d0_L_68, h2_resVsPt_d0_L_90, h2_resVsPt_d0_L_99, 0, 0.02 );
2521 
2522   makeResidualIntervalPlot(
2523       type, DIR, "resVsEta_eta", h2_resVsEta_eta_68, h2_resVsEta_eta_90, h2_resVsEta_eta_99, 0, max_eta);
2524   makeResidualIntervalPlot(
2525       type, DIR, "resVsEta_z0", h2_resVsEta_z0_68, h2_resVsEta_z0_90, h2_resVsEta_z0_99, 0, max_z0);
2526   makeResidualIntervalPlot(
2527       type, DIR, "resVsEta_phi", h2_resVsEta_phi_68, h2_resVsEta_phi_90, h2_resVsEta_phi_99, 0, max_phi);
2528   makeResidualIntervalPlot(
2529       type, DIR, "resVsEta_ptRel", h2_resVsEta_ptRel_68, h2_resVsEta_ptRel_90, h2_resVsEta_ptRel_99, 0, max_eta_ptRel);
2530   //makeResidualIntervalPlot( type, DIR, "resVsEta_d0", h2_resVsEta_d0_68, h2_resVsEta_d0_90, h2_resVsEta_d0_99, 0, 0.02 );
2531 
2532   makeResidualIntervalPlot(
2533       type, DIR, "resVsEta_L_eta", h2_resVsEta_eta_L_68, h2_resVsEta_eta_L_90, h2_resVsEta_eta_L_99, 0, max_eta);
2534   makeResidualIntervalPlot(
2535       type, DIR, "resVsEta_L_z0", h2_resVsEta_z0_L_68, h2_resVsEta_z0_L_90, h2_resVsEta_z0_L_99, 0, max_z0);
2536   makeResidualIntervalPlot(
2537       type, DIR, "resVsEta_L_phi", h2_resVsEta_phi_L_68, h2_resVsEta_phi_L_90, h2_resVsEta_phi_L_99, 0, max_phi);
2538   makeResidualIntervalPlot(type,
2539                            DIR,
2540                            "resVsEta_L_ptRel",
2541                            h2_resVsEta_ptRel_L_68,
2542                            h2_resVsEta_ptRel_L_90,
2543                            h2_resVsEta_ptRel_L_99,
2544                            0,
2545                            max_eta_ptRel);
2546   //makeResidualIntervalPlot( type, DIR, "resVsEta_L_d0", h2_resVsEta_d0_L_68, h2_resVsEta_d0_L_90, h2_resVsEta_d0_L_99, 0, 0.02 );
2547 
2548   makeResidualIntervalPlot(
2549       type, DIR, "resVsEta_H_eta", h2_resVsEta_eta_H_68, h2_resVsEta_eta_H_90, h2_resVsEta_eta_H_99, 0, max_eta);
2550   makeResidualIntervalPlot(
2551       type, DIR, "resVsEta_H_z0", h2_resVsEta_z0_H_68, h2_resVsEta_z0_H_90, h2_resVsEta_z0_H_99, 0, max_z0);
2552   makeResidualIntervalPlot(
2553       type, DIR, "resVsEta_H_phi", h2_resVsEta_phi_H_68, h2_resVsEta_phi_H_90, h2_resVsEta_phi_H_99, 0, max_phi);
2554   makeResidualIntervalPlot(type,
2555                            DIR,
2556                            "resVsEta_H_ptRel",
2557                            h2_resVsEta_ptRel_H_68,
2558                            h2_resVsEta_ptRel_H_90,
2559                            h2_resVsEta_ptRel_H_99,
2560                            0,
2561                            max_eta_ptRel);
2562   //makeResidualIntervalPlot( type, DIR, "resVsEta_H_d0", h2_resVsEta_d0_H_68, h2_resVsEta_d0_H_90, h2_resVsEta_d0_H_99, 0, 0.02 );
2563 
2564   if (doDetailedPlots) {
2565     makeResidualIntervalPlot(
2566         type, DIR, "resVsPhi_ptRel", h2_resVsPhi_ptRel_68, h2_resVsPhi_ptRel_90, h2_resVsPhi_ptRel_99, 0, 0.5);
2567     makeResidualIntervalPlot(type, DIR, "resVsPhi_pt", h2_resVsPhi_pt_68, h2_resVsPhi_pt_90, h2_resVsPhi_pt_99, 0, 20);
2568   }
2569 
2570   // ----------------------------------------------------------------------------------------------------------
2571   // resoultion vs pt
2572   // ----------------------------------------------------------------------------------------------------------
2573 
2574   h2_resVsPt_pt_90->SetMinimum(0);
2575   h2_resVsPt_pt_90->SetMarkerStyle(20);
2576   h2_resVsPt_pt_90->Draw("p");
2577   c.SaveAs(DIR + type + "_resVsPt_pt_90.pdf");
2578 
2579   h2_resVsPt_ptRel_90->SetMinimum(0);
2580   h2_resVsPt_ptRel_90->SetMarkerStyle(20);
2581   h2_resVsPt_ptRel_90->Draw("p");
2582   c.SaveAs(DIR + type + "_resVsPt_ptRel_90.pdf");
2583 
2584   h2_resVsPt_z0_90->SetMinimum(0);
2585   h2_resVsPt_z0_90->SetMarkerStyle(20);
2586   h2_resVsPt_z0_90->Draw("p");
2587   c.SaveAs(DIR + type + "_resVsPt_z0_90.pdf");
2588 
2589   h2_resVsPt_phi_90->SetMinimum(0);
2590   h2_resVsPt_phi_90->SetMarkerStyle(20);
2591   h2_resVsPt_phi_90->Draw("p");
2592   c.SaveAs(DIR + type + "_resVsPt_phi_90.pdf");
2593 
2594   h2_resVsPt_eta_90->SetMinimum(0);
2595   h2_resVsPt_eta_90->SetMarkerStyle(20);
2596   h2_resVsPt_eta_90->Draw("p");
2597   c.SaveAs(DIR + type + "_resVsPt_eta_90.pdf");
2598 
2599   /*
2600   h2_resVsPt_phi_90->SetMinimum(0);
2601   h2_resVsPt_d0_90->SetMarkerStyle(20);
2602   h2_resVsPt_d0_90->Draw("p");
2603   c.SaveAs(DIR+type+"_resVsPt_d0_90.pdf");
2604   */
2605 
2606   // Limit decimal places for doubles in normalized tracklet eff. graphs
2607   gStyle->SetPaintTextFormat("4.2f");
2608 
2609   h_trk_tracklet_eff->SetMinimum(0);
2610   h_trk_tracklet_eff->Draw("col text");
2611   c.SaveAs(DIR + type + "_trk_tracklet_eff.pdf");
2612 
2613   // Remove decimal places for ints in in tracklet hits graphs
2614   gStyle->SetPaintTextFormat("4.0f");
2615 
2616   h_trk_tracklet_hits->SetMinimum(0);
2617   h_trk_tracklet_hits->Draw("col text");
2618   c.SaveAs(DIR + type + "_trk_tracklet_hits.pdf");
2619 
2620   if (doDetailedPlots) {
2621     h2_resVsPt_eta->Write();
2622 
2623     h2_resVsPt_pt->Write();
2624     h2_resVsPt_pt_C->Write();
2625     h2_resVsPt_pt_I->Write();
2626     h2_resVsPt_pt_F->Write();
2627 
2628     h2_resVsPt_ptRel->Write();
2629     h2_resVsPt_ptRel_C->Write();
2630     h2_resVsPt_ptRel_I->Write();
2631     h2_resVsPt_ptRel_F->Write();
2632 
2633     h2_mresVsPt_pt->Write();
2634     h2_mresVsPt_pt_C->Write();
2635     h2_mresVsPt_pt_I->Write();
2636     h2_mresVsPt_pt_F->Write();
2637 
2638     h2_resVsPt_d0->Write();
2639 
2640     h2_resVsPt_z0_C->Write();
2641     h2_resVsPt_z0_I->Write();
2642     h2_resVsPt_z0_F->Write();
2643 
2644     h2_resVsPt_phi->Write();
2645     h2_resVsPt_phi_C->Write();
2646     h2_resVsPt_phi_I->Write();
2647     h2_resVsPt_phi_F->Write();
2648   }
2649 
2650   // ----------------------------------------------------------------------------------------------------------
2651   // resolution vs eta
2652   // ----------------------------------------------------------------------------------------------------------
2653 
2654   h2_resVsEta_eta_90->SetMinimum(0);
2655   h2_resVsEta_eta_90->SetMarkerStyle(20);
2656   h2_resVsEta_eta_90->Draw("p");
2657   c.SaveAs(DIR + type + "_resVsEta_eta_90.pdf");
2658 
2659   h2_resVsEta_eta_68->SetMinimum(0);
2660   h2_resVsEta_eta_68->SetMarkerStyle(20);
2661   h2_resVsEta_eta_68->Draw("p");
2662   c.SaveAs(DIR + type + "_resVsEta_eta_68.pdf");
2663 
2664   if (doDetailedPlots) {
2665     h2_resVsEta_eta_L_90->Draw("p");
2666     sprintf(ctxt, "p_{T} < 8 GeV");
2667     mySmallText(0.22, 0.82, 1, ctxt);
2668     c.SaveAs(DIR + type + "_resVsEta_eta_L_90.pdf");
2669 
2670     h2_resVsEta_eta_H_90->Draw("p");
2671     sprintf(ctxt, "p_{T} > 8 GeV");
2672     mySmallText(0.22, 0.82, 1, ctxt);
2673     c.SaveAs(DIR + type + "_resVsEta_eta_H_90.pdf");
2674   }
2675 
2676   h2_resVsEta_z0_90->SetMinimum(0);
2677   h2_resVsEta_z0_90->SetMarkerStyle(20);
2678   h2_resVsEta_z0_90->Draw("p");
2679   c.SaveAs(DIR + type + "_resVsEta_z0_90.pdf");
2680 
2681   h2_resVsEta_z0_68->SetMinimum(0);
2682   h2_resVsEta_z0_68->SetMarkerStyle(20);
2683   h2_resVsEta_z0_68->Draw("p");
2684   c.SaveAs(DIR + type + "_resVsEta_z0_68.pdf");
2685 
2686   if (doDetailedPlots) {
2687     h2_resVsEta_z0_L_90->Draw();
2688     sprintf(ctxt, "p_{T} < 8 GeV");
2689     mySmallText(0.22, 0.82, 1, ctxt);
2690     c.SaveAs(DIR + type + "_resVsEta_z0_L_90.pdf");
2691 
2692     h2_resVsEta_z0_H_90->Draw();
2693     sprintf(ctxt, "p_{T} > 8 GeV");
2694     mySmallText(0.22, 0.82, 1, ctxt);
2695     c.SaveAs(DIR + type + "_resVsEta_z0_H_90.pdf");
2696   }
2697 
2698   /*
2699   h2_resVsEta_d0_90->Draw();
2700   c.SaveAs(DIR+type+"_resVsEta_d0_90.pdf");
2701 
2702   h2_resVsEta_d0_L_90->Draw();
2703   sprintf(ctxt,"p_{T} < 8 GeV");
2704   mySmallText(0.22,0.82,1,ctxt);
2705   c.SaveAs(DIR+type+"_resVsEta_d0_L_90.pdf");
2706 
2707   h2_resVsEta_d0_H_90->Draw();
2708   sprintf(ctxt,"p_{T} > 8 GeV");
2709   mySmallText(0.22,0.82,1,ctxt);
2710   c.SaveAs(DIR+type+"_resVsEta_d0_H_90.pdf");
2711   */
2712 
2713   h2_resVsEta_phi_90->SetMinimum(0);
2714   h2_resVsEta_phi_90->SetMarkerStyle(20);
2715   h2_resVsEta_phi_90->Draw("p");
2716   c.SaveAs(DIR + type + "_resVsEta_phi_90.pdf");
2717 
2718   h2_resVsEta_phi_68->SetMinimum(0);
2719   h2_resVsEta_phi_68->SetMarkerStyle(20);
2720   h2_resVsEta_phi_68->Draw("p");
2721   c.SaveAs(DIR + type + "_resVsEta_phi_68.pdf");
2722 
2723   if (doDetailedPlots) {
2724     h2_resVsEta_phi_L_90->Draw();
2725     sprintf(ctxt, "p_{T} < 8 GeV");
2726     mySmallText(0.22, 0.82, 1, ctxt);
2727     c.SaveAs(DIR + type + "_resVsEta_phi_L_90.pdf");
2728 
2729     h2_resVsEta_phi_H_90->Draw();
2730     sprintf(ctxt, "p_{T} > 8 GeV");
2731     mySmallText(0.22, 0.82, 1, ctxt);
2732     c.SaveAs(DIR + type + "_resVsEta_phi_H_90.pdf");
2733   }
2734 
2735   h2_resVsEta_ptRel_90->SetMinimum(0);
2736   h2_resVsEta_ptRel_90->SetMarkerStyle(20);
2737   h2_resVsEta_ptRel_90->Draw("p");
2738   c.SaveAs(DIR + type + "_resVsEta_ptRel_90.pdf");
2739 
2740   h2_resVsEta_ptRel_68->SetMinimum(0);
2741   h2_resVsEta_ptRel_68->SetMarkerStyle(20);
2742   h2_resVsEta_ptRel_68->Draw("p");
2743   c.SaveAs(DIR + type + "_resVsEta_ptRel_68.pdf");
2744 
2745   if (doDetailedPlots) {
2746     h2_resVsEta_ptRel_L_90->Draw();
2747     sprintf(ctxt, "p_{T} < 8 GeV");
2748     mySmallText(0.22, 0.82, 1, ctxt);
2749     c.SaveAs(DIR + type + "_resVsEta_ptRel_L_90.pdf");
2750 
2751     h2_resVsEta_ptRel_H_90->Draw();
2752     sprintf(ctxt, "p_{T} > 8 GeV");
2753     mySmallText(0.22, 0.82, 1, ctxt);
2754     c.SaveAs(DIR + type + "_resVsEta_ptRel_H_90.pdf");
2755 
2756     h2_resVsEta_eta->Write();
2757     h2_resVsEta_eta_L->Write();
2758     h2_resVsEta_eta_H->Write();
2759 
2760     h2_resVsEta_z0->Draw();
2761     c.SaveAs(DIR + type + "_resVsEta_z0_rms.pdf");
2762     h2_resVsEta_eta->Draw();
2763     c.SaveAs(DIR + type + "_resVsEta_eta_rms.pdf");
2764     h2_resVsEta_ptRel->Draw();
2765     c.SaveAs(DIR + type + "_resVsEta_ptRel_rms.pdf");
2766     h2_resVsEta_phi->Draw();
2767     c.SaveAs(DIR + type + "_resVsEta_phi_rms.pdf");
2768 
2769     // check residuals
2770     h2_mresVsEta_z0->Draw();
2771     h2_mresVsEta_z0->Write();
2772     c.SaveAs(DIR + type + "_mean-resVsEta_z0.pdf");
2773 
2774     h2_mresVsEta_eta->Draw();
2775     h2_mresVsEta_eta->Write();
2776     c.SaveAs(DIR + type + "_mean-resVsEta_eta.pdf");
2777 
2778     h2_mresVsEta_ptRel->Draw();
2779     h2_mresVsEta_ptRel->Write();
2780     c.SaveAs(DIR + type + "_mean-resVsEta_ptRel.pdf");
2781 
2782     h2_mresVsEta_phi->Draw();
2783     h2_mresVsEta_phi->Write();
2784     c.SaveAs(DIR + type + "_mean-resVsEta_phi.pdf");
2785 
2786     h2_resVsEta_z0->Write();
2787     h2_resVsEta_z0_L->Write();
2788     h2_resVsEta_z0_H->Write();
2789 
2790     h2_resVsEta_d0->Write();
2791     h2_resVsEta_d0_L->Write();
2792     h2_resVsEta_d0_H->Write();
2793 
2794     h2_resVsEta_phi->Write();
2795     h2_resVsEta_phi_L->Write();
2796     h2_resVsEta_phi_H->Write();
2797 
2798     h2_resVsEta_ptRel->Write();
2799     h2_resVsEta_ptRel_L->Write();
2800     h2_resVsEta_ptRel_H->Write();
2801   }
2802 
2803   if (doGausFit) {
2804     h3_resVsEta_eta_L->Write();
2805     h3_resVsEta_z0_L->Write();
2806     h3_resVsEta_phi_L->Write();
2807     h3_resVsEta_ptRel_L->Write();
2808 
2809     h3_resVsEta_eta_H->Write();
2810     h3_resVsEta_z0_H->Write();
2811     h3_resVsEta_phi_H->Write();
2812     h3_resVsEta_ptRel_H->Write();
2813   }
2814 
2815   // resolution vs phi
2816   if (doDetailedPlots) {
2817     h2_resVsPhi_pt_90->SetMinimum(0);
2818     h2_resVsPhi_pt_90->SetMarkerStyle(20);
2819     h2_resVsPhi_pt_90->Draw("p");
2820     c.SaveAs(DIR + type + "_resVsPhi_pt_90.pdf");
2821 
2822     h2_resVsPhi_ptRel_90->SetMinimum(0);
2823     h2_resVsPhi_ptRel_90->SetMarkerStyle(20);
2824     h2_resVsPhi_ptRel_90->Draw("p");
2825     c.SaveAs(DIR + type + "_resVsPhi_ptRel_90.pdf");
2826   }
2827 
2828   // ----------------------------------------------------------------------------------------------------------------
2829   // track quality plots
2830   // ----------------------------------------------------------------------------------------------------------------
2831 
2832   if (doDetailedPlots) {
2833     h_match_trk_nstub->Write();
2834     h_match_trk_nstub_C->Write();
2835     h_match_trk_nstub_I->Write();
2836     h_match_trk_nstub_F->Write();
2837   }
2838 
2839   h_trk_chi2->Draw();
2840   sprintf(ctxt, "|eta| < 2.4");
2841   mySmallText(0.52, 0.82, 1, ctxt);
2842   c.SaveAs(DIR + type + "_trk_chi2.pdf");
2843 
2844   h_trk_chi2_dof->Draw();
2845   sprintf(ctxt, "|eta| < 2.4");
2846   mySmallText(0.52, 0.82, 1, ctxt);
2847   c.SaveAs(DIR + type + "_trk_chi2_dof.pdf");
2848 
2849   h_trk_chi2rphi->Draw();
2850   sprintf(ctxt, "|eta| < 2.4");
2851   mySmallText(0.52, 0.82, 1, ctxt);
2852   c.SaveAs(DIR + type + "_trk_chi2rphi.pdf");
2853 
2854   h_trk_chi2rphi_dof->Draw();
2855   sprintf(ctxt, "|eta| < 2.4");
2856   mySmallText(0.52, 0.82, 1, ctxt);
2857   c.SaveAs(DIR + type + "_trk_chi2rphi_dof.pdf");
2858 
2859   h_trk_chi2rz->Draw();
2860   sprintf(ctxt, "|eta| < 2.4");
2861   mySmallText(0.52, 0.82, 1, ctxt);
2862   c.SaveAs(DIR + type + "_trk_chi2rz.pdf");
2863 
2864   h_trk_chi2rz_dof->Draw();
2865   sprintf(ctxt, "|eta| < 2.4");
2866   mySmallText(0.52, 0.82, 1, ctxt);
2867   c.SaveAs(DIR + type + "_trk_chi2rz_dof.pdf");
2868 
2869   h_trk_chi2->Write();
2870   h_trk_chi2rphi->Write();
2871   h_trk_chi2rz->Write();
2872   h_match_trk_chi2->Write();
2873   h_match_trk_chi2rphi->Write();
2874   h_match_trk_chi2rz->Write();
2875 
2876   if (doDetailedPlots) {
2877     h_match_trk_chi2_C_L->Write();
2878     h_match_trk_chi2_I_L->Write();
2879     h_match_trk_chi2_F_L->Write();
2880     h_match_trk_chi2_C_H->Write();
2881     h_match_trk_chi2_I_H->Write();
2882     h_match_trk_chi2_F_H->Write();
2883 
2884     h_match_trk_chi2_dof_C_L->Write();
2885     h_match_trk_chi2_dof_I_L->Write();
2886     h_match_trk_chi2_dof_F_L->Write();
2887     h_match_trk_chi2_dof_C_H->Write();
2888     h_match_trk_chi2_dof_I_H->Write();
2889     h_match_trk_chi2_dof_F_H->Write();
2890   }
2891 
2892   // ----------------------------------------------------------------------------------------------------------------
2893   // efficiency plots
2894   // ----------------------------------------------------------------------------------------------------------------
2895 
2896   // rebin pt/phi plots
2897   h_tp_pt->Rebin(2);
2898   h_match_tp_pt->Rebin(2);
2899   h_tp_phi->Rebin(2);
2900   h_match_tp_phi->Rebin(2);
2901 
2902   h_tp_pt_L->Rebin(2);
2903   h_match_tp_pt_L->Rebin(2);
2904   h_tp_pt_LC->Rebin(2);
2905   h_match_tp_pt_LC->Rebin(2);
2906   h_tp_pt_H->Rebin(2);
2907   h_match_tp_pt_H->Rebin(2);
2908 
2909   // h_tp_eta->Rebin(2);
2910   // h_match_tp_eta->Rebin(2);
2911   // h_tp_eta_L->Rebin(2);
2912   // h_match_tp_eta_L->Rebin(2);
2913   // h_tp_eta_H->Rebin(2);
2914   // h_match_tp_eta_H->Rebin(2);
2915 
2916   // calculate the efficiency
2917   h_match_tp_pt->Sumw2();
2918   h_tp_pt->Sumw2();
2919   TH1F* h_eff_pt = (TH1F*)h_match_tp_pt->Clone();
2920   h_eff_pt->SetName("eff_pt");
2921   h_eff_pt->GetYaxis()->SetTitle("Efficiency");
2922   h_eff_pt->Divide(h_match_tp_pt, h_tp_pt, 1.0, 1.0, "B");
2923 
2924   h_match_tp_pt_L->Sumw2();
2925   h_tp_pt_L->Sumw2();
2926   TH1F* h_eff_pt_L = (TH1F*)h_match_tp_pt_L->Clone();
2927   h_eff_pt_L->SetName("eff_pt_L");
2928   h_eff_pt_L->GetYaxis()->SetTitle("Efficiency");
2929   h_eff_pt_L->Divide(h_match_tp_pt_L, h_tp_pt_L, 1.0, 1.0, "B");
2930 
2931   h_match_tp_pt_LC->Sumw2();
2932   h_tp_pt_LC->Sumw2();
2933   TH1F* h_eff_pt_LC = (TH1F*)h_match_tp_pt_LC->Clone();
2934   h_eff_pt_LC->SetName("eff_pt_LC");
2935   h_eff_pt_LC->GetYaxis()->SetTitle("Efficiency");
2936   h_eff_pt_LC->Divide(h_match_tp_pt_LC, h_tp_pt_LC, 1.0, 1.0, "B");
2937 
2938   h_match_tp_pt_H->Sumw2();
2939   h_tp_pt_H->Sumw2();
2940   TH1F* h_eff_pt_H = (TH1F*)h_match_tp_pt_H->Clone();
2941   h_eff_pt_H->SetName("eff_pt_H");
2942   h_eff_pt_H->GetYaxis()->SetTitle("Efficiency");
2943   h_eff_pt_H->Divide(h_match_tp_pt_H, h_tp_pt_H, 1.0, 1.0, "B");
2944 
2945   h_match_tp_eta->Sumw2();
2946   h_tp_eta->Sumw2();
2947   TH1F* h_eff_eta = (TH1F*)h_match_tp_eta->Clone();
2948   h_eff_eta->SetName("eff_eta");
2949   h_eff_eta->GetYaxis()->SetTitle("Efficiency");
2950   h_eff_eta->Divide(h_match_tp_eta, h_tp_eta, 1.0, 1.0, "B");
2951 
2952   h_match_tp_eta_L->Sumw2();
2953   h_tp_eta_L->Sumw2();
2954   TH1F* h_eff_eta_L = (TH1F*)h_match_tp_eta_L->Clone();
2955   h_eff_eta_L->SetName("eff_eta_L");
2956   h_eff_eta_L->GetYaxis()->SetTitle("Efficiency");
2957   h_eff_eta_L->Divide(h_match_tp_eta_L, h_tp_eta_L, 1.0, 1.0, "B");
2958 
2959   h_match_tp_eta_H->Sumw2();
2960   h_tp_eta_H->Sumw2();
2961   TH1F* h_eff_eta_H = (TH1F*)h_match_tp_eta_H->Clone();
2962   h_eff_eta_H->SetName("eff_eta_H");
2963   h_eff_eta_H->GetYaxis()->SetTitle("Efficiency");
2964   h_eff_eta_H->Divide(h_match_tp_eta_H, h_tp_eta_H, 1.0, 1.0, "B");
2965 
2966   h_match_tp_eta_23->Sumw2();
2967   h_tp_eta_23->Sumw2();
2968   TH1F* h_eff_eta_23 = (TH1F*)h_match_tp_eta_23->Clone();
2969   h_eff_eta_23->SetName("eff_eta_23");
2970   h_eff_eta_23->GetYaxis()->SetTitle("Efficiency");
2971   h_eff_eta_23->Divide(h_match_tp_eta_23, h_tp_eta_23, 1.0, 1.0, "B");
2972 
2973   h_match_tp_eta_35->Sumw2();
2974   h_tp_eta_35->Sumw2();
2975   TH1F* h_eff_eta_35 = (TH1F*)h_match_tp_eta_35->Clone();
2976   h_eff_eta_35->SetName("eff_eta_35");
2977   h_eff_eta_35->GetYaxis()->SetTitle("Efficiency");
2978   h_eff_eta_35->Divide(h_match_tp_eta_35, h_tp_eta_35, 1.0, 1.0, "B");
2979 
2980   h_match_tp_eta_5->Sumw2();
2981   h_tp_eta_5->Sumw2();
2982   TH1F* h_eff_eta_5 = (TH1F*)h_match_tp_eta_5->Clone();
2983   h_eff_eta_5->SetName("eff_eta_5");
2984   h_eff_eta_5->GetYaxis()->SetTitle("Efficiency");
2985   h_eff_eta_5->Divide(h_match_tp_eta_5, h_tp_eta_5, 1.0, 1.0, "B");
2986 
2987   h_match_tp_phi->Sumw2();
2988   h_tp_phi->Sumw2();
2989   TH1F* h_eff_phi = (TH1F*)h_match_tp_phi->Clone();
2990   h_eff_phi->SetName("eff_phi");
2991   h_eff_phi->GetYaxis()->SetTitle("Efficiency");
2992   h_eff_phi->Divide(h_match_tp_phi, h_tp_phi, 1.0, 1.0, "B");
2993 
2994   h_match_tp_z0->Sumw2();
2995   h_tp_z0->Sumw2();
2996   TH1F* h_eff_z0 = (TH1F*)h_match_tp_z0->Clone();
2997   h_eff_z0->SetName("eff_z0");
2998   h_eff_z0->GetYaxis()->SetTitle("Efficiency");
2999   h_eff_z0->Divide(h_match_tp_z0, h_tp_z0, 1.0, 1.0, "B");
3000 
3001   h_match_tp_z0_L->Sumw2();
3002   h_tp_z0_L->Sumw2();
3003   TH1F* h_eff_z0_L = (TH1F*)h_match_tp_z0_L->Clone();
3004   h_eff_z0_L->SetName("eff_z0_L");
3005   h_eff_z0_L->GetYaxis()->SetTitle("Efficiency");
3006   h_eff_z0_L->Divide(h_match_tp_z0_L, h_tp_z0_L, 1.0, 1.0, "B");
3007 
3008   h_match_tp_z0_H->Sumw2();
3009   h_tp_z0_H->Sumw2();
3010   TH1F* h_eff_z0_H = (TH1F*)h_match_tp_z0_H->Clone();
3011   h_eff_z0_H->SetName("eff_z0_H");
3012   h_eff_z0_H->GetYaxis()->SetTitle("Efficiency");
3013   h_eff_z0_H->Divide(h_match_tp_z0_H, h_tp_z0_H, 1.0, 1.0, "B");
3014 
3015   h_match_tp_d0->Sumw2();
3016   h_tp_d0->Sumw2();
3017   TH1F* h_eff_d0 = (TH1F*)h_match_tp_d0->Clone();
3018   h_eff_d0->SetName("eff_d0");
3019   h_eff_d0->GetYaxis()->SetTitle("Efficiency");
3020   h_eff_d0->Divide(h_match_tp_d0, h_tp_d0, 1.0, 1.0, "B");
3021 
3022   h_match_tp_absd0->Sumw2();
3023   h_tp_absd0->Sumw2();
3024   TH1F* h_eff_absd0 = (TH1F*)h_match_tp_absd0->Clone();
3025   h_eff_absd0->SetName("eff_absd0");
3026   h_eff_absd0->GetYaxis()->SetTitle("Efficiency");
3027   h_eff_absd0->Divide(h_match_tp_absd0, h_tp_absd0, 1.0, 1.0, "B");
3028 
3029   h_match_tp_absd0_eta2->Sumw2();
3030   h_tp_absd0_eta2->Sumw2();
3031   TH1F* h_eff_absd0_eta2 = (TH1F*)h_match_tp_absd0_eta2->Clone();
3032   h_eff_absd0_eta2->SetName("eff_absd0_eta2");
3033   h_eff_absd0_eta2->GetYaxis()->SetTitle("Efficiency");
3034   h_eff_absd0_eta2->Divide(h_match_tp_absd0_eta2, h_tp_absd0_eta2, 1.0, 1.0, "B");
3035 
3036   h_match_tp_absd0_eta2_pt3->Sumw2();
3037   h_tp_absd0_eta2_pt3->Sumw2();
3038   TH1F* h_eff_absd0_eta2_pt3 = (TH1F*)h_match_tp_absd0_eta2_pt3->Clone();
3039   h_eff_absd0_eta2_pt3->SetName("eff_absd0_eta2_pt3");
3040   h_eff_absd0_eta2_pt3->GetYaxis()->SetTitle("Efficiency");
3041   h_eff_absd0_eta2_pt3->Divide(h_match_tp_absd0_eta2_pt3, h_tp_absd0_eta2_pt3, 1.0, 1.0, "B");
3042 
3043   // set the axis range
3044   h_eff_pt->SetAxisRange(0, 1.1, "Y");
3045   h_eff_pt_L->SetAxisRange(0, 1.1, "Y");
3046   h_eff_pt_LC->SetAxisRange(0, 1.1, "Y");
3047   h_eff_pt_H->SetAxisRange(0, 1.1, "Y");
3048   h_eff_eta->SetAxisRange(0, 1.1, "Y");
3049   h_eff_eta_L->SetAxisRange(0, 1.1, "Y");
3050   h_eff_eta_H->SetAxisRange(0, 1.1, "Y");
3051   h_eff_eta_23->SetAxisRange(0, 1.1, "Y");
3052   h_eff_eta_35->SetAxisRange(0, 1.1, "Y");
3053   h_eff_eta_5->SetAxisRange(0, 1.1, "Y");
3054   h_eff_phi->SetAxisRange(0, 1.1, "Y");
3055   h_eff_z0->SetAxisRange(0, 1.1, "Y");
3056   h_eff_z0_L->SetAxisRange(0, 1.1, "Y");
3057   h_eff_z0_H->SetAxisRange(0, 1.1, "Y");
3058   h_eff_d0->SetAxisRange(0, 1.1, "Y");
3059   h_eff_absd0->SetAxisRange(0, 1.1, "Y");
3060   h_eff_absd0_eta2->SetAxisRange(0, 1.1, "Y");
3061   h_eff_absd0_eta2_pt3->SetAxisRange(0, 1.1, "Y");
3062 
3063   gPad->SetGridx();
3064   gPad->SetGridy();
3065 
3066   // draw and save plots
3067   h_eff_pt->Draw();
3068   h_eff_pt->Write();
3069   c.SaveAs(DIR + type + "_eff_pt.pdf");
3070 
3071   if (type.Contains("Mu")) {
3072     h_eff_pt->GetYaxis()->SetRangeUser(0.8, 1.01);  // zoomed-in plot
3073     c.SaveAs(DIR + type + "_eff_pt_zoom.pdf");
3074   }
3075 
3076   h_eff_pt_L->Draw();
3077   h_eff_pt_L->Write();
3078   sprintf(ctxt, "p_{T} < 8 GeV");
3079   mySmallText(0.45, 0.5, 1, ctxt);
3080   c.SaveAs(DIR + type + "_eff_pt_L.pdf");
3081 
3082   if (doDetailedPlots) {
3083     h_eff_pt_LC->Draw();
3084     h_eff_pt_LC->Write();
3085     sprintf(ctxt, "p_{T} < 8 GeV, |#eta|<1.0");
3086     mySmallText(0.45, 0.5, 1, ctxt);
3087     c.SaveAs(DIR + type + "_eff_pt_LC.pdf");
3088   }
3089   h_eff_pt_H->Draw();
3090   h_eff_pt_H->Write();
3091   sprintf(ctxt, "p_{T} > 8 GeV");
3092   mySmallText(0.45, 0.5, 1, ctxt);
3093   c.SaveAs(DIR + type + "_eff_pt_H.pdf");
3094 
3095   h_eff_eta->Draw();
3096   h_eff_eta->Write();
3097   c.SaveAs(DIR + type + "_eff_eta.pdf");
3098 
3099   if (type.Contains("Mu")) {
3100     h_eff_eta->GetYaxis()->SetRangeUser(0.8, 1.01);  // zoomed-in plot
3101     c.SaveAs(DIR + type + "_eff_eta_zoom.pdf");
3102   }
3103 
3104   h_eff_eta_L->Draw();
3105   h_eff_eta_L->Write();
3106   sprintf(ctxt, "p_{T} < 8 GeV");
3107   mySmallText(0.45, 0.5, 1, ctxt);
3108   c.SaveAs(DIR + type + "_eff_eta_L.pdf");
3109 
3110   h_eff_eta_H->Draw();
3111   h_eff_eta_H->Write();
3112   sprintf(ctxt, "p_{T} > 8 GeV");
3113   mySmallText(0.45, 0.5, 1, ctxt);
3114   c.SaveAs(DIR + type + "_eff_eta_H.pdf");
3115 
3116   h_eff_eta_23->Write();
3117   h_eff_eta_35->Write();
3118   h_eff_eta_5->Write();
3119 
3120   if (doDetailedPlots) {
3121     h_eff_eta_23->Draw();
3122     sprintf(ctxt, "2 < p_{T} < 3 GeV");
3123     mySmallText(0.45, 0.5, 1, ctxt);
3124     c.SaveAs(DIR + type + "_eff_eta_23.pdf");
3125 
3126     h_eff_eta_35->Draw();
3127     sprintf(ctxt, "3 < p_{T} < 5 GeV");
3128     mySmallText(0.45, 0.5, 1, ctxt);
3129     c.SaveAs(DIR + type + "_eff_eta_35.pdf");
3130 
3131     h_eff_eta_5->Draw();
3132     sprintf(ctxt, "p_{T} > 5 GeV");
3133     mySmallText(0.45, 0.5, 1, ctxt);
3134     c.SaveAs(DIR + type + "_eff_eta_5.pdf");
3135 
3136     h_eff_z0->Draw();
3137     h_eff_z0->Write();
3138     c.SaveAs(DIR + type + "_eff_z0.pdf");
3139 
3140     h_eff_z0_L->Write();
3141     h_eff_z0_H->Write();
3142 
3143     h_eff_phi->Draw();
3144     h_eff_phi->Write();
3145     c.SaveAs(DIR + type + "_eff_phi.pdf");
3146 
3147     if (type.Contains("Mu")) {
3148       h_eff_phi->GetYaxis()->SetRangeUser(0.8, 1.01);  // zoomed-in plot
3149       c.SaveAs(DIR + type + "_eff_phi_zoom.pdf");
3150     }
3151   }
3152 
3153   if (doDetailedPlots || TP_maxD0 > 1.0) {
3154     h_eff_d0->Write();
3155     h_eff_absd0->Write();
3156     h_eff_absd0_eta2->Write();
3157     h_eff_absd0_eta2_pt3->Write();
3158 
3159     h_eff_d0->Draw();
3160     c.SaveAs(DIR + type + "_eff_d0.pdf");
3161 
3162     h_eff_absd0->Draw();
3163     c.SaveAs(DIR + type + "_eff_absd0.pdf");
3164 
3165     h_eff_absd0_eta2->Draw();
3166     c.SaveAs(DIR + type + "_eff_absd0_eta2.pdf");
3167 
3168     h_eff_absd0_eta2_pt3->Draw();
3169     c.SaveAs(DIR + type + "_eff_absd0_eta2_pt3.pdf");
3170   }
3171 
3172   gPad->SetGridx(0);
3173   gPad->SetGridy(0);
3174 
3175   // ----------------------------------------------------------------------------------------------------------------
3176   // more resolution plots
3177   // ----------------------------------------------------------------------------------------------------------------
3178 
3179   float rms = 0;
3180 
3181   if (doDetailedPlots) {
3182     // draw and save plots
3183     h_res_pt->Draw();
3184     rms = h_res_pt->GetRMS();
3185     sprintf(ctxt, "RMS = %.4f", rms);
3186     mySmallText(0.22, 0.82, 1, ctxt);
3187     c.SaveAs(DIR + type + "_res_pt.pdf");
3188 
3189     h_res_ptRel->Draw();
3190     rms = h_res_ptRel->GetRMS();
3191     sprintf(ctxt, "RMS = %.4f", rms);
3192     mySmallText(0.22, 0.82, 1, ctxt);
3193     c.SaveAs(DIR + type + "_res_ptRel.pdf");
3194 
3195     h_res_eta->Draw();
3196     rms = h_res_eta->GetRMS();
3197     sprintf(ctxt, "RMS = %.3e", rms);
3198     mySmallText(0.22, 0.82, 1, ctxt);
3199     c.SaveAs(DIR + type + "_res_eta.pdf");
3200 
3201     h_res_phi->Draw();
3202     rms = h_res_phi->GetRMS();
3203     sprintf(ctxt, "RMS = %.3e", rms);
3204     mySmallText(0.22, 0.82, 1, ctxt);
3205     c.SaveAs(DIR + type + "_res_phi.pdf");
3206 
3207     h_res_z0->Draw();
3208     rms = h_res_z0->GetRMS();
3209     sprintf(ctxt, "RMS = %.4f", rms);
3210     mySmallText(0.22, 0.82, 1, ctxt);
3211     c.SaveAs(DIR + type + "_res_z0.pdf");
3212 
3213     h_res_z0_C->Draw();
3214     rms = h_res_z0_C->GetRMS();
3215     sprintf(ctxt, "RMS = %.4f;", rms);
3216     mySmallText(0.22, 0.82, 1, ctxt);
3217     sprintf(ctxt, "|eta| < 0.8");
3218     mySmallText(0.22, 0.76, 1, ctxt);
3219     c.SaveAs(DIR + type + "_res_z0_C.pdf");
3220 
3221     h_res_z0_I->Draw();
3222     rms = h_res_z0_I->GetRMS();
3223     sprintf(ctxt, "RMS = %.4f;", rms);
3224     mySmallText(0.22, 0.82, 1, ctxt);
3225     sprintf(ctxt, "0.8 < |eta| < 1.6");
3226     mySmallText(0.22, 0.76, 1, ctxt);
3227     c.SaveAs(DIR + type + "_res_z0_I.pdf");
3228 
3229     h_res_z0_F->Draw();
3230     rms = h_res_z0_F->GetRMS();
3231     sprintf(ctxt, "RMS = %.4f;", rms);
3232     mySmallText(0.22, 0.82, 1, ctxt);
3233     sprintf(ctxt, "|eta| > 1.6");
3234     mySmallText(0.22, 0.76, 1, ctxt);
3235     c.SaveAs(DIR + type + "_res_z0_F.pdf");
3236 
3237     h_res_z0_C_L->Draw();
3238     h_res_z0_C_L->Write();
3239     rms = h_res_z0_C_L->GetRMS();
3240     sprintf(ctxt, "RMS = %.4f;", rms);
3241     mySmallText(0.22, 0.82, 1, ctxt);
3242     sprintf(ctxt, "|eta| < 0.8");
3243     mySmallText(0.22, 0.76, 1, ctxt);
3244     c.SaveAs(DIR + type + "_res_z0_C_L.pdf");
3245 
3246     h_res_z0_I_L->Draw();
3247     h_res_z0_I_L->Write();
3248     rms = h_res_z0_I_L->GetRMS();
3249     sprintf(ctxt, "RMS = %.4f;", rms);
3250     mySmallText(0.22, 0.82, 1, ctxt);
3251     sprintf(ctxt, "0.8 < |eta| < 1.6");
3252     mySmallText(0.22, 0.76, 1, ctxt);
3253     c.SaveAs(DIR + type + "_res_z0_I_L.pdf");
3254 
3255     h_res_z0_F_L->Draw();
3256     h_res_z0_F_L->Write();
3257     rms = h_res_z0_F_L->GetRMS();
3258     sprintf(ctxt, "RMS = %.4f;", rms);
3259     mySmallText(0.22, 0.82, 1, ctxt);
3260     sprintf(ctxt, "|eta| > 1.6");
3261     mySmallText(0.22, 0.76, 1, ctxt);
3262     c.SaveAs(DIR + type + "_res_z0_F_L.pdf");
3263 
3264     h_res_z0_C_H->Draw();
3265     h_res_z0_C_H->Write();
3266     rms = h_res_z0_C_H->GetRMS();
3267     sprintf(ctxt, "RMS = %.4f;", rms);
3268     mySmallText(0.22, 0.82, 1, ctxt);
3269     sprintf(ctxt, "|eta| < 0.8");
3270     mySmallText(0.22, 0.76, 1, ctxt);
3271     c.SaveAs(DIR + type + "_res_z0_C_H.pdf");
3272 
3273     h_res_z0_I_H->Draw();
3274     h_res_z0_I_H->Write();
3275     rms = h_res_z0_I_H->GetRMS();
3276     sprintf(ctxt, "RMS = %.4f;", rms);
3277     mySmallText(0.22, 0.82, 1, ctxt);
3278     sprintf(ctxt, "0.8 < |eta| < 1.6");
3279     mySmallText(0.22, 0.76, 1, ctxt);
3280     c.SaveAs(DIR + type + "_res_z0_I_H.pdf");
3281 
3282     h_res_z0_F_H->Draw();
3283     h_res_z0_F_H->Write();
3284     rms = h_res_z0_F_H->GetRMS();
3285     sprintf(ctxt, "RMS = %.4f;", rms);
3286     mySmallText(0.22, 0.82, 1, ctxt);
3287     sprintf(ctxt, "|eta| > 1.6");
3288     mySmallText(0.22, 0.76, 1, ctxt);
3289     c.SaveAs(DIR + type + "_res_z0_F_H.pdf");
3290 
3291     h_res_z0_L->Draw();
3292     h_res_z0_L->Write();
3293     rms = h_res_z0_L->GetRMS();
3294     sprintf(ctxt, "RMS = %.4f;", rms);
3295     mySmallText(0.22, 0.82, 1, ctxt);
3296     sprintf(ctxt, "p_{T} < 5 GeV");
3297     mySmallText(0.22, 0.76, 1, ctxt);
3298     c.SaveAs(DIR + type + "_res_z0_L.pdf");
3299 
3300     h_res_z0_H->Draw();
3301     h_res_z0_H->Write();
3302     rms = h_res_z0_H->GetRMS();
3303     sprintf(ctxt, "RMS = %.4f;", rms);
3304     mySmallText(0.22, 0.82, 1, ctxt);
3305     sprintf(ctxt, "p_{T} > 15 GeV");
3306     mySmallText(0.22, 0.76, 1, ctxt);
3307     c.SaveAs(DIR + type + "_res_z0_H.pdf");
3308 
3309     if (h_res_d0->GetEntries() > 0) {
3310       h_res_d0->Draw();
3311       rms = h_res_d0->GetRMS();
3312       sprintf(ctxt, "RMS = %.4f", rms);
3313       mySmallText(0.22, 0.82, 1, ctxt);
3314       c.SaveAs(DIR + type + "_res_d0.pdf");
3315 
3316       h_res_d0_C->Draw();
3317       h_res_d0_C->Write();
3318       rms = h_res_d0_C->GetRMS();
3319       sprintf(ctxt, "RMS = %.4f;", rms);
3320       mySmallText(0.22, 0.82, 1, ctxt);
3321       sprintf(ctxt, "|eta| < 0.8");
3322       mySmallText(0.22, 0.76, 1, ctxt);
3323       c.SaveAs(DIR + type + "_res_d0_C.pdf");
3324 
3325       h_res_d0_I->Draw();
3326       h_res_d0_I->Write();
3327       rms = h_res_d0_I->GetRMS();
3328       sprintf(ctxt, "RMS = %.4f;", rms);
3329       mySmallText(0.22, 0.82, 1, ctxt);
3330       sprintf(ctxt, "0.8 < |eta| < 1.6");
3331       mySmallText(0.22, 0.76, 1, ctxt);
3332       c.SaveAs(DIR + type + "_res_d0_I.pdf");
3333 
3334       h_res_d0_F->Draw();
3335       h_res_d0_F->Write();
3336       rms = h_res_d0_F->GetRMS();
3337       sprintf(ctxt, "RMS = %.4f;", rms);
3338       mySmallText(0.22, 0.82, 1, ctxt);
3339       sprintf(ctxt, "|eta| > 1.6");
3340       mySmallText(0.22, 0.76, 1, ctxt);
3341       c.SaveAs(DIR + type + "_res_d0_F.pdf");
3342 
3343       h_res_d0_C_L->Draw();
3344       h_res_d0_C_L->Write();
3345       rms = h_res_d0_C_L->GetRMS();
3346       sprintf(ctxt, "RMS = %.4f;", rms);
3347       mySmallText(0.22, 0.82, 1, ctxt);
3348       sprintf(ctxt, "|eta| < 0.8");
3349       mySmallText(0.22, 0.76, 1, ctxt);
3350       c.SaveAs(DIR + type + "_res_d0_C_L.pdf");
3351 
3352       h_res_d0_I_L->Draw();
3353       h_res_d0_I_L->Write();
3354       rms = h_res_d0_I_L->GetRMS();
3355       sprintf(ctxt, "RMS = %.4f;", rms);
3356       mySmallText(0.22, 0.82, 1, ctxt);
3357       sprintf(ctxt, "0.8 < |eta| < 1.6");
3358       mySmallText(0.22, 0.76, 1, ctxt);
3359       c.SaveAs(DIR + type + "_res_d0_I_L.pdf");
3360 
3361       h_res_d0_F_L->Draw();
3362       h_res_d0_F_L->Write();
3363       rms = h_res_d0_F_L->GetRMS();
3364       sprintf(ctxt, "RMS = %.4f;", rms);
3365       mySmallText(0.22, 0.82, 1, ctxt);
3366       sprintf(ctxt, "|eta| > 1.6");
3367       mySmallText(0.22, 0.76, 1, ctxt);
3368       c.SaveAs(DIR + type + "_res_d0_F_L.pdf");
3369 
3370       h_res_d0_C_H->Draw();
3371       h_res_d0_C_H->Write();
3372       rms = h_res_d0_C_H->GetRMS();
3373       sprintf(ctxt, "RMS = %.4f;", rms);
3374       mySmallText(0.22, 0.82, 1, ctxt);
3375       sprintf(ctxt, "|eta| < 0.8");
3376       mySmallText(0.22, 0.76, 1, ctxt);
3377       c.SaveAs(DIR + type + "_res_d0_C_H.pdf");
3378 
3379       h_res_d0_I_H->Draw();
3380       h_res_d0_I_H->Write();
3381       rms = h_res_d0_I_H->GetRMS();
3382       sprintf(ctxt, "RMS = %.4f;", rms);
3383       mySmallText(0.22, 0.82, 1, ctxt);
3384       sprintf(ctxt, "0.8 < |eta| < 1.6");
3385       mySmallText(0.22, 0.76, 1, ctxt);
3386       c.SaveAs(DIR + type + "_res_d0_I_H.pdf");
3387 
3388       h_res_d0_F_H->Draw();
3389       h_res_d0_F_H->Write();
3390       rms = h_res_d0_F_H->GetRMS();
3391       sprintf(ctxt, "RMS = %.4f;", rms);
3392       mySmallText(0.22, 0.82, 1, ctxt);
3393       sprintf(ctxt, "|eta| > 1.6");
3394       mySmallText(0.22, 0.76, 1, ctxt);
3395       c.SaveAs(DIR + type + "_res_d0_F_H.pdf");
3396 
3397       h_res_d0_L->Draw();
3398       h_res_d0_L->Write();
3399       rms = h_res_d0_L->GetRMS();
3400       sprintf(ctxt, "RMS = %.4f;", rms);
3401       mySmallText(0.22, 0.82, 1, ctxt);
3402       sprintf(ctxt, "p_{T} < 5 GeV");
3403       mySmallText(0.22, 0.76, 1, ctxt);
3404       c.SaveAs(DIR + type + "_res_d0_L.pdf");
3405 
3406       h_res_d0_H->Draw();
3407       h_res_d0_H->Write();
3408       rms = h_res_d0_H->GetRMS();
3409       sprintf(ctxt, "RMS = %.4f;", rms);
3410       mySmallText(0.22, 0.82, 1, ctxt);
3411       sprintf(ctxt, "p_{T} > 15 GeV");
3412       mySmallText(0.22, 0.76, 1, ctxt);
3413       c.SaveAs(DIR + type + "_res_d0_H.pdf");
3414     }
3415   }
3416 
3417   // ---------------------------------------------------------------------------------------------------------
3418   // "fake rates"
3419 
3420   h_trk_all_vspt->Sumw2();
3421   h_trk_loose_vspt->Sumw2();
3422   h_trk_genuine_vspt->Sumw2();
3423   h_trk_notloose_vspt->Sumw2();
3424   h_trk_notgenuine_vspt->Sumw2();
3425   h_trk_duplicate_vspt->Sumw2();
3426   h_tp_vspt->Sumw2();
3427 
3428   // fraction of not genuine tracks
3429   TH1F* h_notgenuine_pt = (TH1F*)h_trk_notgenuine_vspt->Clone();
3430   h_notgenuine_pt->SetName("notgenuine_pt");
3431   h_notgenuine_pt->GetYaxis()->SetTitle("Not genuine fraction");
3432   h_notgenuine_pt->Divide(h_trk_notgenuine_vspt, h_trk_all_vspt, 1.0, 1.0, "B");
3433 
3434   h_notgenuine_pt->Write();
3435   h_notgenuine_pt->Draw();
3436   c.SaveAs(DIR + type + "_notgenuine.pdf");
3437 
3438   // fraction of not loosely genuine tracks
3439   TH1F* h_notloose_pt = (TH1F*)h_trk_notloose_vspt->Clone();
3440   h_notloose_pt->SetName("notloose_pt");
3441   h_notloose_pt->GetYaxis()->SetTitle("Not loose fraction");
3442   h_notloose_pt->Divide(h_trk_notloose_vspt, h_trk_all_vspt, 1.0, 1.0, "B");
3443 
3444   h_notloose_pt->Write();
3445   h_notloose_pt->Draw();
3446   c.SaveAs(DIR + type + "_notloose.pdf");
3447 
3448   // fraction of DUPLICATE tracks (genuine and not matched)
3449   TH1F* h_duplicatefrac_pt = (TH1F*)h_trk_duplicate_vspt->Clone();
3450   h_duplicatefrac_pt->SetName("duplicatefrac_pt");
3451   h_duplicatefrac_pt->GetYaxis()->SetTitle("Duplicate fraction");
3452   h_duplicatefrac_pt->Divide(h_trk_duplicate_vspt, h_trk_all_vspt, 1.0, 1.0, "B");
3453 
3454   h_duplicatefrac_pt->Write();
3455   h_duplicatefrac_pt->Draw();
3456   c.SaveAs(DIR + type + "_duplicatefrac.pdf");
3457 
3458   // ---------------------------------------------------------------------------------------------------------
3459   // total track rates vs pt
3460 
3461   h_trk_all_vspt->Scale(1.0 / nevt);
3462   h_trk_loose_vspt->Scale(1.0 / nevt);
3463   h_trk_genuine_vspt->Scale(1.0 / nevt);
3464   h_trk_notloose_vspt->Scale(1.0 / nevt);
3465   h_trk_notgenuine_vspt->Scale(1.0 / nevt);
3466   h_trk_duplicate_vspt->Scale(1.0 / nevt);
3467   h_tp_vspt->Scale(1.0 / nevt);
3468 
3469   h_tp_vspt->GetYaxis()->SetTitle("Tracks / event");
3470   h_tp_vspt->GetXaxis()->SetTitle("Track p_{T} [GeV]");
3471   h_tp_vspt->SetLineColor(4);
3472   h_tp_vspt->SetLineStyle(2);
3473 
3474   h_trk_notgenuine_vspt->SetLineColor(2);
3475   h_trk_notgenuine_vspt->SetLineStyle(1);
3476 
3477   h_trk_duplicate_vspt->SetLineColor(8);
3478   h_trk_duplicate_vspt->SetLineStyle(2);
3479 
3480   float max = h_tp_vspt->GetMaximum();
3481   if (h_trk_all_vspt->GetMaximum() > max)
3482     max = h_trk_all_vspt->GetMaximum();
3483   h_tp_vspt->SetAxisRange(0.001, max * 1.5, "Y");
3484 
3485   h_tp_vspt->Draw("hist");
3486   h_trk_all_vspt->Draw("same,hist");
3487   h_tp_vspt->Draw("same,hist");
3488   h_trk_notgenuine_vspt->Draw("same,hist");
3489   //h_trk_duplicate_vspt->Draw("same,hist");
3490 
3491   h_trk_all_vspt->Write();
3492   h_trk_loose_vspt->Write();
3493   h_trk_genuine_vspt->Write();
3494   h_trk_notloose_vspt->Write();
3495   h_trk_notgenuine_vspt->Write();
3496   h_trk_duplicate_vspt->Write();
3497   h_tp_vspt->Write();
3498 
3499   char txt[500];
3500   sprintf(txt, "# tracks/event = %.1f", h_trk_all_vspt->GetSum());
3501   mySmallText(0.5, 0.85, 1, txt);
3502   char txt3[500];
3503   sprintf(txt3, "# TPs(stubs in #geq 4 layers)/");
3504   char txt2[500];
3505   sprintf(txt2, "event = %.1f", h_tp_vspt->GetSum());
3506   mySmallText(0.5, 0.79, 4, txt3);
3507   mySmallText(0.5, 0.74, 4, txt2);
3508 
3509   sprintf(txt, "# !genuine tracks/event = %.1f", h_trk_notgenuine_vspt->GetSum());
3510   mySmallText(0.5, 0.69, 2, txt);
3511   //sprintf(txt,"# duplicates/event = %.1f",h_trk_duplicate_vspt->GetSum());
3512   //mySmallText(0.5,0.64,8,txt);
3513 
3514   c.SaveAs(DIR + type + "_trackrate_vspt.pdf");
3515 
3516   gPad->SetLogy();
3517   c.SaveAs(DIR + type + "_trackrate_vspt_log.pdf");
3518   gPad->SetLogy(0);
3519 
3520   // ---------------------------------------------------------------------------------------------------------
3521   // sum track/ TP pt in jets
3522   /*
3523   if (TP_select_injet > 0) {
3524 
3525     TH1F* h_frac_sumpt_vspt = (TH1F*) h_jet_trk_sumpt_vspt->Clone();
3526     h_frac_sumpt_vspt->SetName("frac_sumpt_vspt");
3527     h_frac_sumpt_vspt->GetYaxis()->SetTitle("L1 sum(p_{T}) / TP sum(p_{T})");
3528     h_frac_sumpt_vspt->Divide(h_jet_trk_sumpt_vspt, h_jet_tp_sumpt_vspt, 1.0, 1.0, "B");
3529 
3530     TH1F* h_frac_sumpt_vseta = (TH1F*) h_jet_trk_sumpt_vseta->Clone();
3531     h_frac_sumpt_vseta->SetName("frac_sumpt_vseta");
3532     h_frac_sumpt_vseta->GetYaxis()->SetTitle("L1 sum(p_{T}) / TP sum(p_{T})");
3533     h_frac_sumpt_vseta->Divide(h_jet_trk_sumpt_vseta, h_jet_tp_sumpt_vseta, 1.0, 1.0, "B");
3534 
3535 
3536     TH1F* h_matchfrac_sumpt_vspt = (TH1F*) h_jet_matchtrk_sumpt_vspt->Clone();
3537     h_matchfrac_sumpt_vspt->SetName("matchfrac_sumpt_vspt");
3538     h_matchfrac_sumpt_vspt->GetYaxis()->SetTitle("Matched L1 sum(p_{T}) / TP sum(p_{T})");
3539     h_matchfrac_sumpt_vspt->Divide(h_jet_matchtrk_sumpt_vspt, h_jet_tp_sumpt_vspt, 1.0, 1.0, "B");
3540 
3541     TH1F* h_matchfrac_sumpt_vseta = (TH1F*) h_jet_matchtrk_sumpt_vseta->Clone();
3542     h_matchfrac_sumpt_vseta->SetName("matchfrac_sumpt_vseta");
3543     h_matchfrac_sumpt_vseta->GetYaxis()->SetTitle("Matched L1 sum(p_{T}) / TP sum(p_{T})");
3544     h_matchfrac_sumpt_vseta->Divide(h_jet_matchtrk_sumpt_vseta, h_jet_tp_sumpt_vseta, 1.0, 1.0, "B");
3545 
3546 
3547     h_frac_sumpt_vspt->Draw();
3548     c.SaveAs(DIR+type+"_sumpt_vspt.pdf");
3549 
3550     h_frac_sumpt_vseta->Draw();
3551     c.SaveAs(DIR+type+"_sumpt_vseta.pdf");
3552 
3553     h_matchfrac_sumpt_vspt->Draw();
3554     c.SaveAs(DIR+type+"_sumpt_match_vspt.pdf");
3555 
3556     h_matchfrac_sumpt_vseta->Draw();
3557     c.SaveAs(DIR+type+"_sumpt_match_vseta.pdf");
3558   }
3559   */
3560 
3561   // nbr tracks per event
3562 
3563   h_ntrk_pt2->Write();
3564   h_ntrk_pt3->Write();
3565   h_ntrk_pt10->Write();
3566 
3567   h_ntrkPerSector_all->Write();
3568   h_ntrkPerSector_pt2->Write();
3569   h_ntrkPerSector_pt3->Write();
3570   h_ntrkPerSector_pt4->Write();
3571 
3572   h_ntrkPerSector_all->Scale(1.0 / nevt);
3573   h_ntrkPerSector_pt2->Scale(1.0 / nevt);
3574   h_ntrkPerSector_pt3->Scale(1.0 / nevt);
3575   h_ntrkPerSector_pt4->Scale(1.0 / nevt);
3576 
3577   h_ntrkPerSector_all->GetYaxis()->SetTitle("Fraction of events");
3578   h_ntrkPerSector_all->GetXaxis()->SetTitle("Max number of transmitted tracks per #phi sector");
3579 
3580   h_ntrkPerSector_all->SetLineColor(1);
3581   h_ntrkPerSector_pt2->SetLineColor(4);
3582   h_ntrkPerSector_pt3->SetLineColor(2);
3583   h_ntrkPerSector_pt4->SetLineColor(8);
3584 
3585   max = h_ntrkPerSector_all->GetMaximum();
3586   h_ntrkPerSector_all->SetAxisRange(0.00001, max * 5, "Y");
3587   h_ntrkPerSector_all->SetAxisRange(0., 100, "X");
3588 
3589   h_ntrkPerSector_all->Draw("hist");
3590   h_ntrkPerSector_pt2->Draw("same,hist");
3591   h_ntrkPerSector_pt3->Draw("same,hist");
3592   h_ntrkPerSector_pt4->Draw("same,hist");
3593   gPad->SetLogy();
3594 
3595   TLegend* l = new TLegend(0.6, 0.55, 0.85, 0.85);
3596   l->SetFillStyle(0);
3597   l->SetBorderSize(0);
3598   l->SetTextSize(0.04);
3599   l->AddEntry(h_ntrkPerSector_all, "no p_{T}cut", "l");
3600   l->AddEntry(h_ntrkPerSector_pt2, "p_{T}^{track} > 2 GeV", "l");
3601   l->AddEntry(h_ntrkPerSector_pt3, "p_{T}^{track} > 3 GeV", "l");
3602   l->AddEntry(h_ntrkPerSector_pt4, "p_{T}^{track} > 4 GeV", "l");
3603   l->SetTextFont(42);
3604   l->Draw();
3605 
3606   c.SaveAs(DIR + type + "_trackRatePerPhiSector_log.pdf");
3607   gPad->SetLogy(0);
3608 
3609   h_ntrk_genuine_pt2->Write();
3610   h_ntrk_genuine_pt3->Write();
3611   h_ntrk_genuine_pt10->Write();
3612 
3613   if (doDetailedPlots) {
3614     h_ntrk_pt2->Draw();
3615     c.SaveAs(DIR + type + "_trackrate_pt2_perevt.pdf");
3616 
3617     h_ntrk_pt3->Draw();
3618     c.SaveAs(DIR + type + "_trackrate_pt3_perevt.pdf");
3619 
3620     h_ntrk_pt10->Draw();
3621     c.SaveAs(DIR + type + "_trackrate_pt10_perevt.pdf");
3622   }
3623 
3624   // number of tracks vs. eta, pT (trk_eta/trk_pt)
3625 
3626   if (doDetailedPlots) {
3627     h_trk_eta->Write();
3628     h_trk_pt->Write();
3629 
3630     h_trk_eta->Draw();
3631     c.SaveAs(DIR + type + "_trk_eta.pdf");
3632     h_trk_pt->Draw();
3633     c.SaveAs(DIR + type + "_trk_pt.pdf");
3634   }
3635 
3636   fout->Close();
3637 
3638   // ---------------------------------------------------------------------------------------------------------
3639   //some printouts
3640 
3641   float k = (float)n_match_eta1p0;
3642   float N = (float)n_all_eta1p0;
3643   if (std::abs(N) > 0)
3644     cout << endl
3645          << "efficiency for |eta| < 1.0 = " << k / N * 100.0 << " +- " << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0
3646          << endl;
3647   k = (float)n_match_eta1p75;
3648   N = (float)n_all_eta1p75;
3649   if (std::abs(N) > 0)
3650     cout << "efficiency for 1.0 < |eta| < 1.75 = " << k / N * 100.0 << " +- "
3651          << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << endl;
3652   k = (float)n_match_eta2p5;
3653   N = (float)n_all_eta2p5;
3654   if (std::abs(N) > 0)
3655     cout << "efficiency for 1.75 < |eta| < " << std::min(TP_maxEta, 2.5f) << " = " << k / N * 100.0 << " +- "
3656          << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << endl;
3657   N = (float)n_all_eta1p0 + n_all_eta1p75 + n_all_eta2p5;
3658   k = (float)n_match_eta1p0 + n_match_eta1p75 + n_match_eta2p5;
3659   if (std::abs(N) > 0)
3660     cout << "combined efficiency for |eta| < " << std::min(TP_maxEta, 2.5f) << " = " << k / N * 100.0 << " +- "
3661          << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << " = " << k << "/" << N << endl
3662          << endl;
3663 
3664   k = (float)n_match_ptg2;
3665   N = (float)n_all_ptg2;
3666   if (std::abs(N) > 0)
3667     cout << "efficiency for pt > " << std::max(TP_minPt, 2.0f) << " = " << k / N * 100.0 << " +- "
3668          << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << endl;
3669   k = (float)n_match_pt2to8;
3670   N = (float)n_all_pt2to8;
3671   if (std::abs(N) > 0)
3672     cout << "efficiency for " << std::max(TP_minPt, 2.0f) << " < pt < 8.0 = " << k / N * 100.0 << " +- "
3673          << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << endl;
3674   k = (float)n_match_ptg8;
3675   N = (float)n_all_ptg8;
3676   if (std::abs(N) > 0)
3677     cout << "efficiency for pt > 8.0 = " << k / N * 100.0 << " +- " << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0
3678          << endl;
3679   k = (float)n_match_ptg40;
3680   N = (float)n_all_ptg40;
3681   if (std::abs(N) > 0)
3682     cout << "efficiency for pt > 40.0 = " << k / N * 100.0 << " +- " << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0
3683          << endl
3684          << endl;
3685 
3686   // track rates
3687   cout << "# TP/event (pt > " << std::max(TP_minPt, 2.0f) << ") = " << (float)ntp_pt2 / nevt << endl;
3688   cout << "# TP/event (pt > 3.0) = " << (float)ntp_pt3 / nevt << endl;
3689   cout << "# TP/event (pt > 10.0) = " << (float)ntp_pt10 / nevt << endl;
3690 
3691   cout << "# tracks/event (no pt cut)= " << (float)ntrk / nevt << endl;
3692   cout << "# tracks/event (pt > " << std::max(TP_minPt, 2.0f) << ") = " << (float)ntrk_pt2 / nevt << endl;
3693   cout << "# tracks/event (pt > 3.0) = " << (float)ntrk_pt3 / nevt << endl;
3694   cout << "# tracks/event (pt > 10.0) = " << (float)ntrk_pt10 / nevt << endl;
3695 }
3696 
3697 void SetPlotStyle() {
3698   // from ATLAS plot style macro
3699 
3700   // use plain black on white colors
3701   gStyle->SetFrameBorderMode(0);
3702   gStyle->SetFrameFillColor(0);
3703   gStyle->SetCanvasBorderMode(0);
3704   gStyle->SetCanvasColor(0);
3705   gStyle->SetPadBorderMode(0);
3706   gStyle->SetPadColor(0);
3707   gStyle->SetStatColor(0);
3708   gStyle->SetHistLineColor(1);
3709 
3710   gStyle->SetPalette(1);
3711 
3712   // set the paper & margin sizes
3713   gStyle->SetPaperSize(20, 26);
3714   gStyle->SetPadTopMargin(0.05);
3715   gStyle->SetPadRightMargin(0.05);
3716   gStyle->SetPadBottomMargin(0.16);
3717   gStyle->SetPadLeftMargin(0.16);
3718 
3719   // set title offsets (for axis label)
3720   gStyle->SetTitleXOffset(1.4);
3721   gStyle->SetTitleYOffset(1.4);
3722 
3723   // use large fonts
3724   gStyle->SetTextFont(42);
3725   gStyle->SetTextSize(0.05);
3726   gStyle->SetLabelFont(42, "x");
3727   gStyle->SetTitleFont(42, "x");
3728   gStyle->SetLabelFont(42, "y");
3729   gStyle->SetTitleFont(42, "y");
3730   gStyle->SetLabelFont(42, "z");
3731   gStyle->SetTitleFont(42, "z");
3732   gStyle->SetLabelSize(0.05, "x");
3733   gStyle->SetTitleSize(0.05, "x");
3734   gStyle->SetLabelSize(0.05, "y");
3735   gStyle->SetTitleSize(0.05, "y");
3736   gStyle->SetLabelSize(0.05, "z");
3737   gStyle->SetTitleSize(0.05, "z");
3738 
3739   // use bold lines and markers
3740   gStyle->SetMarkerStyle(20);
3741   gStyle->SetMarkerSize(1.2);
3742   gStyle->SetHistLineWidth(2.);
3743   gStyle->SetLineStyleString(2, "[12 12]");
3744 
3745   // get rid of error bar caps
3746   gStyle->SetEndErrorSize(0.);
3747 
3748   // do not display any of the standard histogram decorations
3749   gStyle->SetOptTitle(0);
3750   gStyle->SetOptStat(0);
3751   gStyle->SetOptFit(0);
3752 
3753   // put tick marks on top and RHS of plots
3754   gStyle->SetPadTickX(1);
3755   gStyle->SetPadTickY(1);
3756 }
3757 
3758 void mySmallText(Double_t x, Double_t y, Color_t color, char* text) {
3759   Double_t tsize = 0.044;
3760   TLatex l;
3761   l.SetTextSize(tsize);
3762   l.SetNDC();
3763   l.SetTextColor(color);
3764   l.DrawLatex(x, y, text);
3765 }
3766 
3767 double getIntervalContainingFractionOfEntries(TH1* absResidualHistogram, double quantileToCalculate, int minEntries) {
3768   double totalIntegral = absResidualHistogram->Integral(0, absResidualHistogram->GetNbinsX() + 1);
3769   double numEntries = absResidualHistogram->GetEntries();
3770 
3771   // Check that the interval is not somewhere in the overflow bin
3772   double maxAllowedEntriesInOverflow = totalIntegral * (1 - quantileToCalculate);
3773   double nEntriesInOverflow = absResidualHistogram->GetBinContent(absResidualHistogram->GetNbinsX() + 1);
3774   if (nEntriesInOverflow > maxAllowedEntriesInOverflow) {
3775     // cout << "WARNING : Cannot compute range corresponding to interval, as it is in the overflow bin" << endl;
3776     return absResidualHistogram->GetXaxis()->GetXmax() * 1.2;
3777   }
3778 
3779   // Calculate quantile for given interval
3780   double interval[1];
3781   double quantile[1] = {quantileToCalculate};
3782   if (totalIntegral > 0 && numEntries >= minEntries) {
3783     absResidualHistogram->GetQuantiles(1, interval, quantile);
3784   } else {
3785     cout << "WARNING: histo " << absResidualHistogram->GetName()
3786          << " empty or with too few entries, so can't calc quantiles." << endl;
3787     interval[0] = 0.;
3788   }
3789 
3790   return interval[0];
3791 }
3792 
3793 void makeResidualIntervalPlot(
3794     TString type, TString dir, TString variable, TH1F* h_68, TH1F* h_90, TH1F* h_99, double minY, double maxY) {
3795   TCanvas c;
3796 
3797   h_68->SetMinimum(minY);
3798   h_90->SetMinimum(minY);
3799   h_99->SetMinimum(minY);
3800 
3801   h_68->SetMaximum(maxY);
3802   h_90->SetMaximum(maxY);
3803   h_99->SetMaximum(maxY);
3804 
3805   h_68->SetMarkerStyle(20);
3806   h_90->SetMarkerStyle(26);
3807   h_99->SetMarkerStyle(24);
3808 
3809   h_68->Draw("P");
3810   h_68->Write();
3811   h_90->Draw("P same");
3812   h_90->Write();
3813   h_99->Draw("P same");
3814   h_99->Write();
3815 
3816   TLegend* l = new TLegend(0.65, 0.65, 0.85, 0.85);
3817   l->SetFillStyle(0);
3818   l->SetBorderSize(0);
3819   l->SetTextSize(0.04);
3820   l->AddEntry(h_99, "99%", "p");
3821   l->AddEntry(h_90, "90%", "p");
3822   l->AddEntry(h_68, "68%", "p");
3823   l->SetTextFont(42);
3824   l->Draw();
3825 
3826   c.SaveAs(dir + type + "_" + variable + "_interval.pdf");
3827 
3828   delete l;
3829 }