CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTSegmentCand.cc
Go to the documentation of this file.
1 
7 /* This Class Header */
9 
13 
14 /* Collaborating Class Header */
15 
16 /* C++ Headers */
17 
18 /* ====================================================================== */
19 const double DTSegmentCand::chi2max=20.; // to be tuned!!
20 const unsigned int DTSegmentCand::nHitsMin=3; // to be tuned!!
21 
24  const DTSuperLayer* sl) :
25 theSL(sl), theChi2(-1.) , theHits(hits){
26 }
27 
30  LocalVector& direction,
31  double chi2,
32  const AlgebraicSymMatrix& covMat,
33  const DTSuperLayer* sl) :
34 theSL(sl), thePosition(position), theDirection(direction), theChi2(chi2),
35  theCovMatrix( covMat), theHits(hits) {
36 }
37 
40 }
41 
42 /* Operations */
44  static const double epsilon=0.00001;
45  if (nHits()!=seg.nHits()) return false;
46  if (fabs(chi2()-seg.chi2())>epsilon) return false;
47  if (fabs(position().x()-seg.position().x())>epsilon ||
48  fabs(position().y()-seg.position().y())>epsilon ||
49  fabs(position().z()-seg.position().z())>epsilon) return false;
50  if (fabs(direction().x()-seg.direction().x())>epsilon ||
51  fabs(direction().y()-seg.direction().y())>epsilon ||
52  fabs(direction().z()-seg.direction().z())>epsilon) return false;
53  return true;
54 }
55 
57  if (nHits()==seg.nHits()) return (chi2()>seg.chi2());
58  return (nHits()<seg.nHits());
59 }
60 
61 void DTSegmentCand::add(std::shared_ptr<DTHitPairForFit> hit, DTEnums::DTCellSide code) {
62  theHits.insert(AssPoint(hit,code));
63 }
64 
66  theHits.erase(badHit);
67 }
68 
70  int result=0;
71  AssPointCont hitsCont = seg.hits();
72 
73  for (AssPointCont::const_iterator hit=theHits.begin();
74  hit!=theHits.end() ; ++hit) {
75  for (AssPointCont::const_iterator hit2=hitsCont.begin();
76  hit2!=hitsCont.end() ; ++hit2) {
77  // if(result) return result ; // TODO, uncomm this line or move it in another func
78  if ((*(*hit).first)==(*(*hit2).first)) {
79  ++result;
80  continue;
81  }
82  }
83  }
84  return result;
85 }
86 
90  const AssPointCont & hits2 = seg.theHits;
91 
92 // if (nSharedHitPairs(seg)==0) return result;
93 
94  AssPointCont::const_iterator hitBegin2 = hits2.begin(), hitEnd2 = hits2.end();
95  for (AssPointCont::const_iterator hit = theHits.begin(), hitEnd = theHits.end();
96  hit != hitEnd ; ++hit) {
97  for (AssPointCont::const_iterator hit2 = hitBegin2; hit2 != hitEnd2; ++hit2) {
98  if ((*(*hit).first)==(*(*hit2).first) &&
99  (*hit).second != (*hit2).second) {
100  result.insert(*hit);
101  continue;
102  }
103  }
104  }
105  return result;
106 }
107 
109 {
110  // std::cout << NDOF() << " " << chi2()/NDOF() << " " << nHits() << std::endl;
111  if(NDOF() == 0) return false;
112  if(chi2()/NDOF() > chi2max || nHits() < nHitsMin) return false;
113 
114  if(nHits() == nHitsMin && hitsShareLayer()) return false ;
115 
116  return true;
117 }
118 
120 {
121  int layerN[20];
122  int i=0;
123 
124  // we don't expect so many 1D hits, if such a segment arrives just drop it
125  if (theHits.size()>20) return false;
126 
127  for(DTSegmentCand::AssPointCont::iterator assHit=theHits.begin();
128  assHit!=theHits.end(); ++assHit) {
129  layerN[i]=(*assHit).first->id().layerId().layer()+10*(*assHit).first->id().superlayerId().superlayer();
130  i++;
131 // std::cout << (*assHit).first->id().layerId().layer()+10*(*assHit).first->id().superlayerId().superlayer()) << std::endl;
132  }
133 
134  for(int i=0;i<(int)theHits.size();i++){
135  for(int j=0;j<i;j++){
136  if(layerN[i] == layerN[j]) return true;
137  }
138  }
139 
140  return false;
141 }
142 
144  // TODO
145  return 0;
146 }
147 
149 
150  LocalPoint seg2Dposition = position();
151  LocalVector seg2DDirection = direction();
152  double seg2DChi2 = chi2();
153  AlgebraicSymMatrix seg2DCovMatrix = covMatrix();
154 
155  std::vector<DTRecHit1D> hits1D;
156  for(DTSegmentCand::AssPointCont::iterator assHit=theHits.begin();
157  assHit!=theHits.end(); ++assHit) {
158 
159  GlobalPoint hitGlobalPos =
160  theSL->toGlobal( (*assHit).first->localPosition((*assHit).second) );
161 
162  LocalPoint hitPosInLayer =
163  theSL->layer( (*assHit).first->id().layerId() )->toLocal(hitGlobalPos);
164 
165  DTRecHit1D hit( ((*assHit).first)->id(),
166  (*assHit).second,
167  ((*assHit).first)->digiTime(),
168  hitPosInLayer,
169  ((*assHit).first)->localPositionError() );
170  hits1D.push_back(hit);
171  }
172 
173  return new DTSLRecSegment2D(theSL->id(),
174  seg2Dposition,seg2DDirection,seg2DCovMatrix,
175  seg2DChi2,hits1D);
176 }
177 
179 
180  // input position and direction are in sl frame, while must be stored in
181  // chamber one: so I have to extrapolate the position (along the direction) to
182  // the chamber reference plane.
183 
184  LocalPoint posInCh = theSL->chamber()->toLocal(theSL->toGlobal( position() ));
185  LocalVector dirInCh= theSL->chamber()->toLocal(theSL->toGlobal( direction() ));
186 
187  LocalPoint pos=posInCh + dirInCh * posInCh.z()/cos(dirInCh.theta());
188 
189  double seg2DChi2 = chi2();
190  AlgebraicSymMatrix seg2DCovMatrix = covMatrix();
191 
192  std::vector<DTRecHit1D> hits1D;
193  for(DTSegmentCand::AssPointCont::iterator assHit=theHits.begin();
194  assHit!=theHits.end(); ++assHit) {
195 
196  GlobalPoint hitGlobalPos =
197  theSL->toGlobal( (*assHit).first->localPosition((*assHit).second) );
198 
199  LocalPoint hitPosInLayer =
200  theSL->chamber()
201  ->superLayer((*assHit).first->id().superlayerId())
202  ->layer( (*assHit).first->id().layerId() )->toLocal(hitGlobalPos);
203 
204  DTRecHit1D hit( ((*assHit).first)->id(),
205  (*assHit).second,
206  ((*assHit).first)->digiTime(),
207  hitPosInLayer,
208  ((*assHit).first)->localPositionError() );
209  hits1D.push_back(hit);
210  }
211 
212  return new DTChamberRecSegment2D(theSL->chamber()->id(),
213  pos,dirInCh,seg2DCovMatrix,
214  seg2DChi2,hits1D);
215 
216  // chamber and Phi SLs' frame are oriented in the same way, only a transaltion,
217  // so the covariance matrix is the same!
218 }
219 
220 
222  const AssPoint& pt2) const {
223  return *(pt1.first) < *(pt2.first);
224 }
225 
226 std::ostream& operator<<(std::ostream& out, const DTSegmentCand& seg) {
227  out << " pos: " << seg.position() << " dir: " << seg.direction()
228  << " chi2/nHits: " << seg.chi2() << "/" << seg.DTSegmentCand::nHits()
229  << " t0: " << seg.t0();
230  return out;
231 }
232 
233 std::ostream& operator<<(std::ostream& out, const DTSegmentCand::AssPoint& hit) {
234  // out << "Hits " << (hit.first)->localPosition(DTEnums::Left) <<
235  // " " << hit.second << " Lay " << (hit.first)->layerNumber() << endl;
236  return out;
237 }
std::pair< std::shared_ptr< DTHitPairForFit >, DTEnums::DTCellSide > AssPoint
Definition: DTSegmentCand.h:38
int i
Definition: DBlmapReader.cc:9
virtual void add(std::shared_ptr< DTHitPairForFit > hit, DTEnums::DTCellSide code)
add hits to the hit list.
T y() const
Definition: PV3DBase.h:63
DTCellSide
Which side of the DT cell.
Definition: DTEnums.h:15
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
virtual bool good() const
virtual unsigned int NDOF() const
Definition: DTSegmentCand.h:90
static const unsigned int nHitsMin
DTSegmentCand(AssPointCont &hits, const DTSuperLayer *sl)
Constructor.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
virtual bool operator==(const DTSegmentCand &seg)
equality operator based on position, direction, chi2 and nHits
virtual bool hitsShareLayer() const
virtual bool operator<(const DTSegmentCand &seg)
less operator based on nHits and chi2
AssPointCont theHits
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
static const double chi2max
int j
Definition: DBlmapReader.cc:9
bool operator()(const AssPoint &pt1, const AssPoint &pt2) const
virtual int nLayers() const
number of different layers with hits
virtual double chi2() const
the chi2 (NOT chi2/NDOF) of the fit
Definition: DTSegmentCand.h:64
virtual AssPointCont hits() const
the used hits
tuple out
Definition: dbtoconf.py:99
virtual AssPointCont conflictingHitPairs(const DTSegmentCand &seg) const
std::set< AssPoint, AssPointLessZ > AssPointCont
Definition: DTSegmentCand.h:40
virtual unsigned int nHits() const
Definition: DTSegmentCand.h:61
virtual double t0() const
the t0 of the segment
Definition: DTSegmentCand.h:70
virtual LocalPoint position() const
Definition: DTSegmentCand.h:82
static int position[264][3]
Definition: ReadPGInfo.cc:509
virtual void removeHit(AssPoint hit)
remove hit from the candidate
CLHEP::HepSymMatrix AlgebraicSymMatrix
virtual ~DTSegmentCand()
Destructor.
virtual int nSharedHitPairs(const DTSegmentCand &seg) const
number of shared hit pair with other segment candidate
volatile std::atomic< bool > shutdown_flag false
const double epsilon
T x() const
Definition: PV3DBase.h:62
virtual LocalVector direction() const
Definition: DTSegmentCand.h:85