Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-12 09:07:55

0001 #include "Phase2EndcapSingleRing.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
0006 #include "TrackingTools/DetLayers/interface/MeasurementEstimator.h"
0007 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
0008 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
0009 #include "TrackingTools/DetLayers/interface/ForwardRingDiskBuilderFromDet.h"
0010 
0011 #include "LayerCrossingSide.h"
0012 #include "DetGroupMerger.h"
0013 #include "CompatibleDetToGroupAdder.h"
0014 
0015 #include "TkDetUtil.h"
0016 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
0017 
0018 #include "DetGroupElementZLess.h"
0019 
0020 using namespace std;
0021 
0022 typedef GeometricSearchDet::DetWithState DetWithState;
0023 
0024 Phase2EndcapSingleRing::Phase2EndcapSingleRing(vector<const GeomDet*>& allDets)
0025     : GeometricSearchDet(true), theDets(allDets.begin(), allDets.end()) {
0026   theDisk = ForwardRingDiskBuilderFromDet()(theDets);
0027 
0028   theBinFinder = BinFinderType(theDets.front()->surface().position().phi(), theDets.size());
0029 
0030 #ifdef EDM_ML_DEBUG
0031   LogDebug("TkDetLayers") << "DEBUG INFO for Phase2EndcapSingleRing";
0032   for (vector<const GeomDet*>::const_iterator it = theDets.begin(); it != theDets.end(); it++) {
0033     LogDebug("TkDetLayers") << "Det detId,phi,z,r: " << (*it)->geographicalId().rawId() << " , "
0034                             << (*it)->surface().position().phi() << " , " << (*it)->surface().position().z() << " , "
0035                             << (*it)->surface().position().perp();
0036   }
0037 
0038 #endif
0039 }
0040 
0041 Phase2EndcapSingleRing::~Phase2EndcapSingleRing() = default;
0042 
0043 const vector<const GeometricSearchDet*>& Phase2EndcapSingleRing::components() const {
0044   throw DetLayerException("Phase2EndcapSingleRing doesn't have GeometricSearchDet components");
0045 }
0046 
0047 pair<bool, TrajectoryStateOnSurface> Phase2EndcapSingleRing::compatible(const TrajectoryStateOnSurface&,
0048                                                                         const Propagator&,
0049                                                                         const MeasurementEstimator&) const {
0050   edm::LogError("TkDetLayers") << "temporary dummy implementation of Phase2EndcapSingleRing::compatible()!!";
0051   return pair<bool, TrajectoryStateOnSurface>();
0052 }
0053 
0054 void Phase2EndcapSingleRing::groupedCompatibleDetsV(const TrajectoryStateOnSurface& tsos,
0055                                                     const Propagator& prop,
0056                                                     const MeasurementEstimator& est,
0057                                                     std::vector<DetGroup>& result) const {
0058   SubLayerCrossing crossing;
0059 
0060   crossing = computeCrossing(tsos, prop.propagationDirection());
0061 
0062   if (!crossing.isValid())
0063     return;
0064 
0065   std::vector<DetGroup> closestResult;
0066 
0067   addClosest(tsos, prop, est, crossing, closestResult);
0068   if (closestResult.empty())
0069     return;
0070 
0071   DetGroupElement closestGel(closestResult.front().front());
0072 
0073   float phiWindow = tkDetUtil::computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
0074 
0075   searchNeighbors(tsos, prop, est, crossing, phiWindow, closestResult, false);
0076 
0077   DetGroupMerger::addSameLevel(std::move(closestResult), result);
0078 }
0079 
0080 SubLayerCrossing Phase2EndcapSingleRing::computeCrossing(const TrajectoryStateOnSurface& startingState,
0081                                                          PropagationDirection propDir) const {
0082   auto rho = startingState.transverseCurvature();
0083 
0084   HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
0085   HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
0086   HelixForwardPlaneCrossing crossing(startPos, startDir, rho, propDir);
0087 
0088   pair<bool, double> frontPath = crossing.pathLength(*theDisk);
0089   if (!frontPath.first)
0090     return SubLayerCrossing();
0091 
0092   GlobalPoint gFrontPoint(crossing.position(frontPath.second));  //There is only one path
0093 
0094   int frontIndex = theBinFinder.binIndex(gFrontPoint.barePhi());
0095   SubLayerCrossing frontSLC(0, frontIndex, gFrontPoint);
0096 
0097   return frontSLC;
0098 }
0099 
0100 bool Phase2EndcapSingleRing::addClosest(const TrajectoryStateOnSurface& tsos,
0101                                         const Propagator& prop,
0102                                         const MeasurementEstimator& est,
0103                                         const SubLayerCrossing& crossing,
0104                                         vector<DetGroup>& result) const {
0105   const vector<const GeomDet*>& sub(subLayer(crossing.subLayerIndex()));
0106 
0107   const GeomDet* det(sub[crossing.closestDetIndex()]);
0108 
0109   bool firstgroup = CompatibleDetToGroupAdder::add(*det, tsos, prop, est, result);
0110 
0111   return firstgroup;
0112 }
0113 
0114 void Phase2EndcapSingleRing::searchNeighbors(const TrajectoryStateOnSurface& tsos,
0115                                              const Propagator& prop,
0116                                              const MeasurementEstimator& est,
0117                                              const SubLayerCrossing& crossing,
0118                                              float window,
0119                                              vector<DetGroup>& result,
0120                                              bool checkClosest) const {
0121   const GlobalPoint& gCrossingPos = crossing.position();
0122 
0123   const vector<const GeomDet*>& sLayer(subLayer(crossing.subLayerIndex()));
0124 
0125   int closestIndex = crossing.closestDetIndex();
0126   int negStartIndex = closestIndex - 1;
0127   int posStartIndex = closestIndex + 1;
0128 
0129   if (checkClosest) {  // must decide if the closest is on the neg or pos side
0130     if (Geom::phiLess(gCrossingPos.barePhi(), sLayer[closestIndex]->surface().phi())) {
0131       posStartIndex = closestIndex;
0132     } else {
0133       negStartIndex = closestIndex;
0134     }
0135   }
0136 
0137   const BinFinderType& binFinder = theBinFinder;
0138 
0139   typedef CompatibleDetToGroupAdder Adder;
0140   int half = sLayer.size() / 2;  // to check if dets are called twice....
0141   for (int idet = negStartIndex; idet >= negStartIndex - half; idet--) {
0142     const GeomDet& neighborDet = *sLayer[binFinder.binIndex(idet)];
0143     if (!tkDetUtil::overlapInPhi(gCrossingPos, neighborDet, window))
0144       break;
0145     if (!Adder::add(neighborDet, tsos, prop, est, result))
0146       break;
0147   }
0148   for (int idet = posStartIndex; idet < posStartIndex + half; idet++) {
0149     const GeomDet& neighborDet = *sLayer[binFinder.binIndex(idet)];
0150     if (!tkDetUtil::overlapInPhi(gCrossingPos, neighborDet, window))
0151       break;
0152     if (!Adder::add(neighborDet, tsos, prop, est, result))
0153       break;
0154   }
0155 }