CMS 3D CMS Logo

MillePedeMonitor.h
Go to the documentation of this file.
1 #ifndef MILLEPEDEMONITOR_H
2 #define MILLEPEDEMONITOR_H
3 
13 
15 
17 
19 
21 
22 #include <vector>
23 #include <array>
24 
25 #include <TString.h>
26 #include <TH1.h>
27 #include <TH2.h>
28 
29 class TH1;
30 class TH2;
31 class TDirectory;
32 class Trajectory;
33 
34 class TrackerTopology;
35 
36 namespace reco {
37  class Track;
38 }
39 
40 class Alignable;
43 
44 /***************************************
45 ****************************************/
47 public:
48  // book histograms in constructor
49  MillePedeMonitor(const TrackerTopology *tTopo, const char *rootFile = "trackMonitor.root");
50  MillePedeMonitor(TDirectory *rootDir, const TrackerTopology *tTopo);
51  // writes histograms in destructor
52  ~MillePedeMonitor(); // non-virtual destructor: not intended to be parent class
53 
54  void fillTrack(const reco::Track *track); //, const Trajectory *traj);
55  void fillUsedTrack(const reco::Track *track, unsigned int nHitX, unsigned int nHitY); //, const Trajectory *traj);
58  const float *localDerivs,
59  unsigned int nLocal,
60  const float *globalDerivs,
61  unsigned int nGlobal,
62  const int *labels);
64  const TrajectoryStateOnSurface &tsos,
65  unsigned int nHit,
66  float residuum,
67  float sigma,
68  bool isY);
69  void fillFrameToFrame(const AlignableDetOrUnitPtr &aliDet, const Alignable *ali);
70 
72 
73  void fillPxbSurveyHistsChi2(const float &chi2);
74  void fillPxbSurveyHistsLocalPars(const float &a0, const float &a1, const float &S, const float &phi);
75 
76 private:
77  bool init(TDirectory *directory);
78  bool equidistLogBins(double *bins, int nBins, double first, double last) const;
79  void fillResidualHists(const std::vector<TH1 *> &hists, float phiSensToNorm, float residuum, float sigma);
81  const std::vector<TH1 *> &hists, float angle, float residuum, float sigma, unsigned int nHit);
82  void fillTrack(const reco::Track *track, std::vector<TH1 *> &trackHists1D, std::vector<TH2 *> &trackHists2D);
83 
84  template <class OBJECT_TYPE>
85  int GetIndex(const std::vector<OBJECT_TYPE *> &vec, const TString &name);
86  template <class OBJECT_TYPE>
87  std::vector<OBJECT_TYPE *> cloneHists(const std::vector<OBJECT_TYPE *> &orgs,
88  const TString &namAd,
89  const TString &titAd) const;
90  template <class OBJECT_TYPE>
91  void addToDirectory(const std::vector<OBJECT_TYPE *> &objs, TDirectory *dir) const;
92  template <typename T, size_t SIZE>
93  std::array<int, SIZE> indexArray1D(const std::vector<T *> &hists, const char *title);
94  template <typename T, size_t SIZE>
95  std::array<std::array<int, SIZE>, SIZE> indexArray2D(const std::vector<T *> &hists, const char *title);
96 
97  TDirectory *myRootDir;
99 
100  std::vector<TH1 *> myTrackHists1D; // all input tracks
101  std::vector<TH2 *> myTrackHists2D;
102  std::vector<TH1 *> myUsedTrackHists1D; // tracks used, i.e. tranferred to pede
103  std::vector<TH2 *> myUsedTrackHists2D;
104  std::vector<TH1 *> myTrajectoryHists1D;
105  std::vector<TH2 *> myTrajectoryHists2D;
106  std::vector<TH2 *> myDerivHists2D;
107  std::vector<TH2 *> myResidHists2D;
108  std::vector<std::vector<TH1 *> > myResidHistsVec1DX;
109  std::vector<std::vector<TH1 *> > myResidHistsVec1DY;
110  std::vector<TH1 *> myResidHitHists1DX;
111  std::vector<TH1 *> myResidHitHists1DY;
112  std::vector<TH2 *> myFrame2FrameHists2D;
113  std::vector<TH1 *> myCorrHists; // correlations
114  std::vector<TH1 *> myPxbSurveyHists; // correlations
115 
117 };
118 
119 template <class OBJECT_TYPE>
120 int MillePedeMonitor::GetIndex(const std::vector<OBJECT_TYPE *> &vec, const TString &name) {
121  int result = 0;
122  for (typename std::vector<OBJECT_TYPE *>::const_iterator iter = vec.begin(), iterEnd = vec.end(); iter != iterEnd;
123  ++iter, ++result) {
124  if (*iter && (*iter)->GetName() == name)
125  return result;
126  }
127  edm::LogError("Alignment") << "@SUB=MillePedeMonitor::GetIndex"
128  << " could not find " << name;
129  return -1;
130 }
131 
132 template <class OBJECT_TYPE>
133 std::vector<OBJECT_TYPE *> MillePedeMonitor::cloneHists(const std::vector<OBJECT_TYPE *> &orgs,
134  const TString &namAd,
135  const TString &titAd) const {
136  // OBJECT_TYPE required to have methods Clone(const char*), GetName(), SetTitle(const char*) and GetTitle()
137  std::vector<OBJECT_TYPE *> result;
138  for (typename std::vector<OBJECT_TYPE *>::const_iterator iter = orgs.begin(), iterEnd = orgs.end(); iter != iterEnd;
139  ++iter) {
140  if (!(*iter))
141  continue;
142  result.push_back(static_cast<OBJECT_TYPE *>((*iter)->Clone(namAd + (*iter)->GetName())));
143  if (result.back())
144  result.back()->SetTitle((*iter)->GetTitle() + titAd);
145  else
146  edm::LogError("Alignment") << "@SUB=MillePedeMonitor::cloneHists"
147  << "out of memory?";
148  }
149 
150  return result;
151 }
152 
153 template <class OBJECT_TYPE>
154 void MillePedeMonitor::addToDirectory(const std::vector<OBJECT_TYPE *> &obs, TDirectory *dir) const {
155  // OBJECT_TYPE is required to have method SetDirectory(TDirectory *dir)
156  for (typename std::vector<OBJECT_TYPE *>::const_iterator iter = obs.begin(), iterEnd = obs.end(); iter != iterEnd;
157  ++iter) {
158  if (*iter)
159  (*iter)->SetDirectory(dir);
160  }
161 }
162 
163 template <typename T, size_t SIZE>
164 std::array<int, SIZE> MillePedeMonitor::indexArray1D(const std::vector<T *> &hists, const char *title) {
165  std::array<int, SIZE> result{};
166  for (size_t i = 0; i < SIZE; ++i) {
167  result[i] = this->GetIndex(hists, Form(title, i));
168  }
169  return result;
170 }
171 
172 template <typename T, size_t SIZE>
173 std::array<std::array<int, SIZE>, SIZE> MillePedeMonitor::indexArray2D(const std::vector<T *> &hists,
174  const char *title) {
175  std::array<std::array<int, SIZE>, SIZE> result{};
176  for (size_t i = 0; i < SIZE; ++i) {
177  for (size_t j = 0; j < SIZE; ++j) {
178  result[i][j] = this->GetIndex(hists, Form(title, i, j));
179  }
180  }
181  return result;
182 }
183 
184 #endif
std::vector< std::vector< TH1 * > > myResidHistsVec1DY
[0]=all [1]=TPB [2]=TPE [3]=TIB [4]=TID [5]=TOB [6]=TEC
std::vector< TH2 * > myResidHists2D
void fillCorrelations2D(float corr, const TransientTrackingRecHit::ConstRecHitPointer &hit)
bool equidistLogBins(double *bins, int nBins, double first, double last) const
std::vector< TH1 * > myUsedTrackHists1D
std::vector< TH1 * > myCorrHists
std::vector< OBJECT_TYPE * > cloneHists(const std::vector< OBJECT_TYPE *> &orgs, const TString &namAd, const TString &titAd) const
void fillFrameToFrame(const AlignableDetOrUnitPtr &aliDet, const Alignable *ali)
std::vector< TH1 * > myPxbSurveyHists
void addToDirectory(const std::vector< OBJECT_TYPE *> &objs, TDirectory *dir) const
void fillPxbSurveyHistsLocalPars(const float &a0, const float &a1, const float &S, const float &phi)
std::array< std::array< int, SIZE >, SIZE > indexArray2D(const std::vector< T *> &hists, const char *title)
std::array< int, SIZE > indexArray1D(const std::vector< T *> &hists, const char *title)
int GetIndex(const std::vector< OBJECT_TYPE *> &vec, const TString &name)
const TrackerTopology * trackerTopology
Log< level::Error, false > LogError
std::vector< TH1 * > myResidHitHists1DX
[0]=all [1]=TPB [2]=TPE [3]=TIB [4]=TID [5]=TOB [6]=TEC
MillePedeMonitor(const TrackerTopology *tTopo, const char *rootFile="trackMonitor.root")
void fillResiduals(const TransientTrackingRecHit::ConstRecHitPointer &recHit, const TrajectoryStateOnSurface &tsos, unsigned int nHit, float residuum, float sigma, bool isY)
void fillPxbSurveyHistsChi2(const float &chi2)
std::vector< TH2 * > myUsedTrackHists2D
std::vector< TH2 * > myTrackHists2D
std::vector< TH2 * > myDerivHists2D
dictionary corr
void fillUsedTrack(const reco::Track *track, unsigned int nHitX, unsigned int nHitY)
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
std::vector< TH1 * > myTrajectoryHists1D
TDirectory * myRootDir
std::vector< TH2 * > myTrajectoryHists2D
bool init(TDirectory *directory)
void fillResidualHitHists(const std::vector< TH1 *> &hists, float angle, float residuum, float sigma, unsigned int nHit)
std::vector< TH2 * > myFrame2FrameHists2D
static constexpr float a0
void fillTrack(const reco::Track *track)
std::vector< TH1 * > myTrackHists1D
fixed size matrix
std::vector< TH1 * > myResidHitHists1DY
void fillRefTrajectory(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr)
void fillDerivatives(const TransientTrackingRecHit::ConstRecHitPointer &recHit, const float *localDerivs, unsigned int nLocal, const float *globalDerivs, unsigned int nGlobal, const int *labels)
void fillResidualHists(const std::vector< TH1 *> &hists, float phiSensToNorm, float residuum, float sigma)
std::vector< std::vector< TH1 * > > myResidHistsVec1DX
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11