B1TrackingAction.cc 1.82 KB
Newer Older
1

2
#include "B1TrackingAction.hh"
3 4 5
#include "G4Track.hh"
#include "G4VSolid.hh"
#include "G4Region.hh"
6
#include "B1DetectorConstruction.hh"
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
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();
}