CMS 3D CMS Logo

CaloSamples.cc
Go to the documentation of this file.
3 #include <cmath>
4 #include <iostream>
5 
6 CaloSamples::CaloSamples() : id_(), size_(0), presamples_(0), preciseSize_(0), precisePresamples_(0) { setBlank(); }
7 
9  : id_(id),
10  size_(size),
11  presamples_(0),
12  data_(size_, 0.0),
13  deltaTprecise_(0.0f),
14  preciseSize_(0),
16  setBlank();
17 }
18 
19 CaloSamples::CaloSamples(const DetId &id, int size, int presize)
20  : id_(id),
21  size_(size),
22  presamples_(0),
23  data_(size_, 0.0),
24  deltaTprecise_(0.0f),
25  preciseSize_(presize),
27  setBlank();
28 }
29 
30 // add option to set these later.
32 
33 void CaloSamples::setPresamples(int pre) { presamples_ = pre; }
34 
36  for (int i = 0; i < size_; i++)
37  data_[i] *= value;
38  for (std::vector<float>::iterator j = preciseData_.begin(); j != preciseData_.end(); ++j)
39  (*j) *= value;
40  return (*this);
41 }
42 
44  for (int i = 0; i < size_; i++)
45  data_[i] += value;
46  for (std::vector<float>::iterator j = preciseData_.begin(); j != preciseData_.end(); ++j)
47  (*j) += value * deltaTprecise_ / 25.0; // note that the scale is conserved!
48  return (*this);
49 }
50 
52  if (size_ != other.size_ || presamples_ != other.presamples_ || preciseSize_ != other.preciseSize_) {
53  edm::LogError("CaloHitResponse") << "Mismatched calo signals ";
54  }
55  int i;
56  for (i = 0; i < size_; ++i) {
57  data_[i] += other.data_[i];
58  }
59  if (preciseData_.empty() && !other.preciseData_.empty())
60  resetPrecise();
61  if (!other.preciseData_.empty()) {
62  for (i = 0; i < preciseSize_; ++i) {
63  preciseData_[i] += other.preciseData_[i];
64  }
65  }
66  return *this;
67 }
68 
70  std::vector<double> data(size_, 0.0);
71  for (int i(0); i != size_; ++i) {
72  double t = i * 25. - offset;
73  int firstbin = floor(t / 25.);
74  double f = t / 25. - firstbin;
75  int nextbin = firstbin + 1;
76  double v1 = (firstbin < 0 || firstbin >= size_) ? 0. : data_[firstbin];
77  double v2 = (nextbin < 0 || nextbin >= size_) ? 0. : data_[nextbin];
78  data[i] = (v1 * (1. - f) + v2 * f);
79  }
80  for (int i(0); i != size_; ++i) {
81  data_[i] = data[i];
82  }
83  return (*this);
84 }
85 
86 bool CaloSamples::isBlank() const // are the samples blank (zero?)
87 {
88  for (int i(0); i != size_; ++i) {
89  if (1.e-6 < fabs(data_[i]))
90  return false;
91  }
92  return true;
93 }
94 
95 void CaloSamples::setBlank() // keep id, presamples, size but zero out data
96 {
97  std::fill(data_.begin(), data_.end(), (double)0.0);
98  std::fill(preciseData_.begin(), preciseData_.end(), (double)0.0);
99 }
100 
101 std::ostream &operator<<(std::ostream &s, const CaloSamples &samples) {
102  s << "DetId " << samples.id();
103  // print out every so many precise samples
104  float preciseStep = samples.preciseSize() / samples.size();
105  s << ", " << samples.size() << " samples";
106  if (preciseStep > 0)
107  s << ", " << samples.preciseSize() << " preciseSamples"
108  << ", " << preciseStep << " preciseStep";
109  s << '\n';
110  for (int i = 0; i < samples.size(); i++) {
111  s << i << ":" << samples[i] << " precise:";
112  int precise_start(i * preciseStep), precise_end(precise_start + preciseStep);
113  for (int j(precise_start); ((j < precise_end) && (j < samples.preciseSize())); ++j)
114  s << " " << samples.preciseAt(j);
115  s << std::endl;
116  }
117  return s;
118 }
CaloSamples & scale(double value)
multiply each item by this value
Definition: CaloSamples.cc:35
int precisePresamples_
Definition: CaloSamples.h:94
void resetPrecise()
Definition: CaloSamples.cc:31
int preciseSize() const
get the size
Definition: CaloSamples.h:70
std::vector< float > preciseData_
Definition: CaloSamples.h:93
bool isBlank() const
Definition: CaloSamples.cc:86
void setBlank()
Definition: CaloSamples.cc:95
std::ostream & operator<<(std::ostream &s, const CaloSamples &samples)
Definition: CaloSamples.cc:101
double f[11][100]
Definition: value.py:1
void setPresamples(int pre)
set presample information
Definition: CaloSamples.cc:33
std::vector< double > data_
Definition: CaloSamples.h:91
Definition: DetId.h:17
int size() const
get the size
Definition: CaloSamples.h:24
CaloSamples & offsetTime(double offset)
shift all the samples by a time, in ns, interpolating
Definition: CaloSamples.cc:69
float deltaTprecise_
Definition: CaloSamples.h:92
int presamples_
Definition: CaloSamples.h:90
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
CaloSamples & operator+=(double value)
add a value to all samples
Definition: CaloSamples.cc:43
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
int preciseSize_
Definition: CaloSamples.h:94