ATLAS Offline Software
Loading...
Searching...
No Matches
ISF::PDFcreator Class Reference

Creates random numbers with a distribution given as ROOT TF1. More...

#include <PDFcreator.h>

Collaboration diagram for ISF::PDFcreator:

Public Member Functions

 PDFcreator ()
 construct the class with a given TF1 and a random engine
 ~PDFcreator ()
void setName (const std::string &PDFname)
 all following is used to set up the class
void addToEnergyEtaHist1DMap (int energy, int etaMin, TH1 *hist)
double getRand (CLHEP::HepRandomEngine *rndmEngine, const std::vector< int > &inputParameters) const
 get the random value with this method, by providing the input parameters
const std::string & getName () const

Private Attributes

std::string m_name
 Give pdf a name for debug purposes.
std::map< int, std::map< int, TH1 * > > m_energy_eta_hists1D
 map of energies to map of eta ranges to 1D histograms

Detailed Description

Creates random numbers with a distribution given as ROOT TF1.

The TF1 function parameters will be retrieved from a histogram given by addPar.

Author
Elmar Ritsch Elmar.nosp@m..Rit.nosp@m.sch@c.nosp@m.ern..nosp@m.ch @maintainer/updater Thomas Carter thoma.nosp@m.s.mi.nosp@m.chael.nosp@m..car.nosp@m.ter@c.nosp@m.ern..nosp@m.ch

Definition at line 36 of file PDFcreator.h.

Constructor & Destructor Documentation

◆ PDFcreator()

ISF::PDFcreator::PDFcreator ( )
inline

construct the class with a given TF1 and a random engine

Definition at line 41 of file PDFcreator.h.

41{};

◆ ~PDFcreator()

ISF::PDFcreator::~PDFcreator ( )

Definition at line 32 of file PDFcreator.cxx.

32 {
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}
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

Member Function Documentation

◆ addToEnergyEtaHist1DMap()

void ISF::PDFcreator::addToEnergyEtaHist1DMap ( int energy,
int etaMin,
TH1 * hist )

Definition at line 41 of file PDFcreator.cxx.

41 {
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}

◆ getName()

const std::string & ISF::PDFcreator::getName ( ) const
inline

Definition at line 51 of file PDFcreator.h.

51{return m_name;};
std::string m_name
Give pdf a name for debug purposes.
Definition PDFcreator.h:54

◆ getRand()

double ISF::PDFcreator::getRand ( CLHEP::HepRandomEngine * rndmEngine,
const std::vector< int > & inputParameters ) const

get the random value with this method, by providing the input parameters

Definition at line 56 of file PDFcreator.cxx.

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}

◆ setName()

void ISF::PDFcreator::setName ( const std::string & PDFname)
inline

all following is used to set up the class

Definition at line 46 of file PDFcreator.h.

46{ m_name = PDFname; }; //get the pdf's name

Member Data Documentation

◆ m_energy_eta_hists1D

std::map< int , std::map< int, TH1*> > ISF::PDFcreator::m_energy_eta_hists1D
private

map of energies to map of eta ranges to 1D histograms

Definition at line 55 of file PDFcreator.h.

◆ m_name

std::string ISF::PDFcreator::m_name
private

Give pdf a name for debug purposes.

Definition at line 54 of file PDFcreator.h.


The documentation for this class was generated from the following files: