ArrayTH1D Class Reference

#include <ArrayTH1D.h>

List of all members.

Public Member Functions

 ArrayTH1D ()
 ArrayTH1D (const Char_t *, const Char_t *, Int_t, Double_t, Double_t, Bool_t variable_flag)
 ArrayTH1D (TH1D *hist, Bool_t variable_flag)
 ~ArrayTH1D ()
Int_t GetNBins ()
Int_t GetNEntries ()
void Fill (Double_t xvalue, Double_t weight)
void Add (ArrayTH1D *arrayhist, Double_t weight)
Double_t GetBinContent (Int_t binplus1)
void SetBinContent (Int_t binplus1, Double_t content)
Double_t GetXaxisGetBinCenter (Int_t binplus1)
Double_t GetXaxisGetBinLowEdge (Int_t binnumber)
Double_t GetXaxisGetBinUpEdge (Int_t binnumber)
void Scale (Double_t scale)
void Decay (Double_t alpha, Double_t sin2)
void Reset ()
Char_t * GetHistName ()
ArrayTH1DCloneArrayHist ()
TH1D * ConvertTH1D (const Char_t *histname)
TH1D * ConvertTH1D ()

Private Member Functions

Int_t GetBinNumber (Double_t xvalue)
void SetNEntries (Int_t entries)

Private Attributes

Int_t fNEntries
Int_t fNBins
Double_t fXMin
Double_t fXMax
Bool_t fVariableBinningFlag
Double_t fUnderflowBinCenter1
Double_t * fOverflowBinCenters
const Char_t * fArrayHistName
const Char_t * fArrayHistTitle
Double_t * fXArray
Double_t * fBinEdges

Detailed Description

Definition at line 8 of file ArrayTH1D.h.


Constructor & Destructor Documentation

ArrayTH1D::ArrayTH1D (  ) 

Definition at line 12 of file ArrayTH1D.cxx.

Referenced by CloneArrayHist().

00013 {
00014   //Initialise to low level values as constructor
00015   fNBins = 1;
00016   fNEntries = 0;
00017   fXMin = 0.0;
00018   fXMax = 1.0;
00019 
00020   fXArray = new Double_t[fNBins+2];
00021   for(Int_t i=0;i<fNBins+2;i++) fXArray[i] = 0.0;  
00022 }

ArrayTH1D::ArrayTH1D ( const Char_t *  arrayhistname,
const Char_t *  arrayhisttitle,
Int_t  nbins,
Double_t  xmin,
Double_t  xmax,
Bool_t  variable_flag 
)

Definition at line 23 of file ArrayTH1D.cxx.

References fArrayHistName, fArrayHistTitle, fBinEdges, fNBins, fNEntries, fOverflowBinCenters, fUnderflowBinCenter1, fVariableBinningFlag, fXArray, fXMax, and fXMin.

