235 std::vector<art::Ptr<recob::Slice>>
slices;
236 std::vector<int> slcIDs;
237 unsigned int nInputHits = 0;
244 nInputHits = (*inputHits).size();
262 throw cet::exception(
"TrajClusterModule") <<
"Failed to get a inputSlices";
269 throw cet::exception(
"TrajClusterModule") <<
"Failed to get a handle to SpacePoints\n";
270 tca::evt.
sptHits.resize((*InputSpts).size(), {{UINT_MAX, UINT_MAX, UINT_MAX}});
275 if (!hitsFromSpt.isValid())
277 <<
"Failed to get a handle to SpacePoint -> Hit assns\n";
279 auto& firstHit = hitsFromSpt.at(0)[0];
280 if (firstHit.id() != inputHits.id())
282 <<
"The SpacePoint -> Hit assn doesn't reference the input hit collection\n";
283 tca::evt.
sptHits.resize((*InputSpts).size(), {{UINT_MAX, UINT_MAX, UINT_MAX}});
284 for (
unsigned int isp = 0; isp < (*InputSpts).size(); ++isp) {
285 auto& hits = hitsFromSpt.at(isp);
286 for (
unsigned short iht = 0; iht < hits.size(); ++iht) {
287 unsigned short plane = hits[iht]->WireID().Plane;
293 if (nInputHits > 0) {
294 auto const clockData =
298 auto const* geom = lar::providerFrom<geo::Geometry>();
299 for (
const auto& tpcid : geom->IterateTPCIDs()) {
301 if (geom->TPC(tpcid).DriftDistance() < 25.0)
continue;
304 std::vector<std::vector<unsigned int>> sltpcHits;
305 if (inputSlices.isValid()) {
308 GetHits(*inputHits, tpcid, *inputSlices, hitFromSlc, sltpcHits, slcIDs);
313 GetHits(*inputHits, tpcid, sltpcHits);
317 if (sltpcHits.empty())
continue;
318 for (
unsigned short isl = 0; isl < sltpcHits.size(); ++isl) {
319 auto& tpcHits = sltpcHits[isl];
320 if (tpcHits.empty())
continue;
324 std::vector<HitLoc> sortVec(tpcHits.size());
325 for (
unsigned int indx = 0; indx < tpcHits.size(); ++indx) {
326 auto&
hit = (*inputHits)[tpcHits[indx]];
327 sortVec[indx].index = indx;
329 sortVec[indx].wire =
hit.WireID().Wire;
330 sortVec[indx].tick =
hit.StartTick();
331 sortVec[indx].localIndex =
hit.LocalIndex();
333 std::sort(sortVec.begin(), sortVec.end(),
SortHits);
335 for (
unsigned int ii = 0; ii < tpcHits.size(); ++ii)
336 tpcHits[ii] = tmp[sortVec[ii].
index];
343 for (
unsigned short indx = 0; indx < tpcHits.size(); ++indx) {
344 auto&
hit = (*inputHits)[tpcHits[indx]];
349 std::cout <<
"Debug hit " << tpcHits[indx] <<
" found in slice ID " << slcIDs[isl];
350 std::cout <<
" RMS " <<
hit.RMS();
351 std::cout <<
" Multiplicity " <<
hit.Multiplicity();
352 std::cout <<
" GoodnessOfFit " <<
hit.GoodnessOfFit();
368 std::vector<recob::Hit> hitCol;
369 std::vector<recob::Cluster> clsCol;
370 std::vector<recob::PFParticle> pfpCol;
371 std::vector<recob::Vertex> vx3Col;
372 std::vector<recob::EndPoint2D> vx2Col;
373 std::vector<recob::Seed> sedCol;
374 std::vector<recob::Shower> shwCol;
375 std::vector<anab::CosmicTag> ctCol;
377 std::vector<unsigned int> newIndex(nInputHits, UINT_MAX);
381 std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> cls_hit_assn(
384 std::unique_ptr<art::Assns<recob::Cluster, recob::EndPoint2D, unsigned short>> cls_vx2_assn(
386 std::unique_ptr<art::Assns<recob::Cluster, recob::Vertex, unsigned short>> cls_vx3_assn(
389 std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> shwr_hit_assn(
392 std::unique_ptr<art::Assns<recob::PFParticle, recob::Cluster>> pfp_cls_assn(
394 std::unique_ptr<art::Assns<recob::PFParticle, recob::Shower>> pfp_shwr_assn(
396 std::unique_ptr<art::Assns<recob::PFParticle, recob::Vertex>> pfp_vx3_assn(
398 std::unique_ptr<art::Assns<recob::PFParticle, anab::CosmicTag>> pfp_cos_assn(
400 std::unique_ptr<art::Assns<recob::PFParticle, recob::Seed>> pfp_sed_assn(
403 std::unique_ptr<art::Assns<recob::Slice, recob::Cluster>> slc_cls_assn(
405 std::unique_ptr<art::Assns<recob::Slice, recob::PFParticle>> slc_pfp_assn(
407 std::unique_ptr<art::Assns<recob::Slice, recob::Hit>> slc_hit_assn(
410 std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> sp_hit_assn(
416 unsigned short slIndx;
418 unsigned short vxColIndx;
420 std::vector<slcVxStruct> vx2StrList;
422 std::vector<slcVxStruct> vx3StrList;
424 if (nInputHits > 0) {
427 unsigned int hitColBeginIndex = 0;
428 for (
unsigned short isl = 0; isl < nSlices; ++isl) {
429 unsigned short slcIndex = 0;
430 if (!slices.empty()) {
431 for (slcIndex = 0; slcIndex < slices.size(); ++slcIndex)
432 if (slices[slcIndex]->
ID() == slcIDs[isl])
break;
433 if (slcIndex == slices.size())
continue;
437 if (!slc.isValid)
continue;
439 for (
auto& vx2 : slc.vtxs) {
440 if (vx2.ID <= 0)
continue;
443 unsigned int vtxID = vx2.UID;
444 unsigned int wire = std::nearbyint(vx2.Pos[0]);
459 tmp.vxColIndx = vx2Col.size() - 1;
460 vx2StrList.push_back(tmp);
464 for (
auto& vx3 : slc.vtx3s) {
465 if (vx3.ID <= 0)
continue;
467 if (vx3.Wire >= 0)
continue;
468 unsigned int vtxID = vx3.UID;
473 vx3Col.emplace_back(xyz, vtxID);
478 tmp.vxColIndx = vx3Col.size() - 1;
479 vx3StrList.push_back(tmp);
482 for (
auto& tj : slc.tjs) {
484 hitColBeginIndex = hitCol.size();
485 for (
unsigned short ipt = tj.EndPt[0]; ipt <= tj.EndPt[1]; ++ipt) {
486 auto& tp = tj.Pts[ipt];
487 if (tp.Chg <= 0)
continue;
489 std::vector<unsigned int> tpHits;
490 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
491 if (!tp.UseHit[ii])
continue;
492 if (tp.Hits[ii] > slc.slHits.size() - 1) {
break; }
493 unsigned int allHitsIndex = slc.slHits[tp.Hits[ii]].allHitsIndex;
494 if (allHitsIndex > nInputHits - 1) {
break; }
495 tpHits.push_back(allHitsIndex);
496 if (newIndex[allHitsIndex] != UINT_MAX) {
497 std::cout <<
"Bad Slice " << isl <<
" tp.Hits " << tp.Hits[ii] <<
" allHitsIndex " 499 std::cout <<
" old newIndex " << newIndex[allHitsIndex];
500 auto& oldhit = (*inputHits)[allHitsIndex];
501 std::cout <<
" old " << oldhit.WireID().Plane <<
":" << oldhit.WireID().Wire <<
":" 502 << (
int)oldhit.PeakTime();
503 auto& newhit = hitCol[newIndex[allHitsIndex]];
504 std::cout <<
" new " << newhit.WireID().Plane <<
":" << newhit.WireID().Wire <<
":" 505 << (
int)newhit.PeakTime();
506 std::cout <<
" hitCol size " << hitCol.size();
517 for (
auto iht : tpHits) {
518 hitCol.push_back((*inputHits)[iht]);
519 newIndex[iht] = hitCol.size() - 1;
526 if (hitCol.empty())
continue;
530 for (
unsigned int indx = hitColBeginIndex; indx < hitCol.size(); ++indx) {
531 auto&
hit = hitCol[indx];
532 sumChg +=
hit.Integral();
533 sumADC +=
hit.SummedADC();
534 if (!slices.empty() &&
535 !
util::CreateAssn(*
this, evt, hitCol, slices[slcIndex], *slc_hit_assn, indx)) {
537 <<
"Failed to associate hits with Slice";
540 geo::View_t view = hitCol[hitColBeginIndex].View();
541 auto& firstTP = tj.Pts[tj.EndPt[0]];
542 auto& lastTP = tj.Pts[tj.EndPt[1]];
547 unsigned int nclhits = hitCol.size() - hitColBeginIndex + 1;
548 clsCol.emplace_back(firstTP.Pos[0],
575 *
this, evt, clsCol, hitCol, *cls_hit_assn, hitColBeginIndex, hitCol.size())) {
577 <<
"Failed to associate hits with cluster ID " << tj.UID;
580 if (!slices.empty()) {
581 if (!
util::CreateAssn(*
this, evt, clsCol, slices[slcIndex], *slc_cls_assn)) {
583 <<
"Failed to associate slice with PFParticle";
587 for (
unsigned short end = 0;
end < 2; ++
end) {
588 if (tj.VtxID[
end] <= 0)
continue;
589 for (
auto& vx2str : vx2StrList) {
590 if (vx2str.slIndx != isl)
continue;
591 if (vx2str.ID != tj.VtxID[
end])
continue;
593 *
this, evt, *cls_vx2_assn, clsCol.size() - 1, vx2str.vxColIndx,
end)) {
595 <<
"Failed to associate cluster " << tj.UID <<
" with EndPoint2D";
597 auto& vx2 = slc.vtxs[tj.VtxID[
end] - 1];
599 for (
auto vx3str : vx3StrList) {
600 if (vx3str.slIndx != isl)
continue;
601 if (vx3str.ID != vx2.Vx3ID)
continue;
603 *
this, evt, *cls_vx3_assn, clsCol.size() - 1, vx3str.vxColIndx,
end)) {
605 <<
"Failed to associate cluster " << tj.UID <<
" with Vertex";
616 for (
auto& ss3 : slc.showers) {
617 if (ss3.ID <= 0)
continue;
625 TVector3
dir = {ss3.Dir[0], ss3.Dir[1], ss3.Dir[2]};
627 TVector3 dirErr = {ss3.DirErr[0], ss3.DirErr[1], ss3.DirErr[2]};
629 TVector3
pos = {ss3.Start[0], ss3.Start[1], ss3.Start[2]};
631 TVector3 posErr = {ss3.StartErr[0], ss3.StartErr[1], ss3.StartErr[2]};
637 shwCol.push_back(shower);
639 std::vector<unsigned int> shwHits(ss3.Hits.size());
640 for (
unsigned int iht = 0; iht < ss3.Hits.size(); ++iht)
641 shwHits[iht] = newIndex[ss3.Hits[iht]];
643 *
this, evt, *shwr_hit_assn, shwCol.size() - 1, shwHits.begin(), shwHits.end())) {
645 <<
"Failed to associate hits with Shower";
651 for (
unsigned short isl = 0; isl < nSlices; ++isl) {
652 unsigned short slcIndex = 0;
653 if (!slices.empty()) {
654 for (slcIndex = 0; slcIndex < slices.size(); ++slcIndex)
655 if (slices[slcIndex]->
ID() == slcIDs[isl])
break;
656 if (slcIndex == slices.size())
continue;
660 if (!slc.isValid)
continue;
662 for (
size_t ipfp = 0; ipfp < slc.pfps.size(); ++ipfp) {
663 auto& pfp = slc.
pfps[ipfp];
664 if (pfp.ID <= 0)
continue;
666 size_t self = pfpCol.size();
667 size_t offset =
self - ipfp;
668 size_t parentIndex = UINT_MAX;
669 if (pfp.ParentUID > 0) parentIndex = pfp.ParentUID + offset - 1;
670 std::vector<size_t> dtrIndices(pfp.DtrUIDs.size());
671 for (
unsigned short idtr = 0; idtr < pfp.DtrUIDs.size(); ++idtr)
672 dtrIndices[idtr] = pfp.DtrUIDs[idtr] + offset - 1;
673 pfpCol.emplace_back(pfp.PDGCode,
self, parentIndex, dtrIndices);
676 double sp[] = {pos[0], pos[1], pos[2]};
677 double sd[] = {dir[0], dir[1], dir[2]};
678 double spe[] = {0., 0., 0.};
679 double sde[] = {0., 0., 0.};
680 sedCol.emplace_back(sp, sd, spe, sde);
682 std::vector<unsigned int> clsIndices;
683 for (
auto tuid : pfp.TjUIDs) {
684 unsigned int clsIndex = 0;
685 for (clsIndex = 0; clsIndex < clsCol.size(); ++clsIndex)
686 if (
abs(clsCol[clsIndex].
ID()) == tuid)
break;
687 if (clsIndex == clsCol.size())
continue;
688 clsIndices.push_back(clsIndex);
697 <<
"Failed to associate clusters with PFParticle";
700 if (pfp.Vx3ID[0] > 0) {
701 for (
auto vx3str : vx3StrList) {
702 if (vx3str.slIndx != isl)
continue;
703 if (vx3str.ID != pfp.Vx3ID[0])
continue;
704 std::vector<unsigned short> indx(1, vx3str.vxColIndx);
706 *
this, evt, *pfp_vx3_assn, pfpCol.size() - 1, indx.begin(), indx.end())) {
708 <<
"Failed to associate PFParticle " << pfp.UID <<
" with Vertex";
714 if (!sedCol.empty()) {
722 pfpCol.size() - 1)) {
724 <<
"Failed to associate seed with PFParticle";
728 if (!slices.empty()) {
729 if (!
util::CreateAssn(*
this, evt, pfpCol, slices[slcIndex], *slc_pfp_assn)) {
731 <<
"Failed to associate slice with PFParticle";
735 if (pfp.PDGCode == 1111) {
736 std::vector<unsigned short> shwIndex(1, 0);
737 for (
auto& ss3 : slc.showers) {
738 if (ss3.ID <= 0)
continue;
739 if (ss3.PFPIndex == ipfp)
break;
742 if (shwIndex[0] < shwCol.size()) {
750 <<
"Failed to associate shower with PFParticle";
756 std::vector<float> tempPt1, tempPt2;
757 tempPt1.push_back(-999);
758 tempPt1.push_back(-999);
759 tempPt1.push_back(-999);
760 tempPt2.push_back(-999);
761 tempPt2.push_back(-999);
762 tempPt2.push_back(-999);
765 *
this, evt, pfpCol, ctCol, *pfp_cos_assn, ctCol.size() - 1, ctCol.size())) {
767 <<
"Failed to associate CosmicTag with PFParticle";
778 for (
unsigned int allHitsIndex = 0; allHitsIndex < nInputHits; ++allHitsIndex) {
779 if (newIndex[allHitsIndex] != UINT_MAX)
continue;
780 std::vector<unsigned int> oneHit(1, allHitsIndex);
784 for (
size_t isl = 0; isl < slices.size(); ++isl) {
785 auto& hit_in_slc = hitFromSlc.at(isl);
786 for (
auto&
hit : hit_in_slc) {
787 if (
hit.key() != allHitsIndex)
continue;
792 <<
"Failed to associate old Hit with Slice";
802 for (
unsigned int allHitsIndex = 0; allHitsIndex < nInputHits; ++allHitsIndex) {
803 if (newIndex[allHitsIndex] != UINT_MAX)
continue;
804 std::vector<unsigned int> oneHit(1, allHitsIndex);
811 if (nInputHits > 0) {
816 for (
unsigned int allHitsIndex = 0; allHitsIndex < nInputHits; ++allHitsIndex) {
817 if (newIndex[allHitsIndex] == UINT_MAX)
819 auto& sp_from_hit = spFromHit.at(allHitsIndex);
820 for (
auto& sp : sp_from_hit) {
822 if (!
util::CreateAssn(*
this, evt, hitCol, sp, *sp_hit_assn, newIndex[allHitsIndex])) {
824 <<
"Failed to associate new Hit with SpacePoint";
835 std::unique_ptr<std::vector<recob::Hit>> hcol(
new std::vector<recob::Hit>(
std::move(hitCol)));
836 std::unique_ptr<std::vector<recob::Cluster>> ccol(
837 new std::vector<recob::Cluster>(
std::move(clsCol)));
838 std::unique_ptr<std::vector<recob::EndPoint2D>> v2col(
839 new std::vector<recob::EndPoint2D>(
std::move(vx2Col)));
840 std::unique_ptr<std::vector<recob::Vertex>> v3col(
841 new std::vector<recob::Vertex>(
std::move(vx3Col)));
842 std::unique_ptr<std::vector<recob::PFParticle>> pcol(
843 new std::vector<recob::PFParticle>(
std::move(pfpCol)));
844 std::unique_ptr<std::vector<recob::Seed>> sdcol(
845 new std::vector<recob::Seed>(
std::move(sedCol)));
846 std::unique_ptr<std::vector<recob::Shower>> scol(
847 new std::vector<recob::Shower>(
std::move(shwCol)));
848 std::unique_ptr<std::vector<anab::CosmicTag>> ctgcol(
849 new std::vector<anab::CosmicTag>(
std::move(ctCol)));
void PrintAll(detinfo::DetectorPropertiesData const &detProp, std::string someText)
void ClearResults()
Deletes all the results.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void set_start_point_err(const TVector3 &xyz_e)
void set_dedx_err(const std::vector< double > &q)
void set_direction_err(const TVector3 &dir_e)
EventNumber_t event() const
tca::TrajClusterAlg fTCAlg
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
The data type to uniquely identify a Plane.
void set_total_energy(const std::vector< double > &q)
void RunTrajClusterAlg(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< unsigned int > &hitsInSlice, int sliceID)
art::InputTag fSliceModuleLabel
CryostatID_t Cryostat
Index of cryostat.
void set_total_MIPenergy_err(const std::vector< double > &q)
Point3_t PosAtEnd(const PFPStruct &pfp, unsigned short end)
bool SortHits(HitLoc const &h1, HitLoc const &h2)
std::vector< std::array< unsigned int, 3 > > sptHits
SpacePoint -> Hits assns by plane.
void set_total_energy_err(const std::vector< double > &q)
static const SentryArgument_t Sentry
An instance of the sentry object.
void set_id(const int id)
bool SetInputHits(std::vector< recob::Hit > const &inputHits, unsigned int run, unsigned int event)
unsigned int Hit
set to the hit index in evt.allHits if a Plane:Wire:Tick match is found
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
art::InputTag fHitModuleLabel
void set_direction(const TVector3 &dir)
int Wire
Select hit Wire for debugging.
float unitsPerTick
scale factor from Tick to WSE equivalent units
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
bool CreateAssnD(PRODUCER const &prod, art::Event &evt, art::Assns< T, U, D > &assn, size_t first_index, size_t second_index, typename art::Assns< T, U, D >::data_t &&data)
Creates a single one-to-one association with associated data.
unsigned short GetSlicesSize() const
void set_length(const double &l)
void set_open_angle(const double &a)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
A class handling a collection of hits and its associations.
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.
const geo::GeometryCore * geom
PlaneID_t Plane
Index of the plane within its TPC.
void set_total_best_plane(const int q)
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
void set_total_MIPenergy(const std::vector< double > &q)
std::vector< TCSlice > slices
Detector simulation of raw signals on wires.
TCSlice const & GetSlice(unsigned short sliceIndex) const
art::InputTag fSpacePointModuleLabel
void GetHits(const std::vector< recob::Hit > &inputHits, const geo::TPCID &tpcid, std::vector< std::vector< unsigned int >> &tpcHits)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
int Tick
Select hit PeakTime for debugging (< 0 for vertex finding)
geo::PlaneID DecodeCTP(CTP_t CTP)
CTP_t EncodeCTP(unsigned int cryo, unsigned int tpc, unsigned int plane)
void MergeTPHits(std::vector< unsigned int > &tpHits, std::vector< recob::Hit > &newHitCol, std::vector< unsigned int > &newHitAssns) const
void SetSourceHits(std::vector< recob::Hit > const &srcHits)
std::vector< PFPStruct > pfps
void set_start_point(const TVector3 &xyz)
TPCID_t TPC
Index of the TPC within its cryostat.
void SetInputSpts(std::vector< recob::SpacePoint > const &sptHandle)
Vector3_t DirAtEnd(const PFPStruct &pfp, unsigned short end)
short recoSlice
only reconstruct the slice with ID (0 = all)
cet::coded_exception< error, detail::translate > exception
art::InputTag fSpacePointHitAssnLabel
void set_dedx(const std::vector< double > &q)