Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-27 09:18:07

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /*
0027  * ============================================================================
0028  *
0029  *       Filename:  CexmcAngularRange.cc
0030  *
0031  *    Description:  angular range object
0032  *
0033  *        Version:  1.0
0034  *        Created:  28.12.2009 22:35:07
0035  *       Revision:  none
0036  *       Compiler:  gcc
0037  *
0038  *         Author:  Alexey Radkov (), 
0039  *        Company:  PNPI
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