ATLAS Offline Software
CaloCellVolumes.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CaloCellVolumes.h"
6 
8 
9 #include "GaudiKernel/ISvcLocator.h"
13 
17 
18 #include <iostream>
19 #include <iomanip>
20 #include <algorithm>
21 
23 {
25  { return a.channelID < b.channelID; }
27  { return a.channelID < b; }
28 };
29 
30 
31 CaloCellVolumes::CaloCellVolumes(ISvcLocator* svcLocator
32  , const CaloCell_ID* calocell_id)
33  : m_calocell_id(calocell_id)
34 {
35  // Retrieve input parameters from the database
36  IGeoModelSvc* geoModel{nullptr};
37  IGeoDbTagSvc* geoDbTagSvc{nullptr};
38  IRDBAccessSvc* rdbAccess{nullptr};
39 
40  if(svcLocator->service("GeoModelSvc",geoModel) == StatusCode::FAILURE)
41  throw std::runtime_error("CellVolumes error: cannot access GeoModelSvc");
42 
43  if(svcLocator->service("GeoDbTagSvc",geoDbTagSvc) == StatusCode::FAILURE)
44  throw std::runtime_error("CellVolumes error: cannot access GeoDbTagSvc");
45 
46  if(svcLocator->service(geoDbTagSvc->getParamSvcName(),rdbAccess) == StatusCode::FAILURE)
47  throw std::runtime_error("CellVolumes error: cannot access RDBAccessSvc");
48 
49  std::string larKey, larNode;
50  if(geoDbTagSvc->getSqliteReader()==nullptr) {
51  DecodeVersionKey detectorKey = DecodeVersionKey(geoModel,"LAr");
52  larKey = detectorKey.tag();
53  larNode = detectorKey.node();
54  }
55 
56  IRDBRecordset_ptr cellVolRec = rdbAccess->getRecordsetPtr("LArCellVolumes",larKey,larNode);
57  if(cellVolRec->size()==0) {
58  cellVolRec = rdbAccess->getRecordsetPtr("LArCellVolumes","LArCellVolumes-00");
59  if(cellVolRec->size()==0) {
60  throw std::runtime_error("CaloCellVolumes error: 0 size of LArCellVolumes recordset");
61  }
62  }
63 
64  // get fcal tube spacings
65  IRDBRecordset_ptr fcalModRec = rdbAccess->getRecordsetPtr("FCalMod",larKey,larNode);
66  if(fcalModRec->size()==0) {
67  fcalModRec = rdbAccess->getRecordsetPtr("FCalMod","FCalMod-00");
68  if(fcalModRec->size()==0) {
69  throw std::runtime_error("CaloCellVolumes error: 0 size of FCalMod recordset");
70  }
71  }
72 
73  for(const IRDBRecord_ptr& rec : *fcalModRec) {
74  m_fcalTubeSpacings[rec->getInt("FCALSAMPLING")] = rec->getDouble("TUBESPACING");
75  }
76 
77  m_geometryLayout = "Atlas";
78  if(geoDbTagSvc->getSqliteReader()==nullptr) {
79  std::string LArTag = rdbAccess->getChildTag("LAr",larKey,larNode);
80  if(LArTag.find("H8")!=std::string::npos) {
81  m_geometryLayout = "H8";
82  }
83  else if(LArTag.find("H6")!=std::string::npos) {
84  m_geometryLayout = "H6";
85  }
86  else if(LArTag.find("G3")!=std::string::npos) {
87  m_geometryLayout = "G3";
88  }
89  }
90 
91  // Initialize m_cellVolumes vector
92  for(const IRDBRecord_ptr& rec : *cellVolRec) {
93 
94  int subcalo = rec->getInt("SUBCALO");
95  int posneg = rec->getInt("POSNEG");
96  int sampling = rec->getInt("SAMPLING");
97  int region = rec->getInt("REGION");
98  int eta = rec->getInt("ETA");
99  int phi = rec->getInt("PHI");
100 
101  Identifier channelID;
102  if(m_geometryLayout != "H6" || subcalo == CaloCell_ID::LARFCAL) {
103  channelID = m_calocell_id->cell_id (subcalo, posneg, sampling, region, eta, phi);
104  }
105  else {
106  Identifier reg_id = m_calocell_id->region_id(subcalo, posneg, sampling, region);
107  int phimin = m_calocell_id->phi_min(reg_id);
108  channelID = m_calocell_id->cell_id (subcalo, posneg, sampling, region, eta, phimin);
109  }
110 
111  CaloCellVolume cellVol;
112  cellVol.channelID = channelID;
113  cellVol.volume = rec->getDouble("VOLUME");
114  m_cellVolumes.push_back(cellVol);
115  }
116 
117  if (m_cellVolumes.empty()) {
118  throw std::runtime_error("CaloCellVolumes error: 0 volumes have been built!");
119  }
120 
121  std::sort (m_cellVolumes.begin(), m_cellVolumes.end(),
123 }
124 
126 {
127  m_cellVolumes.clear();
128 }
129 
131 {
132  // compute Identifier of Cell with same eta, but phi=0 and pos side
133  // (except for fcal)
134  Identifier volId;
135 
136  if (!m_calocell_id->is_fcal(cell_id)) {
137  int subCalo = m_calocell_id->sub_calo(cell_id);
138  int posneg = std::abs (m_calocell_id->pos_neg(cell_id));
139  int sampling = m_calocell_id->sampling(cell_id);
140  int region = m_calocell_id->region(cell_id);
141  int eta = m_calocell_id->eta(cell_id);
142 
143  if(m_geometryLayout != "H6") {
144  volId = m_calocell_id->cell_id(subCalo, posneg, sampling, region, eta, 0);
145  }
146  else {
147  Identifier reg_id = m_calocell_id->region_id(subCalo, posneg, sampling, region);
148  int phimin = m_calocell_id->phi_min(reg_id);
149  volId = m_calocell_id->cell_id(subCalo, posneg, sampling, region, eta, phimin);
150  }
151  }
152  else {
153  volId = cell_id;
154  }
155 
156  CaloCellVolumeVector::const_iterator it =
157  std::lower_bound (m_cellVolumes.begin(), m_cellVolumes.end(), volId,
159  if (it != m_cellVolumes.end() && it->channelID == volId) return it->volume;
160 
161  return 0.;
162 }
163 
165 {
166  if (m_cellVolumes.empty()) {
167  std::cerr << "CaloCellVolumes::print(). No cell volumes..." << std::endl;
168  }
169  else {
170  std::cout << "CaloCellVolumes::print(). Number of volumes found: "
171  << m_cellVolumes.size() << std::endl;
172 
173  for(const CaloCellVolume& vol : m_cellVolumes) {
174  m_calocell_id->print( (Identifier) vol.channelID );
175  std::cout << m_calocell_id->show_to_string( (Identifier) vol.channelID );
176  std::cout << " ==> vol= " << vol.volume << " mm3" << std::endl;
177  }
178  }
179 }
180 
182 {
183  TubeSpacingMap::const_iterator it = m_fcalTubeSpacings.find(sampling);
184  if(it==m_fcalTubeSpacings.end())
185  throw std::runtime_error("CaloCellVolumes::getFcalTubeSpacing error: wrong sampling provided");
186 
187  return (*it).second;
188 }
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
CaloCellVolume::volume
float volume
Definition: CaloCellVolumes.h:19
CaloCell_Base_ID::region
int region(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
CaloCell_Base_ID::phi_min
int phi_min(const Identifier regId) const
min value of phi index (-999 == failure)
IGeoModelSvc
Definition: IGeoModelSvc.h:17
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
CaloCell_Base_ID::pos_neg
int pos_neg(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
CaloCellVolumes::CaloCellVolumes
CaloCellVolumes(ISvcLocator *svcLocator, const CaloCell_ID *calocell_id)
Definition: CaloCellVolumes.cxx:31
CaloCell_Base_ID::region_id
Identifier region_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy) const
Make a region ID from constituting fields and subCalo index; for (Mini)FCAL and Tiles,...
skel.it
it
Definition: skel.GENtoEVGEN.py:423
DecodeVersionKey::node
const std::string & node() const
Return the version node.
Definition: DecodeVersionKey.cxx:99
CaloCellVolume::channelID
Identifier channelID
Definition: CaloCellVolumes.h:18
CaloCell_ID.h
CaloCellVolume_Compare
Definition: CaloCellVolumes.cxx:23
CaloCellVolumes::m_cellVolumes
CaloCellVolumeVector m_cellVolumes
Definition: CaloCellVolumes.h:41
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
CaloCellVolumes.h
CaloCellVolumes::m_fcalTubeSpacings
TubeSpacingMap m_fcalTubeSpacings
Definition: CaloCellVolumes.h:46
CaloCell_Base_ID::is_fcal
bool is_fcal(const Identifier id) const
test if the id belongs to the FCAL - true also for MiniFCAL
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
IRDBAccessSvc
IRDBAccessSvc is an abstract interface to the athena service that provides the following functionalit...
Definition: IRDBAccessSvc.h:45
CaloCell_Base_ID::sampling
int sampling(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
DecodeVersionKey
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
Definition: DecodeVersionKey.h:18
DecodeVersionKey::tag
const std::string & tag() const
Return version tag.
Definition: DecodeVersionKey.cxx:93
CaloCell_Base_ID::eta
int eta(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
CaloCell_Base_ID::sub_calo
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
IGeoDbTagSvc
Definition: IGeoDbTagSvc.h:26
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
CaloCellVolumes::print
void print()
Definition: CaloCellVolumes.cxx:164
CaloCellVolumes::getFcalTubeSpacing
double getFcalTubeSpacing(int sampling)
Definition: CaloCellVolumes.cxx:181
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
DecodeVersionKey.h
CaloCell_Base_ID::cell_id
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
AtlasDetectorID::print
void print(Identifier id, const IdContext *context=0) const
Expanded print out of any identifier.
Definition: AtlasDetectorID.cxx:648
a
TList * a
Definition: liststreamerinfos.cxx:10
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
AtlasDetectorID::show_to_string
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:574
CaloCellVolume_Compare::operator()
bool operator()(const CaloCellVolume &a, const CaloCellVolume &b)
Definition: CaloCellVolumes.cxx:24
IRDBRecord_ptr
std::unique_ptr< IRDBRecord > IRDBRecord_ptr
Definition: IRDBRecordset.h:23
CaloCellVolumes::m_calocell_id
const CaloCell_ID * m_calocell_id
Definition: CaloCellVolumes.h:40
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
CaloCellVolumes::~CaloCellVolumes
~CaloCellVolumes()
Definition: CaloCellVolumes.cxx:125
IGeoModelSvc.h
CaloCellVolumes::CellVolume
double CellVolume(Identifier cell_id)
Definition: CaloCellVolumes.cxx:130
CaloCellVolumes::m_geometryLayout
std::string m_geometryLayout
Definition: CaloCellVolumes.h:42
IGeoDbTagSvc.h
CaloCellVolume
Definition: CaloCellVolumes.h:17