ATLAS Offline Software
Loading...
Searching...
No Matches
TFCS1DFunctionInt16Histogram.cxx File Reference
#include "ISF_FastCaloSimEvent/TFCS1DFunctionInt16Histogram.h"
#include <algorithm>
#include <iostream>
#include "TMath.h"
#include "TCanvas.h"
#include "TH2F.h"
#include "TRandom.h"
#include "TFile.h"
Include dependency graph for TFCS1DFunctionInt16Histogram.cxx:

Go to the source code of this file.

Functions

void TFCS1DFunctionInt16Histogram::unit_test ATLAS_NOT_THREAD_SAFE (TH1 *hist)

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

void TFCS1DFunctionInt16Histogram::unit_test ATLAS_NOT_THREAD_SAFE ( TH1 * hist)

Definition at line 94 of file TFCS1DFunctionInt16Histogram.cxx.

94 {
96 int nbinsx;
97 if (hist == nullptr) {
98 nbinsx = 50;
99 hist = new TH1D("test1D", "test1D", nbinsx, 0, 1);
100 hist->Sumw2();
101 for (int ix = 1; ix <= nbinsx; ++ix) {
102 double val = (0.5 + gRandom->Rndm()) * (nbinsx + ix);
103 if (gRandom->Rndm() < 0.1)
104 val = 0;
105 hist->SetBinContent(ix, val);
106 hist->SetBinError(ix, 0);
107 }
108 }
110 nbinsx = hist->GetNbinsX();
111
112 float value[2];
113 float rnd[2];
114 //cppcheck-suppress uninitvar
115 for (rnd[0] = 0; rnd[0] < 0.9999; rnd[0] += 0.25) {
116 rtof.rnd_to_fct(value, rnd);
117 ATH_MSG_NOCLASS(logger, "rnd0=" << rnd[0] << " -> x=" << value[0]);
118 }
119
120 TH1 *hist_val = (TH1 *)hist->Clone("hist_val");
121 hist_val->SetTitle("difference");
122 hist_val->Reset();
123 int nrnd = 100000;
124 double weight = hist->Integral() / nrnd;
125 hist_val->Sumw2();
126 for (int i = 0; i < nrnd; ++i) {
127 rnd[0] = gRandom->Rndm();
128 rtof.rnd_to_fct(value, rnd);
129 hist_val->Fill(value[0], weight);
130 }
131 hist_val->Add(hist, -1);
132
133 TH1F *hist_pull = new TH1F("pull", "pull", 200, -10, 10);
134 for (int ix = 1; ix <= nbinsx; ++ix) {
135 float val = hist_val->GetBinContent(ix);
136 float err = hist_val->GetBinError(ix);
137 if (err > 0)
138 hist_pull->Fill(val / err);
139 ATH_MSG_NOCLASS(logger, "val=" << val << " err=" << err);
140 }
141
142// Screen output in athena won't make sense and would require linking of
143// additional libraries
144#if defined(__FastCaloSimStandAlone__)
145 new TCanvas("input", "Input");
146 hist->Draw();
147
148 new TCanvas("validation", "Validation");
149 hist_val->Draw();
150
151 new TCanvas("pull", "Pull");
152 hist_pull->Draw();
153#endif
154}
static TRandom * rnd
#define ATH_MSG_NOCLASS(logger_name, x)
Definition MLogging.h:52
Cut down AthMessaging.
Definition MLogging.h:176
static Root::TMsgLogger logger("iLumiCalc")
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)