test
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.
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
57  const BasicTrajectoryState::SurfaceType& surface,
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 SurfaceType& aSurface,
80  const SurfaceSide side) :
81  theFreeState(fts),
82  theLocalError(InvalidError()),
83  theLocalParameters(),
84  theLocalParametersValid(false),
85  theValid(true),
86  theSurfaceSide(side),
87  theSurfaceP( &aSurface),
88  theWeight(1.)
89 {}
90 
91 
94  const CartesianTrajectoryError& err,
95  const SurfaceType& aSurface,
96  const SurfaceSide side) :
97  theFreeState(par, err),
98  theLocalError(InvalidError()),
99  theLocalParameters(),
100  theLocalParametersValid(false),
101  theValid(true),
102  theSurfaceSide(side),
103  theSurfaceP( &aSurface),
104  theWeight(1.)
105 {}
106 
107 
108 
111  const LocalTrajectoryError& err,
112  const SurfaceType& aSurface,
113  const MagneticField* field,
114  const SurfaceSide side) :
115  theFreeState(makeFTS(par,aSurface,field)),
116  theLocalError(err),
117  theLocalParameters(par),
118  theLocalParametersValid(true),
119  theValid(true),
120  theSurfaceSide(side),
121  theSurfaceP( &aSurface),
122  theWeight(1.)
123 {}
124 
125 
126 
127 
128 
130  throw TrajectoryStateException("TrajectoryStateOnSurface is invalid and cannot return any parameters");
131 }
132 
133 namespace {
134  void verifyLocalErr(LocalTrajectoryError const & err, const FreeTrajectoryState & state ) {
135  if unlikely(!err.posDef())
136  edm::LogWarning("BasicTrajectoryState") << "local error not pos-def\n"
137  << err.matrix()
138  << "\npos/mom/mf " << state.position() << ' ' << state.momentum()
139  << ' ' << state.parameters().magneticFieldInTesla();
140  }
141  void verifyCurvErr(CurvilinearTrajectoryError const & err, const FreeTrajectoryState & state ) {
142  if unlikely(!err.posDef())
143  edm::LogWarning("BasicTrajectoryState") << "curv error not pos-def\n"
144  << err.matrix()
145  << "\npos/mom/mf " << state.position() << ' ' << state.momentum()
146  << ' ' << state.parameters().magneticFieldInTesla();
147  }
148 }
149 
150 
151 void BasicTrajectoryState::missingError(char const * where) const{
152  std::stringstream form;
153  form<<"BasicTrajectoryState: attempt to access errors when none available "
154  <<where<<".\nfreestate pointer: " <<theFreeState
155  <<"\nlocal error valid/values :"<< theLocalError.valid() << "\n"
156  << theLocalError.matrix();
157 
158  edm::LogWarning("BasicTrajectoryState") << form.str();
159 
160  // throw TrajectoryStateException(form.str());
161 }
162 
163 
164 
167 
169 
171  const AlgebraicMatrix55& jac = loc2Curv.jacobian();
172  const AlgebraicSymMatrix55 &cov = ROOT::Math::Similarity(jac, theLocalError.matrix());
173 
175 
176  verifyLocalErr(theLocalError,theFreeState);
177  verifyCurvErr(cov,theFreeState);
178 }
179 
180 
181 
182 // create local parameters from global
186 // believe p.z() never exactly equals 0.
187  bool isCharged = theFreeState.charge()!=0;
190  p.x()/p.z(), p.y()/p.z(), x.x(), x.y(), p.z()>0. ? 1.:-1., isCharged);
192 }
193 
197  else theLocalError = InvalidError();
198 }
199 
200 void
202 
204  const AlgebraicMatrix55 & jac = curv2Loc.jacobian();
205 
206  theLocalError = ROOT::Math::Similarity(jac, theFreeState.curvilinearError().matrix());
207 
208  verifyCurvErr(theFreeState.curvilinearError(),theFreeState);
209  verifyLocalErr(theLocalError,theFreeState);
210 
211 }
212 
213 
214 
215 // update in place and in the very same place
216 void
219  theSurfaceSide = side;
222 
223  theValid = true;
225 
226 }
227 
228 
229 void
231  const SurfaceType& aSurface,
232  const MagneticField* field,
233  const SurfaceSide side)
234 {
236  if (&aSurface != &*theSurfaceP) theSurfaceP.reset(&aSurface);
237  theSurfaceSide = side;
238  theWeight = 1.0;
240  theFreeState=makeFTS(p,aSurface,field);
241 
242  theValid = true;
244 }
245 
246 void
248  const LocalTrajectoryParameters& p,
249  const LocalTrajectoryError& err,
250  const SurfaceType& aSurface,
251  const MagneticField* field,
252  const SurfaceSide side)
253 {
255  theLocalError = err;
256  if (&aSurface != &*theSurfaceP) theSurfaceP.reset(&aSurface);
257  theSurfaceSide = side;
258  theWeight = weight;
259  theFreeState=makeFTS(p,aSurface,field);
260 
261  theValid = true;
263 }
264 
265 
266 void
268  const LocalTrajectoryError& err,
269  const SurfaceSide side)
270 {
272  theLocalError = err;
273  theSurfaceSide = side;
275 
276  theValid = true;
278 }
279 
280 
281 void
283  if unlikely(!hasError()) missingError(" trying to rescale");
284  theFreeState.rescaleError(factor);
285 
286  if (theLocalError.valid()){
287  //do it by hand if the free state is not around.
288  bool zeroField = (magneticField()->nominalValue()==0);
289  if unlikely(zeroField){
291  //scale the 0 indexed covariance by the square root of the factor
292  for (unsigned int i=1;i!=5;++i) errors(i,0)*=factor;
293  double factor_squared=factor*factor;
294  //scale all others by the scaled factor
295  for (unsigned int i=1;i!=5;++i) for (unsigned int j=i;j!=5;++j) errors(i,j)*=factor_squared;
296  //term 0,0 is not scaled at all
298  }
299  else theLocalError *= (factor*factor);
300  }
301 }
302 
303 
304 
305 
307 std::vector<TrajectoryStateOnSurface>
309  std::vector<TrajectoryStateOnSurface> result; result.reserve(1);
310  result.emplace_back(clone());
311  // result.emplace_back(const_cast<BasicTrajectoryState*>(this));
312  return result;
313 }
314 
ConstReferenceCountingPointer< SurfaceType > theSurfaceP
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
int i
Definition: DBlmapReader.cc:9
const MagneticField * magneticField() const
const GlobalTrajectoryParameters & parameters() const
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:56
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)
std::vector< TrajectoryStateOnSurface > components() const override
tuple result
Definition: mps_fire.py:84
#define unlikely(x)
T x() const
Cartesian x coordinate.
#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
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
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
tuple cout
Definition: gather_cfg.py:145
volatile std::atomic< bool > shutdown_flag false
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