191 std::unique_ptr<std::vector<sbn::PCAnglePlane>> outAngles(
new std::vector<sbn::PCAnglePlane>);
192 std::unique_ptr<art::Assns<recob::PFParticle, sbn::PCAnglePlane>> assn(
new art::Assns<recob::PFParticle, sbn::PCAnglePlane>);
194 art::PtrMaker<sbn::PCAnglePlane> anglePtrMaker {
evt};
198 auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(
evt);
200 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(
evt, clock_data);
204 art::Handle<std::vector<recob::PFParticle>> pfparticle_handle;
207 std::vector<art::Ptr<recob::PFParticle>> pfparticles;
208 art::fill_ptr_vector(pfparticles, pfparticle_handle);
211 std::map<unsigned, art::Ptr<recob::PFParticle>> id_to_pfp;
212 for (
unsigned i = 0; i < pfparticles.size(); i++) {
213 id_to_pfp[pfparticles[i]->Self()] = pfparticles[i];
220 for (
unsigned i_part = 0; i_part < pfparticles.size(); i_part++) {
221 std::cout <<
"New particle! " << i_part << std::endl;
222 art::Ptr<recob::PFParticle> thisPFP = pfparticles[i_part];
224 std::cout <<
"Child of: " << thisPFP->Parent() << std::endl;
234 std::map<unsigned, std::array<std::vector<unsigned>, 3>> pfpToHits;
235 std::map<unsigned, std::array<std::vector<art::Ptr<recob::Hit>>,3>> allHits;
237 const std::vector<art::Ptr<recob::Cluster>> &thisCluster = pfparticleClusters.at(i_part);
241 if (!thisCluster.size()) {
246 const std::vector<art::Ptr<recob::Vertex>> &pfpVerts = pfparticleVertices.at(i_part);
249 if (!pfpVerts.size()) {
259 for (
unsigned i_clus = 0; i_clus < thisCluster.size(); i_clus++) {
260 allHits[thisPFP->Self()][thisCluster[i_clus]->Plane().Plane].insert(allHits[thisPFP->Self()][thisCluster[i_clus]->Plane().Plane].begin(),
261 clusterHits.at(i_clus).begin(), clusterHits.at(i_clus).end());
262 SaveHits(pfpToHits, clusterHits.at(i_clus), thisCluster[i_clus]->Plane().Plane, thisPFP);
268 struct daughter_stack_info {
269 unsigned daughter_id;
270 long unsigned hit_key;
273 std::stack<daughter_stack_info> d_pfps;
274 for (
unsigned d: thisPFP->Daughters()) {
275 daughter_stack_info dsi {d, thisPFP->Self()};
280 while (!d_pfps.empty()) {
281 daughter_stack_info daughter_info = d_pfps.top();
282 unsigned daughter = daughter_info.daughter_id;
283 unsigned hit_key = daughter_info.hit_key;
287 const art::Ptr<recob::PFParticle> &d_pfp = id_to_pfp.at(daughter);
294 allHits[d_pfp->Self()][0] = allHits[hit_key][0];
295 allHits[d_pfp->Self()][1] = allHits[hit_key][1];
296 allHits[d_pfp->Self()][2] = allHits[hit_key][2];
299 hit_key = d_pfp->Self();
303 for (
unsigned d: d_pfp->Daughters()) {
304 daughter_stack_info dsi {d, hit_key};
309 const std::vector<art::Ptr<recob::Cluster>> &d_cluster = pfparticleClusters.at(d_pfp.key());
312 if (!d_cluster.size())
continue;
315 for (
unsigned i_clus = 0; i_clus < d_cluster.size(); i_clus++) {
316 allHits[hit_key][d_cluster[i_clus]->Plane().Plane].insert(allHits[hit_key][d_cluster[i_clus]->
Plane().
Plane].
begin(),
317 d_cluster_hits.at(i_clus).begin(), d_cluster_hits.at(i_clus).end());
318 SaveHits(pfpToHits, d_cluster_hits.at(i_clus), d_cluster[i_clus]->Plane().Plane, d_pfp);
324 std::array<std::vector<sbn::PCAngleInfo>, 3> planeAngles;
328 for (
auto const &pair: allHits) {
329 unsigned branch_id = pair.first;
330 const std::array<std::vector<art::Ptr<recob::Hit>>, 3> &branchHits = pair.second;
335 std::array<std::vector<art::Ptr<recob::Hit>>, 3> sortedHits =
SortHits(branchHits, pfpVert, geo, dprop);
338 for (
unsigned i_plane = 0; i_plane < 3; i_plane++) {
339 for (
unsigned i_hit = 0; i_hit < sortedHits[i_plane].size(); i_hit++) {
354 std::array<float, 2> pca_vec_lo =
sbnpca::HitPCAVec(hitslo, *sortedHits[i_plane][i_hit], geo, dprop);
355 std::array<float, 2> pca_vec_hi =
sbnpca::HitPCAVec(hitshi, *sortedHits[i_plane][i_hit], geo, dprop);
358 if (pca_vec_lo[0] > -99. && pca_vec_lo[1] > -99. && pca_vec_hi[0] > -99. && pca_vec_hi[1] > -99.) {
363 std::array<float, 2> hv =
sbnpca::HitVector(*sortedHits[i_plane][i_hit], geo, dprop);
367 thisAngle.
angle.wire = sortedHits[i_plane][i_hit]->WireID();
369 thisAngle.
angle.lo_vector = pca_vec_lo;
370 thisAngle.
angle.hi_vector = pca_vec_hi;
371 thisAngle.
angle.hit_wire_cm = hv[0];
372 thisAngle.
angle.hit_time_cm = hv[1];
373 thisAngle.
angle.complete = complete;
374 thisAngle.
angle.hitID = sortedHits[i_plane][i_hit].key();
376 if (hitshi.size()) thisAngle.
angle.dist_to_hi =
sbnpca::HitDistance(*hitshi.back(), *sortedHits[i_plane][i_hit], geo, dprop);
377 else thisAngle.
angle.dist_to_hi = -100.;
378 if (hitslo.size()) thisAngle.
angle.dist_to_lo =
sbnpca::HitDistance(*hitslo.back(), *sortedHits[i_plane][i_hit], geo, dprop);
379 else thisAngle.
angle.dist_to_lo = -100.;
381 if (hitshi.size()) thisAngle.
angle.hitIDHi = hitshi.back().key();
382 else thisAngle.
angle.hitIDHi = -1;
383 if (hitslo.size()) thisAngle.
angle.hitIDLo = hitslo.back().key();
384 else thisAngle.
angle.hitIDLo = -1;
386 thisAngle.
branch = branch_id;
391 art::Ptr<recob::PFParticle>
check = id_to_pfp.at(branch_id);
392 while (check->Self() != thisPFP->Self()) {
394 check = id_to_pfp.at(check->Parent());
397 planeAngles[i_plane].push_back(thisAngle);
403 for (
unsigned i_plane = 0; i_plane < 3; i_plane++) {
404 std::map<unsigned, std::vector<sbn::PCAngleInfo>> selected =
RemoveDupes(planeAngles[i_plane]);
406 sbn::PCAnglePlane thisPlane;
408 thisPlane.plane = planeID;
409 for (
auto const &pair: selected) {
410 thisPlane.branchIDs.push_back(pair.first);
413 thisPlane.branchHierarchy.emplace_back();
414 art::Ptr<recob::PFParticle> check = id_to_pfp.at(pair.first);
415 thisPlane.branchHierarchy.back().push_back(check->Self());
416 while (check->Self() != thisPFP->Self()) {
417 check = id_to_pfp.at(check->Parent());
418 thisPlane.branchHierarchy.back().push_back(check->Self());
421 if (pair.second.size()) thisPlane.generations.push_back(pair.second.front().generation);
422 else thisPlane.generations.push_back(-1);
424 if (pair.second.size()) thisPlane.plane = pair.second.front().angle.wire;
426 thisPlane.angles.emplace_back();
429 thisPlane.nBranches = thisPlane.angles.size();
430 outAngles->push_back(thisPlane);
431 art::Ptr<sbn::PCAnglePlane> thisAnglePtr = anglePtrMaker(outAngles->size()-1);
432 assn->addSingle(thisPFP, thisAnglePtr);
437 evt.put(std::move(outAngles));
438 evt.put(std::move(assn));
void SaveHits(std::map< unsigned, std::array< std::vector< unsigned >, 3 >> &pfpToHits, const std::vector< art::Ptr< recob::Hit >> &hits, unsigned plane, const art::Ptr< recob::PFParticle > &pfp)
BEGIN_PROLOG true icarus_rawdigitfilter FilterTools FilterPlane1 Plane
std::array< float, 2 > HitPCAVec(const std::vector< art::Ptr< recob::Hit >> &hits, const recob::Hit ¢er, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop)
static constexpr size_t kPFParticlePrimary
Define index to signify primary particle.
std::map< unsigned, std::vector< sbn::PCAngleInfo > > RemoveDupes(std::vector< sbn::PCAngleInfo > &angles)
The data type to uniquely identify a Plane.
Definition of vertex object for LArSoft.
std::tuple< std::vector< art::Ptr< recob::Hit > >, std::vector< art::Ptr< recob::Hit > >, bool > GetNearestHits(const std::vector< art::Ptr< recob::Hit >> &hits, int ihit, float distance, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop)
process_name tightIsolTest check
std::array< std::vector< art::Ptr< recob::Hit > >, 3 > SortHits(const std::array< std::vector< art::Ptr< recob::Hit >>, 3 > &hits, const recob::Vertex &start, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop)
float VecAngle(std::array< float, 2 > A, std::array< float, 2 > B)
float HitDistance(const recob::Hit &A, const recob::Hit &B, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop)
Description of geometry of one entire detector.
auto begin(FixedBins< T, C > const &) noexcept
finds tracks best matching by angle
bool DoBranch(art::Ptr< recob::PFParticle > particle, const std::map< unsigned, art::Ptr< recob::PFParticle >> &pfpMap)
art::InputTag fPFParticleLabel
BEGIN_PROLOG could also be cout
std::array< float, 2 > HitVector(const recob::Hit &A, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop)