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 ] [ 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 /digits_hits/utils/src/G4VScoreWriter.cc (Version 11.3.0) and /digits_hits/utils/src/G4VScoreWriter.cc (Version 3.1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 // G4VScoreWriter                                 
 27 // -------------------------------------------    
 28                                                   
 29 #include "G4VScoreWriter.hh"                      
 30                                                   
 31 #include "G4MultiFunctionalDetector.hh"           
 32 #include "G4VPrimitiveScorer.hh"                  
 33 #include "G4VScoringMesh.hh"                      
 34                                                   
 35 #include <map>                                    
 36 #include <fstream>                                
 37                                                   
 38 void G4VScoreWriter::SetScoringMesh(G4VScoring    
 39 {                                                 
 40   // Should be checked for nullptr!               
 41   fScoringMesh = sm;                              
 42   fScoringMesh->GetNumberOfSegments(fNMeshSegm    
 43 }                                                 
 44                                                   
 45 void G4VScoreWriter::DumpQuantityToFile(const     
 46                                         const     
 47                                         const     
 48 {                                                 
 49   // change the option string into lowercase t    
 50   G4String opt = option;                          
 51   std::transform(opt.begin(), opt.end(), opt.b    
 52                                                   
 53   // confirm the option                           
 54   if(opt.empty())                                 
 55     opt = "csv";                                  
 56   if(opt.find("csv") == std::string::npos &&      
 57      opt.find("sequence") == std::string::npos    
 58   {                                               
 59     G4cerr << "ERROR : DumpToFile : Unknown op    
 60     return;                                       
 61   }                                               
 62                                                   
 63   // open the file                                
 64   std::ofstream ofile(fileName);                  
 65   if(!ofile)                                      
 66   {                                               
 67     G4cerr << "ERROR : DumpToFile : File open     
 68     return;                                       
 69   }                                               
 70   ofile << "# mesh name: " << fScoringMesh->Ge    
 71                                                   
 72   using MeshScoreMap = G4VScoringMesh::MeshSco    
 73   // retrieve the map                             
 74   MeshScoreMap fSMap = fScoringMesh->GetScoreM    
 75                                                   
 76   // NOLINTNEXTLINE(modernize-use-auto): Expli    
 77   MeshScoreMap::const_iterator msMapItr = fSMa    
 78   if(msMapItr == fSMap.end())                     
 79   {                                               
 80     G4cerr << "ERROR : DumpToFile : Unknown qu    
 81            << G4endl;                             
 82     return;                                       
 83   }                                               
 84                                                   
 85   std::map<G4int, G4StatDouble*>* score = msMa    
 86   ofile << "# primitive scorer name: " << msMa    
 87   if(fact != 1.0)                                 
 88   {                                               
 89     ofile << "# multiplied factor : " << fact     
 90   }                                               
 91                                                   
 92   G4double unitValue = fScoringMesh->GetPSUnit    
 93   G4String unit      = fScoringMesh->GetPSUnit    
 94   G4String divisionAxisNames[3];                  
 95   fScoringMesh->GetDivisionAxisNames(divisionA    
 96   // index order                                  
 97   ofile << "# i" << divisionAxisNames[0] << ",    
 98         << ", i" << divisionAxisNames[2];         
 99   // unit of scored value                         
100   ofile << ", total(value) ";                     
101   if(!unit.empty())                               
102     ofile << "[" << unit << "]";                  
103   ofile << ", total(val^2), entry" << G4endl;     
104                                                   
105   // "sequence" option: write header info         
106   if(opt.find("sequence") != std::string::npos    
107   {                                               
108     ofile << fNMeshSegments[0] << " " << fNMes    
109           << fNMeshSegments[2] << G4endl;         
110   }                                               
111                                                   
112   // write quantity                               
113   G4long count = 0;                               
114   ofile << std::setprecision(16);  // for doub    
115   for(G4int x = 0; x < fNMeshSegments[0]; x++)    
116   {                                               
117     for(G4int y = 0; y < fNMeshSegments[1]; y+    
118     {                                             
119       for(G4int z = 0; z < fNMeshSegments[2];     
120       {                                           
121         G4int idx = GetIndex(x, y, z);            
122                                                   
123         if(opt.find("csv") != std::string::npo    
124           ofile << x << "," << y << "," << z <    
125                                                   
126         auto value = score->find(idx);            
127         if(value == score->end())                 
128         {                                         
129           ofile << 0. << "," << 0. << "," << 0    
130         }                                         
131         else                                      
132         {                                         
133           ofile << (value->second->sum_wx()) /    
134                 << (value->second->sum_wx2())     
135                      fact                         
136                 << "," << value->second->n();     
137         }                                         
138                                                   
139         if(opt.find("csv") != std::string::npo    
140         {                                         
141           ofile << G4endl;                        
142         }                                         
143         else if(opt.find("sequence") != std::s    
144         {                                         
145           ofile << " ";                           
146           if(count++ % 5 == 4)                    
147             ofile << G4endl;                      
148         }                                         
149                                                   
150       }  // z                                     
151     }    // y                                     
152   }      // x                                     
153   ofile << std::setprecision(6);                  
154                                                   
155   // close the file                               
156   ofile.close();                                  
157 }                                                 
158                                                   
159 void G4VScoreWriter::DumpAllQuantitiesToFile(c    
160                                              c    
161 {                                                 
162   // change the option string into lowercase t    
163   G4String opt = option;                          
164   std::transform(opt.begin(), opt.end(), opt.b    
165                                                   
166   // confirm the option                           
167   if(opt.empty())                                 
168     opt = "csv";                                  
169   if(opt.find("csv") == std::string::npos &&      
170      opt.find("sequence") == std::string::npos    
171   {                                               
172     G4cerr << "ERROR : DumpToFile : Unknown op    
173     return;                                       
174   }                                               
175                                                   
176   // open the file                                
177   std::ofstream ofile(fileName);                  
178   if(!ofile)                                      
179   {                                               
180     G4cerr << "ERROR : DumpToFile : File open     
181     return;                                       
182   }                                               
183   ofile << "# mesh name: " << fScoringMesh->Ge    
184   if(fact != 1.0)                                 
185   {                                               
186     ofile << "# multiplied factor : " << fact     
187   }                                               
188                                                   
189   // retrieve the map                             
190   using MeshScoreMap = G4VScoringMesh::MeshSco    
191   MeshScoreMap fSMap = fScoringMesh->GetScoreM    
192   // NOLINTNEXTLINE(modernize-use-auto): Expli    
193   MeshScoreMap::const_iterator msMapItr = fSMa    
194   std::map<G4int, G4StatDouble*>* score;          
195   for(; msMapItr != fSMap.end(); msMapItr++)      
196   {                                               
197     G4String psname = msMapItr->first;            
198                                                   
199     score = msMapItr->second->GetMap();           
200     ofile << "# primitive scorer name: " << ms    
201                                                   
202     G4double unitValue = fScoringMesh->GetPSUn    
203     G4String unit      = fScoringMesh->GetPSUn    
204     G4String divisionAxisNames[3];                
205     fScoringMesh->GetDivisionAxisNames(divisio    
206     // index order                                
207     ofile << "# i" << divisionAxisNames[0] <<     
208           << ", i" << divisionAxisNames[2];       
209     // unit of scored value                       
210     ofile << ", total(value) ";                   
211     if(!unit.empty())                             
212       ofile << "[" << unit << "]";                
213     ofile << ", total(val^2), entry" << G4endl    
214                                                   
215     // "sequence" option: write header info       
216     if(opt.find("sequence") != std::string::np    
217     {                                             
218       ofile << fNMeshSegments[0] << " " << fNM    
219             << fNMeshSegments[2] << G4endl;       
220     }                                             
221                                                   
222     // write quantity                             
223     G4long count = 0;                             
224     ofile << std::setprecision(16);  // for do    
225     for(G4int x = 0; x < fNMeshSegments[0]; x+    
226     {                                             
227       for(G4int y = 0; y < fNMeshSegments[1];     
228       {                                           
229         for(G4int z = 0; z < fNMeshSegments[2]    
230         {                                         
231           G4int idx = GetIndex(x, y, z);          
232                                                   
233           if(opt.find("csv") != std::string::n    
234             ofile << x << "," << y << "," << z    
235                                                   
236           auto value = score->find(idx);          
237           if(value == score->end())               
238           {                                       
239             ofile << 0. << "," << 0. << "," <<    
240           }                                       
241           else                                    
242           {                                       
243             ofile << (value->second->sum_wx())    
244                   << (value->second->sum_wx2()    
245                        fact                       
246                   << "," << value->second->n()    
247           }                                       
248                                                   
249           if(opt.find("csv") != std::string::n    
250           {                                       
251             ofile << G4endl;                      
252           }                                       
253           else if(opt.find("sequence") != std:    
254           {                                       
255             ofile << " ";                         
256             if(count++ % 5 == 4)                  
257               ofile << G4endl;                    
258           }                                       
259                                                   
260         }  // z                                   
261       }    // y                                   
262     }      // x                                   
263     ofile << std::setprecision(6);                
264                                                   
265   }  // for(; msMapItr ....)                      
266                                                   
267   // close the file                               
268   ofile.close();                                  
269 }                                                 
270                                                   
271 G4int G4VScoreWriter::GetIndex(G4int x, G4int     
272 {                                                 
273   return x * fNMeshSegments[1] * fNMeshSegment    
274 }                                                 
275