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();
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 TSiStripMatchedRecHit (const GeomDet * geom, const TrackingRecHit * rh,
00077 const SiStripRecHitMatcher *matcher,
00078 const StripClusterParameterEstimator* cpe,
00079 float weight, float annealing,
00080 bool computeCoarseLocalPosition) :
00081 GenericTransientTrackingRecHit(geom, *rh, weight, annealing), theMatcher(matcher),theCPE(cpe) {
00082 if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
00083 }
00084
00085 TSiStripMatchedRecHit (const GeomDet * geom, std::auto_ptr<TrackingRecHit> rh,
00086 const SiStripRecHitMatcher *matcher,
00087 const StripClusterParameterEstimator* cpe,
00088 float weight, float annealing,
00089 bool computeCoarseLocalPosition) :
00090 GenericTransientTrackingRecHit(geom, rh.release(), weight, annealing), theMatcher(matcher),theCPE(cpe) {
00091 if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
00092 }
00093 TSiStripMatchedRecHit (const GeomDet * geom, const TrackingRecHit * rh,
00094 const SiStripRecHitMatcher *matcher,
00095 const StripClusterParameterEstimator* cpe,
00096 float weight, float annealing,
00097 bool computeCoarseLocalPosition,
00098 const DontCloneRecHit &) :
00099 GenericTransientTrackingRecHit(geom, const_cast<TrackingRecHit *>(rh), weight, annealing), theMatcher(matcher),theCPE(cpe) {
00100 if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
00101 }
00102
00103
00104 void ComputeCoarseLocalPosition(){
00105 if (!theCPE || !theMatcher) return;
00106 const SiStripMatchedRecHit2D *orig = static_cast<const SiStripMatchedRecHit2D *> (trackingRecHit_);
00107 if (orig && !orig->hasPositionAndError()){
00108 LogDebug("TSiStripMatchedRecHit")<<"calculating coarse position/error.";
00109 const GeomDet *det = this->det();
00110 const GluedGeomDet *gdet = static_cast<const GluedGeomDet *> (det);
00111 LocalVector tkDir = det->surface().toLocal( det->position()-GlobalPoint(0,0,0));
00112
00113 const SiStripMatchedRecHit2D* better=0;
00114
00115 if(!orig->monoHit()->cluster().isNull()){
00116 const SiStripCluster& monoclust = *orig->monoHit()->cluster();
00117 const SiStripCluster& stereoclust = *orig->stereoHit()->cluster();
00118
00119 StripClusterParameterEstimator::LocalValues lvMono =
00120 theCPE->localParameters( monoclust, *gdet->monoDet());
00121 StripClusterParameterEstimator::LocalValues lvStereo =
00122 theCPE->localParameters( stereoclust, *gdet->stereoDet());
00123
00124 SiStripRecHit2D monoHit = SiStripRecHit2D( lvMono.first, lvMono.second,
00125 gdet->monoDet()->geographicalId(),
00126 orig->monoHit()->cluster());
00127
00128 SiStripRecHit2D stereoHit = SiStripRecHit2D( lvStereo.first, lvStereo.second,
00129 gdet->stereoDet()->geographicalId(),
00130 orig->stereoHit()->cluster());
00131 better = theMatcher->match(&monoHit,&stereoHit,gdet,tkDir);
00132 }else{
00133 const SiStripCluster& monoclust = *orig->monoHit()->cluster_regional();
00134 const SiStripCluster& stereoclust = *orig->stereoHit()->cluster_regional();
00135 StripClusterParameterEstimator::LocalValues lvMono =
00136 theCPE->localParameters( monoclust, *gdet->monoDet());
00137 StripClusterParameterEstimator::LocalValues lvStereo =
00138 theCPE->localParameters( stereoclust, *gdet->stereoDet());
00139
00140 SiStripRecHit2D monoHit = SiStripRecHit2D( lvMono.first, lvMono.second,
00141 gdet->monoDet()->geographicalId(),
00142 orig->monoHit()->cluster_regional());
00143
00144 SiStripRecHit2D stereoHit = SiStripRecHit2D( lvStereo.first, lvStereo.second,
00145 gdet->stereoDet()->geographicalId(),
00146 orig->stereoHit()->cluster_regional());
00147 better = theMatcher->match(&monoHit,&stereoHit,gdet,tkDir);
00148
00149 }
00150 if (!better) {
00151 edm::LogWarning("TSiStripMatchedRecHit")<<"could not get a matching rechit.";
00152 }else{
00153 trackingRecHit_ = better->clone();
00154 }
00155 }
00156 }
00157
00158 virtual TSiStripMatchedRecHit* clone() const {
00159 return new TSiStripMatchedRecHit(*this);
00160 }
00161
00162 };
00163
00164
00165
00166 #endif