Advertisement
luizrosalba

GEANT4 - DetectorSD.cpp

Nov 17th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. #include "DetectorSD.hh"
  2. #include "G4HCofThisEvent.hh"
  3. #include "G4Step.hh"
  4. #include "G4Run.hh"
  5. #include "G4ThreeVector.hh"
  6. #include "G4SDManager.hh"
  7. #include "G4ios.hh"
  8.  
  9. void DetectorSD::SetContagens (int _ent)
  10. {
  11. contagens = _ent;
  12. }
  13. int DetectorSD::GetContagens ()
  14. {
  15. return (contagens);
  16. }
  17. DetectorSD::DetectorSD(G4String name)
  18. :G4VSensitiveDetector(name)
  19. {
  20.  
  21. G4String HCname;
  22. collectionName.insert(name);
  23. }
  24.  
  25. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  26.  
  27. DetectorSD::~DetectorSD(){
  28.  
  29. }
  30.  
  31. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  32.  
  33. void DetectorSD::Initialize(G4HCofThisEvent* HCE)
  34. {
  35. ///cada thread gera hitcollection[0]
  36. //// Nome do detector : Detector
  37. DetectorCollection = new DetectorHitsCollection (SensitiveDetectorName,collectionName[0]);
  38. static G4int HCID = -1;
  39. if(HCID<0)
  40. {
  41. HCID = GetCollectionID(0);
  42.  
  43. }
  44. HCE->AddHitsCollection( HCID, DetectorCollection );
  45.  
  46. }
  47.  
  48. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  49.  
  50. G4bool DetectorSD::ProcessHits(G4Step* aStep,G4TouchableHistory*)
  51. {
  52. //G4double edep = -1*(aStep->GetDeltaEnergy())/CLHEP::keV; /// bremss
  53. // G4double edep = (aStep->GetPostStepPoint()->GetKineticEnergy())/CLHEP::keV; /// nao ve particulas
  54. /// menos energeticas
  55.  
  56. G4double edep = aStep->GetPreStepPoint()->GetKineticEnergy()/CLHEP::keV; // o de sempre
  57.  
  58.  
  59.  
  60. G4String particleName = aStep -> GetTrack() -> GetDynamicParticle() ->
  61. GetDefinition() -> GetParticleName();
  62.  
  63.  
  64. int detector ;
  65. if(edep==0.) return false;
  66. //if (particleName == "gamma" ||particleName == "e-" )
  67. if (particleName == "gamma" )
  68. {
  69. contagens+=1;
  70.  
  71. DetectorHit* newHit = new DetectorHit();
  72. newHit->SetTrackID (aStep->GetTrack()->GetTrackID());
  73. newHit->SetEdep (edep);
  74. newHit->SetPos (aStep->GetPostStepPoint()->GetPosition());
  75.  
  76. // descomente para ver colisoes
  77. //G4cout << " colisao " << edep << " keV " << aStep->GetPostStepPoint()->GetPosition() <<G4endl;
  78. DetectorCollection->insert( newHit );
  79.  
  80.  
  81.  
  82. }
  83. return true;
  84. }
  85.  
  86. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  87.  
  88. void DetectorSD::EndOfEvent(G4HCofThisEvent*)
  89. {
  90.  
  91.  
  92.  
  93. if (verboseLevel>0) {
  94. G4int NbHits = DetectorCollection->entries();
  95. G4cout << "\n-------->Hits Collection: in this event they are " << NbHits
  96. << " hits in the Detector chambers: " << G4endl;
  97. for (G4int i=0;i<NbHits;i++) (*DetectorCollection)[i]->Print();
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement