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

Class for shower library shower lib. More...

#include <EtaEnergyShowerLib.h>

Inheritance diagram for ShowerLib::EtaEnergyShowerLib:
Collaboration diagram for ShowerLib::EtaEnergyShowerLib:

Public Member Functions

virtual ~EtaEnergyShowerLib ()
 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::map< float, Showeretabin
typedef std::map< float, etabinlibrary

Private Member Functions

 EtaEnergyShowerLib ()
bool read (TTree *source)
 read library from given TTree
bool write (TTree *dest) const
 write library to given TTree
bool readStructure (std::vector< float > &structure)
bool checkEtaAndStuff (const G4Track *track) const

Private Attributes

float m_mineta
float m_maxeta
library m_libData
bool m_onlyPositive

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: EtaEnergyShowerLib.h 769594 2016-08-23 13:48:34Z ssnyder $

Definition at line 35 of file EtaEnergyShowerLib.h.

Member Typedef Documentation

◆ etabin

typedef std::map<float,Shower> ShowerLib::EtaEnergyShowerLib::etabin
private

Definition at line 94 of file EtaEnergyShowerLib.h.

◆ library

typedef std::map<float,etabin> ShowerLib::EtaEnergyShowerLib::library
private

Definition at line 95 of file EtaEnergyShowerLib.h.

Constructor & Destructor Documentation

◆ ~EtaEnergyShowerLib()

virtual ShowerLib::EtaEnergyShowerLib::~EtaEnergyShowerLib ( )
inlinevirtual

default destructor

Definition at line 46 of file EtaEnergyShowerLib.h.

47 {
48 for ( auto& eta : m_libData) { // eta bins
49 for (auto& ene : eta.second ) { // energy map
50 for ( auto& spot : ene.second ) {
51 delete spot;
52 }
53 ene.second.clear();
54 }
55 eta.second.clear();
56 }
57 m_libData.clear();
58 }
Scalar eta() const
pseudorapidity method

◆ EtaEnergyShowerLib()

ShowerLib::EtaEnergyShowerLib::EtaEnergyShowerLib ( )
inlineprivate

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

◆ checkEtaAndStuff()

bool ShowerLib::EtaEnergyShowerLib::checkEtaAndStuff ( const G4Track * track) const
private

Definition at line 550 of file EtaEnergyShowerLib.cxx.

551 {
552 if (!m_filled) {
553 std::cout << "Library is not created for production use" << std::endl;
554 return false;
555 }
556
557 double eta = track->GetPosition().eta();
558
559 if ((m_onlyPositive) && (eta < 0.0)) eta = -eta;
560
561 if ( (eta < m_mineta) || (eta > m_maxeta)) {
562 std::cout << "eta is outside library eta range: mineta=" << m_mineta << " maxeta: " << m_maxeta <<" eta=" << eta << std::endl;
563 return false;
564 }
565
566 G4int particleCode = track->GetDefinition()->GetPDGEncoding();
567 if ( particleCode < 0 ) particleCode = -particleCode; // hack for positrons.
568
569 if ( particleCode != m_particle ) {
570 std::cout << "wrong particle: " << particleCode << "!=" << m_particle << std::endl;
571 return false;
572 }
573 return true;
574 }
int m_particle
ID of the generated particles.
Definition IShowerLib.h:107
bool m_filled
is the library read from ROOT or from structure file
Definition IShowerLib.h:114

◆ 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::EtaEnergyShowerLib::createEmptyLib ( const std::string & inputFile)
static

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

Definition at line 62 of file EtaEnergyShowerLib.cxx.

