90 auto scol = std::make_unique<std::vector<recob::Slice>>();
91 auto slc_hit_assn = std::make_unique<art::Assns<recob::Slice, recob::Hit>>();
92 auto slc_sps_assn = std::make_unique<art::Assns<recob::Slice, recob::SpacePoint>>();
98 std::vector<art::Ptr<recob::Hit>> hits;
99 art::fill_ptr_vector(hits, hitsHandle);
102 std::vector<art::Ptr<recob::SpacePoint>> sps;
103 art::fill_ptr_vector(sps, spsHandle);
106 if (!spFromHit.isValid()) {
111 static bool first =
true;
113 bool success =
false;
114 bool foundsps =
false;
115 for (
auto&
hit : hits) {
116 auto& sps = spFromHit.at(
hit.key());
117 if (sps.empty())
continue;
118 success = (sps[0].id() == spsHandle.id());
122 if ((!success) && foundsps)
123 throw cet::exception(
"DBCluster3D")
124 <<
"HitModuleLabel, SpacePointModuleLabel and SPHitAssnLabel are inconsistent\n";
129 if (!hitFromSp.isValid()) {
142 if (maxid >= 0) nslc = maxid + 1;
145 std::vector<std::vector<art::Ptr<recob::Hit>>> slcHits(nslc);
147 std::map<geo::PlaneID, std::vector<std::pair<art::Ptr<recob::Hit>,
unsigned int>>> hitmap;
148 for (
auto&
hit : hits) {
149 auto& sps = spFromHit.at(
hit.key());
160 for (
auto&
hit : hits) {
162 for (
size_t i = 0; i < slcHits.size(); ++i) {
163 if (std::find(slcHits[i].
begin(), slcHits[i].
end(),
hit) != slcHits[i].end()) {
171 double x0 =
hit->WireID().Wire;
172 double y0 =
hit->PeakTime() * UnitsPerTick;
173 double mindis = DBL_MAX;
174 unsigned slcIndex = UINT_MAX;
176 double dx = hit2.first->WireID().Wire - x0;
177 double dy = hit2.first->PeakTime() * UnitsPerTick - y0;
178 double dis = dx * dx + dy * dy;
181 slcIndex = hit2.second;
184 if (slcIndex != UINT_MAX && mindis <
fMinHitDis) { slcHits[slcIndex].push_back(
hit); }
189 std::vector<std::vector<art::Ptr<recob::SpacePoint>>> sps_in_slc(nslc);
197 for (
size_t isl = 0; isl < nslc; ++isl) {
198 double sum = sps_in_slc[isl].size();
200 double center[3] = {0.};
202 float charge = slcHits[isl].size();
203 for (
auto& spt : sps_in_slc[isl]) {
204 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
205 center[xyz] += spt->XYZ()[xyz];
207 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
210 double sumx = 0, sumy = 0., sumz = 0., sumx2 = 0, sumy2 = 0, sumz2 = 0;
211 double sumxy = 0, sumxz = 0;
212 for (
auto& spt : sps_in_slc[isl]) {
213 double xx = spt->XYZ()[0] - center[0];
214 double yy = spt->XYZ()[1] - center[1];
215 double zz = spt->XYZ()[2] - center[2];
225 double delta = sum * sumx2 - sumx * sumx;
226 if (delta <= 0)
continue;
228 double dydx = (sumxy * sum - sumx * sumy) / delta;
229 double dzdx = (sumxz * sum - sumx * sumz) / delta;
232 double norm = std::sqrt(1 + dydx * dydx + dzdx * dzdx);
233 direction[0] = 1 /
norm;
234 direction[1] = dydx /
norm;
235 direction[2] = dzdx /
norm;
237 unsigned int imax = 0, imin = 0;
238 float minAlong = 1E6, maxAlong = -1E6;
240 for (
unsigned int ipt = 0; ipt < sps_in_slc[isl].size(); ++ipt) {
241 auto& spt = sps_in_slc[isl][ipt];
242 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
243 tmpVec[xyz] = spt->XYZ()[xyz] - center[xyz];
245 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
246 dotp += tmpVec[xyz] * direction[xyz];
247 if (dotp < minAlong) {
251 if (dotp > maxAlong) {
258 float aspectRatio = 0;
259 double arg = sum * sumy2 - sumy * sumy;
261 aspectRatio +=
std::abs(sum * sumxy - sumx * sumy) / sqrt(delta * arg);
264 arg = sum * sumz2 - sumz * sumz;
266 aspectRatio +=
std::abs(sum * sumxz - sumx * sumz) / sqrt(delta * arg);
269 if (cnt > 1) aspectRatio /= cnt;
271 Point_t ctr(center[0], center[1], center[2]);
272 Vector_t dir(direction[0], direction[1], direction[2]);
273 auto pos0 = sps_in_slc[isl][imin]->XYZ();
274 Point_t ep0(pos0[0], pos0[1], pos0[2]);
275 auto pos1 = sps_in_slc[isl][imax]->XYZ();
276 Point_t ep1(pos1[0], pos1[1], pos1[2]);
277 scol->emplace_back(
id, ctr,
dir, ep0, ep1, aspectRatio, charge);
282 evt.put(std::move(scol));
283 evt.put(std::move(slc_hit_assn));
284 evt.put(std::move(slc_sps_assn));
geo::GeometryCore const * fGeom
The data type to uniquely identify a Plane.
const art::InputTag fSpacePointModuleLabel
const art::InputTag fHitModuleLabel
const art::InputTag fSPHitAssnLabel
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
recob::tracking::Point_t Point_t
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
void init(const std::vector< art::Ptr< recob::SpacePoint >> &sps, art::FindManyP< recob::Hit > &hitFromSp)
auto end(FixedBins< T, C > const &) noexcept
auto norm(Vector const &v)
Return norm of the specified vector.
auto begin(FixedBins< T, C > const &) noexcept
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.
std::vector< point_t > points
recob::tracking::Vector_t Vector_t
BEGIN_PROLOG could also be cout