ATLAS Offline Software
Loading...
Searching...
No Matches
ShowerLib::TestShowerLib Class Reference

Class for shower library shower lib. More...

#include <TestShowerLib.h>

Inheritance diagram for ShowerLib::TestShowerLib:
Collaboration diagram for ShowerLib::TestShowerLib:

Classes

struct  genInfo

Public Member Functions

virtual ~TestShowerLib ()
 default destructor
virtual std::vector< EnergySpot > * getShower (const G4Track *track, ShowerLibStatistics *stats, int randomShift) const
 get shower for given G4 track
virtual double getContainmentZ (const G4Track *track) const
 get average length of showers for the given energy
virtual double getContainmentR (const G4Track *track) const
 get average lateral spread of the showers for the given energy
virtual bool storeShower (HepMC::ConstGenParticlePtr genParticle, const Shower *shower)
 store shower in the library
virtual bool writeToROOT (TFile *dest)
 write library to ROOT file
virtual ShowerLibStatisticscreateStatistics () const
virtual const std::string getName () const
const std::string statistics () const
 print library statistics
virtual const std::string detector () const
 get detector tag
virtual int particle_id () const
 get particle tag
virtual const std::string release () const
 get Release tag
virtual void release (const std::string &release)
 set Release tag
virtual const std::string geometry () const
 get Geometry tag
virtual void geometry (const std::string &geometry)
 set Geometry tag
virtual const std::string geantVersion () const
 get geant version tag
virtual void geantVersion (const std::string &version)
 set geant version tag
virtual const std::string physicsList () const
 get geant 4 physics list name
virtual void physicsList (const std::string &list)
 set geant 4 physics list name
virtual const std::string comment () const
 get comment
virtual void comment (const std::string &comment)
 set given string as comment
virtual void addComment (const std::string &comment)
 add given string to comment

Static Public Member Functions

static IShowerLibreadFromROOTFile (TFile *source)
 factory method. create a library from root file. returns NULL if file is invalid.
static IShowerLibcreateEmptyLib (const std::string &inputFile)
 factory method. create empty library with the given structure. returns NULL if file is invalid.

Protected Member Functions

virtual const std::string printParameters () const
bool readMeta (TTree *source)
 read metadata from the given TTree
bool writeMeta (TTree *dest) const
 write metadata to the given TTree

Protected Attributes

std::string m_detector
 name of the detector
int m_particle
 ID of the generated particles.
std::string m_release
 atlas software release
std::string m_geometry
 atlas geometry version
std::string m_geantVersion
 geant 4 version
std::string m_physicsList
 used geant 4 physics list
std::string m_comment
 comment
bool m_filled
 is the library read from ROOT or from structure file

Private Types

typedef std::pair< genInfo, ShowerstoredShower
typedef std::list< storedShowerlibrary

Private Member Functions

 TestShowerLib ()
bool read (TTree *source)
 read library from given TTree
bool write (TTree *dest) const
 write library to given TTree

Private Attributes

library m_libData

Detailed Description

Class for shower library shower lib.

   Store complete shower library (collection of energy bins)
Author
Wolfgang Ehrenfeld, University of Hamburg, Germany
Sasha Glazov, DESY Hamburg, Germany
Version
$Id: TestShowerLib.h 769594 2016-08-23 13:48:34Z ssnyder $

Definition at line 35 of file TestShowerLib.h.

Member Typedef Documentation

◆ library

typedef std::list<storedShower> ShowerLib::TestShowerLib::library
private

Definition at line 77 of file TestShowerLib.h.

◆ storedShower

Definition at line 76 of file TestShowerLib.h.

Constructor & Destructor Documentation

◆ ~TestShowerLib()

ShowerLib::TestShowerLib::~TestShowerLib ( )
virtual

default destructor

Definition at line 37 of file TestShowerLib.cxx.

38 {
39 }

◆ TestShowerLib()

ShowerLib::TestShowerLib::TestShowerLib ( )
inlineprivate

