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