CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Attributes
DAClusterizerInZ_vect Class Referencefinal

#include <DAClusterizerInZ_vect.h>

Inheritance diagram for DAClusterizerInZ_vect:
TrackClusterizerInZ

Classes

struct  track_t
 
struct  vertex_t
 

Public Member Functions

double beta0 (const double betamax, track_t const &tks, vertex_t const &y) const
 
std::vector< std::vector
< reco::TransientTrack > > 
clusterize (const std::vector< reco::TransientTrack > &tracks) const
 
 DAClusterizerInZ_vect (const edm::ParameterSet &conf)
 
void dump (const double beta, const vertex_t &y, const track_t &tks, const int verbosity=0) const
 
track_t fill (const std::vector< reco::TransientTrack > &tracks) const
 
bool merge (vertex_t &) const
 
bool merge (vertex_t &y, double &beta) const
 
bool purge (vertex_t &, track_t &, double &, const double) const
 
bool split (const double beta, track_t &t, vertex_t &y) const
 
void splitAll (vertex_t &y) const
 
double update (double beta, track_t &gtracks, vertex_t &gvertices, bool useRho0, double &rho0) const
 
std::vector< TransientVertexvertices (const std::vector< reco::TransientTrack > &tracks, const int verbosity=0) const
 
- Public Member Functions inherited from TrackClusterizerInZ
 TrackClusterizerInZ ()
 
 TrackClusterizerInZ (const edm::ParameterSet &conf)
 
virtual ~TrackClusterizerInZ ()
 

Private Attributes

float betamax_
 
float betastop_
 
double coolingFactor_
 
double d0CutOff_
 
double dzCutOff_
 
int maxIterations_
 
bool useTc_
 
bool verbose_
 
float vertexSize_
 

Detailed Description

Description: separates event tracks into clusters along the beam line

Version which auto-vectorizes with gcc 4.6 or newer

Definition at line 21 of file DAClusterizerInZ_vect.h.

Constructor & Destructor Documentation

DAClusterizerInZ_vect::DAClusterizerInZ_vect ( const edm::ParameterSet conf)

Definition at line 15 of file DAClusterizerInZ_vect.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), LogDebug, and builder_last_value_cfg::Tmin.

