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 8 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 @@ -25,6 +25,7 @@
// LDMX //
//------------//
#include "SimCore/UserAction.h"
#include "SimCore/Geant4_PtrRetrieval.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;
static G4Region* TargetRegion = Geant4_PtrRetrieval::GetRegion("target"); // Static local variable
auto region = vol->GetRegion();
return region ? (region->GetName().compareTo("target") != 0) : true;
return region ? (region != TargetRegion) : true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Biasing/include/Biasing/TargetENProcessFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/UserAction.h"
#include "SimCore/Geant4_PtrRetrieval.h"

// Forward Declarations
class G4Step;
Expand Down Expand Up @@ -56,7 +57,6 @@ class TargetENProcessFilter : public simcore::UserAction {
* target parent volume and so it will break if the target parent volume
* changes its name.
*/
Copy link
Member

Choose a reason for hiding this comment

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

You removed the variable but not the corresponding comment

std::string volumeName_{"target_PV"};

/** Flag indicating if the reaction of intereset occurred. */
bool reactionOccurred_{false};
Expand Down
1 change: 1 addition & 0 deletions Biasing/include/Biasing/TargetProcessFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TargetProcessFilter : public simcore::UserAction {

/// The process to bias
std::string process_{""};

};

} // namespace biasing
Expand Down
19 changes: 10 additions & 9 deletions Biasing/src/Biasing/EcalProcessFilter.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "Biasing/EcalProcessFilter.h"

/*~~~~~~~~~~~~*/
Expand All @@ -13,6 +12,7 @@
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/UserTrackInformation.h"
#include "SimCore/Geant4_PtrRetrieval.h"

