28 #include "art/Framework/Principal/Event.h"
29 #include "art/Framework/Services/Registry/ServiceHandle.h"
30 #include "canvas/Persistency/Common/Assns.h"
31 #include "canvas/Persistency/Common/FindManyP.h"
32 #include "canvas/Persistency/Common/Ptr.h"
33 #include "cetlib/pow.h"
34 #include "messagefacility/MessageLogger/MessageLogger.h"
52 fGsigma = p.get<
double>(
"Gsigma");
62 double const Norm = 1. / std::sqrt(2 * TMath::Pi() * cet::square(sigma));
63 return Norm *
exp(-cet::sum_of_squares(x, y) / (2 * cet::square(sigma)));
70 double const Norm = 1. / (std::sqrt(2 * TMath::Pi()) *
cet::cube(fGsigma));
71 return Norm * (-
x) *
exp(-cet::sum_of_squares(x, y) / (2 * cet::square(fGsigma)));
78 double const Norm = 1. / (std::sqrt(2 * TMath::Pi()) *
cet::cube(fGsigma));
79 return Norm * (-
y) *
exp(-cet::sum_of_squares(x, y) / (2 * cet::square(fGsigma)));
87 std::ofstream bmpFile(fileName, std::ios::binary);
88 bmpFile.write(
"B", 1);
89 bmpFile.write(
"M", 1);
90 int bitsOffset = 54 + 256 * 4;
91 int size = bitsOffset + dx * dy;
92 bmpFile.write((
const char*)&size, 4);
94 bmpFile.write((
const char*)&reserved, 4);
95 bmpFile.write((
const char*)&bitsOffset, 4);
97 bmpFile.write((
const char*)&bmiSize, 4);
98 bmpFile.write((
const char*)&dx, 4);
99 bmpFile.write((
const char*)&dy, 4);
101 bmpFile.write((
const char*)&planes, 2);
103 bmpFile.write((
const char*)&bitCount, 2);
105 for (i = 0; i < 6; i++)
106 bmpFile.write((
const char*)&temp, 4);
110 for (i = 0; i < 256; i++) {
114 bmpFile.write(lutEntry,
sizeof lutEntry);
117 bmpFile.write((
const char*)pix, dx * dy);
123 std::vector<recob::EndPoint2D>& vtxcol,
124 std::vector<art::PtrVector<recob::Hit>>& vtxHitsOut,
125 art::Event
const&
evt,
126 std::string
const& label)
const
129 art::ServiceHandle<geo::Geometry const> geom;
130 auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
131 auto const det_prop =
132 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clock_data);
135 std::vector<art::Ptr<recob::Hit>>
hit;
137 art::FindManyP<recob::Hit> fmh(clusIn, evt, label);
146 unsigned int numberwires = 0;
147 const unsigned int numbertimesamples = det_prop.ReadOutWindowSize();
148 const float TicksPerBin = numbertimesamples / fTimeBins;
150 double MatrixAAsum = 0.;
151 double MatrixBBsum = 0.;
152 double MatrixCCsum = 0.;
153 std::vector<double> Cornerness2;
156 double wx[49] = {0.};
157 double wy[49] = {0.};
159 for (
int i = -3; i < 4; ++i) {
160 for (
int j = 3; j > -4; --j) {
161 w[ctr] = Gaussian(i, j, fGsigma);
162 wx[ctr] = GaussianDerivativeX(i, j);
163 wy[ctr] = GaussianDerivativeY(i, j);
168 unsigned int wire = 0;
169 unsigned int wire2 = 0;
170 for (
auto view : geom->Views()) {
171 art::PtrVector<recob::Hit> vHits;
172 art::PtrVector<recob::Cluster>::const_iterator clusterIter = clusIn.begin();
175 while (clusterIter != clusIn.end()) {
176 if ((*clusterIter)->View() == view) {
177 hit = fmh.at(cinctr);
183 if (hit.size() == 0)
continue;
186 numberwires = geom->Cryostat(wid.
Cryostat).TPC(wid.
TPC).Plane(wid.
Plane).Nwires();
187 mf::LogInfo(
"EndPointAlg") <<
" --- endpoints check " << numberwires <<
" " << numbertimesamples
190 std::vector<std::vector<double>> MatrixAsum(numberwires);
191 std::vector<std::vector<double>> MatrixBsum(numberwires);
192 std::vector<std::vector<double>> hit_map(numberwires);
195 std::vector<std::vector<int>> hit_loc(numberwires);
197 std::vector<std::vector<double>> Cornerness(numberwires);
199 for (
unsigned int wi = 0; wi < numberwires; ++wi) {
200 hit_map[wi].resize(fTimeBins, 0);
201 hit_loc[wi].resize(fTimeBins, -1);
202 Cornerness[wi].resize(fTimeBins, 0);
203 MatrixAsum[wi].resize(fTimeBins, 0);
204 MatrixBsum[wi].resize(fTimeBins, 0);
206 for (
unsigned int i = 0; i < hit.size(); ++i) {
207 wire = hit[i]->WireID().Wire;
208 const float center = hit[i]->PeakTime(), sigma = hit[i]->RMS();
209 const int iFirstBin = int((center - 3 * sigma) / TicksPerBin),
210 iLastBin = int((center + 3 * sigma) / TicksPerBin);
211 for (
int iBin = iFirstBin; iBin <= iLastBin; ++iBin) {
212 const float bin_center = iBin * TicksPerBin;
213 hit_map[wire][iBin] += Gaussian(bin_center, center, sigma);
218 for (
unsigned int wire = 1; wire < numberwires - 1; ++wire) {
220 for (
int timebin = 1; timebin < fTimeBins - 1; ++timebin) {
221 MatrixAsum[wire][timebin] = 0.;
222 MatrixBsum[wire][timebin] = 0.;
224 for (
int i = -3; i <= 3; ++i) {
226 if (windex < 0) windex = 0;
228 else if ((
unsigned int)windex >= numberwires)
229 windex = numberwires - 1;
231 for (
int j = -3; j <= 3; ++j) {
232 tindex = timebin + j;
235 else if (tindex >= fTimeBins)
236 tindex = fTimeBins - 1;
238 MatrixAsum[wire][timebin] += wx[
n] * hit_map[windex][tindex];
239 MatrixBsum[wire][timebin] += wy[
n] * hit_map[windex][tindex];
247 for (
unsigned int wire = 1; wire < numberwires - 1; ++wire) {
249 for (
int timebin = 1; timebin < fTimeBins - 1; ++timebin) {
255 for (
int i = -3; i <= 3; ++i) {
257 if (windex < 0) windex = 0;
259 else if ((
unsigned int)windex >= numberwires)
260 windex = numberwires - 1;
262 for (
int j = -3; j <= 3; ++j) {
263 tindex = timebin + j;
266 else if (tindex >= fTimeBins)
267 tindex = fTimeBins - 1;
269 MatrixAAsum += w[
n] * pow(MatrixAsum[windex][tindex], 2);
270 MatrixBBsum += w[
n] * pow(MatrixBsum[windex][tindex], 2);
271 MatrixCCsum += w[
n] * MatrixAsum[windex][tindex] * MatrixBsum[windex][tindex];
276 if ((MatrixAAsum + MatrixBBsum) > 0)
277 Cornerness[wire][timebin] =
278 (MatrixAAsum * MatrixBBsum - pow(MatrixCCsum, 2)) / (MatrixAAsum + MatrixBBsum);
280 Cornerness[wire][timebin] = 0;
282 if (Cornerness[wire][timebin] > 0) {
283 for (
unsigned int i = 0; i < hit.size(); ++i) {
284 wire2 = hit[i]->WireID().Wire;
286 if (wire == wire2 &&
std::abs(hit[i]->TimeDistanceAsRMS(
287 timebin * (numbertimesamples / fTimeBins))) < 1.) {
289 hit_loc[wire][timebin] = i;
290 Cornerness2.push_back(Cornerness[wire][timebin]);
298 std::sort(Cornerness2.rbegin(), Cornerness2.rend());
300 for (
int vertexnum = 0; vertexnum < fMaxCorners; ++vertexnum) {
302 for (
unsigned int wire = 0; wire < numberwires && flag == 0; ++wire) {
303 for (
int timebin = 0; timebin < fTimeBins && flag == 0; ++timebin) {
304 if (Cornerness2.size() > (
unsigned int)vertexnum)
305 if (Cornerness[wire][timebin] == Cornerness2[vertexnum] &&
306 Cornerness[wire][timebin] > 0. && hit_loc[wire][timebin] > -1) {
310 if (Cornerness2.size())
311 if (Cornerness[wire][timebin] < (fThreshold * Cornerness2[0]))
312 vertexnum = fMaxCorners;
313 vHits.push_back(hit[hit_loc[wire][timebin]]);
317 for (
size_t vh = 0; vh < vHits.size(); ++vh)
318 totalQ += vHits[vh]->Integral();
321 hit[hit_loc[wire][timebin]]->
WireID(),
322 Cornerness[wire][timebin],
326 vtxcol.push_back(endpoint);
327 vtxHitsOut.push_back(vHits);
335 double drifttick = det_prop.DriftVelocity(det_prop.Efield(), det_prop.Temperature());
337 double wirepitch = geom->WirePitch();
338 double corrfactor = drifttick / wirepitch;
342 (
int)((fWindow * (numbertimesamples / fTimeBins) * corrfactor) + .5);
344 (int)wire + (
int)((fWindow * (numbertimesamples / fTimeBins) * corrfactor) + .5);
346 for (
int timebinout = timebin - fWindow; timebinout <= timebin + fWindow;
348 if (std::sqrt(pow(wire - wireout, 2) + pow(timebin - timebinout, 2)) <
350 Cornerness[wireout][timebinout] = 0;
359 if (clusterIter != clusIn.end()) clusterIter++;
361 if ((
int)wid.
Plane == fSaveVertexMap) {
362 unsigned char* outPix =
new unsigned char[fTimeBins * numberwires];
368 for (
int y = 0;
y < fTimeBins; ++
y) {
369 for (
unsigned int x = 0;
x < numberwires; ++
x) {
370 cell = (int)(hit_map[
x][
y] * 1000);
371 if (cell > maxCell) { maxCell = cell; }
374 for (
int y = 0;
y < fTimeBins; ++
y) {
375 for (
unsigned int x = 0;
x < numberwires; ++
x) {
377 if (maxCell > 0) pix = (int)((1500000 * hit_map[
x][
y]) / maxCell);
378 outPix[y * numberwires +
x] = pix;
384 for (
unsigned int ii = 0; ii < vtxcol.size(); ++ii) {
385 if (vtxcol[ii].View() == (
unsigned int)view) {
387 outPix[(int)(vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) * numberwires +
388 vtxcol[ii].WireID().Wire] = 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)) * numberwires +
392 vtxcol[ii].WireID().Wire + 1] = pix;
393 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) - 1) *
395 vtxcol[ii].
WireID().Wire] = pix;
396 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) + 1) *
398 vtxcol[ii].
WireID().Wire] = pix;
399 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) - 1) *
401 vtxcol[ii].
WireID().Wire - 1] = pix;
402 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) - 1) *
404 vtxcol[ii].
WireID().Wire - 2] = pix;
405 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) + 1) *
407 vtxcol[ii].
WireID().Wire + 1] = pix;
408 outPix[(int)((vtxcol[ii].DriftTime() * (fTimeBins / numbertimesamples)) + 1) *
410 vtxcol[ii].
WireID().Wire + 2] = pix;
414 VSSaveBMPFile(Form(
"harrisvertexmap_%d_%d.bmp", (*clusIn.begin())->ID(), wid.
Plane),
422 return vtxcol.size();
algorithm to find 2D endpoints
Encapsulate the construction of a single cyostat.
process_name opflash particleana ie x
then echo unknown compiler flag
Declaration of signal hit object.
CryostatID_t Cryostat
Index of cryostat.
std::size_t size(FixedBins< T, C > const &) noexcept
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void VSSaveBMPFile(const char *fileName, unsigned char *pix, int dx, int dy) const
process_name opflash particleana ie ie y
EndPointAlg(fhicl::ParameterSet const &pset)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
size_t EndPoint(const art::PtrVector< recob::Cluster > &clusIn, std::vector< recob::EndPoint2D > &vtxcol, std::vector< art::PtrVector< recob::Hit > > &vtxHitsOut, art::Event const &evt, std::string const &label) const
PlaneID_t Plane
Index of the plane within its TPC.
Declaration of cluster object.
double GaussianDerivativeY(int x, int y) const
double Gaussian(int x, int y, double sigma) const
Encapsulate the construction of a single detector plane.
services TFileService fileName
double GaussianDerivativeX(int x, int y) const
TPCID_t TPC
Index of the TPC within its cryostat.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
art framework interface to geometry description
Encapsulate the construction of a single detector plane.