All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TTSpacePointFinder_module.cc
Go to the documentation of this file.
1 /*!
2  * Title: TTSpacePointFinder class
3  * Author: wketchum@lanl.gov
4  * Inputs: recob::Hit
5  * Outputs: recob::SpacePoint
6  *
7  * Description:
8  * This module, TimeTickSpacePointFinder (or TTSpacePointFinder for short) was
9  * originally designed to produce a spacepoint object based on hits from
10  * TTHitFinder, with the intention to allow for a significant number of
11  * ghost spacepoints, where some downstream application would deal with the
12  * results.
13  *
14  * In reality, it is just a generic SpacePointFinder implementing the
15  * SpacePointAlg_TimeSort algorithm.
16  *
17  * This code is totally microboone specific, btw.
18  */
19 
20 #include <string>
21 
22 // Framework includes
23 #include "art/Framework/Core/EDProducer.h"
24 #include "art/Framework/Core/ModuleMacros.h"
25 #include "art/Framework/Principal/Event.h"
26 #include "art/Framework/Services/Registry/ServiceHandle.h"
27 
28 // LArSoft Includes
35 
36 namespace sppt {
37 
38  class TTSpacePointFinder : public art::EDProducer {
39  public:
40  explicit TTSpacePointFinder(fhicl::ParameterSet const& pset);
41 
42  private:
43  void produce(art::Event& evt);
44  void beginRun(art::Run& run);
45 
46  std::string fHitModuleLabel; /// Input hit module name
47  std::string fUHitsInstanceLabel; /// Input U hits instance name
48  std::string fVHitsInstanceLabel; /// Input V hits instance name
49  std::string fYHitsInstanceLabel; /// Input Y hits instance name
50 
52  }; // class TTSpacePointFinder
53 
54  //-------------------------------------------------
55  TTSpacePointFinder::TTSpacePointFinder(fhicl::ParameterSet const& pset)
56  : EDProducer{pset}, fSpptAlg(pset.get<fhicl::ParameterSet>("SpacePointAlgParams"))
57  {
58  fHitModuleLabel = pset.get<std::string>("HitModuleLabel", "tthit");
59  fUHitsInstanceLabel = pset.get<std::string>("UHitsInstaceLabel", "uhits");
60  fVHitsInstanceLabel = pset.get<std::string>("VHitsInstaceLabel", "vhits");
61  fYHitsInstanceLabel = pset.get<std::string>("YHitsInstaceLabel", "yhits");
62 
63  produces<std::vector<recob::SpacePoint>>();
64  produces<art::Assns<recob::SpacePoint, recob::Hit>>();
65  }
66 
67  //-------------------------------------------------
68  void
70  {
71  auto const detProp =
72  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
75  }
76 
77  //-------------------------------------------------
78  void
80  {
81  //initialize our spacepoint collection
82  auto spptCollection = std::make_unique<std::vector<recob::SpacePoint>>();
83  auto spptAssociatedHits = std::make_unique<std::vector<std::vector<art::Ptr<recob::Hit>>>>();
84 
85  // Read in the hits. Note, we will reorder hit vector, so we do in fact need a copy.
86  art::Handle<std::vector<recob::Hit>> hitHandle_U;
87  evt.getByLabel(fHitModuleLabel, fUHitsInstanceLabel, hitHandle_U);
88  std::vector<art::Ptr<recob::Hit>> hitVec_U;
89  art::fill_ptr_vector(hitVec_U, hitHandle_U);
90 
91  art::Handle<std::vector<recob::Hit>> hitHandle_V;
92  evt.getByLabel(fHitModuleLabel, fVHitsInstanceLabel, hitHandle_V);
93  std::vector<art::Ptr<recob::Hit>> hitVec_V;
94  art::fill_ptr_vector(hitVec_V, hitHandle_V);
95 
96  art::Handle<std::vector<recob::Hit>> hitHandle_Y;
97  evt.getByLabel(fHitModuleLabel, fYHitsInstanceLabel, hitHandle_Y);
98  std::vector<art::Ptr<recob::Hit>> hitVec_Y;
99  art::fill_ptr_vector(hitVec_Y, hitHandle_Y);
100 
101  MF_LOG_DEBUG("TTSpacePointFinder") << "Got handles to hits:\n"
102  << hitVec_U.size() << " u hits, " << hitVec_V.size()
103  << " v hits, " << hitVec_Y.size() << " y hits.";
104 
105  auto const detProp =
106  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt);
108  detProp, hitVec_U, hitVec_V, hitVec_Y, spptCollection, spptAssociatedHits);
109 
110  mf::LogInfo("TTSpacePointFinder")
111  << "Finished spacepoint alg. Created " << spptCollection->size() << " spacepoints.";
112 
113  //check that spptCollection and spptAssociatedHits have same size
114  if (spptCollection->size() != spptAssociatedHits->size()) {
115  mf::LogError("TTSpacePointFinder")
116  << "ERROR in space point alg.\n"
117  << "Spacepoint and associated hit collections have different sizes!\n"
118  << spptCollection->size() << " != " << spptAssociatedHits->size()
119  << "\nWill return with no space points put on event.";
120  return;
121  }
122 
123  //Now, need to fill in the sppt<-->hit associations
124  std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> spptAssns(
125  new art::Assns<recob::SpacePoint, recob::Hit>);
126  for (unsigned int isppt = 0; isppt < spptCollection->size(); isppt++) {
127  util::CreateAssn(evt, *spptCollection, spptAssociatedHits->at(isppt), *spptAssns, isppt);
128  }
129 
130  //finally, put things on the event
131  evt.put(std::move(spptCollection));
132  evt.put(std::move(spptAssns));
133 
134  } // End of produce()
135 
136  DEFINE_ART_MODULE(TTSpacePointFinder)
137 
138 } // end of sppt namespace
void setTimeOffsets(detinfo::DetectorPropertiesData const &detProp)
Declaration of signal hit object.
std::string fYHitsInstanceLabel
Input V hits instance name.
std::string fVHitsInstanceLabel
Input U hits instance name.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
std::string fUHitsInstanceLabel
Input hit module name.
void createSpacePoints(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &hitVec_U, std::vector< art::Ptr< recob::Hit >> &hitVec_V, std::vector< art::Ptr< recob::Hit >> &hitVec_Y, std::unique_ptr< std::vector< recob::SpacePoint >> &spptCollection, std::unique_ptr< std::vector< std::vector< art::Ptr< recob::Hit >>>> &spptAssociatedHits)
SpacePointAlg_TimeSort fSpptAlg
Input Y hits instance name.
TCEvent evt
Definition: DataStructs.cxx:8
TTSpacePointFinder(fhicl::ParameterSet const &pset)
auto const detProp