Skip to content
Snippets Groups Projects
Commit e673ead9 authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn
Browse files

WIP: to make SD work properly, we construct the world from dd4hep directly.

parent 51bd6c03
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,14 @@ ExampleAnaElemTool::EndOfEventAction(const G4Event* anEvent) {
warning() << "Collection iCol " << icol << " is missing" << endmsg;
continue;
}
info() << "Collection " << collect->GetName() << endmsg;
size_t nhits = collect->GetSize();
info() << "Collection " << collect->GetName()
<< " #" << icol
<< " has " << nhits << " hits."
<< endmsg;
}
}
......
......@@ -29,10 +29,10 @@ DECLARE_COMPONENT(AnExampleDetElemTool)
G4LogicalVolume*
AnExampleDetElemTool::getLV() {
G4Material* Galactic = G4Material::GetMaterial("Galactic");
// G4Material* Galactic = G4Material::GetMaterial("Galactic");
G4VSolid* solidAnExample= new G4Box("sAnExample", m_x.value(), m_y.value(), m_z.value());
G4LogicalVolume* logicAnExample= new G4LogicalVolume( solidAnExample, Galactic, "lAnExample", 0, 0, 0);
// G4VSolid* solidAnExample= new G4Box("sAnExample", m_x.value(), m_y.value(), m_z.value());
// G4LogicalVolume* logicAnExample= new G4LogicalVolume( solidAnExample, Galactic, "lAnExample", 0, 0, 0);
// Following is an example to get the DD4hep volume
dd4hep::Detector* dd4hep_geo = &(dd4hep::Detector::getInstance());
......@@ -48,19 +48,20 @@ AnExampleDetElemTool::getLV() {
G4LogicalVolume* logicDD4hepExample = m_world->GetLogicalVolume();
if (logicDD4hepExample) {
new G4PVPlacement(0, // no rotation
G4ThreeVector(), // at (0,0,0)
logicDD4hepExample, // logical volume
"lDD4hepExampleDetElem", // name
logicAnExample, // mother volume
false, // no boolean operations
0); // no field
// new G4PVPlacement(0, // no rotation
// G4ThreeVector(), // at (0,0,0)
// logicDD4hepExample, // logical volume
// "lDD4hepExampleDetElem", // name
// logicAnExample, // mother volume
// false, // no boolean operations
// 0); // no field
} else {
warning() << "Can't Find the logical volume lDD4hepExampleDetElem " << std::endl;
}
return logicAnExample;
// return logicAnExample;
return logicDD4hepExample;
}
void
......@@ -89,7 +90,7 @@ AnExampleDetElemTool::ConstructSDandField() {
G4VSensitiveDetector* g4sd = dd4hep::PluginService::Create<G4VSensitiveDetector*>(typ, nam, lcdd);
if (g4sd == nullptr) {
std::string tmp = typ;
// tmp[0] = ::toupper(tmp[0]);
tmp[0] = ::toupper(tmp[0]);
typ = "Geant4" + tmp;
g4sd = dd4hep::PluginService::Create<G4VSensitiveDetector*>(typ, nam, lcdd);
if (g4sd == nullptr) {
......@@ -112,6 +113,7 @@ AnExampleDetElemTool::ConstructSDandField() {
throw std::runtime_error("ConstructSDandField: Failed to access G4LogicalVolume for SD " + nam + " of type " +
typ + ".");
}
info() << " -> Adding " << g4v->GetName() << endmsg;
G4SDManager::GetSDMpointer()->AddNewDetector(g4sd);
g4v->SetSensitiveDetector(g4sd);
}
......
......@@ -27,27 +27,28 @@ DECLARE_COMPONENT(WorldDetElemTool)
G4LogicalVolume*
WorldDetElemTool::getLV() {
G4Material* Galactic = G4Material::GetMaterial("Galactic");
// G4Material* Galactic = G4Material::GetMaterial("Galactic");
G4VSolid* solidWorld= new G4Box("sWorld", 60*m, 60*m, 60*m);
G4LogicalVolume* logicWorld= new G4LogicalVolume( solidWorld, Galactic, "lWorld", 0, 0, 0);
// G4VSolid* solidWorld= new G4Box("sWorld", 60*m, 60*m, 60*m);
// G4LogicalVolume* logicWorld= new G4LogicalVolume( solidWorld, Galactic, "lWorld", 0, 0, 0);
// An example, get a detelem first, then place the detector components inside world.
ToolHandle<IDetElemTool> inner_detelem_tool("AnExampleDetElemTool");
G4LogicalVolume* inner_lv = inner_detelem_tool->getLV();
if (inner_lv) {
new G4PVPlacement(0, // no rotation
G4ThreeVector(), // at (0,0,0)
inner_lv, // logical volume
"pAnExampleDetElem", // name
logicWorld, // mother volume
false, // no boolean operations
0); // no field
// new G4PVPlacement(0, // no rotation
// G4ThreeVector(), // at (0,0,0)
// inner_lv, // logical volume
// "pAnExampleDetElem", // name
// logicWorld, // mother volume
// false, // no boolean operations
// 0); // no field
} else {
warning() << "Can't Find the logical volume ExampleDetElem " << std::endl;
}
return logicWorld;
// return logicWorld;
return inner_lv;
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment