LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PixelMapProducer.cxx
Go to the documentation of this file.
1 //
6 // Modifications to allow unwrapped collection view
7 // - Leigh Whitehead - leigh.howard.whitehead@cern.ch
9 
10 #include <algorithm>
11 #include <iostream>
12 #include <list>
13 #include <numeric>
14 #include <ostream>
15 
16 #include "TH2D.h"
17 #include "TVector2.h"
22 
28 
29 namespace lcvn {
30 
32  {
33 
34  Waveform ret;
35  double pe = fHit.Integral();
36  if (pe > fThreshold) ret.push_back(std::map<double, double>({{fHit.PeakTime(), pe}}));
37 
38  return ret;
39  }
40 
42  {
43  return fHit.WireID();
44  }
45 
47  {
48 
49  Waveform ret;
50  auto ROIs = fWire.SignalROI();
51  if (!(ROIs.get_ranges().size())) return ret;
52 
53  for (auto iROI = ROIs.begin_range(); iROI != ROIs.end_range(); ++iROI) {
54  auto& ROI = *iROI;
55  std::map<double, double> pulse;
56  for (int tick = ROI.begin_index(); tick < (int)ROI.end_index(); tick++) {
57  if (!(ROI[tick] > fThreshold)) continue;
58  pulse.insert(std::pair<double, double>((double)tick, (double)ROI[tick]));
59  }
60  ret.push_back(pulse);
61  }
62  return ret;
63  }
64 
66  {
67  geo::WireID ret;
68  std::vector<geo::WireID> wireids = fGeometry->ChannelToWire(fWire.Channel());
69  if (!wireids.size()) return ret;
70  ret = wireids[0];
71 
72  if (wireids.size() > 1) {
73  for (auto iwire : wireids)
74  if (iwire.Plane == fWire.View()) ret = iwire;
75  }
76  return ret;
77  }
78 
80  {
81 
82  Waveform ret;
83  auto& ROIs = fSimchan.TDCIDEMap();
84  if (!(ROIs.size())) return ret;
85 
86  for (auto iROI = ROIs.begin(); iROI != ROIs.end(); ++iROI) {
87  auto& ROI = *iROI;
88  auto tick = ROI.first;
89  double charge = 0.005 * fSimchan.Charge(tick);
90 
91  if (!(charge > fThreshold)) continue;
92  ret.push_back(std::map<double, double>({{(double)tick, charge}}));
93  }
94  return ret;
95  }
96 
98  {
99  geo::WireID ret;
100  std::vector<geo::WireID> wireids = fGeometry->ChannelToWire(fSimchan.Channel());
101  if (!wireids.size()) return ret;
102  ret = wireids[0];
103  return ret;
104  }
105 
106  template <class T, class U>
108  unsigned int nTdc,
109  double tRes,
110  double threshold)
111  : fNWire(nWire), fNTdc(nTdc), fTRes(tRes), fThreshold(threshold), fMultipleDrifts(false)
112  {
113 
115  }
116 
117  template <class T, class U>
119  {
121  }
122 
123  template <class T, class U>
125  : fNWire(pset.get<unsigned int>("WireLength"))
126  , fNTdc(pset.get<unsigned int>("TdcWidth"))
127  , fTRes(pset.get<double>("TimeResolution"))
128  , fThreshold(pset.get<double>("Threshold"))
129  , fMultipleDrifts(pset.get<bool>("MultipleDrifts"))
130  {
132  }
133 
134  template <class T, class U>
137  {
138  std::vector<const T*> newCluster;
139  for (const art::Ptr<T> hit : cluster) {
140  newCluster.push_back(hit.get());
141  }
142  return CreateMap(detProp, newCluster);
143  }
144 
145  template <class T, class U>
147  const std::vector<const T*>& cluster)
148  {
149  Boundary bound = DefineBoundary(detProp, cluster);
150  return CreateMapGivenBoundary(detProp, cluster, bound);
151  }
152 
153  template <class T, class U>
155  detinfo::DetectorPropertiesData const& detProp,
156  const std::vector<const T*>& cluster,
157  const Boundary& bound)
158  {
159 
160  PixelMap pm(fNWire, fNTdc, bound);
161 
162  for (size_t iHit = 0; iHit < cluster.size(); ++iHit) {
163 
164  U wraphit(*(cluster[iHit]), fThreshold);
165  Waveform wf = wraphit.GetWaveform();
166  geo::WireID wireid = wraphit.GetID();
167 
168  unsigned int tempWire = wireid.Wire;
169  unsigned int tempPlane = wireid.Plane;
170 
171  if (!fMultipleDrifts) ConvertLocaltoGlobal(wireid, tempWire, tempPlane);
172 
173  for (auto& pulse : wf) {
174  // Leigh: Simple modification to unwrap the collection view wire plane
175  for (auto& i : pulse) {
176  const double pe = i.second;
177  double temptdc = i.first;
178  if (fMultipleDrifts)
179  ConvertLocaltoGlobalTDC(wireid, i.first, tempWire, tempPlane, temptdc);
180 
181  const unsigned int wire = tempWire;
182  const unsigned int wirePlane = tempPlane;
183  const double tdc = temptdc;
184 
185  pm.Add(wire, tdc, wirePlane, pe);
186  }
187  }
188  }
189  pm.SetTotHits(fTotHits);
190  return pm;
191  }
192 
193  template <class T, class U>
194  std::ostream& operator<<(std::ostream& os, const PixelMapProducer<T, U>& p)
195  {
196  os << "PixelMapProducer: " << p.NTdc() << " tdcs X " << p.NWire() << " wires";
197  return os;
198  }
199 
200  template <class T, class U>
202  const std::vector<const T*>& cluster)
203  {
204 
205  std::vector<double> tmin_0;
206  std::vector<double> tmin_1;
207  std::vector<double> tmin_2;
208 
209  std::vector<int> wire_0, bwire_0;
210  std::vector<int> wire_1, bwire_1;
211  std::vector<int> wire_2, bwire_2;
212 
213  std::vector<double> tsum = {0., 0., 0.};
214  std::vector<double> tsize = {0., 0., 0.};
215 
216  for (size_t iHit = 0; iHit < cluster.size(); ++iHit) {
217  U wraphit(*(cluster[iHit]), fThreshold);
218  Waveform wf = wraphit.GetWaveform();
219  geo::WireID wireid = wraphit.GetID();
220 
221  unsigned int tempWire = wireid.Wire;
222  unsigned int tempPlane = wireid.Plane;
223 
224  if (!fMultipleDrifts) ConvertLocaltoGlobal(wireid, tempWire, tempPlane);
225 
226  for (auto& pulse : wf) {
227  double min_tick = (double)INT_MAX;
228  for (auto& i : pulse) {
229  double temptdc = i.first;
230 
231  if (fMultipleDrifts)
232  ConvertLocaltoGlobalTDC(wireid, i.first, tempWire, tempPlane, temptdc);
233 
234  if (temptdc < min_tick) min_tick = temptdc;
235 
236  tsum[tempPlane] += temptdc;
237  tsize[tempPlane] += 1.;
238  }
239 
240  if (!(pulse.empty())) {
241  if (tempPlane == 0) {
242  tmin_0.push_back(min_tick);
243  wire_0.push_back(tempWire);
244  }
245  if (tempPlane == 1) {
246  tmin_1.push_back(min_tick);
247  wire_0.push_back(tempWire);
248  }
249  if (tempPlane == 2) {
250  tmin_2.push_back(min_tick);
251  wire_0.push_back(tempWire);
252  }
253  }
254  } // end loop over pulses on single wire
255  } // end loop over struck wires
256 
257  double tmean_0 = tsum[0] / tsize[0];
258  double tmean_1 = tsum[1] / tsize[1];
259  double tmean_2 = tsum[2] / tsize[2];
260 
261  for (int i = 0; i < (int)wire_0.size(); i++) {
262  if (std::abs(tmin_0[i] - tmean_0) < (double)fTRes) bwire_0.push_back(wire_0[i]);
263  }
264  for (int i = 0; i < (int)wire_1.size(); i++) {
265  if (std::abs(tmin_1[i] - tmean_1) < (double)fTRes) bwire_1.push_back(wire_1[i]);
266  }
267  for (int i = 0; i < (int)wire_2.size(); i++) {
268  if (std::abs(tmin_2[i] - tmean_2) < (double)fTRes) bwire_2.push_back(wire_2[i]);
269  }
270 
271  std::cout << "Boundary wire vector sizes: " << bwire_0.size() << ", " << bwire_1.size() << ", "
272  << bwire_2.size() << std::endl;
273 
274  int minwire_0 = 0;
275  int minwire_1 = 0;
276  int minwire_2 = 0;
277  auto minwireelement_0 = std::min_element(bwire_0.begin(), bwire_0.end());
278  auto minwireelement_1 = std::min_element(bwire_1.begin(), bwire_1.end());
279  auto minwireelement_2 = std::min_element(bwire_2.begin(), bwire_2.end());
280 
281  if (bwire_0.size() > 0) {
282  minwire_0 = *minwireelement_0 - 1;
283  std::cout << "minwire 0: " << (*minwireelement_0 - 1) << std::endl;
284  }
285  if (bwire_1.size() > 0) {
286  minwire_1 = *minwireelement_1 - 1;
287  std::cout << "minwire 1: " << (*minwireelement_1 - 1) << std::endl;
288  }
289  if (bwire_2.size() > 0) {
290  minwire_2 = *minwireelement_2 - 1;
291  std::cout << "minwire 2: " << (*minwireelement_2 - 1) << std::endl;
292  }
293 
294  fTotHits = bwire_0.size() + bwire_1.size() + bwire_2.size();
295 
296  Boundary bound(fNWire, fTRes, minwire_0, minwire_1, minwire_2, tmean_0, tmean_1, tmean_2);
297 
298  return bound;
299  }
300 
301  template <class T, class U>
303  unsigned int& globalWire,
304  unsigned int& globalPlane) const
305  {
306  globalWire = wireid.Wire;
307  globalPlane = wireid.Plane;
308  }
309 
310  template <class T, class U>
312  double localTDC,
313  unsigned int& globalWire,
314  unsigned int& globalPlane,
315  double& globalTDC) const
316  {
317  globalWire = wireid.Wire;
318  globalPlane = wireid.Plane;
319  globalTDC = localTDC;
320  }
321 
325 
326 } // namespace lcvn
virtual PixelMap CreateMap(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< T >> &cluster)
virtual geo::WireID GetID()
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
virtual Waveform GetWaveform()
Declaration of signal hit object.
void SetTotHits(unsigned int tothits)
Definition: PixelMap.h:62
constexpr auto abs(T v)
Returns the absolute value of the argument.
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:20
Utility class for truth labels.
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:244
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:563
geo::WireID const & WireID() const
Initial tdc tick for hit.
Definition: Hit.h:280
Cluster finding and building.
virtual Waveform GetWaveform()
virtual Waveform GetWaveform()
Producer algorithm for PixelMap, input to CVN neural net.
virtual PixelMap CreateMapGivenBoundary(detinfo::DetectorPropertiesData const &detProp, const std::vector< const T * > &cluster, const Boundary &bound)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
Access the description of detector geometry.
virtual void ConvertLocaltoGlobalTDC(geo::WireID wireid, double localTDC, unsigned int &globalWire, unsigned int &globalPlane, double &globalTDC) const
virtual Boundary DefineBoundary(detinfo::DetectorPropertiesData const &detProp, const std::vector< const T * > &cluster)
Get boundaries for pixel map representation of cluster.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:73
virtual geo::WireID GetID()
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
virtual geo::WireID GetID()
Detector simulation of raw signals on wires.
geo::GeometryCore const * fGeometry
double fThreshold
Charge threshold to consider for hits/waveforms etc.
unsigned int fNTdc
Number of tdcs, width of pixel map.
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:220
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
virtual void ConvertLocaltoGlobal(geo::WireID wireid, unsigned int &globalWire, unsigned int &globalPlane) const
PixelMapProducer for CVN.
unsigned int fNWire
Number of wires, length for pixel maps.
unsigned int fTotHits
Total hits in the pixel map.
void Add(const unsigned int &wire, const double &tdc, const unsigned int &view, const double &pe)
Definition: PixelMap.cxx:44
double fTRes
Timing resolution for pixel map.
unsigned int NTdc() const
Width in tdcs.
Definition: PixelMap.h:29
geo::GeometryCore const * fGeometry
std::vector< std::map< double, double > > Waveform
Definition: fwd.h:26
art framework interface to geometry description
bool fMultipleDrifts
True if making the pixel map requires handling for multiple drift regions.