CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Attributes
DAClusterizerInZ Class Reference

#include <DAClusterizerInZ.h>

Inheritance diagram for DAClusterizerInZ:
TrackClusterizerInZ

Classes

struct  track_t
 
struct  vertex_t
 

Public Member Functions

double beta0 (const double betamax, std::vector< track_t > &tks, std::vector< vertex_t > &y) const
 
std::vector< std::vector< reco::TransientTrack > > clusterize (const std::vector< reco::TransientTrack > &tracks) const override
 
 DAClusterizerInZ (const edm::ParameterSet &conf)
 
void dump (const double beta, const std::vector< vertex_t > &y, const std::vector< track_t > &tks, const int verbosity=0) const
 
double Eik (const track_t &t, const vertex_t &k) const
 
std::vector< track_tfill (const std::vector< reco::TransientTrack > &tracks) const
 
bool merge (std::vector< vertex_t > &, int) const
 
bool merge (std::vector< vertex_t > &, double &) const
 
bool purge (std::vector< vertex_t > &, std::vector< track_t > &, double &, const double) const
 
bool split (double beta, std::vector< track_t > &tks, std::vector< vertex_t > &y, double threshold) const
 
void splitAll (std::vector< vertex_t > &y) 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 &) 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

Definition at line 18 of file DAClusterizerInZ.h.

Constructor & Destructor Documentation

◆ DAClusterizerInZ()

DAClusterizerInZ::DAClusterizerInZ ( const edm::ParameterSet conf)

Definition at line 414 of file DAClusterizerInZ.cc.

References gather_cfg::cout, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), and HLT_2023v12_cff::Tmin.

414  {
415  // some defaults to avoid uninitialized variables
416  verbose_ = conf.getUntrackedParameter<bool>("verbose", false);
417  useTc_ = true;
418  betamax_ = 0.1;
419  betastop_ = 1.0;
420  coolingFactor_ = 0.8;
421  maxIterations_ = 100;
422  vertexSize_ = 0.05; // 0.5 mm
423  dzCutOff_ = 4.0; // Adaptive Fitter uses 3.0 but that appears to be a bit tight here sometimes
424 
425  // configure
426 
427  double Tmin = conf.getParameter<double>("Tmin");
428  vertexSize_ = conf.getParameter<double>("vertexSize");
429  coolingFactor_ = conf.getParameter<double>("coolingFactor");
430  d0CutOff_ = conf.getParameter<double>("d0CutOff");
431  dzCutOff_ = conf.getParameter<double>("dzCutOff");
432  maxIterations_ = 100;
433  if (Tmin == 0) {
434  cout << "DAClusterizerInZ: invalid Tmin" << Tmin << " reset do default " << 1. / betamax_ << endl;
435  } else {
436  betamax_ = 1. / Tmin;
437  }
438 
439  // for testing, negative cooling factor: revert to old splitting scheme
440  if (coolingFactor_ < 0) {
442  useTc_ = false;
443  }
444 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T getUntrackedParameter(std::string const &, T const &) const

Member Function Documentation

◆ beta0()

double DAClusterizerInZ::beta0 ( const double  betamax,
std::vector< track_t > &  tks,
std::vector< vertex_t > &  y 
) const

Definition at line 267 of file DAClusterizerInZ.cc.

References a, b, PVValHelper::dx, mps_fire::i, dqmdumpme::k, dqm-mbProfile::log, nt, funct::pow(), and w().

267  {
268  double T0 = 0; // max Tc for beta=0
269  // estimate critical temperature from beta=0 (T=inf)
270  unsigned int nt = tks.size();
271 
272  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
273  // vertex fit at T=inf
274  double sumwz = 0;
275  double sumw = 0;
276  for (unsigned int i = 0; i < nt; i++) {
277  double w = tks[i].pi / tks[i].dz2;
278  sumwz += w * tks[i].z;
279  sumw += w;
280  }
281  k->z = sumwz / sumw;
282 
283  // estimate Tcrit, eventually do this in the same loop
284  double a = 0, b = 0;
285  for (unsigned int i = 0; i < nt; i++) {
286  double dx = tks[i].z - (k->z);
287  double w = tks[i].pi / tks[i].dz2;
288  a += w * pow(dx, 2) / tks[i].dz2;
289  b += w;
290  }
291  double Tc = 2. * a / b; // the critical temperature of this vertex
292  if (Tc > T0)
293  T0 = Tc;
294  } // vertex loop (normally there should be only one vertex at beta=0)
295 
296  if (T0 > 1. / betamax) {
297  return betamax / pow(coolingFactor_, int(log(T0 * betamax) / log(coolingFactor_)) - 1);
298  } else {
299  // ensure at least one annealing step
300  return betamax / coolingFactor_;
301  }
302 }
T w() const
int nt
Definition: AMPTWrapper.h:42
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ clusterize()

