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

Class for shower library shower lib. More...

#include <FCALDistEtaEnergyShowerLib.h>

Inheritance diagram for ShowerLib::FCALDistEtaEnergyShowerLib:
Collaboration diagram for ShowerLib::FCALDistEtaEnergyShowerLib:

Public Member Functions

virtual ~FCALDistEtaEnergyShowerLib ()
 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, Showerdistbin
typedef std::map< float, distbinetabin
typedef std::map< float, etabinlibrary

Private Member Functions

 FCALDistEtaEnergyShowerLib ()
bool read (TTree *source)
 read library from given TTree
bool write (TTree *dest) const
 write library to given TTree
bool readStructure (std::map< float, std::vector< float > > &structure)
float distance (double x, double y) const

Private Attributes

library m_libData
double m_xrodcent
double m_yrodcent
double m_step
bool m_compat

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

Definition at line 35 of file FCALDistEtaEnergyShowerLib.h.

Member Typedef Documentation

◆ distbin

typedef std::map<float,Shower> ShowerLib::FCALDistEtaEnergyShowerLib::distbin
private

Definition at line 101 of file FCALDistEtaEnergyShowerLib.h.

◆ etabin

typedef std::map<float,distbin> ShowerLib::FCALDistEtaEnergyShowerLib::etabin
private

Definition at line 102 of file FCALDistEtaEnergyShowerLib.h.

◆ library

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

Definition at line 103 of file FCALDistEtaEnergyShowerLib.h.

Constructor & Destructor Documentation

◆ ~FCALDistEtaEnergyShowerLib()

virtual ShowerLib::FCALDistEtaEnergyShowerLib::~FCALDistEtaEnergyShowerLib ( )
inlinevirtual

default destructor

Definition at line 46 of file FCALDistEtaEnergyShowerLib.h.

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

◆ FCALDistEtaEnergyShowerLib()

ShowerLib::FCALDistEtaEnergyShowerLib::FCALDistEtaEnergyShowerLib ( )
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

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

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

Definition at line 94 of file FCALDistEtaEnergyShowerLib.cxx.

