00001
00002
00003 #include "musrShieldSD.hh"
00004 #include "G4HCofThisEvent.hh"
00005 #include "G4Step.hh"
00006 #include "G4ThreeVector.hh"
00007 #include "G4SDManager.hh"
00008 #include "G4ios.hh"
00009
00010
00016
00017 musrShieldSD::musrShieldSD(G4String name)
00018 :G4VSensitiveDetector(name)
00019 {
00020 G4String HCname;
00021 collectionName.insert(HCname="shieldCollection");
00022 }
00023
00024
00025
00026 musrShieldSD::~musrShieldSD(){ }
00027
00028
00029
00030 void musrShieldSD::Initialize(G4HCofThisEvent* HCE)
00031 {
00032 shieldCollection = new musrShieldHitsCollection
00033 (SensitiveDetectorName,collectionName[0]);
00034 static G4int HCID = -1;
00035 if(HCID<0)
00036 { HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); }
00037 HCE->AddHitsCollection( HCID, shieldCollection );
00038 }
00039
00040
00041
00042 G4bool musrShieldSD::ProcessHits(G4Step* aStep,G4TouchableHistory*)
00043 {
00048 G4double edep = aStep->GetTotalEnergyDeposit();
00049
00050 if(edep==0.) return false;
00051
00052 musrShieldHit* newHit = new musrShieldHit();
00053 newHit->SetParticleName (aStep->GetTrack()->GetDefinition()->GetParticleName());
00054 newHit->SetTrackID (aStep->GetTrack()->GetTrackID());
00055 newHit->SetEdep (edep);
00056 newHit->SetPos (aStep->GetPostStepPoint()->GetPosition());
00057 newHit->SetPol (aStep->GetTrack()->GetPolarization());
00058 newHit->SetLogVolName (aStep->GetTrack()->GetVolume()->GetLogicalVolume()->GetName());
00059 shieldCollection->insert( newHit );
00060
00061 newHit->Print();
00062 newHit->Draw();
00063
00064
00065
00066 return true;
00067 }
00068
00069
00070
00071 void musrShieldSD::EndOfEvent(G4HCofThisEvent*)
00072 {
00073 if (verboseLevel>0) {
00074 G4int NbHits = shieldCollection->entries();
00075 G4cout << "\n-------->Hits Collection: in this event they are " << NbHits
00076 << " hits: " << G4endl;
00077 for (G4int i=0;i<NbHits;i++) (*shieldCollection)[i]->Print();
00078 }
00079 }
00080
00081
00082