Message: How should I modify novice example 2? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question How should I modify novice example 2? 

Keywords: Sensitive Detector
Forum: Documentation and Examples
Date: 08 Feb, 2005
From: Joel <Joel>

I am trying to learn Geant4 and want to modify example 2 to get the coordinate for the particle when it hits the sensitive detectors. I have created a class and and tried to use them in and EndOfEventAction. But it I get error in line ExN02Detector* DCH1= ExN02Detector*; and if I use ExN02Detector* DCH1; instead I get a segmentation fault.

/ $Id:

#include "ExN02Detector.hh"

#include "G4VPhysicalVolume.hh" 
#include "G4Step.hh"
#include "G4Track.hh"
#include "G4VTouchable.hh"
#include "G4TouchableHistory.hh"
#include "G4VProcess.hh"

////////////////////////////// // Class description /////////////////////////////

ExN02Detector::ExN02Detector(const G4String& name): G4VSensitiveDetector(name)
  collectionName.insert("Detector hit");

void ExN02Detector::Initialize(G4HCofThisEvent* HCTE) {

  DetectorHitsCollection=new ExN02DetectorHitCollection(SensitiveDetectorName, collectionName[0]);

  G4int DetectorID = GetCollectionID(0);
  HCTE -> AddHitsCollection(DetectorID, DetectorHitsCollection);


G4bool ExN02Detector::ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist)
  // Step information
  const G4StepPoint* preStepPoint = aStep-> GetPreStepPoint();

  G4TouchableHandle theTouchable = preStepPoint->GetTouchableHandle();

  G4VPhysicalVolume* theMotherPhysical = theTouchable->GetVolume(1);
  G4int idc = theMotherPhysical->GetCopyNo();
  //G4int idc =0;//  aStep-> GetTrack() -> GetDefinition() -> theMotherPtr->GetCopyNo();
  G4int copyNo = preStepPoint->GetPhysicalVolume()-> GetCopyNo();
  G4int trackN = aStep -> GetTrack() -> GetTrackID();
  G4ThreeVector p   = preStepPoint -> GetMomentum();
  G4ThreeVector pos = preStepPoint -> GetPosition();
  G4double tof = preStepPoint -> GetGlobalTime();
  G4double depositE = aStep -> GetTotalEnergyDeposit(); 
  G4double kE = aStep -> GetPreStepPoint() -> GetKineticEnergy();
  G4double vE = aStep -> GetTrack() -> GetVertexKineticEnergy();

  if (aStep-> GetPreStepPoint()->GetProcessDefinedStep()!=NULL)
      G4String process = aStep->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName(); 

      G4String particle = aStep->GetTrack()->GetDefinition()->GetParticleName();

      ExN02DetectorHit* dHit = new ExN02DetectorHit(idc, copyNo,trackN, pos, p, tof, kE, depositE,vE, process, particle);

  return true;

void ExN02Detector::EndOfEvent(G4HCofThisEvent* HCTE){}

void ExN02Detector::PrintAll()
  G4int nHit=DetectorHitsCollection->entries();
             DetectorHitsCollection -> PrintAllHits();


void ExN02EventAction::EndOfEventAction(const G4Event* evt)
//  const G4RunManager* runManager=G4RunManager::GetRunManager();
//  const G4UserRunAction* usrRunAction= runManager->GetUserRunAction();
  G4SDManager* SDManager = G4SDManager::GetSDMpointer();

  ExN02Detector* DCH1= ExN02Detector*;

  SDManager-> FindSensitiveDetector("/beamtest/DCH1");



#include "g4std/iomanip"
#include "ExN02DetectorHit.hh"

G4Allocator<ExN02DetectorHit> ExN02DetectorHitAllocator;

ExN02DetectorHit::ExN02DetectorHit(G4int idc, G4int iplane, G4int trkno,
				   const G4ThreeVector& pos,
				   const G4ThreeVector& p,
				   G4double atof,
				   G4double kE,
				   G4double edep,
				   G4double vE,
				   const G4String process,
				   const G4String particle)
  : DCHID(idc),

void ExN02DetectorHit::Print() {

} ------------------------------------------------------------------

  // Sensitive detectors in

  G4SDManager* SDman = G4SDManager::GetSDMpointer();

  ExN02Detector* DCH1=new ExN02Detector("/beamtest/DCH1");

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

1 More: Re: How should I modify novice example 2?   (Joel - 09 Feb, 2005)
 Add Message Add Message
to: "How should I modify novice example 2?"

 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 ]