ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTowerGeometryCondAlg.cxx
Go to the documentation of this file.
1//Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
5#include <memory>
6#include <cstdarg>
7
8namespace {
9 std::string fmtMsg(const char* fmt,...) {
10 char buffer[1024];
11 va_list args;
12 va_start(args,fmt);
13 vsprintf(buffer,fmt,args);
14 va_end(args);
15 return std::string(buffer);
16 }
17}
18
19
21
22 ATH_CHECK(m_caloMgrKey.initialize());
23
24 ATH_CHECK(m_outputKey.initialize());
25
26 return StatusCode::SUCCESS;
27}
28
29
30StatusCode CaloTowerGeometryCondAlg::execute(const EventContext& ctx) const {
31
33 const CaloDetDescrManager* caloDDM = *caloMgrHandle;
34
35 //Set up write handle
37 if (writeHandle.isValid()) {
38 ATH_MSG_DEBUG("Found valid write handle");
39 return StatusCode::SUCCESS;
40 }
41
42 writeHandle.addDependency(caloMgrHandle);
43
44
45 std::unique_ptr<CaloTowerGeometry> towerGeo=std::make_unique<CaloTowerGeometry>(caloDDM);
46
47 //Assign properties to CaloTowerGeometry CDO:
48 towerGeo->m_towerEtaBins =m_towerEtaBins;
49 towerGeo->m_towerEtaMin =m_towerEtaMin;
50 towerGeo->m_towerEtaMax =m_towerEtaMax;
51 towerGeo->m_adjustEta =m_adjustEta;
52 towerGeo->m_towerPhiBins =m_towerPhiBins;
53 towerGeo->m_towerPhiMin =m_towerPhiMin;
54 towerGeo->m_towerPhiMax =m_towerPhiMax;
55 towerGeo->m_fcal1Xslice =m_fcal1Xslice;
56 towerGeo->m_fcal1Yslice =m_fcal1Yslice;
57 towerGeo->m_fcal2Xslice =m_fcal2Xslice;
58 towerGeo->m_fcal2Yslice =m_fcal2Yslice;
59 towerGeo->m_fcal3Xslice =m_fcal3Xslice;
60 towerGeo->m_fcal3Yslice =m_fcal3Yslice;
61
62 ATH_CHECK(towerGeo->initialize( msg() ));
63
64
65 dump(towerGeo.get()); //does nothing execept jO "TowerGridFile" or "TowerMapFile" given
66
67
68 ATH_CHECK(writeHandle.record(std::move(towerGeo)));
69 ATH_MSG_INFO("recorded new CaloTowerGeometry object with key " << writeHandle.key() << " and range " << writeHandle.getRange());
70
71 return StatusCode::SUCCESS;
72}
73
74
76
77 if (!m_towerGridFile.empty()) {
78 std::vector<std::string> logger; logger.reserve(towerGeo->m_towerBins+10);
79 logger.push_back(fmtMsg("[%s] +-------- Tower Index Mapping ---------+------------+------------+",this->name().c_str()));
80 logger.push_back(fmtMsg("[%s] | %10.10s | %10.10s | %10.10s | %10.10s | %10.10s |",this->name().c_str(),"TowerIndex", " EtaIndex ", " PhiIndex "," Eta "," Phi "));
81 logger.push_back(fmtMsg("[%s] +------------+------------+------------+------------+------------+",this->name().c_str()));
82 for ( size_t i(0); i<towerGeo->m_towerBins; ++i ) {
83 size_t etaIndex(towerGeo->etaIndexFromTowerIndex(i));
84 size_t phiIndex(towerGeo->phiIndexFromTowerIndex(i));
85 double eta(towerGeo->towerEta(i)); double phi(towerGeo->towerPhi(i));
86 logger.push_back(fmtMsg("[%s] | %5zu | %5zu | %5zu | %6.3f | %6.3f |",this->name().c_str(),i,etaIndex,phiIndex,eta,phi));
87 }
88 logger.push_back(fmtMsg("[%s] +------------+------------+------------+------------+------------+",this->name().c_str()));
89 //
90 std::ofstream logfile;
91 logfile.open(m_towerGridFile);
92 for ( const auto& mlog : logger ) {
93 logfile << mlog << std::endl;
94 }
95 logfile.close();
96 } //end if tower grid file name given
97
98
99 if (!m_towerMapFile.empty()>0) {
100 std::ofstream towerfile;
101 towerfile.open("towermap.dat");
102 auto it=towerGeo->begin();
103 unsigned cellCounter=0;
104 for (;it!=towerGeo->end();++it,++cellCounter) { //Loop over cells in cell-to-tower lookup
105 towerfile << cellCounter << ": ";
106 for (const auto& item : *it) { //
107 auto idx=std::get<0>(item);
108 double w=std::get<1>(item);
109 towerfile << " (" << idx << "," << w <<");";
110 }//end loop over towers per cell
111 towerfile << std::endl;
112 }//end loop over cells
113 towerfile.close();
114 }//end if file-name given
115
116
117 }
118
119
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
const char *const fmt
This class provides the client interface for accessing the detector description information common to...
StatusCode execute(const EventContext &ctx) const override final
Gaudi::Property< double > m_fcal3Yslice
Gaudi::Property< std::string > m_towerGridFile
Gaudi::Property< unsigned > m_towerEtaBins
Gaudi::Property< double > m_fcal2Xslice
Gaudi::Property< double > m_towerEtaMax
Gaudi::Property< bool > m_adjustEta
StatusCode initialize() override final
SG::WriteCondHandleKey< CaloTowerGeometry > m_outputKey
Gaudi::Property< double > m_fcal2Yslice
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Gaudi::Property< std::string > m_towerMapFile
Gaudi::Property< double > m_towerPhiMax
Gaudi::Property< double > m_fcal3Xslice
Gaudi::Property< double > m_towerEtaMin
Gaudi::Property< double > m_towerPhiMin
void dump(const CaloTowerGeometry *towerGeo) const
Gaudi::Property< double > m_fcal1Yslice
Gaudi::Property< double > m_fcal1Xslice
Gaudi::Property< unsigned > m_towerPhiBins
Retrieve the list of towers associated with a calorimeter cell referenced by its hash identifier.
uint_t m_towerBins
Maximum number of towers.
elementmap_t::const_iterator begin() const
Iterator points to first entry in internal look-up table (only const access!)
index_t phiIndexFromTowerIndex(index_t towerIdx) const
Get tower bin index for a given global tower index.
double towerEta(index_t towerIndex) const
Return pseudorapidity from global tower index (bin center)
elementmap_t::const_iterator end() const
Iterator marks end of internal look-up table (only const access)
double towerPhi(index_t towerIndex) const
Return azimuth from global tower index (bin center)
index_t etaIndexFromTowerIndex(index_t towerIdx) const
Get tower bin index for a given global tower index.
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
static Root::TMsgLogger logger("iLumiCalc")
std::string fmtMsg(const char *fmt,...)
-event-from-file