95 {
96 /*
97 * Eta Energy Structure format:
98 *
99 * VER PART DET
100 * XRODCENT YRODCENT STEP
101 * ETA1 DIST1 DIST2 ...
102 * ETA2 DIST1 DIST2 ...
103 * ...
104 * END
105 * COMMENT
106 *
107 * where
108 *
109 * VER == 5
110 * DIST(N+1) > DIST(N)
111 * DIST(N) >= 0
112 * First DIST is the beginning of the lib. If not zero, zero will be added
113 * Last DIST is the end of the lib. If less then 4.5, 4.5 will be added
114 */
115 std::ifstream filestr(inputFile.c_str(),std::ios::in);
116
117
118 if (!filestr.is_open()) {
119 std::cout << "FCALDistEtaEnergyShowerLib " << inputFile << ": bad file!" << std::endl;
120 return nullptr;
121 }
122
123 std::string instr;
124 std::getline(filestr,instr);
125
126 int ver;
127 int part;
128 std::string det;
129
130 {
131 std::stringstream ss(instr);
132
133 ss >> ver;
134
135#ifndef __FSLIB_NO_BACKWARD_COMPAT__
136 if (ver == LIB_VERSION_OLD) {
137 std::cout << "FCALDistEtaEnergyShowerLib: you are trying to create the old version of this library. Use the new one." << std::endl;
138 return nullptr;
139 }
140#endif
141 if (ver != LIB_VERSION) {
142 return nullptr;
143 }
144
145 ss >> part >> det;
146 }
147
148 std::getline(filestr,instr);
149 double xrodcent, yrodcent,step;
150 {
151 std::stringstream ss(instr);
152 ss >> xrodcent >> yrodcent >> step;
153 }
154
155 std::map<float,std::vector<float> > libstruct;
156
157 float etaold = 0;
158 std::getline(filestr,instr);
159 while (instr != "END") {
160
161 std::stringstream ss(instr);
162
163 float eta;
164 ss >> eta;
165
166 if (etaold == 0) {
167 if (eta > 3.0001) {
168 std::cout << "First eta should be 3.0 (have " << eta << ")" << std::endl;
169 return nullptr;
170 }
171 eta = 3.0;
172 } else if (eta <= etaold) {
173 std::cout << "eta is not correct: " << eta << "<=" << etaold << std::endl;
174 return nullptr;
175 }
176 etaold = eta;
177
178 std::vector<float> * distlist = &(libstruct[eta]);
179
180 float dist;
181 float distold;
182
183 ss >> dist;
184
185 if (ss.fail()) {
186 std::cout << "file reading failed! (not enough data)" << std::endl;
187 return nullptr;
188 }
189
190 if (dist != 0.) {
191 if (dist < 0) {
192 std::cout << "no negative dists allowed (" << eta << ")" << std::endl;
193 return nullptr;
194 }
195 distlist->push_back(0.);
196 }
197
198 distlist->push_back(dist);
199 distold = dist;
200
201 float maxdist = step/sqrt(3);
202
203 while (!ss.eof()) {
204 ss >> dist;
205 if ((ss.fail()) || (dist <= distold)) {
206 std::cout << "screwed dists! (" << dist << "<=" << distold << ")" << std::endl;
207 return nullptr;
208 }
209 if (dist < maxdist) {
210 distlist->push_back(dist);
211 } else if (dist >= maxdist) {
212 std::cout << "dist can't be bigger than " << maxdist << " (" << dist << "). ignored" << std::endl;
213 }
214 distold = dist;
215 }
216 std::getline(filestr,instr);
217 if (filestr.fail()) {
218 std::cout << "file reading failed! (not enough data)" << std::endl;
219 return nullptr;
220 }
221 }
222
223 //if (etalist.back() < 4.5) etalist.push_back(4.5);
224
226 if (!newlib->readStructure(libstruct)) {
227 std::cout << "this structure is not valid" << std::endl;
228 delete newlib;
229 return nullptr;
230 }
231
232 newlib->m_detector = std::move(det);
233 newlib->m_particle = part;
234
235 newlib->m_xrodcent = xrodcent;
236 newlib->m_yrodcent = yrodcent;
237 newlib->m_step = step;
238
239 newlib->m_filled = false;
240
241 std::getline(filestr,instr);
242 newlib->m_comment = std::move(instr);
243
244 return newlib;
245 }
#define LIB_VERSION
#define LIB_VERSION_OLD
static Double_t ss

◆ createStatistics()

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

Implements ShowerLib::IShowerLib.

Definition at line 794 of file FCALDistEtaEnergyShowerLib.cxx.

795 {
796 std::map<int, std::string> names;
797 std::map<int, int> sizes;
798 for(library::const_iterator it = m_libData.begin(); it != m_libData.end(); ++it) {
799 for(etabin::const_iterator etait = (*it).second.begin(); etait != (*it).second.end(); ++etait) {
800 sizes[calcKey(it->first, etait->first)]=etait->second.size();
801 float etalow = it->first;
802 float distlow = etait->first;
803 float etahigh;
804 float disthigh;
805 library::const_iterator it_copy = it;
806 ++it_copy;
807 if (it_copy == m_libData.end()) {
808 etahigh = 9.99;
809 } else {
810 etahigh = it_copy->first;
811 }
812 etabin::const_iterator etait_copy = etait;
813 ++etait_copy;
814 if (etait_copy == (*it).second.end()) {
815 disthigh = 4.5;
816 } else {
817 disthigh = etait_copy->first;
818 }
819 std::stringstream ss;
820 ss << std::showpos << std::fixed << std::setprecision(2);
821 ss << "ETA: " << etalow << " .. " << etahigh << " DIST: " << distlow << " .. " << disthigh;
822 names[calcKey(it->first, etait->first)]= ss.str();
823 }
824 }
825 return new ShowerLibStatistics(names, sizes);
826 }
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

◆ distance()

float ShowerLib::FCALDistEtaEnergyShowerLib::distance ( double x,
double y ) const
private

Definition at line 39 of file FCALDistEtaEnergyShowerLib.cxx.