vector< vector< reco::TransientTrack > > DAClusterizerInZ::clusterize ( const std::vector< reco::TransientTrack > &  tracks) const
overridevirtual

Implements TrackClusterizerInZ.

Definition at line 680 of file DAClusterizerInZ.cc.

References bsc_activity_cfg::clusters, gather_cfg::cout, mps_fire::i, dqmdumpme::k, position, pwdgSkimBPark_cfi::tracks, and AlignmentTracksFromVertexSelector_cfi::vertices.

680  {
681  if (verbose_) {
682  cout << "###################################################" << endl;
683  cout << "# DAClusterizerInZ::clusterize nt=" << tracks.size() << endl;
684  cout << "###################################################" << endl;
685  }
686 
687  vector<vector<reco::TransientTrack> > clusters;
688  vector<TransientVertex> pv = vertices(tracks);
689 
690  if (verbose_) {
691  cout << "# DAClusterizerInZ::clusterize pv.size=" << pv.size() << endl;
692  }
693  if (pv.empty()) {
694  return clusters;
695  }
696 
697  // fill into clusters and merge
698  vector<reco::TransientTrack> aCluster = pv.begin()->originalTracks();
699 
700  for (vector<TransientVertex>::iterator k = pv.begin() + 1; k != pv.end(); k++) {
701  if (fabs(k->position().z() - (k - 1)->position().z()) > (2 * vertexSize_)) {
702  // close a cluster
703  clusters.push_back(aCluster);
704  aCluster.clear();
705  }
706  for (unsigned int i = 0; i < k->originalTracks().size(); i++) {
707  aCluster.push_back(k->originalTracks().at(i));
708  }
709  }
710  clusters.push_back(aCluster);
711 
712  return clusters;
713 }
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks, const int verbosity=0) const
static int position[264][3]
Definition: ReadPGInfo.cc:289

◆ dump()

void DAClusterizerInZ::dump ( const double  beta,
const std::vector< vertex_t > &  y,
const std::vector< track_t > &  tks,
const int  verbosity = 0 
) const

Definition at line 446 of file DAClusterizerInZ.cc.

References HLT_2023v12_cff::beta, gather_cfg::cout, TauDecayModes::dec, JetChargeProducer_cfi::exp, F(), alignBH_cfg::fixed, reco::TrackBase::highPurity, mps_fire::i, listHistos::IP, dqmdumpme::k, dqm-mbProfile::log, reco::HitPattern::MISSING_OUTER_HITS, AlCaHLTBitMon_ParallelJobs::p, pi, GeomDetEnumerators::PixelBarrel, mathSSE::sqrt(), submitPVValidationJobs::t, verbosity, and BeamSpotPI::Z.

