Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
nnet::EmTrack< N > Class Template Reference

#include <EmTrack.h>

Classes

struct  Config
 

Public Types

using key = std::tuple< unsigned int, unsigned int, unsigned int >
 
using cryo_tpc_view_keymap = std::map< key, std::vector< size_t >>
 

Public Member Functions

 EmTrack (Config const &c, std::string const &s, art::ProducesCollector &pc)
 
void produce (art::Event &e)
 

Private Types

using writer = anab::MVAWriter< N >
 

Private Member Functions

bool isViewSelected (int view) const
 
void make_clusters (art::Event &evt, std::vector< art::Ptr< recob::Hit >> const &hitPtrList, std::vector< char > const &hitInFA, EmTrack::cryo_tpc_view_keymap const &hitMap)
 
void make_tracks (art::Event const &evt, std::vector< char > const &hitInFA)
 make tracks More...
 
cryo_tpc_view_keymap create_hitmap (std::vector< art::Ptr< recob::Hit >> const &hitPtrList) const
 
std::vector< char > classify_hits (art::Event const &evt, EmTrack::cryo_tpc_view_keymap const &hitMap, std::vector< art::Ptr< recob::Hit >> const &hitPtrList)
 

Private Attributes

const size_t fBatchSize
 
std::unique_ptr< PointIdAlgTools::IPointIdAlgfPointIdAlgTool
 
writer fMVAWriter
 
const art::InputTag fWireProducerLabel
 
const art::InputTag fHitModuleLabel
 
const art::InputTag fClusterModuleLabel
 
const art::InputTag fTrackModuleLabel
 
const bool fDoClusters
 
const bool fDoTracks
 
const std::vector< int > fViews
 
const art::InputTag fNewClustersTag
 

Detailed Description

template<size_t N>
class nnet::EmTrack< N >

Definition at line 31 of file EmTrack.h.

Member Typedef Documentation

template<size_t N>
using nnet::EmTrack< N >::cryo_tpc_view_keymap = std::map<key, std::vector<size_t>>

Definition at line 34 of file EmTrack.h.

template<size_t N>
using nnet::EmTrack< N >::key = std::tuple<unsigned int, unsigned int, unsigned int>

Definition at line 33 of file EmTrack.h.

template<size_t N>
using nnet::EmTrack< N >::writer = anab::MVAWriter<N>
private

Definition at line 78 of file EmTrack.h.

Constructor & Destructor Documentation

template<size_t N>
nnet::EmTrack< N >::EmTrack ( EmTrack< N >::Config const &  config,
std::string const &  s,
art::ProducesCollector pc 
)
explicit

Definition at line 394 of file EmTrack.h.

