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
00015 #include <vector>
00016 #include <algorithm>
00017
00018 namespace slic
00019 {
00020 std::vector<G4SensitiveDetector*> HitsCollectionUtil::getSensitiveDetectors()
00021 {
00022 G4SDManager* SDmgr = G4SDManager::GetSDMpointer();
00023 G4HCtable* HCtbl = SDmgr->GetHCtable();
00024 G4int num_entries = HCtbl->entries();
00025
00026 std::vector<G4SensitiveDetector*> sds;
00027
00028 for (G4int i = 0;i < num_entries;i++) {
00029
00030 G4String sdname = HCtbl->GetSDname( i );
00031
00032 G4SensitiveDetector* sd =
00033 static_cast<G4SensitiveDetector*> ( G4SDManager::GetSDMpointer()->FindSensitiveDetector( sdname ) );
00034
00035 if (sd && std::find(sds.begin(), sds.end(), sd) == sds.end()) sds.push_back(sd);
00036 }
00037 return sds;
00038 }
00039
00040 std::vector<int> HitsCollectionUtil::getHCIDs()
00041 {
00042 std::vector<int> hcids;
00043 const std::vector<G4SensitiveDetector*>& sds = getSensitiveDetectors();
00044 for ( std::vector<G4SensitiveDetector*>::const_iterator it = sds.begin();
00045 it != sds.end();
00046 it++ )
00047 {
00048 G4SensitiveDetector* sd = (*it);
00049 for( int i = 0; i < sd->getNumberOfHitsCollections(); i++)
00050 {
00051 hcids.push_back( sd->getHCID(i) );
00052 }
00053 }
00054 return hcids;
00055 }
00056
00057 std::vector<std::string> HitsCollectionUtil::getHCNames()
00058 {
00059 std::vector<int> hcids = getHCIDs();
00060
00061 const G4Event* currEvent =
00062 G4EventManager::GetEventManager()->GetConstCurrentEvent();
00063
00064 G4HCofThisEvent* hce = currEvent->GetHCofThisEvent();
00065
00066 std::vector<std::string> hcnames;
00067
00068 if ( currEvent ) {
00069
00070 G4VHitsCollection* hc = 0;
00071
00072 for (std::vector<int>::const_iterator iter = hcids.begin();
00073 iter != hcids.end();
00074 iter++) {
00075 hc = hce->GetHC( (*iter) );
00076 hcnames.push_back( hc->GetName() );
00077 }
00078 }
00079
00080 return hcnames;
00081 }
00082 }
00083