14 , ISvcLocator* pSvcLocator )
16 m_strawStatus(
"TRT_StrawStatusSummaryTool",this),
38 return StatusCode::SUCCESS;
50 if(writeHandle.isValid()) {
51 ATH_MSG_DEBUG(
"CondHandle " << writeHandle.fullKey() <<
" is already valid."
52 <<
". In theory this should not be called, but may happen"
53 <<
" if multiple concurrent events are being processed out of order.");
55 return StatusCode::SUCCESS;
61 std::unique_ptr<TRTCond::ActiveFraction> writeCdo{std::make_unique<TRTCond::ActiveFraction>()};
68 ATH_MSG_INFO(
" Initialize TRTCond::ActiveFraction table with number of phi, eta bins: "
69 << writeCdo->getPhiBins().size() <<
", " << writeCdo->getEtaBins().size() );
71 for (
unsigned int i=0;
i<writeCdo->getEtaBins().
size();
i++) {
72 float etaMin = writeCdo->getEtaBins()[
i].first;
73 float etaMax = writeCdo->getEtaBins()[
i].second;
77 for (
unsigned int j=0; j<writeCdo->getPhiBins().
size(); j++) {
78 float phiMin = writeCdo->getPhiBins()[j].first;
79 float phiMax = writeCdo->getPhiBins()[j].second;
80 int bin = writeCdo->findPhiBin( (phiMin+phiMax)/2. );
81 ATH_MSG_DEBUG(
"TRTCond::ActiveFraction: findPhiBin( " << phiMin <<
", " << phiMax <<
" ] = " <<
bin );
85 std::vector<int> dummyPhiVec( writeCdo->getPhiBins().size(), 0 );
86 std::vector<std::vector<int> > dummyTableCountAll( writeCdo->getEtaBins().size(), dummyPhiVec );
87 std::vector<std::vector<int> > dummyTableCountDead( writeCdo->getEtaBins().size(), dummyPhiVec );
91 if (not trtDetEleHandle.
isValid() or elements==
nullptr) {
93 return StatusCode::FAILURE;
96 float rMinEndcap = 617.;
97 float rMaxEndcap = 1106.;
98 int countAll(0), countDead(0), countPhiSkipped(0), countEtaSkipped(0), countInvalidEtaValues(0);
101 for (
int i=0;
i<=nStrawsInLayer;
i++) {
110 countAll++;
if (
status) countDead++;
113 double phi = std::atan2( strawPosition.y(), strawPosition.x() );
114 int phiBin = writeCdo->findPhiBin(
phi );
123 float z = std::abs( strawPosition.z() );
124 float thetaMin(0.), thetaMax(0.);
128 float r = std::sqrt(
std::pow(strawPosition.x(), 2) +
std::pow(strawPosition.y(), 2) );
130 thetaMax = ((
z-zRange)>0.) ?
std::atan(
r / (
z-zRange) ) : 1.57;
136 float thetaDummy = thetaMin;
137 thetaMin =
M_PI - thetaMax;
138 thetaMax =
M_PI - thetaDummy;
141 float thetaCheck[] = {thetaMax, thetaMin};
142 float etaCheck[] = {0., 0.};
143 for (
int ti=0; ti<2; ti++) {
144 if (thetaCheck[ti]<=0.||thetaCheck[ti]>=
M_PI)
ATH_MSG_DEBUG(
"TRTCond::ActiveFraction: theta " << ti <<
" " << thetaCheck[ti]);
145 float tanTheta =
std::tan(thetaCheck[ti]/2.);
147 ATH_MSG_DEBUG(
"TRTCond::ActiveFraction: theta tan " << ti <<
" " << tanTheta );
148 countInvalidEtaValues++;
151 etaCheck[ti] = -
std::log( tanTheta );
153 float etaMin = etaCheck[0];
154 float etaMax = etaCheck[1];
155 int etaMinBin = writeCdo->findEtaBin(
etaMin );
156 int etaMaxBin = writeCdo->findEtaBin(
etaMax );
158 if (etaMinBin<0 && etaMaxBin<0) {
159 ATH_MSG_WARNING(
"TRTCond::ActiveFraction: etaMaxBin<etaMinBin " << thetaMin <<
" " << thetaMax
160 <<
" " <<
etaMin <<
" " <<
etaMax <<
" " << etaMinBin <<
" " << etaMaxBin <<
", side: " <<
side);
164 if (etaMinBin<0) etaMinBin = 0;
165 if (etaMaxBin<0) etaMaxBin = writeCdo->getEtaBins().size() - 1;
166 if (etaMaxBin<etaMinBin)
ATH_MSG_WARNING(
"TRTCond::ActiveFraction: etaMaxBin<etaMinBin " << etaMinBin <<
" " << etaMaxBin <<
", side: " <<
side);
176 for (
unsigned int i = 0;
i < writeCdo->getEtaBins().
size(); ++
i) {
177 for (
unsigned int j = 0; j < writeCdo->getPhiBins().
size(); ++j) {
178 float deadFraction = 1. * dummyTableCountDead[
i][j];
179 if (dummyTableCountAll[
i][j]>0) deadFraction /= (1. * dummyTableCountAll[
i][j]);
180 writeCdo->setActiveFraction(
i, j, 1. - deadFraction);
181 ATH_MSG_DEBUG(
"dummyTableCountDead: " <<
i <<
", " << j <<
", count " << dummyTableCountAll[
i][j] <<
" dead " << deadFraction);
185 float deadStrawFraction = (1.*countDead) / (1.*countAll);
186 ATH_MSG_INFO(
" Initialize TRTCond::ActiveFraction table finished, count all TRT straws: " << countAll
187 <<
", count dead straws: " << countDead <<
" (" << deadStrawFraction
188 <<
"%), straws skipped due to invalid phi, eta range: " << countPhiSkipped <<
" " << countEtaSkipped );
190 if (countInvalidEtaValues)
ATH_MSG_WARNING(
"TRT_ActiveFraction: found invalid eta range, check: " << countInvalidEtaValues);
199 if(strawContainer==
nullptr) {
201 return StatusCode::FAILURE;
205 if(!strawReadHandle.range(rangeW)) {
206 ATH_MSG_ERROR(
"Failed to retrieve validity range for " << strawReadHandle.key());
207 return StatusCode::FAILURE;
212 if(writeHandle.record(rangeW,std::move(writeCdo)).isFailure()) {
213 ATH_MSG_ERROR(
"Could not record ActiveFraction " << writeHandle.key()
214 <<
" with EventRange " << rangeW
215 <<
" into Conditions Store");
216 return StatusCode::FAILURE;
220 return StatusCode::SUCCESS;