449  {
450  // copy and sort for nicer printout
451  vector<track_t> tks;
452  for (vector<track_t>::const_iterator t = tks0.begin(); t != tks0.end(); t++) {
453  tks.push_back(*t);
454  }
455  stable_sort(tks.begin(), tks.end(), recTrackLessZ1);
456 
457  cout << "-----DAClusterizerInZ::dump ----" << endl;
458  cout << "beta=" << beta << " betamax= " << betamax_ << endl;
459  cout << " z= ";
460  cout.precision(4);
461  for (vector<vertex_t>::const_iterator k = y.begin(); k != y.end(); k++) {
462  cout << setw(8) << fixed << k->z;
463  }
464  cout << endl << "T=" << setw(15) << 1. / beta << " Tc= ";
465  for (vector<vertex_t>::const_iterator k = y.begin(); k != y.end(); k++) {
466  cout << setw(8) << fixed << k->Tc;
467  }
468 
469  cout << endl << " pk=";
470  for (vector<vertex_t>::const_iterator k = y.begin(); k != y.end(); k++) {
471  cout << setw(8) << setprecision(3) << fixed << k->pk;
472  }
473  cout << endl;
474 
475  if (verbosity > 0) {
476  double E = 0, F = 0;
477  cout << endl;
478  cout << "---- z +/- dz ip +/-dip pt phi eta weights ----" << endl;
479  cout.precision(4);
480  for (unsigned int i = 0; i < tks.size(); i++) {
481  if (tks[i].Z > 0) {
482  F -= log(tks[i].Z) / beta;
483  }
484  double tz = tks[i].z;
485  cout << setw(3) << i << ")" << setw(8) << fixed << setprecision(4) << tz << " +/-" << setw(6) << sqrt(tks[i].dz2);
486 
487  if (tks[i].tt->track().quality(reco::TrackBase::highPurity)) {
488  cout << " *";
489  } else {
490  cout << " ";
491  }
492  if (tks[i].tt->track().hitPattern().hasValidHitInPixelLayer(PixelSubdetector::SubDetector::PixelBarrel, 1)) {
493  cout << "+";
494  } else {
495  cout << "-";
496  }
497  cout << setw(1)
498  << tks[i]
499  .tt->track()
500  .hitPattern()
501  .pixelBarrelLayersWithMeasurement(); // see DataFormats/TrackReco/interface/HitPattern.h
502  cout << setw(1) << tks[i].tt->track().hitPattern().pixelEndcapLayersWithMeasurement();
503  cout << setw(1) << hex
504  << tks[i].tt->track().hitPattern().trackerLayersWithMeasurement() -
505  tks[i].tt->track().hitPattern().pixelLayersWithMeasurement()
506  << dec;
507  cout << "=" << setw(1) << hex
508  << tks[i].tt->track().hitPattern().numberOfLostHits(reco::HitPattern::MISSING_OUTER_HITS) << dec;
509 
510  Measurement1D IP = tks[i].tt->stateAtBeamLine().transverseImpactParameter();
511  cout << setw(8) << IP.value() << "+/-" << setw(6) << IP.error();
512  cout << " " << setw(6) << setprecision(2) << tks[i].tt->track().pt() * tks[i].tt->track().charge();
513  cout << " " << setw(5) << setprecision(2) << tks[i].tt->track().phi() << " " << setw(5) << setprecision(2)
514  << tks[i].tt->track().eta();
515 
516  for (vector<vertex_t>::const_iterator k = y.begin(); k != y.end(); k++) {
517  if ((tks[i].pi > 0) && (tks[i].Z > 0)) {
518  //double p=pik(beta,tks[i],*k);
519  double p = k->pk * exp(-beta * Eik(tks[i], *k)) / tks[i].Z;
520  if (p > 0.0001) {
521  cout << setw(8) << setprecision(3) << p;
522  } else {
523  cout << " . ";
524  }
525  E += p * Eik(tks[i], *k);
526  } else {
527  cout << " ";
528  }
529  }
530  cout << endl;
531  }
532  cout << endl << "T=" << 1 / beta << " E=" << E << " n=" << y.size() << " F= " << F << endl << "----------" << endl;
533  }
534 }
const Double_t pi
Definition: TTTypes.h:54
T sqrt(T t)
Definition: SSEVec.h:19
const int verbosity
double Eik(const track_t &t, const vertex_t &k) const
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163

◆ Eik()

double DAClusterizerInZ::Eik ( const track_t t,
const vertex_t k 
) const

Definition at line 42 of file DAClusterizerInZ.cc.

References dqmdumpme::k, funct::pow(), and submitPVValidationJobs::t.

42 { return pow(t.z - k.z, 2) / t.dz2; }
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ fill()

vector< DAClusterizerInZ::track_t > DAClusterizerInZ::fill ( const std::vector< reco::TransientTrack > &  tracks) const

Definition at line 15 of file DAClusterizerInZ.cc.

References pwdgSkimBPark_cfi::beamSpot, funct::cos(), JetChargeProducer_cfi::exp, listHistos::IP, position, funct::pow(), funct::sin(), submitPVValidationJobs::t, funct::tan(), and pwdgSkimBPark_cfi::tracks.

