Skip to content

Commit

Permalink
indents and copy/pasta
Browse files Browse the repository at this point in the history
  • Loading branch information
lgray committed Sep 29, 2016
1 parent 259b53b commit 8bc21be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 89 deletions.
Expand Up @@ -65,15 +65,11 @@ struct vertex_t{
std::vector<track_t> & tks,
std::vector<vertex_t> & y,
double threshold ) const;

double update( double beta,
std::vector<track_t> & tks,
std::vector<vertex_t> & y ) const;


double update(double beta,
std::vector<track_t> & tks,
std::vector<vertex_t> & y,
double &rho0 )const;
const double rho0 = 0.0 )const;

void dump(const double beta, const std::vector<vertex_t> & y, const std::vector<track_t> & tks, const int verbosity=0) const;
bool merge(std::vector<vertex_t> &,int ) const;
Expand Down
81 changes: 6 additions & 75 deletions RecoVertex/PrimaryVertexProducer/src/DAClusterizerInZT.cc
Expand Up @@ -74,87 +74,19 @@ double DAClusterizerInZT::e_ik(const track_t & t, const vertex_t &k ) const {



double DAClusterizerInZT::update( double beta,
vector<track_t> & tks,
vector<vertex_t> & y ) const {
//update weights and vertex positions
// mass constrained annealing without noise
// returns the squared sum of changes of vertex positions

unsigned int nt=tks.size();

//initialize sums
double sumpi=0;
for(vector<vertex_t>::iterator k=y.begin(); k!=y.end(); ++k){
k->sw=0.; k->swz=0.; k->swt = 0.; k->se=0.;
k->swE=0.; k->tC=0.;
}


// loop over tracks
for(unsigned int i=0; i<nt; i++){

// update pik and Zi
double Zi = 0.;
for(vector<vertex_t>::iterator k=y.begin(); k!=y.end(); ++k){
k->ei = std::exp(-beta*e_ik(tks[i],*k));// cache exponential for one track at a time
Zi += k->pk * k->ei;
}
tks[i].zi=Zi;

// normalization for pk
if (tks[i].zi>0){
sumpi += tks[i].pi;
// accumulate weighted z and weights for vertex update
for(vector<vertex_t>::iterator k=y.begin(); k!=y.end(); ++k){
k->se += tks[i].pi* k->ei / Zi;
const double w = k->pk * tks[i].pi* k->ei / ( Zi * ( tks[i].dz2 * tks[i].dt2 ) );
k->sw += w;
k->swz += w * tks[i].z;
k->swt += w * tks[i].t;
k->swE += w * e_ik(tks[i],*k);
}
}else{
sumpi += tks[i].pi;
}


} // end of track loop


// now update z and pk
double delta=0;
for(vector<vertex_t>::iterator k=y.begin(); k!=y.end(); k++){
if ( k->sw > 0){
const double znew = k->swz/k->sw;
const double tnew = k->swt/k->sw;
delta += sqr(k->z-znew) + sqr(k->t-tnew);
k->z = znew;
k->t = tnew;
k->tC = 2.*k->swE/k->sw;
}else{
LogDebug("sumw") << "invalid sum of weights in fit: " << k->sw << endl;
if(verbose_){cout << " a cluster melted away ? pk=" << k->pk << " sumw=" << k->sw << endl;}
k->tC=-1;
}

k->pk = k->pk * k->se / sumpi;
}

// return how much the prototypes moved
return delta;
}

double DAClusterizerInZT::update( double beta,
vector<track_t> & tks,
vector<vertex_t> & y,
double & rho0 ) const {
const double rho0 ) const {
// MVF style, no more vertex weights, update tracks weights and vertex positions, with noise
// returns the squared sum of changes of vertex positions

unsigned int nt=tks.size();

//initialize sums
double sumpi = 0.;
for(vector<vertex_t>::iterator k=y.begin(); k!=y.end(); k++){
k->sw = 0.; k->swz = 0.; k->swt = 0.; k->se = 0.;
k->swE = 0.; k->tC=0.;
Expand All @@ -172,10 +104,11 @@ double DAClusterizerInZT::update( double beta,
Zi += k->pk * k->ei;
}
tks[i].zi=Zi;
sumpi += tks[i].pi;

// normalization
if (tks[i].zi>0){
// accumulate weighted z and weights for vertex update
// accumulate weighted z and weights for vertex update
for(vector<vertex_t>::iterator k=y.begin(); k!=y.end(); k++){
k->se += tks[i].pi* k->ei / Zi;
double w = k->pk * tks[i].pi * k->ei /( Zi * ( tks[i].dz2 * tks[i].dt2 ) );
Expand All @@ -185,8 +118,6 @@ double DAClusterizerInZT::update( double beta,
k->swE += w * e_ik(tks[i],*k);
}
}


} // end of track loop


Expand All @@ -203,9 +134,9 @@ double DAClusterizerInZT::update( double beta,
}else{
edm::LogInfo("sumw") << "invalid sum of weights in fit: " << k->sw << endl;
if(verbose_){cout << " a cluster melted away ? pk=" << k->pk << " sumw=" << k->sw << endl;}
k->tC = 0;
k->tC = (rho0 == 0. ? -1 : 0);
}

if(rho0 == 0.) k->pk = k->pk * k->se / sumpi;
}

// return how much the prototypes moved
Expand Down
16 changes: 8 additions & 8 deletions RecoVertex/VertexPrimitives/interface/VertexState.h
Expand Up @@ -26,43 +26,43 @@ class VertexState final : private BasicVertexState::Proxy {
// Base ( new BSVS ( std::forward<Args>(args)...)){}

explicit VertexState(BasicVertexState* p) :
Base(p) {}
Base(p) {}

explicit VertexState(const reco::BeamSpot& beamSpot) :
Base ( new BSVS ( GlobalPoint(Basic3DVector<float> (beamSpot.position())),
Base ( new BSVS ( GlobalPoint(Basic3DVector<float> (beamSpot.position())),
GlobalError(beamSpot.rotatedCovariance3D()), 1.0)) {}


VertexState(const GlobalPoint & pos,
const GlobalError & posErr,
const double & weightInMix= 1.0) :
Base ( new BSVS (pos, posErr, weightInMix)) {}
Base ( new BSVS (pos, posErr, weightInMix)) {}

VertexState(const GlobalPoint & pos,
const GlobalWeight & posWeight,
const double & weightInMix= 1.0) :
Base ( new BSVS (pos, posWeight, weightInMix)) {}
Base ( new BSVS (pos, posWeight, weightInMix)) {}

VertexState(const AlgebraicVector3 & weightTimesPosition,
const GlobalWeight & posWeight,
const double & weightInMix= 1.0) :
Base ( new BSVS (weightTimesPosition, posWeight, weightInMix)) {}
Base ( new BSVS (weightTimesPosition, posWeight, weightInMix)) {}

// with time
VertexState(const GlobalPoint & pos, const double time,
const GlobalError & posTimeErr,
const double & weightInMix = 1.0) :
Base ( new BSVS (pos, time, posTimeErr, weightInMix)) {}
Base ( new BSVS (pos, time, posTimeErr, weightInMix)) {}

VertexState(const GlobalPoint & pos, const double time,
const GlobalWeight & posTimeWeight,
const double & weightInMix = 1.0) :
Base ( new BSVS (pos, time, posTimeWeight, weightInMix)) {}
Base ( new BSVS (pos, time, posTimeWeight, weightInMix)) {}

VertexState(const AlgebraicVector4 & weightTimesPosition,
const GlobalWeight & posTimeWeight,
const double & weightInMix = 1.0) :
Base ( new BSVS (weightTimesPosition, posTimeWeight, weightInMix)) {}
Base ( new BSVS (weightTimesPosition, posTimeWeight, weightInMix)) {}


//3D covariance matrices (backwards compatible)
Expand Down

0 comments on commit 8bc21be

Please sign in to comment.