23 #include "art/Framework/Core/EDProducer.h"
24 #include "art/Framework/Core/ModuleMacros.h"
25 #include "art/Framework/Principal/Event.h"
26 #include "art/Framework/Principal/Handle.h"
27 #include "canvas/Persistency/Common/FindManyP.h"
28 #include "canvas/Persistency/Common/Ptr.h"
29 #include "fhiclcpp/ParameterSet.h"
30 #include "messagefacility/MessageLogger/MessageLogger.h"
49 explicit LineMerger(fhicl::ParameterSet
const& pset);
119 return fEndWires[ClusterEnds_t::clStart];
126 return fEndTicks[ClusterEnds_t::clStart];
214 return fAngles[ClusterEnds_t::clStart];
235 return fAngles[ClusterEnds_t::clEnd];
331 template <
typename T>
335 if (value > var) var =
value;
337 template <
typename T>
341 if (value < var) var =
value;
361 if (!cluster.
isValid())
return false;
364 AdoptEnd(cluster, ClusterEnds_t::clStart);
365 AdoptEnd(cluster, ClusterEnds_t::clEnd);
373 if (cluster.
View() !=
View())
return false;
380 AdoptEnd(cluster, ClusterEnds_t::clStart);
383 AdoptEnd(cluster, ClusterEnds_t::clEnd);
406 Add(cluster, cluster_hits);
449 hits.insert(prepend ?
hits.begin() :
hits.end(), cluster_hits.begin(), cluster_hits.end());
462 AddHits(cluster_hits, prepend);
469 , fClusterModuleLabel(pset.get<std::string>(
"ClusterModuleLabel"))
470 , fSlope(pset.get<
double>(
"Slope"))
471 , fEndpointWindow(pset.get<
double>(
"EndpointWindow"))
473 produces<std::vector<recob::Cluster>>();
474 produces<art::Assns<recob::Cluster, recob::Hit>>();
482 art::Handle<std::vector<recob::Cluster>> clusterVecHandle;
485 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
487 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
490 constexpr
size_t nViews = 3;
493 std::array<std::vector<size_t>, nViews> ClsIndices;
496 std::array<std::vector<int>, nViews> Cls_matches;
499 for (
size_t i = 0; i < clusterVecHandle->size(); ++i) {
502 art::Ptr<recob::Cluster> cl(clusterVecHandle, i);
505 switch (cl->View()) {
512 Cls_matches[view].push_back(0);
513 ClsIndices[view].push_back(i);
516 auto SuperClusters = std::make_unique<std::vector<recob::Cluster>>();
517 auto assn = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
526 for (
size_t i = 0; i < nViews; ++i) {
528 int clustersfound = 0;
531 for (
size_t c = 0; c < ClsIndices[i].size(); ++c) {
532 if (Cls_matches[i][clsnum1] == 1) {
540 recob::Cluster const& StartingCluster = clusterVecHandle->at(ClsIndices[i][c]);
544 Cls_matches[i][clsnum1] = 1;
548 for (
size_t c2 = 0; c2 < ClsIndices[i].size(); ++c2) {
550 if (Cls_matches[i][clsnum2] == 1) {
555 const recob::Cluster& cl2(clusterVecHandle->at(ClsIndices[i][c2]));
578 if (sameSlope && (sameEndpoint != 0)) {
583 cl1.Add(cl2, fmh.at(ClsIndices[i][c2]), sameEndpoint == 1);
584 Cls_matches[i][clsnum2] = 1;
592 ClusterParamAlgo.ImportHits(gser, cl1.Hits());
595 SuperClusters->emplace_back(cl1.StartWire(),
596 cl1.SigmaStartWire(),
598 cl1.SigmaStartTick(),
601 cl1.StartOpeningAngle(),
608 cl1.EndOpeningAngle(),
609 ClusterParamAlgo.Integral().value(),
610 ClusterParamAlgo.IntegralStdDev().value(),
611 ClusterParamAlgo.SummedADC().value(),
612 ClusterParamAlgo.SummedADCStdDev().value(),
613 ClusterParamAlgo.NHits(),
614 ClusterParamAlgo.MultipleHitDensity(),
628 mf::LogVerbatim(
"Summary") << std::setfill(
'-') << std::setw(175) <<
"-" << std::setfill(
' ');
629 mf::LogVerbatim(
"Summary") <<
"LineMerger Summary:";
630 for (
size_t i = 0; i < SuperClusters->size(); ++i)
631 mf::LogVerbatim(
"Summary") << SuperClusters->at(i);
633 evt.put(std::move(SuperClusters));
634 evt.put(std::move(assn));
642 double sl1 = atan(slope1);
643 double sl2 = atan(slope2);
662 std::sqrt((pow(sclendwire - cl2startwire, 2) * 13.5) + pow(sclendtime - cl2starttime, 2));
666 std::sqrt((pow(sclstartwire - cl2endwire, 2) * 13.5) + pow(sclstarttime - cl2endtime, 2));
float EndOpeningAngle() const
Returns the opening angle at the end of the cluster.
int EndpointCompatibility(float sclstartwire, float sclstarttime, float sclendwire, float sclendtime, float cl2startwire, float cl2starttime, float cl2endwire, float cl2endtime)
float EndWire() const
Returns the wire coordinate of the end of the cluster.
ClusterAndHitMerger(recob::Cluster const &cluster, HitVector_t const &cluster_hits)
float SigmaStartWire() const
Returns the uncertainty on wire coordinate of the start of the cluster.
Utilities related to art service access.
float StartAngle() const
Returns the starting angle of the cluster.
float SigmaWireCoord(ClusterEnds_t side) const
Returns the uncertainty on wire coordinate of one of the end sides of the cluster.
float EdgeCharge(ClusterEnds_t side) const
Returns the charge on the first or last wire of the cluster.
float Angle(ClusterEnds_t side) const
Returns the angle at either end of the cluster.
ClusterMerger(recob::Cluster const &cluster)
float SigmaTickCoord(ClusterEnds_t side) const
Returns the uncertainty on tick coordinate of one of the end sides of the cluster.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
float TickCoord(ClusterEnds_t side) const
Returns the tick coordinate of one of the end sides of the cluster.
Declaration of signal hit object.
float fEndCharges[ClusterEnds_t::NEnds]
Charge on the start and end wire of the cluster.
void produce(art::Event &evt) override
The data type to uniquely identify a Plane.
bool isValid
Whether this ID points to a valid element.
float EdgeCharge(ClusterEnds_t side) const
Returns the charge on the first or last wire of the cluster.
float SigmaTickCoord(ClusterEnds_t side) const
Returns the uncertainty on tick coordinate of one of the end sides of the cluster.
float StartWire() const
Returns the wire coordinate of the start of the cluster.
Planes which measure Z direction.
Set of hits with a 2D structure.
geo::PlaneID Plane() const
Returns the plane ID this cluster lies on.
static void bot(T &var, T value)
float fWidth
A measure of the cluster width, in homogenized units.
bool isValid() const
Returns if the cluster is valid (that is, if its ID is not invalid)
float SigmaStartTick() const
float StartWire() const
Returns the wire coordinate of the start of the cluster.
static const SentryArgument_t Sentry
An instance of the sentry object.
std::vector< HitPtr_t > HitVector_t
vector of pointers to hits
float StartOpeningAngle() const
Returns the opening angle at the start of the cluster.
unsigned int n_clusters
number of clusters added so far
LineMerger(fhicl::ParameterSet const &pset)
bool Add(recob::Cluster const &cluster, HitVector_t const &cluster_hits, bool prepend=false)
Merges a single cluster into this object.
float TickCoord(ClusterEnds_t side) const
Returns the tick coordinate of one of the end sides of the cluster.
float fOpeningAngles[ClusterEnds_t::NEnds]
Opening angle of the cluster shape at the start and end of the cluster.
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
static void top(T &var, T value)
std::string fClusterModuleLabel
Wrapper for ClusterParamsAlgBase objects to accept diverse input.
void AdoptEnd(recob::Cluster const &cluster, ClusterEnds_t iEnd)
Imports all the member of the corresponding end.
float SigmaEndWire() const
Returns the uncertainty on wire coordinate of the end of the cluster.
float Width() const
A measure of the cluster width, in homogenized units.
ClusterAndHitMerger()=default
float SigmaEndTick() const
Returns the uncertainty on tick coordinate of the end of the cluster.
Wrapper for ClusterParamsAlgBase objects to accept arbitrary input.
float Angle(ClusterEnds_t side) const
Returns the angle at either end of the cluster.
Declaration of cluster object.
float WireCoord(ClusterEnds_t side) const
Returns the wire coordinate of one of the end sides of the cluster.
Definition of data types for geometry description.
bool hasPlane() const
Returns whether geometry plane is valid.
float fEndWires[ClusterEnds_t::NEnds]
Data referring to start and end of the cluster.
float SigmaWireCoord(ClusterEnds_t side) const
Returns the uncertainty on wire coordinate of one of the end sides of the cluster.
float StartTick() const
Returns the tick coordinate of the start of the cluster.
Class merging clusters: recomputes start and end position and hit list.
float Width() const
A measure of the cluster width, in homogenized units.
art::Ptr< recob::Hit > HitPtr_t
type of pointer to hits
HitVector_t hits
hits in the cluster
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.
HitVector_t const & Hits() const
Returns a constant reference to the current list of hits.
geo::View_t View() const
Returns the view for this cluster.
geo::View_t fView
View for this cluster.
float StartCharge() const
Returns the charge on the first wire of the cluster.
float OpeningAngle(ClusterEnds_t side) const
Returns the opening angle at either end of the cluster.
ID_t ID() const
Identifier of this cluster.
float fSigmaEndWires[ClusterEnds_t::NEnds]
Uncertainty on wire coordinate of the start and end of the cluster.
bool SlopeCompatibility(double slope1, double slope2)
float fEndTicks[ClusterEnds_t::NEnds]
Tick coordinate of the start and end of the cluster.
unsigned int NHits() const
Number of hits in the cluster.
bool hasPlane() const
Returns whether geometry plane is valid.
float fSigmaEndTicks[ClusterEnds_t::NEnds]
Uncertainty on tick coordinate of the start and end of the cluster.
geo::View_t View() const
Returns the view for this cluster.
Interface to class computing cluster parameters.
geo::PlaneID Plane() const
Returns the plane ID this cluster lies on.
std::vector< HitPtr_t > HitVector_t
vector of pointers to hits
Class merging clusters: recomputes start and end position and hit list.
art::Ptr< recob::Hit > HitPtr_t
type of pointer to hits
float OpeningAngle(ClusterEnds_t side) const
Returns the opening angle at either end of the cluster.
float EndAngle() const
Returns the ending angle of the cluster.
recob::Cluster::ID_t ID_t
Type of cluster ID.
float WireCoord(ClusterEnds_t side) const
Returns the wire coordinate of one of the end sides of the cluster.
art framework interface to geometry description
int ID_t
Type of cluster ID.
void AddHits(HitVector_t const &cluster_hits, bool prepend)
geo::PlaneID fPlaneID
Location of the start of the cluster.
float EndCharge() const
Returns the charge on the last wire of the cluster.
float EndTick() const
Returns the tick coordinate of the end of the cluster.
bool Add(recob::Cluster const &cluster)
Merges a single cluster into this object.
float EndWire() const
Returns the wire coordinate of the end of the cluster.
float fAngles[ClusterEnds_t::NEnds]
Angle of the start and end of the cluster, defined in [-pi,pi].