ATLAS Offline Software
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 
8 namespace {
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 
23 
25 
26  return StatusCode::SUCCESS;
27 }
28 
29 
30 StatusCode 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 
CaloTowerGeometry::m_fcal2Yslice
double m_fcal2Yslice
Number of y slices for cells in FCal2.
Definition: CaloTowerGeometry.h:149
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
CaloTowerGeometryCondAlg::m_fcal1Yslice
Gaudi::Property< double > m_fcal1Yslice
Definition: CaloTowerGeometryCondAlg.h:44
CaloTowerGeometry::m_fcal1Yslice
double m_fcal1Yslice
Number of y slices for cells in FCal1.
Definition: CaloTowerGeometry.h:147
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CaloTowerGeometry::m_towerEtaMax
double m_towerEtaMax
Upper boundary .
Definition: CaloTowerGeometry.h:141
CaloRec::Helpers::fmtMsg
std::string fmtMsg(const char *fmt,...)
Definition: CaloTopoClusterFromTowerHelpers.cxx:13
CaloTowerGeometry::towerPhi
double towerPhi(index_t towerIndex) const
Return azimuth from global tower index (bin center)
Definition: CaloTowerGeometry.h:327
CaloTowerGeometryCondAlg::m_towerEtaMin
Gaudi::Property< double > m_towerEtaMin
Definition: CaloTowerGeometryCondAlg.h:34
CaloTowerGeometryCondAlg::m_fcal3Xslice
Gaudi::Property< double > m_fcal3Xslice
Definition: CaloTowerGeometryCondAlg.h:49
CaloTowerGeometry::m_towerBins
uint_t m_towerBins
Maximum number of towers.
Definition: CaloTowerGeometry.h:131
CaloTowerGeometry::end
elementmap_t::const_iterator end() const
Iterator marks end of internal look-up table (only const access)
Definition: CaloTowerGeometry.h:330
CaloTowerGeometryCondAlg::m_adjustEta
Gaudi::Property< bool > m_adjustEta
Definition: CaloTowerGeometryCondAlg.h:36
CaloTowerGeometryCondAlg::m_fcal2Xslice
Gaudi::Property< double > m_fcal2Xslice
Definition: CaloTowerGeometryCondAlg.h:46
CaloTowerGeometry::m_towerPhiMin
double m_towerPhiMin
Lower boundary .
Definition: CaloTowerGeometry.h:144
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
CaloTowerGeometry::etaIndexFromTowerIndex
index_t etaIndexFromTowerIndex(index_t towerIdx) const
Get tower bin index for a given global tower index.
Definition: CaloTowerGeometry.h:315
python.InDetPriVxFinderConfig.mlog
mlog
Definition: InDetPriVxFinderConfig.py:134
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloTowerGeometryCondAlg::initialize
StatusCode initialize() override final
Definition: CaloTowerGeometryCondAlg.cxx:20
CaloTowerGeometry::m_towerPhiMax
double m_towerPhiMax
Upper boundary .
Definition: CaloTowerGeometry.h:145
CaloTowerGeometry::towerEta
double towerEta(index_t towerIndex) const
Return pseudorapidity from global tower index (bin center)
Definition: CaloTowerGeometry.h:326
CaloTowerGeometryCondAlg::m_fcal2Yslice
Gaudi::Property< double > m_fcal2Yslice
Definition: CaloTowerGeometryCondAlg.h:47
CaloTowerGeometry::m_fcal3Xslice
double m_fcal3Xslice
Number of x slices for cells in FCal3.
Definition: CaloTowerGeometry.h:150
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloTowerGeometryCondAlg::m_towerPhiMin
Gaudi::Property< double > m_towerPhiMin
Definition: CaloTowerGeometryCondAlg.h:39
CaloTowerGeometryCondAlg::dump
void dump(const CaloTowerGeometry *towerGeo) const
Definition: CaloTowerGeometryCondAlg.cxx:75
CaloTowerGeometryCondAlg::m_towerEtaMax
Gaudi::Property< double > m_towerEtaMax
Definition: CaloTowerGeometryCondAlg.h:35
IOVInfiniteRange.h
CaloTowerGeometryCondAlg::m_fcal3Yslice
Gaudi::Property< double > m_fcal3Yslice
Definition: CaloTowerGeometryCondAlg.h:50
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
python.runDiffRootOnChanged.logfile
logfile
Definition: runDiffRootOnChanged.py:143
CaloTowerGeometryCondAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: CaloTowerGeometryCondAlg.cxx:30
CaloTowerGeometry
Tower geometry store and description provider.
Definition: CaloTowerGeometry.h:23
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
item
Definition: ItemListSvc.h:43
CaloTowerGeometry::m_towerEtaBins
uint_t m_towerEtaBins
Number of bins.
Definition: CaloTowerGeometry.h:139
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
CaloTowerGeometry::m_fcal1Xslice
double m_fcal1Xslice
Number of x slices for cells in FCal1.
Definition: CaloTowerGeometry.h:146
fmt
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloTowerGeometry::m_fcal2Xslice
double m_fcal2Xslice
Number of x slices for cells in FCal2.
Definition: CaloTowerGeometry.h:148
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloTowerGeometry::begin
elementmap_t::const_iterator begin() const
Iterator points to first entry in internal look-up table (only const access!)
Definition: CaloTowerGeometry.h:329
CaloTowerGeometry::m_adjustEta
bool m_adjustEta
Adjust FCal cells to eta boundary (default true )
Definition: CaloTowerGeometry.h:142
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
CaloTowerGeometry::initialize
StatusCode initialize(MsgStream &msg)
Initialize object.
Definition: CaloTowerGeometry.cxx:32
CaloTowerGeometry::m_towerEtaMin
double m_towerEtaMin
Lower boundary .
Definition: CaloTowerGeometry.h:140
CaloTowerGeometryCondAlg::m_fcal1Xslice
Gaudi::Property< double > m_fcal1Xslice
Definition: CaloTowerGeometryCondAlg.h:43
CaloTowerGeometryCondAlg::m_towerEtaBins
Gaudi::Property< unsigned > m_towerEtaBins
Definition: CaloTowerGeometryCondAlg.h:33
CaloTowerGeometryCondAlg::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: CaloTowerGeometryCondAlg.h:29
CaloTowerGeometryCondAlg::m_outputKey
SG::WriteCondHandleKey< CaloTowerGeometry > m_outputKey
Definition: CaloTowerGeometryCondAlg.h:30
CaloTowerGeometryCondAlg::m_towerGridFile
Gaudi::Property< std::string > m_towerGridFile
Definition: CaloTowerGeometryCondAlg.h:52
CaloTowerGeometryCondAlg.h
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
CaloTowerGeometry::m_fcal3Yslice
double m_fcal3Yslice
Number of y slices for cells in FCal3.
Definition: CaloTowerGeometry.h:151
CaloTowerGeometryCondAlg::m_towerPhiMax
Gaudi::Property< double > m_towerPhiMax
Definition: CaloTowerGeometryCondAlg.h:40
CaloTowerGeometryCondAlg::m_towerPhiBins
Gaudi::Property< unsigned > m_towerPhiBins
Definition: CaloTowerGeometryCondAlg.h:38
CaloTowerGeometry::phiIndexFromTowerIndex
index_t phiIndexFromTowerIndex(index_t towerIdx) const
Get tower bin index for a given global tower index.
Definition: CaloTowerGeometry.h:316
CaloTowerGeometryCondAlg::m_towerMapFile
Gaudi::Property< std::string > m_towerMapFile
Definition: CaloTowerGeometryCondAlg.h:54
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
CaloTowerGeometry::m_towerPhiBins
uint_t m_towerPhiBins
Number of bins.
Definition: CaloTowerGeometry.h:143