CMS 3D CMS Logo

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