Import Geant4 11.3.0.beta source tree
This commit is contained in:
@@ -24,33 +24,35 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
#include "Par04SensitiveDetector.hh"
|
||||
#include <CLHEP/Vector/Rotation.h> // for HepRotation
|
||||
|
||||
#include "Par04EventInformation.hh" // for Par04EventInformation
|
||||
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
|
||||
|
||||
#include "G4Event.hh" // for G4Event
|
||||
#include "G4EventManager.hh" // for G4EventManager
|
||||
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
|
||||
#include "G4SDManager.hh" // for G4SDManager
|
||||
#include "G4Step.hh" // for G4Step
|
||||
#include "G4Track.hh" // for G4Track
|
||||
|
||||
#include <CLHEP/Vector/Rotation.h> // for HepRotation
|
||||
#include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
|
||||
#include <cmath> // for floor
|
||||
#include <G4CollectionNameVector.hh> // for G4CollectionNameVector
|
||||
#include <G4FastHit.hh> // for G4FastHit
|
||||
#include <G4FastTrack.hh> // for G4FastTrack
|
||||
#include <G4RotationMatrix.hh> // for G4RotationMatrix
|
||||
#include <G4StepPoint.hh> // for G4StepPoint
|
||||
#include <G4THitsCollection.hh> // for G4THitsCollection
|
||||
#include <G4ThreeVector.hh> // for G4ThreeVector
|
||||
#include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
|
||||
#include <G4CollectionNameVector.hh> // for G4CollectionNameVector
|
||||
#include <G4FastHit.hh> // for G4FastHit
|
||||
#include <G4FastTrack.hh> // for G4FastTrack
|
||||
#include <G4RotationMatrix.hh> // for G4RotationMatrix
|
||||
#include <G4StepPoint.hh> // for G4StepPoint
|
||||
#include <G4THitsCollection.hh> // for G4THitsCollection
|
||||
#include <G4ThreeVector.hh> // for G4ThreeVector
|
||||
#include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
|
||||
#include <G4VUserEventInformation.hh> // for G4VUserEventInformation
|
||||
#include <cstddef> // for size_t
|
||||
#include <vector> // for vector
|
||||
#include "G4Event.hh" // for G4Event
|
||||
#include "G4EventManager.hh" // for G4EventManager
|
||||
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
|
||||
#include "G4SDManager.hh" // for G4SDManager
|
||||
#include "G4Step.hh" // for G4Step
|
||||
#include "G4Track.hh" // for G4Track
|
||||
#include "Par04EventInformation.hh" // for Par04EventInformation
|
||||
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
|
||||
#include <cmath> // for floor
|
||||
#include <cstddef> // for size_t
|
||||
#include <vector> // for vector
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
Par04SensitiveDetector::Par04SensitiveDetector(G4String aName)
|
||||
: G4VSensitiveDetector(aName)
|
||||
Par04SensitiveDetector::Par04SensitiveDetector(G4String aName) : G4VSensitiveDetector(aName)
|
||||
{
|
||||
collectionName.insert("hits");
|
||||
}
|
||||
@@ -58,9 +60,7 @@ Par04SensitiveDetector::Par04SensitiveDetector(G4String aName)
|
||||
|
||||
Par04SensitiveDetector::Par04SensitiveDetector(G4String aName, G4ThreeVector aNb,
|
||||
G4ThreeVector aSize)
|
||||
: G4VSensitiveDetector(aName)
|
||||
, fMeshNbOfCells(aNb)
|
||||
, fMeshSizeOfCells(aSize)
|
||||
: G4VSensitiveDetector(aName), fMeshNbOfCells(aNb), fMeshSizeOfCells(aSize)
|
||||
{
|
||||
collectionName.insert("hits");
|
||||
}
|
||||
@@ -74,8 +74,7 @@ Par04SensitiveDetector::~Par04SensitiveDetector() = default;
|
||||
void Par04SensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
|
||||
{
|
||||
fHitsCollection = new Par04HitsCollection(SensitiveDetectorName, collectionName[0]);
|
||||
if(fHitCollectionID < 0)
|
||||
{
|
||||
if (fHitCollectionID < 0) {
|
||||
fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
|
||||
}
|
||||
aHCE->AddHitsCollection(fHitCollectionID, fHitsCollection);
|
||||
@@ -90,12 +89,10 @@ void Par04SensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
|
||||
G4bool Par04SensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
|
||||
{
|
||||
G4double edep = aStep->GetTotalEnergyDeposit();
|
||||
if(edep == 0.)
|
||||
return true;
|
||||
if (edep == 0.) return true;
|
||||
|
||||
auto hit = RetrieveAndSetupHit(aStep->GetPostStepPoint()->GetPosition());
|
||||
if(hit == nullptr)
|
||||
return true;
|
||||
if (hit == nullptr) return true;
|
||||
|
||||
// Add energy deposit from G4Step
|
||||
hit->AddEdep(edep);
|
||||
@@ -104,13 +101,12 @@ G4bool Par04SensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
|
||||
|
||||
// Fill time information from G4Step
|
||||
// If it's already filled, choose hit with earliest global time
|
||||
if(hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
|
||||
if (hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
|
||||
hit->SetTime(aStep->GetTrack()->GetGlobalTime());
|
||||
|
||||
// Set hit type to full simulation (only if hit is not already marked as fast
|
||||
// sim)
|
||||
if(hit->GetType() != 1)
|
||||
hit->SetType(0);
|
||||
if (hit->GetType() != 1) hit->SetType(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -121,12 +117,10 @@ G4bool Par04SensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTr
|
||||
G4TouchableHistory*)
|
||||
{
|
||||
G4double edep = aHit->GetEnergy();
|
||||
if(edep == 0.)
|
||||
return true;
|
||||
if (edep == 0.) return true;
|
||||
|
||||
auto hit = RetrieveAndSetupHit(aHit->GetPosition());
|
||||
if(hit == nullptr)
|
||||
return true;
|
||||
if (hit == nullptr) return true;
|
||||
|
||||
// Add energy deposit from G4FastHit
|
||||
hit->AddEdep(edep);
|
||||
@@ -135,8 +129,7 @@ G4bool Par04SensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTr
|
||||
|
||||
// Fill time information from G4FastTrack
|
||||
// If it's already filled, choose hit with earliest global time
|
||||
if(hit->GetTime() == -1 || hit->GetTime() > aTrack->GetPrimaryTrack()->GetGlobalTime())
|
||||
{
|
||||
if (hit->GetTime() == -1 || hit->GetTime() > aTrack->GetPrimaryTrack()->GetGlobalTime()) {
|
||||
hit->SetTime(aTrack->GetPrimaryTrack()->GetGlobalTime());
|
||||
}
|
||||
|
||||
@@ -151,13 +144,11 @@ G4bool Par04SensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTr
|
||||
|
||||
Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosition)
|
||||
{
|
||||
if(fEntrancePosition.x() == -1)
|
||||
{
|
||||
auto info = dynamic_cast<Par04EventInformation*>(
|
||||
if (fEntrancePosition.x() == -1) {
|
||||
auto info = dynamic_cast<Par04EventInformation*>(
|
||||
G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetUserInformation());
|
||||
if(info == nullptr)
|
||||
return nullptr;
|
||||
fEntrancePosition = info->GetPosition();
|
||||
if (info == nullptr) return nullptr;
|
||||
fEntrancePosition = info->GetPosition();
|
||||
fEntranceDirection = info->GetDirection();
|
||||
}
|
||||
|
||||
@@ -166,8 +157,8 @@ Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosit
|
||||
// Calculate rotation matrix along the particle momentum direction
|
||||
// It will rotate the shower axes to match the incoming particle direction
|
||||
G4RotationMatrix rotMatrix = G4RotationMatrix();
|
||||
double particleTheta = fEntranceDirection.theta();
|
||||
double particlePhi = fEntranceDirection.phi();
|
||||
double particleTheta = fEntranceDirection.theta();
|
||||
double particlePhi = fEntranceDirection.phi();
|
||||
rotMatrix.rotateZ(-particlePhi);
|
||||
rotMatrix.rotateY(-particleTheta);
|
||||
G4RotationMatrix rotMatrixInv = CLHEP::inverseOf(rotMatrix);
|
||||
@@ -176,27 +167,25 @@ Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosit
|
||||
|
||||
G4int rhoNo = std::floor(delta.perp() / fMeshSizeOfCells.x());
|
||||
G4int phiNo = std::floor((CLHEP::pi + delta.phi()) / fMeshSizeOfCells.y());
|
||||
G4int zNo = std::floor(delta.z() / fMeshSizeOfCells.z());
|
||||
G4int zNo = std::floor(delta.z() / fMeshSizeOfCells.z());
|
||||
|
||||
std::size_t hitID =
|
||||
fMeshNbOfCells.x() * fMeshNbOfCells.z() * phiNo + fMeshNbOfCells.z() * rhoNo + zNo;
|
||||
|
||||
if(zNo >= fMeshNbOfCells.z() || rhoNo >= fMeshNbOfCells.x() || zNo < 0)
|
||||
{
|
||||
|
||||
if (zNo >= fMeshNbOfCells.z() || rhoNo >= fMeshNbOfCells.x() || zNo < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto hit = fHitsMap[hitID].get();
|
||||
if (hit==nullptr) {
|
||||
if (hit == nullptr) {
|
||||
fHitsMap[hitID] = std::unique_ptr<Par04Hit>(new Par04Hit());
|
||||
hit = fHitsMap[hitID].get();
|
||||
hit->SetPhiId(phiNo);
|
||||
hit->SetRhoId(rhoNo);
|
||||
hit->SetZid(zNo);
|
||||
hit->SetRot(rotMatrixInv);
|
||||
hit->SetPos(fEntrancePosition +
|
||||
rotMatrixInv * G4ThreeVector(0, 0, (zNo + 0.5) * fMeshSizeOfCells.z()));
|
||||
|
||||
hit->SetPos(fEntrancePosition
|
||||
+ rotMatrixInv * G4ThreeVector(0, 0, (zNo + 0.5) * fMeshSizeOfCells.z()));
|
||||
}
|
||||
return hit;
|
||||
}
|
||||
@@ -205,7 +194,7 @@ Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosit
|
||||
|
||||
void Par04SensitiveDetector::EndOfEvent(G4HCofThisEvent*)
|
||||
{
|
||||
for(const auto& hits: fHitsMap){
|
||||
for (const auto& hits : fHitsMap) {
|
||||
fHitsCollection->insert(new Par04Hit(*hits.second.get()));
|
||||
}
|
||||
fHitsMap.clear();
|
||||
|
||||
Reference in New Issue
Block a user