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

Public Member Functions

 CaloClustering (fhicl::ParameterSet const &p)
 
 CaloClustering (CaloClustering const &)=delete
 
 CaloClustering (CaloClustering &&)=delete
 
CaloClusteringoperator= (CaloClustering const &)=delete
 
CaloClusteringoperator= (CaloClustering &&)=delete
 
void produce (art::Event &e) override
 
- 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 CollectTracks (const art::Event &evt, const std::string &label, std::vector< art::Ptr< gar::rec::Track > > &trkVector)
 
void CollectHits (const art::Event &evt, const std::string &label, const std::string &instance, std::vector< art::Ptr< gar::rec::CaloHit > > &hitVector)
 

Private Attributes

std::string fTrackLabel
 label to find the reco tracks More...
 
std::string fCaloHitLabel
 label to find the right reco calo hits More...
 
std::string fInstanceName
 product instance name More...
 
const detinfo::DetectorPropertiesfDetProp
 detector properties More...
 
const geo::GeometryCorefGeo
 pointer to the geometry More...
 
std::unique_ptr< rec::alg::KNNClusterAlgfClusterAlgo
 

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 41 of file CaloClustering_module.cc.

Constructor & Destructor Documentation

gar::rec::CaloClustering::CaloClustering ( fhicl::ParameterSet const &  p)
explicit

Definition at line 73 of file CaloClustering_module.cc.

73  : EDProducer{p}
74  {
75  fTrackLabel = p.get<std::string>("TrackLabel", "track");
76  fCaloHitLabel = p.get<std::string>("CaloHitLabel", "calohit");
77  fInstanceName = p.get<std::string >("InstanceLabelName", "");
78 
79  fGeo = gar::providerFrom<geo::GeometryGAr>();
80  fDetProp = gar::providerFrom<detinfo::DetectorPropertiesService>();
81 
82  //configure the cluster algorithm
83  auto fClusterAlgoPars = p.get<fhicl::ParameterSet>("ClusterAlgPars");
84  fClusterAlgo = std::make_unique<rec::alg::KNNClusterAlg>(fClusterAlgoPars);
85 
86  art::InputTag tag(fCaloHitLabel, fInstanceName);
87  consumes<std::vector<gar::rec::CaloHit>>(tag);
88  produces< std::vector<gar::rec::Cluster> >(fInstanceName);
89  produces< art::Assns<gar::rec::Cluster, gar::rec::CaloHit> >(fInstanceName);
90  if (fClusterAlgo->usesTracks()) produces< art::Assns<gar::rec::Cluster, gar::rec::Track> >(fInstanceName);
91  }
std::string fTrackLabel
label to find the reco tracks
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
p
Definition: test.py:223
std::string fCaloHitLabel
label to find the right reco calo hits
std::string fInstanceName
product instance name
const geo::GeometryCore * fGeo
pointer to the geometry
const detinfo::DetectorProperties * fDetProp
detector properties
std::unique_ptr< rec::alg::KNNClusterAlg > fClusterAlgo
gar::rec::CaloClustering::CaloClustering ( CaloClustering const &  )
delete
gar::rec::CaloClustering::CaloClustering ( CaloClustering &&  )
delete

Member Function Documentation

void gar::rec::CaloClustering::CollectHits ( const art::Event evt,
const std::string label,
const std::string instance,
std::vector< art::Ptr< gar::rec::CaloHit > > &  hitVector 
)
private

Definition at line 175 of file CaloClustering_module.cc.

176  {
178  auto theHits = evt.getHandle< std::vector<gar::rec::CaloHit> >(itag);
179  if (!theHits) return;
180 
181  for (unsigned int i = 0; i < theHits->size(); ++i)
182  {
183  const art::Ptr<gar::rec::CaloHit> hit(theHits, i);
184  hitVector.push_back(hit);
185  }
186  }
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
const std::string instance
Detector simulation of raw signals on wires.
void gar::rec::CaloClustering::CollectTracks ( const art::Event evt,
const std::string label,
std::vector< art::Ptr< gar::rec::Track > > &  trkVector 
)
private

Definition at line 188 of file CaloClustering_module.cc.

189  {
190  auto theTracks = evt.getHandle< std::vector<gar::rec::Track> >(label);
191  if (!theTracks) return;
192 
193  for (unsigned int i = 0; i < theTracks->size(); ++i)
194  {
195  const art::Ptr<gar::rec::Track> track(theTracks, i);
196  trkVector.push_back(track);
197  }
198  }
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
CaloClustering& gar::rec::CaloClustering::operator= ( CaloClustering const &  )
delete
CaloClustering& gar::rec::CaloClustering::operator= ( CaloClustering &&  )
delete
void gar::rec::CaloClustering::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 93 of file CaloClustering_module.cc.

