Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:53

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:  CexmcRunAction.cc
0030  *
0031  *    Description:  run action
0032  *
0033  *        Version:  1.0
0034  *        Created:  20.12.2009 00:18:05
0035  *       Revision:  none
0036  *       Compiler:  gcc
0037  *
0038  *         Author:  Alexey Radkov (), 
0039  *        Company:  PNPI
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     /* there are 7 auxiliary columns:
0079      * 1. acc real, [floating point number]
0080      * 2. triggered real,
0081      * 3. total hits sampled and monitored,
0082      * 4. acc reconstructed, [floating point number]
0083      * 5. triggered reconstructed,
0084      * 6. total hits sampled and monitored (identical with #3),
0085      * 7. total hits sampled.
0086      * As far as #3 and #6 are identical, nmbOfAuxColumns = 6 */
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     /* addition of 2 (for '0.') for acceptances, that are floating point
0096      * numbers, is correct as far as ios::fixed will be used, and no negative
0097      * values are expected, and values will be less than 1. */
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