CMS 3D CMS Logo

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 8 of file UpdateTProfile.h.

Constructor & Destructor Documentation

◆ UpdateTProfile()

UpdateTProfile::UpdateTProfile ( )

Definition at line 8 of file UpdateTProfile.cc.

8 { ; }

◆ ~UpdateTProfile()

UpdateTProfile::~UpdateTProfile ( )

Definition at line 12 of file UpdateTProfile.cc.

12 { ; }

Member Function Documentation

◆ setBinContent()

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 80 of file UpdateTProfile.cc.

References newFWLiteAna::bin, DMR_cfg::cerr, SiStripPI::mean, mathSSE::sqrt(), and mps_merge::weight.

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

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

◆ setBinContents()

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 16 of file UpdateTProfile.cc.

References newFWLiteAna::bin, SiStripPI::mean, setBinContent(), and mathSSE::sqrt().

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