Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:39

0001 //#define EDM_ML_DEBUG
0002 
0003 /** \file
0004  *
0005  *  \author L. Gray - FNAL
0006  */
0007 
0008 #include "RecoMTD/DetLayers/interface/MTDDetRing.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 #include <vector>
0016 
0017 using namespace std;
0018 
0019 MTDDetRing::MTDDetRing(vector<const GeomDet*>::const_iterator first, vector<const GeomDet*>::const_iterator last)
0020     : ForwardDetRingOneZ(first, last) {
0021   init();
0022 }
0023 
0024 MTDDetRing::MTDDetRing(const vector<const GeomDet*>& vdets) : ForwardDetRingOneZ(vdets) { init(); }
0025 
0026 void MTDDetRing::init() {
0027   theBinFinder = BinFinderType(basicComponents().front()->position().phi(), basicComponents().size());
0028 }
0029 
0030 MTDDetRing::~MTDDetRing() {}
0031 
0032 const vector<const GeometricSearchDet*>& MTDDetRing::components() const {
0033   // FIXME dummy impl.
0034   edm::LogError("MTDDetLayers") << "temporary dummy implementation of MTDDetRing::components()!!";
0035   static const vector<const GeometricSearchDet*> result;
0036   return result;
0037 }
0038 
0039 pair<bool, TrajectoryStateOnSurface> MTDDetRing::compatible(const TrajectoryStateOnSurface& ts,
0040                                                             const Propagator& prop,
0041                                                             const MeasurementEstimator& est) const {
0042   TrajectoryStateOnSurface ms = prop.propagate(ts, specificSurface());
0043 
0044 #ifdef EDM_ML_DEBUG
0045   LogTrace("MTDDetLayers") << "MTDDetRing::compatible, Surface at Z: " << specificSurface().position().z()
0046                            << " R1: " << specificSurface().innerRadius() << " R2: " << specificSurface().outerRadius()
0047                            << " TS   at Z,R: " << ts.globalPosition().z() << "," << ts.globalPosition().perp();
0048   if (ms.isValid()) {
0049     LogTrace("MTDDetLayers") << " DEST at Z,R: " << ms.globalPosition().z() << "," << ms.globalPosition().perp()
0050                              << " local Z: " << ms.localPosition().z();
0051   } else {
0052     LogTrace("MTDDetLayers") << " DEST: not valid";
0053   }
0054 #endif
0055 
0056   return make_pair(ms.isValid() and est.estimate(ms, specificSurface()) != 0, ms);
0057 }
0058 
0059 vector<GeometricSearchDet::DetWithState> MTDDetRing::compatibleDets(const TrajectoryStateOnSurface& startingState,
0060                                                                     const Propagator& prop,
0061                                                                     const MeasurementEstimator& est) const {
0062   LogTrace("MTDDetLayers") << "MTDDetRing::compatibleDets, Surface at Z: " << surface().position().z()
0063                            << " R1: " << specificSurface().innerRadius() << " R2: " << specificSurface().outerRadius()
0064                            << " TS at Z,R: " << startingState.globalPosition().z() << ","
0065                            << startingState.globalPosition().perp() << "     DetRing pos." << position();
0066 
0067   vector<DetWithState> result;
0068 
0069   // Propagate and check that the result is within bounds
0070   pair<bool, TrajectoryStateOnSurface> compat = compatible(startingState, prop, est);
0071   if (!compat.first) {
0072     LogTrace("MTDDetLayers") << "    MTDDetRing::compatibleDets: not compatible"
0073                              << "    (should not have been selected!)";
0074     return result;
0075   }
0076 
0077   // Find the most probable destination component
0078   TrajectoryStateOnSurface& tsos = compat.second;
0079   GlobalPoint startPos = tsos.globalPosition();
0080   int closest = theBinFinder.binIndex(startPos.phi());
0081   const vector<const GeomDet*> dets = basicComponents();
0082   LogTrace("MTDDetLayers") << "     MTDDetRing::compatibleDets, closest det: " << closest
0083                            << " Phi: " << dets[closest]->surface().position().phi() << " impactPhi " << startPos.phi();
0084 
0085   // Add this detector, if it is compatible
0086   // NOTE: add performs a null propagation
0087   add(closest, result, tsos, prop, est);
0088 
0089 #ifdef EDM_ML_DEBUG
0090   int nclosest = result.size();
0091   int nnextdet = 0;  // MDEBUG counters
0092 
0093   // Try the neighbors on each side until no more compatible.
0094   float dphi = 0;
0095   if (!result.empty()) {  // If closest is not compatible the next cannot be either
0096     float nSigmas = 3.;
0097     if (result.back().second.hasError()) {
0098       dphi = nSigmas * atan(sqrt(result.back().second.localError().positionError().xx()) /
0099                             result.back().second.globalPosition().perp());
0100     }
0101   } else {
0102     LogTrace("MTDDetLayers") << "     MTDDetRing::compatibleDets, closest not compatible!";
0103     //FIXME:  if closest is not compatible the next cannot be either
0104   }
0105 #endif
0106 
0107   for (int idet = closest + 1; idet < closest + int(dets.size()) / 4 + 1; idet++) {
0108     // FIXME: should use dphi to decide if det must be queried.
0109     // Right now query until not compatible.
0110     int idetp = theBinFinder.binIndex(idet);
0111     {
0112 #ifdef EDM_ML_DEBUG
0113       LogTrace("MTDDetLayers") << "     next det:" << idetp << " at Z: " << dets[idetp]->position().z()
0114                                << " phi: " << dets[idetp]->position().phi() << " FTS phi " << startPos.phi()
0115                                << " max dphi " << dphi;
0116       nnextdet++;
0117 #endif
0118       if (!add(idetp, result, tsos, prop, est))
0119         break;
0120     }
0121   }
0122 
0123   for (int idet = closest - 1; idet > closest - int(dets.size()) / 4 - 1; idet--) {
0124     // FIXME: should use dphi to decide if det must be queried.
0125     // Right now query until not compatible.
0126     int idetp = theBinFinder.binIndex(idet);
0127     {
0128 #ifdef EDM_ML_DEBUG
0129       LogTrace("MTDDetLayers") << "     previous det:" << idetp << " " << idet << " " << closest - dets.size() / 4 - 1
0130                                << " at Z: " << dets[idetp]->position().z() << " phi: " << dets[idetp]->position().phi()
0131                                << " FTS phi " << startPos.phi() << " max dphi" << dphi;
0132       nnextdet++;
0133 #endif
0134       if (!add(idetp, result, tsos, prop, est))
0135         break;
0136     }
0137   }
0138 
0139 #ifdef EDM_ML_DEBUG
0140   LogTrace("MTDDetLayers") << "     MTDDetRing::compatibleDets, size: " << result.size() << " on closest: " << nclosest
0141                            << " # checked dets: " << nnextdet + 1;
0142 
0143   if (result.empty()) {
0144     LogTrace("MTDDetLayers") << "   ***Ring not compatible,should have been discarded before!!!";
0145   }
0146 #endif
0147 
0148   return result;
0149 }
0150 
0151 vector<DetGroup> MTDDetRing::groupedCompatibleDets(const TrajectoryStateOnSurface& startingState,
0152                                                    const Propagator& prop,
0153                                                    const MeasurementEstimator& est) const {
0154   // FIXME should be implemented to allow returning  overlapping chambers
0155   // as separate groups!
0156   edm::LogError("MTDDetLayers") << "dummy implementation of MTDDetRing::groupedCompatibleDets()";
0157   vector<DetGroup> result;
0158   return result;
0159 }