00024 {
00025   fNBins = nbins;
00026   fXMin = xmin;
00027   fXMax = xmax;
00028   fNEntries = 0;
00029   fArrayHistName = arrayhistname;
00030   fArrayHistTitle = arrayhisttitle;
00031   fVariableBinningFlag = variable_flag;
00032 
00033   if(fNBins <=0){
00034     cout << " *-* Error: Bin number Incorrect, Setting to 1 " << endl;
00035     fNBins = 1;
00036   }
00037 
00038   if(fXMin == fXMax){
00039     cout << " *-* Error: Min Value = Max Value, Incrementing Max Value by 1 *-* " << endl;
00040     fXMax += 1.;
00041   }
00042 
00043   if(fXMin > fXMax){
00044     cout << " *-* Error: Min Value > Max Value, Swapping Limits *-*" << endl;
00045      Double_t fmintemp = fXMin;
00046      Double_t fmaxtemp = fXMax;
00047      
00048      fXMin = fmaxtemp;
00049      fXMax = fmintemp;
00050   }
00051   //Set up arrays
00052   fXArray = new Double_t[fNBins+2]; for(Int_t i=0;i<fNBins+2;i++) fXArray[i] = 0.0;
00053   fBinEdges = new Double_t[fNBins+1]; for(Int_t i=0;i<fNBins+1;i++) fBinEdges[i] = 0.0;
00054   fOverflowBinCenters = new Double_t[21]; for(Int_t i=0;i<21;i++) fOverflowBinCenters[i] = 0.0;//setup here, only use if varialbe binning array
00055 
00056   if(!fVariableBinningFlag){
00057     Double_t binwidth = (fXMax - fXMin)/fNBins;
00058     for(Int_t i=0;i<fNBins;i++) fBinEdges[i+1] = fBinEdges[i] + binwidth; 
00059   }
00060 
00061   if(fVariableBinningFlag){  
00062 
00063     if( fNBins<100 ){
00064       cout << " ******** ERROR ERROR ERROR " << endl;
00065     }
00066 
00067     fUnderflowBinCenter1 = 0.25;
00068     fOverflowBinCenters[0] = 20.5;
00069     for(Int_t i=0;i<9;i++) fOverflowBinCenters[i+1] = fOverflowBinCenters[i] + 1;
00070     fOverflowBinCenters[10] = 31;
00071     for(Int_t i=1;i<10;i++) fOverflowBinCenters[i+10] = fOverflowBinCenters[i+9] + 2;
00072     fOverflowBinCenters[20] = 75;
00073 
00074     fBinEdges[1] = 0.5;
00075     for(Int_t i=2;i<80;i++) fBinEdges[i] = fBinEdges[i-1] + 0.25;
00076     for(Int_t i=80;i<90;i++) fBinEdges[i] = fBinEdges[i-1] + 1;
00077     for(Int_t i=90;i<99;i++) fBinEdges[i] = fBinEdges[i-1] + 2;
00078     fBinEdges[99] = 50; fBinEdges[100] = 200;
00079   }
00080 }

ArrayTH1D::ArrayTH1D ( TH1D *  hist,
Bool_t  variable_flag 
)

Definition at line 82 of file ArrayTH1D.cxx.

References fBinEdges, fNBins, fNEntries, fOverflowBinCenters, fUnderflowBinCenter1, fVariableBinningFlag, fXArray, fXMax, and fXMin.

00083 {
00084   fNBins = hist->GetXaxis()->GetNbins();
00085   fXMin = hist->GetXaxis()->GetBinLowEdge(1);
00086   fXMax = hist->GetXaxis()->GetBinUpEdge(fNBins);
00087   fNEntries = (Int_t)hist->GetEntries();
00088   fVariableBinningFlag = variable_flag;
00089 
00090   fXArray = new Double_t[fNBins+2]; for(Int_t i=0;i<fNBins+2;i++) fXArray[i] = 0.0;
00091   fBinEdges = new Double_t[fNBins+1]; for(Int_t i=0;i<fNBins+1;i++) fBinEdges[i] = 0.0;
00092   fOverflowBinCenters = new Double_t[21];  for(Int_t i=0;i<21;i++) fOverflowBinCenters[i] = 0.0;//setup here, only use if varalbe binning array
00093 
00094   fBinEdges[0] = hist->GetXaxis()->GetBinLowEdge(1);
00095   for(Int_t i=0;i<fNBins+1;i++){
00096     fBinEdges[i] = hist->GetXaxis()->GetBinUpEdge(i+1);
00097   }
00098   
00099   for(Int_t i=0;i<fNBins+2;i++){
00100     fXArray[i] = hist->GetBinContent(i); //copies overflow
00101   }
00102   
00103   if(fVariableBinningFlag){  
00104 
00105     fUnderflowBinCenter1 = 0.25;
00106     fOverflowBinCenters[0] = 20.5;
00107     for(Int_t i=0;i<9;i++) fOverflowBinCenters[i+1] = fOverflowBinCenters[i] + 1;
00108     fOverflowBinCenters[10] = 31;
00109     for(Int_t i=1;i<10;i++) fOverflowBinCenters[i+10] = fOverflowBinCenters[i+9] + 2;
00110     fOverflowBinCenters[20] = 75;
00111   }
00112 }

