SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
HitsCollectionUtil.cc
Go to the documentation of this file.
1 #include "HitsCollectionUtil.hh"
2 
3 // LCDD
4 #include "lcdd/core/LCDDProcessor.hh"
5 #include "lcdd/detectors/SensitiveDetector.hh"
6 
7 // Geant4
8 #include "G4SDManager.hh"
9 #include "G4HCtable.hh"
10 #include "G4EventManager.hh"
11 #include "G4Event.hh"
12 
13 // STL
14 #include <vector>
15 #include <algorithm>
16 
17 namespace slic {
18 std::vector<SensitiveDetector*> HitsCollectionUtil::getSensitiveDetectors() {
19  G4SDManager* SDmgr = G4SDManager::GetSDMpointer();
20  G4HCtable* HCtbl = SDmgr->GetHCtable();
21  G4int num_entries = HCtbl->entries();
22 
23  std::vector<SensitiveDetector*> sds;
24 
25  for (G4int i = 0; i < num_entries; i++) {
26  // get the name of this SD
27  G4String sdname = HCtbl->GetSDname(i);
28  // retrieve corresponding Sensitive Detector from Geant4 store and cast to LCDD type
29  SensitiveDetector* sd = static_cast<SensitiveDetector*>(G4SDManager::GetSDMpointer()->FindSensitiveDetector(sdname));
30  // Add, checking for dups.
31  if (sd && std::find(sds.begin(), sds.end(), sd) == sds.end())
32  sds.push_back(sd);
33  }
34  return sds;
35 }
36 
37 std::vector<int> HitsCollectionUtil::getHCIDs() {
38  std::vector<int> hcids;
39  const std::vector<SensitiveDetector*>& sds = getSensitiveDetectors();
40  for (std::vector<SensitiveDetector*>::const_iterator it = sds.begin(); it != sds.end(); it++) {
41  SensitiveDetector* sd = (*it);
42  for (int i = 0; i < sd->getNumberOfHitsCollections(); i++) {
43  hcids.push_back(sd->getHCID(i));
44  }
45  }
46  return hcids;
47 }
48 
49 std::vector<std::string> HitsCollectionUtil::getHCNames() {
50  std::vector<int> hcids = getHCIDs();
51 
52  const G4Event* currEvent = G4EventManager::GetEventManager()->GetConstCurrentEvent();
53 
54  G4HCofThisEvent* hce = currEvent->GetHCofThisEvent();
55 
56  std::vector<std::string> hcnames;
57 
58  if (currEvent) {
59 
60  G4VHitsCollection* hc = 0;
61 
62  for (std::vector<int>::const_iterator iter = hcids.begin(); iter != hcids.end(); iter++) {
63  hc = hce->GetHC((*iter));
64  hcnames.push_back(hc->GetName());
65  }
66  }
67 
68  return hcnames;
69 }
70 }
71 
static std::vector< std::string > getHCNames()
static std::vector< int > getHCIDs()
static std::vector< SensitiveDetector * > getSensitiveDetectors()