B1SD.cc 1.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#include "B1SD.hh"

#include "G4HCofThisEvent.hh"
#include "G4TouchableHistory.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include "G4SDManager.hh"
#include "G4ios.hh"

B1SD::B1SD(G4String SDname): G4VSensitiveDetector(SDname),
11
  hitCollection(nullptr), HCID(-1) {
12
  G4cout << "Criando Hit Collection com nome: " << SDname <<G4endl;
13
  collectionName.insert(SDname);
14 15
  track_id = 0;
  sdname = SDname;
16 17 18 19 20 21 22 23
}

B1SD::~B1SD() {

}

G4bool B1SD::ProcessHits(G4Step* step, G4TouchableHistory* ROhist) {
  G4TouchableHandle touchable = step->GetPreStepPoint()->GetTouchableHandle();
24 25 26
  const G4String particle_name = step->GetTrack()->GetDynamicParticle()->GetParticleDefinition()->GetParticleName();
  //G4cout << particle_def->GetParticleName() << G4endl;
  G4int track = step->GetTrack()->GetTrackID();
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  /*
  G4cout << sdname << G4endl;
  G4cout << track << G4endl;
  G4cout << track_id << G4endl;
  */

  if (track == track_id) {
    if (track == 0) {
      B1Hits* hit = new B1Hits();
      hit->set_partdef(particle_name);
      hitCollection->insert(hit);
      track_id = track;
      return true;
    }
    return true;
  } else {
43 44 45 46 47 48 49
    B1Hits* hit = new B1Hits();
    hit->set_partdef(particle_name);
    hitCollection->insert(hit);
    track_id = track;
    return true;
  }

50 51 52 53 54 55 56
}

void B1SD::Initialize(G4HCofThisEvent* HCE) {
  hitCollection = new B1HitsCollection(SensitiveDetectorName,collectionName[0]);
  if (HCID < 0) HCID = GetCollectionID(0);
  HCE->AddHitsCollection(HCID, hitCollection);
}