Definition at line 69 of file TestShowerLib.h.

69{}

Member Function Documentation

◆ addComment()

void ShowerLib::IShowerLib::addComment ( const std::string & comment)
inlinevirtualinherited

add given string to comment

Definition at line 141 of file IShowerLib.h.

141{ m_comment += comment; }
virtual const std::string comment() const
get comment
Definition IShowerLib.h:139
std::string m_comment
comment
Definition IShowerLib.h:112

◆ comment() [1/2]

const std::string ShowerLib::IShowerLib::comment ( ) const
inlinevirtualinherited

get comment

Definition at line 139 of file IShowerLib.h.

139{ return m_comment; }

◆ comment() [2/2]

void ShowerLib::IShowerLib::comment ( const std::string & comment)
inlinevirtualinherited

set given string as comment

Definition at line 140 of file IShowerLib.h.

140{ m_comment = comment; }

◆ createEmptyLib()

IShowerLib * ShowerLib::TestShowerLib::createEmptyLib ( const std::string & inputFile)
static

factory method. create empty library with the given structure. returns NULL if file is invalid.

Definition at line 67 of file TestShowerLib.cxx.

68 {
69 /*
70 * Test library Structure format:
71 *
72 * VER PART DET
73 * COMMENT
74 *
75 * where
76 *
77 * VER == 10
78 */
79 std::ifstream filestr(inputFile.c_str(),std::ios::in);
80
81 if (!filestr.is_open()) {
82 std::cout << "TestShowerLib " << inputFile << ": bad file!" << std::endl;
83 return nullptr;
84 }
85
86 std::string instr;
87 std::getline(filestr,instr);
88 std::stringstream ss(instr);
89
90 int ver;
91
92 ss >> ver;
93
94 if (ver != LIB_VERSION) {
95 return nullptr;
96 }
97
98
99 int part;
100 std::string det;
101
102 ss >> part >> det;
103
104
105 TestShowerLib* newlib = new TestShowerLib();
106
107 newlib->m_detector = std::move(det);
108 newlib->m_particle = part;
109 newlib->m_filled = false;
110
111 std::getline(filestr,instr);
112 newlib->m_comment = std::move(instr);
113
114 return newlib;
115 }
#define LIB_VERSION
static Double_t ss

◆ createStatistics()

ShowerLibStatistics * ShowerLib::TestShowerLib::createStatistics ( ) const
virtual

Implements ShowerLib::IShowerLib.

Definition at line 281 of file TestShowerLib.cxx.

282 {
283 return nullptr;
284 }

◆ detector()

const std::string ShowerLib::IShowerLib::detector ( ) const
inlinevirtualinherited

get detector tag

Definition at line 121 of file IShowerLib.h.

121{ return m_detector; }
std::string m_detector
name of the detector
Definition IShowerLib.h:106

◆ geantVersion() [1/2]

const std::string ShowerLib::IShowerLib::geantVersion ( ) const
inlinevirtualinherited

get geant version tag

Definition at line 133 of file IShowerLib.h.

133{ return m_geantVersion; }
std::string m_geantVersion
geant 4 version
Definition IShowerLib.h:110

◆ geantVersion() [2/2]

void ShowerLib::IShowerLib::geantVersion ( const std::string & version)
inlinevirtualinherited

set geant version tag

Definition at line 134 of file IShowerLib.h.

◆ geometry() [1/2]

const std::string ShowerLib::IShowerLib::geometry ( ) const
inlinevirtualinherited

get Geometry tag

Definition at line 130 of file IShowerLib.h.

130{ return m_geometry; }
std::string m_geometry
atlas geometry version
Definition IShowerLib.h:109

◆ geometry() [2/2]

void ShowerLib::IShowerLib::geometry ( const std::string & geometry)
inlinevirtualinherited

set Geometry tag

Definition at line 131 of file IShowerLib.h.

131{ m_geometry = geometry; }
virtual const std::string geometry() const
get Geometry tag
Definition IShowerLib.h:130

