CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DTSegmentCand.cc
Go to the documentation of this file.
1 
7 /* This Class Header */
9 
13 
14 /* Collaborating Class Header */
15 
16 /* C++ Headers */
17 
18 /* ====================================================================== */
19 const double DTSegmentCand::chi2max = 20.; // to be tuned!!
20 const unsigned int DTSegmentCand::nHitsMin = 3; // to be tuned!!
21 
23 DTSegmentCand::DTSegmentCand(AssPointCont& hits, const DTSuperLayer* sl) : theSL(sl), theChi2(-1.), theHits(hits) {}
24 
27  LocalVector& direction,
28  double chi2,
29  const AlgebraicSymMatrix& covMat,
30  const DTSuperLayer* sl)
31  : theSL(sl), thePosition(position), theDirection(direction), theChi2(chi2), theCovMatrix(covMat), theHits(hits) {}
32 
35 
36 /* Operations */
38  static const double epsilon = 0.00001;
39  if (nHits() != seg.nHits())
40  return false;
41  if (fabs(chi2() - seg.chi2()) > epsilon)
42  return false;
43  if (fabs(position().x() - seg.position().x()) > epsilon || fabs(position().y() - seg.position().y()) > epsilon ||
44  fabs(position().z() - seg.position().z()) > epsilon)
45  return false;
46  if (fabs(direction().x() - seg.direction().x()) > epsilon || fabs(direction().y() - seg.direction().y()) > epsilon ||
47  fabs(direction().z() - seg.direction().z()) > epsilon)
48  return false;
49  return true;
50 }
51 
53  if (nHits() == seg.nHits())
54  return (chi2() > seg.chi2());
55  return (nHits() < seg.nHits());
56 }
57 
58 void DTSegmentCand::add(AssPoint newHit) { theHits.insert(newHit); }
59 
60 void DTSegmentCand::add(std::shared_ptr<DTHitPairForFit> hit, DTEnums::DTCellSide code) {
61  AssPoint newHit(hit, code);
62  theHits.insert(newHit);
63 }
64 
65 void DTSegmentCand::removeHit(AssPoint badHit) { theHits.erase(badHit); }
66 
68  int result = 0;
69 
70  for (AssPointCont::const_iterator hit = theHits.begin(); hit != theHits.end(); ++hit) {
71  for (AssPointCont::const_iterator hit2 = seg.hits().begin(); hit2 != seg.hits().end(); ++hit2) {
72  // if(result) return result ; // TODO, uncomm this line or move it in another func
73  if ((*(*hit).first) == (*(*hit2).first)) {
74  ++result;
75  continue;
76  }
77  }
78  }
79  return result;
80 }
81 
84  const AssPointCont& hits2 = seg.theHits;
85 
86  // if (nSharedHitPairs(seg)==0) return result;
87 
88  AssPointCont::const_iterator hitBegin2 = hits2.begin(), hitEnd2 = hits2.end();
89  for (AssPointCont::const_iterator hit = theHits.begin(), hitEnd = theHits.end(); hit != hitEnd; ++hit) {
90  for (AssPointCont::const_iterator hit2 = hitBegin2; hit2 != hitEnd2; ++hit2) {
91  if ((*(*hit).first) == (*(*hit2).first) && (*hit).second != (*hit2).second) {
92  result.insert(*hit);
93  continue;
94  }
95  }
96  }
97  return result;
98 }
99 
100 bool DTSegmentCand::good() const {
101  // std::cout << NDOF() << " " << chi2()/NDOF() << " " << nHits() << std::endl;
102  if (NDOF() == 0)
103  return false;
104  if (chi2() / NDOF() > chi2max || nHits() < nHitsMin)
105  return false;
106 
107  if (nHits() == nHitsMin && hitsShareLayer())
108  return false;
109 
110  return true;
111 }
112 
114  const unsigned int hitsSize = theHits.size();
115  // we don't expect so many 1D hits, if such a segment arrives just drop it
116  if (hitsSize > 20)
117  return false;
118 
119  int layerN[hitsSize];
120  unsigned int i = 0;
121  for (DTSegmentCand::AssPointCont::iterator assHit = theHits.begin(); assHit != theHits.end(); ++assHit) {
122  layerN[i] = (*assHit).first->id().layerId().layer() + 10 * (*assHit).first->id().superlayerId().superlayer();
123  for (unsigned int j = 0; j < i; j++) {
124  if (layerN[i] == layerN[j])
125  return true;
126  }
127  i++;
128  }
129 
130  return false;
131 }
132 
134  // TODO
135  return 0;
136 }
137 
139  LocalPoint seg2Dposition = position();
140  LocalVector seg2DDirection = direction();
141  double seg2DChi2 = chi2();
142  AlgebraicSymMatrix seg2DCovMatrix = covMatrix();
143 
144  std::vector<DTRecHit1D> hits1D;
145  for (DTSegmentCand::AssPointCont::iterator assHit = theHits.begin(); assHit != theHits.end(); ++assHit) {
146  GlobalPoint hitGlobalPos = theSL->toGlobal((*assHit).first->localPosition((*assHit).second));
147 
148  LocalPoint hitPosInLayer = theSL->layer((*assHit).first->id().layerId())->toLocal(hitGlobalPos);
149 
150  DTRecHit1D hit(((*assHit).first)->id(),
151  (*assHit).second,
152  ((*assHit).first)->digiTime(),
153  hitPosInLayer,
154  ((*assHit).first)->localPositionError());
155  hits1D.push_back(hit);
156  }
157 
158  return new DTSLRecSegment2D(theSL->id(), seg2Dposition, seg2DDirection, seg2DCovMatrix, seg2DChi2, hits1D);
159 }
160 
162  // input position and direction are in sl frame, while must be stored in
163  // chamber one: so I have to extrapolate the position (along the direction) to
164  // the chamber reference plane.
165 
166  LocalPoint posInCh = theSL->chamber()->toLocal(theSL->toGlobal(position()));
167  LocalVector dirInCh = theSL->chamber()->toLocal(theSL->toGlobal(direction()));
168 
169  LocalPoint pos = posInCh + dirInCh * posInCh.z() / cos(dirInCh.theta());
170 
171  double seg2DChi2 = chi2();
172  AlgebraicSymMatrix seg2DCovMatrix = covMatrix();
173 
174  std::vector<DTRecHit1D> hits1D;
175  for (DTSegmentCand::AssPointCont::iterator assHit = theHits.begin(); assHit != theHits.end(); ++assHit) {
176  GlobalPoint hitGlobalPos = theSL->toGlobal((*assHit).first->localPosition((*assHit).second));
177 
178  LocalPoint hitPosInLayer = theSL->chamber()
179  ->superLayer((*assHit).first->id().superlayerId())
180  ->layer((*assHit).first->id().layerId())
181  ->toLocal(hitGlobalPos);
182 
183  DTRecHit1D hit(((*assHit).first)->id(),
184  (*assHit).second,
185  ((*assHit).first)->digiTime(),
186  hitPosInLayer,
187  ((*assHit).first)->localPositionError());
188  hits1D.push_back(hit);
189  }
190 
191  return new DTChamberRecSegment2D(theSL->chamber()->id(), pos, dirInCh, seg2DCovMatrix, seg2DChi2, hits1D);
192 
193  // chamber and Phi SLs' frame are oriented in the same way, only a transaltion,
194  // so the covariance matrix is the same!
195 }
196 
197 bool DTSegmentCand::AssPointLessZ::operator()(const AssPoint& pt1, const AssPoint& pt2) const {
198  return *(pt1.first) < *(pt2.first);
199 }
200 
201 std::ostream& operator<<(std::ostream& out, const DTSegmentCand& seg) {
202  out << " pos: " << seg.position() << " dir: " << seg.direction() << " chi2/nHits: " << seg.chi2() << "/"
203  << seg.DTSegmentCand::nHits() << " t0: " << seg.t0();
204  return out;
205 }
206 
207 std::ostream& operator<<(std::ostream& out, const DTSegmentCand::AssPoint& hit) {
208  // out << "Hits " << (hit.first)->localPosition(DTEnums::Left) <<
209  // " " << hit.second << " Lay " << (hit.first)->layerNumber() << endl;
210  return out;
211 }
std::pair< std::shared_ptr< DTHitPairForFit >, DTEnums::DTCellSide > AssPoint
Definition: DTSegmentCand.h:36
virtual const AssPointCont & hits() const
the used hits
T y() const
Definition: PV3DBase.h:60
DTCellSide
Which side of the DT cell.
Definition: DTEnums.h:15
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
virtual bool good() const
virtual unsigned int NDOF() const
Definition: DTSegmentCand.h:87
static const unsigned int nHitsMin
constexpr std::array< uint8_t, layerIndexSize > layer
tuple result
Definition: mps_fire.py:311
DTSegmentCand(AssPointCont &hits, const DTSuperLayer *sl)
Constructor.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
virtual bool operator==(const DTSegmentCand &seg)
equality operator based on position, direction, chi2 and nHits
virtual bool hitsShareLayer() const
virtual void add(AssPoint newHit)
add hits to the hit list.
virtual bool operator<(const DTSegmentCand &seg)
less operator based on nHits and chi2
AssPointCont theHits
T z() const
Definition: PV3DBase.h:61
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
static const double chi2max
bool operator()(const AssPoint &pt1, const AssPoint &pt2) const
virtual int nLayers() const
number of different layers with hits
virtual double chi2() const
the chi2 (NOT chi2/NDOF) of the fit
Definition: DTSegmentCand.h:61
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
virtual AssPointCont conflictingHitPairs(const DTSegmentCand &seg) const
std::set< AssPoint, AssPointLessZ > AssPointCont
Definition: DTSegmentCand.h:38
virtual unsigned int nHits() const
Definition: DTSegmentCand.h:58
virtual double t0() const
the t0 of the segment
Definition: DTSegmentCand.h:67
virtual LocalPoint position() const
Definition: DTSegmentCand.h:79
static int position[264][3]
Definition: ReadPGInfo.cc:289
virtual void removeHit(AssPoint hit)
remove hit from the candidate
CLHEP::HepSymMatrix AlgebraicSymMatrix
virtual ~DTSegmentCand()
Destructor.
virtual int nSharedHitPairs(const DTSegmentCand &seg) const
number of shared hit pair with other segment candidate
T x() const
Definition: PV3DBase.h:59
virtual LocalVector direction() const
Definition: DTSegmentCand.h:82