Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iss1376 geant4 object pointer for comparison #1633

Open
wants to merge 23 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Biasing/include/Biasing/TargetDarkBremFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//------------//
// LDMX //
//------------//
#include "SimCore/G4User/PtrRetrieval.h"
#include "SimCore/UserAction.h"

namespace biasing {
Expand Down Expand Up @@ -117,8 +118,9 @@ class TargetDarkBremFilter : public simcore::UserAction {
*/
inline bool isOutsideTargetRegion(const G4LogicalVolume* vol) const {
if (!vol) return true;
auto target_region = simcore::g4user::ptrretrieval::getRegion("target");
auto region = vol->GetRegion();
return region ? (region->GetName().compareTo("target") != 0) : true;
return region ? (region != target_region) : true;
}

/**
Expand Down
12 changes: 0 additions & 12 deletions Biasing/include/Biasing/TargetENProcessFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ class TargetENProcessFilter : public simcore::UserAction {
}

private:
/**
* The volume name of the LDMX target
*
* The 'target_PV' volume name is automatically constructed by Geant4's
* GDML parser and was found by inspecting the geometry using a
* visualization. This Physical Volume (PV) is associated with the
* target parent volume and so it will break if the target parent volume
* changes its name.
*/
std::string volumeName_{"target_PV"};

/** Flag indicating if the reaction of intereset occurred. */
bool reactionOccurred_{false};

Expand All @@ -68,7 +57,6 @@ class TargetENProcessFilter : public simcore::UserAction {
std::string process_{"electronNuclear"};

}; // TargetENProcessFilter

} // namespace biasing

#endif // BIASING_TARGETPROCESSFILTER_H
25 changes: 10 additions & 15 deletions Biasing/src/Biasing/DeepEcalProcessFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/G4User/VolumeChecks.h"
#include "SimCore/UserEventInformation.h"
#include "SimCore/UserTrackInformation.h"

Expand Down Expand Up @@ -52,17 +53,19 @@ void DeepEcalProcessFilter::stepping(const G4Step* step) {
}

// Check in which volume the particle is currently
auto volume{track->GetVolume()->GetLogicalVolume()
? track->GetVolume()->GetLogicalVolume()->GetName()
: "undefined"};
auto volume = track->GetVolume()->GetLogicalVolume();
auto volume_name = volume->GetName();
if (!volume_name) {
volume_name = "undefined";
}

auto trackInfo{simcore::UserTrackInformation::get(track)};
// Tag the brem photon from the primary electron
if (processName.contains("eBrem") and (track->GetParentID() == 1)) {
trackInfo->tagBremCandidate();
getEventInfo()->incBremCandidateCount();
trackInfo->setSaveFlag(true);
if (volume.contains("target")) {
if (volume_name.contains("target")) {
photonFromTarget_ = true;
}
}
Expand All @@ -86,20 +89,12 @@ void DeepEcalProcessFilter::stepping(const G4Step* step) {
// skip this step if it does not have any of the processes needed
if (not hasProcessNeeded) return;

// isInEcal should be taken from
// simcore::logical_volume_tests::isInEcal(volume) but for now it's under
// its own namespace so I cannot reach it here, see issue
// https://github.com/LDMX-Software/ldmx-sw/issues/1286
auto isInEcal{((volume.contains("Si") || volume.contains("W") ||
volume.contains("PCB") || volume.contains("strongback") ||
volume.contains("Glue") || volume.contains("CFMix") ||
volume.contains("Al") || volume.contains("C")) &&
volume.contains("volume")) ||
(volume.contains("nohole_motherboard"))};
auto is_in_ecal =
simcore::g4user::volumechecks::isInEcal(volume, volume_name);

// Skip this step if it does not have the processes needed
// or if it's not in the ECAL
if (not isInEcal) return;
if (not is_in_ecal) return;

// Check the z position of the particle, and
// flag if it is deeper than the min Z we are considering (but in ECAL)
Expand Down
17 changes: 11 additions & 6 deletions Biasing/src/Biasing/EcalProcessFilter.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/*~~~~~~~~~~~~~*/
/* Biasing */
/*~~~~~~~~~~~~~*/
#include "Biasing/EcalProcessFilter.h"

/*~~~~~~~~~~~~*/
Expand All @@ -12,6 +14,7 @@
/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/G4User/PtrRetrieval.h"
#include "SimCore/UserTrackInformation.h"

namespace biasing {
Expand Down Expand Up @@ -60,9 +63,9 @@ void EcalProcessFilter::stepping(const G4Step* step) {

// Get the region the particle is currently in. Continue processing
// the particle only if it's in the calorimeter region.
if (auto region{
track->GetVolume()->GetLogicalVolume()->GetRegion()->GetName()};
region.compareTo("CalorimeterRegion") != 0) {
auto region = simcore::g4user::ptrretrieval::getRegion("CalorimeterRegion");

if (track->GetVolume()->GetLogicalVolume()->GetRegion() != region) {
// If secondaries were produced outside of the volume of interest,
// and there aren't additional brems to process, abort the
// event. Otherwise, suspend the track and move on to the next
Expand Down Expand Up @@ -105,8 +108,10 @@ void EcalProcessFilter::stepping(const G4Step* step) {
* hcal parent volume and so it will break if the hcal parent volume
* changes its name.
*/
if (auto volume{track->GetNextVolume()->GetName()};
volume.compareTo("hcal_PV") == 0) {
auto volume_after_exiting_ecal =
simcore::g4user::ptrretrieval::getLogicalVolume("hadronic_calorimeter");
auto volume = track->GetNextVolume()->GetLogicalVolume();
if (volume == volume_after_exiting_ecal) {
/*
std::cout << "[ EcalProcessFilter ]: "
<<
Expand Down
29 changes: 13 additions & 16 deletions Biasing/src/Biasing/NonFiducialFilter.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*~~~~~~~~~~~~~*/
/* Biasing */
/*~~~~~~~~~~~~~*/
#include "Biasing/NonFiducialFilter.h"

/*~~~~~~~~~~~~*/
Expand All @@ -12,6 +15,8 @@
/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/G4User/PtrRetrieval.h"
#include "SimCore/G4User/VolumeChecks.h"
#include "SimCore/UserEventInformation.h"
#include "SimCore/UserTrackInformation.h"

Expand Down Expand Up @@ -43,9 +48,7 @@ void NonFiducialFilter::stepping(const G4Step* step) {
}

// Check in which volume the electron is currently
auto volume{track->GetVolume()->GetLogicalVolume()
? track->GetVolume()->GetLogicalVolume()->GetName()
: "undefined"};
auto volume = track->GetVolume()->GetLogicalVolume();

// Check if the track is tagged.
auto electronCheck{simcore::UserTrackInformation::get(track)};
Expand All @@ -60,18 +63,10 @@ void NonFiducialFilter::stepping(const G4Step* step) {
}
// Check if the track ever enters the ECal. If it does, kill the track and
// abort the event.
auto isInEcal{((volume.contains("Si") || volume.contains("W") ||
volume.contains("PCB") || volume.contains("strongback") ||
volume.contains("Glue") || volume.contains("CFMix") ||
volume.contains("Al") || volume.contains("C")) &&
volume.contains("volume")) ||
(volume.contains("nohole_motherboard"))};

// isInEcal should be taken from
// simcore::logical_volume_tests::isInEcal(volume) but for now it's under
// its own namespace so I cannot reach it here see issue
// https://github.com/LDMX-Software/ldmx-sw/issues/1286
if (abort_fiducial_ && isInEcal) {
auto volume_name = volume->GetName();
auto is_in_ecal =
simcore::g4user::volumechecks::isInEcal(volume, volume_name);
if (abort_fiducial_ && is_in_ecal) {
track->SetTrackStatus(fKillTrackAndSecondaries);
G4RunManager::GetRunManager()->AbortEvent();
ldmx_log(debug) << ">> This event is fiducial, exiting";
Expand All @@ -86,7 +81,9 @@ void NonFiducialFilter::stepping(const G4Step* step) {
return;
} else {
// Check if the particle enters the recoil tracker.
if (volume.compareTo("recoil") == 0) {
auto recoil_volume =
simcore::g4user::ptrretrieval::getLogicalVolume("recoil");
if (volume == recoil_volume) {
/* Tag the tracks that:
1) Have a recoil electron
2) Enter/Exit the Target */
Expand Down
21 changes: 13 additions & 8 deletions Biasing/src/Biasing/PrimaryToEcalFilter.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/*~~~~~~~~~~~~~*/
/* Biasing */
/*~~~~~~~~~~~~~*/
#include "Biasing/PrimaryToEcalFilter.h"

/*~~~~~~~~~~~~*/
Expand All @@ -8,6 +10,11 @@
#include "G4RunManager.hh"
#include "G4Step.hh"

/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/G4User/PtrRetrieval.h"

namespace biasing {

PrimaryToEcalFilter::PrimaryToEcalFilter(
Expand All @@ -25,13 +32,11 @@ void PrimaryToEcalFilter::stepping(const G4Step* step) {

// Get the region the particle is currently in. Continue processing
// the particle only if it's NOT in the calorimeter region
if (auto region{step->GetTrack()
->GetVolume()
->GetLogicalVolume()
->GetRegion()
->GetName()};
region.compareTo("CalorimeterRegion") == 0)
return;
auto current_region =
step->GetTrack()->GetVolume()->GetLogicalVolume()->GetRegion();
auto calorimeter_region =
simcore::g4user::ptrretrieval::getRegion("CalorimeterRegion");
if (current_region == calorimeter_region) return;

// If the energy of the particle fell below threshold, stop processing the
// event.
Expand Down
32 changes: 20 additions & 12 deletions Biasing/src/Biasing/TaggerHitFilter.cxx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@

/*~~~~~~~~~~~~~*/
/* Biasing */
/*~~~~~~~~~~~~~*/
#include "Biasing/TaggerHitFilter.h"

//~~ Geant4 ~~//
//------------//
// Geant4 //
//------------//
#include "G4RunManager.hh"
#include "G4Step.hh"

/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/G4User/PtrRetrieval.h"

namespace biasing {

TaggerHitFilter::TaggerHitFilter(const std::string& name,
Expand All @@ -25,24 +34,23 @@ void TaggerHitFilter::stepping(const G4Step* step) {
}

// Only electrons in the Tagger region are of interest.
auto volume{track->GetVolume()};
if (auto region{volume->GetLogicalVolume()->GetRegion()->GetName()};
region.compareTo("tagger") != 0)
return;
auto current_region = (track->GetVolume()->GetLogicalVolume()->GetRegion());
auto tagger_region = simcore::g4user::ptrretrieval::getRegion("tagger");
if (current_region != tagger_region) return;

// Check if we are exiting the tagger
if (auto nregion{
track->GetNextVolume()->GetLogicalVolume()->GetRegion()->GetName()};
(nregion.compareTo("tagger") != 0)) {
auto next_region = (track->GetNextVolume()->GetLogicalVolume()->GetRegion());
if (next_region != tagger_region) {
checkAbortEvent(track);
return;
}

// A particle will only leave hits in the active silicon so other volumes can
// be skipped for now.
if (auto volume_name{track->GetVolume()->GetName()};
volume_name.compareTo("tagger_PV") == 0)
return;
auto current_volume = (track->GetVolume());
auto tagger_physical_volume =
simcore::g4user::ptrretrieval::getPhysicalVolume("tagger_PV");
if (current_volume == tagger_physical_volume) return;

// The copy number is used to identify which layer energy was deposited into.
int copy_number{0};
Expand Down
16 changes: 12 additions & 4 deletions Biasing/src/Biasing/TaggerVetoFilter.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/*~~~~~~~~~~~~~*/
/* Biasing */
/*~~~~~~~~~~~~~*/
#include "Biasing/TaggerVetoFilter.h"

/*~~~~~~~~~~~~*/
Expand All @@ -7,6 +9,11 @@
#include "G4RunManager.hh"
#include "G4Step.hh"

/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/G4User/PtrRetrieval.h"

namespace biasing {

TaggerVetoFilter::TaggerVetoFilter(const std::string &name,
Expand Down Expand Up @@ -41,10 +48,11 @@ void TaggerVetoFilter::stepping(const G4Step *step) {

// Get the region the particle is currently in. Continue processing
// the particle only if it's in the tagger region.
if (auto region{
track->GetVolume()->GetLogicalVolume()->GetRegion()->GetName()};
region.compareTo("tagger") != 0)
auto current_region = track->GetVolume()->GetLogicalVolume()->GetRegion();
auto tagger_region = simcore::g4user::ptrretrieval::getRegion("tagger");
if (current_region != tagger_region) {
return;
}

primary_entered_tagger_region_ = true;
// If the energy of the particle falls below threshold, stop
Expand Down
30 changes: 19 additions & 11 deletions Biasing/src/Biasing/TargetBremFilter.cxx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@

/*~~~~~~~~~~~~~*/
/* Biasing */
/*~~~~~~~~~~~~~*/
#include "Biasing/TargetBremFilter.h"

/*~~~~~~~~~~~~*/
/* Geant4 */
/*~~~~~~~~~~~~*/
#include "G4Electron.hh"
#include "G4EventManager.hh"
#include "G4RunManager.hh"

/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/G4User/PtrRetrieval.h"
#include "SimCore/UserEventInformation.h"
#include "SimCore/UserTrackInformation.h"

Expand Down Expand Up @@ -60,10 +64,9 @@ void TargetBremFilter::stepping(const G4Step* step) {

// Get the region the particle is currently in. Continue processing
// the particle only if it's in the target region.
if (auto region{
track->GetVolume()->GetLogicalVolume()->GetRegion()->GetName()};
region.compareTo("target") != 0)
return;
auto target_region = simcore::g4user::ptrretrieval::getRegion("target");
auto track_region = track->GetVolume()->GetLogicalVolume()->GetRegion();
if (track_region != target_region) return;

/*
std::cout << "[TargetBremFilter] : Stepping primary electron in 'target'
Expand All @@ -84,8 +87,13 @@ void TargetBremFilter::stepping(const G4Step* step) {
* We also check if the next volume is World_PV because in some geometries
* (e.g. v14), there is a air-gap between the target region and the recoil.
*/
if (auto volume{track->GetNextVolume()->GetName()};
volume.compareTo("recoil_PV") == 0 or volume.compareTo("World_PV") == 0) {
auto recoil_physical_volume =
simcore::g4user::ptrretrieval::getPhysicalVolume("recoil_PV");
auto world_physical_volume =
simcore::g4user::ptrretrieval::getPhysicalVolume("World_PV");
auto track_volume = track->GetNextVolume();
if (track_volume == recoil_physical_volume or
track_volume == world_physical_volume) {
// If the recoil electron
if (track->GetMomentum().mag() >= recoilMaxPThreshold_) {
track->SetTrackStatus(fKillTrackAndSecondaries);
Expand All @@ -101,10 +109,10 @@ void TargetBremFilter::stepping(const G4Step* step) {
return;
} else {
for (auto& secondary_track : *secondaries) {
G4String processName =
secondary_track->GetCreatorProcess()->GetProcessName();

if (processName.compareTo("eBrem") == 0 &&
auto electron = G4Electron::Definition();
auto ebrem_process =
simcore::g4user::ptrretrieval::getProcess(electron, "eBrem");
if (ebrem_process &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really the electron that's supposed to be here @tomeichlersmith @EinarElen ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so... thats the particle that would do the eBrem. Are you asking if this should be a photon whose creator process is eBrem?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was my thinking, but I guess it works as it is

secondary_track->GetKineticEnergy() > bremEnergyThreshold_) {
auto trackInfo{simcore::UserTrackInformation::get(secondary_track)};
trackInfo->tagBremCandidate();
Expand Down
Loading
Loading