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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 10.7.p4)


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