FEDRA emulsion software from the OPERA Collaboration
EdbPeak2 Class Reference

#include <EdbCell2.h>

Inheritance diagram for EdbPeak2:
Collaboration diagram for EdbPeak2:

Public Member Functions

void Delete ()
 
TH2F * DrawH2N (const char *name="xyN", const char *title="EdbH2plot2D")
 
TH1F * DrawSpectrumN (const char *name="spectrumN", const char *title="EdbH2 DrawSpectrum")
 
 EdbPeak2 ()
 
 EdbPeak2 (const EdbH2 &h)
 
float EstimatePeakMeanPosition (int iv[2], int ir[2], float &x, float &y, int mean=0)
 
float EstimatePeakVolume (int ipeak)
 
float EstimatePeakVolumeSafe (int ipeak)
 
float FindGlobalPeak (float &x, float &y, float ratio=0.1)
 
int FindPeak (float &x, float &y)
 
int FindPeak (float v[2])
 
int FindPeak (int iv[2])
 
float FindPeak9 (float &x, float &y)
 
void Init (const EdbH2 &h, int npeaks=10)
 
void InitPeaks (int npeaks)
 
float Mean (int i=0) const
 
float Mean3 (int i=0) const
 
float Peak (int i=0) const
 
void Print ()
 
float ProbPeak ()
 
float ProbPeak (float &x, float &y)
 
float ProbPeak (int iv[2], int ir[2])
 
int ProbPeaks (int npeak)
 
int ProbPeaks (int npeak, int ir[2])
 
float Smooth (Option_t *option="k5a")
 
int WipePeak (int iv[2], int ir[2])
 
float Xmean ()
 
float Ymean ()
 
 ~EdbPeak2 ()
 
- Public Member Functions inherited from EdbH2
void AddBin (int jcell, int n)
 
int Bin (float x, float y) const
 
int Bin (int iv[2]) const
 
int Bin (int ix, int iy) const
 
int Bin (int j) const
 
void CleanCells ()
 
void Copy (const EdbH2 &h)
 
void Delete ()
 
int DiscardHighCells (int nmax)
 
TH2F * DrawH2 (const char *name="plot2d", const char *title="EdbH2plot2D")
 
TH1I * DrawSpectrum (const char *name="plot1d", const char *title="EdbH2 DrawSpectrum")
 
 EdbH2 ()
 
 EdbH2 (const EdbH2 &h)
 
 EdbH2 (int nx, float minx, float maxx, int ny, float miny, float maxy)
 
int Fill (float x, float y)
 
int Fill (float x, float y, int n)
 
int Fill (int j, int n=1)
 
int InitH2 (const EdbH2 &h)
 
int InitH2 (int n[2], float min[2], float max[2])
 
int InitH2 (int nx, float minx, float maxx, int ny, float miny, float maxy)
 
Long_t Integral ()
 
Long_t Integral (int iv[2], int ir[2])
 
int IX (float x) const
 
int IX (int jcell) const
 
int IY (float y) const
 
int IY (int jcell) const
 
int Jcell (float v[2]) const
 
int Jcell (float x, float y) const
 
int Jcell (int ix, int iy) const
 
int MaxBin ()
 
Float_t Mean ()
 
int Ncell () const
 
int NX () const
 
int NY () const
 
void PrintStat ()
 
EdbH1ProjectionX ()
 
EdbH1ProjectionY ()
 
void Set0 ()
 
void SetBin (int ix, int iy, int n)
 
void SetBin (int j, int n)
 
float X (int ix) const
 
float Xbin () const
 
float Xj (int j) const
 
float Xmax () const
 
float XmaxA (float level=0)
 
float Xmin () const
 
float XminA (float level=0)
 
float Y (int iy) const
 
float Ybin () const
 
float Yj (int j) const
 
float Ymax () const
 
float YmaxA (float level=0)
 
float Ymin () const
 
float YminA (float level=0)
 
 ~EdbH2 ()
 

Public Attributes

TArrayF eMean
 
TArrayF eMean3
 
Float_t eNorm
 
Int_t eNpeaks
 
TArrayF ePeak
 
TArrayF eXpeak
 
TArrayF eYpeak
 

Additional Inherited Members

- Protected Attributes inherited from EdbH2
Float_t eBin [2]
 
Float_t eMax [2]
 
Float_t eMin [2]
 
Int_t eN [2]
 
Int_t * eNC
 
Int_t eNcell
 

Constructor & Destructor Documentation

◆ EdbPeak2() [1/2]

