What's the reason to use G4VHit

I have set up a SensitiveDetector and it has the method of ProcessHits to do some actions when hit happen. What i what to do in ProcessHits is to simply record hits.

I find in the Geant4 examples like advanced/air_shower, they create a G4VHit class called UltraOpticalHit and make a UltraOpticalHitsCollection. And then in their ProcessHits, they create UltraOpticalHit object and put it into UltraOpticalHitsCollection. At last in the EventAction, they call UltraOpticalHitsCollection and use G4AnalysisManager to record hits.

My question is: can we just call G4AnalysisManager and record the information at SensitiveDetector::ProcessHits? What’s the reason to use G4VHit in that example?

Hallo, in general, yes, you can store the hits information either directly in an analysis object and then you do the analysis in post-processing or in a HitsCollection. In the last case you can access the HitsCollection at the level of the event/run and do some processing before storing the information in an analysis object.

If you would like to know why the author of the example chose that option, please contact him via e-mail. The webpage of the Advanced Examples is https://geant4.web.cern.ch/collaboration/working_groups/advanced_examples

The author e-mail is there.

Thanks for reply. :grinning:

Do you mean the point is the following?

you can access the HitsCollection at the level of the event/run and do some processing before storing the information in an analysis object.

I am wondering is there any other concerns? For example, is doing analysis in a HitsCollection more efficient than in post-processing?

It really depends on your application. If your simulation stops with the hits, then you could certainly write your SD to fill a G4analysis N-tuple directly, and bypass the extra step of filling a collection, then transferring that info to an N-tuple.

Geant4 supports more complex simulations, including things like detector response, digitization, and readout. In those cases, the subsequent stages can look for HitsCollections semi-automatically, and then process those hits further.

1 Like