398  , fPointIdAlgTool(art::make_tool<PointIdAlgTools::IPointIdAlg>(
399  config.PointIdAlg.get_PSet()))
400  , fMVAWriter(collector, "emtrkmichel")
406  , fDoTracks(!fTrackModuleLabel.label().empty())
407  , fViews(config.Views())
408  , fNewClustersTag(
409  module_label,
410  "",
412  {
413  fMVAWriter.template produces_using<recob::Hit>();
414 
415  if (!fClusterModuleLabel.label().empty()) {
416  collector.produces<std::vector<recob::Cluster>>();
417  collector.produces<art::Assns<recob::Cluster, recob::Hit>>();
418 
419  fMVAWriter.template produces_using<recob::Cluster>();
420  }
421 
422  if (!fTrackModuleLabel.label().empty()) {
423  fMVAWriter.template produces_using<recob::Track>();
424  }
425  }
const art::InputTag fTrackModuleLabel
Definition: EmTrack.h:83
const art::InputTag fWireProducerLabel
Definition: EmTrack.h:80
fhicl::Table< PointIdAlgTools::IPointIdAlg::Config > PointIdAlg
Definition: EmTrack.h:40
writer fMVAWriter
Definition: EmTrack.h:79
std::unique_ptr< PointIdAlgTools::IPointIdAlg > fPointIdAlgTool
Definition: EmTrack.h:77
const std::vector< int > fViews
Definition: EmTrack.h:86
fhicl::Atom< art::InputTag > TrackModuleLabel
Definition: EmTrack.h:60
fhicl::Atom< art::InputTag > HitModuleLabel
Definition: EmTrack.h:50
std::string const & label() const noexcept
Definition: InputTag.cc:79
const bool fDoClusters
Definition: EmTrack.h:84
static Config * config
Definition: config.cpp:1054
fhicl::Atom< art::InputTag > ClusterModuleLabel
Definition: EmTrack.h:54
const art::InputTag fHitModuleLabel
Definition: EmTrack.h:81
fhicl::Atom< size_t > BatchSize
Definition: EmTrack.h:42
fhicl::Sequence< int > Views
Definition: EmTrack.h:65
const art::InputTag fNewClustersTag
Definition: EmTrack.h:88
fhicl::Atom< art::InputTag > WireLabel
Definition: EmTrack.h:46
const size_t fBatchSize
Definition: EmTrack.h:76
const art::InputTag fClusterModuleLabel
Definition: EmTrack.h:82
const bool fDoTracks
Definition: EmTrack.h:85

Member Function Documentation

template<size_t N>
std::vector< char > nnet::EmTrack< N >::classify_hits ( art::Event const &  evt,
EmTrack< N >::cryo_tpc_view_keymap const &  hitMap,
std::vector< art::Ptr< recob::Hit >> const &  hitPtrList 
)
private

Definition at line 332 of file EmTrack.h.

335  {
336  auto hitID = fMVAWriter.template initOutputs<recob::Hit>(
337  fHitModuleLabel, hitPtrList.size(), fPointIdAlgTool->outputLabels());
338 
339  auto const clockData =
341  auto const detProp =
343  evt, clockData);
344  auto wireHandle =
345  evt.getValidHandle<std::vector<recob::Wire>>(fWireProducerLabel);
346  std::vector<char> hitInFA(hitPtrList.size(),
347  0); // tag hits in fid. area as 1, use 0 for hits
348  // close to the projectrion edges
349  for (auto const& [key, hits] : hitMap) {
350  auto const& [cryo, tpc, view] = key;
351  if (!isViewSelected(view))
352  continue; // should not happen, hits were selected
353 
354  fPointIdAlgTool->setWireDriftData(
355  clockData, detProp, *wireHandle, view, tpc, cryo);
356 
357  // (1) do all hits in this plane
358  // ------------------------------------------------
359  for (size_t idx = 0; idx < hits.size(); idx += fBatchSize) {
360  std::vector<std::pair<unsigned int, float>> points;
361  std::vector<size_t> keys;
362  for (size_t k = 0; k < fBatchSize; ++k) {
363  if (idx + k >= hits.size()) {
364  break;
365  } // careful about the tail
366 
367  size_t h = hits[idx + k]; // h is the Ptr< recob::Hit >::key()
368  const recob::Hit& hit = *(hitPtrList[h]);
369  points.emplace_back(hit.WireID().Wire, hit.PeakTime());
370  keys.push_back(h);
371  }
372 
373  auto batch_out = fPointIdAlgTool->predictIdVectors(points);
374  if (points.size() != batch_out.size()) {
375  throw cet::exception("EmTrack")
376  << "hits processing failed" << std::endl;
377  }
378 
379  for (size_t k = 0; k < points.size(); ++k) {
380  size_t h = keys[k];
381  fMVAWriter.setOutput(hitID, h, batch_out[k]);
382  if (fPointIdAlgTool->isInsideFiducialRegion(points[k].first,
383  points[k].second)) {
384  hitInFA[h] = 1;
385  }
386  }
387  } // hits done
388  // ------------------------------------------------------------------
389  }
390  return hitInFA;
391  }
const art::InputTag fWireProducerLabel
Definition: EmTrack.h:80
writer fMVAWriter
Definition: EmTrack.h:79
geo::WireID WireID() const
Definition: Hit.h:233
void setOutput(FVector_ID id, size_t key, std::array< float, N > const &values)
Definition: MVAWriter.h:175
std::unique_ptr< PointIdAlgTools::IPointIdAlg > fPointIdAlgTool
Definition: EmTrack.h:77
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
const art::InputTag fHitModuleLabel
Definition: EmTrack.h:81
Detector simulation of raw signals on wires.
bool isViewSelected(int view) const
Definition: EmTrack.h:452
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
const size_t fBatchSize
Definition: EmTrack.h:76
TCEvent evt
Definition: DataStructs.cxx:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
std::tuple< unsigned int, unsigned int, unsigned int > key
Definition: EmTrack.h:33
template<size_t N>
EmTrack< N >::cryo_tpc_view_keymap nnet::EmTrack< N >::create_hitmap ( std::vector< art::Ptr< recob::Hit >> const &  hitPtrList) const
private

Definition at line 312 of file EmTrack.h.

