FEDRA emulsion software from the OPERA Collaboration
EdbIP Class Reference

#include <EdbIP.h>

Inheritance diagram for EdbIP:
Collaboration diagram for EdbIP:

Public Member Functions

int Clusterize (EdbFrame *frame, TTree *tree)
 
int Clusterize2 (EdbFrame *frame, TTree *tree)
 
int CutBG (EdbFrame *frame)
 
 EdbIP ()
 
TTree * InitTree ()
 
void SetFIR (EdbFIRF *fir)
 
void SetThr (Float_t thr)
 

Static Public Member Functions

static float BurnPix (TH2F *h, int ic, int ir, float thr, EdbClustP &cl)
 
static int BurnPix (unsigned char *img, int ic, int ir, int nc, unsigned char thr, EdbCluster &cl)
 
static int Clusterize (EdbFrame *f, unsigned char thr, EdbView &v)
 
static int Clusterize (TH2F *h, float thr, TTree *tree, float z, int ifr)
 
static int Clusterize2 (TH2F *h, float thr, TTree *tree, float z, int ifr)
 
static int Peak12 (TH2F *h, float thr)
 
static int Peak8 (TH2F *h, float thr)
 

Private Attributes

EdbFIRFeFIR
 
Float_t eThr
 

Constructor & Destructor Documentation

◆ EdbIP()

EdbIP::EdbIP ( )
254 {
255  eFIR=0;
256  eThr=0;
257 }
Float_t eThr
Definition: EdbIP.h:91
EdbFIRF * eFIR
Definition: EdbIP.h:90

Member Function Documentation

◆ BurnPix() [1/2]

float EdbIP::BurnPix ( TH2F *  h,
int  ic,
int  ir,
float  thr,
EdbClustP cl 
)
static
452 {
453  float pix=h->GetBinContent(ic,ir);
454  if( pix<thr ) return 0;
455 
456  cl.AddPixel(ic-.5,ir-.5,pix-thr);
457 
458  h->SetBinContent(ic,ir,0,-pix);
459  pix = 1;
460 
461  int xn[4] = { 1, -1, 0, 0 }; //pixel closest suburbs
462  int yn[4] = { 0, 0, 1, -1 };
463  float pp;
464  int i,j;
465 
466  for(int in=0; in<4; in++) {
467  i = ic+xn[in];
468  j = ir+yn[in];
469  pp = (float)( h->GetBinContent(i,j) );
470  if( pp < thr ) continue;
471  pix += BurnPix(h,i,j, thr, cl);
472  }
473  return pix;
474 }
void AddPixel(float ic, float ir, float pix)
Definition: EdbIP.cxx:195
static float BurnPix(TH2F *h, int ic, int ir, float thr, EdbClustP &cl)
Definition: EdbIP.cxx:451

◆ BurnPix() [2/2]

int EdbIP::BurnPix ( unsigned char *  img,
int  ic,
int  ir,
int  nc,
unsigned char  thr,
EdbCluster cl 
)
static
600 {
601  int pix = buf[nc*ir+ic];
602  cl.AddPixelSum(ic,ir,pix-thr);
603  buf[nc*ir+ic]=0;
604 
605  pix = 1;
606  if(cl.GetArea() >50000) return pix;
607 
608  int xn[4] = { 1, -1, 0, 0 }; //pixel closest suburbs
609  int yn[4] = { 0, 0, 1, -1 };
610  unsigned char pp;
611  int i,j;
612 
613  for(int in=0; in<4; in++) {
614  i = ic+xn[in];
615  j = ir+yn[in];
616  pp = buf[nc*j+i];
617  if( pp < thr ) continue;
618  pix += BurnPix(buf,i,j, nc, thr, cl);
619  }
620  return pix;
621 }
void AddPixelSum(int x, int y, unsigned char pix)
Definition: EdbCluster.h:60
Float_t GetArea() const
Definition: EdbCluster.h:54

◆ Clusterize() [1/3]

