9#include "GaudiKernel/MsgStream.h"
11#include "CLHEP/Units/SystemOfUnits.h"
13#include "Identifier/Identifier.h"
17#include "CaloDetDescr/CaloDetDescrElement.h"
21#include "CaloGeoHelpers/CaloSampling.h"
43 const std::string& name,
44 const IInterface* parent)
71 return StatusCode::SUCCESS;
83 MsgStream log(msgSvc(),name());
95 <<
"tool does not hang off the TBXMLWriter algorithm."
97 return StatusCode::FAILURE;
102 if ( checkOut.isFailure() )
105 <<
"cannot convert properties correctly!"
107 return StatusCode::FAILURE;
113 <<
"list of included calo samplings:"
120 <<
"\042 with SubCalo index "
130 const EventContext& ctx = Gaudi::Hive::currentContext();
131 EventIDBase::number_type run_number = ctx.eventID().run_number();
135 if ( checkOut.isFailure() )
138 <<
"cannot produce run XML files."
140 return StatusCode::FAILURE;
159 outStream <<
"<!-- TBXMLCaloCellWriterTool: begin write cell container "
162 std::vector<std::string> theCellAttrNames;
163 theCellAttrNames.push_back(
"name");
164 theCellAttrNames.push_back(
"ncols");
165 theCellAttrNames.push_back(
"nrows");
166 theCellAttrNames.push_back(
"idtype");
167 theCellAttrNames.push_back(
"etype");
168 std::vector<std::string> theCellAttrValues;
174 (
unsigned int)ceil( (
double)dataSize / (
double)
m_nCols );
175 theCellAttrValues.push_back(std::to_string(
m_nCols));
176 theCellAttrValues.push_back(std::to_string(nRows));
177 theCellAttrValues.push_back(
"uint");
178 theCellAttrValues.push_back(
"double");
180 theCellAttrNames,theCellAttrValues);
191 baseIndex, lastIndex);
193 unsigned int theCtr = 0;
194 bool isTerminated =
false;
195 for ( ; firstCell != lastCell; ++firstCell )
198 double eta = (*firstCell)->eta();
199 double phi = (*firstCell)->phi();
205 theLayer = CaloSampling::Unknown;
216 (*firstCell)->caloDDE()->calo_hash();
218 int etaIndex =
m_idHelper->eta((*firstCell)->ID());
219 int phiIndex =
m_idHelper->phi((*firstCell)->ID());
220 int regIndex =
m_idHelper->region((*firstCell)->ID());
222 int lyrIndex =
m_idHelper->sampling((*firstCell)->ID());
225 if (
m_idHelper->is_em_barrel((*firstCell)->ID()) )
229 else if (
m_idHelper->is_em_endcap((*firstCell)->ID()) )
233 else if (
m_idHelper->is_tile_barrel((*firstCell)->ID()) )
237 else if (
m_idHelper->is_tile_extbarrel((*firstCell)->ID()) )
241 else if (
m_idHelper->is_hec((*firstCell)->ID()) )
245 else if (
m_idHelper->is_fcal((*firstCell)->ID()) )
250 double theEnergy = (*firstCell)->e();
251 if ( theCtr == 0 || ( theCtr %
m_nCols ) == 0 )
255 theIndex -= (int)baseIndex;
257 outStream << std::format(
"{:>10} {:>3} {:>3} {:>3} {:>3} {:>3} {:>10.5g}",
266 if ( (isTerminated = ( theCtr %
m_nCols )) == 0 )
272 if ( ! isTerminated ) outStream <<
'\n';
275 outStream <<
"<!-- TBXMLCaloCellWriterTool: end write cell container "
279 return StatusCode::SUCCESS;
288 unsigned int runNumber)
295 std::ofstream thisFileStream(std::format(
"{}/geom.{:06}.xml", fileDir, runNumber));
298 std::vector<std::string> theRunElements;
299 theRunElements.push_back(
"FCalGeomTable*");
300 this->
openDictionary(thisFileStream,
"FCalGeomTable",theRunElements);
301 std::vector<std::string> theRunAttr;
302 theRunAttr.push_back(
"name CDATA #REQUIRED");
303 this->
addAttributes(thisFileStream,
"FCalGeomTable",theRunAttr);
306 std::vector<std::string> anyData;
307 anyData.push_back(
"ANY");
309 std::vector<std::string> theGeomAttr;
310 theGeomAttr.push_back(
"name CDATA #REQUIRED");
311 this->
addAttributes(thisFileStream,
"FCalGeomTable",theGeomAttr);
326 firstIndex, lastIndex);
327 safeIndex = firstIndex;
330 std::vector<std::string> theRunValues(theRunAttr.size());
331 for (
unsigned int i=0; i<theRunAttr.size(); i++ )
333 if ( (theRunAttr[i]).
find(
"name") != std::string::npos )
335 theRunValues[i] =
"FCalMod0";
337 theRunAttr[i].substr(0,theRunAttr[i].find_first_of(
' '));
340 this->
openElement(thisFileStream,
"FCalGeomTable",theRunAttr,theRunValues);
341 theRunValues[0] =
"FCalCells";
342 this->
openElement(thisFileStream,
"FCalGeomTable",theRunAttr,theRunValues);
343 thisFileStream <<
"<!-- 32-bit Id"
354 std::unordered_map<int, double> smallestDx;
355 smallestDx.reserve(8);
357 for (
unsigned int iCtr = safeIndex; iCtr <= lastIndex; ++iCtr)
360 const int theCalo =
m_idHelper->sub_calo(theId);
363 const double dx = theElement->
dx();
366 auto [it, inserted] = smallestDx.try_emplace(theCalo, dx);
367 if (!inserted && dx < it->second)
372 for (
unsigned int iCtr=(
unsigned int)firstIndex;
373 iCtr<=(
unsigned int)lastIndex; iCtr++ )
385 double theX = theElement->
x();
386 double theY = theElement->
y();
387 double theZ = theElement->
z();
389 double dx = theElement->
dx();
390 int tileSize = dx > 1.1*smallestDx[theCalo] ? 1 : 0;
393 thisFileStream <<
" "
395 << std::setfill(
' ') << iCtr-(
unsigned int)firstIndex
397 << std::setw(2) << std::setfill(
' ') << theModule
399 << std::setw(2) << std::setfill(
' ') << theEta
401 << std::setw(2) << std::setfill(
' ') << thePhi
403 << std::setw(10) << std::setprecision(5) << theX <<
" "
404 << std::setw(10) << std::setprecision(5) << theY <<
" "
405 << std::setw(10) << std::setprecision(5) << theZ <<
" "
407 << std::setw(2) << std::setfill(
' ') << tileSize
411 thisFileStream.close();
413 return StatusCode::SUCCESS;
420 MsgStream log(msgSvc(),name());
429 std::vector<std::string>::iterator firstCalo =
m_includedCalos.begin();
431 while ( firstCalo != lastCalo )
433 if ( *firstCalo ==
"LAREM" )
438 else if ( *firstCalo ==
"LARHEC" )
443 else if ( *firstCalo ==
"LARFCAL" )
448 else if ( *firstCalo ==
"TILE" )
467 if ( sample ==
"PreSamplerB" )
469 if ( sample ==
"EMB0" )
471 if ( sample ==
"EMB1" )
473 if ( sample ==
"EMB2" )
475 if ( sample ==
"TileBar0" )
477 if ( sample ==
"TileBar1" )
479 if ( sample ==
"TileBar2" )
481 if ( sample ==
"TileExt0" )
483 if ( sample ==
"TileExt1" )
485 if ( sample ==
"TileExt2" )
489 if ( sample ==
"EME1" )
491 if ( sample ==
"EME2" )
493 if ( sample ==
"HEC0" )
495 if ( sample ==
"HEC1" )
497 if ( sample ==
"HEC2" )
499 if ( sample ==
"HEC3" )
501 if ( sample ==
"FCAL0" )
503 if ( sample ==
"FCAL1" )
505 if ( sample ==
"FCAL2" )
510 ? StatusCode::FAILURE
511 : StatusCode::SUCCESS;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition of CaloDetDescrManager.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
Container class for CaloCell.
CaloCellContainer::const_iterator beginConstCalo(CaloCell_ID::SUBCALO caloNum) const
get const iterators on cell of just one calo
CaloCellContainer::const_iterator endConstCalo(CaloCell_ID::SUBCALO caloNum) const
int nCellsCalo(const CaloCell_ID::SUBCALO caloNum) const
get number of cels of given calorimeter
This class groups all DetDescr information related to a CaloCell.
CaloCell_ID::CaloSample getSampling() const
cell sampling
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
DataModel_detail::const_iterator< DataVector > const_iterator
This is a "hash" representation of an Identifier.
constexpr value_type value() const
std::string find(const std::string &s)
return a remapped string