Import Geant4 10.2.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 14:11:04 +02:00
parent c9b32a6c0a
commit d4af681f38
4886 changed files with 420149 additions and 1023309 deletions
@@ -54,11 +54,14 @@
#include <TCollection.h>
#include <TDirectory.h>
#include <TString.h>
#include <TRegexp.h>
#ifdef CEXMC_USE_ROOTQT
#include <TCanvas.h>
#include <TList.h>
#include <QApplication>
#include <QFont>
#include <QMenu>
#include <G4UIQt.hh>
#include "CexmcMessenger.hh"
#endif
#include <G4LogicalVolume.hh>
#include <G4Box.hh>
@@ -91,6 +94,8 @@ namespace
const G4double CexmcHistoAngularCResolution( 0.001 );
const G4int CexmcHistoCanvasWidth( 800 );
const G4int CexmcHistoCanvasHeight( 600 );
const G4String CexmcHistoDirectoryHandle( "histograms" );
const G4String CexmcHistoDirectoryTitle( "Histograms" );
}
@@ -117,7 +122,9 @@ CexmcHistoManager::CexmcHistoManager() : outFile( NULL ),
isInitialized( false ), opName( "" ), nopName( "" ), opMass( 0. ),
nopMass( 0. ), verboseLevel( 0 ),
#ifdef CEXMC_USE_ROOTQT
rootCanvas( NULL ),
rootCanvas( NULL ), areLiveHistogramsEnabled( false ),
isHistoMenuInitialized( false ), drawOptions1D( "" ), drawOptions2D( "" ),
drawOptions3D( "" ), histoMenuHandle( "" ), histoMenuLabel( "" ),
#endif
messenger( NULL )
{
@@ -196,7 +203,7 @@ void CexmcHistoManager::AddHisto( const CexmcHistoData & data,
}
CexmcHistosMap::iterator found( histos.find( data.type ) );
if ( found == histos.end() )
throw CexmcException( CexmcWeirdException );
@@ -206,16 +213,13 @@ void CexmcHistoManager::AddHisto( const CexmcHistoData & data,
{
G4bool dirOk( false );
if ( outFile )
{
dirOk = gDirectory->Get( fullName ) != NULL;
dirOk = gDirectory->Get( fullName ) != NULL;
if ( ! dirOk )
dirOk = ( gDirectory->mkdir( fullName, fullTitle ) != NULL );
if ( ! dirOk )
dirOk = ( gDirectory->mkdir( fullName, fullTitle ) != NULL );
if ( dirOk )
gDirectory->cd( fullName );
}
if ( dirOk )
gDirectory->cd( fullName );
std::ostringstream histoName;
std::ostringstream histoTitle;
@@ -228,11 +232,8 @@ void CexmcHistoManager::AddHisto( const CexmcHistoData & data,
CreateHisto( histoVector, data.impl, histoName.str(), histoTitle.str(),
data.axes );
if ( outFile )
{
if ( dirOk )
gDirectory->cd( ".." );
}
if ( dirOk )
gDirectory->cd( ".." );
}
else
{
@@ -322,6 +323,15 @@ void CexmcHistoManager::Initialize( void )
".root" );
outFile = new TFile( resultsFile, "recreate" );
}
else
{
outFile = new TDirectoryFile( CexmcHistoDirectoryHandle,
CexmcHistoDirectoryTitle );
gDirectory->cd( CexmcHistoDirectoryHandle );
}
if ( ! outFile )
throw CexmcException( CexmcWeirdException );
const CexmcSetup * setup( static_cast< const CexmcSetup * >(
runManager->GetUserDetectorConstruction() ) );
@@ -435,22 +445,12 @@ void CexmcHistoManager::SetupARHistos( const CexmcAngularRangeList & aRanges )
{
TString name( obj->GetName() );
if ( outFile )
if ( obj->IsFolder() && ( name.Contains( TString( "_arreal_" ) ) ||
name.Contains( TString( "_arrec_" ) ) ) )
{
if ( obj->IsFolder() && ( name.Contains( TString( "_arreal_" ) ) ||
name.Contains( TString( "_arrec_" ) ) ) )
{
gDirectory->cd( name );
gDirectory->DeleteAll();
gDirectory->cd( ".." );
}
}
else
{
if ( name.Contains( TRegexp( "_r[0-9]+" ) ) )
{
gDirectory->Remove( obj );
}
gDirectory->cd( name );
gDirectory->DeleteAll();
gDirectory->cd( ".." );
}
}
@@ -733,6 +733,7 @@ void CexmcHistoManager::Add( CexmcHistoType histoType, unsigned int index,
void CexmcHistoManager::List( void ) const
{
/* BEWARE: list will be printed on stdout */
gDirectory->ls();
}
@@ -747,6 +748,7 @@ void CexmcHistoManager::Print( const G4String & value )
return;
}
/* BEWARE: histo will be printed on stdout */
histo->Print( "range" );
}
@@ -756,9 +758,7 @@ void CexmcHistoManager::Print( const G4String & value )
void CexmcHistoManager::Draw( const G4String & histoName,
const G4String & histoDrawOptions )
{
CexmcRunManager * runManager( static_cast< CexmcRunManager * >(
G4RunManager::GetRunManager() ) );
if ( ! runManager->AreLiveHistogramsEnabled() )
if ( ! areLiveHistogramsEnabled )
{
G4cout << "Live histograms option is disabled" << G4endl;
return;
@@ -787,6 +787,92 @@ void CexmcHistoManager::Draw( const G4String & histoName,
rootCanvas->GetCanvas()->Update();
}
void CexmcHistoManager::EnableLiveHistograms( G4UIsession * session,
G4bool on )
{
areLiveHistogramsEnabled = on;
if ( ! on || ! isInitialized )
return;
G4UIQt * qtSession( dynamic_cast< G4UIQt * >( session ) );
if ( ! qtSession )
return;
if ( ! histoMenuHandle.empty() && ! isHistoMenuInitialized )
{
qtSession->AddMenu( histoMenuHandle, histoMenuLabel );
BuildMenuTree( qtSession, histoMenuHandle, gDirectory->GetList() );
isHistoMenuInitialized = true;
}
}
void CexmcHistoManager::BuildMenuTree( G4UIQt * session,
const G4String & menu, TList * ls )
{
TIter objs( ls );
TObject * obj( NULL );
while ( ( obj = ( TObject * )objs() ) )
{
G4String name( obj->GetName() );
G4String title( obj->GetTitle() );
if ( obj->IsFolder() )
{
AddSubmenu( session, menu, name, title );
BuildMenuTree( session, name, ( ( TDirectory * )obj )->GetList() );
}
else
{
G4String options( name );
do
{
if ( obj->InheritsFrom( TH3::Class() ) &&
! drawOptions3D.empty() )
{
title = G4String( "3: " ) + title;
options += G4String( " " ) + drawOptions3D;
break;
}
if ( obj->InheritsFrom( TH2::Class() ) &&
! drawOptions2D.empty() )
{
title = G4String( "2: " ) + title;
options += G4String( " " ) + drawOptions2D;
break;
}
if ( obj->InheritsFrom( TH1::Class() ) &&
! drawOptions1D.empty() )
{
options += G4String( " " ) + drawOptions1D;
break;
}
} while ( false );
G4String cmd( CexmcMessenger::histoDirName + "draw " + options );
session->AddButton( menu, title.c_str(), cmd );
}
}
}
void CexmcHistoManager::AddSubmenu( G4UIQt * session,
const G4String & parent,
const G4String & name,
const G4String & label )
{
QMenu * menu( new QMenu( label.c_str() ) );
QMenu * parentMenu( ( QMenu * )session->GetInteractor( parent ) );
parentMenu->addMenu( menu );
session->AddInteractor( name, ( G4Interactor )menu );
}
#endif
#endif
@@ -57,7 +57,8 @@ CexmcHistoManagerMessenger::CexmcHistoManagerMessenger(
histoManager( histoManager ), setVerboseLevel( NULL ), listHistos( NULL ),
printHisto( NULL )
#ifdef CEXMC_USE_ROOTQT
, drawHisto( NULL )
, drawHisto( NULL ), addHistoMenu( NULL ), drawHistoOptions1D( NULL ),
drawHistoOptions2D( NULL ), drawHistoOptions3D( NULL )
#endif
{
setVerboseLevel = new G4UIcmdWithAnInteger(
@@ -83,11 +84,44 @@ CexmcHistoManagerMessenger::CexmcHistoManagerMessenger(
drawHisto = new G4UIcmdWithAString(
( CexmcMessenger::histoDirName + "draw" ).c_str(), this );
drawHisto->SetGuidance( "Draw specified histogram. The first parameter is\n"
" the histogram name, the second is draw "
" the histogram name, the rest is draw "
"options.\n Available only if the program was "
"launched\n in graphical mode" );
drawHisto->SetParameterName( "DrawHisto", false );
drawHisto->AvailableForStates( G4State_Idle );
addHistoMenu = new G4UIcmdWithAString(
( CexmcMessenger::histoDirName + "addHistoMenu" ).c_str(), this );
addHistoMenu->SetGuidance( "Add histogram menu in GUI menu bar. The first "
"parameter is\n the menu handle, the rest is "
"the menu label.\n The menu cannot be added "
"or disabled in runtime" );
addHistoMenu->SetParameterName( "AddHistoMenu", true );
addHistoMenu->AvailableForStates( G4State_Idle );
drawHistoOptions1D = new G4UIcmdWithAString(
( CexmcMessenger::histoDirName + "drawOptions1D" ).c_str(), this );
drawHistoOptions1D->SetGuidance( "Set draw options for 1D histograms drawn "
"from the menu.\n The options cannot "
"be changed after the menu was built");
drawHistoOptions1D->SetParameterName( "DrawOptions1D", false );
drawHistoOptions1D->AvailableForStates( G4State_Idle );
drawHistoOptions2D = new G4UIcmdWithAString(
( CexmcMessenger::histoDirName + "drawOptions2D" ).c_str(), this );
drawHistoOptions2D->SetGuidance( "Set draw options for 2D histograms drawn "
"from the menu.\n The options cannot "
"be changed after the menu was built");
drawHistoOptions2D->SetParameterName( "DrawOptions2D", false );
drawHistoOptions2D->AvailableForStates( G4State_Idle );
drawHistoOptions3D = new G4UIcmdWithAString(
( CexmcMessenger::histoDirName + "drawOptions3D" ).c_str(), this );
drawHistoOptions3D->SetGuidance( "Set draw options for 3D histograms drawn "
"from the menu.\n The options cannot "
"be changed after the menu was built");
drawHistoOptions3D->SetParameterName( "DrawOptions3D", false );
drawHistoOptions3D->AvailableForStates( G4State_Idle );
#endif
}
@@ -99,6 +133,10 @@ CexmcHistoManagerMessenger::~CexmcHistoManagerMessenger()
delete printHisto;
#ifdef CEXMC_USE_ROOTQT
delete drawHisto;
delete addHistoMenu;
delete drawHistoOptions1D;
delete drawHistoOptions2D;
delete drawHistoOptions3D;
#endif
}
@@ -136,6 +174,32 @@ void CexmcHistoManagerMessenger::SetNewValue( G4UIcommand * cmd,
value.c_str() + delimPosEnd );
break;
}
if ( cmd == addHistoMenu )
{
size_t delimPos( value.find_first_of( " \t" ) );
size_t delimPosEnd( G4String::npos );
if ( delimPos != G4String::npos )
delimPosEnd = value.find_first_not_of( " \t", delimPos );
histoManager->AddHistoMenu( std::string( value, 0, delimPos ),
delimPosEnd == G4String::npos ? "" :
value.c_str() + delimPosEnd );
break;
}
if ( cmd == drawHistoOptions1D )
{
histoManager->SetDrawOptions1D( value );
break;
}
if ( cmd == drawHistoOptions2D )
{
histoManager->SetDrawOptions2D( value );
break;
}
if ( cmd == drawHistoOptions3D )
{
histoManager->SetDrawOptions3D( value );
break;
}
#endif
} while ( false );
}
@@ -46,13 +46,20 @@
#include <QContextMenuEvent>
#include <TObject.h>
#include <TCanvas.h>
#include <TH1.h>
#include <TAxis.h>
#include <TList.h>
#include "CexmcHistoWidget.hh"
CexmcHistoWidget::CexmcHistoWidget()
{
/* this is a workaround of the repaint bug in the ROOT Qt backend:
* see http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=17081#p73055 */
fCanvas->SetFillColor( 10 );
}
void CexmcHistoWidget::contextMenuEvent( QContextMenuEvent * event )
{
/* TRootContextMenu responsiveness is very ugly and unstable in Geant4
@@ -64,12 +71,11 @@ void CexmcHistoWidget::contextMenuEvent( QContextMenuEvent * event )
* TRootContextMenu object. */
if ( event->reason() == QContextMenuEvent::Other )
{
TCanvas * canvas( Canvas() );
TObject * object( NULL );
TListIter curPrimitive( canvas->GetListOfPrimitives() );
TListIter curPrimitive( fCanvas->GetListOfPrimitives() );
while ( ( object = curPrimitive.Next() ) )
{
if ( ! object->InheritsFrom( "TH1" ) )
if ( ! object->InheritsFrom( TH1::Class() ) )
continue;
TH1 * histo( static_cast< TH1 * >( object ) );
TAxis * axis( histo->GetXaxis() );
@@ -82,7 +88,7 @@ void CexmcHistoWidget::contextMenuEvent( QContextMenuEvent * event )
if ( axis )
axis->UnZoom();
}
canvas->Update();
fCanvas->Update();
}
}
@@ -110,7 +110,7 @@ CexmcRunManager::CexmcRunManager( const G4String & projectId,
gdmlFileName( "default.gdml" ), shouldGdmlFileBeValidated( true ),
zipGdmlFile( false ), projectsDir( "." ), projectId( projectId ),
rProject( rProject ), guiMacroName( "" ), cfFileName( "" ),
eventCountPolicy( CexmcCountAllEvents ), areLiveHistogramsEnabled( false ),
eventCountPolicy( CexmcCountAllEvents ),
skipInteractionsWithoutEDTonWrite( true ),
evDataVerboseLevel( CexmcWriteEventDataOnEveryEDT ),
rEvDataVerboseLevel( CexmcWriteNoEventData ), numberOfEventsProcessed( 0 ),