44 std::vector<art::Ptr<recob::Hit>> hits1;
45 std::vector<art::Ptr<recob::Hit>> hits2;
46 std::vector<art::Ptr<recob::Hit>> hits3;
83 std::vector<ems::DirOfGamma*> pair);
86 std::vector<ems::DirOfGamma*> input,
101 std::vector<size_t>& used,
104 bool Has(
const std::vector<size_t>& v,
size_t idx);
107 std::vector<ems::DirOfGamma*> input,
114 std::vector<std::vector<art::Ptr<recob::Hit>>>
fClusters;
140 produces<std::vector<recob::Track>>();
141 produces<std::vector<recob::Vertex>>();
142 produces<std::vector<recob::Cluster>>();
143 produces<std::vector<recob::SpacePoint>>();
144 produces<art::Assns<recob::Track, recob::Hit>>();
145 produces<art::Assns<recob::Track, recob::Vertex>>();
146 produces<art::Assns<recob::Cluster, recob::Hit>>();
147 produces<art::Assns<recob::Track, recob::SpacePoint>>();
148 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
149 produces<art::Assns<recob::Track, recob::Cluster>>();
177 src[0]->WireID().planeID());
186 unsigned int nplanes = wireReadoutGeom.Nplanes({src.
front()->
Cryo(), src.
front()->
TPC()});
187 size_t nusedhitsmax = 0;
189 for (
unsigned int p = 0; p < nplanes; ++p) {
190 unsigned int nusedP = 0;
193 if (nusedP > nusedhitsmax) {
194 nusedhitsmax = nusedP;
199 std::vector<std::vector<double>> vdedx;
200 std::vector<double> dedx;
202 for (
unsigned int p = 0; p < nplanes; ++p) {
203 unsigned int nusedP = 0;
207 dedx.push_back(dEdxplane);
208 if (
int(p) == bestplane)
212 vdedx.push_back(dedx);
215 std::vector<TVector3> xyz, dircos;
217 for (
size_t i = 0; i < src.
size(); i++) {
218 xyz.push_back(src[i]->
Point3D());
220 if (i < src.
size() - 1) {
221 TVector3 dc(src[i + 1]->
Point3D());
222 dc -= src[i]->Point3D();
223 dc *= 1.0 / dc.Mag();
224 dircos.push_back(dc);
227 dircos.push_back(dircos.back());
249 unsigned int nplanes = wireReadoutGeom.Nplanes({src.
front()->
Cryo(), src.
front()->
TPC()});
250 size_t nusedhitsmax = 0;
252 for (
unsigned int p = 0; p < nplanes; ++p) {
253 unsigned int nusedP = 0;
256 if (nusedP > nusedhitsmax) {
257 nusedhitsmax = nusedP;
262 std::vector<std::vector<double>> vdedx;
263 std::vector<double> dedx;
265 for (
unsigned int p = 0; p < nplanes; ++p) {
266 unsigned int nusedP = 0;
270 dedx.push_back(dEdxplane);
271 if (
int(p) == bestplane)
275 vdedx.push_back(dedx);
278 std::vector<TVector3> xyz, dircos;
280 for (
size_t i = 0; i < src.
size(); i++) {
281 xyz.push_back(src[i]->
Point3D());
283 if (i < src.
size() - 1) {
284 TVector3 dc(src[i + 1]->
Point3D());
285 dc -= src[i]->Point3D();
286 dc *= 1.0 / dc.Mag();
287 dircos.push_back(dc);
290 dircos.push_back(dircos.back());
314 auto tracks = std::make_unique<std::vector<recob::Track>>();
315 auto vertices = std::make_unique<std::vector<recob::Vertex>>();
316 auto clusters = std::make_unique<std::vector<recob::Cluster>>();
317 auto allsp = std::make_unique<std::vector<recob::SpacePoint>>();
319 auto trk2hit = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
320 auto trk2vtx = std::make_unique<art::Assns<recob::Track, recob::Vertex>>();
321 auto cl2hit = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
322 auto trk2cl = std::make_unique<art::Assns<recob::Track, recob::Cluster>>();
323 auto trk2sp = std::make_unique<art::Assns<recob::Track, recob::SpacePoint>>();
324 auto sp2hit = std::make_unique<art::Assns<recob::SpacePoint, recob::Hit>>();
336 std::vector<art::Ptr<recob::Hit>> hitlist;
342 std::vector<ems::DirOfGamma*> showernviews =
CollectShower2D(detProp, e);
344 Link(detProp, showernviews);
355 size_t spStart = 0, spEnd = 0;
356 double sp_pos[3], sp_err[6], vtx_pos[3];
357 for (
size_t i = 0; i < 6; i++)
365 vtx_pos[0] =
trk.track->front()->Point3D().X();
366 vtx_pos[1] =
trk.track->front()->Point3D().Y();
367 vtx_pos[2] =
trk.track->front()->Point3D().Z();
368 vertices->emplace_back(vtx_pos,
fTrkIndex);
372 std::vector<art::Ptr<recob::Cluster>> cl2d;
376 std::vector<art::Ptr<recob::Hit>> hits2d;
379 spStart = allsp->
size();
380 for (
int h =
trk.track->size() - 1; h >= 0; h--) {
384 if ((h == 0) || (sp_pos[0] != h3d->
Point3D().X()) || (sp_pos[1] != h3d->
Point3D().Y()) ||
385 (sp_pos[2] != h3d->
Point3D().Z())) {
391 sp_pos[0] = h3d->
Point3D().X();
392 sp_pos[1] = h3d->
Point3D().Y();
393 sp_pos[2] = h3d->
Point3D().Z();
402 spEnd = allsp->size();
404 if (vertices->size()) {
405 size_t vtx_idx = (size_t)(vertices->size() - 1);
423 std::vector<art::Ptr<recob::Cluster>> cl2d;
427 std::vector<art::Ptr<recob::Hit>> hits2d;
430 spStart = allsp->
size();
431 for (
int h =
trk.track->size() - 1; h >= 0; h--) {
435 if ((h == 0) || (sp_pos[0] != h3d->
Point3D().X()) || (sp_pos[1] != h3d->
Point3D().Y()) ||
436 (sp_pos[2] != h3d->
Point3D().Z())) {
442 sp_pos[0] = h3d->
Point3D().X();
443 sp_pos[1] = h3d->
Point3D().Y();
444 sp_pos[2] = h3d->
Point3D().Z();
453 spEnd = allsp->size();
473 for (
unsigned int i = 0; i < showernviews.size(); i++)
474 delete showernviews[i];
476 for (
unsigned int i = 0; i < fSeltracks.size(); i++)
477 delete fSeltracks[i].
track;
479 for (
unsigned int i = 0; i <
fInisegs.size(); i++)
482 for (
unsigned int i = 0; i < fPMA3D.size(); i++)
483 delete fPMA3D[i].
track;
486 e.
put(std::move(tracks));
487 e.
put(std::move(vertices));
488 e.
put(std::move(clusters));
489 e.
put(std::move(allsp));
491 e.
put(std::move(trk2hit));
492 e.
put(std::move(trk2vtx));
493 e.
put(std::move(cl2hit));
494 e.
put(std::move(trk2cl));
495 e.
put(std::move(trk2sp));
496 e.
put(std::move(sp2hit));
502 const float min_dist = 3.0F;
513 TVector3 p1 =
fSeltracks[ta].track->front()->Point3D();
514 TVector3 p2 =
fSeltracks[tb].track->front()->Point3D();
525 std::vector<art::Ptr<recob::Hit>> hits3 =
fSeltracks[ta].hits1;
527 for (
size_t h = 0; h <
fSeltracks[ta].hits2.size(); ++h)
533 for (
size_t h = 0; h <
fSeltracks[tb].hits1.size(); ++h)
539 for (
size_t h = 0; h <
fSeltracks[tb].hits2.size(); ++h)
556 initrack.idcl3 = idcl3;
558 initrack.view3 = view3;
560 initrack.hits3 = hits3;
564 initrack.track =
track;
586 std::vector<ems::DirOfGamma*> input;
591 std::vector<art::Ptr<recob::Hit>> hitlist;
594 if (hitlist.size() > 5) {
595 std::vector<art::Ptr<recob::Hit>> hits_out;
598 if (hits_out.size() > 5) {
603 if (sh->
GetHits2D().size()) input.push_back(sh);
613 std::vector<ems::DirOfGamma*> input)
615 std::vector<std::vector<size_t>> saveids;
616 std::vector<size_t> saveidsnotusedcls;
619 while (i < input.size()) {
620 if (!input[i]->GetCandidates().size()) {
625 double mindist = 1.0;
626 std::vector<ems::DirOfGamma*> pairs;
628 size_t startview = input[i]->GetFirstHit()->WireID().Plane;
629 size_t tpc = input[i]->GetFirstHit()->WireID().TPC;
630 size_t cryo = input[i]->GetFirstHit()->WireID().Cryostat;
632 float t1 = detProp.
ConvertTicksToX(input[i]->GetFirstHit()->PeakTime(), startview, tpc, cryo);
634 unsigned int idsave = 0;
635 for (
unsigned int j = 0; j < input.size(); j++) {
636 if (!input[j]->GetCandidates().size())
continue;
638 size_t secondview = input[j]->GetFirstHit()->WireID().Plane;
639 size_t tpc_j = input[j]->GetFirstHit()->WireID().TPC;
640 size_t cryo_j = input[j]->GetFirstHit()->WireID().Cryostat;
642 if ((i != j) && (secondview != startview) && (tpc == tpc_j) && (cryo == cryo_j)) {
644 detProp.
ConvertTicksToX(input[j]->GetFirstHit()->PeakTime(), secondview, tpc_j, cryo_j);
645 float dist = fabs(t2 - t1);
647 if (dist < mindist) {
650 pairs.push_back(input[i]);
651 pairs.push_back(input[j]);
658 for (
unsigned int v = 0; v < saveids.size(); v++)
659 if ((saveids[v][0] == i) || (saveids[v][0] == idsave))
660 if ((saveids[v][1] == i) || (saveids[v][1] == idsave)) exist =
true;
665 std::vector<size_t> ids;
667 ids.push_back(idsave);
668 saveids.push_back(ids);
671 saveidsnotusedcls.push_back(i);
678 while (i < saveidsnotusedcls.size()) {
685 std::vector<ems::DirOfGamma*> input,
693 if (input[
id]->GetCandidates().
size() < 2) {
return index; }
695 double mindist = 3.0;
696 std::vector<ems::DirOfGamma*> pairs;
702 while (c < input[
id]->GetCandidates().
size()) {
704 size_t startview = input[id]->GetCandidates()[c].GetPlane();
705 size_t tpc = input[id]->GetCandidates()[c].GetTPC();
706 size_t cryo = input[id]->GetCandidates()[c].GetCryo();
708 float t1 = input[id]->GetCandidates()[c].GetPosition().Y();
711 for (
size_t j = 0; j < input.size(); ++j) {
712 if (!input[j]->GetCandidates().size())
continue;
713 if (j ==
id)
continue;
716 for (
size_t cj = 0; cj < input[j]->GetCandidates().size(); ++cj) {
717 size_t secondview = input[j]->GetCandidates()[cj].GetPlane();
718 size_t tpc_j = input[j]->GetCandidates()[cj].GetTPC();
719 size_t cryo_j = input[j]->GetCandidates()[cj].GetCryo();
721 size_t thirdview = startview;
725 auto const p = plane.ID().Plane;
726 if ((p == startview) || (p == secondview)) {
continue; }
733 if ((startview != secondview) && (tpc == tpc_j) && (cryo == cryo_j)) {
734 float t2 = input[j]->GetCandidates()[cj].GetPosition().Y();
735 float dist = fabs(t2 - t1);
737 if ((dist < mindist) &&
Validate(detProp, input,
id, j, c, cj, thirdview)) {
740 pairs.push_back(input[
id]);
741 pairs.push_back(input[j]);
755 if (found && pairs.size()) {
756 input[id]->SetIdCandidate(idcsave);
757 input[idsave]->SetIdCandidate(idcjsave);
765 std::vector<ems::DirOfGamma*> pair)
767 if (pair.size() < 2)
return;
770 size_t tpc1 = pair[0]->GetFirstHit()->WireID().TPC;
771 size_t tpc2 = pair[1]->GetFirstHit()->WireID().TPC;
773 std::vector<art::Ptr<recob::Hit>> vec1 = pair[0]->GetIniHits();
774 std::vector<art::Ptr<recob::Hit>> vec2 = pair[1]->GetIniHits();
776 if ((vec1.size() < 3) && (vec2.size() < 3))
return;
778 std::vector<art::Ptr<recob::Hit>> hitscl1uniquetpc;
779 std::vector<art::Ptr<recob::Hit>> hitscl2uniquetpc;
782 for (
size_t i = 0; i < vec1.size(); ++i)
783 for (
size_t j = 0; j < vec2.size(); ++j)
784 if ((vec1[i]->
WireID().TPC == vec2[j]->
WireID().TPC) && (tpc1 == vec2[j]->WireID().TPC)) {
785 hitscl1uniquetpc.push_back(vec1[i]);
786 hitscl2uniquetpc.push_back(vec2[j]);
789 if ((hitscl1uniquetpc.size() > 2) && (hitscl2uniquetpc.size() > 2)) {
794 if ((trk->
back()->
Hit2DPtr() == pair[0]->GetFirstHit()) ||
799 initrack.idcl1 = pair[0]->GetIdCl();
800 initrack.view1 = pair[0]->GetFirstHit()->WireID().Plane;
801 initrack.hits1 = hitscl1uniquetpc;
802 initrack.idcl2 = pair[1]->GetIdCl();
803 initrack.view2 = pair[1]->GetFirstHit()->WireID().Plane;
804 initrack.hits2 = hitscl2uniquetpc;
805 initrack.track = trk;
812 std::vector<ems::DirOfGamma*> input,
820 if (id1 == id2)
return false;
822 std::vector<art::Ptr<recob::Hit>> vec1 = input[id1]->GetCandidates()[
c1].GetIniHits();
823 std::vector<art::Ptr<recob::Hit>> vec2 = input[id2]->GetCandidates()[
c2].GetIniHits();
825 if ((vec1.size() < 3) || (vec2.size() < 3))
return false;
827 std::vector<art::Ptr<recob::Hit>> hitscl1uniquetpc;
828 std::vector<art::Ptr<recob::Hit>> hitscl2uniquetpc;
830 size_t tpc = vec1[0]->WireID().TPC;
831 for (
size_t i = 0; i < vec1.size(); ++i)
832 for (
size_t j = 0; j < vec2.size(); ++j)
833 if ((vec1[i]->
WireID().TPC == tpc) && (vec2[j]->WireID().TPC == tpc)) {
834 hitscl1uniquetpc.push_back(vec1[i]);
835 hitscl2uniquetpc.push_back(vec2[j]);
838 if ((hitscl1uniquetpc.size() < 3) || (hitscl2uniquetpc.size() < 3))
return false;
842 for (
size_t i = 0; i < input.size(); ++i) {
843 std::vector<Hit2D*> hits2dcl = input[i]->GetHits2D();
844 for (
size_t h = 0; h < hits2dcl.size(); ++h) {
849 if ((
pma::Dist2(hits2dcl[h]->GetPointCm(), pfront) < 1.0F) &&
850 (
pma::Dist2(hits2dcl[h]->GetPointCm(), pback) < 1.0F)) {
863 if (c == idx)
return true;
870 std::vector<size_t>& used,
876 const double gapMargin = 5.0;
879 while ((idx < hits_in.size()) &&
Has(used, idx))
882 if (idx < hits_in.size()) {
883 hits_out.push_back(hits_in[idx]);
886 double r2d2 = r2d * r2d;
887 double gapMargin2 = sqrt(2 * gapMargin * gapMargin);
888 gapMargin2 = (gapMargin2 + r2d) * (gapMargin2 + r2d);
893 for (
size_t i = 0; i < hits_in.size(); i++)
905 for (
size_t idx_o = 0; idx_o < hits_out.size(); idx_o++) {
923 if (d2 < gapMargin2) {
931 hits_out.push_back(hi);
947 size_t min_size = hits_in.size() / 5;
948 if (min_size < 3) min_size = 3;
950 std::vector<size_t> used;
951 std::vector<art::Ptr<recob::Hit>> close_hits;
953 while (
GetCloseHits(detProp, r2d, hits_in, used, close_hits)) {
954 if (close_hits.size() > min_size)
955 for (
auto h : close_hits)
956 hits_out.push_back(h);
void Link(detinfo::DetectorPropertiesData const &detProp, std::vector< ems::DirOfGamma * > input)
Utilities related to art service access.
Implementation of the Projection Matching Algorithm.
double Dist2(const TVector2 &v1, const TVector2 &v2)
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
Declaration of signal hit object.
pma::Hit3D const * front() const
std::vector< std::vector< art::Ptr< recob::Hit > > > fClusters
unsigned int Cryo() const noexcept
TrackTrajectory::Flags_t Flags_t
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
art::Handle< std::vector< recob::Cluster > > fCluListHandle
TVector3 const & Point3D() const
CryostatID_t Cryostat
Index of cryostat.
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 >> SMatrixSym55
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Set of hits with a 2D structure.
WireID_t Wire
Index of the wire within its plane.
geo::WireID const & WireID() const
Initial tdc tick for hit.
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)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
unsigned int BackCryo() const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
void produce(art::Event &e) override
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< Hit2D * > const & GetHits2D() const
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)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void Make3DSeg(detinfo::DetectorPropertiesData const &detProp, std::vector< ems::DirOfGamma * > pair)
void push_back(Ptr< U > const &p)
std::string fTrk3DModuleLabel
A trajectory in space reconstructed from hits.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
double ConvertXToTicks(double X, int p, int t, int c) const
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
unsigned int FrontTPC() const
size_t LinkCandidates(detinfo::DetectorPropertiesData const &detProp, std::vector< ems::DirOfGamma * > input, size_t id)
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.
Declaration of cluster object.
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 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.
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.
recob::Track ConvertFrom(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, pma::Track3D &src)
std::vector< size_t > fTracksNotUsed
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
double dist(const TReal *x, const TReal *y, const unsigned int dimension)
Contains all timing reference information for the detector.
Provides recob::Track data product.
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)
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.
The data type to uniquely identify a cryostat.