◆ getContainmentR()

double ShowerLib::TestShowerLib::getContainmentR ( const G4Track * track) const
virtual

get average lateral spread of the showers for the given energy

Implements ShowerLib::IShowerLib.

Definition at line 140 of file TestShowerLib.cxx.

141 {
142 if (!m_filled) {
143 std::cout << "Library is not created for production use" << std::endl;
144 return 0.0;
145 }
146
147 std::cout << "Library is only for testing, not for production use" << std::endl;
148 return 0.0;
149 }
bool m_filled
is the library read from ROOT or from structure file
Definition IShowerLib.h:114

◆ getContainmentZ()

double ShowerLib::TestShowerLib::getContainmentZ ( const G4Track * track) const
virtual

get average length of showers for the given energy

Implements ShowerLib::IShowerLib.

Definition at line 129 of file TestShowerLib.cxx.

130 {
131 if (!m_filled) {
132 std::cout << "Library is not created for production use" << std::endl;
133 return 0.0;
134 }
135
136 std::cout << "Library is only for testing, not for production use" << std::endl;
137 return 0.0;
138 }

◆ getName()

virtual const std::string ShowerLib::TestShowerLib::getName ( ) const
inlinevirtual

Reimplemented from ShowerLib::IShowerLib.

Definition at line 61 of file TestShowerLib.h.

61{ return "Test Energy ShowerLib"; }

◆ getShower()

std::vector< EnergySpot > * ShowerLib::TestShowerLib::getShower ( const G4Track * track,
ShowerLibStatistics * stats,
int randomShift ) const
virtual

get shower for given G4 track

Implements ShowerLib::IShowerLib.

Definition at line 118 of file TestShowerLib.cxx.

119 {
120 if (!m_filled) {
121 std::cout << "Library is not created for production use" << std::endl;
122 return nullptr;
123 }
124
125 std::cout << "Library is only for testing, not for production use" << std::endl;
126 return nullptr;
127 }

◆ particle_id()

int ShowerLib::IShowerLib::particle_id ( ) const
inlinevirtualinherited

get particle tag

Definition at line 124 of file IShowerLib.h.

124{ return m_particle; }
int m_particle
ID of the generated particles.
Definition IShowerLib.h:107

◆ physicsList() [1/2]

const std::string ShowerLib::IShowerLib::physicsList ( ) const
inlinevirtualinherited

get geant 4 physics list name

Definition at line 136 of file IShowerLib.h.

136{ return m_physicsList; }
std::string m_physicsList
used geant 4 physics list
Definition IShowerLib.h:111

◆ physicsList() [2/2]

void ShowerLib::IShowerLib::physicsList ( const std::string & list)
inlinevirtualinherited

set geant 4 physics list name

Definition at line 137 of file IShowerLib.h.

137{ m_physicsList = list; }
list(name, path='/')
Definition histSizes.py:38

◆ printParameters()

virtual const std::string ShowerLib::TestShowerLib::printParameters ( ) const
inlineprotectedvirtual

Implements ShowerLib::IShowerLib.

Definition at line 65 of file TestShowerLib.h.

65{return "";}

◆ read()

bool ShowerLib::TestShowerLib::read ( TTree * source)
private

read library from given TTree

Definition at line 187 of file TestShowerLib.cxx.

