LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrackShowerHits_module.cc
Go to the documentation of this file.
1 // Class: TrackShowerHits
3 // Module Type: producer
4 // File: TrackShowerHits_module.cc
5 // Authors: dorota.stefan@cern.ch robert.sulej@cern.ch
7 
13 #include "fhiclcpp/ParameterSet.h"
15 
21 
23 
24 #include <memory>
25 
26 namespace tss {
27 
28  typedef std::map<unsigned int, std::vector<tss::Hit2D>> view_hitmap;
29  typedef std::map<unsigned int, view_hitmap> tpc_view_hitmap;
30  typedef std::map<unsigned int, tpc_view_hitmap> cryo_tpc_view_hitmap;
31 
33  public:
34  explicit TrackShowerHits(fhicl::ParameterSet const& p);
35 
36  TrackShowerHits(TrackShowerHits const&) = delete;
37  TrackShowerHits(TrackShowerHits&&) = delete;
38  TrackShowerHits& operator=(TrackShowerHits const&) = delete;
40 
41  private:
42  void produce(art::Event& e) override;
43 
44  cryo_tpc_view_hitmap fHitMap;
45  bool sortHits(const art::Event& evt);
46 
48 
50 
53 
54  std::string fHitModuleLabel;
55  };
56  // ------------------------------------------------------
57 
59  : EDProducer{p}, fSegmentation2D(p.get<fhicl::ParameterSet>("Segmentation2DAlg"))
60  {
61  fHitModuleLabel = p.get<std::string>("HitModuleLabel");
62  fHugeShowers = p.get<bool>("FindHugeShowers");
63  fShowersBySeg2D = p.get<bool>("FindMoreShowers");
64 
65  produces<std::vector<recob::Cluster>>();
66  produces<art::Assns<recob::Cluster, recob::Hit>>();
67  }
68  // ------------------------------------------------------
69 
71  {
72  auto const detProp =
74  fHitMap.clear();
75 
77  std::vector<art::Ptr<recob::Hit>> hitlist;
78  if (evt.getByLabel(fHitModuleLabel, hitListHandle)) {
79  art::fill_ptr_vector(hitlist, hitListHandle);
80 
81  unsigned int cryo, tpc, view;
82  for (auto const& h : hitlist) {
83  cryo = h->WireID().Cryostat;
84  tpc = h->WireID().TPC;
85  view = h->WireID().Plane;
86 
87  fHitMap[cryo][tpc][view].emplace_back(detProp, h);
88  }
89  return true;
90  }
91  return false;
92  }
93  // ------------------------------------------------------
94 
96  {
97  std::unique_ptr<std::vector<recob::Cluster>> clusters(new std::vector<recob::Cluster>);
98  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> clu2hit(
100 
101  if (sortHits(evt)) {
102  unsigned int cidx = 0;
103  const unsigned int emTag = 0x10000;
104 
105  for (auto const& tpcid : fGeom->Iterate<geo::TPCID>()) {
106  for (const auto& v : fHitMap[tpcid.Cryostat][tpcid.TPC]) {
107  auto cls = fSimpleClustering.run(v.second);
108 
109  if (fHugeShowers) {
110  mf::LogVerbatim("TrackShowerHits") << "Find huge EM showers (cores).";
111 
112  int c = 0, clsSize = cls.size();
113  while (c < clsSize) {
114  if (cls[c].hits().size() < 2) {
115  c++;
116  continue;
117  }
118 
119  std::vector<const tss::Hit2D*> trks, ems;
120  fSegmentation2D.splitHitsNaive(cls[c], trks, ems);
121  cls.erase(cls.begin() + c);
122  clsSize--;
123 
124  cls.emplace_back(Cluster2D(trks));
125  cls.emplace_back(Cluster2D(ems));
126  cls.back().tagEM(true);
127  }
128  }
129 
130  if (fShowersBySeg2D) {
131  mf::LogVerbatim("TrackShowerHits") << "Find EM showers by density of vtxs.";
132 
133  int c = 0, clsSize = cls.size();
134  while (c < clsSize) {
135  if (cls[c].isEM() || (cls[c].hits().size() < 2)) {
136  c++;
137  continue;
138  }
139 
140  auto segs = fSegmentation2D.run(cls[c]);
141 
142  for (const auto& s : segs)
143  cls.emplace_back(Cluster2D(s));
144 
145  cls.erase(cls.begin() + c);
146  clsSize--;
147  }
148  }
149 
150  for (auto& c : cls) {
151  if (!c.hits().size()) continue; // skip 0-size clusters
152 
153  if (!c.isEM()) continue; // create clusters only for em parts now
154 
155  clusters->emplace_back(
156  recob::Cluster(0.0F,
157  0.0F,
158  0.0F,
159  0.0F,
160  0.0F,
161  0.0F,
162  0.0F,
163  0.0F,
164  0.0F,
165  0.0F,
166  0.0F,
167  0.0F,
168  0.0F,
169  0.0F,
170  0.0F,
171  0.0F,
172  0.0F,
173  0.0F,
174  c.hits().size(),
175  0.0F,
176  0.0F,
177  cidx + emTag,
178  (geo::View_t)c.hits().front()->View(),
179  c.hits().front()->Hit2DPtr()->WireID().planeID()));
180 
181  std::vector<art::Ptr<recob::Hit>> hits2d;
182  hits2d.reserve(c.hits().size());
183 
184  for (auto h2d : c.hits())
185  hits2d.push_back(h2d->Hit2DPtr());
186 
187  if (hits2d.size()) util::CreateAssn(evt, *clusters, hits2d, *clu2hit);
188 
189  ++cidx;
190  }
191  }
192  }
193  }
194  else
195  mf::LogWarning("TrackShowerHits") << "Hits not found in the event.";
196 
197  evt.put(std::move(clusters));
198  evt.put(std::move(clu2hit));
199  }
200  // ------------------------------------------------------
201 
203 
204 }
details::range_type< T > Iterate() const
Initializes the specified ID with the ID of the first cryostat.
Definition: GeometryCore.h:541
cryo_tpc_view_hitmap fHitMap
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
TrackShowerHits & operator=(TrackShowerHits const &)=delete
tss::SimpleClustering fSimpleClustering
art::ServiceHandle< geo::Geometry const > fGeom
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
tss::Segmentation2D fSegmentation2D
void splitHitsNaive(const tss::Cluster2D &inp, std::vector< const tss::Hit2D * > &trackHits, std::vector< const tss::Hit2D * > &emHits) const
Set of hits with a 2D structure.
Definition: Cluster.h:69
Split into linear clusters.
TrackShowerHits(fhicl::ParameterSet const &p)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
std::vector< tss::Cluster2D > run(const std::vector< tss::Hit2D > &inp) const
void produce(art::Event &e) override
std::map< unsigned int, view_hitmap > tpc_view_hitmap
std::vector< tss::Cluster2D > run(tss::Cluster2D &inp) const
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
Declaration of cluster object.
Definition: DirOfGamma.h:22
std::map< unsigned int, tpc_view_hitmap > cryo_tpc_view_hitmap
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
std::map< unsigned int, std::vector< tss::Hit2D > > view_hitmap
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
bool sortHits(const art::Event &evt)
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
Float_t e
Definition: plot.C:35
art framework interface to geometry description