40 {
41 double stepy = m_step * sqrt(3.)/2.;
42 double dy = fmod(y-m_yrodcent,stepy);
43 int ny = int( (y-m_yrodcent)/stepy );
44 //additional half shift:
45 double dx0 = (ny % 2 )*m_step/2.;
46 double dx = fmod(x-m_xrodcent-dx0,m_step);
47 double d1 = sqrt(dx*dx+dy*dy);
48 double d2 = sqrt((m_step-dx)*(m_step-dx)+dy*dy);
49 double d3 = sqrt((m_step/2.-dx)*(m_step/2.-dx)+(stepy-dy)*(stepy-dy));
50 float dd = d1;
51 if (dd > d2) dd = d2;
52 if (dd > d3) dd = d3;
53 return dd;
54 }
#define y
#define x

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

get average lateral spread of the showers for the given energy

Implements ShowerLib::IShowerLib.

Definition at line 455 of file FCALDistEtaEnergyShowerLib.cxx.

456 {
457 if (!m_filled) {
458 std::cout << "Library is not created for production use" << std::endl;
459 return 0;
460 }
461
462 //std::cout << "Starting getShower()" << std::endl;
463
464 double x = track->GetPosition().getX();
465 double y = track->GetPosition().getY();
466
467 float dist = this->distance(x,y);
468 double eta = track->GetPosition().eta();
469 if (eta < 0) {
470 eta = -eta;
471 }
472
473 G4int particleCode = track->GetDefinition()->GetPDGEncoding();
474 if ( particleCode < 0 ) particleCode = -particleCode; // hack for positrons.
475
476 if ( particleCode != m_particle ) {
477 std::cout << "wrong particle: " << particleCode << "!=" << m_particle << std::endl;
478 return 0;
479 }
480 if (eta < 3.0) {
481 std::cout << "wrong eta: |eta|=" << eta << " is not inside FCAL" << std::endl;
482 return 0;
483 }
484
485 library::const_iterator libit = m_libData.upper_bound(eta);
486 if (libit == m_libData.begin()) {
487 //this is really weird
488 std::cout << "Something is wrong with eta: |eta|=" << eta << std::endl;
489 } else {
490 --libit;
491 }
492
493 etabin::const_iterator etait = (*libit).second.upper_bound(dist);
494 if (etait == (*libit).second.begin()) {
495 //this is really weird
496 std::cout << "Something is wrong with dist: x=" << x << " y=" << y << " dist=" << dist << std::endl;
497 } else {
498 --etait;
499 }
500
501 //std::cout << "Found eta bin" << std::endl;
502
503 if ((*etait).second.empty()) {
504 std::cout << "The etabin corresponding to the eta is empty" << std::endl;
505 return 0;
506 }
507 double trenergy = track->GetKineticEnergy();
508 //std::cout << "Energy: " << trenergy << std::endl;
509 distbin::const_iterator distit = (*etait).second.lower_bound(trenergy);
510 if (distit == (*etait).second.end()) --distit; //if it points to the end, repoint it to the last shower in bin
511 else if (distit != (*etait).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
512 distbin::const_iterator distitch = distit;
513 --distitch;
514 if (((*distit).first - trenergy) > (trenergy - (*distitch).first)) { // the closest is the previous
515 --distit;
516 }
517 }
518 //std::cout << "Found closest energy:" << (*etait).first << std::endl;
519 double rezR = (*distit).second.getRSize();
520 distbin::const_iterator distiter = distit;
521 int actualNumFS = 1;
522 int spread = 2; //will calculate average Z for 5 showers max ( -2 .. 0 .. +2 )
523 double upperEnergy = (*distit).first * 1.01; //we allow 1% off
524 for (int i = 0; i < spread; i++) {
525 ++distiter;
526 if (distiter == (*etait).second.end()) {
527 break;
528 }
529 if (upperEnergy < (*distiter).first) break; //energy diff too high
530 //the shower is OK, including it to the average
531 rezR += (*distiter).second.getRSize();
532 actualNumFS++;
533 }
534 distiter = distit;
535 if (distiter != (*etait).second.begin()) {
536 double lowerEnergy = (*distit).first * 0.99; //we allow 1% off
537 for (int i = 0; i < spread; i++) {
538 --distiter;
539 if (lowerEnergy > (*distiter).first) break; //energy diff too high
540 //the shower is OK, including it to the average
541 rezR += (*distiter).second.getRSize();
542 actualNumFS++;
543 if (distiter == (*etait).second.begin()) {
544 break;
545 }
546 }
547 }
548 return rezR/actualNumFS; //average Z size
549 }
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