188 {
189 /*
190 * Eta Energy library format:
191 * | x | y | z | e | time | - name of branch in TTree
192 * ------------------------------------------------------------------
193 * | vertex | vertex | vertex | num of | cont | - shower header
194 * | X | Y | Z | hits | Z |
195 * ------------------------------------------------------------------
196 * | momentum | momentum | momentum | truth | cont | - shower header
197 * | X | Y | Z | energy | R |
198 * ------------------------------------------------------------------
199 * |x-coord of hit|y-coord of hit|z-coord of hit|dep.energy|hit time| - hit
200 */
201 int nentr = source->GetEntriesFast();
202 if (nentr < 3) return false;
203 Float_t x,y,z,e,time;
204 source->SetBranchAddress("x",&x);
205 source->SetBranchAddress("y",&y);
206 source->SetBranchAddress("z",&z);
207 source->SetBranchAddress("e",&e);
208 source->SetBranchAddress("time",&time);
209 int entr = 0;
210
211 do {
212 //read eta bin header
213 source->GetEntry(entr++);
214 int nhits = (int)(e+0.1); // +0.1 just in case - c++ has low round
215 Shower shower;
216 shower.setZSize(time);
217 genInfo theinfo{};
218 theinfo.vertex = std::make_unique<HepMC::FourVector>(x,y,z,0);
219 source->GetEntry(entr++);
220 shower.setRSize(time);
221 theinfo.momentum = std::make_unique<HepMC::FourVector>(x,y,z,e);
222 for(int i = 0; i < nhits; i++) {
223 source->GetEntry(entr++); //variables mean what the name suggests
224 shower.push_back(new ShowerEnergySpot(G4ThreeVector(x,y,z),e,time));
225 }
226 m_libData.emplace_back(std::move(theinfo),shower);
227 } while (entr < nentr);
228
229 m_filled = true;
230 return true;
231 }
#define y
#define x
#define z
time(flags, cells_name, *args, **kw)
std::unique_ptr< HepMC::FourVector > vertex

◆ readFromROOTFile()

IShowerLib * ShowerLib::TestShowerLib::readFromROOTFile ( TFile * source)
static

factory method. create a library from root file. returns NULL if file is invalid.

Definition at line 41 of file TestShowerLib.cxx.

42 {
43 TParameter<int>* ver;
44 ver = (TParameter<int>*)source->Get("version");
45
46 if ((ver == nullptr) || (ver->GetVal() != LIB_VERSION)) return nullptr; //Test library header = 10
47
48 TTree* TTreeMeta = (TTree*)source->Get("meta");
49 TTree* TTreeLib = (TTree*)source->Get("library");
50
51 if ((TTreeMeta == nullptr) || (TTreeLib == nullptr)) return nullptr;
52
53 std::cout << "TestShowerLib header found." << std::endl;
54
55 TestShowerLib* newlib = new TestShowerLib();
56
57 if (!(newlib->readMeta(TTreeMeta)) || !(newlib->read(TTreeLib))) {
58 delete newlib;
59 std::cout << "TestShowerLib read unsuccessful." << std::endl;
60 return nullptr;
61 }
62
63 return newlib;
64
65 }

◆ readMeta()

bool ShowerLib::IShowerLib::readMeta ( TTree * source)
protectedinherited

read metadata from the given TTree

Definition at line 16 of file IShowerLib.cxx.

16 {
17 char detector[40];
18 char release[40];
19 char geometry[40];
20 char geant[40];
21 char physics[40];
22 char comment[100];
23 source->SetBranchAddress("detector",&detector);
24 source->SetBranchAddress("particle",&m_particle);
25 source->SetBranchAddress("release",&release);
26 source->SetBranchAddress("geometry",&geometry);
27 source->SetBranchAddress("geantVersion",&geant);
28 source->SetBranchAddress("physicsList",&physics);
29 source->SetBranchAddress("comment",&comment);
30 source->GetEntry(0);
34 m_geantVersion = geant;
35 m_physicsList = physics;
37 return true;
38 }
virtual const std::string release() const
get Release tag
Definition IShowerLib.h:127
std::string m_release
atlas software release
Definition IShowerLib.h:108
virtual const std::string detector() const
get detector tag
Definition IShowerLib.h:121

◆ release() [1/2]

const std::string ShowerLib::IShowerLib::release ( ) const
inlinevirtualinherited

get Release tag

Definition at line 127 of file IShowerLib.h.

127{ return m_release; }

◆ release() [2/2]

void ShowerLib::IShowerLib::release ( const std::string & release)
inlinevirtualinherited

set Release tag

