Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 167 of file LArG4ShowerLibSvc.cxx.

168 {
169  const ShowerLib::IShowerLib* library = getShowerLib(particleCode, detectorTag);
170  if (library != nullptr) return true;
171 
172  return false;
173 }

◆ finalize()

StatusCode LArG4ShowerLibSvc::finalize ( )
virtual

Definition at line 127 of file LArG4ShowerLibSvc.cxx.

128 {
129 
130  ATH_MSG_INFO("Finalizing shower library service.");
131 
132  libmap::const_iterator iter;
133 
134  for (iter = m_libraryMap.begin(); iter != m_libraryMap.end(); ++iter) {
135  ATH_MSG_INFO("Found ShowerLib at location " << m_locations[(*iter).first]);
136  ATH_MSG_INFO(std::endl << (*iter).second->statistics());
137  if (m_statisticsMap.find((*iter).second) != m_statisticsMap.end())
138  ATH_MSG_INFO(m_statisticsMap.find((*iter).second)->second->statistics());
139  else
140  ATH_MSG_INFO("No statistics available for this kind of library");
141  // delete the library:
142  delete (*iter).second ;
143  }
144 
145  return StatusCode::SUCCESS;
146 }

◆ getContainmentR()

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

Definition at line 257 of file LArG4ShowerLibSvc.cxx.

258 {
259  // get shower lib from the map
260  const ShowerLib::IShowerLib* library = getShowerLib(track.GetPrimaryTrack()->GetDefinition()->GetPDGEncoding(), detectorTag);
261 
262  if (library == nullptr) {
263  return 0.0;
264  }
265 
266  return library->getContainmentR(track.GetPrimaryTrack());
267 }

◆ getContainmentZ()

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

Definition at line 244 of file LArG4ShowerLibSvc.cxx.

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

◆ 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 185 of file LArG4ShowerLibSvc.cxx.

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

◆ 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 152 of file LArG4ShowerLibSvc.cxx.

153 {
154  int location;
155 
156  location = detectorTag + particleCode;
157 
158  libmap::const_iterator iter = m_libraryMap.find(location);
159  if (iter != m_libraryMap.end()) {
160  return (*iter).second;
161  }
162 
163  return nullptr;
164 }

◆ initialize()

StatusCode LArG4ShowerLibSvc::initialize ( )
virtual

Definition at line 44 of file LArG4ShowerLibSvc.cxx.

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

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
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:152
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:83
ShowerLib::IShowerLib::particle_id
virtual int particle_id() const
get particle tag
Definition: IShowerLib.h:124
LArSamples::EMEC
@ EMEC
Definition: CaloId.h:25
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.LArMinBiasAlgConfig.int
int
Definition: LArMinBiasAlgConfig.py:59
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:240
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
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:513
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:13
jobOptions.fileName
fileName
Definition: jobOptions.SuperChic_ALP2.py:39
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37