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(const 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 
29 CSCSegment::~CSCSegment() {}
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 
48 LocalError CSCSegment::localPositionError() const {
49  return LocalError(theCovMatrix[2][2], theCovMatrix[2][3], theCovMatrix[3][3]);
50 }
51 
52 LocalError CSCSegment::localDirectionError() const {
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 
72 AlgebraicMatrix CSCSegment::projectionMatrix() const {
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 {
133  return testSharesAllInSpecificRecHits( theCSCRecHits , anotherSegment.specificRecHits(), sharesInput);
134 }
135 
136 //
137 bool CSCSegment::sharesRecHits(const CSCSegment & anotherSegment) const {
138  if(testSharesAllInSpecificRecHits( theCSCRecHits , anotherSegment.specificRecHits(), CSCRecHit2D::someWires) &&
139  testSharesAllInSpecificRecHits( theCSCRecHits , anotherSegment.specificRecHits(), CSCRecHit2D::someStrips)){
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
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
CLHEP::HepMatrix AlgebraicMatrix
T sqrt(T t)
Definition: SSEVec.h:48
tuple result
Definition: query.py:137
Definition: DetId.h:20
CLHEP::HepVector AlgebraicVector
#define N
Definition: blowfish.cc:9
float maxDiff(float one, float two, float three, float four)
CLHEP::HepSymMatrix AlgebraicSymMatrix
tuple cout
Definition: gather_cfg.py:121