Import Geant4 9.6.0 source tree
This commit is contained in:
@@ -23,119 +23,102 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: HistoManager.cc,v 1.5 2010-11-09 20:41:49 asaim Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
/// \file electromagnetic/TestEm17/src/HistoManager.cc
|
||||
/// \brief Implementation of the HistoManager class
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#include "HistoManager.hh"
|
||||
#include "HistoMessenger.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
|
||||
#ifdef G4ANALYSIS_USE
|
||||
#include "AIDA/AIDA.h"
|
||||
#endif
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
HistoManager::HistoManager()
|
||||
:af(0),tree(0),hf(0),factoryOn(false)
|
||||
{
|
||||
#ifdef G4ANALYSIS_USE
|
||||
// Creating the analysis factory
|
||||
af = AIDA_createAnalysisFactory();
|
||||
if(!af) {
|
||||
G4cout << " HistoManager::HistoManager() :"
|
||||
<< " problem creating the AIDA analysis factory."
|
||||
<< G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
fileName[0] = "testem17";
|
||||
fileType = "root";
|
||||
fileOption = "";
|
||||
fileName[0] = "testem17";
|
||||
factoryOn = false;
|
||||
fNbHist = 0;
|
||||
|
||||
// histograms
|
||||
for (G4int k=0; k<MaxHisto; k++) {
|
||||
histo[k] = 0;
|
||||
exist[k] = false;
|
||||
Unit[k] = 1.0;
|
||||
Width[k] = 1.0;
|
||||
fHistId[k] = 0;
|
||||
fHistPt[k] = 0;
|
||||
fExist[k] = false;
|
||||
fUnit[k] = 1.0;
|
||||
fWidth[k] = 1.0;
|
||||
fAscii[k] = false;
|
||||
}
|
||||
|
||||
histoMessenger = new HistoMessenger(this);
|
||||
fHistoMessenger = new HistoMessenger(this);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
HistoManager::~HistoManager()
|
||||
{
|
||||
delete histoMessenger;
|
||||
|
||||
#ifdef G4ANALYSIS_USE
|
||||
delete af;
|
||||
#endif
|
||||
delete fHistoMessenger;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void HistoManager::book()
|
||||
{
|
||||
#ifdef G4ANALYSIS_USE
|
||||
if(!af) return;
|
||||
|
||||
// Creating a tree mapped to an hbook file.
|
||||
fileName[1] = fileName[0] + "." + fileType;
|
||||
G4bool readOnly = false;
|
||||
G4bool createNew = true;
|
||||
AIDA::ITreeFactory* tf = af->createTreeFactory();
|
||||
tree = tf->create(fileName[1], fileType, readOnly, createNew, fileOption);
|
||||
delete tf;
|
||||
if(!tree) {
|
||||
G4cout << "HistoManager::book() :"
|
||||
<< " problem creating the AIDA tree with "
|
||||
<< " storeName = " << fileName[1]
|
||||
<< " storeType = " << fileType
|
||||
<< " readOnly = " << readOnly
|
||||
<< " createNew = " << createNew
|
||||
<< " options = " << fileOption
|
||||
// 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->SetVerboseLevel(0);
|
||||
G4String extension = analysisManager->GetFileType();
|
||||
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;
|
||||
}
|
||||
|
||||
// Creating a histogram factory, whose histograms will be handled by the tree
|
||||
hf = af->createHistogramFactory(*tree);
|
||||
}
|
||||
|
||||
// create selected histograms
|
||||
//
|
||||
analysisManager->SetFirstHistoId(1);
|
||||
|
||||
for (G4int k=0; k<MaxHisto; k++) {
|
||||
if (exist[k]) {
|
||||
histo[k] = hf->createHistogram1D( Label[k], Title[k],
|
||||
Nbins[k], Vmin[k], Vmax[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 Tree is opened in " << fileName[1] << G4endl;
|
||||
|
||||
#endif
|
||||
if (factoryOn)
|
||||
G4cout << "\n----> Histogram file is opened in " << fileName[1] << G4endl;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void HistoManager::save()
|
||||
{
|
||||
#ifdef G4ANALYSIS_USE
|
||||
if (factoryOn) {
|
||||
tree->commit(); // Writing the histograms to the file
|
||||
tree->close(); // and closing the tree (and the file)
|
||||
G4cout << "\n----> Histogram Tree is saved in " << fileName[1] << G4endl;
|
||||
|
||||
delete hf;
|
||||
delete tree;
|
||||
tree = 0;
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -144,54 +127,55 @@ void HistoManager::FillHisto(G4int ih, G4double e, G4double weight)
|
||||
{
|
||||
if (ih > MaxHisto) {
|
||||
G4cout << "---> warning from HistoManager::FillHisto() : histo " << ih
|
||||
<< "does not exist; e= " << e << " w= " << weight << G4endl;
|
||||
<< "does not fExist; e= " << e << " w= " << weight << G4endl;
|
||||
return;
|
||||
}
|
||||
#ifdef G4ANALYSIS_USE
|
||||
if(exist[ih]) histo[ih]->fill(e/Unit[ih], weight);
|
||||
#endif
|
||||
|
||||
if (fHistPt[ih]) fHistPt[ih]->fill(e/fUnit[ih], weight);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void HistoManager::SetHisto(G4int ih,
|
||||
G4int nbins, G4double valmin, G4double valmax, const G4String& unit)
|
||||
G4int nbins, G4double vmin, G4double vmax, const G4String& unit)
|
||||
{
|
||||
if (ih > MaxHisto) {
|
||||
G4cout << "---> warning from HistoManager::SetHisto() : histo " << ih
|
||||
<< "does not exist" << G4endl;
|
||||
<< "does not fExist" << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const G4String id[] = { "0", "1", "2", "3", "4", "5", "6", "7"};
|
||||
const G4String id[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
|
||||
const G4String title[] =
|
||||
{ "dummy", //0
|
||||
"log10(Etransfert/Emu) Ionization", //1
|
||||
"log10(Etransfert/Emu) Pair", //2
|
||||
"log10(Etransfert/Emu) Brems", //3
|
||||
"log10(Etransfert/Emu) Nuclear", //4
|
||||
"log10(Etransfert/Emu) Ionization", //5
|
||||
"log10(Etransfert/Emu) Pair", //6
|
||||
"log10(Etransfert/Emu) Brems" //7
|
||||
{ "dummy", //0
|
||||
"log10(Etransfert/Emu) muIonization", //1
|
||||
"log10(Etransfert/Emu) muPair", //2
|
||||
"log10(Etransfert/Emu) muBrems", //3
|
||||
"log10(Etransfert/Emu) muNuclear", //4
|
||||
"log10(Etransfert/Emu) hIonization", //5
|
||||
"log10(Etransfert/Emu) hPair", //6
|
||||
"log10(Etransfert/Emu) hBrems", //7
|
||||
"dummy", //8
|
||||
"dummy" //9
|
||||
};
|
||||
|
||||
G4String titl = title[ih];
|
||||
G4double vmin = valmin, vmax = valmax;
|
||||
Unit[ih] = 1.;
|
||||
fUnit[ih] = 1.;
|
||||
|
||||
if (unit != "none") {
|
||||
titl = title[ih] + " (" + unit + ")";
|
||||
Unit[ih] = G4UnitDefinition::GetValueOf(unit);
|
||||
vmin = valmin/Unit[ih]; vmax = valmax/Unit[ih];
|
||||
fUnit[ih] = G4UnitDefinition::GetValueOf(unit);
|
||||
}
|
||||
|
||||
exist[ih] = true;
|
||||
Label[ih] = id[ih];
|
||||
Title[ih] = titl;
|
||||
Nbins[ih] = nbins;
|
||||
Vmin[ih] = vmin;
|
||||
Vmax[ih] = vmax;
|
||||
Width[ih] = (valmax-valmin)/nbins;
|
||||
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 "
|
||||
@@ -201,15 +185,60 @@ void HistoManager::SetHisto(G4int ih,
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void HistoManager::RemoveHisto(G4int ih)
|
||||
void HistoManager::Normalize(G4int ih, G4double fac)
|
||||
{
|
||||
if (ih > MaxHisto) {
|
||||
G4cout << "---> warning from HistoManager::RemoveHisto() : histo " << ih
|
||||
<< "does not exist" << G4endl;
|
||||
if (ih >= MaxHisto) {
|
||||
G4cout << "---> warning from HistoManager::Normalize() : histo " << ih
|
||||
<< " fac= " << fac << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
histo[ih] = 0; exist[ih] = false;
|
||||
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......
|
||||
|
||||
Reference in New Issue
Block a user