changed to print particle and handle with Tracking action class

parent 68eee290
......@@ -32,11 +32,13 @@
#include "B1RunAction.hh"
#include "B1EventAction.hh"
#include "B1SteppingAction.hh"
#include "B1TrackingAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B1ActionInitialization::B1ActionInitialization()
: G4VUserActionInitialization()
B1ActionInitialization::B1ActionInitialization(B1DetectorConstruction *Detector)
: G4VUserActionInitialization(),
fDetectorConstruction(Detector)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -58,13 +60,17 @@ void B1ActionInitialization::Build() const
{
SetUserAction(new B1PrimaryGeneratorAction);
//adicionando Tracking Action
B1TrackingAction* trackingAction = new B1TrackingAction(fDetectorConstruction); //cria objeto trackingAction, da classe B1TrackingAction
SetUserAction(trackingAction);
B1RunAction* runAction = new B1RunAction;
SetUserAction(runAction);
B1EventAction* eventAction = new B1EventAction(runAction);
SetUserAction(eventAction);
SetUserAction(new B1SteppingAction(eventAction));
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -43,7 +43,7 @@
B1PrimaryGeneratorAction::B1PrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction(),
fParticleGun(0),
fParticleGun(0),
fEnvelopeBox(0)
{
G4int n_particle = 1;
......@@ -77,12 +77,11 @@ void B1PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
// on DetectorConstruction class we get Envelope volume
// from G4LogicalVolumeStore.
fParticleGun->SetParticlePosition(G4ThreeVector(0,0,-101.*m));
fParticleGun->SetParticlePosition(G4ThreeVector(0,0,-100.*m));
fParticleGun->GeneratePrimaryVertex(anEvent);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -31,6 +31,8 @@
#include "B1PrimaryGeneratorAction.hh"
#include "B1DetectorConstruction.hh"
#include "B1SteppingAction.hh"
//adicionando Tracking Action
#include "B1TrackingAction.hh"
// #include "B1Run.hh"
// Adicionando header de análise de dados:
#include "B1Analysis.hh"
......@@ -77,6 +79,13 @@ B1RunAction::~B1RunAction()
void B1RunAction::BeginOfRunAction(const G4Run*)
{
bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == G4RunManager::sequentialRM);
if (sequential) {
G4cout << "aaaa" << G4endl;
fptrackingAction = (B1TrackingAction*) G4RunManager::GetRunManager()->GetUserTrackingAction();
G4cout << "bbbb" << G4endl;
}
createHistogram();
// inform the runManager to save random number seed
G4RunManager::GetRunManager()->SetRandomNumberStore(false);
......@@ -131,6 +140,7 @@ void B1RunAction::EndOfRunAction(const G4Run* run)
// Print
//
if (IsMaster()) {
G4cout
<< G4endl
......@@ -153,9 +163,27 @@ void B1RunAction::EndOfRunAction(const G4Run* run)
<< G4endl
<< G4endl;
//salva os histogramas
WriteHistogram();
WriteHistogram();
delete G4AnalysisManager::Instance();
//printando partículas criadas
std::map<const G4ParticleDefinition*, int>&
particlesCreatedInWorld = fptrackingAction->GetNParticlesCreatedInWorld();
G4cout << "Partículas criadas dentro do mundo :" << G4endl;
PrintParticles(particlesCreatedInWorld);
G4cout << "_______________________" << G4endl;
std::map<const G4ParticleDefinition*, int>&
particlesCreatedOutsideWorld = fptrackingAction->GetNParticlesCreatedOutsideWorld();
G4cout << "Prtículas criadas fora do mundo :" << G4endl;
PrintParticles(particlesCreatedOutsideWorld);
//limpa dados
fptrackingAction->clearParticles();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -207,5 +235,18 @@ void B1RunAction::WriteHistogram()
}
//função para printar partículas
void B1RunAction::PrintParticles(std::map<const G4ParticleDefinition*, int>& container) {
std::map<const G4ParticleDefinition*, int>::iterator it;
G4cout << "aa" << G4endl;
for(it = container.begin() ;it != container.end(); it ++)
{
G4cout << "N " << it->first->GetParticleName() << " : " << it->second << G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef TrackingAction_h
#define TrackingAction_h
#include "B1TrackingAciont.hh"
#include "B1TrackingAction.hh"
#include "G4Track.hh"
#include "G4VSolid.hh"
#include "G4Region.hh"
#include "DetectorConstruction.hh"
#include "B1DetectorConstruction.hh"
void B1TrackingAction::PreUserT
using namespace std;
//implementação do construtor
B1TrackingAction::B1TrackingAction(B1DetectorConstruction* world) {
fworld = world;
fworldRegion = 0;
worldVolume = 0;
}
//implementação do destrutor
B1TrackingAction::~B1TrackingAction() {
fworld = 0;
fworldRegion = 0;
worldVolume = 0;
}
//implementação da função(instância da classe B1TrackingAction) PreUserTrackingAction
void B1TrackingAction::PreUserTrackingAction(const G4Track* track) {
//pega o nome da partícula relacionado ao seu TrackID.
particle_def = track->GetParticleDefinition();
//const G4String& particle_name = particle_def->GetParticleName();
//se a variável fworldRegio não possui a regiao do mundo, fazer isso
if(fworldRegion == 0) {
worldVolume= fworld->GetScoringVolume();
fworldRegion = worldVolume->GetRegion();
}
const G4ThreeVector& position = track->GetPosition();
int N = fworldRegion->GetNumberOfRootVolumes();
std::vector<G4LogicalVolume*>::iterator it_logicalVolumeInRegion = fworldRegion->GetRootLogicalVolumeIterator();
bool inside_world = false;
//checar se está dentro do mundo
for(int i = 0; i < N ; i++, it_logicalVolumeInRegion++)
{
EInside test_status = (*it_logicalVolumeInRegion)->GetSolid()->Inside(position) ;
if(test_status == kInside)
{
inside_world = true;
break;
}
}
//coloca eles no std::map
if (inside_world) {
fNParticleInWorld[particle_def]++;
} else {
fNParticleOutsideWorld[particle_def]++;
}
}
void B1TrackingAction::clearParticles() {
fNParticleInWorld.clear();
fNParticleOutsideWorld.clear();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment