CMS 3D CMS Logo

UpdateTProfile.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommon/interface/UpdateTProfile.h"
00002 #include "TProfile.h"
00003 #include <iostream>
00004 #include <math.h>
00005 
00006 using namespace std;
00007 
00008 // -----------------------------------------------------------------------------
00010 UpdateTProfile::UpdateTProfile() {;}
00011 
00012 // -----------------------------------------------------------------------------
00014 UpdateTProfile::~UpdateTProfile() {;}
00015 
00016 // -----------------------------------------------------------------------------
00018 void UpdateTProfile::setBinContents( TProfile* const prof,
00019                                      const uint32_t& bin, 
00020                                      const double& num_of_entries, 
00021                                      const double& sum_of_contents,
00022                                      const double& sum_of_squares ) {
00023   //   cout << "[UpdateTProfile::setBinContents]" << endl;
00024   
00025   double mean = 0.;
00026   double spread = 0.;
00027   if ( num_of_entries ) { 
00028     mean = sum_of_contents / num_of_entries;
00029     spread = sqrt( sum_of_squares/ num_of_entries - mean * mean ); 
00030   }
00031    
00032 //   LogTrace("TEST")
00033 //     << "[UpdateTProfile::setBinContents]"
00034 //     << " bin: " << bin
00035 //     << " entries: " << num_of_entries
00036 //     << " contents: " << sum_of_contents
00037 //     << " squared: " << sum_of_squares
00038 //     << " mean: " << mean
00039 //     << " spread: " << spread;
00040   
00041   UpdateTProfile::setBinContent( prof, bin, num_of_entries, mean, spread );
00042   
00043 }
00044 
00045 // -----------------------------------------------------------------------------
00083 void UpdateTProfile::setBinContent( TProfile* const prof,
00084                                     const uint32_t& bin, 
00085                                     const double& num_of_entries, 
00086                                     const double& mean,
00087                                     const double& spread ) {
00088   //   cout << "[UpdateTProfile::setBinContents]" << endl;
00089 
00090   // Check histo exists
00091   if ( !prof ) {
00092     cerr << "[UpdateTProfile::setBinContents]"
00093          << " NULL pointer to TProfile object!" << endl;
00094     return;
00095   }
00096 
00097   // Check bin number is valid
00098   if ( bin == 0 || bin > static_cast<uint32_t>(prof->GetNbinsX()) ) {
00099     cerr << "[UpdateTProfile::setBinContents]"
00100          << " Unexpected bin number!" << endl;
00101     return;
00102   }
00103 
00104   // Check entries are present
00105   if ( num_of_entries <= 0. ) { return; } //@@ what about negative weights???
00106   double entries = num_of_entries;
00107   
00108   // Check error option
00109   const char* spread_option = "s";
00110   const char* default_option = "";
00111   //   const char* option = prof->GetErrorOption();
00112   //   if ( option[0] != spread_option[0] ) {
00113   //     cout << "[UpdateTProfile::setBinContents]"
00114   //     << " Setting error option for TProfile to 's'!" << endl;
00115   //     prof->SetErrorOption( "s" );
00116   //   }
00117   const char* error_option = prof->GetErrorOption();
00118 
00119   // Calculate "weight" used for SetBinError() method
00120   double weight;
00121   if ( error_option[0] == spread_option[0] ) {
00122     weight = sqrt( mean*mean*entries + spread*spread*entries  );
00123   } else if (error_option[0] == default_option[0] ) {
00124     weight = sqrt( mean*mean*entries + spread*spread*entries*entries );
00125   } else { 
00126     cerr << "[UpdateTProfile::setBinContents]"
00127          << " Unexpected error option for TProfile!" << endl;
00128     weight = 0.; 
00129   }
00130   
00131   // Set bin entries, contents and error
00132   prof->SetBinEntries( bin, entries );
00133   prof->SetBinContent( bin, mean * entries );
00134   prof->SetBinError( bin, weight );
00135  
00136 //   LogTrace("TEST")
00137 //     << "[UpdateTProfile::" << __func__ << "]"
00138 //     << " bin/entries/mean/content/error: " 
00139 //     << bin << "/"
00140 //     << entries << "/"
00141 //     << mean << "/"
00142 //     << mean*entries << "/"
00143 //     << weight;
00144 
00145   // Set total number of entries 
00146   if ( bin == 1 ) { prof->SetEntries( entries ); }
00147   else { prof->SetEntries( prof->GetEntries() + entries ); }
00148   
00149 }
00150 
00151 

Generated on Tue Jun 9 17:33:34 2009 for CMSSW by  doxygen 1.5.4