CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BasicTrajectoryState.cc
Go to the documentation of this file.
6 
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 
41 
42 namespace {
43  inline
45  const BasicTrajectoryState::SurfaceType& surface,
46  const MagneticField* field) {
47  GlobalPoint x = surface.toGlobal(par.position());
48  GlobalVector p = surface.toGlobal(par.momentum());
49  return FreeTrajectoryState(x, p, par.charge(), field);
50  }
51 
52 }
53 
56  const SurfaceType& aSurface,
57  const SurfaceSide side) :
58  theFreeState(fts),
59  theLocalError(InvalidError()),
60  theLocalParameters(),
61  theLocalParametersValid(false),
62  theValid(true),
63  theSurfaceSide(side),
64  theSurfaceP( &aSurface),
65  theWeight(1.)
66 {}
67 
70  const SurfaceType& aSurface,
71  const SurfaceSide side) :
72  theFreeState(par),
73  theLocalError(InvalidError()),
74  theLocalParameters(),
75  theLocalParametersValid(false),
76  theValid(true),
77  theSurfaceSide(side),
78  theSurfaceP( &aSurface),
79  theWeight(1.)
80 {}
81 
84  const CartesianTrajectoryError& err,
85  const SurfaceType& aSurface,
86  const SurfaceSide side) :
87  theFreeState(par, err),
88  theLocalError(InvalidError()),
89  theLocalParameters(),
90  theLocalParametersValid(false),
91  theValid(true),
92  theSurfaceSide(side),
93  theSurfaceP( &aSurface),
94  theWeight(1.)
95 {}
96 
99  const CurvilinearTrajectoryError& err,
100  const SurfaceType& aSurface,
101  const SurfaceSide side,
102  double weight) :
103  theFreeState(par, err),
104  theLocalError(InvalidError()),
105  theLocalParameters(),
106  theLocalParametersValid(false),
107  theValid(true),
108  theSurfaceSide(side),
109  theSurfaceP( &aSurface),
110  theWeight(weight)
111 {}
112 
115  const CurvilinearTrajectoryError& err,
116  const SurfaceType& aSurface,
117  double weight) :
118  theFreeState(par, err),
119  theLocalError(InvalidError()),
120  theLocalParameters(),
121  theLocalParametersValid(false),
122  theValid(true),
123  theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
124  theSurfaceP( &aSurface),
125  theWeight(weight)
126 {}
127 
130  const SurfaceType& aSurface,
131  const MagneticField* field,
132  const SurfaceSide side) :
133  theFreeState(makeFTS(par,aSurface,field)),
134  theLocalError(InvalidError()),
135  theLocalParameters(par),
136  theLocalParametersValid(true),
137  theValid(true),
138  theSurfaceSide(side),
139  theSurfaceP( &aSurface),
140  theWeight(1.)
141 {}
142 
145  const LocalTrajectoryError& err,
146  const SurfaceType& aSurface,
147  const MagneticField* field,
148  const SurfaceSide side,
149  double weight) :
150  theFreeState(makeFTS(par,aSurface,field)),
151  theLocalError(err),
152  theLocalParameters(par),
153  theLocalParametersValid(true),
154  theValid(true),
155  theSurfaceSide(side),
156  theSurfaceP( &aSurface),
157  theWeight(weight)
158 {}
159 
162  const LocalTrajectoryError& err,
163  const SurfaceType& aSurface,
164  const MagneticField* field,
165  double weight) :
166  theFreeState(makeFTS(par,aSurface,field)),
167  theLocalError(err),
168  theLocalParameters(par),
169  theLocalParametersValid(true),
170  theValid(true),
171  theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
172  theSurfaceP( &aSurface),
173  theWeight(weight){}
174 
177  theLocalError(InvalidError()),
178  theLocalParameters(),
179  theLocalParametersValid(false),
180  theValid(false),
181  theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
182  theSurfaceP( &aSurface),
183  theWeight(0)
184 {}
185 
186 
187 
189  throw TrajectoryStateException("TrajectoryStateOnSurface is invalid and cannot return any parameters");
190 }
191 
192 namespace {
193  void verifyLocalErr(LocalTrajectoryError const & err ) {
194  if unlikely(!err.posDef())
195  edm::LogWarning("BasicTrajectoryState") << "local error not pos-def\n"
196  << err.matrix();
197  }
198  void verifyCurvErr(CurvilinearTrajectoryError const & err ) {
199  if unlikely(!err.posDef())
200  edm::LogWarning("BasicTrajectoryState") << "curv error not pos-def\n"
201  << err.matrix();
202  }
203 
204 }
205 
206 void BasicTrajectoryState::missingError(char const * where) const{
207  std::stringstream form;
208  form<<"BasicTrajectoryState: attempt to access errors when none available "
209  <<where<<".\nfreestate pointer: " <<theFreeState
210  <<"\nlocal error valid/values :"<< theLocalError.valid() << "\n"
211  << theLocalError.matrix();
212 
213  edm::LogWarning("BasicTrajectoryState") << form.str();
214 
215  // throw TrajectoryStateException(form.str());
216 }
217 
218 
219 
222 
224 
226  const AlgebraicMatrix55& jac = loc2Curv.jacobian();
227  const AlgebraicSymMatrix55 &cov = ROOT::Math::Similarity(jac, theLocalError.matrix());
228 
230 
231  verifyLocalErr(theLocalError);
232  verifyCurvErr(cov);
233 }
234 
235 
236 
237 // create local parameters from global
241 // believe p.z() never exactly equals 0.
242  bool isCharged = theFreeState.charge()!=0;
245  p.x()/p.z(), p.y()/p.z(), x.x(), x.y(), p.z()>0. ? 1.:-1., isCharged);
247 }
248 
252  else theLocalError = InvalidError();
253 }
254 
255 void
257 
259  const AlgebraicMatrix55& jac = curv2Loc.jacobian();
260 
261  const AlgebraicSymMatrix55 &cov =
262  ROOT::Math::Similarity(jac, theFreeState.curvilinearError().matrix());
263  // cout<<"Clocal via curvilinear error"<<endl;
265 
266  verifyCurvErr(theFreeState.curvilinearError());
267  verifyLocalErr(theLocalError);
268 
269 }
270 
271 
272 void
274  const SurfaceType& aSurface,
275  const MagneticField* field,
276  const SurfaceSide side)
277 {
279  if (&aSurface != &*theSurfaceP) theSurfaceP.reset(&aSurface);
280  theSurfaceSide = side;
281  theWeight = 1.0;
283  theFreeState=makeFTS(p,aSurface,field);
284 
285  theValid = true;
287 }
288 
289 void
291  const LocalTrajectoryError& err,
292  const SurfaceType& aSurface,
293  const MagneticField* field,
294  const SurfaceSide side,
295  double weight)
296 {
298  theLocalError = err;
299  if (&aSurface != &*theSurfaceP) theSurfaceP.reset(&aSurface);
300  theSurfaceSide = side;
301  theWeight = weight;
302  theFreeState=makeFTS(p,aSurface,field);
303 
304  theValid = true;
306 }
307 
308 void
310  if unlikely(!hasError()) missingError(" trying to rescale");
311  theFreeState.rescaleError(factor);
312 
313  if (theLocalError.valid()){
314  //do it by hand if the free state is not around.
315  bool zeroField = (magneticField()->nominalValue()==0);
316  if unlikely(zeroField){
318  //scale the 0 indexed covariance by the square root of the factor
319  for (unsigned int i=1;i!=5;++i) errors(i,0)*=factor;
320  double factor_squared=factor*factor;
321  //scale all others by the scaled factor
322  for (unsigned int i=1;i!=5;++i) for (unsigned int j=i;j!=5;++j) errors(i,j)*=factor_squared;
323  //term 0,0 is not scaled at all
325  }
326  else theLocalError *= (factor*factor);
327  }
328 }
329 
330 
331 
332 
333 
335 std::vector<TrajectoryStateOnSurface>
337  std::vector<TrajectoryStateOnSurface> result; result.reserve(1);
338  result.push_back( const_cast<BasicTrajectoryState*>(this));
339  return result;
340 }
ConstReferenceCountingPointer< SurfaceType > theSurfaceP
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
int i
Definition: DBlmapReader.cc:9
const MagneticField * magneticField() const
void createLocalErrorFromCurvilinearError() const dso_internal
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:57
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)
T y() const
Definition: PV3DBase.h:63
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)
Definition: Likely.h:21
T mag() const
Definition: PV3DBase.h:67
const T & max(const T &a, const T &b)
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
void createLocalParameters() const
const AlgebraicSymMatrix55 & matrix() const
LocalVector momentum() const
Momentum vector in the local frame.
GlobalVector momentum() const
void setCurvilinearError(const CurvilinearTrajectoryError &err)
GlobalPoint position() const
const SurfaceType & surface() const
const GlobalTrajectoryParameters & globalParameters() const
void rescaleError(double factor)
FreeTrajectoryState theFreeState
TrackCharge charge() const
Charge (-1, 0 or 1)
const AlgebraicMatrix55 & jacobian() const
void missingError(char const *where) const
const LocalTrajectoryParameters & localParameters() const
#define likely(x)
Definition: Likely.h:20
const AlgebraicSymMatrix55 & matrix() const
virtual std::vector< TrajectoryStateOnSurface > components() const
LocalTrajectoryParameters theLocalParameters
const AlgebraicMatrix55 & jacobian() const
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10
int weight
Definition: histoStyle.py:50
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