Import Geant4 0.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-01 15:25:35 +02:00
parent 54d6b71f95
commit b97f8d0df7
3237 changed files with 807095 additions and 0 deletions
@@ -0,0 +1,58 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4HCtable.cc,v 2.1 1998/07/12 02:53:29 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
#include "G4HCtable.hh"
G4HCtable::G4HCtable() {;}
G4HCtable::~G4HCtable() {;}
G4int G4HCtable::Registor(G4String SDname,G4String HCname)
{
for(int i=0;i<HClist.entries();i++)
{ if(HClist[i]==HCname && SDlist[i]==SDname) return -1; }
HClist.insert(HCname);
SDlist.insert(SDname);
return HClist.entries();
}
G4int G4HCtable::GetCollectionID(G4String HCname)
{
G4int i = -1;
if(HCname.index("/")==RW_NPOS) // HCname only
{
for(G4int j=0;j<HClist.entries();j++)
{
if(HClist[j]==HCname)
{
if(i>=0) return -2;
i = j;
}
}
}
else
{
for(G4int j=0;j<HClist.entries();j++)
{
G4String tgt = SDlist[j];
tgt += "/";
tgt += HClist[j];
if(tgt==HCname)
{
if(i>=0) return -2;
i = j;
}
}
}
return i;
}
@@ -0,0 +1,111 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4SDManager.cc,v 2.2 1998/07/13 16:50:04 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
#include "G4SDManager.hh"
#include "G4SDmessenger.hh"
#include "G4HCofThisEvent.hh"
#include "G4VHitsCollection.hh"
#include "G4VSensitiveDetector.hh"
#include "G4ios.hh"
G4SDManager* G4SDManager::fSDManager = 0;
G4SDManager* G4SDManager::GetSDMpointer()
{
if(!fSDManager)
{
fSDManager = new G4SDManager;
}
return fSDManager;
}
G4SDManager* G4SDManager::GetSDMpointerIfExist()
{ return fSDManager; }
G4SDManager::G4SDManager():verboseLevel(0)
{
G4String topName = "/";
treeTop = new G4SDStructure(topName);
theMessenger = new G4SDmessenger(this);
HCtable = new G4HCtable;
}
G4SDManager::~G4SDManager()
{
delete theMessenger;
}
void G4SDManager::AddNewDetector(G4VSensitiveDetector*aSD)
{
G4String pathName = aSD->GetPathName();
G4int numberOfCollections = aSD->GetNumberOfCollections();
if( pathName(0) != '/' ) pathName.prepend("/");
if( pathName(pathName.length()-1) != '/' ) pathName += "/";
treeTop->AddNewDetector(aSD,pathName);
for(int i=0;i<numberOfCollections;i++)
{
G4String SDname = aSD->GetName();
G4String DCname = aSD->GetCollectionName(i);
HCtable->Registor(SDname,DCname);
}
if( verboseLevel > 0 )
{
G4cout << "New sensitive detector <" << aSD->GetName()
<< "> is registored at " << pathName << endl;
}
}
G4HCofThisEvent* G4SDManager::PrepareNewEvent()
{
G4HCofThisEvent* HCE = new G4HCofThisEvent(HCtable->entries());
treeTop->Initialize(HCE);
return HCE;
}
void G4SDManager::TerminateCurrentEvent(G4HCofThisEvent* HCE)
{
treeTop->Terminate(HCE);
}
void G4SDManager::Activate(G4String dName, G4bool activeFlag)
{
G4String pathName = dName;
if( pathName(0) != '/' ) pathName.prepend("/");
treeTop->Activate(pathName,activeFlag);
}
G4VSensitiveDetector* G4SDManager::FindSensitiveDetector(G4String dName)
{
G4String pathName = dName;
if( pathName(0) != '/' ) pathName.prepend("/");
return treeTop->FindSensitiveDetector(pathName);
}
G4int G4SDManager::GetCollectionID(G4String colName)
{
G4int id = HCtable->GetCollectionID(colName);
if(id==-1)
{ G4cout << "<" << colName << "> is not found." << endl; }
else if(id==-2)
{ G4cout << "<" << colName << "> is ambiguous." << endl; }
return id;
}
G4int G4SDManager::GetCollectionID(G4VHitsCollection* aHC)
{
G4String HCname = aHC->GetSDname();
HCname += "/";
HCname += aHC->GetName();
return GetCollectionID(HCname);
}
@@ -0,0 +1,217 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4SDStructure.cc,v 2.2 1998/07/13 16:50:05 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4SDStructure
#include "G4SDStructure.hh"
#include "G4ios.hh"
G4SDStructure::G4SDStructure(G4String aPath):verboseLevel(0)
{
pathName = aPath;
dirName = aPath;
int i = dirName.length();
if( i > 1 )
{
dirName.remove(i-1);
int isl = dirName.last('/');
dirName.remove(0,isl+1);
dirName += "/";
}
}
G4SDStructure::~G4SDStructure()
{
}
int G4SDStructure::operator==(const G4SDStructure &right) const
{
return false;
}
void G4SDStructure::AddNewDetector(G4VSensitiveDetector*aSD,
G4String treeStructure)
{
G4String remainingPath = treeStructure;
remainingPath.remove(0,pathName.length());
if( ! remainingPath.isNull() )
{ // The detector should be kept in subdirectory.
// First, check if the subdirectoy exists.
G4String subD = ExtractDirName( remainingPath );
G4SDStructure* tgtSDS = FindSubDirectory(subD);
if( tgtSDS == NULL )
{ // Subdirectory not found. Create a new directory.
subD.prepend(pathName);
tgtSDS = new G4SDStructure(subD);
structure.insert( tgtSDS );
}
tgtSDS->AddNewDetector(aSD,treeStructure);
}
else
{ // The sensitive detector should be kept in this directory.
G4VSensitiveDetector* tgtSD = GetSD( aSD->GetName() );
if( tgtSD != NULL )
{
G4cout << aSD->GetName() << " had already stored in "
<< pathName << endl;
}
else
{
detector.insert( aSD );
}
}
}
G4SDStructure* G4SDStructure::FindSubDirectory(G4String subD)
{
for( int i=0; i<structure.entries(); i++ )
{
if( subD == structure(i)->dirName ) return structure(i);
}
return NULL;
}
G4VSensitiveDetector* G4SDStructure::GetSD(G4String aSDName)
{
for( int i=0; i<detector.entries(); i++ )
{
G4VSensitiveDetector* tgtSD = detector(i);
if( aSDName == tgtSD->GetName() ) return tgtSD;
}
return NULL;
}
G4String G4SDStructure::ExtractDirName(G4String aName)
{
G4String subD = aName;
int i = aName.first('/');
if( i != RW_NPOS ) subD.remove(i+1);
return subD;
}
void G4SDStructure::Activate(G4String aName, G4bool sensitiveFlag)
{
G4String aPath = aName;
aPath.remove(0,pathName.length());
if( aPath.first('/') != RW_NPOS )
{ // Command is ordered for a subdirectory.
G4String subD = ExtractDirName(aPath);
G4SDStructure* tgtSDS = FindSubDirectory(subD);
if( tgtSDS == NULL )
{ // The subdirectory is not found
G4cout << subD << " is not found in " << pathName << endl;
}
else
{
tgtSDS->Activate(aName,sensitiveFlag);
}
}
else if( aPath.isNull() )
{ // Command is ordered for all detectors in this directory.
for( int i=0; i<detector.entries(); i++)
{
detector(i)->Activate(sensitiveFlag);
}
for( int j=0;j<structure.entries(); j++)
{
structure(j)->Activate(G4String("/"),sensitiveFlag);
}
}
else
{ // Command is ordered to a particular detector.
G4VSensitiveDetector* tgtSD = GetSD(aPath);
if( tgtSD == NULL )
{ // The detector is not found.
G4cout << aPath << " is not found in " << pathName << endl;
}
else
{
tgtSD->Activate(sensitiveFlag);
}
}
}
G4VSensitiveDetector* G4SDStructure::FindSensitiveDetector(G4String aName)
{
G4String aPath = aName;
aPath.remove(0,pathName.length());
if( aPath.first('/') != RW_NPOS )
{ // SD exists in sub-directory
G4String subD = ExtractDirName(aPath);
G4SDStructure* tgtSDS = FindSubDirectory(subD);
if( tgtSDS == NULL )
{ // The subdirectory is not found
G4cout << subD << " is not found in " << pathName << endl;
return NULL;
}
else
{
return tgtSDS->FindSensitiveDetector(aName);
}
}
else
{ // SD must exist in this directory
G4VSensitiveDetector* tgtSD = GetSD(aPath);
if( tgtSD == NULL )
{ // The detector is not found.
G4cout << aPath << " is not found in " << pathName << endl;
}
return tgtSD;
}
}
void G4SDStructure::Initialize(G4HCofThisEvent*HCE)
{
int i;
// Broadcast to subdirectories.
for( i=0; i<structure.entries(); i++ )
{
structure(i)->Initialize(HCE);
}
// Initialize all detectors in this directory.
for( i=0; i<detector.entries(); i++ )
{
if(detector(i)->isActive()) detector(i)->Initialize(HCE);
}
}
void G4SDStructure::Terminate(G4HCofThisEvent*HCE)
{
int i;
// Broadcast to subdirectories.
for( i=0; i<structure.entries(); i++ )
{
structure(i)->Terminate(HCE);
}
// Initialize all detectors in this directory.
for( i=0; i<detector.entries(); i++ )
{
if(detector(i)->isActive()) detector(i)->EndOfEvent(HCE);
}
}
void G4SDStructure::ListTree()
{
G4cout << pathName << endl;
for(int i=0; i<detector.entries(); i++)
{
G4VSensitiveDetector* sd = detector(i);
G4cout << pathName << sd->GetName();
if( sd->isActive() )
{ G4cout << " *** Active "; }
else
{ G4cout << " XXX Inactive "; }
G4cout << endl;
}
for(int j=0; j<structure.entries(); j++)
{ structure(j)->ListTree(); }
}
@@ -0,0 +1,65 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4SDmessenger.cc,v 2.2 1998/07/14 17:24:16 asaim Exp $
// GEANT4 tag $Name: geant4-00 $
//
// ---------------------------------------------------------------------
#include "G4SDmessenger.hh"
#include "G4SDManager.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithAnInteger.hh"
G4SDmessenger::G4SDmessenger(G4SDManager* SDManager):fSDMan(SDManager)
{
hitsDir = new G4UIdirectory("/hits/");
hitsDir->SetGuidance("Sensitive detectors and Hits");
listCmd = new G4UIcmdWithoutParameter("/hits/list",this);
listCmd->SetGuidance("List sensitive detector tree.");
activeCmd = new G4UIcmdWithAString("/hits/activate",this);
activeCmd->SetGuidance("Activate sensitive detector(s).");
activeCmd->SetParameterName("detector",true);
activeCmd->SetDefaultValue("/");
inactiveCmd = new G4UIcmdWithAString("/hits/inactivate",this);
inactiveCmd->SetGuidance("Inactivate sensitive detector(s).");
inactiveCmd->SetParameterName("detector",true);
inactiveCmd->SetDefaultValue("/");
verboseCmd = new G4UIcmdWithAnInteger("/hits/verbose",this);
verboseCmd->SetGuidance("Set the Verbose level.");
verboseCmd->SetParameterName("level",false);
}
G4SDmessenger::~G4SDmessenger()
{
delete listCmd;
delete activeCmd;
delete inactiveCmd;
delete verboseCmd;
delete hitsDir;
}
void G4SDmessenger::SetNewValue(G4UIcommand * command,G4String newVal)
{
if( command==listCmd )
{ fSDMan->ListTree(); }
if( command==activeCmd )
{ fSDMan->Activate(newVal,1); }
if( command==inactiveCmd )
{ fSDMan->Activate(newVal,0); }
if( command==verboseCmd )
{ fSDMan->SetVerboseLevel(verboseCmd->GetNewIntValue(newVal)); }
return;
}
@@ -0,0 +1,81 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4SensitiveVolumeList.cc,v 2.1 1998/07/12 02:53:31 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
// --------------------------------------------------------------
// GEANT 4 class implementation file
//
// For information related to this code contact:
// CERN, CN Division, ASD Group
// History: first implementation June'96, based on Hits+Digi
// domain model of April 1996, S.Piperov
//
// ---------------- G4SensitiveVolumeList -----------------
#include "G4SensitiveVolumeList.hh"
//Constructors
G4SensitiveVolumeList::G4SensitiveVolumeList()
{
}
G4SensitiveVolumeList::G4SensitiveVolumeList(const G4SensitiveVolumeList &right)
{
thePhysicalVolumeList = right.thePhysicalVolumeList;
theLogicalVolumeList = right.theLogicalVolumeList;
}
//Destructor
G4SensitiveVolumeList::~G4SensitiveVolumeList()
{
}
//Assignment Operation
const G4SensitiveVolumeList & G4SensitiveVolumeList::operator=(const G4SensitiveVolumeList &right)
{
thePhysicalVolumeList = right.thePhysicalVolumeList;
theLogicalVolumeList = right.theLogicalVolumeList;
return *this;
}
//Equality Operations
G4int G4SensitiveVolumeList::operator==(const G4SensitiveVolumeList &right) const
{
return (this == (G4SensitiveVolumeList *) &right);
}
G4int G4SensitiveVolumeList::operator!=(const G4SensitiveVolumeList &right) const
{
return (this != (G4SensitiveVolumeList *) &right);
}
//Other Operations
G4bool G4SensitiveVolumeList::CheckPV(const G4VPhysicalVolume * pvp) const
{
if (thePhysicalVolumeList.entries()==0) return false;
for(int i=0;i<thePhysicalVolumeList.entries();i++)
{ if(thePhysicalVolumeList(i)==pvp) return true; }
return false;
}
G4bool G4SensitiveVolumeList::CheckLV(const G4LogicalVolume * lvp) const
{
if (theLogicalVolumeList.entries()==0) return false;
for(int i=0;i<theLogicalVolumeList.entries();i++)
{ if(theLogicalVolumeList(i)==lvp) return true; }
return false;
}
@@ -0,0 +1,136 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4VReadOutGeometry.cc,v 2.1 1998/07/12 02:53:31 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
#include "G4VReadOutGeometry.hh"
#include "G4Navigator.hh"
G4VReadOutGeometry::G4VReadOutGeometry()
:ROworld(NULL),touchableHistory(NULL),
fincludeList(NULL),fexcludeList(NULL)
{
name = "unknown";
ROnavigator = new G4Navigator();
}
G4VReadOutGeometry::G4VReadOutGeometry(const G4VReadOutGeometry &right)
{
fincludeList = right.fincludeList;
fexcludeList = right.fexcludeList;
name = right.name;
ROworld = right.ROworld;
touchableHistory = NULL;
// COPY CONSTRUCTOR NOT STRAIGHT FORWARD: need to copy the touchabelHistory
// VALUE, same foe navigator and same for the World+Geom hierachy ??
}
G4VReadOutGeometry::G4VReadOutGeometry(G4String n)
:name(n),ROworld(NULL),touchableHistory(NULL),
fincludeList(NULL),fexcludeList(NULL)
{
ROnavigator = new G4Navigator();
}
G4VReadOutGeometry::~G4VReadOutGeometry()
{
//if(ROworld) delete ROworld; //should we do ? will it delete the goem tree also ?
if(fincludeList) delete fincludeList;
if(fexcludeList) delete fexcludeList;
if(touchableHistory) delete touchableHistory;
if(ROnavigator) delete ROnavigator;
}
const G4VReadOutGeometry & G4VReadOutGeometry::operator=(const G4VReadOutGeometry &right)
{
fincludeList = right.fincludeList;
fexcludeList = right.fexcludeList;
name = right.name;
ROworld = right.ROworld;
touchableHistory = NULL;
return *this;
}
G4int G4VReadOutGeometry::operator==(const G4VReadOutGeometry &right) const
{ return (this == (G4VReadOutGeometry *) &right); }
G4int G4VReadOutGeometry::operator!=(const G4VReadOutGeometry &right) const
{ return (this != (G4VReadOutGeometry *) &right); }
void G4VReadOutGeometry::BuildROGeometry()
{
ROworld = Build();
ROnavigator->SetWorldVolume(ROworld);
}
G4bool G4VReadOutGeometry::CheckROVolume(G4Step*currentStep,G4TouchableHistory*& ROhist)
{
ROhist = NULL;
G4bool incFlg = true;
G4VPhysicalVolume* PV = currentStep->GetPreStepPoint()->GetPhysicalVolume();
if((fexcludeList)&&(fexcludeList->CheckPV(PV)))
{ incFlg = false; }
else if ((fincludeList)&&(fincludeList->CheckPV(PV)))
{ incFlg = true; }
else if((fexcludeList)&&(fexcludeList->CheckLV(PV->GetLogicalVolume())))
{ incFlg = false; }
else if((fincludeList)&&(fincludeList->CheckLV(PV->GetLogicalVolume())))
{ incFlg = true; }
if(!incFlg) return false;
if(ROworld)
{ incFlg = FindROTouchable(currentStep); }
if(incFlg)
{ ROhist = touchableHistory; }
return incFlg;
}
G4bool G4VReadOutGeometry::FindROTouchable(G4Step*currentStep)
{
// Update G4TouchableHistory object (touchableHistory)
// using the parallel readout world (ROworld)
// Return false in case the current Step is outside of the
// sensitive volume of the readout world.
// At first invokation, creates the touchable history. Note
// that default value (false) of Locate method is used.
if(!touchableHistory)
{
touchableHistory = new G4TouchableHistory();
ROnavigator->LocateGlobalPointAndUpdateTouchable(
currentStep->GetPreStepPoint()->GetPosition(),
touchableHistory);
}
else
{
ROnavigator->LocateGlobalPointAndUpdateTouchable(
currentStep->GetPreStepPoint()->GetPosition(),
touchableHistory,
true);
}
// Can the above be improved by the use of an isotropic safety
// in order to avoid LocateGlobalPointAndUpdateTouchable
// at each Step ?
// Should require that an RO geometry is notified at the
// starting of a track to avoid possible confusion looking
// at the safety value only.
// checks if volume is sensitive:
G4VPhysicalVolume* currentVolume;
// checks first if a physical volume exists here:
if ( currentVolume = touchableHistory->GetVolume() )
{
return currentVolume->GetLogicalVolume()->
GetSensitiveDetector() != NULL;
}
// no sensitive volume found: returns false
return false;
}
@@ -0,0 +1,85 @@
// This code implementation is the intellectual property of
// the RD44 GEANT4 collaboration.
//
// By copying, distributing or modifying the Program (or any work
// based on the Program) you indicate your acceptance of this statement,
// and all its terms.
//
// $Id: G4VSensitiveDetector.cc,v 2.1 1998/07/12 02:53:32 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VSensitiveDetector
#include "G4VSensitiveDetector.hh"
#include "G4SDManager.hh"
G4VSensitiveDetector::G4VSensitiveDetector(G4String name)
:verboseLevel(0),active(true),ROgeometry(NULL)
{
size_t sLast = name.last('/');
if(sLast==RW_NPOS)
{ // detector name only
SensitiveDetectorName = name;
thePathName = "/";
}
else
{ // name conatin the directory path
SensitiveDetectorName = name;
SensitiveDetectorName.remove(0,sLast+1);
thePathName = name;
thePathName.remove(sLast+1,name.length()-sLast);
if(thePathName(0)!='/') thePathName.prepend("/");
}
fullPathName = thePathName + SensitiveDetectorName;
}
G4VSensitiveDetector::G4VSensitiveDetector(const G4VSensitiveDetector &right)
{
}
G4VSensitiveDetector::~G4VSensitiveDetector()
{
}
const G4VSensitiveDetector & G4VSensitiveDetector::operator=(const G4VSensitiveDetector &right)
{
return *this;
}
int G4VSensitiveDetector::operator==(const G4VSensitiveDetector &right) const
{
return false;
}
int G4VSensitiveDetector::operator!=(const G4VSensitiveDetector &right) const
{
return true;
}
G4int G4VSensitiveDetector::GetCollectionID(G4int i)
{
return G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[i]);
}
//----- following methoods are abstract methods to be
//----- implemented in the concrete classes
void G4VSensitiveDetector::Initialize(G4HCofThisEvent*HCE)
{
}
void G4VSensitiveDetector::EndOfEvent(G4HCofThisEvent*HCE)
{
}
void G4VSensitiveDetector::clear()
{
}
void G4VSensitiveDetector::DrawAll()
{
}
void G4VSensitiveDetector::PrintAll()
{
}