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(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  }
42 
43 private:
44  template<typename HI>
45  void copy(HI itm, HI e, TrackingRecHitCollection & hits) const {
46  for(;itm!=e;++itm) if( (!removeNoDet) | ((*itm).recHitR().det()!=nullptr)) hits.push_back((*itm).recHitR().clone());
47  }
48 
49  template<typename HI>
50  void split(HI itm, HI e, TrackingRecHitCollection & hits, bool along) const {
51  for(;itm!=e;++itm) {
52  auto const & hit = *(*itm).recHit()->hit();
53  if( (removeNoDet) & ((*itm).recHitR().det()==nullptr)) continue;
54  if(trackerHitRTTI::isUndef(hit) | ( hit.dimension()!=2) ) {
55  hits.push_back(hit.clone());
56  continue;
57  }
58  auto const & thit = static_cast<BaseTrackerRecHit const&>(hit);
59  auto const & clus = thit.firstClusterRef();
60  if (clus.isPixel()) hits.push_back(hit.clone());
61  else if (thit.isMatched()) {
62  auto zdir = itm->updatedState().localDirection().z();
63  if (keepOrder & (!along)) zdir = -zdir;
64  split(*itm,static_cast<SiStripMatchedRecHit2D const&>(thit),hits,zdir);
65  }else if (thit.isProjected()) {
66  auto detU = static_cast<ProjectedSiStripRecHit2D const&>(thit).originalDet();
67  hits.push_back(build(*detU, clus));
68  } else hits.push_back(clone(thit));
69  }
70  }
71 
72  TrackingRecHit * clone(BaseTrackerRecHit const & hit2D ) const {
73  auto const & detU = *hit2D.detUnit();
74  //Use 2D SiStripRecHit in endcap
75  bool endcap = detU.type().isEndcap();
76  if (endcap) return hit2D.clone();
77  return new SiStripRecHit1D(hit2D.localPosition(),
79  *hit2D.det(), hit2D.firstClusterRef());
80 
81  }
82 
83 
85  OmniClusterRef const & clus) const {
86  //Use 2D SiStripRecHit in endcap
87  bool endcap = idet.type().isEndcap();
88  auto && lv = theCPE->localParameters(clus.stripCluster(),idet);
89  if (endcap) return new SiStripRecHit2D(lv.first,lv.second,idet,clus);
90  return new SiStripRecHit1D(lv.first, LocalError(lv.second.xx(),0.f,std::numeric_limits<float>::max()),idet,clus);
91  }
92 
93  void split(TrajectoryMeasurement const & itm,
94  SiStripMatchedRecHit2D const& mhit, TrackingRecHitCollection & hits, float zdir) const {
95  const GluedGeomDet *gdet = static_cast<const GluedGeomDet *> (mhit.det());
96 
97  auto hitM = build (*gdet->monoDet(),
98  mhit.monoClusterRef());
99  auto hitS = build(*gdet->stereoDet(),
100  mhit.stereoClusterRef());
101 
102  // we should find a faster way
103  LocalPoint firstLocalPos =
104  itm.updatedState().surface().toLocal(gdet->monoDet()->position());
105  LocalPoint secondLocalPos =
106  itm.updatedState().surface().toLocal(gdet->stereoDet()->position());
107  LocalVector Delta = secondLocalPos - firstLocalPos;
108  float scalar = Delta.z() * zdir;
109  // hit along the direction
110  if(scalar<0) {
111  hits.push_back(hitS);
112  hits.push_back(hitM);
113  } else {
114  hits.push_back(hitM);
115  hits.push_back(hitS);
116  }
117 
118  }
119 
120 
121 };
122 
123 
124 #endif
virtual LocalValues localParameters(const SiStripCluster &, const GeomDetUnit &) const
float xx() const
Definition: LocalError.h:24
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
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:274
virtual LocalError localPositionError() const
const SurfaceType & surface() const
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:41
const GeomDet * det() const
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:64
virtual const GeomDetType & type() const =0
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:268
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