◆ getContainmentZ()

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

get average length of showers for the given energy

Implements ShowerLib::IShowerLib.

Definition at line 359 of file FCALDistEtaEnergyShowerLib.cxx.

360 {
361 if (!m_filled) {
362 std::cout << "Library is not created for production use" << std::endl;
363 return 0;
364 }
365
366 //std::cout << "Starting getShower()" << std::endl;
367
368 double x = track->GetPosition().getX();
369 double y = track->GetPosition().getY();
370
371 float dist = this->distance(x,y);
372 double eta = track->GetPosition().eta();
373 if (eta < 0) {
374 eta = -eta;
375 }
376
377 G4int particleCode = track->GetDefinition()->GetPDGEncoding();
378 if ( particleCode < 0 ) particleCode = -particleCode; // hack for positrons.
379
380 if ( particleCode != m_particle ) {
381 std::cout << "wrong particle: " << particleCode << "!=" << m_particle << std::endl;
382 return 0;
383 }
384 if (eta < 3.0) {
385 std::cout << "wrong eta: |eta|=" << eta << " is not inside FCAL" << std::endl;
386 return 0;
387 }
388
389 library::const_iterator libit = m_libData.upper_bound(eta);
390 if (libit == m_libData.begin()) {
391 //this is really weird
392 std::cout << "Something is wrong with eta: |eta|=" << eta << std::endl;
393 } else {
394 --libit;
395 }
396
397 etabin::const_iterator etait = (*libit).second.upper_bound(dist);
398 if (etait == (*libit).second.begin()) {
399 //this is really weird
400 std::cout << "Something is wrong with dist: x=" << x << " y=" << y << " dist=" << dist << std::endl;
401 } else {
402 --etait;
403 }
404
405 //std::cout << "Found eta bin" << std::endl;
406
407 if ((*etait).second.empty()) {
408 std::cout << "The etabin corresponding to the eta is empty" << std::endl;
409 return 0;
410 }
411 double trenergy = track->GetKineticEnergy();
412 //std::cout << "Energy: " << trenergy << std::endl;
413 distbin::const_iterator distit = (*etait).second.lower_bound(trenergy);
414 if (distit == (*etait).second.end()) --distit; //if it points to the end, repoint it to the last shower in bin
415 else if (distit != (*etait).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
416 distbin::const_iterator distitch = distit;
417 --distitch;
418 if (((*distit).first - trenergy) > (trenergy - (*distitch).first)) { // the closest is the previous
419 --distit;
420 }
421 }
422 //std::cout << "Found closest energy:" << (*etait).first << std::endl;
423 double rezZ = (*distit).second.getZSize();
424 distbin::const_iterator distiter = distit;
425 int actualNumFS = 1;
426 int spread = 2; //will calculate average Z for 5 showers max ( -2 .. 0 .. +2 )
427 double upperEnergy = (*distit).first * 1.01; //we allow 1% off
428 for (int i = 0; i < spread; i++) {
429 ++distiter;
430 if (distiter == (*etait).second.end()) {
431 break;
432 }
433 if (upperEnergy < (*distiter).first) break; //energy diff too high
434 //the shower is OK, including it to the average
435 rezZ += (*distiter).second.getZSize();
436 actualNumFS++;
437 }
438 distiter = distit;
439 if (distiter != (*etait).second.begin()) {
440 double lowerEnergy = (*distit).first * 0.99; //we allow 1% off
441 for (int i = 0; i < spread; i++) {
442 --distiter;
443 if (lowerEnergy > (*distiter).first) break; //energy diff too high
444 //the shower is OK, including it to the average
445 rezZ += (*distiter).second.getZSize();
446 actualNumFS++;
447 if (distiter == (*etait).second.begin()) {
448 break;
449 }
450 }
451 }
452 return rezZ/actualNumFS; //average Z size
453 }

◆ getName()

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

Reimplemented from ShowerLib::IShowerLib.

Definition at line 76 of file FCALDistEtaEnergyShowerLib.h.

76{ return "FCALDist Eta Energy ShowerLib"; }

◆ getShower()

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

get shower for given G4 track

Implements ShowerLib::IShowerLib.

