FEDRA emulsion software from the OPERA Collaboration
EdbPeak2 Class Reference

peak analyser for EdbH2 More...

#include <EdbCell2.h>

Inheritance diagram for EdbPeak2:
Collaboration diagram for EdbPeak2:

Public Member Functions

void Delete ()
 
 EdbPeak2 ()
 
 EdbPeak2 (const EdbH2 &h)
 
float EstimatePeakMeanPosition (int iv[2], int ir[2], float &x, float &y)
 
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 DrawSpectrun")
 
 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 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
 the norm-factor in case of the smoothing applied More...
 
Int_t eNpeaks
 number of found peaks More...
 
TArrayF ePeak
 

Additional Inherited Members

- Protected Attributes inherited from EdbH2
Float_t eBin [2]
 bin size More...
 
Float_t eMax [2]
 max More...
 
Float_t eMin [2]
 min More...
 
Int_t eN [2]
 divisions More...
 
Int_t * eNC
 [eNcell] number of objects/cell More...
 
Int_t eNcell
 eNx*eNy More...
 

Detailed Description

peak analyser for EdbH2

Constructor & Destructor Documentation

◆ EdbPeak2() [1/2]

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

◆ EdbPeak2() [2/2]

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

◆ ~EdbPeak2()

EdbPeak2::~EdbPeak2 ( )
inline
117{}

Member Function Documentation

◆ Delete()

void EdbPeak2::Delete ( )
244{
245 ((EdbH2*)this)->Delete();
246 eNpeaks=0;
247}
fast 2-dim histogram class (used as a basis for EdbCell2)
Definition: EdbCell2.h:19
Int_t eNpeaks
number of found peaks
Definition: EdbCell2.h:108

◆ EstimatePeakMeanPosition()

float EdbPeak2::EstimatePeakMeanPosition ( int  iv[2],
int  ir[2],
float &  x,
float &  y 
)
355{
356 double x0=0, y0=0, volume=0;
357 for(int ix=iv[0]-ir[0]; ix<=iv[0]+ir[0]; ix++)
358 for(int iy=iv[1]-ir[1]; iy<=iv[1]+ir[1]; iy++)
359 {
360 x0 += Bin(ix,iy)*X(ix);
361 y0 += Bin(ix,iy)*Y(iy);
362 volume += Bin(ix,iy);
363 }
364 if(volume>0) { x = x0/volume; y = y0/volume; }
365 return volume;
366}
float X(int ix) const
Definition: EdbCell2.h:60
float Y(int iy) const
Definition: EdbCell2.h:61
int Bin(float x, float y) const
Definition: EdbCell2.h:80

◆ EstimatePeakVolume()

float EdbPeak2::EstimatePeakVolume ( int  ipeak)
415{
416 if(ipeak>(eNpeaks-1)||ipeak<0) return 0;
417 return ePeak[ipeak] + 8*eMean3[ipeak] - 9*eMean[ipeak];
418}
TArrayF eMean
Definition: EdbCell2.h:111
TArrayF ePeak
Definition: EdbCell2.h:109
TArrayF eMean3
Definition: EdbCell2.h:110

◆ EstimatePeakVolumeSafe()

float EdbPeak2::EstimatePeakVolumeSafe ( int  ipeak)

add to the background one standard deviation for the safety

407{
409 if(ipeak>(eNpeaks-1)||ipeak<0) return 0;
410 return ePeak[ipeak] + 8*eMean3[ipeak] - 9*(eMean[ipeak] + Sqrt(eMean[ipeak]));
411}

◆ FindGlobalPeak()

float EdbPeak2::FindGlobalPeak ( float &  x,
float &  y,
float  ratio = 0.1 
)

to find the center of wide multibin peak select ratio*Nbin of highest bins and calculate CoG