314  {
315  cryo_tpc_view_keymap hitMap;
316  for (auto const& hptr : hitPtrList) {
317  auto const& h = *hptr;
318  unsigned int view = h.WireID().Plane;
319  if (!isViewSelected(view))
320  continue;
321 
322  unsigned int cryo = h.WireID().Cryostat;
323  unsigned int tpc = h.WireID().TPC;
324 
325  hitMap[{cryo, tpc, view}].push_back(hptr.key());
326  }
327  return hitMap;
328  }
std::map< key, std::vector< size_t >> cryo_tpc_view_keymap
Definition: EmTrack.h:34
bool isViewSelected(int view) const
Definition: EmTrack.h:452
template<size_t N>
bool nnet::EmTrack< N >::isViewSelected ( int  view) const
private

Definition at line 452 of file EmTrack.h.

453  {
454  if (fViews.empty())
455  return true;
456  return cet::search_all(fViews, view);
457  }
const std::vector< int > fViews
Definition: EmTrack.h:86
bool search_all(FwdCont const &, Datum const &)
template<size_t N>
void nnet::EmTrack< N >::make_clusters ( art::Event evt,
std::vector< art::Ptr< recob::Hit >> const &  hitPtrList,
std::vector< char > const &  hitInFA,
EmTrack< N >::cryo_tpc_view_keymap const &  hitMap 
)
private

Definition at line 104 of file EmTrack.h.

108  {
109  // **************** prepare for new clusters ****************
110  auto clusters = std::make_unique<std::vector<recob::Cluster>>();
111  auto clu2hit = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
112 
113  // ************** get and sort input clusters ***************
114  auto cluListHandle =
115  evt.getValidHandle<std::vector<recob::Cluster>>(fClusterModuleLabel);
116  std::vector<art::Ptr<recob::Cluster>> cluPtrList;
117  art::fill_ptr_vector(cluPtrList, cluListHandle);
118 
120  for (auto const& c : cluPtrList) {
121  unsigned int view = c->Plane().Plane;
122  if (!isViewSelected(view))
123  continue;
124 
125  unsigned int cryo = c->Plane().Cryostat;
126  unsigned int tpc = c->Plane().TPC;
127 
128  cluMap[{cryo, tpc, view}].push_back(c.key());
129  }
130 
131  auto cluID = fMVAWriter.template initOutputs<recob::Cluster>(
132  fNewClustersTag, fPointIdAlgTool->outputLabels());
133 
134  unsigned int cidx = 0; // new clusters index
135  art::FindManyP<recob::Hit> hitsFromClusters(
136  cluListHandle, evt, fClusterModuleLabel);
137  std::vector<bool> hitUsed(hitPtrList.size(),
138  false); // tag hits used in clusters
139  // clang-format off
140  for (auto const & [key, clusters_keys] : cluMap)
141  {
142  auto const& [cryo, tpc, view]= key;
143  // clang-format on
144  if (!isViewSelected(view))
145  continue; // should not happen, clusters were pre-selected
146 
147  for (size_t c : clusters_keys) // c is the Ptr< recob::Cluster >::key()
148  {
149  auto v = hitsFromClusters.at(c);
150  if (v.empty())
151  continue;
152 
153  for (auto const& hit : v) {
154  if (hitUsed[hit.key()]) {
155  mf::LogWarning("EmTrack") << "hit already used in another cluster";
156  }
157  hitUsed[hit.key()] = true;
158  }
159 
160  auto vout = fMVAWriter.template getOutput<recob::Hit>(
161  v, [&](art::Ptr<recob::Hit> const& ptr) {
162  return (float)hitInFA[ptr.key()];
163  });
164 
165  float pvalue = vout[0] / (vout[0] + vout[1]);
166  mf::LogVerbatim("EmTrack")
167  << "cluster in tpc:" << tpc << " view:" << view
168  << " size:" << v.size() << " p:" << pvalue;
169 
170  clusters->emplace_back(recob::Cluster(0.0F,
171  0.0F,
172  0.0F,
173  0.0F,
174  0.0F,
175  0.0F,
176  0.0F,
177  0.0F,
178  0.0F,
179  0.0F,
180  0.0F,
181  0.0F,
182  0.0F,
183  0.0F,
184  0.0F,
185  0.0F,
186  0.0F,
187  0.0F,
188  v.size(),
189  0.0F,
190  0.0F,
191  cidx,
192  (geo::View_t)view,
193  v.front()->WireID().planeID()));
194  util::CreateAssn(evt, *clusters, v, *clu2hit);
195  cidx++;
196 
197  fMVAWriter.addOutput(cluID,
198  vout); // add copy of the input cluster
199  }
200 
201  // (2b) make single-hit clusters
202  // --------------------------------------------
203  for (size_t h :
204  hitMap.at({cryo, tpc, view})) // h is the Ptr< recob::Hit >::key()
205  {
206  if (hitUsed[h])
207  continue;
208 
209  auto vout = fMVAWriter.template getOutput<recob::Hit>(h);
210  float pvalue = vout[0] / (vout[0] + vout[1]);
211 
212  mf::LogVerbatim("EmTrack")
213  << "single hit in tpc:" << tpc << " view:" << view
214  << " wire:" << hitPtrList[h]->WireID().Wire
215  << " drift:" << hitPtrList[h]->PeakTime() << " p:" << pvalue;
216 
217  art::PtrVector<recob::Hit> cluster_hits;
218  cluster_hits.push_back(hitPtrList[h]);
219  clusters->emplace_back(
220  recob::Cluster(0.0F,
221  0.0F,
222  0.0F,
223  0.0F,
224  0.0F,
225  0.0F,
226  0.0F,
227  0.0F,
228  0.0F,
229  0.0F,
230  0.0F,
231  0.0F,
232  0.0F,
233  0.0F,
234  0.0F,
235  0.0F,
236  0.0F,
237  0.0F,
238  1,
239  0.0F,
240  0.0F,
241  cidx,
242  (geo::View_t)view,
243  hitPtrList[h]->WireID().planeID()));
244  util::CreateAssn(evt, *clusters, cluster_hits, *clu2hit);
245  cidx++;
246 
248  cluID, vout); // add single-hit cluster tagging unclutered hit
249  }
250  mf::LogVerbatim("EmTrack")
251  << "...produced " << cidx - clusters_keys.size()
252  << " single-hit clusters.";
253  }
254 
255  evt.put(std::move(clusters));
256  evt.put(std::move(clu2hit));
257  }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
writer fMVAWriter
Definition: EmTrack.h:79
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::unique_ptr< PointIdAlgTools::IPointIdAlg > fPointIdAlgTool
Definition: EmTrack.h:77
Set of hits with a 2D structure.
Definition: Cluster.h:71
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
std::map< key, std::vector< size_t >> cryo_tpc_view_keymap
Definition: EmTrack.h:34
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
Detector simulation of raw signals on wires.
bool isViewSelected(int view) const
Definition: EmTrack.h:452
void addOutput(FVector_ID id, std::array< float, N > const &values)
Definition: MVAWriter.h:180
const art::InputTag fNewClustersTag
Definition: EmTrack.h:88
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
const art::InputTag fClusterModuleLabel
Definition: EmTrack.h:82
std::tuple< unsigned int, unsigned int, unsigned int > key
Definition: EmTrack.h:33
template<size_t N>
void nnet::EmTrack< N >::make_tracks ( art::Event const &  evt,
std::vector< char > const &  hitInFA 
)
private

