Go to the documentation of this file.00001 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertexCandidate.h"
00002
00003 #include "DataFormats/TrackReco/interface/Track.h"
00004 #include "DataFormats/Math/interface/Point3D.h"
00005
00006 using namespace std;
00007 using namespace reco;
00008
00009
00010 PFDisplacedVertexCandidate::PFDisplacedVertexCandidate(){}
00011
00012 void PFDisplacedVertexCandidate::addElement(const TrackBaseRef element) {
00013 elements_.push_back( element );
00014 }
00015
00016
00017 void PFDisplacedVertexCandidate::setLink(const unsigned i1,
00018 const unsigned i2,
00019 const float dist,
00020 const GlobalPoint& dcaPoint,
00021 const VertexLinkTest test){
00022
00023
00024 assert( test<LINKTEST_ALL );
00025
00026 unsigned index = 0;
00027 bool ok = matrix2vector(i1,i2, index);
00028
00029 if(ok) {
00030
00031 if ( dist > -0.5 ) {
00032 VertexLink & l = vertexLinkData_[index];
00033 l.distance_ = dist;
00034 l.dcaPoint_ = dcaPoint;
00035 l.test_ |= (1 << test);
00036 } else
00037 {
00038 VertexLinkData::iterator it = vertexLinkData_.find(index);
00039 if(it!=vertexLinkData_.end()) vertexLinkData_.erase(it);
00040 }
00041
00042 } else {
00043 assert(0);
00044 }
00045
00046 }
00047
00048
00049 void PFDisplacedVertexCandidate::associatedElements( const unsigned i,
00050 const VertexLinkData& vertexLinkData,
00051 multimap<float, unsigned>& sortedAssociates,
00052 const VertexLinkTest test ) const {
00053
00054 sortedAssociates.clear();
00055
00056
00057 if( i > elements_.size() ) return;
00058
00059 for(unsigned ie=0; ie<elements_.size(); ie++) {
00060
00061
00062 if( ie == i ) {
00063 continue;
00064 }
00065
00066
00067
00068 unsigned index = 0;
00069 if( !matrix2vector(i, ie, index) ) continue;
00070
00071 float c2=-1;
00072 VertexLinkData::const_iterator it = vertexLinkData.find(index);
00073 if ( it!=vertexLinkData.end() &&
00074 ( ( (1 << test ) & it->second.test_) !=0 || (test == LINKTEST_ALL) ) )
00075 c2= it->second.distance_;
00076
00077
00078 if( c2 < 0 ) {
00079 continue;
00080 }
00081
00082 sortedAssociates.insert( pair<float,unsigned>(c2, ie) );
00083 }
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 PFDisplacedVertexCandidate::DistMap PFDisplacedVertexCandidate::r2Map() const {
00096
00097 DistMap r2Map;
00098
00099 for (unsigned ie1 = 0; ie1<elements_.size(); ie1++)
00100 for (unsigned ie2 = ie1+1; ie2<elements_.size(); ie2++){
00101
00102 GlobalPoint P = dcaPoint(ie1, ie2);
00103 if (P.x() > 1e9) continue;
00104
00105 float r2 = P.x()*P.x()+P.y()*P.y()+P.z()*P.z();
00106
00107 r2Map.insert(pair<float, pair<int,int> >(r2, pair <int, int>(ie1, ie2)));
00108 }
00109
00110 return r2Map;
00111
00112 }
00113
00114
00115
00116 PFDisplacedVertexCandidate::DistVector PFDisplacedVertexCandidate::r2Vector() const {
00117
00118 DistVector r2Vector;
00119
00120 for (unsigned ie1 = 0; ie1<elements_.size(); ie1++)
00121 for (unsigned ie2 = ie1+1; ie2<elements_.size(); ie2++){
00122
00123 GlobalPoint P = dcaPoint(ie1, ie2);
00124 if (P.x() > 1e9) continue;
00125
00126 float r2 = P.x()*P.x()+P.y()*P.y()+P.z()*P.z();
00127
00128 r2Vector.push_back(r2);
00129 }
00130
00131 return r2Vector;
00132
00133 }
00134
00135
00136 PFDisplacedVertexCandidate::DistVector PFDisplacedVertexCandidate::distVector() const {
00137
00138 DistVector distVector;
00139
00140
00141 for (unsigned ie1 = 0; ie1<elements_.size(); ie1++)
00142 for (unsigned ie2 = ie1+1; ie2<elements_.size(); ie2++){
00143
00144 float d = dist(ie1, ie2);
00145 if (d < -0.5) continue;
00146
00147 distVector.push_back(d);
00148
00149 }
00150
00151 return distVector;
00152
00153 }
00154
00155 const GlobalPoint PFDisplacedVertexCandidate::dcaPoint( unsigned ie1, unsigned ie2) const {
00156
00157 GlobalPoint dcaPoint(1e10,1e10,1e10);
00158
00159 unsigned index = 0;
00160 if( !matrix2vector(ie1, ie2, index) ) return dcaPoint;
00161 VertexLinkData::const_iterator it = vertexLinkData_.find(index);
00162 if( it!=vertexLinkData_.end() ) dcaPoint = it->second.dcaPoint_;
00163
00164 return dcaPoint;
00165
00166 }
00167
00168
00169
00170
00171 bool PFDisplacedVertexCandidate::testLink(unsigned ie1, unsigned ie2) const {
00172 float d = dist( ie1, ie2);
00173 if (d < -0.5) return false;
00174 return true;
00175 }
00176
00177
00178 const float PFDisplacedVertexCandidate::dist( unsigned ie1, unsigned ie2) const {
00179
00180 float dist = -1;
00181
00182 unsigned index = 0;
00183 if( !matrix2vector(ie1, ie2, index) ) return dist;
00184 VertexLinkData::const_iterator it = vertexLinkData_.find(index);
00185 if( it!=vertexLinkData_.end() ) dist= it->second.distance_;
00186
00187 return dist;
00188
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 unsigned PFDisplacedVertexCandidate::vertexLinkDataSize() const {
00203 unsigned n = elements_.size();
00204
00205
00206
00207
00208 return n*(n-1)/2;
00209 }
00210
00211
00212 bool PFDisplacedVertexCandidate::matrix2vector( unsigned iindex,
00213 unsigned jindex,
00214 unsigned& index ) const {
00215
00216 unsigned size = elements_.size();
00217 if( iindex == jindex ||
00218 iindex >= size ||
00219 jindex >= size ) {
00220 return false;
00221 }
00222
00223 if( iindex > jindex )
00224 swap( iindex, jindex);
00225
00226
00227 index = jindex-iindex-1;
00228
00229 if(iindex>0) {
00230 index += iindex*size;
00231 unsigned missing = iindex*(iindex+1)/2;
00232 index -= missing;
00233 }
00234
00235 return true;
00236 }
00237
00238 void PFDisplacedVertexCandidate::Dump( ostream& out ) const {
00239 if(! out ) return;
00240
00241 const vector < TrackBaseRef >& elements = elements_;
00242 out<<"\t--- DisplacedVertexCandidate --- "<<endl;
00243 out<<"\tnumber of elements: "<<elements.size()<<endl;
00244
00245
00246
00247 for(unsigned ie=0; ie<elements.size(); ie++) {
00248
00249 math::XYZPoint Pi(elements[ie].get()->innerPosition());
00250 math::XYZPoint Po(elements[ie].get()->outerPosition());
00251
00252 float innermost_radius = sqrt(Pi.x()*Pi.x() + Pi.y()*Pi.y() + Pi.z()*Pi.z());
00253 float outermost_radius = sqrt(Po.x()*Po.x() + Po.y()*Po.y() + Po.z()*Po.z());
00254 float innermost_rho = sqrt(Pi.x()*Pi.x() + Pi.y()*Pi.y());
00255 float outermost_rho = sqrt(Po.x()*Po.x() + Po.y()*Po.y());
00256
00257 double pt = elements[ie]->pt();
00258
00259
00260 out<<"ie = " << elements[ie].key() << " pt = " << pt
00261 <<" innermost hit radius = " << innermost_radius << " rho = " << innermost_rho
00262 <<" outermost hit radius = " << outermost_radius << " rho = " << outermost_rho
00263 <<endl;
00264 }
00265
00266 out<<endl;
00267
00268
00269 }
00270