Message: Re: Confusing with ExN02TrackerSD::Initialize() Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Confusing with ExN02TrackerSD::Initialize() 

Forum: Documentation and Examples
Re: Question Confusing with ExN02TrackerSD::Initialize() (Gu W.Q.)
Date: 10 Nov, 2010
From: Michael H. Kelsey <Michael H. Kelsey>

On Wed, 10 Nov 2010 14:38:56 GMT, Gu W.Q. wrote:
> ExN02TrackerSD::ExN02TrackerSD(G4String name)
>   :G4VSensitiveDetector(name)
>   {
>     G4String HCname;
>     collectionName.insert(HCname="trackerCollection");
>   }
> 
> void ExN02TrackerSD::Initialize(G4HCofThisEvent* HCE)                           
>  {     
>     trackerCollection = new ExN02TrackerHitsCollection                            
>                             (SensitiveDetectorName,collectionName[0]);            
>     static G4int HCID = -1;
>     if(HCID<0) 
>     { HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); }  
>     HCE->AddHitsCollection HCID, trackerCollection );         
>   }
> 
> I know that ExN02TrackerSD::Initialize() is invoked at the beginning of
> each event. But what does " collectionName[0] " mean?

collectionName is a list. The [0] subscript references the first item in the list (C and C++ index starting with zero, not with one).

 Why can we use it
> to get a CollectionID, while not collectionName[1]?

Look at the constructor:

> collectionName.insert(HCname="trackerCollection");

"collectionName" is a std::vector<>, to which you have only added a single element. Therefore, collectionName[1] is undefined. If you want to define multiple collections with different names, then modify the constructor to put multiple names onto the list (I'd use "push_back()" rather than "insert()" in that case).

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

1 None: Re: Confusing with ExN02TrackerSD::Initialize()   (Gu W.Q. - 13 Nov, 2010)
 Add Message Add Message
to: "Re: Confusing with ExN02TrackerSD::Initialize()"

 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 ]