Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

LIChannel.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Program name: LIChannel.cxx
00004 //                                                                     
00005 // Package: LISummary
00006 //  
00007 // Coded by Jeff Hartnell Oct/2002  
00008 //
00009 // Based on code by: Rob Morse Feb/2002
00010 //                             
00011 // Purpose: To store and calculate the average mean and rms for a 
00012 //          given channel
00013 //                                                                    
00014 // Contact: jeffrey.hartnell@physics.ox.ac.uk   
00016 
00017 #include <cmath>
00018 
00019 #include "MessageService/MsgService.h"
00020 
00021 #include "LISummary/LIChannel.h"
00022 
00023 using namespace std;
00024 
00025 CVSID("$Id: LIChannel.cxx,v 1.11 2003/11/18 13:51:01 hartnell Exp $");
00026 
00027 //......................................................................
00028 
00029 LIChannel::LIChannel()
00030 {
00031   //initialise variables
00032   fMean=0;
00033   fNumEntries=0;
00034   fRms=0;
00035   fSigma1=0;
00036   fSigma2=0;
00037   fSummaryCounter=0;
00038 }
00039 //......................................................................
00040 
00041 LIChannel::~LIChannel()
00042 {
00043   //nothing
00044 }
00045 
00046 //......................................................................
00047 
00048 Bool_t operator==(LIChannel a, LIChannel b)
00049 {
00050   return a.GetRawChannelId()==b.GetRawChannelId();
00051 }
00052 
00053 //......................................................................
00054 
00055 Bool_t operator<(LIChannel a, LIChannel b)
00056 {
00057   return a.GetRawChannelId()<b.GetRawChannelId();
00058 }
00059 
00060 //......................................................................
00061  
00062 void LIChannel::Clean()
00063 {
00064   //reset all variables
00065   fNumEntries=0;
00066   fMean=0.;
00067   fRms=0.;
00068   fSummaryCounter=0;
00069   fSigma1=0;
00070   fSigma2=0;
00071   fChannelId=RawChannelId();//set to default
00072 }
00073 
00074 //......................................................................
00075 
00076 void LIChannel::SetEntry(Int_t entries, Float_t mean, 
00077                          Float_t rms)
00078 {
00079   fNumEntries=entries;
00080   fMean=static_cast<Double_t>(mean);
00081   fRms=static_cast<Double_t>(rms);
00082   fSummaryCounter=1;
00083 }
00084 
00085 //......................................................................
00086 
00087 Float_t LIChannel::GetRms()
00088 {
00089   //calcualte the rms from the sum of 
00090   //1.) the weighted sum of the (sq of the new mean plus the sq of the
00091   //    new rms)
00092   //2.) the weighted sum of all the means
00093   
00094   //protect against fpe
00095   if (fNumEntries==0) return fRms;
00096 
00097   //calculate averages
00098   Double_t avSigma1=fSigma1/fNumEntries;
00099   Double_t avSigma2Sqd=pow(fSigma2/fNumEntries,2);
00100   
00101   //calculate average rms if possible
00102   if (avSigma1>=avSigma2Sqd){
00103     fRms=sqrt(avSigma1-avSigma2Sqd);
00104   }
00105   else{//would be imaginary
00106     fRms=0;
00107     MSG("LIChannel",Msg::kVerbose) 
00108       << "Zero rms channel (avSigma1="<<avSigma1
00109       <<" < avSigma2Sqd="<<avSigma2Sqd<<")"
00110       <<", ent="<<fNumEntries
00111       <<", fMean="<<fMean
00112       <<", fRms="<<fRms 
00113       << endl;
00114   }
00115   return static_cast<Float_t>(fRms);
00116 }
00117 
00118 //......................................................................
00119 
00120 void LIChannel::AddEntry(Int_t entries, Float_t meanInput, 
00121                          Float_t rmsInput)
00122 {
00123   //convert to double to preserve precision
00124   Double_t rms=static_cast<Double_t>(rmsInput);
00125   Double_t mean=static_cast<Double_t>(meanInput);
00126   
00127   MSG("LIChannel",Msg::kVerbose)
00128     <<" ent="<<entries<<", mean="<<meanInput<<", rms="<<rmsInput
00129     <<endl;
00130   
00131   //protect against fpe
00132   if(entries>0){   
00133     //calcuate the sum of the sq of the new mean and the new rms
00134     //and weight it by the number of new entries
00135     fSigma1+=entries*(pow(rms,2)+pow(mean,2));
00136     
00137     //calculate weighted sum of all the means
00138     fSigma2+=mean*entries;
00139     
00140     //calculate mean by weighting existing mean and new mean
00141     fMean=fMean*fNumEntries/(fNumEntries+entries)+
00142       mean*entries/(fNumEntries+entries);
00143     
00144     //sum the number of entries in this channel
00145     fNumEntries+=entries;
00146     
00147     //count the number of summaries included
00148     fSummaryCounter++;
00149   }
00150 }
00151 
00152 //......................................................................

Generated on Mon Feb 15 11:06:51 2010 for loon by  doxygen 1.3.9.1