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