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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/medical/electronScattering2/src/ElectronRun.cc (Version 11.3.0) and /examples/extended/medical/electronScattering2/src/ElectronRun.cc (Version 10.7)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 /// \file medical/electronScattering2/src/Elec     27 /// \file medical/electronScattering2/src/ElectronRun.cc
 28 /// \brief Implementation of the ElectronRun c     28 /// \brief Implementation of the ElectronRun class
 29                                                    29 
 30 #include "ElectronRun.hh"                          30 #include "ElectronRun.hh"
 31                                                << 
 32 #include "G4MultiFunctionalDetector.hh"            31 #include "G4MultiFunctionalDetector.hh"
 33 #include "G4SDManager.hh"                          32 #include "G4SDManager.hh"
 34 #include "G4SystemOfUnits.hh"                  << 
 35 #include "G4VPrimitiveScorer.hh"                   33 #include "G4VPrimitiveScorer.hh"
 36                                                <<  34 #include "G4SystemOfUnits.hh"
 37 #include <assert.h>                                35 #include <assert.h>
 38                                                    36 
 39 //....oooOO0OOooo........oooOO0OOooo........oo     37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 40                                                    38 
 41 ElectronRun::ElectronRun() : G4Run(), fMap()   <<  39 ElectronRun::ElectronRun()
                                                   >>  40 : G4Run(), fMap()
 42 {                                                  41 {
 43   fMap[0] = new G4THitsMap<G4double>("MyDetect <<  42     fMap[0] = new G4THitsMap<G4double>("MyDetector", "cell flux");
 44   fMap[1] = new G4THitsMap<G4double>("MyDetect <<  43     fMap[1] = new G4THitsMap<G4double>("MyDetector", "e cell flux");
 45   fMap[2] = new G4THitsMap<G4double>("MyDetect <<  44     fMap[2] = new G4THitsMap<G4double>("MyDetector", "population");
 46   fMap[3] = new G4THitsMap<G4double>("MyDetect <<  45     fMap[3] = new G4THitsMap<G4double>("MyDetector", "e population");
 47 }                                                  46 }
 48                                                    47 
 49 //....oooOO0OOooo........oooOO0OOooo........oo     48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 50                                                    49 
 51 ElectronRun::~ElectronRun()                        50 ElectronRun::~ElectronRun()
 52 {                                                  51 {
 53   // Important to clean up the map             <<  52     // Important to clean up the map
 54   std::map<G4int, G4THitsMap<G4double>*>::iter <<  53     std::map<G4int, G4THitsMap<G4double>* >::iterator iter = fMap.begin();
 55                                                <<  54     
 56   while (iter != fMap.end()) {                 <<  55     while (iter != fMap.end()) {
 57     delete iter->second;                       <<  56         delete iter->second;
 58     iter++;                                    <<  57         iter++;
 59   }                                            <<  58     }
 60 }                                                  59 }
 61                                                    60 
 62 //....oooOO0OOooo........oooOO0OOooo........oo     61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 63                                                    62 
 64 void ElectronRun::RecordEvent(const G4Event* a     63 void ElectronRun::RecordEvent(const G4Event* anEvent)
 65 {                                                  64 {
 66   // Get the hits collection                   <<  65     // Get the hits collection
 67   G4HCofThisEvent* eventHitCollection = anEven <<  66     G4HCofThisEvent* eventHitCollection = anEvent->GetHCofThisEvent();
 68                                                <<  67     
 69   if (!eventHitCollection) return;             <<  68     if (!eventHitCollection) return;
 70                                                <<  69     
 71   // Update our private fMap                   <<  70     // Update our private fMap
 72   std::map<G4int, G4THitsMap<G4double>*>::iter <<  71     std::map< G4int, G4THitsMap<G4double>* >::iterator iter = fMap.begin();
 73                                                <<  72     
 74   while (iter != fMap.end()) {                 <<  73     while (iter != fMap.end()) {
 75     G4int id = iter->first;                    <<  74         G4int id = iter->first;
 76                                                <<  75         
 77     // Get the hit collection corresponding to <<  76         // Get the hit collection corresponding to "id"
 78     G4THitsMap<G4double>* eventHitsMap =       <<  77         G4THitsMap<G4double>* eventHitsMap
 79       dynamic_cast<G4THitsMap<G4double>*>(even <<  78         = dynamic_cast< G4THitsMap<G4double>* >(eventHitCollection->GetHC(id));
 80                                                <<  79         
 81     // Expect this to exist                    <<  80         // Expect this to exist
 82     assert(0 != eventHitsMap);                 <<  81         assert (0 != eventHitsMap);
 83                                                <<  82         
 84     // Accumulate event data into our G4THitsM <<  83         // Accumulate event data into our G4THitsMap<G4double> map
 85     *(iter->second) += *eventHitsMap;          <<  84         *(iter->second) += *eventHitsMap;
 86                                                <<  85         
 87     iter++;                                    <<  86         iter++;
 88   }                                            <<  87     }
 89                                                <<  88     
 90   G4Run::RecordEvent(anEvent);                 <<  89     G4Run::RecordEvent(anEvent);
 91 }                                                  90 }
 92                                                    91 
 93 //....oooOO0OOooo........oooOO0OOooo........oo     92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 94                                                    93 
 95 void ElectronRun::DumpData(G4String& outputFil <<  94 void ElectronRun::DumpData(G4String &outputFileSpec) const
 96 {                                                  95 {
 97   // Titles                                    <<  96     // Titles
 98   std::vector<G4String> title;                 <<  97     std::vector<G4String> title;
 99   title.push_back("Radius");                   <<  98     title.push_back("Radius");
100                                                <<  99     
101   // Output map - energy binning on x axis, th << 100     // Output map - energy binning on x axis, theta on y
102   std::map<G4int, std::vector<G4double>> outpu << 101     std::map< G4int, std::vector<G4double> > output;
103                                                << 102     
104   G4int nThetaBins = 233;                      << 103     G4int nThetaBins = 233;
105                                                << 104     
106   // Energy bins depends on the number of scor << 105     // Energy bins depends on the number of scorers
107   G4int nEnergyBins = fMap.size();             << 106     G4int nEnergyBins = fMap.size();
108                                                << 107     
109   G4int i(0), j(0);                            << 108     G4int i(0), j(0);
110                                                << 109     
111   // Initialise current to 0 in all bins       << 110     // Initialise current to 0 in all bins
112   for (i = 0; i < nThetaBins; i++) {           << 111     for (i=0; i<nThetaBins; i++) {
113     for (j = 0; j < nEnergyBins; j++) {        << 112         for (j=0; j<nEnergyBins; j++) {
114       output[i].push_back(0);                  << 113             output[i].push_back(0);
                                                   >> 114         }
115     }                                             115     }
116   }                                            << 116     
117                                                << 117     i=0;
118   i = 0;                                       << 118     
119                                                << 119     // Fill the output map
120   // Fill the output map                       << 120     std::map< G4int, G4THitsMap<G4double>* >::const_iterator iter = fMap.begin();
121   std::map<G4int, G4THitsMap<G4double>*>::cons << 121     
122                                                << 122     while (iter != fMap.end()) {
123   while (iter != fMap.end()) {                 << 123         G4THitsMap<G4double>* hitMap = iter->second;
124     G4THitsMap<G4double>* hitMap = iter->secon << 124         
125                                                << 125         title.push_back(hitMap->GetName());
126     title.push_back(hitMap->GetName());        << 126         
127                                                << 127         std::map<G4int,G4double*>* myMap = hitMap->GetMap();
128     std::map<G4int, G4double*>* myMap = hitMap << 128         
129                                                << 129         for (j=0; j<nThetaBins; j++) {
130     for (j = 0; j < nThetaBins; j++) {         << 130             G4double* current = (*myMap)[j];
131       G4double* current = (*myMap)[j];         << 131             if (0 != current) output[j][i] = (*current);
132       if (0 != current) output[j][i] = (*curre << 132         }
                                                   >> 133         
                                                   >> 134         i++;
                                                   >> 135         iter++;
133     }                                             136     }
134                                                << 137     
135     i++;                                       << 138     Print(title, output, outputFileSpec);
136     iter++;                                    << 
137   }                                            << 
138                                                << 
139   Print(title, output, outputFileSpec);        << 
140 }                                                 139 }
141                                                   140 
142 //....oooOO0OOooo........oooOO0OOooo........oo    141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143                                                   142 
144 void ElectronRun::Print(const std::vector<G4St    143 void ElectronRun::Print(const std::vector<G4String>& title,
145                         const std::map<G4int,  << 144                         const std::map< G4int, std::vector<G4double> >&myMap,
146                         G4String& outputFileSp << 145                         G4String &outputFileSpec) const
147 {                                                 146 {
148   // Print to G4cout and an output file        << 147     // Print to G4cout and an output file
149   std::ofstream outFile(outputFileSpec);       << 148     std::ofstream outFile(outputFileSpec);
150                                                << 149     
151   // Print title vector                        << 150     // Print title vector
152   std::vector<G4String>::const_iterator titleI << 151     std::vector<G4String>::const_iterator titleIter = title.begin();
153                                                << 152     
154   while (titleIter != title.end()) {           << 153     while (titleIter != title.end()) {
155     G4cout << std::setw(8) << *titleIter << "  << 154         G4cout << std::setw(8)<<*titleIter<<" ";
156     titleIter++;                               << 155         titleIter++;
157   }                                            << 156     }
158                                                << 157     
159   G4cout << G4endl;                            << 158     G4cout<<G4endl;
160                                                << 159     
161   // Print current data                        << 160     // Print current data
162   std::map<G4int, std::vector<G4double>>::cons << 161     std::map< G4int, std::vector<G4double> >::const_iterator iter = myMap.begin();
163                                                << 162     
164   while (iter != myMap.end()) {                << 163     while (iter != myMap.end()) {
165     G4cout << std::setw(8) << std::setprecisio << 164         G4cout << std::setw(8)<<std::setprecision(3)<< iter->first<<" ";
166                                                << 165         
167     std::vector<G4double>::const_iterator ener << 166         std::vector<G4double>::const_iterator energyBinIter = iter->second.begin();
168                                                << 167         
169     // The built-in scorers do not automatical << 168         // The built-in scorers do not automatically account for the area of the
170     // cylinder replica rings. We must account << 169         // cylinder replica rings. We must account for this now by multiplying our result
171     // by the ratio of the area of the full cy << 170         // by the ratio of the area of the full cylinder end over the area of the actual
172     // scoring ring.                           << 171         // scoring ring.
173     // In this ratio, PI divides out, as does  << 172         // In this ratio, PI divides out, as does the width of the scoring rings.
174     // Left with just the number of rings squa << 173         // Left with just the number of rings squared divided by the ring index plus
175     // 1 squared minus ring index squared.     << 174         // 1 squared minus ring index squared.
176     G4int ringNum = iter->first;               << 175         G4int ringNum = iter->first;
177     G4double areaCorrection = 233. * 233. / (( << 176         G4double areaCorrection = 233.*233. /
178     G4int counter = 0;                         << 177         ( (ringNum+1)*(ringNum+1) - ringNum*ringNum );
179                                                << 178         G4int counter = 0;
180     while (energyBinIter != iter->second.end() << 179         
181       G4double value = *energyBinIter;         << 180         while (energyBinIter != iter->second.end()) {
182       if (counter < 2) value = value * areaCor << 181             G4double value = *energyBinIter;
183       G4cout << std::setw(10) << std::setpreci << 182             if (counter < 2) value = value*areaCorrection;
184       outFile << value * mm * mm;              << 183             G4cout << std::setw(10)<<std::setprecision(5)<< value*mm*mm<<" ";
185       if (counter < 3) outFile << ",";         << 184             outFile << value*mm*mm;
186       counter++;                               << 185             if (counter < 3) outFile <<",";
187       energyBinIter++;                         << 186             counter++;
188     }                                          << 187             energyBinIter++;
189     outFile << G4endl;                         << 188         }
190     G4cout << G4endl;                          << 189         outFile<<G4endl;
191     iter++;                                    << 190         G4cout<<G4endl;
192   }                                            << 191         iter++;
                                                   >> 192     }
193 }                                                 193 }
194                                                   194 
195 //....oooOO0OOooo........oooOO0OOooo........oo    195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196                                                   196 
197 void ElectronRun::Merge(const G4Run* aRun)        197 void ElectronRun::Merge(const G4Run* aRun)
198 {                                                 198 {
199   // This method is called at the end of the r << 199     // This method is called at the end of the run for each worker thread.
200   // It accumulates the worker's results into  << 200     // It accumulates the worker's results into global results.
201   const ElectronRun* localRun = static_cast<co << 201     const ElectronRun* localRun = static_cast<const ElectronRun*>(aRun);
202   const std::map<G4int, G4THitsMap<G4double>*> << 202     const std::map< G4int, G4THitsMap<G4double>* >& localMap = localRun->fMap;
203   std::map<G4int, G4THitsMap<G4double>*>::cons << 203     std::map< G4int, G4THitsMap<G4double>* >::const_iterator iter = localMap.begin();
204   for (; iter != localMap.end(); ++iter)       << 204     for ( ; iter != localMap.end() ; ++iter)
205     (*(fMap[iter->first])) += (*(iter->second) << 205         (*(fMap[iter->first])) += (*(iter->second));
206                                                << 206     
207   // This call lets Geant4 maintain overall su << 207     // This call lets Geant4 maintain overall summary information.
208   G4Run::Merge(aRun);                          << 208     G4Run::Merge(aRun);
209 }                                                 209 }
210                                                   210 
211 //....oooOO0OOooo........oooOO0OOooo........oo    211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
212                                                   212