40{
42
43
44
45 SG::WriteCondHandle<TRTCond::ActiveFraction> writeHandle{
m_strawWriteKey, ctx};
46
47
50 << ". In theory this should not be called, but may happen"
51 << " if multiple concurrent events are being processed out of order.");
52
53 return StatusCode::SUCCESS;
54 }
55
56
57
58
59 std::unique_ptr<TRTCond::ActiveFraction> writeCdo{std::make_unique<TRTCond::ActiveFraction>()};
60
61
62
63
64
65
66 ATH_MSG_INFO(
" Initialize TRTCond::ActiveFraction table with number of phi, eta bins: "
67 << writeCdo->getPhiBins().size() << ", " << writeCdo->getEtaBins().size() );
68
69 for (
unsigned int i=0;
i<writeCdo->getEtaBins().
size();
i++) {
70 float etaMin = writeCdo->getEtaBins()[
i].first;
71 float etaMax = writeCdo->getEtaBins()[
i].second;
72 int bin = writeCdo->findEtaBin( (etaMin+etaMax)/2. );
73 ATH_MSG_DEBUG(
"TRTCond::ActiveFraction: findEtaBin( " << etaMin <<
", " << etaMax <<
" ] = " << bin );
74
75 for (
unsigned int j=0; j<writeCdo->getPhiBins().
size(); j++) {
76 float phiMin = writeCdo->getPhiBins()[j].first;
77 float phiMax = writeCdo->getPhiBins()[j].second;
78 int bin = writeCdo->findPhiBin( (phiMin+phiMax)/2. );
79 ATH_MSG_DEBUG(
"TRTCond::ActiveFraction: findPhiBin( " << phiMin <<
", " << phiMax <<
" ] = " << bin );
80 }
81 }
82
83 std::vector<int> dummyPhiVec( writeCdo->getPhiBins().size(), 0 );
84 std::vector<std::vector<int> > dummyTableCountAll( writeCdo->getEtaBins().size(), dummyPhiVec );
85 std::vector<std::vector<int> > dummyTableCountDead( writeCdo->getEtaBins().size(), dummyPhiVec );
86
87 SG::ReadCondHandle<InDetDD::TRT_DetElementContainer> trtDetEleHandle(
m_trtDetEleContKey, ctx);
88 const InDetDD::TRT_DetElementCollection* elements(trtDetEleHandle->getElements());
89 if (not trtDetEleHandle.isValid() or elements==nullptr) {
91 return StatusCode::FAILURE;
92 }
93
94 float rMinEndcap = 617.;
95 float rMaxEndcap = 1106.;
96 int countAll(0), countDead(0), countPhiSkipped(0), countEtaSkipped(0), countInvalidEtaValues(0);
97 for (std::vector<Identifier>::const_iterator it =
m_trtId->straw_layer_begin(); it !=
m_trtId->straw_layer_end(); ++it ) {
98 int nStrawsInLayer =
m_trtId->straw_max(*it);
99 for (
int i=0;
i<=nStrawsInLayer;
i++) {
100
101 Identifier
id =
m_trtId->straw_id(*it, i);
102
103 Identifier strawLayerId =
m_trtId->layer_id(
id);
104
105 IdentifierHash hashId =
m_trtId->straw_layer_hash(strawLayerId);
106
108 countAll++; if (status) countDead++;
109
110 const Amg::Vector3D &strawPosition = elements->getDetectorElement(hashId)->center(
id);
111 double phi = std::atan2( strawPosition.y(), strawPosition.x() );
112 int phiBin = writeCdo->findPhiBin(
phi );
113 if (phiBin<0) {
114 ATH_MSG_DEBUG(
"TRTCond::ActiveFraction phiBin<0: " <<
phi <<
" " << phiBin);
115 countPhiSkipped++;
116 continue;
117 }
118
119
121 float z = std::abs( strawPosition.z() );
122 float thetaMin(0.), thetaMax(0.);
123 if (abs(side)==1) {
124 float zRange = 360.;
125 if (
m_trtId->layer_or_wheel(
id) == 0 &&
m_trtId->straw_layer(
id) < 9 ) zRange = 160.;
126 float r = std::sqrt( std::pow(strawPosition.x(), 2) + std::pow(strawPosition.y(), 2) );
127 thetaMin = std::atan(
r / (
z+zRange) );
128 thetaMax = ((
z-zRange)>0.) ? std::atan(
r / (
z-zRange) ) : 1.57;
129 } else {
130 thetaMin = std::atan( rMinEndcap /
z );
131 thetaMax = std::atan( rMaxEndcap /
z );
132 }
133 if (side<0) {
134 float thetaDummy = thetaMin;
135 thetaMin =
M_PI - thetaMax;
136 thetaMax =
M_PI - thetaDummy;
137 }
138
139 float thetaCheck[] = {thetaMax, thetaMin};
140 float etaCheck[] = {0., 0.};
141 for (int ti=0; ti<2; ti++) {
142 if (thetaCheck[ti]<=0.||thetaCheck[ti]>=
M_PI)
ATH_MSG_DEBUG(
"TRTCond::ActiveFraction: theta " << ti <<
" " << thetaCheck[ti]);
143 float tanTheta = std::tan(thetaCheck[ti]/2.);
144 if (tanTheta<=0.) {
145 ATH_MSG_DEBUG(
"TRTCond::ActiveFraction: theta tan " << ti <<
" " << tanTheta );
146 countInvalidEtaValues++;
147 continue;
148 }
149 etaCheck[ti] = -std::log( tanTheta );
150 }
151 float etaMin = etaCheck[0];
152 float etaMax = etaCheck[1];
153 int etaMinBin = writeCdo->findEtaBin( etaMin );
154 int etaMaxBin = writeCdo->findEtaBin( etaMax );
155 if (etaMin>=etaMax)
ATH_MSG_WARNING(
"TRTCond::ActiveFraction: etaMaxBin<etaMinBin " << etaMin <<
" " << etaMax <<
" " << thetaMin <<
" " << thetaMax);
156 if (etaMinBin<0 && etaMaxBin<0) {
157 ATH_MSG_WARNING(
"TRTCond::ActiveFraction: etaMaxBin<etaMinBin " << thetaMin <<
" " << thetaMax
158 << " " << etaMin << " " << etaMax << " " << etaMinBin << " " << etaMaxBin << ", side: " << side);
159 countEtaSkipped++;
160 continue;
161 }
162 if (etaMinBin<0) etaMinBin = 0;
163 if (etaMaxBin<0) etaMaxBin = writeCdo->getEtaBins().size() - 1;
164 if (etaMaxBin<etaMinBin)
ATH_MSG_WARNING(
"TRTCond::ActiveFraction: etaMaxBin<etaMinBin " << etaMinBin <<
" " << etaMaxBin <<
", side: " << side);
165
166 for (
int iEta = etaMinBin;
iEta <= etaMaxBin;
iEta++) {
168 if (status) dummyTableCountDead[
iEta][
phiBin]++;
169 }
170
171 }
172 }
173
174 for (
unsigned int i = 0;
i < writeCdo->getEtaBins().
size(); ++
i) {
175 for (
unsigned int j = 0; j < writeCdo->getPhiBins().
size(); ++j) {
176 float deadFraction = 1. * dummyTableCountDead[
i][j];
177 if (dummyTableCountAll[i][j]>0) deadFraction /= (1. * dummyTableCountAll[
i][j]);
178 writeCdo->setActiveFraction(i, j, 1. - deadFraction);
179 ATH_MSG_DEBUG(
"dummyTableCountDead: " << i <<
", " << j <<
", count " << dummyTableCountAll[i][j] <<
" dead " << deadFraction);
180 }
181 }
182
183 float deadStrawFraction = (1.*countDead) / (1.*countAll);
184 ATH_MSG_INFO(
" Initialize TRTCond::ActiveFraction table finished, count all TRT straws: " << countAll
185 << ", count dead straws: " << countDead << " (" << deadStrawFraction
186 << "%), straws skipped due to invalid phi, eta range: " << countPhiSkipped << " " << countEtaSkipped );
187
188 if (countInvalidEtaValues)
ATH_MSG_WARNING(
"TRT_ActiveFraction: found invalid eta range, check: " << countInvalidEtaValues);
189
190
191
192
193 EventIDRange rangeW;
194
195 SG::ReadCondHandle<StrawStatusContainer> strawReadHandle{
m_strawReadKey, ctx};
197 if(strawContainer==nullptr) {
199 return StatusCode::FAILURE;
200 }
201
202
203 if(!strawReadHandle.
range(rangeW)) {
204 ATH_MSG_ERROR(
"Failed to retrieve validity range for " << strawReadHandle.
key());
205 return StatusCode::FAILURE;
206 }
207
208
209
210 if(writeHandle.
record(rangeW,std::move(writeCdo)).isFailure()) {
212 << " with EventRange " << rangeW
213 << " into Conditions Store");
214 return StatusCode::FAILURE;
215 }
216
217
218 return StatusCode::SUCCESS;
219}
Scalar phi() const
phi method
#define ATH_MSG_WARNING(x)
bool range(EventIDRange &r)
const std::string & key() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
TRTCond::StrawStatusMultChanContainer StrawStatusContainer
ToolHandle< ITRT_StrawStatusSummaryTool > m_strawStatus
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
SG::WriteCondHandleKey< TRTCond::ActiveFraction > m_strawWriteKey
SG::ReadCondHandleKey< StrawStatusContainer > m_strawReadKey
Eigen::Matrix< double, 3, 1 > Vector3D
setScale setgFexType iEta
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setPhiMap phiBin