63 {
64 /*
65 * Eta Energy Structure format:
66 *
67 * VER PART DET ETA1 ETA2 ...
68 * COMMENT
69 *
70 * where
71 *
72 * VER == 1
73 * ETA(N+1) > ETA(N)
74 * First ETA is the beginning of the lib
75 * Last ETA is the end of the lib
76 */
77 std::ifstream filestr(inputFile.c_str(),std::ios::in);
78
79
80 if (!filestr.is_open()) {
81 std::cout << "EtaEnergyShowerLib " << inputFile << ": bad file!" << std::endl;
82 return nullptr;
83 }
84
85 std::string instr;
86 std::getline(filestr,instr);
87 std::stringstream ss(instr);
88
89 int ver;
90
91 ss >> ver;
92
93 if (ver != LIB_VERSION) {
94 return nullptr;
95 }
96
97
98 int part;
99 std::string det;
100
101 ss >> part >> det;
102
103 std::vector<float> etalist;
104
105 float eta;
106 float etaold = -9999999.9; //hopefully will be enough
107
108 ss >> eta;
109
110 if (ss.fail()) {
111 std::cout << "file reading failed! (not enough data)" << std::endl;
112 return nullptr;
113 }
114
115 float mineta = eta;
116 float maxeta = eta;
117
118 while (!ss.eof()) {
119 if ((ss.fail()) || (eta <= etaold)) {
120 std::cout << "screwed etas! (" << eta << "<=" << etaold << ")" << std::endl;
121 return nullptr;
122 }
123 etalist.push_back(eta);
124 etaold = eta;
125 ss >> eta;
126 maxeta = eta;
127 }
128
130 if (!newlib->readStructure(etalist)) {
131 std::cout << "this structure is not valid" << std::endl;
132 delete newlib;
133 return nullptr;
134 }
135
136 newlib->m_detector = std::move(det);
137 newlib->m_particle = part;
138 newlib->m_mineta = mineta;
139 newlib->m_maxeta = maxeta;
140
141 newlib->m_filled = false;
142 if (mineta < 0) newlib->m_onlyPositive = false;
143 else newlib->m_onlyPositive = true;
144
145 std::getline(filestr,instr);
146 newlib->m_comment = std::move(instr);
147
148 return newlib;
149 }
#define LIB_VERSION

◆ createStatistics()

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

Implements ShowerLib::IShowerLib.

Definition at line 527 of file EtaEnergyShowerLib.cxx.

528 {
529 std::map<int, std::string> names;
530 std::map<int, int> sizes;
531 for(library::const_iterator it = m_libData.begin(); it != m_libData.end(); ++it) {
532 sizes[calcKey(it->first)]=it->second.size();
533 float etalow = it->first;
534 float etahigh;
535 library::const_iterator it_copy = it;
536 ++it_copy;
537 if (it_copy == m_libData.end()) {
538 etahigh = m_maxeta;
539 } else {
540 etahigh = it_copy->first;
541 }
542 std::stringstream ss;
543 ss << std::showpos << std::fixed << std::setprecision(2);
544 ss << "ETA: " << etalow << " .. " << etahigh;
545 names[calcKey(it->first)] = ss.str();
546 }
547 return new ShowerLibStatistics(names, sizes);
548 }
int calcKey(float eta)

◆ 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::EtaEnergyShowerLib::getContainmentR ( const G4Track * track) const
virtual

get average lateral spread of the showers for the given energy

Implements ShowerLib::IShowerLib.

Definition at line 295 of file EtaEnergyShowerLib.cxx.

296 {
297 if (!checkEtaAndStuff(track)) return 0.0;
298
299 double eta = track->GetPosition().eta();
300
301 if ((m_onlyPositive) && (eta < 0.0)) eta = -eta;
302
303 library::const_iterator libit = m_libData.upper_bound(eta);
304
305 if (libit == m_libData.begin()) {
306 //this is really weird
307 std::cout << "Something is wrong with eta: mineta=" << m_mineta << " eta=" << eta << std::endl;
308 } else {
309 --libit;
310 }
311
312 if ((*libit).second.empty()) {
313 std::cout << "The etabin corresponding to the eta is empty" << std::endl;
314 return 0.0;
315 }
316 double trenergy = track->GetKineticEnergy();
317 etabin::const_iterator etait = (*libit).second.lower_bound(trenergy);
318 if (etait == (*libit).second.end()) --etait; //if it points to the end, repoint it to the last shower in bin
319 else if (etait != (*libit).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
320 etabin::const_iterator etaitch = etait;
321 --etaitch;
322 if (((*etait).first - trenergy) > (trenergy - (*etaitch).first)) { // the closest is the previous
323 --etait;
324 }
325 }
326 //std::cout << "Found closest energy:" << (*etait).first << std::endl;
327 double rezR = (*etait).second.getRSize();
328 etabin::const_iterator etaiter = etait;
329 int actualNumFS = 1;
330 int spread = 2; //will calculate average Z for 5 showers max ( -2 .. 0 .. +2 )
331 double upperEnergy = (*etait).first * 1.01; //we allow 1% off
332 for (int i = 0; i < spread; i++) {
333 ++etaiter;
334 if (etaiter == (*libit).second.end()) {
335 break;
336 }
337 if (upperEnergy < (*etaiter).first) break; //energy diff too high
338 //the shower is OK, including it to the average
339 rezR += (*etaiter).second.getRSize();
340 actualNumFS++;
341 }
342 etaiter = etait;
343 if (etaiter != (*libit).second.begin()) {
344 double lowerEnergy = (*etait).first * 0.99; //we allow 1% off
345 for (int i = 0; i < spread; i++) {
346 --etaiter;
347 if (lowerEnergy > (*etaiter).first) break; //energy diff too high
348 //the shower is OK, including it to the average
349 rezR += (*etaiter).second.getRSize();
350 actualNumFS++;
351 if (etaiter == (*libit).second.begin()) {
352 break;
353 }
354 }
355 }
356 return rezR/actualNumFS; //average Z size
357 }
bool checkEtaAndStuff(const G4Track *track) const

