ATLAS Offline Software
Functions
TFCS2DFunction.cxx File Reference
#include "ISF_FastCaloSimEvent/TFCS2DFunction.h"
#include "ISF_FastCaloSimEvent/TFCS2DFunctionHistogram.h"
#include "ISF_FastCaloSimEvent/TFCS2DFunctionTemplateHistogram.h"
#include "TH2.h"
#include "TCanvas.h"
#include "TH2F.h"
#include "TRandom.h"
#include "TFile.h"
#include <iostream>
Include dependency graph for TFCS2DFunction.cxx:

Go to the source code of this file.

Functions

TH2 *create_random_TH2 ATLAS_NOT_THREAD_SAFE (int nbinsx=64, int nbinsy=64)
 
void TFCS2DFunction::unit_test ATLAS_NOT_THREAD_SAFE (TH2 *hist, TFCS2DFunction *rtof, const char *outfilename, int nrnd)
 
void TFCS2DFunction::unit_tests ATLAS_NOT_THREAD_SAFE (TH2 *hist, const char *outfilename, int nrnd)
 

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/3]

TH2* create_random_TH2 ATLAS_NOT_THREAD_SAFE ( int  nbinsx = 64,
int  nbinsy = 64 
)

Definition at line 76 of file TFCS2DFunction.cxx.

76  {
77  TH2 *hist = new TH2F("test2D", "test2D", nbinsx, 0, 1, nbinsy, 0, 1);
78  hist->Sumw2();
79  for (int ix = 1; ix <= nbinsx; ++ix) {
80  for (int iy = 1; iy <= nbinsy; ++iy) {
81  hist->SetBinContent(ix, iy,
82  (0.5 + gRandom->Rndm()) * (nbinsx + ix) *
83  (nbinsy * nbinsy / 2 + iy * iy));
84  if (gRandom->Rndm() < 0.1)
85  hist->SetBinContent(ix, iy, 0);
86  hist->SetBinError(ix, iy, 0);
87  }
88  }
89  return hist;
90 }

◆ ATLAS_NOT_THREAD_SAFE() [2/3]

void TFCS2DFunction::unit_tests ATLAS_NOT_THREAD_SAFE ( TH2 hist,
const char *  outfilename,
int  nrnd 
)

Definition at line 170 of file TFCS2DFunction.cxx.

170  {
171  if (hist == nullptr)
172  hist = create_random_TH2(16, 16);
173 
174  const int ntest = 4;
175  TFCS2DFunction *tests[ntest];
180 
181  for (int i = 0; i < ntest; ++i) {
182  unit_test(hist, tests[i], outfilename, nrnd);
183  }
184 }

◆ ATLAS_NOT_THREAD_SAFE() [3/3]

void TFCS2DFunction::unit_test ATLAS_NOT_THREAD_SAFE ( TH2 hist,
TFCS2DFunction rtof,
const char *  outfilename,
int  nrnd 
)

Definition at line 92 of file TFCS2DFunction.cxx.

95  {
97  if (hist == nullptr)
98  hist = create_random_TH2();
99  if (rtof == nullptr)
100  rtof = new TFCS2DFunctionHistogram(hist);
101 
102  int nbinsx = hist->GetNbinsX();
103  int nbinsy = hist->GetNbinsY();
104 
105  float value[2];
106  float rnd[2];
107  //cppcheck-suppress uninitvar
108  for (rnd[0] = 0; rnd[0] < 0.9999; rnd[0] += 0.25) {
109  for (rnd[1] = 0; rnd[1] < 0.9999; rnd[1] += 0.25) {
110  rtof->rnd_to_fct(value, rnd);
111  ATH_MSG_NOCLASS(logger, "rnd0=" << rnd[0] << " rnd1=" << rnd[1]
112  << " -> x=" << value[0]
113  << " y=" << value[1]);
114  }
115  }
116 
117  // TH2F* hist_val=new
118  // TH2F("val2D","val2D",16,hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),
119  // 16,hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax());
120  TH2F *hist_val =
121  (TH2F *)hist->Clone(TString(hist->GetName()) + "_" + rtof->ClassName());
122  hist_val->Reset();
123 
124  float weight = hist->Integral() / nrnd;
125  hist_val->Sumw2();
126  for (int i = 0; i < nrnd; ++i) {
127  rnd[0] = gRandom->Rndm();
128  rnd[1] = gRandom->Rndm();
129  rtof->rnd_to_fct(value, rnd);
130  hist_val->Fill(value[0], value[1], weight);
131  }
132  hist_val->Add(hist, -1);
133 
134  TH1F *hist_pull =
135  new TH1F(TString("pull_") + rtof->ClassName(),
136  TString("pull for ") + rtof->ClassName(), 80, -4, 4);
137  for (int ix = 1; ix <= nbinsx; ++ix) {
138  for (int iy = 1; iy <= nbinsy; ++iy) {
139  float val = hist_val->GetBinContent(ix, iy);
140  float err = hist_val->GetBinError(ix, iy);
141  if (err > 0)
142  hist_pull->Fill(val / err);
143  // ATH_MSG_NOCLASS(logger,"val="<<val<<" err="<<err);
144  }
145  }
146 
147  std::unique_ptr<TFile> outputfile(TFile::Open(outfilename, "UPDATE"));
148  if (outputfile != nullptr) {
149  hist->Write();
150  hist_val->Write();
151  hist_pull->Write();
152  outputfile->ls();
153  }
154 
155 // Screen output in athena won't make sense and would require linking of
156 // additional libraries
157 #if defined(__FastCaloSimStandAlone__)
158  new TCanvas(hist->GetName(), hist->GetTitle());
159  hist->Draw("colz");
160 
161  new TCanvas(hist_val->GetName(), hist_val->GetTitle());
162  hist_val->Draw("colz");
163 
164  new TCanvas(hist_pull->GetName(), hist_pull->GetTitle());
165  hist_pull->Draw();
166 #endif
167 }
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
TFCS2DFunctionInt8Int8Int32Histogram
Definition: TFCS2DFunctionTemplateHistogram.h:283
TH2F
Definition: rootspy.cxx:420
plotmaker.hist
hist
Definition: plotmaker.py:148
athena.value
value
Definition: athena.py:122
TFCS2DFunctionHistogram
Definition: TFCS2DFunctionHistogram.h:15
python.setupRTTAlg.tests
list tests
Definition: setupRTTAlg.py:40
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
TFCS2DFunctionInt8Int8Int16Histogram
Definition: TFCS2DFunctionTemplateHistogram.h:269
outputfile
ofstream outputfile
Definition: CellClusterLinkTool.h:25
TFCS2DFunction::rnd_to_fct
virtual void rnd_to_fct(float &valuex, float &valuey, float rnd0, float rnd1) const =0
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
lumiFormat.i
int i
Definition: lumiFormat.py:92
TH2
Definition: rootspy.cxx:373
TH2F::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:425
TFCS2DFunctionInt8Int8Int8Histogram
Definition: TFCS2DFunctionTemplateHistogram.h:255
ATH_MSG_NOCLASS
#define ATH_MSG_NOCLASS(logger_name, x)
Definition: MLogging.h:52
TH1F
Definition: rootspy.cxx:320
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
TFCS2DFunction
Definition: TFCS2DFunction.h:15
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
python.CreateTierZeroArgdict.outfilename
outfilename
Definition: CreateTierZeroArgdict.py:236
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14