CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  deltaTprecise_ (0.0f) ,
13  preciseSize_(0),
14  precisePresamples_(0) { setBlank() ; }
15 
16 CaloSamples::CaloSamples(const DetId& id, int size, int presize) :
17  id_ ( id ) ,
18  size_ ( size ) ,
19  presamples_ ( 0 ) ,
20  deltaTprecise_ (0.0f) ,
21  preciseSize_(presize),
22  precisePresamples_(0) { setBlank() ; }
23 
24 // add option to set these later.
26  preciseData_.resize(preciseSize_,0);
27 }
28 
29 void CaloSamples::setPresamples( int pre ) {
30  presamples_ = pre ;
31 }
32 
34  for (int i=0; i<MAXSAMPLES; i++) data_[i]*=value;
35  for (std::vector<float>::iterator j=preciseData_.begin() ; j!=preciseData_.end(); j++)
36  (*j)*=value;
37  return (*this);
38 }
39 
41  for (int i=0; i<MAXSAMPLES; i++) data_[i]+=value;
42  for (std::vector<float>::iterator j=preciseData_.begin() ; j!=preciseData_.end(); j++)
43  (*j)+=value*deltaTprecise_/25.0; // note that the scale is conserved!
44  return (*this);
45 }
46 
48  if(size_ != other.size_ ||
49  presamples_ != other.presamples_ ||
50  preciseSize_ != other.preciseSize_) {
51  edm::LogError("CaloHitResponse") << "Mismatched calo signals ";
52  }
53  int i;
54  for(i = 0; i < size_; ++i) {
55  data_[i] += other.data_[i];
56  }
57  if ( preciseData_.size() == 0 && other.preciseData_.size() > 0 ) resetPrecise();
58  if ( other.preciseData_.size() > 0 ) {
59  for(i = 0; i < preciseSize_; ++i) {
60  preciseData_[i] += other.preciseData_[i];
61  }
62  }
63  return *this;
64 }
65 
68 {
69  double data[MAXSAMPLES];
70  for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
71  {
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 >= MAXSAMPLES) ? 0. : data_[firstbin];
77  double v2 = (nextbin < 0 || nextbin >= MAXSAMPLES) ? 0. : data_[nextbin];
78  data[i] = (v1*(1.-f)+v2*f);
79  }
80  for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
81  {
82  data_[i] = data[i];
83  }
84  return (*this);
85 }
86 
87 bool
88 CaloSamples::isBlank() const // are the samples blank (zero?)
89 {
90  for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
91  {
92  if( 1.e-6 < fabs( data_[i] ) ) return false ;
93  }
94  return true ;
95 }
96 
97 void
98 CaloSamples::setBlank() // keep id, presamples, size but zero out data
99 {
100  std::fill( data_ , data_ + MAXSAMPLES, (double)0.0 ) ;
101  std::fill( preciseData_.begin() , preciseData_.end(), (double)0.0 ) ;
102 }
103 
104 std::ostream& operator<<(std::ostream& s, const CaloSamples& samples) {
105  s << "DetId=" << samples.id();
106  // print out every so many precise samples
107  float preciseStep = samples.preciseSize()/samples.size();
108  s << ", "<< samples.size() << " samples";
109  if (preciseStep > 0)
110  s << ", " << samples.preciseSize() << " preciseSamples"
111  << ", " << preciseStep << " precise step";
112  s << '\n';
113  for (int i=0; i<samples.size(); i++) {
114  s << i << ":" << samples[i];
115  int precisei = i*preciseStep;
116  if(precisei < samples.preciseSize()) {
117  s << " " << samples.preciseAt(precisei) ;
118  }
119  s << std::endl;
120  }
121  return s;
122 }
int i
Definition: DBlmapReader.cc:9
string fill
Definition: lumiContext.py:319
CaloSamples & scale(double value)
multiply each item by this value
Definition: CaloSamples.cc:33
static const int MAXSAMPLES
Definition: CaloSamples.h:75
void resetPrecise()
Definition: CaloSamples.cc:25
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
int preciseSize() const
get the size
Definition: CaloSamples.h:64
std::vector< float > preciseData_
Definition: CaloSamples.h:81
bool isBlank() const
Definition: CaloSamples.cc:88
int j
Definition: DBlmapReader.cc:9
void setBlank()
Definition: CaloSamples.cc:98
double f[11][100]
void setPresamples(int pre)
set presample information
Definition: CaloSamples.cc:29
unsigned int offset(bool)
Definition: DetId.h:20
int size() const
get the size
Definition: CaloSamples.h:26
CaloSamples & offsetTime(double offset)
shift all the samples by a time, in ns, interpolating
Definition: CaloSamples.cc:67
string const
Definition: compareJSON.py:14
float deltaTprecise_
Definition: CaloSamples.h:80
int presamples_
Definition: CaloSamples.h:79
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
size_(0)
Definition: OwnArray.h:181
CaloSamples & operator+=(double value)
add a value to all samples
Definition: CaloSamples.cc:40
DetId id() const
get the (generic) id
Definition: CaloSamples.h:23
double data_[MAXSAMPLES]
Definition: CaloSamples.h:78
tuple size
Write out results.
int preciseSize_
Definition: CaloSamples.h:82