EdbPeak2::EdbPeak2 ( )
inline
116 { InitPeaks(10); }
void InitPeaks(int npeaks)
Definition: EdbCell2.cpp:380

◆ EdbPeak2() [2/2]

EdbPeak2::EdbPeak2 ( const EdbH2 h)
inline
117 : EdbH2( h ) { InitPeaks(10); }
EdbH2()
Definition: EdbCell2.cpp:25

◆ ~EdbPeak2()

EdbPeak2::~EdbPeak2 ( )
inline
118 {}

Member Function Documentation

◆ Delete()

void EdbPeak2::Delete ( )
366 {
367  ((EdbH2*)this)->Delete();
368  eNpeaks=0;
369 }
Definition: EdbCell2.h:19
Int_t eNpeaks
Definition: EdbCell2.h:107

◆ DrawH2N()

TH2F * EdbPeak2::DrawH2N ( const char *  name = "xyN",
const char *  title = "EdbH2plot2D" 
)
354 {
355  TObject *obj=0;
356  if((obj=gDirectory->FindObject(name))) delete obj;
357  TH2F *h = new TH2F(name, title, eN[0],eMin[0],eMax[0],eN[1],eMin[1],eMax[1]);
358  for(int i=0; i<eN[0]; i++)
359  for(int j=0; j<eN[1]; j++)
360  h->Fill( X(i), Y(j), Bin(i,j)/eNorm );
361  return h;
362 }
float X(int ix) const
Definition: EdbCell2.h:60
Float_t eMin[2]
Definition: EdbCell2.h:24
float Y(int iy) const
Definition: EdbCell2.h:61
Int_t eN[2]
Definition: EdbCell2.h:23
Float_t eMax[2]
Definition: EdbCell2.h:25
int Bin(float x, float y) const
Definition: EdbCell2.h:80
Float_t eNorm
Definition: EdbCell2.h:111
const char * name
Definition: merge_Energy_SytematicSources_Electron.C:24

◆ DrawSpectrumN()

TH1F * EdbPeak2::DrawSpectrumN ( const char *  name = "spectrumN",
const char *  title = "EdbH2 DrawSpectrum" 
)
344 {
345  int nbin = MaxBin()+1;
346  float max = 1.*MaxBin()/eNorm;
347  TH1F *h = new TH1F(name, title, nbin,0,max);
348  for(int i=0; i<eNcell; i++) h->Fill( eNC[i]/eNorm );
349  return h;
350 }
int max
Definition: check_shower.C:41
Int_t * eNC
Definition: EdbCell2.h:29
int MaxBin()
Definition: EdbCell2.cpp:244
Int_t eNcell
Definition: EdbCell2.h:28

◆ EstimatePeakMeanPosition()

float EdbPeak2::EstimatePeakMeanPosition ( int  iv[2],
int  ir[2],
float &  x,
float &  y,
int  mean = 0 
)
483 {
484  double x0=0, y0=0, volume=0;
485  for(int ix=iv[0]-ir[0]; ix<=iv[0]+ir[0]; ix++)
486  for(int iy=iv[1]-ir[1]; iy<=iv[1]+ir[1]; iy++)
487  {
488  int bin = Bin(ix,iy)-mean;
489  x0 += bin*X(ix);
490  y0 += bin*Y(iy);
491  volume += bin;
492  }
493  if(volume>0) { x = x0/volume; y = y0/volume; }
494  return volume;
495 }
float bin
Definition: emthickness.cpp:98

◆ EstimatePeakVolume()

float EdbPeak2::EstimatePeakVolume ( int  ipeak)
544 {
545  if(ipeak>(eNpeaks-1)||ipeak<0) return 0;
546  return ePeak[ipeak] + 8*eMean3[ipeak] - 9*eMean[ipeak];
547 }
TArrayF eMean
Definition: EdbCell2.h:110
TArrayF ePeak
Definition: EdbCell2.h:108
TArrayF eMean3
Definition: EdbCell2.h:109

◆ EstimatePeakVolumeSafe()

float EdbPeak2::EstimatePeakVolumeSafe ( int  ipeak)
536 {
537  // add to the background one standard deviation for the safety
538  if(ipeak>(eNpeaks-1)||ipeak<0) return 0;
539  return ePeak[ipeak] + 8*eMean3[ipeak] - 9*(eMean[ipeak] + Sqrt(eMean[ipeak]));
540 }

◆ FindGlobalPeak()

