ATLAS Offline Software
Functions
TFCS1DFunction.cxx File Reference
#include "ISF_FastCaloSimEvent/TFCS1DFunction.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TRandom.h"
#include <string>
#include <iostream>
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 95 of file TFCS1DFunction.cxx.

96  {
97  TH1 *hist = new TH1D("test_slope1D", "test_slope1D", nbinsx, xmin, xmax);
98  hist->Sumw2();
99  for (int ix = 1; ix <= nbinsx; ++ix) {
100  double val = (0.5 + gRandom->Rndm()) * (nbinsx + ix);
101  if (gRandom->Rndm() < zerothreshold)
102  val = 0;
103  hist->SetBinContent(ix, val);
104  hist->SetBinError(ix, 0);
105  }
106  return hist;
107 }

◆ 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 110 of file TFCS1DFunction.cxx.

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

◆ 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 122 of file TFCS1DFunction.cxx.

124  {
126  ATH_MSG_NOCLASS(logger, "========= " << hist->GetName() << " funcsize="
127  << rtof->MemorySize() << " ========");
128  int nbinsx = hist->GetNbinsX();
129  double integral = hist->Integral();
130 
131  float value[2];
132  float rnd[2];
133  //cppcheck-suppress uninitvar
134  for (rnd[0] = 0; rnd[0] < 0.9999; rnd[0] += 0.25) {
135  rtof->rnd_to_fct(value, rnd);
136  ATH_MSG_NOCLASS(logger, "rnd0=" << rnd[0] << " -> x=" << value[0]);
137  }
138 
139  TH1 *hist_val = nullptr;
140  if (histfine)
141  hist_val = (TH1 *)histfine->Clone(TString(hist->GetName()) + "hist_val");
142  else
143  hist_val = (TH1 *)hist->Clone(TString(hist->GetName()) + "hist_val");
144  double weightfine = hist_val->Integral() / nrnd;
145  hist_val->SetTitle("toy simulation");
146  hist_val->Reset();
147  hist_val->SetLineColor(2);
148  hist_val->Sumw2();
149 
150  TH1 *hist_diff = (TH1 *)hist->Clone(TString(hist->GetName()) + "_difference");
151  hist_diff->SetTitle("cut efficiency difference");
152  hist_diff->Reset();
153  hist_diff->Sumw2();
154 
155  double weight = integral / nrnd;
156  for (int i = 0; i < nrnd; ++i) {
157  rnd[0] = gRandom->Rndm();
158  rtof->rnd_to_fct(value, rnd);
159  hist_val->Fill(value[0], weightfine);
160  hist_diff->Fill(value[0], weight);
161  }
162  hist_diff->Add(hist, -1);
163  hist_diff->Scale(1.0 / integral);
164 
165  TH1F *hist_pull =
166  new TH1F(TString(hist->GetName()) + "_pull", "pull", 200, -10, 10);
167  for (int ix = 1; ix <= nbinsx; ++ix) {
168  float val = hist_diff->GetBinContent(ix);
169  float err = hist_diff->GetBinError(ix);
170  if (err > 0)
171  hist_pull->Fill(val / err);
172  }
173 
174 // Screen output in athena won't make sense and would require linking of
175 // additional libraries
176 #if defined(__FastCaloSimStandAlone__)
177  TCanvas *c = new TCanvas(hist->GetName(), hist->GetName());
178  c->Divide(2, 2);
179 
180  c->cd(1);
181  if (histfine) {
182  histfine->SetLineColor(kGray);
183  histfine->DrawClone("hist");
184  hist->DrawClone("same");
185  } else {
186  hist->DrawClone();
187  }
188  hist_val->DrawClone("sameshist");
189 
190  c->cd(2);
191  if (histfine) {
192  histfine->SetLineColor(kGray);
193  histfine->DrawClone("hist");
194  hist->DrawClone("same");
195  } else {
196  hist->DrawClone();
197  }
198  hist_val->DrawClone("sameshist");
199  gPad->SetLogy();
200 
201  c->cd(3);
202  hist_diff->Draw();
203 
204  c->cd(4);
205  hist_pull->Draw();
206 
207  c->SaveAs(".png");
208 #endif
209 }
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
integral
double integral(TH1 *h)
Definition: computils.cxx:58
plotmaker.hist
hist
Definition: plotmaker.py:148
TFCS1DFunction::rnd_to_fct
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...
Definition: TFCS1DFunction.cxx:17
athena.value
value
Definition: athena.py:124
x
#define x
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
lumiFormat.i
int i
Definition: lumiFormat.py:85
xmin
double xmin
Definition: listroot.cxx:60
ATH_MSG_NOCLASS
#define ATH_MSG_NOCLASS(logger_name, x)
Definition: MLogging.h:52
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
xmax
double xmax
Definition: listroot.cxx:61
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
python.compressB64.c
def c
Definition: compressB64.py:93
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
TFCSFunction::MemorySize
virtual std::size_t MemorySize() const
Gives the total memory size, including the size of additional memory allocated inside the class.
Definition: TFCSFunction.h:19