CMS 3D CMS Logo

FcnBeamSpotFitPV.cc
Go to the documentation of this file.
2 #include "Math/SVector.h"
3 #include "Math/SMatrix.h"
4 // #include "Math/SMatrixDfwd.h"
5 //#include "FWCore/MessageLogger/interface/MessageLogger.h"
6 
7 using namespace std;
8 
9 //
10 // constructor from vertex data
11 //
12 FcnBeamSpotFitPV::FcnBeamSpotFitPV(const vector<BeamSpotFitPVData>& data) : data_(data), errorDef_(1.) {
13  //
14  // default: no additional cuts
15  //
16  lowerLimits_[0] = lowerLimits_[1] = lowerLimits_[2] = -1.e30;
17  upperLimits_[0] = upperLimits_[1] = upperLimits_[2] = 1.e30;
18 }
19 
20 void FcnBeamSpotFitPV::setLimits(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax) {
21  lowerLimits_[0] = xmin;
22  lowerLimits_[1] = ymin;
23  lowerLimits_[2] = zmin;
24  upperLimits_[0] = xmax;
25  upperLimits_[1] = ymax;
26  upperLimits_[2] = zmax;
27 }
28 
29 unsigned int FcnBeamSpotFitPV::nrOfVerticesUsed() const {
30  //
31  // count vertices imposing the current limits
32  //
33  unsigned int nVtx = 0;
34  double v1(0);
35  double v2(0);
36  double v3(0);
37  for (vector<BeamSpotFitPVData>::const_iterator ipv = data_.begin(); ipv != data_.end(); ++ipv) {
38  v1 = (*ipv).position[0];
39  if (v1 < lowerLimits_[0] || v1 > upperLimits_[0])
40  continue;
41  v2 = (*ipv).position[1];
42  if (v2 < lowerLimits_[1] || v2 > upperLimits_[1])
43  continue;
44  v3 = (*ipv).position[2];
45  if (v3 < lowerLimits_[2] || v3 > upperLimits_[2])
46  continue;
47 
48  ++nVtx;
49  }
50 
51  return nVtx;
52 }
53 
54 double FcnBeamSpotFitPV::operator()(const std::vector<double>& pars) const {
55  //
56  // fit parameters
57  //
58  double vb1 = pars[0];
59  double vb2 = pars[1];
60  double vb3 = pars[2];
61  double sigb1 = pars[3];
62  double corrb12 = pars[4];
63  double sigb2 = pars[5];
64  double dxdz = pars[6];
65  double dydz = pars[7];
66  double sigb3 = pars[8];
67  double escale = pars[9];
68  //
69  // covariance matrix of the beamspot distribution
70  //
71  typedef ROOT::Math::SVector<double, 3> Vector3D;
72  typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > Matrix3D;
73  Matrix3D covb;
74  double varb1 = sigb1 * sigb1;
75  double varb2 = sigb2 * sigb2;
76  double varb3 = sigb3 * sigb3;
77  // parametrisation: rotation (dx/dz, dy/dz); covxy
78  covb(0, 0) = varb1;
79  covb(1, 0) = covb(0, 1) = corrb12 * sigb1 * sigb2;
80  covb(1, 1) = varb2;
81  covb(2, 0) = covb(0, 2) = dxdz * (varb3 - varb1) - dydz * covb(1, 0);
82  covb(2, 1) = covb(1, 2) = dydz * (varb3 - varb2) - dxdz * covb(1, 0);
83  covb(2, 2) = varb3;
84 
85  //
86  // calculation of the likelihood function
87  //
88  double sumLL(0);
89  double v1(0);
90  double v2(0);
91  double v3(0);
92  double ev1(0);
93  double corr12(0);
94  double ev2(0);
95  double corr13(0);
96  double corr23(0);
97  double ev3(0);
98  //
99  // vertex - beamspot difference and total covariance matrix
100  //
101  Vector3D dv;
102  Matrix3D cov;
103  Matrix3D wgt;
104  //
105  // iteration over vertices
106  //
107  for (vector<BeamSpotFitPVData>::const_iterator ipv = data_.begin(); ipv != data_.end(); ++ipv) {
108  //
109  // additional selection
110  //
111  v1 = (*ipv).position[0];
112  if (v1 < lowerLimits_[0] || v1 > upperLimits_[0])
113  continue;
114  v2 = (*ipv).position[1];
115  if (v2 < lowerLimits_[1] || v2 > upperLimits_[1])
116  continue;
117  v3 = (*ipv).position[2];
118  if (v3 < lowerLimits_[2] || v3 > upperLimits_[2])
119  continue;
120  //
121  // vertex errors (after scaling) and correlations
122  //
123  ev1 = (*ipv).posError[0];
124  corr12 = (*ipv).posCorr[0];
125  ev2 = (*ipv).posError[1];
126  corr13 = (*ipv).posCorr[1];
127  corr23 = (*ipv).posCorr[2];
128  ev3 = (*ipv).posError[2];
129  ev1 *= escale;
130  ev2 *= escale;
131  ev3 *= escale;
132  //
133  // vertex covariance matrix
134  //
135  cov(0, 0) = ev1 * ev1;
136  cov(1, 0) = cov(0, 1) = ev1 * ev2 * corr12;
137  cov(1, 1) = ev2 * ev2;
138  cov(2, 0) = cov(0, 2) = ev1 * ev3 * corr13;
139  cov(2, 1) = cov(1, 2) = ev2 * ev3 * corr23;
140  cov(2, 2) = ev3 * ev3;
141  //
142  // total covariance and weight matrix
143  //
144  cov += covb;
145  int ifail;
146  wgt = cov.Inverse(ifail);
147  if (ifail) {
148  //edm::LogWarning("FcnBeamSpotFitPV")
149  cout << "Inversion failed" << endl;
150  return -1.e30;
151  }
152  //
153  // difference of vertex and beamspot positions
154  //
155  dv(0) = v1 - vb1;
156  dv(1) = v2 - vb2;
157  dv(2) = v3 - vb3;
158  //
159  // exponential term and normalization
160  // (neglecting the additional cut)
161  //
162  sumLL += ROOT::Math::Similarity(dv, wgt);
163  double det;
164  cov.Det2(det);
165  sumLL += log(det);
166  }
167 
168  return sumLL;
169 }
FcnBeamSpotFitPV(const std::vector< BeamSpotFitPVData > &data)
double operator()(const std::vector< double > &) const override
void setLimits(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned int nrOfVerticesUsed() const
const std::vector< BeamSpotFitPVData > & data_