9 #include "art/Persistency/Common/PtrMaker.h"
15 #include "art/Framework/Core/EDProducer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 #include "canvas/Persistency/Common/Ptr.h"
19 #include "canvas/Persistency/Common/Assns.h"
20 #include "canvas/Utilities/InputTag.h"
21 #include "fhiclcpp/types/Atom.h"
22 #include "fhiclcpp/types/Sequence.h"
23 #include "fhiclcpp/types/Name.h"
24 #include "fhiclcpp/types/Comment.h"
25 #include "messagefacility/MessageLogger/MessageLogger.h"
56 fhicl::Sequence<art::InputTag>
hits{
58 Comment(
"collections of hits to be clustered")
62 Name(
"hitsPerCluster"),
63 Comment(
"number of hits associated with each cluster"),
72 : EDProducer{config},
hitTags(config().hits())
75 produces<std::vector<recob::Cluster>>();
76 produces<art::Assns<recob::Hit, recob::Cluster>>();
79 virtual void produce(art::Event& event)
override;
87 (art::Event
const& event)
const;
101 template <
typename T>
102 inline T
sqr(T v) {
return v*v; }
112 std::vector<art::Ptr<recob::Hit>> hits =
collectHits(event);
117 auto clusters = std::make_unique<std::vector<recob::Cluster>>();
119 = std::make_unique<art::Assns<recob::Hit, recob::Cluster>>();
127 art::PtrMaker<recob::Cluster> ptrMaker(event);
129 for (
unsigned int i = 0; i < nClusters; ++i) {
134 std::vector<art::Ptr<recob::Hit>> clusterHits;
135 std::size_t iHit = i;
136 while (iHit < hits.size()) {
137 clusterHits.push_back(hits[iHit]);
144 clusters->emplace_back(
145 float(clusterHits.front()->WireID().Wire),
147 clusterHits.front()->PeakTime(),
148 clusterHits.front()->SigmaPeakTime(),
149 clusterHits.front()->Integral(),
152 float(clusterHits.back()->WireID().Wire),
154 clusterHits.back()->PeakTime(),
155 clusterHits.back()->SigmaPeakTime(),
156 clusterHits.back()->Integral(),
159 std::accumulate(clusterHits.cbegin(), clusterHits.cend(), 0.0,
160 [](
float sum, art::Ptr<recob::Hit>
const&
hit)
161 {
return sum +
hit->Integral(); }
163 std::sqrt(std::accumulate(clusterHits.cbegin(), clusterHits.cend(), 0.0,
164 [](
float sum, art::Ptr<recob::Hit>
const&
hit)
165 {
return sum +
sqr(
hit->SigmaIntegral()); }
167 std::accumulate(clusterHits.cbegin(), clusterHits.cend(), 0.0,
168 [](
float sum, art::Ptr<recob::Hit>
const&
hit)
169 {
return sum +
hit->SummedADC(); }
171 std::sqrt(std::accumulate(clusterHits.cbegin(), clusterHits.cend(), 0.0,
172 [](
float sum, art::Ptr<recob::Hit>
const&
hit)
173 {
return sum +
hit->SummedADC(); }
179 clusterHits.front()->View(),
180 clusterHits.front()->WireID().asPlaneID(),
187 auto const clusterPtr = ptrMaker(i);
188 for (art::Ptr<recob::Hit>
const&
hit: clusterHits)
189 hitClusterAssns->addSingle(
hit, clusterPtr);
193 mf::LogInfo(
"AssnsChainClusterMaker")
194 <<
"Created " << clusters->size() <<
" clusters with about "
195 <<
nHitsPerCluster <<
" hits each from " << hits.size() <<
" hits and "
196 << hitClusterAssns->size() <<
" associations from "
197 <<
hitTags.size() <<
" collections";
199 event.put(std::move(clusters));
200 event.put(std::move(hitClusterAssns));
207 (art::Event
const& event)
const
210 std::vector<art::Ptr<recob::Hit>> allHits;
212 for (
auto const& tag: hitTags) {
213 auto hits =
event.getValidHandle<std::vector<recob::Hit>>(tag);
215 std::size_t
const nHits = hits->size();
216 for (std::size_t i = 0; i < nHits; ++i)
217 allHits.emplace_back(hits, i);
std::vector< art::InputTag > hitTags
List of hit tags for clustering.
BEGIN_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree showermakertwo END_PROLOG hitmakerfive hitsPerCluster
Creates some dummy clusters and associations to hits.
Declaration of signal hit object.
AssnsChainClusterMaker(Parameters const &config)
std::vector< art::Ptr< recob::Hit > > collectHits(art::Event const &event) const
Returns a list of hits to be clustered.
static const SentryArgument_t Sentry
An instance of the sentry object.
fhicl::Atom< unsigned int > hitsPerCluster
virtual void produce(art::Event &event) override
BEGIN_PROLOG vertical distance to the surface Name
Declaration of cluster object.
Definition of data types for geometry description.
fhicl::Sequence< art::InputTag > hits
unsigned int nHitsPerCluster
Maximum number of hits per cluster.
BEGIN_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree showermakertwo END_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree sequence::inline_paths sequence::inline_paths sequence::inline_paths showermakers test
art::EDProducer::Table< Config > Parameters
int ID_t
Type of cluster ID.