CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BasicTrajectoryState.h
Go to the documentation of this file.
1 #ifndef BasicTrajectoryState_H
2 #define BasicTrajectoryState_H
3 
5 
12 
13 #include <vector>
14 
18 
24 
26 // #include <iostream>
27 
28 class MagneticField;
30 
31 #ifdef DO_BTSCount
32 class BTSCount {
33 public:
34  BTSCount() {}
35  virtual ~BTSCount();
36  BTSCount(BTSCount const&) {}
37 
38  static unsigned int maxReferences;
39  static unsigned long long aveReferences;
40  static unsigned long long toteReferences;
41 
42  void addReference() const {
43  ++referenceCount_;
44  referenceMax_ = std::max(referenceMax_, referenceCount_);
45  }
46  void removeReference() const {
47  if (0 == --referenceCount_) {
48  delete const_cast<BTSCount*>(this);
49  }
50  }
51 
52  unsigned int references() const { return referenceCount_; }
53 
54 private:
55  mutable unsigned int referenceCount_ = 0;
56  mutable unsigned int referenceMax_ = 0;
57 };
58 #endif
59 
67 public:
73 
74 public:
75  // default constructor : to make root happy
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) {
87  return std::make_shared<T>(std::forward<Args>(args)...);
88  }
89 
90  template <typename T, typename... Args>
91  static std::shared_ptr<BTSOS> churn(Args&&... args) {
92  return std::allocate_shared<T>(churn_allocator<T>(), std::forward<Args>(args)...);
93  }
94 
99  const SurfaceType& aSurface,
101  : theFreeState(fts),
105  theValid(true),
106  theSurfaceSide(side),
107  theSurfaceP(&aSurface),
108  theWeight(1.) {}
109 
113  : theFreeState(fts),
117  theValid(true),
118  theWeight(1.) {}
119 
125  const LocalTrajectoryError& err,
126  const SurfaceType& aSurface,
127  const MagneticField* field,
129 
134  const SurfaceType& aSurface,
135  const MagneticField* field,
137  : BasicTrajectoryState(par, InvalidError(), aSurface, field, side) {}
138 
144  const SurfaceType& aSurface,
146  : theFreeState(par, err),
150  theValid(true),
151  theSurfaceSide(side),
152  theSurfaceP(&aSurface),
153  theWeight(1.) {}
154 
161  const SurfaceType& aSurface,
163  : theFreeState(par, err),
167  theValid(true),
168  theSurfaceSide(side),
169  theSurfaceP(&aSurface),
170  theWeight(1.) {}
171 
176  const SurfaceType& aSurface,
178  : BasicTrajectoryState(par, InvalidError(), aSurface, side) {}
179 
180  // as above, with explicit weight
181  template <typename... Args>
182  BasicTrajectoryState(double iweight, Args&&... args) : BasicTrajectoryState(std::forward<Args>(args)...) {
183  theWeight = iweight;
184  }
185 
186  bool isValid() const { return theValid; }
187 
188  // access global parameters/errors
193  TrackCharge charge() const { return theFreeState.charge(); }
196 
198  if UNLIKELY (!hasError()) {
199  missingError(" accesing cartesian error.");
200  return CartesianTrajectoryError();
201  }
202  return freeTrajectoryState(true)->cartesianError();
203  }
205  if UNLIKELY (!hasError()) {
206  missingError(" accesing curvilinearerror.");
207  static const CurvilinearTrajectoryError crap;
208  return crap;
209  }
210  return freeTrajectoryState(true)->curvilinearError();
211  }
212 
213  FreeTrajectoryState const* freeTrajectoryState(bool withErrors = true) const {
214  if UNLIKELY (!isValid())
215  notValid();
216  if (withErrors && hasError()) { // this is the right thing
218  }
219  return &theFreeState;
220  }
221 
223 
224  // access local parameters/errors
226  if UNLIKELY (!isValid())
227  notValid();
230  return theLocalParameters;
231  }
235 
237  if UNLIKELY (!hasError()) {
238  missingError(" accessing local error.");
239  return theLocalError;
240  }
243  return theLocalError;
244  }
245 
246  const SurfaceType& surface() const { return *theSurfaceP; }
247 
248  double weight() const { return theWeight; }
249 
250  void rescaleError(double factor);
251 
254 
255  bool hasError() const { return theFreeState.hasError() || theLocalError.valid(); }
256 
257  virtual bool canUpdateLocalParameters() const { return true; }
258 
259  virtual void update(const LocalTrajectoryParameters& p,
260  const SurfaceType& aSurface,
261  const MagneticField* field,
262  const SurfaceSide side);
263 
264  // update in place and in the very same place
265  virtual void update(const LocalTrajectoryParameters& p, const SurfaceSide side) final;
266 
267  virtual void update(double weight,
269  const LocalTrajectoryError& err,
270  const SurfaceType& aSurface,
271  const MagneticField* field,
272  const SurfaceSide side);
273 
274  // update in place and in the very same place
275  virtual void update(const LocalTrajectoryParameters& p,
276  const LocalTrajectoryError& err,
277  const SurfaceSide side) final;
278 
280 
281 public:
282  using Components = std::vector<TrajectoryStateOnSurface>;
283  virtual Components const& components() const = 0;
284  virtual bool singleState() const = 0;
285 
286 private:
287  static void notValid();
288 
289  void missingError(char const* where) const; // dso_internal;
290 
291  // create global errors from local
292  void checkCurvilinError() const; // dso_internal;
293 
294  // create local parameters and errors from global
295  void createLocalParameters() const;
296  // create local errors from global
297  void createLocalError() const;
299 
300 private:
302 
305 
307  mutable bool theValid;
308 
311 
312  double theWeight = 0.;
313 };
314 
315 #endif
GlobalPoint globalPosition() const
ConstReferenceCountingPointer< SurfaceType > theSurfaceP
CurvilinearTrajectoryError & setCurvilinearError()
LocalPoint localPosition() const
virtual bool singleState() const =0
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
CartesianTrajectoryError cartesianError() const
const MagneticField * magneticField() const
SurfaceSideDefinition::SurfaceSide SurfaceSide
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
const GlobalTrajectoryParameters & parameters() const
virtual pointer clone() const =0
LocalPoint position() const
Local x and y position coordinates.
BasicTrajectoryState(const GlobalTrajectoryParameters &par, const CurvilinearTrajectoryError &err, const SurfaceType &aSurface, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
const CartesianTrajectoryError cartesianError() const
virtual void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side)
BasicTrajectoryState(double iweight, Args &&...args)
TrackCharge charge() const
TrackCharge charge() const
std::shared_ptr< T > pointer
Definition: ProxyBase11.h:25
const CurvilinearTrajectoryError & curvilinearError() const
virtual Components const & components() const =0
void rescaleError(double factor)
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)
void createLocalErrorFromCurvilinearError() const
const LocalTrajectoryError & localError() const
BasicTrajectoryState(const FreeTrajectoryState &fts, const SurfaceType &aSurface, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
double signedInverseMomentum() const
void createLocalParameters() const
#define dso_internal
Definition: Visibility.h:13
LocalVector momentum() const
Momentum vector in the local frame.
GlobalVector momentum() const
Vector3DBase unit() const
Definition: Vector3DBase.h:54
GlobalPoint position() const
const SurfaceType & surface() const
static std::shared_ptr< BTSOS > churn(Args &&...args)
const GlobalTrajectoryParameters & globalParameters() const
double transverseCurvature() const
FreeTrajectoryState theFreeState
CurvilinearTrajectoryError & setCurvilinearError()
double transverseCurvature() const
BasicTrajectoryState(const GlobalTrajectoryParameters &par, const SurfaceType &aSurface, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
void missingError(char const *where) const
GlobalVector globalMomentum() const
BasicTrajectoryState(const GlobalTrajectoryParameters &par, const CartesianTrajectoryError &err, const SurfaceType &aSurface, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
const LocalTrajectoryParameters & localParameters() const
LocalTrajectoryParameters theLocalParameters
virtual bool canUpdateLocalParameters() const
LocalVector localDirection() const
const MagneticField & magneticField() const
LocalVector localMomentum() const
const CurvilinearTrajectoryError & curvilinearError() const
#define UNLIKELY(x)
Definition: Likely.h:21
BasicTrajectoryState(const FreeTrajectoryState &fts)
long double T
LocalTrajectoryError theLocalError
ProxyBase11< BTSOS > Proxy
double signedInverseMomentum() const
BasicTrajectoryState BTSOS