Definition at line 247 of file FCALDistEtaEnergyShowerLib.cxx.

248 {
249 if (!m_filled) {
250 std::cout << "Library is not created for production use" << std::endl;
251 return nullptr;
252 }
253
254 //std::cout << "Starting getShower()" << std::endl;
255
256 double x = track->GetPosition().getX();
257 double y = track->GetPosition().getY();
258
259 float dist = this->distance(x,y);
260 double eta = track->GetPosition().eta();
261 if (eta < 0) {
262 eta = -eta;
263 }
264
265 G4int particleCode = track->GetDefinition()->GetPDGEncoding();
266 if ( particleCode < 0 ) particleCode = -particleCode; // hack for positrons.
267
268 if ( particleCode != m_particle ) {
269 std::cout << "wrong particle: " << particleCode << "!=" << m_particle << std::endl;
270 return nullptr;
271 }
272 if (eta < 3.0) {
273 std::cout << "wrong eta: |eta|=" << eta << " is not inside FCAL" << std::endl;
274 return nullptr;
275 }
276
277 //std::cout << "Extracted particle parameters: " << eta << std::endl;
278
279 library::const_iterator libit = m_libData.upper_bound(eta);
280 if (libit == m_libData.begin()) {
281 //this is really weird
282 std::cout << "Something is wrong with eta: |eta|=" << eta << std::endl;
283 } else {
284 --libit;
285 }
286
287 etabin::const_iterator etait = (*libit).second.upper_bound(dist);
288
289 if (etait == (*libit).second.begin()) {
290 //this is really weird
291 std::cout << "Something is wrong with dist: x=" << x << " y=" << y << " dist=" << dist << std::endl;
292 } else {
293 --etait;
294 }
295
296 //std::cout << "Found eta bin" << std::endl;
297
298 if ((*etait).second.empty()) {
299 std::cout << "The bin corresponding to the eta/dist pair is empty" << std::endl;
300 return nullptr;
301 }
302 double trenergy = track->GetKineticEnergy();
303 //std::cout << "Energy: " << trenergy << std::endl;
304 distbin::const_iterator distit = (*etait).second.lower_bound(trenergy);
305 if (distit == (*etait).second.end()) --distit; //if it points to the end, repoint it to the last shower in bin
306 else if (distit != (*etait).second.begin()) { //find the closest energy. it's either found item or previous (if there is a previous)
307 distbin::const_iterator distitch = distit;
308 --distitch;
309 if (((*distit).first - trenergy) > (trenergy - (*distitch).first)) { // the closest is the previous
310 --distit;
311 }
312 }
313 //std::cout << "Found closest energy:" << (*distit).first << std::endl;
314 if (randomShift > 0) {
315 double upperEnergy = (*distit).first * 1.01; //we allow 1% off
316 for (int i = 0; i < randomShift; i++) {
317 ++distit;
318 if (distit == (*etait).second.end()) {
319 --distit;
320 break;
321 }
322 if ((*distit).first > upperEnergy) break; //energy diff too high
323 }
324 }
325 if ((randomShift < 0)&&(distit != (*etait).second.begin())) {
326 double lowerEnergy = (*distit).first * 0.99; //we allow 1% off
327 for (int i = 0; i > randomShift; i--) {
328 --distit;
329 if (distit == (*etait).second.begin()) {
330 //distit++;
331 break;
332 }
333 if (lowerEnergy > (*distit).first) break; //energy diff too high
334 }
335 }
336 //std::cout << "Found out energy" << std::endl;
337 //std::cout << "Shower with num hits:" << (*etait).second.size() << std::endl;
338 std::vector<EnergySpot>* outshower = new std::vector<EnergySpot>();//((*etait).second);
339 Shower::const_iterator iter;
340 //std::cout << "Created out shower" << std::endl;
341
342 float energyScale = track->GetKineticEnergy() / (*distit).first;
343 //std::cout << "Scale: " << energyScale << std::endl;
344
345 for (iter = (*distit).second.begin() /*outshower->begin()*/; iter != (*distit).second.end() /*outshower->end()*/; ++iter) {
346 EnergySpot tmp( (*iter)->GetPosition(), (*iter)->GetEnergy(), (*iter)->GetTime() );
347 tmp.SetEnergy(tmp.GetEnergy() * energyScale);
348 outshower->push_back(tmp);
349 //(*iter).SetEnergy((*iter).GetEnergy() * energyScale);
350 }
351 //std::cout << "Scaled" << std::endl;
352 if (stats != nullptr) {
353 stats->recordShowerLibUse(calcKey((*libit).first,(*etait).first));
354 }
355 //std::cout << "Done" << std::endl;
356 return outshower;
357 }

