CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CalibFormats/CaloObjects/src/CaloSamples.cc

Go to the documentation of this file.
00001 #include "CalibFormats/CaloObjects/interface/CaloSamples.h"
00002 #include <math.h>
00003 
00004 CaloSamples::CaloSamples() : id_(), size_(0), presamples_(0) { setBlank() ; }
00005 
00006 CaloSamples::CaloSamples(const DetId& id, int size) :
00007    id_          ( id   ) , 
00008    size_        ( size ) , 
00009    presamples_  ( 0    ) 
00010 {
00011    setBlank() ;
00012 }
00013 
00014 void
00015 CaloSamples::setPresamples( int pre ) 
00016 {
00017    presamples_ = pre ;
00018 }
00019 
00020 CaloSamples& 
00021 CaloSamples::scale( double value )
00022 {
00023    for (int i=0; i<MAXSAMPLES; i++) data_[i]*=value;
00024    return (*this);
00025 }
00026 
00027 CaloSamples& 
00028 CaloSamples::operator+=(double value) 
00029 {  
00030    for (int i=0; i<MAXSAMPLES; i++) data_[i]+=value;
00031    return (*this);
00032 }
00033 
00034 CaloSamples &
00035 CaloSamples::offsetTime(double offset)
00036 {
00037   double data[MAXSAMPLES];
00038   for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
00039   {
00040     double t = i*25. - offset;
00041     int firstbin = floor(t/25.);
00042     double f = t/25. - firstbin;
00043     int nextbin = firstbin + 1;
00044     double v1 = (firstbin < 0 || firstbin >= MAXSAMPLES) ? 0. : data_[firstbin];
00045     double v2 = (nextbin < 0  || nextbin  >= MAXSAMPLES) ? 0. : data_[nextbin];
00046     data[i] = (v1*(1.-f)+v2*f);
00047   }
00048   for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
00049   {
00050     data_[i] = data[i];
00051   }
00052   return (*this);
00053 }
00054 
00055 bool 
00056 CaloSamples::isBlank() const // are the samples blank (zero?)
00057 {
00058    for( int i ( 0 ) ; i != MAXSAMPLES ; ++i )
00059    {
00060       if( 1.e-6 < fabs( data_[i] ) ) return false ;
00061    }
00062    return true ;
00063 }
00064 
00065 void 
00066 CaloSamples::setBlank() // keep id, presamples, size but zero out data
00067 {
00068    std::fill( data_ , data_ + MAXSAMPLES, (double)0.0 ) ;
00069 }
00070 
00071 std::ostream& operator<<(std::ostream& s, const CaloSamples& samples) {
00072   s << "DetId=" << samples.id().rawId();
00073   s << ", "<<  samples.size() << "samples" << std::endl;
00074   for (int i=0; i<samples.size(); i++)
00075     s << i << ":" << samples[i] << std::endl;
00076   return s;
00077 }