int EdbIP::Clusterize ( EdbFrame f,
unsigned char  thr,
EdbView v 
)
static
561 {
562  // input: frame;
563  // output: clusters added to a view
564 
565  TStopwatch sw;
566  sw.Start();
567 
568  float z = frame->GetZ();
569  int ifr = frame->GetID();
570  EdbImage *img=frame->GetImage();
571  int nc = img->Width();
572  int nr = img->Height();
573  printf("img: %d %d\n",nc,nr);
574 
575  unsigned char *buf = (unsigned char*)(img->GetBuffer());
576  unsigned char pix;
577  float wcl;
578  int ncl=0;
579  EdbCluster *cl=0;
580 
581  for(int ir=2; ir<nr-3; ir++) {
582  for(int ic=2; ic<nc-3; ic++) {
583 
584  pix = buf[nc*ir+ic];
585  if( pix <= thr) continue;
586 
587  cl = v.AddCluster(0,0,z, 0, 0, ifr, 0);
588  wcl = BurnPix( buf, ic,ir, nc, thr, *cl);
589  cl->Normalize();
590  ncl++;
591  }
592  }
593  printf("Clusterize2............ %15.8f\n",sw.CpuTime());
594  printf("ncl=%d\n",ncl);
595  return ncl;
596 }
Definition: EdbCluster.h:19
void Normalize()
Definition: EdbCluster.h:69
Definition: EdbImage.h:23
Int_t Height() const
Definition: EdbImage.h:60
char * GetBuffer() const
Definition: EdbImage.h:48
Int_t Width() const
Definition: EdbImage.h:59
EdbCluster * AddCluster(EdbCluster *c)
Definition: EdbView.h:225

◆ Clusterize() [2/3]

int EdbIP::Clusterize ( EdbFrame frame,
TTree *  tree 
)
399 {
400  TH2F *img = eFIR->ApplyTo(frame->GetImage());
401  float z = frame->GetZ();
402  int ifr = frame->GetID();
403  int ncl = Clusterize( img, eThr, tree, z, ifr );
404  delete img;
405  return ncl;
406 }
TH2F * ApplyTo(EdbImage *img)
Definition: EdbIP.cxx:166
float GetZ() const
Definition: EdbFrame.h:42
int GetID() const
Definition: EdbFrame.h:41
EdbImage * GetImage() const
Definition: EdbFrame.h:45
int Clusterize(EdbFrame *frame, TTree *tree)
Definition: EdbIP.cxx:398

◆ Clusterize() [3/3]

int EdbIP::Clusterize ( TH2F *  h,
float  thr,
TTree *  tree,
float  z,
int  ifr 
)
static
410 {
411  // c++ remake of my good old "Fire in steppe ;-)"
412 
413  int nc = h->GetNbinsX();
414  int nr = h->GetNbinsY();
415  float pix;
416  float wcl;
417  int ncl=0;
418  printf("hist: %d %d\n",nc,nr);
419 
420  tree->GetDirectory()->cd();
421  EdbClustP *cl = 0;
422  tree->SetBranchAddress("cl",&cl);
423  cl = new EdbClustP();
424 
425  TStopwatch sw;
426  sw.Start();
427 
428  for(int ic=2; ic<nc-3; ic++) {
429  for(int ir=2; ir<nr-3; ir++) {
430 
431  pix = (float)(h->GetBinContent(ic,ir));
432  if( pix <= thr) continue;
433 
434  cl->Reset();
435  wcl = BurnPix( h, ic,ir, thr, *cl);
436  cl->SetZ(z);
437  cl->SetFrame(ifr);
438  tree->Fill();
439  ncl++;
440  }
441  }
442  printf("Clusterize2............ %15.8f\n",sw.CpuTime());
443 
444 
445  tree->AutoSave();
446 
447  return ncl;
448 }
Definition: EdbIP.h:58
void Reset()
Definition: EdbIP.cxx:245
void SetFrame(int f)
Definition: EdbCluster.h:47
virtual void SetZ(float z)
Definition: EdbCluster.h:83

◆ Clusterize2() [1/2]

