ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
LArG4ShowerLibSvc Class Reference

Class for shower library service. More...

#include <LArG4ShowerLibSvc.h>

Inheritance diagram for LArG4ShowerLibSvc:
Collaboration diagram for LArG4ShowerLibSvc:

Public Member Functions

 LArG4ShowerLibSvc (const std::string &name, ISvcLocator *svc)
 
virtual ~LArG4ShowerLibSvc ()
 
virtual StatusCode initialize ()
 
virtual StatusCode finalize ()
 
virtual bool checkLibrary (G4int particleCode, int detectorTag)
 
virtual std::vector< EnergySpotgetShower (const G4FastTrack &track, int detectorTag) const
 return list of energy depositions for given track (interface implementation) More...
 
virtual double getContainmentZ (const G4FastTrack &track, int detectorTag)
 
virtual double getContainmentR (const G4FastTrack &track, int detectorTag)
 

Private Types

typedef std::map< int, const ShowerLib::IShowerLib * > libmap
 
typedef std::map< const ShowerLib::IShowerLib *, ShowerLib::ShowerLibStatistics * > statmap
 

Private Member Functions

const ShowerLib::IShowerLibgetShowerLib (G4int particleCode, int detectorTag) const
 get shower library from StoreGate by track (using current volume name) More...
 

Private Attributes

libmap m_libraryMap
 mapping StoreGate key to handle in StoreGate More...
 
statmap m_statisticsMap
 
std::map< int, std::string > m_locations
 
std::map< std::string, int > m_detmap
 
StringArrayProperty m_fileNameList
 property, list of library files More...
 

Detailed Description

Class for shower library service.

   Converts tracks into a list of energy deposits 
   using frozen shower libraries.
Author
Wolfgang Ehrenfeld, University of Hamburg, Germany
Sasha Glazov, DESY Hamburg, Germany
Version
Id
LArG4ShowerLibSvc.h 576157 2013-12-18 16:57:49Z gsedov

Definition at line 41 of file LArG4ShowerLibSvc.h.

Member Typedef Documentation

◆ libmap

typedef std::map<int, const ShowerLib::IShowerLib*> LArG4ShowerLibSvc::libmap
private

Definition at line 68 of file LArG4ShowerLibSvc.h.

◆ statmap

Definition at line 70 of file LArG4ShowerLibSvc.h.

Constructor & Destructor Documentation

◆ LArG4ShowerLibSvc()

LArG4ShowerLibSvc::LArG4ShowerLibSvc ( const std::string &  name,
ISvcLocator *  svc 
)

Definition at line 22 of file LArG4ShowerLibSvc.cxx.

23  : base_class(name,svc)
24  , m_fileNameList()
25 {
26  declareProperty( "FileNameList", m_fileNameList, "List of filenames for direct reading" );
27 
28  /* BE SURE THIS ONE IS THE SAME AS IN LArG4FastSimSvc!!! */
29  enum DETECTOR {EMB=100000,EMEC=200000,FCAL1=300000,FCAL2=400000,FCAL3=500000,HECLOC=600000,HEC=700000};
30 
31  m_detmap["EMB"]=EMB;
32  m_detmap["EMEC"]=EMEC;
33  m_detmap["FCAL1"]=FCAL1;
34  m_detmap["FCAL2"]=FCAL2;
35  m_detmap["FCAL3"]=FCAL3;
36  m_detmap["HECLOC"]=HECLOC;
37  m_detmap["HEC"]=HEC;
38 }

◆ ~LArG4ShowerLibSvc()

LArG4ShowerLibSvc::~LArG4ShowerLibSvc ( )
virtual

Definition at line 40 of file LArG4ShowerLibSvc.cxx.

41 {
42 }

Member Function Documentation

◆ checkLibrary()

bool LArG4ShowerLibSvc::checkLibrary ( G4int  particleCode,
int  detectorTag 
)
virtual

Definition at line 155 of file LArG4ShowerLibSvc.cxx.

156 {
157  const ShowerLib::IShowerLib* library = getShowerLib(particleCode, detectorTag);
158  if (library != nullptr) return true;
159 
160  return false;
161 }

◆ finalize()

StatusCode LArG4ShowerLibSvc::finalize ( )
virtual

