Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:10

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 
0050 namespace {
0051   inline void print(const char* where, const TrajectoryStateOnSurface& t1, const TrajectoryStateOnSurface& t2) {
0052     std::cout << where << std::endl;
0053     std::cout << t1.localParameters().vector() << std::endl;
0054     std::cout << t1.localError().positionError() << std::endl;
0055     std::cout << t2.localParameters().vector() << std::endl;
0056     std::cout << t2.localError().positionError() << std::endl;
0057   }
0058 }  // namespace
0059 
0060 template <typename Collector>
0061 void TkGluedMeasurementDet::doubleMatch(const TrajectoryStateOnSurface& ts,
0062                                         const MeasurementTrackerEvent& data,
0063                                         Collector& collector) const {
0064   GlobalVector glbDir = (ts.isValid() ? ts.globalMomentum() : position() - GlobalPoint(0, 0, 0));
0065 
0066   //  static SiStripRecHitMatcher::SimpleHitCollection vsStereoHits;
0067   // vsStereoHits.resize(simpleSteroHitsByValue.size());
0068   //std::transform(simpleSteroHitsByValue.begin(), simpleSteroHitsByValue.end(), vsStereoHits.begin(), take_address());
0069 
0070   std::vector<SiStripRecHit2D> monoHits;
0071   std::vector<SiStripRecHit2D> stereoHits;
0072 
0073   auto mf = monoHits.size();
0074   auto sf = stereoHits.size();
0075 
0076   bool emptyMono = false;
0077   bool emptyStereo = false;
0078 
0079   // FIXME  clean this and optimize the rest of the code once understood and validated
0080   if (true) {  // collector.filter()) {
0081     emptyMono = theMonoDet->empty(data);
0082     if LIKELY (!emptyMono) {
0083       // mono does require "projection" for precise estimate
0084       TrajectoryStateOnSurface mts = fastProp(ts, geomDet().surface(), theMonoDet->geomDet().surface());
0085       if LIKELY (mts.isValid())
0086         theMonoDet->simpleRecHits(mts, collector.estimator(), data, monoHits);
0087     }
0088     // print("mono", mts,ts);
0089     mf = monoHits.size();
0090   } else {
0091     theMonoDet->simpleRecHits(ts, data, monoHits);
0092     emptyMono = monoHits.empty();
0093   }
0094 
0095   // stereo requires "projection" for precision and change in coordinates
0096   if (collector.filter()) {
0097     emptyStereo = theStereoDet->empty(data);
0098     if LIKELY (!emptyStereo) {
0099       TrajectoryStateOnSurface pts = fastProp(ts, geomDet().surface(), theStereoDet->geomDet().surface());
0100       if LIKELY (pts.isValid())
0101         theStereoDet->simpleRecHits(pts, collector.estimator(), data, stereoHits);
0102       // print("stereo", pts,ts);
0103     }
0104     sf = stereoHits.size();
0105   } else {
0106     theStereoDet->simpleRecHits(ts, data, stereoHits);
0107     emptyStereo = stereoHits.empty();
0108   }
0109 
0110   if (collector.filter()) {
0111     auto mh = monoHits.size();
0112     auto sh = stereoHits.size();
0113     stat(mh, sh, mf, sf);
0114   }
0115 
0116   if UNLIKELY (emptyMono & emptyStereo)
0117     return;
0118 
0119   if UNLIKELY (emptyStereo) {
0120     // make mono TTRHs and project them
0121     projectOnGluedDet(collector, monoHits, glbDir);
0122     return;
0123   }
0124 
0125   if UNLIKELY (emptyMono) {
0126     // make stereo TTRHs and project them
0127     projectOnGluedDet(collector, stereoHits, glbDir);
0128     return;
0129   }
0130 
0131   if ((!monoHits.empty()) && (!stereoHits.empty())) {
0132     const GluedGeomDet* gluedDet = &specificGeomDet();
0133     LocalVector trdir = (ts.isValid() ? ts.localDirection() : surface().toLocal(position() - GlobalPoint(0, 0, 0)));
0134 
0135     CollectorHelper<Collector> chelper(collector, glbDir);
0136     theMatcher->doubleMatch(
0137         monoHits.begin(), monoHits.end(), stereoHits.begin(), stereoHits.end(), gluedDet, trdir, chelper);
0138   }
0139 
0140   if (ts.globalMomentum().perp2() > collector.estimator().minPt2ForHitRecoveryInGluedDet()) {
0141     // if no match found try add mon than try to add stereo...
0142     if (0 == collector.size())
0143       projectOnGluedDet(collector, monoHits, glbDir);
0144     if (0 == collector.size())
0145       projectOnGluedDet(collector, stereoHits, glbDir);
0146   }
0147   /*
0148   // recover hits outside 
0149   if ( collector.filter() && 0==collector.size())  {
0150     auto inoutM = reinterpret_cast<RectangularPlaneBounds const&>(theMonoDet->surface().bounds()).inout(ts.localPosition(), 
0151                                                     ts.localError().positionError() ,3.f);
0152     auto inoutS = reinterpret_cast<RectangularPlaneBounds const&>(theStereoDet->surface().bounds()).inout(pts.localPosition(), 
0153                                                       pts.localError().positionError() ,3.f);
0154     if (inoutM.first&&inoutS.second)
0155       projectOnGluedDet( collector, monoHits, glbDir);
0156     if (inoutM.second&&inoutS.first)
0157       projectOnGluedDet( collector, stereoHits, glbDir);
0158   }
0159   */
0160 
0161   if (collector.filter()) {
0162     stat.match(collector.size());
0163   }
0164 }