int EdbIP::Clusterize2 ( EdbFrame frame,
TTree *  tree 
)
478 {
479  TH2F *img = eFIR->ApplyTo(frame->GetImage());
480  float z = frame->GetZ();
481  int ifr = frame->GetID();
482  int ncl = Clusterize2( img, eThr, tree, z, ifr );
483  delete img;
484  return ncl;
485 }
int Clusterize2(EdbFrame *frame, TTree *tree)
Definition: EdbIP.cxx:477

◆ Clusterize2() [2/2]

int EdbIP::Clusterize2 ( TH2F *  h,
float  thr,
TTree *  tree,
float  z,
int  ifr 
)
static
489 {
490  // Should be faster...
491  /*
492  int nc = h->GetNbinsX();
493  int nr = h->GetNbinsY();
494  float pix;
495  printf("hist: %d %d\n",nc,nr);
496 
497  tree->GetDirectory()->cd();
498  EdbClustP *cl = 0;
499  tree->SetBranchAddress("cl",&cl);
500 
501  TStopwatch sw;
502  sw.Start();
503  TList clusters; // list of clusters
504  EdbClustP *ptrup[nc]; // line of pointers (ToDo: check direction)
505  for(int i=0; i<nc; i++) ptrup[i]=0;
506 
507  int i;
508  for(int ir=1; ir<nr-3; ir++) {
509  for(int ic=1; ic<nc-3; ic++) {
510 
511  i = ic;
512 
513  pix = (float)(h->GetBinContent(ic,ir));
514 
515  if( pix <= thr) {
516  if(cl) {ptrup[i]=cl; cl=0;}
517  else ptrup[i]=0;
518  continue;
519  }
520  if(!cl) {
521  if(!ptrup[i]) {cl = new EdbClustP(); clusters.Add(cl);
522  }
523  else cl = ptrup[i];
524  }
525  printf("ncl=%d\n",clusters.GetEntries());
526  cl->AddPixelSum(ic-.5,ir-.5,pix-thr);
527  cl->Print();
528  if(!ptrup[i]) ptrup[i]=cl;
529  else if( ptrup[i] != cl ) {
530  cl->AddClusterSum(ptrup[i]);
531  clusters.Remove(ptrup[i]);
532  //delete ptrup[i];
533  ptrup[i]=cl;
534  for(int j=i-1; j>1; j--) {if(!ptrup[j]) break; ptrup[j]=cl;}
535  }
536  }
537  }
538  printf("Clusterize2............ %15.8f\n",sw.CpuTime());
539 
540  printf("ncl=%d\n",clusters.GetEntries());
541 
542  TListIter next(&clusters);
543  int ncl=0;
544  while ( (cl = (EdbClustP*)next()) ) {
545  cl->Normalize(); //if used AddPixelSum
546  cl->SetZ(z);
547  cl->SetFrame(ifr);
548  tree->Fill();
549  ncl++;
550  }
551  tree->AutoSave();
552  printf("ncl=%d\n",ncl);
553  return ncl;
554  */
555  return 0;
556 }

◆ CutBG()

int EdbIP::CutBG ( EdbFrame frame)
362 {
363  int npix = 0;
364  TH2F *h = eFIR->ApplyTo(frame->GetImage());
365  int nc = h->GetNbinsX();
366  int nr = h->GetNbinsY();
367  float pix;
368  int ic,ir;
369  for(ic=0; ic<nc; ic++) {
370  for(ir=0; ir<nr; ir++) {
371  pix = (float)(h->GetBinContent(ic,ir));
372  if(pix<=eThr) h->SetBinContent(ic,ir,0);
373  else h->SetBinContent(ic,ir,pix-eThr);
374  }
375  }
376 
377  float binmax = h->GetMaximum();
378  printf("binmax = %f\n",binmax);
379  unsigned char *buf = (unsigned char*)(frame->GetImage()->GetBuffer());
380 
381  for(ic=0; ic<nc; ic++) {
382  for(ir=0; ir<nr; ir++) {
383  pix = (float)(h->GetBinContent(ic,ir));
384  if(pix>0) {
385  buf[nc*ir+ic] = (unsigned char)(255.*pix/binmax);
386  npix++;
387  }
388  else buf[nc*ir+ic] =0;
389  }
390  }
391 
392  delete h;
393  return npix;
394 }