namespace biasing {

Expand All @@ -26,7 +26,7 @@ G4ClassificationOfNewTrack EcalProcessFilter::ClassifyNewTrack(
const G4Track* track, const G4ClassificationOfNewTrack& currentTrackClass) {
// Get the particle type.
G4String particleName = track->GetParticleDefinition()->GetParticleName();

if (track == currentTrack_) {
/*
std::cout << "[ EcalProcessFilter ]: "
Expand Down Expand Up @@ -54,15 +54,15 @@ void EcalProcessFilter::stepping(const G4Step* step) {
// Get the track info and check if this track is a brem candidate
auto trackInfo{simcore::UserTrackInformation::get(track)};
if ((trackInfo != nullptr) && !trackInfo->isBremCandidate()) return;

// Get the particles daughters.
auto secondaries{step->GetSecondary()};

// 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 = Geant4_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 +105,9 @@ 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 = Geant4_PtrRetrieval::GetVolume("hadronic_calorimeter");
auto volume = track->GetNextVolume();
if (volume == volume_after_exiting_ecal) {
/*
std::cout << "[ EcalProcessFilter ]: "
<<
Expand Down
23 changes: 8 additions & 15 deletions Biasing/src/Biasing/NonFiducialFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
/*~~~~~~~~~~~~~*/
#include "SimCore/UserEventInformation.h"
#include "SimCore/UserTrackInformation.h"
#include "SimCore/Geant4_PtrRetrieval.h"
#include "SimCore/VolumeTests.h"

namespace biasing {

Expand Down Expand Up @@ -43,9 +45,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,17 +60,9 @@ 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
auto volume = track->GetVolume()->GetLogicalVolume();
auto volumeName = volume->GetName();
auto isInEcal = simcore::volume_tests::isInEcal(volume, volumeName);
if (abort_fiducial_ && isInEcal) {
track->SetTrackStatus(fKillTrackAndSecondaries);
G4RunManager::GetRunManager()->AbortEvent();
Expand All @@ -86,7 +78,8 @@ void NonFiducialFilter::stepping(const G4Step* step) {
return;
} else {
// Check if the particle enters the recoil tracker.
if (volume.compareTo("recoil") == 0) {
auto recoil_volume = Geant4_PtrRetrieval::GetVolume("recoil");
if (volume == recoil_volume->GetLogicalVolume()) {
/* Tag the tracks that:
1) Have a recoil electron
2) Enter/Exit the Target */
Expand Down
10 changes: 4 additions & 6 deletions Biasing/src/Biasing/PrimaryToEcalFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "G4EventManager.hh"
#include "G4RunManager.hh"
#include "G4Step.hh"
#include "SimCore/Geant4_PtrRetrieval.h"

namespace biasing {

Expand All @@ -25,12 +26,9 @@ 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)
auto CurrentRegion = step->GetTrack()->GetVolume()->GetLogicalVolume()->GetRegion();
auto CalorimeterRegion = Geant4_PtrRetrieval::GetRegion("CalorimeterRegion");
if (CurrentRegion == CalorimeterRegion)
return;

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

#include "Biasing/TaggerHitFilter.h"

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

/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/Geant4_PtrRetrieval.h"

namespace biasing {

TaggerHitFilter::TaggerHitFilter(const std::string& name,
Expand All @@ -25,23 +31,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)
auto Current_Region = (track->GetVolume()->GetLogicalVolume()->GetRegion());
auto Tagger_Region = Geant4_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)
auto Current_Volume = (track->GetVolume());
auto Tagger_PhysicalVolume = Geant4_PtrRetrieval::GetVolume("tagger_PV");
if (Current_Volume == Tagger_PhysicalVolume)
return;

// The copy number is used to identify which layer energy was deposited into.
Expand Down
13 changes: 8 additions & 5 deletions Biasing/src/Biasing/TaggerVetoFilter.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "Biasing/TaggerVetoFilter.h"

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

/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/Geant4_PtrRetrieval.h"

namespace biasing {

TaggerVetoFilter::TaggerVetoFilter(const std::string &name,
Expand Down Expand Up @@ -41,10 +45,9 @@ 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)
return;
auto Current_Region = track->GetVolume()->GetLogicalVolume()->GetRegion();
auto Tagger_Region = Geant4_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
21 changes: 14 additions & 7 deletions Biasing/src/Biasing/TargetBremFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
/*~~~~~~~~~~~~*/
#include "G4EventManager.hh"
#include "G4RunManager.hh"
#include "G4ParticleTable.hh"

/*~~~~~~~~~~~~~*/
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/UserEventInformation.h"
#include "SimCore/UserTrackInformation.h"
#include "SimCore/Geant4_PtrRetrieval.h"

namespace biasing {

Expand Down Expand Up @@ -60,9 +62,10 @@ 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)
auto Target_Region = Geant4_PtrRetrieval::GetRegion("target");
auto Track_Volume = track->GetVolume()->GetLogicalVolume()->GetRegion();
if (Track_Volume != Target_Region)
//if (auto region{track->GetVolume()->GetLogicalVolume()->GetRegion()} != Target_Region)
return;

/*
Expand All @@ -84,8 +87,10 @@ 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_PV = Geant4_PtrRetrieval::GetVolume("recoil_PV");
auto World_PV = Geant4_PtrRetrieval::GetVolume("World_PV");
auto volume = track->GetNextVolume(); // Declare volume separatelyi
if (volume == Recoil_PV or volume == World_PV) {
// If the recoil electron
if (track->GetMomentum().mag() >= recoilMaxPThreshold_) {
track->SetTrackStatus(fKillTrackAndSecondaries);
Expand All @@ -103,9 +108,11 @@ void TargetBremFilter::stepping(const G4Step* step) {
for (auto& secondary_track : *secondaries) {
G4String processName =
secondary_track->GetCreatorProcess()->GetProcessName();

if (processName.compareTo("eBrem") == 0 &&
auto electron = G4ParticleTable::GetParticleTable()->FindParticle("e-"); // Get the electron definition
auto eBrem_process = Geant4_PtrRetrieval::GetProcess(electron,"eBrem");
if (processName == eBrem_process->GetProcessName() &&
secondary_track->GetKineticEnergy() > bremEnergyThreshold_) {

auto trackInfo{simcore::UserTrackInformation::get(secondary_track)};
trackInfo->tagBremCandidate();

Expand Down
5 changes: 2 additions & 3 deletions Biasing/src/Biasing/TargetENProcessFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ void TargetENProcessFilter::stepping(const G4Step* step) {

// Get the volume the particle is in.
G4VPhysicalVolume* volume = track->GetVolume();
G4String volumeName = volume->GetName();

auto Target_Volume = Geant4_PtrRetrieval::GetVolume("target_PV");
// If the particle isn't in the target, don't continue with the processing.
if (volumeName.compareTo(volumeName_) != 0) return;
if (volume != Target_Volume) return;

/*std::cout << "*******************************" << std::endl;
std::cout << "* Step " << track->GetCurrentStepNumber() << std::endl;
Expand Down
16 changes: 9 additions & 7 deletions Biasing/src/Biasing/TargetProcessFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/* SimCore */
/*~~~~~~~~~~~~~*/
#include "SimCore/UserTrackInformation.h"
#include "SimCore/Geant4_PtrRetrieval.h"

namespace biasing {

Expand Down Expand Up @@ -60,9 +61,9 @@ void TargetProcessFilter::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) {
auto Target_Region = Geant4_PtrRetrieval::GetRegion("target");
auto Current_Region = track->GetVolume()->GetLogicalVolume()->GetRegion();
if (Target_Region != Current_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 brem.
Expand Down Expand Up @@ -97,9 +98,10 @@ void TargetProcessFilter::stepping(const G4Step* step) {
* We also check for 'World_PV' because in later geometries, there is
* an air gap between the target region and the recoil tracker.
*/
if (auto volume{track->GetNextVolume()->GetName()};
volume.compareTo("recoil_PV") == 0 or
volume.compareTo("World_PV") == 0) {
auto recoil_PhysicalVolume = Geant4_PtrRetrieval::GetVolume("recoil_PV");
auto World_PhysicalVolume = Geant4_PtrRetrieval::GetVolume("World_PV");
auto Current_Volume = track->GetNextVolume();
if (Current_Volume == recoil_PhysicalVolume or Current_Volume == World_PhysicalVolume) {
if (getEventInfo()->bremCandidateCount() == 1) {
track->SetTrackStatus(fKillTrackAndSecondaries);
G4RunManager::GetRunManager()->AbortEvent();
Expand Down Expand Up @@ -151,4 +153,4 @@ void TargetProcessFilter::stepping(const G4Step* step) {
void TargetProcessFilter::EndOfEventAction(const G4Event*) {}
} // namespace biasing

DECLARE_ACTION(biasing, TargetProcessFilter)
DECLARE_ACTION(biasing, TargetProcessFilter)
Loading
Loading