Skip to content

Commit

Permalink
reverted to updated version
Browse files Browse the repository at this point in the history
  • Loading branch information
martinunland committed Jan 24, 2024
1 parent 798312a commit 0be644b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
13 changes: 9 additions & 4 deletions common/framework/include/OMSimSensitiveDetector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "G4VSensitiveDetector.hh"
#include "G4ThreeVector.hh"
#include "OMSimPMTResponse.hh"

#include "G4OpBoundaryProcess.hh"
#include <vector>

class G4Step;
Expand All @@ -18,7 +18,8 @@ class G4TouchableHistory;
*/
enum class DetectorType {
PMT, ///< Photomultiplier tube detector.
GeneralPhotonDetector ///< General photon detector.
VolumePhotonDetector, ///< Photon detector based on absorption in volume.
BoundaryPhotonDetector ///< Photon detector based on absorption in boundary.
};

/**
Expand Down Expand Up @@ -58,11 +59,15 @@ public:
private:
OMSimPMTResponse *mPMTResponse;
DetectorType mDetectorType;
G4bool checkAbsorbedPhotons(G4Step *pStep);
G4OpBoundaryProcess* mBoundaryProcess = nullptr;

G4bool checkVolumeAbsorption(G4Step *pStep);
G4bool checkBoundaryAbsorption(G4Step *pStep);
PhotonInfo getPhotonInfo(G4Step *pStep);
G4bool handlePMT(G4Step *pStep, G4TouchableHistory *pTouchableHistory);
G4bool handleGeneralPhotonDetector(G4Step *pStep, G4TouchableHistory *pTouchableHistory);
void storePhotonHit(PhotonInfo &info);
void fetchBoundaryProcess();
};

#endif
#endif
81 changes: 52 additions & 29 deletions common/framework/src/OMSimSensitiveDetector.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "OMSimSensitiveDetector.hh"


#include "G4ios.hh"
#include "G4LogicalVolume.hh"
#include "G4ParticleDefinition.hh"
Expand All @@ -17,7 +16,8 @@
#include "OMSimCommandArgsTable.hh"
#include "OMSimHitManager.hh"
#include "G4VProcess.hh"

#include "G4ProcessVector.hh"
#include "G4ProcessManager.hh"
std::vector<G4String> splitStringByDelimiter(G4String const &s, char delim)
{
std::vector<G4String> result;
Expand All @@ -39,11 +39,30 @@ std::vector<G4String> splitStringByDelimiter(char *cs, char d)
/**
* @brief Constructor.
* @param name Name of the sensitive detector.
* @param pDetectorType Type of the detector (e.g., PMT, GeneralPhotonDetector).
* @param pDetectorType Type of the detector (e.g., PMT, VolumePhotonDetector).
*/
OMSimSensitiveDetector::OMSimSensitiveDetector(G4String name, DetectorType pDetectorType)
: G4VSensitiveDetector(name), mDetectorType(pDetectorType), mPMTResponse(&NoResponse::getInstance())
{}
{
}

void OMSimSensitiveDetector::fetchBoundaryProcess()
{
G4ProcessManager *lProcessManager = G4OpticalPhoton::OpticalPhoton()->GetProcessManager();
G4ProcessVector *lProcessVector = lProcessManager->GetProcessList();
for (int i = 0; i < lProcessVector->length(); i++)
{
if (dynamic_cast<G4OpBoundaryProcess *>((*lProcessVector)[i]))
{
mBoundaryProcess = (G4OpBoundaryProcess *)(*lProcessVector)[i];
break;
}
}
if (!mBoundaryProcess)
{
G4cerr << "Error: G4OpBoundaryProcess not found!" << G4endl;
}
}

void OMSimSensitiveDetector::setPMTResponse(OMSimPMTResponse *pResponse)
{
Expand All @@ -58,19 +77,31 @@ void OMSimSensitiveDetector::setPMTResponse(OMSimPMTResponse *pResponse)
*/
G4bool OMSimSensitiveDetector::ProcessHits(G4Step *pStep, G4TouchableHistory *pTouchableHistory)
{
if (checkAbsorbedPhotons(pStep))
switch (mDetectorType)
if (pStep->GetTrack()->GetDefinition() == G4OpticalPhoton::Definition()) // check if particle is a photon
{
if (checkVolumeAbsorption(pStep))
{
case DetectorType::PMT:
return handlePMT(pStep, pTouchableHistory);
case DetectorType::GeneralPhotonDetector:
return handleGeneralPhotonDetector(pStep, pTouchableHistory);
switch (mDetectorType)
{
case DetectorType::PMT:
return handlePMT(pStep, pTouchableHistory);
case DetectorType::VolumePhotonDetector:
return handleGeneralPhotonDetector(pStep, pTouchableHistory);
}
}
else if (checkBoundaryAbsorption(pStep))
{
switch (mDetectorType)
{
case DetectorType::BoundaryPhotonDetector:
return handleGeneralPhotonDetector(pStep, pTouchableHistory);
}
}
}

return false;
}


PhotonInfo OMSimSensitiveDetector::getPhotonInfo(G4Step *aStep)
{
PhotonInfo info;
Expand All @@ -94,21 +125,15 @@ PhotonInfo OMSimSensitiveDetector::getPhotonInfo(G4Step *aStep)
return info;
}

/**
* @brief Checks if the photon in the given step is absorbed.
*
* This function checks if the particle in the given step is an optical photon
* and if it's either the last step in the volume or if the post step process
* was absorption. If either of these conditions is met, the photon is considered
* absorbed and the function returns true.
*
* @param aStep The step in which the particle is being checked.
* @return True if the photon is absorbed, false otherwise.
*/
G4bool OMSimSensitiveDetector::checkAbsorbedPhotons(G4Step *aStep)

G4bool OMSimSensitiveDetector::checkVolumeAbsorption(G4Step *aStep)
{
G4Track *aTrack = aStep->GetTrack();
if (aTrack->GetDefinition() != G4OpticalPhoton::Definition())
return aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() == "OpAbsorption";
}

G4bool OMSimSensitiveDetector::checkBoundaryAbsorption(G4Step *aStep)
{
if (mBoundaryProcess == nullptr)
{
fetchBoundaryProcess();
};
Expand All @@ -118,7 +143,6 @@ G4bool OMSimSensitiveDetector::checkAbsorbedPhotons(G4Step *aStep)
if (mBoundaryProcess)
{
G4OpBoundaryProcessStatus boundaryStatus = mBoundaryProcess->GetStatus();

if (boundaryStatus == G4OpBoundaryProcessStatus::Detection)
{
return true;
Expand All @@ -128,7 +152,7 @@ G4bool OMSimSensitiveDetector::checkAbsorbedPhotons(G4Step *aStep)
return false;
}

/**
/**
* @brief Handles hits for PMTs.
* @param pStep The current step information.
* @param pTouchableHistory The history of touchable objects.
Expand Down Expand Up @@ -163,7 +187,6 @@ G4bool OMSimSensitiveDetector::handleGeneralPhotonDetector(G4Step *aStep, G4Touc
return true;
}


/**
* @brief Stores photon hit information into the HitManager
* @param info The photon hit information.
Expand All @@ -183,4 +206,4 @@ void OMSimSensitiveDetector::storePhotonHit(PhotonInfo &info)
info.deltaPosition.mag() / m,
info.PMTResponse,
info.detectorID);
}
}

0 comments on commit 0be644b

Please sign in to comment.