source: trunk/examples/extended/biasing/B02/src/B02RunAction.cc @ 812

Last change on this file since 812 was 807, checked in by garnier, 16 years ago

update

File size: 8.4 KB
Line 
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// $Id: B02RunAction.cc,v 1.3 2007/06/22 13:38:55 ahoward Exp $
28// GEANT4 tag $Name:  $
29//
30#include "B02RunAction.hh"
31#include "B02Run.hh"
32
33//-- In order to obtain detector information.
34#include "G4RunManager.hh"
35#include "B02ImportanceDetectorConstruction.hh"
36#include "G4THitsMap.hh"
37
38#include "G4UnitsTable.hh"
39//=======================================================================
40// B02RunAction
41// 
42//
43//
44//=======================================================================
45// Constructor
46B02RunAction::B02RunAction():
47  FieldName(15),
48  FieldValue(14)
49{
50  // - Prepare data member for B02Run.
51  //   vector represents a list of MultiFunctionalDetector names.
52  theSDName.push_back(G4String("ConcreteSD"));
53}
54
55// Destructor.
56B02RunAction::~B02RunAction()
57{
58  theSDName.clear();
59}
60
61//
62//==
63G4Run* B02RunAction::GenerateRun()
64{
65  // Generate new RUN object, which is specially
66  // dedicated for MultiFunctionalDetector scheme.
67  //  Detail description can be found in B02Run.hh/cc.
68  return new B02Run(theSDName);
69}
70
71//
72//==
73void B02RunAction::BeginOfRunAction(const G4Run* aRun)
74{
75  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
76}
77
78//
79//==
80void B02RunAction::EndOfRunAction(const G4Run* aRun)
81{
82    G4cout << " ###### EndOfRunAction  " <<G4endl;
83  //- B02Run object.
84  B02Run* re02Run = (B02Run*)aRun;
85  //--- Dump all socred quantities involved in B02Run.
86  // re02Run->DumpAllScorer();
87  //---
88  G4RunManager* mgr = G4RunManager::GetRunManager();
89  //
90 
91  for ( G4int i = 0; i < (G4int)theSDName.size(); i++ ){
92    const G4VUserDetectorConstruction* vdet = mgr->GetUserDetectorConstruction();
93    //    B02DetectorConstruction* bdet = (B02DetectorConstruction*)vdet;
94    B02ImportanceDetectorConstruction* bdet = (B02ImportanceDetectorConstruction*)vdet;
95    //
96   
97    //---------------------------------------------
98    // Dump accumulated quantities for this RUN.
99    //  (Display only central region of x-y plane)
100    //      0       ConcreteSD/Collisions
101    //      1       ConcreteSD/CollWeight
102    //      2       ConcreteSD/Population
103    //      3       ConcreteSD/TrackEnter
104    //      4       ConcreteSD/SL
105    //      5       ConcreteSD/SLW
106    //      6       ConcreteSD/SLWE
107    //      7       ConcreteSD/SLW_V
108    //      8       ConcreteSD/SLWE_V
109    //---------------------------------------------
110    G4THitsMap<G4double>* Collisions = re02Run->GetHitsMap(theSDName[i]+"/Collisions");
111    G4THitsMap<G4double>* CollWeight = re02Run->GetHitsMap(theSDName[i]+"/CollWeight");
112    G4THitsMap<G4double>* Population = re02Run->GetHitsMap(theSDName[i]+"/Population");
113    G4THitsMap<G4double>* TrackEnter = re02Run->GetHitsMap(theSDName[i]+"/TrackEnter");
114    G4THitsMap<G4double>* SL = re02Run->GetHitsMap(theSDName[i]+"/SL");
115    G4THitsMap<G4double>* SLW = re02Run->GetHitsMap(theSDName[i]+"/SLW");
116    G4THitsMap<G4double>* SLWE = re02Run->GetHitsMap(theSDName[i]+"/SLWE");
117    G4THitsMap<G4double>* SLW_V = re02Run->GetHitsMap(theSDName[i]+"/SLW_V");
118    G4THitsMap<G4double>* SLWE_V = re02Run->GetHitsMap(theSDName[i]+"/SLWE_V");
119
120
121    G4cout << "=============================================================" <<G4endl;
122    G4cout << " Number of event processed : "<< aRun->GetNumberOfEvent() << G4endl;
123    G4cout << "=============================================================" <<G4endl;
124
125    std::ostream *myout = &G4cout;
126    PrintHeader(myout);
127
128    for ( G4int iz = 0; iz < 20; iz++){ 
129      G4double* SumCollisions = (*Collisions)[iz];
130      G4double* SumCollWeight = (*CollWeight)[iz];
131      G4double* Populations   = (*Population)[iz];
132      G4double* TrackEnters   = (*TrackEnter)[iz];
133      G4double* SLs   = (*SL)[iz];
134      G4double* SLWs   = (*SLW)[iz];
135      G4double* SLWEs   = (*SLWE)[iz];
136      G4double* SLW_Vs   = (*SLW_V)[iz];
137      G4double* SLWE_Vs   = (*SLWE_V)[iz];
138      if ( !SumCollisions ) SumCollisions = new G4double(0.0);
139      if ( !SumCollWeight ) SumCollWeight = new G4double(0.0);
140      if ( !Populations   ) Populations   = new G4double(0.0);
141      if ( !TrackEnters   ) { G4cout << " NO TRACKS - WHY? " << G4endl; TrackEnters   = new G4double(0.0);}
142      if ( !SLs   ) SLs   = new G4double(0.0);
143      if ( !SLWs   ) SLWs   = new G4double(0.0);
144      if ( !SLWEs   ) SLWEs   = new G4double(0.0);
145      if ( !SLW_Vs   ) SLW_Vs   = new G4double(0.0);
146      if ( !SLWE_Vs   ) SLWE_Vs   = new G4double(0.0);
147      G4double NumWeightedEnergy =0.0;
148      G4double FluxWeightedEnergy=0.0; 
149      G4double AverageTrackWeight=0.0;
150      if ( *SLW_Vs !=0. ) NumWeightedEnergy  = (*SLWE_Vs)/(*SLW_Vs);
151      if ( *SLWs   !=0. ) FluxWeightedEnergy  = (*SLWEs)/(*SLWs);
152      if ( *SLs    !=0. ) AverageTrackWeight  = (*SLWs)/(*SLs);
153      G4String cname = bdet->GetCellName(iz);
154      G4cout
155        << std::setw(FieldValue) << cname << " |"
156        << std::setw(FieldValue) << (*TrackEnters) << " |"
157        << std::setw(FieldValue) << (*Populations) << " |"
158        << std::setw(FieldValue) << (*SumCollisions) << " |"
159        << std::setw(FieldValue) << (*SumCollWeight) << " |"
160        << std::setw(FieldValue) << NumWeightedEnergy << " |"
161        << std::setw(FieldValue) << FluxWeightedEnergy << " |"
162        << std::setw(FieldValue) << AverageTrackWeight << " |"
163        << std::setw(FieldValue) << (*SLs) << " |"
164        << std::setw(FieldValue) << (*SLWs) << " |"
165        << std::setw(FieldValue) << (*SLW_Vs) << " |"
166        << std::setw(FieldValue) << (*SLWEs) << " |"
167        << std::setw(FieldValue) << (*SLWE_Vs) << " |"
168        << G4endl;
169    }
170    G4cout << "============================================="<<G4endl;
171  }
172}
173//
174// --
175
176void B02RunAction::PrintHeader(std::ostream *out)
177{
178  std::vector<G4String> vecScoreName;
179  vecScoreName.push_back("Tr.Entering");
180  vecScoreName.push_back("Population");
181  vecScoreName.push_back("Collisions");
182  vecScoreName.push_back("Coll*WGT");
183  vecScoreName.push_back("NumWGTedE");
184  vecScoreName.push_back("FluxWGTedE");
185  vecScoreName.push_back("Av.Tr.WGT");
186  vecScoreName.push_back("SL");
187  vecScoreName.push_back("SLW");
188  vecScoreName.push_back("SLW_v");
189  vecScoreName.push_back("SLWE");
190  vecScoreName.push_back("SLWE_v");
191
192  // head line
193  //std::string vname = FillString("Volume", ' ', FieldName+1);
194  //*out << vname << '|';
195  std::string vname;
196  *out << std::setw(FieldValue) << "Volume" << " |";
197  for (std::vector<G4String>::iterator it = vecScoreName.begin();
198       it != vecScoreName.end(); it++) {
199      //vname = FillString((*it),
200//                     ' ',
201//                     FieldValue+1,
202//                     false);
203//    *out << vname << '|';
204      *out << std::setw(FieldValue) << (*it) << " |";
205  }
206  *out << G4endl; 
207}
208
209std::string B02RunAction::FillString(const std::string &name, 
210                                       char c, G4int n, G4bool back)
211{
212  std::string fname("");
213  G4int k = n - name.size();
214  if (k > 0) {
215    if (back) {
216      fname = name;
217      fname += std::string(k,c);
218    }
219    else {
220      fname = std::string(k,c);
221      fname += name;
222    }
223  }
224  else {
225    fname = name;
226  }
227  return fname;
228}
Note: See TracBrowser for help on using the repository browser.