Definition at line 128 of file IShowerLib.h.

128{ m_release = release; }

◆ statistics()

const std::string ShowerLib::IShowerLib::statistics ( ) const
inherited

print library statistics

Definition at line 71 of file IShowerLib.cxx.

71 {
72
73 if (m_filled) {
74 std::stringstream out;
75
76 out << "======================================================" << std::endl;
77 out << " Statistics of the shower library " << std::endl;
78 out << "======================================================" << std::endl;
79 out << "Library Type: "<< getName() <<" PARTICLE: " << m_particle << " DETECTOR: "<< m_detector << std::endl;
80 out << m_release << " " << m_geometry << " " << m_geantVersion << " " << m_physicsList << std::endl;
81 if (printParameters().length() > 0)
82 out << printParameters() << std::endl;
83 out << m_comment << std::endl;
84 return out.str();
85 } else { //statistics for the genlib, shorter version
86 std::stringstream out;
87 out << getName() <<" PARTICLE: " << m_particle << " DETECTOR: "<< m_detector << ", ";
88 out << m_release << " " << m_geometry << " " << m_geantVersion << " " << m_physicsList << std::endl;
89 if (printParameters().length() > 0)
90 out << printParameters() << std::endl;
91 out << m_comment << std::endl;
92 return out.str();
93 }
94 }
double length(const pvec &v)
virtual const std::string printParameters() const =0
virtual const std::string getName() const
Definition IShowerLib.h:93

◆ storeShower()

bool ShowerLib::TestShowerLib::storeShower ( HepMC::ConstGenParticlePtr genParticle,
const Shower * shower )
virtual

store shower in the library

Implements ShowerLib::IShowerLib.

Definition at line 151 of file TestShowerLib.cxx.

152 {
153 if (m_filled) {
154 std::cout << "ERROR: filled" << std::endl;
155 return false;
156 }
157
158 genInfo theinfo{};
159 theinfo.vertex = std::make_unique<HepMC::FourVector>(genParticle->production_vertex()->position());
160 theinfo.momentum = std::make_unique<HepMC::FourVector>(genParticle->momentum());
161
162 m_libData.emplace_back(std::move(theinfo), *shower);
163
164 return true;
165 }

◆ write()

bool ShowerLib::TestShowerLib::write ( TTree * dest) const
private

write library to given TTree

Definition at line 233 of file TestShowerLib.cxx.

234 {
235 /*
236 * Eta Energy library format:
237 * | x | y | z | e | time | - name of branch in TTree
238 * ------------------------------------------------------------------
239 * | vertex | vertex | vertex | num of | cont | - shower header
240 * | X | Y | Z | hits | Z |
241 * ------------------------------------------------------------------
242 * | momentum | momentum | momentum | truth | cont | - shower header
243 * | X | Y | Z | energy | R |
244 * ------------------------------------------------------------------
245 * |x-coord of hit|y-coord of hit|z-coord of hit|dep.energy|hit time| - hit
246 */
247 Float_t x,y,z,e,time;
248 dest->Branch("x",&x);
249 dest->Branch("y",&y);
250 dest->Branch("z",&z);
251 dest->Branch("e",&e);
252 dest->Branch("time",&time);
253 for (const storedShower& lib : m_libData) {
254 HepMC::FourVector vertex = *lib.first.vertex;
255 HepMC::FourVector momentum = *lib.first.momentum;
256 x = vertex.x();
257 y = vertex.y();
258 z = vertex.z();
259 e = lib.second.size();
260 time = lib.second.getZSize();
261 dest->Fill(); //eta bin header
262 x = momentum.px();
263 y = momentum.py();
264 z = momentum.pz();
265 e = momentum.e();
266 time = lib.second.getRSize();
267 dest->Fill(); //eta bin header
268 for (const ShowerEnergySpot* spot : lib.second) {
269 x = spot->GetPosition().x();
270 y = spot->GetPosition().y();
271 z = spot->GetPosition().z();
272 e = spot->GetEnergy();
273 time = spot->GetTime();
274 dest->Fill();
275 }
276 }
277 //dest->Write();
278 return true;
279 }
std::pair< genInfo, Shower > storedShower

