Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cluster::ClusterMergeHelper Class Reference

#include <ClusterMergeHelper.h>

Public Member Functions

::cmtool::CMergeManagerGetManager ()
 
void SetClusters (util::GeometryUtilities const &gser, const std::vector< std::vector< art::Ptr< recob::Hit >>> &clusters)
 Utility method to set cluster input information to CMergeManager from LArSoft data product (vector of recob::Hit art::Ptr) More...
 
void SetClusters (util::GeometryUtilities const &gser, const art::Event &evt, const std::string &cluster_module_label)
 Utility method to set cluster input information to CMerteManager from art::Event and cluster data product label. More...
 
void Process (util::GeometryUtilities const &gser)
 Function to execute CMergeManager::Process() More...
 
const std::vector< std::vector< art::Ptr< recob::Hit > > > & GetMergedClusterHits () const
 Utility method to retrieve merged clusters in terms of a vector of art::Ptr<recob::Hit> More...
 
const std::vector< cluster::ClusterParamsAlg > & GetMergedCPAN () const
 Utility method to retrieve merged clusters in terms of a vector of CPAN. More...
 
void AppendResult (util::GeometryUtilities const &gser, art::Event &ev, std::vector< recob::Cluster > &out_clusters, art::Assns< recob::Cluster, recob::Hit > &assns) const
 Utility method to append result set to user's data product storage. More...
 

Protected Member Functions

void SetClusters (util::GeometryUtilities const &gser, const std::vector< std::vector< util::PxHit >> &clusters)
 Internal method to transfer input cluster information in the right format to CMergeManager. More...
 

Protected Attributes

::cmtool::CMergeManager fMgr
 CMergeManager instance. More...
 
::util::GeometryUtilities fGeoU
 GeometryUtilities. More...
 
std::vector< std::vector< art::Ptr< recob::Hit > > > fInputClusters
 Input clusters in terms of a vector of art::Ptr<recob::Hit> collection. More...
 
std::vector< std::vector< art::Ptr< recob::Hit > > > fOutputClusters
 Output clusters in terms of a vector of art::Ptr<recob::Hit> collection. More...
 

Detailed Description

Definition at line 35 of file ClusterMergeHelper.h.

Member Function Documentation

void cluster::ClusterMergeHelper::AppendResult ( util::GeometryUtilities const &  gser,
art::Event ev,
std::vector< recob::Cluster > &  out_clusters,
art::Assns< recob::Cluster, recob::Hit > &  assns 
) const

Utility method to append result set to user's data product storage.

Definition at line 151 of file ClusterMergeHelper.cxx.

