Message: Primitive scoring -- Energy deposition Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Primitive scoring -- Energy deposition 

Forum: Hits, Digitization and Pileup
Date: 08 Jun, 2010
From: RY <RY>

Hi,

I'm having some trouble extracting the total energy deposited in each of two logical volumes. What additional code (in RunAction.cc and elsewhere?) is required as I have already added Run to the TestEM4 example. I think I may be missing some access methods in the header file for Run.

// DetectorConstruction.cc

#include "DetectorConstruction.hh"
#include "G4NistManager.hh"

#include "G4Material.hh"
#include "G4Tubs.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"

#include "G4SDManager.hh"

#include "G4MultiFunctionalDetector.hh"
#include "G4VPrimitiveScorer.hh"
#include "G4PSEnergyDeposit.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorConstruction::DetectorConstruction() {}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorConstruction::~DetectorConstruction() {}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

G4VPhysicalVolume* DetectorConstruction::Construct() {

---------- Code snipped here --------------

  //  Scoring

  G4MultiFunctionalDetector* scoreBGO = new G4MultiFunctionalDetector("BGOscorer");
  G4SDManager::GetSDMpointer()->AddNewDetector(scoreBGO);
  logicBGO->SetSensitiveDetector(scoreBGO);
  G4VPrimitiveScorer* edepBGO = new G4PSEnergyDeposit("BGOenergy");
  scoreBGO->RegisterPrimitive(edepBGO);

  G4MultiFunctionalDetector* scorePlastic = new G4MultiFunctionalDetector("Plasticscorer");
  G4SDManager::GetSDMpointer()->AddNewDetector(scorePlastic);
  logicPlastic->SetSensitiveDetector(scorePlastic);
  G4VPrimitiveScorer* edepPlastic = new G4PSEnergyDeposit("Plasticenergy");
  scorePlastic->RegisterPrimitive(edepPlastic);

  //
  //always return the physical World
  //  
  return physiWorld;
}

// RunAction.cc

#include "RunAction.hh"
#include "Run.hh"

#include "G4Run.hh"
#include "G4RunManager.hh"

#include "G4THitsMap.hh"

#include "Randomize.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

RunAction::RunAction() {;}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

RunAction::~RunAction() {;}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

G4Run* RunAction::GenerateRun() {return new Run;}

void RunAction::BeginOfRunAction(const G4Run* aRun)
{
  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;

  // save Rndm status
  G4RunManager::GetRunManager()->SetRandomNumberStore(true);
  CLHEP::HepRandom::showEngineStatus();
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void RunAction::EndOfRunAction(const G4Run* aRun)
{
  // show Rndm status
  CLHEP::HepRandom::showEngineStatus();

  const Run* theRun = (const Run*)aRun;

  //G4THitsMap<G4double>* totEdep = theRun->GetHitsMap("BGOscorer/BGOenergy");
}

// RunAction.hh

#ifndef RunAction_h
#define RunAction_h 1

#include "G4UserRunAction.hh"
#include "globals.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

class G4Run;

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

class RunAction : public G4UserRunAction
{
  public:
    RunAction();
   ~RunAction();

  public:
	G4Run* GenerateRun();
    void BeginOfRunAction(const G4Run*);
    void EndOfRunAction(const G4Run*);

  private:   
};

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

#endif

// Run.cc

#include "Run.hh"
#include "G4Event.hh"
#include "G4HCofThisEvent.hh"
#include "G4SDManager.hh"

Run::Run():nEvent(0)
{
	G4SDManager* SDM = G4SDManager::GetSDMpointer();
	edepBGOid = SDM->GetCollectionID("BGOscorer/BGOenergy");
	edepPlasticid = SDM->GetCollectionID("Plasticscorer/Plasticenergy");
}

Run::~Run() {;}

void Run::RecordEvent(const G4Event* evt)
{
	nEvent++;
	G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
	eventedepBGO = (G4THitsMap<G4double>*)(HCE->GetHC(edepBGOid));
	eventedepPlastic = (G4THitsMap<G4double>*)(HCE->GetHC(edepPlasticid));
	edepBGO += *eventedepBGO;
	edepPlastic += *eventedepPlastic;
}

// Run.hh

#include "G4Run.hh"
#include "G4Event.hh"
#include "G4THitsMap.hh"

class G4Event;

class Run: public G4Run
{
public:
	Run();
	virtual ~Run();
	virtual void RecordEvent(const G4Event*);
  // - Get HitsMap of this RUN.
  //   by sequential number, by multifucntional name and collection name,
  //   and by collection name with full path.
  //G4THitsMap<G4double>* GetHitsMap(const G4String& detName, 
	//			  const G4String& colName);
private:
	G4int nEvent;
	G4int edepBGOid, edepPlasticid;
	G4THitsMap<G4double> edepBGO;
	G4THitsMap<G4double> edepPlastic;
	G4THitsMap<G4double>* eventedepBGO;
	G4THitsMap<G4double>* eventedepPlastic;

public:

	//  Need to insert access methods here ie for edepBGO
};

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

1 None: Re: Primitive scoring -- Energy deposition   (Tsukasa Aso - 08 Jun, 2010)
 Add Message Add Message
to: "Primitive scoring -- Energy deposition"

 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 ]