829 art::ServiceHandle<geo::Geometry const> geom;
839 spts.erase(spts.begin(), spts.end());
852 std::vector<std::vector<std::vector<std::multimap<unsigned int, art::Ptr<recob::Hit>>>>> hitmap;
855 unsigned int ncstat = geom->Ncryostats();
856 hitmap.resize(ncstat);
857 for (
unsigned int cstat = 0; cstat < ncstat; ++cstat) {
858 unsigned int ntpc = geom->Cryostat(cstat).NTPC();
859 hitmap[cstat].resize(ntpc);
860 for (
unsigned int tpc = 0; tpc < ntpc; ++tpc) {
861 int nplane = geom->Cryostat(cstat).TPC(tpc).Nplanes();
862 hitmap[cstat][tpc].resize(nplane);
866 for (art::PtrVector<recob::Hit>::const_iterator ihit = hits.begin(); ihit != hits.end();
868 const art::Ptr<recob::Hit>& phit = *ihit;
874 std::make_pair(phitWireID.
Wire, phit));
883 art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
886 for (
unsigned int cstat = 0; cstat < ncstat; ++cstat) {
887 for (
unsigned int tpc = 0; tpc < geom->Cryostat(cstat).NTPC(); ++tpc) {
888 int nplane = geom->Cryostat(cstat).TPC(tpc).Nplanes();
889 for (
int plane = 0; plane < nplane; ++plane) {
890 for (std::map<
unsigned int, art::Ptr<recob::Hit>>::const_iterator ihit =
891 hitmap[cstat][tpc][plane].
begin();
892 ihit != hitmap[cstat][tpc][plane].end();
894 const art::Ptr<recob::Hit>& phit = ihit->second;
900 mcinfo.pchit.resize(nplane, 0);
901 mcinfo.dist2.resize(nplane, 1.e20);
905 std::vector<sim::IDE> ides = bt_serv->HitToAvgSimIDEs(clockData, phit);
909 mcinfo.trackIDs.reserve(ides.size());
910 for (std::vector<sim::IDE>::const_iterator i = ides.begin(); i != ides.end(); ++i)
911 mcinfo.trackIDs.push_back(i->trackID);
912 sort(mcinfo.trackIDs.begin(), mcinfo.trackIDs.end());
917 mcinfo.xyz = bt_serv->SimIDEsToXYZ(ides);
919 catch (cet::exception&
x) {
928 for (
unsigned int cstat = 0; cstat < ncstat; ++cstat) {
929 for (
unsigned int tpc = 0; tpc < geom->Cryostat(cstat).NTPC(); ++tpc) {
930 int nplane = geom->Cryostat(cstat).TPC(tpc).Nplanes();
931 for (
int plane = 0; plane < nplane; ++plane) {
932 for (std::map<
unsigned int, art::Ptr<recob::Hit>>::const_iterator ihit =
933 hitmap[cstat][tpc][plane].
begin();
934 ihit != hitmap[cstat][tpc][plane].end();
936 const art::Ptr<recob::Hit>& phit = ihit->second;
939 if (mcinfo.xyz.size() != 0) {
940 assert(mcinfo.xyz.size() == 3);
944 for (
int plane2 = 0; plane2 < nplane; ++plane2) {
945 for (std::map<
unsigned int, art::Ptr<recob::Hit>>::const_iterator jhit =
946 hitmap[cstat][tpc][plane2].
begin();
947 jhit != hitmap[cstat][tpc][plane2].end();
949 const art::Ptr<recob::Hit>& phit2 = jhit->second;
951 const HitMCInfo& mcinfo2 =
fHitMCMap[&hit2];
953 if (mcinfo2.xyz.size() != 0) {
954 assert(mcinfo2.xyz.size() == 3);
955 double dx = mcinfo.xyz[0] - mcinfo2.xyz[0];
956 double dy = mcinfo.xyz[1] - mcinfo2.xyz[1];
957 double dz = mcinfo.xyz[2] - mcinfo2.xyz[2];
958 double dist2 = dx * dx + dy * dy + dz * dz;
959 if (dist2 < mcinfo.dist2[plane2]) {
960 mcinfo.dist2[plane2] = dist2;
961 mcinfo.pchit[plane2] = &hit2;
975 mf::LogDebug
debug(
"SpacePointAlg");
976 if (mf::isDebugEnabled()) {
977 debug <<
"Total hits = " << hits.size() <<
"\n\n";
979 for (
unsigned int cstat = 0; cstat < ncstat; ++cstat) {
980 for (
unsigned int tpc = 0; tpc < geom->Cryostat(cstat).NTPC(); ++tpc) {
981 int nplane = hitmap[cstat][tpc].size();
982 for (
int plane = 0; plane < nplane; ++plane) {
983 debug <<
"TPC, Plane: " << tpc <<
", " << plane
984 <<
", hits = " << hitmap[cstat][tpc][plane].size() <<
"\n";
996 std::multimap<sptkey_type, recob::SpacePoint> sptmap;
997 std::set<sptkey_type> sptkeys;
1000 for (
unsigned int cstat = 0; cstat < ncstat; ++cstat) {
1001 for (
unsigned int tpc = 0; tpc < geom->Cryostat(cstat).NTPC(); ++tpc) {
1016 int nplane = hitmap[cstat][tpc].size();
1017 std::vector<int> index(nplane);
1019 for (
int i = 0; i < nplane; ++i)
1022 for (
int i = 0; i < nplane - 1; ++i) {
1024 for (
int j = i + 1; j < nplane; ++j) {
1029 if ((hitmap[cstat][tpc][index[i]].
size() > hitmap[cstat][tpc][index[j]].
size() &&
1032 int temp = index[i];
1033 index[i] = index[j];
1042 std::vector<std::multimap<unsigned int, art::Ptr<recob::Hit>>>& hitsByPlaneVec =
1044 int nViewsWithHits(0);
1046 for (
int i = 0; i < nplane; i++) {
1047 if (hitsByPlaneVec[index[i]].
size() > 0) nViewsWithHits++;
1053 if ((nViewsWithHits == 2 || nplane == 2) &&
fMinViews <= 2) {
1056 for (
int i = 0; i < nplane - 1; ++i) {
1057 unsigned int plane1 = index[i];
1059 if (hitmap[cstat][tpc][plane1].
empty())
continue;
1061 for (
int j = i + 1; j < nplane; ++j) {
1062 unsigned int plane2 = index[j];
1064 if (hitmap[cstat][tpc][plane2].
empty())
continue;
1067 const geo::WireGeo& wgeo2 = geom->Cryostat(cstat).TPC(tpc).Plane(plane2).Wire(0);
1068 double hl2 = wgeo2.
HalfL();
1073 double s2 = (xyz22[1] - xyz21[1]) / (2. * hl2);
1074 double c2 = (xyz22[2] - xyz21[2]) / (2. * hl2);
1075 double dist2 = -xyz21[1] * c2 + xyz21[2] * s2;
1076 double pitch2 = geom->WirePitch(plane2, tpc, cstat);
1079 hitmap[cstat][tpc][plane1].
size() > hitmap[cstat][tpc][plane2].
size())
1080 throw cet::exception(
"SpacePointAlg")
1081 <<
"makeSpacePoints(): hitmaps with incompatible size\n";
1085 art::PtrVector<recob::Hit> hitvec;
1088 for (std::map<
unsigned int, art::Ptr<recob::Hit>>::const_iterator ihit1 =
1089 hitmap[cstat][tpc][plane1].
begin();
1090 ihit1 != hitmap[cstat][tpc][plane1].end();
1093 const art::Ptr<recob::Hit>& phit1 = ihit1->second;
1095 const geo::WireGeo& wgeo = geom->WireIDToWireGeo(phit1WireID);
1099 assert(phit1WireID.
Cryostat == cstat);
1100 assert(phit1WireID.
TPC == tpc);
1101 assert(phit1WireID.
Plane == plane1);
1102 double hl1 = wgeo.
HalfL();
1110 double wire21 = (-xyz1[1] * c2 + xyz1[2] * s2 - dist2) / pitch2;
1111 double wire22 = (-xyz2[1] * c2 + xyz2[2] * s2 - dist2) / pitch2;
1113 int wmin = std::max(0., std::min(wire21, wire22));
1114 int wmax = std::max(0., std::max(wire21, wire22) + 1.);
1116 std::map<unsigned int, art::Ptr<recob::Hit>>::const_iterator
1117 ihit2 = hitmap[cstat][tpc][plane2].lower_bound(wmin),
1118 ihit2end = hitmap[cstat][tpc][plane2].upper_bound(wmax);
1120 for (; ihit2 != ihit2end; ++ihit2) {
1122 const art::Ptr<recob::Hit>& phit2 = ihit2->second;
1129 hitvec.push_back(phit1);
1130 hitvec.push_back(phit2);
1145 std::vector<recob::SpacePoint> sptv;
1147 sptkey_type key = &*phit2;
1148 sptmap.insert(std::pair<sptkey_type, recob::SpacePoint>(key, sptv.back()));
1149 sptkeys.insert(key);
1164 art::PtrVector<recob::Hit> hitvec;
1167 unsigned int plane1 = index[0];
1168 unsigned int plane2 = index[1];
1169 unsigned int plane3 = index[2];
1173 const geo::WireGeo& wgeo1 = geom->Cryostat(cstat).TPC(tpc).Plane(plane1).Wire(0);
1174 double hl1 = wgeo1.
HalfL();
1179 double s1 = (xyz12[1] - xyz11[1]) / (2. * hl1);
1180 double c1 = (xyz12[2] - xyz11[2]) / (2. * hl1);
1181 double dist1 = -xyz11[1] * c1 + xyz11[2] * s1;
1182 double pitch1 = geom->WirePitch(plane1, tpc, cstat);
1183 const double TicksOffset1 =
detProp.GetXTicksOffset(plane1, tpc, cstat);
1187 const geo::WireGeo& wgeo2 = geom->Cryostat(cstat).TPC(tpc).Plane(plane2).Wire(0);
1188 double hl2 = wgeo2.
HalfL();
1193 double s2 = (xyz22[1] - xyz21[1]) / (2. * hl2);
1194 double c2 = (xyz22[2] - xyz21[2]) / (2. * hl2);
1195 double dist2 = -xyz21[1] * c2 + xyz21[2] * s2;
1196 double pitch2 = geom->WirePitch(plane2, tpc, cstat);
1197 const double TicksOffset2 =
detProp.GetXTicksOffset(plane2, tpc, cstat);
1201 const geo::WireGeo& wgeo3 = geom->Cryostat(cstat).TPC(tpc).Plane(plane3).Wire(0);
1202 double hl3 = wgeo3.
HalfL();
1207 double s3 = (xyz32[1] - xyz31[1]) / (2. * hl3);
1208 double c3 = (xyz32[2] - xyz31[2]) / (2. * hl3);
1209 double dist3 = -xyz31[1] * c3 + xyz31[2] * s3;
1210 double pitch3 = geom->WirePitch(plane3, tpc, cstat);
1211 const double TicksOffset3 =
detProp.GetXTicksOffset(plane3, tpc, cstat);
1215 double s12 = s1 * c2 - s2 * c1;
1216 double s23 = s2 * c3 - s3 * c2;
1217 double s31 = s3 * c1 - s1 * c3;
1221 std::map<unsigned int, art::Ptr<recob::Hit>>::const_iterator
1222 ihit1 = hitmap[cstat][tpc][plane1].begin(),
1223 ihit1end = hitmap[cstat][tpc][plane1].end();
1224 for (; ihit1 != ihit1end; ++ihit1) {
1226 unsigned int wire1 = ihit1->first;
1227 const art::Ptr<recob::Hit>& phit1 = ihit1->second;
1229 const geo::WireGeo& wgeo = geom->WireIDToWireGeo(phit1WireID);
1233 assert(phit1WireID.
Cryostat == cstat);
1234 assert(phit1WireID.
TPC == tpc);
1235 assert(phit1WireID.
Plane == plane1);
1236 assert(phit1WireID.
Wire == wire1);
1237 double hl1 = wgeo.
HalfL();
1245 double t1 = phit1->PeakTime() - TicksOffset1;
1246 double u1 = wire1 * pitch1 + dist1;
1250 double wire21 = (-xyz1[1] * c2 + xyz1[2] * s2 - dist2) / pitch2;
1251 double wire22 = (-xyz2[1] * c2 + xyz2[2] * s2 - dist2) / pitch2;
1253 int wmin = std::max(0., std::min(wire21, wire22));
1254 int wmax = std::max(0., std::max(wire21, wire22) + 1.);
1256 std::map<unsigned int, art::Ptr<recob::Hit>>::const_iterator
1257 ihit2 = hitmap[cstat][tpc][plane2].lower_bound(wmin),
1258 ihit2end = hitmap[cstat][tpc][plane2].upper_bound(wmax);
1260 for (; ihit2 != ihit2end; ++ihit2) {
1262 int wire2 = ihit2->first;
1263 const art::Ptr<recob::Hit>& phit2 = ihit2->second;
1267 double t2 = phit2->PeakTime() - TicksOffset2;
1278 hitvec.push_back(phit1);
1279 hitvec.push_back(phit2);
1285 double u2 = wire2 * pitch2 + dist2;
1289 double u3pred = (-u1 * s23 - u2 * s31) / s12;
1290 double w3pred = (u3pred - dist3) / pitch3;
1292 int w3min = std::max(0., std::ceil(w3pred - w3delta));
1293 int w3max = std::max(0., std::floor(w3pred + w3delta));
1295 std::map<unsigned int, art::Ptr<recob::Hit>>::const_iterator
1296 ihit3 = hitmap[cstat][tpc][plane3].lower_bound(w3min),
1297 ihit3end = hitmap[cstat][tpc][plane3].upper_bound(w3max);
1299 for (; ihit3 != ihit3end; ++ihit3) {
1301 int wire3 = ihit3->first;
1302 const art::Ptr<recob::Hit>& phit3 = ihit3->second;
1306 double t3 = phit3->PeakTime() - TicksOffset3;
1315 double u3 = wire3 * pitch3 + dist3;
1316 double S = s23 * u1 + s31 * u2 + s12 * u3;
1323 hitvec.push_back(phit1);
1324 hitvec.push_back(phit2);
1325 hitvec.push_back(phit3);
1340 std::vector<recob::SpacePoint> sptv;
1342 sptkey_type key = &*phit3;
1344 std::pair<sptkey_type, recob::SpacePoint>(key, sptv.back()));
1345 sptkeys.insert(key);
1362 spts.reserve(spts.size() + sptkeys.size());
1367 for (std::set<sptkey_type>::const_iterator i = sptkeys.begin(); i != sptkeys.end(); ++i) {
1368 sptkey_type key = *i;
1373 double best_chisq = 0.;
1376 for (std::multimap<sptkey_type, recob::SpacePoint>::const_iterator j =
1377 sptmap.lower_bound(key);
1378 j != sptmap.upper_bound(key);
1381 if (best_spt == 0 || spt.
Chisq() < best_chisq) {
1383 best_chisq = spt.
Chisq();
1390 throw cet::exception(
"SpacePointAlg") <<
"makeSpacePoints(): no best point\n";
1391 spts.push_back(*best_spt);
1405 spts.reserve(spts.size() + sptkeys.size());
1410 for (std::set<sptkey_type>::const_iterator i = sptkeys.begin(); i != sptkeys.end(); ++i) {
1411 sptkey_type key = *i;
1417 std::multimap<sptkey_type, recob::SpacePoint>::const_iterator jSPT =
1418 sptmap.lower_bound(key),
1420 sptmap.upper_bound(key);
1422 art::PtrVector<recob::Hit> merged_hits;
1423 for (; jSPT != jSPTend; ++jSPT) {
1430 merged_hits.reserve(merged_hits.size() +
1432 for (art::PtrVector<recob::Hit>::const_iterator
k = spt_hits.begin();
1433 k != spt_hits.end();
1435 const art::Ptr<recob::Hit>& hit = *
k;
1436 merged_hits.push_back(hit);
1442 std::sort(merged_hits.begin(), merged_hits.end());
1443 art::PtrVector<recob::Hit>::iterator it =
1444 std::unique(merged_hits.begin(), merged_hits.end());
1445 merged_hits.erase(it, merged_hits.end());
1464 spts.reserve(spts.size() + sptkeys.size());
1468 for (std::multimap<sptkey_type, recob::SpacePoint>::const_iterator j = sptmap.begin();
1472 spts.push_back(spt);
1483 if (mf::isDebugEnabled()) {
1484 debug <<
"\n2-hit space points = " << n2 <<
"\n"
1485 <<
"3-hit space points = " << n3 <<
"\n"
1486 <<
"2-hit filtered/merged space points = " << n2filt <<
"\n"
1487 <<
"3-hit filtered/merged space points = " << n3filt;
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
see a below echo S(symbol in a section other than those above)
std::map< const recob::Hit *, HitMCInfo > fHitMCMap
double fMaxDT
Maximum time difference between planes.
process_name opflash particleana ie x
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
void update(detinfo::DetectorPropertiesData const &detProp) const
The data type to uniquely identify a Plane.
bool fEnableW
Enable flag (W).
CryostatID_t Cryostat
Index of cryostat.
std::size_t size(FixedBins< T, C > const &) noexcept
Planes which measure Z direction.
WireID_t Wire
Index of the wire within its plane.
const art::PtrVector< recob::Hit > & getAssociatedHits(const recob::SpacePoint &spt) const
bool fEnableU
Enable flag (U).
std::map< int, art::PtrVector< recob::Hit > > fSptHitMap
void fillComplexSpacePoint(detinfo::DetectorPropertiesData const &detProp, const art::PtrVector< recob::Hit > &hits, std::vector< recob::SpacePoint > &sptv, int sptid) const
double fMaxS
Maximum space separation between wires.
The data type to uniquely identify a TPC.
PlaneID_t Plane
Index of the plane within its TPC.
bool fPreferColl
Sort by collection wire.
auto begin(FixedBins< T, C > const &) noexcept
double HalfL() const
Returns half the length of the wire [cm].
bool compatible(detinfo::DetectorPropertiesData const &detProp, const art::PtrVector< recob::Hit > &hits, bool useMC=false) const
constexpr WireID()=default
Default constructor: an invalid TPC ID.
int fMinViews
Mininum number of views per space point.
2D representation of charge deposited in the TDC/wire plane
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
TPCID_t TPC
Index of the TPC within its cryostat.
void fillSpacePoint(detinfo::DetectorPropertiesData const &detProp, const art::PtrVector< recob::Hit > &hits, std::vector< recob::SpacePoint > &sptv, int sptid) const
bool empty(FixedBins< T, C > const &) noexcept
Signal from collection planes.
bool fEnableV
Enable flag (V).