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