LArSoft  v10_04_05
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  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout>()->Get();
45 
46  static Ntuple<unsigned int, unsigned int, unsigned int, double> evtids(
47  hdffile, "evtids", {"run", "subrun", "event", "evttime"});
48 
49  static auto image =
50  make_ntuple({hdffile, "image", 1000},
51  make_scalar_column<unsigned short>("label"),
52  make_column<float, 2>(
53  "adc", // 2 means each element is a 2-d array
54  {50, 50}, // extent of each array dimension
55  1024 * 1024 / (2500 * sizeof(float)), // chunk size
56  {PropertyList{H5P_DATASET_CREATE}(&H5Pset_shuffle)(&H5Pset_deflate, 6u)}));
57 
58  // Get event information
59  double evttime;
60 
61  art::Timestamp ts = e.time();
62  if (ts.timeHigh() == 0) {
63  TTimeStamp tts(ts.timeLow());
64  evttime = tts.AsDouble();
65  }
66  else {
67  TTimeStamp tts(ts.timeHigh(), ts.timeLow());
68  evttime = tts.AsDouble();
69  }
70 
71  // Get image information
72  // * tracks
73  auto const& tracks = e.getProduct<std::vector<recob::Track>>(fTrackModuleLabel);
74  auto trackListHandle = e.getHandle<std::vector<recob::Track>>(fTrackModuleLabel);
76 
77  // * wires
78  auto const& wires = e.getProduct<std::vector<recob::Wire>>(fWireModuleLabel);
79 
80  // * MC truth
81  auto const& mclist = e.getProduct<std::vector<simb::MCTruth>>(fMCTruthLabel);
82 
83  unsigned short flag = 999;
84  if (!mclist.empty()) {
85  auto particle = mclist[0].GetParticle(0);
86  if (std::abs(particle.PdgCode()) == 13) flag = 0;
87  if (std::abs(particle.PdgCode()) == 211) flag = 1;
88  }
89 
90  if (!tracks.empty()) {
91  auto trkend = tracks[0].End();
92  if (trkend.X() > -360 + 50 && trkend.X() < 360 - 50 && trkend.Y() > 50 &&
93  trkend.Y() < 610 - 50 && trkend.Z() > 50 && trkend.Z() < 710 - 50) {
94  if (fmthm.isValid()) {
95  auto vhit = fmthm.at(0);
96  auto vmeta = fmthm.data(0);
97  int ihit = -1;
98  int maxindex = -1;
99  for (size_t i = 0; i < vhit.size(); ++i) {
100  if (static_cast<int>(vmeta[i]->Index()) == std::numeric_limits<int>::max()) {
101  continue;
102  }
103  if (vhit[i]->WireID().Plane == 2) {
104  if (int(vmeta[i]->Index()) > maxindex) {
105  maxindex = vmeta[i]->Index();
106  ihit = i;
107  }
108  }
109  }
110  if (ihit >= 0) {
111  auto endwire = vhit[ihit]->WireID();
112  float endtime = vhit[ihit]->PeakTime();
113  float adc[50][50] = {{0.}};
114  for (auto& wire : wires) {
115  int channel = wire.Channel();
116  auto wireids = wireReadoutGeom.ChannelToWire(channel);
117  if (wireids[0].Plane == 2 && wireids[0].TPC == endwire.TPC &&
118  wireids[0].Wire >= endwire.Wire - 25 && wireids[0].Wire < endwire.Wire + 25) {
119  int idx = wireids[0].Wire - endwire.Wire + 25;
120  const recob::Wire::RegionsOfInterest_t& signalROI = wire.SignalROI();
121  int lasttick = 0;
122  for (const auto& range : signalROI.get_ranges()) {
123  const auto& waveform = range.data();
124  // ROI start time
125  raw::TDCtick_t roiFirstBinTick = range.begin_index();
126  for (int i = lasttick; i < roiFirstBinTick; ++i) {
127  if (i >= int(endtime) - 25 && i < int(endtime) + 25) {
128  adc[idx][i - int(endtime) - 25] = 0;
129  }
130  }
131  lasttick = roiFirstBinTick;
132  for (size_t i = 0; i < waveform.size(); ++i) {
133  if (lasttick >= int(endtime) - 25 && lasttick < int(endtime) + 25) {
134  adc[idx][lasttick - int(endtime) + 25] = waveform[i];
135  ++lasttick;
136  }
137  }
138  }
139  for (int i = lasttick; i < 6000; ++i) {
140  if (i >= int(endtime) - 25 && i < int(endtime) + 25) {
141  adc[idx][i - int(endtime) + 25] = 0;
142  }
143  }
144  }
145  } // Loop over all wire signals
146  evtids.insert(e.run(), e.subRun(), e.id().event(), evttime);
147  image.insert(flag, &adc[0][0]);
148  }
149  }
150  }
151  }
152 
153  return;
154  }
155 }
156 
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
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.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
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
Definition: ImageMaker.h:4
Handle< PROD > getHandle(SelectorBase const &) const
Provides recob::Track data product.
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