42 std::vector<art::Ptr<recob::Hit>> hits1;
43 std::vector<art::Ptr<recob::Hit>> hits2;
44 std::vector<art::Ptr<recob::Hit>> hits3;
77 std::vector<ems::DirOfGamma*>
input);
84 std::vector<ems::DirOfGamma*> pair);
87 std::vector<ems::DirOfGamma*> input,
102 std::vector<size_t>& used,
105 bool Has(
const std::vector<size_t>& v,
size_t idx);
109 std::vector<ems::DirOfGamma*> input,
116 std::vector<std::vector<art::Ptr<recob::Hit>>>
fClusters;
142 produces<std::vector<recob::Track>>();
143 produces<std::vector<recob::Vertex>>();
144 produces<std::vector<recob::Cluster>>();
145 produces<std::vector<recob::SpacePoint>>();
146 produces<art::Assns<recob::Track, recob::Hit>>();
147 produces<art::Assns<recob::Track, recob::Vertex>>();
148 produces<art::Assns<recob::Cluster, recob::Hit>>();
149 produces<art::Assns<recob::Track, recob::SpacePoint>>();
150 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
151 produces<art::Assns<recob::Track, recob::Cluster>>();
180 src[0]->WireID().planeID());
188 auto const* geom = lar::providerFrom<geo::Geometry>();
191 size_t nusedhitsmax = 0;
193 for (
unsigned int p = 0;
p < nplanes; ++
p) {
194 unsigned int nusedP = 0;
197 if (nusedP > nusedhitsmax) {
198 nusedhitsmax = nusedP;
203 std::vector<std::vector<double>> vdedx;
204 std::vector<double> dedx;
206 for (
unsigned int p = 0;
p < nplanes; ++
p) {
207 unsigned int nusedP = 0;
211 dedx.push_back(dEdxplane);
212 if (
int(
p) == bestplane)
216 vdedx.push_back(dedx);
219 std::vector<TVector3> xyz, dircos;
221 for (
size_t i = 0; i < src.
size(); i++) {
222 xyz.push_back(src[i]->
Point3D());
224 if (i < src.
size() - 1) {
225 TVector3 dc(src[i + 1]->
Point3D());
226 dc -= src[i]->Point3D();
227 dc *= 1.0 / dc.Mag();
228 dircos.push_back(dc);
231 dircos.push_back(dircos.back());
251 auto const* geom = lar::providerFrom<geo::Geometry>();
255 size_t nusedhitsmax = 0;
257 for (
unsigned int p = 0;
p < nplanes; ++
p) {
258 unsigned int nusedP = 0;
261 if (nusedP > nusedhitsmax) {
262 nusedhitsmax = nusedP;
267 std::vector<std::vector<double>> vdedx;
268 std::vector<double> dedx;
270 for (
unsigned int p = 0;
p < nplanes; ++
p) {
271 unsigned int nusedP = 0;
275 dedx.push_back(dEdxplane);
276 if (
int(
p) == bestplane)
280 vdedx.push_back(dedx);
283 std::vector<TVector3> xyz, dircos;
285 for (
size_t i = 0; i < src.
size(); i++) {
286 xyz.push_back(src[i]->
Point3D());
288 if (i < src.
size() - 1) {
289 TVector3 dc(src[i + 1]->
Point3D());
290 dc -= src[i]->Point3D();
291 dc *= 1.0 / dc.Mag();
292 dircos.push_back(dc);
295 dircos.push_back(dircos.back());
320 auto tracks = std::make_unique<std::vector<recob::Track>>();
321 auto vertices = std::make_unique<std::vector<recob::Vertex>>();
322 auto clusters = std::make_unique<std::vector<recob::Cluster>>();
323 auto allsp = std::make_unique<std::vector<recob::SpacePoint>>();
325 auto trk2hit = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
326 auto trk2vtx = std::make_unique<art::Assns<recob::Track, recob::Vertex>>();
327 auto cl2hit = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
328 auto trk2cl = std::make_unique<art::Assns<recob::Track, recob::Cluster>>();
329 auto trk2sp = std::make_unique<art::Assns<recob::Track, recob::SpacePoint>>();
330 auto sp2hit = std::make_unique<art::Assns<recob::SpacePoint, recob::Hit>>();
342 std::vector<art::Ptr<recob::Hit>> hitlist;
348 std::vector<ems::DirOfGamma*> showernviews =
CollectShower2D(detProp, e);
350 Link(e, detProp, showernviews);
361 size_t spStart = 0, spEnd = 0;
362 double sp_pos[3], sp_err[6], vtx_pos[3];
363 for (
size_t i = 0; i < 6; i++)
371 vtx_pos[0] =
trk.track->front()->Point3D().X();
372 vtx_pos[1] =
trk.track->front()->Point3D().Y();
373 vtx_pos[2] =
trk.track->front()->Point3D().Z();
374 vertices->emplace_back(vtx_pos,
fTrkIndex);
378 std::vector<art::Ptr<recob::Cluster>> cl2d;
382 std::vector<art::Ptr<recob::Hit>> hits2d;
385 spStart = allsp->
size();
386 for (
int h =
trk.track->size() - 1;
h >= 0;
h--) {
390 if ((
h == 0) || (sp_pos[0] != h3d->
Point3D().X()) || (sp_pos[1] != h3d->
Point3D().Y()) ||
391 (sp_pos[2] != h3d->
Point3D().Z())) {
397 sp_pos[0] = h3d->
Point3D().X();
398 sp_pos[1] = h3d->
Point3D().Y();
399 sp_pos[2] = h3d->
Point3D().Z();
408 spEnd = allsp->size();
410 if (vertices->size()) {
411 size_t vtx_idx = (size_t)(vertices->size() - 1);
429 std::vector<art::Ptr<recob::Cluster>> cl2d;
433 std::vector<art::Ptr<recob::Hit>> hits2d;
436 spStart = allsp->
size();
437 for (
int h =
trk.track->size() - 1;
h >= 0;
h--) {
441 if ((
h == 0) || (sp_pos[0] != h3d->
Point3D().X()) || (sp_pos[1] != h3d->
Point3D().Y()) ||
442 (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();
479 for (
unsigned int i = 0; i < showernviews.size(); i++)
480 delete showernviews[i];
482 for (
unsigned int i = 0; i < fSeltracks.size(); i++)
483 delete fSeltracks[i].track;
485 for (
unsigned int i = 0; i <
fInisegs.size(); i++)
488 for (
unsigned int i = 0; i < fPMA3D.size(); i++)
489 delete fPMA3D[i].track;
509 const float min_dist = 3.0F;
520 TVector3 p1 =
fSeltracks[ta].track->front()->Point3D();
521 TVector3 p2 =
fSeltracks[tb].track->front()->Point3D();
532 std::vector<art::Ptr<recob::Hit>> hits3 =
fSeltracks[ta].hits1;
533 std::vector<art::Ptr<recob::Hit>> hits =
fSeltracks[ta].hits1;
540 for (
size_t h = 0; h <
fSeltracks[tb].hits1.size(); ++
h)
546 for (
size_t h = 0; h <
fSeltracks[tb].hits2.size(); ++
h)
563 initrack.idcl3 = idcl3;
565 initrack.view3 = view3;
567 initrack.hits3 = hits3;
571 initrack.track = track;
589 std::vector<ems::DirOfGamma*>
593 std::vector<ems::DirOfGamma*>
input;
598 std::vector<art::Ptr<recob::Hit>> hitlist;
601 if (hitlist.size() > 5) {
602 std::vector<art::Ptr<recob::Hit>> hits_out;
605 if (hits_out.size() > 5) {
610 if (sh->
GetHits2D().size()) input.push_back(sh);
622 std::vector<ems::DirOfGamma*>
input)
624 std::vector<std::vector<size_t>> saveids;
625 std::vector<size_t> saveidsnotusedcls;
628 while (i < input.size()) {
629 if (!input[i]->GetCandidates().size()) {
634 double mindist = 1.0;
635 std::vector<ems::DirOfGamma*> pairs;
637 size_t startview = input[i]->GetFirstHit()->WireID().Plane;
638 size_t tpc = input[i]->GetFirstHit()->WireID().TPC;
639 size_t cryo = input[i]->GetFirstHit()->WireID().Cryostat;
641 float t1 = detProp.
ConvertTicksToX(input[i]->GetFirstHit()->PeakTime(), startview, tpc, cryo);
643 unsigned int idsave = 0;
644 for (
unsigned int j = 0; j < input.size(); j++) {
645 if (!input[j]->GetCandidates().size())
continue;
647 size_t secondview = input[j]->GetFirstHit()->WireID().Plane;
648 size_t tpc_j = input[j]->GetFirstHit()->WireID().TPC;
649 size_t cryo_j = input[j]->GetFirstHit()->WireID().Cryostat;
651 if ((i != j) && (secondview != startview) && (tpc == tpc_j) && (cryo == cryo_j)) {
653 detProp.
ConvertTicksToX(input[j]->GetFirstHit()->PeakTime(), secondview, tpc_j, cryo_j);
654 float dist = fabs(t2 - t1);
656 if (dist < mindist) {
659 pairs.push_back(input[i]);
660 pairs.push_back(input[j]);
667 for (
unsigned int v = 0; v < saveids.size(); v++)
668 if ((saveids[v][0] == i) || (saveids[v][0] == idsave))
669 if ((saveids[v][1] == i) || (saveids[v][1] == idsave)) exist =
true;
672 if (!exist)
Make3DSeg(e, detProp, pairs);
674 std::vector<size_t> ids;
676 ids.push_back(idsave);
677 saveids.push_back(ids);
680 saveidsnotusedcls.push_back(i);
687 while (i < saveidsnotusedcls.size()) {
696 std::vector<ems::DirOfGamma*>
input,
704 if (input[
id]->GetCandidates().
size() < 2) {
return index; }
706 double mindist = 3.0;
707 std::vector<ems::DirOfGamma*> pairs;
713 while (c < input[
id]->GetCandidates().
size()) {
715 size_t startview = input[id]->GetCandidates()[
c].GetPlane();
716 size_t tpc = input[id]->GetCandidates()[
c].GetTPC();
717 size_t cryo = input[id]->GetCandidates()[
c].GetCryo();
719 float t1 = input[id]->GetCandidates()[
c].GetPosition().Y();
722 for (
size_t j = 0; j < input.size(); ++j) {
723 if (!input[j]->GetCandidates().size())
continue;
724 if (j ==
id)
continue;
727 for (
size_t cj = 0; cj < input[j]->GetCandidates().size(); ++cj) {
728 size_t secondview = input[j]->GetCandidates()[cj].GetPlane();
729 size_t tpc_j = input[j]->GetCandidates()[cj].GetTPC();
730 size_t cryo_j = input[j]->GetCandidates()[cj].GetCryo();
732 size_t thirdview = startview;
736 if ((
p == startview) || (
p == secondview)) {
continue; }
742 if ((startview != secondview) && (tpc == tpc_j) && (cryo == cryo_j)) {
743 float t2 = input[j]->GetCandidates()[cj].GetPosition().Y();
744 float dist = fabs(t2 - t1);
746 if ((dist < mindist) &&
Validate(detProp, input,
id, j, c, cj, thirdview)) {
749 pairs.push_back(input[
id]);
750 pairs.push_back(input[j]);
764 if (found && pairs.size()) {
765 input[id]->SetIdCandidate(idcsave);
766 input[idsave]->SetIdCandidate(idcjsave);
776 std::vector<ems::DirOfGamma*> pair)
778 if (pair.size() < 2)
return;
781 size_t tpc1 = pair[0]->GetFirstHit()->WireID().TPC;
782 size_t tpc2 = pair[1]->GetFirstHit()->WireID().TPC;
784 std::vector<art::Ptr<recob::Hit>> vec1 = pair[0]->GetIniHits();
785 std::vector<art::Ptr<recob::Hit>> vec2 = pair[1]->GetIniHits();
787 if ((vec1.size() < 3) && (vec2.size() < 3))
return;
789 std::vector<art::Ptr<recob::Hit>> hitscl1uniquetpc;
790 std::vector<art::Ptr<recob::Hit>> hitscl2uniquetpc;
793 for (
size_t i = 0; i < vec1.size(); ++i)
794 for (
size_t j = 0; j < vec2.size(); ++j)
795 if ((vec1[i]->
WireID().
TPC == vec2[j]->
WireID().
TPC) && (tpc1 == vec2[j]->WireID().TPC)) {
796 hitscl1uniquetpc.push_back(vec1[i]);
797 hitscl2uniquetpc.push_back(vec2[j]);
800 if ((hitscl1uniquetpc.size() > 2) && (hitscl2uniquetpc.size() > 2)) {
805 if ((trk->
back()->
Hit2DPtr() == pair[0]->GetFirstHit()) ||
810 initrack.idcl1 = pair[0]->GetIdCl();
811 initrack.view1 = pair[0]->GetFirstHit()->WireID().Plane;
812 initrack.hits1 = hitscl1uniquetpc;
813 initrack.idcl2 = pair[1]->GetIdCl();
814 initrack.view2 = pair[1]->GetFirstHit()->WireID().Plane;
815 initrack.hits2 = hitscl2uniquetpc;
816 initrack.track = trk;
824 std::vector<ems::DirOfGamma*>
input,
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)) {
846 hitscl1uniquetpc.push_back(vec1[i]);
847 hitscl2uniquetpc.push_back(vec2[j]);
850 if ((hitscl1uniquetpc.size() < 3) || (hitscl2uniquetpc.size() < 3))
return false;
854 for (
size_t i = 0; i < input.size(); ++i) {
855 std::vector<Hit2D*> hits2dcl = input[i]->GetHits2D();
856 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)) {
876 if (
c == idx)
return true;
884 std::vector<size_t>& used,
890 const double gapMargin = 5.0;
893 while ((idx < hits_in.size()) &&
Has(used, idx))
896 if (idx < hits_in.size()) {
897 hits_out.push_back(hits_in[idx]);
900 double r2d2 = r2d * r2d;
901 double gapMargin2 = sqrt(2 * gapMargin * gapMargin);
902 gapMargin2 = (gapMargin2 + r2d) * (gapMargin2 + r2d);
907 for (
size_t i = 0; i < hits_in.size(); i++)
919 for (
size_t idx_o = 0; idx_o < hits_out.size(); idx_o++) {
937 if (d2 < gapMargin2) {
945 hits_out.push_back(hi);
962 size_t min_size = hits_in.size() / 5;
963 if (min_size < 3) min_size = 3;
965 std::vector<size_t> used;
966 std::vector<art::Ptr<recob::Hit>> close_hits;
968 while (
GetCloseHits(detProp, r2d, hits_in, used, close_hits)) {
969 if (close_hits.size() > min_size)
970 for (
auto h : close_hits)
971 hits_out.push_back(
h);
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)
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
pma::Hit3D const * front() const
std::vector< std::vector< art::Ptr< recob::Hit > > > fClusters
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
unsigned int Cryo() const noexcept
TrackTrajectory::Flags_t Flags_t
art::Handle< std::vector< recob::Cluster > > fCluListHandle
size_t LinkCandidates(art::Event const &e, detinfo::DetectorPropertiesData const &detProp, std::vector< ems::DirOfGamma * > input, size_t id)
TVector3 const & Point3D() const
CryostatID_t Cryostat
Index of cryostat.
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
Set of hits with a 2D structure.
WireID_t Wire
Index of the wire within its plane.
Geometry information for a single cryostat.
unsigned int BackTPC() const
void FilterOutSmallParts(detinfo::DetectorPropertiesData const &detProp, double r2d, const std::vector< art::Ptr< recob::Hit >> &hits_in, std::vector< art::Ptr< recob::Hit >> &hits_out)
std::vector< IniSeg > fInisegs
bool Validate(detinfo::DetectorPropertiesData const &detProp, std::vector< ems::DirOfGamma * > input, size_t id1, size_t id2, size_t c1, size_t c2, size_t plane3)
unsigned int BackCryo() const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
void produce(art::Event &e) override
std::vector< Hit2D * > const & GetHits2D() const
double selectInitialHits(pma::Track3D &trk, unsigned int view=geo::kZ, unsigned int *nused=0) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
EMShower3D(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void push_back(Ptr< U > const &p)
std::string fTrk3DModuleLabel
A trajectory in space reconstructed from hits.
void Make3DSeg(art::Event const &e, detinfo::DetectorPropertiesData const &detProp, std::vector< ems::DirOfGamma * > pair)
double ConvertXToTicks(double X, int p, int t, int c) const
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
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)
unsigned int FrontTPC() const
unsigned int FrontCryo() const
pma::Track3D * buildSegment(const detinfo::DetectorPropertiesData &clockData, const std::vector< art::Ptr< recob::Hit >> &hits_1, const std::vector< art::Ptr< recob::Hit >> &hits_2={}) const
PlaneID_t Plane
Index of the plane within its TPC.
calo::CalorimetryAlg fCalorimetryAlg
std::vector< ems::DirOfGamma * > CollectShower2D(detinfo::DetectorPropertiesData const &detProp, art::Event const &e)
double ConvertTicksToX(double ticks, int p, int t, int c) const
bool GetCloseHits(detinfo::DetectorPropertiesData const &detProp, double r2d, const std::vector< art::Ptr< recob::Hit >> &hits_in, std::vector< size_t > &used, std::vector< art::Ptr< recob::Hit >> &hits_out)
std::vector< IniSeg > fPMA3D
Implementation of the Projection Matching Algorithm.
float PeakTime() const
Time of the signal peak, in tick units.
Declaration of signal hit object.
recob::Track ConvertFrom(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, pma::Track3D &src)
std::vector< size_t > fTracksNotUsed
Contains all timing reference information for the detector.
void Link(art::Event const &e, detinfo::DetectorPropertiesData const &detProp, std::vector< ems::DirOfGamma * > input)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
pma::ProjectionMatchingAlg fProjectionMatchingAlg
recob::Track ConvertFrom2(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, pma::Track3D &src)
std::vector< size_t > fClustersNotUsed
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
Provides recob::Track data product.
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
pma::Hit3D const * back() const
art::Ptr< recob::Hit > const & Hit2DPtr() const
bool Has(const std::vector< size_t > &v, size_t idx)
std::vector< IniSeg > fSeltracks
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
bool Flip(const detinfo::DetectorPropertiesData &detProp, std::vector< pma::Track3D * > &allTracks)
void Reoptimize(detinfo::DetectorPropertiesData const &detProp)
TPCID_t TPC
Index of the TPC within its cryostat.
unsigned int TPC() const noexcept
std::string fCluModuleLabel
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.