CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AttachSD.cc
Go to the documentation of this file.
6 
9 #include <string>
10 #include <sstream>
11 #include <algorithm>
12 
13 std::pair<std::vector<SensitiveTkDetector*>, std::vector<SensitiveCaloDetector*>> sim::attachSD(
14  const std::unordered_map<std::string, std::unique_ptr<SensitiveDetectorMakerBase>>& makers,
15  const edm::EventSetup& es,
16  const SensitiveDetectorCatalog& clg,
17  edm::ParameterSet const& p,
18  const SimTrackManager* man,
19  SimActivityRegistry& reg) {
20  std::pair<std::vector<SensitiveTkDetector*>, std::vector<SensitiveCaloDetector*>> detList;
21  const std::vector<std::string_view>& rouNames = clg.readoutNames();
22 
23  edm::LogVerbatim("SimG4CoreSensitiveDetector") << " AttachSD: Initialising " << rouNames.size() << " SDs";
24  for (auto& rname : rouNames) {
25  std::string_view className = clg.className({rname.data(), rname.size()});
26  auto makerItr = makers.find(std::string(className.data(), className.size()));
27  if (makerItr == makers.end()) {
28  throw cms::Exception("MissingSensitiveDetector")
29  << "Asked to use " << className << " sensitive detector but it was not in the list of preloaded ones.";
30  }
31 
32  std::unique_ptr<SensitiveDetector> sd{makerItr->second->make({rname.data(), rname.size()}, es, clg, p, man, reg)};
33 
34  std::stringstream ss;
35  ss << " AttachSD: created a " << className << " with name " << rname;
36 
37  if (sd->isCaloSD()) {
38  detList.second.push_back(static_cast<SensitiveCaloDetector*>(sd.release()));
39  ss << " + calo SD";
40  } else {
41  detList.first.push_back(static_cast<SensitiveTkDetector*>(sd.release()));
42  ss << " + tracking SD";
43  }
44  edm::LogVerbatim("SimG4CoreSensitiveDetector") << ss.str();
45  }
46  return detList;
47 }
Log< level::Info, true > LogVerbatim
std::string_view className(const std::string &readoutName) const
std::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > attachSD(const std::unordered_map< std::string, std::unique_ptr< SensitiveDetectorMakerBase >> &, const edm::EventSetup &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *, SimActivityRegistry &reg)
double sd
const G4String rname[NREG]
const std::vector< std::string_view > readoutNames(const std::string &className) const
std::string className(const T &t)
Definition: ClassName.h:31