CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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),
15  precisePresamples_(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),
26  precisePresamples_(0) {
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  bool addHighFidelityPreMix = false;
53  if (size_ != other.size_ || presamples_ != other.presamples_ || preciseSize_ != other.preciseSize_) {
54  if (presamples_ == other.presamples_ && preciseSize_ == other.size_) {
55  addHighFidelityPreMix = true;
56  } else {
57  edm::LogError("CaloHitResponse") << "Mismatched calo signals ";
58  }
59  }
60  if (addHighFidelityPreMix) {
61  int sampleBin(0);
62  for (int i = 0; i < preciseSize_; ++i) {
63  sampleBin = floor(i * deltaTprecise_ / 25);
64  data_[sampleBin] += other.data_[i];
65  preciseData_[i] += other.data_[i];
66  }
67  } else {
68  int i;
69  for (i = 0; i < size_; ++i) {
70  data_[i] += other.data_[i];
71  }
72  if (preciseData_.empty() && !other.preciseData_.empty())
73  resetPrecise();
74  if (!other.preciseData_.empty()) {
75  for (i = 0; i < preciseSize_; ++i) {
76  preciseData_[i] += other.preciseData_[i];
77  }
78  }
79  }
80  return *this;
81 }
82 
84  std::vector<double> data(size_, 0.0);
85  for (int i(0); i != size_; ++i) {
86  double t = i * 25. - offset;
87  int firstbin = floor(t / 25.);
88  double f = t / 25. - firstbin;
89  int nextbin = firstbin + 1;
90  double v1 = (firstbin < 0 || firstbin >= size_) ? 0. : data_[firstbin];
91  double v2 = (nextbin < 0 || nextbin >= size_) ? 0. : data_[nextbin];
92  data[i] = (v1 * (1. - f) + v2 * f);
93  }
94  for (int i(0); i != size_; ++i) {
95  data_[i] = data[i];
96  }
97  return (*this);
98 }
99 
100 bool CaloSamples::isBlank() const // are the samples blank (zero?)
101 {
102  for (int i(0); i != size_; ++i) {
103  if (1.e-6 < fabs(data_[i]))
104  return false;
105  }
106  return true;
107 }
108 
109 void CaloSamples::setBlank() // keep id, presamples, size but zero out data
110 {
111  std::fill(data_.begin(), data_.end(), (double)0.0);
112  std::fill(preciseData_.begin(), preciseData_.end(), (double)0.0);
113 }
114 
115 std::ostream &operator<<(std::ostream &s, const CaloSamples &samples) {
116  s << "DetId " << samples.id();
117  // print out every so many precise samples
118  float preciseStep = samples.preciseSize() / samples.size();
119  s << ", " << samples.size() << " samples";
120  if (preciseStep > 0)
121  s << ", " << samples.preciseSize() << " preciseSamples"
122  << ", " << preciseStep << " preciseStep";
123  s << '\n';
124  for (int i = 0; i < samples.size(); i++) {
125  s << i << ":" << samples[i] << " precise:";
126  int precise_start(i * preciseStep), precise_end(precise_start + preciseStep);
127  for (int j(precise_start); ((j < precise_end) && (j < samples.preciseSize())); ++j)
128  s << " " << samples.preciseAt(j);
129  s << std::endl;
130  }
131  return s;
132 }
CaloSamples & scale(double value)
multiply each item by this value
Definition: CaloSamples.cc:35
void resetPrecise()
Definition: CaloSamples.cc:31
Log< level::Error, false > LogError
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
int preciseSize() const
get the size
Definition: CaloSamples.h:70
std::vector< float > preciseData_
Definition: CaloSamples.h:93
bool isBlank() const
Definition: CaloSamples.cc:100
void setBlank()
Definition: CaloSamples.cc:109
void setPresamples(int pre)
set presample information
Definition: CaloSamples.cc:33
std::vector< double > data_
Definition: CaloSamples.h:91
Definition: DetId.h:17
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
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:83
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
tuple size
Write out results.
int preciseSize_
Definition: CaloSamples.h:94