CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoTracker/TransientTrackingRecHit/interface/TSiStripMatchedRecHit.h

Go to the documentation of this file.
00001 #ifndef RECOTRACKER_TRANSIENTRACKINGRECHIT_TSiStripMatchedRecHit_H
00002 #define RECOTRACKER_TRANSIENTRACKINGRECHIT_TSiStripMatchedRecHit_H
00003 
00004 #include "TrackingTools/TransientTrackingRecHit/interface/GenericTransientTrackingRecHit.h"
00005 #include "TrackingTools/TransientTrackingRecHit/interface/HelpertRecHit2DLocalPos.h"
00006 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
00007 #include "RecoLocalTracker/ClusterParameterEstimator/interface/StripClusterParameterEstimator.h"
00008 #include<memory>
00009 
00010 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 
00013 class TSiStripMatchedRecHit : public GenericTransientTrackingRecHit{
00014 public:
00015 
00016   virtual void getKfComponents( KfComponentsHolder & holder ) const {
00017       HelpertRecHit2DLocalPos().getKfComponents(holder, *hit(), *det()); 
00018   }
00019 
00020   virtual AlgebraicSymMatrix parametersError() const {
00021     return HelpertRecHit2DLocalPos().parError( localPositionError(), *det()); 
00022   }
00023 
00024   const GeomDetUnit* detUnit() const {return 0;}
00025 
00026   static RecHitPointer build( const GeomDet * geom, const TrackingRecHit * rh, 
00027                               const SiStripRecHitMatcher *matcher,
00028                               const StripClusterParameterEstimator* cpe=0,
00029                               float weight=1., float annealing=1.,
00030                               bool computeCoarseLocalPosition=false) {
00031     return RecHitPointer( new TSiStripMatchedRecHit( geom, rh, matcher,cpe, weight, annealing, computeCoarseLocalPosition));
00032   }
00033 
00034   static RecHitPointer build( const GeomDet * geom, std::auto_ptr<TrackingRecHit> rh, 
00035                               const SiStripRecHitMatcher *matcher,
00036                               const StripClusterParameterEstimator* cpe=0,
00037                               float weight=1., float annealing=1.,
00038                               bool computeCoarseLocalPosition=false) {
00039     return RecHitPointer( new TSiStripMatchedRecHit( geom, rh, matcher,cpe,weight, annealing, computeCoarseLocalPosition));
00040   }
00041 
00042   virtual RecHitPointer clone( const TrajectoryStateOnSurface& ts) const;
00043   virtual bool canImproveWithTrack() const {return (theMatcher != 0);}
00044   virtual ConstRecHitContainer  transientHits () const;
00045 
00047   struct DontCloneRecHit {};
00048 
00053   static void buildInPlace(std::auto_ptr<TSiStripMatchedRecHit> &memory,
00054                               const GeomDet * geom, const TrackingRecHit * rh,
00055                               const SiStripRecHitMatcher *matcher,
00056                               const StripClusterParameterEstimator* cpe=0,
00057                               float weight=1., float annealing=1.,
00058                               bool computeCoarseLocalPosition=false) {
00059         if (memory.get()) {
00060             memory->~TSiStripMatchedRecHit(); // call destructor
00061             new (memory.get()) TSiStripMatchedRecHit( geom, rh, matcher,cpe,weight, annealing, computeCoarseLocalPosition, DontCloneRecHit());
00062         } else {
00063             memory.reset(new TSiStripMatchedRecHit( geom, rh, matcher,cpe,weight, annealing, computeCoarseLocalPosition, DontCloneRecHit()));
00064         }
00065   }
00066 
00068   void clonePersistentHit()  { trackingRecHit_ = trackingRecHit_->clone(); }
00071   void clearPersistentHit() { trackingRecHit_ = 0; }
00072 
00073 private:
00074   const SiStripRecHitMatcher* theMatcher; 
00075   const StripClusterParameterEstimator* theCPE;
00076 
00077 private:
00078   TSiStripMatchedRecHit (const GeomDet * geom, const TrackingRecHit * rh, 
00079                          const SiStripRecHitMatcher *matcher,
00080                          const StripClusterParameterEstimator* cpe,
00081                          float weight, float annealing,
00082                          bool computeCoarseLocalPosition) : 
00083     GenericTransientTrackingRecHit(geom, *rh, weight, annealing), theMatcher(matcher),theCPE(cpe) {
00084     if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
00085   }
00086 
00087   TSiStripMatchedRecHit (const GeomDet * geom, std::auto_ptr<TrackingRecHit> rh,
00088                          const SiStripRecHitMatcher *matcher,
00089                          const StripClusterParameterEstimator* cpe,
00090                          float weight, float annealing,
00091                          bool computeCoarseLocalPosition) : 
00092     GenericTransientTrackingRecHit(geom, rh.release(), weight, annealing), theMatcher(matcher),theCPE(cpe) {
00093     if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
00094   }
00095   TSiStripMatchedRecHit (const GeomDet * geom, const TrackingRecHit * rh, 
00096                          const SiStripRecHitMatcher *matcher,
00097                          const StripClusterParameterEstimator* cpe,
00098                          float weight, float annealing,
00099                          bool computeCoarseLocalPosition,
00100                          const DontCloneRecHit &) : 
00101     GenericTransientTrackingRecHit(geom, const_cast<TrackingRecHit *>(rh), weight, annealing), theMatcher(matcher),theCPE(cpe) {
00102     if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
00103   }
00104 
00105 private:
00106     void ComputeCoarseLocalPosition(){
00107       if (!theCPE || !theMatcher) return;
00108       const SiStripMatchedRecHit2D *orig = static_cast<const SiStripMatchedRecHit2D *> (trackingRecHit_);
00109       if (orig && !orig->hasPositionAndError()){
00110         LogDebug("TSiStripMatchedRecHit")<<"calculating coarse position/error.";
00111         const GeomDet *det = this->det();
00112         const GluedGeomDet *gdet = static_cast<const GluedGeomDet *> (det);
00113         LocalVector tkDir = det->surface().toLocal( det->position()-GlobalPoint(0,0,0));
00114         
00115         const SiStripMatchedRecHit2D* better=0;
00116         
00117         if(!orig->monoHit()->cluster().isNull()){
00118           const SiStripCluster& monoclust   = *orig->monoHit()->cluster();  
00119           const SiStripCluster& stereoclust = *orig->stereoHit()->cluster();
00120           
00121           StripClusterParameterEstimator::LocalValues lvMono = 
00122             theCPE->localParameters( monoclust, *gdet->monoDet());
00123           StripClusterParameterEstimator::LocalValues lvStereo = 
00124             theCPE->localParameters( stereoclust, *gdet->stereoDet());
00125           
00126           SiStripRecHit2D monoHit = SiStripRecHit2D( lvMono.first, lvMono.second,
00127                                                      gdet->monoDet()->geographicalId(),
00128                                                      orig->monoHit()->cluster());
00129           
00130           SiStripRecHit2D stereoHit = SiStripRecHit2D( lvStereo.first, lvStereo.second,
00131                                                        gdet->stereoDet()->geographicalId(),
00132                                                        orig->stereoHit()->cluster());
00133           better =  theMatcher->match(&monoHit,&stereoHit,gdet,tkDir);
00134         }else{
00135           const SiStripCluster& monoclust   = *orig->monoHit()->cluster_regional();  
00136           const SiStripCluster& stereoclust = *orig->stereoHit()->cluster_regional();
00137           StripClusterParameterEstimator::LocalValues lvMono = 
00138             theCPE->localParameters( monoclust, *gdet->monoDet());
00139           StripClusterParameterEstimator::LocalValues lvStereo = 
00140             theCPE->localParameters( stereoclust, *gdet->stereoDet());
00141           
00142           SiStripRecHit2D monoHit = SiStripRecHit2D( lvMono.first, lvMono.second,
00143                                                      gdet->monoDet()->geographicalId(),
00144                                                      orig->monoHit()->cluster_regional());
00145           
00146           SiStripRecHit2D stereoHit = SiStripRecHit2D( lvStereo.first, lvStereo.second,
00147                                                        gdet->stereoDet()->geographicalId(),
00148                                                        orig->stereoHit()->cluster_regional());
00149           better =  theMatcher->match(&monoHit,&stereoHit,gdet,tkDir);
00150           
00151         }
00152         if (!better) {
00153           edm::LogWarning("TSiStripMatchedRecHit")<<"could not get a matching rechit.";
00154         }else{
00155           trackingRecHit_ = better->clone();
00156         }
00157       }
00158     }
00159 
00160   virtual TSiStripMatchedRecHit* clone() const {
00161     return new TSiStripMatchedRecHit(*this);
00162   }
00163 
00164 };
00165 
00166 
00167 
00168 #endif