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 
99 
100 
106  const LocalTrajectoryError& err,
107  const SurfaceType& aSurface,
108  const MagneticField* field,
109  const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface);
110 
111 
116  const SurfaceType& aSurface,
117  const MagneticField* field,
118  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface) :
119  BasicTrajectoryState(par, InvalidError(), aSurface, field, side){}
120 
121 
122 
123 
128  const CartesianTrajectoryError& err,
129  const SurfaceType& aSurface,
130  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
131 
137  const CurvilinearTrajectoryError& err,
138  const SurfaceType& aSurface,
139  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface) :
140  theFreeState(par, err),
141  theLocalError(InvalidError()),
142  theLocalParameters(),
143  theLocalParametersValid(false),
144  theValid(true),
145  theSurfaceSide(side),
146  theSurfaceP( &aSurface),
147  theWeight(1.)
148  {}
149 
150 
155  const SurfaceType& aSurface,
156  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface) :
157  BasicTrajectoryState(par, InvalidError(), aSurface, side){}
158 
159 
160  // as above, with explicit weight
161  template<typename... Args>
162  BasicTrajectoryState(double iweight, Args && ...args) : BasicTrajectoryState(std::forward<Args>(args)...) {
163  theWeight = iweight;
164  }
165 
166 
167 
168  bool isValid() const { return theValid; }
169 
170 
171 // access global parameters/errors
173  return theFreeState.parameters();
174  }
176  return theFreeState.position();
177  }
179  return theFreeState.momentum();
180  }
182  return theFreeState.momentum().unit();
183  }
184  TrackCharge charge() const {
185  return theFreeState.charge();
186  }
187  double signedInverseMomentum() const {
188  return theFreeState.signedInverseMomentum();
189  }
190  double transverseCurvature() const {
191  return theFreeState.transverseCurvature();
192  }
193 
195  if unlikely(!hasError()) {
196  missingError(" accesing cartesian error.");
197  return CartesianTrajectoryError();
198  }
199  return freeTrajectoryState(true)->cartesianError();
200  }
202  if unlikely(!hasError()) {
203  missingError(" accesing curvilinearerror.");
204  static const CurvilinearTrajectoryError crap;
205  return crap;
206  }
207  return freeTrajectoryState(true)->curvilinearError();
208  }
209 
210 
211 
212  FreeTrajectoryState const* freeTrajectoryState(bool withErrors=true) const {
213  if unlikely(!isValid()) notValid();
214  if(withErrors && hasError()) { // this is the right thing
215  checkCurvilinError();
216  }
217  return &theFreeState;
218  }
219 
220 
221  const MagneticField *magneticField() const { return &theFreeState.parameters().magneticField(); }
222 
223 // access local parameters/errors
225  if unlikely(!isValid()) notValid();
226  if unlikely(!theLocalParametersValid)
227  createLocalParameters();
228  return theLocalParameters;
229  }
231  return localParameters().position();
232  }
234  return localParameters().momentum();
235  }
237  return localMomentum().unit();
238  }
239 
241  if unlikely(!hasError()) {
242  missingError(" accessing local error.");
243  return theLocalError;
244  }
245  if unlikely(theLocalError.invalid()) createLocalError();
246  return theLocalError;
247  }
248 
249  const SurfaceType& surface() const {
250  return *theSurfaceP;
251  }
252 
253  double weight() const {return theWeight;}
254 
255  void rescaleError(double factor);
256 
257 
258 
260  SurfaceSide surfaceSide() const {
261  return theSurfaceSide;
262  }
263 
264  bool hasError() const {
265  return theFreeState.hasError() || theLocalError.valid();
266  }
267 
268 
269  virtual bool canUpdateLocalParameters() const { return true; }
270 
271  virtual void update( const LocalTrajectoryParameters& p,
272  const SurfaceType& aSurface,
273  const MagneticField* field,
274  const SurfaceSide side ) ;
275 
276  // update in place and in the very same place
277  virtual void update( const LocalTrajectoryParameters& p, const SurfaceSide side ) final;
278 
279 
280 
281  virtual void update( double weight,
282  const LocalTrajectoryParameters& p,
283  const LocalTrajectoryError& err,
284  const SurfaceType& aSurface,
285  const MagneticField* field,
286  const SurfaceSide side);
287 
288  // update in place and in the very same place
289  virtual void update( const LocalTrajectoryParameters& p,
290  const LocalTrajectoryError& err,
291  const SurfaceSide side) final;
292 
294  return theFreeState.setCurvilinearError();
295  }
296 
297 public:
298  using Components = std::vector<TrajectoryStateOnSurface>;
299  virtual Components const & components() const =0;
300  virtual bool singleState() const=0;
301 
302 private:
303 
304  static void notValid();
305 
306 
307  void missingError(char const * where) const; // dso_internal;
308 
309  // create global errors from local
310  void checkCurvilinError() const; // dso_internal;
311 
312  // create local parameters and errors from global
313  void createLocalParameters() const;
314  // create local errors from global
315  void createLocalError() const;
316  void createLocalErrorFromCurvilinearError() const dso_internal;
317 
318 private:
319 
320  mutable FreeTrajectoryState theFreeState;
321 
322  mutable LocalTrajectoryError theLocalError;
323  mutable LocalTrajectoryParameters theLocalParameters;
324 
325  mutable bool theLocalParametersValid;
326  mutable bool theValid;
327 
328 
329  SurfaceSide theSurfaceSide;
330  ConstReferenceCountingPointer<SurfaceType> theSurfaceP;
331 
332  double theWeight=0.;
333 };
334 
335 #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
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
const LocalTrajectoryParameters & localParameters() const
#define update(a, b)
virtual bool canUpdateLocalParameters() const
LocalVector localDirection() const
LocalVector localMomentum() const
const CurvilinearTrajectoryError & curvilinearError() const
long double T
ProxyBase11< BTSOS > Proxy
BasicTrajectoryState BTSOS