15  {
16  // prepare track data for clustering
17  vector<track_t> tks;
18  for (vector<reco::TransientTrack>::const_iterator it = tracks.begin(); it != tracks.end(); it++) {
19  track_t t;
20  t.z = ((*it).stateAtBeamLine().trackStateAtPCA()).position().z();
21  double tantheta = tan(((*it).stateAtBeamLine().trackStateAtPCA()).momentum().theta());
22  double phi = ((*it).stateAtBeamLine().trackStateAtPCA()).momentum().phi();
23  // get the beam-spot
24  reco::BeamSpot beamspot = (it->stateAtBeamLine()).beamSpot();
25  t.dz2 = pow((*it).track().dzError(), 2) // track errror
26  + (pow(beamspot.BeamWidthX() * cos(phi), 2) + pow(beamspot.BeamWidthY() * sin(phi), 2)) /
27  pow(tantheta, 2) // beam-width induced
28  + pow(vertexSize_, 2); // intrinsic vertex size, safer for outliers and short lived decays
29  if (d0CutOff_ > 0) {
30  Measurement1D IP = (*it).stateAtBeamLine().transverseImpactParameter(); // error constains beamspot
31  t.pi = 1. / (1. + exp(pow(IP.value() / IP.error(), 2) - pow(d0CutOff_, 2))); // reduce weight for high ip tracks
32  } else {
33  t.pi = 1.;
34  }
35  t.tt = &(*it);
36  t.Z = 1.;
37  tks.push_back(t);
38  }
39  return tks;
40 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static int position[264][3]
Definition: ReadPGInfo.cc:289
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ merge() [1/2]

bool DAClusterizerInZ::merge ( std::vector< vertex_t > &  y,
int  nt 
) const

Definition at line 171 of file DAClusterizerInZ.cc.

References dqmdumpme::k.

171  {
172  // merge clusters that collapsed or never separated, return true if vertices were merged, false otherwise
173 
174  if (y.size() < 2)
175  return false;
176 
177  for (vector<vertex_t>::iterator k = y.begin(); (k + 1) != y.end(); k++) {
178  if (fabs((k + 1)->z - k->z) < 1.e-3) { // with fabs if only called after freeze-out (splitAll() at highter T)
179  double rho = k->pk + (k + 1)->pk;
180  if (rho > 0) {
181  k->z = (k->pk * k->z + (k + 1)->z * (k + 1)->pk) / rho;
182  } else {
183  k->z = 0.5 * (k->z + (k + 1)->z);
184  }
185  k->pk = rho;
186 
187  y.erase(k + 1);
188  return true;
189  }
190  }
191 
192  return false;
193 }

◆ merge() [2/2]

bool DAClusterizerInZ::merge ( std::vector< vertex_t > &  y,
double &  beta 
) const

Definition at line 195 of file DAClusterizerInZ.cc.

References HLT_2023v12_cff::beta, dqmdumpme::k, and funct::pow().

195  {
196  // merge clusters that collapsed or never separated,
197  // only merge if the estimated critical temperature of the merged vertex is below the current temperature
198  // return true if vertices were merged, false otherwise
199  if (y.size() < 2)
200  return false;
201 
202  for (vector<vertex_t>::iterator k = y.begin(); (k + 1) != y.end(); k++) {
203  if (fabs((k + 1)->z - k->z) < 2.e-3) {
204  double rho = k->pk + (k + 1)->pk;
205  double swE = k->swE + (k + 1)->swE - k->pk * (k + 1)->pk / rho * pow((k + 1)->z - k->z, 2);
206  double Tc = 2 * swE / (k->sw + (k + 1)->sw);
207 
208  if (Tc * beta < 1) {
209  if (rho > 0) {
210  k->z = (k->pk * k->z + (k + 1)->z * (k + 1)->pk) / rho;
211  } else {
212  k->z = 0.5 * (k->z + (k + 1)->z);
213  }
214  k->pk = rho;
215  k->sw += (k + 1)->sw;
216  k->swE = swE;
217  k->Tc = Tc;
218  y.erase(k + 1);
219  return true;
220  }
221  }
222  }
223 
224  return false;
225 }
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ purge()

bool DAClusterizerInZ::purge ( std::vector< vertex_t > &  y,
std::vector< track_t > &  tks,
double &  rho0,
const double  beta 
) const

Definition at line 227 of file DAClusterizerInZ.cc.

References HLT_2023v12_cff::beta, gather_cfg::cout, JetChargeProducer_cfi::exp, mps_fire::i, dqmdumpme::k, reco::ParticleMasses::k0, nt, AlCaHLTBitMon_ParallelJobs::p, pi, and BeamSpotPI::Z.

227  {
228  // eliminate clusters with only one significant/unique track
229  if (y.size() < 2)
230  return false;
231 
232  unsigned int nt = tks.size();
233  double sumpmin = nt;
234  vector<vertex_t>::iterator k0 = y.end();
235  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
236  int nUnique = 0;
237  double sump = 0;
238  double pmax = k->pk / (k->pk + rho0 * exp(-beta * dzCutOff_ * dzCutOff_));
239  for (unsigned int i = 0; i < nt; i++) {
240  if (tks[i].Z > 0) {
241  double p = k->pk * exp(-beta * Eik(tks[i], *k)) / tks[i].Z;
242  sump += p;
243  if ((p > 0.9 * pmax) && (tks[i].pi > 0)) {
244  nUnique++;
245  }
246  }
247  }
248 
249  if ((nUnique < 2) && (sump < sumpmin)) {
250  sumpmin = sump;
251  k0 = k;
252  }
253  }
254 
255  if (k0 != y.end()) {
256  if (verbose_) {
257  cout << "eliminating prototype at " << k0->z << " with sump=" << sumpmin << endl;
258  }
259  //rho0+=k0->pk;
260  y.erase(k0);
261  return true;
262  } else {
263  return false;
264  }
265 }
const Double_t pi
int nt
Definition: AMPTWrapper.h:42
double Eik(const track_t &t, const vertex_t &k) const

