Commit a7fecbde authored by MARCOS ANTONIO DE OLIVEIRA DEROS's avatar MARCOS ANTONIO DE OLIVEIRA DEROS

changes to handle Tracking Action class

parents 53adc2a8 bad8a766
......@@ -30,6 +30,7 @@ include_directories(${PROJECT_SOURCE_DIR}/include)
#
set(PROJECT_SRC
<<<<<<< HEAD
src/ActionInitialization.cc
src/DetectorConstruction.cc
src/EventAction.cc
......@@ -46,6 +47,26 @@ include/PrimaryGeneratorAction.hh
include/RunAction.hh
include/SteppingAction.hh
include/Analysis.hh
=======
src/B1ActionInitialization.cc
src/B1DetectorConstruction.cc
src/B1EventAction.cc
src/B1PrimaryGeneratorAction.cc
src/B1RunAction.cc
src/B1SteppingAction.cc
src/B1TrackingAction.cc
)
set(PROJECT_HEADER
include/B1ActionInitialization.hh
include/B1DetectorConstruction.hh
include/B1EventAction.hh
include/B1PrimaryGeneratorAction.hh
include/B1RunAction.hh
include/B1SteppingAction.hh
include/B1Analysis.hh
include/B1TrackingAction.hh
>>>>>>> print_particles
)
#----------------------------------------------------------------------------
......
......@@ -59,7 +59,7 @@ int main(int argc,char** argv)
// Choose the Random engine
G4Random::setTheEngine(new CLHEP::RanecuEngine);
// Construct the default run manager
//
#ifdef G4MULTITHREADED
......@@ -71,17 +71,27 @@ int main(int argc,char** argv)
// Set mandatory initialization classes
//
// Detector construction
<<<<<<< HEAD
runManager->SetUserInitialization(new DetectorConstruction());
=======
B1DetectorConstruction* detector = new B1DetectorConstruction();
runManager->SetUserInitialization(detector);
>>>>>>> print_particles
// Physics list - FTFP_BERT - p/shower
// added verbose to the physics list
G4int verbose = 0;
G4VModularPhysicsList* physicsList = new FTFP_BERT;
runManager->SetUserInitialization(physicsList);
// User action initialization
<<<<<<< HEAD
runManager->SetUserInitialization(new ActionInitialization());
=======
runManager->SetUserInitialization(new B1ActionInitialization(detector));
>>>>>>> print_particles
// Initialize visualization
// (if you don't want the image, just delete the G4VisManager objetc and everything that concerns it)
G4VisManager* visManager = new G4VisExecutive;
......@@ -94,13 +104,13 @@ int main(int argc,char** argv)
// Process macro or start UI session
// (you can delete this if-clause too.)
if ( ! ui ) {
if ( ! ui ) {
// batch mode
G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command+fileName);
}
else {
else {
// interactive mode
UImanager->ApplyCommand("/control/execute init_vis.mac");
ui->SessionStart();
......@@ -109,9 +119,9 @@ int main(int argc,char** argv)
// Job termination
// Free the store: user actions, physics_list and detector_description are
// owned and deleted by the run manager, so they should not be deleted
// owned and deleted by the run manager, so they should not be deleted
// in the main() program !
delete visManager; //(delete this line too if you don't want image).
delete runManager;
}
......
......@@ -33,12 +33,22 @@
#include "G4VUserActionInitialization.hh"
/// Action initialization class.
class B1DetectorConstruction;
class ActionInitialization : public G4VUserActionInitialization
{
private:
B1DetectorConstruction* fDetectorConstruction;
public:
<<<<<<< HEAD:include/ActionInitialization.hh
ActionInitialization();
virtual ~ActionInitialization();
=======
B1ActionInitialization(B1DetectorConstruction *Detector);
virtual ~B1ActionInitialization();
>>>>>>> print_particles:include/B1ActionInitialization.hh
virtual void BuildForMaster() const;
virtual void Build() const;
......@@ -47,5 +57,3 @@ class ActionInitialization : public G4VUserActionInitialization
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
#ifndef TrackingAction_h
#define TrackingAction_h
#include "G4UserTrackingAction.hh"
#include "G4LogicalVolume.hh"
#include <map>
class G4Region;
class G4ParticleDefinition;
class B1DetectorConstruction;
class B1TrackingAction : public G4UserTrackingAction
{
private:
//aqui ficam as variáveis da classe
B1DetectorConstruction* fworld;
G4Region* fworldRegion;
G4LogicalVolume* worldVolume;
const G4ParticleDefinition* particle_def;
std::map<const G4ParticleDefinition*, int> fNParticleOutsideWorld;
std::map<const G4ParticleDefinition*, int> fNParticleInWorld;
public:
//aqui ficam as funçes que a classe terá
B1TrackingAction(B1DetectorConstruction* world); //construtor
~B1TrackingAction(); //destrutor
virtual void PreUserTrackingAction(const G4Track* track);
std::map<const G4ParticleDefinition*, int>& GetNParticlesCreatedOutsideWorld()
{
return fNParticleOutsideWorld;
}
std::map<const G4ParticleDefinition*, int>& GetNParticlesCreatedInWorld()
{
return fNParticleInWorld;
}
void clearParticles();
};
#endif
......@@ -31,10 +31,13 @@
#define RunAction_h 1
#include "G4UserRunAction.hh"
#include "G4ParticleDefinition.hh"
#include "G4Accumulable.hh"
#include "globals.hh"
#include <map>
class G4Run;
class B1TrackingAction;
/// Run action class
///
......@@ -52,6 +55,7 @@ class RunAction : public G4UserRunAction
virtual void BeginOfRunAction(const G4Run*);
virtual void EndOfRunAction(const G4Run*);
void PrintParticles(std::map<const G4ParticleDefinition*, int>& container);
void AddEdep (G4double edep);
private:
......@@ -60,6 +64,8 @@ class RunAction : public G4UserRunAction
void WriteHistogram();
G4Accumulable<G4double> fEdep;
G4Accumulable<G4double> fEdep2;
B1TrackingAction* fptrackingAction;
};
#endif
......@@ -27,6 +27,7 @@
/// \file B1ActionInitialization.cc
/// \brief Implementation of the B1ActionInitialization class
<<<<<<< HEAD:src/ActionInitialization.cc
#include "ActionInitialization.hh"
#include "PrimaryGeneratorAction.hh"
#include "RunAction.hh"
......@@ -37,6 +38,20 @@
ActionInitialization::ActionInitialization()
: G4VUserActionInitialization()
=======
#include "B1ActionInitialization.hh"
#include "B1PrimaryGeneratorAction.hh"
#include "B1RunAction.hh"
#include "B1EventAction.hh"
#include "B1SteppingAction.hh"
#include "B1TrackingAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B1ActionInitialization::B1ActionInitialization(B1DetectorConstruction *Detector)
: G4VUserActionInitialization(),
fDetectorConstruction(Detector)
>>>>>>> print_particles:src/B1ActionInitialization.cc
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -58,6 +73,7 @@ void ActionInitialization::Build() const
{
SetUserAction(new PrimaryGeneratorAction);
<<<<<<< HEAD:src/ActionInitialization.cc
RunAction* runAction = new RunAction;
SetUserAction(runAction);
......@@ -66,5 +82,19 @@ void ActionInitialization::Build() const
SetUserAction(new SteppingAction(eventAction));
}
=======
//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));
}
>>>>>>> print_particles:src/B1ActionInitialization.cc
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "B1TrackingAction.hh"
#include "G4Track.hh"
#include "G4VSolid.hh"
#include "G4Region.hh"
#include "B1DetectorConstruction.hh"
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();
}
......@@ -43,7 +43,7 @@
PrimaryGeneratorAction::PrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction(),
fParticleGun(0),
fParticleGun(0),
fEnvelopeBox(0)
{
G4int n_particle = 1;
......@@ -77,12 +77,11 @@ void PrimaryGeneratorAction::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......
......@@ -27,10 +27,19 @@
/// \file B1RunAction.cc
/// \brief Implementation of the B1RunAction class
<<<<<<< HEAD:src/RunAction.cc
#include "RunAction.hh"
#include "PrimaryGeneratorAction.hh"
#include "DetectorConstruction.hh"
#include "SteppingAction.hh"
=======
#include "B1RunAction.hh"
#include "B1PrimaryGeneratorAction.hh"
#include "B1DetectorConstruction.hh"
#include "B1SteppingAction.hh"
//adicionando Tracking Action
#include "B1TrackingAction.hh"
>>>>>>> print_particles:src/B1RunAction.cc
// #include "B1Run.hh"
// Adicionando header de análise de dados:
#include "Analysis.hh"
......@@ -79,6 +88,13 @@ RunAction::~RunAction()
void RunAction::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);
......@@ -133,6 +149,7 @@ void RunAction::EndOfRunAction(const G4Run* run)
// Print
//
if (IsMaster()) {
G4cout
<< G4endl
......@@ -155,9 +172,27 @@ void RunAction::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......
......@@ -209,5 +244,18 @@ void RunAction::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......
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