CMS 3D CMS Logo

Functions
hgcalsimclustertime Namespace Reference

Functions

float fixSizeHighestDensity (std::vector< float > &t, float deltaT=0.210, float timeWidthBy=0.5)
 

Function Documentation

float hgcalsimclustertime::fixSizeHighestDensity ( std::vector< float > &  t,
float  deltaT = 0.210,
float  timeWidthBy = 0.5 
)

Definition at line 21 of file ComputeClusterTime.h.

References funct::abs(), HltBtagPostValidation_cff::c, HLT_2018_cff::distance, EgammaValidation_cff::num, command_line::start, tolerance, and heppy_batch::val.

Referenced by RealisticSimClusterMapper::buildClusters(), and HGCalLayerClusterProducer::produce().

23  {
24  float tolerance = 0.05f;
25  std::sort(t.begin(), t.end());
26 
27  int max_elements = 0;
28  int start_el = 0;
29  int end_el = 0;
30  float timeW = 0.f;
31 
32  for (auto start = t.begin(); start != t.end(); ++start) {
33  const auto startRef = *start;
34  int c = count_if(start, t.end(), [&](float el) { return el - startRef <= deltaT + tolerance; });
35  if (c > max_elements) {
36  max_elements = c;
37  auto last_el = find_if_not(start, t.end(), [&](float el) { return el - startRef <= deltaT + tolerance; });
38  auto val = *(--last_el);
39  if (std::abs(deltaT - (val - startRef)) < tolerance) {
40  tolerance = std::abs(deltaT - (val - startRef));
41  }
42  start_el = distance(t.begin(), start);
43  end_el = distance(t.begin(), last_el);
44  timeW = val - startRef;
45  }
46  }
47 
48  // further adjust time width around the chosen one based on the hits density
49  // proved to improve the resolution: get as many hits as possible provided they are close in time
50 
51  float HalfTimeDiff = timeW * timeWidthBy;
52  float sum = 0.;
53  int num = 0;
54  int totSize = t.size();
55 
56  for (int ij = 0; ij <= start_el; ++ij) {
57  if (t[ij] > (t[start_el] - HalfTimeDiff)) {
58  for (int kl = ij; kl < totSize; ++kl) {
59  if (t[kl] < (t[end_el] + HalfTimeDiff)) {
60  sum += t[kl];
61  ++num;
62  } else
63  break;
64  }
65  break;
66  }
67  }
68 
69  if (num == 0)
70  return -99.;
71  return sum / num;
72  }
Definition: start.py:1
const double tolerance
Abs< T >::type abs(const T &t)
Definition: Abs.h:22