155  {
156 
157  if (!fOutputClusters.size())
158 
159  throw cet::exception(__FUNCTION__)
160  << "\033[93m"
161  << "You must call Process() before calling " << __FUNCTION__ << " to retrieve result."
162  << "\033[00m" << std::endl;
163 
165 
166  // Store output
167  for (size_t out_index = 0; out_index < GetMergedCPAN().size(); ++out_index) {
168 
169  // To save typing let's just retrieve const cluster_params instance
170  const cluster_params& res = GetMergedCPAN()[out_index].GetParams();
171 
172  // this "algo" is actually parroting its cluster_params
173  LazyClusterParamsAlg algo(res);
174 
175  std::vector<art::Ptr<recob::Hit>> const& hits = GetMergedClusterHits().at(out_index);
176 
177  // the full plane needed but not a part of cluster_params...
178  // get the one from the first hit
179  geo::PlaneID plane; // invalid by default
180  if (!hits.empty()) plane = hits.front()->WireID().planeID();
181 
182  // View_t needed but not a part of cluster_params, so retrieve it here
183  geo::View_t view_id = geo->Plane(plane).View();
184 
185  // Push back a new cluster data product with parameters copied from cluster_params
186  out_clusters.emplace_back(res.start_point.w / fGeoU.WireToCm(), // start_wire
187  0., // sigma_start_wire
188  res.start_point.t / fGeoU.TimeToCm(), // start_tick
189  0., // sigma_start_tick
190  algo.StartCharge(gser).value(),
191  algo.StartAngle().value(),
192  algo.StartOpeningAngle().value(),
193  res.end_point.w / fGeoU.WireToCm(), // end_wire
194  0., // sigma_end_wire
195  res.end_point.t / fGeoU.TimeToCm(), // end_tick
196  0., // sigma_end_tick
197  algo.EndCharge(gser).value(),
198  algo.EndAngle().value(),
199  algo.EndOpeningAngle().value(),
200  algo.Integral().value(),
201  algo.IntegralStdDev().value(),
202  algo.SummedADC().value(),
203  algo.SummedADCStdDev().value(),
204  algo.NHits(),
205  algo.MultipleHitDensity(),
206  algo.Width(gser),
207  out_clusters.size(), // ID
208  view_id,
209  plane,
211 
212  util::CreateAssn(ev, out_clusters, GetMergedClusterHits().at(out_index), assns);
213  }
214  }
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
Double_t TimeToCm() const
Double_t WireToCm() const
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
const std::vector< std::vector< art::Ptr< recob::Hit > > > & GetMergedClusterHits() const
Utility method to retrieve merged clusters in terms of a vector of art::Ptr<recob::Hit> ...
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:184
std::vector< std::vector< art::Ptr< recob::Hit > > > fOutputClusters
Output clusters in terms of a vector of art::Ptr<recob::Hit> collection.
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.
::util::GeometryUtilities fGeoU
GeometryUtilities.
const std::vector< cluster::ClusterParamsAlg > & GetMergedCPAN() const
Utility method to retrieve merged clusters in terms of a vector of CPAN.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
::cmtool::CMergeManager& cluster::ClusterMergeHelper::GetManager ( )
inline

Definition at line 38 of file ClusterMergeHelper.h.

39  {
40  return fMgr;
41  }
::cmtool::CMergeManager fMgr
CMergeManager instance.
const std::vector< std::vector< art::Ptr< recob::Hit > > > & cluster::ClusterMergeHelper::GetMergedClusterHits ( ) const

Utility method to retrieve merged clusters in terms of a vector of art::Ptr<recob::Hit>

Definition at line 124 of file ClusterMergeHelper.cxx.

126  {
127  if (!fOutputClusters.size())
128  throw cet::exception(__FUNCTION__)
129  << "\033[93m"
130  << "You must call Process() before calling " << __FUNCTION__ << " to retrieve result."
131  << "\033[00m" << std::endl;
132 
133  return fOutputClusters;
134  }
std::vector< std::vector< art::Ptr< recob::Hit > > > fOutputClusters
Output clusters in terms of a vector of art::Ptr<recob::Hit> collection.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
const std::vector< cluster::ClusterParamsAlg > & cluster::ClusterMergeHelper::GetMergedCPAN ( ) const

Utility method to retrieve merged clusters in terms of a vector of CPAN.

Definition at line 138 of file ClusterMergeHelper.cxx.

140  {
141  if (!fOutputClusters.size())
142  throw cet::exception(__FUNCTION__)
143  << "\033[93m"
144  << "You must call Process() before calling " << __FUNCTION__ << " to retrieve result."
145  << "\033[00m" << std::endl;
146 
147  return fMgr.GetClusters();
148  }
const std::vector< cluster::ClusterParamsAlg > & GetClusters() const
A method to obtain output clusters.
Definition: CMergeManager.h:58
std::vector< std::vector< art::Ptr< recob::Hit > > > fOutputClusters
Output clusters in terms of a vector of art::Ptr<recob::Hit> collection.
::cmtool::CMergeManager fMgr
CMergeManager instance.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void cluster::ClusterMergeHelper::Process ( util::GeometryUtilities const &  gser)

Function to execute CMergeManager::Process()

Definition at line 90 of file ClusterMergeHelper.cxx.

92  {
93  if (fMgr.GetClusters().size())
94  throw cet::exception(__PRETTY_FUNCTION__)
95  << "\033[93m"
96  << "Merged cluster set not empty... Called Process() twice?"
97  << "\033[00m" << std::endl;
98 
99  fMgr.Process(gser);
100 
101  // Now create output clusters
102  auto res = fMgr.GetBookKeeper();
103 
104  std::vector<std::vector<unsigned short>> out_clusters = res.GetResult();
105  fOutputClusters.clear();
106 
107  fOutputClusters.reserve(out_clusters.size());
108 
109  for (auto const& cluster_index_v : out_clusters) {
110 
111  std::vector<art::Ptr<recob::Hit>> out_cluster;
112 
113  for (auto const& cluster_index : cluster_index_v) {
114  out_cluster.reserve(out_cluster.size() + fInputClusters.at(cluster_index).size());
115  for (auto const& hit_ptr : fInputClusters.at(cluster_index))
116  out_cluster.push_back(hit_ptr);
117  }
118  fOutputClusters.push_back(out_cluster);
119  }
120  }
std::vector< std::vector< art::Ptr< recob::Hit > > > fInputClusters
Input clusters in terms of a vector of art::Ptr<recob::Hit> collection.
std::vector< std::vector< unsigned short > > GetResult() const
const std::vector< cluster::ClusterParamsAlg > & GetClusters() const
A method to obtain output clusters.
Definition: CMergeManager.h:58
std::vector< std::vector< art::Ptr< recob::Hit > > > fOutputClusters
Output clusters in terms of a vector of art::Ptr<recob::Hit> collection.
void Process(util::GeometryUtilities const &gser)
A method to execute the main action, to be called per event.
const CMergeBookKeeper & GetBookKeeper() const
A method to obtain book keeper.
Definition: CMergeManager.h:65
::cmtool::CMergeManager fMgr
CMergeManager instance.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void cluster::ClusterMergeHelper::SetClusters ( util::GeometryUtilities const &  gser,
const std::vector< std::vector< art::Ptr< recob::Hit >>> &  clusters 
)

Utility method to set cluster input information to CMergeManager from LArSoft data product (vector of recob::Hit art::Ptr)

Definition at line 24 of file ClusterMergeHelper.cxx.

27  {
28  fInputClusters.clear();
29  fOutputClusters.clear();
30 
31  std::vector<std::vector<util::PxHit>> px_clusters(clusters.size(), std::vector<util::PxHit>());
32 
33  fInputClusters.resize(clusters.size(), std::vector<art::Ptr<recob::Hit>>());
34 
35  for (size_t cluster_index = 0; cluster_index < clusters.size(); ++cluster_index) {
36 
37  px_clusters.at(cluster_index).resize(clusters.at(cluster_index).size(), util::PxHit());
38 
39  fInputClusters.at(cluster_index).resize(clusters.at(cluster_index).size());
40 
41  for (size_t hit_index = 0; hit_index < clusters.at(cluster_index).size(); ++hit_index) {
42 
43  px_clusters.at(cluster_index).at(hit_index).plane =
44  clusters.at(cluster_index).at(hit_index)->WireID().Plane;
45  px_clusters.at(cluster_index).at(hit_index).w =
46  clusters.at(cluster_index).at(hit_index)->WireID().Wire * fGeoU.WireToCm();
47  px_clusters.at(cluster_index).at(hit_index).t =
48  clusters.at(cluster_index).at(hit_index)->PeakTime() * fGeoU.TimeToCm();
49  px_clusters.at(cluster_index).at(hit_index).charge =
50  clusters.at(cluster_index).at(hit_index)->Integral();
51 
52  fInputClusters.at(cluster_index).at(hit_index) = clusters.at(cluster_index).at(hit_index);
53  }
54  }
55 
56  SetClusters(gser, px_clusters);
57  }
std::vector< std::vector< art::Ptr< recob::Hit > > > fInputClusters
Input clusters in terms of a vector of art::Ptr<recob::Hit> collection.
Double_t TimeToCm() const
Double_t WireToCm() const
std::vector< std::vector< art::Ptr< recob::Hit > > > fOutputClusters
Output clusters in terms of a vector of art::Ptr<recob::Hit> collection.
::util::GeometryUtilities fGeoU
GeometryUtilities.
void SetClusters(util::GeometryUtilities const &gser, const std::vector< std::vector< art::Ptr< recob::Hit >>> &clusters)
Utility method to set cluster input information to CMergeManager from LArSoft data product (vector of...
void cluster::ClusterMergeHelper::SetClusters ( util::GeometryUtilities const &  gser,
const art::Event evt,
const std::string cluster_module_label 
)

Utility method to set cluster input information to CMerteManager from art::Event and cluster data product label.

Definition at line 61 of file ClusterMergeHelper.cxx.

65  {
66 
68  evt.getByLabel(cluster_module_label, clusters_h);
69 
70  if (!(clusters_h.isValid()))
71 
72  throw cet::exception(__FUNCTION__)
73  << "\033[93m"
74  << " Failed to retrieve recob::Cluster with label: " << cluster_module_label.c_str()
75  << "\033[00m" << std::endl;
76 
77  std::vector<std::vector<art::Ptr<recob::Hit>>> cluster_hits_v;
78  cluster_hits_v.reserve(clusters_h->size());
79 
80  art::FindManyP<recob::Hit> hit_m(clusters_h, evt, cluster_module_label);
81 
82  for (size_t i = 0; i < clusters_h->size(); ++i)
83  cluster_hits_v.push_back(hit_m.at(i));
84 
85  SetClusters(gser, cluster_hits_v);
86  }
bool isValid() const noexcept
Definition: Handle.h:191
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
void SetClusters(util::GeometryUtilities const &gser, const std::vector< std::vector< art::Ptr< recob::Hit >>> &clusters)
Utility method to set cluster input information to CMergeManager from LArSoft data product (vector of...
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void cluster::ClusterMergeHelper::SetClusters ( util::GeometryUtilities const &  gser,
const std::vector< std::vector< util::PxHit >> &  clusters 
)
inlineprotected

Internal method to transfer input cluster information in the right format to CMergeManager.

Definition at line 70 of file ClusterMergeHelper.h.

72  {
73  fMgr.Reset();
74  fMgr.SetClusters(gser, clusters);
75  }
virtual void Reset()
Method to reset itself.
void SetClusters(util::GeometryUtilities const &gser, const std::vector< std::vector< util::PxHit >> &clusters)
A simple method to add a cluster.
::cmtool::CMergeManager fMgr
CMergeManager instance.

Member Data Documentation

::util::GeometryUtilities cluster::ClusterMergeHelper::fGeoU
protected

GeometryUtilities.

Definition at line 82 of file ClusterMergeHelper.h.

std::vector<std::vector<art::Ptr<recob::Hit> > > cluster::ClusterMergeHelper::fInputClusters
protected

Input clusters in terms of a vector of art::Ptr<recob::Hit> collection.

Definition at line 85 of file ClusterMergeHelper.h.

::cmtool::CMergeManager cluster::ClusterMergeHelper::fMgr
protected

CMergeManager instance.

Definition at line 79 of file ClusterMergeHelper.h.

std::vector<std::vector<art::Ptr<recob::Hit> > > cluster::ClusterMergeHelper::fOutputClusters
protected

Output clusters in terms of a vector of art::Ptr<recob::Hit> collection.

Definition at line 88 of file ClusterMergeHelper.h.


The documentation for this class was generated from the following files: