17#include "Randomize.hh"
22 : base_class(name,svc)
25 enum DETECTOR {EMB=100000,EMEC=200000,FCAL1=300000,FCAL2=400000,FCAL3=500000,HECLOC=600000,HEC=700000};
40 std::vector<std::string> ignoredLibraryFiles{};
44 if (resolvedFilename.empty()) {
45 ATH_MSG_WARNING(
"Could not resolve input filename " << (fileName) <<
". Ignoring!");
46 ignoredLibraryFiles.push_back(fileName);
49 ATH_MSG_INFO(
"Resolving input filename to " << resolvedFilename);
52 TFile
rootfile(resolvedFilename.c_str(),
"READ");
55 ATH_MSG_WARNING(
"File " << resolvedFilename <<
" is not a valid ROOT file");
56 ignoredLibraryFiles.push_back(fileName);
66 if (library ==
nullptr) {
67 ATH_MSG_WARNING(
"File " << resolvedFilename <<
" is not a valid library file");
68 ignoredLibraryFiles.push_back(fileName);
73 ATH_MSG_WARNING(
"Library " << resolvedFilename <<
" is produced for unknown detector: " << library->
detector());
74 ignoredLibraryFiles.push_back(fileName);
79 std::stringstream location;
96 ATH_MSG_ERROR(
"No library files found. Please check the configuration of this job.");
97 return StatusCode::FAILURE;
100 if (!ignoredLibraryFiles.empty() ) {
101 for (
const std::string& fileName : ignoredLibraryFiles) {
102 ATH_MSG_ERROR(
"Failed to create a library from filename: " << (fileName));
104 ATH_MSG_ERROR(
"Some library filenames were invalid. Please check the configuration of this job.");
105 return StatusCode::FAILURE;
110#ifdef DEBUG_FrozenShowers
114 ATH_MSG_INFO(
"Shower library successfully initialized.");
116 return StatusCode::SUCCESS;
124 libmap::const_iterator iter;
128 ATH_MSG_INFO(std::endl << (*iter).second->statistics());
132 ATH_MSG_INFO(
"No statistics available for this kind of library");
134 delete (*iter).second ;
137 return StatusCode::SUCCESS;
148 location = detectorTag + particleCode;
150 libmap::const_iterator iter =
m_libraryMap.find(location);
152 return (*iter).second;
162 if (library !=
nullptr)
return true;
172#ifdef DEBUG_FrozenShowers
173std::vector<EnergySpot>
176std::vector<EnergySpot>
183 if (library ==
nullptr) {
185 ATH_MSG_ERROR(
"No library for location: " << detectorTag <<
"/" << track.GetPrimaryTrack()->GetDefinition()->GetPDGEncoding());
186 return std::vector<EnergySpot>();
190 G4ThreeVector PositionShower = track.GetPrimaryTrack()->GetPosition();
194 randomShift = (int)(CLHEP::RandGaussZiggurat::shoot(G4Random::getTheEngine(), 0., 2.5)+0.5);
196#ifdef DEBUG_FrozenShowers
197 std::vector<EnergySpot>* shower = library->
getShower(track.GetPrimaryTrack(),
m_statisticsMap[library], randomShift);
199 std::vector<EnergySpot>* shower = library->
getShower(track.GetPrimaryTrack(),
nullptr, randomShift);
203 if (shower ==
nullptr) {
204 return std::vector<EnergySpot>();
208 G4ThreeVector DirectionShower = track.GetPrimaryTrack()->GetMomentumDirection();
211 G4double tof = track.GetPrimaryTrack()->GetGlobalTime() / Units::ns;
212 G4double time = tof - ( track.GetPrimaryTrack()->GetPosition().
mag()/Units::c_light ) / Units::ns;
214 std::vector<EnergySpot>::iterator hit;
217 for (hit = shower->begin(); hit != shower->end(); ++hit) {
218 G4ThreeVector hitpos = (*hit).GetPosition();
219 hitpos.rotateUz(DirectionShower);
220 (*hit).SetPosition(hitpos+PositionShower);
221 (*hit).SetTime((*hit).GetTime() + time);
224 if (msgSvc()->outputLevel(name()) <= MSG::VERBOSE) {
226 for (std::vector<EnergySpot>::const_iterator iter = shower->begin(); iter != shower->end(); ++iter) {
227 ATH_MSG_VERBOSE(
"EnergySpot: " << iter->GetPosition().x() <<
" " << iter->GetPosition().y() <<
" " << iter->GetPosition().z()
228 <<
" " << iter->GetEnergy() <<
" " << iter->GetTime());
232 return *std::unique_ptr< std::vector<EnergySpot> >(shower);
241 if (library ==
nullptr) {
254 if (library ==
nullptr) {
Scalar mag() const
mag method
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Wrapper to avoid constant divisions when using units.
virtual bool checkLibrary(G4int particleCode, int detectorTag) override
std::map< int, std::string > m_locations
virtual double getContainmentR(const G4FastTrack &track, int detectorTag) override
const ShowerLib::IShowerLib * getShowerLib(G4int particleCode, int detectorTag) const
get shower library from StoreGate by track (using current volume name)
virtual double getContainmentZ(const G4FastTrack &track, int detectorTag) override
LArG4ShowerLibSvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode finalize() override
libmap m_libraryMap
mapping StoreGate key to handle in StoreGate
std::map< std::string, int > m_detmap
StringArrayProperty m_fileNameList
property, list of library files
virtual StatusCode initialize() override
virtual std::vector< EnergySpot > getShower(const G4FastTrack &track, int detectorTag) const override
return list of energy depositions for given track (interface implementation)
Class for shower library shower lib interface.
virtual const std::string release() const
get Release tag
virtual int particle_id() const
get particle tag
virtual const std::string geantVersion() const
get geant version tag
virtual const std::string physicsList() const
get geant 4 physics list name
virtual std::vector< EnergySpot > * getShower(const G4Track *track, ShowerLibStatistics *stats, int randomShift) const =0
get shower for given G4 track
virtual double getContainmentR(const G4Track *track) const =0
get average lateral spread of the showers for the given energy
virtual double getContainmentZ(const G4Track *track) const =0
get average length of showers for the given energy
virtual const std::string detector() const
get detector tag
static std::vector< std::string > rootfile
IShowerLib * iterateTTree(TFile *fname)