LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SavePiMu_tool.cc
Go to the documentation of this file.
7 
14 
15 #include "ImageMaker.h"
16 #include "TTimeStamp.h"
17 #include "hep_hpc/hdf5/Ntuple.hpp"
18 #include "hep_hpc/hdf5/make_ntuple.hpp"
19 
20 using namespace hep_hpc::hdf5;
21 
22 namespace dnn {
23 
24  class SavePiMu : public ImageMaker {
25  public:
26  explicit SavePiMu(fhicl::ParameterSet const& ps);
27 
28  void saveImage(art::Event const& e, hep_hpc::hdf5::File& hdffile) override;
29 
30  private:
34  };
35 
36  SavePiMu::SavePiMu(fhicl::ParameterSet const& ps)
37  : fTrackModuleLabel{ps.get<art::InputTag>("TrackModuleLabel")}
38  , fWireModuleLabel{ps.get<art::InputTag>("WireModuleLabel")}
39  , fMCTruthLabel{ps.get<art::InputTag>("MCTruthLabel")}
40  {}
41 
43  {
44 
46 
47  static Ntuple<unsigned int, unsigned int, unsigned int, double> evtids(
48  hdffile, "evtids", {"run", "subrun", "event", "evttime"});
49 
50  static auto image =
51  make_ntuple({hdffile, "image", 1000},
52  make_scalar_column<unsigned short>("label"),
53  make_column<float, 2>(
54  "adc", // 2 means each element is a 2-d array
55  {50, 50}, // extent of each array dimension
56  1024 * 1024 / (2500 * sizeof(float)), // chunk size
57  {PropertyList{H5P_DATASET_CREATE}(&H5Pset_shuffle)(&H5Pset_deflate, 6u)}));
58 
59  // Get event information
60  double evttime;
61 
62  art::Timestamp ts = e.time();
63  if (ts.timeHigh() == 0) {
64  TTimeStamp tts(ts.timeLow());
65  evttime = tts.AsDouble();
66  }
67  else {
68  TTimeStamp tts(ts.timeHigh(), ts.timeLow());
69  evttime = tts.AsDouble();
70  }
71 
72  // Get image information
73  // * tracks
74  auto const& tracks = e.getProduct<std::vector<recob::Track>>(fTrackModuleLabel);
75  auto trackListHandle = e.getHandle<std::vector<recob::Track>>(fTrackModuleLabel);
77 
78  // * wires
79  auto const& wires = e.getProduct<std::vector<recob::Wire>>(fWireModuleLabel);
80 
81  // * MC truth
82  auto const& mclist = e.getProduct<std::vector<simb::MCTruth>>(fMCTruthLabel);
83 
84  unsigned short flag = 999;
85  if (!mclist.empty()) {
86  auto particle = mclist[0].GetParticle(0);
87  if (std::abs(particle.PdgCode()) == 13) flag = 0;
88  if (std::abs(particle.PdgCode()) == 211) flag = 1;
89  }
90 
91  if (!tracks.empty()) {
92  auto trkend = tracks[0].End();
93  if (trkend.X() > -360 + 50 && trkend.X() < 360 - 50 && trkend.Y() > 50 &&
94  trkend.Y() < 610 - 50 && trkend.Z() > 50 && trkend.Z() < 710 - 50) {
95  if (fmthm.isValid()) {
96  auto vhit = fmthm.at(0);
97  auto vmeta = fmthm.data(0);
98  int ihit = -1;
99  int maxindex = -1;
100  for (size_t i = 0; i < vhit.size(); ++i) {
101  if (static_cast<int>(vmeta[i]->Index()) == std::numeric_limits<int>::max()) {
102  continue;
103  }
104  if (vhit[i]->WireID().Plane == 2) {
105  if (int(vmeta[i]->Index()) > maxindex) {
106  maxindex = vmeta[i]->Index();
107  ihit = i;
108  }
109  }
110  }
111  if (ihit >= 0) {
112  auto endwire = vhit[ihit]->WireID();
113  float endtime = vhit[ihit]->PeakTime();
114  float adc[50][50] = {{0.}};
115  for (auto& wire : wires) {
116  int channel = wire.Channel();
117  auto wireids = geom->ChannelToWire(channel);
118  if (wireids[0].Plane == 2 && wireids[0].TPC == endwire.TPC &&
119  wireids[0].Wire >= endwire.Wire - 25 && wireids[0].Wire < endwire.Wire + 25) {
120  int idx = wireids[0].Wire - endwire.Wire + 25;
121  const recob::Wire::RegionsOfInterest_t& signalROI = wire.SignalROI();
122  int lasttick = 0;
123  for (const auto& range : signalROI.get_ranges()) {
124  const auto& waveform = range.data();
125  // ROI start time
126  raw::TDCtick_t roiFirstBinTick = range.begin_index();
127  for (int i = lasttick; i < roiFirstBinTick; ++i) {
128  if (i >= int(endtime) - 25 && i < int(endtime) + 25) {
129  adc[idx][i - int(endtime) - 25] = 0;
130  }
131  }
132  lasttick = roiFirstBinTick;
133  for (size_t i = 0; i < waveform.size(); ++i) {
134  if (lasttick >= int(endtime) - 25 && lasttick < int(endtime) + 25) {
135  adc[idx][lasttick - int(endtime) + 25] = waveform[i];
136  ++lasttick;
137  }
138  }
139  }
140  for (int i = lasttick; i < 6000; ++i) {
141  if (i >= int(endtime) - 25 && i < int(endtime) + 25) {
142  adc[idx][i - int(endtime) + 25] = 0;
143  }
144  }
145  }
146  } // Loop over all wire signals
147  evtids.insert(e.run(), e.subRun(), e.id().event(), evttime);
148  image.insert(flag, &adc[0][0]);
149  }
150  }
151  }
152  }
153 
154  return;
155  }
156 }
157 
SubRunNumber_t subRun() const
Definition: Event.cc:35
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
art::InputTag fTrackModuleLabel
void saveImage(art::Event const &e, hep_hpc::hdf5::File &hdffile) override
art::InputTag fMCTruthLabel
Declaration of signal hit object.
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
constexpr auto abs(T v)
Returns the absolute value of the argument.
Class to keep data related to recob::Hit associated with recob::Track.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
art::InputTag fWireModuleLabel
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
T get(std::string const &key) const
Definition: ParameterSet.h:314
Provides recob::Track data product.
Definition: ImageMaker.h:4
Handle< PROD > getHandle(SelectorBase const &) const
Timestamp time() const
Definition: Event.cc:47
EventNumber_t event() const
Definition: EventID.h:116
Declaration of basic channel signal object.
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.cc:29
recob::tracking::Plane Plane
Definition: TrackState.h:17
PROD const & getProduct(InputTag const &tag) const
EventID id() const
Definition: Event.cc:23
art framework interface to geometry description