Definition at line 115 of file LArG4ShowerLibSvc.cxx.

116 {
117 
118  ATH_MSG_INFO("Finalizing shower library service.");
119 
120  libmap::const_iterator iter;
121 
122  for (iter = m_libraryMap.begin(); iter != m_libraryMap.end(); ++iter) {
123  ATH_MSG_INFO("Found ShowerLib at location " << m_locations[(*iter).first]);
124  ATH_MSG_INFO(std::endl << (*iter).second->statistics());
125  if (m_statisticsMap.find((*iter).second) != m_statisticsMap.end())
126  ATH_MSG_INFO(m_statisticsMap.find((*iter).second)->second->statistics());
127  else
128  ATH_MSG_INFO("No statistics available for this kind of library");
129  // delete the library:
130  delete (*iter).second ;
131  }
132 
133  return StatusCode::SUCCESS;
134 }

◆ getContainmentR()

double LArG4ShowerLibSvc::getContainmentR ( const G4FastTrack &  track,
int  detectorTag 
)
virtual

Definition at line 245 of file LArG4ShowerLibSvc.cxx.

246 {
247  // get shower lib from the map
248  const ShowerLib::IShowerLib* library = getShowerLib(track.GetPrimaryTrack()->GetDefinition()->GetPDGEncoding(), detectorTag);
249 
250  if (library == nullptr) {
251  return 0.0;
252  }
253 
254  return library->getContainmentR(track.GetPrimaryTrack());
255 }

◆ getContainmentZ()

double LArG4ShowerLibSvc::getContainmentZ ( const G4FastTrack &  track,
int  detectorTag 
)
virtual

Definition at line 232 of file LArG4ShowerLibSvc.cxx.

233 {
234  // get shower lib from the map
235  const ShowerLib::IShowerLib* library = getShowerLib(track.GetPrimaryTrack()->GetDefinition()->GetPDGEncoding(), detectorTag);
236 
237  if (library == nullptr) {
238  return 0.0;
239  }
240 
241  return library->getContainmentZ(track.GetPrimaryTrack());
242 }

◆ getShower()

std::vector< EnergySpot > LArG4ShowerLibSvc::getShower ( const G4FastTrack &  track,
int  detectorTag 
) const
virtual

return list of energy depositions for given track (interface implementation)

Definition at line 173 of file LArG4ShowerLibSvc.cxx.

175 {
176  // get shower lib from the map
177  const ShowerLib::IShowerLib* library = getShowerLib(track.GetPrimaryTrack()->GetDefinition()->GetPDGEncoding(), detectorTag);
178 
179  if (library == nullptr) {
180  // no library in map
181  ATH_MSG_ERROR("No library for location: " << detectorTag << "/" << track.GetPrimaryTrack()->GetDefinition()->GetPDGEncoding());
182  return std::vector<EnergySpot>();
183  }
184 
185  // starting point of the shower:
186  G4ThreeVector PositionShower = track.GetPrimaryTrack()->GetPosition();
187 
188  // get a shower from the library
189  int randomShift = 0;
190  randomShift = (int)(CLHEP::RandGaussZiggurat::shoot(G4Random::getTheEngine(), 0., 2.5)+0.5);
191 
192 #ifdef DEBUG_FrozenShowers
193  std::vector<EnergySpot>* shower = library->getShower(track.GetPrimaryTrack(), m_statisticsMap[library], randomShift);
194 #else
195  std::vector<EnergySpot>* shower = library->getShower(track.GetPrimaryTrack(), nullptr, randomShift);
196 #endif
197 
198 
199  if (shower == nullptr) {
200  return std::vector<EnergySpot>();
201  }
202 
203  // axis of the shower, in global reference frame:
204  G4ThreeVector DirectionShower = track.GetPrimaryTrack()->GetMomentumDirection();
205 
206  // time of the track (as in LArBarrelCalculator.cc)
207  G4double tof = track.GetPrimaryTrack()->GetGlobalTime() / Units::ns;
208  G4double time = tof - ( track.GetPrimaryTrack()->GetPosition().mag()/Units::c_light ) / Units::ns;
209 
211 
212  // Create energy spots
213  for (hit = shower->begin(); hit != shower->end(); ++hit) {
214  G4ThreeVector hitpos = (*hit).GetPosition();
215  hitpos.rotateUz(DirectionShower); // rotate the hit to the needed direction
216  (*hit).SetPosition(hitpos+PositionShower);
217  (*hit).SetTime((*hit).GetTime() + time);
218  }
219 
220  if (msgSvc()->outputLevel(name()) <= MSG::VERBOSE) {
221  ATH_MSG_VERBOSE("Prepared " << shower->size() << " EnergySpot");
222  for (std::vector<EnergySpot>::const_iterator iter = shower->begin(); iter != shower->end(); ++iter) {
223  ATH_MSG_VERBOSE("EnergySpot: " << iter->GetPosition().x() << " " << iter->GetPosition().y() << " " << iter->GetPosition().z()
224  << " " << iter->GetEnergy() << " " << iter->GetTime());
225  }
226  }
227 
228  return *std::unique_ptr< std::vector<EnergySpot> >(shower);
229 }

