RegPixelMapProducer.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file RegPixelMapProducer.h
3 /// \brief RegPixelMapProducer for RegCNN modified from PixelMapProducer.h
4 /// \author Ilsoo Seong - iseong@uci.edu
5 // Wenjie Wu - wenjieww@uci.edu
6 //
7 // Modifications to allow unwrapped collection view
8 // - Leigh Whitehead - leigh.howard.whitehead@cern.ch
9 ////////////////////////////////////////////////////////////////////////
10 
11 #include <iostream>
12 #include <ostream>
13 #include <list>
14 #include <algorithm>
15 
16 #include "larcorealg/Geometry/Exceptions.h" // geo::InvalidWireError
19 #include "TVector2.h"
20 
21 namespace cnn
22 {
23 
24  RegPixelMapProducer::RegPixelMapProducer(unsigned int nWire, unsigned int wRes, unsigned int nTdc, double tRes, int Global, bool ProngOnly, bool ByHit):
25  fNWire(nWire),
26  fWRes(wRes),
27  fNTdc(nTdc),
28  fTRes(tRes),
29  fGlobalWireMethod(Global),
30  fProngOnly(ProngOnly),
31  fByHit(ByHit),
32  fOffset{0,0}
33  {}
34 
36  detinfo::DetectorPropertiesData const& detProp,
38  art::FindManyP<recob::Wire> const& fmwire)
39  {
40 
41  hitwireidx.clear();
42  tmin_each_wire.clear();
43  tmax_each_wire.clear();
44  trms_max_each_wire.clear();
45  fOffset[0] = 0; fOffset[1] = 0;
46 
47  RegCNNBoundary bound = DefineBoundary(detProp, cluster);
48 
49  //return CreateMapGivenBoundaryByHit(clockData, detProp, cluster, bound, fmwire, fProngOnly);
50  return CreateMapGivenBoundary(clockData, detProp, cluster, bound, fmwire);
51 
52  }
53 
55  detinfo::DetectorPropertiesData const& detProp,
57  art::FindManyP<recob::Wire> const& fmwire,
58  const std::vector<float> &vtx)
59  {
60  // Create pixel maps around the vertex
61  hitwireidx.clear();
62  tmin_each_wire.clear();
63  tmax_each_wire.clear();
64  trms_max_each_wire.clear();
65  fOffset[0] = 0; fOffset[1] = 0;
66 
67  RegCNNBoundary bound = DefineBoundary(detProp, cluster, vtx);
68 
69  return CreateMapGivenBoundary(clockData, detProp, cluster, bound, fmwire);
70  }
71 
73  detinfo::DetectorPropertiesData const& detProp,
75  art::FindManyP<recob::Wire> const& fmwire,
76  art::FindManyP<recob::Track> const& fmtrkhit,
77  const std::vector<float> &vtx)
78  {
79  // tag prong by track
80  // Create pixel maps around the vertex
81  hitwireidx.clear();
82  tmin_each_wire.clear();
83  tmax_each_wire.clear();
84  trms_max_each_wire.clear();
85  fOffset[0] = 0; fOffset[1] = 0;
86 
87  RegCNNBoundary bound = DefineBoundary(detProp, cluster, vtx);
88 
89  if (fByHit) {
90  return CreateMapGivenBoundaryByHit(clockData, detProp, cluster, bound, fmwire, fmtrkhit, fProngOnly);
91  } else {
92  return CreateMapGivenBoundary(clockData, detProp, cluster, bound, fmwire);
93  }
94  }
95 
97  detinfo::DetectorPropertiesData const& detProp,
99  art::FindManyP<recob::Wire> const& fmwire,
100  art::FindManyP<recob::Shower> const& fmshwhit,
101  const std::vector<float> &vtx)
102  {
103  // tag prong by shower
104  // Create pixel maps around the vertex
105  hitwireidx.clear();
106  tmin_each_wire.clear();
107  tmax_each_wire.clear();
108  trms_max_each_wire.clear();
109  fOffset[0] = 0; fOffset[1] = 0;
110 
111  RegCNNBoundary bound = DefineBoundary(detProp, cluster, vtx);
112 
113  if (fByHit) {
114  return CreateMapGivenBoundaryByHit(clockData, detProp, cluster, bound, fmwire, fmshwhit, fProngOnly);
115  } else {
116  return CreateMapGivenBoundary(clockData, detProp, cluster, bound, fmwire);
117  }
118  }
119 
120 
122  detinfo::DetectorPropertiesData const& detProp,
124  const RegCNNBoundary& bound,
125  art::FindManyP<recob::Wire> const& fmwire)
126  {
127  RegPixelMap pm(fNWire, fWRes, fNTdc, fTRes, bound, 0);
128 
129  if (!fmwire.isValid()) return pm;
130 
131  // get all raw adc of every hit wire
132  for (size_t iwire = 0; iwire < hitwireidx.size(); ++iwire)
133  {
134  unsigned int iHit = hitwireidx[iwire];
135  std::vector< art::Ptr<recob::Wire> > wireptr = fmwire.at(iHit);
136  geo::WireID wireid = cluster[iHit]->WireID();
137 
138  for (size_t iwireptr = 0; iwireptr < wireptr.size(); ++iwireptr){
139  std::vector<geo::WireID> wireids = geom->ChannelToWire(wireptr[iwireptr]->Channel());
140  bool goodWID = false;
141  for (auto const & wid:wireids){
142  if (wid.Plane == wireid.Plane &&
143  wid.Wire == wireid.Wire &&
144  wid.TPC == wireid.TPC &&
145  wid.Cryostat == wireid.Cryostat) goodWID = true;
146  }
147  if (!goodWID) continue;
148 
149 
150  //int t0_hit = (int)( tmin_each_wire[iwire] - 3 * (trms_max_each_wire[iwire]) );
151  //int t1_hit = (int)( tmax_each_wire[iwire] + 3 * (trms_max_each_wire[iwire]) );
152  float hit_first_time = tmin_each_wire[iwire] - 3 * (trms_max_each_wire[iwire]);
153  float hit_end_time = tmax_each_wire[iwire] + 3 * (trms_max_each_wire[iwire]);
154  int t0_hit = (hit_first_time < 0) ? 0 : (int)hit_first_time;
155  int t1_hit = (hit_end_time > 4491) ? 4491 : (int)hit_end_time;
156 
157  const std::vector<float>& signal = wireptr[0]->Signal();
158  unsigned int globalWire = 0;
159  if (fGlobalWireMethod == 1){
160  globalWire = (unsigned int)GetGlobalWire(wireid);
161  if (wireid.TPC%2 == 1) {
162  if (wireid.Plane == 0) globalWire += fOffset[0];
163  if (wireid.Plane == 1) globalWire += fOffset[1];
164  }
165  }
166 
167  unsigned int globalplane = wireid.Plane;
168  for (int tt = t0_hit; tt <= t1_hit; ++tt)
169  {
170  //double correctedadc = (double) signal[tt];
171  double correctedadc = ( signal[tt] * TMath::Exp( (sampling_rate(clockData) * tt) / (detProp.ElectronLifetime()*1.e3) ) );
172  int tdc = tt;
173  if (wireid.TPC%2 == 0) tdc = -tdc;
174  if (fGlobalWireMethod == 2){
175  double globaltick = double(tt);
176  GetDUNEGlobalWireTDC(detProp, wireid, (double)tt, globalWire, globalplane, globaltick);
177  //tdc = (int)round(globaltick);
178  tdc = (int)globaltick;
179  // FIXIT
180  //if (globalplane==0 && correctedadc) {
181  // std::cout<<tt<<", "<<globalplane<<" | ";
182  // std::cout<<globalWire<<", "<<globaltick<<", "<<tdc<<", "<<correctedadc<<std::endl;
183  //}
184  }
185  pm.Add((int)globalWire, tdc, globalplane, correctedadc, wireid.TPC, 0);
186 
187  } // end of tt
188  } // end of iwireptr
189  } // end of iwire
190 
191  //std::cout<< "===============> Offsets: " << fOffset[0] << " " << fOffset[1] << std::endl;
192  return pm;
193 
194  }
195 
197  detinfo::DetectorPropertiesData const& detProp,
199  const RegCNNBoundary& bound,
200  art::FindManyP<recob::Wire> const& fmwire,
201  art::FindManyP<recob::Track> const& fmtrkhit,
202  const bool& ProngOnly)
203  {
204 
205  RegPixelMap pm(fNWire, fWRes, fNTdc, fTRes, bound, ProngOnly);
206 
207  if (!fmwire.isValid()) return pm;
208 
209  // Loop over hits
210  unsigned int nhits = cluster.size();
211  for (unsigned int ihit= 0; ihit< nhits; ++ihit) {
212  art::Ptr<recob::Hit> hit = cluster.at(ihit);
213  geo::WireID wireid = hit->WireID();
214 
215  unsigned int planeid = wireid.Plane;
216 
217  double peaktime = hit->PeakTime() ;
218  if (wireid.TPC%2 == 0) peaktime = -peaktime;
219 
220  unsigned int globalWire = 0;
221  unsigned int globalplane = planeid;
222  if (fGlobalWireMethod == 1) {
223  globalWire = GetGlobalWire(wireid);
224  if (wireid.TPC%2 == 1) {
225  if (wireid.Plane == 0) globalWire += fOffset[0];
226  if (wireid.Plane == 1) globalWire += fOffset[1];
227  }
228  } else if (fGlobalWireMethod == 2) {
229  globalWire = wireid.Wire;
230  GetDUNEGlobalWireTDC(detProp, wireid, cluster[ihit]->PeakTime(), globalWire, globalplane, peaktime);
231  } else {
232  std::cout<<"Wrong GlobalWireMethod"<<std::endl;
233  abort();
234  }
235 
236  double correctedHitCharge = (hit->Integral()*TMath::Exp((sampling_rate(clockData)*hit->PeakTime()) / (detProp.ElectronLifetime()*1.e3) ) );
237 
238  int hit_prong_tag = -1;
239  if (fmtrkhit.isValid() && fmtrkhit.at(ihit).size()!=0) {
240  hit_prong_tag = fmtrkhit.at(ihit)[0]->ID();
241  }
242 
243  pm.Add((int)globalWire, (int)round(peaktime), globalplane, correctedHitCharge, wireid.TPC, hit_prong_tag);
244  }
245 
246  pm.Finish();
247 
248  return pm;
249 
250  }
251 
253  detinfo::DetectorPropertiesData const& detProp,
255  const RegCNNBoundary& bound,
256  art::FindManyP<recob::Wire> const& fmwire,
257  art::FindManyP<recob::Shower> const& fmshwhit,
258  const bool& ProngOnly)
259  {
260 
261  RegPixelMap pm(fNWire, fWRes, fNTdc, fTRes, bound, ProngOnly);
262 
263  if (!fmwire.isValid()) return pm;
264 
265  // Loop over hits
266  unsigned int nhits = cluster.size();
267  for (unsigned int ihit= 0; ihit< nhits; ++ihit) {
268  art::Ptr<recob::Hit> hit = cluster.at(ihit);
269  geo::WireID wireid = hit->WireID();
270 
271  unsigned int planeid = wireid.Plane;
272 
273  double peaktime = hit->PeakTime() ;
274  if (wireid.TPC%2 == 0) peaktime = -peaktime;
275 
276  unsigned int globalWire = 0;
277  unsigned int globalplane = planeid;
278  if (fGlobalWireMethod == 1) {
279  globalWire = GetGlobalWire(wireid);
280  if (wireid.TPC%2 == 1) {
281  if (wireid.Plane == 0) globalWire += fOffset[0];
282  if (wireid.Plane == 1) globalWire += fOffset[1];
283  }
284  } else if (fGlobalWireMethod == 2) {
285  globalWire = wireid.Wire;
286  GetDUNEGlobalWireTDC(detProp, wireid, cluster[ihit]->PeakTime(), globalWire, globalplane, peaktime);
287  } else {
288  std::cout<<"Wrong GlobalWireMethod"<<std::endl;
289  abort();
290  }
291 
292  double correctedHitCharge = (hit->Integral()*TMath::Exp((sampling_rate(clockData)*hit->PeakTime()) / (detProp.ElectronLifetime()*1.e3) ) );
293 
294  int hit_prong_tag = -1;
295  if (fmshwhit.isValid() && fmshwhit.at(ihit).size()!=0) {
296  hit_prong_tag = fmshwhit.at(ihit)[0]->ID();
297  }
298 
299  pm.Add((int)globalWire, (int)round(peaktime), globalplane, correctedHitCharge, wireid.TPC, hit_prong_tag);
300  }
301 
302  std::cout<<"FIXME: Produce pixelmap from fmshwhit and prongonly = "<<ProngOnly<<std::endl;
303  pm.Finish();
304 
305  return pm;
306 
307  }
308 
309 
310  std::ostream& operator<<(std::ostream& os, const RegPixelMapProducer& p)
311  {
312  os << "RegPixelMapProducer: "
313  << p.NTdc() <<" tdcs X " << p.NWire() << " wires";
314  return os;
315  }
316 
317 
318 
321  {
323 
324  std::vector<float> time_0;
325  std::vector<float> time_1;
326  std::vector<float> time_2;
327 
328  std::vector<int> wire_0;
329  std::vector<int> wire_1;
330  std::vector<int> wire_2;
331 
332  unsigned int temp_wire = cluster[0]->WireID().Wire;
333  float temp_time_min = 1e5; //99999;
334  float temp_time_max = 0; //-99999;
335  float temp_trms_max = 0; //-99999;
336  for(size_t iHit = 0; iHit < cluster.size(); ++iHit)
337  {
338  geo::WireID wireid = cluster[iHit]->WireID();
339  //if (temp_wire != wireid.Wire || iHit == cluster.size()-1){ // lost last hit info
340  if (temp_wire != wireid.Wire ){ // lost last hit info
341  temp_wire = wireid.Wire;
342  hitwireidx.push_back(iHit-1);
343  tmin_each_wire.push_back(int(temp_time_min));
344  tmax_each_wire.push_back(int(temp_time_max));
345  trms_max_each_wire.push_back(temp_trms_max);
346  //temp_time_min = 99999; temp_time_max = -99999, temp_trms_max = -99999;
347  temp_time_min = 1e5; temp_time_max = 0; temp_trms_max = 0;
348  }
349  if (temp_time_min > cluster[iHit]->PeakTime()) temp_time_min = cluster[iHit]->PeakTime();
350  if (temp_time_max < cluster[iHit]->PeakTime()) temp_time_max = cluster[iHit]->PeakTime();
351  if (temp_trms_max < cluster[iHit]->RMS()) temp_trms_max = (float)cluster[iHit]->RMS();
352 
353  unsigned int planeid = wireid.Plane;
354  double peaktime = cluster[iHit]->PeakTime() ;
355  if (wireid.TPC%2 == 0) peaktime = -peaktime;
356 
357  unsigned int globalWire = 0;
358  unsigned int globalplane = planeid;
359  if (fGlobalWireMethod == 1){
360  globalWire = GetGlobalWire(wireid);
361  } else if (fGlobalWireMethod == 2 ){
362  GetDUNEGlobalWireTDC(detProp, wireid, cluster[iHit]->PeakTime(), globalWire, globalplane, peaktime);
363  } else {
364  std::cout << "Wrong GlobalWireMethod" << std::endl;
365  abort();
366  }
367 
368  if (wireid.TPC%2 == 1 && fGlobalWireMethod == 1) {
369  if (wireid.Plane == 0) globalWire += fOffset[0];
370  if (wireid.Plane == 1) globalWire += fOffset[1];
371  }
372 
373  if(globalplane==0){
374  time_0.push_back(peaktime);
375  wire_0.push_back((int)globalWire);
376  }
377  if(globalplane==1){
378  time_1.push_back(peaktime);
379  wire_1.push_back((int)globalWire);
380  }
381  if(globalplane==2){
382  time_2.push_back(peaktime);
383  wire_2.push_back((int)globalWire);
384  }
385  }
386 
387 
388  double tsum_0 = std::accumulate(time_0.begin(), time_0.end(), 0.0);
389  double tmean_0 = tsum_0 / time_0.size();
390 
391  double tsum_1 = std::accumulate(time_1.begin(), time_1.end(), 0.0);
392  double tmean_1 = tsum_1 / time_1.size();
393 
394  double tsum_2 = std::accumulate(time_2.begin(), time_2.end(), 0.0);
395  double tmean_2 = tsum_2 / time_2.size();
396 
397 
398  double wiresum_0 = std::accumulate(wire_0.begin(), wire_0.end(), 0.0);
399  double wiremean_0 = wiresum_0 / wire_0.size();
400 
401  double wiresum_1 = std::accumulate(wire_1.begin(), wire_1.end(), 0.0);
402  double wiremean_1 = wiresum_1 / wire_1.size();
403 
404  double wiresum_2 = std::accumulate(wire_2.begin(), wire_2.end(), 0.0);
405  double wiremean_2 = wiresum_2 / wire_2.size();
406 
407  //std::cout << "TDC ===> " << round(tmean_0) << " " << round(tmean_1) << " " << round(tmean_2) << std::endl;
408  //std::cout << "Wire ==> " << round(wiremean_0) << " " << round(wiremean_1) << " " << round(wiremean_2) << std::endl;
409  //std::cout << "Offset ==> " << fOffset[0] << " " << fOffset[1] << std::endl;
410 
411  //auto minwireelement_0= std::min_element(wire_0.begin(), wire_0.end());
412  //std::cout<<"minwire 0: "<<*minwireelement_0<<std::endl;
413  //auto minwireelement_1= std::min_element(wire_1.begin(), wire_1.end());
414  //std::cout<<"minwire 1: "<<*minwireelement_1<<std::endl;
415  //auto minwireelement_2= std::min_element(wire_2.begin(), wire_2.end());
416  //std::cout<<"minwire 2: "<<*minwireelement_2<<std::endl;
417 
418  //auto maxwireelement_0= std::max_element(wire_0.begin(), wire_0.end());
419  //std::cout<<"maxwire 0: "<<*maxwireelement_0<<std::endl;
420  //auto maxwireelement_1= std::max_element(wire_1.begin(), wire_1.end());
421  //std::cout<<"maxwire 1: "<<*maxwireelement_1<<std::endl;
422  //auto maxwireelement_2= std::max_element(wire_2.begin(), wire_2.end());
423  //std::cout<<"maxwire 2: "<<*maxwireelement_2<<std::endl;
424 
425 
426  //int minwire_0 = *minwireelement_0-1;
427  //int minwire_1 = *minwireelement_1-1;
428  //int minwire_2 = *minwireelement_2-1;
429 
430  RegCNNBoundary bound(fNWire,fNTdc,fWRes,fTRes,round(wiremean_0),round(wiremean_1),round(wiremean_2),round(tmean_0),round(tmean_1),round(tmean_2));
431  std::cout<<bound<<std::endl;
432 
433  return bound;
434  }
435 
438  const std::vector<float> &vtx)
439  {
440 
441  unsigned int temp_wire = cluster[0]->WireID().Wire;
442  float temp_time_min = 1e5; //99999;
443  float temp_time_max = 0; //-99999;
444  float temp_trms_max = 0; //-99999;
445  for(size_t iHit = 0; iHit < cluster.size(); ++iHit)
446  {
447  geo::WireID wireid = cluster[iHit]->WireID();
448  if (temp_wire != wireid.Wire ){ // lost last hit info
449  temp_wire = wireid.Wire;
450  hitwireidx.push_back(iHit-1);
451  tmin_each_wire.push_back(int(temp_time_min));
452  tmax_each_wire.push_back(int(temp_time_max));
453  trms_max_each_wire.push_back(temp_trms_max);
454  // temp_time_min = 99999; temp_time_max = -99999, temp_trms_max = -99999;
455  temp_time_min = 1e5; temp_time_max = 0; temp_trms_max = 0;
456  }
457  if (temp_time_min > cluster[iHit]->PeakTime()) temp_time_min = cluster[iHit]->PeakTime();
458  if (temp_time_max < cluster[iHit]->PeakTime()) temp_time_max = cluster[iHit]->PeakTime();
459  if (temp_trms_max < cluster[iHit]->RMS()) temp_trms_max = (float)cluster[iHit]->RMS();
460  }
461 
462  double center_wire[3] = {-99999, -99999, -99999};
463  double center_tick[3] = {-99999, -99999, -99999};
464  unsigned int size_vtx = (unsigned int) vtx.size();
465  if (size_vtx == 3){
466  double regvtx_loc[3] = {(double)vtx[0], (double)vtx[1], (double)vtx[2]};
467  int rawcrys = 0;
468  bool inTPC = false;
469  if (geom->FindTPCAtPosition(regvtx_loc).isValid) inTPC = true;
470  if (inTPC){
471  for (int iplane = 0; iplane<3; iplane++){
472  int rawtpc = (int) (geom->FindTPCAtPosition(regvtx_loc)).TPC;
473  geo::PlaneGeo const& planegeo_temp = geom->Plane(iplane);
474  geo::WireID w1;
475  try {
476  w1 = geom->NearestWireID(regvtx_loc, iplane, rawtpc, rawcrys);
477  }
478  catch (geo::InvalidWireError const& e){
479  if (!e.hasSuggestedWire()) throw;
480  w1 = planegeo_temp.ClosestWireID(e.suggestedWireID());
481  }
482  double time1 = detProp.ConvertXToTicks(regvtx_loc[0], iplane, rawtpc, rawcrys);
483  if (fGlobalWireMethod == 1){
484  std::cout << "You Can't use this with GlobalWireMethod = 1" << std::endl;
485  abort();
486  } else if (fGlobalWireMethod == 2){
487  unsigned int globalWire = (double)w1.Wire;
488  unsigned int globalPlane = w1.Plane;
489  double globalTDC = time1;
490  GetDUNEGlobalWireTDC(detProp, w1, time1, globalWire, globalPlane, globalTDC);
491  center_wire[globalPlane] = globalWire;
492  //center_tick[globalPlane] = (double)globalTDC;
493  center_tick[globalPlane] = (int)globalTDC;
494  } else {
495  std::cout << "Wrong Global Wire Method" << std::endl;
496  abort();
497  }
498  } // end of iplane
499  } // end of inTPC
500  } else if ( size_vtx == 6){
501  for (int ii = 0; ii < 3; ii++){
502  center_wire[ii] = vtx[ii*2+1];
503  center_tick[ii] = vtx[ii*2];
504  }
505  } else{
506  std::cout << "Wrong reconstructed vertex" << std::endl;
507  std::cout << "-->" << size_vtx << std::endl;
508  }
509 
510 
511  int shift = 56*fWRes;
512  center_wire[0] += fNWire*fWRes/2 - shift;
513  center_wire[1] -= fNWire*fWRes/2 - shift;
514  center_wire[2] += fNWire*fWRes/2 - shift;
515 
516  RegCNNBoundary bound(fNWire,fNTdc,fWRes,fTRes,round(center_wire[0]),round(center_wire[1]),round(center_wire[2]),round(center_tick[0]),round(center_tick[1]),round(center_tick[2]));
517  return bound;
518  }
519 
520 
522  // Get Global Wire Coordinate for RegCNN
523  double globalWire = -9999;
524  unsigned int nwires = geom->Nwires(wireID.Plane, 0, wireID.Cryostat);
525  // Induction
526  if (geom->SignalType(wireID) == geo::kInduction) {
527  double WireCentre[3] = {0};
528  geom->WireIDToWireGeo(wireID).GetCenter(WireCentre);
529  geo::PlaneID p1;
530  int temp_tpc = 0;
531  if (wireID.TPC % 2 == 0) { temp_tpc = 0; }
532  else { temp_tpc = 1; }
533  p1 = geo::PlaneID(wireID.Cryostat, temp_tpc, wireID.Plane);
534  globalWire = geom->WireCoordinate(WireCentre[1], WireCentre[2], p1);
535  }
536  // Collection
537  else {
538  int block = wireID.TPC / 4;
539  globalWire = (double)( ((int)nwires*block) + wireID.Wire );
540  }
541  return round(globalWire);
542 
543  }
544 
545  std::vector<unsigned int> getUniques(std::vector<unsigned int> coll)
546  {
547  std::vector<unsigned int> uniques;
548  for (unsigned int tpc : coll)
549  {
550  if (std::find(uniques.begin(), uniques.end(), tpc) == uniques.end())
551  uniques.push_back(tpc);
552  }
553  return uniques;
554  }
555 
557  {
558  // find hits passing through an APA
559  std::vector<unsigned int> list_TPCs;
560  std::map<unsigned int, double> map_mean_U, map_mean_V, map_Twei_U, map_Twei_V;
561  int nhits_z[24] = {0};
562  for (unsigned int iHit = 0; iHit < cluster.size(); ++iHit)
563  {
564  geo::WireID wireid = cluster[iHit]->WireID();
565  if (wireid.Plane == 2){
566  nhits_z[wireid.TPC] += 1;
567  }
568  //if (cluster[iHit]->PeakTime() < 30){ // select 30 ticks
569  if (cluster[iHit]->PeakTime() < 150){ // select 150 ticks
570  double Twei = cluster[iHit]->PeakTime()+1.; //
571  list_TPCs.push_back(wireid.TPC);
572  if (wireid.Plane == 0){
573  map_mean_U[wireid.TPC] += GetGlobalWire(wireid)/Twei;
574  map_Twei_U[wireid.TPC] += 1.0/Twei;
575  }
576  if (wireid.Plane == 1){
577  map_mean_V[wireid.TPC] += GetGlobalWire(wireid)/Twei;
578  map_Twei_V[wireid.TPC] += 1.0/Twei;
579  }
580  }
581  }
582  std::vector<unsigned int> unique_TPCs = getUniques(list_TPCs);
583  for (unsigned int tmp_idx : unique_TPCs)
584  {
585  if (map_Twei_U[tmp_idx]>0) map_mean_U[tmp_idx] /= map_Twei_U[tmp_idx];
586  if (map_Twei_V[tmp_idx]>0) map_mean_V[tmp_idx] /= map_Twei_V[tmp_idx];
587  }
588  // obtain offsets for U and V planes
589  if (unique_TPCs.size() > 1){
590  // shift global wire for an event passing through an APA
591  int maxsum = 0;
592  unsigned int nmax_tpcs[2] = {10000,10000};
593  for (unsigned int ii = 0; ii < unique_TPCs.size()-1; ++ii)
594  {
595  unsigned int tpc1 = unique_TPCs[ii];
596  unsigned int tpc2 = unique_TPCs[ii+1];
597  if (tpc1/4 != tpc2/4) continue;
598  if (tpc1%2 == tpc2%2) continue;
599  int sum = nhits_z[tpc1] + nhits_z[tpc2];
600  if (sum > maxsum){
601  maxsum = sum;
602  nmax_tpcs[0] = tpc1;
603  nmax_tpcs[1] = tpc2;
604  }
605  }
606  if (nmax_tpcs[0] < 10000 && nmax_tpcs[1] < 10000){
607  double offsetU = 0, offsetV = 0;
608  if (map_Twei_U[nmax_tpcs[0]] > 0 && map_Twei_U[nmax_tpcs[1]] > 0) offsetU = map_mean_U[nmax_tpcs[0]] - map_mean_U[nmax_tpcs[1]];
609  if (map_Twei_V[nmax_tpcs[0]] > 0 && map_Twei_V[nmax_tpcs[1]] > 0) offsetV = map_mean_V[nmax_tpcs[0]] - map_mean_V[nmax_tpcs[1]];
610  fOffset[0] = round(offsetU);
611  fOffset[1] = round(offsetV);
612  } // end of nmax_tpc
613  } // ned of unique_TPCs
614  }
615 
617  const geo::WireID& wireID, double localTDC,
618  unsigned int& globalWire, unsigned int& globalPlane,
619  double& globalTDC){
620  unsigned int localWire = wireID.Wire;
621  unsigned int plane = wireID.Plane;
622  unsigned int tpc = wireID.TPC;
623 
624  unsigned int nWiresTPC = 400;
625  unsigned int wireGap = 4;
626  double driftLen = geom->TPC(tpc,0).DriftDistance();
627  double apaLen = geom->TPC(tpc,0).Width() - geom->TPC(tpc,0).ActiveWidth();
628  double driftVel = detProp.DriftVelocity();
629  //unsigned int drift_size = (driftLen / driftVel) * 2;
630  //unsigned int apa_size = 4*(apaLen / driftVel) * 2;
631  double drift_size = (driftLen / driftVel) * 2;
632  double apa_size = 4*(apaLen / driftVel) * 2;
633 
634  globalWire = 0;
635  globalPlane = 0;
636  // Collection plane has more wires
637  if(plane == 2){
638  nWiresTPC=480;
639  wireGap = 5;
640  globalPlane = 2;
641  }
642  bool includeZGap = true;
643  if(includeZGap) nWiresTPC += wireGap;
644 
645  // Workspace geometry has two drift regions
646  // |-----|-----| / /
647  // y ^ | 3 | 2 |/ /
648  // | -| z |-----|-----| /
649  // | / | 1 | 0 | /
650  // x <---|/ |-----|-----|/
651  //
652 
653  int tpcMod4 = tpc%4;
654  int offset = 0;
655  // Induction views depend on the drift direction
656  if(plane < 2){
657  // For TPCs 0 and 3 keep U and V as defined.
658  if(tpcMod4 == 0 || tpcMod4 == 3){
659  globalPlane = plane;
660  // But reverse the TDCs
661  }
662  // For TPCs 1 and 2, swap U and V.
663  else{
664  if(plane == 0) globalPlane = 1;
665  else globalPlane = 0;
666  }
667  }
668  if(globalPlane != 1){
669  globalWire += (tpc/4)*nWiresTPC + (tpcMod4>1)*offset + localWire;
670  }
671  else{
672  globalWire += ((23-tpc)/4)*nWiresTPC + (tpcMod4>1)*offset + localWire;
673  }
674 
675  if(tpcMod4 == 0 || tpcMod4 == 2){
676  //globalTDC = (float)( drift_size - (double)localTDC );
677  globalTDC = drift_size - localTDC;
678  }
679  else {
680  //globalTDC = (float)( (double)localTDC + drift_size + apa_size );
681  globalTDC = localTDC + drift_size + apa_size;
682  }
683 
684 
685  } // end of GetDUNEGlobalWireTDC
686 
687 }
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
RegCNNBoundary DefineBoundary(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit > > const &cluster)
Get boundaries for pixel map representation of cluster.
RegPixelMap CreateMap(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit > > const &cluster, art::FindManyP< recob::Wire > const &fmwire)
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
double GetGlobalWire(const geo::WireID &wireID)
Function to convert to a global unwrapped wire number.
geo::WireID WireID() const
Definition: Hit.h:233
RegPixelMap, basic input to CNN neural net.
Definition: RegPixelMap.h:22
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:211
struct vector vector
unsigned int NWire() const
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
Producer algorithm for RegPixelMap, input to CVN neural net.
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
Cluster finding and building.
void Add(const int &wire, const int &tdc, const unsigned int &view, const double &pe, const unsigned int &tpc, int hit_prong_tag)
Definition: RegPixelMap.cxx:60
RegPixelMap CreateMapGivenBoundaryByHit(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit > > const &cluster, const RegCNNBoundary &bound, art::FindManyP< recob::Wire > const &fmwire, art::FindManyP< recob::Track > const &fmtrkhit, const bool &ProngOnly)
double Width() const
Width is associated with x coordinate [cm].
Definition: TPCGeo.h:109
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
RegPixelMapProducer(unsigned int nWire, unsigned int wRes, unsigned int nTdc, double tRes, int Global, bool ProngOnly, bool ByHit)
art::ServiceHandle< geo::Geometry > geom
void ShiftGlobalWire(std::vector< art::Ptr< recob::Hit > > const &cluster)
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
Definition: type_traits.h:61
const double e
RegPixelMap CreateMapGivenBoundary(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit > > const &cluster, const RegCNNBoundary &bound, art::FindManyP< recob::Wire > const &fmwire)
Signal from induction planes.
Definition: geo_types.h:145
RegPixelMapProducer for RegCNN modified from PixelMapProducer.h.
Collection of exceptions for Geometry system.
std::vector< int > tmin_each_wire
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
p
Definition: test.py:223
double ConvertXToTicks(double X, int p, int t, int c) const
unsigned int fNWire
Number of wires, length for pixel maps.
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
unsigned int fNTdc
Number of tdcs, width of pixel map.
Detector simulation of raw signals on wires.
std::vector< float > trms_max_each_wire
void GetDUNEGlobalWireTDC(detinfo::DetectorPropertiesData const &detProp, const geo::WireID &wireID, double localTDC, unsigned int &globalWire, unsigned int &globalPlane, double &globalTDC)
unsigned int NTdc() const
std::vector< int > hitwireidx
Defines an enumeration for cellhit classification.
std::vector< int > tmax_each_wire
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
double DriftDistance() const
Definition: TPCGeo.h:155
Contains all timing reference information for the detector.
double ActiveWidth() const
Width (associated with x coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:97
geo::WireID ClosestWireID(geo::WireID::WireID_t wireNo) const
Returns the closest valid wire ID to the specified wire.
Definition: PlaneGeo.h:1520
std::ostream & operator<<(std::ostream &os, const RegPixelMap3DProducer &p)
Exception thrown on invalid wire number.
Definition: Exceptions.h:42
geo::WireID NearestWireID(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the ID of wire closest to position in the specified TPC.
std::vector< unsigned int > getUniques(std::vector< unsigned int > coll)
detail::Node< FrameID, bool > PlaneID
Definition: CRTID.h:125
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:73
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
geo::WireID suggestedWireID() const
Returns a better wire ID.
Definition: Exceptions.h:120
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
bool hasSuggestedWire() const
Returns whether we known a better wire number.
Definition: Exceptions.h:114
QTextStream & endl(QTextStream &s)
WireGeo const & WireIDToWireGeo(geo::WireID const &wireid) const