AliPhysics  1976924 (1976924)
TLinearBinning.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2016, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 #include <cfloat>
16 #include <vector>
17 #include <TArrayD.h>
18 #include <TLinearBinning.h>
19 #include <TMath.h>
20 
22  TBinning(),
23  fNbins(0),
24  fMinimum(0),
25  fMaximum(0),
26  fLimitsSet(kFALSE)
27 {
28 
29 }
30 
32  TBinning(),
33  fNbins(nbins),
34  fMinimum(min),
35  fMaximum(max),
36  fLimitsSet(kTRUE)
37 {
38 
39 }
40 
41 void TLinearBinning::CreateBinEdges(TArrayD &binedges) const {
42  if(!fLimitsSet){
43  throw LimitsNotSetException();
44  }
45  double binwidth = (fMaximum - fMinimum) / fNbins;
46 
47  std::vector<double> tmpedges;
48  double currentmin = fMinimum;
49  tmpedges.push_back(currentmin);
50  while((currentmin < fMaximum) && (TMath::Abs(currentmin - fMaximum) > DBL_EPSILON)){
51  currentmin += binwidth;
52  tmpedges.push_back(currentmin);
53  }
54 
55  binedges.Set(tmpedges.size());
56  int bincounter = 0;
57  for(auto binedge : tmpedges) binedges[bincounter++] = binedge;
58 }
59 
61  return new TLinearBinning(*this);
62 }
double Double_t
Definition: External.C:58
virtual void CreateBinEdges(TArrayD &binedges) const
Interface for binnings used by the histogram handler.
Definition: TBinning.h:21
int Int_t
Definition: External.C:63
Double_t fMinimum
Minimum of the binning.
Exception indicating that the limits are not set.
const Int_t nbins
Int_t fNbins
Number of bins.
Bool_t fLimitsSet
Switch indicating that the binning is initialized.
virtual TBinning * MakeCopy() const
Double_t fMaximum
Maximum of the binning.