Message: Re: Referencing/passing sensitive detector to analysis manager Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: Referencing/passing sensitive detector to analysis manager 

Forum: Event and Track Management
Re: None Referencing/passing sensitive detector to analysis manager (Bethany)
Date: 30 Aug, 2012
From: Zach Hartwig <Zach Hartwig>

Hi Bethany

> Here is the issue that I'm having. I have a stepping action file in my
> simulation which has information I need to use to know when to call a
> function in my sensitive detector file. 

Typically the sensitive detector ("SD" hereafter) is triggered automatically during tracking provided it has been attached to logical volume present in the geometry. But I'll assume you have your reasons for triggering manually from a user action class...

> What I need to do is to pass the sensitive detector to either the stepping 
> action or analysis manager file, so that I can call a function from 
> sensitive detector from one of those two places ...
>
> I have tried to do this by passing the sensitive detector to either the
> stepping action or analysis manager files as the analysis manager is
> passed to the stepping action and analysis manager files...

I would not suggest trying to pass your SDs from class to class in the manner you suggest. Geant4, in fact, has a built-in solution to your oft-encountered use case!

The best and easiest way to access your active SDs is to use the G4SDManager class. The G4SDManager is a "singleton" class (meaning there is only a single concrete object instantiated when you execute your binary) that provides static access to itself (meaning that you can "grab" the concrete G4SDManager object from anywhere in your code via a static call and use the provided functions to access your SDs).

For example, let's assume you created an SD object of type "ScintillatorSD" in your detector construction and called it "SodiumIodideSD". You can access this SD from your user stepping action in the following way:

  #include "G4SDManager.hh"

  #include "ScintillatorSD.hh"

  // ... other code here ... //

  void SteppingAction::UserSteppingAction(const G4Step *CurrentStep)
  {

    // ... code to determine when to trigger ScintillatorSD ... //
    TriggerScintillatorSD = true;

    if(TriggerScintillatorSD){
       ScintillatorSD *SodiumIodideSD = (ScintillatorSD *)G4SDManager::GetSDMpointer()->FindSensitiveDetector("SodiumIodideSD",false);
       if(SodiumIodideSD){
         // ... call your SD function here ... //
       }
    }
  }

You must ensure that you call the G4SDManager::FindSensitiveDetector() method *after* you initialize your geometry with the G4RunManager otherwise the method will return a null pointer (since the SD hasn't been created and attached to the geometry yet!). Also, you must ensure that you cast the returned SD to the your SD class in order to access the derived methods that you want to call manually.

Hope this helps.

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Referencing/passing sensitive detector to analysis manager   (Bethany - 31 Aug, 2012)
(_ Idea: Re: Referencing/passing sensitive detector to analysis manager   (Zach Hartwig - 31 Aug, 2012)
 Add Message Add Message
to: "Re: Referencing/passing sensitive detector to analysis manager"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]