TrackShowerHits_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TrackShowerHits
3 // Module Type: producer
4 // File: TrackShowerHits_module.cc
5 // Authors: dorota.stefan@cern.ch robert.sulej@cern.ch
6 ////////////////////////////////////////////////////////////////////////
7 
12 #include "fhiclcpp/ParameterSet.h"
14 
20 
22 
23 #include <memory>
24 
25 namespace tss {
26 
27  typedef std::map<unsigned int, std::vector<tss::Hit2D>> view_hitmap;
28  typedef std::map<unsigned int, view_hitmap> tpc_view_hitmap;
29  typedef std::map<unsigned int, tpc_view_hitmap> cryo_tpc_view_hitmap;
30 
32  public:
33  explicit TrackShowerHits(fhicl::ParameterSet const& p);
34 
35  TrackShowerHits(TrackShowerHits const&) = delete;
36  TrackShowerHits(TrackShowerHits&&) = delete;
37  TrackShowerHits& operator=(TrackShowerHits const&) = delete;
39 
40  private:
41  void produce(art::Event& e) override;
42 
43  cryo_tpc_view_hitmap fHitMap;
44  bool sortHits(const art::Event& evt);
45 
47 
49 
52 
54  };
55  // ------------------------------------------------------
56 
58  : EDProducer{p}, fSegmentation2D(p.get<fhicl::ParameterSet>("Segmentation2DAlg"))
59  {
60  fHitModuleLabel = p.get<std::string>("HitModuleLabel");
61  fHugeShowers = p.get<bool>("FindHugeShowers");
62  fShowersBySeg2D = p.get<bool>("FindMoreShowers");
63 
64  produces<std::vector<recob::Cluster>>();
65  produces<art::Assns<recob::Cluster, recob::Hit>>();
66  }
67  // ------------------------------------------------------
68 
69  bool
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  else
92  return false;
93  }
94  // ------------------------------------------------------
95 
96  void
98  {
99  std::unique_ptr<std::vector<recob::Cluster>> clusters(new std::vector<recob::Cluster>);
100  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> clu2hit(
102 
103  if (sortHits(evt)) {
104  unsigned int cidx = 0;
105  const unsigned int emTag = 0x10000;
106 
107  for (auto tpc_iter = fGeom->begin_TPC_id(); tpc_iter != fGeom->end_TPC_id(); tpc_iter++) {
108  for (const auto& v : fHitMap[tpc_iter->Cryostat][tpc_iter->TPC]) {
109  auto cls = fSimpleClustering.run(v.second);
110 
111  if (fHugeShowers) {
112  mf::LogVerbatim("TrackShowerHits") << "Find huge EM showers (cores).";
113 
114  int c = 0, clsSize = cls.size();
115  while (c < clsSize) {
116  if (cls[c].hits().size() < 2) {
117  c++;
118  continue;
119  }
120 
121  std::vector<const tss::Hit2D*> trks, ems;
122  fSegmentation2D.splitHitsNaive(cls[c], trks, ems);
123  cls.erase(cls.begin() + c);
124  clsSize--;
125 
126  cls.emplace_back(Cluster2D(trks));
127  cls.emplace_back(Cluster2D(ems));
128  cls.back().tagEM(true);
129  }
130  }
131 
132  if (fShowersBySeg2D) {
133  mf::LogVerbatim("TrackShowerHits") << "Find EM showers by density of vtxs.";
134 
135  int c = 0, clsSize = cls.size();
136  while (c < clsSize) {
137  if (cls[c].isEM() || (cls[c].hits().size() < 2)) {
138  c++;
139  continue;
140  }
141 
142  auto segs = fSegmentation2D.run(cls[c]);
143 
144  for (const auto& s : segs)
145  cls.emplace_back(Cluster2D(s));
146 
147  cls.erase(cls.begin() + c);
148  clsSize--;
149  }
150  }
151 
152  for (auto& c : cls) {
153  if (!c.hits().size()) continue; // skip 0-size clusters
154 
155  if (!c.isEM()) continue; // create clusters only for em parts now
156 
157  clusters->emplace_back(
158  recob::Cluster(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  0.0F,
175  0.0F,
176  c.hits().size(),
177  0.0F,
178  0.0F,
179  cidx + emTag,
180  (geo::View_t)c.hits().front()->View(),
181  c.hits().front()->Hit2DPtr()->WireID().planeID()));
182 
183  std::vector<art::Ptr<recob::Hit>> hits2d;
184  hits2d.reserve(c.hits().size());
185 
186  for (auto h2d : c.hits())
187  hits2d.push_back(h2d->Hit2DPtr());
188 
189  if (hits2d.size()) util::CreateAssn(*this, evt, *clusters, hits2d, *clu2hit);
190 
191  ++cidx;
192  }
193  }
194  }
195  }
196  else
197  mf::LogWarning("TrackShowerHits") << "Hits not found in the event.";
198 
199  evt.put(std::move(clusters));
200  evt.put(std::move(clu2hit));
201  }
202  // ------------------------------------------------------
203 
205 
206 }
cryo_tpc_view_hitmap fHitMap
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
TrackShowerHits & operator=(TrackShowerHits const &)=delete
tss::SimpleClustering fSimpleClustering
TPC_id_iterator begin_TPC_id() const
Returns an iterator pointing to the first TPC ID in the detector.
art::ServiceHandle< geo::Geometry const > fGeom
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
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:71
Split into linear clusters.
TrackShowerHits(fhicl::ParameterSet const &p)
art framework interface to geometry description
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
std::vector< tss::Cluster2D > run(const std::vector< tss::Hit2D > &inp) const
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
void produce(art::Event &e) override
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.
std::map< unsigned int, view_hitmap > tpc_view_hitmap
std::vector< tss::Cluster2D > run(tss::Cluster2D &inp) const
TPC_id_iterator end_TPC_id() const
Returns an iterator pointing after the last TPC ID in the detector.
Definition: DirOfGamma.h:20
std::map< unsigned int, tpc_view_hitmap > cryo_tpc_view_hitmap
Declaration of signal hit object.
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:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
static QCString * s
Definition: config.cpp:1042