454{
456 int n = Ncell();
457 TArrayI ind(n);
458 Sort(n, eNC , ind.GetArray(), 0); // sort encreasing order
459 Int_t nwipe = Min( (Int_t)((1.-ratio)*n), n-1 );
460 double mean=0;
461 for(int i=0; i<nwipe; i++) {
462 mean += eNC[ind[i]];
463 eNC[ind[i]] = 0;
464 }
465 mean /= nwipe;
466 x = Xmean();
467 y = Ymean();
468 float peakvolume = Integral() - (n-nwipe)*mean;
469 Log(3,"EdbPeak2::FindGlobalPeak","of volume %8.2f at %10.2f %10.2f using %d bins",
470 peakvolume,x,y, n-nwipe );
471 return peakvolume;
472}
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
Int_t * eNC
[eNcell] number of objects/cell
Definition: EdbCell2.h:29
int Ncell() const
Definition: EdbCell2.h:49
Long_t Integral()
Definition: EdbCell2.cpp:216
float Ymean()
Definition: EdbCell2.cpp:437
float Xmean()
Definition: EdbCell2.cpp:421

◆ FindPeak() [1/3]

int EdbPeak2::FindPeak ( float &  x,
float &  y 
)
397{
398 int iv[2];
399 int peak=FindPeak(iv);
400 x = X(iv[0]);
401 y = Y(iv[1]);
402 return peak;
403}
int FindPeak(int iv[2])
Definition: EdbCell2.cpp:369

◆ FindPeak() [2/3]

int EdbPeak2::FindPeak ( float  v[2])
387{
388 int iv[2];
389 int peak=FindPeak(iv);
390 v[0] = X(iv[0]);
391 v[1] = Y(iv[1]);
392 return peak;
393}

◆ FindPeak() [3/3]

int EdbPeak2::FindPeak ( int  iv[2])
370{
371 int peak=0;
372 for(int ix=0; ix<eN[0]; ix++)
373 for(int iy=0; iy<eN[1]; iy++) {
374 int j = Jcell(ix,iy);
375 if(eNC[j]>peak) {
376 peak =eNC[j];
377 iv[0] = ix;
378 iv[1] = iy;
379 }
380 }
381 Log(4,"EdbPeak2::FindPeak","of %d at %d %d", peak, iv[0],iv[1] );
382 return peak;
383}
int Jcell(int ix, int iy) const
Definition: EdbCell2.h:57
Int_t eN[2]
divisions
Definition: EdbCell2.h:23

◆ FindPeak9()

float EdbPeak2::FindPeak9 ( float &  x,
float &  y 
)

particular case of 3x3 peak neiboring, return peak volume and estimate mean position

346{
348 int iv[2], ir[2]={1,1};
349 FindPeak(iv);
350 return EstimatePeakMeanPosition(iv, ir, x, y);
351}
float EstimatePeakMeanPosition(int iv[2], int ir[2], float &x, float &y)
Definition: EdbCell2.cpp:354

◆ Init()

void EdbPeak2::Init ( const EdbH2 h,
int  npeaks = 10 
)
251{
252 Delete();
253 ((EdbH2*)this)->Copy(h);
254 InitPeaks(npeaks);
255}
void Delete()
Definition: EdbCell2.cpp:243

◆ InitPeaks()

void EdbPeak2::InitPeaks ( int  npeaks)
259{
260 eNpeaks=0;
261 ePeak.Set(npeaks); ePeak.Reset(0);
262 eMean3.Set(npeaks); eMean3.Reset(0);
263 eMean.Set(npeaks); eMean.Reset(0);
264 eNorm = 1.; // default norm factor;
265}
Float_t eNorm
the norm-factor in case of the smoothing applied
Definition: EdbCell2.h:112

◆ 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 ( )
269{
270 printf("%d peaks:\n", eNpeaks);
271 for(int i=0; i<eNpeaks; i++)
272 printf("%d : %f %f %f \n", i, ePeak[i], eMean3[i], eMean[i]);
273}

◆ ProbPeak() [1/3]

float EdbPeak2::ProbPeak ( )
288{
289 int iv[2];
290 FindPeak(iv);
291 int ir[2]={1,1}; // 3x3 neigbouring
292 return ProbPeak(iv,ir);
293}
float ProbPeak()
Definition: EdbCell2.cpp:287