make tracks

Definition at line 262 of file EmTrack.h.

264  {
265  auto trkListHandle =
266  evt.getValidHandle<std::vector<recob::Track>>(fTrackModuleLabel);
267  art::FindManyP<recob::Hit> hitsFromTracks(
268  trkListHandle, evt, fTrackModuleLabel);
269  std::vector<std::vector<art::Ptr<recob::Hit>>> trkHitPtrList(
270  trkListHandle->size());
271  for (size_t t = 0; t < trkListHandle->size(); ++t) {
272  auto v = hitsFromTracks.at(t);
273  size_t nh[3] = {0, 0, 0};
274  for (auto const& hptr : v) {
275  ++nh[hptr->View()];
276  }
277  size_t best_view = 2; // collection
278  if ((nh[0] >= nh[1]) && (nh[0] > 2 * nh[2]))
279  best_view = 0; // ind1
280  if ((nh[1] >= nh[0]) && (nh[1] > 2 * nh[2]))
281  best_view = 1; // ind2
282 
283  size_t k = 0;
284  while (!isViewSelected(best_view)) {
285  best_view = (best_view + 1) % 3;
286  if (++k > 3) {
287  throw cet::exception("EmTrack")
288  << "No views selected at all?" << std::endl;
289  }
290  }
291 
292  for (auto const& hptr : v) {
293  if (hptr->View() == best_view)
294  trkHitPtrList[t].emplace_back(hptr);
295  }
296  }
297 
298  auto trkID = fMVAWriter.template initOutputs<recob::Track>(
299  fTrackModuleLabel, trkHitPtrList.size(), fPointIdAlgTool->outputLabels());
300  for (size_t t = 0; t < trkHitPtrList.size();
301  ++t) // t is the Ptr< recob::Track >::key()
302  {
303  auto vout = fMVAWriter.template getOutput<recob::Hit>(
304  trkHitPtrList[t], [&](art::Ptr<recob::Hit> const& ptr) {
305  return (float)hitInFA[ptr.key()];
306  });
307  fMVAWriter.setOutput(trkID, t, vout);
308  }
309  }
const art::InputTag fTrackModuleLabel
Definition: EmTrack.h:83
writer fMVAWriter
Definition: EmTrack.h:79
void setOutput(FVector_ID id, size_t key, std::array< float, N > const &values)
Definition: MVAWriter.h:175
std::unique_ptr< PointIdAlgTools::IPointIdAlg > fPointIdAlgTool
Definition: EmTrack.h:77
bool isViewSelected(int view) const
Definition: EmTrack.h:452
TCEvent evt
Definition: DataStructs.cxx:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
template<size_t N>
void nnet::EmTrack< N >::produce ( art::Event e)

