00001
00002 #include "HitsCollectionUtil.hh"
00003
00004
00005 #include "LCDDProcessor.hh"
00006 #include "G4SensitiveDetector.hh"
00007
00008
00009 #include "G4SDManager.hh"
00010 #include "G4HCtable.hh"
00011 #include "G4EventManager.hh"
00012 #include "G4Event.hh"
00013
00014 namespace slic
00015 {
00016 std::vector<int> HitsCollectionUtil::getHCIDs()
00017 {
00018 G4SDManager* SDmgr = G4SDManager::GetSDMpointer();
00019 G4HCtable* HCtbl = SDmgr->GetHCtable();
00020 G4int num_entries = HCtbl->entries();
00021
00022 std::vector<int> hcids;
00023
00024 for (G4int i = 0;
00025 i < num_entries;
00026 i++) {
00027
00028
00029 G4String sdname = HCtbl->GetSDname( i );
00030
00031
00032 G4SensitiveDetector* SD =
00033 static_cast<G4SensitiveDetector*> ( G4SDManager::GetSDMpointer()->FindSensitiveDetector( sdname ) );
00034
00035
00036 if (SD) {
00037 hcids.push_back( SD->getHCID() );
00038 }
00039 }
00040
00041 return hcids;
00042 }
00043
00044 std::vector<std::string> HitsCollectionUtil::getHCNames()
00045 {
00046 std::vector<int> hcids = getHCIDs();
00047
00048 const G4Event* currEvent =
00049 G4EventManager::GetEventManager()->GetConstCurrentEvent();
00050
00051 G4HCofThisEvent* hce = currEvent->GetHCofThisEvent();
00052
00053 std::vector<std::string> hcnames;
00054
00055 if ( currEvent ) {
00056
00057 G4VHitsCollection* hc = 0;
00058
00059 for (std::vector<int>::const_iterator iter = hcids.begin();
00060 iter != hcids.end();
00061 iter++) {
00062 hc = hce->GetHC( (*iter) );
00063 hcnames.push_back( hc->GetName() );
00064 }
00065 }
00066
00067 return hcnames;
00068 }
00069 }
00070