15 #include "nuevdb/EventDisplayBase/View3D.h"
16 #include "nusimdata/SimulationBase/MCParticle.h"
18 #include "art/Framework/Principal/Event.h"
19 #include "art/Framework/Services/Registry/ServiceHandle.h"
20 #include "art/Utilities/ToolMacros.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
23 #include "TPolyMarker3D.h"
31 void Draw(
const art::Event&, evdb::View3D*)
const override;
35 void drawAll(
const art::Event&, evdb::View3D*)
const;
50 art::ServiceHandle<evd::SimulationDrawingOptions const> drawOpt;
53 if (!drawOpt->fShowSimEnergyInfo)
return;
67 art::ServiceHandle<evd::SimulationDrawingOptions const> drawOpt;
71 art::Handle<std::vector<simb::MCParticle>> mcParticleHandle;
73 evt.getByLabel(drawOpt->fG4ModuleLabel, mcParticleHandle);
75 if (!mcParticleHandle.isValid())
return;
78 using TrackToMcParticleMap = std::map<int, const simb::MCParticle*>;
80 TrackToMcParticleMap trackToMcParticleMap;
82 for (
const auto& mcParticle : *mcParticleHandle)
83 trackToMcParticleMap[mcParticle.TrackId()] = &mcParticle;
86 art::Handle<std::vector<sim::SimEnergyDeposit>> simEnergyDepositHandle;
88 evt.getByLabel(drawOpt->fSimEnergyLabel, simEnergyDepositHandle);
90 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
92 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
94 if (simEnergyDepositHandle.isValid() && simEnergyDepositHandle->size() > 0) {
95 mf::LogDebug(
"SimEnergyDeposit3DDrawer")
96 <<
"Starting loop over " << simEnergyDepositHandle->size() <<
" SimEnergyDeposits, "
99 art::ServiceHandle<geo::Geometry const> geom;
102 using MCPartToSimEnergyMap =
103 std::map<const simb::MCParticle*, std::vector<const sim::SimEnergyDeposit*>>;
105 MCPartToSimEnergyMap mcPartToSimEnergyMap;
108 for (
const auto& simEnergyDeposit : *simEnergyDepositHandle) {
109 TrackToMcParticleMap::const_iterator trackMCItr =
110 trackToMcParticleMap.find(simEnergyDeposit.TrackID());
112 if (trackMCItr == trackToMcParticleMap.end())
continue;
114 mcPartToSimEnergyMap[trackMCItr->second].push_back(&simEnergyDeposit);
119 std::map<int, std::vector<sim::SimEnergyDeposit::Point_t>> colorToPositionMap;
122 for (
const auto& mcPartToSimEnergy : mcPartToSimEnergyMap) {
126 double g4Ticks(clockData.TPCG4Time2Tick(mcPartToSimEnergy.first->T()) -
129 double xPosMinTick(0.);
130 double xPosMaxTick(std::numeric_limits<double>::max());
132 for (
const auto& simEnergyDeposit : mcPartToSimEnergy.second) {
139 geo::TPCID tpcID = geom->PositionToTPCID(point);
142 xPosMinTick =
detProp.ConvertTicksToX(0, planeID);
143 xPosMaxTick =
detProp.ConvertTicksToX(
detProp.NumberTimeSamples(), planeID);
144 xOffset =
detProp.ConvertTicksToX(g4Ticks, planeID) - xPosMinTick;
146 if (xPosMaxTick < xPosMinTick) std::swap(xPosMinTick, xPosMaxTick);
158 for (
const auto& pair : colorToPositionMap) {
159 int colorIdx(pair.first);
160 int markerIdx(kFullDotMedium);
163 TPolyMarker3D& pm = view->AddPolyMarker3D(1, colorIdx, markerIdx, markerSize);
166 std::vector<double> posArrayVec;
169 posArrayVec.resize(3 * pair.second.size());
171 for (
const auto& point : pair.second) {
172 posArrayVec[3 * hitCount] = point.X();
173 posArrayVec[3 * hitCount + 1] = point.Y();
174 posArrayVec[3 * hitCount + 2] = point.Z();
178 pm.SetPolyMarker(hitCount, posArrayVec.data(), markerIdx);
188 art::ServiceHandle<evd::SimulationDrawingOptions const> drawOpt;
194 art::Handle<std::vector<sim::SimEnergyDeposit>> simEnergyDepositHandle;
196 evt.getByLabel(drawOpt->fSimEnergyLabel, simEnergyDepositHandle);
198 if (simEnergyDepositHandle.isValid() && simEnergyDepositHandle->size() > 0) {
199 mf::LogDebug(
"SimEnergyDeposit3DDrawer")
200 <<
"Starting loop over " << simEnergyDepositHandle->size() <<
" SimEnergyDeposits, "
204 auto const clockData =
205 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
207 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
208 art::ServiceHandle<geo::Geometry const> geom;
212 std::map<int, std::vector<sim::SimEnergyDeposit::Point_t>> colorToPositionMap;
215 for (
const auto& simEnergyDeposit : *simEnergyDepositHandle) {
221 double depTime = simEnergyDeposit.T();
222 geo::TPCID tpcID = geom->PositionToTPCID(point);
224 double g4Ticks = clockData.TPCG4Time2Tick(depTime) -
trigger_offset(clockData);
225 double xPosMinTick =
detProp.ConvertTicksToX(0, planeID);
226 double xOffset =
detProp.ConvertTicksToX(g4Ticks, planeID) - xPosMinTick;
237 for (
const auto& pair : colorToPositionMap) {
238 int colorIdx(pair.first);
239 int markerIdx(kFullDotMedium);
242 TPolyMarker3D& pm = view->AddPolyMarker3D(1, colorIdx, markerIdx, markerSize);
245 std::vector<double> posArrayVec;
248 posArrayVec.resize(3 * pair.second.size());
250 for (
const auto& point : pair.second) {
251 posArrayVec[3 * hitCount] = point.X();
252 posArrayVec[3 * hitCount + 1] = point.Y();
253 posArrayVec[3 * hitCount + 2] = point.Z();
257 pm.SetPolyMarker(hitCount, posArrayVec.data(), markerIdx);
The data type to uniquely identify a Plane.
static int ColorFromPDG(int pdgcode)
The data type to uniquely identify a TPC.
contains information for a single step in the detector simulation
int trigger_offset(DetectorClocksData const &data)
art framework interface to geometry description