◆ 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()

const std::string ShowerLib::FCALDistEtaEnergyShowerLib::printParameters ( ) const
protectedvirtual

Implements ShowerLib::IShowerLib.

Definition at line 771 of file FCALDistEtaEnergyShowerLib.cxx.

772 {
773 std::stringstream ss;
774 ss << std::fixed << std::setprecision(3);
775 ss << "Distance calculator parameters: xrod_cent=" << m_xrodcent << " yrod_cent=" << m_yrodcent << " step=" << m_step;
776 return ss.str();
777 }

◆ read()

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

read library from given TTree

Definition at line 615 of file FCALDistEtaEnergyShowerLib.cxx.

616 {
617 /*
618 * Dist Energy library format:
619 * | x | y | z | e | time | - name of branch in TTree
620 * ------------------------------------------------------------------
621 * | xrod cent | yrod cent |step (roddist)| not | not | - library header
622 * | (parameter) | (parameter) | (parameter) | used | used |
623 * ------------------------------------------------------------------
624 * |num of distbin| min eta for | not | not | not | - eta bin header
625 * | in eta bin | cur eta bin | used | used | used |
626 * ------------------------------------------------------------------
627 * |num of showers| min dist for | not | not | not | - dist bin header
628 * | in dist bin | cur dist bin | used | used | used |
629 * ------------------------------------------------------------------
630 * | num of hits |shower r-size |shower z-size | truth | not | - shower header
631 * | in shower |for cont.check|for cont.check| energy | used |
632 * ------------------------------------------------------------------
633 * |x-coord of hit|y-coord of hit|z-coord of hit|dep.energy|hit time| - hit
634 */
635 int nentr = source->GetEntriesFast();
636 if (nentr < 3) return false;
637 Float_t x,y,z,e,time;
638 source->SetBranchAddress("x",&x);
639 source->SetBranchAddress("y",&y);
640 source->SetBranchAddress("z",&z);
641 source->SetBranchAddress("e",&e);
642 source->SetBranchAddress("time",&time);
643 int entr = 0;
644
645#ifndef __FSLIB_NO_BACKWARD_COMPAT__
646 if (m_compat == false) {
647#endif
648 source->GetEntry(entr++);
649 m_xrodcent = x;
650 m_yrodcent = y;
651 m_step = z;
652#ifndef __FSLIB_NO_BACKWARD_COMPAT__
653 } else {
654 m_xrodcent = -748.12;
655 m_yrodcent = -717.719;
656 m_step = 7.5;
657 }
658#endif
659
660
661 do {
662 //read eta bin header
663 source->GetEntry(entr++); //x - ndistbins, y - min eta in the current eta bin
664 int ndists = (int)(x+0.1); // +0.1 just in case - c++ has low round
665 float curEta = y;
666 etabin * curetabin = &(m_libData[curEta]); //creating a new eta bin
667
668 for (int i = 0; i < ndists; i++) {
669 source->GetEntry(entr++); //x - nshowers, y - min dist in the current dist bin
670 int nsh = (int)(x+0.1); // +0.1 just in case - c++ has low round
671 float curDist = y;
672 distbin * curbin = &((*curetabin)[curDist]); //creating a new dist bin
673 for(int j = 0; j < nsh; j++) {
674 //read shower header
675 source->GetEntry(entr++); //x - nhits, y - r size, z - z size, e - gen energy
676 int nhits = (int)(x+0.1);
677 float curEnergy = e;
678 Shower * shower = &((*curbin)[curEnergy]);
679 shower->setRSize(y);
680 shower->setZSize(z);
681 for(int k = 0; k < nhits; k++) {
682 source->GetEntry(entr++); //variables mean what the name suggests
683 shower->push_back(new ShowerEnergySpot(G4ThreeVector(x,y,z),e,time));
684 }
685 }
686 }
687 } while (entr < nentr);
688
689 if (entr != nentr) {
690 return false;
691 }
692
693 m_filled = true;
694 return true;
695 }
#define z
time(flags, cells_name, *args, **kw)

