Public Member Functions | Private Member Functions | Private Attributes | List of all members
cluster::BlurredClustering Class Reference
Inheritance diagram for cluster::BlurredClustering:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 BlurredClustering (fhicl::ParameterSet const &pset)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void produce (art::Event &evt) override
 

Private Attributes

std::string const fHitsModuleLabel
 
std::string const fTrackModuleLabel
 
std::string const fVertexModuleLabel
 
std::string const fPFParticleModuleLabel
 
bool const fCreateDebugPDF
 
bool const fMergeClusters
 
bool const fGlobalTPCRecon
 
bool const fShowerReconOnly
 
cluster::BlurredClusteringAlg fBlurredClusteringAlg
 
cluster::MergeClusterAlg fMergeClusterAlg
 
shower::TrackShowerSeparationAlg fTrackShowerSeparationAlg
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 52 of file BlurredClustering_module.cc.

Constructor & Destructor Documentation

cluster::BlurredClustering::BlurredClustering ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 68 of file BlurredClustering_module.cc.

69  : EDProducer{pset}
70  , fHitsModuleLabel{pset.get<std::string>("HitsModuleLabel")}
71  , fTrackModuleLabel{pset.get<std::string>("TrackModuleLabel")}
72  , fVertexModuleLabel{pset.get<std::string>("VertexModuleLabel")}
73  , fPFParticleModuleLabel{pset.get<std::string>("PFParticleModuleLabel")}
74  , fCreateDebugPDF{pset.get<bool>("CreateDebugPDF")}
75  , fMergeClusters{pset.get<bool>("MergeClusters")}
76  , fGlobalTPCRecon{pset.get<bool>("GlobalTPCRecon")}
77  , fShowerReconOnly{pset.get<bool>("ShowerReconOnly")}
78  , fBlurredClusteringAlg{pset.get<fhicl::ParameterSet>("BlurredClusterAlg")}
79  , fMergeClusterAlg{pset.get<fhicl::ParameterSet>("MergeClusterAlg")}
80  , fTrackShowerSeparationAlg{pset.get<fhicl::ParameterSet>("TrackShowerSeparationAlg")}
81 {
82  produces<std::vector<recob::Cluster>>();
83  produces<art::Assns<recob::Cluster, recob::Hit>>();
84 }
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
cluster::MergeClusterAlg fMergeClusterAlg
shower::TrackShowerSeparationAlg fTrackShowerSeparationAlg
cluster::BlurredClusteringAlg fBlurredClusteringAlg

Member Function Documentation

void cluster::BlurredClustering::produce ( art::Event evt)
overrideprivatevirtual

Implements art::EDProducer.

Definition at line 87 of file BlurredClustering_module.cc.

