Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef ALIGNMENT_OFFLINEVALIDATION_PVVALIDATIONHELPER_H
0002 #define ALIGNMENT_OFFLINEVALIDATION_PVVALIDATIONHELPER_H
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <map>
0007 #include <cassert>
0008 #include <utility>
0009 #include "TH1.h"
0010 
0011 #ifndef PLOTTING_MACRO
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #define COUT edm::LogWarning("PVValidationHelpers")
0014 #else
0015 #include <iostream>
0016 #define COUT std::cout << "PVValidationHelpers: "
0017 #endif
0018 
0019 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
0020 
0021 namespace PVValHelper {
0022 
0023   constexpr double max_eta_phase0 = 2.5;
0024   constexpr double max_eta_phase1 = 2.7;
0025   constexpr double max_eta_phase2 = 4.0;
0026 
0027   // helper logarithmic bin generator
0028 
0029   template <typename T, size_t N>
0030   std::array<T, N + 1> makeLogBins(const T& min, const T& max) {
0031     const T minLog10 = std::log10(min);
0032     const T maxLog10 = std::log10(max);
0033     const T width = (maxLog10 - minLog10) / N;
0034     std::array<T, N + 1> ret;
0035     ret[0] = std::pow(10, minLog10);
0036     const T mult = std::pow(10, width);
0037     for (size_t i = 1; i <= N; ++i) {
0038       ret[i] = ret[i - 1] * mult;
0039     }
0040     return ret;
0041   }
0042 
0043   // helper data formats
0044 
0045   enum estimator { MEAN = 1, WIDTH = 2, MEDIAN = 3, MAD = 4, UNKWN = -1 };
0046 
0047   enum residualType {
0048     dxy = 1,
0049     dx = 2,
0050     dy = 3,
0051     dz = 4,
0052     IP2D = 5,
0053     resz = 6,
0054     IP3D = 7,
0055     d3D = 8,
0056 
0057     norm_dxy = 9,
0058     norm_dx = 10,
0059     norm_dy = 11,
0060     norm_dz = 12,
0061     norm_IP2D = 13,
0062     norm_resz = 14,
0063     norm_IP3D = 15,
0064     norm_d3D = 16,
0065     END_OF_TYPES = 17,
0066   };
0067 
0068   enum plotVariable {
0069     phi = 1,
0070     eta = 2,
0071     pT = 3,
0072     pTCentral = 4,
0073     ladder = 5,
0074     modZ = 6,
0075     END_OF_PLOTS = 7,
0076   };
0077 
0078   enum detectorPhase {
0079     phase0 = 0,
0080     phase1 = 1,
0081     phase2 = 2,
0082     END_OF_PHASES = 3,
0083   };
0084 
0085   struct histodetails {
0086     int histobins;
0087     std::map<std::pair<residualType, plotVariable>, std::pair<float, float>> range;
0088     std::map<plotVariable, std::vector<float>> trendbins;
0089 
0090     void setMap(residualType type, plotVariable plot, float low, float high) {
0091       assert(low < high);
0092       range[std::make_pair(type, plot)] = std::make_pair(low, high);
0093     }
0094 
0095     std::pair<float, float> getRange(residualType type, plotVariable plot) {
0096       if (range.find(std::make_pair(type, plot)) != range.end()) {
0097         return range[std::make_pair(type, plot)];
0098       } else {
0099         COUT << "Trying to get range for non-existent combination " << std::endl;
0100         return std::make_pair(0., 0.);
0101       }
0102     }
0103 
0104     float getLow(residualType type, plotVariable plot) {
0105       if (range.find(std::make_pair(type, plot)) != range.end()) {
0106         return range[std::make_pair(type, plot)].first;
0107       } else {
0108         COUT << "Trying to get low end of range for non-existent combination " << std::endl;
0109         return 0.;
0110       }
0111     }
0112 
0113     float getHigh(residualType type, plotVariable plot) {
0114       if (range.find(std::make_pair(type, plot)) != range.end()) {
0115         return range[std::make_pair(type, plot)].second;
0116       } else {
0117         COUT << "Trying get high end of range for non-existent combination " << std::endl;
0118         return 0.;
0119       }
0120     }
0121   };
0122 
0123   typedef std::tuple<std::string, std::string, std::string> plotLabels;
0124 
0125   // helper methods
0126 
0127   void add(std::map<std::string, TH1*>& h, TH1* hist);
0128 
0129   void fill(std::map<std::string, TH1*>& h, const std::string& s, double x);
0130 
0131   void fill(std::map<std::string, TH1*>& h, const std::string& s, double x, double y);
0132 
0133   void fillByIndex(std::vector<TH1F*>& h, unsigned int index, double x, std::string tag = "");
0134 
0135   void shrinkHistVectorToFit(std::vector<TH1F*>& h, unsigned int desired_size);
0136 
0137   plotLabels getTypeString(residualType type);
0138 
0139   plotLabels getVarString(plotVariable var);
0140 
0141   std::vector<float> generateBins(int n, float start, float range);
0142 
0143   Measurement1D getMedian(TH1F* histo);
0144 
0145   Measurement1D getMAD(TH1F* histo);
0146 
0147   std::pair<Measurement1D, Measurement1D> fitResiduals(TH1* hist);
0148 
0149 };  // namespace PVValHelper
0150 
0151 #endif