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