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 | #include "Test2SDHitSum.hh" |
---|
27 | #include <fstream> |
---|
28 | #include <map> |
---|
29 | |
---|
30 | Test2SDHitSum::Test2SDHitSum(const G4String& detName, |
---|
31 | std::vector<G4String>& hcnameVec) { |
---|
32 | DTName = detName; |
---|
33 | G4String fullName; |
---|
34 | for(size_t i = 0; i < hcnameVec.size() ; i++) { |
---|
35 | fullName = detName+"/"+hcnameVec[i]; |
---|
36 | G4cout << "AAAA" << fullName << G4endl; |
---|
37 | HCName.push_back(fullName); |
---|
38 | MapSum.push_back(new G4THitsMap<G4double>(detName,hcnameVec[i])); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | Test2SDHitSum::~Test2SDHitSum() { |
---|
43 | //--- Clear HitsMap for RUN |
---|
44 | G4int Nmap = MapSum.size(); |
---|
45 | for ( G4int i = 0; i < Nmap; i++){ |
---|
46 | if(MapSum[i] ) MapSum[i]->clear(); |
---|
47 | } |
---|
48 | HCName.clear(); |
---|
49 | MapSum.clear(); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | void Test2SDHitSum::Analyze(Test2PhantomHit* hc){ |
---|
54 | G4double one = 1.0; |
---|
55 | G4int index = hc->GetID(); |
---|
56 | // |
---|
57 | // eDep |
---|
58 | // |
---|
59 | G4double eDep = hc->GetEdep(); |
---|
60 | MapSum[0]->add(index,eDep); |
---|
61 | |
---|
62 | // |
---|
63 | // trackLength |
---|
64 | // |
---|
65 | G4double tlen = hc->GetTrackLength(); |
---|
66 | // |
---|
67 | // trackLengthGamma |
---|
68 | if ( hc->GetParticleName() == "gamma" ){ |
---|
69 | MapSum[1]->add(index,tlen); |
---|
70 | } |
---|
71 | // |
---|
72 | // trackLengthElec |
---|
73 | if ( hc->GetParticleName() == "e-" ){ |
---|
74 | MapSum[2]->add(index,tlen); |
---|
75 | } |
---|
76 | // |
---|
77 | // trackLengthPosi |
---|
78 | if ( hc->GetParticleName() == "e+" ){ |
---|
79 | MapSum[3]->add(index,tlen); |
---|
80 | } |
---|
81 | // |
---|
82 | // nStepGamma |
---|
83 | if ( hc->GetParticleName() == "gamma" ){ |
---|
84 | MapSum[4]->add(index,one); |
---|
85 | } |
---|
86 | // |
---|
87 | // nStepElec |
---|
88 | if ( hc->GetParticleName() == "e-" ){ |
---|
89 | MapSum[5]->add(index,one); |
---|
90 | } |
---|
91 | // |
---|
92 | // nStepPosi |
---|
93 | if ( hc->GetParticleName() == "e+" ){ |
---|
94 | MapSum[6]->add(index,one); |
---|
95 | } |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | void Test2SDHitSum::DumpQuantitiesToFile(){ |
---|
100 | G4int Nmap = MapSum.size(); |
---|
101 | G4cout << "Nmap " << Nmap<<G4endl; |
---|
102 | for(G4int i = 0; i < Nmap; i++) { |
---|
103 | DumpQuantitiyToFile(i); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | void Test2SDHitSum::DumpQuantitiyToFile(G4int i){ |
---|
108 | if ( MapSum.size() > size_t(i+1) && MapSum[i] ) { |
---|
109 | G4String filename = HCName[i]; |
---|
110 | DumpQuantitiyToFile(MapSum[i],filename); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | void Test2SDHitSum::DumpQuantitiyToFile(const G4THitsMap<G4double> *map, |
---|
115 | G4String& fileName){ |
---|
116 | std::ofstream ofile(fileName); |
---|
117 | if ( ofile ){ |
---|
118 | std::map<G4int,G4double*>::iterator itr = map->GetMap()->begin(); |
---|
119 | for(; itr != map->GetMap()->end(); itr++) { |
---|
120 | ofile << (itr->first) << "\t" << *(itr->second) << G4endl; |
---|
121 | } |
---|
122 | } |
---|
123 | ofile.close(); |
---|
124 | } |
---|
125 | |
---|
126 | G4double Test2SDHitSum::GetTotal(G4int i) const{ |
---|
127 | if ( MapSum.size() > size_t(i+1) && MapSum[i] ) { |
---|
128 | return GetTotal(MapSum[i]); |
---|
129 | }else{ |
---|
130 | return 0; |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | G4double Test2SDHitSum::GetTotal(const G4THitsMap<G4double>* map) const{ |
---|
135 | G4double total = 0.; |
---|
136 | std::map<G4int,G4double*>::iterator itr = map->GetMap()->begin(); |
---|
137 | for(; itr != map->GetMap()->end(); itr++) { |
---|
138 | total += *(itr->second); |
---|
139 | } |
---|
140 | return total; |
---|
141 | } |
---|
142 | |
---|
143 | |
---|