15  {
16 
17  // some defaults to avoid uninitialized variables
18  verbose_ = conf.getUntrackedParameter<bool> ("verbose", false);
19 
20  betamax_ = 0.1;
21  betastop_ = 1.0;
22  /*
23  coolingFactor_ = 0.6;
24  maxIterations_ = 100;
25  vertexSize_ = 0.01; // 0.1 mm
26  dzCutOff_ = 4.0;
27  */
28  // configure
29 
30  double Tmin = conf.getParameter<double> ("Tmin");
31  vertexSize_ = conf.getParameter<double> ("vertexSize");
32  coolingFactor_ = conf.getParameter<double> ("coolingFactor");
33  useTc_=true;
34  if(coolingFactor_<0){
35  coolingFactor_=-coolingFactor_;
36  useTc_=false;
37  }
38  d0CutOff_ = conf.getParameter<double> ("d0CutOff");
39  dzCutOff_ = conf.getParameter<double> ("dzCutOff");
40  maxIterations_ = 100;
41  if (Tmin == 0) {
42  LogDebug("DAClusterizerinZ_vectorized") << "DAClusterizerInZ: invalid Tmin" << Tmin
43  << " reset do default " << 1. / betamax_ << endl;
44  } else {
45  betamax_ = 1. / Tmin;
46  }
47 
48 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const

Member Function Documentation

double DAClusterizerInZ_vect::beta0 ( const double  betamax,
track_t const &  tks,
vertex_t const &  y 
) const

Definition at line 351 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::track_t::_dz2, DAClusterizerInZ_vect::track_t::_pi, DAClusterizerInZ_vect::track_t::_z, DAClusterizerInZ_vect::vertex_t::_z, a, b, DAClusterizerInZ_vect::track_t::GetSize(), DAClusterizerInZ_vect::vertex_t::GetSize(), i, gen::k, fff_deleter::log, nt, funct::pow(), and w().

351  {
352 
353  double T0 = 0; // max Tc for beta=0
354  // estimate critical temperature from beta=0 (T=inf)
355  const unsigned int nt = tks.GetSize();
356  const unsigned int nv = y.GetSize();
357 
358  for (unsigned int k = 0; k < nv; k++) {
359 
360  // vertex fit at T=inf
361  double sumwz = 0;
362  double sumw = 0;
363  for (unsigned int i = 0; i < nt; i++) {
364  double w = tks._pi[i] / tks._dz2[i];
365  sumwz += w * tks._z[i];
366  sumw += w;
367  }
368  y._z[k] = sumwz / sumw;
369 
370  // estimate Tcrit, eventually do this in the same loop
371  double a = 0, b = 0;
372  for (unsigned int i = 0; i < nt; i++) {
373  double dx = tks._z[i] - y._z[k];
374  double w = tks._pi[i] / tks._dz2[i];
375  a += w * std::pow(dx, 2) / tks._dz2[i];
376  b += w;
377  }
378  double Tc = 2. * a / b; // the critical temperature of this vertex
379  if (Tc > T0) T0 = Tc;
380  }// vertex loop (normally there should be only one vertex at beta=0)
381 
382  if (T0 > 1. / betamax) {
383  return betamax / std::pow(coolingFactor_, int(std::log(T0 * betamax) / std::log(coolingFactor_)) - 1);
384  } else {
385  // ensure at least one annealing step
386  return betamax / coolingFactor_;
387  }
388 }
int i
Definition: DBlmapReader.cc:9
int nt
Definition: AMPTWrapper.h:32
int k[5][pyjets_maxn]
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
T w() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
vector< vector< reco::TransientTrack > > DAClusterizerInZ_vect::clusterize ( const std::vector< reco::TransientTrack > &  tracks) const
virtual

Implements TrackClusterizerInZ.

Definition at line 652 of file DAClusterizerInZ_vect.cc.

References funct::abs(), gather_cfg::cout, i, gen::k, LogDebug, and position.

653  {
654 
655  if (verbose_) {
656  std::cout << "###################################################" << endl;
657  std::cout << "# vectorized DAClusterizerInZ_vect::clusterize nt=" << tracks.size() << endl;
658  std::cout << "###################################################" << endl;
659  }
660 
661  vector<vector<reco::TransientTrack> > clusters;
662  vector<TransientVertex> && pv = vertices(tracks);
663 
664  if (verbose_) {
665  LogDebug("DAClusterizerinZ_vectorized") << "# DAClusterizerInZ::clusterize pv.size=" << pv.size()
666  << endl;
667  }
668  if (pv.size() == 0) {
669  return clusters;
670  }
671 
672  // fill into clusters and merge
673  vector<reco::TransientTrack> aCluster = pv.begin()->originalTracks();
674 
675  for (auto k = pv.begin() + 1; k != pv.end(); k++) {
676  if ( std::abs(k->position().z() - (k - 1)->position().z()) > (2 * vertexSize_)) {
677  // close a cluster
678  clusters.push_back(aCluster);
679  aCluster.clear();
680  }
681  for (unsigned int i = 0; i < k->originalTracks().size(); i++) {
682  aCluster.push_back(k->originalTracks()[i]);
683  }
684 
685  }
686  clusters.emplace_back(std::move(aCluster));
687 
688  return clusters;
689 
690 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int k[5][pyjets_maxn]
tuple tracks
Definition: testEve_cfg.py:39
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks, const int verbosity=0) const
tuple cout
Definition: gather_cfg.py:121
void DAClusterizerInZ_vect::dump ( const double  beta,
const vertex_t y,
const track_t tks,
const int  verbosity = 0 
) const

Definition at line 696 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::track_t::_dz2, DAClusterizerInZ_vect::track_t::_pi, DAClusterizerInZ_vect::vertex_t::_pk, DAClusterizerInZ_vect::track_t::_z, DAClusterizerInZ_vect::vertex_t::_z, DAClusterizerInZ_vect::track_t::_Z_sum, beta, Measurement1D::error(), create_public_lumi_plots::exp, F(), DAClusterizerInZ_vect::track_t::GetSize(), DAClusterizerInZ_vect::vertex_t::GetSize(), reco::TrackBase::highPurity, i, listHistos::IP, fff_deleter::log, LogDebug, reco::HitPattern::MISSING_OUTER_HITS, nt, AlCaHLTBitMon_ParallelJobs::p, mathSSE::sqrt(), DAClusterizerInZ_vect::track_t::tt, and Measurement1D::value().

697  {
698 
699  const unsigned int nv = y.GetSize();
700  const unsigned int nt = tks.GetSize();
701 
702  LogDebug("DAClusterizerinZ_vectorized") << "-----DAClusterizerInZ::dump ----" << endl;
703  LogDebug("DAClusterizerinZ_vectorized") << "beta=" << beta << " betamax= " << betamax_ << endl;
704  LogDebug("DAClusterizerinZ_vectorized") << " z= ";
705  LogDebug("DAClusterizerinZ_vectorized") << setprecision(4);
706  for (unsigned int ivertex = 0; ivertex < nv; ++ ivertex) {
707  LogDebug("DAClusterizerinZ_vectorized") << setw(8) << fixed << y._z[ivertex];
708  }
709  LogDebug("DAClusterizerinZ_vectorized") << endl << "T=" << setw(15) << 1. / beta
710  << " Tc= ";
711  LogDebug("DAClusterizerinZ_vectorized") << endl
712  << " pk=";
713  double sumpk = 0;
714  for (unsigned int ivertex = 0; ivertex < nv; ++ ivertex) {
715  LogDebug("DAClusterizerinZ_vectorized") << setw(8) << setprecision(3) << fixed << y._pk[ivertex];
716  sumpk += y._pk[ivertex];
717  }
718  LogDebug("DAClusterizerinZ_vectorized") << endl;
719 
720  if (verbosity > 0) {
721  double E = 0, F = 0;
722  LogDebug("DAClusterizerinZ_vectorized") << endl;
723  LogDebug("DAClusterizerinZ_vectorized")
724  << "---- z +/- dz ip +/-dip pt phi eta weights ----"
725  << endl;
726  LogDebug("DAClusterizerinZ_vectorized") << setprecision(4);
727  for (unsigned int i = 0; i < nt; i++) {
728  if (tks._Z_sum[i] > 0) {
729  F -= std::log(tks._Z_sum[i]) / beta;
730  }
731  double tz = tks._z[i];
732  LogDebug("DAClusterizerinZ_vectorized") << setw(3) << i << ")" << setw(8) << fixed << setprecision(4)
733  << tz << " +/-" << setw(6) << sqrt(tks._dz2[i]);
734 
735  if (tks.tt[i]->track().quality(reco::TrackBase::highPurity)) {
736  LogDebug("DAClusterizerinZ_vectorized") << " *";
737  } else {
738  LogDebug("DAClusterizerinZ_vectorized") << " ";
739  }
740  if (tks.tt[i]->track().hitPattern().hasValidHitInFirstPixelBarrel()) {
741  LogDebug("DAClusterizerinZ_vectorized") << "+";
742  } else {
743  LogDebug("DAClusterizerinZ_vectorized") << "-";
744  }
745  LogDebug("DAClusterizerinZ_vectorized") << setw(1)
746  << tks.tt[i]->track().hitPattern().pixelBarrelLayersWithMeasurement(); // see DataFormats/TrackReco/interface/HitPattern.h
747  LogDebug("DAClusterizerinZ_vectorized") << setw(1)
748  << tks.tt[i]->track().hitPattern().pixelEndcapLayersWithMeasurement();
749  LogDebug("DAClusterizerinZ_vectorized") << setw(1) << hex
750  << tks.tt[i]->track().hitPattern().trackerLayersWithMeasurement()
751  - tks.tt[i]->track().hitPattern().pixelLayersWithMeasurement()
752  << dec;
753  LogDebug("DAClusterizerinZ_vectorized") << "=" << setw(1) << hex
754  << tks.tt[i]->track().hitPattern().numberOfHits(reco::HitPattern::MISSING_OUTER_HITS)
755  << dec;
756 
757  Measurement1D IP =
758  tks.tt[i]->stateAtBeamLine().transverseImpactParameter();
759  LogDebug("DAClusterizerinZ_vectorized") << setw(8) << IP.value() << "+/-" << setw(6) << IP.error();
760  LogDebug("DAClusterizerinZ_vectorized") << " " << setw(6) << setprecision(2)
761  << tks.tt[i]->track().pt() * tks.tt[i]->track().charge();
762  LogDebug("DAClusterizerinZ_vectorized") << " " << setw(5) << setprecision(2)
763  << tks.tt[i]->track().phi() << " " << setw(5)
764  << setprecision(2) << tks.tt[i]->track().eta();
765 
766  double sump = 0.;
767  for (unsigned int ivertex = 0; ivertex < nv; ++ ivertex) {
768  if ((tks._pi[i] > 0) && (tks._Z_sum[i] > 0)) {
769  //double p=pik(beta,tks[i],*k);
770  double p = y._pk[ivertex] * exp(-beta * Eik(tks._z[i], y._z[ivertex], tks._dz2[i])) / tks._Z_sum[i];
771  if (p > 0.0001) {
772  LogDebug("DAClusterizerinZ_vectorized") << setw(8) << setprecision(3) << p;
773  } else {
774  LogDebug("DAClusterizerinZ_vectorized") << " . ";
775  }
776  E += p * Eik(tks._z[i], y._z[ivertex], tks._dz2[i]);
777  sump += p;
778  } else {
779  LogDebug("DAClusterizerinZ_vectorized") << " ";
780  }
781  }
782  LogDebug("DAClusterizerinZ_vectorized") << endl;
783  }
784  LogDebug("DAClusterizerinZ_vectorized") << endl << "T=" << 1 / beta << " E=" << E << " n=" << y.GetSize()
785  << " F= " << F << endl << "----------" << endl;
786  }
787 }
#define LogDebug(id)
const double beta
int i
Definition: DBlmapReader.cc:9
double error() const
Definition: Measurement1D.h:30
T sqrt(T t)
Definition: SSEVec.h:48
tuple IP
Definition: listHistos.py:76
int nt
Definition: AMPTWrapper.h:32
double value() const
Definition: Measurement1D.h:28
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
DAClusterizerInZ_vect::track_t DAClusterizerInZ_vect::fill ( const std::vector< reco::TransientTrack > &  tracks) const

Definition at line 63 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::track_t::AddItem(), SiPixelRawToDigiRegional_cfi::beamSpot, funct::cos(), Measurement1D::error(), DAClusterizerInZ_vect::track_t::ExtractRaw(), DAClusterizerInZ_vect::track_t::GetSize(), listHistos::IP, LogDebug, phi, position, funct::pow(), funct::sin(), funct::tan(), and Measurement1D::value().

63  {
64 
65  // prepare track data for clustering
66  track_t tks;
67  for (auto it = tracks.begin(); it!= tracks.end(); it++){
68  double t_pi;
69  double t_z = ((*it).stateAtBeamLine().trackStateAtPCA()).position().z();
70  double phi=((*it).stateAtBeamLine().trackStateAtPCA()).momentum().phi();
71  double tantheta = std::tan( ((*it).stateAtBeamLine().trackStateAtPCA()).momentum().theta());
72  // get the beam-spot
73  reco::BeamSpot beamspot = (it->stateAtBeamLine()).beamSpot();
74  double t_dz2 =
75  std::pow((*it).track().dzError(), 2) // track errror
76  + (std::pow(beamspot.BeamWidthX()*cos(phi),2)+std::pow(beamspot.BeamWidthY()*sin(phi),2))/std::pow(tantheta,2) // beam-width
77  + std::pow(vertexSize_, 2); // intrinsic vertex size, safer for outliers and short lived decays
78  if (d0CutOff_ > 0) {
80  (*it).stateAtBeamLine().transverseImpactParameter();// error constains beamspot
81  t_pi = 1. / (1. + local_exp(std::pow(IP.value() / IP.error(), 2) - std::pow(d0CutOff_, 2))); // reduce weight for high ip tracks
82  } else {
83  t_pi = 1.;
84  }
85  tks.AddItem(t_z, t_dz2, &(*it), t_pi);
86  }
87  tks.ExtractRaw();
88 
89  if (verbose_) {
90  LogDebug("DAClusterizerinZ_vectorized") << "Track count " << tks.GetSize() << std::endl;
91  }
92 
93  return tks;
94 }
#define LogDebug(id)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double error() const
Definition: Measurement1D.h:30
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
tuple IP
Definition: listHistos.py:76
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
tuple tracks
Definition: testEve_cfg.py:39
double value() const
Definition: Measurement1D.h:28
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Definition: DDAxes.h:10
bool DAClusterizerInZ_vect::merge ( vertex_t y) const

Definition at line 274 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::vertex_t::_pk, DAClusterizerInZ_vect::vertex_t::_z, funct::abs(), DAClusterizerInZ_vect::vertex_t::GetSize(), gen::k, LogDebug, and DAClusterizerInZ_vect::vertex_t::RemoveItem().

274  {
275  // merge clusters that collapsed or never separated, return true if vertices were merged, false otherwise
276 
277  const unsigned int nv = y.GetSize();
278 
279  if (nv < 2) return false;
280 
281  for (unsigned int k = 0; (k + 1) < nv; k++) {
282  //if ((k+1)->z - k->z<1.e-2){ // note, no fabs here, maintains z-ordering (with split()+merge() at every temperature)
283  if (std::abs(y._z[k + 1] - y._z[k]) < 1.e-2) { // with fabs if only called after freeze-out (splitAll() at highter T)
284  y._pk[k] += y._pk[k + 1];
285  y._z[k] = 0.5 * (y._z[k] + y._z[k + 1]);
286 
287  y.RemoveItem(k + 1);
288 
289  if ( verbose_)
290  {
291  LogDebug("DAClusterizerinZ_vectorized") << "Merging vertices k = " << k << std::endl;
292  }
293 
294  return true;
295  }
296  }
297 
298  return false;
299 }
#define LogDebug(id)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int k[5][pyjets_maxn]
bool DAClusterizerInZ_vect::merge ( vertex_t y,
double &  beta 
) const

Definition at line 236 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::vertex_t::_pk, DAClusterizerInZ_vect::vertex_t::_sw, DAClusterizerInZ_vect::vertex_t::_swE, DAClusterizerInZ_vect::vertex_t::_z, DAClusterizerInZ_vect::vertex_t::GetSize(), gen::k, funct::pow(), DAClusterizerInZ_vect::vertex_t::RemoveItem(), and rho.

236  {
237  // merge clusters that collapsed or never separated,
238  // only merge if the estimated critical temperature of the merged vertex is below the current temperature
239  // return true if vertices were merged, false otherwise
240  const unsigned int nv = y.GetSize();
241 
242  if (nv < 2)
243  return false;
244 
245 
246  for (unsigned int k = 0; (k + 1) < nv; k++) {
247  if (fabs(y._z[k + 1] - y._z[k]) < 2.e-2) {
248  double rho=y._pk[k] + y._pk[k+1];
249  double swE=y._swE[k]+y._swE[k+1] - y._pk[k]*y._pk[k+1] /rho *std::pow(y._z[k+1]-y._z[k],2);
250  double Tc=2*swE/(y._sw[k]+y._sw[k+1]);
251 
252  if(Tc*beta<1){
253  if(rho>0){
254  y._z[k] = (y._pk[k]*y._z[k] + y._pk[k+1]*y._z[k + 1])/rho;
255  }else{
256  y._z[k] = 0.5 * (y._z[k] + y._z[k + 1]);
257  }
258  y._pk[k] = rho;
259  y._sw[k]+=y._sw[k+1];
260  y._swE[k]=swE;
261  y.RemoveItem(k+1);
262  return true;
263  }
264  }
265  }
266 
267  return false;
268 }
const double beta
Definition: DDAxes.h:10
int k[5][pyjets_maxn]
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
bool DAClusterizerInZ_vect::purge ( vertex_t y,
track_t tks,
double &  rho0,
const double  beta 
) const

Definition at line 302 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::track_t::_dz2, DAClusterizerInZ_vect::track_t::_pi, DAClusterizerInZ_vect::vertex_t::_pk, DAClusterizerInZ_vect::track_t::_z, DAClusterizerInZ_vect::vertex_t::_z, DAClusterizerInZ_vect::track_t::_Z_sum, DAClusterizerInZ_vect::track_t::GetSize(), DAClusterizerInZ_vect::vertex_t::GetSize(), i, gen::k, reco::ParticleMasses::k0, LogDebug, nt, AlCaHLTBitMon_ParallelJobs::p, and DAClusterizerInZ_vect::vertex_t::RemoveItem().

302  {
303  // eliminate clusters with only one significant/unique track
304  const unsigned int nv = y.GetSize();
305  const unsigned int nt = tks.GetSize();
306 
307  if (nv < 2)
308  return false;
309 
310  double sumpmin = nt;
311  unsigned int k0 = nv;
312 
313  for (unsigned int k = 0; k < nv; k++) {
314 
315  int nUnique = 0;
316  double sump = 0;
317  double pmax = y._pk[k] / (y._pk[k] + rho0 * local_exp(-beta * dzCutOff_* dzCutOff_));
318 
319  for (unsigned int i = 0; i < nt; i++) {
320 
321  if (tks._Z_sum[i] > 0) {
322  //double p=pik(beta,tks[i],*k);
323  double p = y._pk[k] * local_exp(-beta * Eik(tks._z[i], y._z[k], tks._dz2[i])) / tks._Z_sum[i];
324  sump += p;
325  if ((p > 0.9 * pmax) && (tks._pi[i] > 0)) {
326  nUnique++;
327  }
328  }
329  }
330 
331  if ((nUnique < 2) && (sump < sumpmin)) {
332  sumpmin = sump;
333  k0 = k;
334  }
335  }
336 
337  if (k0 != nv) {
338  if (verbose_) {
339  LogDebug("DAClusterizerinZ_vectorized") << "eliminating prototype at " << y._z[k0] << " with sump="
340  << sumpmin << endl;
341  }
342  //rho0+=k0->pk;
343  y.RemoveItem(k0);
344  return true;
345  } else {
346  return false;
347  }
348 }
#define LogDebug(id)
const double beta
int i
Definition: DBlmapReader.cc:9
int nt
Definition: AMPTWrapper.h:32
int k[5][pyjets_maxn]
bool DAClusterizerInZ_vect::split ( const double  beta,
track_t t,
vertex_t y 
) const

Definition at line 392 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::track_t::_dz2, DAClusterizerInZ_vect::vertex_t::_pk, DAClusterizerInZ_vect::vertex_t::_sw, DAClusterizerInZ_vect::vertex_t::_swE, DAClusterizerInZ_vect::track_t::_z, DAClusterizerInZ_vect::vertex_t::_z, DAClusterizerInZ_vect::track_t::_Z_sum, hlt_jetmet_dqm_QT_fromfile_cfg::critical, alignCSCRings::e, epsilon, DAClusterizerInZ_vect::track_t::GetSize(), DAClusterizerInZ_vect::vertex_t::GetSize(), i, DAClusterizerInZ_vect::vertex_t::InsertItem(), gen::k, nt, AlCaHLTBitMon_ParallelJobs::p, p1, p2, edm::second(), split, w(), and w2.

392  {
393  // split only critical vertices (Tc >~ T=1/beta <==> beta*Tc>~1)
394  // an update must have been made just before doing this (same beta, no merging)
395  // returns true if at least one cluster was split
396 
397  double epsilon=1e-3; // split all single vertices by 10 um
398  unsigned int nv = y.GetSize();
399 
400  // avoid left-right biases by splitting highest Tc first
401 
402  std::vector<std::pair<double, unsigned int> > critical;
403  for(unsigned int k=0; k<nv; k++){
404  double Tc= 2*y._swE[k]/y._sw[k];
405  if (beta*Tc > 1.){
406  critical.push_back( make_pair(Tc, k));
407  }
408  }
409  if (critical.size()==0) return false;
410  std::stable_sort(critical.begin(), critical.end(), std::greater<std::pair<double, unsigned int> >() );
411 
412 
413  bool split=false;
414  const unsigned int nt = tks.GetSize();
415 
416  for(unsigned int ic=0; ic<critical.size(); ic++){
417  unsigned int k=critical[ic].second;
418  // estimate subcluster positions and weight
419  double p1=0, z1=0, w1=0;
420  double p2=0, z2=0, w2=0;
421  for(unsigned int i=0; i<nt; i++){
422  if (tks._Z_sum[i] > 0) {
423  double p = y._pk[k] * local_exp(-beta * Eik(tks._z[i], y._z[k], tks._dz2[i])) / tks._Z_sum[i];
424  double w=p/tks._dz2[i];
425  if(tks._z[i]<y._z[k]){
426  p1+=p; z1+=w*tks._z[i]; w1+=w;
427  }else{
428  p2+=p; z2+=w*tks._z[i]; w2+=w;
429  }
430  }
431  }
432  if(w1>0){ z1=z1/w1;} else{z1=y._z[k]-epsilon;}
433  if(w2>0){ z2=z2/w2;} else{z2=y._z[k]+epsilon;}
434 
435  // reduce split size if there is not enough room
436  if( ( k > 0 ) && ( y._z[k-1]>=z1 ) ){ z1=0.5*(y._z[k]+y._z[k-1]); }
437  if( ( k+1 < nv) && ( y._z[k+1]<=z2 ) ){ z2=0.5*(y._z[k]+y._z[k+1]); }
438 
439  // split if the new subclusters are significantly separated
440  if( (z2-z1)>epsilon){
441  split=true;
442  double pk1=p1*y._pk[k]/(p1+p2);
443  double pk2=p2*y._pk[k]/(p1+p2);
444  y._z[k] = z2;
445  y._pk[k] = pk2;
446  y.InsertItem(k, z1, pk1);
447  nv++;
448 
449  // adjust remaining pointers
450  for(unsigned int jc=ic; jc<critical.size(); jc++){
451  if (critical[jc].second>k) {critical[jc].second++;}
452  }
453  }
454  }
455  return split;
456 }
const double beta
int i
Definition: DBlmapReader.cc:9
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
bool split(const double beta, track_t &t, vertex_t &y) const
U second(std::pair< T, U > const &p)
double p2[4]
Definition: TauolaWrapper.h:90
int nt
Definition: AMPTWrapper.h:32
int k[5][pyjets_maxn]
double p1[4]
Definition: TauolaWrapper.h:89
T w() const
const double epsilon
void DAClusterizerInZ_vect::splitAll ( vertex_t y) const

Definition at line 460 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::vertex_t::_pk, DAClusterizerInZ_vect::vertex_t::_z, DAClusterizerInZ_vect::vertex_t::AddItem(), DAClusterizerInZ_vect::vertex_t::DebugOut(), alignCSCRings::e, epsilon, DAClusterizerInZ_vect::vertex_t::ExtractRaw(), DAClusterizerInZ_vect::vertex_t::GetSize(), gen::k, LogDebug, DAClusterizerInZ_vect::vertex_t::pk, and DAClusterizerInZ_vect::vertex_t::z.

460  {
461 
462  const unsigned int nv = y.GetSize();
463 
464  double epsilon = 1e-3; // split all single vertices by 10 um
465  double zsep = 2 * epsilon; // split vertices that are isolated by at least zsep (vertices that haven't collapsed)
466  vertex_t y1;
467 
468  if (verbose_) {
469  LogDebug("DAClusterizerinZ_vectorized") << "Before Split "<< std::endl;
470  y.DebugOut();
471  }
472 
473  for (unsigned int k = 0; k < nv; k++) {
474  if (
475  ( (k == 0) || ( y._z[k - 1] < (y._z[k] - zsep)) ) &&
476  ( ((k + 1) == nv) || ( y._z[k + 1] > (y._z[k] + zsep)) ) )
477  {
478  // isolated prototype, split
479  double new_z = y.z[k] - epsilon;
480  y.z[k] = y.z[k] + epsilon;
481 
482  double new_pk = 0.5 * y.pk[k];
483  y.pk[k] = 0.5 * y.pk[k];
484 
485  y1.AddItem(new_z, new_pk);
486  y1.AddItem(y._z[k], y._pk[k]);
487  }
488  else if ( (y1.GetSize() == 0 ) ||
489  (y1._z[y1.GetSize() - 1] < (y._z[k] - zsep) ))
490  {
491  y1.AddItem(y._z[k], y._pk[k]);
492  }
493  else
494  {
495  y1._z[y1.GetSize() - 1] = y1._z[y1.GetSize() - 1] - epsilon;
496  y._z[k] = y._z[k] + epsilon;
497  y1.AddItem( y._z[k] , y._pk[k]);
498  }
499  }// vertex loop
500 
501  y = y1;
502  y.ExtractRaw();
503 
504  if (verbose_) {
505  LogDebug("DAClusterizerinZ_vectorized") << "After split " << std::endl;
506  y.DebugOut();
507  }
508 }
#define LogDebug(id)
int k[5][pyjets_maxn]
const double epsilon
double DAClusterizerInZ_vect::update ( double  beta,
track_t gtracks,
vertex_t gvertices,
bool  useRho0,
double &  rho0 
) const

Definition at line 104 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::vertex_t::_ei, DAClusterizerInZ_vect::vertex_t::_ei_cache, DAClusterizerInZ_vect::track_t::_pi, DAClusterizerInZ_vect::vertex_t::_se, DAClusterizerInZ_vect::vertex_t::_sw, DAClusterizerInZ_vect::vertex_t::_swE, DAClusterizerInZ_vect::vertex_t::_swz, DAClusterizerInZ_vect::track_t::_Z_sum, beta, delta, DAClusterizerInZ_vect::track_t::GetSize(), DAClusterizerInZ_vect::vertex_t::GetSize(), gen::k, LogDebug, nt, funct::pow(), testEve_cfg::tracks, and w().

Referenced by progressbar.ProgressBar::__next__(), relval_steps.Matrix::__setitem__(), relval_steps.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), relval_steps.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

