source: trunk/source/digits_hits/utils/test/test2/src/Test2RunPS.cc@ 1354

Last change on this file since 1354 was 1350, checked in by garnier, 15 years ago

update to last version 4.9.4

File size: 4.0 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: Test2RunPS.cc,v 1.1 2010/11/03 08:48:57 taso Exp $
28// GEANT4 tag $Name: $
29//
30
31#include "Test2RunPS.hh"
32#include "G4Event.hh"
33#include "G4HCofThisEvent.hh"
34#include "G4SDManager.hh"
35
36#include <fstream>
37
38Test2RunPS::Test2RunPS(G4String& detName,std::vector<G4String>& hcnameVec) {
39
40 G4SDManager * SDMan = G4SDManager::GetSDMpointer();
41 SDMan->SetVerboseLevel(1);
42 DTName = detName;
43 G4String fullName;
44 for(size_t i = 0; i < hcnameVec.size() ; i++) {
45 fullName = detName+"/"+hcnameVec[i];
46 G4int id = SDMan->GetCollectionID(fullName);
47 if ( id >= 0 ) {
48 HCName.push_back(fullName);
49 CollID.push_back(id);
50 MapSum.push_back(new G4THitsMap<G4double>(detName,hcnameVec[i]));
51 }
52 }
53}
54
55Test2RunPS::~Test2RunPS() {
56 //--- Clear HitsMap for RUN
57 G4int Nmap = MapSum.size();
58 for ( G4int i = 0; i < Nmap; i++){
59 if(MapSum[i] ) MapSum[i]->clear();
60 }
61 HCName.clear();
62 CollID.clear();
63 MapSum.clear();
64}
65
66#include "Test2PhantomHit.hh"
67
68void Test2RunPS::RecordEvent(const G4Event* evt) {
69
70 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
71 if(!HCE) return;
72 numberOfEvent++;
73
74 G4int Nmap = MapSum.size();
75 for(G4int i = 0; i < Nmap; i++) {
76 G4THitsMap<G4double>* evtMap = (G4THitsMap<G4double>*)(HCE->GetHC(CollID[i]));
77 *MapSum[i] += *evtMap;
78 }
79}
80
81void Test2RunPS::DumpQuantitiesToFile(){
82 G4int Nmap = MapSum.size();
83 for(G4int i = 0; i < Nmap; i++) {
84 DumpQuantitiyToFile(i);
85 }
86}
87
88void Test2RunPS::DumpQuantitiyToFile(G4int i){
89 if ( MapSum.size() > size_t(i+1) && MapSum[i] ) {
90 G4String filename = HCName[i];
91 DumpQuantitiyToFile(MapSum[i],filename);
92 }
93}
94
95void Test2RunPS::DumpQuantitiyToFile(const G4THitsMap<G4double> *map,
96 G4String& fileName){
97 std::ofstream ofile(fileName);
98 if ( ofile ){
99 std::map<G4int,G4double*>::iterator itr = map->GetMap()->begin();
100 for(; itr != map->GetMap()->end(); itr++) {
101 ofile << (itr->first) << "\t" << *(itr->second) << G4endl;
102 }
103 }
104 ofile.close();
105}
106
107G4double Test2RunPS::GetTotal(G4int i) const{
108 if ( MapSum.size() > size_t(i+1) && MapSum[i] ) {
109 return GetTotal(MapSum[i]);
110 }else{
111 return 0;
112 }
113}
114
115G4double Test2RunPS::GetTotal(const G4THitsMap<G4double> *map) const
116{
117 G4double total = 0.;
118 std::map<G4int,G4double*>::iterator itr = map->GetMap()->begin();
119 for(; itr != map->GetMap()->end(); itr++) {
120 total += *(itr->second);
121 }
122 return total;
123}
124
125
126
127
128
Note: See TracBrowser for help on using the repository browser.