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)
Re: Idea Re: Referencing/passing sensitive detector to analysis manager (Zach Hartwig)
Re: None Re: Referencing/passing sensitive detector to analysis manager (Bethany)
Date: 31 Aug, 2012
From: Zach Hartwig <Zach Hartwig>

Hi Bethany,

Your welcome.

> ... everything seems to work until the calling of the function. I'm not
> really sure of what syntax would be good. The function in my SD file is
> called Reset, and when I call it within the SD file where it's declared,
> I just have "Reset();". This doesn't work to call it here (Reset is not
> declared in this scope). I also tried ScintillatorSD.Reset(); since this
> is similar to how I call functions from AnalysisManager, but it doesn't
> like that either, although it doesn't tell me that the function is not
> declared; it complains about: error: expected unqualified-id before token. Does this mean I'm getting closer, or is there a specific way of
> doing this that I'm just unaware of?

The SD object that you obtain from the G4SDManager is *pointer* to an object. In the example I gave, you are obtaining a pointer to a concrete object of class type ScintillatorSD. The concrete object is named "SodiumIodideSD". In order to access member functions of a pointer you need to use the "->" syntax. Thus in your case, you probably want to do


> Does this have anything to do with your comment to "ensure that you cast
> the returned SD to the your SD class"? I'm really not sure what this>?
> means, could you explain further if that's something I should check on?>

The SD class that you are using is a *derived* class. In your SD class header file you inherit from the G4VSensitiveDetector class and implement your own methods (some of which are mandatory other are whatever you want, such as your Reset() function). In the example, to ensure that the object returned from G4SDManager is of type ScintillatorSD (the "derived" class) and NOT of type G4VSensitiveDetector (the "base" class), you must cast it as shown. This ensures you will have access to the methods that *you* implemented when you wrote your ScintillatorSD class.

I'd strongly recommend brushing up on your object oriented C++ (classes, member data and functions, inheritance, etc) as well as reviewing pointers, as much of Geant4 is based around this functionality.

Hope this helps.

 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 ]