16 #include "art/Framework/Principal/Event.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "art/Framework/Principal/Handle.h"
19 #include "canvas/Persistency/Common/Ptr.h"
20 #include "canvas/Persistency/Common/PtrVector.h"
21 #include "art/Framework/Services/Registry/ServiceHandle.h"
22 #include "messagefacility/MessageLogger/MessageLogger.h"
32 #include "art/Framework/Core/ModuleMacros.h"
33 #include "art/Framework/Core/EDProducer.h"
34 #include "canvas/Persistency/Common/FindManyP.h"
65 fStitchAlg(pset.get< fhicl::ParameterSet >(
"StitchAlg"))
67 fTrackModuleLabel = pset.get< std::string >(
"TrackModuleLabel");
68 fSpptModuleLabel = pset.get< std::string >(
"SpptModuleLabel");
69 fStizatch = pset.get<
bool > (
"CommonComponentStitch",
true);
71 produces< std::vector<recob::Track> >();
72 produces<std::vector<art::PtrVector<recob::Track> > >();
73 produces<art::Assns<recob::Track, recob::Hit> >();
74 produces<art::Assns<recob::Track, recob::SpacePoint> >();
75 produces<art::Assns<recob::SpacePoint, recob::Hit> >();
84 art::ServiceHandle<geo::Geometry const> geom;
90 std::unique_ptr<std::vector<recob::Track> > tcol(
new std::vector<recob::Track>);
91 std::unique_ptr<art::PtrVector<recob::SpacePoint> > scol(
new art::PtrVector<recob::SpacePoint>);
93 std::unique_ptr<std::vector< art::PtrVector<recob::Track> > > tvcol(
new std::vector< art::PtrVector<recob::Track> >);
94 std::unique_ptr< art::Assns<recob::Track, recob::Hit> > thassn(
new art::Assns<recob::Track, recob::Hit>);
95 std::unique_ptr< art::Assns<recob::Track, recob::SpacePoint> > tsptassn(
new art::Assns<recob::Track, recob::SpacePoint>);
96 std::unique_ptr< art::Assns<recob::SpacePoint, recob::Hit > > spthassn(
new art::Assns<recob::SpacePoint, recob::Hit>);
102 art::Handle< std::vector < recob::SpacePoint > > sppth;
105 mf::LogWarning(
"TrackStitcher") <<
"Trying to read Track3DKalmanXYZ-style PtrVector of std::vector of SpacePoints" << std::endl;
106 art::Handle< std::vector < art::PtrVector <recob::SpacePoint> > > sppth;
108 for (
size_t ii=0; ii<sppth->size() ;ii++)
109 for (
size_t jj=0; jj<sppth->at(ii).size() ;ii++)
111 art::Ptr<recob::SpacePoint> sptmp(sppth->at(ii).at(jj));
112 scol->push_back(sptmp );
117 mf::LogWarning(
"TrackStitcher") <<
"Trying instead to read CosmicTracker-style already-flattened vector of SpacePoints" << std::endl;
118 art::Handle< std::vector < recob::SpacePoint > > sppthf;
120 for (
size_t ii=0; ii<sppthf->size() ;ii++)
122 art::Ptr<recob::SpacePoint> sptmpf(sppthf,ii);
123 scol->push_back(sptmpf);
139 mf::LogVerbatim(
"TrackStitcher.beginning") <<
"There are " <<
fStitchAlg.
ftListHandle->size() <<
" Tracks in this event before stitching.";
144 if (tcol->size()!=tvcol->size())
145 throw cet::exception(
"TrackStitcher") <<
"Tracks and TrackComposites do not match: "<<tcol->size()<<
" vs "<<tvcol->size()<<
"\n";
147 std::vector<size_t> spIndices(scol->size());
149 for (
size_t ii=0; ii<scol->size(); ii++ )
152 for (
size_t ii=0; ii<tvcol->size(); ii++)
164 std::vector<std::pair<std::vector<art::Ptr<recob::Hit> >::const_iterator, std::vector<art::Ptr<recob::Hit> >::const_iterator > > pits;
166 std::vector<art::Ptr<recob::Hit>> hitsFromSppts;
169 size_t start(0), finish(0);
170 for (
unsigned int ii=0; ii < sppts.size(); ++ii )
172 hitsFromSppts.insert(hitsFromSppts.end(),hitAssns.at(ii).begin(), hitAssns.at(ii).end());
173 finish = start+(size_t)(hitAssns.at(ii).end() - hitAssns.at(ii).begin());
174 std::pair< std::vector<art::Ptr<recob::Hit> >::const_iterator, std::vector<art::Ptr<recob::Hit> >::const_iterator > pithittmp(hitAssns.at(ii).begin(),hitAssns.at(ii).end());
175 pits.push_back(pithittmp);
180 for (
size_t jj=0; jj<sppts.size(); jj++ )
183 size_t ll(scol->size());
187 for (
auto& kk : spIndices )
189 const art::Ptr<recob::SpacePoint> spptnc(scol->at(kk));
190 if ( spptnc != sppts.at(jj)) { off++;
continue;}
199 std::vector <art::Ptr <recob::Hit> > hitsThisSppt;
200 hitsThisSppt.insert(hitsThisSppt.begin(),pits.at(jj).first,pits.at(jj).second);
207 mf::LogVerbatim(
"TrackStitcher.end") <<
"There are " << tvcol->size() <<
" Tracks in this event after stitching.";
208 evt.put(std::move(tcol));
209 evt.put(std::move(tvcol));
211 evt.put(std::move(thassn));
212 evt.put(std::move(tsptassn));
213 evt.put(std::move(spthassn));
220 art::PtrVector<recob::Hit> hits;
223 for (
unsigned int ii=0; ii < tcomp.size(); ++ii )
225 hits.insert(hits.end(),hitAssns.at(ii).begin(), hitAssns.at(ii).end());
236 art::PtrVector<recob::SpacePoint> sppts;
238 for (
unsigned int ii=0; ii < tcomp.size(); ++ii )
240 sppts.insert(sppts.end(),spptAssns.at(ii).begin(), spptAssns.at(ii).end());
250 std::vector<art::Ptr<recob::Hit>> hits;
253 size_t start(0), finish(0);
254 for (
unsigned int ii=0; ii < sppts.size(); ++ii )
256 hits.insert(hits.end(),hitAssns.at(ii).begin(), hitAssns.at(ii).end());
257 finish = start+(size_t)(hitAssns.at(ii).end() - hitAssns.at(ii).begin());
258 std::pair< std::vector<art::Ptr<recob::Hit> >::const_iterator, std::vector<art::Ptr<recob::Hit> >::const_iterator > pithittmp(hitAssns.at(ii).begin(),hitAssns.at(ii).end());
259 pithit.push_back(pithittmp);
std::vector< art::Ptr< recob::Hit > > GetHitsFromAssdSpacePoints(const art::PtrVector< recob::SpacePoint > &, const art::Event &evt, std::vector< std::pair< std::vector< art::Ptr< recob::Hit > >::const_iterator, std::vector< art::Ptr< recob::Hit > >::const_iterator > > &vpi)
void GetTracks(std::vector< recob::Track > &t) const
art::Handle< std::vector< recob::Track > > ftListHandle
void FindHeadsAndTails(const art::Event &e, const std::string &t)
bool CommonComponentStitch()
Declaration of signal hit object.
art::PtrVector< recob::Hit > GetHitsFromComponentTracks(const art::PtrVector< recob::Track > &, const art::Event &evt)
void GetTrackComposites(std::vector< art::PtrVector< recob::Track > > &c) const
std::size_t size(FixedBins< T, C > const &) noexcept
TrackStitcher(fhicl::ParameterSet const &pset)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::string fSpptModuleLabel
Provides recob::Track data product.
std::string fTrackModuleLabel
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::PtrVector< recob::SpacePoint > GetSpacePointsFromComponentTracks(const art::PtrVector< recob::Track > &, const art::Event &evt)
art framework interface to geometry description
void produce(art::Event &evt) override