839 spts.erase(spts.begin(), spts.end());
852 std::vector<std::vector<std::vector<std::multimap<unsigned int, art::Ptr<recob::Hit>>>>> hitmap;
856 hitmap.resize(ncstat);
857 for (
unsigned int cstat = 0; cstat < ncstat; ++cstat) {
859 hitmap[cstat].resize(ntpc);
860 for (
unsigned int tpc = 0; tpc < ntpc; ++tpc) {
862 hitmap[cstat][tpc].resize(nplane);
874 std::make_pair(phitWireID.
Wire, phit));
886 for (
unsigned int cstat = 0; cstat < ncstat; ++cstat) {
887 for (
unsigned int tpc = 0; tpc < geom->
Cryostat(cstat).
NTPC(); ++tpc) {
889 for (
int plane = 0; plane < nplane; ++plane) {
891 hitmap[cstat][tpc][plane].
begin();
892 ihit != hitmap[cstat][tpc][plane].end();
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());
911 mcinfo.trackIDs.push_back(i->trackID);
912 sort(mcinfo.trackIDs.begin(), mcinfo.trackIDs.end());
928 for (
unsigned int cstat = 0; cstat < ncstat; ++cstat) {
929 for (
unsigned int tpc = 0; tpc < geom->
Cryostat(cstat).
NTPC(); ++tpc) {
931 for (
int plane = 0; plane < nplane; ++plane) {
933 hitmap[cstat][tpc][plane].
begin();
934 ihit != hitmap[cstat][tpc][plane].end();
939 if (mcinfo.xyz.size() != 0) {
940 assert(mcinfo.xyz.size() == 3);
944 for (
int plane2 = 0; plane2 < nplane; ++plane2) {
946 hitmap[cstat][tpc][plane2].
begin();
947 jhit != hitmap[cstat][tpc][plane2].end();
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;
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) {
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;
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())
1081 <<
"makeSpacePoints(): hitmaps with incompatible size\n";
1089 hitmap[cstat][tpc][plane1].
begin();
1090 ihit1 != hitmap[cstat][tpc][plane1].end();
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;
1117 ihit2 = hitmap[cstat][tpc][plane2].lower_bound(wmin),
1118 ihit2end = hitmap[cstat][tpc][plane2].upper_bound(wmax);
1120 for (; ihit2 != ihit2end; ++ihit2) {
1131 bool ok =
compatible(detProp, hitvec, useMC);
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);
1167 unsigned int plane1 =
index[0];
1168 unsigned int plane2 =
index[1];
1169 unsigned int plane3 =
index[2];
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);
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);
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;
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;
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;
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;
1267 double t2 = phit2->
PeakTime() - TicksOffset2;
1280 bool h12ok =
compatible(detProp, hitvec, useMC);
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));
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;
1306 double t3 = phit3->
PeakTime() - TicksOffset3;
1315 double u3 = wire3 * pitch3 + dist3;
1316 double S = s23 * u1 + s31 * u2 + s12 * u3;
1326 bool h123ok =
compatible(detProp, hitvec, useMC);
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());
1368 sptkey_type
key = *i;
1373 double best_chisq = 0.;
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());
1411 sptkey_type key = *i;
1418 sptmap.lower_bound(key),
1420 sptmap.upper_bound(key);
1423 for (; jSPT != jSPTend; ++jSPT) {
1433 k != spt_hits.
end();
1442 std::sort(merged_hits.
begin(), merged_hits.
end());
1444 std::unique(merged_hits.
begin(), merged_hits.
end());
1445 merged_hits.
erase(it, merged_hits.
end());
1464 spts.reserve(spts.size() + sptkeys.size());
1472 spts.push_back(spt);
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...
void reserve(size_type n)
typename data_t::iterator iterator
std::map< const recob::Hit *, HitMCInfo > fHitMCMap
double fMaxDT
Maximum time difference between planes.
WireGeo const & Wire(unsigned int iwire) const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
geo::WireID WireID() const
unsigned int Nplanes() const
Number of planes in this tpc.
void update(detinfo::DetectorPropertiesData const &detProp) const
The data type to uniquely identify a Plane.
bool fEnableW
Enable flag (W).
iterator erase(iterator position)
CryostatID_t Cryostat
Index of cryostat.
Planes which measure Z direction.
geo::View_t View() const
View for the plane of the hit.
WireID_t Wire
Index of the wire within its plane.
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
const art::PtrVector< recob::Hit > & getAssociatedHits(const recob::SpacePoint &spt) const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
typename data_t::const_iterator const_iterator
bool fEnableU
Enable flag (U).
void push_back(Ptr< U > const &p)
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
unsigned int NTPC() const
Number of TPCs in this cryostat.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
double fMaxS
Maximum space separation between wires.
static int max(int a, int b)
The data type to uniquely identify a TPC.
PlaneID_t Plane
Index of the plane within its TPC.
bool fPreferColl
Sort by collection wire.
Detector simulation of raw signals on wires.
double HalfL() const
Returns half the length of the wire [cm].
float PeakTime() const
Time of the signal peak, in tick units.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
std::vector< sim::IDE > HitToAvgSimIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
bool compatible(detinfo::DetectorPropertiesData const &detProp, const art::PtrVector< recob::Hit > &hits, bool useMC=false) const
int fMinViews
Mininum number of views per space point.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
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
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Signal from collection planes.
bool fEnableV
Enable flag (V).
WireGeo const & WireIDToWireGeo(geo::WireID const &wireid) const