105  {
106 
107  //update weights and vertex positions
108  // mass constrained annealing without noise
109  // returns the squared sum of changes of vertex positions
110 
111  const unsigned int nt = gtracks.GetSize();
112  const unsigned int nv = gvertices.GetSize();
113 
114  //initialize sums
115  double sumpi = 0;
116 
117  // to return how much the prototype moved
118  double delta = 0;
119 
120 
121  // intial value of a sum
122  double Z_init = 0;
123 
124  // define kernels
125  auto kernel_calc_exp_arg = [ beta, nv ] ( const unsigned int itrack,
126  track_t const& tracks,
127  vertex_t const& vertices ) {
128  const double track_z = tracks._z[itrack];
129  const double botrack_dz2 = -beta/tracks._dz2[itrack];
130 
131  // auto-vectorized
132  for ( unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
133  auto mult_res = track_z - vertices._z[ivertex];
134  vertices._ei_cache[ivertex] = botrack_dz2 * ( mult_res * mult_res );
135  }
136  };
137 
138  auto kernel_add_Z = [ nv, Z_init ] (vertex_t const& vertices) -> double
139  {
140  double ZTemp = Z_init;
141  for (unsigned int ivertex = 0; ivertex < nv; ++ivertex) {
142  ZTemp += vertices._pk[ivertex] * vertices._ei[ivertex];
143  }
144  return ZTemp;
145  };
146 
147  auto kernel_calc_normalization = [ beta, nv ] (const unsigned int track_num,
148  track_t & tks_vec,
149  vertex_t & y_vec ) {
150  auto tmp_trk_pi = tks_vec._pi[track_num];
151  auto o_trk_Z_sum = 1./tks_vec._Z_sum[track_num];
152  auto o_trk_dz2 = 1./tks_vec._dz2[track_num];
153  auto tmp_trk_z = tks_vec._z[track_num];
154  auto obeta = -1./beta;
155 
156  // auto-vectorized
157  for (unsigned int k = 0; k < nv; ++k) {
158  y_vec._se[k] += y_vec._ei[k] * (tmp_trk_pi* o_trk_Z_sum);
159  auto w = y_vec._pk[k] * y_vec._ei[k] * (tmp_trk_pi*o_trk_Z_sum *o_trk_dz2);
160  y_vec._sw[k] += w;
161  y_vec._swz[k] += w * tmp_trk_z;
162  y_vec._swE[k] += w * y_vec._ei_cache[k]*obeta;
163  }
164  };
165 
166 
167  for (auto ivertex = 0U; ivertex < nv; ++ivertex) {
168  gvertices._se[ivertex] = 0.0;
169  gvertices._sw[ivertex] = 0.0;
170  gvertices._swz[ivertex] = 0.0;
171  gvertices._swE[ivertex] = 0.0;
172  }
173 
174 
175  // independpent of loop
176  if ( useRho0 )
177  {
178  Z_init = rho0 * local_exp(-beta * dzCutOff_ * dzCutOff_); // cut-off
179  }
180 
181  // loop over tracks
182  for (auto itrack = 0U; itrack < nt; ++itrack) {
183  kernel_calc_exp_arg(itrack, gtracks, gvertices);
184  local_exp_list(gvertices._ei_cache, gvertices._ei, nv);
185 
186  gtracks._Z_sum[itrack] = kernel_add_Z(gvertices);
187 
188  // used in the next major loop to follow
189  if (!useRho0)
190  sumpi += gtracks._pi[itrack];
191 
192  if (gtracks._Z_sum[itrack] > 0) {
193  kernel_calc_normalization(itrack, gtracks, gvertices);
194  }
195  }
196 
197  // now update z and pk
198  auto kernel_calc_z = [ sumpi, nv, this, useRho0 ] (vertex_t & vertices ) -> double {
199 
200  double delta=0;
201  // does not vectorizes
202  for (unsigned int ivertex = 0; ivertex < nv; ++ ivertex ) {
203  if (vertices._sw[ivertex] > 0) {
204  auto znew = vertices._swz[ ivertex ] / vertices._sw[ ivertex ];
205  // prevents from vectorizing if
206  delta += std::pow( vertices._z[ ivertex ] - znew, 2 );
207  vertices._z[ ivertex ] = znew;
208  }
209 #ifdef VI_DEBUG
210  else {
211  edm::LogInfo("sumw") << "invalid sum of weights in fit: " << vertices._sw[ivertex] << endl;
212  if (this->verbose_) {
213  LogDebug("DAClusterizerinZ_vectorized") << " a cluster melted away ? pk=" << vertices._pk[ ivertex ] << " sumw="
214  << vertices._sw[ivertex] << endl;
215  }
216  }
217 #endif
218  }
219  // dont do, if rho cut
220  if ( ! useRho0 ){
221  auto osumpi = 1./sumpi;
222  for (unsigned int ivertex = 0; ivertex < nv; ++ ivertex )
223  vertices._pk[ ivertex ] = vertices._pk[ ivertex ] * vertices._se[ ivertex ] * osumpi;
224  }
225  return delta;
226  };
227 
228  delta += kernel_calc_z(gvertices);
229 
230  // return how much the prototypes moved
231  return delta;
232 }
#define LogDebug(id)
const double beta
dbl * delta
Definition: mlp_gen.cc:36
int nt
Definition: AMPTWrapper.h:32
int k[5][pyjets_maxn]
tuple tracks
Definition: testEve_cfg.py:39
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks, const int verbosity=0) const
T w() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
vector< TransientVertex > DAClusterizerInZ_vect::vertices ( const std::vector< reco::TransientTrack > &  tracks,
const int  verbosity = 0 
) const

