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=false; // FIXME move to enum
22  bool removeNoDet=true; // true == as in conversion from TTRH to TRH
23 public:
24  using TrajParams = std::vector<LocalTrajectoryParameters>;
25  using Chi2sFive = std::vector<unsigned char>;
26 
27  static unsigned char toChi2x5(float chi2) { float tc = std::round(5.f*chi2); return std::min(tc,255.f);}
28 
29  // default for final reco::Track
31 
32  Traj2TrackHits(const TransientTrackingRecHitBuilder* builder, bool ikeepOrder, bool noNoDet=true) :
33  theCPE(static_cast<TkTransientTrackingRecHitBuilder const *>(builder)->stripClusterParameterEstimator()),
34  keepOrder(ikeepOrder), removeNoDet(noNoDet) {}
35 
36  void operator()(Trajectory const & traj, TrackingRecHitCollection & hits, bool splitting) const {
37  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
38  bool along = traj.direction() == alongMomentum;
39  auto const & meas = traj.measurements();
40  hits.reserve(splitting ? 2*meas.size() : meas.size());
41  if(!splitting){
42  if (keepOrder | along) copy(meas.begin(),meas.end(),hits);
43  else copy(meas.rbegin(),meas.rend(),hits);
44  return;
45  }
46  if (keepOrder | along) split(meas.begin(),meas.end(),hits, along);
47  else split(meas.rbegin(),meas.rend(),hits,along);
48  hits.shrink_to_fit();
49  }
50 
51  void operator()(Trajectory const & traj, TrackingRecHitCollection & hits, TrajParams & trajParams, Chi2sFive & chi2s) const {
52  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
53  bool along = traj.direction() == alongMomentum;
54  auto const & meas = traj.measurements();
55  trajParams.reserve(meas.size());
56  chi2s.reserve(meas.size());
57  if (keepOrder | along) copy(meas.begin(),meas.end(),hits, trajParams, chi2s);
58  else copy(meas.rbegin(),meas.rend(),hits, trajParams, chi2s);
59  }
60 
61 private:
62  template<typename HI>
63  void copy(HI itm, HI e, TrackingRecHitCollection & hits, TrajParams & trajParams, Chi2sFive & chi2s) const {
64  for(;itm!=e;++itm) if( (!removeNoDet) | ((*itm).recHitR().det()!=nullptr)) {
65  hits.push_back((*itm).recHitR().cloneHit());
66  trajParams.push_back((*itm).updatedState().localParameters());
67  chi2s.push_back(toChi2x5((*itm).estimate()));
68  }
69  }
70 
71  template<typename HI>
72  void copy(HI itm, HI e, TrackingRecHitCollection & hits) const {
73  for(;itm!=e;++itm) if( (!removeNoDet) | ((*itm).recHitR().det()!=nullptr)) hits.push_back((*itm).recHitR().cloneHit());
74  }
75 
76 
77  template<typename HI>
78  void split(HI itm, HI e, TrackingRecHitCollection & hits, bool along) const {
79  for(;itm!=e;++itm) {
80  auto const & hit = *(*itm).recHit()->hit();
81  if( (removeNoDet) & ((*itm).recHitR().det()==nullptr)) continue;
82  if(trackerHitRTTI::isUndef(hit) | ( hit.dimension()!=2) ) {
83  hits.push_back(hit.clone());
84  continue;
85  }
86  auto const & thit = static_cast<BaseTrackerRecHit const&>(hit);
87  auto const & clus = thit.firstClusterRef();
88  if (clus.isPixel()) hits.push_back(hit.clone());
89  else if (clus.isPhase2()) hits.push_back(hit.clone());
90  else if (thit.isMatched()) {
91  auto zdir = itm->updatedState().localDirection().z();
92  if (keepOrder & (!along)) zdir = -zdir;
93  split(*itm,static_cast<SiStripMatchedRecHit2D const&>(thit),hits,zdir);
94  }else if (thit.isProjected()) {
95  auto detU = static_cast<ProjectedSiStripRecHit2D const&>(thit).originalDet();
96  hits.push_back(build(*detU, clus));
97  } else hits.push_back(clone(thit));
98  }
99  }
100 
101  TrackingRecHit * clone(BaseTrackerRecHit const & hit2D ) const {
102  auto const & detU = *hit2D.detUnit();
103  //Use 2D SiStripRecHit in endcap
104  bool endcap = detU.type().isEndcap();
105  if (endcap) return hit2D.clone();
106  return new SiStripRecHit1D(hit2D.localPosition(),
108  *hit2D.det(), hit2D.firstClusterRef());
109 
110  }
111 
112 
114  OmniClusterRef const & clus) const {
115  //Use 2D SiStripRecHit in endcap
116  bool endcap = idet.type().isEndcap();
117  auto && lv = theCPE->localParameters(clus.stripCluster(),idet);
118  if (endcap) return new SiStripRecHit2D(lv.first,lv.second,idet,clus);
119  return new SiStripRecHit1D(lv.first, LocalError(lv.second.xx(),0.f,std::numeric_limits<float>::max()),idet,clus);
120  }
121 
122  void split(TrajectoryMeasurement const & itm,
123  SiStripMatchedRecHit2D const& mhit, TrackingRecHitCollection & hits, float zdir) const {
124  const GluedGeomDet *gdet = static_cast<const GluedGeomDet *> (mhit.det());
125 
126  auto hitM = build (*gdet->monoDet(),
127  mhit.monoClusterRef());
128  auto hitS = build(*gdet->stereoDet(),
129  mhit.stereoClusterRef());
130 
131  // we should find a faster way
132  LocalPoint firstLocalPos =
133  itm.updatedState().surface().toLocal(gdet->monoDet()->position());
134  LocalPoint secondLocalPos =
135  itm.updatedState().surface().toLocal(gdet->stereoDet()->position());
136  LocalVector Delta = secondLocalPos - firstLocalPos;
137  float scalar = Delta.z() * zdir;
138  // hit along the direction
139  if(scalar<0) {
140  hits.push_back(hitS);
141  hits.push_back(hitM);
142  } else {
143  hits.push_back(hitM);
144  hits.push_back(hitS);
145  }
146 
147  }
148 
149 
150 };
151 
152 
153 #endif
float xx() const
Definition: LocalError.h:24
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
virtual const GeomDetType & type() const
Definition: GeomDet.cc:85
static unsigned char toChi2x5(float chi2)
bool isEndcap() const
Definition: GeomDetType.cc:18
OmniClusterRef const & stereoClusterRef() const
virtual void localParameters(AClusters const &clusters, ALocalValues &retValues, const GeomDetUnit &gd, const LocalTrajectoryParameters &ltp) const
Traj2TrackHits(const TransientTrackingRecHitBuilder *builder, bool ikeepOrder, bool noNoDet=true)
std::vector< unsigned char > Chi2sFive
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:140
DataContainer const & measurements() const
Definition: Trajectory.h:196
SiStripCluster const & stripCluster() const
TrackingRecHit * clone(BaseTrackerRecHit const &hit2D) const
void push_back(D *&d)
Definition: OwnVector.h:290
const SurfaceType & surface() const
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:48
const GeomDet * det() const
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:64
void shrink_to_fit()
Definition: OwnVector.h:128
std::vector< LocalTrajectoryParameters > TrajParams
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
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
void operator()(Trajectory const &traj, TrackingRecHitCollection &hits, TrajParams &trajParams, Chi2sFive &chi2s) const
virtual const GeomDetUnit * detUnit() const
bool isUndef(TrackingRecHit const &hit)
TrajectoryStateOnSurface const & updatedState() const
void copy(HI itm, HI e, TrackingRecHitCollection &hits, TrajParams &trajParams, Chi2sFive &chi2s) const
BaseTrackerRecHit * build(GeomDetUnit const &idet, OmniClusterRef const &clus) const
virtual LocalError localPositionError() const final
virtual LocalPoint localPosition() const final
void reserve(size_t)
Definition: OwnVector.h:284
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