Import Geant4 5.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-08 16:57:27 +02:00
parent 330b82b769
commit 37fff30d2e
5733 changed files with 263867 additions and 74574 deletions
@@ -30,20 +30,24 @@
// -----------
// 16 Jan 2002 Alex Howard Created
// 17 June 2002 Alex Howard Successfully Modified to AIDA 2.2
// 17 November 2002 Alex Howard Migrated to AIDA 3.0 and added fitting
//
// -------------------------------------------------------------------
#ifdef G4ANALYSIS_USE
#include "DMXAnalysisManager.hh"
//#include "g4std/iomanip"
DMXAnalysisManager* DMXAnalysisManager::instance = 0;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
DMXAnalysisManager::DMXAnalysisManager() :
af(0), tree(0), hf(0), tpf(0), pf(0)
af(0), tree(0), hf(0), tpf(0), pf(0),
plotter(0), ntuple1(0), ntuple2(0), ntuple3(0), ntuple4(0),
hEsourcep(0), hEdepp(0), hEdepRecoil(0), hNumPhLow(0), hNumPhHigh(0),
hAvPhArrival(0), hPhArrival(0), hPMTHits(0), h1stPMTHit(0),hGammaEdep(0),
hNeutronEdep(0), hElectronEdep(0), hPositronEdep(0), hOtherEdep(0),
funFact(0),fitFact(0),exponFun(0),gaussFun(0),e_fitter(0),fitResult(0)
{
// tree is created and booked inside book()
;
@@ -53,35 +57,20 @@ DMXAnalysisManager::DMXAnalysisManager() :
DMXAnalysisManager::~DMXAnalysisManager()
{
delete pf;
pf=0;
delete tpf;
tpf=0;
delete hf;
hf=0;
delete tree;
tree=0;
delete af;
af = 0;
Finish();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
DMXAnalysisManager* DMXAnalysisManager::getInstance()
{
if (instance == 0) instance = new DMXAnalysisManager;
if (instance == 0) instance = new DMXAnalysisManager();
return instance;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void DMXAnalysisManager::book(G4String histogramfile)
void DMXAnalysisManager::book(G4String histogramfile, G4bool plotevent)
{
// histoManager->selectStore("DMX.his");
@@ -96,9 +85,9 @@ void DMXAnalysisManager::book(G4String histogramfile)
G4bool fileExists = false;
G4bool readOnly = false;
ITreeFactory * tf = af->createTreeFactory();
AIDA::ITreeFactory * tf = af->createTreeFactory();
tree = tf->create(histogramfile, readOnly, fileExists, "hbook");
tree = tf->create(histogramfile, "hbook", readOnly, fileExists);
G4cout << "Tree store : " << tree->storeName() << G4endl;
@@ -110,27 +99,27 @@ void DMXAnalysisManager::book(G4String histogramfile)
// ---- primary ntuple ------
ITuple* ntuple1 = tpf->create( "1 Energy", "Particle Source Energy",
"float energy" );
ntuple1 = tpf->create( "1", "Particle Source Energy",
"double energy" );
assert(ntuple1);
// ---- secondary ntuple ------
ITuple* ntuple2 = tpf->create( "2 Hits Info", "Scintillation Hits Info",
ntuple2 = tpf->create( "2", "Scintillation Hits Info",
"float Event,e_prim,tot_e,s_hits,xe_time,num_ph,avphtime,1stpart,1stparte,gamma,neutron,posi,elec,other,seed1,seed2" );
assert(ntuple2);
// ---- tertiary ntuple ------
ITuple* ntuple3 = tpf->create( "3 Pmt Info", "PMT Hits Info",
ntuple3 = tpf->create( "3", "PMT Hits Info",
"float event, hits, xpos, ypos, zpos" );
assert(ntuple3);
assert(ntuple3);
// ---- extra ntuple ------
ITuple* ntuple4 = tpf->create( "4 Particle Info", "Particles energy type",
ntuple4 = tpf->create( "4", "Particles energy type",
"float energy, NameIdx" );
assert(ntuple4);
@@ -138,51 +127,88 @@ void DMXAnalysisManager::book(G4String histogramfile)
// Creating an 1-dimensional histogram in the root directory of the tree
IHistogram1D* hEsourcep;
hEsourcep = hf->create1D("10","Source Energy /keV", 1000,0.,10000.);
hEsourcep = hf->createHistogram1D("10","Source Energy /keV", 1000,0.,10000.);
IHistogram1D* hEdepp;
hEdepp = hf->create1D("20","Energy Deposit /keV", 1000,0.,1000.);
hEdepp = hf->createHistogram1D("20","Energy Deposit /keV", 1000,0.,1000.);
IHistogram1D* hEdepRecoil;
hEdepRecoil = hf->create1D("30","Nuclear Recoil Edep /keV", 100,0.,100.);
hEdepRecoil = hf->createHistogram1D("30","Nuclear Recoil Edep /keV", 100,0.,100.);
IHistogram1D* hNumPhLow;
hNumPhLow = hf->create1D("40","Number of Photons - LowE", 200,0.,200.);
hNumPhLow = hf->createHistogram1D("40","Number of Photons - LowE", 200,0.,200.);
IHistogram1D* hNumPhHigh;
hNumPhHigh = hf->create1D("50","Number of Photons - HighE", 100,0.,10000.);
hNumPhHigh = hf->createHistogram1D("50","Number of Photons - HighE", 100,0.,10000.);
IHistogram1D* hAvPhArrival;
hAvPhArrival = hf->create1D("60","Average Photon Arrival/ns", 200,0.,200.);
IHistogram1D* h1stPhArrival;
h1stPhArrival = hf->create1D("61","1st event Photon Arrival", 200,0.,200.);
hAvPhArrival = hf->createHistogram1D("60","Average Photon Arrival/ns", 200,0.,200.);
hPhArrival = hf->createHistogram1D("61","1st event Photon Arrival", 200,0.,200.);
IHistogram2D* hPMTHits;
hPMTHits = hf->create2D("70","PMT Hit Pattern",
//2D histograms:
hPMTHits = hf->createHistogram2D("70","PMT Hit Pattern",
300 ,-30.,30.,300,-30.,30.);
IHistogram2D* h1stPMTHit;
h1stPMTHit = hf->create2D("71","1st event PMT Hit Pattern",
h1stPMTHit = hf->createHistogram2D("71","1st event PMT Hit Pattern",
300 ,-30.,30.,300,-30.,30.);
IHistogram1D* hGammaEdep;
hGammaEdep = hf->create1D("91","Gamma Energy Deposit/keV", 1000,0.,1000.);
IHistogram1D* hNeutronEdep;
hNeutronEdep = hf->create1D("92","Neutron Ener Deposit/keV", 1000,0.,1000.);
IHistogram1D* hElectronEdep;
hElectronEdep = hf->create1D("93","Electron Ener Deposit/keV",1000,0.,1000.);
IHistogram1D* hPositronEdep;
hPositronEdep = hf->create1D("94","Positron Ener Deposit/keV",1000,0.,1000.);
IHistogram1D* hOtherEdep;
hOtherEdep = hf->create1D("95","Other Ener Deposit/keV", 1000,0.,1000.);
// extra 1D Histos:
hGammaEdep = hf->createHistogram1D("91","Gamma Energy Deposit/keV", 1000,0.,1000.);
hNeutronEdep = hf->createHistogram1D("92","Neutron Ener Deposit/keV", 1000,0.,1000.);
hElectronEdep = hf->createHistogram1D("93","Electron Ener Deposit/keV",1000,0.,1000.);
hPositronEdep = hf->createHistogram1D("94","Positron Ener Deposit/keV",1000,0.,1000.);
hOtherEdep = hf->createHistogram1D("95","Other Ener Deposit/keV", 1000,0.,1000.);
delete tf;
// Creating the plotter factory
pf = af->createPlotterFactory();
if(pf && plotevent) {
plotter = pf->create();
if(plotter) {
plotter->show();
plotter->setParameter("pageTitle","DMX Output Summary");
}
delete pf;
}
// create fitting factories ..
G4cout << " creating fit factories " << G4endl;
funFact = af->createFunctionFactory(*tree);
fitFact = af->createFitFactory();
G4cout << " creating Exponential Function " << G4endl;
exponFun = funFact->createFunctionByName("Exponential","E");
G4cout << " created " << G4endl;
G4cout << " creating Gaussian Function " << G4endl;
gaussFun = funFact->createFunctionByName("Gaussian","G");
G4cout << " created " << G4endl;
// assert(exponFun);
// e_fitter = fitFact->createFitter("Chi2","","printLevel=-1 errorUP=1.0");
G4cout << " creating fitter " << G4endl;
e_fitter = fitFact->createFitter();
// assert(e_fitter);
G4cout << " Created e_fitter " << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void DMXAnalysisManager::finish()
void DMXAnalysisManager::Init()
{
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void DMXAnalysisManager::Finish()
{
// Committing the transaction with the tree
@@ -202,15 +228,95 @@ void DMXAnalysisManager::finish()
delete hf;
delete tree;
delete af;
delete plotter;
delete funFact;
delete fitFact;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void DMXAnalysisManager::PulseTimeFit()
{
// created fitter factory then fitter
if(!plotter) plotter = pf->create();
if(plotter) {
plotter->show();
plotter->setParameter("pageTitle","DMX Fitting");
}
G4cout << " Started Pulse Time Fit " << G4endl;
for (int i = 0; i < 2 ; ++i)
G4cout << "\n Fit Parameters: " << i << ":\t"
<< exponFun->parameterNames()[i] << G4endl;
// first fit to time histogram:
exponFun->setParameter("amp", 3.);
exponFun->setParameter("slope", -0.03);
G4cout << " parameters set " << G4endl;
fitResult = e_fitter->fit(*hPhArrival,*exponFun);
G4cout << " Fit Completed " << G4endl;
G4cout << " chi2/ndf is: " << fitResult->quality() << " / "
<< fitResult->ndf() << G4endl;
// retrieve fitted parameters and errors and print them
for (i = 0; i < 2 ; ++i)
G4cout << fitResult->fittedParameterNames()[i] << " = "
<< fitResult->fittedParameters()[i] << " +/- "
<< fitResult->errors()[i];
// plot function with its annotation and then histogram
plotter->currentRegion().plot(*exponFun,"[0,100] annotation");
plotter->currentRegion().plot(*hPhArrival, "overlay");
plotter->refresh();
plotter->writeToFile("ExponentialFit.ps","ps");
for (i = 0; i < 3 ; ++i)
G4cout << "\n Fit Parameters: " << i << ":\t"
<< gaussFun->parameterNames()[i] << G4endl;
// first fit to time histogram:
gaussFun->setParameter("mean", 50.);
gaussFun->setParameter("sigma", 10.);
gaussFun->setParameter("amp", 2.);
G4cout << " parameters set " << G4endl;
fitResult = e_fitter->fit(*hAvPhArrival,*gaussFun);
G4cout << " Fit Completed " << G4endl;
G4cout << " chi2/ndf is: " << fitResult->quality() << " / "
<< fitResult->ndf() << G4endl;
// retrieve fitted parameters and errors and print them
for (i = 0; i < 3 ; ++i)
G4cout << fitResult->fittedParameterNames()[i] << " = "
<< fitResult->fittedParameters()[i] << " +/- "
<< fitResult->errors()[i];
// plot function with its annotation and then histogram
plotter->createRegions(1,1);
plotter->currentRegion().plot(*gaussFun,"[0,100] annotation");
plotter->currentRegion().plot(*hAvPhArrival, "overlay");
plotter->refresh();
plotter->writeToFile("TimeConstantFit.ps","ps");
G4cout << " Fit finished " << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void DMXAnalysisManager::analyseScintHits(G4int event_id, G4double energy_pri, G4double totEnergy, G4int S_hits, G4double firstLXeHitTime, G4int P_hits, G4double aveTimePmtHits, G4String firstparticleName, G4double firstParticleE, G4bool gamma_ev, G4bool neutron_ev, G4bool positron_ev,G4bool electron_ev,G4bool other_ev, long seed1, long seed2)
{
G4int firstparticleIndex = 0;
if(firstparticleName == "gamma") firstparticleIndex = 1;
if(firstparticleName == "neutron") firstparticleIndex = 2;
@@ -218,27 +324,21 @@ void DMXAnalysisManager::analyseScintHits(G4int event_id, G4double energy_pri, G
if(firstparticleName == "positron") firstparticleIndex = 4;
if(firstparticleName == "other") {
firstparticleIndex = 5;
IHistogram1D* h4 = dynamic_cast<IHistogram1D *> ( tree->find("30") );
h4->fill(totEnergy); // fill(x,y,weight)
hEdepRecoil->fill(totEnergy);
}
IHistogram1D* h2 = dynamic_cast<IHistogram1D *> ( tree->find("40") );
h2->fill(P_hits,10.); // fill(x,weight)
hNumPhLow->fill(P_hits,10.); // fill(x,weight)
IHistogram1D* h3 = dynamic_cast<IHistogram1D *> ( tree->find("50") );
h3->fill(P_hits); // fill(x,y,weight)
hNumPhHigh->fill(P_hits); // fill(x,y,weight)
IHistogram1D* h1 = dynamic_cast<IHistogram1D *> ( tree->find("10") );
h1->fill( energy_pri/keV ); // fill(x,weight)
hEsourcep->fill( energy_pri/keV );
IHistogram1D* h5 = dynamic_cast<IHistogram1D *> ( tree->find("20") );
h5->fill( totEnergy/keV );
hEdepp->fill( totEnergy/keV );
IHistogram1D* h6 = dynamic_cast<IHistogram1D *> ( tree->find("60") );
h6->fill(aveTimePmtHits/ns); // fill(x,y,weight)
hAvPhArrival->fill(aveTimePmtHits/ns);
ITuple * ntuple = dynamic_cast<ITuple *> ( tree->find("2 Hits Info") );
AIDA::ITuple * ntuple = dynamic_cast<AIDA::ITuple *> ( tree->find("2") );
// Fill the ntuple
ntuple->fill( ntuple->findColumn( "Event" ), (G4float) event_id );
@@ -258,8 +358,6 @@ void DMXAnalysisManager::analyseScintHits(G4int event_id, G4double energy_pri, G
ntuple->fill( ntuple->findColumn( "seed1" ), (G4float) seed1 );
ntuple->fill( ntuple->findColumn( "seed2" ), (G4float) seed2 );
//ntuple->fill( ntuple->findColumn( "Event" ), static_cast<float>(event_id) );
//Values of attributes are prepared; store them to the nTuple:
ntuple->addRow();
@@ -270,15 +368,13 @@ void DMXAnalysisManager::analyseScintHits(G4int event_id, G4double energy_pri, G
void DMXAnalysisManager::analysePMTHits(G4int event, G4int i, G4double x, G4double y, G4double z)
{
IHistogram2D* h7 = dynamic_cast<IHistogram2D *> ( tree->find("70") );
h7->fill(x/mm, y/mm); // fill(x,y,weight)
hPMTHits->fill(x/mm, y/mm); // fill(x,y,weight)
if (event == 0 ) {
IHistogram2D* h9 = dynamic_cast<IHistogram2D *> ( tree->find("71") );
h9->fill(x,y); // fill(x,y,weight)
h1stPMTHit->fill(x,y);
}
ITuple * ntuple = dynamic_cast<ITuple *> ( tree->find("3 Pmt Info") );
AIDA::ITuple * ntuple = dynamic_cast<AIDA::ITuple *> ( tree->find("3") );
// Fill the secondaries ntuple
ntuple->fill( ntuple->findColumn( "event" ), (G4float) event );
ntuple->fill( ntuple->findColumn( "hits" ), (G4float) i );
@@ -289,9 +385,6 @@ void DMXAnalysisManager::analysePMTHits(G4int event, G4int i, G4double x, G4doub
// NEW: Values of attributes are prepared; store them to the nTuple:
ntuple->addRow(); // check for returning true ...
// IHistogram1D* h3 = dynamic_cast<IHistogram1D *> ( theTree->find("30") );
//h3->fill(ph_hits);
}
@@ -300,18 +393,13 @@ void DMXAnalysisManager::analysePMTHits(G4int event, G4int i, G4double x, G4doub
void DMXAnalysisManager::analysePrimaryGenerator(G4double energy)
{
// IHistogram1D* h1 = dynamic_cast<IHistogram1D *> ( tree->find("10") );
// h1->fill(static_cast<double>(energy/keV)); // fill(x,weight)
ITuple * ntuple = dynamic_cast<ITuple *> ( tree->find("1 Energy") );
AIDA::ITuple * ntuple = dynamic_cast<AIDA::ITuple *> ( tree->find("1") );
// Fill energy ntple:
ntuple->fill( ntuple->findColumn( "energy" ), (G4float) energy );
ntuple->fill( ntuple->findColumn( "energy" ), energy );
// NEW: Values of attributes are prepared; store them to the nTuple:
ntuple->addRow(); // check for returning true ...
// h1 and h2 are the order in which they are filled, "1" and "2"
// are the labels associated with the histogram
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -322,121 +410,88 @@ void DMXAnalysisManager::analyseParticleSource(G4double energy, G4String name)
{
if(name == "gamma") {
IHistogram1D* h11 = dynamic_cast<IHistogram1D *> ( tree->find("91") );
h11->fill(energy/keV); // fill(x,weight)
hGammaEdep->fill(energy/keV);
}
if(name == "neutron") {
IHistogram1D* h12 = dynamic_cast<IHistogram1D *> ( tree->find("92") );
h12->fill(energy/keV); // fill(x,weight)
hNeutronEdep->fill(energy/keV); // fill(x,weight)
}
if(name == "electron") {
IHistogram1D* h13 = dynamic_cast<IHistogram1D *> ( tree->find("93") );
h13->fill(energy/keV); // fill(x,weight)
hElectronEdep->fill(energy/keV); // fill(x,weight)
}
if(name == "positron") {
IHistogram1D* h14 = dynamic_cast<IHistogram1D *> ( tree->find("94") );
h14->fill(energy/keV); // fill(x,weight)
if(name == "positron") {
hPositronEdep->fill(energy/keV); // fill(x,weight)
}
if(name == "other") {
IHistogram1D* h15 = dynamic_cast<IHistogram1D *> ( tree->find("95") );
h15->fill(energy/keV); // fill(x,weight)
if(name == "other") {
hOtherEdep->fill(energy/keV); // fill(x,weight)
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void DMXAnalysisManager::HistFirstTime(G4double time)
void DMXAnalysisManager::HistTime(G4double time)
{
IHistogram1D* h8 = dynamic_cast<IHistogram1D *> ( tree->find("61") );
h8->fill(time/ns); // fill(x,y,weight)
hPhArrival->fill(time/ns); // fill(x,y,weight)
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void DMXAnalysisManager::PlotHistosInter(G4int flag)
{
// The plotter is updated only if there are some hits in the event
if(!flag) return;
// Set the plotter ; set the number of regions and attach histograms
// to plot for each region.
// It is done here, since then EndOfRun set regions
// for paper output.
if(plotter) {
plotter->currentRegion().plot(*hNumPhLow);
plotter->refresh();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void DMXAnalysisManager::PlotHistos(G4bool interactive)
{
IHistogram1D* h1p = dynamic_cast<IHistogram1D *> ( tree->find("10") );
IHistogram1D& h1 = *h1p;
IHistogram1D* h2p = dynamic_cast<IHistogram1D *> ( tree->find("20") );
IHistogram1D& h2 = *h2p;
IHistogram1D* h3p = dynamic_cast<IHistogram1D *> ( tree->find("40") );
IHistogram1D& h3 = *h3p;
IHistogram1D* h4p = dynamic_cast<IHistogram1D *> ( tree->find("50") );
IHistogram1D& h4 = *h4p;
IHistogram1D* h5p = dynamic_cast<IHistogram1D *> ( tree->find("60") );
IHistogram1D& h5 = *h5p;
IHistogram1D* h6p = dynamic_cast<IHistogram1D *> ( tree->find("61") );
IHistogram1D& h6 = *h6p;
IHistogram2D* h7p = dynamic_cast<IHistogram2D *> ( tree->find("70") );
IHistogram2D& h7 = *h7p;
IHistogram1D* h8p = dynamic_cast<IHistogram1D *> ( tree->find("91") );
IHistogram1D& h8 = *h8p;
// Creating the plotter factory
pf = af->createPlotterFactory();
// Creating a plotter
IPlotter* plotter = pf->create();
// plotter = pf->create();
// Creating two regions
plotter->clearPage();
plotter->createRegions(2, 2, 0); // set the current working region to the first one
if(!plotter) plotter = pf->create();
plotter->show();
plotter->setParameter("pageTitle","DMX Output Summary");
// Plotting the second histogram in the first region
plotter->plot( h1 );
// G4int n = 1;
if(plotter) {
// We set one single region for the plotter
// We now print the histograms, each one in a separate file
plotter->createRegions(1,1);
plotter->currentRegion().plot(*hNumPhHigh);
plotter->refresh();
plotter->writeToFile("NumberPhotons.ps","ps");
plotter->createRegions(1,1);
plotter->currentRegion().plot(*hEdepp);
plotter->refresh();
plotter->writeToFile("EnergyDeposit.ps","ps");
// Plotting the first histogram in the next available region
plotter->next(); // or explicitly : plotter->setCurrentRegion( 1 );
plotter->plot( h2 );
plotter->next(); // or explicitly : plotter->setCurrentRegion( 1 );
plotter->plot( h3 );
plotter->next(); // or explicitly : plotter->setCurrentRegion( 1 );
plotter->plot( h4 );
// Update the canvas on the screen
plotter->refresh();
plotter->write("summary1.ps", "ps");
if (interactive) {
// Wait for the keyboard return to avoid destroying the plotter window too quickly.
G4cout << "Press <ENTER> to exit" << G4endl;
G4cin.get();
}
plotter = pf->create();
plotter->clearPage();
plotter->createRegions(2, 2, 0); // set the current working region to the first one
plotter->show();
// plotter->setCurrentRegion( 0 );
plotter->plot( h5 );
// Plotting the first histogram in the next available region
plotter->next(); // or explicitly : plotter->setCurrentRegion( 1 );
plotter->plot( h6 );
plotter->next(); // or explicitly : plotter->setCurrentRegion( 1 );
plotter->plot( h7 );
plotter->next(); // or explicitly : plotter->setCurrentRegion( 1 );
plotter->plot( h8 );
// Update the canvas on the screen
plotter->refresh();
plotter->write("summary2.ps", "ps");
if (interactive) {
// Wait for the keyboard return to avoid destroying the plotter window too quickly.
G4cout << "Press <ENTER> to exit" << G4endl;
G4cin.get();
plotter->createRegions(1,1);
plotter->currentRegion().plot(*hEsourcep);
plotter->refresh();
plotter->writeToFile("SourceEnergy.ps","ps");
plotter->createRegions(1,1);
plotter->currentRegion().plot(*hNumPhLow);
plotter->refresh();
plotter->writeToFile("NumberPhotonsLow.ps","ps");
}
// // Creating two regions
// plotter->clearRegions();
// // plotter->createRegions(2, 2, 0); // set the current working region to the first one
// plotter->show();
if (interactive) {
// Wait for the keyboard return to avoid destroying the plotter window too quickly.
G4cout << "Press <ENTER> to exit" << G4endl;
G4cin.get();
}
}
@@ -446,10 +501,3 @@ void DMXAnalysisManager::PlotHistos(G4bool interactive)
#endif