◆ split()

bool DAClusterizerInZ::split ( double  beta,
std::vector< track_t > &  tks,
std::vector< vertex_t > &  y,
double  threshold 
) const

Definition at line 304 of file DAClusterizerInZ.cc.

References HLT_2023v12_cff::beta, hlt_jetmet_dqm_QT_fromfile_cfg::critical, MillePedeFileConverter_cfg::e, geometryDiff::epsilon, JetChargeProducer_cfi::exp, mps_fire::i, AlCaHLTBitMon_ParallelJobs::p, LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, DAClusterizerInZ::vertex_t::pk, edm::second(), submitPVValidationJobs::split(), w(), w1, w2, DAClusterizerInZ::vertex_t::z, BeamSpotPI::Z, and testProducerWithPsetDescEmpty_cfi::z2.

304  {
305  // split only critical vertices (Tc >~ T=1/beta <==> beta*Tc>~1)
306  // an update must have been made just before doing this (same beta, no merging)
307  // returns true if at least one cluster was split
308 
309  double epsilon = 1e-3; // split all single vertices by 10 um
310  bool split = false;
311 
312  // avoid left-right biases by splitting highest Tc first
313 
314  std::vector<std::pair<double, unsigned int> > critical;
315  for (unsigned int ik = 0; ik < y.size(); ik++) {
316  if (beta * y[ik].Tc > 1.) {
317  critical.push_back(make_pair(y[ik].Tc, ik));
318  }
319  }
320  stable_sort(critical.begin(), critical.end(), std::greater<std::pair<double, unsigned int> >());
321 
322  for (unsigned int ic = 0; ic < critical.size(); ic++) {
323  unsigned int ik = critical[ic].second;
324  // estimate subcluster positions and weight
325  double p1 = 0, z1 = 0, w1 = 0;
326  double p2 = 0, z2 = 0, w2 = 0;
327  //double sumpi=0;
328  for (unsigned int i = 0; i < tks.size(); i++) {
329  if (tks[i].Z > 0) {
330  //sumpi+=tks[i].pi;
331  double p = y[ik].pk * exp(-beta * Eik(tks[i], y[ik])) / tks[i].Z * tks[i].pi;
332  double w = p / tks[i].dz2;
333  if (tks[i].z < y[ik].z) {
334  p1 += p;
335  z1 += w * tks[i].z;
336  w1 += w;
337  } else {
338  p2 += p;
339  z2 += w * tks[i].z;
340  w2 += w;
341  }
342  }
343  }
344  if (w1 > 0) {
345  z1 = z1 / w1;
346  } else {
347  z1 = y[ik].z - epsilon;
348  }
349  if (w2 > 0) {
350  z2 = z2 / w2;
351  } else {
352  z2 = y[ik].z + epsilon;
353  }
354 
355  // reduce split size if there is not enough room
356  if ((ik > 0) && (y[ik - 1].z >= z1)) {
357  z1 = 0.5 * (y[ik].z + y[ik - 1].z);
358  }
359  if ((ik + 1 < y.size()) && (y[ik + 1].z <= z2)) {
360  z2 = 0.5 * (y[ik].z + y[ik + 1].z);
361  }
362 
363  // split if the new subclusters are significantly separated
364  if ((z2 - z1) > epsilon) {
365  split = true;
366  vertex_t vnew;
367  vnew.pk = p1 * y[ik].pk / (p1 + p2);
368  y[ik].pk = p2 * y[ik].pk / (p1 + p2);
369  vnew.z = z1;
370  y[ik].z = z2;
371  y.insert(y.begin() + ik, vnew);
372 
373  // adjust remaining pointers
374  for (unsigned int jc = ic; jc < critical.size(); jc++) {
375  if (critical[jc].second > ik) {
376  critical[jc].second++;
377  }
378  }
379  }
380  }
381 
382  // stable_sort(y.begin(), y.end(), clusterLessZ);
383  return split;
384 }
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
T w() const
bool split(double beta, std::vector< track_t > &tks, std::vector< vertex_t > &y, double threshold) const
U second(std::pair< T, U > const &p)
weight_default_t w1[2000]
Definition: w1.h:9
double Eik(const track_t &t, const vertex_t &k) const

◆ splitAll()

void DAClusterizerInZ::splitAll ( std::vector< vertex_t > &  y) const

Definition at line 386 of file DAClusterizerInZ.cc.

References MillePedeFileConverter_cfg::e, geometryDiff::epsilon, dqmdumpme::k, DAClusterizerInZ::vertex_t::pk, testProducerWithPsetDescEmpty_cfi::y1, and DAClusterizerInZ::vertex_t::z.

