18 #ifndef HarrisVertexFinder_H 19 #define HarrisVertexFinder_H 36 #include <sys/types.h> 79 void SaveBMPFile(
const char *fileName,
unsigned char *pix,
int dx,
int dy);
97 ,
fTimeBins (pset.get< int >(
"TimeBins") )
99 ,
fGsigma (pset.get< double >(
"Gsigma") )
100 ,
fWindow (pset.get< int >(
"Window") )
101 ,
fThreshold (pset.get< double >(
"Threshold") )
104 produces< std::vector<recob::EndPoint2D> >();
105 produces< art::Assns<recob::EndPoint2D, recob::Hit> >();
117 fNoVertices= tfs->
make<TH2F>(
"fNoVertices",
";Event No; No of vertices", 100,0, 100, 30, 0, 30);
124 double Norm = 1./std::sqrt(2*TMath::Pi()*pow(sigma,2));
125 double value = Norm*exp(-(pow(x,2)+pow(y,2))/(2*pow(sigma,2)));
132 double Norm = 1./(std::sqrt(2*TMath::Pi())*pow(
fGsigma,3));
133 double value = Norm*(-
x)*exp(-(pow(x,2)+pow(y,2))/(2*pow(
fGsigma,2)));
140 double Norm = 1./(std::sqrt(2*TMath::Pi())*pow(
fGsigma,3));
141 double value = Norm*(-
y)*exp(-(pow(x,2)+pow(y,2))/(2*pow(
fGsigma,2)));
155 std::unique_ptr<std::vector<recob::EndPoint2D> > vtxcol(
new std::vector<recob::EndPoint2D>);
158 std::vector< art::Ptr<recob::Hit> > cHits;
162 for(
unsigned int ii = 0; ii < clusterListHandle->size(); ++ii){
171 unsigned int numberwires = 0;
172 double MatrixAAsum = 0.;
173 double MatrixBBsum = 0.;
174 double MatrixCCsum = 0.;
175 std::vector<double> Cornerness2;
178 double wx[49] = {0.};
179 double wy[49] = {0.};
181 for(
int i = -3; i < 4; ++i){
182 for(
int j = 3; j > -4; --j){
190 const unsigned int numbertimesamples
191 = lar::providerFrom<detinfo::DetectorPropertiesService>()->ReadOutWindowSize();
193 const float BinsPerTick =
fTimeBins / numbertimesamples;
194 const float TicksPerBin = numbertimesamples /
fTimeBins;
201 for(
size_t ci = 0; ci < clusIn.
size(); ++ci) {
204 for(
unsigned int i = 0; i < cHits.size(); ++i) hit.
push_back(cHits[i]);
207 if(hit.
size() == 0)
continue;
210 std::vector< std::vector<double> > MatrixAsum(numberwires);
211 std::vector< std::vector<double> > MatrixBsum(numberwires);
212 std::vector< std::vector<double> > hit_map(numberwires);
213 std::vector< std::vector<int> > hit_loc(numberwires);
214 std::vector< std::vector<double> > Cornerness(numberwires);
216 for(
unsigned int wi = 0; wi < numberwires; ++wi){
222 for(
int timebin = 0; timebin <
fTimeBins; ++timebin){
223 hit_map[wi][timebin] = 0.;
224 hit_loc[wi][timebin] = -1;
225 Cornerness[wi][timebin] = 0.;
226 MatrixAsum[wi][timebin] = 0.;
227 MatrixBsum[wi][timebin] = 0.;
231 for(
unsigned int i = 0; i < hit.
size(); ++i){
232 unsigned int wire = hit[i]->WireID().Wire;
234 const float center = hit[i]->PeakTime(), sigma = hit[i]->RMS();
235 const int iFirstBin = int((center - 3*sigma) / TicksPerBin),
236 iLastBin = int((center + 3*sigma) / TicksPerBin);
237 for (
int iBin = iFirstBin; iBin <= iLastBin; ++iBin) {
238 const float bin_center = iBin * TicksPerBin;
239 hit_map[wire][iBin] +=
Gaussian(bin_center, center, sigma);
244 for(
unsigned int wire = 1;wire < numberwires-1; ++wire){
245 for(
int timebin = 1;timebin <
fTimeBins-1; ++timebin){
246 MatrixAsum[wire][timebin] = 0.;
247 MatrixBsum[wire][timebin] = 0.;
249 for(
int i = -3; i <= 3; ++i) {
250 unsigned int windex = ((int)wire < -i)? 0: wire + i;
251 if (windex >= numberwires) windex = numberwires - 1;
252 for(
int j = -3; j <= 3; ++j) {
253 unsigned int tindex = (
unsigned int)
std::min(
std::max(timebin +j, 0), fTimeBins - 1);
255 MatrixAsum[wire][timebin] += wx[
n]*hit_map[windex][tindex];
256 MatrixBsum[wire][timebin] += wy[
n]*hit_map[windex][tindex];
264 for(
unsigned int wire = 1; wire < numberwires-1; ++wire){
265 for(
int timebin = 1; timebin <
fTimeBins-1; ++timebin){
272 for(
int i = -3; i <= 3; i++) {
273 unsigned int windex = ((int)wire < -i)? 0: wire + i;
274 if (windex >= numberwires) windex = numberwires - 1;
275 for(
int j = -3; j <= 3; j++) {
276 unsigned int tindex = (
unsigned int)
std::min(
std::max(timebin +j, 0), 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 unsigned int wire2 = hit[i]->WireID().Wire;
294 const float time = timebin / TicksPerBin;
295 if(wire == wire2 && std::abs(hit[i]->TimeDistanceAsRMS(time)) < 1.){
297 hit_loc[wire][timebin] = i;
298 Cornerness2.push_back(Cornerness[wire][timebin]);
306 std::sort(Cornerness2.rbegin(),Cornerness2.rend());
308 for(
int vertexnum = 0; vertexnum <
fMaxCorners; ++vertexnum){
310 for(
unsigned int wire = 0;wire < numberwires && flag == 0; ++wire){
311 for(
int timebin = 0;timebin <
fTimeBins && flag == 0; ++timebin){
312 if(Cornerness2.size() > (
unsigned int)vertexnum)
313 if(Cornerness[wire][timebin] == Cornerness2[vertexnum]
314 && Cornerness[wire][timebin] > 0.
315 && hit_loc[wire][timebin]>-1){
318 if(Cornerness2.size())
319 if(Cornerness[wire][timebin] < (
fThreshold*Cornerness2[0]))
320 vertexnum = fMaxCorners;
322 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(
vertex);
345 for(
unsigned int wireout=wire-(
int)((
fWindow*BinsPerTick*.0743)+.5);
346 wireout <= wire+(int)((
fWindow*BinsPerTick*.0743)+.5) ; wireout++)
347 for(
int timebinout=timebin-
fWindow;timebinout <= timebin+
fWindow; timebinout++)
348 if(std::sqrt(pow(wire-wireout,2)+pow(timebin-timebinout,2))<
fWindow)
349 Cornerness[wireout][timebinout]=0;
358 unsigned char *outPix =
new unsigned char [
fTimeBins*numberwires];
360 int cell, pix=0, maxCell=0;
362 for (
unsigned int x = 0;
x < numberwires; ++
x){
363 cell = (int)(hit_map[
x][
y]*1000);
370 for (
unsigned int y = 0;
y < (
unsigned int)fTimeBins; ++
y){
371 for (
unsigned int x = 0;
x < numberwires; ++
x){
374 pix = (int)((1500000*hit_map[
x][
y])/maxCell);
375 outPix[y*numberwires +
x] = pix;
378 SaveBMPFile(
"harrisvertexmap.bmp", outPix, numberwires, fTimeBins);
383 mf::LogInfo(
"HarrisVertexFinder") <<
"Size of vtxcol= " << vtxcol->size();
386 evt.
put(std::move(vtxcol));
393 std::ofstream bmpFile(fileName, std::ios::binary);
394 bmpFile.write(
"B", 1);
395 bmpFile.write(
"M", 1);
396 int bitsOffset = 54 +256*4;
397 int size = bitsOffset + dx*dy;
398 bmpFile.write((
const char *)&size, 4);
400 bmpFile.write((
const char *)&reserved, 4);
401 bmpFile.write((
const char *)&bitsOffset, 4);
403 bmpFile.write((
const char *)&bmiSize, 4);
404 bmpFile.write((
const char *)&dx, 4);
405 bmpFile.write((
const char *)&dy, 4);
407 bmpFile.write((
const char *)&planes, 2);
409 bmpFile.write((
const char *)&bitCount, 2);
412 bmpFile.write((
const char *)&temp, 4);
416 for (i=0; i<256; i++)
418 lutEntry[0] = lutEntry[1] = lutEntry[2] = i;
419 bmpFile.write(lutEntry,
sizeof lutEntry);
422 bmpFile.write((
const char *)pix, dx*dy);
431 #endif // HarrisVertexFinder_H std::string fDBScanModuleLabel
Encapsulate the construction of a single cyostat.
virtual ~HarrisVertexFinder()
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
void SaveBMPFile(const char *fileName, unsigned char *pix, int dx, int dy)
Cluster finding and building.
void produce(art::Event &evt)
IteratorBox< plane_id_iterator,&GeometryCore::begin_plane_id,&GeometryCore::end_plane_id > IteratePlaneIDs() const
Enables ranged-for loops on all plane IDs of the detector.
ProductID put(std::unique_ptr< PROD > &&product)
double Gaussian(int x, int y, double sigma)
#define DEFINE_ART_MODULE(klass)
void push_back(Ptr< U > const &p)
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
Declaration of cluster object.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
HarrisVertexFinder(fhicl::ParameterSet const &pset)
Detector simulation of raw signals on wires.
T * make(ARGS...args) const
std::string value(boost::any const &)
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
double GaussianDerivativeY(int x, int y)
unsigned int Nwires() const
Number of wires in this plane.
EventNumber_t event() const
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
art framework interface to geometry description
Encapsulate the construction of a single detector plane.
double GaussianDerivativeX(int x, int y)