Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CompositeTECWedge.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "ForwardDiskSectorBuilderFromDet.h"
0006 #include "LayerCrossingSide.h"
0007 #include "DetGroupMerger.h"
0008 #include "CompatibleDetToGroupAdder.h"
0009 
0010 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
0011 
0012 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
0013 #include "TrackingTools/DetLayers/interface/MeasurementEstimator.h"
0014 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
0015 
0016 #include "TkDetUtil.h"
0017 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
0018 
0019 using namespace std;
0020 
0021 typedef GeometricSearchDet::DetWithState DetWithState;
0022 
0023 // --------- Temporary solution. DetSorting.h has to be used.
0024 namespace {
0025   class DetPhiLess {
0026   public:
0027     bool operator()(const GeomDet* a, const GeomDet* b) { return Geom::phiLess(a->surface(), b->surface()); }
0028   };
0029 }  // namespace
0030 // ---------------------
0031 
0032 CompositeTECWedge::CompositeTECWedge(vector<const GeomDet*>& innerDets, vector<const GeomDet*>& outerDets)
0033     : theFrontDets(innerDets.begin(), innerDets.end()), theBackDets(outerDets.begin(), outerDets.end()) {
0034   theDets.assign(theFrontDets.begin(), theFrontDets.end());
0035   theDets.insert(theDets.end(), theBackDets.begin(), theBackDets.end());
0036 
0037   //
0038   std::sort(theFrontDets.begin(), theFrontDets.end(), DetPhiLess());
0039   std::sort(theBackDets.begin(), theBackDets.end(), DetPhiLess());
0040 
0041   theFrontSector = ForwardDiskSectorBuilderFromDet()(theFrontDets);
0042   theBackSector = ForwardDiskSectorBuilderFromDet()(theBackDets);
0043   theDiskSector = ForwardDiskSectorBuilderFromDet()(theDets);
0044 
0045   //--------- DEBUG INFO --------------
0046   LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECWedge"
0047                           << "\n"
0048                           << "TECWedge z, perp,innerRadius,outerR: " << this->position().z() << " , "
0049                           << this->position().perp() << " , " << theDiskSector->innerRadius() << " , "
0050                           << theDiskSector->outerRadius();
0051 
0052   for (vector<const GeomDet*>::const_iterator it = theFrontDets.begin(); it != theFrontDets.end(); it++) {
0053     LogDebug("TkDetLayers") << "frontDet phi,z,r: " << (*it)->surface().position().phi() << " , "
0054                             << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
0055   }
0056 
0057   for (vector<const GeomDet*>::const_iterator it = theBackDets.begin(); it != theBackDets.end(); it++) {
0058     LogDebug("TkDetLayers") << "backDet phi,z,r: " << (*it)->surface().phi() << " , " << (*it)->surface().position().z()
0059                             << " , " << (*it)->surface().position().perp();
0060   }
0061   //-----------------------------------
0062 }
0063 
0064 CompositeTECWedge::~CompositeTECWedge() {}
0065 
0066 const vector<const GeometricSearchDet*>& CompositeTECWedge::components() const {
0067   throw DetLayerException("CompositeTECWedge doesn't have GeometricSearchDet components");
0068 }
0069 
0070 pair<bool, TrajectoryStateOnSurface> CompositeTECWedge::compatible(const TrajectoryStateOnSurface& ts,
0071                                                                    const Propagator&,
0072                                                                    const MeasurementEstimator&) const {
0073   edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECWedge::compatible()!!";
0074   return pair<bool, TrajectoryStateOnSurface>();
0075 }
0076 
0077 void CompositeTECWedge::groupedCompatibleDetsV(const TrajectoryStateOnSurface& tsos,
0078                                                const Propagator& prop,
0079                                                const MeasurementEstimator& est,
0080                                                std::vector<DetGroup>& result) const {
0081   SubLayerCrossings crossings = computeCrossings(tsos, prop.propagationDirection());
0082   if (!crossings.isValid())
0083     return;
0084 
0085   std::vector<DetGroup> closestResult;
0086   addClosest(tsos, prop, est, crossings.closest(), closestResult);
0087 
0088   LogDebug("TkDetLayers") << "in CompositeTECWedge::groupedCompatibleDets,closestResult.size(): "
0089                           << closestResult.size();
0090 
0091   if (closestResult.empty())
0092     return;
0093 
0094   DetGroupElement closestGel(closestResult.front().front());
0095   auto window = tkDetUtil::computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
0096 
0097   searchNeighbors(tsos, prop, est, crossings.closest(), window, closestResult, false);
0098 
0099   std::vector<DetGroup> nextResult;
0100   searchNeighbors(tsos, prop, est, crossings.other(), window, nextResult, true);
0101 
0102   int crossingSide = LayerCrossingSide().endcapSide(closestGel.trajectoryState(), prop);
0103   DetGroupMerger::orderAndMergeTwoLevels(
0104       std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
0105 }
0106 
0107 // private methods for the implementation of groupedCompatibleDets()
0108 
0109 SubLayerCrossings CompositeTECWedge::computeCrossings(const TrajectoryStateOnSurface& startingState,
0110                                                       PropagationDirection propDir) const {
0111   HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
0112   HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
0113 
0114   auto rho = startingState.transverseCurvature();
0115 
0116   HelixForwardPlaneCrossing crossing(startPos, startDir, rho, propDir);
0117 
0118   pair<bool, double> frontPath = crossing.pathLength(*theFrontSector);
0119   if (!frontPath.first)
0120     return SubLayerCrossings();
0121 
0122   pair<bool, double> backPath = crossing.pathLength(*theBackSector);
0123   if (!backPath.first)
0124     return SubLayerCrossings();
0125 
0126   GlobalPoint gFrontPoint(crossing.position(frontPath.second));
0127   GlobalPoint gBackPoint(crossing.position(backPath.second));
0128 
0129   LogDebug("TkDetLayers") << "in TECWedge,front crossing r,z,phi: (" << gFrontPoint.perp() << "," << gFrontPoint.z()
0130                           << "," << gFrontPoint.phi() << ")";
0131 
0132   LogDebug("TkDetLayers") << "in TECWedge,back crossing r,z,phi: (" << gBackPoint.perp() << "," << gBackPoint.z() << ","
0133                           << gBackPoint.phi() << ")" << endl;
0134 
0135   int frontIndex = findClosestDet(gFrontPoint, 0);
0136   SubLayerCrossing frontSLC(0, frontIndex, gFrontPoint);
0137 
0138   int backIndex = findClosestDet(gBackPoint, 1);
0139   SubLayerCrossing backSLC(1, backIndex, gBackPoint);
0140 
0141   auto frontDist = std::abs(Geom::deltaPhi(gFrontPoint.barePhi(), theFrontDets[frontIndex]->surface().phi()));
0142   /*
0143     float frontDist = theFrontDets[frontIndex]->surface().phi()  - gFrontPoint.phi(); 
0144     frontDist *= Geom::phiLess( theFrontDets[frontIndex]->surface().phi(),gFrontPoint.barePhi()) ? -1. : 1.; 
0145     if (frontDist < 0.) { frontDist += 2.*Geom::pi();}
0146   */
0147   auto backDist = std::abs(Geom::deltaPhi(gBackPoint.barePhi(), theBackDets[backIndex]->surface().phi()));
0148   /*
0149     float backDist = theBackDets[backIndex]->surface().phi()  - gBackPoint.phi(); 
0150     backDist  *= Geom::phiLess( theBackDets[backIndex]->surface().phi(),gBackPoint.barePhi()) ? -1. : 1.;
0151     if ( backDist < 0.) { backDist  += 2.*Geom::pi();}
0152   */
0153 
0154   if (frontDist < backDist) {
0155     return SubLayerCrossings(frontSLC, backSLC, 0);
0156   } else {
0157     return SubLayerCrossings(backSLC, frontSLC, 1);
0158   }
0159 }
0160 
0161 bool CompositeTECWedge::addClosest(const TrajectoryStateOnSurface& tsos,
0162                                    const Propagator& prop,
0163                                    const MeasurementEstimator& est,
0164                                    const SubLayerCrossing& crossing,
0165                                    vector<DetGroup>& result) const {
0166   const vector<const GeomDet*>& sWedge(subWedge(crossing.subLayerIndex()));
0167 
0168   LogDebug("TkDetLayers") << "in CompositeTECWedge,adding GeomDet at r,z,phi: ("
0169                           << sWedge[crossing.closestDetIndex()]->position().perp() << ","
0170                           << sWedge[crossing.closestDetIndex()]->position().z() << ","
0171                           << sWedge[crossing.closestDetIndex()]->position().phi() << ")";
0172 
0173   return CompatibleDetToGroupAdder().add(*sWedge[crossing.closestDetIndex()], tsos, prop, est, result);
0174 }
0175 
0176 void CompositeTECWedge::searchNeighbors(const TrajectoryStateOnSurface& tsos,
0177                                         const Propagator& prop,
0178                                         const MeasurementEstimator& est,
0179                                         const SubLayerCrossing& crossing,
0180                                         float window,
0181                                         vector<DetGroup>& result,
0182                                         bool checkClosest) const {
0183   const GlobalPoint& gCrossingPos = crossing.position();
0184 
0185   const vector<const GeomDet*>& sWedge(subWedge(crossing.subLayerIndex()));
0186 
0187   int closestIndex = crossing.closestDetIndex();
0188   int negStartIndex = closestIndex - 1;
0189   int posStartIndex = closestIndex + 1;
0190 
0191   if (checkClosest) {  // must decide if the closest is on the neg or pos side
0192     if (Geom::phiLess(gCrossingPos.barePhi(), sWedge[closestIndex]->surface().phi())) {
0193       posStartIndex = closestIndex;
0194     } else {
0195       negStartIndex = closestIndex;
0196     }
0197   }
0198 
0199   typedef CompatibleDetToGroupAdder Adder;
0200   for (int idet = negStartIndex; idet >= 0; idet--) {
0201     //if(idet <0 || idet>=sWedge.size()) {edm::LogInfo(TkDetLayers) << "==== warning! gone out vector bounds.idet: " << idet ;break;}
0202     if (!tkDetUtil::overlapInPhi(gCrossingPos, *sWedge[idet], window))
0203       break;
0204     if (!Adder::add(*sWedge[idet], tsos, prop, est, result))
0205       break;
0206   }
0207   for (int idet = posStartIndex; idet < static_cast<int>(sWedge.size()); idet++) {
0208     //if(idet <0 || idet>=sWedge.size()) {edm::LogInfo(TkDetLayers) << "==== warning! gone out vector bounds.idet: " << idet ;break;}
0209     if (!tkDetUtil::overlapInPhi(gCrossingPos, *sWedge[idet], window))
0210       break;
0211     if (!Adder::add(*sWedge[idet], tsos, prop, est, result))
0212       break;
0213   }
0214 }
0215 
0216 int CompositeTECWedge::findClosestDet(const GlobalPoint& startPos, int sectorId) const {
0217   vector<const GeomDet*> const& myDets = sectorId == 0 ? theFrontDets : theBackDets;
0218 
0219   int close = 0;
0220   auto closeDist = std::abs((myDets.front()->toLocal(startPos)).x());
0221   for (unsigned int i = 1; i < myDets.size(); i++) {
0222     auto dist = std::abs((myDets[i]->toLocal(startPos)).x());
0223     if (dist < closeDist) {
0224       close = i;
0225       closeDist = dist;
0226     }
0227   }
0228   return close;
0229 }