◆ writeMeta()

bool ShowerLib::IShowerLib::writeMeta ( TTree * dest) const
protectedinherited

write metadata to the given TTree

Definition at line 40 of file IShowerLib.cxx.

40 {
41 char detector[40];
42 char release[40];
43 char geometry[40];
44 char geant[40];
45 char physics[40];
46 char comment[100];
48 m_detector.copy(detector,39,0);
49 detector[m_detector.length()] = '\0';
50 m_release.copy(release,39,0);
51 release[m_release.length()] = '\0';
52 m_geometry.copy(geometry,39,0);
53 geometry[m_geometry.length()] = '\0';
54 m_geantVersion.copy(geant,39,0);
55 geant[m_geantVersion.length()] = '\0';
56 m_physicsList.copy(physics,39,0);
57 physics[m_physicsList.length()] = '\0';
58 m_comment.copy(comment,99,0);
59 comment[m_comment.length()] = '\0';
60 source->Branch("detector",&detector,"detector/C");
61 source->Branch("particle",&particle,"particle/I");
62 source->Branch("release",&release,"release/C");
63 source->Branch("geometry",&geometry,"geometry/C");
64 source->Branch("geantVersion",&geant,"geantVersion/C");
65 source->Branch("physicsList",&physics,"physicsList/C");
66 source->Branch("comment",&comment,"comment/C");
67 source->Fill();
68 return true;
69 }
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses

◆ writeToROOT()

bool ShowerLib::TestShowerLib::writeToROOT ( TFile * dest)
virtual

write library to ROOT file

Implements ShowerLib::IShowerLib.

Definition at line 167 of file TestShowerLib.cxx.

168 {
169 if (m_libData.empty()) return false;
170 TParameter<int> ver("version",LIB_VERSION);
171
172 dest->WriteObject(&ver,"version");
173
174 TTree TTreeMeta;
175 TTree TTreeLib;
176
177 write(&TTreeLib);
178 writeMeta(&TTreeMeta);
179
180 dest->WriteObject(&TTreeLib,"library");
181 dest->WriteObject(&TTreeMeta,"meta");
182
183 return true;
184 }
bool writeMeta(TTree *dest) const
write metadata to the given TTree
bool write(TTree *dest) const
write library to given TTree

Member Data Documentation

◆ m_comment

std::string ShowerLib::IShowerLib::m_comment
protectedinherited

comment

Definition at line 112 of file IShowerLib.h.

◆ m_detector

std::string ShowerLib::IShowerLib::m_detector
protectedinherited

name of the detector

Definition at line 106 of file IShowerLib.h.

◆ m_filled

bool ShowerLib::IShowerLib::m_filled
protectedinherited

is the library read from ROOT or from structure file

Definition at line 114 of file IShowerLib.h.

◆ m_geantVersion

std::string ShowerLib::IShowerLib::m_geantVersion
protectedinherited

geant 4 version

Definition at line 110 of file IShowerLib.h.

◆ m_geometry

std::string ShowerLib::IShowerLib::m_geometry
protectedinherited

atlas geometry version

Definition at line 109 of file IShowerLib.h.

◆ m_libData

library ShowerLib::TestShowerLib::m_libData
private

Definition at line 84 of file TestShowerLib.h.

◆ m_particle

int ShowerLib::IShowerLib::m_particle
protectedinherited

ID of the generated particles.

Definition at line 107 of file IShowerLib.h.

◆ m_physicsList

std::string ShowerLib::IShowerLib::m_physicsList
protectedinherited

used geant 4 physics list

Definition at line 111 of file IShowerLib.h.

◆ m_release

std::string ShowerLib::IShowerLib::m_release
protectedinherited

atlas software release

Definition at line 108 of file IShowerLib.h.


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