◆ getShowerLib()

const ShowerLib::IShowerLib * LArG4ShowerLibSvc::getShowerLib ( G4int  particleCode,
int  detectorTag 
) const
private

get shower library from StoreGate by track (using current volume name)

Definition at line 140 of file LArG4ShowerLibSvc.cxx.

141 {
142  int location;
143 
144  location = detectorTag + particleCode;
145 
146  libmap::const_iterator iter = m_libraryMap.find(location);
147  if (iter != m_libraryMap.end()) {
148  return (*iter).second;
149  }
150 
151  return nullptr;
152 }

◆ initialize()

StatusCode LArG4ShowerLibSvc::initialize ( )
virtual

Definition at line 44 of file LArG4ShowerLibSvc.cxx.

45 {
46  ATH_MSG_INFO("Initializing");
47 
48  // iterate through filenames in list
49  for (const std::string& fileName : m_fileNameList) {
50  std::string resolvedFilename = PathResolverFindCalibFile(fileName);
51  if (resolvedFilename.empty()) {
52  ATH_MSG_WARNING("Could not resolve input filename " << (fileName) << ". Ignoring!");
53  continue;
54  } else {
55  ATH_MSG_INFO("Resolving input filename to " << resolvedFilename);
56  }
57 
58  TFile rootfile(resolvedFilename.c_str(),"READ");
59 
60  if (rootfile.IsZombie()) {
61  ATH_MSG_WARNING("File " << resolvedFilename << " is not a valid ROOT file");
62  continue;
63  }
64 
65  const ShowerLib::IShowerLib* library = nullptr;
66 
67  // trying to create a library out of provided file
69 
70  // if no library can be created based on the file nullptr is returned
71  if (library == nullptr) {
72  ATH_MSG_WARNING("File " << resolvedFilename << " is not a valid library file");
73  continue;
74  }
75 
76  if (m_detmap.find(library->detector()) == m_detmap.end()) {
77  ATH_MSG_WARNING("Library " << resolvedFilename << " is produced for unknown detector: " << library->detector());
78  delete library;
79  continue;
80  }
81 
82  std::stringstream location;
83  location << library->detector() << "/" << library->particle_id();
84  int key = m_detmap.find(library->detector())->second + library->particle_id();
85 
86  // put the library into map
87  m_libraryMap[key] = library;
88  m_locations[key] = location.str();
89 
90  ATH_MSG_DEBUG("Filename: " << resolvedFilename.c_str());
91  ATH_MSG_DEBUG("Location: " << location.str());
92  ATH_MSG_DEBUG("Release: " << library->release().c_str());
93  ATH_MSG_DEBUG("Geant ver: " << library->geantVersion().c_str());
94  ATH_MSG_DEBUG("Phys list: " << library->physicsList().c_str());
95  }
96 
97  // no point in the service with no libraries
98  if (m_libraryMap.empty()) {
99  ATH_MSG_WARNING("No library files found");
100  } else {
101  ATH_MSG_INFO("List of loaded libraries:");
102  for (const auto& m : m_libraryMap) {
103  ATH_MSG_INFO(" " << m_locations[m.first] << ": " << m.second->comment());
104 #ifdef DEBUG_FrozenShowers
105  m_statisticsMap[m.second] = m.second->createStatistics();
106 #endif
107  }
108  }
109 
110  ATH_MSG_INFO("Shower library successfully initialized.");
111 
112  return StatusCode::SUCCESS;
113 }

