LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ClusterMergeHelper.cxx
Go to the documentation of this file.
1 //
3 // ClusterMergeHelper source
4 //
6 
7 #ifndef CLUSTERMERGEHELPER_CXX
8 #define CLUSTERMERGEHELPER_CXX
9 
10 #include "ClusterMergeHelper.h"
12 
13 namespace cluster{
14 
15 
16  //####################################################################################################
18  //####################################################################################################
19  {
20  fInputClusters.clear();
21  fOutputClusters.clear();
22 
23  std::vector<std::vector<util::PxHit> > px_clusters(clusters.size(),std::vector<util::PxHit>());
24 
25  fInputClusters.resize(clusters.size(),std::vector<art::Ptr<recob::Hit> >());
26 
27  for(size_t cluster_index=0; cluster_index < clusters.size(); ++cluster_index) {
28 
29  px_clusters.at(cluster_index).resize(clusters.at(cluster_index).size(),util::PxHit());
30 
31  fInputClusters.at(cluster_index).resize(clusters.at(cluster_index).size());
32 
33  for(size_t hit_index=0; hit_index < clusters.at(cluster_index).size(); ++hit_index) {
34 
35  px_clusters.at(cluster_index).at(hit_index).plane = clusters.at(cluster_index).at(hit_index)->WireID().Plane;
36  px_clusters.at(cluster_index).at(hit_index).w = clusters.at(cluster_index).at(hit_index)->WireID().Wire * fGeoU.WireToCm();
37  px_clusters.at(cluster_index).at(hit_index).t = clusters.at(cluster_index).at(hit_index)->PeakTime() * fGeoU.TimeToCm();
38  px_clusters.at(cluster_index).at(hit_index).charge = clusters.at(cluster_index).at(hit_index)->Integral();
39 
40  fInputClusters.at(cluster_index).at(hit_index) = clusters.at(cluster_index).at(hit_index);
41 
42  }
43 
44  }
45 
46  SetClusters(px_clusters);
47 
48  }
49 
50  //##################################################################################################
51  void ClusterMergeHelper::SetClusters(const art::Event &evt, const std::string &cluster_module_label)
52  //##################################################################################################
53  {
54 
56  evt.getByLabel(cluster_module_label, clusters_h);
57 
58  if(!(clusters_h.isValid()))
59 
60  throw cet::exception(__FUNCTION__)
61  << "\033[93m"
62  << " Failed to retrieve recob::Cluster with label: "
63  << cluster_module_label.c_str()
64  << "\033[00m"
65  << std::endl;
66 
67  std::vector<std::vector<art::Ptr<recob::Hit> > > cluster_hits_v;
68 
69  cluster_hits_v.reserve(clusters_h->size());
70 
71  art::FindManyP<recob::Hit> hit_m(clusters_h, evt, cluster_module_label);
72 
73  for(size_t i=0; i<clusters_h->size(); ++i)
74 
75  cluster_hits_v.push_back(hit_m.at(i));
76 
77  SetClusters(cluster_hits_v);
78 
79  }
80 
81  //################################
83  //################################
84  {
85  if(fMgr.GetClusters().size())
86 
87  throw cet::exception(__PRETTY_FUNCTION__) << "\033[93m"
88  << "Merged cluster set not empty... Called Process() twice?"
89  << "\033[00m"
90  << std::endl;
91 
92  // Process
93  fMgr.Process();
94 
95  // Now create output clusters
96  auto res = fMgr.GetBookKeeper();
97 
98  std::vector<std::vector<unsigned short> > out_clusters = res.GetResult();
99 
100  fOutputClusters.clear();
101 
102  fOutputClusters.reserve(out_clusters.size());
103 
104  for(auto const &cluster_index_v : out_clusters) {
105 
106  std::vector<art::Ptr<recob::Hit> > out_cluster;
107 
108  for(auto const& cluster_index : cluster_index_v) {
109 
110  out_cluster.reserve(out_cluster.size() + fInputClusters.at(cluster_index).size());
111 
112  for(auto const& hit_ptr : fInputClusters.at(cluster_index))
113 
114  out_cluster.push_back(hit_ptr);
115 
116  }
117 
118  fOutputClusters.push_back(out_cluster);
119 
120  }
121 
122  }
123 
124  //######################################################################################################
125  const std::vector<std::vector<art::Ptr<recob::Hit> > >& ClusterMergeHelper::GetMergedClusterHits() const
126  //######################################################################################################
127  {
128  if(!fOutputClusters.size())
129 
130  throw cet::exception(__FUNCTION__)
131  << "\033[93m"
132  << "You must call Process() before calling " << __FUNCTION__ << " to retrieve result."
133  << "\033[00m"
134  << std::endl;
135 
136  return fOutputClusters;
137  }
138 
139  //#####################################################################################
140  const std::vector<cluster::ClusterParamsAlg>& ClusterMergeHelper::GetMergedCPAN() const
141  //#####################################################################################
142  {
143  if(!fOutputClusters.size())
144 
145  throw cet::exception(__FUNCTION__)
146  << "\033[93m"
147  << "You must call Process() before calling " << __FUNCTION__ << " to retrieve result."
148  << "\033[00m"
149  << std::endl;
150 
151  return fMgr.GetClusters();
152  }
153 
155  art::Event &ev,
156  std::vector<recob::Cluster> &out_clusters,
158  {
159 
160  if(!fOutputClusters.size())
161 
162  throw cet::exception(__FUNCTION__)
163  << "\033[93m"
164  << "You must call Process() before calling " << __FUNCTION__ << " to retrieve result."
165  << "\033[00m"
166  << std::endl;
167 
168 
170 
171  // Store output
172  for(size_t out_index=0; out_index < GetMergedCPAN().size(); ++out_index) {
173 
174  // To save typing let's just retrieve const cluster_params instance
175  const cluster_params &res = GetMergedCPAN().at(out_index).GetParams();
176 
177  // this "algo" is actually parroting its cluster_params
178  LazyClusterParamsAlg algo(res);
179 
180  std::vector<art::Ptr<recob::Hit>> const& hits
181  = GetMergedClusterHits().at(out_index);
182 
183  // the full plane needed but not a part of cluster_params...
184  // get the one from the first hit
185  geo::PlaneID plane; // invalid by default
186  if (!hits.empty()) plane = hits.front()->WireID().planeID();
187 
188  // View_t needed but not a part of cluster_params, so retrieve it here
189  geo::View_t view_id = geo->Plane(plane).View();
190 
191  // Push back a new cluster data product with parameters copied from cluster_params
192  out_clusters.emplace_back(
193  res.start_point.w / fGeoU.WireToCm(), // start_wire
194  0., // sigma_start_wire
195  res.start_point.t / fGeoU.TimeToCm(), // start_tick
196  0., // sigma_start_tick
197  algo.StartCharge().value(), // start_charge
198  algo.StartAngle().value(), // start_angle
199  algo.StartOpeningAngle().value(), // start_opening
200  res.end_point.w / fGeoU.WireToCm(), // end_wire
201  0., // sigma_end_wire
202  res.end_point.t / fGeoU.TimeToCm(), // end_tick
203  0., // sigma_end_tick
204  algo.EndCharge().value(), // end_charge
205  algo.EndAngle().value(), // end_angle
206  algo.EndOpeningAngle().value(), // end_opening
207  algo.Integral().value(), // integral
208  algo.IntegralStdDev().value(), // integral_stddev
209  algo.SummedADC().value(), // summedADC
210  algo.SummedADCStdDev().value(), // summedADC_stddev
211  algo.NHits(), // n_hits
212  algo.MultipleHitDensity(), // multiple_hit_density
213  algo.Width(), // width
214  out_clusters.size(), // ID
215  view_id, // view
216  plane, // plane
217  recob::Cluster::Sentry // sentry
218  );
219 
220  util::CreateAssn(ed,
221  ev,
222  out_clusters,
223  GetMergedClusterHits().at(out_index),
224  assns
225  );
226  }
227 
228  }
229 
230 } // namespace cluster
231 
232 #endif
Algorithm class inheriting pre-computed results.
Algorithm class inheriting cluster parameters.
std::vector< std::vector< art::Ptr< recob::Hit > > > fInputClusters
Input clusters in terms of a vector of art::Ptr<recob::Hit> collection.
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
virtual Measure_t EndAngle() override
Computes the angle of the cluster.
virtual size_t NHits() override
Returns the number of hits in the cluster.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
std::vector< std::vector< unsigned short > > GetResult() const
Double_t TimeToCm() const
Double_t WireToCm() const
virtual Measure_t SummedADC() override
Computes the total charge of the cluster from Hit::SummedADC()
const std::vector< cluster::ClusterParamsAlg > & GetClusters() const
A method to obtain output clusters.
Definition: CMergeManager.h:50
virtual Measure_t StartCharge() override
Computes the charge on the first and last wire of the track.
Cluster finding and building.
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> ...
virtual Measure_t EndOpeningAngle() override
Computes the opening angle at the start or end of the cluster.
virtual Measure_t Integral() override
Computes the total charge of the cluster from Hit::Integral()
void AppendResult(art::EDProducer &ed, 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&#39;s data product storage.
bool isValid() const
Definition: Handle.h:190
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:171
void hits()
Definition: readHits.C:15
virtual Measure_t EndCharge() override
Computes the charge on the first and last wire of the track.
double t
Definition: PxUtils.h:11
void Process()
Function to execute CMergeManager::Process()
void Process()
A method to execute the main action, to be called per event.
virtual Measure_t SummedADCStdDev() override
Computes the standard deviation on the charge of the cluster hits.
std::vector< std::vector< art::Ptr< recob::Hit > > > fOutputClusters
Output clusters in terms of a vector of art::Ptr<recob::Hit> collection.
virtual float MultipleHitDensity() override
Fraction of wires in the cluster with more than one hit.
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::PxPoint start_point
start point
Definition: ClusterParams.h:24
::util::GeometryUtilities fGeoU
GeometryUtilities.
virtual Measure_t IntegralStdDev() override
Computes the standard deviation on the charge of the cluster hits.
double w
Definition: PxUtils.h:10
virtual float Width() override
Computes the width of the cluster.
util::PxPoint end_point
end point
Definition: ClusterParams.h:25
virtual Measure_t StartOpeningAngle() override
Computes the opening angle at the start or end of the cluster.
virtual Measure_t StartAngle() override
Computes the angle of the cluster.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
const std::vector< cluster::ClusterParamsAlg > & GetMergedCPAN() const
Utility method to retrieve merged clusters in terms of a vector of CPAN.
void SetClusters(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...
const CMergeBookKeeper & GetBookKeeper() const
A method to obtain book keeper.
Definition: CMergeManager.h:53
::cmtool::CMergeManager fMgr
CMergeManager instance.
Namespace collecting geometry-related classes utilities.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33