94  {
95  //maps of the hit/track pointer to art ptr pointers
96  std::unordered_map< const gar::rec::CaloHit*, art::Ptr<gar::rec::CaloHit> > hitMaptoArtPtr;
97  std::unordered_map< const gar::rec::Track*, art::Ptr<gar::rec::Track> > trkMaptoArtPtr;
98 
99  //Collect the tracks to be passed to the algo. As of Jun 2019, the algo doesn't need tracks.
100  //But maybe someday it will!
101  std::vector< art::Ptr<gar::rec::Track> > artTrk;
102  if (fClusterAlgo->usesTracks())
103  this->CollectTracks(e, fTrackLabel, artTrk);
104 
105  //Collect the hits to be passed to the algo
106  std::vector< art::Ptr<gar::rec::CaloHit> > artHits;
107  this->CollectHits(e, fCaloHitLabel, fInstanceName, artHits);
108 
109  //Prepare the hits for clustering (tag isolated hits and possible mip hits)
110  //artTrk and trkMaptoArtPtr will be empty if ( !fClusterAlgo->usesTracks() )
111  fClusterAlgo->PrepareAlgo(artTrk, artHits, trkMaptoArtPtr, hitMaptoArtPtr);
112  //Perform the clustering
113  fClusterAlgo->DoClustering();
114  //Get back the cluster results
115  std::vector< gar::rec::Cluster* > ClusterVec = fClusterAlgo->GetFoundClusters();
116 
117  // make an art::PtrVector of the clusters
118  std::unique_ptr< std::vector<gar::rec::Cluster> > ClusterCol(new std::vector<gar::rec::Cluster>);
119  std::unique_ptr< art::Assns<gar::rec::Cluster, gar::rec::CaloHit> > ClusterHitAssns(new art::Assns<gar::rec::Cluster, gar::rec::CaloHit>);
120  std::unique_ptr< art::Assns<gar::rec::Cluster, gar::rec::Track> > ClusterTrackAssns(new art::Assns<gar::rec::Cluster, gar::rec::Track>);
121 
123 
124  MF_LOG_DEBUG("CaloClustering_module")
125  << "Found " << ClusterVec.size() << " Clusters";
126 
127  //Copy the clusters to the collection
128  for(auto const &it : ClusterVec)
129  {
130  MF_LOG_DEBUG("CaloClustering_module")
131  << "Cluster has " << it->CalorimeterHits().size() << " calo hits";
132 
133  ClusterCol->emplace_back(*it);
134 
135  art::Ptr<gar::rec::Cluster> clusterPtr = makeClusterPtr(ClusterCol->size() - 1);
136 
137  //get list of hits associated to the cluster
138  const std::vector< gar::rec::CaloHit* > hitVec = it->CalorimeterHits();
139  for (size_t i=0; i<hitVec.size(); ++i)
140  {
141  const gar::rec::CaloHit* pCaloHit = hitVec[i];
142  //Need to find the corresponding art ptr in the map
143  if(hitMaptoArtPtr.find(pCaloHit) != hitMaptoArtPtr.end())
144  {
145  // associate the hits to this cluster
146  art::Ptr<gar::rec::CaloHit> hitpointer = hitMaptoArtPtr[pCaloHit];
147  ClusterHitAssns->addSingle(clusterPtr, hitpointer);
148  }
149  }
150 
151  if (fClusterAlgo->usesTracks()) {
152  //get list of track associated to the cluster
153  const std::vector< gar::rec::Track* > trkVec = it->Tracks();
154  for(const gar::rec::Track *const pTrack : trkVec)
155  {
156  //Need to find the corresponding art ptr in the map
157  if(trkMaptoArtPtr.find(pTrack) != trkMaptoArtPtr.end())
158  {
159  // associate the hits to this cluster
160  art::Ptr<gar::rec::Track> trkpointer = trkMaptoArtPtr[pTrack];
161  ClusterTrackAssns->addSingle(clusterPtr, trkpointer);
162  }
163  }
164  }
165  }
166 
167  e.put(std::move(ClusterCol), fInstanceName);
168  e.put(std::move(ClusterHitAssns), fInstanceName);
169  if (fClusterAlgo->usesTracks())
170  e.put(std::move(ClusterTrackAssns), fInstanceName);
171 
172  return;
173  }
std::string fTrackLabel
label to find the reco tracks
void CollectTracks(const art::Event &evt, const std::string &label, std::vector< art::Ptr< gar::rec::Track > > &trkVector)
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
std::string fCaloHitLabel
label to find the right reco calo hits
std::string fInstanceName
product instance name
void CollectHits(const art::Event &evt, const std::string &label, const std::string &instance, std::vector< art::Ptr< gar::rec::CaloHit > > &hitVector)
#define MF_LOG_DEBUG(id)
std::vector< gar::rec::Cluster * > ClusterVec
Definition: KNNClusterAlg.h:38
std::unique_ptr< rec::alg::KNNClusterAlg > fClusterAlgo
Definition: fwd.h:31

Member Data Documentation

std::string gar::rec::CaloClustering::fCaloHitLabel
private

label to find the right reco calo hits

Definition at line 63 of file CaloClustering_module.cc.

std::unique_ptr<rec::alg::KNNClusterAlg> gar::rec::CaloClustering::fClusterAlgo
private

Definition at line 69 of file CaloClustering_module.cc.

const detinfo::DetectorProperties* gar::rec::CaloClustering::fDetProp
private

detector properties

Definition at line 66 of file CaloClustering_module.cc.

const geo::GeometryCore* gar::rec::CaloClustering::fGeo
private

pointer to the geometry

Definition at line 67 of file CaloClustering_module.cc.

std::string gar::rec::CaloClustering::fInstanceName
private

product instance name

Definition at line 64 of file CaloClustering_module.cc.

std::string gar::rec::CaloClustering::fTrackLabel
private

label to find the reco tracks

Definition at line 62 of file CaloClustering_module.cc.


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