CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFDisplacedVertexCandidate.cc
Go to the documentation of this file.
2 
5 
6 using namespace std;
7 using namespace reco;
8 
9 
10 PFDisplacedVertexCandidate::PFDisplacedVertexCandidate(){}
11 
12 void PFDisplacedVertexCandidate::addElement(const TrackBaseRef element) {
13  elements_.push_back( element );
14 }
15 
16 
17 void PFDisplacedVertexCandidate::setLink(const unsigned i1,
18  const unsigned i2,
19  const float dist,
20  const GlobalPoint& dcaPoint,
21  const VertexLinkTest test){
22 
23 
24  assert( test<LINKTEST_ALL );
25 
26  unsigned index = 0;
27  bool ok = matrix2vector(i1,i2, index);
28 
29  if(ok) {
30  //ignore the -1, -1 pair
31  if ( dist > -0.5 ) {
32  VertexLink & l = vertexLinkData_[index];
33  l.distance_ = dist;
34  l.dcaPoint_ = dcaPoint;
35  l.test_ |= (1 << test);
36  } else //delete if existing
37  {
38  VertexLinkData::iterator it = vertexLinkData_.find(index);
39  if(it!=vertexLinkData_.end()) vertexLinkData_.erase(it);
40  }
41 
42  } else {
43  assert(0);
44  }
45 
46 }
47 
48 
49 void PFDisplacedVertexCandidate::associatedElements( const unsigned i,
50  const VertexLinkData& vertexLinkData,
51  multimap<float, unsigned>& sortedAssociates,
52  const VertexLinkTest test ) const {
53 
54  sortedAssociates.clear();
55 
56  // i is too large
57  if( i > elements_.size() ) return;
58  // assert(i>=0); // i >= 0, since i is unsigned
59  for(unsigned ie=0; ie<elements_.size(); ie++) {
60 
61  // considered element itself
62  if( ie == i ) {
63  continue;
64  }
65 
66  // Order the elements by increasing distance !
67 
68  unsigned index = 0;
69  if( !matrix2vector(i, ie, index) ) continue;
70 
71  float c2=-1;
72  VertexLinkData::const_iterator it = vertexLinkData.find(index);
73  if ( it!=vertexLinkData.end() &&
74  ( ( (1 << test ) & it->second.test_) !=0 || (test == LINKTEST_ALL) ) )
75  c2= it->second.distance_;
76 
77  // not associated
78  if( c2 < 0 ) {
79  continue;
80  }
81 
82  sortedAssociates.insert( pair<float,unsigned>(c2, ie) );
83  }
84 }
85 
86 
87 
88 
89 
90 
91 
92 // -------- Provide useful information -------- //
93 
94 
95 PFDisplacedVertexCandidate::DistMap PFDisplacedVertexCandidate::r2Map() const {
96 
97  DistMap r2Map;
98 
99  for (unsigned ie1 = 0; ie1<elements_.size(); ie1++)
100  for (unsigned ie2 = ie1+1; ie2<elements_.size(); ie2++){
101 
102  GlobalPoint P = dcaPoint(ie1, ie2);
103  if (P.x() > 1e9) continue;
104 
105  float r2 = P.x()*P.x()+P.y()*P.y()+P.z()*P.z();
106 
107  r2Map.insert(pair<float, pair<int,int> >(r2, pair <int, int>(ie1, ie2)));
108  }
109 
110  return r2Map;
111 
112 }
113 
114 
115 
116 PFDisplacedVertexCandidate::DistVector PFDisplacedVertexCandidate::r2Vector() const {
117 
118  DistVector r2Vector;
119 
120  for (unsigned ie1 = 0; ie1<elements_.size(); ie1++)
121  for (unsigned ie2 = ie1+1; ie2<elements_.size(); ie2++){
122 
123  GlobalPoint P = dcaPoint(ie1, ie2);
124  if (P.x() > 1e9) continue;
125 
126  float r2 = P.x()*P.x()+P.y()*P.y()+P.z()*P.z();
127 
128  r2Vector.push_back(r2);
129  }
130 
131  return r2Vector;
132 
133 }
134 
135 
136 PFDisplacedVertexCandidate::DistVector PFDisplacedVertexCandidate::distVector() const {
137 
138  DistVector distVector;
139 
140 
141  for (unsigned ie1 = 0; ie1<elements_.size(); ie1++)
142  for (unsigned ie2 = ie1+1; ie2<elements_.size(); ie2++){
143 
144  float d = dist(ie1, ie2);
145  if (d < -0.5) continue;
146 
147  distVector.push_back(d);
148 
149  }
150 
151  return distVector;
152 
153 }
154 
155 const GlobalPoint PFDisplacedVertexCandidate::dcaPoint( unsigned ie1, unsigned ie2) const {
156 
157  GlobalPoint dcaPoint(1e10,1e10,1e10);
158 
159  unsigned index = 0;
160  if( !matrix2vector(ie1, ie2, index) ) return dcaPoint;
161  VertexLinkData::const_iterator it = vertexLinkData_.find(index);
162  if( it!=vertexLinkData_.end() ) dcaPoint = it->second.dcaPoint_;
163 
164  return dcaPoint;
165 
166 }
167 
168 
169 // -------- Internal tools -------- //
170 
171 bool PFDisplacedVertexCandidate::testLink(unsigned ie1, unsigned ie2) const {
172  float d = dist( ie1, ie2);
173  if (d < -0.5) return false;
174  return true;
175 }
176 
177 
178 const float PFDisplacedVertexCandidate::dist( unsigned ie1, unsigned ie2) const {
179 
180  float dist = -1;
181 
182  unsigned index = 0;
183  if( !matrix2vector(ie1, ie2, index) ) return dist;
184  VertexLinkData::const_iterator it = vertexLinkData_.find(index);
185  if( it!=vertexLinkData_.end() ) dist= it->second.distance_;
186 
187  return dist;
188 
189 }
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 // -------- Storage of the information -------- //
200 
201 
202 unsigned PFDisplacedVertexCandidate::vertexLinkDataSize() const {
203  unsigned n = elements_.size();
204 
205  // number of possible undirected links between n elements.
206  // reflective links impossible.
207 
208  return n*(n-1)/2;
209 }
210 
211 
212 bool PFDisplacedVertexCandidate::matrix2vector( unsigned iindex,
213  unsigned jindex,
214  unsigned& index ) const {
215 
216  unsigned size = elements_.size();
217  if( iindex == jindex ||
218  iindex >= size ||
219  jindex >= size ) {
220  return false;
221  }
222 
223  if( iindex > jindex )
224  swap( iindex, jindex);
225 
226 
227  index = jindex-iindex-1;
228 
229  if(iindex>0) {
230  index += iindex*size;
231  unsigned missing = iindex*(iindex+1)/2;
232  index -= missing;
233  }
234 
235  return true;
236 }
237 
238 void PFDisplacedVertexCandidate::Dump( ostream& out ) const {
239  if(! out ) return;
240 
241  const vector < TrackBaseRef >& elements = elements_;
242  out<<"\t--- DisplacedVertexCandidate --- "<<endl;
243  out<<"\tnumber of elements: "<<elements.size()<<endl;
244 
245  // Build element label (string) : elid from type, layer and occurence number
246  // use stringstream instead of sprintf to concatenate string and integer into string
247  for(unsigned ie=0; ie<elements.size(); ie++) {
248 
249  math::XYZPoint Pi(elements[ie].get()->innerPosition());
250  math::XYZPoint Po(elements[ie].get()->outerPosition());
251 
252  float innermost_radius = sqrt(Pi.x()*Pi.x() + Pi.y()*Pi.y() + Pi.z()*Pi.z());
253  float outermost_radius = sqrt(Po.x()*Po.x() + Po.y()*Po.y() + Po.z()*Po.z());
254  float innermost_rho = sqrt(Pi.x()*Pi.x() + Pi.y()*Pi.y());
255  float outermost_rho = sqrt(Po.x()*Po.x() + Po.y()*Po.y());
256 
257  double pt = elements[ie]->pt();
258 
259 
260  out<<"ie = " << elements[ie].key() << " pt = " << pt
261  <<" innermost hit radius = " << innermost_radius << " rho = " << innermost_rho
262  <<" outermost hit radius = " << outermost_radius << " rho = " << outermost_rho
263  <<endl;
264  }
265 
266  out<<endl;
267 
268 
269 }
270 
const double Pi
dictionary missing
Definition: combine.py:4
int i
Definition: DBlmapReader.cc:9
list elements
Definition: asciidump.py:414
#define P
std::map< float, std::pair< int, int > > DistMap
std::map< unsigned int, VertexLink > VertexLinkData
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:46
tuple out
Definition: dbtoconf.py:99
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:18
tuple size
Write out results.