File indexing completed on 2025-01-31 09:21:53
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 <limits>
0045 #include <vector>
0046 #include <string>
0047 #include <iostream>
0048 #include <iomanip>
0049 #include "CexmcRunAction.hh"
0050 #include "CexmcPhysicsManager.hh"
0051 #include "CexmcProductionModel.hh"
0052 #include "CexmcAngularRange.hh"
0053 #include "CexmcException.hh"
0054
0055
0056 CexmcRunAction::CexmcRunAction( CexmcPhysicsManager * physicsManager_ ) :
0057 physicsManager( physicsManager_ )
0058 {
0059 }
0060
0061
0062 G4Run * CexmcRunAction::GenerateRun( void )
0063 {
0064 return new CexmcRun;
0065 }
0066
0067
0068 void CexmcRunAction::PrintResults(
0069 const CexmcNmbOfHitsInRanges & nmbOfHitsSampled,
0070 const CexmcNmbOfHitsInRanges & nmbOfHitsSampledFull,
0071 const CexmcNmbOfHitsInRanges & nmbOfHitsTriggeredRealRange,
0072 const CexmcNmbOfHitsInRanges & nmbOfHitsTriggeredRecRange,
0073 const CexmcNmbOfHitsInRanges & nmbOfOrphanHits,
0074 const CexmcAngularRangeList & angularRanges,
0075 G4int nmbOfFalseHitsTriggeredEDT,
0076 G4int nmbOfFalseHitsTriggeredRec )
0077 {
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 const size_t nmbOfAuxColumns( 6 );
0088 const std::streamsize prec( 8 );
0089 std::vector< std::vector< std::string > > auxStrings;
0090 size_t maxSize[ nmbOfAuxColumns ];
0091
0092 for ( size_t i( 0 ); i < nmbOfAuxColumns; ++i )
0093 maxSize[ i ] = 0;
0094
0095
0096
0097
0098 maxSize[ 0 ] = prec + 2;
0099 maxSize[ 3 ] = prec + 2;
0100
0101 for ( CexmcAngularRangeList::const_iterator k( angularRanges.begin() );
0102 k != angularRanges.end(); ++k )
0103 {
0104 G4int total( 0 );
0105 G4int totalFull( 0 );
0106 G4int triggered( 0 );
0107 G4double acc( std::numeric_limits< G4double >::quiet_NaN() );
0108
0109 CexmcNmbOfHitsInRanges::const_iterator found(
0110 nmbOfHitsSampled.find( k->index ) );
0111 if ( found != nmbOfHitsSampled.end() )
0112 {
0113 total = found->second;
0114 acc = 0;
0115 }
0116
0117 found = nmbOfHitsSampledFull.find( k->index );
0118 if ( found != nmbOfHitsSampledFull.end() )
0119 {
0120 totalFull = found->second;
0121 }
0122
0123 G4double accSave( acc );
0124 found = nmbOfHitsTriggeredRealRange.find( k->index );
0125 if ( found != nmbOfHitsTriggeredRealRange.end() )
0126 {
0127 triggered = found->second;
0128 if ( total > 0 )
0129 acc = G4double( triggered ) / total;
0130 }
0131
0132 std::ostringstream auxStringStream[ nmbOfAuxColumns ];
0133
0134 for ( size_t i( 0 ); i < nmbOfAuxColumns; ++i )
0135 {
0136 auxStringStream[ i ].precision( prec );
0137 auxStringStream[ i ].flags( std::ios::fixed );
0138 }
0139
0140 G4int i( 0 );
0141
0142 auxStringStream[ i ] << acc;
0143 auxStringStream[ ++i ] << triggered;
0144 size_t size( auxStringStream[ i ].str().size() );
0145 maxSize[ i ] = maxSize[ i ] > size ? maxSize[ i ] : size;
0146 auxStringStream[ ++i ] << total;
0147 size = auxStringStream[ i ].str().size();
0148 maxSize[ i ] = maxSize[ i ] > size ? maxSize[ i ] : size;
0149
0150 triggered = 0;
0151 acc = accSave;
0152 found = nmbOfHitsTriggeredRecRange.find( k->index );
0153 if ( found != nmbOfHitsTriggeredRecRange.end() )
0154 {
0155 triggered = found->second;
0156 if ( total > 0 )
0157 acc = G4double( triggered ) / total;
0158 }
0159
0160 auxStringStream[ ++i ] << acc;
0161 auxStringStream[ ++i ] << triggered;
0162 size = auxStringStream[ i ].str().size();
0163 maxSize[ i ] = maxSize[ i ] > size ? maxSize[ i ] : size;
0164 auxStringStream[ ++i ] << totalFull;
0165 size = auxStringStream[ i ].str().size();
0166 maxSize[ i ] = maxSize[ i ] > size ? maxSize[ i ] : size;
0167
0168 std::vector< std::string > auxString( nmbOfAuxColumns );
0169
0170 for ( size_t j( 0 ); j < nmbOfAuxColumns; ++j )
0171 auxString[ j ] = auxStringStream[ j ].str();
0172
0173 auxStrings.push_back( auxString );
0174 }
0175
0176 G4cout << " --- Setup acceptances (range | real (trg / mon) | "
0177 "rec (trg / mon / all)):" << G4endl;
0178
0179 G4int i( 0 );
0180 for ( CexmcAngularRangeList::const_iterator k( angularRanges.begin() );
0181 k != angularRanges.end(); ++k )
0182 {
0183 G4cout << " " << *k;
0184 G4int j( 0 );
0185 G4cout << " | " << std::setw( maxSize[ j ] );
0186 G4cout << auxStrings[ i ][ j++ ];
0187 G4cout << " ( " << std::setw( maxSize[ j ] );
0188 G4cout << auxStrings[ i ][ j++ ];
0189 G4cout << " / " << std::setw( maxSize[ j ] );
0190 G4cout << auxStrings[ i ][ j++ ];
0191 G4cout << " ) | " << std::setw( maxSize[ j ] );
0192 G4cout << auxStrings[ i ][ j++ ];
0193 G4cout << " ( " << std::setw( maxSize[ j ] );
0194 G4cout << auxStrings[ i ][ j++ ];
0195 G4cout << " / " << std::setw( maxSize[ 2 ] );
0196 G4cout << auxStrings[ i ][ 2 ];
0197 G4cout << " / " << std::setw( maxSize[ j ] );
0198 G4cout << auxStrings[ i++ ][ j++ ] << " )" << G4endl;
0199 }
0200
0201 CexmcAngularRangeList angularGaps;
0202 GetAngularGaps( angularRanges, angularGaps );
0203
0204 if ( ! angularGaps.empty() )
0205 {
0206 G4cout << " orphans detected: " << G4endl;
0207 for ( CexmcAngularRangeList::const_iterator k( angularGaps.begin() );
0208 k != angularGaps.end(); ++k )
0209 {
0210 G4cout << " " << *k;
0211 G4int total( 0 );
0212
0213 CexmcNmbOfHitsInRanges::const_iterator found(
0214 nmbOfOrphanHits.find( k->index ) );
0215 if ( found != nmbOfHitsSampled.end() )
0216 {
0217 total = found->second;
0218 }
0219 G4cout << " " << total << G4endl;
0220 }
0221 }
0222
0223 G4cout << " ---" << G4endl;
0224 G4cout << " False hits (edt | rec): " <<
0225 nmbOfFalseHitsTriggeredEDT << " | " << nmbOfFalseHitsTriggeredRec <<
0226 G4endl;
0227 }
0228
0229
0230 void CexmcRunAction::EndOfRunAction( const G4Run * run )
0231 {
0232 const CexmcRun * theRun( static_cast< const CexmcRun * >( run ) );
0233
0234 const CexmcNmbOfHitsInRanges & nmbOfHitsSampled(
0235 theRun->GetNmbOfHitsSampled() );
0236 const CexmcNmbOfHitsInRanges & nmbOfHitsSampledFull(
0237 theRun->GetNmbOfHitsSampledFull() );
0238 const CexmcNmbOfHitsInRanges & nmbOfHitsTriggeredRealRange(
0239 theRun->GetNmbOfHitsTriggeredRealRange() );
0240 const CexmcNmbOfHitsInRanges & nmbOfHitsTriggeredRecRange(
0241 theRun->GetNmbOfHitsTriggeredRecRange() );
0242 const CexmcNmbOfHitsInRanges & nmbOfOrphanHits(
0243 theRun->GetNmbOfOrphanHits() );
0244
0245 CexmcProductionModel * productionModel(
0246 physicsManager->GetProductionModel() );
0247 if ( ! productionModel )
0248 throw CexmcException( CexmcWeirdException );
0249
0250 const CexmcAngularRangeList & angularRanges(
0251 productionModel->GetAngularRanges() );
0252
0253 G4cout << G4endl;
0254 PrintResults( nmbOfHitsSampled, nmbOfHitsSampledFull,
0255 nmbOfHitsTriggeredRealRange, nmbOfHitsTriggeredRecRange,
0256 nmbOfOrphanHits, angularRanges,
0257 theRun->GetNmbOfFalseHitsTriggeredEDT(),
0258 theRun->GetNmbOfFalseHitsTriggeredRec() );
0259 G4cout << G4endl;
0260 }
0261