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
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
00033
00034
00035
00036
00037
00038
00039
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
00089
00090
00091 if ( !prof ) {
00092 cerr << "[UpdateTProfile::setBinContents]"
00093 << " NULL pointer to TProfile object!" << endl;
00094 return;
00095 }
00096
00097
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
00105 if ( num_of_entries <= 0. ) { return; }
00106 double entries = num_of_entries;
00107
00108
00109 const char* spread_option = "s";
00110 const char* default_option = "";
00111
00112
00113
00114
00115
00116
00117 const char* error_option = prof->GetErrorOption();
00118
00119
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
00132 prof->SetBinEntries( bin, entries );
00133 prof->SetBinContent( bin, mean * entries );
00134 prof->SetBinError( bin, weight );
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 if ( bin == 1 ) { prof->SetEntries( entries ); }
00147 else { prof->SetEntries( prof->GetEntries() + entries ); }
00148
00149 }
00150
00151