LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
DrawSimPhoton3D_tool.cc
Go to the documentation of this file.
1 
12 
15 
20 
21 #include "TPolyLine3D.h"
22 
23 // Eigen
24 #include <Eigen/Core>
25 
26 namespace evdb_tool {
27 
28  class DrawSimPhoton3D : public ISim3DDrawer {
29  public:
31 
32  void Draw(const art::Event&, evdb::View3D*) const override;
33 
34  private:
36  const Eigen::Vector3f&,
37  const Eigen::Vector3f&,
38  int,
39  int,
40  int) const;
41  };
42 
44  {
46 
47  // If the option is turned off, there's nothing to do
48  if (!drawOpt->fShowSimPhotonInfo) return;
49 
50  // Recover a handle to the collection of MCParticles We need these so we can determine
51  // the offset (if any)
53 
54  evt.getByLabel(drawOpt->fG4ModuleLabel, mcParticleHandle);
55 
56  if (!mcParticleHandle.isValid()) return;
57 
58  // Create a mapping between track ID's and MCParticles
59  using TrackToMcParticleMap = std::map<int, const simb::MCParticle*>;
60 
61  TrackToMcParticleMap trackToMcParticleMap;
62 
63  for (const auto& mcParticle : *mcParticleHandle)
64  trackToMcParticleMap[mcParticle.TrackId()] = &mcParticle;
65 
66  // Now recover the simphotons
68 
69  evt.getByLabel(drawOpt->fSimPhotonLabel, simPhotonsHandle);
70 
71  if (simPhotonsHandle.isValid() && simPhotonsHandle->size() > 0) {
72  mf::LogDebug("SimPhoton3DDrawer")
73  << "Starting loop over " << simPhotonsHandle->size() << " SimPhotons, " << std::endl;
74 
75  // Get the detector properties, clocks...
77 
78  // First step is to create a map between MCParticle and SimEnergyDeposit objects...
79  using MCPartToOnePhotonMap =
80  std::map<const simb::MCParticle*, std::vector<const sim::OnePhoton*>>;
81  using ChanToMCPartToOnePhotonMap = std::map<int, MCPartToOnePhotonMap>;
82 
83  ChanToMCPartToOnePhotonMap chanToMCPartToOnePhotonMap;
84 
85  // Go through the SimEnergyDeposits and populate the map
86  for (const auto& simPhoton : *simPhotonsHandle) {
87  MCPartToOnePhotonMap& mcPartToOnePhotonMap =
88  chanToMCPartToOnePhotonMap[simPhoton.OpChannel()];
89 
90  for (const auto& onePhoton : simPhoton) {
92  trackToMcParticleMap.find(onePhoton.MotherTrackID);
93 
94  if (trackMCItr == trackToMcParticleMap.end()) continue;
95 
96  mcPartToOnePhotonMap[trackMCItr->second].push_back(&onePhoton);
97  }
98  }
99 
100  // Mapping of energy deposited per channel...
101  std::map<int, float> channelToEnergyMap;
102 
103  // Keep track of mininum and maximum
104  float maxEnergy = std::numeric_limits<float>::lowest();
105  float minEnergy = std::numeric_limits<float>::max();
106 
107  // Go through everything and get cenergy desposited per channel...
108  for (const auto& chanToMCPartToOnePhoton : chanToMCPartToOnePhotonMap) {
109  float totalE(0.);
110 
111  // Go through all contributors to this channel
112  for (const auto& mcPartToOnePhoton : chanToMCPartToOnePhoton.second) {
113  // Current scheme will ignore displacement in time... need to come back to this at some point...
114 
115  for (const auto& onePhoton : mcPartToOnePhoton.second) {
116  totalE += onePhoton->Energy;
117  }
118  }
119 
120  channelToEnergyMap[chanToMCPartToOnePhoton.first] = totalE;
121 
122  maxEnergy = std::max(maxEnergy, totalE);
123  minEnergy = std::min(minEnergy, totalE);
124  }
125 
126  // Get the scale factor from energy deposit range
127  float yzWidthScale(1. / (maxEnergy - minEnergy));
128  float energyDepositScale(
129  (cst->fRecoQHigh[geo::kCollection] - cst->fRecoQLow[geo::kCollection]) * yzWidthScale);
130 
131  // Go through the channels and draw the objects
132  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
133  for (const auto& channelToEnergy : channelToEnergyMap) {
134  // Recover the color index based on energy
135  float widthFactor =
136  0.95 * std::max(float(0.), std::min(float(1.), yzWidthScale * channelToEnergy.second));
137  float energyFactor =
138  cst->fRecoQLow[geo::kCollection] + energyDepositScale * channelToEnergy.second;
139 
140  // Recover the position for this channel
141  const geo::OpDetGeo& opHitGeo =
142  wireReadoutGeom.OpDetGeoFromOpChannel(channelToEnergy.first);
143  const geo::Point_t& opHitPos = opHitGeo.GetCenter();
144  float xWidth = 0.01;
145  float zWidth = widthFactor * opHitGeo.HalfW();
146  float yWidth = widthFactor * opHitGeo.HalfH();
147 
148  // Get widths of box to draw
149  Eigen::Vector3f coordsLo(
150  opHitPos.X() - xWidth, opHitPos.Y() - yWidth, opHitPos.Z() - zWidth);
151  Eigen::Vector3f coordsHi(
152  opHitPos.X() + xWidth, opHitPos.Y() + yWidth, opHitPos.Z() + zWidth);
153 
154  int energyColorIdx = cst->CalQ(geo::kCollection).GetColor(energyFactor);
155 
156  DrawRectangularBox(view, coordsLo, coordsHi, energyColorIdx, 1, 1);
157  }
158  }
159  }
160 
162  const Eigen::Vector3f& coordsLo,
163  const Eigen::Vector3f& coordsHi,
164  int color,
165  int width,
166  int style) const
167  {
168  TPolyLine3D& top = view->AddPolyLine3D(5, color, width, style);
169  top.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
170  top.SetPoint(1, coordsHi[0], coordsHi[1], coordsLo[2]);
171  top.SetPoint(2, coordsHi[0], coordsHi[1], coordsHi[2]);
172  top.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
173  top.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
174 
175  TPolyLine3D& side = view->AddPolyLine3D(5, color, width, style);
176  side.SetPoint(0, coordsHi[0], coordsHi[1], coordsLo[2]);
177  side.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
178  side.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
179  side.SetPoint(3, coordsHi[0], coordsHi[1], coordsHi[2]);
180  side.SetPoint(4, coordsHi[0], coordsHi[1], coordsLo[2]);
181 
182  TPolyLine3D& side2 = view->AddPolyLine3D(5, color, width, style);
183  side2.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
184  side2.SetPoint(1, coordsLo[0], coordsLo[1], coordsLo[2]);
185  side2.SetPoint(2, coordsLo[0], coordsLo[1], coordsHi[2]);
186  side2.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
187  side2.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
188 
189  TPolyLine3D& bottom = view->AddPolyLine3D(5, color, width, style);
190  bottom.SetPoint(0, coordsLo[0], coordsLo[1], coordsLo[2]);
191  bottom.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
192  bottom.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
193  bottom.SetPoint(3, coordsLo[0], coordsLo[1], coordsHi[2]);
194  bottom.SetPoint(4, coordsLo[0], coordsLo[1], coordsLo[2]);
195  }
196 
198 }
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
Point_t const & GetCenter() const
Definition: OpDetGeo.h:71
void DrawRectangularBox(evdb::View3D *, const Eigen::Vector3f &, const Eigen::Vector3f &, int, int, int) const
art::InputTag fG4ModuleLabel
module label producing sim::SimChannel objects
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
intermediate_table::const_iterator const_iterator
int GetColor(double x) const
Definition: ColorScale.cxx:126
Particle class.
std::vector< double > fRecoQHigh
high edge of ADC values for drawing raw digits
std::vector< double > fRecoQLow
low edge of ADC values for drawing raw digits
bool isValid() const noexcept
Definition: Handle.h:203
The color scales used by the event display.
double HalfW() const
Definition: OpDetGeo.cxx:48
TPolyLine3D & AddPolyLine3D(int n, int c, int w, int s)
Definition: View3D.cxx:105
bool fShowSimPhotonInfo
Display SimPhoton info in 3D display.
Simulation objects for optical detectors.
art::InputTag fSimPhotonLabel
and for SimPhotons
const evdb::ColorScale & CalQ(geo::SigType_t st) const
Encapsulate the geometry of an optical detector.
std::size_t color(std::string const &procname)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
double HalfH() const
Definition: OpDetGeo.cxx:56
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
A collection of 3D drawable objects.
TCEvent evt
Definition: DataStructs.cxx:8
void Draw(const art::Event &, evdb::View3D *) const override
Signal from collection planes.
Definition: geo_types.h:148
DrawSimPhoton3D(const fhicl::ParameterSet &)