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 24 of file ComputeClusterTime.h.

References funct::abs(), EnergyCorrector::c, SoftLeptonByDistance_cfi::distance, pileupDistInMC::num, command_line::start, tolerance, and heppy_batch::val.

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

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