Import Geant4 10.5.0 source tree

This commit is contained in:
Gabriele Cosmo
2018-12-07 15:15:39 +01:00
parent 6aa23be517
commit db49709b53
11370 changed files with 187480 additions and 160142 deletions
@@ -0,0 +1,34 @@
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(scoreWriter)
#----------------------------------------------------------------------------
# Find Geant4 package, no UI and Vis drivers activated
#
find_package(Geant4 REQUIRED)
#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
#
include(${Geant4_USE_FILE})
#----------------------------------------------------------------------------
# Locate sources and headers for this project
#
include_directories(${PROJECT_SOURCE_DIR}/include
${Geant4_INCLUDE_DIR})
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
#----------------------------------------------------------------------------
# Add the library
#
add_library(scoreWriter ${sources} ${headers})
target_link_libraries(scoreWriter ${Geant4_LIBRARIES} )
#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
# and the library to 'lib' directory under CMAKE_INSTALL_PREFIX
#
install(TARGETS scoreWriter DESTINATION lib)
@@ -0,0 +1,98 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// Author: Ivana Hrivnacova, 30/10/2018 (ivana@ipno.in2p3.fr)
#ifndef G4ScoreNtupleWriter_h
#define G4ScoreNtupleWriter_h 1
#include "G4VScoreNtupleWriter.hh"
#include "G4HCofThisEvent.hh"
#include "G4AnalysisUtilities.hh"
#include "G4Threading.hh"
#include "globals.hh"
#include <memory>
class G4HCofThisEvent;
class G4VAnalysisManager;
class G4ScoreNtupleWriterMessenger;
// class description:
//
// This class implements storing hits collections of G4THitsMap<G4double>
// type vith Geant4 analysis tools.
//
// An ntuple with three columns is created for each primitive scorer:
// int column - eventNumber
// int column - copyNumber
// double column - scored value
class G4ScoreNtupleWriter : public G4VScoreNtupleWriter
{
public:
G4ScoreNtupleWriter(const G4String& outputType = "none");
virtual ~G4ScoreNtupleWriter();
// methods
virtual G4bool Book(G4HCofThisEvent* hce);
virtual void OpenFile();
virtual void Fill(G4HCofThisEvent* hce, G4int eventNumber);
virtual void Write();
// set methods
void SetOutputType(const G4String& outputTypeName);
void SetFileName(const G4String& fileName);
void SetVerboseLevel(G4int value);
// get methods
G4AnalysisOutput GetOutputType() const;
G4String GetFileName() const { return fFileName; }
G4int GetVerboseLevel() const { return fVerboseLevel; }
protected:
// methods
virtual G4VScoreNtupleWriter* CreateInstance() const;
private:
// methods
void CreateAnalysisManager();
// data members
G4ScoreNtupleWriterMessenger* fMessenger;
std::vector<G4int> fHCIds;
G4VAnalysisManager* fAnalysisManager;
G4String fOutputTypeName;
G4String fFileName;
G4int fVerboseLevel;
G4bool fHasAnalysisManager;
G4bool fHasAnalysisFile;
G4bool fIsBooked;
G4bool fIsInitialized;
G4int fFirstNtupleId;
};
#endif
@@ -0,0 +1,65 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// Author: Ivana Hrivnacova, 30/10/2018 (ivana@ipno.in2p3.fr)
#ifndef G4ScoreNtupleWriterMessenger_h
#define G4ScoreNtupleWriterMessenger_h 1
#include "G4UImessenger.hh"
class G4ScoreNtupleWriter;
class G4UIdirectory;
class G4UIcmdWithoutParameter;
class G4UIcmdWithAString;
class G4UIcmdWithAnInteger;
// class description:
//
// This is a concrete class of G4UImessenger which handles the commands for
// G4ScoreNtupleWriter. This class has the following commands:
// /score/writerFileName filename
// /score/writerType csv|root|xml|none
// /score/writerVerbose value
//
class G4ScoreNtupleWriterMessenger: public G4UImessenger
{
public:
G4ScoreNtupleWriterMessenger(G4ScoreNtupleWriter* scoreNtupleWriter);
~G4ScoreNtupleWriterMessenger();
void SetNewValue(G4UIcommand * command,G4String newValues);
private:
G4ScoreNtupleWriter* fScoreNtupleWriter;
// G4UIdirectory* fDirectory;
G4UIcmdWithAString* fWriterTypeCmd;
G4UIcmdWithAString* fWriterFileNameCmd;
G4UIcmdWithAnInteger* fWriterVerboseCmd;
};
#endif
@@ -0,0 +1,342 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// Author: Ivana Hrivnacova, 30/10/2018 (ivana@ipno.in2p3.fr)
// ---------------------------------------------------------------------
#include "G4ScoreNtupleWriter.hh"
#include "G4ScoreNtupleWriterMessenger.hh"
#include "G4THitsMap.hh"
#include "g4csv.hh"
#include "g4root.hh"
#include "g4xml.hh"
#include "G4Threading.hh"
//_____________________________________________________________________________
//
// ctor, dtor
//
//_____________________________________________________________________________
G4ScoreNtupleWriter::G4ScoreNtupleWriter(const G4String& outputType)
: G4VScoreNtupleWriter(),
fMessenger(nullptr),
fHCIds(),
fAnalysisManager(nullptr),
fOutputTypeName(outputType),
fFileName("scoring"),
fVerboseLevel(1),
fHasAnalysisManager(false),
fHasAnalysisFile(false),
fIsBooked(false),
fIsInitialized(false),
fFirstNtupleId(0)
{
// if ( G4Threading::IsMasterThread() ) {
fMessenger = new G4ScoreNtupleWriterMessenger(this);
// }
}
//_____________________________________________________________________________
G4ScoreNtupleWriter::~G4ScoreNtupleWriter()
{
if ( fHasAnalysisManager ) {
delete fAnalysisManager;
}
delete fMessenger;
}
//
// private methods
//
//_____________________________________________________________________________
void G4ScoreNtupleWriter::CreateAnalysisManager()
{
if ( fAnalysisManager ) return;
switch ( GetOutputType() ) {
case G4AnalysisOutput::kCsv:
// create Csv analysis manager
if ( ! G4CsvAnalysisManager::IsInstance() ) fHasAnalysisManager = true;
fAnalysisManager = G4CsvAnalysisManager::Instance();
break;
case G4AnalysisOutput::kRoot:
// create Root analysis manager
if ( ! G4RootAnalysisManager::IsInstance() ) fHasAnalysisManager = true;
fAnalysisManager = G4RootAnalysisManager::Instance();
break;
case G4AnalysisOutput::kXml:
// create Xml analysis manager
if ( ! G4XmlAnalysisManager::IsInstance() ) fHasAnalysisManager = true;
fAnalysisManager = G4XmlAnalysisManager::Instance();
break;
case G4AnalysisOutput::kNone:
// do nothing
break;
}
fAnalysisManager->SetVerboseLevel(fVerboseLevel);
}
//
// protected methods
//
//_____________________________________________________________________________
G4VScoreNtupleWriter* G4ScoreNtupleWriter::CreateInstance() const
{
auto instance = new G4ScoreNtupleWriter();
instance->SetOutputType(fOutputTypeName);
instance->SetFileName(fFileName);
instance->SetVerboseLevel(fVerboseLevel);
return instance;
}
//
// public methods
//
//_____________________________________________________________________________
G4bool G4ScoreNtupleWriter::Book(G4HCofThisEvent* hce)
{
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- G4ScoreNtupleWriter::Book" << G4endl;
}
#endif
if ( ! hce) return false;
// book collection ID if DoubleHitsMap
if (fHCIds.size() == 0) {
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- going to fill fHCIds " << G4endl;
}
#endif
for (G4int i=0; i<hce->GetNumberOfCollections(); ++i) {
auto hitsMap
= dynamic_cast<G4THitsMap<G4double>*>(hce->GetHC(i));
if ( hitsMap ) {
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- adding hcID = " << i << G4endl;
}
#endif
fHCIds.push_back(i);
}
}
}
// Create analysis manager
if ( fHCIds.size() ) {
CreateAnalysisManager();
}
// Create ntuples (only once)
if ( ! fIsInitialized ) {
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "-- going to create ntuples " << G4endl;
}
#endif
auto first = true;
for (auto id : fHCIds) {
auto hitsMap
= static_cast<G4THitsMap<G4double>*>(hce->GetHC(id));
// Create ntuple for this primitive
G4String ntupleName(hitsMap->GetSDname());
ntupleName.append("_");
ntupleName.append(hitsMap->GetName());
G4int ntupleId
= fAnalysisManager->CreateNtuple(ntupleName, ntupleName);
if ( first ) {
fFirstNtupleId = ntupleId;
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "-- set first ntuple Id " << fFirstNtupleId << G4endl;
}
#endif
first = false;
}
G4String colName(ntupleName);
colName.append("_eventId");
fAnalysisManager->CreateNtupleIColumn(colName);
colName = ntupleName;
colName.append("_cell");
fAnalysisManager->CreateNtupleIColumn(colName);
colName = ntupleName;
colName.append("_score");
fAnalysisManager->CreateNtupleDColumn(colName);
fAnalysisManager->FinishNtuple();
fIsBooked = true;
}
fIsInitialized = true;
}
return fIsBooked;
}
//_____________________________________________________________________________
void G4ScoreNtupleWriter::OpenFile()
{
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- G4ScoreNtupleWriter::OpenFile" << G4endl;
}
#endif
if ( fAnalysisManager->IsOpenFile() ) return;
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- G4ScoreNtupleWriter::OpenFile executing" << G4endl;
}
#endif
if ( fAnalysisManager->GetFileName() == "" ) {
fAnalysisManager->SetFileName(fFileName);
}
fAnalysisManager->OpenFile();
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- G4ScoreNtupleWriter::OpenFile isOpenFile: "
<< fAnalysisManager->IsOpenFile() << G4endl;
}
#endif
fHasAnalysisFile = fAnalysisManager->IsOpenFile();
}
//_____________________________________________________________________________
void G4ScoreNtupleWriter::Fill(G4HCofThisEvent* hce, G4int eventNumber)
{
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- start G4ScoreNtupleWriter::Fill" << G4endl;
}
#endif
auto counter = 0;
for (auto id : fHCIds) {
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "in loop over fHCIds, counter " << counter << G4endl;
}
#endif
auto hitsMap
= static_cast<G4THitsMap<G4double>*>(hce->GetHC(id));
//G4cout << eventNumber << ".. go to fill ntuple " << counter + fFirstNtupleId << G4endl;
// fill hits in ntuple
std::map<G4int, G4double*>::iterator it;
for ( it = hitsMap->GetMap()->begin(); it != hitsMap->GetMap()->end(); it++ ) {
fAnalysisManager->FillNtupleIColumn(counter + fFirstNtupleId, 0, eventNumber);
fAnalysisManager->FillNtupleIColumn(counter + fFirstNtupleId, 1, it->first);
fAnalysisManager->FillNtupleDColumn(counter + fFirstNtupleId, 2, *(it->second));
fAnalysisManager->AddNtupleRow(counter + fFirstNtupleId);
}
counter++;
}
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- done G4ScoreNtupleWriter::Fill" << G4endl;
}
#endif
}
//_____________________________________________________________________________
void G4ScoreNtupleWriter::Write()
{
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- start G4ScoreNtupleWriter::Write" << G4endl;
}
#endif
if ( fHasAnalysisFile ) {
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- sG4ScoreNtupleWriter::Write - has file" << G4endl;
}
#endif
fAnalysisManager->Write();
fAnalysisManager->CloseFile();
fAnalysisManager->SetFileName("");
}
#ifdef G4VERBOSE
if ( fVerboseLevel > 1 ) {
G4cout << "--- done G4ScoreNtupleWriter::Write" << G4endl;
}
#endif
}
//_____________________________________________________________________________
void G4ScoreNtupleWriter::SetOutputType(const G4String& outputTypeName)
{
if ( fAnalysisManager ) {
G4ExceptionDescription description;
description
<< "Cannot set output type. The analysis manager has not been created.";
G4Exception("G4HitsNtupleWriter::SetOutputType", "", JustWarning, description);
return;
}
fOutputTypeName = outputTypeName;
}
//_____________________________________________________________________________
void G4ScoreNtupleWriter::SetVerboseLevel(G4int value)
{
fVerboseLevel = value;
if ( fAnalysisManager ) {
fAnalysisManager->SetVerboseLevel(value);
}
}
//_____________________________________________________________________________
void G4ScoreNtupleWriter::SetFileName(const G4String& fileName)
{
fFileName = fileName;
}
//_____________________________________________________________________________
G4AnalysisOutput G4ScoreNtupleWriter::GetOutputType() const
{
return G4Analysis::GetOutput(fOutputTypeName);
}
@@ -0,0 +1,101 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// Author: Ivana Hrivnacova, 30/10/2018 (ivana@ipno.in2p3.fr)
// ---------------------------------------------------------------------
#include "G4ScoreNtupleWriterMessenger.hh"
#include "G4ScoreNtupleWriter.hh"
#include "G4UImanager.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4AnalysisUtilities.hh"
G4ScoreNtupleWriterMessenger::G4ScoreNtupleWriterMessenger(
G4ScoreNtupleWriter* scoreNtupleWriter)
: G4UImessenger(),
fScoreNtupleWriter(scoreNtupleWriter),
// fDirectory(nullptr),
fWriterTypeCmd(nullptr),
fWriterFileNameCmd(nullptr),
fWriterVerboseCmd(nullptr)
{
// Create command directory and commands only if they do not exist.
// To be improved: G4UImanager::FindDirectory cannot be used
// as it is declared private.
// if ( ! G4UImanager::GetUIpointer()->FindDirectory("/score") ) {
// fDirectory = new G4UIdirectory("/score/");
// fDirectory->SetGuidance("Interactive scoring commands.");
// }
fWriterTypeCmd = new G4UIcmdWithAString("/score/writerType",this);
fWriterTypeCmd->SetGuidance( "Set the ntuple writer output file type.");
fWriterTypeCmd->SetParameterName("outputType",false);
G4String candidates;
for ( auto candidate :
{ G4AnalysisOutput::kCsv,
G4AnalysisOutput::kRoot,
G4AnalysisOutput::kXml,
G4AnalysisOutput::kNone } ) {
candidates += G4Analysis::GetOutputName(candidate);
candidates += " ";
}
fWriterTypeCmd->SetCandidates(candidates);
fWriterTypeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
fWriterFileNameCmd = new G4UIcmdWithAString("/score/writerFileName",this);
fWriterFileNameCmd->SetGuidance( "Set the ntuple writer output file name.");
fWriterFileNameCmd->SetParameterName("outputFileName",false);
fWriterFileNameCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
fWriterVerboseCmd = new G4UIcmdWithAnInteger("/score/writerVerbose",this);
fWriterVerboseCmd->SetGuidance("Set the ntuple writer verbose level.");
fWriterVerboseCmd->SetParameterName("writerVerbose",false);
fWriterTypeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
}
G4ScoreNtupleWriterMessenger::~G4ScoreNtupleWriterMessenger()
{
delete fWriterTypeCmd;
delete fWriterFileNameCmd;
delete fWriterVerboseCmd;
// delete fDirectory;
}
void G4ScoreNtupleWriterMessenger::SetNewValue(G4UIcommand * command,G4String newVal)
{
if ( command==fWriterTypeCmd ) {
fScoreNtupleWriter->SetOutputType(newVal);
}
else if ( command==fWriterFileNameCmd ) {
fScoreNtupleWriter->SetFileName(newVal);
}
else if ( command==fWriterVerboseCmd ) {
fScoreNtupleWriter->SetVerboseLevel(fWriterVerboseCmd->GetNewIntValue(newVal));
}
}