ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/RecoTracker/TransientTrackingRecHit/interface/TSiStripMatchedRecHit.h
Revision: 1.1
Committed: Fri Nov 25 17:05:34 2011 UTC (13 years, 5 months ago) by econte
Content type: text/plain
Branch: MAIN
CVS Tags: TBD2011, TBD_2011, HEAD
Log Message:
new IPHC alignment

File Contents

# User Rev Content
1 econte 1.1 #ifndef RECOTRACKER_TRANSIENTRACKINGRECHIT_TSiStripMatchedRecHit_H
2     #define RECOTRACKER_TRANSIENTRACKINGRECHIT_TSiStripMatchedRecHit_H
3    
4     #include "TrackingTools/TransientTrackingRecHit/interface/GenericTransientTrackingRecHit.h"
5     #include "TrackingTools/TransientTrackingRecHit/interface/HelpertRecHit2DLocalPos.h"
6     #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
7     #include "RecoLocalTracker/ClusterParameterEstimator/interface/StripClusterParameterEstimator.h"
8     #include<memory>
9    
10     #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
11     #include "FWCore/MessageLogger/interface/MessageLogger.h"
12    
13     class TSiStripMatchedRecHit : public GenericTransientTrackingRecHit{
14     public:
15    
16     virtual void getKfComponents( KfComponentsHolder & holder ) const {
17     HelpertRecHit2DLocalPos().getKfComponents(holder, *hit(), *det());
18     }
19    
20     virtual AlgebraicSymMatrix parametersError() const {
21     return HelpertRecHit2DLocalPos().parError( localPositionError(), *det());
22     }
23    
24     const GeomDetUnit* detUnit() const {return 0;}
25    
26     static RecHitPointer build( const GeomDet * geom, const TrackingRecHit * rh,
27     const SiStripRecHitMatcher *matcher,
28     const StripClusterParameterEstimator* cpe=0,
29     float weight=1., float annealing=1.,
30     bool computeCoarseLocalPosition=false) {
31     return RecHitPointer( new TSiStripMatchedRecHit( geom, rh, matcher,cpe, weight, annealing, computeCoarseLocalPosition));
32     }
33    
34     static RecHitPointer build( const GeomDet * geom, std::auto_ptr<TrackingRecHit> rh,
35     const SiStripRecHitMatcher *matcher,
36     const StripClusterParameterEstimator* cpe=0,
37     float weight=1., float annealing=1.,
38     bool computeCoarseLocalPosition=false) {
39     return RecHitPointer( new TSiStripMatchedRecHit( geom, rh, matcher,cpe,weight, annealing, computeCoarseLocalPosition));
40     }
41    
42     virtual RecHitPointer clone( const TrajectoryStateOnSurface& ts) const;
43     virtual bool canImproveWithTrack() const {return (theMatcher != 0);}
44     virtual ConstRecHitContainer transientHits () const;
45    
46     /// Dummy struct to pass to the constructor to say 'please don't clone the hit'
47     struct DontCloneRecHit {};
48    
49     /// Build this hit on the heap, but possibly starting from already allocated memory.
50     /// if 'memory' is not null, it will call the placed delete, and then the placed new to make a new hit
51     /// if 'memory' is null, it will fill it with a new heap-allocated hit
52     /// both at entry and exit of this method any rechit in 'memory' DOES NOT own it's persistent rechit
53     static void buildInPlace(std::auto_ptr<TSiStripMatchedRecHit> &memory,
54     const GeomDet * geom, const TrackingRecHit * rh,
55     const SiStripRecHitMatcher *matcher,
56     const StripClusterParameterEstimator* cpe=0,
57     float weight=1., float annealing=1.,
58     bool computeCoarseLocalPosition=false) {
59     if (memory.get()) {
60     memory->~TSiStripMatchedRecHit(); // call destructor
61     new (memory.get()) TSiStripMatchedRecHit( geom, rh, matcher,cpe,weight, annealing, computeCoarseLocalPosition, DontCloneRecHit());
62     } else {
63     memory.reset(new TSiStripMatchedRecHit( geom, rh, matcher,cpe,weight, annealing, computeCoarseLocalPosition, DontCloneRecHit()));
64     }
65     }
66    
67     /// take ownership of the hit, if it wasn't owned (note: if it was owned, this code will leak it)
68     void clonePersistentHit() { trackingRecHit_ = trackingRecHit_->clone(); }
69     /// drop the pointer to the hit, so that it's not deleted by the destructor.
70     /// you must call this before deleting the TSiStripMatchedRecHit IF AND ONLY IF it doesn't own the rechit
71     void clearPersistentHit() { trackingRecHit_ = 0; }
72    
73     private:
74     const SiStripRecHitMatcher* theMatcher;
75     const StripClusterParameterEstimator* theCPE;
76    
77     private:
78     TSiStripMatchedRecHit (const GeomDet * geom, const TrackingRecHit * rh,
79     const SiStripRecHitMatcher *matcher,
80     const StripClusterParameterEstimator* cpe,
81     float weight, float annealing,
82     bool computeCoarseLocalPosition) :
83     GenericTransientTrackingRecHit(geom, *rh, weight, annealing), theMatcher(matcher),theCPE(cpe) {
84     if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
85     }
86    
87     TSiStripMatchedRecHit (const GeomDet * geom, std::auto_ptr<TrackingRecHit> rh,
88     const SiStripRecHitMatcher *matcher,
89     const StripClusterParameterEstimator* cpe,
90     float weight, float annealing,
91     bool computeCoarseLocalPosition) :
92     GenericTransientTrackingRecHit(geom, rh.release(), weight, annealing), theMatcher(matcher),theCPE(cpe) {
93     if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
94     }
95     TSiStripMatchedRecHit (const GeomDet * geom, const TrackingRecHit * rh,
96     const SiStripRecHitMatcher *matcher,
97     const StripClusterParameterEstimator* cpe,
98     float weight, float annealing,
99     bool computeCoarseLocalPosition,
100     const DontCloneRecHit &) :
101     GenericTransientTrackingRecHit(geom, const_cast<TrackingRecHit *>(rh), weight, annealing), theMatcher(matcher),theCPE(cpe) {
102     if (computeCoarseLocalPosition) ComputeCoarseLocalPosition();
103     }
104    
105     private:
106     void ComputeCoarseLocalPosition(){
107     if (!theCPE || !theMatcher) return;
108     const SiStripMatchedRecHit2D *orig = static_cast<const SiStripMatchedRecHit2D *> (trackingRecHit_);
109     if (orig && !orig->hasPositionAndError()){
110     LogDebug("TSiStripMatchedRecHit")<<"calculating coarse position/error.";
111     const GeomDet *det = this->det();
112     const GluedGeomDet *gdet = static_cast<const GluedGeomDet *> (det);
113     LocalVector tkDir = det->surface().toLocal( det->position()-GlobalPoint(0,0,0));
114    
115     const SiStripMatchedRecHit2D* better=0;
116    
117     if(!orig->monoHit()->cluster().isNull()){
118     const SiStripCluster& monoclust = *orig->monoHit()->cluster();
119     const SiStripCluster& stereoclust = *orig->stereoHit()->cluster();
120    
121     StripClusterParameterEstimator::LocalValues lvMono =
122     theCPE->localParameters( monoclust, *gdet->monoDet());
123     StripClusterParameterEstimator::LocalValues lvStereo =
124     theCPE->localParameters( stereoclust, *gdet->stereoDet());
125    
126     SiStripRecHit2D monoHit = SiStripRecHit2D( lvMono.first, lvMono.second,
127     gdet->monoDet()->geographicalId(),
128     orig->monoHit()->cluster());
129    
130     SiStripRecHit2D stereoHit = SiStripRecHit2D( lvStereo.first, lvStereo.second,
131     gdet->stereoDet()->geographicalId(),
132     orig->stereoHit()->cluster());
133     better = theMatcher->match(&monoHit,&stereoHit,gdet,tkDir);
134     }else{
135     const SiStripCluster& monoclust = *orig->monoHit()->cluster_regional();
136     const SiStripCluster& stereoclust = *orig->stereoHit()->cluster_regional();
137     StripClusterParameterEstimator::LocalValues lvMono =
138     theCPE->localParameters( monoclust, *gdet->monoDet());
139     StripClusterParameterEstimator::LocalValues lvStereo =
140     theCPE->localParameters( stereoclust, *gdet->stereoDet());
141    
142     SiStripRecHit2D monoHit = SiStripRecHit2D( lvMono.first, lvMono.second,
143     gdet->monoDet()->geographicalId(),
144     orig->monoHit()->cluster_regional());
145    
146     SiStripRecHit2D stereoHit = SiStripRecHit2D( lvStereo.first, lvStereo.second,
147     gdet->stereoDet()->geographicalId(),
148     orig->stereoHit()->cluster_regional());
149     better = theMatcher->match(&monoHit,&stereoHit,gdet,tkDir);
150    
151     }
152     if (!better) {
153     edm::LogWarning("TSiStripMatchedRecHit")<<"could not get a matching rechit.";
154     }else{
155     trackingRecHit_ = better->clone();
156     }
157     }
158     }
159    
160     virtual TSiStripMatchedRecHit* clone() const {
161     return new TSiStripMatchedRecHit(*this);
162     }
163    
164     };
165    
166    
167    
168     #endif