CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Traj2TrackHits.h
Go to the documentation of this file.
1 #ifndef Traj2TrackHits_H
2 #define Traj2TrackHits_H
3 
6 
7 
11 
16 
17 
19 private:
21  bool keepOrder; // FIXME move to enum
22  bool removeNoDet; // true == as in conversion from TTRH tp TRH
23 public:
24 
25  Traj2TrackHits(const TransientTrackingRecHitBuilder* builder, bool ikeepOrder, bool noNoDet=true) :
26  theCPE(static_cast<TkTransientTrackingRecHitBuilder const *>(builder)->stripClusterParameterEstimator()),
27  keepOrder(ikeepOrder), removeNoDet(noNoDet) {}
28 
29  void operator()(Trajectory const & traj, TrackingRecHitCollection & hits, bool splitting) const {
30  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
31  bool along = traj.direction() == alongMomentum;
32  auto const & meas = traj.measurements();
33  hits.reserve(splitting ? 2*meas.size() : meas.size());
34  if(!splitting){
35  if (keepOrder | along) copy(meas.begin(),meas.end(),hits);
36  else copy(meas.rbegin(),meas.rend(),hits);
37  return;
38  }
39  if (keepOrder | along) split(meas.begin(),meas.end(),hits, along);
40  else split(meas.rbegin(),meas.rend(),hits,along);
41  hits.shrink_to_fit();
42  }
43 
44 private:
45  template<typename HI>
46  void copy(HI itm, HI e, TrackingRecHitCollection & hits) const {
47  for(;itm!=e;++itm) if( (!removeNoDet) | ((*itm).recHitR().det()!=nullptr)) hits.push_back((*itm).recHitR().clone());
48  }
49 
50  template<typename HI>
51  void split(HI itm, HI e, TrackingRecHitCollection & hits, bool along) const {
52  for(;itm!=e;++itm) {
53  auto const & hit = *(*itm).recHit()->hit();
54  if( (removeNoDet) & ((*itm).recHitR().det()==nullptr)) continue;
55  if(trackerHitRTTI::isUndef(hit) | ( hit.dimension()!=2) ) {
56  hits.push_back(hit.clone());
57  continue;
58  }
59  auto const & thit = static_cast<BaseTrackerRecHit const&>(hit);
60  auto const & clus = thit.firstClusterRef();
61  if (clus.isPixel()) hits.push_back(hit.clone());
62  else if (thit.isMatched()) {
63  auto zdir = itm->updatedState().localDirection().z();
64  if (keepOrder & (!along)) zdir = -zdir;
65  split(*itm,static_cast<SiStripMatchedRecHit2D const&>(thit),hits,zdir);
66  }else if (thit.isProjected()) {
67  auto detU = static_cast<ProjectedSiStripRecHit2D const&>(thit).originalDet();
68  hits.push_back(build(*detU, clus));
69  } else hits.push_back(clone(thit));
70  }
71  }
72 
73  TrackingRecHit * clone(BaseTrackerRecHit const & hit2D ) const {
74  auto const & detU = *hit2D.detUnit();
75  //Use 2D SiStripRecHit in endcap
76  bool endcap = detU.type().isEndcap();
77  if (endcap) return hit2D.clone();
78  return new SiStripRecHit1D(hit2D.localPosition(),
80  *hit2D.det(), hit2D.firstClusterRef());
81 
82  }
83 
84 
86  OmniClusterRef const & clus) const {
87  //Use 2D SiStripRecHit in endcap
88  bool endcap = idet.type().isEndcap();
89  auto && lv = theCPE->localParameters(clus.stripCluster(),idet);
90  if (endcap) return new SiStripRecHit2D(lv.first,lv.second,idet,clus);
91  return new SiStripRecHit1D(lv.first, LocalError(lv.second.xx(),0.f,std::numeric_limits<float>::max()),idet,clus);
92  }
93 
94  void split(TrajectoryMeasurement const & itm,
95  SiStripMatchedRecHit2D const& mhit, TrackingRecHitCollection & hits, float zdir) const {
96  const GluedGeomDet *gdet = static_cast<const GluedGeomDet *> (mhit.det());
97 
98  auto hitM = build (*gdet->monoDet(),
99  mhit.monoClusterRef());
100  auto hitS = build(*gdet->stereoDet(),
101  mhit.stereoClusterRef());
102 
103  // we should find a faster way
104  LocalPoint firstLocalPos =
105  itm.updatedState().surface().toLocal(gdet->monoDet()->position());
106  LocalPoint secondLocalPos =
107  itm.updatedState().surface().toLocal(gdet->stereoDet()->position());
108  LocalVector Delta = secondLocalPos - firstLocalPos;
109  float scalar = Delta.z() * zdir;
110  // hit along the direction
111  if(scalar<0) {
112  hits.push_back(hitS);
113  hits.push_back(hitM);
114  } else {
115  hits.push_back(hitM);
116  hits.push_back(hitS);
117  }
118 
119  }
120 
121 
122 };
123 
124 
125 #endif
virtual LocalValues localParameters(const SiStripCluster &, const GeomDetUnit &) const
float xx() const
Definition: LocalError.h:24
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
virtual const GeomDetType & type() const
Definition: GeomDet.cc:90
bool isEndcap() const
Definition: GeomDetType.cc:18
OmniClusterRef const & stereoClusterRef() const
Traj2TrackHits(const TransientTrackingRecHitBuilder *builder, bool ikeepOrder, bool noNoDet=true)
void copy(HI itm, HI e, TrackingRecHitCollection &hits) const
void split(HI itm, HI e, TrackingRecHitCollection &hits, bool along) const
PropagationDirection const & direction() const
Definition: Trajectory.cc:118
DataContainer const & measurements() const
Definition: Trajectory.h:203
SiStripCluster const & stripCluster() const
TrackingRecHit * clone(BaseTrackerRecHit const &hit2D) const
void push_back(D *&d)
Definition: OwnVector.h:280
virtual LocalError localPositionError() const
const SurfaceType & surface() const
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:46
const GeomDet * det() const
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:64
void shrink_to_fit()
Definition: OwnVector.h:127
OmniClusterRef const & monoClusterRef() const
virtual TrackingRecHit * clone() const =0
void operator()(Trajectory const &traj, TrackingRecHitCollection &hits, bool splitting) const
const StripClusterParameterEstimator * theCPE
virtual OmniClusterRef const & firstClusterRef() const =0
string const
Definition: compareJSON.py:14
virtual const GeomDetUnit * detUnit() const
bool isUndef(TrackingRecHit const &hit)
TrajectoryStateOnSurface const & updatedState() const
BaseTrackerRecHit * build(GeomDetUnit const &idet, OmniClusterRef const &clus) const
virtual LocalPoint localPosition() const
void reserve(size_t)
Definition: OwnVector.h:274
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
void split(TrajectoryMeasurement const &itm, SiStripMatchedRecHit2D const &mhit, TrackingRecHitCollection &hits, float zdir) const
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:183