Go to the documentation of this file.00001 #include "CalibFormats/CaloObjects/interface/CaloSamples.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <math.h>
00004 #include <iostream>
00005
00006 CaloSamples::CaloSamples() : id_(), size_(0), presamples_(0), preciseSize_(0), precisePresamples_(0) { setBlank() ; }
00007
00008 CaloSamples::CaloSamples(const DetId& id, int size) :
00009 id_ ( id ) ,
00010 size_ ( size ) ,
00011 presamples_ ( 0 ) ,
00012 deltaTprecise_ (0.0f) ,
00013 preciseSize_(0),
00014 precisePresamples_(0) { setBlank() ; }
00015
00016 CaloSamples::CaloSamples(const DetId& id, int size, int presize) :
00017 id_ ( id ) ,
00018 size_ ( size ) ,
00019 presamples_ ( 0 ) ,
00020 deltaTprecise_ (0.0f) ,
00021 preciseSize_(presize),
00022 precisePresamples_(0) { setBlank() ; }
00023
00024
00025 void CaloSamples::resetPrecise() {
00026 preciseData_.resize(preciseSize_,0);
00027 }
00028
00029 void CaloSamples::setPresamples( int pre ) {
00030 presamples_ = pre ;
00031 }
00032
00033 CaloSamples& CaloSamples::scale( double value ) {
00034 for (int i=0; i<MAXSAMPLES; i++) data_[i]*=value;
00035 for (std::vector<float>::iterator j=preciseData_.begin() ; j!=preciseData_.end(); j++)
00036 (*j)*=value;
00037 return (*this);
00038 }
00039
00040 CaloSamples& CaloSamples::operator+=(double value) {
00041 for (int i=0; i<MAXSAMPLES; i++) data_[i]+=value;
00042 for (std::vector<float>::iterator j=preciseData_.begin() ; j!=preciseData_.end(); j++)
00043 (*j)+=value*deltaTprecise_/25.0;
00044 return (*this);
00045 }
00046
00047 CaloSamples& CaloSamples::operator+=(const CaloSamples & other) {
00048 if(size_ != other.size_ ||
00049 presamples_ != other.presamples_ ||
00050 preciseSize_ != other.preciseSize_) {
00051 edm::LogError("CaloHitResponse") << "Mismatched calo signals ";
00052 }
00053 int i;
00054 for(i = 0; i < size_; ++i) {
00055 data_[i] += other.data_[i];
00056 }
00057 if ( preciseData_.size() == 0 && other.preciseData_.size() > 0 ) resetPrecise();
00058 if ( other.preciseData_.size() > 0 ) {
00059 for(i = 0; i < preciseSize_; ++i) {
00060 preciseData_[i] += other.preciseData_[i];
00061 }
00062 }
00063 return *this;
00064 }
00065
00066 CaloSamples &
00067 CaloSamples::offsetTime(double offset)
00068 {
00069 double data[MAXSAMPLES];
00070 for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
00071 {
00072 double t = i*25. - offset;
00073 int firstbin = floor(t/25.);
00074 double f = t/25. - firstbin;
00075 int nextbin = firstbin + 1;
00076 double v1 = (firstbin < 0 || firstbin >= MAXSAMPLES) ? 0. : data_[firstbin];
00077 double v2 = (nextbin < 0 || nextbin >= MAXSAMPLES) ? 0. : data_[nextbin];
00078 data[i] = (v1*(1.-f)+v2*f);
00079 }
00080 for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
00081 {
00082 data_[i] = data[i];
00083 }
00084 return (*this);
00085 }
00086
00087 bool
00088 CaloSamples::isBlank() const
00089 {
00090 for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
00091 {
00092 if( 1.e-6 < fabs( data_[i] ) ) return false ;
00093 }
00094 return true ;
00095 }
00096
00097 void
00098 CaloSamples::setBlank()
00099 {
00100 std::fill( data_ , data_ + MAXSAMPLES, (double)0.0 ) ;
00101 std::fill( preciseData_.begin() , preciseData_.end(), (double)0.0 ) ;
00102 }
00103
00104 std::ostream& operator<<(std::ostream& s, const CaloSamples& samples) {
00105 s << "DetId=" << samples.id().rawId();
00106 s << ", "<< samples.size() << "samples" << std::endl;
00107
00108 float preciseStep = samples.preciseSize()/samples.size();
00109 for (int i=0; i<samples.size(); i++) {
00110 s << i << ":" << samples[i];
00111 int precisei = i*preciseStep;
00112 if(precisei < samples.preciseSize()) {
00113 s << " " << samples.preciseAt(precisei) ;
00114 }
00115 s << std::endl;
00116 }
00117 return s;
00118 }