◆ getContainmentZ()

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

get average length of showers for the given energy

Implements ShowerLib::IShowerLib.

Definition at line 231 of file EtaEnergyShowerLib.cxx.

232 {
233 if (!checkEtaAndStuff(track)) return 0.0;
234
235 double eta = track->GetPosition().eta();
236
237 if ((m_onlyPositive) && (eta < 0.0)) eta = -eta;
238
239 library::const_iterator libit = m_libData.upper_bound(eta);
240
241 if (libit == m_libData.begin()) {
242 //this is really weird
243 std::cout << "Something is wrong with eta: mineta=" << m_mineta << " eta=" << eta << std::endl;
244 } else {
245 --libit;
246 }
247
248 if ((*libit).second.empty()) {
249 std::cout << "The etabin corresponding to the eta is empty" << std::endl;
250 return 0.0;
251 }
252 double trenergy = track->GetKineticEnergy();
253 etabin::const_iterator etait = (*libit).second.lower_bound(trenergy);
254 if (etait == (*libit).second.end()) --etait; //if it points to the end, repoint it to the last shower in bin
255 else if (etait != (*libit).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
256 etabin::const_iterator etaitch = etait;
257 --etaitch;
258 if (((*etait).first - trenergy) > (trenergy - (*etaitch).first)) { // the closest is the previous
259 --etait;
260 }
261 }
262 //std::cout << "Found closest energy:" << (*etait).first << std::endl;
263 double rezZ = (*etait).second.getZSize();
264 etabin::const_iterator etaiter = etait;
265 int actualNumFS = 1;
266 int spread = 2; //will calculate average Z for 5 showers max ( -2 .. 0 .. +2 )
267 double upperEnergy = (*etait).first * 1.01; //we allow 1% off
268 for (int i = 0; i < spread; i++) {
269 ++etaiter;
270 if (etaiter == (*libit).second.end()) {
271 break;
272 }
273 if (upperEnergy < (*etaiter).first) break; //energy diff too high
274 //the shower is OK, including it to the average
275 rezZ += (*etaiter).second.getZSize();
276 actualNumFS++;
277 }
278 etaiter = etait;
279 if (etaiter != (*libit).second.begin()) {
280 double lowerEnergy = (*etait).first * 0.99; //we allow 1% off
281 for (int i = 0; i < spread; i++) {
282 --etaiter;
283 if (lowerEnergy > (*etaiter).first) break; //energy diff too high
284 //the shower is OK, including it to the average
285 rezZ += (*etaiter).second.getZSize();
286 actualNumFS++;
287 if (etaiter == (*libit).second.begin()) {
288 break;
289 }
290 }
291 }
292 return rezZ/actualNumFS; //average Z size
293 }

◆ getName()

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

Reimplemented from ShowerLib::IShowerLib.

Definition at line 73 of file EtaEnergyShowerLib.h.

73{ return "Eta Energy ShowerLib"; }

◆ getShower()

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

get shower for given G4 track

Implements ShowerLib::IShowerLib.

Definition at line 151 of file EtaEnergyShowerLib.cxx.

