9 #include "GaudiKernel/Bootstrap.h"
10 #include "GaudiKernel/ISvcLocator.h"
42 if (curRZ->size()==0) {
43 ATH_MSG_ERROR(
"Unable to create volume representation for geoID="<<geoID);
44 return StatusCode::FAILURE;
46 ATH_MSG_VERBOSE(
"Found " << curRZ->size() <<
" (r,z) pairs with positive z for geoID=" << geoID);
57 ATH_MSG_DEBUG(
"Preparing " << curRZ->size() <<
" (r,z) pairs with positive z for geoID=" << geoID);
58 while ( curRZ->size()) {
60 double maxR =
std::max( curRZ->front().first , curRZ->back().first );
61 double zFront = curRZ->front().second;
62 double zBack = curRZ->back().second;
63 double minZ =
std::min( zFront, zBack);
65 ATH_MSG_VERBOSE(
" minz=" << minZ <<
" zBack="<<zBack<<
" zFront="<<zFront<<
" maxR="<<maxR<<
" curRZ->size()="<<curRZ->size());
69 if (zFront<zBack) curRZ->pop_front();
70 else if (zBack<zFront) curRZ->pop_back();
74 if (curRZ->size()>0) curRZ->pop_back();
78 size_t curZBin = tmpZBins[geoID].size();
80 if ( (curZBin>0) && ( fabs(tmpZBins[geoID][curZBin-1]-minZ) <m_tolerance) )
continue;
82 tmpZBins[geoID].push_back(minZ);
92 tmpRBins[geoID][curZBin] = maxR*maxR;
96 ATH_MSG_DEBUG(
"Combining individual volumen boundaries in one common representation");
102 tmpZBinIndex[geoID] = 0;
103 std::vector<double> tmpZBinsGlobal;
104 std::map< size_t, RadiusGeoIDPairSet > tmpRBinsGlobal;
117 curRadiusGeoIDs.clear();
121 size_t curTmpZBinIndex = tmpZBinIndex[geoID];
124 if ( curTmpZBinIndex >= tmpZBins[geoID].
size())
continue;
125 double curZ = tmpZBins[geoID][curTmpZBinIndex];
127 if ( fabs(curZ)<m_tolerance) {
128 (tmpZBinIndex[geoID])++;
133 else if ( curZ<minZ) {
137 double curR2 = tmpRBins[geoID][curTmpZBinIndex];
140 " geoID=" << geoID <<
" for minZ<=" << minZ);
144 (tmpZBinIndex[minZGeoID])++;
145 }
while ( fabs(minZ-prevMinZ)<m_tolerance );
148 if ( curRadiusGeoIDs.size()==0)
break;
150 " curRadiusGeoIDs.size()=" << curRadiusGeoIDs.size() );
153 size_t curZBinGlobal = tmpZBinsGlobal.size();
154 tmpZBinsGlobal.push_back(minZ);
155 tmpRBinsGlobal[curZBinGlobal] = curRadiusGeoIDs;
158 ATH_MSG_DEBUG(
"Converting volume representation into faster format");
161 m_numZBins = tmpZBinsGlobal.size();
162 m_zBins =
new double[m_numZBins];
165 for (
int i=0;
i<m_numZBins;
i++) {
166 m_zBins[
i] = tmpZBinsGlobal[
i];
172 for ( ; radIt!=radItEnd; ++radIt) {
173 double curR = sqrt((*radIt).first);
175 if (curR<m_tolerance)
continue;
178 " --> geoID=" << (*radIt).second);
179 m_radiusBins[
i*m_maxRBins+ii++] = (*radIt);
185 return StatusCode::SUCCESS;
208 if ( (geoID == geoIDFwd) || (geoID == geoIDAft) ) {
210 if ( geoIDFwd == geoIDAft ) {
213 }
else if ( geoIDFwd != geoIDAft ) {
228 double z = fabs(
pos.z()) ;
229 while ( (zBin<m_numZBins) && (
z>=m_zBins[zBin]) ) {
238 double r2 =
pos.perp2();
240 (r2 >= m_radiusBins[zBin*m_maxRBins+radiusBin].
first) ) {
250 return identifiedGeoID;
275 std::unique_ptr<RZPairList> positiveZ = std::make_unique<RZPairList>();
276 std::unique_ptr<RZPairList> negativeZ = std::make_unique<RZPairList>();
282 <<
"' (GeoID="<< geoID <<
").");
290 if ( positiveZ->size() || negativeZ->size() ) {
291 ATH_MSG_ERROR(
"Can not interpret the (r,z) pairs provided by the EnvelopeDefSvc");
298 const RZPairVector &rz = m_envDefSvc->getRZBoundary( geoID );
303 int signZChanges = 0;
304 int prevZSign =
sign(rz.at(0).second);
307 RZPairVector::const_iterator rzIt = rz.begin();
308 RZPairVector::const_iterator rzItEnd = rz.end();
309 for (; rzIt!=rzItEnd; ++rzIt) {
310 const RZPair &curRZ = *rzIt;
311 double curZ = curRZ.second;
312 int curZSign =
sign(curZ);
315 " curZSign=" <<curZSign<<
316 " prevZSign=" << prevZSign<<
318 " curR=" <<curRZ.first );
321 if ( curZSign==-1) curRZList = negativeZ.get();
323 else if ( curZSign==1) curRZList = positiveZ.get();
326 ATH_MSG_WARNING(
"Ignoring an (r,z) pair from the EnvelopeDefSvc with z==0.");
331 if ( curZSign != prevZSign) {
333 prevZSign = curZSign;
336 curRZInsertIt = curRZList->begin();
342 if ( signZChanges<2 ) {
343 curRZList->push_back(curRZ);
349 else if ( signZChanges==2 ) {
350 curRZList->insert( curRZInsertIt, curRZ );
356 ATH_MSG_ERROR(
"Unable to interpret (r,z) pairs for envelope definition provided by the EnvelopeDefSvc" );
357 ATH_MSG_ERROR(
" -> provided (r,z) pairs traverse the z==0 plane more than twice" );
368 if ( (!checkSymmetric( *positiveZ, *negativeZ)) ) {
369 ATH_MSG_ERROR(
"(r,z) pairs received from EnvelopeDefSvc are not symmetric around z==0 plane");
377 double frontR = positiveZ->front().first;
378 double backR = positiveZ->back().first;
379 positiveZ->push_front(
RZPair(frontR, 0.) );
380 positiveZ->push_back(
RZPair(backR , 0.) );
392 ATH_MSG_DEBUG(
"checking symmetry around z==0 plane for given (r,z) pairs");
395 if ( positiveZ.size() != negativeZ.size()) {
396 ATH_MSG_ERROR(
"Can not interpret the (r,z) pairs given by the EnvelopeDefSvc");
397 ATH_MSG_ERROR(
" -> different number of (r,z) pairs on either side of the z==0 plane");
419 while ( posIt != posItEnd) {
423 if ( fabs(negIt->first-posIt->first)>m_tolerance || fabs(negIt->second+posIt->second)>m_tolerance)