CMS 3D CMS Logo

ComputeClusterTime.cc
Go to the documentation of this file.
2 
3 // functions to select the hits to compute the time of a given cluster
4 // start with the only hits with timing information
5 // average among the hits contained in the chosen time interval
6 
7 // N.B. time is corrected wrt vtx-calorimeter distance
8 // with straight line and light speed hypothesis
9 // for charged tracks or heavy particles (longer track length or beta < 1)
10 // need to correct the offset at analysis level
11 
12 using namespace hgcalsimclustertime;
13 
14 std::vector<size_t> decrease_sorted_indices(const std::vector<float>& v) {
15  // initialize original index locations
16  std::vector<size_t> idx(v.size());
17  std::iota(idx.begin(), idx.end(), 0);
18 
19  // sort indices based on comparing values in v (decreasing order)
20  std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1] < v[i2]; });
21  return idx;
22 };
23 
24 ComputeClusterTime::ComputeClusterTime(float Xmin, float Xmax, float Cterm, float Aterm)
25  : xMin_(Xmin), xMax_(Xmax), cTerm_(Cterm), aTerm_(Aterm) {
26  if (xMin_ <= 0)
27  xMin_ = 0.1;
28 };
29 
30 ComputeClusterTime::ComputeClusterTime() : xMin_(1.), xMax_(5.), cTerm_(0), aTerm_(0){};
31 
32 void ComputeClusterTime::setParameters(float Xmin, float Xmax, float Cterm, float Aterm) {
33  xMin_ = (Xmin > 0) ? Xmin : 0.1;
34  xMax_ = Xmax;
35  cTerm_ = Cterm;
36  aTerm_ = Aterm;
37  return;
38 }
39 
40 //time resolution parametrization
42  float funcVal = pow(aTerm_ / x, 2) + pow(cTerm_, 2);
43  return sqrt(funcVal);
44 }
45 
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 }
63 
64 //time-interval based on that ~210ps wide and with the highest number of hits
65 //extension valid in high PU of taking smallest interval with (order of)68% of hits
67  std::vector<float>& time, std::vector<float> weight, unsigned int minNhits, float deltaT, float timeWidthBy) {
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 }
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
mps_fire.i
i
Definition: mps_fire.py:428
hgcalsimclustertime
Definition: ComputeClusterTime.h:21
start
Definition: start.py:1
cms::cuda::totSize
cudaStream_t T uint32_t const T *__restrict__ const uint32_t *__restrict__ uint32_t totSize
Definition: HistoContainer.h:92
hgcalsimclustertime::ComputeClusterTime::xMin_
float xMin_
Definition: ComputeClusterTime.h:46
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
protons_cff.time
time
Definition: protons_cff.py:39
findQualityFiles.v
v
Definition: findQualityFiles.py:179
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
hgcalsimclustertime::ComputeClusterTime::fixSizeHighestDensity
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)
Definition: ComputeClusterTime.cc:66
hgcalsimclustertime::ComputeClusterTime::timeResolution
float timeResolution(float xVal)
Definition: ComputeClusterTime.cc:41
hgcalsimclustertime::ComputeClusterTime::aTerm_
float aTerm_
Definition: ComputeClusterTime.h:49
w
const double w
Definition: UKUtility.cc:23
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ComputeClusterTime.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
tolerance
const double tolerance
Definition: HGCalGeomParameters.cc:29
PixelVTXMonitor_cfi.Xmax
Xmax
Definition: PixelVTXMonitor_cfi.py:8
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
hgcalsimclustertime::ComputeClusterTime::ComputeClusterTime
ComputeClusterTime()
Definition: ComputeClusterTime.cc:30
hgcalsimclustertime::ComputeClusterTime::cTerm_
float cTerm_
Definition: ComputeClusterTime.h:48
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
decrease_sorted_indices
std::vector< size_t > decrease_sorted_indices(const std::vector< float > &v)
Definition: ComputeClusterTime.cc:14
hgcalsimclustertime::ComputeClusterTime::xMax_
float xMax_
Definition: ComputeClusterTime.h:47
hgcalsimclustertime::ComputeClusterTime::getTimeError
float getTimeError(std::string type, float xVal)
Definition: ComputeClusterTime.cc:46
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
command_line.start
start
Definition: command_line.py:167
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
hgcalsimclustertime::ComputeClusterTime::setParameters
void setParameters(float Xmix, float Xmax, float Cterm, float Aterm)
Definition: ComputeClusterTime.cc:32
PixelVTXMonitor_cfi.Xmin
Xmin
Definition: PixelVTXMonitor_cfi.py:8
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
weight
Definition: weight.py:1