File indexing completed on 2025-02-27 09:18:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include <algorithm>
0045 #include <iostream>
0046 #include <iomanip>
0047 #include <cmath>
0048 #include "CexmcAngularRange.hh"
0049
0050
0051 void GetNormalizedAngularRange( const CexmcAngularRangeList & src,
0052 CexmcAngularRangeList & dst )
0053 {
0054 dst = src;
0055 if ( dst.size() < 2 )
0056 return;
0057
0058 std::sort( dst.begin(), dst.end() );
0059
0060 const G4double epsilon( 1E-7 );
0061
0062 for ( CexmcAngularRangeList::iterator k( dst.begin() + 1 );
0063 k != dst.end(); )
0064 {
0065 if ( std::fabs( k->top - ( k - 1 )->top ) < epsilon ||
0066 k->bottom + epsilon >= ( k - 1 )->bottom )
0067 {
0068 k = dst.erase( k );
0069 continue;
0070 }
0071 if ( k->top + epsilon >= ( k - 1 )->bottom )
0072 {
0073 ( k - 1 )->bottom = k->bottom;
0074 k = dst.erase( k );
0075 continue;
0076 }
0077 ++k;
0078 }
0079 }
0080
0081
0082 void GetAngularGaps( const CexmcAngularRangeList & src,
0083 CexmcAngularRangeList & dst )
0084 {
0085 if ( src.empty() )
0086 {
0087 dst.push_back( CexmcAngularRange( 1.0, -1.0 , 0 ) );
0088 return;
0089 }
0090
0091 CexmcAngularRangeList normalizedAngularRanges;
0092 GetNormalizedAngularRange( src, normalizedAngularRanges );
0093
0094 G4int index( 0 );
0095 if ( normalizedAngularRanges[ 0 ].top < 1.0 )
0096 dst.push_back( CexmcAngularRange(
0097 1.0, normalizedAngularRanges[ 0 ].top, index++ ) );
0098
0099 for ( CexmcAngularRangeList::iterator
0100 k( normalizedAngularRanges.begin() );
0101 k != normalizedAngularRanges.end(); ++k )
0102 {
0103 if ( k + 1 == normalizedAngularRanges.end() )
0104 break;
0105 dst.push_back( CexmcAngularRange(
0106 k->bottom, ( k + 1 )->top, index++ ) );
0107 }
0108
0109 if ( normalizedAngularRanges.back().bottom > -1.0 )
0110 dst.push_back( CexmcAngularRange(
0111 normalizedAngularRanges.back().bottom, -1.0, index ) );
0112 }
0113
0114
0115 std::ostream & operator<<( std::ostream & out,
0116 const CexmcAngularRange & angularRange )
0117 {
0118 std::ostream::fmtflags savedFlags( out.flags() );
0119 std::streamsize prec( out.precision() );
0120
0121 out.precision( 4 );
0122 out.flags( std::ios::fixed );
0123
0124 out << std::setw( 2 ) << angularRange.index + 1 << " [" << std::setw( 7 ) <<
0125 angularRange.top << ", " << std::setw( 7 ) << angularRange.bottom <<
0126 ")";
0127
0128 out.precision( prec );
0129 out.flags( savedFlags );
0130
0131 return out;
0132 }
0133
0134
0135 std::ostream & operator<<( std::ostream & out,
0136 const CexmcAngularRangeList & angularRanges )
0137 {
0138 out << std::endl;
0139 for ( CexmcAngularRangeList::const_iterator k( angularRanges.begin() );
0140 k != angularRanges.end(); ++k )
0141 {
0142 out << " " << *k << std::endl;
0143 }
0144
0145 return out;
0146 }
0147