All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TCTrack_module.cc
Go to the documentation of this file.
1 /**
2  * @file TCTrack_module.cc
3  * @brief Create seeds, spacepoints and tracks from 3D matched clusters produced by TrajCluster_module
4  * @author Bruce Baller (baller@fnal.gov)
5  */
6 
7 // C/C++ standard libraries
8 #include <string>
9 
10 // Framework libraries
11 #include "art/Framework/Core/EDProducer.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "canvas/Persistency/Common/FindManyP.h"
15 #include "canvas/Utilities/InputTag.h"
16 #include "fhiclcpp/ParameterSet.h"
17 
18 // LArSoft includes
27 
28 // ... more includes in the implementation section
29 
30 namespace trkf {
31 
32  class TCTrack : public art::EDProducer {
33 
34  public:
35  explicit TCTrack(fhicl::ParameterSet const& pset);
36 
37  private:
38  void produce(art::Event& evt) override;
39 
41 
42  art::InputTag fPFPtag;
43  }; // class TCTrack
44 
45  //----------------------------------------------------------------------------
46  TCTrack::TCTrack(fhicl::ParameterSet const& pset)
47  : EDProducer{pset}
48  , fSptalg{pset.get<fhicl::ParameterSet>("SpacePointAlg")}
49  , fPFPtag{pset.get<std::string>("PFPModuleLabel")}
50  {
51  produces<std::vector<recob::SpacePoint>>();
52  produces<art::Assns<recob::SpacePoint, recob::Hit>>();
53  }
54 
55  //----------------------------------------------------------------------------
56  void
57  TCTrack::produce(art::Event& evt)
58  {
59  // all data products are assumed to be produced by the same module that produced the PFParticles -> TrajCluster_module
60  auto pfpHandle = evt.getValidHandle<std::vector<recob::PFParticle>>(fPFPtag);
61  auto clsHandle = evt.getValidHandle<std::vector<recob::Cluster>>(fPFPtag);
62 
63  art::FindManyP<recob::Cluster> pfp_cls(pfpHandle, evt, fPFPtag);
64  art::FindManyP<recob::Hit> cls_hit(clsHandle, evt, fPFPtag);
65 
66  auto sphitassn = std::make_unique<art::Assns<recob::SpacePoint, recob::Hit>>();
67  auto spts = std::make_unique<std::vector<recob::SpacePoint>>();
68 
69  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
70  auto const detProp =
71  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
72 
73  art::PtrVector<recob::Hit> hits;
74  for (unsigned short ipfp = 0; ipfp < pfpHandle->size(); ++ipfp) {
75  // Get the clusters associated with this PFParticle - there should be one in each plane
76  std::vector<art::Ptr<recob::Cluster>> clsList;
77  pfp_cls.get(ipfp, clsList);
78  hits.clear();
79  std::cout << "PFP " << ipfp << "\n";
80  for (unsigned short icl = 0; icl < clsList.size(); ++icl) {
81  std::vector<art::Ptr<recob::Hit>> hitList;
82  unsigned int clsIndex = clsList[icl]->ID() - 1;
83  cls_hit.get(clsIndex, hitList);
84  std::cout << " cls index " << clsIndex << " hits size " << hitList.size() << " "
85  << (int)clsList[icl]->StartWire() << ":" << (int)clsList[icl]->StartTick()
86  << " EndWire " << (int)clsList[icl]->EndWire() << ":"
87  << (int)clsList[icl]->EndTick() << "\n";
88  hits.reserve(hits.size() + hitList.size());
89  hits.insert(hits.end(), hitList.begin(), hitList.end());
90  } // icl
91  // make new space points using these hits
92  std::vector<recob::SpacePoint> new_spts;
93  fSptalg.makeSpacePoints(clockData, detProp, hits, new_spts);
94  if (new_spts.empty()) continue;
95 
96  int nspt = spts->size();
97  spts->insert(spts->end(), new_spts.begin(), new_spts.end());
98  // associate the hits with the spacepoints
99  art::PtrVector<recob::SpacePoint> sptvec;
100  for (unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
101  const recob::SpacePoint& spt = (*spts)[ispt];
102  const art::PtrVector<recob::Hit>& hits = fSptalg.getAssociatedHits(spt);
103  util::CreateAssn(evt, *spts, hits, *sphitassn, ispt);
104  } // ispt
105  } // ipfp
106 
107  evt.put(std::move(spts));
108  evt.put(std::move(sphitassn));
109 
110  } // TCTrack::produce()
111 
112  DEFINE_ART_MODULE(TCTrack)
113 
114 } // namespace trkf
void produce(art::Event &evt) override
SpacePointAlg fSptalg
Declaration of signal hit object.
BEGIN_PROLOG StartTick
const art::PtrVector< recob::Hit > & getAssociatedHits(const recob::SpacePoint &spt) const
void makeSpacePoints(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const art::PtrVector< recob::Hit > &hits, std::vector< recob::SpacePoint > &spts) const
Declaration of cluster object.
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.
art::InputTag fPFPtag
TCEvent evt
Definition: DataStructs.cxx:8
Algorithm for generating space points from hits.
TCTrack(fhicl::ParameterSet const &pset)
BEGIN_PROLOG could also be cout
auto const detProp