File indexing completed on 2025-12-17 09:28:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include "ElectronRun.hh"
0031
0032 #include "G4MultiFunctionalDetector.hh"
0033 #include "G4SDManager.hh"
0034 #include "G4SystemOfUnits.hh"
0035 #include "G4VPrimitiveScorer.hh"
0036
0037 #include <assert.h>
0038
0039
0040
0041 ElectronRun::ElectronRun() : G4Run(), fMap()
0042 {
0043 fMap[0] = new G4THitsMap<G4double>("MyDetector", "cell flux");
0044 fMap[1] = new G4THitsMap<G4double>("MyDetector", "e cell flux");
0045 fMap[2] = new G4THitsMap<G4double>("MyDetector", "population");
0046 fMap[3] = new G4THitsMap<G4double>("MyDetector", "e population");
0047 }
0048
0049
0050
0051 ElectronRun::~ElectronRun()
0052 {
0053
0054 std::map<G4int, G4THitsMap<G4double>*>::iterator iter = fMap.begin();
0055
0056 while (iter != fMap.end()) {
0057 delete iter->second;
0058 iter++;
0059 }
0060 }
0061
0062
0063
0064 void ElectronRun::RecordEvent(const G4Event* anEvent)
0065 {
0066
0067 G4HCofThisEvent* eventHitCollection = anEvent->GetHCofThisEvent();
0068
0069 if (!eventHitCollection) return;
0070
0071
0072 std::map<G4int, G4THitsMap<G4double>*>::iterator iter = fMap.begin();
0073
0074 while (iter != fMap.end()) {
0075 G4int id = iter->first;
0076
0077
0078 G4THitsMap<G4double>* eventHitsMap =
0079 dynamic_cast<G4THitsMap<G4double>*>(eventHitCollection->GetHC(id));
0080
0081
0082 assert(0 != eventHitsMap);
0083
0084
0085 *(iter->second) += *eventHitsMap;
0086
0087 iter++;
0088 }
0089
0090 G4Run::RecordEvent(anEvent);
0091 }
0092
0093
0094
0095 void ElectronRun::DumpData(G4String& outputFileSpec) const
0096 {
0097
0098 std::vector<G4String> title;
0099 title.push_back("Radius");
0100
0101
0102 std::map<G4int, std::vector<G4double>> output;
0103
0104 G4int nThetaBins = 233;
0105
0106
0107 G4int nEnergyBins = fMap.size();
0108
0109 G4int i(0), j(0);
0110
0111
0112 for (i = 0; i < nThetaBins; i++) {
0113 for (j = 0; j < nEnergyBins; j++) {
0114 output[i].push_back(0);
0115 }
0116 }
0117
0118 i = 0;
0119
0120
0121 std::map<G4int, G4THitsMap<G4double>*>::const_iterator iter = fMap.begin();
0122
0123 while (iter != fMap.end()) {
0124 G4THitsMap<G4double>* hitMap = iter->second;
0125
0126 title.push_back(hitMap->GetName());
0127
0128 std::map<G4int, G4double*>* myMap = hitMap->GetMap();
0129
0130 for (j = 0; j < nThetaBins; j++) {
0131 G4double* current = (*myMap)[j];
0132 if (0 != current) output[j][i] = (*current);
0133 }
0134
0135 i++;
0136 iter++;
0137 }
0138
0139 Print(title, output, outputFileSpec);
0140 }
0141
0142
0143
0144 void ElectronRun::Print(const std::vector<G4String>& title,
0145 const std::map<G4int, std::vector<G4double>>& myMap,
0146 G4String& outputFileSpec) const
0147 {
0148
0149 std::ofstream outFile(outputFileSpec);
0150
0151
0152 std::vector<G4String>::const_iterator titleIter = title.begin();
0153
0154 while (titleIter != title.end()) {
0155 G4cout << std::setw(8) << *titleIter << " ";
0156 titleIter++;
0157 }
0158
0159 G4cout << G4endl;
0160
0161
0162 std::map<G4int, std::vector<G4double>>::const_iterator iter = myMap.begin();
0163
0164 while (iter != myMap.end()) {
0165 G4cout << std::setw(8) << std::setprecision(3) << iter->first << " ";
0166
0167 std::vector<G4double>::const_iterator energyBinIter = iter->second.begin();
0168
0169
0170
0171
0172
0173
0174
0175
0176 G4int ringNum = iter->first;
0177 G4double areaCorrection = 233. * 233. / ((ringNum + 1) * (ringNum + 1) - ringNum * ringNum);
0178 G4int counter = 0;
0179
0180 while (energyBinIter != iter->second.end()) {
0181 G4double value = *energyBinIter;
0182 if (counter < 2) value = value * areaCorrection;
0183 G4cout << std::setw(10) << std::setprecision(5) << value * mm * mm << " ";
0184 outFile << value * mm * mm;
0185 if (counter < 3) outFile << ",";
0186 counter++;
0187 energyBinIter++;
0188 }
0189 outFile << G4endl;
0190 G4cout << G4endl;
0191 iter++;
0192 }
0193 }
0194
0195
0196
0197 void ElectronRun::Merge(const G4Run* aRun)
0198 {
0199
0200
0201 const ElectronRun* localRun = static_cast<const ElectronRun*>(aRun);
0202 const std::map<G4int, G4THitsMap<G4double>*>& localMap = localRun->fMap;
0203 std::map<G4int, G4THitsMap<G4double>*>::const_iterator iter = localMap.begin();
0204 for (; iter != localMap.end(); ++iter)
0205 (*(fMap[iter->first])) += (*(iter->second));
0206
0207
0208 G4Run::Merge(aRun);
0209 }
0210
0211