152 {
153 if (!checkEtaAndStuff(track)) return nullptr;
154
155 double eta = track->GetPosition().eta();
156
157 if ((m_onlyPositive) && (eta < 0.0)) eta = -eta;
158
159 library::const_iterator libit = m_libData.upper_bound(eta);
160
161 if (libit == m_libData.begin()) {
162 //this is really weird
163 std::cout << "Something is wrong with eta: mineta=" << m_mineta << " eta=" << eta << std::endl;
164 } else {
165 --libit;
166 }
167
168 //std::cout << "Found eta bin" << std::endl;
169
170 if ((*libit).second.empty()) {
171 std::cout << "The etabin corresponding to the eta is empty" << std::endl;
172 return nullptr;
173 }
174 double trenergy = track->GetKineticEnergy();
175 //std::cout << "Energy: " << trenergy << std::endl;
176 etabin::const_iterator etait = (*libit).second.lower_bound(trenergy);
177 if (etait == (*libit).second.end()) --etait; //if it points to the end, repoint it to the last shower in bin
178 else if (etait != (*libit).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
179 etabin::const_iterator etaitch = etait;
180 --etaitch;
181 if (((*etait).first - trenergy) > (trenergy - (*etaitch).first)) { // if the closest is the previous
182 --etait;
183 }
184 }
185 //std::cout << "Found closest energy:" << (*etait).first << std::endl;
186 if (randomShift > 0) {
187 double upperEnergy = (*etait).first * 1.01; //we allow 1% off
188 for (int i = 0; i < randomShift; i++) {
189 ++etait;
190 if (etait == (*libit).second.end()) {
191 --etait; // oops! we reached the end of the bin, going back
192 break;
193 }
194 if ((*etait).first > upperEnergy) break; //energy diff too high
195 }
196 }
197 if ((randomShift < 0)&&(etait != (*libit).second.begin())) {
198 double lowerEnergy = (*etait).first * 0.99; //we allow 1% off
199 for (int i = 0; i > randomShift; i--) {
200 --etait;
201 if (etait == (*libit).second.begin()) { // oops! we reached the beginning of the bin
202 //etait++; iterator.begin() is a perfectly normal shower, in contrary to the iterator.end(), which is not
203 break;
204 }
205 if (lowerEnergy > (*etait).first) break; //energy diff too high
206 }
207 }
208 //std::cout << "Found out energy" << std::endl;
209 //std::cout << "Shower with num hits:" << (*etait).second.size() << std::endl;
210 std::vector<EnergySpot>* outshower = new std::vector<EnergySpot>();//((*etait).second);
211 Shower::const_iterator iter;
212 //std::cout << "Created out shower" << std::endl;
213
214 float energyScale = track->GetKineticEnergy() / (*etait).first;
215 //std::cout << "Scale: " << energyScale << std::endl;
216
217 for (iter = (*etait).second.begin() /*outshower->begin()*/; iter != (*etait).second.end() /*outshower->end()*/; ++iter) {
218 EnergySpot tmp( (*iter)->GetPosition(), (*iter)->GetEnergy(), (*iter)->GetTime() );
219 tmp.SetEnergy(tmp.GetEnergy() * energyScale);
220 outshower->push_back(tmp);
221 //(*iter).SetEnergy((*iter).GetEnergy() * energyScale);
222 }
223 //std::cout << "Scaled" << std::endl;
224 if (stats != nullptr) {
225 stats->recordShowerLibUse(calcKey((*libit).first));
226 }
227 //std::cout << "Done" << std::endl;
228 return outshower;
229 }

◆ particle_id()

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

get particle tag

Definition at line 124 of file IShowerLib.h.

124{ return m_particle; }

◆ 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::EtaEnergyShowerLib::printParameters ( ) const
inlineprotectedvirtual

Implements ShowerLib::IShowerLib.

Definition at line 77 of file EtaEnergyShowerLib.h.

77{return "";}

◆ read()

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

read library from given TTree

Definition at line 410 of file EtaEnergyShowerLib.cxx.