ArrayTH1D::~ArrayTH1D (  ) 

Definition at line 114 of file ArrayTH1D.cxx.

References fBinEdges, fOverflowBinCenters, and fXArray.

00115 {
00116   delete[] fXArray;
00117   delete[] fBinEdges;
00118   delete[] fOverflowBinCenters;
00119 }


Member Function Documentation

void ArrayTH1D::Add ( ArrayTH1D arrayhist,
Double_t  weight 
)

Definition at line 160 of file ArrayTH1D.cxx.

References fNBins, fNEntries, fXArray, GetBinContent(), and GetNBins().

Referenced by GhostSample::GetSpectrum(), and GhostSample::InterpMin().

00161 {
00162   if(this->fNBins == arrayhist->GetNBins()){
00163     for(Int_t i=0;i<fNBins+2;i++){
00164       fXArray[i] += weight*(arrayhist->GetBinContent(i));
00165     }
00166     fNEntries += arrayhist->fNEntries; 
00167   }
00168   else cout << " *-* Error: Attempting to Add Array Histograms with Different Numbers of Bins *-*" << endl;
00169 }

ArrayTH1D * ArrayTH1D::CloneArrayHist (  ) 

Definition at line 187 of file ArrayTH1D.cxx.

References ArrayTH1D(), fNBins, fNEntries, fVariableBinningFlag, fXArray, fXMax, fXMin, SetBinContent(), and SetNEntries().

00188 {
00189   ArrayTH1D* ArrayTH1Dtemp;
00190   const Char_t* name = "clone";
00191   ArrayTH1Dtemp = new ArrayTH1D(name,name,fNBins,fXMin,fXMax,fVariableBinningFlag);
00192   ArrayTH1Dtemp->SetNEntries(fNEntries);
00193   
00194   for(int i=0;i<fNBins+2;i++){   //Also clones overflow
00195     Double_t tempbincontent = fXArray[i];
00196     ArrayTH1Dtemp->SetBinContent(i,tempbincontent);
00197   }
00198   return ArrayTH1Dtemp;
00199 }

TH1D * ArrayTH1D::ConvertTH1D (  ) 

Definition at line 213 of file ArrayTH1D.cxx.

References fArrayHistName, fArrayHistTitle, fBinEdges, fNBins, fNEntries, and fXArray.

00214 {
00215     
00216   TH1D* htemp = new TH1D(fArrayHistName,fArrayHistTitle,fNBins,fBinEdges);    //Make array for variable bins using, then generate hist
00217   
00218   for(Int_t i=0; i<fNBins; i++){
00219     htemp->SetBinContent(i+1,fXArray[i+1]);
00220   }
00221   htemp->SetEntries(fNEntries);
00222   return htemp;
00223 }

TH1D * ArrayTH1D::ConvertTH1D ( const Char_t *  histname  ) 

Definition at line 201 of file ArrayTH1D.cxx.

References fBinEdges, fNBins, fNEntries, and fXArray.

Referenced by GhostSample::GetSpectrum().

00202 {
00203   
00204   TH1D* htemp = new TH1D(histname,histname,fNBins,fBinEdges);
00205   
00206   for(Int_t i=0; i<fNBins; i++){  //Lose information about overflow here
00207     htemp->SetBinContent(i+1,fXArray[i+1]);
00208   }
00209   htemp->SetEntries(fNEntries);
00210   return htemp;
00211 }

void ArrayTH1D::Decay ( Double_t  alpha,
Double_t  sin2 
)

Definition at line 143 of file ArrayTH1D.cxx.

References NuOscProbCalc::DecayWeightNC(), MuELoss::e, fBinEdges, fNBins, and fXArray.

Referenced by GhostSample::GetSpectrum().

00144 {
00145   fXArray[0] *= GhostUtilities::DecayWeightNC(TMath::Max(fBinEdges[0],1e-10),alpha,sin2);
00146   for(Int_t i=1;i<fNBins+2;i++){
00147     Double_t energy = (fBinEdges[i]+fBinEdges[i-1])/2;
00148     fXArray[i] *= GhostUtilities::DecayWeightNC(energy,alpha,sin2);
00149   }
00150 }

