Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-13 22:50:12

0001 
0002 
0003 namespace {
0004 
0005   template <typename Collector>
0006   struct CollectorHelper {
0007     Collector& m_collector;
0008     GlobalVector const& glbDir;
0009 
0010     CollectorHelper(Collector& i_collector, GlobalVector const& i_glbDir)
0011         : m_collector(i_collector), glbDir(i_glbDir) {}
0012 
0013     inline static SiStripRecHit2D const& monoHit(TkGluedMeasurementDet::RecHitContainer::const_iterator monoHit) {
0014       return *reinterpret_cast<const SiStripRecHit2D*>((**monoHit).hit());
0015     }
0016 
0017     inline static SiStripRecHit2D const& monoHit(std::vector<SiStripRecHit2D>::const_iterator iter) { return *iter; }
0018 
0019     inline static SiStripRecHit2D const& stereoHit(std::vector<SiStripRecHit2D>::const_iterator iter) { return *iter; }
0020 
0021     inline static SiStripRecHit2D const& stereoHit(TkGluedMeasurementDet::RecHitContainer::const_iterator hit) {
0022       return *reinterpret_cast<const SiStripRecHit2D*>((**hit).hit());
0023     }
0024 
0025     typename Collector::Collector& collector() { return m_collector.collector(); }
0026 
0027     inline void closure(TkGluedMeasurementDet::RecHitContainer::const_iterator monoHit) {
0028       if (m_collector.hasNewMatchedHits()) {
0029         m_collector.clearNewMatchedHitsFlag();
0030       } else {
0031         m_collector.addProjected(**monoHit, glbDir);
0032       }
0033     }
0034 
0035     inline void closure(std::vector<SiStripRecHit2D>::const_iterator monoHit) {
0036       if (m_collector.hasNewMatchedHits()) {
0037         m_collector.clearNewMatchedHitsFlag();
0038       } else {
0039         m_collector.addProjected(*monoHit, glbDir);
0040       }
0041     }
0042   };
0043 
0044 }  // namespace
0045 
0046 #include "RecHitPropagator.h"
0047 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
0048 #include "DataFormats/GeometrySurface/interface/LocalError.h"
0049 #include "DataFormats/Math/interface/logic.h"
0050 
0051 namespace {
0052   inline void print(const char* where, const TrajectoryStateOnSurface& t1, const TrajectoryStateOnSurface& t2) {
0053     std::cout << where << std::endl;
0054     std::cout << t1.localParameters().vector() << std::endl;
0055     std::cout << t1.localError().positionError() << std::endl;
0056     std::cout << t2.localParameters().vector() << std::endl;
0057     std::cout << t2.localError().positionError() << std::endl;
0058   }
0059 }  // namespace
0060 
0061 template <typename Collector>
0062 void TkGluedMeasurementDet::doubleMatch(const TrajectoryStateOnSurface& ts,
0063                                         const MeasurementTrackerEvent& data,
0064                                         Collector& collector) const {
0065   GlobalVector glbDir = (ts.isValid() ? ts.globalMomentum() : position() - GlobalPoint(0, 0, 0));
0066 
0067   //  static SiStripRecHitMatcher::SimpleHitCollection vsStereoHits;
0068   // vsStereoHits.resize(simpleSteroHitsByValue.size());
0069   //std::transform(simpleSteroHitsByValue.begin(), simpleSteroHitsByValue.end(), vsStereoHits.begin(), take_address());
0070 
0071   std::vector<SiStripRecHit2D> monoHits;
0072   std::vector<SiStripRecHit2D> stereoHits;
0073 
0074   auto mf = monoHits.size();
0075   auto sf = stereoHits.size();
0076 
0077   bool emptyMono = false;
0078   bool emptyStereo = false;
0079 
0080   // FIXME  clean this and optimize the rest of the code once understood and validated
0081   if (true) {  // collector.filter()) {
0082     emptyMono = theMonoDet->empty(data);
0083     if LIKELY (!emptyMono) {
0084       // mono does require "projection" for precise estimate
0085       TrajectoryStateOnSurface mts = fastProp(ts, geomDet().surface(), theMonoDet->geomDet().surface());
0086       if LIKELY (mts.isValid())
0087         theMonoDet->simpleRecHits(mts, collector.estimator(), data, monoHits);
0088     }
0089     // print("mono", mts,ts);
0090     mf = monoHits.size();
0091   } else {
0092     theMonoDet->simpleRecHits(ts, data, monoHits);
0093     emptyMono = monoHits.empty();
0094   }
0095 
0096   // stereo requires "projection" for precision and change in coordinates
0097   if (collector.filter()) {
0098     emptyStereo = theStereoDet->empty(data);
0099     if LIKELY (!emptyStereo) {
0100       TrajectoryStateOnSurface pts = fastProp(ts, geomDet().surface(), theStereoDet->geomDet().surface());
0101       if LIKELY (pts.isValid())
0102         theStereoDet->simpleRecHits(pts, collector.estimator(), data, stereoHits);
0103       // print("stereo", pts,ts);
0104     }
0105     sf = stereoHits.size();
0106   } else {
0107     theStereoDet->simpleRecHits(ts, data, stereoHits);
0108     emptyStereo = stereoHits.empty();
0109   }
0110 
0111   if (collector.filter()) {
0112     auto mh = monoHits.size();
0113     auto sh = stereoHits.size();
0114     stat(mh, sh, mf, sf);
0115   }
0116 
0117   if UNLIKELY (emptyMono & emptyStereo)
0118     return;
0119 
0120   if UNLIKELY (emptyStereo) {
0121     // make mono TTRHs and project them
0122     projectOnGluedDet(collector, monoHits, glbDir);
0123     return;
0124   }
0125 
0126   if UNLIKELY (emptyMono) {
0127     // make stereo TTRHs and project them
0128     projectOnGluedDet(collector, stereoHits, glbDir);
0129     return;
0130   }
0131 
0132   if (reco::branchless_and(!monoHits.empty(), !stereoHits.empty())) {
0133     const GluedGeomDet* gluedDet = &specificGeomDet();
0134     LocalVector trdir = (ts.isValid() ? ts.localDirection() : surface().toLocal(position() - GlobalPoint(0, 0, 0)));
0135 
0136     CollectorHelper<Collector> chelper(collector, glbDir);
0137     theMatcher->doubleMatch(
0138         monoHits.begin(), monoHits.end(), stereoHits.begin(), stereoHits.end(), gluedDet, trdir, chelper);
0139   }
0140 
0141   if (ts.globalMomentum().perp2() > collector.estimator().minPt2ForHitRecoveryInGluedDet()) {
0142     // if no match found try add mon than try to add stereo...
0143     if (0 == collector.size())
0144       projectOnGluedDet(collector, monoHits, glbDir);
0145     if (0 == collector.size())
0146       projectOnGluedDet(collector, stereoHits, glbDir);
0147   }
0148   /*
0149   // recover hits outside 
0150   if ( collector.filter() && 0==collector.size())  {
0151     auto inoutM = reinterpret_cast<RectangularPlaneBounds const&>(theMonoDet->surface().bounds()).inout(ts.localPosition(), 
0152                                                     ts.localError().positionError() ,3.f);
0153     auto inoutS = reinterpret_cast<RectangularPlaneBounds const&>(theStereoDet->surface().bounds()).inout(pts.localPosition(), 
0154                                                       pts.localError().positionError() ,3.f);
0155     if (inoutM.first&&inoutS.second)
0156       projectOnGluedDet( collector, monoHits, glbDir);
0157     if (inoutM.second&&inoutS.first)
0158       projectOnGluedDet( collector, stereoHits, glbDir);
0159   }
0160   */
0161 
0162   if (collector.filter()) {
0163     stat.match(collector.size());
0164   }
0165 }