Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-12 03:09:54

0001 #ifndef OptimalHelixPlaneCrossing_H
0002 #define OptimalHelixPlaneCrossing_H
0003 
0004 #include "TrackingTools/GeomPropagators/interface/HelixBarrelPlaneCrossingByCircle.h"
0005 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
0006 #include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing.h"
0007 
0008 #include <memory>
0009 
0010 class OptimalHelixPlaneCrossing {
0011 public:
0012   using Base = HelixPlaneCrossing;
0013 
0014   template <typename... Args>
0015   OptimalHelixPlaneCrossing(Plane const &plane, Args &&...args) {
0016     GlobalVector u = plane.normalVector();
0017     constexpr float small = 1.e-6;  // for orientation of planes
0018 
0019     if (std::abs(u.z()) < small) {
0020       // barrel plane:
0021       // instantiate HelixBarrelPlaneCrossing,
0022       new (get()) HelixBarrelPlaneCrossingByCircle(args...);
0023     } else if ((std::abs(u.x()) < small) & (std::abs(u.y()) < small)) {
0024       // forward plane:
0025       // instantiate HelixForwardPlaneCrossing
0026       new (get()) HelixForwardPlaneCrossing(args...);
0027     } else {
0028       // arbitrary plane:
0029       // instantiate HelixArbitraryPlaneCrossing
0030       new (get()) HelixArbitraryPlaneCrossing(args...);
0031     }
0032   }
0033 
0034   ~OptimalHelixPlaneCrossing() { get()->~Base(); }
0035 
0036   Base &operator*() { return *get(); }
0037   Base const &operator*() const { return *get(); }
0038 
0039 private:
0040   Base *get() { return (Base *)&mem; }
0041   Base const *get() const { return (Base const *)&mem; }
0042 
0043   union Tmp {
0044     HelixBarrelPlaneCrossingByCircle a;
0045     HelixForwardPlaneCrossing b;
0046     HelixArbitraryPlaneCrossing c;
0047   };
0048   using aligned_union_t = typename std::aligned_storage<sizeof(Tmp), alignof(Tmp)>::type;
0049   aligned_union_t mem;
0050 };
0051 
0052 #endif