Member Data Documentation

◆ m_detmap

std::map<std::string,int> LArG4ShowerLibSvc::m_detmap
private

Definition at line 73 of file LArG4ShowerLibSvc.h.

◆ m_fileNameList

StringArrayProperty LArG4ShowerLibSvc::m_fileNameList
private

property, list of library files

Definition at line 75 of file LArG4ShowerLibSvc.h.

◆ m_libraryMap

libmap LArG4ShowerLibSvc::m_libraryMap
private

mapping StoreGate key to handle in StoreGate

Definition at line 69 of file LArG4ShowerLibSvc.h.

◆ m_locations

std::map<int,std::string> LArG4ShowerLibSvc::m_locations
private

Definition at line 72 of file LArG4ShowerLibSvc.h.

◆ m_statisticsMap

statmap LArG4ShowerLibSvc::m_statisticsMap
private

Definition at line 71 of file LArG4ShowerLibSvc.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ShowerLib::IShowerLib::getContainmentZ
virtual double getContainmentZ(const G4Track *track) const =0
get average length of showers for the given energy
ShowerLib::IShowerLib::release
virtual const std::string release() const
get Release tag
Definition: IShowerLib.h:127
LArSamples::HEC
@ HEC
Definition: CaloId.h:26
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ShowerLib::IShowerLib::getContainmentR
virtual double getContainmentR(const G4Track *track) const =0
get average lateral spread of the showers for the given energy
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ShowerLib::IShowerLib::detector
virtual const std::string detector() const
get detector tag
Definition: IShowerLib.h:121
LArG4ShowerLibSvc::getShowerLib
const ShowerLib::IShowerLib * getShowerLib(G4int particleCode, int detectorTag) const
get shower library from StoreGate by track (using current volume name)
Definition: LArG4ShowerLibSvc.cxx:140
ShowerLib::iterateTTree
IShowerLib * iterateTTree(TFile *fname)
Definition: ShowerLibList.cxx:55
CaloCell_ID_FCS::FCAL1
@ FCAL1
Definition: FastCaloSim_CaloCell_ID.h:41
LArG4ShowerLibSvc::m_libraryMap
libmap m_libraryMap
mapping StoreGate key to handle in StoreGate
Definition: LArG4ShowerLibSvc.h:69
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
LArCalib_HVScale2NtupleConfig.rootfile
string rootfile
Definition: LArCalib_HVScale2NtupleConfig.py:74
ShowerLib::IShowerLib::particle_id
virtual int particle_id() const
get particle tag
Definition: IShowerLib.h:124
LArSamples::EMEC
@ EMEC
Definition: CaloId.h:25
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArSamples::EMB
@ EMB
Definition: CaloId.h:25
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
LArG4ShowerLibSvc::m_detmap
std::map< std::string, int > m_detmap
Definition: LArG4ShowerLibSvc.h:73
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
python.sizes.location
string location
Definition: sizes.py:11
LArG4ShowerLibSvc::m_locations
std::map< int, std::string > m_locations
Definition: LArG4ShowerLibSvc.h:72
LArG4ShowerLibSvc::m_statisticsMap
statmap m_statisticsMap
Definition: LArG4ShowerLibSvc.h:71
ShowerLib::IShowerLib
Class for shower library shower lib interface.
Definition: IShowerLib.h:40
ShowerLib::IShowerLib::getShower
virtual std::vector< EnergySpot > * getShower(const G4Track *track, ShowerLibStatistics *stats, int randomShift) const =0
get shower for given G4 track
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArG4ShowerLibSvc::m_fileNameList
StringArrayProperty m_fileNameList
property, list of library files
Definition: LArG4ShowerLibSvc.h:75
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:63
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ShowerLib::IShowerLib::geantVersion
virtual const std::string geantVersion() const
get geant version tag
Definition: IShowerLib.h:133
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
CaloCell_ID_FCS::FCAL2
@ FCAL2
Definition: FastCaloSim_CaloCell_ID.h:42
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
ShowerLib::IShowerLib::physicsList
virtual const std::string physicsList() const
get geant 4 physics list name
Definition: IShowerLib.h:136
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37