Import Geant4 10.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 11:51:14 +02:00
parent e2d2f9810a
commit 286caacf06
12421 changed files with 730077 additions and 502383 deletions
@@ -23,128 +23,46 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file eventgenerator/particleGun/src/HistoManager.cc
/// \file hadronic/Hadr03/src/HistoManager.cc
/// \brief Implementation of the HistoManager class
//
//
// $Id$
// $Id: HistoManager.cc 72243 2013-07-12 08:45:36Z gcosmo $
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "HistoManager.hh"
#include "HistoMessenger.hh"
#include "G4UnitsTable.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
HistoManager::HistoManager()
: fFileName("particleGun")
{
fileName[0] = "particleGun";
factoryOn = false;
fNbHist = 0;
// histograms
for (G4int k=0; k<MaxHisto; k++) {
fHistId[k] = 0;
fHistPt[k] = 0;
fExist[k] = false;
fUnit[k] = 1.0;
fWidth[k] = 1.0;
fAscii[k] = false;
}
fHistoMessenger = new HistoMessenger(this);
Book();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
HistoManager::~HistoManager()
{
delete fHistoMessenger;
delete G4AnalysisManager::Instance();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void HistoManager::book()
void HistoManager::Book()
{
// if no histos, do nothing
if (fNbHist == 0) return;
// Create or get analysis manager
// The choice of analysis technology is done via selection of a namespace
// in HistoManager.hh
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
analysisManager->SetFileName(fFileName);
analysisManager->SetVerboseLevel(1);
G4String extension = analysisManager->GetType();
fileName[1] = fileName[0] + "." + extension;
// Open an output file
//
G4bool fileOpen = analysisManager->OpenFile(fileName[0]);
if (!fileOpen) {
G4cout << "\n---> HistoManager::book(): cannot open " << fileName[1]
<< G4endl;
return;
}
// create selected histograms
//
analysisManager->SetFirstHistoId(1);
for (G4int k=0; k<MaxHisto; k++) {
if (fExist[k]) {
fHistId[k] = analysisManager->CreateH1( fLabel[k], fTitle[k],
fNbins[k], fVmin[k], fVmax[k]);
fHistPt[k] = analysisManager->GetH1(fHistId[k]);
factoryOn = true;
}
}
if (factoryOn)
G4cout << "\n----> Histogram file is opened in " << fileName[1] << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void HistoManager::save()
{
if (factoryOn) {
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
analysisManager->Write();
analysisManager->CloseFile();
saveAscii(); // Write fAscii file, if any
G4cout << "\n----> Histograms are saved in " << fileName[1] << G4endl;
delete G4AnalysisManager::Instance();
factoryOn = false;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void HistoManager::FillHisto(G4int ih, G4double e, G4double weight)
{
if (ih > MaxHisto) {
G4cout << "---> warning from HistoManager::FillHisto() : histo " << ih
<< "does not fExist; e= " << e << " w= " << weight << G4endl;
return;
}
if (fHistPt[ih]) fHistPt[ih]->fill(e/fUnit[ih], weight);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void HistoManager::SetHisto(G4int ih,
G4int nbins, G4double vmin, G4double vmax, const G4String& unit)
{
if (ih > MaxHisto) {
G4cout << "---> warning from HistoManager::SetHisto() : histo " << ih
<< "does not fExist" << G4endl;
return;
}
analysisManager->SetActivation(true); //enable inactivation of histograms
// Define histograms start values
const G4int kMaxHisto = 9;
const G4String id[] = { "0", "1", "2", "3", "4", "5", "6", "7" , "8" };
const G4String title[] =
{ "dummy", //0
@@ -158,87 +76,17 @@ void HistoManager::SetHisto(G4int ih,
"moment dir: angular distr dN/dOmega = f(psi) " //8 for GunAction#3
};
G4String titl = title[ih];
fUnit[ih] = 1.;
// Default values (to be reset via /analysis/h1/set command)
G4int nbins = 100;
G4double vmin = 0.;
G4double vmax = 100.;
if (unit != "none") {
titl = title[ih] + " (" + unit + ")";
fUnit[ih] = G4UnitDefinition::GetValueOf(unit);
// Create all histograms as inactivated
// as we have not yet set nbins, vmin, vmax
for (G4int k=0; k<kMaxHisto; k++) {
G4int ih = analysisManager->CreateH1(id[k], title[k], nbins, vmin, vmax);
analysisManager->SetH1Activation(ih, false);
}
fExist[ih] = true;
fLabel[ih] = id[ih];
fTitle[ih] = titl;
fNbins[ih] = nbins;
fVmin[ih] = vmin;
fVmax[ih] = vmax;
fWidth[ih] = fUnit[ih]*(vmax-vmin)/nbins;
fNbHist++;
G4cout << "----> SetHisto " << ih << ": " << titl << "; "
<< nbins << " bins from "
<< vmin << " " << unit << " to " << vmax << " " << unit << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void HistoManager::Normalize(G4int ih, G4double fac)
{
if (ih >= MaxHisto) {
G4cout << "---> warning from HistoManager::Normalize() : histo " << ih
<< " fac= " << fac << G4endl;
return;
}
if (fHistPt[ih]) fHistPt[ih]->scale(fac);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void HistoManager::PrintHisto(G4int ih)
{
if (ih < MaxHisto) { fAscii[ih] = true; fAscii[0] = true; }
else
G4cout << "---> warning from HistoManager::PrintHisto() : histo " << ih
<< "does not exist" << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include <fstream>
void HistoManager::saveAscii()
{
if (!fAscii[0]) return;
G4String name = fileName[0] + ".ascii";
std::ofstream File(name, std::ios::out);
if (!File) {
G4cout
<< "\n---> HistoManager::saveAscii(): cannot open " << name << G4endl;
return;
}
File.setf( std::ios::scientific, std::ios::floatfield );
//write selected histograms
for (G4int ih=0; ih<MaxHisto; ih++) {
if (fHistPt[ih] && fAscii[ih]) {
File << "\n 1D histogram " << ih << ": " << fTitle[ih]
<< "\n \n \t X \t\t Y" << G4endl;
for (G4int iBin=0; iBin<fNbins[ih]; iBin++) {
File << " " << iBin << "\t"
<< fHistPt[ih]->axis().bin_center(iBin) << "\t"
<< fHistPt[ih]->bin_height(iBin)
<< G4endl;
}
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......