void ArrayTH1D::Fill ( Double_t  xvalue,
Double_t  weight 
)

Definition at line 131 of file ArrayTH1D.cxx.

References fNEntries, fXArray, and GetBinNumber().

00132 {
00133   Int_t BinNumber = this->GetBinNumber(xvalue);
00134   fXArray[BinNumber] += weight;
00135   fNEntries += 1;
00136 }

Double_t ArrayTH1D::GetBinContent ( Int_t  binplus1  ) 

Definition at line 171 of file ArrayTH1D.cxx.

References fXArray.

Referenced by Add().

00172 {
00173   if(binplus1 <= fNBins+1 && binplus1 >= 0){ 
00174     return fXArray[binplus1];
00175   }
00176   return -999;
00177 }

Int_t ArrayTH1D::GetBinNumber ( Double_t  xvalue  )  [private]

Definition at line 225 of file ArrayTH1D.cxx.

References fBinEdges, fNBins, fXMax, and fXMin.

Referenced by Fill().

00226 {
00227   Int_t fBinNumber = -1;
00228   
00229   if(xvalue<=fXMin){
00230     fBinNumber = 0;
00231     return fBinNumber;
00232   }
00233   if(xvalue>=fXMax){
00234     fBinNumber = fNBins + 1;
00235     return fBinNumber;
00236   }
00237   for(Int_t i=0;i<fNBins;i++){
00238     if(fBinEdges[i]<=xvalue && xvalue<fBinEdges[i+1]){
00239       fBinNumber = i+1;
00240       return fBinNumber;
00241     }
00242   }
00243   return -1;
00244 }

Char_t * ArrayTH1D::GetHistName (  ) 

Definition at line 251 of file ArrayTH1D.cxx.

References fArrayHistName.

00252 {
00253   Char_t* ReturnName = (Char_t*)fArrayHistName;
00254   return ReturnName;
00255 }

Int_t ArrayTH1D::GetNBins (  ) 

Definition at line 121 of file ArrayTH1D.cxx.

References fNBins.

Referenced by Add().

00122 {
00123   return fNBins;
00124 }

Int_t ArrayTH1D::GetNEntries (  ) 

Definition at line 126 of file ArrayTH1D.cxx.

References fNEntries.

00127 {
00128   return fNEntries;
00129 }

Double_t ArrayTH1D::GetXaxisGetBinCenter ( Int_t  binplus1  ) 

Definition at line 257 of file ArrayTH1D.cxx.

References fNBins, fOverflowBinCenters, fVariableBinningFlag, fXMax, and fXMin.

00258 {
00259   if(!fVariableBinningFlag){
00260     if(binplus1>=1 && binplus1<=fNBins){
00261       return fXMin + (binplus1-0.5)*(fXMax-fXMin)/(fNBins+0.0);
00262     }
00263   }
00264   if(fVariableBinningFlag){
00265 
00266     if(binplus1==1) return 0.25;
00267 
00268     if(binplus1>=2 && binplus1<80){
00269       return 0.625 + (binplus1-2)*0.25;;
00270     }
00271     
00272     if(binplus1>=80){
00273       return fOverflowBinCenters[binplus1-80];
00274     }
00275   }
00276   if(binplus1<=0){
00277     return fXMin;
00278   }
00279   if(binplus1>fNBins){
00280     return fXMax;
00281   }
00282   return -99999.9;
00283 }

Double_t ArrayTH1D::GetXaxisGetBinLowEdge ( Int_t  binnumber  ) 

Definition at line 285 of file ArrayTH1D.cxx.

References fBinEdges, fNBins, fXMax, and fXMin.

00286 {
00287   if(binplus1>=1 && binplus1<=fNBins){
00288     return fBinEdges[binplus1-1];
00289   }
00290   
00291   if(binplus1<=0){
00292     cout << " *-* Error: Bin plus1 less than or equal to zero *-*" << endl;
00293     return fXMin;
00294   }
00295   
00296   if(binplus1>fNBins){
00297     cout << " *-* Error: Bin plus1 greater then number of bins *-*" << endl;
00298     return fXMax;
00299   }
00300   return -99999.9;
00301 }

