Import Geant4 10.0.0 source tree
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: B2ActionInitialization.cc 68058 2013-03-13 14:47:43Z gcosmo $
|
||||
//
|
||||
/// \file B2ActionInitialization.cc
|
||||
/// \brief Implementation of the B2ActionInitialization class
|
||||
|
||||
#include "B2ActionInitialization.hh"
|
||||
#include "B2PrimaryGeneratorAction.hh"
|
||||
#include "B2RunAction.hh"
|
||||
#include "B2EventAction.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2ActionInitialization::B2ActionInitialization()
|
||||
: G4VUserActionInitialization()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2ActionInitialization::~B2ActionInitialization()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2ActionInitialization::BuildForMaster() const
|
||||
{
|
||||
SetUserAction(new B2RunAction);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2ActionInitialization::Build() const
|
||||
{
|
||||
SetUserAction(new B2PrimaryGeneratorAction);
|
||||
SetUserAction(new B2RunAction);
|
||||
SetUserAction(new B2EventAction);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: B2EventAction.cc 69652 2013-05-10 09:05:11Z ihrivnac $
|
||||
//
|
||||
/// \file B2EventAction.cc
|
||||
/// \brief Implementation of the B2EventAction class
|
||||
|
||||
#include "B2EventAction.hh"
|
||||
|
||||
#include "G4Event.hh"
|
||||
#include "G4EventManager.hh"
|
||||
#include "G4TrajectoryContainer.hh"
|
||||
#include "G4Trajectory.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2EventAction::B2EventAction()
|
||||
: G4UserEventAction()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2EventAction::~B2EventAction()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2EventAction::BeginOfEventAction(const G4Event*)
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2EventAction::EndOfEventAction(const G4Event* event)
|
||||
{
|
||||
// get number of stored trajectories
|
||||
|
||||
G4TrajectoryContainer* trajectoryContainer = event->GetTrajectoryContainer();
|
||||
G4int n_trajectories = 0;
|
||||
if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
|
||||
|
||||
// periodic printing
|
||||
|
||||
G4int eventID = event->GetEventID();
|
||||
if ( eventID < 100 || eventID % 100 == 0) {
|
||||
G4cout << ">>> Event: " << eventID << G4endl;
|
||||
if ( trajectoryContainer ) {
|
||||
G4cout << " " << n_trajectories
|
||||
<< " trajectories stored in this event." << G4endl;
|
||||
}
|
||||
G4VHitsCollection* hc = event->GetHCofThisEvent()->GetHC(0);
|
||||
G4cout << " "
|
||||
<< hc->GetSize() << " hits stored in this event" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: B2PrimaryGeneratorAction.cc 66536 2012-12-19 14:32:36Z ihrivnac $
|
||||
//
|
||||
/// \file B2PrimaryGeneratorAction.cc
|
||||
/// \brief Implementation of the B2PrimaryGeneratorAction class
|
||||
|
||||
#include "B2PrimaryGeneratorAction.hh"
|
||||
|
||||
#include "G4LogicalVolumeStore.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4Box.hh"
|
||||
#include "G4Event.hh"
|
||||
#include "G4ParticleGun.hh"
|
||||
#include "G4ParticleTable.hh"
|
||||
#include "G4ParticleDefinition.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
#include "Randomize.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2PrimaryGeneratorAction::B2PrimaryGeneratorAction()
|
||||
: G4VUserPrimaryGeneratorAction()
|
||||
{
|
||||
G4int nofParticles = 1;
|
||||
fParticleGun = new G4ParticleGun(nofParticles);
|
||||
|
||||
// default particle kinematic
|
||||
|
||||
G4ParticleDefinition* particleDefinition
|
||||
= G4ParticleTable::GetParticleTable()->FindParticle("proton");
|
||||
|
||||
fParticleGun->SetParticleDefinition(particleDefinition);
|
||||
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
|
||||
fParticleGun->SetParticleEnergy(3.0*GeV);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2PrimaryGeneratorAction::~B2PrimaryGeneratorAction()
|
||||
{
|
||||
delete fParticleGun;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
|
||||
{
|
||||
// This function is called at the begining of event
|
||||
|
||||
// In order to avoid dependence of PrimaryGeneratorAction
|
||||
// on DetectorConstruction class we get world volume
|
||||
// from G4LogicalVolumeStore.
|
||||
|
||||
G4double worldZHalfLength = 0;
|
||||
G4LogicalVolume* worldLV
|
||||
= G4LogicalVolumeStore::GetInstance()->GetVolume("World");
|
||||
G4Box* worldBox = NULL;
|
||||
if ( worldLV ) worldBox = dynamic_cast<G4Box*>(worldLV->GetSolid());
|
||||
if ( worldBox ) worldZHalfLength = worldBox->GetZHalfLength();
|
||||
else {
|
||||
G4cerr << "World volume of box not found." << G4endl;
|
||||
G4cerr << "Perhaps you have changed geometry." << G4endl;
|
||||
G4cerr << "The gun will be place in the center." << G4endl;
|
||||
}
|
||||
|
||||
fParticleGun->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength));
|
||||
|
||||
fParticleGun->GeneratePrimaryVertex(anEvent);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: B2RunAction.cc 66536 2012-12-19 14:32:36Z ihrivnac $
|
||||
//
|
||||
/// \file B2RunAction.cc
|
||||
/// \brief Implementation of the B2RunAction class
|
||||
|
||||
#include "B2RunAction.hh"
|
||||
|
||||
#include "G4Run.hh"
|
||||
#include "G4RunManager.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2RunAction::B2RunAction()
|
||||
: G4UserRunAction()
|
||||
{
|
||||
// set printing event number per each 100 events
|
||||
G4RunManager::GetRunManager()->SetPrintProgress(1000);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2RunAction::~B2RunAction()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2RunAction::BeginOfRunAction(const G4Run*)
|
||||
{
|
||||
//inform the runManager to save random number seed
|
||||
G4RunManager::GetRunManager()->SetRandomNumberStore(false);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2RunAction::EndOfRunAction(const G4Run* )
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: B2TrackerHit.cc 69505 2013-05-07 01:57:27Z asaim $
|
||||
//
|
||||
/// \file B2TrackerHit.cc
|
||||
/// \brief Implementation of the B2TrackerHit class
|
||||
|
||||
#include "B2TrackerHit.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4VVisManager.hh"
|
||||
#include "G4Circle.hh"
|
||||
#include "G4Colour.hh"
|
||||
#include "G4VisAttributes.hh"
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
G4ThreadLocal G4Allocator<B2TrackerHit>* B2TrackerHitAllocator=0;
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2TrackerHit::B2TrackerHit()
|
||||
: G4VHit(),
|
||||
fTrackID(-1),
|
||||
fChamberNb(-1),
|
||||
fEdep(0.),
|
||||
fPos(G4ThreeVector())
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2TrackerHit::~B2TrackerHit() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2TrackerHit::B2TrackerHit(const B2TrackerHit& right)
|
||||
: G4VHit()
|
||||
{
|
||||
fTrackID = right.fTrackID;
|
||||
fChamberNb = right.fChamberNb;
|
||||
fEdep = right.fEdep;
|
||||
fPos = right.fPos;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
const B2TrackerHit& B2TrackerHit::operator=(const B2TrackerHit& right)
|
||||
{
|
||||
fTrackID = right.fTrackID;
|
||||
fChamberNb = right.fChamberNb;
|
||||
fEdep = right.fEdep;
|
||||
fPos = right.fPos;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4int B2TrackerHit::operator==(const B2TrackerHit& right) const
|
||||
{
|
||||
return ( this == &right ) ? 1 : 0;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2TrackerHit::Draw()
|
||||
{
|
||||
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
||||
if(pVVisManager)
|
||||
{
|
||||
G4Circle circle(fPos);
|
||||
circle.SetScreenSize(4.);
|
||||
circle.SetFillStyle(G4Circle::filled);
|
||||
G4Colour colour(1.,0.,0.);
|
||||
G4VisAttributes attribs(colour);
|
||||
circle.SetVisAttributes(attribs);
|
||||
pVVisManager->Draw(circle);
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2TrackerHit::Print()
|
||||
{
|
||||
G4cout
|
||||
<< " trackID: " << fTrackID << " chamberNb: " << fChamberNb
|
||||
<< "Edep: "
|
||||
<< std::setw(7) << G4BestUnit(fEdep,"Energy")
|
||||
<< " Position: "
|
||||
<< std::setw(7) << G4BestUnit( fPos,"Length")
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: B2TrackerSD.cc 66536 2012-12-19 14:32:36Z ihrivnac $
|
||||
//
|
||||
/// \file B2TrackerSD.cc
|
||||
/// \brief Implementation of the B2TrackerSD class
|
||||
|
||||
#include "B2TrackerSD.hh"
|
||||
#include "G4HCofThisEvent.hh"
|
||||
#include "G4Step.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
#include "G4SDManager.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2TrackerSD::B2TrackerSD(const G4String& name,
|
||||
const G4String& hitsCollectionName)
|
||||
: G4VSensitiveDetector(name),
|
||||
fHitsCollection(NULL)
|
||||
{
|
||||
collectionName.insert(hitsCollectionName);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2TrackerSD::~B2TrackerSD()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2TrackerSD::Initialize(G4HCofThisEvent* hce)
|
||||
{
|
||||
// Create hits collection
|
||||
|
||||
fHitsCollection
|
||||
= new B2TrackerHitsCollection(SensitiveDetectorName, collectionName[0]);
|
||||
|
||||
// Add this collection in hce
|
||||
|
||||
G4int hcID
|
||||
= G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
|
||||
hce->AddHitsCollection( hcID, fHitsCollection );
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4bool B2TrackerSD::ProcessHits(G4Step* aStep,
|
||||
G4TouchableHistory*)
|
||||
{
|
||||
// energy deposit
|
||||
G4double edep = aStep->GetTotalEnergyDeposit();
|
||||
|
||||
if (edep==0.) return false;
|
||||
|
||||
B2TrackerHit* newHit = new B2TrackerHit();
|
||||
|
||||
newHit->SetTrackID (aStep->GetTrack()->GetTrackID());
|
||||
newHit->SetChamberNb(aStep->GetPreStepPoint()->GetTouchableHandle()
|
||||
->GetCopyNumber());
|
||||
newHit->SetEdep(edep);
|
||||
newHit->SetPos (aStep->GetPostStepPoint()->GetPosition());
|
||||
|
||||
fHitsCollection->insert( newHit );
|
||||
|
||||
//newHit->Print();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2TrackerSD::EndOfEvent(G4HCofThisEvent*)
|
||||
{
|
||||
if ( verboseLevel>1 ) {
|
||||
G4int nofHits = fHitsCollection->entries();
|
||||
G4cout << "\n-------->Hits Collection: in this event they are " << nofHits
|
||||
<< " hits in the tracker chambers: " << G4endl;
|
||||
for ( G4int i=0; i<nofHits; i++ ) (*fHitsCollection)[i]->Print();
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
/// \file B2bChamberParameterisation.cc
|
||||
/// \brief Implementation of the B2bChamberParameterisation class
|
||||
|
||||
#include "B2bChamberParameterisation.hh"
|
||||
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
#include "G4Tubs.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2bChamberParameterisation::B2bChamberParameterisation(
|
||||
G4int noChambers,
|
||||
G4double startZ, // Z of center of first
|
||||
G4double spacingZ, // Z spacing of centers
|
||||
G4double widthChamber,
|
||||
G4double lengthInitial,
|
||||
G4double lengthFinal )
|
||||
: G4VPVParameterisation()
|
||||
{
|
||||
fNoChambers = noChambers;
|
||||
fStartZ = startZ;
|
||||
fHalfWidth = 0.5*widthChamber;
|
||||
fSpacing = spacingZ;
|
||||
fRmaxFirst = 0.5 * lengthInitial;
|
||||
if( noChambers > 0 ){
|
||||
fRmaxIncr = 0.5 * (lengthFinal-lengthInitial)/(noChambers-1);
|
||||
if (spacingZ < widthChamber) {
|
||||
G4Exception("B2bChamberParameterisation::B2bChamberParameterisation()",
|
||||
"InvalidSetup", FatalException,
|
||||
"Width>Spacing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2bChamberParameterisation::~B2bChamberParameterisation()
|
||||
{ }
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2bChamberParameterisation::ComputeTransformation
|
||||
(const G4int copyNo, G4VPhysicalVolume* physVol) const
|
||||
{
|
||||
// Note: copyNo will start with zero!
|
||||
G4double Zposition = fStartZ + copyNo * fSpacing;
|
||||
G4ThreeVector origin(0,0,Zposition);
|
||||
physVol->SetTranslation(origin);
|
||||
physVol->SetRotation(0);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2bChamberParameterisation::ComputeDimensions
|
||||
(G4Tubs& trackerChamber, const G4int copyNo, const G4VPhysicalVolume*) const
|
||||
{
|
||||
// Note: copyNo will start with zero!
|
||||
G4double rmax = fRmaxFirst + copyNo * fRmaxIncr;
|
||||
trackerChamber.SetInnerRadius(0);
|
||||
trackerChamber.SetOuterRadius(rmax);
|
||||
trackerChamber.SetZHalfLength(fHalfWidth);
|
||||
trackerChamber.SetStartPhiAngle(0.*deg);
|
||||
trackerChamber.SetDeltaPhiAngle(360.*deg);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,346 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
/// \file B2bDetectorConstruction.cc
|
||||
/// \brief Implementation of the B2bDetectorConstruction class
|
||||
|
||||
#include "B2bDetectorConstruction.hh"
|
||||
#include "B2bDetectorMessenger.hh"
|
||||
#include "B2bChamberParameterisation.hh"
|
||||
#include "B2TrackerSD.hh"
|
||||
|
||||
#include "G4Material.hh"
|
||||
#include "G4NistManager.hh"
|
||||
|
||||
#include "G4Box.hh"
|
||||
#include "G4Tubs.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4PVPlacement.hh"
|
||||
#include "G4PVParameterised.hh"
|
||||
#include "G4GlobalMagFieldMessenger.hh"
|
||||
|
||||
#include "G4GeometryTolerance.hh"
|
||||
#include "G4GeometryManager.hh"
|
||||
|
||||
#include "G4UserLimits.hh"
|
||||
|
||||
#include "G4VisAttributes.hh"
|
||||
#include "G4Colour.hh"
|
||||
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
//#include "G4ios.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4ThreadLocal
|
||||
G4GlobalMagFieldMessenger* B2bDetectorConstruction::fMagFieldMessenger = 0;
|
||||
|
||||
B2bDetectorConstruction::B2bDetectorConstruction()
|
||||
:G4VUserDetectorConstruction(),
|
||||
fLogicTarget(NULL), fLogicChamber(NULL),
|
||||
fTargetMaterial(NULL), fChamberMaterial(NULL),
|
||||
fStepLimit(NULL),
|
||||
fCheckOverlaps(true)
|
||||
{
|
||||
fMessenger = new B2bDetectorMessenger(this);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2bDetectorConstruction::~B2bDetectorConstruction()
|
||||
{
|
||||
delete fStepLimit;
|
||||
delete fMessenger;
|
||||
delete fMagFieldMessenger;
|
||||
fMagFieldMessenger = 0;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4VPhysicalVolume* B2bDetectorConstruction::Construct()
|
||||
{
|
||||
// Define materials
|
||||
DefineMaterials();
|
||||
|
||||
// Define volumes
|
||||
return DefineVolumes();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2bDetectorConstruction::DefineMaterials()
|
||||
{
|
||||
// Material definition
|
||||
|
||||
G4NistManager* nistManager = G4NistManager::Instance();
|
||||
|
||||
// Air defined using NIST Manager
|
||||
nistManager->FindOrBuildMaterial("G4_AIR");
|
||||
|
||||
// Lead defined using NIST Manager
|
||||
fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb");
|
||||
|
||||
// Xenon gas defined using NIST Manager
|
||||
fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe");
|
||||
|
||||
// Print materials
|
||||
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4VPhysicalVolume* B2bDetectorConstruction::DefineVolumes()
|
||||
{
|
||||
G4Material* air = G4Material::GetMaterial("G4_AIR");
|
||||
|
||||
// Sizes of the principal geometrical components (solids)
|
||||
|
||||
G4int NbOfChambers = 5;
|
||||
G4double chamberSpacing = 80*cm; // from chamber center to center!
|
||||
|
||||
G4double chamberWidth = 20.0*cm; // width of the chambers
|
||||
G4double targetLength = 5.0*cm; // full length of Target
|
||||
|
||||
G4double trackerLength = (NbOfChambers+1)*chamberSpacing;
|
||||
|
||||
G4double worldLength = 1.2 * (2*targetLength + trackerLength);
|
||||
|
||||
G4double targetRadius = 0.5*targetLength; // Radius of Target
|
||||
targetLength = 0.5*targetLength; // Half length of the Target
|
||||
G4double trackerSize = 0.5*trackerLength; // Half length of the Tracker
|
||||
|
||||
// Definitions of Solids, Logical Volumes, Physical Volumes
|
||||
|
||||
// World
|
||||
|
||||
G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength);
|
||||
|
||||
G4cout << "Computed tolerance = "
|
||||
<< G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/mm
|
||||
<< " mm" << G4endl;
|
||||
|
||||
G4Box* worldS
|
||||
= new G4Box("world", //its name
|
||||
worldLength/2,worldLength/2,worldLength/2); //its size
|
||||
G4LogicalVolume* worldLV
|
||||
= new G4LogicalVolume(
|
||||
worldS, //its solid
|
||||
air, //its material
|
||||
"World"); //its name
|
||||
|
||||
// Must place the World Physical volume unrotated at (0,0,0).
|
||||
//
|
||||
G4VPhysicalVolume* worldPV
|
||||
= new G4PVPlacement(
|
||||
0, // no rotation
|
||||
G4ThreeVector(), // at (0,0,0)
|
||||
worldLV, // its logical volume
|
||||
"World", // its name
|
||||
0, // its mother volume
|
||||
false, // no boolean operations
|
||||
0, // copy number
|
||||
fCheckOverlaps); // checking overlaps
|
||||
|
||||
// Target
|
||||
|
||||
G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetLength+trackerSize));
|
||||
|
||||
G4Tubs* targetS
|
||||
= new G4Tubs("target",0.,targetRadius,targetLength,0.*deg,360.*deg);
|
||||
fLogicTarget
|
||||
= new G4LogicalVolume(targetS, fTargetMaterial,"Target",0,0,0);
|
||||
new G4PVPlacement(0, // no rotation
|
||||
positionTarget, // at (x,y,z)
|
||||
fLogicTarget, // its logical volume
|
||||
"Target", // its name
|
||||
worldLV, // its mother volume
|
||||
false, // no boolean operations
|
||||
0, // copy number
|
||||
fCheckOverlaps); // checking overlaps
|
||||
|
||||
G4cout << "Target is " << 2*targetLength/cm << " cm of "
|
||||
<< fTargetMaterial->GetName() << G4endl;
|
||||
|
||||
// Tracker
|
||||
|
||||
G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
|
||||
|
||||
G4Tubs* trackerS
|
||||
= new G4Tubs("tracker",0,trackerSize,trackerSize, 0.*deg, 360.*deg);
|
||||
G4LogicalVolume* trackerLV
|
||||
= new G4LogicalVolume(trackerS, air, "Tracker",0,0,0);
|
||||
new G4PVPlacement(0, // no rotation
|
||||
positionTracker, // at (x,y,z)
|
||||
trackerLV, // its logical volume
|
||||
"Tracker", // its name
|
||||
worldLV, // its mother volume
|
||||
false, // no boolean operations
|
||||
0, // copy number
|
||||
fCheckOverlaps); // checking overlaps
|
||||
|
||||
// Tracker segments
|
||||
|
||||
// An example of Parameterised volumes
|
||||
// Dummy values for G4Tubs -- modified by parameterised volume
|
||||
|
||||
G4Tubs* chamberS
|
||||
= new G4Tubs("tracker",0, 100*cm, 100*cm, 0.*deg, 360.*deg);
|
||||
fLogicChamber
|
||||
= new G4LogicalVolume(chamberS,fChamberMaterial,"Chamber",0,0,0);
|
||||
|
||||
G4double firstPosition = -trackerSize + chamberSpacing;
|
||||
G4double firstLength = trackerLength/10;
|
||||
G4double lastLength = trackerLength;
|
||||
|
||||
G4VPVParameterisation* chamberParam =
|
||||
new B2bChamberParameterisation(
|
||||
NbOfChambers, // NoChambers
|
||||
firstPosition, // Z of center of first
|
||||
chamberSpacing, // Z spacing of centers
|
||||
chamberWidth, // chamber width
|
||||
firstLength, // initial length
|
||||
lastLength); // final length
|
||||
|
||||
// dummy value : kZAxis -- modified by parameterised volume
|
||||
|
||||
new G4PVParameterised("Chamber", // their name
|
||||
fLogicChamber, // their logical volume
|
||||
trackerLV, // Mother logical volume
|
||||
kZAxis, // Are placed along this axis
|
||||
NbOfChambers, // Number of chambers
|
||||
chamberParam, // The parametrisation
|
||||
fCheckOverlaps); // checking overlaps
|
||||
|
||||
G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
|
||||
<< "\nThe chambers are " << chamberWidth/cm << " cm of "
|
||||
<< fChamberMaterial->GetName() << "\nThe distance between chamber is "
|
||||
<< chamberSpacing/cm << " cm" << G4endl;
|
||||
|
||||
// Visualization attributes
|
||||
|
||||
G4VisAttributes* boxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
|
||||
worldLV ->SetVisAttributes(boxVisAtt);
|
||||
fLogicTarget ->SetVisAttributes(boxVisAtt);
|
||||
trackerLV ->SetVisAttributes(boxVisAtt);
|
||||
|
||||
G4VisAttributes* chamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0));
|
||||
fLogicChamber->SetVisAttributes(chamberVisAtt);
|
||||
|
||||
// Example of User Limits
|
||||
//
|
||||
// Below is an example of how to set tracking constraints in a given
|
||||
// logical volume
|
||||
//
|
||||
// Sets a max step length in the tracker region, with G4StepLimiter
|
||||
|
||||
G4double maxStep = 0.5*chamberWidth;
|
||||
fStepLimit = new G4UserLimits(maxStep);
|
||||
trackerLV->SetUserLimits(fStepLimit);
|
||||
|
||||
/// Set additional contraints on the track, with G4UserSpecialCuts
|
||||
///
|
||||
/// G4double maxLength = 2*trackerLength, maxTime = 0.1*ns, minEkin = 10*MeV;
|
||||
/// trackerLV->SetUserLimits(new G4UserLimits(maxStep,
|
||||
/// maxLength,
|
||||
/// maxTime,
|
||||
/// minEkin));
|
||||
|
||||
// Always return the physical world
|
||||
|
||||
return worldPV;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2bDetectorConstruction::ConstructSDandField()
|
||||
{
|
||||
// Sensitive detectors
|
||||
|
||||
G4String trackerChamberSDname = "B2/TrackerChamberSD";
|
||||
B2TrackerSD* aTrackerSD = new B2TrackerSD(trackerChamberSDname,
|
||||
"TrackerHitsCollection");
|
||||
SetSensitiveDetector( fLogicChamber, aTrackerSD );
|
||||
|
||||
// Create global magnetic field messenger.
|
||||
// Uniform magnetic field is then created automatically if
|
||||
// the field value is not zero.
|
||||
G4ThreeVector fieldValue = G4ThreeVector();
|
||||
fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
|
||||
fMagFieldMessenger->SetVerboseLevel(1);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2bDetectorConstruction::SetTargetMaterial(G4String materialName)
|
||||
{
|
||||
G4NistManager* nistManager = G4NistManager::Instance();
|
||||
|
||||
G4Material* pttoMaterial =
|
||||
nistManager->FindOrBuildMaterial(materialName);
|
||||
|
||||
if (fTargetMaterial != pttoMaterial) {
|
||||
if ( pttoMaterial ) {
|
||||
fTargetMaterial = pttoMaterial;
|
||||
if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
|
||||
G4cout << "\n----> The target is made of " << materialName << G4endl;
|
||||
} else {
|
||||
G4cout << "\n--> WARNING from SetTargetMaterial : "
|
||||
<< materialName << " not found" << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2bDetectorConstruction::SetChamberMaterial(G4String materialName)
|
||||
{
|
||||
G4NistManager* nistManager = G4NistManager::Instance();
|
||||
|
||||
G4Material* pttoMaterial =
|
||||
nistManager->FindOrBuildMaterial(materialName);
|
||||
|
||||
if (fChamberMaterial != pttoMaterial) {
|
||||
if ( pttoMaterial ) {
|
||||
fChamberMaterial = pttoMaterial;
|
||||
if (fLogicChamber) fLogicChamber->SetMaterial(fChamberMaterial);
|
||||
G4cout << "\n----> The chambers are made of " << materialName << G4endl;
|
||||
} else {
|
||||
G4cout << "\n--> WARNING from SetChamberMaterial : "
|
||||
<< materialName << " not found" << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2bDetectorConstruction::SetMaxStep(G4double maxStep)
|
||||
{
|
||||
if ((fStepLimit)&&(maxStep>0.)) fStepLimit->SetMaxAllowedStep(maxStep);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
/// \file B2bDetectorMessenger.cc
|
||||
/// \brief Implementation of the B2bDetectorMessenger class
|
||||
|
||||
#include "B2bDetectorMessenger.hh"
|
||||
#include "B2bDetectorConstruction.hh"
|
||||
|
||||
#include "G4UIdirectory.hh"
|
||||
#include "G4UIcmdWithAString.hh"
|
||||
#include "G4UIcmdWithADoubleAndUnit.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2bDetectorMessenger::B2bDetectorMessenger(B2bDetectorConstruction* Det)
|
||||
: G4UImessenger(),
|
||||
fDetectorConstruction(Det)
|
||||
{
|
||||
fB2Directory = new G4UIdirectory("/B2/");
|
||||
fB2Directory->SetGuidance("UI commands specific to this example.");
|
||||
|
||||
fDetDirectory = new G4UIdirectory("/B2/det/");
|
||||
fDetDirectory->SetGuidance("Detector construction control");
|
||||
|
||||
fTargMatCmd = new G4UIcmdWithAString("/B2/det/setTargetMaterial",this);
|
||||
fTargMatCmd->SetGuidance("Select Material of the Target.");
|
||||
fTargMatCmd->SetParameterName("choice",false);
|
||||
fTargMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
|
||||
|
||||
fChamMatCmd = new G4UIcmdWithAString("/B2/det/setChamberMaterial",this);
|
||||
fChamMatCmd->SetGuidance("Select Material of the Chamber.");
|
||||
fChamMatCmd->SetParameterName("choice",false);
|
||||
fChamMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
|
||||
|
||||
fStepMaxCmd = new G4UIcmdWithADoubleAndUnit("/B2/det/stepMax",this);
|
||||
fStepMaxCmd->SetGuidance("Define a step max");
|
||||
fStepMaxCmd->SetParameterName("stepMax",false);
|
||||
fStepMaxCmd->SetUnitCategory("Length");
|
||||
fStepMaxCmd->AvailableForStates(G4State_Idle);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
B2bDetectorMessenger::~B2bDetectorMessenger()
|
||||
{
|
||||
delete fTargMatCmd;
|
||||
delete fChamMatCmd;
|
||||
delete fStepMaxCmd;
|
||||
delete fB2Directory;
|
||||
delete fDetDirectory;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void B2bDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
|
||||
{
|
||||
if( command == fTargMatCmd )
|
||||
{ fDetectorConstruction->SetTargetMaterial(newValue);}
|
||||
|
||||
if( command == fChamMatCmd )
|
||||
{ fDetectorConstruction->SetChamberMaterial(newValue);}
|
||||
|
||||
if( command == fStepMaxCmd ) {
|
||||
fDetectorConstruction
|
||||
->SetMaxStep(fStepMaxCmd->GetNewDoubleValue(newValue));
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// This class implements the worker model run manager for TBB based
|
||||
// application.
|
||||
// It is instantiated by tbbUserWorkerInitialization and used by
|
||||
// tbbMasterRunManager.
|
||||
// See G4WorkerRunManager for documentation of methods relative to
|
||||
// base class. Only class specific methods are documented here.
|
||||
//
|
||||
// Equivalent in traditional MT:
|
||||
// G4WorkerRunManager
|
||||
//
|
||||
// History:
|
||||
// Oct 31st, 2013 A. Dotti - First Implementation
|
||||
|
||||
#include "tbbMasterRunManager.hh"
|
||||
#include "tbbTask.hh"
|
||||
|
||||
tbbMasterRunManager::tbbMasterRunManager() :
|
||||
G4MTRunManager(),
|
||||
theTasks(static_cast<tbb::task_list*>(0)),
|
||||
nEvtsPerTask(1)
|
||||
{
|
||||
}
|
||||
|
||||
tbbMasterRunManager::~tbbMasterRunManager()
|
||||
{
|
||||
}
|
||||
|
||||
void tbbMasterRunManager::TerminateWorkers()
|
||||
{
|
||||
//For TBB based example this should be empty
|
||||
}
|
||||
|
||||
void tbbMasterRunManager::CreateAndStartWorkers()
|
||||
{
|
||||
//Instead of pthread based workers, create tbbTask
|
||||
G4int ntasks = numberOfEventToBeProcessed/nEvtsPerTask;
|
||||
G4int remn = numberOfEventToBeProcessed % nEvtsPerTask;
|
||||
for ( G4int nt = 0 ; nt < ntasks ; ++nt )
|
||||
{
|
||||
G4int evts= nEvtsPerTask;
|
||||
if ( nt == ntasks - 1 ) evts+=remn;
|
||||
CreateTask(nt,evts);
|
||||
}
|
||||
}
|
||||
|
||||
void tbbMasterRunManager::CreateTask(G4int id,G4int evts)
|
||||
{
|
||||
tbbTask& task = * new(tbb::task::allocate_root())
|
||||
tbbTask( id , NULL , evts ); //Add output for merging
|
||||
theTasks->push_back( task );
|
||||
}
|
||||
|
||||
void tbbMasterRunManager::RunTermination()
|
||||
{
|
||||
// Reduce results ....
|
||||
G4MTRunManager::RunTermination();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
#include "tbbTask.hh"
|
||||
#include "tbbWorkerRunManager.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4String.hh"
|
||||
#include "G4WorkerRunManager.hh"
|
||||
#include "G4MTRunManager.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UserWorkerThreadInitialization.hh"
|
||||
#include "G4WorkerThread.hh"
|
||||
#include "G4MTRunManagerKernel.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4UserWorkerInitialization.hh"
|
||||
#include "G4VUserActionInitialization.hh"
|
||||
|
||||
//Equivalent to G4MTRunManagerKernel::StartThread
|
||||
|
||||
tbbTask::tbbTask(G4int anId,
|
||||
tbb::concurrent_queue<const G4Run*>* out,
|
||||
G4int nevts)
|
||||
: nEvents(nevts),
|
||||
thisID(anId),
|
||||
output(out),
|
||||
beamOnCondition(false)
|
||||
{
|
||||
}
|
||||
|
||||
tbbTask::~tbbTask()
|
||||
{
|
||||
}
|
||||
|
||||
#include <tbb/atomic.h>
|
||||
namespace {
|
||||
tbb::atomic<int> counter;
|
||||
}
|
||||
|
||||
tbb::task* tbbTask::execute()
|
||||
{
|
||||
// In tbb we do not have anymore the concept of thread:
|
||||
// tasks run "somewhere"; but there is no control over where.
|
||||
// This somewhere is a thread, created, controlled and 'switched'
|
||||
// to our task by the TBB runtime system.
|
||||
//
|
||||
// The "pedantic" way to proceed is: recreate the "context"
|
||||
// from scratch every time (context=local run manager,
|
||||
// geometry, etc)
|
||||
// This would be a clear waste of resources: there is no
|
||||
// need to initialize multiple times, when the same thread
|
||||
// is used several times, ie for several tasks.
|
||||
|
||||
// In the current version to avoid this we initialize only
|
||||
// i) the first time we run on each thread, and
|
||||
// ii) at the start of a new run on each thread (reinitialization).
|
||||
// We are confident that this works because TBB co-works with TLS.
|
||||
// In addition this ensures that minimal changes needed to G4 code base.
|
||||
//
|
||||
// Note 1: that this "thread" is responsible for 1 or more TBB task,
|
||||
// e.g. at least one event.
|
||||
// Note 2: In this first example, we do not care about memory usage:
|
||||
// The resources required depend only on the total number of
|
||||
// threads used for at least one event during the simulation.
|
||||
// Note 3: It is possible to do better - this is left for another example.
|
||||
// Here is a sketch how:
|
||||
// If there is a set maximum <N> threads which will be doing
|
||||
// simulation at any point, and that this is smaller than the
|
||||
// number of TBB tasks which can run simulataneously.
|
||||
// What would need to be done is to "acquire" a resource (workspace)
|
||||
// which holds all the memory required for a running task/thread,
|
||||
// and release it at the end of the task to be re-used by other tasks
|
||||
// possibly on different threads. This is demonstrated in another
|
||||
// example.
|
||||
|
||||
static G4ThreadLocal tbbWorkerRunManager* localRM = 0;
|
||||
|
||||
|
||||
//Is this task running for the first time?
|
||||
//How to re-initialize between runs????
|
||||
if (! localRM ) {
|
||||
//It's a new thread, basically repeat what is being done in
|
||||
//G4MTRunManagerKernel::StarThread with an
|
||||
//important difference, do not process data or wait for master to
|
||||
//communicate what to do, it will
|
||||
//not happen!
|
||||
G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
|
||||
//============================
|
||||
//Step-0: Thread ID
|
||||
//============================
|
||||
//Initliazie per-thread stream-output
|
||||
//The following line is needed before we actually do I/O initialization
|
||||
//because the constructor of UI manager resets the I/O destination.
|
||||
G4int thisId = counter.fetch_and_increment();
|
||||
G4Threading::G4SetThreadId( thisId );
|
||||
G4UImanager::GetUIpointer()->SetUpForAThread( thisId );
|
||||
|
||||
//============================
|
||||
//Step-1: Random number engine
|
||||
//============================
|
||||
//RNG Engine needs to be initialized by "cloning" the master one.
|
||||
const CLHEP::HepRandomEngine* masterEngine =
|
||||
masterRM->getMasterRandomEngine();
|
||||
masterRM->GetUserWorkerThreadInitialization()->SetupRNGEngine(masterEngine);
|
||||
|
||||
//============================
|
||||
//Step-2: Initialize worker thread
|
||||
//============================
|
||||
if(masterRM->GetUserWorkerInitialization())
|
||||
masterRM->GetUserWorkerInitialization()->WorkerInitialize();
|
||||
if(masterRM->GetUserActionInitialization()) {
|
||||
G4VSteppingVerbose* sv =
|
||||
masterRM->GetUserActionInitialization()->InitializeSteppingVerbose();
|
||||
if (sv) G4VSteppingVerbose::SetInstance(sv);
|
||||
}
|
||||
//Now initialize worker part of shared objects (geometry/physics)
|
||||
G4WorkerThread::BuildGeometryAndPhysicsVector();
|
||||
localRM = static_cast<tbbWorkerRunManager*>(
|
||||
masterRM->GetUserWorkerThreadInitialization()->CreateWorkerRunManager()
|
||||
);
|
||||
G4cout<<localRM<<G4endl;
|
||||
//localRM->SetWorkerThread(wThreadContext);
|
||||
// G4AutoLock wrmm(&workerRMMutex);
|
||||
// G4MTRunManagerKernel::workerRMvector->push_back(localRM); //<<<<?????? ANDREA TBB
|
||||
// wrmm.unlock();
|
||||
|
||||
//================================
|
||||
//Step-3: Setup worker run manager
|
||||
//================================
|
||||
// Set the detector and physics list to the worker thread. Share with master
|
||||
const G4VUserDetectorConstruction* detector =
|
||||
masterRM->GetUserDetectorConstruction();
|
||||
localRM->G4RunManager::SetUserInitialization(
|
||||
const_cast<G4VUserDetectorConstruction*>(detector));
|
||||
const G4VUserPhysicsList* physicslist = masterRM->GetUserPhysicsList();
|
||||
localRM->SetUserInitialization(const_cast<G4VUserPhysicsList*>(physicslist));
|
||||
|
||||
//================================
|
||||
//Step-4: Initialize worker run manager
|
||||
//================================
|
||||
if(masterRM->GetUserActionInitialization())
|
||||
{ masterRM->GetNonConstUserActionInitialization()->Build(); }
|
||||
if(masterRM->GetUserWorkerInitialization())
|
||||
{ masterRM->GetUserWorkerInitialization()->WorkerStart(); }
|
||||
localRM->Initialize();
|
||||
|
||||
//Problem at this point is if there is more than one run...
|
||||
// Execute UI commands stored in the masther UI manager
|
||||
std::vector<G4String> cmds = masterRM->GetCommandStack();
|
||||
G4UImanager* uimgr = G4UImanager::GetUIpointer(); //TLS instance
|
||||
std::vector<G4String>::const_iterator it = cmds.begin();
|
||||
for(;it!=cmds.end();it++)
|
||||
{ uimgr->ApplyCommand(*it); }
|
||||
//Start this run
|
||||
G4String macroFile = masterRM->GetSelectMacro();
|
||||
G4int numSelect = masterRM->GetNumberOfSelectEvents();
|
||||
if ( macroFile == "" || macroFile == " " )
|
||||
{
|
||||
localRM->BeamOn(nEvents,0,numSelect);
|
||||
}
|
||||
else
|
||||
{
|
||||
localRM->BeamOn(nEvents,macroFile,numSelect);
|
||||
}
|
||||
//======= NEW TBB SPECIFIC ===========
|
||||
//Step-5: Initialize and start run
|
||||
//====================================
|
||||
// bla-bla-bla-bla
|
||||
// This is basically BeamOn
|
||||
beamOnCondition = localRM->ConfirmBeamOnCondition();
|
||||
if (beamOnCondition) {
|
||||
localRM->SetNumberOfEventsToBeProcessed( nEvents );
|
||||
localRM->ConstructScoringWorlds();
|
||||
localRM->RunInitialization();
|
||||
//Register this G4Run in output
|
||||
//Note: the idea is that we are going to accumulate everything in
|
||||
//G4Run or derived class. We let the kernel know this is the object
|
||||
//where the output is accumulated for the tbb::tasks that run on
|
||||
//this thread.
|
||||
if ( output ) {}
|
||||
}
|
||||
}
|
||||
assert(localRM!=0);
|
||||
if ( beamOnCondition ) {
|
||||
localRM->DoEventLoop( nEvents );
|
||||
//localRM->RunTermination(); //<<<< How to call this??? ANDREA TBB
|
||||
}
|
||||
|
||||
//Cannot be done here since thread can be re-used by other task
|
||||
//===============================
|
||||
//Step-6: Terminate worker thread
|
||||
//===============================
|
||||
// if(masterRM->GetUserWorkerInitialization())
|
||||
// { masterRM->GetUserWorkerInitialization()->WorkerStop(); }
|
||||
|
||||
// wrmm.lock();
|
||||
// std::vector<G4WorkerRunManager*>::iterator itrWrm = workerRMvector->begin();
|
||||
// for(;itrWrm!=workerRMvector->end();itrWrm++)
|
||||
// {
|
||||
// if((*itrWrm)==wrm)
|
||||
// {
|
||||
// workerRMvector->erase(itrWrm);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// wrmm.unlock();
|
||||
|
||||
// wThreadContext->DestroyGeometryAndPhysicsVector();
|
||||
// wThreadContext = 0;
|
||||
|
||||
return static_cast<tbb::task*>(NULL);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
#include "tbbUserWorkerInitialization.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "tbbWorkerRunManager.hh"
|
||||
|
||||
tbbUserWorkerInitialization::~tbbUserWorkerInitialization()
|
||||
{}
|
||||
|
||||
void tbbUserWorkerInitialization::JoinWorker(G4Thread*)
|
||||
{
|
||||
//Not needed for TBB
|
||||
}
|
||||
|
||||
G4Thread* tbbUserWorkerInitialization::CreateAndStartWorker(G4WorkerThread*)
|
||||
{
|
||||
//Not needed for TBB
|
||||
return static_cast<G4Thread*>(0);
|
||||
}
|
||||
|
||||
G4WorkerRunManager* tbbUserWorkerInitialization::CreateWorkerRunManager() const
|
||||
{
|
||||
return new tbbWorkerRunManager();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
#include "tbbWorkerRunManager.hh"
|
||||
#include "G4Run.hh"
|
||||
#include "G4MTRunManager.hh"
|
||||
#include "G4UserWorkerInitialization.hh"
|
||||
#include "G4UserRunAction.hh"
|
||||
#include "G4SDManager.hh"
|
||||
|
||||
tbbWorkerRunManager::tbbWorkerRunManager() :
|
||||
G4WorkerRunManager()
|
||||
{}
|
||||
|
||||
tbbWorkerRunManager::~tbbWorkerRunManager()
|
||||
{}
|
||||
|
||||
void tbbWorkerRunManager::MergePartialResults()
|
||||
{
|
||||
//TBB ??????
|
||||
}
|
||||
|
||||
void tbbWorkerRunManager::ConstructScoringWorlds()
|
||||
{
|
||||
//Forward call to protected method, that's all
|
||||
G4WorkerRunManager::ConstructScoringWorlds();
|
||||
}
|
||||
Reference in New Issue
Block a user