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
00007
00009 UpdateTProfile::UpdateTProfile() {;}
00010
00011
00013 UpdateTProfile::~UpdateTProfile() {;}
00014
00015
00017 void UpdateTProfile::setBinContents( TProfile* const prof,
00018 const uint32_t& bin,
00019 const double& num_of_entries,
00020 const double& sum_of_contents,
00021 const double& sum_of_squares ) {
00022
00023
00024 double mean = 0.;
00025 double spread = 0.;
00026 if ( num_of_entries ) {
00027 mean = sum_of_contents / num_of_entries;
00028 spread = sqrt( sum_of_squares/ num_of_entries - mean * mean );
00029 }
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 UpdateTProfile::setBinContent( prof, bin, num_of_entries, mean, spread );
00041
00042 }
00043
00044
00082 void UpdateTProfile::setBinContent( TProfile* const prof,
00083 const uint32_t& bin,
00084 const double& num_of_entries,
00085 const double& mean,
00086 const double& spread ) {
00087
00088
00089
00090 if ( !prof ) {
00091 std::cerr << "[UpdateTProfile::setBinContents]"
00092 << " NULL pointer to TProfile object!" << std::endl;
00093 return;
00094 }
00095
00096
00097 if ( bin == 0 || bin > static_cast<uint32_t>(prof->GetNbinsX()) ) {
00098 std::cerr << "[UpdateTProfile::setBinContents]"
00099 << " Unexpected bin number!" << std::endl;
00100 return;
00101 }
00102
00103
00104 if ( num_of_entries <= 0. ) { return; }
00105 double entries = num_of_entries;
00106
00107
00108 const char* spread_option = "s";
00109 const char* default_option = "";
00110
00111
00112
00113
00114
00115
00116 const char* error_option = prof->GetErrorOption();
00117
00118
00119 double weight;
00120 if ( error_option[0] == spread_option[0] ) {
00121 weight = sqrt( mean*mean*entries + spread*spread*entries );
00122 } else if (error_option[0] == default_option[0] ) {
00123 weight = sqrt( mean*mean*entries + spread*spread*entries*entries );
00124 } else {
00125 std::cerr << "[UpdateTProfile::setBinContents]"
00126 << " Unexpected error option for TProfile!" << std::endl;
00127 weight = 0.;
00128 }
00129
00130
00131 prof->SetBinEntries( bin, entries );
00132 prof->SetBinContent( bin, mean * entries );
00133 prof->SetBinError( bin, weight );
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 if ( bin == 1 ) { prof->SetEntries( entries ); }
00146 else { prof->SetEntries( prof->GetEntries() + entries ); }
00147
00148 }
00149
00150