LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TCTrack_module.cc
Go to the documentation of this file.
1 
10 // C/C++ standard libraries
11 #include <string>
12 #include <utility> // std::unique_ptr<>
13 
14 // Framework libraries
15 #include "fhiclcpp/ParameterSet.h"
21 
22 //LArSoft includes
32 
33 // ... more includes in the implementation section
34 
35 namespace trkf {
36 
37  class TCTrack: public art::EDProducer {
38 
39  public:
40  explicit TCTrack(fhicl::ParameterSet const & pset);
41  virtual ~TCTrack() = default;
42 
43  void reconfigure(fhicl::ParameterSet const & pset) ;
44  void produce(art::Event & evt) override;
45  void endJob() override;
46 
47  private:
48 
50 
51  std::string fPFPModuleLabel;
52 // std::string fHitModuleLabel;
53 
54 
55  }; // class TCTrack
56 
57  //----------------------------------------------------------------------------
59  {
60 // fHitModuleLabel = pset.get< std::string >("HitModuleLabel");
61  fPFPModuleLabel = pset.get< std::string >("PFPModuleLabel");
62 
63  fSptalg.reconfigure(pset.get<fhicl::ParameterSet>("SpacePointAlg"));
64 
65  }
66 
67  //----------------------------------------------------------------------------
69  : fSptalg(pset.get<fhicl::ParameterSet>("SpacePointAlg"))
70  {
71 
72  reconfigure(pset);
73 
74  produces<std::vector<recob::SpacePoint> >();
75  produces<art::Assns<recob::SpacePoint, recob::Hit> >();
76 
77  } // TCTrack::TCTrack()
78 
79  //----------------------------------------------------------------------------
81  {
82  } // endJob
83 
84  //----------------------------------------------------------------------------
86  {
87 
88  // all data products are assumed to be produced by the same module that produced the PFParticles -> TrajCluster_module
89  art::InputTag DataInputTag(fPFPModuleLabel);
90  art::ValidHandle<std::vector<recob::PFParticle>> pfpHandle = evt.getValidHandle<std::vector<recob::PFParticle>>(DataInputTag);
91 
92  art::ValidHandle<std::vector<recob::Cluster>> clsHandle = evt.getValidHandle<std::vector<recob::Cluster>>(DataInputTag);
93 
94  art::FindManyP<recob::Cluster> pfp_cls(pfpHandle, evt, fPFPModuleLabel);
95  art::FindManyP<recob::Hit> cls_hit(clsHandle, evt, fPFPModuleLabel);
96 
97  std::unique_ptr< art::Assns<recob::SpacePoint, recob::Hit> > sphitassn(new art::Assns<recob::SpacePoint, recob::Hit>);
98  std::unique_ptr<std::vector<recob::SpacePoint> > spts(new std::vector<recob::SpacePoint>);
99 
101  for(unsigned short ipfp = 0; ipfp < pfpHandle->size(); ++ipfp) {
102  // Get the clusters associated with this PFParticle - there should be one in each plane
103  std::vector<art::Ptr<recob::Cluster> > clsList;
104  pfp_cls.get(ipfp, clsList);
105  hits.clear();
106  std::cout<<"PFP "<<ipfp<<"\n";
107  for(unsigned short icl = 0; icl < clsList.size(); ++icl) {
108  std::vector<art::Ptr<recob::Hit> > hitList;
109  unsigned int clsIndex = clsList[icl]->ID() - 1;
110  cls_hit.get(clsIndex, hitList);
111  std::cout<<" cls index "<<clsIndex<<" hits size "<<hitList.size()<<" "<<(int)clsList[icl]->StartWire()<<":"<<(int)clsList[icl]->StartTick()<<" EndWire "<<(int)clsList[icl]->EndWire()<<":"<<(int)clsList[icl]->EndTick()<<"\n";
112  hits.reserve(hits.size() + hitList.size());
113  for(std::vector< art::Ptr<recob::Hit> >::const_iterator i = hitList.begin(); i != hitList.end(); ++i) hits.push_back(*i);
114  } // icl
115  // make new space points using these hits
116  std::vector<recob::SpacePoint> new_spts;
117  fSptalg.makeSpacePoints(hits, new_spts);
118  if(new_spts.empty()) continue;
119 /*
120  if(ipfp == 0) {
121  std::cout<<"new_spts size "<<new_spts.size()<<"\n";
122  for(auto& spt : new_spts) {
123  std::cout<<" "<<spt<<"\n";
124  } // spt
125  std::cout<<"\n";
126  } // ipfp == 0
127 */
128  int nspt = spts->size();
129  spts->insert(spts->end(), new_spts.begin(), new_spts.end());
130  // associate the hits with the spacepoints
132  for(unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
133  const recob::SpacePoint& spt = (*spts)[ispt];
135  util::CreateAssn(*this, evt, *spts, hits, *sphitassn, ispt);
136  } // ispt
137  } // ipfp
138 
139  evt.put(std::move(spts));
140  evt.put(std::move(sphitassn));
141 
142  } // TCTrack::produce()
143 
145 
146 } // namespace trkf
147 
148 
void reserve(size_type n)
Definition: PtrVector.h:343
void produce(art::Event &evt) override
SpacePointAlg fSptalg
Declaration of signal hit object.
const art::PtrVector< recob::Hit > & getAssociatedHits(const recob::SpacePoint &spt) const
void reconfigure(fhicl::ParameterSet const &pset)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Provides recob::Track data product.
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
parameter set interface
T get(std::string const &key) const
Definition: ParameterSet.h:231
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.
Declaration of cluster object.
size_type size() const
Definition: PtrVector.h:308
void reconfigure(const fhicl::ParameterSet &pset)
void makeSpacePoints(const art::PtrVector< recob::Hit > &hits, std::vector< recob::SpacePoint > &spts) const
Utility object to perform functions of association.
void endJob() override
size_type get(size_type i, reference item, data_reference data) const
Definition: FindManyP.h:469
TCEvent evt
Definition: DataStructs.cxx:5
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
std::string fPFPModuleLabel
Algorithm for generating space points from hits.
void clear()
Definition: PtrVector.h:537
virtual ~TCTrack()=default
TCTrack(fhicl::ParameterSet const &pset)