float EdbPeak2::FindGlobalPeak ( float &  x,
float &  y,
float  ratio = 0.1 
)
583 {
584  // to find the center of wide multibin peak select ratio*Nbin of highest bins and calculate CoG
585  int n = Ncell();
586  TArrayI ind(n);
587  Sort(n, eNC , ind.GetArray(), 0); // sort encreasing order
588  Int_t nwipe = Min( (Int_t)((1.-ratio)*n), n-1 );
589  double mean=0;
590  for(int i=0; i<nwipe; i++) {
591  mean += eNC[ind[i]];
592  eNC[ind[i]] = 0;
593  }
594  mean /= nwipe;
595  x = Xmean();
596  y = Ymean();
597  float peakvolume = Integral() - (n-nwipe)*mean;
598  Log(3,"EdbPeak2::FindGlobalPeak","of volume %8.2f at %10.2f %10.2f using %d bins",
599  peakvolume,x,y, n-nwipe );
600  return peakvolume;
601 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
int Ncell() const
Definition: EdbCell2.h:49
Long_t Integral()
Definition: EdbCell2.cpp:226
float Ymean()
Definition: EdbCell2.cpp:566
float Xmean()
Definition: EdbCell2.cpp:550

◆ FindPeak() [1/3]

int EdbPeak2::FindPeak ( float &  x,
float &  y 
)
526 {
527  int iv[2];
528  int peak=FindPeak(iv);
529  x = X(iv[0]);
530  y = Y(iv[1]);
531  return peak;
532 }
int FindPeak(int iv[2])
Definition: EdbCell2.cpp:498

◆ FindPeak() [2/3]

int EdbPeak2::FindPeak ( float  v[2])
516 {
517  int iv[2];
518  int peak=FindPeak(iv);
519  v[0] = X(iv[0]);
520  v[1] = Y(iv[1]);
521  return peak;
522 }

◆ FindPeak() [3/3]

int EdbPeak2::FindPeak ( int  iv[2])
499 {
500  int peak=0;
501  for(int ix=0; ix<eN[0]; ix++)
502  for(int iy=0; iy<eN[1]; iy++) {
503  int j = Jcell(ix,iy);
504  if(eNC[j]>peak) {
505  peak =eNC[j];
506  iv[0] = ix;
507  iv[1] = iy;
508  }
509  }
510  Log(4,"EdbPeak2::FindPeak","of %d at %d %d", peak, iv[0],iv[1] );
511  return peak;
512 }
int Jcell(int ix, int iy) const
Definition: EdbCell2.h:57

◆ FindPeak9()

float EdbPeak2::FindPeak9 ( float &  x,
float &  y 
)
474 {
475  // particular case of 3x3 peak neiboring, return peak volume and estimate mean position
476  int iv[2], ir[2]={1,1};
477  FindPeak(iv);
478  return EstimatePeakMeanPosition(iv, ir, x, y);
479 }
float EstimatePeakMeanPosition(int iv[2], int ir[2], float &x, float &y, int mean=0)
Definition: EdbCell2.cpp:482

◆ Init()

void EdbPeak2::Init ( const EdbH2 h,
int  npeaks = 10 
)
373 {
374  Delete();
375  ((EdbH2*)this)->Copy(h);
376  InitPeaks(npeaks);
377 }
void Delete()
Definition: EdbCell2.cpp:365

◆ InitPeaks()

void EdbPeak2::InitPeaks ( int  npeaks)
381 {
382  eNpeaks=0;
383  ePeak.Set(npeaks); ePeak.Reset(0);
384  eMean3.Set(npeaks); eMean3.Reset(0);
385  eMean.Set(npeaks); eMean.Reset(0);
386  eXpeak.Set(npeaks); eXpeak.Reset(0);
387  eYpeak.Set(npeaks); eYpeak.Reset(0);
388  eNorm = 1.; // default norm factor;
389 }
TArrayF eXpeak
Definition: EdbCell2.h:112
TArrayF eYpeak
Definition: EdbCell2.h:113

◆ Mean()

float EdbPeak2::Mean ( int  i = 0) const
inline
142 { if(i>=0&&i<eNpeaks) return eMean[i]; else return -1; }

◆ Mean3()

float EdbPeak2::Mean3 ( int  i = 0) const
inline
141 { if(i>=0&&i<eNpeaks) return eMean3[i]; else return -1; }

◆ Peak()

float EdbPeak2::Peak ( int  i = 0) const
inline
140 { if(i>=0&&i<eNpeaks) return ePeak[i]; else return -1; }

◆ Print()

void EdbPeak2::Print ( )
393 {
394  printf("%d peaks:\n", eNpeaks);
395  for(int i=0; i<eNpeaks; i++)
396  printf("%d : %.1f %.1f %.1f %.1f %.1f \n", i, eXpeak[i], eYpeak[i], ePeak[i], eMean3[i], eMean[i]);
397 }

◆ ProbPeak() [1/3]

float EdbPeak2::ProbPeak ( )
412 {
413  int iv[2];
414  FindPeak(iv);
415  int ir[2]={1,1}; // 3x3 neigbouring
416  return ProbPeak(iv,ir);
417 }
float ProbPeak()
Definition: EdbCell2.cpp:411

◆ ProbPeak() [2/3]

float EdbPeak2::ProbPeak ( float &  x,
float &  y 
)
401 {
402  int iv[2];
403  FindPeak(iv);
404  x = X(iv[0]);
405  y = Y(iv[1]);
406  int ir[2]={1,1}; // 3x3 neigbouring
407  return ProbPeak(iv,ir);
408 }

◆ ProbPeak() [3/3]

float EdbPeak2::ProbPeak ( int  iv[2],
int  ir[2] 
)
441 {
442  float prob=0;
443  int npeak = Bin(iv);
444  int nbinPeak = (2*ir[0]+1)*(2*ir[1]+1);
445  float meanNeib = 1.*(Integral(iv,ir) - npeak)/(nbinPeak-1);
446  float meanNoPeak = 1.*(Integral() - Integral(iv,ir))/(Ncell()-nbinPeak);
447  float x,y;
448  float volume = EstimatePeakMeanPosition(iv, ir, x, y,meanNoPeak);
449  Log(3,"ProbPeak","found at (%3d %3d): %4d %6.3f %6.3f", iv[0],iv[1],npeak, meanNeib,meanNoPeak);
450  eXpeak[eNpeaks] = x;
451  eYpeak[eNpeaks] = y;
452  ePeak[eNpeaks] = volume/eNorm;
453  eMean3[eNpeaks] = meanNeib/eNorm;
454  eMean[eNpeaks] = meanNoPeak/eNorm;
455  prob = (npeak - meanNoPeak)/eNorm;
456  eNpeaks++;
457  return prob;
458 }

◆ ProbPeaks() [1/2]

int EdbPeak2::ProbPeaks ( int  npeak)
421 {
422  int ir[2]={1,1};
423  return ProbPeaks(npeaks,ir);
424 }
int ProbPeaks(int npeak)
Definition: EdbCell2.cpp:420

◆ ProbPeaks() [2/2]

int EdbPeak2::ProbPeaks ( int  npeak,
int  ir[2] 
)
428 {
429  int iv[2], ic=0;
430  for(int i=0; i<npeaks; i++) {
431  FindPeak(iv);
432  ProbPeak(iv,ir);
433  WipePeak(iv,ir);
434  ic++;
435  }
436  return ic;
437 }
int WipePeak(int iv[2], int ir[2])
Definition: EdbCell2.cpp:461

◆ Smooth()

float EdbPeak2::Smooth ( Option_t *  option = "k5a")
253 {
254  // Smooth bin contents of this 2-d histogram using kernel algorithms
255  // similar to the ones used in the raster graphics community.
256  // Bin contents in the active range are replaced by their smooth values.
257  //
258  // This code is copied from root_5.22 mainly to not depend on the newest root versions
259  // Adopted to fedra by VT
260  // to speedup processing do all calculations as integer, so the histogram do not normalised at output
261  // return value - norm-factor of the kernel
262 
263  if(NX()<1||NY()<1) return 1.;
264 
265  Int_t k5a[5][5] = { { 0, 0, 1, 0, 0 },
266  { 0, 2, 2, 2, 0 },
267  { 1, 2, 5, 2, 1 },
268  { 0, 2, 2, 2, 0 },
269  { 0, 0, 1, 0, 0 } }; // norm = 25
270  Int_t k5b[5][5] = { { 0, 1, 2, 1, 0 },
271  { 1, 2, 4, 2, 1 },
272  { 2, 4, 8, 4, 2 },
273  { 1, 2, 4, 2, 1 },
274  { 0, 1, 2, 1, 0 } };
275  Int_t k3a[3][3] = { { 0, 1, 0 },
276  { 1, 2, 1 },
277  { 0, 1, 0 } }; // norm = 6
278  Int_t k3b[3][3] = { { 1, 2, 1 }, //gauss smoothing
279  { 2, 4, 2 },
280  { 1, 2, 1 } }; // norm = 16
281 
282  Int_t ksize_x, ksize_y;
283  TString opt = option;
284  opt.ToLower();
285  Int_t *kernel = &k5a[0][0];
286  if (opt.Contains("k5a")) {
287  kernel = &k5a[0][0];
288  ksize_x = ksize_y = 5;
289  }
290  else if (opt.Contains("k5b")) {
291  kernel = &k5b[0][0];
292  ksize_x = ksize_y = 5;
293  }
294  else if (opt.Contains("k3a")) {
295  kernel = &k3a[0][0];
296  ksize_x = ksize_y = 3;
297  }
298  else if (opt.Contains("k3b")) {
299  kernel = &k3b[0][0];
300  ksize_x = ksize_y = 3;
301  }
302  else return 1.;
303 
304  // Kernel tail sizes (kernel sizes must be odd for this to work!)
305  Int_t x_push = (ksize_x-1)/2;
306  Int_t y_push = (ksize_y-1)/2;
307 
308  Int_t norm=0;
309  for(int i=0; i<ksize_x; i++)
310  for(int j=0; j<ksize_y; j++) norm += kernel[i*ksize_y +j];
311 
312  int nx = NX(), ny= NY();
313 
314  EdbH2 buf( *((EdbH2*)this) );
315 
316  Long_t content;
317  int bin=0, k=0;
318 
319  for (int i=0; i<nx; i++){ // input hist
320  for (int j=0; j<=ny; j++) {
321 
322  content = 0;
323  for (int n=0; n<ksize_x; n++) { // kernel
324  for (int m=0; m<ksize_y; m++) {
325  Int_t xb = i+(n-x_push);
326  Int_t yb = j+(m-y_push);
327  bin = buf.Bin(xb,yb); // out of dimensions - return 0;
328  if (!bin) continue;
329  k = kernel[n*ksize_y +m];
330  if (!k) continue;
331  content += k*bin;
332  }
333  }
334  //SetBin( i, j, Nint(1.*content/norm) );
335  SetBin( i, j, content );
336  }
337  }
338  eNorm = (float)norm;
339  return eNorm;
340 }
int NX() const
Definition: EdbCell2.h:50
void SetBin(int ix, int iy, int n)
Definition: EdbCell2.h:91
int NY() const
Definition: EdbCell2.h:51
int nx
Definition: emthickness.cpp:60
int ny
Definition: emthickness.cpp:62
const char * opt
Definition: mc2raw.cxx:42

◆ WipePeak()

int EdbPeak2::WipePeak ( int  iv[2],
int  ir[2] 
)
462 {
463  int mean = (int)Mean();
464  int nbin=0;
465  for(int ix=iv[0]-ir[0]; ix<=iv[0]+ir[0]; ix++)
466  for(int iy=iv[1]-ir[1]; iy<=iv[1]+ir[1]; iy++)
467  if(Jcell(ix,iy)>-1)
468  {eNC[Jcell(ix,iy)] = mean; nbin++;}
469  return nbin;
470 }
Float_t Mean()
Definition: EdbCell2.h:96

◆ Xmean()

float EdbPeak2::Xmean ( )
551 {
552  Double_t mean=0, sum=0;
553  for(int ix=0; ix<eN[0]; ix++) {
554  float x = X(ix);
555  for(int iy=0; iy<eN[1]; iy++) {
556  int j = Jcell(ix,iy);
557  mean += x*eNC[j];
558  sum += eNC[j];
559  }
560  }
561  mean /= sum;
562  return mean;
563 }

◆ Ymean()

float EdbPeak2::Ymean ( )
567 {
568  Double_t mean=0, sum=0;
569  for(int iy=0; iy<eN[1]; iy++) {
570  float y = Y(iy);
571  for(int ix=0; ix<eN[0]; ix++) {
572  int j = Jcell(ix,iy);
573  mean += y*eNC[j];
574  sum += eNC[j];
575  }
576  }
577  mean /= sum;
578  return mean;
579 }

Member Data Documentation

◆ eMean

TArrayF EdbPeak2::eMean

◆ eMean3

TArrayF EdbPeak2::eMean3

◆ eNorm

Float_t EdbPeak2::eNorm

◆ eNpeaks

Int_t EdbPeak2::eNpeaks

◆ ePeak

TArrayF EdbPeak2::ePeak

◆ eXpeak

TArrayF EdbPeak2::eXpeak

◆ eYpeak

TArrayF EdbPeak2::eYpeak

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