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 
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
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) {
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,
100  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface)
101  : theFreeState(fts),
102  theLocalError(InvalidError()),
103  theLocalParameters(),
104  theLocalParametersValid(false),
105  theValid(true),
106  theSurfaceSide(side),
107  theSurfaceP(&aSurface),
108  theWeight(1.) {}
109 
113  : theFreeState(fts),
114  theLocalError(InvalidError()),
115  theLocalParameters(),
116  theLocalParametersValid(false),
117  theValid(true),
118  theWeight(1.) {}
119 
125  const LocalTrajectoryError& err,
126  const SurfaceType& aSurface,
127  const MagneticField* field,
128  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
129 
134  const SurfaceType& aSurface,
135  const MagneticField* field,
136  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface)
137  : BasicTrajectoryState(par, InvalidError(), aSurface, field, side) {}
138 
143  const CartesianTrajectoryError& err,
144  const SurfaceType& aSurface,
145  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface)
146  : theFreeState(par, err),
147  theLocalError(InvalidError()),
148  theLocalParameters(),
149  theLocalParametersValid(false),
150  theValid(true),
151  theSurfaceSide(side),
152  theSurfaceP(&aSurface),
153  theWeight(1.) {}
154 
160  const CurvilinearTrajectoryError& err,
161  const SurfaceType& aSurface,
162  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface)
163  : theFreeState(par, err),
164  theLocalError(InvalidError()),
165  theLocalParameters(),
166  theLocalParametersValid(false),
167  theValid(true),
168  theSurfaceSide(side),
169  theSurfaceP(&aSurface),
170  theWeight(1.) {}
171 
176  const SurfaceType& aSurface,
177  const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface)
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
189  const GlobalTrajectoryParameters& globalParameters() const { return theFreeState.parameters(); }
190  GlobalPoint globalPosition() const { return theFreeState.position(); }
191  GlobalVector globalMomentum() const { return theFreeState.momentum(); }
192  GlobalVector globalDirection() const { return theFreeState.momentum().unit(); }
193  TrackCharge charge() const { return theFreeState.charge(); }
194  double signedInverseMomentum() const { return theFreeState.signedInverseMomentum(); }
195  double transverseCurvature() const { return theFreeState.transverseCurvature(); }
196 
198  if
199  UNLIKELY(!hasError()) {
200  missingError(" accesing cartesian error.");
201  return CartesianTrajectoryError();
202  }
203  return freeTrajectoryState(true)->cartesianError();
204  }
206  if
207  UNLIKELY(!hasError()) {
208  missingError(" accesing curvilinearerror.");
209  static const CurvilinearTrajectoryError crap;
210  return crap;
211  }
212  return freeTrajectoryState(true)->curvilinearError();
213  }
214 
215  FreeTrajectoryState const* freeTrajectoryState(bool withErrors = true) const {
216  if
217  UNLIKELY(!isValid()) notValid();
218  if (withErrors && hasError()) { // this is the right thing
219  checkCurvilinError();
220  }
221  return &theFreeState;
222  }
223 
224  const MagneticField* magneticField() const { return &theFreeState.parameters().magneticField(); }
225 
226  // access local parameters/errors
228  if
229  UNLIKELY(!isValid()) notValid();
230  if
231  UNLIKELY(!theLocalParametersValid)
232  createLocalParameters();
233  return theLocalParameters;
234  }
235  LocalPoint localPosition() const { return localParameters().position(); }
236  LocalVector localMomentum() const { return localParameters().momentum(); }
237  LocalVector localDirection() const { return localMomentum().unit(); }
238 
240  if
241  UNLIKELY(!hasError()) {
242  missingError(" accessing local error.");
243  return theLocalError;
244  }
245  if
246  UNLIKELY(theLocalError.invalid()) createLocalError();
247  return theLocalError;
248  }
249 
250  const SurfaceType& surface() const { return *theSurfaceP; }
251 
252  double weight() const { return theWeight; }
253 
254  void rescaleError(double factor);
255 
257  SurfaceSide surfaceSide() const { return theSurfaceSide; }
258 
259  bool hasError() const { return theFreeState.hasError() || theLocalError.valid(); }
260 
261  virtual bool canUpdateLocalParameters() const { return true; }
262 
263  virtual void update(const LocalTrajectoryParameters& p,
264  const SurfaceType& aSurface,
265  const MagneticField* field,
266  const SurfaceSide side);
267 
268  // update in place and in the very same place
269  virtual void update(const LocalTrajectoryParameters& p, const SurfaceSide side) final;
270 
271  virtual void update(double weight,
272  const LocalTrajectoryParameters& p,
273  const LocalTrajectoryError& err,
274  const SurfaceType& aSurface,
275  const MagneticField* field,
276  const SurfaceSide side);
277 
278  // update in place and in the very same place
279  virtual void update(const LocalTrajectoryParameters& p,
280  const LocalTrajectoryError& err,
281  const SurfaceSide side) final;
282 
283  CurvilinearTrajectoryError& setCurvilinearError() { return theFreeState.setCurvilinearError(); }
284 
285 public:
286  using Components = std::vector<TrajectoryStateOnSurface>;
287  virtual Components const& components() const = 0;
288  virtual bool singleState() const = 0;
289 
290 private:
291  static void notValid();
292 
293  void missingError(char const* where) const; // dso_internal;
294 
295  // create global errors from local
296  void checkCurvilinError() const; // dso_internal;
297 
298  // create local parameters and errors from global
299  void createLocalParameters() const;
300  // create local errors from global
301  void createLocalError() const;
302  void createLocalErrorFromCurvilinearError() const dso_internal;
303 
304 private:
305  mutable FreeTrajectoryState theFreeState;
306 
307  mutable LocalTrajectoryError theLocalError;
308  mutable LocalTrajectoryParameters theLocalParameters;
309 
310  mutable bool theLocalParametersValid;
311  mutable bool theValid;
312 
313  SurfaceSide theSurfaceSide;
314  ConstReferenceCountingPointer<SurfaceType> theSurfaceP;
315 
316  double theWeight = 0.;
317 };
318 
319 #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:25
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:54
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