CMS 3D CMS Logo

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