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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/fanoCavity/src/HistoManager.cc (Version 11.3.0) and /examples/extended/medical/fanoCavity/src/HistoManager.cc (Version 9.6)


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