CMS 3D CMS Logo

PVValidationHelpers.h
Go to the documentation of this file.
1 #ifndef ALIGNMENT_OFFLINEVALIDATION_PVVALIDATIONHELPER_H
2 #define ALIGNMENT_OFFLINEVALIDATION_PVVALIDATIONHELPER_H
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include <cassert>
8 #include <utility>
9 #include "TH1.h"
10 
11 #ifndef PLOTTING_MACRO
13 #define COUT edm::LogWarning("PVValidationHelpers")
14 #else
15 #include <iostream>
16 #define COUT std::cout << "PVValidationHelpers: "
17 #endif
18 
20 
21 namespace PVValHelper {
22 
23  const double max_eta_phase0 = 2.5;
24  const double max_eta_phase1 = 2.7;
25 
26  // helper logarithmic bin generator
27 
28  template <typename T, size_t N>
29  std::array<T, N + 1> makeLogBins(const T& min, const T& max) {
30  const T minLog10 = std::log10(min);
31  const T maxLog10 = std::log10(max);
32  const T width = (maxLog10 - minLog10) / N;
33  std::array<T, N + 1> ret;
34  ret[0] = std::pow(10, minLog10);
35  const T mult = std::pow(10, width);
36  for (size_t i = 1; i <= N; ++i) {
37  ret[i] = ret[i - 1] * mult;
38  }
39  return ret;
40  }
41 
42  // helper data formats
43 
44  enum estimator { MEAN = 1, WIDTH = 2, MEDIAN = 3, MAD = 4, UNKWN = -1 };
45 
46  enum residualType {
47  dxy = 1,
48  dx = 2,
49  dy = 3,
50  dz = 4,
51  IP2D = 5,
52  resz = 6,
53  IP3D = 7,
54  d3D = 8,
55 
56  norm_dxy = 9,
57  norm_dx = 10,
58  norm_dy = 11,
59  norm_dz = 12,
60  norm_IP2D = 13,
61  norm_resz = 14,
62  norm_IP3D = 15,
63  norm_d3D = 16,
65  };
66 
67  enum plotVariable {
68  phi = 1,
69  eta = 2,
70  pT = 3,
71  pTCentral = 4,
72  ladder = 5,
73  modZ = 6,
75  };
76 
77  struct histodetails {
78  int histobins;
79  std::map<std::pair<residualType, plotVariable>, std::pair<float, float>> range;
80  std::map<plotVariable, std::vector<float>> trendbins;
81 
82  void setMap(residualType type, plotVariable plot, float low, float high) {
83  assert(low < high);
84  range[std::make_pair(type, plot)] = std::make_pair(low, high);
85  }
86 
87  std::pair<float, float> getRange(residualType type, plotVariable plot) {
88  if (range.find(std::make_pair(type, plot)) != range.end()) {
89  return range[std::make_pair(type, plot)];
90  } else {
91  COUT << "Trying to get range for non-existent combination " << std::endl;
92  return std::make_pair(0., 0.);
93  }
94  }
95 
97  if (range.find(std::make_pair(type, plot)) != range.end()) {
98  return range[std::make_pair(type, plot)].first;
99  } else {
100  COUT << "Trying to get low end of range for non-existent combination " << std::endl;
101  return 0.;
102  }
103  }
104 
106  if (range.find(std::make_pair(type, plot)) != range.end()) {
107  return range[std::make_pair(type, plot)].second;
108  } else {
109  COUT << "Trying get high end of range for non-existent combination " << std::endl;
110  return 0.;
111  }
112  }
113  };
114 
115  typedef std::tuple<std::string, std::string, std::string> plotLabels;
116 
117  // helper methods
118 
119  void add(std::map<std::string, TH1*>& h, TH1* hist);
120 
121  void fill(std::map<std::string, TH1*>& h, const std::string& s, double x);
122 
123  void fill(std::map<std::string, TH1*>& h, const std::string& s, double x, double y);
124 
125  void fillByIndex(std::vector<TH1F*>& h, unsigned int index, double x, std::string tag = "");
126 
127  void shrinkHistVectorToFit(std::vector<TH1F*>& h, unsigned int desired_size);
128 
129  plotLabels getTypeString(residualType type);
130 
131  plotLabels getVarString(plotVariable var);
132 
133  std::vector<float> generateBins(int n, float start, float range);
134 
136 
137  Measurement1D getMAD(TH1F* histo);
138 
139  std::pair<Measurement1D, Measurement1D> fitResiduals(TH1* hist);
140 
141 }; // namespace PVValHelper
142 
143 #endif
Definition: start.py:1
type
Definition: HCALResponse.h:21
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Measurement1D getMedian(TH1F *histo)
void fillByIndex(std::vector< TH1F * > &h, unsigned int index, double x, std::string tag="")
std::pair< Measurement1D, Measurement1D > fitResiduals(TH1 *hist)
ret
prodAgent to be discontinued
std::vector< float > generateBins(int n, float start, float range)
std::map< std::pair< residualType, plotVariable >, std::pair< float, float > > range
Measurement1D getMAD(TH1F *histo)
plotLabels getVarString(plotVariable var)
std::map< plotVariable, std::vector< float > > trendbins
float getHigh(residualType type, plotVariable plot)
float getLow(residualType type, plotVariable plot)
T min(T a, T b)
Definition: MathUtil.h:58
#define COUT
void setMap(residualType type, plotVariable plot, float low, float high)
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
plotLabels getTypeString(residualType type)
#define N
Definition: blowfish.cc:9
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
void shrinkHistVectorToFit(std::vector< TH1F * > &h, unsigned int desired_size)
std::array< T, N+1 > makeLogBins(const T &min, const T &max)
std::pair< float, float > getRange(residualType type, plotVariable plot)
std::tuple< std::string, std::string, std::string > plotLabels
const double max_eta_phase0
long double T
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
const double max_eta_phase1