◆ InitTree()

TTree * EdbIP::InitTree ( )
348 {
349  TFile *f = new TFile("clusters.root","RECREATE");
350  f->cd();
351  TTree *tree = new TTree("clust","clusters tree");
352 
353  EdbClustP *cl = new EdbClustP();
354  tree->Branch("cl","EdbClustP",&cl,32000,99);
355 
356  return tree;
357  // f.Close();
358 }
FILE * f
Definition: RecDispMC.C:150

◆ Peak12()

int EdbIP::Peak12 ( TH2F *  h,
float  thr 
)
static
296 {
297  int xn[12] = { 1, -1, 0, 0, 1, 1, -1, -1, 2, 0, 0, -2 }; //pixel 12 suburbs
298  int yn[12] = { 0, 0, 1, -1, 1, -1, 1, -1, 0, 2, -2, 0 };
299 
300  int nc = h->GetNbinsX();
301  int nr = h->GetNbinsY();
302  float pix,pp;
303 
304  float s4, s8;
305  printf("hist: %d %d\n",nc,nr);
306 
307  int npeaks=0;
308  for(int ic=2; ic<nc-3; ic++) {
309  for(int ir=2; ir<nr-3; ir++) {
310 
311  pix = h->GetBinContent(ic,ir);
312 
313  if( pix < thr) goto NEXTPIX;
314  int in;
315 
316  s4=0;
317  for(in=0; in<4; in++) {
318  pp = h->GetBinContent( ic+xn[in], ir+yn[in] );
319  if( pix < pp ) goto NEXTPIX;
320  s4 += pp;
321  }
322 
323  s8=0;
324  for(in=4; in<12; in++) {
325  pp = h->GetBinContent( ic+xn[in], ir+yn[in] );
326  if( pix < pp ) goto NEXTPIX;
327  s8 += pp;
328  }
329  s4 /= 4.;
330  s8 /= 8.;
331  if( s4 < s8+5 ) goto NEXTPIX;
332  if( pix < s4+5 ) goto NEXTPIX;
333 
334  npeaks++;
335  printf("peak12(%d,%d) = %f \t %f\t %f\n",ic,ir,pix, s4,s8);
336  h->SetBinContent(ic,ir,0,5000);
337 
338  NEXTPIX:
339  continue;
340  }
341  }
342 
343  return npeaks;
344 }

◆ Peak8()

int EdbIP::Peak8 ( TH2F *  h,
float  thr 
)
static
262 {
263  int xn[8] = { 1, -1, 0, 0, 1, 1, -1, -1 }; //pixel 3x3 suburbs
264  int yn[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
265 
266  int nc = h->GetNbinsX();
267  int nr = h->GetNbinsY();
268  float pix,pp;
269 
270  printf("hist: %d %d\n",nc,nr);
271  int npeaks=0;
272  int ic,ir,in; // declare here to fix marazmatic eror messages of VC++
273  for(ic=2; ic<nc-3; ic++) {
274  for(ir=2; ir<nr-3; ir++) {
275 
276  pix = (float)(h->GetBinContent(ic,ir));
277  if( pix < thr) goto NEXTPIX;
278 
279  for(in=0; in<8; in++) {
280  pp = (float)(h->GetBinContent( ic+xn[in], ir+yn[in] ));
281  if( pix <= pp ) goto NEXTPIX;
282  }
283  printf("peak8(%d,%d) = %f\n",ic,ir,pix);
284  npeaks++;
285 
286  NEXTPIX:
287  continue;
288  }
289  }
290 
291  return npeaks;
292 }

◆ SetFIR()

void EdbIP::SetFIR ( EdbFIRF fir)
inline
97 {eFIR = fir;}

◆ SetThr()

void EdbIP::SetThr ( Float_t  thr)
inline
98 {eThr = thr;}

Member Data Documentation

◆ eFIR

EdbFIRF* EdbIP::eFIR
private

◆ eThr

Float_t EdbIP::eThr
private

The documentation for this class was generated from the following files: