-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hit manager output diagnostic (#1596)
- Loading branch information
Showing
7 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
//------------------------------- -*- C++ -*- -------------------------------// | ||
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file accel/detail/HitManagerOutput.cc | ||
//---------------------------------------------------------------------------// | ||
#include "HitManagerOutput.hh" | ||
|
||
#include <G4LogicalVolume.hh> | ||
#include <G4VSensitiveDetector.hh> | ||
#include <nlohmann/json.hpp> | ||
|
||
#include "corecel/cont/Range.hh" | ||
#include "corecel/io/JsonPimpl.hh" | ||
#include "corecel/sys/TypeDemangler.hh" | ||
|
||
#include "HitManager.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace detail | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Construct from hit manager. | ||
*/ | ||
HitManagerOutput::HitManagerOutput(SPConstHitManager hits) | ||
: hits_(std::move(hits)) | ||
{ | ||
CELER_EXPECT(hits_); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Write output to the given JSON object. | ||
*/ | ||
void HitManagerOutput::output(JsonPimpl* j) const | ||
{ | ||
using json = nlohmann::json; | ||
|
||
auto result = json::object(); | ||
|
||
// Save detectors | ||
{ | ||
auto const& celer_vols = hits_->celer_vols(); | ||
auto const& geant_vols = *hits_->geant_vols(); | ||
TypeDemangler<G4VSensitiveDetector> demangle_sd; | ||
|
||
auto vol_ids = json::array(); | ||
auto gv_names = json::array(); | ||
auto sd_names = json::array(); | ||
auto sd_types = json::array(); | ||
|
||
for (auto i : range(celer_vols.size())) | ||
{ | ||
vol_ids.push_back(celer_vols[i].get()); | ||
|
||
auto const* lv = geant_vols[i]; | ||
G4VSensitiveDetector const* sd{nullptr}; | ||
if (lv) | ||
{ | ||
gv_names.push_back(lv->GetName()); | ||
sd = lv->GetSensitiveDetector(); | ||
} | ||
else | ||
{ | ||
gv_names.push_back(nullptr); | ||
} | ||
|
||
if (sd) | ||
{ | ||
sd_names.push_back(sd->GetName()); | ||
sd_types.push_back(demangle_sd(*sd)); | ||
} | ||
else | ||
{ | ||
sd_names.push_back(nullptr); | ||
sd_types.push_back(nullptr); | ||
} | ||
} | ||
|
||
result["vol_id"] = std::move(vol_ids); | ||
result["lv_name"] = std::move(gv_names); | ||
result["sd_name"] = std::move(sd_names); | ||
result["sd_type"] = std::move(sd_types); | ||
} | ||
|
||
// TODO: save filter selection | ||
result["locate_touchable"] = hits_->locate_touchable(); | ||
|
||
j->obj = std::move(result); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // namespace celeritas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//------------------------------- -*- C++ -*- -------------------------------// | ||
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file accel/detail/HitManagerOutput.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "corecel/io/OutputInterface.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace detail | ||
{ | ||
class HitManager; | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Save debugging information about sensitive detector mappings. | ||
*/ | ||
class HitManagerOutput final : public OutputInterface | ||
{ | ||
public: | ||
//!@{ | ||
//! \name Type aliases | ||
using SPConstHitManager = std::shared_ptr<HitManager const>; | ||
//!@} | ||
|
||
public: | ||
// Construct from shared hit manager | ||
explicit HitManagerOutput(SPConstHitManager hits); | ||
|
||
//! Category of data to write | ||
Category category() const final { return Category::internal; } | ||
|
||
//! Name of the entry inside the category. | ||
std::string_view label() const final { return "hit-manager"; } | ||
|
||
// Write output to the given JSON object | ||
void output(JsonPimpl*) const final; | ||
|
||
private: | ||
SPConstHitManager hits_; | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // namespace celeritas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters