CMS 3D CMS Logo

CSCSegment.cc
Go to the documentation of this file.
1 
7 #include <iostream>
8 
9 namespace {
10  // Get CSCDetId from one of the rechits, but then remove the layer part so it's a _chamber_ id
11  inline DetId buildDetId(CSCDetId id) { return CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), 0); }
12 
13 } // namespace
14 
15 CSCSegment::CSCSegment(const std::vector<const CSCRecHit2D*>& proto_segment,
16  LocalPoint origin,
17  LocalVector direction,
19  double chi2)
20  : RecSegment(buildDetId(proto_segment.front()->cscDetId())),
21  theOrigin(origin),
22  theLocalDirection(direction),
23  theCovMatrix(errors),
24  theChi2(chi2),
25  aME11a_duplicate(false) {
26  for (unsigned int i = 0; i < proto_segment.size(); ++i)
27  theCSCRecHits.push_back(*proto_segment[i]);
28 }
29 
31 
32 std::vector<const TrackingRecHit*> CSCSegment::recHits() const {
33  std::vector<const TrackingRecHit*> pointersOfRecHits;
34  for (std::vector<CSCRecHit2D>::const_iterator irh = theCSCRecHits.begin(); irh != theCSCRecHits.end(); ++irh) {
35  pointersOfRecHits.push_back(&(*irh));
36  }
37  return pointersOfRecHits;
38 }
39 
40 std::vector<TrackingRecHit*> CSCSegment::recHits() {
41  std::vector<TrackingRecHit*> pointersOfRecHits;
42  for (std::vector<CSCRecHit2D>::iterator irh = theCSCRecHits.begin(); irh != theCSCRecHits.end(); ++irh) {
43  pointersOfRecHits.push_back(&(*irh));
44  }
45  return pointersOfRecHits;
46 }
47 
49  return LocalError(theCovMatrix[2][2], theCovMatrix[2][3], theCovMatrix[3][3]);
50 }
51 
53  return LocalError(theCovMatrix[0][0], theCovMatrix[0][1], theCovMatrix[1][1]);
54 }
55 
57  // For consistency with DT and what we require for the TrackingRecHit interface,
58  // the order of the parameters in the returned vector should be (dx/dz, dy/dz, x, z)
59 
61 
64  result[2] = theOrigin.x();
65  result[3] = theOrigin.y();
66 
67  return result;
68 }
69 
71  AlgebraicMatrix m(4, 5, 0);
72  m[0][1] = 1;
73  m[1][2] = 1;
74  m[2][3] = 1;
75  m[3][4] = 1;
76  return m;
77 }
78 
80 
82 
83 void CSCSegment::setDuplicateSegments(std::vector<CSCSegment*>& duplicates) {
84  theDuplicateSegments.clear();
85  for (unsigned int i = 0; i < duplicates.size(); ++i) {
86  theDuplicateSegments.push_back(*duplicates[i]);
87  //avoid copying duplicates of duplicates of duplicates...
88  theDuplicateSegments.back().theDuplicateSegments.resize(0);
89  }
90 }
91 
92 bool CSCSegment::testSharesAllInSpecificRecHits(const std::vector<CSCRecHit2D>& specificRecHits_1,
93  const std::vector<CSCRecHit2D>& specificRecHits_2,
94  CSCRecHit2D::SharedInputType sharesInput) const {
95  const std::vector<CSCRecHit2D>* rhContainer_1 = &specificRecHits_1;
96  const std::vector<CSCRecHit2D>* rhContainer_2 = &specificRecHits_2;
97  if (specificRecHits_1.size() > specificRecHits_2.size()) {
98  rhContainer_2 = &specificRecHits_1;
99  rhContainer_1 = &specificRecHits_2;
100  }
101  //
102  bool shareConditionPassed = true;
103  for (std::vector<CSCRecHit2D>::const_iterator itRH = rhContainer_1->begin(); itRH != rhContainer_1->end(); ++itRH) {
104  const CSCRecHit2D* firstRecHit = &(*itRH);
105  bool sharedHit = false;
106  for (std::vector<CSCRecHit2D>::const_iterator itRH2 = rhContainer_2->begin(); itRH2 != rhContainer_2->end();
107  ++itRH2) {
108  if (itRH2->sharesInput(firstRecHit, sharesInput)) {
109  sharedHit = true;
110  break;
111  }
112  }
113  if (!sharedHit) {
114  shareConditionPassed = false;
115  break;
116  }
117  }
118  return shareConditionPassed;
119 }
120 
121 //bool CSCSegment::sharesRecHits(CSCSegment & anotherSegment, CSCRecHit2D::SharedInputType sharesInput){
122 // 2 tracks through a chamber leave 4 rechits per layer (2 strips x 2 wire groups)
123 // this function finds segments sharing wires or strips (first the rechits by sharesInput() )
124 // there could probably be more complicated cases with partial sharing (but this needs studies)
125 //
126 //return testSharesAllInSpecificRecHits( theCSCRecHits , anotherSegment.specificRecHits(), sharesInput);
127 //}
128 
129 bool CSCSegment::sharesRecHits(const CSCSegment& anotherSegment, CSCRecHit2D::SharedInputType sharesInput) const {
131 }
132 
133 //
134 bool CSCSegment::sharesRecHits(const CSCSegment& anotherSegment) const {
137  return true;
138  } else {
139  return false;
140  }
141 }
142 //
143 
144 float CSCSegment::time() const {
145  float averageTime = 0;
146  std::vector<float> wireTimes;
147  for (std::vector<CSCRecHit2D>::const_iterator itRH = theCSCRecHits.begin(); itRH != theCSCRecHits.end(); ++itRH) {
148  const CSCRecHit2D* recHit = &(*itRH);
149  averageTime += recHit->tpeak();
150  averageTime += recHit->wireTime();
151  wireTimes.push_back(recHit->wireTime());
152  }
153  averageTime = averageTime / (2 * theCSCRecHits.size());
154 
155  //The wire times have a long tail that has to be pruned. The strip times (tpeak) are fine
156  bool modified = true;
157  while (modified) {
158  modified = false;
159  double maxDiff = -1;
160  std::vector<float>::iterator maxHit;
161  for (std::vector<float>::iterator itWT = wireTimes.begin(); itWT != wireTimes.end(); ++itWT) {
162  float diff = fabs(*itWT - averageTime);
163  if (diff > maxDiff) {
164  maxDiff = diff;
165  maxHit = itWT;
166  }
167  }
168  if (maxDiff > 26) {
169  int N = theCSCRecHits.size() + wireTimes.size();
170  averageTime = (averageTime * N - (*maxHit)) / (N - 1);
171  wireTimes.erase(maxHit);
172  modified = true;
173  }
174  }
175  return averageTime;
176 }
177 
178 //
179 void CSCSegment::print() const { std::cout << *this << std::endl; }
180 
181 std::ostream& operator<<(std::ostream& os, const CSCSegment& seg) {
182  os << "CSCSegment: local pos = " << seg.localPosition() << " posErr = (" << sqrt(seg.localPositionError().xx()) << ","
183  << sqrt(seg.localPositionError().yy()) << "0,)\n"
184  << " dir = " << seg.localDirection() << " dirErr = (" << sqrt(seg.localDirectionError().xx()) << ","
185  << sqrt(seg.localDirectionError().yy()) << "0,)\n"
186  << " chi2/ndf = " << seg.chi2() / double(seg.degreesOfFreedom())
187  << " #rechits = " << seg.specificRecHits().size() << " ME1/1a duplicates : " << seg.duplicateSegments().size();
188  return os;
189 }
190 
191 /*
192 const CSCChamber* CSCSegment::chamber() const { return theChamber; }
193 */
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
Definition: CSCSegment.cc:32
bool sharesRecHits(const CSCSegment &anotherSegment, CSCRecHit2D::SharedInputType sharesInput) const
Definition: CSCSegment.cc:129
float time() const
Definition: CSCSegment.cc:144
LocalPoint localPosition() const override
Definition: CSCSegment.h:39
AlgebraicVector parameters() const override
Parameters of the segment, for the track fit in the order (dx/dz, dy/dz, x, y )
Definition: CSCSegment.cc:56
T z() const
Definition: PV3DBase.h:61
std::vector< CSCSegment > theDuplicateSegments
Definition: CSCSegment.h:99
static const AlgebraicMatrix theProjectionMatrix
Definition: CSCSegment.cc:79
double chi2() const override
Chi2 of the segment fit.
Definition: CSCSegment.h:58
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
LocalVector localDirection() const override
Local direction.
Definition: CSCSegment.h:42
float yy() const
Definition: LocalError.h:24
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
~CSCSegment() override
Destructor.
Definition: CSCSegment.cc:30
CLHEP::HepMatrix AlgebraicMatrix
T sqrt(T t)
Definition: SSEVec.h:23
AlgebraicSymMatrix theCovMatrix
Definition: CSCSegment.h:96
void print() const
Definition: CSCSegment.cc:179
int degreesOfFreedom() const override
Degrees of freedom of the segment fit.
Definition: CSCSegment.h:62
LocalPoint theOrigin
Definition: CSCSegment.h:94
std::ostream & operator<<(std::ostream &os, const CSCSegment &seg)
Definition: CSCSegment.cc:181
LocalError localDirectionError() const override
Error on the local direction.
Definition: CSCSegment.cc:52
Definition: DetId.h:17
CLHEP::HepVector AlgebraicVector
std::vector< CSCRecHit2D > theCSCRecHits
Definition: CSCSegment.h:93
#define N
Definition: blowfish.cc:9
float maxDiff(float one, float two, float three, float four)
CSCSegment()
Default constructor.
Definition: CSCSegment.h:24
AlgebraicMatrix projectionMatrix() const override
The projection matrix relates the trajectory state parameters to the segment parameters().
Definition: CSCSegment.cc:81
AlgebraicMatrix createStaticMatrix()
Definition: CSCSegment.cc:70
bool testSharesAllInSpecificRecHits(const std::vector< CSCRecHit2D > &specificRecHits_1, const std::vector< CSCRecHit2D > &specificRecHits_2, CSCRecHit2D::SharedInputType) const
Definition: CSCSegment.cc:92
LocalVector theLocalDirection
Definition: CSCSegment.h:95
CLHEP::HepSymMatrix AlgebraicSymMatrix
const std::vector< CSCRecHit2D > & specificRecHits() const
Definition: CSCSegment.h:66
Definition: errors.py:1
LocalError localPositionError() const override
Definition: CSCSegment.cc:48
const std::vector< CSCSegment > & duplicateSegments() const
Definition: CSCSegment.h:76
float xx() const
Definition: LocalError.h:22
void setDuplicateSegments(std::vector< CSCSegment *> &duplicates)
Definition: CSCSegment.cc:83