12 #include "Stl3Util/gl3/gl3Histo.h"
20 int iNBins,
double iXMin,
double iXMax ) {
23 fprintf ( stderr,
" %d bins, not valid value \n", (
int)iNBins );
26 header.nBins = iNBins ;
27 if ( iXMin > iXMax ) {
28 fprintf ( stderr,
" xMin %e xMax %e, not valid values \n", iXMin, iXMax );
31 strcpy ( header.id, iId ) ;
32 strcpy ( header.title, iTitle ) ;
33 header.nBins = iNBins ;
38 header.yMin = header.yMax = 0. ;
39 header.xStep = (header.xMax-header.xMin)/
float(header.nBins);
42 info =
new double[header.nBins+2];
43 memset ( info, 0, (header.nBins+2)*
sizeof(
double) ) ;
49 if ( info )
delete[] info ;
55 int iBin = (int)((x-header.xMin)/header.xStep)+1 ;
56 if ( iBin < 1 ) iBin = 0 ;
57 else if ( iBin > header.nBins ) iBin = header.nBins + 1 ;
58 info[iBin] += weight ;
59 if ( iBin > 1 && iBin < header.nBins + 1 ) {
60 if ( info[iBin] > header.yMax )
62 header.yMax = info[iBin] ;
65 if ( info[iBin] < header.yMin ) header.yMin = info[iBin] ;
67 header.sum += weight ;
75 if ( iBin < 0 || iBin > header.nBins+2 ) {
76 printf(
"out of range\n");
85 printf (
"gl3Histo::Print: id %s title %s nBins %d \n",
86 header.id, header.title, (
int)header.nBins ) ;
102 if ( info )
delete info ;
103 info =
new double[header.nBins+2];
106 (header.nBins+2)*
sizeof(
double) ) ;
120 header.nEntries = 0 ;
125 memset ( info, 0, (header.nBins+2)*
sizeof(
double) ) ;
135 >= (
size_t)maxBytes ) {
137 printf(
"gl3Histo::Write %d bytes in buffer not enough \n", maxBytes);
143 (header.nBins+2)*
sizeof(
double) );
166 return header.maxBin;
174 return(header.xMin+(
float(Bin-0.5)*header.xStep)) ;
183 for(
int cnt=minBin; cnt<=maxBin; cnt++) sum +=
GetY(cnt);
192 double gl3Histo::getWeightedMean(
double sigmaWidthBins)
202 double SigmaHalfL =
Integral(
int(HistoMaxBin-sigmaWidthBins),HistoMaxBin-1);
203 double SigmaHalfR =
Integral(HistoMaxBin+1,
int(HistoMaxBin+sigmaWidthBins));
204 double SigmaHalfLCenter=0;
206 for(
int cnt=HistoMaxBin-1; cnt>=(HistoMaxBin-sigmaWidthBins); cnt--) {
207 SigmaHalfLCenter = SigmaHalfLCenter +
GetBinCenter(cnt);
209 SigmaHalfLCenter=SigmaHalfLCenter/sigmaWidthBins;
211 double SigmaHalfRCenter=0;
212 for(
int cnt=HistoMaxBin+1; cnt<=(HistoMaxBin+sigmaWidthBins); cnt++) {
215 SigmaHalfRCenter=SigmaHalfRCenter/sigmaWidthBins;
218 if((SigmaHalfL+HistoMax+SigmaHalfR)>0) {
219 weightedMean = ( (SigmaHalfL * SigmaHalfLCenter) +
220 (HistoMax * HistoMaxCenter) +
221 (SigmaHalfR * SigmaHalfRCenter) )
222 / (SigmaHalfL+HistoMax+SigmaHalfR);
224 else weightedMean=0.0;
226 return(weightedMean);
double GetMaximum()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...
int Reset()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
double GetBinCenter(int Bin)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...
int Write(unsigned int maxBytes, char *output)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
double Integral(int minBin, int maxBin)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...
~gl3Histo()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...
double GetY(int iBin)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...
int Print(short Level=1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...
gl3Histo(char iId[10]="id", char iTitle[100]="name", int iNBins=100, double iXMin=0., double iXMax=100.)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...
int GetMaximumBin()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...
int Read(char *input)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
int Fill(double x, double weight=1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...