CMS 3D CMS Logo

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