Double_t ArrayTH1D::GetXaxisGetBinUpEdge ( Int_t  binnumber  ) 

Definition at line 303 of file ArrayTH1D.cxx.

References fBinEdges, fNBins, fXMax, and fXMin.

00304 {
00305   if(binplus1>=1 && binplus1<=fNBins){
00306     return fBinEdges[binplus1];
00307   }
00308   
00309   if(binplus1<=0){
00310     cout << " *-* Error: Bin plus1 less than or equal to zero *-*" << endl;
00311     return fXMin;
00312   }
00313   
00314   if(binplus1>fNBins){
00315     cout << " *-* Error: Bin plus1 greater then number of bins *-* " << endl;
00316     return fXMax;
00317 }
00318   return -99999.9;
00319 }

void ArrayTH1D::Reset (  ) 

Definition at line 152 of file ArrayTH1D.cxx.

References fNBins, fNEntries, and fXArray.

Referenced by GhostSample::GetSpectrum(), and GhostSample::InterpolateOscillatedSpectra().

00153 {
00154   for(Int_t i=0;i<fNBins+2;i++){
00155     fXArray[i] = 0.0;
00156   }
00157   fNEntries = 0;
00158 }

void ArrayTH1D::Scale ( Double_t  scale  ) 

Definition at line 138 of file ArrayTH1D.cxx.

References fNBins, and fXArray.

Referenced by GhostSample::GetSpectrum().

00139 {
00140   for(Int_t i=0;i<fNBins+2;i++) fXArray[i] = scale*fXArray[i];
00141 }

void ArrayTH1D::SetBinContent ( Int_t  binplus1,
Double_t  content 
)

Definition at line 179 of file ArrayTH1D.cxx.

References fXArray.

Referenced by CloneArrayHist(), and GhostSample::InterpolateOscillatedSpectra().

00180 {
00181   if(binplus1 <= fNBins+1 && binplus1 >= 0){ 
00182     fXArray[binplus1] = content;
00183   }
00184   else cout << " *-* Error: Bin Number Outside Range *-*" << endl;
00185 }

void ArrayTH1D::SetNEntries ( Int_t  entries  )  [private]

Definition at line 246 of file ArrayTH1D.cxx.

References fNEntries.

Referenced by CloneArrayHist().

00247 {
00248   fNEntries = entries;
00249 }


Member Data Documentation

const Char_t* ArrayTH1D::fArrayHistName [private]

Definition at line 55 of file ArrayTH1D.h.

Referenced by ArrayTH1D(), ConvertTH1D(), and GetHistName().

const Char_t* ArrayTH1D::fArrayHistTitle [private]

Definition at line 56 of file ArrayTH1D.h.

Referenced by ArrayTH1D(), and ConvertTH1D().

Double_t* ArrayTH1D::fBinEdges [private]
Int_t ArrayTH1D::fNBins [private]
Int_t ArrayTH1D::fNEntries [private]

Definition at line 43 of file ArrayTH1D.h.

Referenced by Add(), ArrayTH1D(), CloneArrayHist(), ConvertTH1D(), Fill(), GetNEntries(), Reset(), and SetNEntries().

Double_t* ArrayTH1D::fOverflowBinCenters [private]

Definition at line 53 of file ArrayTH1D.h.

Referenced by ArrayTH1D(), GetXaxisGetBinCenter(), and ~ArrayTH1D().

Double_t ArrayTH1D::fUnderflowBinCenter1 [private]

Definition at line 51 of file ArrayTH1D.h.

Referenced by ArrayTH1D().

Definition at line 49 of file ArrayTH1D.h.

Referenced by ArrayTH1D(), CloneArrayHist(), and GetXaxisGetBinCenter().

Double_t* ArrayTH1D::fXArray [private]
Double_t ArrayTH1D::fXMax [private]
Double_t ArrayTH1D::fXMin [private]

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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1