CMS 3D CMS Logo

PFDisplacedVertexCandidate.cc
Go to the documentation of this file.
2 
5 
6 using namespace std;
7 using namespace reco;
8 
9 PFDisplacedVertexCandidate::PFDisplacedVertexCandidate() {}
10 
11 void PFDisplacedVertexCandidate::addElement(const TrackBaseRef element) { elements_.push_back(element); }
12 
13 void PFDisplacedVertexCandidate::setLink(
14  const unsigned i1, const unsigned i2, const float dist, const GlobalPoint& dcaPoint, const VertexLinkTest test) {
15  assert(test < LINKTEST_ALL);
16 
17  unsigned index = 0;
18  bool ok = matrix2vector(i1, i2, index);
19 
20  if (ok) {
21  //ignore the -1, -1 pair
22  if (dist > -0.5) {
23  VertexLink& l = vertexLinkData_[index];
24  l.distance_ = dist;
25  l.dcaPoint_ = dcaPoint;
26  l.test_ |= (1 << test);
27  } else //delete if existing
28  {
29  VertexLinkData::iterator it = vertexLinkData_.find(index);
30  if (it != vertexLinkData_.end())
31  vertexLinkData_.erase(it);
32  }
33 
34  } else {
35  assert(0);
36  }
37 }
38 
39 void PFDisplacedVertexCandidate::associatedElements(const unsigned i,
40  const VertexLinkData& vertexLinkData,
41  multimap<float, unsigned>& sortedAssociates,
42  const VertexLinkTest test) const {
43  sortedAssociates.clear();
44 
45  // i is too large
46  if (i > elements_.size())
47  return;
48  // assert(i>=0); // i >= 0, since i is unsigned
49  for (unsigned ie = 0; ie < elements_.size(); ie++) {
50  // considered element itself
51  if (ie == i) {
52  continue;
53  }
54 
55  // Order the elements by increasing distance !
56 
57  unsigned index = 0;
58  if (!matrix2vector(i, ie, index))
59  continue;
60 
61  float c2 = -1;
62  VertexLinkData::const_iterator it = vertexLinkData.find(index);
63  if (it != vertexLinkData.end() && (((1 << test) & it->second.test_) != 0 || (test == LINKTEST_ALL)))
64  c2 = it->second.distance_;
65 
66  // not associated
67  if (c2 < 0) {
68  continue;
69  }
70 
71  sortedAssociates.insert(pair<float, unsigned>(c2, ie));
72  }
73 }
74 
75 // -------- Provide useful information -------- //
76 
77 PFDisplacedVertexCandidate::DistMap PFDisplacedVertexCandidate::r2Map() const {
78  DistMap r2Map;
79 
80  for (unsigned ie1 = 0; ie1 < elements_.size(); ie1++)
81  for (unsigned ie2 = ie1 + 1; ie2 < elements_.size(); ie2++) {
82  GlobalPoint P = dcaPoint(ie1, ie2);
83  if (P.x() > 1e9)
84  continue;
85 
86  float r2 = P.x() * P.x() + P.y() * P.y() + P.z() * P.z();
87 
88  r2Map.insert(pair<float, pair<int, int> >(r2, pair<int, int>(ie1, ie2)));
89  }
90 
91  return r2Map;
92 }
93 
94 PFDisplacedVertexCandidate::DistVector PFDisplacedVertexCandidate::r2Vector() const {
95  DistVector r2Vector;
96 
97  for (unsigned ie1 = 0; ie1 < elements_.size(); ie1++)
98  for (unsigned ie2 = ie1 + 1; ie2 < elements_.size(); ie2++) {
99  GlobalPoint P = dcaPoint(ie1, ie2);
100  if (P.x() > 1e9)
101  continue;
102 
103  float r2 = P.x() * P.x() + P.y() * P.y() + P.z() * P.z();
104 
105  r2Vector.push_back(r2);
106  }
107 
108  return r2Vector;
109 }
110 
111 PFDisplacedVertexCandidate::DistVector PFDisplacedVertexCandidate::distVector() const {
112  DistVector distVector;
113 
114  for (unsigned ie1 = 0; ie1 < elements_.size(); ie1++)
115  for (unsigned ie2 = ie1 + 1; ie2 < elements_.size(); ie2++) {
116  float d = dist(ie1, ie2);
117  if (d < -0.5)
118  continue;
119 
120  distVector.push_back(d);
121  }
122 
123  return distVector;
124 }
125 
126 const GlobalPoint PFDisplacedVertexCandidate::dcaPoint(unsigned ie1, unsigned ie2) const {
127  GlobalPoint dcaPoint(1e10, 1e10, 1e10);
128 
129  unsigned index = 0;
130  if (!matrix2vector(ie1, ie2, index))
131  return dcaPoint;
132  VertexLinkData::const_iterator it = vertexLinkData_.find(index);
133  if (it != vertexLinkData_.end())
134  dcaPoint = it->second.dcaPoint_;
135 
136  return dcaPoint;
137 }
138 
139 // -------- Internal tools -------- //
140 
141 bool PFDisplacedVertexCandidate::testLink(unsigned ie1, unsigned ie2) const {
142  float d = dist(ie1, ie2);
143  if (d < -0.5)
144  return false;
145  return true;
146 }
147 
148 const float PFDisplacedVertexCandidate::dist(unsigned ie1, unsigned ie2) const {
149  float dist = -1;
150 
151  unsigned index = 0;
152  if (!matrix2vector(ie1, ie2, index))
153  return dist;
154  VertexLinkData::const_iterator it = vertexLinkData_.find(index);
155  if (it != vertexLinkData_.end())
156  dist = it->second.distance_;
157 
158  return dist;
159 }
160 
161 // -------- Storage of the information -------- //
162 
163 unsigned PFDisplacedVertexCandidate::vertexLinkDataSize() const {
164  unsigned n = elements_.size();
165 
166  // number of possible undirected links between n elements.
167  // reflective links impossible.
168 
169  return n * (n - 1) / 2;
170 }
171 
172 bool PFDisplacedVertexCandidate::matrix2vector(unsigned iindex, unsigned jindex, unsigned& index) const {
173  unsigned size = elements_.size();
174  if (iindex == jindex || iindex >= size || jindex >= size) {
175  return false;
176  }
177 
178  if (iindex > jindex)
179  swap(iindex, jindex);
180 
181  index = jindex - iindex - 1;
182 
183  if (iindex > 0) {
184  index += iindex * size;
185  unsigned missing = iindex * (iindex + 1) / 2;
186  index -= missing;
187  }
188 
189  return true;
190 }
191 
192 void PFDisplacedVertexCandidate::Dump(ostream& out) const {
193  if (!out)
194  return;
195 
196  const vector<TrackBaseRef>& elements = elements_;
197  out << "\t--- DisplacedVertexCandidate --- " << endl;
198  out << "\tnumber of elements: " << elements.size() << endl;
199 
200  // Build element label (string) : elid from type, layer and occurence number
201  // use stringstream instead of sprintf to concatenate string and integer into string
202  for (unsigned ie = 0; ie < elements.size(); ie++) {
203  math::XYZPoint Pi(elements[ie].get()->innerPosition());
204  math::XYZPoint Po(elements[ie].get()->outerPosition());
205 
206  float innermost_radius = sqrt(Pi.x() * Pi.x() + Pi.y() * Pi.y() + Pi.z() * Pi.z());
207  float outermost_radius = sqrt(Po.x() * Po.x() + Po.y() * Po.y() + Po.z() * Po.z());
208  float innermost_rho = sqrt(Pi.x() * Pi.x() + Pi.y() * Pi.y());
209  float outermost_rho = sqrt(Po.x() * Po.x() + Po.y() * Po.y());
210 
211  double pt = elements[ie]->pt();
212 
213  out << "ie = " << elements[ie].key() << " pt = " << pt << " innermost hit radius = " << innermost_radius
214  << " rho = " << innermost_rho << " outermost hit radius = " << outermost_radius << " rho = " << outermost_rho
215  << endl;
216  }
217 
218  out << endl;
219 }
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
mps_fire.i
i
Definition: mps_fire.py:355
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
reco::PFDisplacedVertexCandidate::VertexLinkTest
VertexLinkTest
Definition: PFDisplacedVertexCandidate.h:43
cms::cuda::assert
assert(be >=bs)
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
reco::PFDisplacedVertexCandidate::DistMap
std::map< float, std::pair< int, int > > DistMap
Definition: PFDisplacedVertexCandidate.h:49
std::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: cuda_cxx17.h:13
test
Definition: SmallWORMDict.h:13
ctpps_dqm_sourceclient-live_cfg.test
test
Definition: ctpps_dqm_sourceclient-live_cfg.py:7
Track.h
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
PFDisplacedVertexCandidate.h
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
get
#define get
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
reco::PFDisplacedVertexCandidate::VertexLinkData
std::map< unsigned int, VertexLink > VertexLinkData
Definition: PFDisplacedVertexCandidate.h:45
bookConverter.elements
elements
Definition: bookConverter.py:147
std
Definition: JetResolutionObject.h:76
Point3D.h
edm::RefToBase< reco::Track >
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
math::GlobalPoint
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:18
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ztail.d
d
Definition: ztail.py:151
combine.missing
missing
Definition: combine.py:5
P
std::pair< OmniClusterRef, TrackingParticleRef > P
Definition: BDHadronTrackMonitoringAnalyzer.cc:202
reco::PFDisplacedVertexCandidate::DistVector
std::vector< float > DistVector
Definition: PFDisplacedVertexCandidate.h:50