386  {
387  double epsilon = 1e-3; // split all single vertices by 10 um
388  double zsep = 2 * epsilon; // split vertices that are isolated by at least zsep (vertices that haven't collapsed)
389  vector<vertex_t> y1;
390 
391  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
392  if (((k == y.begin()) || (k - 1)->z < k->z - zsep) && (((k + 1) == y.end()) || (k + 1)->z > k->z + zsep)) {
393  // isolated prototype, split
394  vertex_t vnew;
395  vnew.z = k->z - epsilon;
396  (*k).z = k->z + epsilon;
397  vnew.pk = 0.5 * (*k).pk;
398  (*k).pk = 0.5 * (*k).pk;
399  y1.push_back(vnew);
400  y1.push_back(*k);
401 
402  } else if (y1.empty() || (y1.back().z < k->z - zsep)) {
403  y1.push_back(*k);
404  } else {
405  y1.back().z -= epsilon;
406  k->z += epsilon;
407  y1.push_back(*k);
408  }
409  } // vertex loop
410 
411  y = y1;
412 }

◆ update() [1/2]

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

Definition at line 44 of file DAClusterizerInZ.cc.

References HLT_2023v12_cff::beta, gather_cfg::cout, dumpMFGeometry_cfg::delta, JetChargeProducer_cfi::exp, mps_fire::i, dqmdumpme::k, nt, funct::pow(), w(), and BeamSpotPI::Z.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

44  {
45  //update weights and vertex positions
46  // mass constrained annealing without noise
47  // returns the squared sum of changes of vertex positions
48 
49  unsigned int nt = tks.size();
50 
51  //initialize sums
52  double sumpi = 0;
53  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
54  k->se = 0;
55  k->sw = 0;
56  k->swz = 0;
57  k->swE = 0;
58  k->Tc = 0;
59  }
60 
61  // loop over tracks
62  for (unsigned int i = 0; i < nt; i++) {
63  // update pik and Zi
64  double Zi = 0.;
65  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
66  k->ei = exp(-beta * Eik(tks[i], *k)); // cache exponential for one track at a time
67  Zi += k->pk * k->ei;
68  }
69  tks[i].Z = Zi;
70 
71  // normalization for pk
72  if (tks[i].Z > 0) {
73  sumpi += tks[i].pi;
74  // accumulate weighted z and weights for vertex update
75  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
76  k->se += tks[i].pi * k->ei / Zi;
77  double w = k->pk * tks[i].pi * k->ei / Zi / tks[i].dz2;
78  k->sw += w;
79  k->swz += w * tks[i].z;
80  k->swE += w * Eik(tks[i], *k);
81  }
82  } else {
83  sumpi += tks[i].pi;
84  }
85 
86  } // end of track loop
87 
88  // now update z and pk
89  double delta = 0;
90  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
91  if (k->sw > 0) {
92  double znew = k->swz / k->sw;
93  delta += pow(k->z - znew, 2);
94  k->z = znew;
95  k->Tc = 2 * k->swE / k->sw;
96  } else {
97  edm::LogInfo("sumw") << "invalid sum of weights in fit: " << k->sw << endl;
98  if (verbose_) {
99  cout << " a cluster melted away ? pk=" << k->pk << " sumw=" << k->sw << endl;
100  }
101  k->Tc = -1;
102  }
103 
104  k->pk = k->pk * k->se / sumpi;
105  }
106 
107  // return how much the prototypes moved
108  return delta;
109 }
T w() const
int nt
Definition: AMPTWrapper.h:42
Log< level::Info, false > LogInfo
double Eik(const track_t &t, const vertex_t &k) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ update() [2/2]

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

Definition at line 111 of file DAClusterizerInZ.cc.

References HLT_2023v12_cff::beta, gather_cfg::cout, dumpMFGeometry_cfg::delta, JetChargeProducer_cfi::exp, mps_fire::i, dqmdumpme::k, nt, funct::pow(), w(), and BeamSpotPI::Z.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

