22 #include <sys/types.h> 75 double Norm=1./std::sqrt(2*TMath::Pi()*pow(sigma,2));
76 double value=Norm*exp(-(pow(x,2)+pow(y,2))/(2*pow(sigma,2)));
83 double Norm=1./(std::sqrt(2*TMath::Pi())*pow(
fGsigma,3));
84 double value=Norm*(-
x)*exp(-(pow(x,2)+pow(y,2))/(2*pow(
fGsigma,2)));
91 double Norm=1./(std::sqrt(2*TMath::Pi())*pow(
fGsigma,3));
92 double value=Norm*(-
y)*exp(-(pow(x,2)+pow(y,2))/(2*pow(
fGsigma,2)));
101 std::ofstream bmpFile(fileName, std::ios::binary);
102 bmpFile.write(
"B", 1);
103 bmpFile.write(
"M", 1);
104 int bitsOffset = 54 +256*4;
105 int size = bitsOffset + dx*dy;
106 bmpFile.write((
const char *)&size, 4);
108 bmpFile.write((
const char *)&reserved, 4);
109 bmpFile.write((
const char *)&bitsOffset, 4);
111 bmpFile.write((
const char *)&bmiSize, 4);
112 bmpFile.write((
const char *)&dx, 4);
113 bmpFile.write((
const char *)&dy, 4);
115 bmpFile.write((
const char *)&planes, 2);
117 bmpFile.write((
const char *)&bitCount, 2);
120 bmpFile.write((
const char *)&temp, 4);
124 for (i=0; i<256; i++)
129 bmpFile.write(lutEntry,
sizeof lutEntry);
132 bmpFile.write((
const char *)pix, dx*dy);
137 std::vector<recob::EndPoint2D> & vtxcol,
140 std::string
const& label)
147 std::vector< art::Ptr<recob::Hit> >
hit;
155 unsigned int numberwires = 0;
157 const float TicksPerBin = numbertimesamples /
fTimeBins;
159 double MatrixAAsum = 0.;
160 double MatrixBBsum = 0.;
161 double MatrixCCsum = 0.;
162 std::vector<double> Cornerness2;
165 double wx[49] = {0.};
166 double wy[49] = {0.};
168 for(
int i = -3; i < 4; ++i){
169 for(
int j = 3; j > -4; --j){
177 unsigned int wire = 0;
178 unsigned int wire2 = 0;
179 for(
auto view : geom->
Views()){
184 while(clusterIter!= clusIn.
end() ) {
185 if((*clusterIter)->View() == view){
186 hit = fmh.at(cinctr);
192 if(hit.size() == 0)
continue;
196 mf::LogInfo(
"EndPointAlg") <<
" --- endpoints check " 197 << numberwires <<
" " 198 << numbertimesamples <<
" " 201 std::vector < std::vector < double > > MatrixAsum(numberwires);
202 std::vector < std::vector < double > > MatrixBsum(numberwires);
203 std::vector < std::vector < double > > hit_map(numberwires);
206 std::vector < std::vector < int > > hit_loc(numberwires);
208 std::vector < std::vector < double > > Cornerness(numberwires);
210 for(
unsigned int wi = 0; wi < numberwires; ++wi){
211 hit_map[wi].resize(fTimeBins,0);
212 hit_loc[wi].resize(fTimeBins,-1);
213 Cornerness[wi].resize(fTimeBins,0);
214 MatrixAsum[wi].resize(fTimeBins,0);
215 MatrixBsum[wi].resize(fTimeBins,0);
217 for(
unsigned int i = 0; i < hit.size(); ++i){
218 wire = hit[i]->WireID().Wire;
222 const float center = hit[i]->PeakTime(), sigma = hit[i]->RMS();
223 const int iFirstBin = int((center - 3*sigma) / TicksPerBin),
224 iLastBin = int((center + 3*sigma) / TicksPerBin);
225 for (
int iBin = iFirstBin; iBin <= iLastBin; ++iBin) {
226 const float bin_center = iBin * TicksPerBin;
227 hit_map[wire][iBin] +=
Gaussian(bin_center, center, sigma);
232 for(
unsigned int wire = 1; wire < numberwires-1; ++wire){
234 for(
int timebin = 1; timebin < fTimeBins-1; ++timebin){
235 MatrixAsum[wire][timebin] = 0.;
236 MatrixBsum[wire][timebin] = 0.;
238 for(
int i = -3; i <= 3; ++i) {
240 if(windex < 0 ) windex = 0;
242 else if ((
unsigned int)windex >= numberwires) windex = numberwires-1;
244 for(
int j = -3; j <= 3; ++j){
246 if(tindex < 0) tindex=0;
247 else if(tindex >= fTimeBins) tindex = fTimeBins-1;
249 MatrixAsum[wire][timebin] += wx[
n]*hit_map[windex][tindex];
250 MatrixBsum[wire][timebin] += wy[
n]*hit_map[windex][tindex];
258 for(
unsigned int wire = 1; wire < numberwires-1; ++wire){
260 for(
int timebin = 1; timebin < fTimeBins-1; ++timebin){
266 for(
int i = -3; i <= 3; ++i){
268 if(windex<0) windex = 0;
270 else if((
unsigned int)windex >= numberwires) windex = numberwires-1;
272 for(
int j = -3; j <= 3; ++j){
274 if(tindex < 0) tindex = 0;
275 else if(tindex >= fTimeBins) tindex = fTimeBins-1;
277 MatrixAAsum += w[
n]*pow(MatrixAsum[windex][tindex],2);
278 MatrixBBsum += w[
n]*pow(MatrixBsum[windex][tindex],2);
279 MatrixCCsum += w[
n]*MatrixAsum[windex][tindex]*MatrixBsum[windex][tindex];
284 if((MatrixAAsum + MatrixBBsum) > 0)
285 Cornerness[wire][timebin] = (MatrixAAsum*MatrixBBsum-pow(MatrixCCsum,2))/(MatrixAAsum+MatrixBBsum);
287 Cornerness[wire][timebin] = 0;
289 if(Cornerness[wire][timebin] > 0){
290 for(
unsigned int i = 0;i < hit.size(); ++i){
291 wire2 = hit[i]->WireID().Wire;
294 && std::abs(hit[i]->TimeDistanceAsRMS(timebin*(numbertimesamples/fTimeBins))) < 1.){
296 hit_loc[wire][timebin] = i;
297 Cornerness2.push_back(Cornerness[wire][timebin]);
305 std::sort(Cornerness2.rbegin(), Cornerness2.rend());
307 for(
int vertexnum = 0; vertexnum <
fMaxCorners; ++vertexnum){
309 for(
unsigned int wire = 0; wire < numberwires && flag == 0; ++wire){
310 for(
int timebin = 0; timebin < fTimeBins && flag == 0; ++timebin){
311 if(Cornerness2.size() > (
unsigned int)vertexnum)
312 if(Cornerness[wire][timebin] == Cornerness2[vertexnum]
313 && Cornerness[wire][timebin] > 0.
314 && hit_loc[wire][timebin] > -1){
318 if(Cornerness2.size())
319 if(Cornerness[wire][timebin] < (
fThreshold*Cornerness2[0]))
320 vertexnum = fMaxCorners;
321 vHits.
push_back(hit[hit_loc[wire][timebin]]);
325 for(
size_t vh = 0; vh < vHits.
size(); ++vh) totalQ += vHits[vh]->Integral();
328 hit[hit_loc[wire][timebin]]->WireID(),
329 Cornerness[wire][timebin],
333 vtxcol.push_back(endpoint);
334 vtxHitsOut.push_back(vHits);
345 double corrfactor = drifttick/wirepitch;
347 for(
int wireout=(
int)wire-(
int)((
fWindow*(numbertimesamples/fTimeBins)*corrfactor)+.5);
348 wireout <= (int)wire+(
int)((
fWindow*(numbertimesamples/
fTimeBins)*corrfactor)+.5); ++wireout){
349 for(
int timebinout=timebin-
fWindow;timebinout <= timebin+
fWindow; timebinout++){
350 if(std::sqrt(pow(wire-wireout,2)+pow(timebin-timebinout,2))<fWindow)
351 Cornerness[wireout][timebinout]=0;
360 if(clusterIter != clusIn.
end()) clusterIter++;
363 unsigned char *outPix =
new unsigned char [fTimeBins*numberwires];
370 for (
unsigned int x = 0;
x < numberwires; ++
x){
371 cell = (int)(hit_map[
x][
y]*1000);
380 for (
unsigned int x = 0;
x<numberwires; ++
x){
383 pix = (int)((1500000*hit_map[
x][
y])/maxCell);
384 outPix[y*numberwires +
x] = pix;
390 for(
unsigned int ii = 0; ii < vtxcol.size(); ++ii){
391 if(vtxcol[ii].View() == (
unsigned int)view){
393 outPix[(int)(vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))*numberwires + vtxcol[ii].WireID().Wire] = pix;
394 outPix[(int)(vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))*numberwires + vtxcol[ii].WireID().Wire-1] = pix;
395 outPix[(int)(vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))*numberwires + vtxcol[ii].WireID().Wire+1] = pix;
396 outPix[(int)((vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))-1)*numberwires + vtxcol[ii].WireID().Wire] = pix;
397 outPix[(int)((vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))+1)*numberwires + vtxcol[ii].WireID().Wire] = pix;
398 outPix[(int)((vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))-1)*numberwires + vtxcol[ii].WireID().Wire-1] = pix;
399 outPix[(int)((vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))-1)*numberwires + vtxcol[ii].WireID().Wire-2] = pix;
400 outPix[(int)((vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))+1)*numberwires + vtxcol[ii].WireID().Wire+1] = pix;
401 outPix[(int)((vtxcol[ii].DriftTime()*(fTimeBins/numbertimesamples))+1)*numberwires + vtxcol[ii].WireID().Wire+2] = pix;
405 VSSaveBMPFile(Form(
"harrisvertexmap_%d_%d.bmp",(*clusIn.
begin())->ID(),wid.
Plane), outPix, numberwires, fTimeBins);
410 return vtxcol.size();
algorithm to find 2D endpoints
virtual unsigned int ReadOutWindowSize() const =0
void reconfigure(fhicl::ParameterSet const &pset)
double GaussianDerivativeX(int x, int y)
Encapsulate the construction of a single cyostat.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
std::set< geo::View_t > const & Views() const
Returns a list of possible views in the detector.
virtual double SamplingRate() const =0
Returns the period of the TPC readout electronics clock.
CryostatID_t Cryostat
Index of cryostat.
double Gaussian(int x, int y, double sigma)
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
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)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
EndPointAlg(fhicl::ParameterSet const &pset)
void push_back(Ptr< U > const &p)
virtual double Temperature() const =0
T get(std::string const &key) const
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
double GaussianDerivativeY(int x, int y)
PlaneID_t Plane
Index of the plane within its TPC.
Declaration of cluster object.
Detector simulation of raw signals on wires.
data_t::const_iterator const_iterator
std::string value(boost::any const &)
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
virtual double DriftVelocity(double efield=0., double temperature=0.) const =0
unsigned int Nwires() const
Number of wires in this plane.
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
virtual double Efield(unsigned int planegap=0) const =0
Returns the nominal electric field in the specified volume.
TPCID_t TPC
Index of the TPC within its cryostat.
WireID()=default
Default constructor: an invalid TPC ID.
void VSSaveBMPFile(const char *fileName, unsigned char *pix, int dx, int dy)
art framework interface to geometry description
Encapsulate the construction of a single detector plane.