ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_FastCaloSim
ISF_PunchThroughTools
src
PDFcreator.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// PDFcreator.cxx, (c) ATLAS Detector software
8
9
// class header
10
#include "
PDFcreator.h
"
11
12
// std
13
#include <algorithm>
14
15
// Random number generators
16
#include "CLHEP/Random/RandFlat.h"
17
18
// ROOT
19
#include "TFile.h"
20
#include "TH2F.h"
21
#include "TAxis.h"
22
#include "TF1.h"
23
24
25
26
27
/*=========================================================================
28
* DESCRIPTION OF FUNCTION:
29
* ==> see headerfile
30
*=======================================================================*/
31
32
ISF::PDFcreator::~PDFcreator
() {
33
for
(
auto
& each_outter :
m_energy_eta_hists1D
) {
34
for
(
auto
& each_inner : each_outter.second) {
35
if
(each_inner.second !=
nullptr
)
36
delete
each_inner.second;
37
}
38
}
39
}
40
41
void
ISF::PDFcreator::addToEnergyEtaHist1DMap
(
int
energy,
int
etaMin, TH1 *hist) {
42
// Make a local copy
43
TH1* localHist = (TH1*) hist->Clone();
44
localHist->SetDirectory(0);
45
46
if
(
m_energy_eta_hists1D
.find(energy) !=
m_energy_eta_hists1D
.end()){
//if energy entry exists, insert into inner eta map
47
(
m_energy_eta_hists1D
.find(energy)->second).insert(std::make_pair(etaMin, localHist));
48
}
49
else
{
//if energy entry does not exist create new full energy entry
50
std::map< int, TH1*> inner;
51
inner.insert(std::make_pair(etaMin, localHist));
52
m_energy_eta_hists1D
.insert(std::make_pair(energy, inner));
53
}
54
}
55
56
double
ISF::PDFcreator::getRand
(CLHEP::HepRandomEngine* rndmEngine,
const
std::vector<int>& inputParameters)
const
57
{
58
59
//define variable to return from getRand call, should never return zero
60
float
randomHist = 0.;
61
62
if
(
m_energy_eta_hists1D
.find(inputParameters.at(0)) ==
m_energy_eta_hists1D
.end()) {
63
//this should never be reached
64
return
0.;
65
}
66
67
const
std::map< int, TH1*>& etaMin_hists =
m_energy_eta_hists1D
.at(inputParameters.at(0));
68
69
if
( etaMin_hists.find(inputParameters.at(1)) == etaMin_hists.end()) {
70
//this should never be reached
71
return
0.;
72
}
73
74
//get the chosen histogram from the map
75
TH1* hist = etaMin_hists.at(inputParameters.at(1));
76
77
//Draw randomly from the histogram CDF distribution.
78
double
randomShoot = CLHEP::RandFlat::shoot(rndmEngine);
79
80
//first select the matching CDF bin
81
int
iBinSelect = 0;
82
for
(
int
iBin = 0; iBin < hist->GetNbinsX(); iBin ++){
83
iBinSelect = iBin;
84
if
(hist->GetBinContent(iBin) > randomShoot){
85
break
;
86
}
87
}
88
89
//Select random value within bin
90
randomHist = CLHEP::RandFlat::shoot(rndmEngine, hist->GetBinLowEdge(iBinSelect) , hist->GetBinLowEdge(iBinSelect+1));
91
92
93
return
randomHist;
94
95
}
PDFcreator.h
ISF::PDFcreator::~PDFcreator
~PDFcreator()
Definition
PDFcreator.cxx:32
ISF::PDFcreator::getRand
double getRand(CLHEP::HepRandomEngine *rndmEngine, const std::vector< int > &inputParameters) const
get the random value with this method, by providing the input parameters
Definition
PDFcreator.cxx:56
ISF::PDFcreator::m_energy_eta_hists1D
std::map< int, std::map< int, TH1 * > > m_energy_eta_hists1D
map of energies to map of eta ranges to 1D histograms
Definition
PDFcreator.h:55
ISF::PDFcreator::addToEnergyEtaHist1DMap
void addToEnergyEtaHist1DMap(int energy, int etaMin, TH1 *hist)
Definition
PDFcreator.cxx:41
Generated on
for ATLAS Offline Software by
1.17.0