LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
SimpleClusterMerger_module.cc
Go to the documentation of this file.
1 // Class: SimpleClusterMerger
3 // Module Type: producer
4 // File: SimpleClusterMerger_module.cc
5 //
6 // Generated at Tue May 27 14:15:41 2014 by Kazuhiro Terao using artmod
7 // from cetpkgsupport v1_05_04.
9 
17 #include "fhiclcpp/ParameterSet.h"
18 
31 
32 #include <memory>
33 
34 namespace cluster {
35 
37 
38  public:
39 
40  explicit SimpleClusterMerger(fhicl::ParameterSet const & p);
41 
42  virtual ~SimpleClusterMerger();
43 
44  void produce(art::Event & evt) override;
45 
46  private:
47 
50 
52  std::string fClusterModuleLabel;
53 
56 
57  //--- CBAlgo instances ---//
58  /*
59  CMergeManager takes pointer to CBoolAlgoBase inherit class instance.
60  So the simplest way is to create them on heap and keep the pointers.
61  But that has a concern to computation speed (though I think that would
62  never be a slow enough to be a concern)... so here we take an example
63  of using CBAlgo instances created on stack.
64  */
65 
68 
71 
74 
77 
78  };
79 }
80 
81 namespace cluster {
82 
84  {
85  // Declare output data products
86  produces< std::vector<recob::Cluster> >();
87  produces< art::Assns<recob::Cluster, recob::Hit> >();
88 
89  // Fill fcl parameter
90  fClusterModuleLabel = p.get<std::string>("InputClusterLabel");
91 
92  //--- Configure Merging Algorithm ---//
93  /*
94  This is where we should pass fcl parameters to configure various algorithms
95  we defined as class member. Here, for simplicity, I don't pass any configuration
96  parameters but you should in your custom merging module.
97  */
98 
99  // Configure angle algorithm
100  fAngleAlg.SetVerbose(false); // no verbous mode... annoying
101  fAngleAlg.SetMinHits(10); // Set minimum # hits to be 10
102  fAngleAlg.SetAngleCut(180); // Set angle-diff cut < 180 degree (i.e. anything :))
103  fAngleAlg.SetAllow180Ambig(true); // Allow 180-degree ambiguity (direction mis-reco)
104 
105  // Configure distance algorithm
106  fDistAlg.SetVerbose(false); // No verbous mode ... annoying
107  fDistAlg.SetMinHits(10); // Set minimum # hits to be 10
108  fDistAlg.SetSquaredDistanceCut(9); // Set distance-squared cut to be 9 cm^2
109 
110  // Attach them to CBAlgoArray to make it into one merging algorithm
111  fMergeAlg.AddAlgo(&fAngleAlg,true); // attach to CBAlgoArray in AND condition
112  fMergeAlg.AddAlgo(&fDistAlg,true); // attach to CBAlgoArray in AND condition
113 
114  //--- Configure Prohibit Algorithm ---//
115 
116  // I configure this using totally arbitrary numbers + I do not configure all parameters...
117  // This is just for example.
118  fProhibitAlg.SetVerbose(false);
119  fProhibitAlg.SetDebug(false);
124 
125 
126  //--- Configure Merger ---//
127 
128  fCMerge.GetManager(0).AddMergeAlgo(&fMergeAlg); // Attach merging algorithm
129  fCMerge.GetManager(0).AddSeparateAlgo(&fProhibitAlg); // Attach prohibit algorithm
130  fCMerge.GetManager(0).DebugMode(::cmtool::CMergeManager::kPerIteration); // Set verbosity level to be per-merging-iteration report
131  fCMerge.GetManager(0).MergeTillConverge(true); // Set to iterate over till it finds no more newly merged clusters
132 
133  //
134  // FYI there's an algorithm to just-merge-everything if you want to do a simple test (line commented out below)
135  //
136  //fCMerge.GetManager(0).AddMergeAlgo( new CBAlgoMergeAll );
137 
138 
139  }
140 
142  {
143  // Clean up dynamic memory and other resources here.
144  }
145 
147  {
148  std::unique_ptr<std::vector<recob::Cluster> > out_clusters(new std::vector<recob::Cluster>);
149  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit> > out_assn(new art::Assns<recob::Cluster, recob::Hit>);
150 
152 
153  //
154  // Preparation
155  //
156 
157  // Retrieve input clusters
159  evt.getByLabel(fClusterModuleLabel,cHandle);
160 
161  if(!cHandle.isValid())
162  throw cet::exception(__FUNCTION__) << "Invalid input cluster label!" << std::endl;
163 
164  // Cluster type conversion: recob::Hit => util::PxHit
165  std::vector<std::vector< ::util::PxHit> > local_clusters;
166  art::FindManyP<recob::Hit> hit_m(cHandle, evt, fClusterModuleLabel);
168  for(size_t i=0; i<cHandle->size(); ++i) {
169 
170  local_clusters.push_back(std::vector< ::util::PxHit>());
171 
172  const std::vector<art::Ptr<recob::Hit> >& hits = hit_m.at(i);
173 
174  conv.GeneratePxHit(hits, local_clusters.back());
175  }
176 
177  //--- Process merging ---//
178  fCMerge.Process(local_clusters);
179 
180  // Store output
181  auto merged_clusters = fCMerge.GetResult().GetResult();
182 
183  auto const& cpan_v = fCMerge.GetClusters();
184  if(merged_clusters.size()!=cpan_v.size())
185 
186  throw cet::exception(__FUNCTION__) << "LOGIC ERROR: merged cluster id length != output cluster counts..." << std::endl;
187 
188  for(size_t out_index=0; out_index < merged_clusters.size(); ++out_index) {
189 
190  // To save typing let's just retrieve const cluster_params instance
191  const cluster_params &res = cpan_v[out_index].GetParams();
192 
193  // this "algo" is actually parroting its cluster_params
194  LazyClusterParamsAlg algo(res);
195 
196  std::vector<art::Ptr<recob::Hit> > merged_hits;
197  for(auto const& c_index : merged_clusters[out_index]) {
198  const std::vector<art::Ptr<recob::Hit> >& hits = hit_m.at(c_index);
199  merged_hits.reserve(merged_hits.size() + hits.size());
200  for(auto const& ptr : hits) merged_hits.push_back(ptr);
201  }
202 
203  // the full plane needed but not a part of cluster_params...
204  // get the one from the first hit
205  geo::PlaneID plane; // invalid by default
206  if (!merged_hits.empty()) plane = merged_hits.front()->WireID().planeID();
207 
208  // View_t needed but not a part of cluster_params, so retrieve it here
209  geo::View_t view_id = geo->Plane(plane).View();
210 
211  // Push back a new cluster data product with parameters copied from cluster_params
212  out_clusters->emplace_back(
213  res.start_point.w / fGeoU.WireToCm(), // start_wire
214  0., // sigma_start_wire
215  res.start_point.t / fGeoU.TimeToCm(), // start_tick
216  0., // sigma_start_tick
217  algo.StartCharge().value(), // start_charge
218  algo.StartAngle().value(), // start_angle
219  algo.StartOpeningAngle().value(), // start_opening
220  res.end_point.w / fGeoU.WireToCm(), // end_wire
221  0., // sigma_end_wire
222  res.end_point.t / fGeoU.TimeToCm(), // end_tick
223  0., // sigma_end_tick
224  algo.EndCharge().value(), // end_charge
225  algo.EndAngle().value(), // end_angle
226  algo.EndOpeningAngle().value(), // end_opening
227  algo.Integral().value(), // integral
228  algo.IntegralStdDev().value(), // integral_stddev
229  algo.SummedADC().value(), // summedADC
230  algo.SummedADCStdDev().value(), // summedADC_stddev
231  algo.NHits(), // n_hits
232  algo.MultipleHitDensity(), // multiple_hit_density
233  algo.Width(), // width
234  out_clusters->size(), // ID
235  view_id, // view
236  plane, // plane
237  recob::Cluster::Sentry // sentry
238  );
239 
240  util::CreateAssn(*this,
241  evt,
242  *(out_clusters.get()),
243  merged_hits,
244  *(out_assn.get())
245  );
246 
247  }
248 
249  evt.put(std::move(out_clusters));
250  evt.put(std::move(out_assn));
251  }
252 }
253 
Class def header for a class CBAlgoArray.
Class def header for a class CMergeHelper.
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:38
Algorithm class inheriting pre-computed results.
Algorithm class inheriting cluster parameters.
SimpleClusterMerger(fhicl::ParameterSet const &p)
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.
void SetSquaredDistanceCut(double d)
Method to set cut value in cm^2 for distance compatibility test.
virtual size_t NHits() override
Returns the number of hits in the cluster.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
::util::GeometryUtilities fGeoU
GeometryUtilities instance.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
::cmtool::CBAlgoTrackSeparate fProhibitAlg
Example prohibit algorithm.
std::vector< std::vector< unsigned short > > GetResult() const
Class def header for a class CBAlgoAngleCompat.
Double_t TimeToCm() const
Double_t WireToCm() const
virtual Measure_t SummedADC() override
Computes the total charge of the cluster from Hit::SummedADC()
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
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()
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:190
Class def header for a class CBAlgoTrackSeparate.
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:171
void SetAllow180Ambig(bool on)
Method to set whether you allow angles to match with +/- 180 deg difference.
void hits()
Definition: readHits.C:15
std::string fClusterModuleLabel
Input cluster data product producer name label.
void GeneratePxHit(const std::vector< unsigned int > &hit_index, const std::vector< art::Ptr< recob::Hit >> hits, std::vector< util::PxHit > &pxhits) const
Generate: from 1 set of hits => 1 set of PxHits using indexes (association)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Class def header for a class CBAlgoAngleSeparate.
void SetAngleCut(double angle)
Method to set cut value in degrees for angle compatibility test.
virtual Measure_t EndCharge() override
Computes the charge on the first and last wire of the track.
double t
Definition: PxUtils.h:11
T get(std::string const &key) const
Definition: ParameterSet.h:231
const std::vector< ::cluster::ClusterParamsAlg > & GetClusters() const
::cmtool::CBAlgoArray fMergeAlg
Example merging algorithm: algorithm array container.
virtual Measure_t SummedADCStdDev() override
Computes the standard deviation on the charge of the cluster hits.
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
void AddMergeAlgo(CBoolAlgoBase *algo)
A simple method to add an algorithm for merging.
Definition: CMergeManager.h:44
::cmtool::CMergeHelper fCMerge
ClusterMergeHelper.
const CMergeBookKeeper & GetResult() const
Definition: CMergeHelper.h:44
Declaration of cluster object.
virtual Measure_t IntegralStdDev() override
Computes the standard deviation on the charge of the cluster hits.
void SetMinHits(size_t n)
Set Minimum Number of Hits to consider Cluster.
double w
Definition: PxUtils.h:10
void produce(art::Event &evt) override
virtual float Width() override
Computes the width of the cluster.
void SetVerbose(bool on)
Setter function for verbosity.
Class def header for a class CBAlgoShortestDist.
Utility object to perform functions of association.
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
::cmtool::CBAlgoAngleCompat fAngleAlg
Merging algorithm 2.
void SetMaxOpeningAngle(float maxangle)
void SetMinLength(float minlength)
void DebugMode(CMMSGLevel_t level)
Method to enable debug mode (lots of couts)
Definition: CMManagerBase.h:54
CMergeManager & GetManager(size_t mgr_id)
Definition: CMergeHelper.cxx:8
virtual void SetVerbose(bool doit=true)
Setter function for verbosity.
Definition: CMAlgoBase.h:80
void SetMinHits(size_t n)
Set Minimum Number of Hits to consider Cluster.
TCEvent evt
Definition: DataStructs.cxx:5
void MergeTillConverge(bool doit=true)
Switch to continue merging till converges.
Definition: CMManagerBase.h:66
::cmtool::CBAlgoShortestDist fDistAlg
Merging algorithm 1.
void Process(const std::vector< std::vector< ::util::PxHit > > &clusters)
Namespace collecting geometry-related classes utilities.
void AddAlgo(CBoolAlgoBase *algo, bool ask_and=true)
A simple method to add a one merging step.
Definition: CBAlgoArray.h:37
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void SetMinAngleDiff(float anglesep)
void AddSeparateAlgo(CBoolAlgoBase *algo)
A simple method to add an algorithm for separation.
Definition: CMergeManager.h:47