Definition at line 513 of file DAClusterizerInZ_vect.cc.

References DAClusterizerInZ_vect::track_t::_dz2, DAClusterizerInZ_vect::track_t::_pi, DAClusterizerInZ_vect::vertex_t::_pk, DAClusterizerInZ_vect::track_t::_z, DAClusterizerInZ_vect::vertex_t::_z, DAClusterizerInZ_vect::track_t::_Z_sum, DAClusterizerInZ_vect::vertex_t::AddItem(), beta, hcal_timing_source_file_cfg::dump, alignCSCRings::e, DAClusterizerInZ_vect::track_t::ExtractRaw(), lumiContext::fill, DAClusterizerInZ_vect::track_t::GetSize(), DAClusterizerInZ_vect::vertex_t::GetSize(), i, gen::k, LogDebug, relval_steps::merge(), nt, AlCaHLTBitMon_ParallelJobs::p, split, DAClusterizerInZ_vect::track_t::tt, update, findQualityFiles::v, and detailsBasic3DVector::y.

513  {
514  track_t tks = fill(tracks);
515  tks.ExtractRaw();
516 
517  unsigned int nt = tracks.size();
518  double rho0 = 0.0; // start with no outlier rejection
519 
520  vector<TransientVertex> clusters;
521  if (tks.GetSize() == 0) return clusters;
522 
523  vertex_t y; // the vertex prototypes
524 
525  // initialize:single vertex at infinite temperature
526  y.AddItem( 0, 1.0);
527 
528  int niter = 0; // number of iterations
529 
530 
531  // estimate first critical temperature
532  double beta = beta0(betamax_, tks, y);
533  if ( verbose_) LogDebug("DAClusterizerinZ_vectorized") << "Beta0 is " << beta << std::endl;
534 
535  niter = 0;
536  while ((update(beta, tks, y, false, rho0) > 1.e-6) &&
537  (niter++ < maxIterations_)) {}
538 
539  // annealing loop, stop when T<Tmin (i.e. beta>1/Tmin)
540  while (beta < betamax_) {
541  if(useTc_){
542  update(beta, tks,y, false, rho0);
543  while(merge(y,beta)){update(beta, tks,y, false, rho0);}
544  split(beta, tks,y);
545  beta=beta/coolingFactor_;
546  }else{
547  beta=beta/coolingFactor_;
548  splitAll(y);
549  }
550 
551  // make sure we are not too far from equilibrium before cooling further
552  niter = 0;
553  while ((update(beta, tks, y, false, rho0) > 1.e-6) &&
554  (niter++ < maxIterations_)) {}
555  }
556 
557 
558  if(useTc_){
559  // last round of splitting, make sure no critical clusters are left
560  update(beta, tks,y, false, rho0);// make sure Tc is up-to-date
561  while(merge(y,beta)){update(beta, tks,y, false, rho0);}
562  unsigned int ntry=0;
563  while( split(beta, tks,y) && (ntry++<10) ){
564  niter=0;
565  while((update(beta, tks,y, false, rho0)>1.e-6) && (niter++ < maxIterations_)){}
566  merge(y,beta);
567  update(beta, tks,y, false, rho0);
568  }
569  }else{
570  // merge collapsed clusters
571  while(merge(y,beta)){update(beta, tks,y, false, rho0);}
572  //while(merge(y)){} original code
573  }
574 
575  if (verbose_) {
576  LogDebug("DAClusterizerinZ_vectorized") << "dump after 1st merging " << endl;
577  dump(beta, y, tks, 2);
578  }
579 
580  // switch on outlier rejection
581  rho0 = 1. / nt;
582 
583  // auto-vectorized
584  for (unsigned int k = 0; k < y.GetSize(); k++) y._pk[k] = 1.; // democratic
585  niter = 0;
586  while ((update(beta, tks, y, true, rho0) > 1.e-8) && (niter++ < maxIterations_)) {}
587  if (verbose_) {
588  LogDebug("DAClusterizerinZ_vectorized") << "rho0=" << rho0 << " niter=" << niter << endl;
589  dump(beta, y, tks, 2);
590  }
591 
592  // merge again (some cluster split by outliers collapse here)
593  while (merge(y)) {}
594  if (verbose_) {
595  LogDebug("DAClusterizerinZ_vectorized") << "dump after 2nd merging " << endl;
596  dump(beta, y, tks, 2);
597  }
598 
599  // continue from freeze-out to Tstop (=1) without splitting, eliminate insignificant vertices
600  while (beta <= betastop_) {
601  while (purge(y, tks, rho0, beta)) {
602  niter = 0;
603  while ((update(beta, tks, y, true, rho0) > 1.e-6) && (niter++ < maxIterations_)) {}
604  }
605  beta /= coolingFactor_;
606  niter = 0;
607  while ((update(beta, tks, y, true, rho0) > 1.e-6) && (niter++< maxIterations_)) {}
608  }
609 
610  if (verbose_) {
611  LogDebug("DAClusterizerinZ_vectorized") << "Final result, rho0=" << rho0 << endl;
612  dump(beta, y, tks, 2);
613  }
614 
615  // select significant tracks and use a TransientVertex as a container
616  GlobalError dummyError;
617 
618  // ensure correct normalization of probabilities, should makes double assginment reasonably impossible
619  const unsigned int nv = y.GetSize();
620 
621  for (unsigned int i = 0; i < nt; i++) {
622  tks._Z_sum[i] = rho0 * local_exp(-beta * dzCutOff_ * dzCutOff_);
623  for (unsigned int k = 0; k < nv; k++) {
624  tks._Z_sum[i] += y._pk[k] * local_exp(-beta * Eik(tks._z[i], y._z[k],tks._dz2[i]));
625  }
626  }
627 
628  for (unsigned int k = 0; k < nv; k++) {
629  GlobalPoint pos(0, 0, y._z[k]);
630 
631  vector<reco::TransientTrack> vertexTracks;
632  for (unsigned int i = 0; i < nt; i++) {
633  if (tks._Z_sum[i] > 0) {
634 
635  double p = y._pk[k] * local_exp(-beta * Eik(tks._z[i], y._z[k],
636  tks._dz2[i])) / tks._Z_sum[i];
637  if ((tks._pi[i] > 0) && (p > 0.5)) {
638 
639  vertexTracks.push_back(*(tks.tt[i]));
640  tks._Z_sum[i] = 0;
641  } // setting Z=0 excludes double assignment
642  }
643  }
644  TransientVertex v(pos, dummyError, vertexTracks, 0);
645  clusters.push_back(v);
646  }
647 
648  return clusters;
649 
650 }
#define LogDebug(id)
const double beta
int i
Definition: DBlmapReader.cc:9
void splitAll(vertex_t &y) const
bool split(const double beta, track_t &t, vertex_t &y) const
track_t fill(const std::vector< reco::TransientTrack > &tracks) const
bool merge(vertex_t &) const
double update(double beta, track_t &gtracks, vertex_t &gvertices, bool useRho0, double &rho0) const
double beta0(const double betamax, track_t const &tks, vertex_t const &y) const
int nt
Definition: AMPTWrapper.h:32
int k[5][pyjets_maxn]
void dump(const double beta, const vertex_t &y, const track_t &tks, const int verbosity=0) const
tuple tracks
Definition: testEve_cfg.py:39
bool purge(vertex_t &, track_t &, double &, const double) const

Member Data Documentation

float DAClusterizerInZ_vect::betamax_
private

Definition at line 202 of file DAClusterizerInZ_vect.h.

float DAClusterizerInZ_vect::betastop_
private

Definition at line 203 of file DAClusterizerInZ_vect.h.

double DAClusterizerInZ_vect::coolingFactor_
private

Definition at line 201 of file DAClusterizerInZ_vect.h.

double DAClusterizerInZ_vect::d0CutOff_
private

Definition at line 205 of file DAClusterizerInZ_vect.h.

double DAClusterizerInZ_vect::dzCutOff_
private

Definition at line 204 of file DAClusterizerInZ_vect.h.

int DAClusterizerInZ_vect::maxIterations_
private

Definition at line 200 of file DAClusterizerInZ_vect.h.

bool DAClusterizerInZ_vect::useTc_
private

Definition at line 206 of file DAClusterizerInZ_vect.h.

bool DAClusterizerInZ_vect::verbose_
private

Definition at line 198 of file DAClusterizerInZ_vect.h.

float DAClusterizerInZ_vect::vertexSize_
private

Definition at line 199 of file DAClusterizerInZ_vect.h.