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