CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions
UpdateTProfile Class Reference

#include <UpdateTProfile.h>

Public Member Functions

 UpdateTProfile ()
 
 ~UpdateTProfile ()
 

Static Public Member Functions

static void setBinContent (TProfile *const profile, const uint32_t &bin, const double &entries, const double &mean, const double &spread)
 
static void setBinContents (TProfile *const profile, const uint32_t &bin, const double &num_of_entries, const double &sum_of_contents, const double &sum_of_squares)
 

Detailed Description

Definition at line 9 of file UpdateTProfile.h.

Constructor & Destructor Documentation

UpdateTProfile::UpdateTProfile ( )

Definition at line 9 of file UpdateTProfile.cc.

9 {;}
UpdateTProfile::~UpdateTProfile ( )

Definition at line 13 of file UpdateTProfile.cc.

13 {;}

Member Function Documentation

void UpdateTProfile::setBinContent ( TProfile *const  prof,
const uint32_t &  bin,
const double &  num_of_entries,
const double &  mean,
const double &  spread 
)
static

Error option "s" means that the error returned using the GetBinError() method is the spread for that bin. (If the default error option is used, the error returned is spread / sqrt(N), where N is the number of entries for that bin). The commissioning procedures use option "s" throughout.

In order that the profile histo correctly displays the "bin_mean" and "bin_spread" (an example being: peds +/- strip noise), we have to manipulate the "contents" and "error" data as follows:

TProfile::SetBinEntries( bin_number, bin_entries ) TProfile::SetBinContents( bin_number, bin_mean * bin_entries ) TProfile::SetBinError( bin_number, weight )

"weight" is calculated based on the GetBinError() method, which returns an error ("err" below) based on the following equation:

1) if error option is set to "s": err = sqrt( wei^2 / num - ( sum / num )^2 ) => err = sqrt( wei^2 / num - sum^2 / num^2 ) => wei = sqrt( err^2 * num + sum^2 / num ) => wei = sqrt( err^2 * num + mean^2 * num )

2) else if error option is set to "" (ie, default): err = ( 1 / sqrt( num ) ) * sqrt( wei^2 / num - ( sum / num )^2 ) => err = sqrt( wei^2 / num^2 - sum^2 / num^3 ) => wei = sqrt( err^2 * num^2 + cont^2 / num ) => wei = sqrt( err^2 * num^2 + mean^2 * num )

where: "num" is the bin entries, as set by the method SetBinEntries() "sum" is the bin content, as set by the method SetBinContent() "wei" is the bin error, as set by the method SetBinError() and "mean" = sum / num

Definition at line 82 of file UpdateTProfile.cc.

References dtNoiseDBValidation_cfg::cerr, python.tagInventory::entries, mathSSE::sqrt(), and CommonMethods::weight().

Referenced by setBinContents(), PedestalsTask::update(), PedsOnlyTask::update(), NoiseTask::update(), and PedsFullNoiseTask::update().

86  {
87  // std::cout << "[UpdateTProfile::setBinContents]" << std::endl;
88 
89  // Check histo exists
90  if ( !prof ) {
91  std::cerr << "[UpdateTProfile::setBinContents]"
92  << " NULL pointer to TProfile object!" << std::endl;
93  return;
94  }
95 
96  // Check bin number is valid
97  if ( bin == 0 || bin > static_cast<uint32_t>(prof->GetNbinsX()) ) {
98  std::cerr << "[UpdateTProfile::setBinContents]"
99  << " Unexpected bin number!" << std::endl;
100  return;
101  }
102 
103  // Check entries are present
104  if ( num_of_entries <= 0. ) { return; } //@@ what about negative weights???
105  double entries = num_of_entries;
106 
107  // Check error option
108  const char* spread_option = "s";
109  const char* default_option = "";
110  // const char* option = prof->GetErrorOption();
111  // if ( option[0] != spread_option[0] ) {
112  // std::cout << "[UpdateTProfile::setBinContents]"
113  // << " Setting error option for TProfile to 's'!" << std::endl;
114  // prof->SetErrorOption( "s" );
115  // }
116  const char* error_option = prof->GetErrorOption();
117 
118  // Calculate "weight" used for SetBinError() method
119  double weight;
120  if ( error_option[0] == spread_option[0] ) {
121  weight = sqrt( mean*mean*entries + spread*spread*entries );
122  } else if (error_option[0] == default_option[0] ) {
123  weight = sqrt( mean*mean*entries + spread*spread*entries*entries );
124  } else {
125  std::cerr << "[UpdateTProfile::setBinContents]"
126  << " Unexpected error option for TProfile!" << std::endl;
127  weight = 0.;
128  }
129 
130  // Set bin entries, contents and error
131  prof->SetBinEntries( bin, entries );
132  prof->SetBinContent( bin, mean * entries );
133  prof->SetBinError( bin, weight );
134 
135 // LogTrace("TEST")
136 // << "[UpdateTProfile::" << __func__ << "]"
137 // << " bin/entries/mean/content/error: "
138 // << bin << "/"
139 // << entries << "/"
140 // << mean << "/"
141 // << mean*entries << "/"
142 // << weight;
143 
144  // Set total number of entries
145  if ( bin == 1 ) { prof->SetEntries( entries ); }
146  else { prof->SetEntries( prof->GetEntries() + entries ); }
147 
148 }
T sqrt(T t)
Definition: SSEVec.h:46
void UpdateTProfile::setBinContents ( TProfile *const  profile,
const uint32_t &  bin,
const double &  num_of_entries,
const double &  sum_of_contents,
const double &  sum_of_squares 
)
static

Definition at line 17 of file UpdateTProfile.cc.

References timingPdfMaker::mean, setBinContent(), and mathSSE::sqrt().

21  {
22  // std::cout << "[UpdateTProfile::setBinContents]" << std::endl;
23 
24  double mean = 0.;
25  double spread = 0.;
26  if ( num_of_entries ) {
27  mean = sum_of_contents / num_of_entries;
28  spread = sqrt( sum_of_squares/ num_of_entries - mean * mean );
29  }
30 
31 // LogTrace("TEST")
32 // << "[UpdateTProfile::setBinContents]"
33 // << " bin: " << bin
34 // << " entries: " << num_of_entries
35 // << " contents: " << sum_of_contents
36 // << " squared: " << sum_of_squares
37 // << " mean: " << mean
38 // << " spread: " << spread;
39 
40  UpdateTProfile::setBinContent( prof, bin, num_of_entries, mean, spread );
41 
42 }
T sqrt(T t)
Definition: SSEVec.h:46
static void setBinContent(TProfile *const profile, const uint32_t &bin, const double &entries, const double &mean, const double &spread)