42 #include "TLorentzVector.h" 43 #include "TMathBase.h" 57 std::vector< art::Ptr< recob::Hit > >
hits1;
58 std::vector< art::Ptr< recob::Hit > >
hits2;
59 std::vector< art::Ptr< recob::Hit > >
hits3;
88 std::vector< ems::DirOfGamma* > CollectShower2D(
art::Event const & e);
90 void Link(
art::Event const & e, std::vector< ems::DirOfGamma* > input);
95 void Make3DSeg(
art::Event const & e, std::vector< ems::DirOfGamma* > pair);
98 bool Validate(std::vector< ems::DirOfGamma* > input,
size_t id1,
size_t id2,
size_t c1,
size_t c2,
size_t plane3);
100 void FilterOutSmallParts(
108 std::vector<size_t>& used,
111 bool Has(
const std::vector<size_t>& v,
size_t idx);
113 size_t LinkCandidates(
art::Event const & e, std::vector< ems::DirOfGamma* > input,
size_t id);
119 std::vector< std::vector< art::Ptr<recob::Hit> > >
fClusters;
138 : fProjectionMatchingAlg(p.get<
fhicl::ParameterSet >(
"ProjectionMatchingAlg")),
139 fCalorimetryAlg(p.get<
fhicl::ParameterSet >(
"CalorimetryAlg"))
143 produces< std::vector<recob::Track> >();
144 produces< std::vector<recob::Vertex> >();
145 produces< std::vector<recob::Cluster> >();
146 produces< std::vector<recob::SpacePoint> >();
147 produces< art::Assns<recob::Track, recob::Hit> >();
148 produces< art::Assns<recob::Track, recob::Vertex> >();
149 produces< art::Assns<recob::Cluster, recob::Hit> >();
150 produces< art::Assns<recob::Track, recob::SpacePoint> >();
151 produces< art::Assns<recob::SpacePoint, recob::Hit> >();
152 produces< art::Assns<recob::Track, recob::Cluster> >();
171 return recob::Cluster(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, src.size(), 0.0F, 0.0F,
fClIndex, src[0]->View(), src[0]->WireID().planeID());
176 auto const* geom = lar::providerFrom<geo::Geometry>();
177 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
181 size_t nusedhitsmax = 0;
int bestplane = -1;
182 for (
unsigned int p = 0; p < nplanes; ++p)
184 unsigned int nusedP = 0;
187 if (nusedP > nusedhitsmax)
189 nusedhitsmax = nusedP;
194 std::vector< std::vector< double > > vdedx;
195 std::vector< double > dedx;
197 for (
unsigned int p = 0; p < nplanes; ++p)
199 unsigned int nusedP = 0;
201 double timeP = detprop->ConvertXToTicks(avdrift,
206 dedx.push_back(dEdxplane);
207 if (
int(p) == bestplane) dedx.push_back(1);
208 else dedx.push_back(0);
209 vdedx.push_back(dedx);
212 std::vector< TVector3 > xyz, dircos;
214 for (
size_t i = 0; i < src.
size(); i++)
216 xyz.push_back(src[i]->
Point3D());
218 if (i < src.
size() - 1)
220 TVector3 dc(src[i + 1]->
Point3D());
221 dc -= src[i]->Point3D();
222 dc *= 1.0 / dc.Mag();
223 dircos.push_back(dc);
225 else dircos.push_back(dircos.back());
238 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
239 auto const* geom = lar::providerFrom<geo::Geometry>();
243 size_t nusedhitsmax = 0;
int bestplane = -1;
244 for (
unsigned int p = 0; p < nplanes; ++p)
246 unsigned int nusedP = 0;
249 if (nusedP > nusedhitsmax)
251 nusedhitsmax = nusedP;
256 std::vector< std::vector< double > > vdedx;
257 std::vector< double > dedx;
259 for (
unsigned int p = 0; p < nplanes; ++p)
261 unsigned int nusedP = 0;
263 double timeP = detprop->ConvertXToTicks(avdrift,
268 dedx.push_back(dEdxplane);
269 if (
int(p) == bestplane) dedx.push_back(1);
270 else dedx.push_back(0);
271 vdedx.push_back(dedx);
274 std::vector< TVector3 > xyz, dircos;
276 for (
size_t i = 0; i < src.
size(); i++)
278 xyz.push_back(src[i]->
Point3D());
280 if (i < src.
size() - 1)
282 TVector3 dc(src[i + 1]->
Point3D());
283 dc -= src[i]->Point3D();
284 dc *= 1.0 / dc.Mag();
285 dircos.push_back(dc);
287 else dircos.push_back(dircos.back());
305 std::unique_ptr< std::vector< recob::Track > > tracks(
new std::vector< recob::Track >);
306 std::unique_ptr< std::vector< recob::Vertex > > vertices(
new std::vector< recob::Vertex >);
307 std::unique_ptr< std::vector< recob::Cluster > > clusters(
new std::vector< recob::Cluster >);
308 std::unique_ptr< std::vector< recob::SpacePoint > > allsp(
new std::vector< recob::SpacePoint >);
326 std::vector< art::Ptr<recob::Hit> > hitlist;
329 if (hitlist.size() > 5)
335 Link(e, showernviews);
347 size_t spStart = 0, spEnd = 0;
348 double sp_pos[3], sp_err[6], vtx_pos[3];
349 for (
size_t i = 0; i < 6; i++) sp_err[i] = 1.0;
357 vtx_pos[0] =
trk.track->front()->Point3D().X();
358 vtx_pos[1] =
trk.track->front()->Point3D().Y();
359 vtx_pos[2] =
trk.track->front()->Point3D().Z();
364 std::vector< art::Ptr< recob::Cluster > > cl2d;
368 std::vector< art::Ptr< recob::Hit > > hits2d;
371 spStart = allsp->size();
372 for (
int h =
trk.track->size() - 1; h >= 0; h--)
378 (sp_pos[0] != h3d->
Point3D().X()) ||
379 (sp_pos[1] != h3d->
Point3D().Y()) ||
380 (sp_pos[2] != h3d->
Point3D().Z()))
387 sp_pos[0] = h3d->
Point3D().X();
388 sp_pos[1] = h3d->
Point3D().Y();
389 sp_pos[2] = h3d->
Point3D().Z();
398 spEnd = allsp->size();
400 if (vertices->size())
402 size_t vtx_idx = (size_t)(vertices->size() - 1);
403 util::CreateAssn(*
this, e, *tracks, *vertices, *trk2vtx, vtx_idx, vtx_idx + 1);
425 std::vector< art::Ptr< recob::Cluster > > cl2d;
429 std::vector< art::Ptr< recob::Hit > > hits2d;
432 spStart = allsp->size();
433 for (
int h =
trk.track->size() - 1; h >= 0; h--)
439 (sp_pos[0] != h3d->
Point3D().X()) ||
440 (sp_pos[1] != h3d->
Point3D().Y()) ||
441 (sp_pos[2] != h3d->
Point3D().Z()))
448 sp_pos[0] = h3d->
Point3D().X();
449 sp_pos[1] = h3d->
Point3D().Y();
450 sp_pos[2] = h3d->
Point3D().Z();
459 spEnd = allsp->size();
486 for (
unsigned int i = 0; i < showernviews.size(); i++)
487 delete showernviews[i];
489 for (
unsigned int i = 0; i < fSeltracks.size(); i++)
490 delete fSeltracks[i].
track;
492 for (
unsigned int i = 0; i <
fInisegs.size(); i++)
495 for (
unsigned int i = 0; i < fPMA3D.size(); i++)
496 delete fPMA3D[i].
track;
500 e.
put(std::move(tracks));
501 e.
put(std::move(vertices));
502 e.
put(std::move(clusters));
503 e.
put(std::move(allsp));
505 e.
put(std::move(trk2hit));
506 e.
put(std::move(trk2vtx));
507 e.
put(std::move(cl2hit));
508 e.
put(std::move(trk2cl));
509 e.
put(std::move(trk2sp));
510 e.
put(std::move(sp2hit));
517 const float min_dist = 3.0F;
525 if (ta == tb) {tb++;
continue;}
527 TVector3 p1 =
fSeltracks[ta].track->front()->Point3D();
528 TVector3 p2 =
fSeltracks[tb].track->front()->Point3D();
537 std::vector< art::Ptr< recob::Hit > > hits3 =
fSeltracks[ta].hits1;
538 std::vector< art::Ptr< recob::Hit > >
hits =
fSeltracks[ta].hits1;
539 for (
size_t h = 0; h <
fSeltracks[ta].hits2.size(); ++h)
545 for (
size_t h = 0; h <
fSeltracks[tb].hits1.size(); ++h)
551 for (
size_t h = 0; h <
fSeltracks[tb].hits2.size(); ++h)
596 std::vector< ems::DirOfGamma* > input;
603 std::vector< art::Ptr<recob::Hit> > hitlist;
606 if (hitlist.size() > 5)
608 std::vector< art::Ptr<recob::Hit> > hits_out;
611 if (hits_out.size() > 5)
629 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
631 std::vector< std::vector< size_t > > saveids;
632 std::vector< size_t > saveidsnotusedcls;
635 while (i < input.size())
637 if (!input[i]->GetCandidates().size()){i++;
continue;}
639 double mindist = 1.0;
640 std::vector< ems::DirOfGamma* > pairs;
642 size_t startview = input[i]->GetFirstHit()->WireID().Plane;
643 size_t tpc = input[i]->GetFirstHit()->WireID().TPC;
644 size_t cryo = input[i]->GetFirstHit()->WireID().Cryostat;
646 float t1 = detprop->ConvertTicksToX(input[i]->GetFirstHit()->PeakTime(), startview, tpc, cryo);
648 unsigned int idsave = 0;
649 for (
unsigned int j = 0; j < input.size(); j++)
651 if (!input[j]->GetCandidates().size())
continue;
653 size_t secondview = input[j]->GetFirstHit()->WireID().Plane;
654 size_t tpc_j = input[j]->GetFirstHit()->WireID().TPC;
655 size_t cryo_j = input[j]->GetFirstHit()->WireID().Cryostat;
657 if ((i != j) && (secondview != startview) && (tpc == tpc_j) && (cryo == cryo_j))
659 float t2 = detprop->ConvertTicksToX(input[j]->GetFirstHit()->PeakTime(), secondview, tpc_j, cryo_j);
660 float dist = fabs(t2 - t1);
666 pairs.push_back(input[i]); pairs.push_back(input[j]);
674 for (
unsigned int v = 0; v < saveids.size(); v++)
675 if ((saveids[v][0] == i) || (saveids[v][0] == idsave))
676 if ((saveids[v][1] == i) || (saveids[v][1] == idsave))
684 std::vector< size_t > ids;
685 ids.push_back(i); ids.push_back(idsave);
686 saveids.push_back(ids);
690 saveidsnotusedcls.push_back(i);
697 while(i < saveidsnotusedcls.size())
708 size_t index = id;
bool found =
false;
710 if (input[
id]->GetCandidates().size() < 2) {
return index; }
712 double mindist = 3.0;
713 std::vector< ems::DirOfGamma* > pairs;
715 size_t idcsave = 0;
size_t idcjsave = 0;
716 size_t c = 0;
size_t idsave = 0;
717 while (c < input[
id]->GetCandidates().size())
720 size_t startview = input[id]->GetCandidates()[c].GetPlane();
721 size_t tpc = input[id]->GetCandidates()[c].GetTPC();
722 size_t cryo = input[id]->GetCandidates()[c].GetCryo();
724 float t1 = input[id]->GetCandidates()[c].GetPosition().Y();
727 for (
size_t j = 0; j < input.size(); ++j)
729 if (!input[j]->GetCandidates().size())
continue;
730 if (j ==
id)
continue;
733 for (
size_t cj = 0; cj < input[j]->GetCandidates().size(); ++cj)
735 size_t secondview = input[j]->GetCandidates()[cj].GetPlane();
736 size_t tpc_j = input[j]->GetCandidates()[cj].GetTPC();
737 size_t cryo_j = input[j]->GetCandidates()[cj].GetCryo();
739 size_t thirdview = startview;
742 for (
size_t p = 0; p < cryostat.
MaxPlanes(); p++)
743 if ((p == startview) || (p == secondview)) {
continue;}
744 else {thirdview = p;
break;}
747 if ((startview != secondview) && (tpc == tpc_j) && (cryo == cryo_j))
749 float t2 = input[j]->GetCandidates()[cj].GetPosition().Y();
750 float dist = fabs(t2 - t1);
752 if ((dist < mindist) &&
Validate(input,
id, j, c, cj, thirdview))
756 pairs.push_back(input[
id]); pairs.push_back(input[j]);
757 idsave = j; index = j;
758 idcsave = c; idcjsave = cj;
768 if (found && pairs.size())
770 input[id]->SetIdCandidate(idcsave);
771 input[idsave]->SetIdCandidate(idcjsave);
780 if (pair.size() < 2)
return;
783 size_t tpc1 = pair[0]->GetFirstHit()->WireID().TPC;
784 size_t tpc2 = pair[1]->GetFirstHit()->WireID().TPC;
786 std::vector< art::Ptr< recob::Hit > > vec1 = pair[0]->GetIniHits();
787 std::vector< art::Ptr< recob::Hit > > vec2 = pair[1]->GetIniHits();
789 if ((vec1.size() < 3) && (vec2.size() < 3))
return;
791 std::vector< art::Ptr<recob::Hit> > hitscl1uniquetpc;
792 std::vector< art::Ptr<recob::Hit> > hitscl2uniquetpc;
795 for (
size_t i = 0; i < vec1.size(); ++i)
796 for (
size_t j = 0; j < vec2.size(); ++j)
797 if ((vec1[i]->WireID().TPC == vec2[j]->WireID().TPC) && (tpc1 == vec2[j]->WireID().TPC))
799 hitscl1uniquetpc.push_back(vec1[i]);
800 hitscl2uniquetpc.push_back(vec2[j]);
803 if ((hitscl1uniquetpc.size() > 2) && (hitscl2uniquetpc.size() > 2))
815 initrack.
idcl1 = pair[0]->GetIdCl();
816 initrack.
view1 = pair[0]->GetFirstHit()->WireID().Plane;
817 initrack.
hits1 = hitscl1uniquetpc;
818 initrack.
idcl2 = pair[1]->GetIdCl();
819 initrack.
view2 = pair[1]->GetFirstHit()->WireID().Plane;
820 initrack.
hits2 = hitscl2uniquetpc;
821 initrack.
track = trk;
832 if (id1 == id2)
return false;
834 std::vector< art::Ptr< recob::Hit > > vec1 = input[id1]->GetCandidates()[
c1].GetIniHits();
835 std::vector< art::Ptr< recob::Hit > > vec2 = input[id2]->GetCandidates()[
c2].GetIniHits();
837 if ((vec1.size() < 3) || (vec2.size() < 3))
return false;
839 std::vector< art::Ptr<recob::Hit> > hitscl1uniquetpc;
840 std::vector< art::Ptr<recob::Hit> > hitscl2uniquetpc;
842 size_t tpc = vec1[0]->WireID().TPC;
843 for (
size_t i = 0; i < vec1.size(); ++i)
844 for (
size_t j = 0; j < vec2.size(); ++j)
845 if ((vec1[i]->WireID().TPC == tpc) && (vec2[j]->WireID().TPC == tpc))
847 hitscl1uniquetpc.push_back(vec1[i]);
848 hitscl2uniquetpc.push_back(vec2[j]);
851 if ((hitscl1uniquetpc.size() < 3) || (hitscl2uniquetpc.size() < 3))
return false;
854 for (
size_t i = 0; i < input.size(); ++i)
856 std::vector< Hit2D* > hits2dcl = input[i]->GetHits2D();
857 for (
size_t h = 0; h < hits2dcl.size(); ++h)
861 if ( (
pma::Dist2(hits2dcl[h]->GetPointCm(), pfront) < 1.0F) &&
862 (
pma::Dist2(hits2dcl[h]->GetPointCm(), pback) < 1.0F) )
863 {result =
true;
break;}
877 std::vector< art::Ptr<recob::Hit> > hitscl;
881 for (
size_t i = 0; i < hits.size(); i++) hitscl.push_back(hits[i]);
892 for (
auto c : v)
if (c == idx)
return true;
899 std::vector<size_t>& used,
905 const double gapMargin = 5.0;
908 while ((idx < hits_in.size()) &&
Has(used, idx)) idx++;
910 if (idx < hits_in.size())
912 hits_out.push_back(hits_in[idx]);
916 double r2d2 = r2d*r2d;
917 double gapMargin2 = sqrt(2 * gapMargin*gapMargin);
918 gapMargin2 = (gapMargin2 + r2d)*(gapMargin2 + r2d);
924 for (
size_t i = 0; i < hits_in.size(); i++)
932 for (
size_t idx_o = 0; idx_o < hits_out.size(); idx_o++)
941 if (d2 < r2d2) { accept =
true;
break; }
945 if (d2 < gapMargin2) { accept =
true;
break; }
951 hits_out.push_back(hi);
967 size_t min_size = hits_in.size() / 5;
968 if (min_size < 3) min_size = 3;
970 std::vector<size_t> used;
971 std::vector< art::Ptr<recob::Hit> > close_hits;
975 if (close_hits.size() > min_size)
976 for (
auto h : close_hits) hits_out.push_back(h);
size_t LinkCandidates(art::Event const &e, std::vector< ems::DirOfGamma * > input, size_t id)
unsigned int TPC(void) const
void Link(art::Event const &e, std::vector< ems::DirOfGamma * > input)
unsigned int Cryo(void) const
unsigned int MaxPlanes() const
Returns the largest number of planes among the TPCs in this cryostat.
Implementation of the Projection Matching Algorithm.
double Dist2(const TVector2 &v1, const TVector2 &v2)
unsigned int FrontTPC(void) const
double dEdx_AREA(art::Ptr< recob::Hit > hit, double pitch, double T0=0) const
unsigned int BackTPC(void) const
bool Flip(std::vector< pma::Track3D * > &allTracks)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
geo::WireID WireID() const
Initial tdc tick for hit.
Declaration of signal hit object.
std::vector< IniSeg > fPMA3D
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
TrackTrajectory::Flags_t Flags_t
CryostatID_t Cryostat
Index of cryostat.
Set of hits with a 2D structure.
WireID_t Wire
Index of the wire within its plane.
void reconfigure(fhicl::ParameterSet const &p)
Geometry information for a single cryostat.
art::Ptr< recob::Hit > const & Hit2DPtr(void) const
Definition of vertex object for LArSoft.
std::vector< size_t > fClustersNotUsed
ProductID put(std::unique_ptr< PROD > &&product)
art::Handle< std::vector< recob::Cluster > > fCluListHandle
void produce(art::Event &e) override
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< size_t > fTracksNotUsed
double selectInitialHits(pma::Track3D &trk, unsigned int view=geo::kZ, unsigned int *nused=0) const
EMShower3D(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
Provides recob::Track data product.
void push_back(Ptr< U > const &p)
std::string fTrk3DModuleLabel
std::vector< art::Ptr< recob::Hit > > hits3
A trajectory in space reconstructed from hits.
recob::Track ConvertFrom2(pma::Track3D &src)
unsigned int BackCryo(void) const
T get(std::string const &key) const
pma::Track3D * buildSegment(const std::vector< art::Ptr< recob::Hit > > &hits_1, const std::vector< art::Ptr< recob::Hit > > &hits_2=std::vector< art::Ptr< recob::Hit > >()) const
void FilterOutSmallParts(double r2d, const std::vector< art::Ptr< recob::Hit > > &hits_in, std::vector< art::Ptr< recob::Hit > > &hits_out)
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
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.
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
PlaneID_t Plane
Index of the plane within its TPC.
Declaration of cluster object.
calo::CalorimetryAlg fCalorimetryAlg
unsigned int FrontCryo(void) const
bool Validate(art::Event const &e, const pma::Track3D &src, size_t plane)
bool GetCloseHits(double r2d, const std::vector< art::Ptr< recob::Hit > > &hits_in, std::vector< size_t > &used, std::vector< art::Ptr< recob::Hit > > &hits_out)
TVector3 const & Point3D(void) const
std::vector< std::vector< art::Ptr< recob::Hit > > > fClusters
Implementation of the Projection Matching Algorithm.
float PeakTime() const
Time of the signal peak, in tick units.
Utility object to perform functions of association.
void Make3DSeg(art::Event const &e, std::vector< ems::DirOfGamma * > pair)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
pma::ProjectionMatchingAlg fProjectionMatchingAlg
TVector2 WireDriftToCm(unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
bool Has(const std::vector< size_t > &v, size_t idx)
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
std::vector< art::Ptr< recob::Hit > > hits2
std::vector< art::Ptr< recob::Hit > > hits1
std::vector< IniSeg > fSeltracks
TPCID_t TPC
Index of the TPC within its cryostat.
recob::Track ConvertFrom(pma::Track3D &src)
std::string fCluModuleLabel
std::vector< Hit2D * > const & GetHits2D(void) const
double validate(const pma::Track3D &trk, const std::vector< art::Ptr< recob::Hit > > &hits) const
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
std::vector< IniSeg > fInisegs
std::vector< ems::DirOfGamma * > CollectShower2D(art::Event const &e)