ATLAS Offline Software
Loading...
Searching...
No Matches
TFCS1DFunction.cxx File Reference
#include "ISF_FastCaloSimEvent/TFCS1DFunction.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TRandom.h"
#include <string>
#include <iostream>
#include <cmath>
Include dependency graph for TFCS1DFunction.cxx:

Go to the source code of this file.

Functions

TH1 *TFCS1DFunction::generate_histogram_random_slope ATLAS_NOT_THREAD_SAFE (int nbinsx, double xmin, double xmax, double zerothreshold)
TH1 *TFCS1DFunction::generate_histogram_random_gauss ATLAS_NOT_THREAD_SAFE (int nbinsx, int ntoy, double xmin, double xmax, double xpeak, double sigma)
void TFCS1DFunction::unit_test ATLAS_NOT_THREAD_SAFE (TH1 *hist, TFCS1DFunction *rtof, int nrnd, TH1 *histfine)

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/3]

TH1 *TFCS1DFunction::generate_histogram_random_slope ATLAS_NOT_THREAD_SAFE ( int nbinsx,
double xmin,
double xmax,
double zerothreshold )

Definition at line 98 of file TFCS1DFunction.cxx.

99 {
100 TH1 *hist = new TH1D("test_slope1D", "test_slope1D", nbinsx, xmin, xmax);
101 hist->Sumw2();
102 for (int ix = 1; ix <= nbinsx; ++ix) {
103 double val = (0.5 + gRandom->Rndm()) * (nbinsx + ix);
104 if (gRandom->Rndm() < zerothreshold)
105 val = 0;
106 hist->SetBinContent(ix, val);
107 hist->SetBinError(ix, 0);
108 }
109 return hist;
110}
double xmax
Definition listroot.cxx:61
double xmin
Definition listroot.cxx:60

◆ ATLAS_NOT_THREAD_SAFE() [2/3]

TH1 *TFCS1DFunction::generate_histogram_random_gauss ATLAS_NOT_THREAD_SAFE ( int nbinsx,
int ntoy,
double xmin,
double xmax,
double xpeak,
double sigma )

Definition at line 113 of file TFCS1DFunction.cxx.

114 {
115 TH1 *hist = new TH1D("test_gauss1D", "test_gauss1D", nbinsx, xmin, xmax);
116 hist->Sumw2();
117 for (int i = 1; i <= ntoy; ++i) {
118 double x = gRandom->Gaus(xpeak, sigma);
119 if (x >= xmin && x < xmax)
120 hist->Fill(x);
121 }
122 return hist;
123}
#define x

◆ ATLAS_NOT_THREAD_SAFE() [3/3]

void TFCS1DFunction::unit_test ATLAS_NOT_THREAD_SAFE ( TH1 * hist,
TFCS1DFunction * rtof,
int nrnd,
TH1 * histfine )

Definition at line 125 of file TFCS1DFunction.cxx.

127 {
129 ATH_MSG_NOCLASS(logger, "========= " << hist->GetName() << " funcsize="
130 << rtof->MemorySize() << " ========");
131 int nbinsx = hist->GetNbinsX();
132 double integral = hist->Integral();
133
134 float value[2];
135 float rnd[2];
136 //cppcheck-suppress uninitvar
137 for (rnd[0] = 0; rnd[0] < 0.9999; rnd[0] += 0.25) {
138 rtof->rnd_to_fct(value, rnd);
139 ATH_MSG_NOCLASS(logger, "rnd0=" << rnd[0] << " -> x=" << value[0]);
140 }
141
142 TH1 *hist_val = nullptr;
143 if (histfine)
144 hist_val = (TH1 *)histfine->Clone(TString(hist->GetName()) + "hist_val");
145 else
146 hist_val = (TH1 *)hist->Clone(TString(hist->GetName()) + "hist_val");
147 double weightfine = hist_val->Integral() / nrnd;
148 hist_val->SetTitle("toy simulation");
149 hist_val->Reset();
150 hist_val->SetLineColor(2);
151 hist_val->Sumw2();
152
153 TH1 *hist_diff = (TH1 *)hist->Clone(TString(hist->GetName()) + "_difference");
154 hist_diff->SetTitle("cut efficiency difference");
155 hist_diff->Reset();
156 hist_diff->Sumw2();
157
158 double weight = integral / nrnd;
159 for (int i = 0; i < nrnd; ++i) {
160 rnd[0] = gRandom->Rndm();
161 rtof->rnd_to_fct(value, rnd);
162 hist_val->Fill(value[0], weightfine);
163 hist_diff->Fill(value[0], weight);
164 }
165 hist_diff->Add(hist, -1);
166 hist_diff->Scale(1.0 / integral);
167
168 TH1F *hist_pull =
169 new TH1F(TString(hist->GetName()) + "_pull", "pull", 200, -10, 10);
170 for (int ix = 1; ix <= nbinsx; ++ix) {
171 float val = hist_diff->GetBinContent(ix);
172 float err = hist_diff->GetBinError(ix);
173 if (err > 0)
174 hist_pull->Fill(val / err);
175 }
176
177// Screen output in athena won't make sense and would require linking of
178// additional libraries
179#if defined(__FastCaloSimStandAlone__)
180 TCanvas *c = new TCanvas(hist->GetName(), hist->GetName());
181 c->Divide(2, 2);
182
183 c->cd(1);
184 if (histfine) {
185 histfine->SetLineColor(kGray);
186 histfine->DrawClone("hist");
187 hist->DrawClone("same");
188 } else {
189 hist->DrawClone();
190 }
191 hist_val->DrawClone("sameshist");
192
193 c->cd(2);
194 if (histfine) {
195 histfine->SetLineColor(kGray);
196 histfine->DrawClone("hist");
197 hist->DrawClone("same");
198 } else {
199 hist->DrawClone();
200 }
201 hist_val->DrawClone("sameshist");
202 gPad->SetLogy();
203
204 c->cd(3);
205 hist_diff->Draw();
206
207 c->cd(4);
208 hist_pull->Draw();
209
210 c->SaveAs(".png");
211#endif
212}
static TRandom * rnd
#define ATH_MSG_NOCLASS(logger_name, x)
Definition MLogging.h:52
Cut down AthMessaging.
Definition MLogging.h:176
virtual void rnd_to_fct(float value[], const float rnd[]) const
Function gets array of random numbers rnd[] in the range [0,1) as arguments and returns function valu...
virtual std::size_t MemorySize() const
Gives the total memory size, including the size of additional memory allocated inside the class.
double integral(TH1 *h)
Definition computils.cxx:59
static Root::TMsgLogger logger("iLumiCalc")
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)