emcHLRatioFEM.C

Go to the documentation of this file.
00001 #include "emcHLRatioFEM.h"
00002 #include "emcDefines.h"
00003 #include "emcCalFEMFactory.h"
00004 #include <iostream>
00005 
00006 float emcHLRatioFEM::fGlobalAverage = 15.4 ;
00007 float emcHLRatioFEM::fGlobalRMS = 1.7 ;
00008 
00009 using namespace std;
00010 
00011 namespace 
00012 {
00013   static string name = "emcHLRatioFEM";
00014   static string title = "H/L ratio calibration data";
00015   static string classname = "emcHLRatioFEM";
00016 
00017   emcCalFEM* creator(int absPosition,
00018                      const PHTimeStamp& start,
00019                      const PHTimeStamp& end,
00020                      bool isDefault)
00021   {
00022     if ( isDefault )
00023       {
00024         return emcHLRatioFEM::Default(absPosition,start,end);
00025       }
00026     else
00027       {
00028         return new emcHLRatioFEM(absPosition,start,end);
00029       }
00030   }
00031 
00032   static bool r = emcCalFEMFactory::registerCreator("HLRatios",
00033                                                     creator);
00034 }
00035 
00036 //_____________________________________________________________________________
00037 emcHLRatioFEM::emcHLRatioFEM(int absPosition)
00038   : emcCalFEM(absPosition)
00039 {
00040   NameIt(name,title,classname);
00041 }
00042 
00043 //_____________________________________________________________________________
00044 emcHLRatioFEM::emcHLRatioFEM(int absPosition, 
00045                              const PHTimeStamp& t1, const PHTimeStamp& t2)
00046   : emcCalFEM(absPosition,t1,t2)
00047 
00048 {
00049   NameIt(name,title,classname);
00050 }
00051 
00052 //_____________________________________________________________________________
00053 emcHLRatioFEM::emcHLRatioFEM(const emcHLRatioFEM& o)
00054   : emcCalFEM(o.AbsolutePosition())
00055 {
00056   o.Copy(*this) ;  
00057 }
00058 
00059 //_____________________________________________________________________________
00060 emcHLRatioFEM&
00061 emcHLRatioFEM::operator=(const emcHLRatioFEM& o)
00062 {
00063   if ( this == &o ) return *this ;
00064   Reset() ;
00065   o.Copy(*this) ;
00066   return *this ;
00067 }
00068 
00069 //_____________________________________________________________________________
00070 void
00071 emcHLRatioFEM::Copy(emcHLRatioFEM& o) const
00072 {
00073   emcCalFEM::Copy(o) ;
00074   o.fHLRatioVector.resize(fHLRatioVector.size()) ;
00075   size_t i ;
00076   for ( i = 0 ; i < fHLRatioVector.size() ; i++) {
00077     o.fHLRatioVector[i] = fHLRatioVector[i] ;
00078   }
00079 }
00080 
00081 //_____________________________________________________________________________
00082 emcHLRatioFEM::~emcHLRatioFEM()
00083 {
00084   Reset() ;
00085 }
00086 
00087 //_____________________________________________________________________________
00088 void emcHLRatioFEM::AppendOneChannel(float average, float rms, 
00089                                    float intercept, float slope)
00090 {
00091   Ratio tmp ;
00092   
00093   tmp.push_back(average) ;
00094   tmp.push_back(rms) ;
00095   tmp.push_back(intercept) ;
00096   tmp.push_back(slope) ;
00097   if (fHLRatioVector.size()<144) {
00098     fHLRatioVector.push_back(tmp) ;
00099   }
00100   else {
00101     cerr << "<E-EMCAL> emcHLRatioFEM::AppendOneChannel : fem is full" << endl ;
00102   }
00103 }
00104 
00105 //_____________________________________________________________________________
00106 emcHLRatioFEM* 
00107 emcHLRatioFEM::Default(const int& absPosition, 
00108                        const PHTimeStamp& t1, 
00109                        const PHTimeStamp& t2)
00110 {
00111   emcHLRatioFEM* fem = new emcHLRatioFEM(absPosition,t1,t2) ;
00112 
00113   size_t i ;
00114   for ( i = 0 ; i < 144 ; i++ ) {
00115     fem->AppendOneChannel(fGlobalAverage,fGlobalRMS,0,16) ;
00116   }
00117 
00118   return fem ;
00119 }
00120 
00121 
00122 //_____________________________________________________________________________
00123 float
00124 emcHLRatioFEM::getValue(int ichannel, int what) const 
00125 {
00126   if (what<0 || what>3) {
00127 
00128     cerr << EMC_WARNING_MSG
00129          << " emcHLRatioFEM::getValue(ichannel,what) : what="
00130          << what << " is incorrect. Returning default value of "
00131          << DefaultReturnValue() << " instead" << endl ;
00132 
00133     return DefaultReturnValue() ;
00134 
00135   }
00136 
00137   if (ichannel>=0 && ichannel<static_cast<int>(fHLRatioVector.size())) {
00138     return getValueFast(ichannel,what) ;
00139   }
00140   else {
00141     return DefaultReturnValue() ;
00142   }
00143 }
00144 
00145 //_____________________________________________________________________________
00146 float
00147 emcHLRatioFEM::getValueFast(int ichannel, int what) const
00148 {
00149   return (fHLRatioVector[ichannel])[what] ;
00150 }
00151 
00152 //_____________________________________________________________________________
00153 bool
00154 emcHLRatioFEM::IsEqual(const emcCalFEM& obj) const
00155 {
00156   if ( !dynamic_cast<const emcHLRatioFEM*>(&obj) ) return false ;
00157 
00158   if ( obj.size() != size() ) return false ;
00159   for ( size_t i = 0 ; i < size() ; i++ ) {
00160     for ( int j = 0 ; j < 4 ; j++ ) {
00161       if ( getValue(i,j) != obj.getValue(i,j) ) return false ;
00162     }
00163   }
00164   return true ;
00165 }
00166 
00167 //_____________________________________________________________________________
00168 void emcHLRatioFEM::Reset(void)
00169 {
00170   fHLRatioVector.clear() ;
00171 }
00172 
00173 //_____________________________________________________________________________
00174 ostream&
00175 emcHLRatioFEM::Print(ostream& out, int level) const
00176 {
00177   emcCalFEM::Print(out,level) ;
00178 
00179   if (level) {
00180     for ( size_t i = 0  ; i < fHLRatioVector.size() ; i++)
00181       {
00182         out << "#" << i 
00183              << " Average=" << getValue(i,0)
00184              << " RMS=" << getValue(i,1)
00185              << " Intercept=" << getValue(i,2)
00186              << " Slope=" << getValue(i,3)
00187              << endl ;
00188       }
00189   }
00190   return out ;
00191 }