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
+223 -182
View File
@@ -23,6 +23,11 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file hadronic/Hadr01/src/Histo.cc
/// \brief Implementation of the Histo class
//
// $Id$
//
//---------------------------------------------------------------------------
//
// ClassName: Histo - Generic histogram/ntuple manager class
@@ -37,276 +42,312 @@
//....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(G4int ver)
Histo::Histo()
{
verbose = ver;
histName = "histo";
histType = "root";
option = "";
nHisto = 0;
defaultAct = 1;
tupleName = "tree.root";
tupleId = "100";
tupleList = "";
ntup = 0;
messenger = 0;
#ifdef G4ANALYSIS_USE
messenger = new HistoMessenger(this);
tree = 0;
af = 0;
#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();
if(verbose>0) {
G4cout<<"HIsto books analysis factory ......... "<<G4endl;
}
// Creating the tree factory
AIDA::ITreeFactory* tf = af->createTreeFactory();
if(verbose>0) {
G4cout<<"Histo books tree factory ......... "<<G4endl;
}
G4String histExt = "";
char* path = getenv("PHYSLIST");
if (path) { histExt = "_" + G4String(path); }
if(!(fHistoActive || fNtupleActive)) { return; }
G4String histDir = "";
path = getenv("HISTODIR");
if (path) histDir = G4String(path) + "/";
// Always creating analysis manager
fManager = G4RootAnalysisManager::Instance();
// Creating a tree mapped to a new hbook file.
G4String name = histDir + histName + histExt + "." + histType;
tree = tf->create(name, histType, false, true, option);
G4cout << "Histo: tree store : " << tree->storeName() << G4endl;
delete tf;
G4String nam = fHistName + "." + fHistType;
// Creating a histogram factory, whose histograms will be handled by the tree
AIDA::IHistogramFactory* hf = af->createHistogramFactory( *tree );
// Open file histogram file
if(!fManager->OpenFile(nam)) {
G4cout << "Histo::Book: ERROR open file <" << nam << ">" << G4endl;
fHistoActive = false;
fNtupleActive = false;
return;
}
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]) {
if(verbose>0) {
G4cout<<" I am in book: histogram "<< i << " id= " << ids[i] <<G4endl;
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;
}
G4String idd;
if(histType == "root") { idd = "h" + ids[i]; }
else { idd = ids[i]; }
histo[i] = hf->createHistogram1D(idd, titles[i], bins[i], xmin[i], xmax[i]);
} else {
histo[i] = 0;
}
}
delete hf;
// Creating a tuple factory, whose tuples will be handled by the tree
if(tupleList != "") {
if(verbose>0) {
G4cout<<"Histo books tuple factory for "<<tupleName <<G4endl;
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]); }
}
AIDA::ITupleFactory* tpf = af->createTupleFactory( *tree );
ntup = tpf->create(tupleId, tupleName, tupleList);
delete tpf;
}
#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
tree->commit();
G4cout << "Closing the tree..." << G4endl;
tree->close();
G4cout << "Histograms and Ntuples are saved" << G4endl;
delete tree;
tree = 0;
#endif
}
if(!fManager->Write()) {
G4cout << "Histo::Save: FATAL ERROR writing ROOT file" << G4endl;
exit(1);
}
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::reset()
{
#ifdef G4ANALYSIS_USE
delete tree;
tree = 0;
#endif
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::setFileType(const G4String& nam)
{
if(nam == "hbook" || nam == "root" || nam == "aida") histType = nam;
else if(nam == "XML" || nam == "xml") histType = "aida";
}
//....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(nHisto > 0) {
for(G4int i=0; i<nHisto; i++) {
if(ids[i] == id) return;
}
}
if(verbose > 0)
G4cout << "New histogram will be booked: #" << id << " <" << name
<< " " << nb << " " << x1 << " " << x2 << " " << u
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 << "nHisto = " << nHisto << 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
<< " weight= " << w << " unit= " << unit[i]
<< G4endl;
}
#ifdef G4ANALYSIS_USE
if(i>=0 && i<nHisto) {
histo[i]->fill(x/unit[i], w);
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;
}
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(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;
G4cout<<" addTuple: Id "<<w1<<" Name "<<w2<<" List "<<w3<<G4endl;
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::print(G4int i)
void Histo::SetFileName(const G4String& nam)
{
G4cout<<"### Histogram "<<i<<" ###"<<G4endl;
#ifdef G4ANALYSIS_USE
if(i>=0 && i<nHisto) {
G4double step = (xmax[i] - xmin[i])/G4double( bins[i]);
G4double x = xmin[i] - step*0.5;
G4double y, maxX=0, maxY=0;
G4int maxJ=0;
for(G4int j=0; j<bins[i]; j++) {
x += step;
y = histo[i]->binHeight(j);
if(maxY < y) {maxY = y; maxX = x; maxJ = j;}
G4cout<<x<<" "<<y<<G4endl;
}
G4cout<<" maxJ "<<maxJ<<" maxX "<<maxX<<" maxY "<<maxY<<G4endl;
}
#endif
fHistName = nam;
fHistoActive = true;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Histo::SetFileType(const G4String& nam)
{
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....