6 #include "G4SDManager.hh" 9 #include "G4StepPoint.hh" 10 #include "G4Transform3D.hh" 11 #include "G4LogicalVolumeStore.hh" 12 #include "G4TouchableHistory.hh" 13 #include "G4VUserTrackInformation.hh" 21 : G4VSensitiveDetector(iname), m_isCalo(
calo) {
27 if (!newcollname.empty())
31 G4SDManager* SDman = G4SDManager::GetSDMpointer();
32 SDman->AddNewDetector(
this);
37 this->
AssignSD({lvname.data(), lvname.size()});
38 ss <<
" " << lvname <<
"\n";
40 if (newcollname.empty())
41 ss <<
" Collection " << iname;
43 ss <<
" Collections " << iname <<
" and " << newcollname;
55 G4LogicalVolumeStore* theStore = G4LogicalVolumeStore::GetInstance();
56 for (
auto& lv : *theStore) {
57 if (vname == lv->GetName()) {
58 lv->SetSensitiveDetector(
this);
64 const G4StepPoint* preStepPoint =
step->GetPreStepPoint();
65 const G4ThreeVector& globalCoordinates = preStepPoint->GetPosition();
69 const G4TouchableHistory* theTouchable =
static_cast<const G4TouchableHistory*
>(preStepPoint->GetTouchable());
70 const G4ThreeVector localCoordinates =
71 theTouchable->GetHistory()->GetTopTransform().TransformPoint(globalCoordinates);
76 const G4StepPoint* postStepPoint =
step->GetPostStepPoint();
77 const G4ThreeVector& globalCoordinates = postStepPoint->GetPosition();
81 const G4StepPoint* preStepPoint =
step->GetPreStepPoint();
82 const G4ThreeVector localCoordinates =
83 preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(globalCoordinates);
88 const G4StepPoint* preStepPoint =
step->GetPreStepPoint();
89 G4ThreeVector localCoordinates =
90 preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preStepPoint->GetPosition());
95 const G4ThreeVector& globalCoordinates =
step->GetPostStepPoint()->GetPosition();
96 G4ThreeVector localCoordinates =
97 step->GetPreStepPoint()->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(globalCoordinates);
103 if (
nullptr ==
info) {
104 edm::LogWarning(
"SensitiveDetector") <<
" no TrackInformation available for trackID= " << aTrack->GetTrackID()
105 <<
" inside SD " << GetName();
107 "SensitiveDetector::cmsTrackInformation()",
"sd01", FatalException,
"cannot handle hits without trackinfo");
118 G4Track* currentTrk = aStep->GetTrack();
119 double ekin = currentTrk->GetKineticEnergy();
121 const G4VPhysicalVolume* pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
122 edm::LogWarning(
"SensitiveDetector") <<
"Negative kinetic energy Ekin(MeV)=" << ekin / CLHEP::MeV <<
" of " 123 << currentTrk->GetDefinition()->GetParticleName()
124 <<
" trackID= " << currentTrk->GetTrackID() <<
" inside " 125 << pCurrentVol->GetName();
126 currentTrk->SetKineticEnergy(0.0);
128 const G4ThreeVector& currentPos = currentTrk->GetPosition();
129 double xyz = currentPos.x() + currentPos.y() + currentPos.z();
130 const G4ThreeVector& currentMom = currentTrk->GetMomentum();
131 xyz += currentMom.x() + currentMom.y() + currentMom.z();
134 const G4VPhysicalVolume* pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
135 edm::LogWarning(
"SensitiveDetector") <<
"NaN detected for trackID= " << currentTrk->GetTrackID() <<
" inside " 136 << pCurrentVol->GetName();
137 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::string &newcollname="")
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