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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/ChargeExchangeMC/src/CexmcRunAction.cc (Version 11.3.0) and /examples/advanced/ChargeExchangeMC/src/CexmcRunAction.cc (Version 11.2.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 /*                                                 26 /*
 27  * ===========================================     27  * ============================================================================
 28  *                                                 28  *
 29  *       Filename:  CexmcRunAction.cc              29  *       Filename:  CexmcRunAction.cc
 30  *                                                 30  *
 31  *    Description:  run action                     31  *    Description:  run action
 32  *                                                 32  *
 33  *        Version:  1.0                            33  *        Version:  1.0
 34  *        Created:  20.12.2009 00:18:05            34  *        Created:  20.12.2009 00:18:05
 35  *       Revision:  none                           35  *       Revision:  none
 36  *       Compiler:  gcc                            36  *       Compiler:  gcc
 37  *                                                 37  *
 38  *         Author:  Alexey Radkov (),              38  *         Author:  Alexey Radkov (), 
 39  *        Company:  PNPI                           39  *        Company:  PNPI
 40  *                                                 40  *
 41  * ===========================================     41  * ============================================================================
 42  */                                                42  */
 43                                                    43 
 44 #include <limits>                                  44 #include <limits>
 45 #include <vector>                                  45 #include <vector>
 46 #include <string>                                  46 #include <string>
 47 #include <iostream>                                47 #include <iostream>
 48 #include <iomanip>                                 48 #include <iomanip>
 49 #include "CexmcRunAction.hh"                       49 #include "CexmcRunAction.hh"
 50 #include "CexmcPhysicsManager.hh"                  50 #include "CexmcPhysicsManager.hh"
 51 #include "CexmcProductionModel.hh"                 51 #include "CexmcProductionModel.hh"
 52 #include "CexmcAngularRange.hh"                    52 #include "CexmcAngularRange.hh"
 53 #include "CexmcException.hh"                       53 #include "CexmcException.hh"
 54                                                    54 
 55                                                    55 
 56 CexmcRunAction::CexmcRunAction( CexmcPhysicsMa     56 CexmcRunAction::CexmcRunAction( CexmcPhysicsManager *  physicsManager_ ) :
 57     physicsManager( physicsManager_ )              57     physicsManager( physicsManager_ )
 58 {                                                  58 {
 59 }                                                  59 }
 60                                                    60 
 61                                                    61 
 62 G4Run *  CexmcRunAction::GenerateRun( void )       62 G4Run *  CexmcRunAction::GenerateRun( void )
 63 {                                                  63 {
 64     return new CexmcRun;                           64     return new CexmcRun;
 65 }                                                  65 }
 66                                                    66 
 67                                                    67 
 68 void  CexmcRunAction::PrintResults(                68 void  CexmcRunAction::PrintResults(
 69                     const CexmcNmbOfHitsInRang     69                     const CexmcNmbOfHitsInRanges &  nmbOfHitsSampled,
 70                     const CexmcNmbOfHitsInRang     70                     const CexmcNmbOfHitsInRanges &  nmbOfHitsSampledFull,
 71                     const CexmcNmbOfHitsInRang     71                     const CexmcNmbOfHitsInRanges &  nmbOfHitsTriggeredRealRange,
 72                     const CexmcNmbOfHitsInRang     72                     const CexmcNmbOfHitsInRanges &  nmbOfHitsTriggeredRecRange,
 73                     const CexmcNmbOfHitsInRang     73                     const CexmcNmbOfHitsInRanges &  nmbOfOrphanHits,
 74                     const CexmcAngularRangeLis     74                     const CexmcAngularRangeList &  angularRanges,
 75                     G4int  nmbOfFalseHitsTrigg     75                     G4int  nmbOfFalseHitsTriggeredEDT,
 76                     G4int  nmbOfFalseHitsTrigg     76                     G4int  nmbOfFalseHitsTriggeredRec )
 77 {                                                  77 {
 78     /* there are 7 auxiliary columns:              78     /* there are 7 auxiliary columns:
 79      * 1. acc real, [floating point number]        79      * 1. acc real, [floating point number]
 80      * 2. triggered real,                          80      * 2. triggered real,
 81      * 3. total hits sampled and monitored,        81      * 3. total hits sampled and monitored,
 82      * 4. acc reconstructed, [floating point n     82      * 4. acc reconstructed, [floating point number]
 83      * 5. triggered reconstructed,                 83      * 5. triggered reconstructed,
 84      * 6. total hits sampled and monitored (id     84      * 6. total hits sampled and monitored (identical with #3),
 85      * 7. total hits sampled.                      85      * 7. total hits sampled.
 86      * As far as #3 and #6 are identical, nmbO     86      * As far as #3 and #6 are identical, nmbOfAuxColumns = 6 */
 87     const size_t                                   87     const size_t                               nmbOfAuxColumns( 6 );
 88     const std::streamsize                          88     const std::streamsize                      prec( 8 );
 89     std::vector< std::vector< std::string > >      89     std::vector< std::vector< std::string > >  auxStrings;
 90     size_t                                         90     size_t                                     maxSize[ nmbOfAuxColumns ];
 91                                                    91 
 92     for ( size_t  i( 0 ); i < nmbOfAuxColumns;     92     for ( size_t  i( 0 ); i < nmbOfAuxColumns; ++i )
 93         maxSize[ i ] = 0;                          93         maxSize[ i ] = 0;
 94                                                    94 
 95     /* addition of 2 (for '0.') for acceptance     95     /* addition of 2 (for '0.') for acceptances, that are floating point
 96      * numbers, is correct as far as ios::fixe     96      * numbers, is correct as far as ios::fixed will be used, and no negative
 97      * values are expected, and values will be     97      * values are expected, and values will be less than 1. */
 98     maxSize[ 0 ] = prec + 2;                       98     maxSize[ 0 ] = prec + 2;
 99     maxSize[ 3 ] = prec + 2;                       99     maxSize[ 3 ] = prec + 2;
100                                                   100 
101     for ( CexmcAngularRangeList::const_iterato    101     for ( CexmcAngularRangeList::const_iterator  k( angularRanges.begin() );
102                                                   102                                                 k != angularRanges.end(); ++k )
103     {                                             103     {
104         G4int     total( 0 );                     104         G4int     total( 0 );
105         G4int     totalFull( 0 );                 105         G4int     totalFull( 0 );
106         G4int     triggered( 0 );                 106         G4int     triggered( 0 );
107         G4double  acc( std::numeric_limits< G4    107         G4double  acc( std::numeric_limits< G4double >::quiet_NaN() );
108                                                   108 
109         CexmcNmbOfHitsInRanges::const_iterator    109         CexmcNmbOfHitsInRanges::const_iterator  found(
110                                         nmbOfH    110                                         nmbOfHitsSampled.find( k->index ) );
111         if ( found != nmbOfHitsSampled.end() )    111         if ( found != nmbOfHitsSampled.end() )
112         {                                         112         {
113             total = found->second;                113             total = found->second;
114             acc = 0;                              114             acc = 0;
115         }                                         115         }
116                                                   116 
117         found = nmbOfHitsSampledFull.find( k->    117         found = nmbOfHitsSampledFull.find( k->index );
118         if ( found != nmbOfHitsSampledFull.end    118         if ( found != nmbOfHitsSampledFull.end() )
119         {                                         119         {
120             totalFull = found->second;            120             totalFull = found->second;
121         }                                         121         }
122                                                   122 
123         G4double  accSave( acc );                 123         G4double  accSave( acc );
124         found = nmbOfHitsTriggeredRealRange.fi    124         found = nmbOfHitsTriggeredRealRange.find( k->index );
125         if ( found != nmbOfHitsTriggeredRealRa    125         if ( found != nmbOfHitsTriggeredRealRange.end() )
126         {                                         126         {
127             triggered = found->second;            127             triggered = found->second;
128             if ( total > 0 )                      128             if ( total > 0 )
129                 acc = G4double( triggered ) /     129                 acc = G4double( triggered ) / total;
130         }                                         130         }
131                                                   131 
132         std::ostringstream  auxStringStream[ n    132         std::ostringstream  auxStringStream[ nmbOfAuxColumns ];
133                                                   133 
134         for ( size_t  i( 0 ); i < nmbOfAuxColu    134         for ( size_t  i( 0 ); i < nmbOfAuxColumns; ++i )
135         {                                         135         {
136             auxStringStream[ i ].precision( pr    136             auxStringStream[ i ].precision( prec );
137             auxStringStream[ i ].flags( std::i    137             auxStringStream[ i ].flags( std::ios::fixed );
138         }                                         138         }
139                                                   139 
140         G4int  i( 0 );                            140         G4int  i( 0 );
141                                                   141 
142         auxStringStream[ i ] << acc;              142         auxStringStream[ i ] << acc;
143         auxStringStream[ ++i ] << triggered;      143         auxStringStream[ ++i ] << triggered;
144         size_t  size( auxStringStream[ i ].str    144         size_t  size( auxStringStream[ i ].str().size() );
145         maxSize[ i ] = maxSize[ i ] > size ? m    145         maxSize[ i ] = maxSize[ i ] > size ? maxSize[ i ] : size;
146         auxStringStream[ ++i ] << total;          146         auxStringStream[ ++i ] << total;
147         size = auxStringStream[ i ].str().size    147         size = auxStringStream[ i ].str().size();
148         maxSize[ i ] = maxSize[ i ] > size ? m    148         maxSize[ i ] = maxSize[ i ] > size ? maxSize[ i ] : size;
149                                                   149 
150         triggered = 0;                            150         triggered = 0;
151         acc = accSave;                            151         acc = accSave;
152         found = nmbOfHitsTriggeredRecRange.fin    152         found = nmbOfHitsTriggeredRecRange.find( k->index );
153         if ( found != nmbOfHitsTriggeredRecRan    153         if ( found != nmbOfHitsTriggeredRecRange.end() )
154         {                                         154         {
155             triggered = found->second;            155             triggered = found->second;
156             if ( total > 0 )                      156             if ( total > 0 )
157                 acc = G4double( triggered ) /     157                 acc = G4double( triggered ) / total;
158         }                                         158         }
159                                                   159 
160         auxStringStream[ ++i ] << acc;            160         auxStringStream[ ++i ] << acc;
161         auxStringStream[ ++i ] << triggered;      161         auxStringStream[ ++i ] << triggered;
162         size = auxStringStream[ i ].str().size    162         size = auxStringStream[ i ].str().size();
163         maxSize[ i ] = maxSize[ i ] > size ? m    163         maxSize[ i ] = maxSize[ i ] > size ? maxSize[ i ] : size;
164         auxStringStream[ ++i ] << totalFull;      164         auxStringStream[ ++i ] << totalFull;
165         size = auxStringStream[ i ].str().size    165         size = auxStringStream[ i ].str().size();
166         maxSize[ i ] = maxSize[ i ] > size ? m    166         maxSize[ i ] = maxSize[ i ] > size ? maxSize[ i ] : size;
167                                                   167 
168         std::vector< std::string >  auxString(    168         std::vector< std::string >  auxString( nmbOfAuxColumns );
169                                                   169 
170         for ( size_t  j( 0 ); j < nmbOfAuxColu    170         for ( size_t  j( 0 ); j < nmbOfAuxColumns; ++j )
171             auxString[ j ] = auxStringStream[     171             auxString[ j ] = auxStringStream[ j ].str();
172                                                   172 
173         auxStrings.push_back( auxString );        173         auxStrings.push_back( auxString );
174     }                                             174     }
175                                                   175 
176     G4cout << " --- Setup acceptances (range |    176     G4cout << " --- Setup acceptances (range | real (trg / mon) | "
177               "rec (trg / mon / all)):" << G4e    177               "rec (trg / mon / all)):" << G4endl;
178                                                   178 
179     G4int  i( 0 );                                179     G4int  i( 0 );
180     for ( CexmcAngularRangeList::const_iterato    180     for ( CexmcAngularRangeList::const_iterator  k( angularRanges.begin() );
181                                                   181                                                 k != angularRanges.end(); ++k )
182     {                                             182     {
183         G4cout << "       " << *k;                183         G4cout << "       " << *k;
184         G4int  j( 0 );                            184         G4int  j( 0 );
185         G4cout << "  | " << std::setw( maxSize    185         G4cout << "  | " << std::setw( maxSize[ j ] );
186         G4cout << auxStrings[ i ][ j++ ];         186         G4cout << auxStrings[ i ][ j++ ];
187         G4cout << " ( " << std::setw( maxSize[    187         G4cout << " ( " << std::setw( maxSize[ j ] );
188         G4cout << auxStrings[ i ][ j++ ];         188         G4cout << auxStrings[ i ][ j++ ];
189         G4cout << " / " << std::setw( maxSize[    189         G4cout << " / " << std::setw( maxSize[ j ] );
190         G4cout << auxStrings[ i ][ j++ ];         190         G4cout << auxStrings[ i ][ j++ ];
191         G4cout << " )  | " << std::setw( maxSi    191         G4cout << " )  | " << std::setw( maxSize[ j ] );
192         G4cout << auxStrings[ i ][ j++ ];         192         G4cout << auxStrings[ i ][ j++ ];
193         G4cout << " ( " << std::setw( maxSize[    193         G4cout << " ( " << std::setw( maxSize[ j ] );
194         G4cout << auxStrings[ i ][ j++ ];         194         G4cout << auxStrings[ i ][ j++ ];
195         G4cout << " / " << std::setw( maxSize[    195         G4cout << " / " << std::setw( maxSize[ 2 ] );
196         G4cout << auxStrings[ i ][ 2 ];           196         G4cout << auxStrings[ i ][ 2 ];
197         G4cout << " / " << std::setw( maxSize[    197         G4cout << " / " << std::setw( maxSize[ j ] );
198         G4cout << auxStrings[ i++ ][ j++ ] <<     198         G4cout << auxStrings[ i++ ][ j++ ] << " )" << G4endl;
199     }                                             199     }
200                                                   200 
201     CexmcAngularRangeList  angularGaps;           201     CexmcAngularRangeList  angularGaps;
202     GetAngularGaps( angularRanges, angularGaps    202     GetAngularGaps( angularRanges, angularGaps );
203                                                   203 
204     if ( ! angularGaps.empty() )                  204     if ( ! angularGaps.empty() )
205     {                                             205     {
206         G4cout << "    orphans detected: " <<     206         G4cout << "    orphans detected: " << G4endl;
207         for ( CexmcAngularRangeList::const_ite    207         for ( CexmcAngularRangeList::const_iterator  k( angularGaps.begin() );
208                                                   208                                                 k != angularGaps.end(); ++k )
209         {                                         209         {
210             G4cout << "       " << *k;            210             G4cout << "       " << *k;
211             G4int     total( 0 );                 211             G4int     total( 0 );
212                                                   212 
213             CexmcNmbOfHitsInRanges::const_iter    213             CexmcNmbOfHitsInRanges::const_iterator  found(
214                                             nm    214                                             nmbOfOrphanHits.find( k->index ) );
215             if ( found != nmbOfHitsSampled.end    215             if ( found != nmbOfHitsSampled.end() )
216             {                                     216             {
217                 total = found->second;            217                 total = found->second;
218             }                                     218             }
219             G4cout << " " << total << G4endl;     219             G4cout << " " << total << G4endl;
220         }                                         220         }
221     }                                             221     }
222                                                   222 
223     G4cout << "       ---" << G4endl;             223     G4cout << "       ---" << G4endl;
224     G4cout << "       False hits (edt | rec):     224     G4cout << "       False hits (edt | rec):  " <<
225         nmbOfFalseHitsTriggeredEDT << " | " <<    225         nmbOfFalseHitsTriggeredEDT << " | " << nmbOfFalseHitsTriggeredRec <<
226         G4endl;                                   226         G4endl;
227 }                                                 227 }
228                                                   228 
229                                                   229 
230 void  CexmcRunAction::EndOfRunAction( const G4    230 void  CexmcRunAction::EndOfRunAction( const G4Run *  run )
231 {                                                 231 {
232     const CexmcRun *  theRun( static_cast< con    232     const CexmcRun *  theRun( static_cast< const CexmcRun * >( run ) );
233                                                   233 
234     const CexmcNmbOfHitsInRanges &  nmbOfHitsS    234     const CexmcNmbOfHitsInRanges &  nmbOfHitsSampled(
235                                         theRun    235                                         theRun->GetNmbOfHitsSampled() );
236     const CexmcNmbOfHitsInRanges &  nmbOfHitsS    236     const CexmcNmbOfHitsInRanges &  nmbOfHitsSampledFull(
237                                         theRun    237                                         theRun->GetNmbOfHitsSampledFull() );
238     const CexmcNmbOfHitsInRanges &  nmbOfHitsT    238     const CexmcNmbOfHitsInRanges &  nmbOfHitsTriggeredRealRange(
239                                     theRun->Ge    239                                     theRun->GetNmbOfHitsTriggeredRealRange() );
240     const CexmcNmbOfHitsInRanges &  nmbOfHitsT    240     const CexmcNmbOfHitsInRanges &  nmbOfHitsTriggeredRecRange(
241                                     theRun->Ge    241                                     theRun->GetNmbOfHitsTriggeredRecRange() );
242     const CexmcNmbOfHitsInRanges &  nmbOfOrpha    242     const CexmcNmbOfHitsInRanges &  nmbOfOrphanHits(
243                                         theRun    243                                         theRun->GetNmbOfOrphanHits() );
244                                                   244 
245     CexmcProductionModel *          production    245     CexmcProductionModel *          productionModel(
246                                         physic    246                                         physicsManager->GetProductionModel() );
247     if ( ! productionModel )                      247     if ( ! productionModel )
248             throw CexmcException( CexmcWeirdEx    248             throw CexmcException( CexmcWeirdException );
249                                                   249 
250     const CexmcAngularRangeList &  angularRang    250     const CexmcAngularRangeList &  angularRanges(
251                                         produc    251                                         productionModel->GetAngularRanges() );
252                                                   252 
253     G4cout << G4endl;                             253     G4cout << G4endl;
254     PrintResults( nmbOfHitsSampled, nmbOfHitsS    254     PrintResults( nmbOfHitsSampled, nmbOfHitsSampledFull,
255                   nmbOfHitsTriggeredRealRange,    255                   nmbOfHitsTriggeredRealRange, nmbOfHitsTriggeredRecRange,
256                   nmbOfOrphanHits, angularRang    256                   nmbOfOrphanHits, angularRanges,
257                   theRun->GetNmbOfFalseHitsTri    257                   theRun->GetNmbOfFalseHitsTriggeredEDT(),
258                   theRun->GetNmbOfFalseHitsTri    258                   theRun->GetNmbOfFalseHitsTriggeredRec() );
259     G4cout << G4endl;                             259     G4cout << G4endl;
260 }                                                 260 }
261                                                   261 
262                                                   262