88 {
89  // Create debug pdf to illustrate the blurring process
91 
92  // Output containers -- collection of clusters and associations
93  auto clusters = std::make_unique<std::vector<recob::Cluster>>();
94  auto associations = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
95 
96  // Compute the cluster characteristics
97  // Just use default for now, but configuration will go here
98  ClusterParamsImportWrapper<StandardClusterParamsAlg> ClusterParamAlgo;
99 
100  // Services
102  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
103  auto const detProp =
105  util::GeometryUtilities const gser{*geom, clockData, detProp};
106  int const readoutWindowSize = detProp.ReadOutWindowSize();
107 
108  // Get the hits from the event
110  std::vector<art::Ptr<recob::Hit>> hits;
111  std::vector<art::Ptr<recob::Hit>> hitsToCluster;
112  if (evt.getByLabel(fHitsModuleLabel, hitCollection)) art::fill_ptr_vector(hits, hitCollection);
113 
114  if (fShowerReconOnly) {
115 
116  // Get the tracks from the event
117  art::Handle<std::vector<recob::Track>> trackCollection;
118  std::vector<art::Ptr<recob::Track>> tracks;
119  if (evt.getByLabel(fTrackModuleLabel, trackCollection))
120  art::fill_ptr_vector(tracks, trackCollection);
121 
122  // Get the space points from the event
123  art::Handle<std::vector<recob::SpacePoint>> spacePointCollection;
124  std::vector<art::Ptr<recob::SpacePoint>> spacePoints;
125  if (evt.getByLabel(fTrackModuleLabel, spacePointCollection))
126  art::fill_ptr_vector(spacePoints, spacePointCollection);
127 
128  // Get vertices from the event
129  art::Handle<std::vector<recob::Vertex>> vertexCollection;
130  std::vector<art::Ptr<recob::Vertex>> vertices;
131  if (evt.getByLabel(fVertexModuleLabel, vertexCollection))
132  art::fill_ptr_vector(vertices, vertexCollection);
133 
134  // Get pandora pfparticles and clusters from the event
135  art::Handle<std::vector<recob::PFParticle>> pfParticleCollection;
136  std::vector<art::Ptr<recob::PFParticle>> pfParticles;
137  if (evt.getByLabel(fPFParticleModuleLabel, pfParticleCollection))
138  art::fill_ptr_vector(pfParticles, pfParticleCollection);
139  art::Handle<std::vector<recob::Cluster>> clusterCollection;
140  evt.getByLabel(fPFParticleModuleLabel, clusterCollection);
141 
142  if (trackCollection.isValid()) {
143  art::FindManyP<recob::Hit> fmht(trackCollection, evt, fTrackModuleLabel);
144  art::FindManyP<recob::Track> fmth(hitCollection, evt, fTrackModuleLabel);
145  art::FindManyP<recob::SpacePoint> fmspt(trackCollection, evt, fTrackModuleLabel);
146  art::FindManyP<recob::Track> fmtsp(spacePointCollection, evt, fTrackModuleLabel);
148  evt.event(), hits, tracks, spacePoints, fmht, fmth, fmspt, fmtsp);
149  }
150  }
151  else
152  hitsToCluster = hits;
153 
154  // Make a map between the planes and the hits on each
155  std::map<std::pair<int, int>, std::vector<art::Ptr<recob::Hit>>> planeToHits;
156  for (auto const& hitToCluster : hitsToCluster) {
157  auto const& wireID = hitToCluster->WireID();
158  auto const planeNo = wireID.Plane;
159  auto const tpc = fGlobalTPCRecon ? wireID.TPC % 2 : wireID.TPC;
160  planeToHits[std::make_pair(planeNo, tpc)].push_back(hitToCluster);
161  }
162 
163  // Loop over views
164  for (auto const& [plane, hits] : planeToHits) {
165  std::vector<art::PtrVector<recob::Hit>> finalClusters;
166 
167  // Implement the algorithm
168  if (hits.size() >= fBlurredClusteringAlg.GetMinSize()) {
169 
170  // Convert hit map to TH2 histogram and blur it
171  auto const image = fBlurredClusteringAlg.ConvertRecobHitsToVector(hits, readoutWindowSize);
172  auto const blurred = fBlurredClusteringAlg.GaussianBlur(image);
173 
174  // Find clusters in histogram
175  std::vector<std::vector<int>>
176  allClusterBins; // Vector of clusters (clusters are vectors of hits)
177  int numClusters = fBlurredClusteringAlg.FindClusters(blurred, allClusterBins);
178  mf::LogVerbatim("Blurred Clustering") << "Found " << numClusters << " clusters" << std::endl;
179 
180  // Create output clusters from the vector of clusters made in FindClusters
181  std::vector<art::PtrVector<recob::Hit>> planeClusters;
182  fBlurredClusteringAlg.ConvertBinsToClusters(image, allClusterBins, planeClusters);
183 
184  // Use the cluster merging algorithm
185  if (fMergeClusters) {
186  int numMergedClusters = fMergeClusterAlg.MergeClusters(planeClusters, finalClusters);
187  mf::LogVerbatim("Blurred Clustering")
188  << "After merging, there are " << numMergedClusters << " clusters" << std::endl;
189  }
190  else
191  finalClusters = planeClusters;
192 
193  // Make the debug PDF
194  if (fCreateDebugPDF) {
195  std::stringstream name;
196  name << "blurred_image";
197  TH2F* imageHist = fBlurredClusteringAlg.MakeHistogram(image, TString{name.str()});
198  name << "_convolved";
199  TH2F* blurredHist = fBlurredClusteringAlg.MakeHistogram(blurred, TString{name.str()});
200  auto const [planeNo, tpc] = plane;
201  fBlurredClusteringAlg.SaveImage(imageHist, 1, tpc, planeNo);
202  fBlurredClusteringAlg.SaveImage(blurredHist, 2, tpc, planeNo);
203  fBlurredClusteringAlg.SaveImage(blurredHist, allClusterBins, 3, tpc, planeNo);
204  fBlurredClusteringAlg.SaveImage(imageHist, finalClusters, 4, tpc, planeNo);
205  imageHist->Delete();
206  blurredHist->Delete();
207  }
208 
209  } // End min hits check
210 
211  // Make the output cluster objects
212  for (auto const& clusterHits : finalClusters) {
213  if (clusterHits.empty()) continue;
214 
215  // Get the start and end wires of the cluster
216  unsigned int const startWire =
217  fBlurredClusteringAlg.GlobalWire(clusterHits.front()->WireID());
218  unsigned int const endWire = fBlurredClusteringAlg.GlobalWire(clusterHits.back()->WireID());
219 
220  // Put cluster hits in the algorithm
221  ClusterParamAlgo.ImportHits(gser, clusterHits);
222 
223  // Create the recob::Cluster and place in the vector of clusters
224  ClusterCreator cluster(gser,
225  ClusterParamAlgo, // algo
226  float(startWire), // start_wire
227  0., // sigma_start_wire
228  clusterHits.front()->PeakTime(), // start_tick
229  clusterHits.front()->SigmaPeakTime(), // sigma_start_tick
230  float(endWire), // end_wire
231  0., // sigma_end_wire,
232  clusterHits.back()->PeakTime(), // end_tick
233  clusterHits.back()->SigmaPeakTime(), // sigma_end_tick
234  clusters->size(), // ID
235  clusterHits.front()->View(), // view
236  clusterHits.front()->WireID().planeID(), // plane
237  recob::Cluster::Sentry // sentry
238  );
239  clusters->emplace_back(cluster.move());
240 
241  // Associate the hits to this cluster
242  util::CreateAssn(evt, *clusters, clusterHits, *associations);
243  } // End loop over all clusters
244  }
245 
246  evt.put(std::move(clusters));
247  evt.put(std::move(associations));
248 }
static QCString name
Definition: declinfo.cpp:673
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
EventNumber_t event() const
Definition: DataViewImpl.cc:85
TH2F * MakeHistogram(std::vector< std::vector< double >> const &image, TString name) const
Converts a 2D vector in a histogram for the debug pdf.
cluster::MergeClusterAlg fMergeClusterAlg
Cluster finding and building.
int FindClusters(std::vector< std::vector< double >> const &image, std::vector< std::vector< int >> &allcluster) const
Find clusters in the histogram.
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
bool isValid() const noexcept
Definition: Handle.h:191
int MergeClusters(std::vector< art::PtrVector< recob::Hit > > const &planeClusters, std::vector< art::PtrVector< recob::Hit > > &clusters) const
void CreateDebugPDF(int run, int subrun, int event)
Create the PDF to save debug images.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
std::vector< art::Ptr< recob::Hit > > SelectShowerHits(int event, const std::vector< art::Ptr< recob::Hit > > &hits, const std::vector< art::Ptr< recob::Track > > &tracks, const std::vector< art::Ptr< recob::SpacePoint > > &spacePoints, const art::FindManyP< recob::Hit > &fmht, const art::FindManyP< recob::Track > &fmth, const art::FindManyP< recob::SpacePoint > &fmspt, const art::FindManyP< recob::Track > &fmtsp) const
def move(depos, offset)
Definition: depos.py:107
int GlobalWire(geo::WireID const &wireID) const
Find the global wire position.
std::vector< std::vector< double > > GaussianBlur(std::vector< std::vector< double >> const &image) const
Applies Gaussian blur to image.
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
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.
void SaveImage(TH2F *image, std::vector< art::PtrVector< recob::Hit >> const &allClusters, int pad, int tpc, int plane)
RunNumber_t run() const
Definition: DataViewImpl.cc:71
shower::TrackShowerSeparationAlg fTrackShowerSeparationAlg
void ConvertBinsToClusters(std::vector< std::vector< double >> const &image, std::vector< std::vector< int >> const &allClusterBins, std::vector< art::PtrVector< recob::Hit >> &clusters) const
Takes a vector of clusters (itself a vector of hits) and turns them into clusters using the initial h...
std::vector< std::vector< double > > ConvertRecobHitsToVector(std::vector< art::Ptr< recob::Hit >> const &hits, int readoutWindowSize)
Takes hit map and returns a 2D vector representing wire and tick, filled with the charge...
cluster::BlurredClusteringAlg fBlurredClusteringAlg
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
unsigned int GetMinSize() const noexcept
Minimum size of cluster to save.
QTextStream & endl(QTextStream &s)