411 {
412 /*
413 * Eta Energy library format:
414 * | x | y | z | e | time | - name of branch in TTree
415 * ------------------------------------------------------------------
416 * |num of showers| min eta for | global | global | not | - eta bin header
417 * | in eta bin | cur eta bin | eta min | eta max | used |
418 * ------------------------------------------------------------------
419 * | num of hits |shower r-size |shower z-size | truth | not | - shower header
420 * | in shower |for cont.check|for cont.check| energy | used |
421 * ------------------------------------------------------------------
422 * |x-coord of hit|y-coord of hit|z-coord of hit|dep.energy|hit time| - hit
423 */
424 int nentr = source->GetEntriesFast();
425 if (nentr < 3) return false;
426 Float_t x,y,z,e,time;
427 source->SetBranchAddress("x",&x);
428 source->SetBranchAddress("y",&y);
429 source->SetBranchAddress("z",&z);
430 source->SetBranchAddress("e",&e);
431 source->SetBranchAddress("time",&time);
432 int entr = 0;
433
434 do {
435 //read eta bin header
436 source->GetEntry(entr++); //x - nshowers, y - min eta in the current eta bin
437 int nsh = (int)(x+0.1); // +0.1 just in case - c++ has low round
438 float curEta = y;
439 etabin * curbin = &(m_libData[curEta]); //creating a new eta bin
440 m_mineta = z;
441 m_maxeta = e;
442 for(int i = 0; i < nsh; i++) {
443 //read shower header
444 source->GetEntry(entr++); //x - nhits, y - r size, z - z size, e - gen energy
445 int nhits = (int)(x+0.1);
446 float curEnergy = e;
447 Shower * shower = &((*curbin)[curEnergy]);
448 shower->setRSize(y);
449 shower->setZSize(z);
450 for(int j = 0; j < nhits; j++) {
451 source->GetEntry(entr++); //variables mean what the name suggests
452 shower->push_back(new ShowerEnergySpot(G4ThreeVector(x,y,z),e,time));
453 }
454 }
455 } while (entr < nentr);
456
457 if (entr != nentr) {
458 return false;
459 }
460
461 m_filled = true;
462 if (m_mineta < 0) m_onlyPositive = false;
463 else m_onlyPositive = true;
464 return true;
465 }
#define y
#define x
#define z
std::map< float, Shower > etabin
time(flags, cells_name, *args, **kw)

◆ readFromROOTFile()

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

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

Definition at line 36 of file EtaEnergyShowerLib.cxx.

37 {
38 TParameter<int>* ver;
39 ver = (TParameter<int>*)source->Get("version");
40
41 if ((ver == nullptr) || (ver->GetVal() != LIB_VERSION)) return nullptr; //Eta Energy library header = 1
42
43 TTree* TTreeMeta = (TTree*)source->Get("meta");
44 TTree* TTreeLib = (TTree*)source->Get("library");
45
46 if ((TTreeMeta == nullptr) || (TTreeLib == nullptr)) return nullptr;
47
48 std::cout << "EtaEnergyShowerLib header found." << std::endl;
49
51
52 if (!(newlib->readMeta(TTreeMeta)) || !(newlib->read(TTreeLib))) {
53 delete newlib;
54 std::cout << "EtaEnergyShowerLib read unsuccessful." << std::endl;
55 return nullptr;
56 }
57
58 return newlib;
59
60 }

◆ 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

◆ readStructure()

bool ShowerLib::EtaEnergyShowerLib::readStructure ( std::vector< float > & structure)
private

Definition at line 516 of file EtaEnergyShowerLib.cxx.

517 {
518 std::vector<float>::const_iterator iter;
519
520 for (iter = structure.begin(); iter != structure.end(); ++iter) {
521 m_libData[(*iter)];
522 }
523
524 return true;
525 }

◆ 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::EtaEnergyShowerLib::storeShower ( HepMC::ConstGenParticlePtr genParticle,
const Shower * shower )
virtual

store shower in the library

Implements ShowerLib::IShowerLib.

Definition at line 359 of file EtaEnergyShowerLib.cxx.

