6 #include "G4SDManager.hh" 9 #include "G4StepPoint.hh" 10 #include "G4Transform3D.hh" 11 #include "G4LogicalVolumeStore.hh" 12 #include "G4TouchableHistory.hh" 13 #include "G4VUserTrackInformation.hh" 18 : G4VSensitiveDetector(iname), m_isCalo(
calo) {
26 G4SDManager* SDman = G4SDManager::GetSDMpointer();
27 SDman->AddNewDetector(
this);
32 this->
AssignSD({lvname.data(), lvname.size()});
35 edm::LogVerbatim(
"SensitiveDetector") <<
" <" << iname <<
"> : Assigns SD to LVs " <<
ss.str();
45 G4LogicalVolumeStore* theStore = G4LogicalVolumeStore::GetInstance();
46 for (
auto& lv : *theStore) {
47 if (vname == lv->GetName()) {
48 lv->SetSensitiveDetector(
this);
54 const G4StepPoint* preStepPoint =
step->GetPreStepPoint();
55 const G4ThreeVector& globalCoordinates = preStepPoint->GetPosition();
59 const G4TouchableHistory* theTouchable =
static_cast<const G4TouchableHistory*
>(preStepPoint->GetTouchable());
60 const G4ThreeVector localCoordinates =
61 theTouchable->GetHistory()->GetTopTransform().TransformPoint(globalCoordinates);
66 const G4StepPoint* postStepPoint =
step->GetPostStepPoint();
67 const G4ThreeVector& globalCoordinates = postStepPoint->GetPosition();
71 const G4StepPoint* preStepPoint =
step->GetPreStepPoint();
72 const G4ThreeVector localCoordinates =
73 preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(globalCoordinates);
78 const G4StepPoint* preStepPoint =
step->GetPreStepPoint();
79 G4ThreeVector localCoordinates =
80 preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preStepPoint->GetPosition());
85 const G4ThreeVector& globalCoordinates =
step->GetPostStepPoint()->GetPosition();
86 G4ThreeVector localCoordinates =
87 step->GetPreStepPoint()->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(globalCoordinates);
93 if (
nullptr ==
info) {
94 edm::LogWarning(
"SensitiveDetector") <<
" no TrackInformation available for trackID= " << aTrack->GetTrackID()
95 <<
" inside SD " << GetName();
97 "SensitiveDetector::cmsTrackInformation()",
"sd01", FatalException,
"cannot handle hits without trackinfo");
108 G4Track* currentTrk = aStep->GetTrack();
109 double ekin = currentTrk->GetKineticEnergy();
111 const G4VPhysicalVolume* pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
112 edm::LogWarning(
"SensitiveDetector") <<
"Negative kinetic energy Ekin(MeV)=" << ekin / CLHEP::MeV <<
" of " 113 << currentTrk->GetDefinition()->GetParticleName()
114 <<
" trackID= " << currentTrk->GetTrackID() <<
" inside " 115 << pCurrentVol->GetName();
116 currentTrk->SetKineticEnergy(0.0);
118 const G4ThreeVector& currentPos = currentTrk->GetPosition();
119 double xyz = currentPos.x() + currentPos.y() + currentPos.z();
120 const G4ThreeVector& currentMom = currentTrk->GetMomentum();
121 xyz += currentMom.x() + currentMom.y() + currentMom.z();
124 const G4VPhysicalVolume* pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
125 edm::LogWarning(
"SensitiveDetector") <<
"NaN detected for trackID= " << currentTrk->GetTrackID() <<
" inside " 126 << pCurrentVol->GetName();
127 G4Exception(
"SensitiveDetector::NaNTrap()",
"sd01", FatalException,
"corrupted event or step");
Log< level::Info, true > LogVerbatim
~SensitiveDetector() override
constexpr bool isNotFinite(T x)
SensitiveDetector(const std::string &iname, const SensitiveDetectorCatalog &, bool calo)
const std::vector< std::string_view > logicalNames(const std::string &readoutName) const
void AssignSD(const std::string &vname)
Local3DPoint FinalStepPosition(const G4Step *step, coordinates) const
std::vector< std::string > m_namesOfSD
Local3DPoint ConvertToLocal3DPoint(const G4ThreeVector &point) const
Local3DPoint InitialStepPosition(const G4Step *step, coordinates) const
TrackInformation * cmsTrackInformation(const G4Track *aTrack)
Local3DPoint LocalPreStepPosition(const G4Step *step) const
void EndOfEvent(G4HCofThisEvent *eventHC) override
void setNames(const std::vector< std::string > &)
Local3DPoint LocalPostStepPosition(const G4Step *step) const
Log< level::Warning, false > LogWarning
void Initialize(G4HCofThisEvent *eventHC) override
void NaNTrap(const G4Step *step) const