◆ ProbPeak() [2/3]

float EdbPeak2::ProbPeak ( float &  x,
float &  y 
)
277{
278 int iv[2];
279 FindPeak(iv);
280 x = X(iv[0]);
281 y = Y(iv[1]);
282 int ir[2]={1,1}; // 3x3 neigbouring
283 return ProbPeak(iv,ir);
284}

◆ ProbPeak() [3/3]

float EdbPeak2::ProbPeak ( int  iv[2],
int  ir[2] 
)
317{
318 float prob=0;
319 int npeak = Bin(iv);
320 int nbinPeak = (2*ir[0]+1)*(2*ir[1]+1);
321 float meanNeib = 1.*(Integral(iv,ir) - npeak)/(nbinPeak-1);
322 float meanNoPeak = 1.*(Integral() - Integral(iv,ir))/(Ncell()-nbinPeak);
323 Log(3,"ProbPeak","found at (%3d %3d): %4d %6.3f %6.3f", iv[0],iv[1],npeak, meanNeib,meanNoPeak);
324 ePeak[eNpeaks] = npeak;
325 eMean3[eNpeaks] = meanNeib;
326 eMean[eNpeaks] = meanNoPeak;
327 prob = npeak - meanNoPeak; // ToDo: this is not normalised value
328 eNpeaks++;
329 return prob;
330}

◆ ProbPeaks() [1/2]

int EdbPeak2::ProbPeaks ( int  npeak)
297{
298 int ir[2]={1,1};
299 return ProbPeaks(npeaks,ir);
300}
int ProbPeaks(int npeak)
Definition: EdbCell2.cpp:296

◆ ProbPeaks() [2/2]

int EdbPeak2::ProbPeaks ( int  npeak,
int  ir[2] 
)
304{
305 int iv[2], ic=0;
306 for(int i=0; i<npeaks; i++) {
307 FindPeak(iv);
308 ProbPeak(iv,ir);
309 WipePeak(iv,ir);
310 ic++;
311 }
312 return ic;
313}
int WipePeak(int iv[2], int ir[2])
Definition: EdbCell2.cpp:333

◆ Smooth()

float EdbPeak2::Smooth ( Option_t *  option = "k5a")

Smooth bin contents of this 2-d histogram using kernel algorithms
similar to the ones used in the raster graphics community.
Bin contents in the active range are replaced by their smooth values.
This code is copied from root_5.22 mainly to not depend on the newest root versions
Adopted to fedra by VT
to speedup processing do all calculations as integer, so the histogram do not normalised at output
return value - norm-factor of the kernel

