CMS 3D CMS Logo

BasicTrajectoryState.h
Go to the documentation of this file.
1 #ifndef BasicTrajectoryState_H
2 #define BasicTrajectoryState_H
3 
5 
12 
13 #include <vector>
14 
15 
19 
25 
27 // #include <iostream>
28 
29 class MagneticField;
31 
32 
33 #ifdef DO_BTSCount
34 class BTSCount {
35 public:
36  BTSCount(){}
37  virtual ~BTSCount();
38  BTSCount(BTSCount const &){}
39 
40  static unsigned int maxReferences;
41  static unsigned long long aveReferences;
42  static unsigned long long toteReferences;
43 
44  void addReference() const { ++referenceCount_ ; referenceMax_ = std::max(referenceMax_, referenceCount_); }
45  void removeReference() const {
46  if( 0 == --referenceCount_ ) {
47  delete const_cast<BTSCount*>(this);
48  }
49  }
50 
51  unsigned int references() const {return referenceCount_;}
52 private :
53  mutable unsigned int referenceCount_=0;
54  mutable unsigned int referenceMax_ =0;
55 };
56 #endif
57 
65  public:
66 
72 
73 public:
74 
75  // default constructor : to make root happy
76  BasicTrajectoryState() : theValid(false), theWeight(0){}
77 
79  explicit BasicTrajectoryState(const SurfaceType& aSurface);
80 
81  virtual ~BasicTrajectoryState();
82 
83  virtual pointer clone() const=0;
84 
85  template<typename T, typename... Args>
86  static std::shared_ptr<BTSOS> build(Args && ...args){ return std::make_shared<T>(std::forward<Args>(args)...);}
87 
88  template<typename T, typename... Args>
89  static std::shared_ptr<BTSOS> churn(Args && ...args){ return std::allocate_shared<T>(churn_allocator<T>(),std::forward<Args>(args)...);}
90 
91 
92 
97  const SurfaceType& aSurface,
98  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface):
99  theFreeState(fts),
100  theLocalError(InvalidError()),
101  theLocalParameters(),
102  theLocalParametersValid(false),
103  theValid(true),
104  theSurfaceSide(side),
105  theSurfaceP( &aSurface),
106  theWeight(1.)
107  {}
108 
109 
110 
114  theFreeState(fts),
115  theLocalError(InvalidError()),
116  theLocalParameters(),
117  theLocalParametersValid(false),
118  theValid(true),
119  theWeight(1.)
120  {}
121 
122 
123 
124 
130  const LocalTrajectoryError& err,
131  const SurfaceType& aSurface,
132  const MagneticField* field,
133  const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface);
134 
135 
140  const SurfaceType& aSurface,
141  const MagneticField* field,
142  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface) :
143  BasicTrajectoryState(par, InvalidError(), aSurface, field, side){}
144 
145 
146 
147 
152  const CartesianTrajectoryError& err,
153  const SurfaceType& aSurface,
154  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface):
155  theFreeState(par, err),
156  theLocalError(InvalidError()),
157  theLocalParameters(),
158  theLocalParametersValid(false),
159  theValid(true),
160  theSurfaceSide(side),
161  theSurfaceP( &aSurface),
162  theWeight(1.)
163  {}
164 
165 
171  const CurvilinearTrajectoryError& err,
172  const SurfaceType& aSurface,
173  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface) :
174  theFreeState(par, err),
175  theLocalError(InvalidError()),
176  theLocalParameters(),
177  theLocalParametersValid(false),
178  theValid(true),
179  theSurfaceSide(side),
180  theSurfaceP( &aSurface),
181  theWeight(1.)
182  {}
183 
184 
189  const SurfaceType& aSurface,
190  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface) :
191  BasicTrajectoryState(par, InvalidError(), aSurface, side){}
192 
193 
194  // as above, with explicit weight
195  template<typename... Args>
196  BasicTrajectoryState(double iweight, Args && ...args) : BasicTrajectoryState(std::forward<Args>(args)...) {
197  theWeight = iweight;
198  }
199 
200 
201 
202  bool isValid() const { return theValid; }
203 
204 
205 // access global parameters/errors
207  return theFreeState.parameters();
208  }
210  return theFreeState.position();
211  }
213  return theFreeState.momentum();
214  }
216  return theFreeState.momentum().unit();
217  }
218  TrackCharge charge() const {
219  return theFreeState.charge();
220  }
221  double signedInverseMomentum() const {
222  return theFreeState.signedInverseMomentum();
223  }
224  double transverseCurvature() const {
225  return theFreeState.transverseCurvature();
226  }
227 
229  if UNLIKELY(!hasError()) {
230  missingError(" accesing cartesian error.");
231  return CartesianTrajectoryError();
232  }
233  return freeTrajectoryState(true)->cartesianError();
234  }
236  if UNLIKELY(!hasError()) {
237  missingError(" accesing curvilinearerror.");
238  static const CurvilinearTrajectoryError crap;
239  return crap;
240  }
241  return freeTrajectoryState(true)->curvilinearError();
242  }
243 
244 
245 
246  FreeTrajectoryState const* freeTrajectoryState(bool withErrors=true) const {
247  if UNLIKELY(!isValid()) notValid();
248  if(withErrors && hasError()) { // this is the right thing
249  checkCurvilinError();
250  }
251  return &theFreeState;
252  }
253 
254 
255  const MagneticField *magneticField() const { return &theFreeState.parameters().magneticField(); }
256 
257 // access local parameters/errors
259  if UNLIKELY(!isValid()) notValid();
260  if UNLIKELY(!theLocalParametersValid)
261  createLocalParameters();
262  return theLocalParameters;
263  }
265  return localParameters().position();
266  }
268  return localParameters().momentum();
269  }
271  return localMomentum().unit();
272  }
273 
275  if UNLIKELY(!hasError()) {
276  missingError(" accessing local error.");
277  return theLocalError;
278  }
279  if UNLIKELY(theLocalError.invalid()) createLocalError();
280  return theLocalError;
281  }
282 
283  const SurfaceType& surface() const {
284  return *theSurfaceP;
285  }
286 
287  double weight() const {return theWeight;}
288 
289  void rescaleError(double factor);
290 
291 
292 
294  SurfaceSide surfaceSide() const {
295  return theSurfaceSide;
296  }
297 
298  bool hasError() const {
299  return theFreeState.hasError() || theLocalError.valid();
300  }
301 
302 
303  virtual bool canUpdateLocalParameters() const { return true; }
304 
305  virtual void update( const LocalTrajectoryParameters& p,
306  const SurfaceType& aSurface,
307  const MagneticField* field,
308  const SurfaceSide side ) ;
309 
310  // update in place and in the very same place
311  virtual void update( const LocalTrajectoryParameters& p, const SurfaceSide side ) final;
312 
313 
314 
315  virtual void update( double weight,
316  const LocalTrajectoryParameters& p,
317  const LocalTrajectoryError& err,
318  const SurfaceType& aSurface,
319  const MagneticField* field,
320  const SurfaceSide side);
321 
322  // update in place and in the very same place
323  virtual void update( const LocalTrajectoryParameters& p,
324  const LocalTrajectoryError& err,
325  const SurfaceSide side) final;
326 
328  return theFreeState.setCurvilinearError();
329  }
330 
331 public:
332  using Components = std::vector<TrajectoryStateOnSurface>;
333  virtual Components const & components() const =0;
334  virtual bool singleState() const=0;
335 
336 private:
337 
338  static void notValid();
339 
340 
341  void missingError(char const * where) const; // dso_internal;
342 
343  // create global errors from local
344  void checkCurvilinError() const; // dso_internal;
345 
346  // create local parameters and errors from global
347  void createLocalParameters() const;
348  // create local errors from global
349  void createLocalError() const;
350  void createLocalErrorFromCurvilinearError() const dso_internal;
351 
352 private:
353 
354  mutable FreeTrajectoryState theFreeState;
355 
356  mutable LocalTrajectoryError theLocalError;
357  mutable LocalTrajectoryParameters theLocalParameters;
358 
359  mutable bool theLocalParametersValid;
360  mutable bool theValid;
361 
362 
363  SurfaceSide theSurfaceSide;
364  ConstReferenceCountingPointer<SurfaceType> theSurfaceP;
365 
366  double theWeight=0.;
367 };
368 
369 #endif
GlobalPoint globalPosition() const
CurvilinearTrajectoryError & setCurvilinearError()
LocalPoint localPosition() const
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
const MagneticField * magneticField() const
SurfaceSideDefinition::SurfaceSide SurfaceSide
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
BasicTrajectoryState(const GlobalTrajectoryParameters &par, const CurvilinearTrajectoryError &err, const SurfaceType &aSurface, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
const CartesianTrajectoryError cartesianError() const
BasicTrajectoryState(double iweight, Args &&...args)
Definition: weight.py:1
TrackCharge charge() const
std::shared_ptr< T > pointer
Definition: ProxyBase11.h:27
BasicTrajectoryState(const LocalTrajectoryParameters &par, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
int TrackCharge
Definition: TrackCharge.h:4
GlobalVector globalDirection() const
std::vector< TrajectoryStateOnSurface > Components
static std::shared_ptr< BTSOS > build(Args &&...args)
const LocalTrajectoryError & localError() const
BasicTrajectoryState(const FreeTrajectoryState &fts, const SurfaceType &aSurface, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
double signedInverseMomentum() const
#define dso_internal
Definition: Visibility.h:13
Vector3DBase unit() const
Definition: Vector3DBase.h:57
const SurfaceType & surface() const
static std::shared_ptr< BTSOS > churn(Args &&...args)
const GlobalTrajectoryParameters & globalParameters() const
double transverseCurvature() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
BasicTrajectoryState(const GlobalTrajectoryParameters &par, const SurfaceType &aSurface, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
GlobalVector globalMomentum() const
BasicTrajectoryState(const GlobalTrajectoryParameters &par, const CartesianTrajectoryError &err, const SurfaceType &aSurface, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
const LocalTrajectoryParameters & localParameters() const
#define update(a, b)
virtual bool canUpdateLocalParameters() const
LocalVector localDirection() const
LocalVector localMomentum() const
const CurvilinearTrajectoryError & curvilinearError() const
#define UNLIKELY(x)
Definition: Likely.h:21
BasicTrajectoryState(const FreeTrajectoryState &fts)
long double T
ProxyBase11< BTSOS > Proxy
BasicTrajectoryState BTSOS