50 <<
". In theory this should not be called, but may happen"
51 <<
" if multiple concurrent events are being processed out of order.");
53 return StatusCode::SUCCESS;
59 std::unique_ptr<TRTCond::ActiveFraction> writeCdo{std::make_unique<TRTCond::ActiveFraction>()};
66 ATH_MSG_INFO(
" Initialize TRTCond::ActiveFraction table with number of phi, eta bins: "
67 << writeCdo->getPhiBins().size() <<
", " << writeCdo->getEtaBins().size() );
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 );
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 );
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 );
89 if (not trtDetEleHandle.
isValid() or elements==
nullptr) {
91 return StatusCode::FAILURE;
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++) {
108 countAll++;
if (status) countDead++;
111 double phi = std::atan2( strawPosition.y(), strawPosition.x() );
112 int phiBin = writeCdo->findPhiBin(
phi );
114 ATH_MSG_DEBUG(
"TRTCond::ActiveFraction phiBin<0: " <<
phi <<
" " << phiBin);
120 int side =
m_trtId->barrel_ec(
id);
121 float z = std::abs( strawPosition.z() );
122 float thetaMin(0.), thetaMax(0.);
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;
130 thetaMin = std::atan( rMinEndcap /
z );
131 thetaMax = std::atan( rMaxEndcap /
z );
134 float thetaDummy = thetaMin;
135 thetaMin =
M_PI - thetaMax;
136 thetaMax =
M_PI - thetaDummy;
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.);
145 ATH_MSG_DEBUG(
"TRTCond::ActiveFraction: theta tan " << ti <<
" " << tanTheta );
146 countInvalidEtaValues++;
149 etaCheck[ti] = -std::log( tanTheta );
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);
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);
166 for (
int iEta = etaMinBin; iEta <= etaMaxBin; iEta++) {
167 dummyTableCountAll[iEta][phiBin]++;
168 if (status) dummyTableCountDead[iEta][phiBin]++;
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);
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 );
188 if (countInvalidEtaValues)
ATH_MSG_WARNING(
"TRT_ActiveFraction: found invalid eta range, check: " << countInvalidEtaValues);
197 if(strawContainer==
nullptr) {
199 return StatusCode::FAILURE;
203 if(!strawReadHandle.
range(rangeW)) {
204 ATH_MSG_ERROR(
"Failed to retrieve validity range for " << strawReadHandle.
key());
205 return StatusCode::FAILURE;
210 if(writeHandle.
record(rangeW,std::move(writeCdo)).isFailure()) {
212 <<
" with EventRange " << rangeW
213 <<
" into Conditions Store");
214 return StatusCode::FAILURE;
218 return StatusCode::SUCCESS;