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

Go to the source code of this file.

Functions

void TFCS2DFunctionHistogram::unit_test ATLAS_NOT_THREAD_SAFE (TH2 *hist)

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

void TFCS2DFunctionHistogram::unit_test ATLAS_NOT_THREAD_SAFE ( TH2 * hist)

Definition at line 102 of file TFCS2DFunctionHistogram.cxx.

102 {
104 int nbinsx;
105 int nbinsy;
106 if (hist == nullptr) {
107 // hist=new TH2F("test2D","test2D",5,0,5,5,0,10);
108 nbinsx = 64;
109 nbinsy = 64;
110 hist = new TH2F("test2D", "test2D", nbinsx, 0, 1, nbinsy, 0, 1);
111 hist->Sumw2();
112 for (int ix = 1; ix <= nbinsx; ++ix) {
113 for (int iy = 1; iy <= nbinsy; ++iy) {
114 hist->SetBinContent(ix, iy,
115 (0.5 + gRandom->Rndm()) * (nbinsx + ix) *
116 (nbinsy * nbinsy / 2 + iy * iy));
117 if (gRandom->Rndm() < 0.1)
118 hist->SetBinContent(ix, iy, 0);
119 hist->SetBinError(ix, iy, 0);
120 }
121 }
122 }
123 TFCS2DFunctionHistogram rtof(hist);
124 nbinsx = hist->GetNbinsX();
125 nbinsy = hist->GetNbinsY();
126
127 float value[2];
128 float rnd[2];
129 //cppcheck-suppress uninitvar
130 for (rnd[0] = 0; rnd[0] < 0.9999; rnd[0] += 0.25) {
131 for (rnd[1] = 0; rnd[1] < 0.9999; rnd[1] += 0.25) {
132 rtof.rnd_to_fct(value, rnd);
133 ATH_MSG_NOCLASS(logger, "rnd0=" << rnd[0] << " rnd1=" << rnd[1]
134 << " -> x=" << value[0]
135 << " y=" << value[1]);
136 }
137 }
138
139 // TH2F* hist_val=new
140 // TH2F("val2D","val2D",16,hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
141 // 16,hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax());
142 TH2F *hist_val = (TH2F *)hist->Clone("hist_val");
143 hist_val->Reset();
144 int nrnd = 100000000;
145 float weight = hist->Integral() / nrnd;
146 hist_val->Sumw2();
147 for (int i = 0; i < nrnd; ++i) {
148 rnd[0] = gRandom->Rndm();
149 rnd[1] = gRandom->Rndm();
150 rtof.rnd_to_fct(value, rnd);
151 hist_val->Fill(value[0], value[1], weight);
152 }
153 hist_val->Add(hist, -1);
154
155 TH1F *hist_pull = new TH1F("pull", "pull", 80, -4, 4);
156 for (int ix = 1; ix <= nbinsx; ++ix) {
157 for (int iy = 1; iy <= nbinsy; ++iy) {
158 float val = hist_val->GetBinContent(ix, iy);
159 float err = hist_val->GetBinError(ix, iy);
160 if (err > 0)
161 hist_pull->Fill(val / err);
162 ATH_MSG_NOCLASS(logger, "val=" << val << " err=" << err);
163 }
164 }
165
166 std::unique_ptr<TFile> outputfile(
167 TFile::Open("TFCS2DFunctionHistogram_unit_test.root", "RECREATE"));
168 if (outputfile != nullptr) {
169 hist->Write();
170 hist_val->Write();
171 hist_pull->Write();
172 outputfile->ls();
173 outputfile->Close();
174 }
175
176// Screen output in athena won't make sense and would require linking of
177// additional libraries
178#if defined(__FastCaloSimStandAlone__)
179 new TCanvas("input", "Input");
180 hist->Draw("colz");
181
182 new TCanvas("validation", "Validation");
183 hist_val->Draw("colz");
184
185 new TCanvas("pull", "Pull");
186 hist_pull->Draw();
187#endif
188}
ofstream outputfile
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")
TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)