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  constexpr double max_eta_phase0 = 2.5;
24  constexpr double max_eta_phase1 = 2.7;
25  constexpr double max_eta_phase2 = 4.0;
26 
27  // helper logarithmic bin generator
28 
29  template <typename T, size_t N>
30  std::array<T, N + 1> makeLogBins(const T& min, const T& max) {
31  const T minLog10 = std::log10(min);
32  const T maxLog10 = std::log10(max);
33  const T width = (maxLog10 - minLog10) / N;
34  std::array<T, N + 1> ret;
35  ret[0] = std::pow(10, minLog10);
36  const T mult = std::pow(10, width);
37  for (size_t i = 1; i <= N; ++i) {
38  ret[i] = ret[i - 1] * mult;
39  }
40  return ret;
41  }
42 
43  // helper data formats
44 
45  enum estimator { MEAN = 1, WIDTH = 2, MEDIAN = 3, MAD = 4, UNKWN = -1 };
46 
47  enum residualType {
48  dxy = 1,
49  dx = 2,
50  dy = 3,
51  dz = 4,
52  IP2D = 5,
53  resz = 6,
54  IP3D = 7,
55  d3D = 8,
56 
57  norm_dxy = 9,
58  norm_dx = 10,
59  norm_dy = 11,
60  norm_dz = 12,
61  norm_IP2D = 13,
62  norm_resz = 14,
63  norm_IP3D = 15,
64  norm_d3D = 16,
66  };
67 
68  enum plotVariable {
69  phi = 1,
70  eta = 2,
71  pT = 3,
72  pTCentral = 4,
73  ladder = 5,
74  modZ = 6,
76  };
77 
79  phase0 = 0,
80  phase1 = 1,
81  phase2 = 2,
83  };
84 
85  struct histodetails {
86  int histobins;
87  std::map<std::pair<residualType, plotVariable>, std::pair<float, float>> range;
88  std::map<plotVariable, std::vector<float>> trendbins;
89 
90  void setMap(residualType type, plotVariable plot, float low, float high) {
91  assert(low < high);
92  range[std::make_pair(type, plot)] = std::make_pair(low, high);
93  }
94 
95  std::pair<float, float> getRange(residualType type, plotVariable plot) {
96  if (range.find(std::make_pair(type, plot)) != range.end()) {
97  return range[std::make_pair(type, plot)];
98  } else {
99  COUT << "Trying to get range for non-existent combination " << std::endl;
100  return std::make_pair(0., 0.);
101  }
102  }
103 
105  if (range.find(std::make_pair(type, plot)) != range.end()) {
106  return range[std::make_pair(type, plot)].first;
107  } else {
108  COUT << "Trying to get low end of range for non-existent combination " << std::endl;
109  return 0.;
110  }
111  }
112 
114  if (range.find(std::make_pair(type, plot)) != range.end()) {
115  return range[std::make_pair(type, plot)].second;
116  } else {
117  COUT << "Trying get high end of range for non-existent combination " << std::endl;
118  return 0.;
119  }
120  }
121  };
122 
123  typedef std::tuple<std::string, std::string, std::string> plotLabels;
124 
125  // helper methods
126 
127  void add(std::map<std::string, TH1*>& h, TH1* hist);
128 
129  void fill(std::map<std::string, TH1*>& h, const std::string& s, double x);
130 
131  void fill(std::map<std::string, TH1*>& h, const std::string& s, double x, double y);
132 
133  void fillByIndex(std::vector<TH1F*>& h, unsigned int index, double x, std::string tag = "");
134 
135  void shrinkHistVectorToFit(std::vector<TH1F*>& h, unsigned int desired_size);
136 
138 
140 
141  std::vector<float> generateBins(int n, float start, float range);
142 
144 
145  Measurement1D getMAD(TH1F* histo);
146 
147  std::pair<Measurement1D, Measurement1D> fitResiduals(TH1* hist);
148 
149 }; // namespace PVValHelper
150 
151 #endif
Definition: start.py:1
Measurement1D getMedian(TH1F *histo)
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
assert(be >=bs)
constexpr double max_eta_phase2
Measurement1D getMAD(TH1F *histo)
plotLabels getVarString(plotVariable var)
std::map< plotVariable, std::vector< float > > trendbins
constexpr double max_eta_phase1
float getHigh(residualType type, plotVariable plot)
float getLow(residualType type, plotVariable plot)
void fill(std::map< std::string, TH1 *> &h, const std::string &s, double x)
#define COUT
void setMap(residualType type, plotVariable plot, float low, float high)
void shrinkHistVectorToFit(std::vector< TH1F *> &h, unsigned int desired_size)
plotLabels getTypeString(residualType type)
#define N
Definition: blowfish.cc:9
std::array< T, N+1 > makeLogBins(const T &min, const T &max)
constexpr double max_eta_phase0
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
std::pair< float, float > getRange(residualType type, plotVariable plot)
std::tuple< std::string, std::string, std::string > plotLabels
void fillByIndex(std::vector< TH1F *> &h, unsigned int index, double x, std::string tag="")
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
long double T
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29