◆ readFromROOTFile()

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

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

Definition at line 56 of file FCALDistEtaEnergyShowerLib.cxx.

57 {
58
59
60 TParameter<int>* ver;
61 ver = (TParameter<int>*)source->Get("version");
62
63 if ((ver == nullptr) || (ver->GetVal() != LIB_VERSION))
64#ifndef __FSLIB_NO_BACKWARD_COMPAT__
65 if ((ver == nullptr) || (ver->GetVal() != LIB_VERSION_OLD))
66#endif
67 return nullptr;
68
69 TTree* TTreeMeta = (TTree*)source->Get("meta");
70 TTree* TTreeLib = (TTree*)source->Get("library");
71
72 if ((TTreeMeta == nullptr) || (TTreeLib == nullptr)) return nullptr;
73
74 std::cout << "FCALDistEtaEnergyShowerLib header found." << std::endl;
75
77#ifndef __FSLIB_NO_BACKWARD_COMPAT__
78 if (ver->GetVal() == LIB_VERSION_OLD)
79 newlib->m_compat=true;
80 else
81 newlib->m_compat=false;
82#endif
83
84 if (!(newlib->readMeta(TTreeMeta)) || !(newlib->read(TTreeLib))) {
85 delete newlib;
86 std::cout << "FCALDistEtaEnergyShowerLib read unsuccessful." << std::endl;
87 return nullptr;
88 }
89
90 return newlib;
91
92 }

◆ 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::FCALDistEtaEnergyShowerLib::readStructure ( std::map< float, std::vector< float > > & structure)
private

Definition at line 779 of file FCALDistEtaEnergyShowerLib.cxx.

780 {
781 std::map<float, std::vector<float> >::const_iterator iter;
782
783 for (iter = structure.begin(); iter != structure.end(); ++iter) {
784 m_libData[(*iter).first];
785 std::vector<float>::const_iterator inneriter;
786 for (inneriter = (*iter).second.begin(); inneriter != (*iter).second.end(); ++inneriter) {
787 (m_libData[(*iter).first])[(*inneriter)];
788 }
789 }
790
791 return true;
792 }

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

store shower in the library

Implements ShowerLib::IShowerLib.

Definition at line 551 of file FCALDistEtaEnergyShowerLib.cxx.

552 {
553 if (m_filled) {
554 std::cout << "ERROR: filled" << std::endl;
555 return false;
556 }
557
558 double x = genParticle->production_vertex()->position().x();
559 double y = genParticle->production_vertex()->position().y();
560
561 float dist = this->distance(x,y);
562 double eta = genParticle->production_vertex()->position().eta();//momentum().eta();
563 if (eta < 0) {
564 eta = -eta;
565 }
566
567 if ( genParticle->pdg_id() != m_particle ) {
568 std::cout << "ERROR: wrong pdgcode: " << m_particle << " != " << genParticle->pdg_id() << std::endl;
569 return false;
570 }
571 if (eta < 3.0) {
572 std::cout << "wrong eta: |eta|=" << eta << " is not inside FCAL" << std::endl;
573 return 0;
574 }
575
576 library::iterator libit = m_libData.upper_bound(eta);
577 if (libit == m_libData.begin()) {
578 //this is really weird
579 std::cout << "Something is wrong with eta: |eta|=" << eta << std::endl;
580 } else {
581 --libit;
582 }
583
584 etabin::iterator etait = (*libit).second.upper_bound(dist);
585 if (etait == (*libit).second.begin()) {
586 //this is really weird
587 std::cout << "Something is wrong with dist: x=" << x << " y=" << y << " dist=" << dist << std::endl;
588 } else {
589 --etait;
590 }
591 (*etait).second.insert(distbin::value_type(genParticle->momentum().e(),(*shower)));
592 return true;
593 }

◆ write()

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

write library to given TTree

Definition at line 697 of file FCALDistEtaEnergyShowerLib.cxx.

