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 
28 CSCSegment::~CSCSegment() {}
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 
47 LocalError CSCSegment::localPositionError() const {
48  return LocalError(theCovMatrix[2][2], theCovMatrix[2][3], theCovMatrix[3][3]);
49 }
50 
51 LocalError CSCSegment::localDirectionError() const {
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 
82 AlgebraicMatrix CSCSegment::projectionMatrix() const {
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 {
134  return testSharesAllInSpecificRecHits( theCSCRecHits , anotherSegment.specificRecHits(), sharesInput);
135 }
136 
137 //
138 bool CSCSegment::sharesRecHits(const CSCSegment & anotherSegment) const {
139  if(testSharesAllInSpecificRecHits( theCSCRecHits , anotherSegment.specificRecHits(), CSCRecHit2D::someWires) &&
140  testSharesAllInSpecificRecHits( theCSCRecHits , anotherSegment.specificRecHits(), CSCRecHit2D::someStrips)){
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
dictionary parameters
Definition: Parameters.py:2
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
static const AlgebraicMatrix theProjectionMatrix
Definition: CSCSegment.cc:80
CLHEP::HepMatrix AlgebraicMatrix
T sqrt(T t)
Definition: SSEVec.h:48
tuple result
Definition: query.py:137
Definition: DetId.h:18
CLHEP::HepVector AlgebraicVector
#define N
Definition: blowfish.cc:9
float maxDiff(float one, float two, float three, float four)
AlgebraicMatrix createStaticMatrix()
Definition: CSCSegment.cc:70
CLHEP::HepSymMatrix AlgebraicSymMatrix
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false