LArSoft  v10_04_05
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  Waveform ret;
34  double pe = fHit.Integral();
35  if (pe > fThreshold) ret.push_back(std::map<double, double>({{fHit.PeakTime(), pe}}));
36 
37  return ret;
38  }
39 
41  {
42  return fHit.WireID();
43  }
44 
46  {
47  Waveform ret;
48  auto ROIs = fWire.SignalROI();
49  if (!(ROIs.get_ranges().size())) return ret;
50 
51  for (auto iROI = ROIs.begin_range(); iROI != ROIs.end_range(); ++iROI) {
52  auto& ROI = *iROI;
53  std::map<double, double> pulse;
54  for (int tick = ROI.begin_index(); tick < (int)ROI.end_index(); tick++) {
55  if (!(ROI[tick] > fThreshold)) continue;
56  pulse.insert(std::pair<double, double>((double)tick, (double)ROI[tick]));
57  }
58  ret.push_back(pulse);
59  }
60  return ret;
61  }
62 
64  {
65  geo::WireID ret;
66  std::vector<geo::WireID> wireids = fWireReadoutGeom->ChannelToWire(fWire.Channel());
67  if (!wireids.size()) return ret;
68  ret = wireids[0];
69 
70  if (wireids.size() > 1) {
71  for (auto iwire : wireids)
72  if (iwire.Plane == fWire.View()) ret = iwire;
73  }
74  return ret;
75  }
76 
78  {
79  Waveform ret;
80  auto& ROIs = fSimchan.TDCIDEMap();
81  if (!(ROIs.size())) return ret;
82 
83  for (auto iROI = ROIs.begin(); iROI != ROIs.end(); ++iROI) {
84  auto& ROI = *iROI;
85  auto tick = ROI.first;
86  double charge = 0.005 * fSimchan.Charge(tick);
87 
88  if (!(charge > fThreshold)) continue;
89  ret.push_back(std::map<double, double>({{(double)tick, charge}}));
90  }
91  return ret;
92  }
93 
95  {
96  std::vector<geo::WireID> wireids = fWireReadoutGeom->ChannelToWire(fSimchan.Channel());
97  if (wireids.empty()) return {};
98  return wireids[0];
99  }
100 
101  template <class T, class U>
103  unsigned int nTdc,
104  double tRes,
105  double threshold)
106  : fNWire(nWire), fNTdc(nTdc), fTRes(tRes), fThreshold(threshold), fMultipleDrifts(false)
107  {}
108 
109  template <class T, class U>
111  : fNWire(pset.get<unsigned int>("WireLength"))
112  , fNTdc(pset.get<unsigned int>("TdcWidth"))
113  , fTRes(pset.get<double>("TimeResolution"))
114  , fThreshold(pset.get<double>("Threshold"))
115  , fMultipleDrifts(pset.get<bool>("MultipleDrifts"))
116  {}
117 
118  template <class T, class U>
121  {
122  std::vector<const T*> newCluster;
123  for (const art::Ptr<T> hit : cluster) {
124  newCluster.push_back(hit.get());
125  }
126  return CreateMap(detProp, newCluster);
127  }
128 
129  template <class T, class U>
131  const std::vector<const T*>& cluster)
132  {
133  Boundary bound = DefineBoundary(detProp, cluster);
134  return CreateMapGivenBoundary(detProp, cluster, bound);
135  }
136 
137  template <class T, class U>
139  detinfo::DetectorPropertiesData const& detProp,
140  const std::vector<const T*>& cluster,
141  const Boundary& bound)
142  {
143  PixelMap pm(fNWire, fNTdc, bound);
144 
145  for (size_t iHit = 0; iHit < cluster.size(); ++iHit) {
146 
147  U wraphit(*(cluster[iHit]), fThreshold);
148  Waveform wf = wraphit.GetWaveform();
149  geo::WireID wireid = wraphit.GetID();
150 
151  unsigned int tempWire = wireid.Wire;
152  unsigned int tempPlane = wireid.Plane;
153 
154  if (!fMultipleDrifts) ConvertLocaltoGlobal(wireid, tempWire, tempPlane);
155 
156  for (auto& pulse : wf) {
157  // Leigh: Simple modification to unwrap the collection view wire plane
158  for (auto& i : pulse) {
159  const double pe = i.second;
160  double temptdc = i.first;
161  if (fMultipleDrifts)
162  ConvertLocaltoGlobalTDC(wireid, i.first, tempWire, tempPlane, temptdc);
163 
164  const unsigned int wire = tempWire;
165  const unsigned int wirePlane = tempPlane;
166  const double tdc = temptdc;
167 
168  pm.Add(wire, tdc, wirePlane, pe);
169  }
170  }
171  }
172  pm.SetTotHits(fTotHits);
173  return pm;
174  }
175 
176  template <class T, class U>
177  std::ostream& operator<<(std::ostream& os, const PixelMapProducer<T, U>& p)
178  {
179  os << "PixelMapProducer: " << p.NTdc() << " tdcs X " << p.NWire() << " wires";
180  return os;
181  }
182 
183  template <class T, class U>
185  const std::vector<const T*>& cluster)
186  {
187  std::vector<double> tmin_0;
188  std::vector<double> tmin_1;
189  std::vector<double> tmin_2;
190 
191  std::vector<int> wire_0, bwire_0;
192  std::vector<int> wire_1, bwire_1;
193  std::vector<int> wire_2, bwire_2;
194 
195  std::vector<double> tsum = {0., 0., 0.};
196  std::vector<double> tsize = {0., 0., 0.};
197 
198  for (size_t iHit = 0; iHit < cluster.size(); ++iHit) {
199  U wraphit(*(cluster[iHit]), fThreshold);
200  Waveform wf = wraphit.GetWaveform();
201  geo::WireID wireid = wraphit.GetID();
202 
203  unsigned int tempWire = wireid.Wire;
204  unsigned int tempPlane = wireid.Plane;
205 
206  if (!fMultipleDrifts) ConvertLocaltoGlobal(wireid, tempWire, tempPlane);
207 
208  for (auto& pulse : wf) {
209  double min_tick = (double)INT_MAX;
210  for (auto& i : pulse) {
211  double temptdc = i.first;
212 
213  if (fMultipleDrifts)
214  ConvertLocaltoGlobalTDC(wireid, i.first, tempWire, tempPlane, temptdc);
215 
216  if (temptdc < min_tick) min_tick = temptdc;
217 
218  tsum[tempPlane] += temptdc;
219  tsize[tempPlane] += 1.;
220  }
221 
222  if (!(pulse.empty())) {
223  if (tempPlane == 0) {
224  tmin_0.push_back(min_tick);
225  wire_0.push_back(tempWire);
226  }
227  if (tempPlane == 1) {
228  tmin_1.push_back(min_tick);
229  wire_0.push_back(tempWire);
230  }
231  if (tempPlane == 2) {
232  tmin_2.push_back(min_tick);
233  wire_0.push_back(tempWire);
234  }
235  }
236  } // end loop over pulses on single wire
237  } // end loop over struck wires
238 
239  double tmean_0 = tsum[0] / tsize[0];
240  double tmean_1 = tsum[1] / tsize[1];
241  double tmean_2 = tsum[2] / tsize[2];
242 
243  for (int i = 0; i < (int)wire_0.size(); i++) {
244  if (std::abs(tmin_0[i] - tmean_0) < (double)fTRes) bwire_0.push_back(wire_0[i]);
245  }
246  for (int i = 0; i < (int)wire_1.size(); i++) {
247  if (std::abs(tmin_1[i] - tmean_1) < (double)fTRes) bwire_1.push_back(wire_1[i]);
248  }
249  for (int i = 0; i < (int)wire_2.size(); i++) {
250  if (std::abs(tmin_2[i] - tmean_2) < (double)fTRes) bwire_2.push_back(wire_2[i]);
251  }
252 
253  std::cout << "Boundary wire vector sizes: " << bwire_0.size() << ", " << bwire_1.size() << ", "
254  << bwire_2.size() << std::endl;
255 
256  int minwire_0 = 0;
257  int minwire_1 = 0;
258  int minwire_2 = 0;
259  auto minwireelement_0 = std::min_element(bwire_0.begin(), bwire_0.end());
260  auto minwireelement_1 = std::min_element(bwire_1.begin(), bwire_1.end());
261  auto minwireelement_2 = std::min_element(bwire_2.begin(), bwire_2.end());
262 
263  if (bwire_0.size() > 0) {
264  minwire_0 = *minwireelement_0 - 1;
265  std::cout << "minwire 0: " << (*minwireelement_0 - 1) << std::endl;
266  }
267  if (bwire_1.size() > 0) {
268  minwire_1 = *minwireelement_1 - 1;
269  std::cout << "minwire 1: " << (*minwireelement_1 - 1) << std::endl;
270  }
271  if (bwire_2.size() > 0) {
272  minwire_2 = *minwireelement_2 - 1;
273  std::cout << "minwire 2: " << (*minwireelement_2 - 1) << std::endl;
274  }
275 
276  fTotHits = bwire_0.size() + bwire_1.size() + bwire_2.size();
277 
278  return Boundary(fNWire, fTRes, minwire_0, minwire_1, minwire_2, tmean_0, tmean_1, tmean_2);
279  }
280 
281  template <class T, class U>
283  unsigned int& globalWire,
284  unsigned int& globalPlane) const
285  {
286  globalWire = wireid.Wire;
287  globalPlane = wireid.Plane;
288  }
289 
290  template <class T, class U>
292  double localTDC,
293  unsigned int& globalWire,
294  unsigned int& globalPlane,
295  double& globalTDC) const
296  {
297  globalWire = wireid.Wire;
298  globalPlane = wireid.Plane;
299  globalTDC = localTDC;
300  }
301 
305 
306 } // namespace lcvn
virtual PixelMap CreateMap(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< T >> &cluster)
virtual geo::WireID GetID()
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:254
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:430
geo::WireID const & WireID() const
Initial tdc tick for hit.
Definition: Hit.h:290
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 the physical detector geometry.
static constexpr auto first()
Definition: geo_types.h:442
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:373
virtual geo::WireID GetID()
Detector simulation of raw signals on wires.
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:226
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
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.