111  {
112  // MVF style, no more vertex weights, update tracks weights and vertex positions, with noise
113  // returns the squared sum of changes of vertex positions
114 
115  unsigned int nt = tks.size();
116 
117  //initialize sums
118  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
119  k->se = 0;
120  k->sw = 0;
121  k->swz = 0;
122  k->swE = 0;
123  k->Tc = 0;
124  }
125 
126  // loop over tracks
127  for (unsigned int i = 0; i < nt; i++) {
128  // update pik and Zi
129  double Zi = rho0 * exp(-beta * dzCutOff_ * dzCutOff_); // cut-off
130  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
131  k->ei = exp(-beta * Eik(tks[i], *k)); // cache exponential for one track at a time
132  Zi += k->pk * k->ei;
133  }
134  tks[i].Z = Zi;
135 
136  // normalization
137  if (tks[i].Z > 0) {
138  // accumulate weighted z and weights for vertex update
139  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
140  k->se += tks[i].pi * k->ei / Zi;
141  double w = k->pk * tks[i].pi * k->ei / Zi / tks[i].dz2;
142  k->sw += w;
143  k->swz += w * tks[i].z;
144  k->swE += w * Eik(tks[i], *k);
145  }
146  }
147 
148  } // end of track loop
149 
150  // now update z
151  double delta = 0;
152  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
153  if (k->sw > 0) {
154  double znew = k->swz / k->sw;
155  delta += pow(k->z - znew, 2);
156  k->z = znew;
157  k->Tc = 2 * k->swE / k->sw;
158  } else {
159  edm::LogInfo("sumw") << "invalid sum of weights in fit: " << k->sw << endl;
160  if (verbose_) {
161  cout << " a cluster melted away ? pk=" << k->pk << " sumw=" << k->sw << endl;
162  }
163  k->Tc = 0;
164  }
165  }
166 
167  // return how much the prototypes moved
168  return delta;
169 }
T w() const
int nt
Definition: AMPTWrapper.h:42
Log< level::Info, false > LogInfo
double Eik(const track_t &t, const vertex_t &k) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ vertices()

vector< TransientVertex > DAClusterizerInZ::vertices ( const std::vector< reco::TransientTrack > &  tracks,
const int  verbosity = 0 
) const

Definition at line 536 of file DAClusterizerInZ.cc.

References HLT_2023v12_cff::beta, bsc_activity_cfg::clusters, gather_cfg::cout, GCP_Ntuples_cfg::dump, MillePedeFileConverter_cfg::e, JetChargeProducer_cfi::exp, ntuplemaker::fill, mps_fire::i, dqmdumpme::k, merge(), nt, AlCaHLTBitMon_ParallelJobs::p, pi, DAClusterizerInZ::vertex_t::pk, submitPVValidationJobs::split(), pwdgSkimBPark_cfi::tracks, update, findQualityFiles::v, DAClusterizerInZ::vertex_t::z, and BeamSpotPI::Z.

