test
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 
7 
8 CaloSamples::CaloSamples() : id_(), size_(0), presamples_(0), preciseSize_(0), precisePresamples_(0) { setBlank() ; }
9 
11  id_ ( id ) ,
12  size_ ( size ) ,
13  presamples_ ( 0 ) ,
14  deltaTprecise_ (0.0f) ,
15  preciseSize_(0),
16  precisePresamples_(0) { setBlank() ; }
17 
18 CaloSamples::CaloSamples(const DetId& id, int size, int presize) :
19  id_ ( id ) ,
20  size_ ( size ) ,
21  presamples_ ( 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<MAXSAMPLES; 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<MAXSAMPLES; 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  double data[MAXSAMPLES];
72  for( int i ( 0 ) ; i != MAXSAMPLES ; ++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 >= MAXSAMPLES) ? 0. : data_[firstbin];
79  double v2 = (nextbin < 0 || nextbin >= MAXSAMPLES) ? 0. : data_[nextbin];
80  data[i] = (v1*(1.-f)+v2*f);
81  }
82  for( int i ( 0 ) ; i != MAXSAMPLES ; ++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 != MAXSAMPLES ; ++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_ , data_ + MAXSAMPLES, (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 }
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:35
static const int MAXSAMPLES
Definition: CaloSamples.h:73
void resetPrecise()
Definition: CaloSamples.cc:27
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
int preciseSize() const
get the size
Definition: CaloSamples.h:62
std::vector< float > preciseData_
Definition: CaloSamples.h:79
bool isBlank() const
Definition: CaloSamples.cc:90
int j
Definition: DBlmapReader.cc:9
void setBlank()
Definition: CaloSamples.cc:100
double f[11][100]
void setPresamples(int pre)
set presample information
Definition: CaloSamples.cc:31
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
string const
Definition: compareJSON.py:14
float deltaTprecise_
Definition: CaloSamples.h:78
int presamples_
Definition: CaloSamples.h:77
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:42
volatile std::atomic< bool > shutdown_flag false
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
double data_[MAXSAMPLES]
Definition: CaloSamples.h:76
tuple size
Write out results.
int preciseSize_
Definition: CaloSamples.h:80