Definition at line 430 of file EmTrack.h.

431  {
432  mf::LogVerbatim("EmTrack")
433  << "next event: " << evt.run() << " / " << evt.id().event();
434  auto hitListHandle =
435  evt.getValidHandle<std::vector<recob::Hit>>(fHitModuleLabel);
436  std::vector<art::Ptr<recob::Hit>> hitPtrList;
437  art::fill_ptr_vector(hitPtrList, hitListHandle);
438  const EmTrack::cryo_tpc_view_keymap hitMap = create_hitmap(hitPtrList);
439  const std::vector<char> hitInFA = classify_hits(evt, hitMap, hitPtrList);
440 
441  if (fDoClusters)
442  make_clusters(evt, hitPtrList, hitInFA, hitMap);
443 
444  if (fDoTracks)
445  make_tracks(evt, hitInFA);
447  }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
unsigned int event
Definition: DataStructs.h:636
unsigned int run
Definition: DataStructs.h:637
writer fMVAWriter
Definition: EmTrack.h:79
void make_tracks(art::Event const &evt, std::vector< char > const &hitInFA)
make tracks
Definition: EmTrack.h:262
std::vector< char > classify_hits(art::Event const &evt, EmTrack::cryo_tpc_view_keymap const &hitMap, std::vector< art::Ptr< recob::Hit >> const &hitPtrList)
Definition: EmTrack.h:332
const bool fDoClusters
Definition: EmTrack.h:84
std::map< key, std::vector< size_t >> cryo_tpc_view_keymap
Definition: EmTrack.h:34
const art::InputTag fHitModuleLabel
Definition: EmTrack.h:81
void make_clusters(art::Event &evt, std::vector< art::Ptr< recob::Hit >> const &hitPtrList, std::vector< char > const &hitInFA, EmTrack::cryo_tpc_view_keymap const &hitMap)
Definition: EmTrack.h:104
void saveOutputs(art::Event &evt)
Check consistency and save all the results in the event.
Definition: MVAWriter.h:325
cryo_tpc_view_keymap create_hitmap(std::vector< art::Ptr< recob::Hit >> const &hitPtrList) const
Definition: EmTrack.h:312
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
const bool fDoTracks
Definition: EmTrack.h:85

Member Data Documentation

template<size_t N>
const size_t nnet::EmTrack< N >::fBatchSize
private

Definition at line 76 of file EmTrack.h.

template<size_t N>
const art::InputTag nnet::EmTrack< N >::fClusterModuleLabel
private

Definition at line 82 of file EmTrack.h.

template<size_t N>
const bool nnet::EmTrack< N >::fDoClusters
private

Definition at line 84 of file EmTrack.h.

template<size_t N>
const bool nnet::EmTrack< N >::fDoTracks
private

Definition at line 85 of file EmTrack.h.

template<size_t N>
const art::InputTag nnet::EmTrack< N >::fHitModuleLabel
private

Definition at line 81 of file EmTrack.h.

template<size_t N>
writer nnet::EmTrack< N >::fMVAWriter
private

Definition at line 79 of file EmTrack.h.

template<size_t N>
const art::InputTag nnet::EmTrack< N >::fNewClustersTag
private

Definition at line 88 of file EmTrack.h.

template<size_t N>
std::unique_ptr<PointIdAlgTools::IPointIdAlg> nnet::EmTrack< N >::fPointIdAlgTool
private

Definition at line 77 of file EmTrack.h.

template<size_t N>
const art::InputTag nnet::EmTrack< N >::fTrackModuleLabel
private

Definition at line 83 of file EmTrack.h.

template<size_t N>
const std::vector<int> nnet::EmTrack< N >::fViews
private

Definition at line 86 of file EmTrack.h.

template<size_t N>
const art::InputTag nnet::EmTrack< N >::fWireProducerLabel
private

Definition at line 80 of file EmTrack.h.


The documentation for this class was generated from the following file: