Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-19 23:36:14

0001 //#define EDM_ML_DEBUG
0002 
0003 /** \file
0004  *
0005  *  \author L. Gray - FNAL
0006  */
0007 
0008 #include "RecoMTD/DetLayers/interface/MTDDetTray.h"
0009 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0010 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0011 #include "TrackingTools/DetLayers/interface/MeasurementEstimator.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 #include <iostream>
0015 
0016 using namespace std;
0017 
0018 MTDDetTray::MTDDetTray(vector<const GeomDet*>::const_iterator first, vector<const GeomDet*>::const_iterator last)
0019     : DetRodOneR(first, last) {
0020   init();
0021 }
0022 
0023 MTDDetTray::MTDDetTray(const vector<const GeomDet*>& vdets) : DetRodOneR(vdets) { init(); }
0024 
0025 void MTDDetTray::init() { theBinFinder = BinFinderType(basicComponents().begin(), basicComponents().end()); }
0026 
0027 MTDDetTray::~MTDDetTray() {}
0028 
0029 const vector<const GeometricSearchDet*>& MTDDetTray::components() const {
0030   // FIXME dummy impl.
0031   edm::LogError("MTDDetLayers") << "temporary dummy implementation of MTDDetTray::components()!!";
0032   static const vector<const GeometricSearchDet*> result;
0033   return result;
0034 }
0035 
0036 pair<bool, TrajectoryStateOnSurface> MTDDetTray::compatible(const TrajectoryStateOnSurface& ts,
0037                                                             const Propagator& prop,
0038                                                             const MeasurementEstimator& est) const {
0039   TrajectoryStateOnSurface ms = prop.propagate(ts, specificSurface());
0040   return make_pair(ms.isValid() and est.estimate(ms, specificSurface()) != 0, ms);
0041 }
0042 
0043 vector<GeometricSearchDet::DetWithState> MTDDetTray::compatibleDets(const TrajectoryStateOnSurface& startingState,
0044                                                                     const Propagator& prop,
0045                                                                     const MeasurementEstimator& est) const {
0046   LogTrace("MTDDetLayers") << "MTDDetTray::compatibleDets, Surface at R,phi: " << surface().position().perp() << ","
0047                            << surface().position().phi() << "     DetRod pos.";
0048   // FIXME      << " TS at R,phi: " << startingState.position().perp() << ","
0049   //            << startingState.position().phi()
0050 
0051   vector<DetWithState> result;
0052 
0053   // Propagate and check that the result is within bounds
0054   pair<bool, TrajectoryStateOnSurface> compat = compatible(startingState, prop, est);
0055 
0056   if (!compat.first) {
0057     LogTrace("MTDDetLayers") << "    MTDDetTray::compatibleDets: not compatible"
0058                              << "    (should not have been selected!)";
0059     return result;
0060   }
0061 
0062   // Find the most probable destination component
0063   TrajectoryStateOnSurface& tsos = compat.second;
0064   GlobalPoint startPos = tsos.globalPosition();
0065   int closest = theBinFinder.binIndex(startPos.z());
0066   const vector<const GeomDet*> dets = basicComponents();
0067   LogTrace("MTDDetLayers") << "     MTDDetTray::compatibleDets, closest det: " << closest
0068                            << " pos: " << dets[closest]->surface().position() << " impact " << startPos;
0069 
0070   // Add this detector, if it is compatible
0071   // NOTE: add performs a null propagation
0072   add(closest, result, tsos, prop, est);
0073 
0074 #ifdef EDM_ML_DEBUG
0075   int nclosest = result.size();
0076   int nnextdet = 0;  // just DEBUG counters
0077 #endif
0078 
0079   // Try the neighbors on each side until no more compatible.
0080   // If closest is not compatible the next cannot be either
0081   if (!result.empty()) {
0082     const BoundPlane& closestPlane(dets[closest]->surface());
0083     MeasurementEstimator::Local2DVector maxDistance = est.maximalLocalDisplacement(result.front().second, closestPlane);
0084 
0085     // detHalfLen is assumed to be the same for all detectors.
0086     float detHalfLen = closestPlane.bounds().length() / 2.;
0087 
0088     for (unsigned int idet = closest + 1; idet < dets.size(); idet++) {
0089       LocalPoint nextPos(dets[idet]->toLocal(startPos));
0090       if (fabs(nextPos.y()) < detHalfLen + maxDistance.y()) {
0091 #ifdef EDM_ML_DEBUG
0092         LogTrace("MTDDetLayers") << "     negativeZ: det:" << idet << " pos " << nextPos.y() << " maxDistance "
0093                                  << maxDistance.y();
0094         nnextdet++;
0095 #endif
0096         if (!add(idet, result, tsos, prop, est))
0097           break;
0098       } else {
0099         break;
0100       }
0101     }
0102 
0103     for (int idet = closest - 1; idet >= 0; idet--) {
0104       LocalPoint nextPos(dets[idet]->toLocal(startPos));
0105       if (fabs(nextPos.y()) < detHalfLen + maxDistance.y()) {
0106 #ifdef EDM_ML_DEBUG
0107         LogTrace("MTDDetLayers") << "     positiveZ: det:" << idet << " pos " << nextPos.y() << " maxDistance "
0108                                  << maxDistance.y();
0109         nnextdet++;
0110 #endif
0111         if (!add(idet, result, tsos, prop, est))
0112           break;
0113       } else {
0114         break;
0115       }
0116     }
0117   }
0118 
0119 #ifdef EDM_ML_DEBUG
0120   LogTrace("MTDDetLayers") << "     MTDDetTray::compatibleDets, size: " << result.size() << " on closest: " << nclosest
0121                            << " # checked dets: " << nnextdet + 1;
0122   if (result.empty()) {
0123     LogTrace("MTDDetLayers") << "   ***Rod not compatible---should have been discarded before!!!";
0124   }
0125 #endif
0126   return result;
0127 }
0128 
0129 vector<DetGroup> MTDDetTray::groupedCompatibleDets(const TrajectoryStateOnSurface& startingState,
0130                                                    const Propagator& prop,
0131                                                    const MeasurementEstimator& est) const {
0132   vector<GeometricSearchDet::DetWithState> detWithStates;
0133 
0134   detWithStates = compatibleDets(startingState, prop, est);
0135 
0136   vector<DetGroup> result;
0137   if (!detWithStates.empty()) {
0138     result.push_back(DetGroup(detWithStates));
0139   }
0140   LogTrace("MTDDetLayers") << "MTDdetTray Compatible modules: " << result.size();
0141   return result;
0142 }