537  {
538  vector<track_t> tks = fill(tracks);
539  unsigned int nt = tracks.size();
540  double rho0 = 0.0; // start with no outlier rejection
541 
542  vector<TransientVertex> clusters;
543  if (tks.empty())
544  return clusters;
545 
546  vector<vertex_t> y; // the vertex prototypes
547 
548  // initialize:single vertex at infinite temperature
549  vertex_t vstart;
550  vstart.z = 0.;
551  vstart.pk = 1.;
552  y.push_back(vstart);
553  int niter = 0; // number of iterations
554 
555  // estimate first critical temperature
556  double beta = beta0(betamax_, tks, y);
557  niter = 0;
558  while ((update(beta, tks, y) > 1.e-6) && (niter++ < maxIterations_)) {
559  }
560 
561  // annealing loop, stop when T<Tmin (i.e. beta>1/Tmin)
562  while (beta < betamax_) {
563  if (useTc_) {
564  update(beta, tks, y);
565  while (merge(y, beta)) {
566  update(beta, tks, y);
567  }
568  split(beta, tks, y, 1.);
570  } else {
572  splitAll(y);
573  }
574 
575  // make sure we are not too far from equilibrium before cooling further
576  niter = 0;
577  while ((update(beta, tks, y) > 1.e-6) && (niter++ < maxIterations_)) {
578  }
579  }
580 
581  if (useTc_) {
582  // last round of splitting, make sure no critical clusters are left
583  update(beta, tks, y);
584  while (merge(y, beta)) {
585  update(beta, tks, y);
586  }
587  unsigned int ntry = 0;
588  while (split(beta, tks, y, 1.) && (ntry++ < 10)) {
589  niter = 0;
590  while ((update(beta, tks, y) > 1.e-6) && (niter++ < maxIterations_)) {
591  }
592  merge(y, beta);
593  update(beta, tks, y);
594  }
595  } else {
596  // merge collapsed clusters
597  while (merge(y, beta)) {
598  update(beta, tks, y);
599  }
600  if (verbose_) {
601  cout << "dump after 1st merging " << endl;
602  dump(beta, y, tks, 2);
603  }
604  }
605 
606  // switch on outlier rejection
607  rho0 = 1. / nt;
608  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
609  k->pk = 1.;
610  } // democratic
611  niter = 0;
612  while ((update(beta, tks, y, rho0) > 1.e-8) && (niter++ < maxIterations_)) {
613  }
614  if (verbose_) {
615  cout << "rho0=" << rho0 << " niter=" << niter << endl;
616  dump(beta, y, tks, 2);
617  }
618 
619  // merge again (some cluster split by outliers collapse here)
620  while (merge(y, tks.size())) {
621  }
622  if (verbose_) {
623  cout << "dump after 2nd merging " << endl;
624  dump(beta, y, tks, 2);
625  }
626 
627  // continue from freeze-out to Tstop (=1) without splitting, eliminate insignificant vertices
628  while (beta <= betastop_) {
629  while (purge(y, tks, rho0, beta)) {
630  niter = 0;
631  while ((update(beta, tks, y, rho0) > 1.e-6) && (niter++ < maxIterations_)) {
632  }
633  }
634  beta /= coolingFactor_;
635  niter = 0;
636  while ((update(beta, tks, y, rho0) > 1.e-6) && (niter++ < maxIterations_)) {
637  }
638  }
639 
640  // // new, one last round of cleaning at T=Tstop
641  // while(purge(y,tks,rho0, beta)){
642  // niter=0; while((update(beta, tks,y,rho0) > 1.e-6) && (niter++ < maxIterations_)){ }
643  // }
644 
645  if (verbose_) {
646  cout << "Final result, rho0=" << rho0 << endl;
647  dump(beta, y, tks, 2);
648  }
649 
650  // select significant tracks and use a TransientVertex as a container
651  GlobalError dummyError;
652 
653  // ensure correct normalization of probabilities, should make double assginment reasonably impossible
654  for (unsigned int i = 0; i < nt; i++) {
655  tks[i].Z = rho0 * exp(-beta * dzCutOff_ * dzCutOff_);
656  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
657  tks[i].Z += k->pk * exp(-beta * Eik(tks[i], *k));
658  }
659  }
660 
661  for (vector<vertex_t>::iterator k = y.begin(); k != y.end(); k++) {
662  GlobalPoint pos(0, 0, k->z);
663  vector<reco::TransientTrack> vertexTracks;
664  for (unsigned int i = 0; i < nt; i++) {
665  if (tks[i].Z > 0) {
666  double p = k->pk * exp(-beta * Eik(tks[i], *k)) / tks[i].Z;
667  if ((tks[i].pi > 0) && (p > 0.5)) {
668  vertexTracks.push_back(*(tks[i].tt));
669  tks[i].Z = 0;
670  } // setting Z=0 excludes double assignment
671  }
672  }
673  TransientVertex v(pos, dummyError, vertexTracks, 5);
674  clusters.push_back(v);
675  }
676 
677  return clusters;
678 }
bool split(double beta, 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
const Double_t pi
Definition: TTTypes.h:54
void splitAll(std::vector< vertex_t > &y) const
std::vector< track_t > fill(const std::vector< reco::TransientTrack > &tracks) const
bool purge(std::vector< vertex_t > &, std::vector< track_t > &, double &, const double) const
double beta0(const double betamax, std::vector< track_t > &tks, std::vector< vertex_t > &y) const
int nt
Definition: AMPTWrapper.h:42
bool merge(std::vector< vertex_t > &, int) const
void dump(const double beta, const std::vector< vertex_t > &y, const std::vector< track_t > &tks, const int verbosity=0) const
double Eik(const track_t &t, const vertex_t &k) const

Member Data Documentation

◆ betamax_

float DAClusterizerInZ::betamax_
private

Definition at line 76 of file DAClusterizerInZ.h.

◆ betastop_

float DAClusterizerInZ::betastop_
private

Definition at line 77 of file DAClusterizerInZ.h.

◆ coolingFactor_

double DAClusterizerInZ::coolingFactor_
private

Definition at line 75 of file DAClusterizerInZ.h.

◆ d0CutOff_

double DAClusterizerInZ::d0CutOff_
private

Definition at line 79 of file DAClusterizerInZ.h.

◆ dzCutOff_

double DAClusterizerInZ::dzCutOff_
private

Definition at line 78 of file DAClusterizerInZ.h.

◆ maxIterations_

int DAClusterizerInZ::maxIterations_
private

Definition at line 74 of file DAClusterizerInZ.h.

◆ useTc_

bool DAClusterizerInZ::useTc_
private

Definition at line 72 of file DAClusterizerInZ.h.

◆ verbose_

bool DAClusterizerInZ::verbose_
private

Definition at line 71 of file DAClusterizerInZ.h.

◆ vertexSize_

float DAClusterizerInZ::vertexSize_
private

Definition at line 73 of file DAClusterizerInZ.h.