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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/electromagnetic/TestEm17/src/HistoManager.cc (Version 11.3.0) and /examples/extended/electromagnetic/TestEm17/src/HistoManager.cc (Version 4.0.p2)


  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 /// \file electromagnetic/TestEm17/src/HistoMa    
 27 /// \brief Implementation of the HistoManager     
 28 //                                                
 29 //                                                
 30 //                                                
 31 //....oooOO0OOooo........oooOO0OOooo........oo    
 32 //....oooOO0OOooo........oooOO0OOooo........oo    
 33                                                   
 34 #include "HistoManager.hh"                        
 35                                                   
 36 #include "HistoMessenger.hh"                      
 37                                                   
 38 #include "G4PhysicalConstants.hh"                 
 39 #include "G4SystemOfUnits.hh"                     
 40 #include "G4UnitsTable.hh"                        
 41                                                   
 42 //....oooOO0OOooo........oooOO0OOooo........oo    
 43                                                   
 44 HistoManager::HistoManager() : fHistoMessenger    
 45 {                                                 
 46   fileName[0] = "testem17";                       
 47   factoryOn = false;                              
 48   fNbHist = 0;                                    
 49                                                   
 50   // histograms                                   
 51   for (G4int k = 0; k < kMaxHisto; k++) {         
 52     fHistId[k] = 0;                               
 53     fHistPt[k] = 0;                               
 54     fExist[k] = false;                            
 55     fUnit[k] = 1.0;                               
 56     fWidth[k] = 1.0;                              
 57     fAscii[k] = false;                            
 58   }                                               
 59                                                   
 60   fHistoMessenger = new HistoMessenger(this);     
 61 }                                                 
 62                                                   
 63 //....oooOO0OOooo........oooOO0OOooo........oo    
 64                                                   
 65 HistoManager::~HistoManager()                     
 66 {                                                 
 67   delete fHistoMessenger;                         
 68 }                                                 
 69                                                   
 70 //....oooOO0OOooo........oooOO0OOooo........oo    
 71                                                   
 72 void HistoManager::Book()                         
 73 {                                                 
 74   // if no histos, do nothing                     
 75   if (fNbHist == 0) return;                       
 76                                                   
 77   // Create or get analysis manager               
 78   // The choice of analysis technology is done    
 79   // in HistoManager.hh                           
 80   G4AnalysisManager* analysisManager = G4Analy    
 81   analysisManager->SetDefaultFileType("root");    
 82   analysisManager->SetVerboseLevel(0);            
 83   G4String extension = analysisManager->GetFil    
 84   fileName[1] = fileName[0] + "." + extension;    
 85                                                   
 86   // Open an output file                          
 87   //                                              
 88   G4bool fileOpen = analysisManager->OpenFile(    
 89   if (!fileOpen) {                                
 90     G4cout << "\n---> HistoManager::book(): ca    
 91     return;                                       
 92   }                                               
 93                                                   
 94   // create selected histograms                   
 95   //                                              
 96   analysisManager->SetFirstHistoId(1);            
 97                                                   
 98   for (G4int k = 0; k < kMaxHisto; k++) {         
 99     if (fExist[k]) {                              
100       fHistId[k] = analysisManager->CreateH1(f    
101       fHistPt[k] = analysisManager->GetH1(fHis    
102       factoryOn = true;                           
103     }                                             
104   }                                               
105                                                   
106   if (factoryOn) G4cout << "\n----> Histogram     
107 }                                                 
108                                                   
109 //....oooOO0OOooo........oooOO0OOooo........oo    
110                                                   
111 void HistoManager::Save()                         
112 {                                                 
113   if (factoryOn) {                                
114     G4cout << "\n----> HistoManager::save " <<    
115     G4AnalysisManager* analysisManager = G4Ana    
116     analysisManager->Write();                     
117     analysisManager->CloseFile();                 
118     SaveAscii();  // Write fAscii file, if any    
119     G4cout << "\n----> Histograms are saved in    
120                                                   
121     analysisManager->Clear();                     
122     factoryOn = false;                            
123   }                                               
124 }                                                 
125                                                   
126 //....oooOO0OOooo........oooOO0OOooo........oo    
127                                                   
128 void HistoManager::FillHisto(G4int ih, G4doubl    
129 {                                                 
130   if (ih > kMaxHisto) {                           
131     G4cout << "---> warning from HistoManager:    
132            << "does not fExist; e= " << e << "    
133     return;                                       
134   }                                               
135                                                   
136   if (fHistPt[ih]) fHistPt[ih]->fill(e / fUnit    
137 }                                                 
138                                                   
139 //....oooOO0OOooo........oooOO0OOooo........oo    
140                                                   
141 void HistoManager::SetHisto(G4int ih, G4int nb    
142                             const G4String& un    
143 {                                                 
144   if (ih > kMaxHisto) {                           
145     G4cout << "---> warning from HistoManager:    
146            << G4endl;                             
147     return;                                       
148   }                                               
149                                                   
150   const G4String id[] = {"0",  "1",  "2",  "3"    
151                          "10", "11", "12", "13    
152                          "20", "21", "22", "23    
153   const G4String title[] = {                      
154     "dummy",  // 0                                
155     "log10(Eloss/Emu) muIonization",  // 1        
156     "log10(Eloss/Emu) muPair",  // 2              
157     "log10(Eloss/Emu) muBrems",  // 3             
158     "log10(Eloss/Emu) muNuclear",  // 4           
159     "log10(Eloss/Emu) hIonization",  // 5         
160     "log10(Eloss/Emu) hPair",  // 6               
161     "log10(Eloss/Emu) hBrems",  // 7              
162     "log10(Eloss/Emu) muToMuonPair",  // 8        
163     "dummy",  // 9                                
164     "dummy",  // 10                               
165     "log10(Eloss/Emu) muIonization",  // 11       
166     "log10(Eloss/Emu) muPair",  // 12             
167     "log10(Eloss/Emu) muBrems",  // 13            
168     "log10(Eloss/Emu) muNuclear",  // 14          
169     "dummy",  // 15                               
170     "dummy",  // 16                               
171     "dummy",  // 17                               
172     "log10(Eloss/Emu) muToMuonPair",  // 18       
173     "dummy",  // 19                               
174     "dummy",  // 20                               
175     "CS(1/mm) vs ekin muIonisation",  // 21       
176     "CS(1/mm) vs ekin muPair",  // 22             
177     "CS(1/mm) vs ekin muBrems",  // 23            
178     "CS(1/mm) vs ekin muNuclear",  // 24          
179     "dummy",  // 25                               
180     "dummy",  // 26                               
181     "dummy",  // 27                               
182     "CS(1/mm) vs ekin muToMuonPair",  // 28       
183     "dummy"  // 29                                
184   };                                              
185                                                   
186   G4String titl = title[ih];                      
187   fUnit[ih] = 1.;                                 
188                                                   
189   if (unit != "none") {                           
190     titl = title[ih] + " (" + unit + ")";         
191     fUnit[ih] = G4UnitDefinition::GetValueOf(u    
192   }                                               
193                                                   
194   fExist[ih] = true;                              
195   fLabel[ih] = "h" + id[ih];                      
196   fTitle[ih] = titl;                              
197   fNbins[ih] = nbins;                             
198   fVmin[ih] = vmin;                               
199   fVmax[ih] = vmax;                               
200   fWidth[ih] = fUnit[ih] * (vmax - vmin) / nbi    
201                                                   
202   fNbHist++;                                      
203                                                   
204   G4cout << "----> SetHisto " << ih << ": " <<    
205          << " " << unit << " to " << vmax << "    
206 }                                                 
207                                                   
208 //....oooOO0OOooo........oooOO0OOooo........oo    
209                                                   
210 void HistoManager::Normalize(G4int ih, G4doubl    
211 {                                                 
212   if (ih >= kMaxHisto) {                          
213     G4cout << "---> warning from HistoManager:    
214            << G4endl;                             
215     return;                                       
216   }                                               
217                                                   
218   if (fHistPt[ih]) fHistPt[ih]->scale(fac);       
219 }                                                 
220                                                   
221 //....oooOO0OOooo........oooOO0OOooo........oo    
222                                                   
223 void HistoManager::PrintHisto(G4int ih)           
224 {                                                 
225   if (ih < kMaxHisto) {                           
226     fAscii[ih] = true;                            
227     fAscii[0] = true;                             
228   }                                               
229   else                                            
230     G4cout << "---> warning from HistoManager:    
231            << G4endl;                             
232 }                                                 
233                                                   
234 //....oooOO0OOooo........oooOO0OOooo........oo    
235                                                   
236 #include <fstream>                                
237                                                   
238 void HistoManager::SaveAscii()                    
239 {                                                 
240   if (!fAscii[0]) return;                         
241                                                   
242   G4String name = fileName[0] + ".ascii";         
243   std::ofstream File(name, std::ios::out);        
244   if (!File) {                                    
245     G4cout << "\n---> HistoManager::saveAscii(    
246     return;                                       
247   }                                               
248                                                   
249   File.setf(std::ios::scientific, std::ios::fl    
250                                                   
251   // write selected histograms                    
252   for (G4int ih = 0; ih < kMaxHisto; ih++) {      
253     if (fHistPt[ih] && fAscii[ih]) {              
254       File << "\n  1D histogram " << ih << ":     
255            << G4endl;                             
256                                                   
257       for (G4int iBin = 0; iBin < fNbins[ih];     
258         File << "  " << iBin << "\t" << fHistP    
259              << fHistPt[ih]->bin_height(iBin)     
260       }                                           
261     }                                             
262   }                                               
263 }                                                 
264                                                   
265 //....oooOO0OOooo........oooOO0OOooo........oo    
266