ATLAS Offline Software
Loading...
Searching...
No Matches
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"
10#include "GaudiKernel/SmartIF.h"
14
18
19#include <iostream>
20#include <iomanip>
21#include <algorithm>
22
24{
25 bool operator() (const CaloCellVolume& a, const CaloCellVolume& b)
26 { return a.channelID < b.channelID; }
28 { return a.channelID < b; }
29};
30
31
32CaloCellVolumes::CaloCellVolumes(ISvcLocator* svcLocator
33 , const CaloCell_ID* calocell_id)
34 : m_calocell_id(calocell_id)
35{
36 // Retrieve input parameters from the database
37 SmartIF<IGeoModelSvc> geoModel{svcLocator->service("GeoModelSvc")};
38 if(!geoModel)
39 throw std::runtime_error("CellVolumes error: cannot access GeoModelSvc");
40
41 SmartIF<IGeoDbTagSvc> geoDbTagSvc{svcLocator->service("GeoDbTagSvc")};
42 if(!geoDbTagSvc)
43 throw std::runtime_error("CellVolumes error: cannot access GeoDbTagSvc");
44
45 SmartIF<IRDBAccessSvc> rdbAccess{svcLocator->service(geoDbTagSvc->getParamSvcName())};
46 if(!rdbAccess)
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
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}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Definition of the abstract IRDBAccessSvc interface.
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
std::unique_ptr< IRDBRecord > IRDBRecord_ptr
CaloCellVolumeVector m_cellVolumes
TubeSpacingMap m_fcalTubeSpacings
const CaloCell_ID * m_calocell_id
double CellVolume(Identifier cell_id)
std::string m_geometryLayout
double getFcalTubeSpacing(int sampling)
CaloCellVolumes(ISvcLocator *svcLocator, const CaloCell_ID *calocell_id)
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
virtual unsigned int size() const =0
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
bool operator()(const CaloCellVolume &a, const CaloCellVolume &b)
Identifier channelID