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