Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:02

0001 #include "RecoTracker/TransientTrackingRecHit/interface/TkClonerImpl.h"
0002 
0003 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0004 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
0005 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
0006 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
0007 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
0008 #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h"
0009 #include "DataFormats/TrackerRecHit2D/interface/VectorHit.h"
0010 
0011 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0012 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0013 
0014 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0015 #include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
0016 
0017 #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
0018 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0019 #include "RecoLocalTracker/ClusterParameterEstimator/interface/StripClusterParameterEstimator.h"
0020 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
0021 
0022 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0023 
0024 #include <iostream>
0025 #include <memory>
0026 
0027 std::unique_ptr<SiPixelRecHit> TkClonerImpl::operator()(SiPixelRecHit const& hit,
0028                                                         TrajectoryStateOnSurface const& tsos) const {
0029   const SiPixelCluster& clust = *hit.cluster();
0030   auto&& params = pixelCPE->getParameters(clust, *hit.detUnit(), tsos);
0031   return std::make_unique<SiPixelRecHit>(
0032       std::get<0>(params), std::get<1>(params), std::get<2>(params), *hit.det(), hit.cluster());
0033 }
0034 
0035 std::unique_ptr<SiStripRecHit2D> TkClonerImpl::operator()(SiStripRecHit2D const& hit,
0036                                                           TrajectoryStateOnSurface const& tsos) const {
0037   /// FIXME: this only uses the first cluster and ignores the others
0038   const SiStripCluster& clust = hit.stripCluster();
0039   StripClusterParameterEstimator::LocalValues lv = stripCPE->localParameters(clust, *hit.detUnit(), tsos);
0040   return std::make_unique<SiStripRecHit2D>(lv.first, lv.second, *hit.det(), hit.omniCluster());
0041 }
0042 
0043 std::unique_ptr<SiStripRecHit1D> TkClonerImpl::operator()(SiStripRecHit1D const& hit,
0044                                                           TrajectoryStateOnSurface const& tsos) const {
0045   /// FIXME: this only uses the first cluster and ignores the others
0046   const SiStripCluster& clust = hit.stripCluster();
0047   StripClusterParameterEstimator::LocalValues lv = stripCPE->localParameters(clust, *hit.detUnit(), tsos);
0048   LocalError le(lv.second.xx(), 0., std::numeric_limits<float>::max());  //Correct??
0049   return std::make_unique<SiStripRecHit1D>(lv.first, le, *hit.det(), hit.omniCluster());
0050 }
0051 
0052 std::unique_ptr<Phase2TrackerRecHit1D> TkClonerImpl::operator()(Phase2TrackerRecHit1D const& hit,
0053                                                                 TrajectoryStateOnSurface const& tsos) const {
0054   const Phase2TrackerCluster1D& clust = hit.phase2OTCluster();
0055   const PixelGeomDetUnit& gdu = (const PixelGeomDetUnit&)*(hit.detUnit());
0056   auto&& params = phase2TrackerCPE->localParameters(clust, gdu, tsos);
0057   return std::make_unique<Phase2TrackerRecHit1D>(params.first, params.second, *hit.det(), hit.cluster());
0058 }
0059 
0060 std::unique_ptr<VectorHit> TkClonerImpl::operator()(VectorHit const& hit, TrajectoryStateOnSurface const& tsos) const {
0061   return std::make_unique<VectorHit>(hit);
0062 }
0063 
0064 TrackingRecHit::ConstRecHitPointer TkClonerImpl::makeShared(SiPixelRecHit const& hit,
0065                                                             TrajectoryStateOnSurface const& tsos) const {
0066   // std::cout << "cloning " << typeid(hit).name() << std::endl;
0067   const SiPixelCluster& clust = *hit.cluster();
0068   auto&& params = pixelCPE->getParameters(clust, *hit.detUnit(), tsos);
0069   return std::make_shared<SiPixelRecHit>(
0070       std::get<0>(params), std::get<1>(params), std::get<2>(params), *hit.det(), hit.cluster());
0071 }
0072 
0073 TrackingRecHit::ConstRecHitPointer TkClonerImpl::makeShared(SiStripRecHit2D const& hit,
0074                                                             TrajectoryStateOnSurface const& tsos) const {
0075   // std::cout << "cloning " << typeid(hit).name()  << std::endl;
0076   /// FIXME: this only uses the first cluster and ignores the others
0077   const SiStripCluster& clust = hit.stripCluster();
0078   StripClusterParameterEstimator::LocalValues lv = stripCPE->localParameters(clust, *hit.detUnit(), tsos);
0079   return std::make_shared<SiStripRecHit2D>(lv.first, lv.second, *hit.det(), hit.omniCluster());
0080 }
0081 
0082 TrackingRecHit::ConstRecHitPointer TkClonerImpl::makeShared(SiStripRecHit1D const& hit,
0083                                                             TrajectoryStateOnSurface const& tsos) const {
0084   // std::cout << "cloning " << typeid(hit).name()  << std::endl;
0085   /// FIXME: this only uses the first cluster and ignores the others
0086   const SiStripCluster& clust = hit.stripCluster();
0087   StripClusterParameterEstimator::LocalValues lv = stripCPE->localParameters(clust, *hit.detUnit(), tsos);
0088   LocalError le(lv.second.xx(), 0., std::numeric_limits<float>::max());  //Correct??
0089   return std::make_shared<SiStripRecHit1D>(lv.first, le, *hit.det(), hit.omniCluster());
0090 }
0091 
0092 TrackingRecHit::ConstRecHitPointer TkClonerImpl::makeShared(Phase2TrackerRecHit1D const& hit,
0093                                                             TrajectoryStateOnSurface const& tsos) const {
0094   const Phase2TrackerCluster1D& clust = hit.phase2OTCluster();
0095   const PixelGeomDetUnit& gdu = (const PixelGeomDetUnit&)*(hit.detUnit());
0096   auto&& params = phase2TrackerCPE->localParameters(clust, gdu, tsos);
0097   return std::make_unique<Phase2TrackerRecHit1D>(params.first, params.second, *hit.det(), hit.cluster());
0098 }
0099 
0100 TrackingRecHit::ConstRecHitPointer TkClonerImpl::makeShared(VectorHit const& hit,
0101                                                             TrajectoryStateOnSurface const& tsos) const {
0102   return std::make_shared<VectorHit>(hit);
0103 }
0104 
0105 namespace {
0106 #undef RecoTracker_TransientTrackingRecHit_TSiStripMatchedRecHit_RefitProj
0107 #undef RecoTracker_TransientTrackingRecHit_TSiStripMatchedRecHit_RefitLGL
0108 #ifdef RecoTracker_TransientTrackingRecHit_TSiStripMatchedRecHit_RefitLGL
0109   // Local lo Global lo Local
0110   inline LocalTrajectoryParameters gluedToStereo(const TrajectoryStateOnSurface& tsos, const GluedGeomDet* gdet) {
0111     const BoundPlane& stripPlane = gdet->stereoDet()->surface();
0112     LocalPoint lp = stripPlane.toLocal(tsos.globalPosition());
0113     LocalVector ld = stripPlane.toLocal(tsos.globalParameters().momentum());
0114     return LocalTrajectoryParameters(lp, ld, tsos.charge());
0115   }
0116 #elif defined(RecoTracker_TransientTrackingRecHit_TSiStripMatchedRecHit_RefitProj)
0117   // A la RecHitProjector
0118   inline LocalTrajectoryParameters gluedToStereo(const TrajectoryStateOnSurface& tsos, const GluedGeomDet* gdet) {
0119     const BoundPlane& stripPlane = gdet->stereoDet()->surface();
0120     double delta = stripPlane.localZ(tsos.globalPosition());
0121     LocalVector ld = stripPlane.toLocal(tsos.globalParameters().momentum());
0122     LocalPoint lp = stripPlane.toLocal(tsos.globalPosition()) - ld * delta / ld.z();
0123     return LocalTrajectoryParameters(lp, ld, tsos.charge());
0124   }
0125 #else
0126   // Dummy
0127   inline const LocalTrajectoryParameters& gluedToStereo(const TrajectoryStateOnSurface& tsos,
0128                                                         const GluedGeomDet* gdet) {
0129     return tsos.localParameters();
0130   }
0131 #endif
0132 }  // namespace
0133 
0134 std::unique_ptr<SiStripMatchedRecHit2D> TkClonerImpl::operator()(SiStripMatchedRecHit2D const& hit,
0135                                                                  TrajectoryStateOnSurface const& tsos) const {
0136   const GeomDet* det = hit.det();
0137   const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(det);
0138   LocalVector tkDir = (tsos.isValid() ? tsos.localParameters().directionNotNormalized()
0139                                       : det->surface().toLocal(det->position() - GlobalPoint(0, 0, 0)));
0140 
0141   const SiStripCluster& monoclust = hit.monoCluster();
0142   const SiStripCluster& stereoclust = hit.stereoCluster();
0143 
0144   StripClusterParameterEstimator::LocalValues lvMono = stripCPE->localParameters(monoclust, *gdet->monoDet(), tsos);
0145   StripClusterParameterEstimator::LocalValues lvStereo =
0146       stripCPE->localParameters(stereoclust, *gdet->stereoDet(), gluedToStereo(tsos, gdet));
0147 
0148   SiStripRecHit2D monoHit = SiStripRecHit2D(lvMono.first, lvMono.second, *gdet->monoDet(), hit.monoClusterRef());
0149   SiStripRecHit2D stereoHit =
0150       SiStripRecHit2D(lvStereo.first, lvStereo.second, *gdet->stereoDet(), hit.stereoClusterRef());
0151 
0152   // return theMatcher->match(&monoHit,&stereoHit,gdet,tkDir,true);
0153   std::unique_ptr<SiStripMatchedRecHit2D> temp = theMatcher->match(&monoHit, &stereoHit, gdet, tkDir, false);
0154   if (temp.get() == nullptr) {
0155     temp = std::unique_ptr<SiStripMatchedRecHit2D>(hit.clone());
0156   }
0157   return temp;
0158 }
0159 
0160 TrackingRecHit::ConstRecHitPointer TkClonerImpl::makeShared(SiStripMatchedRecHit2D const& hit,
0161                                                             TrajectoryStateOnSurface const& tsos) const {
0162   ///std::cout << "cloning " << typeid(hit).name()  << std::endl;
0163   return TrackingRecHit::ConstRecHitPointer((*this)(hit, tsos));
0164 }
0165 
0166 TrackingRecHit::ConstRecHitPointer TkClonerImpl::makeShared(ProjectedSiStripRecHit2D const& hit,
0167                                                             TrajectoryStateOnSurface const& tsos) const {
0168   // std::cout << "cloning " << typeid(hit).name()  << std::endl;
0169   return TrackingRecHit::ConstRecHitPointer((*this)(hit, tsos));
0170 }
0171 
0172 std::unique_ptr<ProjectedSiStripRecHit2D> TkClonerImpl::operator()(ProjectedSiStripRecHit2D const& hit,
0173                                                                    TrajectoryStateOnSurface const& tsos) const {
0174   const SiStripCluster& clust = hit.stripCluster();
0175   const GeomDetUnit* gdu = reinterpret_cast<const GeomDetUnit*>(hit.originalDet());
0176   //if (!gdu) std::cout<<"no luck dude"<<std::endl;
0177   StripClusterParameterEstimator::LocalValues lv = stripCPE->localParameters(clust, *gdu, tsos);
0178 
0179   // project...
0180   const GeomDet& det = *hit.det();
0181   const BoundPlane& gluedPlane = det.surface();
0182   const BoundPlane& hitPlane = gdu->surface();
0183   LocalVector tkDir =
0184       (tsos.isValid() ? tsos.localDirection() : det.surface().toLocal(det.position() - GlobalPoint(0, 0, 0)));
0185 
0186   auto delta = gluedPlane.localZ(hitPlane.position());
0187   const LocalVector& ldir = tkDir;
0188   LocalPoint lhitPos = gluedPlane.toLocal(hitPlane.toGlobal(lv.first));
0189   LocalPoint projectedHitPos = lhitPos - ldir * delta / ldir.z();
0190 
0191   LocalVector hitXAxis = gluedPlane.toLocal(hitPlane.toGlobal(LocalVector(1.f, 0, 0)));
0192   LocalError hitErr = lv.second;
0193   if (gluedPlane.normalVector().dot(hitPlane.normalVector()) < 0) {
0194     // the two planes are inverted, and the correlation element must change sign
0195     hitErr = LocalError(hitErr.xx(), -hitErr.xy(), hitErr.yy());
0196   }
0197   LocalError rotatedError = hitErr.rotate(hitXAxis.x(), hitXAxis.y());
0198   return std::make_unique<ProjectedSiStripRecHit2D>(
0199       projectedHitPos, rotatedError, *hit.det(), *hit.originalDet(), hit.omniCluster());
0200 }
0201 
0202 std::unique_ptr<ProjectedSiStripRecHit2D> TkClonerImpl::project(SiStripMatchedRecHit2D const& hit,
0203                                                                 bool mono,
0204                                                                 TrajectoryStateOnSurface const& tsos) const {
0205   const GeomDet& det = *hit.det();
0206   const GluedGeomDet& gdet = static_cast<const GluedGeomDet&>(det);
0207   const GeomDetUnit* odet = mono ? gdet.monoDet() : gdet.stereoDet();
0208   const BoundPlane& gluedPlane = det.surface();
0209   const BoundPlane& hitPlane = odet->surface();
0210 
0211   LocalVector tkDir =
0212       (tsos.isValid() ? tsos.localDirection() : det.surface().toLocal(det.position() - GlobalPoint(0, 0, 0)));
0213 
0214   const SiStripCluster& monoclust = hit.monoCluster();
0215   const SiStripCluster& stereoclust = hit.stereoCluster();
0216 
0217   StripClusterParameterEstimator::LocalValues lv;
0218   if (tsos.isValid())
0219     lv = mono ? stripCPE->localParameters(monoclust, *odet, tsos)
0220               : stripCPE->localParameters(stereoclust, *odet, gluedToStereo(tsos, &gdet));
0221   else
0222     lv = stripCPE->localParameters(mono ? monoclust : stereoclust, *odet);
0223 
0224   auto delta = gluedPlane.localZ(hitPlane.position());
0225   const LocalVector& ldir = tkDir;
0226   LocalPoint lhitPos = gluedPlane.toLocal(hitPlane.toGlobal(lv.first));
0227   LocalPoint projectedHitPos = lhitPos - ldir * delta / ldir.z();
0228 
0229   LocalVector hitXAxis = gluedPlane.toLocal(hitPlane.toGlobal(LocalVector(1.f, 0, 0)));
0230   LocalError hitErr = lv.second;
0231   if (gluedPlane.normalVector().dot(hitPlane.normalVector()) < 0) {
0232     // the two planes are inverted, and the correlation element must change sign
0233     hitErr = LocalError(hitErr.xx(), -hitErr.xy(), hitErr.yy());
0234   }
0235   LocalError rotatedError = hitErr.rotate(hitXAxis.x(), hitXAxis.y());
0236   return std::make_unique<ProjectedSiStripRecHit2D>(
0237       projectedHitPos, rotatedError, det, *odet, mono ? hit.monoClusterRef() : hit.stereoClusterRef());
0238 }