CMS 3D CMS Logo

BasicTrajectoryState.cc
Go to the documentation of this file.
8 
9 
10 #include <cmath>
11 #include<sstream>
12 
13 #ifdef DO_BTSCount
14 unsigned int BTSCount::maxReferences=0;
15 unsigned long long BTSCount::aveReferences=0;
16 unsigned long long BTSCount::toteReferences=0;
17 
18 BTSCount::~BTSCount(){
19  maxReferences = std::max(referenceMax_, maxReferences);
20  toteReferences++;
21  aveReferences+=referenceMax_;
22  // if (referenceMax_>100) std::cout <<"BST with " << referenceMax_ << std::endl;
23 }
24 
25 #include<iostream>
26 namespace {
27 
28  struct Printer{
29  ~Printer() {
30  std::cout << "maxReferences of BTSCount = "
31  << BTSCount::maxReferences << " "
32  << double(BTSCount::aveReferences)/double(BTSCount::toteReferences)<< std::endl;
33  }
34  };
35  Printer printer;
36 
37 }
38 #endif
39 
43  theLocalError(InvalidError()),
44  theLocalParameters(),
45  theLocalParametersValid(false),
46  theValid(false),
47  theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
48  theSurfaceP( &aSurface),
49  theWeight(1.)
50 {}
51 
52 
53 
54 namespace {
55  inline
58  const MagneticField* field) {
59  GlobalPoint x = surface.toGlobal(par.position());
60  GlobalVector p = surface.toGlobal(par.momentum());
61  return FreeTrajectoryState(x, p, par.charge(), field);
62  }
63 
64 
65  inline
67  const BasicTrajectoryState::SurfaceType& surface,
68  const MagneticField* field, GlobalVector fieldValue) {
69  GlobalPoint x = surface.toGlobal(par.position());
70  GlobalVector p = surface.toGlobal(par.momentum());
71  return FreeTrajectoryState(x, p, par.charge(), field, fieldValue);
72  }
73 
74 
75 }
76 
79  const LocalTrajectoryError& err,
80  const SurfaceType& aSurface,
81  const MagneticField* field,
82  const SurfaceSide side) :
83  theFreeState(makeFTS(par,aSurface,field)),
84  theLocalError(err),
85  theLocalParameters(par),
87  theValid(true),
88  theSurfaceSide(side),
89  theSurfaceP( &aSurface),
90  theWeight(1.)
91 {}
92 
93 
94 
95 
96 
98  throw TrajectoryStateException("TrajectoryStateOnSurface is invalid and cannot return any parameters");
99 }
100 
101 namespace {
102  void verifyLocalErr(LocalTrajectoryError const & err, const FreeTrajectoryState & state ) {
103  if unlikely(!err.posDef())
104  edm::LogWarning("BasicTrajectoryState") << "local error not pos-def\n"
105  << err.matrix()
106  << "\npos/mom/mf " << state.position() << ' ' << state.momentum()
107  << ' ' << state.parameters().magneticFieldInTesla();
108  }
109  void verifyCurvErr(CurvilinearTrajectoryError const & err, const FreeTrajectoryState & state ) {
110  if unlikely(!err.posDef())
111  edm::LogWarning("BasicTrajectoryState") << "curv error not pos-def\n"
112  << err.matrix()
113  << "\npos/mom/mf " << state.position() << ' ' << state.momentum()
114  << ' ' << state.parameters().magneticFieldInTesla();
115  }
116 }
117 
118 
119 void BasicTrajectoryState::missingError(char const * where) const{
120  std::stringstream form;
121  form<<"BasicTrajectoryState: attempt to access errors when none available "
122  <<where<<".\nfreestate pointer: " <<theFreeState
123  <<"\nlocal error valid/values :"<< theLocalError.valid() << "\n"
124  << theLocalError.matrix();
125 
126  edm::LogWarning("BasicTrajectoryState") << form.str();
127 
128  // throw TrajectoryStateException(form.str());
129 }
130 
131 
132 
135 
137 
139  const AlgebraicMatrix55& jac = loc2Curv.jacobian();
140  const AlgebraicSymMatrix55 &cov = ROOT::Math::Similarity(jac, theLocalError.matrix());
141 
143 
144  verifyLocalErr(theLocalError,theFreeState);
145  verifyCurvErr(cov,theFreeState);
146 }
147 
148 
149 
150 // create local parameters from global
154 // believe p.z() never exactly equals 0.
155  bool isCharged = theFreeState.charge()!=0;
158  p.x()/p.z(), p.y()/p.z(), x.x(), x.y(), p.z()>0. ? 1.:-1., isCharged);
160 }
161 
165  else theLocalError = InvalidError();
166 }
167 
168 void
170 
172  const AlgebraicMatrix55 & jac = curv2Loc.jacobian();
173 
174  theLocalError = ROOT::Math::Similarity(jac, theFreeState.curvilinearError().matrix());
175 
176  verifyCurvErr(theFreeState.curvilinearError(),theFreeState);
177  verifyLocalErr(theLocalError,theFreeState);
178 
179 }
180 
181 
182 
183 // update in place and in the very same place
184 void
187  theSurfaceSide = side;
190 
191  theValid = true;
193 
194 }
195 
196 
197 void
199  const SurfaceType& aSurface,
200  const MagneticField* field,
201  const SurfaceSide side)
202 {
204  if (&aSurface != &*theSurfaceP) theSurfaceP.reset(&aSurface);
205  theSurfaceSide = side;
206  theWeight = 1.0;
208  theFreeState=makeFTS(p,aSurface,field);
209 
210  theValid = true;
212 }
213 
214 void
217  const LocalTrajectoryError& err,
218  const SurfaceType& aSurface,
219  const MagneticField* field,
220  const SurfaceSide side)
221 {
223  theLocalError = err;
224  if (&aSurface != &*theSurfaceP) theSurfaceP.reset(&aSurface);
225  theSurfaceSide = side;
226  theWeight = weight;
227  theFreeState=makeFTS(p,aSurface,field);
228 
229  theValid = true;
231 }
232 
233 
234 void
236  const LocalTrajectoryError& err,
237  const SurfaceSide side)
238 {
240  theLocalError = err;
241  theSurfaceSide = side;
243 
244  theValid = true;
246 }
247 
248 
249 void
251  if unlikely(!hasError()) missingError(" trying to rescale");
252  theFreeState.rescaleError(factor);
253 
254  if (theLocalError.valid()){
255  //do it by hand if the free state is not around.
256  bool zeroField = (magneticField()->nominalValue()==0);
257  if unlikely(zeroField){
259  //scale the 0 indexed covariance by the square root of the factor
260  for (unsigned int i=1;i!=5;++i) errors(i,0)*=factor;
261  double factor_squared=factor*factor;
262  //scale all others by the scaled factor
263  for (unsigned int i=1;i!=5;++i) for (unsigned int j=i;j!=5;++j) errors(i,j)*=factor_squared;
264  //term 0,0 is not scaled at all
266  }
267  else theLocalError *= (factor*factor);
268  }
269 }
270 
271 
272 
273 
277  edm::LogError("BasicSingleTrajectoryState") << "asking for componenets to a SingleTrajectoryState"<< std::endl;
278  assert(false);
279 }
280 
ConstReferenceCountingPointer< SurfaceType > theSurfaceP
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
BasicTrajectoryState::Components Components
const MagneticField * magneticField() const
const GlobalTrajectoryParameters & parameters() const
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:58
LocalPoint position() const
Local x and y position coordinates.
bool hasCurvilinearError() const
virtual void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side)
Components const & components() const override
T y() const
Definition: PV3DBase.h:63
Definition: weight.py:1
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
TrackCharge charge() const
const CurvilinearTrajectoryError & curvilinearError() const
void rescaleError(double factor)
#define unlikely(x)
#define likely(x)
T mag() const
Definition: PV3DBase.h:67
void createLocalErrorFromCurvilinearError() const
LocalPoint toLocal(const GlobalPoint &gp) const
GlobalVector magneticFieldInTesla() const
T z() const
Definition: PV3DBase.h:64
void createLocalParameters() const
const AlgebraicSymMatrix55 & matrix() const
LocalVector momentum() const
Momentum vector in the local frame.
GlobalVector momentum() const
GlobalPoint position() const
const SurfaceType & surface() const
const GlobalTrajectoryParameters & globalParameters() const
void rescaleError(double factor)
FreeTrajectoryState theFreeState
CurvilinearTrajectoryError & setCurvilinearError()
TrackCharge charge() const
Charge (-1, 0 or 1)
const AlgebraicMatrix55 & jacobian() const
void missingError(char const *where) const
const LocalTrajectoryParameters & localParameters() const
const AlgebraicSymMatrix55 & matrix() const
LocalTrajectoryParameters theLocalParameters
const AlgebraicMatrix55 & jacobian() const
Definition: errors.py:1
T x() const
Definition: PV3DBase.h:62
LocalTrajectoryError theLocalError
double signedInverseMomentum() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55