LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 
15 #include "fhiclcpp/ParameterSet.h"
17 
26 
28 
29 #include <memory>
30 
31 namespace tss {
32 
33 typedef std::map< unsigned int, std::vector< tss::Hit2D > > view_hitmap;
34 typedef std::map< unsigned int, view_hitmap > tpc_view_hitmap;
35 typedef std::map< unsigned int, tpc_view_hitmap > cryo_tpc_view_hitmap;
36 
38 public:
39  explicit TrackShowerHits(fhicl::ParameterSet const & p);
40 
41  TrackShowerHits(TrackShowerHits const &) = delete;
42  TrackShowerHits(TrackShowerHits &&) = delete;
43  TrackShowerHits & operator = (TrackShowerHits const &) = delete;
45 
46  void reconfigure(fhicl::ParameterSet const& p);
47 
48  void produce(art::Event & e) override;
49 
50 private:
51 
52  cryo_tpc_view_hitmap fHitMap;
53  bool sortHits(const art::Event& evt);
54 
56 
58 
61 
62  std::string fHitModuleLabel;
63 
64 };
65 // ------------------------------------------------------
66 
68  fSegmentation2D(p.get< fhicl::ParameterSet >("Segmentation2DAlg"))
69 {
70  this->reconfigure(p);
71 
72  produces< std::vector<recob::Cluster> >();
73  produces< art::Assns<recob::Cluster, recob::Hit> >();
74 }
75 // ------------------------------------------------------
76 
78 {
79  fHitModuleLabel = pset.get< std::string >("HitModuleLabel");
80  fHugeShowers = pset.get< bool >("FindHugeShowers");
81  fShowersBySeg2D = pset.get< bool >("FindMoreShowers");
82 
83  fSegmentation2D.reconfigure(pset.get< fhicl::ParameterSet >("Segmentation2DAlg"));
84 }
85 // ------------------------------------------------------
86 
88 {
89  fHitMap.clear();
90 
92  std::vector< art::Ptr<recob::Hit> > hitlist;
93  if (evt.getByLabel(fHitModuleLabel, hitListHandle))
94  {
95  art::fill_ptr_vector(hitlist, hitListHandle);
96 
97  unsigned int cryo, tpc, view;
98  for (auto const& h : hitlist)
99  {
100  cryo = h->WireID().Cryostat;
101  tpc = h->WireID().TPC;
102  view = h->WireID().Plane;
103 
104  fHitMap[cryo][tpc][view].emplace_back(tss::Hit2D(h));
105  }
106  return true;
107  }
108  else return false;
109 }
110 // ------------------------------------------------------
111 
113 {
114  std::unique_ptr< std::vector< recob::Cluster > > clusters(new std::vector< recob::Cluster >);
115  std::unique_ptr< art::Assns< recob::Cluster, recob::Hit > > clu2hit(new art::Assns< recob::Cluster, recob::Hit >);
116 
117  if (sortHits(evt))
118  {
119  unsigned int cidx = 0;
120  const unsigned int emTag = 0x10000;
121 
122  for (auto tpc_iter = fGeom->begin_TPC_id();
123  tpc_iter != fGeom->end_TPC_id();
124  tpc_iter++)
125  {
126  for (const auto & v : fHitMap[tpc_iter->Cryostat][tpc_iter->TPC])
127  {
128  auto cls = fSimpleClustering.run(v.second);
129 
130  if (fHugeShowers)
131  {
132  mf::LogVerbatim("TrackShowerHits") << "Find huge EM showers (cores).";
133 
134  int c = 0, clsSize = cls.size();
135  while (c < clsSize)
136  {
137  if (cls[c].hits().size() < 2) { c++; continue; }
138 
139  std::vector< const tss::Hit2D* > trks, ems;
140  fSegmentation2D.splitHitsNaive(cls[c], trks, ems);
141  cls.erase(cls.begin() + c);
142  clsSize--;
143 
144  cls.emplace_back(Cluster2D(trks));
145  cls.emplace_back(Cluster2D(ems));
146  cls.back().tagEM(true);
147  }
148  }
149 
150  if (fShowersBySeg2D)
151  {
152  mf::LogVerbatim("TrackShowerHits") << "Find EM showers by density of vtxs.";
153 
154  int c = 0, clsSize = cls.size();
155  while (c < clsSize)
156  {
157  if (cls[c].isEM() || (cls[c].hits().size() < 2)) { c++; continue; }
158 
159  auto segs = fSegmentation2D.run(cls[c]);
160 
161  for (const auto & s : segs) cls.emplace_back(Cluster2D(s));
162 
163  cls.erase(cls.begin() + c);
164  clsSize--;
165  }
166  }
167 
168  for (auto & c : cls)
169  {
170  if (!c.hits().size()) continue; // skip 0-size clusters
171 
172  if (!c.isEM()) continue; // create clusters only for em parts now
173 
174  clusters->emplace_back(
175  recob::Cluster(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F,
176  c.hits().size(), 0.0F, 0.0F, cidx + emTag, (geo::View_t)c.hits().front()->View(), c.hits().front()->Hit2DPtr()->WireID().planeID()));
177 
178  std::vector< art::Ptr< recob::Hit > > hits2d;
179  hits2d.reserve(c.hits().size());
180 
181  for (auto h2d : c.hits()) hits2d.push_back(h2d->Hit2DPtr());
182 
183  if (hits2d.size()) util::CreateAssn(*this, evt, *clusters, hits2d, *clu2hit);
184 
185  ++cidx;
186  }
187  }
188  }
189 
190  }
191  else mf::LogWarning("TrackShowerHits") << "Hits not found in the event.";
192 
193  evt.put(std::move(clusters));
194  evt.put(std::move(clu2hit));
195 }
196 // ------------------------------------------------------
197 
199 
200 }
201 
cryo_tpc_view_hitmap fHitMap
Float_t s
Definition: plot.C:23
std::map< unsigned int, view_hitmap > tpc_view_hitmap
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void reconfigure(fhicl::ParameterSet const &p)
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.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
art::ServiceHandle< geo::Geometry > fGeom
Declaration of signal hit object.
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)
std::map< unsigned int, std::vector< tss::Hit2D > > view_hitmap
void reconfigure(const fhicl::ParameterSet &p)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
parameter set interface
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::vector< tss::Cluster2D > run(const std::vector< tss::Hit2D > &inp) const
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::vector< tss::Cluster2D > run(tss::Cluster2D &inp) const
Declaration of cluster object.
TPC_id_iterator end_TPC_id() const
Returns an iterator pointing after the last TPC ID in the detector.
Definition: DirOfGamma.h:18
Encapsulate the geometry of a wire.
std::map< unsigned int, tpc_view_hitmap > cryo_tpc_view_hitmap
Implementation of the Projection Matching Algorithm.
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
bool sortHits(const art::Event &evt)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Float_t e
Definition: plot.C:34
art framework interface to geometry description
Encapsulate the construction of a single detector plane.