476{
485
486 if(NX()<1||NY()<1) return 1.;
487
488 Int_t k5a[5][5] = { { 0, 0, 1, 0, 0 },
489 { 0, 2, 2, 2, 0 },
490 { 1, 2, 5, 2, 1 },
491 { 0, 2, 2, 2, 0 },
492 { 0, 0, 1, 0, 0 } }; // norm = 25
493 Int_t k5b[5][5] = { { 0, 1, 2, 1, 0 },
494 { 1, 2, 4, 2, 1 },
495 { 2, 4, 8, 4, 2 },
496 { 1, 2, 4, 2, 1 },
497 { 0, 1, 2, 1, 0 } };
498 Int_t k3a[3][3] = { { 0, 1, 0 },
499 { 1, 2, 1 },
500 { 0, 1, 0 } }; // norm = 6
501 Int_t k3b[3][3] = { { 1, 2, 1 }, //gauss smoothing
502 { 2, 4, 2 },
503 { 1, 2, 1 } }; // norm = 16
504
505 Int_t ksize_x, ksize_y;
506 TString opt = option;
507 opt.ToLower();
508 Int_t *kernel = &k5a[0][0];
509 if (opt.Contains("k5a")) {
510 kernel = &k5a[0][0];
511 ksize_x = ksize_y = 5;
512 }
513 else if (opt.Contains("k5b")) {
514 kernel = &k5b[0][0];
515 ksize_x = ksize_y = 5;
516 }
517 else if (opt.Contains("k3a")) {
518 kernel = &k3a[0][0];
519 ksize_x = ksize_y = 3;
520 }
521 else if (opt.Contains("k3b")) {
522 kernel = &k3b[0][0];
523 ksize_x = ksize_y = 3;
524 }
525 else return 1.;
526
527 // Kernel tail sizes (kernel sizes must be odd for this to work!)
528 Int_t x_push = (ksize_x-1)/2;
529 Int_t y_push = (ksize_y-1)/2;
530
531 Int_t norm=0;
532 for(int i=0; i<ksize_x; i++)
533 for(int j=0; j<ksize_y; j++) norm += kernel[i*ksize_y +j];
534
535 int nx = NX(), ny= NY();
536
537 EdbH2 buf( *((EdbH2*)this) );
538
539 Long_t content;
540 int bin=0, k=0;
541
542 for (int i=0; i<nx; i++){ // input hist
543 for (int j=0; j<=ny; j++) {
544
545 content = 0;
546 for (int n=0; n<ksize_x; n++) { // kernel
547 for (int m=0; m<ksize_y; m++) {
548 Int_t xb = i+(n-x_push);
549 Int_t yb = j+(m-y_push);
550 bin = buf.Bin(xb,yb); // out of dimensions - return 0;
551 if (!bin) continue;
552 k = kernel[n*ksize_y +m];
553 if (!k) continue;
554 content += k*bin;
555 }
556 }
557 //SetBin( i, j, Nint(1.*content/norm) );
558 SetBin( i, j, content );
559 }
560 }
561
562 eNorm = (float)norm;
563 return eNorm;
564}
int NX() const
Definition: EdbCell2.h:50
void SetBin(int ix, int iy, int n)
Definition: EdbCell2.h:90
int NY() const
Definition: EdbCell2.h:51
const char * opt
Definition: mc2raw.cxx:42

◆ WipePeak()

int EdbPeak2::WipePeak ( int  iv[2],
int  ir[2] 
)
334{
335 int mean = (int)Mean();
336 int nbin=0;
337 for(int ix=iv[0]-ir[0]; ix<=iv[0]+ir[0]; ix++)
338 for(int iy=iv[1]-ir[1]; iy<=iv[1]+ir[1]; iy++)
339 if(Jcell(ix,iy)>-1)
340 {eNC[Jcell(ix,iy)] = mean; nbin++;}
341 return nbin;
342}
Float_t Mean()
Definition: EdbCell2.h:96

◆ Xmean()

float EdbPeak2::Xmean ( )
422{
423 Double_t mean=0, sum=0;
424 for(int ix=0; ix<eN[0]; ix++) {
425 float x = X(ix);
426 for(int iy=0; iy<eN[1]; iy++) {
427 int j = Jcell(ix,iy);
428 mean += x*eNC[j];
429 sum += eNC[j];
430 }
431 }
432 mean /= sum;
433 return mean;
434}

◆ Ymean()

float EdbPeak2::Ymean ( )
438{
439 Double_t mean=0, sum=0;
440 for(int iy=0; iy<eN[1]; iy++) {
441 float y = Y(iy);
442 for(int ix=0; ix<eN[0]; ix++) {
443 int j = Jcell(ix,iy);
444 mean += y*eNC[j];
445 sum += eNC[j];
446 }
447 }
448 mean /= sum;
449 return mean;
450}

Member Data Documentation

◆ eMean

TArrayF EdbPeak2::eMean

◆ eMean3

TArrayF EdbPeak2::eMean3

◆ eNorm

Float_t EdbPeak2::eNorm

the norm-factor in case of the smoothing applied

◆ eNpeaks

Int_t EdbPeak2::eNpeaks

number of found peaks

◆ ePeak

TArrayF EdbPeak2::ePeak

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