All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
8 #include "art/Framework/Core/EDProducer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "art/Framework/Services/Registry/ServiceHandle.h"
13 #include "fhiclcpp/ParameterSet.h"
14 #include "messagefacility/MessageLogger/MessageLogger.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 
32  class TrackShowerHits : public art::EDProducer {
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 
45  bool sortHits(const art::Event& evt);
46 
47  art::ServiceHandle<geo::Geometry const> fGeom;
48 
50 
53 
54  std::string fHitModuleLabel;
55  };
56  // ------------------------------------------------------
57 
58  TrackShowerHits::TrackShowerHits(fhicl::ParameterSet const& p)
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 
70  bool
71  TrackShowerHits::sortHits(const art::Event& evt)
72  {
73  auto const detProp =
74  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt);
75  fHitMap.clear();
76 
77  art::Handle<std::vector<recob::Hit>> hitListHandle;
78  std::vector<art::Ptr<recob::Hit>> hitlist;
79  if (evt.getByLabel(fHitModuleLabel, hitListHandle)) {
80  art::fill_ptr_vector(hitlist, hitListHandle);
81 
82  unsigned int cryo, tpc, view;
83  for (auto const& h : hitlist) {
84  cryo = h->WireID().Cryostat;
85  tpc = h->WireID().TPC;
86  view = h->WireID().Plane;
87 
88  fHitMap[cryo][tpc][view].emplace_back(detProp, h);
89  }
90  return true;
91  }
92  else
93  return false;
94  }
95  // ------------------------------------------------------
96 
97  void
99  {
100  std::unique_ptr<std::vector<recob::Cluster>> clusters(new std::vector<recob::Cluster>);
101  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> clu2hit(
102  new art::Assns<recob::Cluster, recob::Hit>);
103 
104  if (sortHits(evt)) {
105  unsigned int cidx = 0;
106  const unsigned int emTag = 0x10000;
107 
108  for (auto tpc_iter = fGeom->begin_TPC_id(); tpc_iter != fGeom->end_TPC_id(); tpc_iter++) {
109  for (const auto& v : fHitMap[tpc_iter->Cryostat][tpc_iter->TPC]) {
110  auto cls = fSimpleClustering.run(v.second);
111 
112  if (fHugeShowers) {
113  mf::LogVerbatim("TrackShowerHits") << "Find huge EM showers (cores).";
114 
115  int c = 0, clsSize = cls.size();
116  while (c < clsSize) {
117  if (cls[c].hits().size() < 2) {
118  c++;
119  continue;
120  }
121 
122  std::vector<const tss::Hit2D*> trks, ems;
123  fSegmentation2D.splitHitsNaive(cls[c], trks, ems);
124  cls.erase(cls.begin() + c);
125  clsSize--;
126 
127  cls.emplace_back(Cluster2D(trks));
128  cls.emplace_back(Cluster2D(ems));
129  cls.back().tagEM(true);
130  }
131  }
132 
133  if (fShowersBySeg2D) {
134  mf::LogVerbatim("TrackShowerHits") << "Find EM showers by density of vtxs.";
135 
136  int c = 0, clsSize = cls.size();
137  while (c < clsSize) {
138  if (cls[c].isEM() || (cls[c].hits().size() < 2)) {
139  c++;
140  continue;
141  }
142 
143  auto segs = fSegmentation2D.run(cls[c]);
144 
145  for (const auto& s : segs)
146  cls.emplace_back(Cluster2D(s));
147 
148  cls.erase(cls.begin() + c);
149  clsSize--;
150  }
151  }
152 
153  for (auto& c : cls) {
154  if (!c.hits().size()) continue; // skip 0-size clusters
155 
156  if (!c.isEM()) continue; // create clusters only for em parts now
157 
158  clusters->emplace_back(
159  recob::Cluster(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  0.0F,
177  c.hits().size(),
178  0.0F,
179  0.0F,
180  cidx + emTag,
181  (geo::View_t)c.hits().front()->View(),
182  c.hits().front()->Hit2DPtr()->WireID().planeID()));
183 
184  std::vector<art::Ptr<recob::Hit>> hits2d;
185  hits2d.reserve(c.hits().size());
186 
187  for (auto h2d : c.hits())
188  hits2d.push_back(h2d->Hit2DPtr());
189 
190  if (hits2d.size()) util::CreateAssn(*this, evt, *clusters, hits2d, *clu2hit);
191 
192  ++cidx;
193  }
194  }
195  }
196  }
197  else
198  mf::LogWarning("TrackShowerHits") << "Hits not found in the event.";
199 
200  evt.put(std::move(clusters));
201  evt.put(std::move(clu2hit));
202  }
203  // ------------------------------------------------------
204 
205  DEFINE_ART_MODULE(TrackShowerHits)
206 
207 }
cryo_tpc_view_hitmap fHitMap
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.
pdgs p
Definition: selectors.fcl:22
tss::Segmentation2D fSegmentation2D
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
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)
while getopts h
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
Declaration of cluster object.
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.
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
std::map< unsigned int, std::vector< tss::Hit2D > > view_hitmap
do i e
bool sortHits(const art::Event &evt)
TCEvent evt
Definition: DataStructs.cxx:8
art framework interface to geometry description
auto const detProp