|
Geant4 examples
|
00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // $Id$ 00027 // 00030 00031 #include "B2TrackerSD.hh" 00032 #include "G4HCofThisEvent.hh" 00033 #include "G4Step.hh" 00034 #include "G4ThreeVector.hh" 00035 #include "G4SDManager.hh" 00036 #include "G4ios.hh" 00037 00038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00039 00040 B2TrackerSD::B2TrackerSD(const G4String& name, 00041 const G4String& hitsCollectionName) 00042 : G4VSensitiveDetector(name), 00043 fHitsCollection(NULL) 00044 { 00045 collectionName.insert(hitsCollectionName); 00046 } 00047 00048 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00049 00050 B2TrackerSD::~B2TrackerSD() 00051 {} 00052 00053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00054 00055 void B2TrackerSD::Initialize(G4HCofThisEvent* hce) 00056 { 00057 // Create hits collection 00058 00059 fHitsCollection 00060 = new B2TrackerHitsCollection(SensitiveDetectorName, collectionName[0]); 00061 00062 // Add this collection in hce 00063 00064 G4int hcID 00065 = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); 00066 hce->AddHitsCollection( hcID, fHitsCollection ); 00067 } 00068 00069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00070 00071 G4bool B2TrackerSD::ProcessHits(G4Step* aStep, 00072 G4TouchableHistory*) 00073 { 00074 // energy deposit 00075 G4double edep = aStep->GetTotalEnergyDeposit(); 00076 00077 if (edep==0.) return false; 00078 00079 B2TrackerHit* newHit = new B2TrackerHit(); 00080 00081 newHit->SetTrackID (aStep->GetTrack()->GetTrackID()); 00082 newHit->SetChamberNb(aStep->GetPreStepPoint()->GetTouchableHandle() 00083 ->GetCopyNumber()); 00084 newHit->SetEdep(edep); 00085 newHit->SetPos (aStep->GetPostStepPoint()->GetPosition()); 00086 00087 fHitsCollection->insert( newHit ); 00088 00089 //newHit->Print(); 00090 //newHit->Draw(); 00091 00092 return true; 00093 } 00094 00095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00096 00097 void B2TrackerSD::EndOfEvent(G4HCofThisEvent*) 00098 { 00099 if ( verboseLevel>1 ) { 00100 G4int nofHits = fHitsCollection->entries(); 00101 G4cout << "\n-------->Hits Collection: in this event they are " << nofHits 00102 << " hits in the tracker chambers: " << G4endl; 00103 for ( G4int i=0; i<nofHits; i++ ) (*fHitsCollection)[i]->Print(); 00104 } 00105 } 00106 00107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
1.7.4