128 auto const det_prop =
132 std::vector<art::Ptr<recob::Hit>>
hit;
143 unsigned int numberwires = 0;
144 const unsigned int numbertimesamples = det_prop.ReadOutWindowSize();
145 const float TicksPerBin = numbertimesamples /
fTimeBins;
147 double MatrixAAsum = 0.;
148 double MatrixBBsum = 0.;
149 double MatrixCCsum = 0.;
150 std::vector<double> Cornerness2;
153 double wx[49] = {0.};
154 double wy[49] = {0.};
156 for (
int i = -3; i < 4; ++i) {
157 for (
int j = 3; j > -4; --j) {
165 unsigned int wire = 0;
166 unsigned int wire2 = 0;
167 for (
auto view : wireReadoutGeom.Views()) {
172 while (clusterIter != clusIn.
end()) {
173 if ((*clusterIter)->View() == view) {
174 hit = fmh.at(cinctr);
180 if (hit.size() == 0)
continue;
183 numberwires = wireReadoutGeom.Plane(wid.
asPlaneID()).Nwires();
184 mf::LogInfo(
"EndPointAlg") <<
" --- endpoints check " << numberwires <<
" " << numbertimesamples
187 std::vector<std::vector<double>> MatrixAsum(numberwires);
188 std::vector<std::vector<double>> MatrixBsum(numberwires);
189 std::vector<std::vector<double>> hit_map(numberwires);
192 std::vector<std::vector<int>> hit_loc(numberwires);
194 std::vector<std::vector<double>> Cornerness(numberwires);
196 for (
unsigned int wi = 0; wi < numberwires; ++wi) {
197 hit_map[wi].resize(fTimeBins, 0);
198 hit_loc[wi].resize(fTimeBins, -1);
199 Cornerness[wi].resize(fTimeBins, 0);
200 MatrixAsum[wi].resize(fTimeBins, 0);
201 MatrixBsum[wi].resize(fTimeBins, 0);
203 for (
unsigned int i = 0; i < hit.size(); ++i) {
204 wire = hit[i]->WireID().Wire;
205 const float center = hit[i]->PeakTime(), sigma = hit[i]->RMS();
206 const int iFirstBin = int((center - 3 * sigma) / TicksPerBin),
207 iLastBin = int((center + 3 * sigma) / TicksPerBin);
208 for (
int iBin = iFirstBin; iBin <= iLastBin; ++iBin) {
209 const float bin_center = iBin * TicksPerBin;
210 hit_map[wire][iBin] +=
Gaussian(bin_center, center, sigma);
215 for (
unsigned int wire = 1; wire < numberwires - 1; ++wire) {
217 for (
int timebin = 1; timebin < fTimeBins - 1; ++timebin) {
218 MatrixAsum[wire][timebin] = 0.;
219 MatrixBsum[wire][timebin] = 0.;
221 for (
int i = -3; i <= 3; ++i) {
223 if (windex < 0) windex = 0;
225 else if ((
unsigned int)windex >= numberwires)
226 windex = numberwires - 1;
228 for (
int j = -3; j <= 3; ++j) {
229 tindex = timebin + j;
232 else if (tindex >= fTimeBins)
233 tindex = fTimeBins - 1;
235 MatrixAsum[wire][timebin] += wx[
n] * hit_map[windex][tindex];
236 MatrixBsum[wire][timebin] += wy[
n] * hit_map[windex][tindex];
244 for (
unsigned int wire = 1; wire < numberwires - 1; ++wire) {
246 for (
int timebin = 1; timebin < fTimeBins - 1; ++timebin) {
252 for (
int i = -3; i <= 3; ++i) {
254 if (windex < 0) windex = 0;
256 else if ((
unsigned int)windex >= numberwires)
257 windex = numberwires - 1;
259 for (
int j = -3; j <= 3; ++j) {
260 tindex = timebin + j;
263 else if (tindex >= fTimeBins)
264 tindex = fTimeBins - 1;
266 MatrixAAsum += w[
n] * pow(MatrixAsum[windex][tindex], 2);
267 MatrixBBsum += w[
n] * pow(MatrixBsum[windex][tindex], 2);
268 MatrixCCsum += w[
n] * MatrixAsum[windex][tindex] * MatrixBsum[windex][tindex];
273 if ((MatrixAAsum + MatrixBBsum) > 0)
274 Cornerness[wire][timebin] =
275 (MatrixAAsum * MatrixBBsum - pow(MatrixCCsum, 2)) / (MatrixAAsum + MatrixBBsum);
277 Cornerness[wire][timebin] = 0;
279 if (Cornerness[wire][timebin] > 0) {
280 for (
unsigned int i = 0; i < hit.size(); ++i) {
281 wire2 = hit[i]->WireID().Wire;
283 if (wire == wire2 &&
std::abs(hit[i]->TimeDistanceAsRMS(
284 timebin * (numbertimesamples / fTimeBins))) < 1.) {
286 hit_loc[wire][timebin] = i;
287 Cornerness2.push_back(Cornerness[wire][timebin]);
295 std::sort(Cornerness2.rbegin(), Cornerness2.rend());
297 auto const& plane = wireReadoutGeom.Plane({0, 0, 0});
298 for (
int vertexnum = 0; vertexnum <
fMaxCorners; ++vertexnum) {
300 for (
unsigned int wire = 0; wire < numberwires && flag == 0; ++wire) {
301 for (
int timebin = 0; timebin < fTimeBins && flag == 0; ++timebin) {
302 if (Cornerness2.size() > (
unsigned int)vertexnum)
303 if (Cornerness[wire][timebin] == Cornerness2[vertexnum] &&
304 Cornerness[wire][timebin] > 0. && hit_loc[wire][timebin] > -1) {
308 if (Cornerness2.size())
309 if (Cornerness[wire][timebin] < (
fThreshold * Cornerness2[0]))
310 vertexnum = fMaxCorners;
311 vHits.
push_back(hit[hit_loc[wire][timebin]]);
315 for (
size_t vh = 0; vh < vHits.
size(); ++vh)
316 totalQ += vHits[vh]->Integral();
319 hit[hit_loc[wire][timebin]]->
WireID(),
320 Cornerness[wire][timebin],
324 vtxcol.push_back(endpoint);
325 vtxHitsOut.push_back(vHits);
333 double drifttick = det_prop.DriftVelocity(det_prop.Efield(), det_prop.Temperature());
335 double wirepitch = plane.WirePitch();
336 double corrfactor = drifttick / wirepitch;
340 (
int)((
fWindow * (numbertimesamples / fTimeBins) * corrfactor) + .5);
342 (int)wire + (
int)((
fWindow * (numbertimesamples /
fTimeBins) * corrfactor) + .5);
344 for (
int timebinout = timebin -
fWindow; timebinout <= timebin +
fWindow;
346 if (std::sqrt(pow(wire - wireout, 2) + pow(timebin - timebinout, 2)) <
348 Cornerness[wireout][timebinout] = 0;
357 if (clusterIter != clusIn.
end()) clusterIter++;
360 unsigned char* outPix =
new unsigned char[fTimeBins * numberwires];
367 for (
unsigned int x = 0;
x < numberwires; ++
x) {
368 cell = (int)(hit_map[
x][
y] * 1000);
369 if (cell > maxCell) { maxCell = cell; }
373 for (
unsigned int x = 0;
x < numberwires; ++
x) {
375 if (maxCell > 0) pix = (int)((1500000 * hit_map[
x][
y]) / maxCell);
376 outPix[y * numberwires +
x] = pix;
382 for (
unsigned int ii = 0; ii < vtxcol.size(); ++ii) {
383 if (vtxcol[ii].View() == (
unsigned int)view) {
385 outPix[(int)(vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) * numberwires +
386 vtxcol[ii].WireID().Wire] = pix;
387 outPix[(int)(vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) * numberwires +
388 vtxcol[ii].WireID().Wire - 1] = pix;
389 outPix[(int)(vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) * numberwires +
390 vtxcol[ii].WireID().Wire + 1] = pix;
391 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) - 1) *
393 vtxcol[ii].
WireID().Wire] = pix;
394 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) + 1) *
396 vtxcol[ii].
WireID().Wire] = pix;
397 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) - 1) *
399 vtxcol[ii].
WireID().Wire - 1] = pix;
400 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) - 1) *
402 vtxcol[ii].
WireID().Wire - 2] = pix;
403 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) + 1) *
405 vtxcol[ii].
WireID().Wire + 1] = pix;
406 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) + 1) *
408 vtxcol[ii].
WireID().Wire + 2] = pix;
420 return vtxcol.size();
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
constexpr auto abs(T v)
Returns the absolute value of the argument.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
void VSSaveBMPFile(const char *fileName, unsigned char *pix, int dx, int dy) const
typename data_t::const_iterator const_iterator
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void push_back(Ptr< U > const &p)
PlaneID_t Plane
Index of the plane within its TPC.
double GaussianDerivativeY(int x, int y) const
Detector simulation of raw signals on wires.
double Gaussian(int x, int y, double sigma) const
double GaussianDerivativeX(int x, int y) const
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
constexpr PlaneID const & asPlaneID() const
Conversion to WireID (for convenience of notation).