Member Data Documentation

cluster::BlurredClusteringAlg cluster::BlurredClustering::fBlurredClusteringAlg
private

Definition at line 63 of file BlurredClustering_module.cc.

bool const cluster::BlurredClustering::fCreateDebugPDF
private

Definition at line 60 of file BlurredClustering_module.cc.

bool const cluster::BlurredClustering::fGlobalTPCRecon
private

Definition at line 60 of file BlurredClustering_module.cc.

std::string const cluster::BlurredClustering::fHitsModuleLabel
private

Definition at line 59 of file BlurredClustering_module.cc.

cluster::MergeClusterAlg cluster::BlurredClustering::fMergeClusterAlg
private

Definition at line 64 of file BlurredClustering_module.cc.

bool const cluster::BlurredClustering::fMergeClusters
private

Definition at line 60 of file BlurredClustering_module.cc.

std::string const cluster::BlurredClustering::fPFParticleModuleLabel
private

Definition at line 59 of file BlurredClustering_module.cc.

bool const cluster::BlurredClustering::fShowerReconOnly
private

Definition at line 60 of file BlurredClustering_module.cc.

std::string const cluster::BlurredClustering::fTrackModuleLabel
private

Definition at line 59 of file BlurredClustering_module.cc.

shower::TrackShowerSeparationAlg cluster::BlurredClustering::fTrackShowerSeparationAlg
private

Definition at line 65 of file BlurredClustering_module.cc.

std::string const cluster::BlurredClustering::fVertexModuleLabel
private

Definition at line 59 of file BlurredClustering_module.cc.


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