698 {
699 /*
700 * Dist Energy library format:
701 * | x | y | z | e | time | - name of branch in TTree
702 * ------------------------------------------------------------------
703 * | xrod cent | yrod cent |step (roddist)| not | not | - library header
704 * | (parameter) | (parameter) | (parameter) | used | used |
705 * ------------------------------------------------------------------
706 * |num of distbin| min eta for | not | not | not | - eta bin header
707 * | in eta bin | cur eta bin | used | used | used |
708 * ------------------------------------------------------------------
709 * |num of showers| min dist for | not | not | not | - dist bin header
710 * | in dist bin | cur dist bin | used | used | used |
711 * ------------------------------------------------------------------
712 * | num of hits |shower r-size |shower z-size | truth | not | - shower header
713 * | in shower |for cont.check|for cont.check| energy | used |
714 * ------------------------------------------------------------------
715 * |x-coord of hit|y-coord of hit|z-coord of hit|dep.energy|hit time| - hit
716 */
717 Float_t x,y,z,e,time;
718 dest->Branch("x",&x);
719 dest->Branch("y",&y);
720 dest->Branch("z",&z);
721 dest->Branch("e",&e);
722 dest->Branch("time",&time);
723
724 x = m_xrodcent;
725 y = m_yrodcent;
726 z = m_step;
727 e = 0;
728 time = 0;
729 dest->Fill();
730
731 library::const_iterator libit;
732 for (libit = m_libData.begin(); libit != m_libData.end(); ++libit) {
733 x = (*libit).second.size();
734 y = (*libit).first;
735 z = 0;
736 e = 0;
737 time = 0;
738 dest->Fill(); //eta bin header
739 etabin::const_iterator etait;
740 for (etait = (*libit).second.begin(); etait != (*libit).second.end(); ++etait) {
741 x = (*etait).second.size();
742 y = (*etait).first;
743 z = 0;
744 e = 0;
745 time = 0;
746 dest->Fill(); //eta bin header
747 distbin::const_iterator distit;
748 for (distit = (*etait).second.begin(); distit != (*etait).second.end(); ++distit) {
749 x = (*distit).second.size();
750 y = (*distit).second.getRSize();
751 z = (*distit).second.getZSize();
752 e = (*distit).first;
753 time = 0;
754 dest->Fill(); //shower header
755 Shower::const_iterator iter;
756 for (iter = (*distit).second.begin(); iter != (*distit).second.end(); ++iter) {
757 x = (*iter)->GetPosition().x();
758 y = (*iter)->GetPosition().y();
759 z = (*iter)->GetPosition().z();
760 e = (*iter)->GetEnergy();
761 time = (*iter)->GetTime();
762 dest->Fill();
763 }
764 }
765 }
766 }
767 //dest->Write();
768 return true;
769 }

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

write library to ROOT file

Implements ShowerLib::IShowerLib.

Definition at line 595 of file FCALDistEtaEnergyShowerLib.cxx.

596 {
597 if (m_libData.empty()) return false;
598 TParameter<int> ver("version",LIB_VERSION);
599
600 dest->WriteObject(&ver,"version");
601
602 TTree TTreeMeta;
603 TTree TTreeLib;
604
605 write(&TTreeLib);
606 writeMeta(&TTreeMeta);
607
608 dest->WriteObject(&TTreeLib,"library");
609 dest->WriteObject(&TTreeMeta,"meta");
610
611 return true;
612 }
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_compat

bool ShowerLib::FCALDistEtaEnergyShowerLib::m_compat
private

Definition at line 113 of file FCALDistEtaEnergyShowerLib.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::FCALDistEtaEnergyShowerLib::m_libData
private

Definition at line 105 of file FCALDistEtaEnergyShowerLib.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.

◆ m_step

double ShowerLib::FCALDistEtaEnergyShowerLib::m_step
private

Definition at line 110 of file FCALDistEtaEnergyShowerLib.h.

◆ m_xrodcent

double ShowerLib::FCALDistEtaEnergyShowerLib::m_xrodcent
private

Definition at line 108 of file FCALDistEtaEnergyShowerLib.h.

◆ m_yrodcent

double ShowerLib::FCALDistEtaEnergyShowerLib::m_yrodcent
private

Definition at line 109 of file FCALDistEtaEnergyShowerLib.h.


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