CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
hgcalsimclustertime::ComputeClusterTime Class Reference

#include <ComputeClusterTime.h>

Public Member Functions

 ComputeClusterTime (float Xmix, float Xmax, float Cterm, float Aterm)
 
 ComputeClusterTime ()
 
std::pair< float, float > fixSizeHighestDensity (std::vector< float > &time, std::vector< float > weight=std::vector< float >(), unsigned int minNhits=3, float deltaT=0.210, float timeWidthBy=0.5)
 
float getTimeError (std::string type, float xVal)
 
void setParameters (float Xmix, float Xmax, float Cterm, float Aterm)
 
float timeResolution (float xVal)
 

Private Attributes

float aTerm_
 
float cTerm_
 
float xMax_
 
float xMin_
 

Detailed Description

Definition at line 23 of file ComputeClusterTime.h.

Constructor & Destructor Documentation

◆ ComputeClusterTime() [1/2]

ComputeClusterTime::ComputeClusterTime ( float  Xmix,
float  Xmax,
float  Cterm,
float  Aterm 
)

◆ ComputeClusterTime() [2/2]

ComputeClusterTime::ComputeClusterTime ( )

Member Function Documentation

◆ fixSizeHighestDensity()

std::pair< float, float > ComputeClusterTime::fixSizeHighestDensity ( std::vector< float > &  time,
std::vector< float >  weight = std::vector<float>(),
unsigned int  minNhits = 3,
float  deltaT = 0.210,
float  timeWidthBy = 0.5 
)

Definition at line 66 of file ComputeClusterTime.cc.

References funct::abs(), HltBtagPostValidation_cff::c, decrease_sorted_indices(), HLT_2024v11_cff::distance, mps_fire::i, EgammaValidation_cff::num, mathSSE::sqrt(), command_line::start, submitPVValidationJobs::t, hcalRecHitTable_cff::time, tolerance, cms::cuda::totSize, and w().

Referenced by ticl::assignPCAtoTracksters(), RealisticSimClusterMapper::buildClusters(), and HGCalLayerClusterProducer::calculateTime().

67  {
68  if (time.size() < minNhits)
69  return std::pair<float, float>(-99., -1.);
70 
71  if (weight.empty())
72  weight.resize(time.size(), 1.);
73 
74  std::vector<float> t(time.size(), 0.);
75  std::vector<float> w(time.size(), 0.);
76  std::vector<size_t> sortedIndex = decrease_sorted_indices(time);
77  for (std::size_t i = 0; i < sortedIndex.size(); ++i) {
78  t[i] = time[sortedIndex[i]];
79  w[i] = weight[sortedIndex[i]];
80  }
81 
82  int max_elements = 0;
83  int start_el = 0;
84  int end_el = 0;
85  float timeW = 0.f;
86  float tolerance = 0.05f;
87 
88  for (auto start = t.begin(); start != t.end(); ++start) {
89  const auto startRef = *start;
90  int c = count_if(start, t.end(), [&](float el) { return el - startRef <= deltaT + tolerance; });
91  if (c > max_elements) {
92  max_elements = c;
93  auto last_el = find_if_not(start, t.end(), [&](float el) { return el - startRef <= deltaT + tolerance; });
94  auto valTostartDiff = *(--last_el) - startRef;
95  if (std::abs(deltaT - valTostartDiff) < tolerance) {
96  tolerance = std::abs(deltaT - valTostartDiff);
97  }
98  start_el = distance(t.begin(), start);
99  end_el = distance(t.begin(), last_el);
100  timeW = valTostartDiff;
101  }
102  }
103 
104  // further adjust time width around the chosen one based on the hits density
105  // proved to improve the resolution: get as many hits as possible provided they are close in time
106  float HalfTimeDiff = timeW * timeWidthBy;
107  float sum = 0.;
108  float num = 0;
109  int totSize = t.size();
110 
111  for (int ij = 0; ij <= start_el; ++ij) {
112  if (t[ij] > (t[start_el] - HalfTimeDiff)) {
113  for (int kl = ij; kl < totSize; ++kl) {
114  if (t[kl] < (t[end_el] + HalfTimeDiff)) {
115  sum += t[kl] * w[kl];
116  num += w[kl];
117  } else
118  break;
119  }
120  break;
121  }
122  }
123 
124  if (num == 0) {
125  return std::pair<float, float>(-99., -1.);
126  }
127  return std::pair<float, float>(sum / num, 1. / sqrt(num));
128 }
Definition: start.py:1
T w() const
const double tolerance
Definition: weight.py:1
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< size_t > decrease_sorted_indices(const std::vector< float > &v)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t totSize

◆ getTimeError()

float ComputeClusterTime::getTimeError ( std::string  type,
float  xVal 
)

Definition at line 46 of file ComputeClusterTime.cc.

References cTerm_, timeResolution(), xMax_, and xMin_.

Referenced by HGCalRecHitWorkerSimple::run().

46  {
47  if (type == "recHit") {
48  //xVal is S/N
49  //time is in ns units
50  //std::cout << type << ", " << xVal << ", " << xMax_ << ", " < xMin_ << ", " << timeResolution(xMin_) << ", " << timeResolution(xVal) << std::endl;
51 
52  if (xVal < xMin_)
53  return timeResolution(xMin_);
54  else if (xVal > xMax_)
55  return cTerm_;
56  else
57  return timeResolution(xVal);
58 
59  return -1;
60  }
61  return -1;
62 }

◆ setParameters()

void ComputeClusterTime::setParameters ( float  Xmix,
float  Xmax,
float  Cterm,
float  Aterm 
)

◆ timeResolution()

float ComputeClusterTime::timeResolution ( float  xVal)

Definition at line 41 of file ComputeClusterTime.cc.

References aTerm_, cTerm_, funct::pow(), mathSSE::sqrt(), and x.

Referenced by getTimeError().

41  {
42  float funcVal = pow(aTerm_ / x, 2) + pow(cTerm_, 2);
43  return sqrt(funcVal);
44 }
T sqrt(T t)
Definition: SSEVec.h:19
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

Member Data Documentation

◆ aTerm_

float hgcalsimclustertime::ComputeClusterTime::aTerm_
private

Definition at line 49 of file ComputeClusterTime.h.

Referenced by setParameters(), and timeResolution().

◆ cTerm_

float hgcalsimclustertime::ComputeClusterTime::cTerm_
private

Definition at line 48 of file ComputeClusterTime.h.

Referenced by getTimeError(), setParameters(), and timeResolution().

◆ xMax_

float hgcalsimclustertime::ComputeClusterTime::xMax_
private

Definition at line 47 of file ComputeClusterTime.h.

Referenced by getTimeError(), and setParameters().

◆ xMin_

float hgcalsimclustertime::ComputeClusterTime::xMin_
private

Definition at line 46 of file ComputeClusterTime.h.

Referenced by ComputeClusterTime(), getTimeError(), and setParameters().