360 {
361 if (m_filled) {
362 std::cout << "ERROR: filled" << std::endl;
363 return false;
364 }
365
366 double eta = genParticle->production_vertex()->position().eta();//momentum().eta();
367
368 if ((m_onlyPositive) && (eta < 0.0)) eta = -eta;
369
370 if ( (eta < m_mineta) || (eta > m_maxeta) ) {
371 std::cout << "ERROR: eta is outside: " << m_mineta << " << " << m_maxeta << " : " << eta << std::endl;
372 return false;
373 }
374 if ( genParticle->pdg_id() != m_particle ) {
375 std::cout << "ERROR: wrong pdgcode: " << m_particle << " != " << genParticle->pdg_id() << std::endl;
376 return false;
377 }
378
379 library::iterator libit = m_libData.upper_bound(eta);
380 if (libit == m_libData.begin()) {
381 //this is really weird
382 std::cout << "Something is wrong with eta: mineta=" << m_mineta << " eta=" << eta << std::endl;
383 } else {
384 --libit;
385 }
386 (*libit).second.insert(etabin::value_type(genParticle->momentum().e(),(*shower)));
387 return true;
388 }

◆ write()

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

write library to given TTree

Definition at line 467 of file EtaEnergyShowerLib.cxx.

468 {
469 /*
470 * Eta Energy library format:
471 * | x | y | z | e | time | - name of branch in TTree
472 * ------------------------------------------------------------------
473 * |num of showers| min eta for | global | global | not | - eta bin header
474 * | in eta bin | cur eta bin | eta min | eta max | used |
475 * ------------------------------------------------------------------
476 * | num of hits |shower r-size |shower z-size | truth | not | - shower header
477 * | in shower |for cont.check|for cont.check| energy | used |
478 * ------------------------------------------------------------------
479 * |x-coord of hit|y-coord of hit|z-coord of hit|dep.energy|hit time| - hit
480 */
481 Float_t x,y,z,e,time;
482 dest->Branch("x",&x);
483 dest->Branch("y",&y);
484 dest->Branch("z",&z);
485 dest->Branch("e",&e);
486 dest->Branch("time",&time);
487 library::const_iterator libit;
488 for (libit = m_libData.begin(); libit != m_libData.end(); ++libit) {
489 x = (*libit).second.size();
490 y = (*libit).first;
491 z = m_mineta;
492 e = m_maxeta;
493 dest->Fill(); //eta bin header
494 etabin::const_iterator etait;
495 for (etait = (*libit).second.begin(); etait != (*libit).second.end(); ++etait) {
496 x = (*etait).second.size();
497 y = (*etait).second.getRSize();
498 z = (*etait).second.getZSize();
499 e = (*etait).first;
500 dest->Fill(); //shower header
501 Shower::const_iterator iter;
502 for (iter = (*etait).second.begin(); iter != (*etait).second.end(); ++iter) {
503 x = (*iter)->GetPosition().x();
504 y = (*iter)->GetPosition().y();
505 z = (*iter)->GetPosition().z();
506 e = (*iter)->GetEnergy();
507 time = (*iter)->GetTime();
508 dest->Fill();
509 }
510 }
511 }
512 //dest->Write();
513 return true;
514 }

◆ 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::EtaEnergyShowerLib::writeToROOT ( TFile * dest)
virtual

write library to ROOT file

Implements ShowerLib::IShowerLib.

Definition at line 390 of file EtaEnergyShowerLib.cxx.

391 {
392 if (m_libData.empty()) return false;
393 TParameter<int> ver("version",LIB_VERSION);
394
395 dest->WriteObject(&ver,"version");
396
397 TTree TTreeMeta;
398 TTree TTreeLib;
399
400 write(&TTreeLib);
401 writeMeta(&TTreeMeta);
402
403 dest->WriteObject(&TTreeLib,"library");
404 dest->WriteObject(&TTreeMeta,"meta");
405
406 return true;
407 }
bool write(TTree *dest) const
write library to given TTree
bool writeMeta(TTree *dest) const
write metadata to the 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::EtaEnergyShowerLib::m_libData
private

Definition at line 97 of file EtaEnergyShowerLib.h.

◆ m_maxeta

float ShowerLib::EtaEnergyShowerLib::m_maxeta
private

Definition at line 92 of file EtaEnergyShowerLib.h.

◆ m_mineta

float ShowerLib::EtaEnergyShowerLib::m_mineta
private

Definition at line 92 of file EtaEnergyShowerLib.h.

◆ m_onlyPositive

bool ShowerLib::EtaEnergyShowerLib::m_onlyPositive
private

Definition at line 98 of file EtaEnergyShowerLib.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: