Import Geant4 9.6.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 17:01:34 +02:00
parent b1eb5424d2
commit e2d2f9810a
10384 changed files with 698580 additions and 628834 deletions
@@ -23,6 +23,11 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file electromagnetic/TestEm9/src/Histo.cc
/// \brief Implementation of the Histo class
//
// $Id$
//
//---------------------------------------------------------------------------
//
// ClassName: Histo - Generic histogram/ntuple manager class
@@ -37,231 +42,311 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
#include "Histo.hh"
#ifdef G4ANALYSIS_USE
#include "AIDA/AIDA.h"
#include "HistoMessenger.hh"
#endif
#include "G4RootAnalysisManager.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
Histo::Histo()
{
verbose = 0;
histName = "testem9";
histType = "root";
nHisto = 0;
defaultAct = 1;
tupleName = "tuple9";
tupleId = "100";
tupleList = "";
ntup = 0;
messenger = 0;
#ifdef G4ANALYSIS_USE
tree = 0;
af = 0;
messenger = new HistoMessenger(this);
#endif
fManager = 0;
fMessenger = new HistoMessenger(this);
fHistName = "test";
fHistType = "root";
fTupleName = "tuple";
fTupleTitle = "test";
fNHisto = 0;
fVerbose = 0;
fDefaultAct = true;
fHistoActive= false;
fNtupleActive= false;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
Histo::~Histo()
{
#ifdef G4ANALYSIS_USE
delete messenger;
delete af;
#endif
delete fMessenger;
delete fManager;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::book()
void Histo::Book()
{
#ifdef G4ANALYSIS_USE
G4cout << "### Histo books " << nHisto << " histograms " << G4endl;
// Creating the analysis factory
if(!af) af = AIDA_createAnalysisFactory();
// Creating the tree factory
AIDA::ITreeFactory* tf = af->createTreeFactory();
if(!(fHistoActive || fNtupleActive)) { return; }
// Always creating analysis manager
fManager = G4RootAnalysisManager::Instance();
// Creating a tree mapped to a new hbook file.
G4String nam = fHistName + "." + fHistType;
G4String nam = histName + "." + histType;
G4String options = "";
//G4String options = "--noErrors export=root uncompress";
tree = tf->create(nam,histType,false,true,options);
delete tf;
if(tree) {
G4cout << "Tree store : " << tree->storeName() << G4endl;
} else {
G4cout << "ERROR: Tree store " << histName << " is not created!" << G4endl;
return;
// Open file histogram file
if(!fManager->OpenFile(nam)) {
G4cout << "Histo::Book: ERROR open file <" << nam << ">" << G4endl;
fHistoActive = false;
fNtupleActive = false;
return;
}
// Creating a histogram factory, whose histograms will be handled by the tree
AIDA::IHistogramFactory* hf = af->createHistogramFactory( *tree );
G4cout << "### Histo::Save: Opended file <" << nam << "> for "
<< fNHisto << " histograms " << G4endl;
// Creating an 1-dimensional histograms in the root directory of the tree
for(G4int i=0; i<nHisto; i++) {
if(active[i]) {
G4String ss = ids[i];
if(histType == "root") ss = "h" + ids[i];
histo[i] = hf->createHistogram1D(ss, titles[i], bins[i], xmin[i], xmax[i]);
for(G4int i=0; i<fNHisto; ++i) {
if(fActive[i]) {
G4String ss = "h" + fIds[i];
fHisto[i] = fManager->CreateH1(ss, fTitles[i], fBins[i], fXmin[i], fXmax[i]);
if(fVerbose > 0) {
G4cout << "Created histogram #" << i << " id= " << fHisto[i]
<< " " << ss << " " << fTitles[i] << G4endl;
}
}
}
delete hf;
// Creating a tuple factory, whose tuples will be handled by the tree
if(tupleList != "") {
AIDA::ITupleFactory* tpf = af->createTupleFactory( *tree );
ntup = tpf->create(tupleId, tupleName, tupleList);
delete tpf;
if(fNtupleActive) {
fManager->CreateNtuple(fTupleName,fTupleTitle);
G4int i;
G4int n = fNtupleI.size();
for(i=0; i<n; ++i) {
if(fTupleI[i] == -1) { fTupleI[i] = fManager->CreateNtupleIColumn(fNtupleI[i]); }
}
n = fNtupleF.size();
for(i=0; i<n; ++i) {
if(fTupleF[i] == -1) { fTupleF[i] = fManager->CreateNtupleFColumn(fNtupleF[i]); }
}
n = fNtupleD.size();
for(i=0; i<n; ++i) {
if(fTupleD[i] == -1) { fTupleD[i] = fManager->CreateNtupleDColumn(fNtupleD[i]); }
}
}
#endif
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::save()
void Histo::Save()
{
#ifdef G4ANALYSIS_USE
if(!(fHistoActive || fNtupleActive)) { return; }
// Creating a tree mapped to a new hbook file.
G4String nam = fHistName + "." + fHistType;
// Write histogram file
if(tree) {
tree->commit();
G4cout << "Closing the tree..." << G4endl;
tree->close();
G4cout << "Histograms and Ntuples are saved" << G4endl;
delete tree;
tree = 0;
if(!fManager->Write()) {
G4cout << "Histo::Save: FATAL ERROR writing ROOT file" << G4endl;
exit(1);
}
#endif
if(fVerbose > 0) {
G4cout << "### Histo::Save: Histograms and Ntuples are saved" << G4endl;
}
if(fManager->CloseFile() && fVerbose > 0) {
G4cout << " File is closed" << G4endl;
}
delete G4RootAnalysisManager::Instance();
fManager = 0;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::add1D(const G4String& id, const G4String& name, G4int nb,
void Histo::Add1D(const G4String& id, const G4String& name, G4int nb,
G4double x1, G4double x2, G4double u)
{
if(verbose > 0) {
G4cout << "New histogram will be booked: #" << id << " <" << name
if(fVerbose > 0) {
G4cout << "Histo::Add1D: New histogram will be booked: #" << id << " <" << name
<< " " << nb << " " << x1 << " " << x2 << " " << u
<< G4endl;
}
nHisto++;
++fNHisto;
x1 /= u;
x2 /= u;
active.push_back(defaultAct);
bins.push_back(nb);
xmin.push_back(x1);
xmax.push_back(x2);
unit.push_back(u);
ids.push_back(id);
titles.push_back(name);
histo.push_back(0);
fActive.push_back(fDefaultAct);
fBins.push_back(nb);
fXmin.push_back(x1);
fXmax.push_back(x2);
fUnit.push_back(u);
fIds.push_back(id);
fTitles.push_back(name);
fHisto.push_back(-1);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::setHisto1D(G4int i, G4int nb, G4double x1, G4double x2, G4double u)
void Histo::SetHisto1D(G4int i, G4int nb, G4double x1, G4double x2, G4double u)
{
if(i>=0 && i<nHisto) {
if(verbose > 0) {
G4cout << "Update histogram: #" << i
if(i>=0 && i<fNHisto) {
if(fVerbose > 0) {
G4cout << "Histo::SetHisto1D: #" << i
<< " " << nb << " " << x1 << " " << x2 << " " << u
<< G4endl;
}
bins[i] = nb;
xmin[i] = x1;
xmax[i] = x2;
unit[i] = u;
fBins[i] = nb;
fXmin[i] = x1;
fXmax[i] = x2;
fUnit[i] = u;
fActive[i] = true;
fHistoActive = true;
} else {
G4cout << "Histo::setHisto1D: WARNING! wrong histogram index " << i << G4endl;
G4cout << "Histo::SetHisto1D: WARNING! wrong histogram index " << i << G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::fill(G4int i, G4double x, G4double w)
void Histo::Activate(G4int i, G4bool val)
{
if(verbose > 1) {
G4cout << "fill histogram: #" << i << " at x= " << x
if(fVerbose > 1) {
G4cout << "Histo::Activate: Histogram: #" << i << " "
<< val << G4endl;
}
if(i>=0 && i<fNHisto) {
fActive[i] = val;
if(val) { fHistoActive = true; }
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::Fill(G4int i, G4double x, G4double w)
{
if(!fHistoActive) { return; }
if(fVerbose > 1) {
G4cout << "Histo::Fill: Histogram: #" << i << " at x= " << x
<< " weight= " << w
<< G4endl;
}
#ifdef G4ANALYSIS_USE
if(!tree) return;
if(i>=0 && i<nHisto) {
if(active[i]) histo[i]->fill((x/unit[i]), w);
if(i>=0 && i<fNHisto) {
if(fActive[i]) { fManager->FillH1(fHisto[i], x/fUnit[i], w); }
} else {
G4cout << "Histo::fill: WARNING! wrong histogram index " << i << G4endl;
G4cout << "Histo::Fill: WARNING! wrong histogram index " << i << G4endl;
}
#endif
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::scale(G4int i, G4double x)
void Histo::ScaleH1(G4int i, G4double x)
{
if(verbose > 0) {
G4cout << "Scale histogram: #" << i << " by factor " << x << G4endl;
if(!fHistoActive) { return; }
if(fVerbose > 0) {
G4cout << "Histo::Scale: Histogram: #" << i << " by factor " << x << G4endl;
}
#ifdef G4ANALYSIS_USE
if(!tree) return;
if(i>=0 && i<nHisto) {
histo[i]->scale(x);
if(i>=0 && i<fNHisto) {
if(fActive[i]) { fManager->GetH1(fHisto[i])->scale(x); }
} else {
G4cout << "Histo::scale: WARNING! wrong histogram index " << i << G4endl;
G4cout << "Histo::Scale: WARNING! wrong histogram index " << i << G4endl;
}
#endif
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::addTuple(const G4String& w1, const G4String& w2, const G4String& w3)
void Histo::AddTuple(const G4String& w1)
{
tupleId = w1;
tupleName = w2;
tupleList = w3;
fTupleTitle = w1;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::fillTuple(const G4String& parname, G4double x)
void Histo::AddTupleI(const G4String& w1)
{
if(verbose > 1) {
G4cout << "fill tuple by parameter <" << parname << "> = " << x << G4endl;
fNtupleActive = true;
fNtupleI.push_back(w1);
fTupleI.push_back(-1);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::AddTupleF(const G4String& w1)
{
fNtupleActive = true;
fNtupleF.push_back(w1);
fTupleF.push_back(-1);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::AddTupleD(const G4String& w1)
{
fNtupleActive = true;
fNtupleD.push_back(w1);
fTupleD.push_back(-1);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::FillTupleI(G4int i, G4int x)
{
if(!fNtupleActive) { return; }
G4int n = fNtupleI.size();
if(i >= 0 && i < n) {
if(fVerbose > 1) {
G4cout << "Histo::FillTupleI: i= " << i << " id= " << fTupleI[i]
<< " <" << fNtupleI[i] << "> = " << x << G4endl;
}
fManager->FillNtupleIColumn(fTupleI[i], x);
} else {
G4cout << "Histo::FillTupleI: WARNING! wrong ntuple index " << i << G4endl;
}
#ifdef G4ANALYSIS_USE
if(ntup) ntup->fill(ntup->findColumn(parname), (float)x);
#endif
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::addRow()
void Histo::FillTupleF(G4int i, G4float x)
{
#ifdef G4ANALYSIS_USE
if(ntup) ntup->addRow();
#endif
if(!fNtupleActive) { return; }
G4int n = fNtupleF.size();
if(i >= 0 && i < n) {
if(fVerbose > 1) {
G4cout << "Histo::FillTupleF: i= " << i << " id= " << fTupleF[i]
<< " <" << fNtupleF[i] << "> = " << x << G4endl;
}
fManager->FillNtupleFColumn(fTupleF[i], x);
} else {
G4cout << "Histo::FillTupleF: WARNING! wrong ntuple index " << i << G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::FillTupleD(G4int i, G4double x)
{
if(!fNtupleActive) { return; }
G4int n = fNtupleD.size();
if(i >= 0 && i < n) {
if(fVerbose > 1) {
G4cout << "Histo::FillTupleD: i= " << i << " id= " << fTupleD[i]
<< " <" << fNtupleD[i] << "> = " << x << G4endl;
}
fManager->FillNtupleDColumn(fTupleD[i], x);
} else {
G4cout << "Histo::FillTupleD: WARNING! wrong ntuple index " << i << G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::AddRow()
{
if(!fNtupleActive) { return; }
fManager->AddNtupleRow();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::setFileName(const G4String& nam)
void Histo::SetFileName(const G4String& nam)
{
histName = nam;
fHistName = nam;
fHistoActive = true;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::setFileType(const G4String& nam)
void Histo::SetFileType(const G4String& nam)
{
if(nam == "root" || nam == "hbook" || nam == "aida") histType = nam;
else if(nam == "xml" || nam == "XML") histType = "aida";
if(nam == "root" || nam == "ROOT" ) { fHistType = "root"; }
else if(nam == "xml" || nam == "XML") { fHistType = "xml"; }
else if(nam == "ascii" || nam == "ASCII" ||
nam == "Csv" || nam == "csv" || nam == "CSV") { fHistType = "ascii"; }
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....