AliPhysics  608b256 (608b256)
TCustomBinning.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 <algorithm>
16 #include <cfloat>
17 #include <functional>
18 #include <vector>
19 
20 #include <TArrayD.h>
21 #include <TMath.h>
22 #include <TCustomBinning.h>
23 
24 ClassImp(TCustomBinning)
25 
27  TBinning(),
28  fMinimum(-10000.),
29  fMinimumSet(kFALSE),
30  fSteps()
31 {
32 }
33 
34 void TCustomBinning::AddStep(double maximum, double binwidth){
35  if(fSteps.find(maximum) != fSteps.end()){
36  printf("TCustomBinning - Maximum already defined\n");
37  return;
38  }
39  fSteps.insert(std::pair<double, double>(maximum, binwidth));
40 }
41 
42 void TCustomBinning::CreateBinEdges(TArrayD &binedges) const {
43  if(!fMinimumSet){
44  throw MinNotSetException();
45  }
46 
47  // sort the ranges
48  std::vector<double> keys;
49  for(auto it : fSteps) keys.push_back(it.first);
50  std::sort(keys.begin(), keys.end(), std::less<double>());
51  std::map<double, double> sortedsteps;
52  for(auto it : keys)
53  sortedsteps.insert(std::pair<double, double>(it, fSteps.find(it)->second));
54 
55 
56  std::vector<double> tmpedges;
57  Double_t currentmin = fMinimum;
58  tmpedges.push_back(currentmin);
59  for(auto range : sortedsteps){
60  while((currentmin < range.first) && (TMath::Abs(currentmin - range.first) > DBL_EPSILON)){
61  currentmin += range.second;
62  tmpedges.push_back(currentmin);
63  }
64  }
65 
66  binedges.Set(tmpedges.size());
67  int bincounter = 0;
68  for(auto binedge : tmpedges) binedges[bincounter++] = binedge;
69 }
70 
72  return new TCustomBinning(*this);
73 }
double Double_t
Definition: External.C:58
virtual TBinning * MakeCopy() const
void AddStep(Double_t max, Double_t binwidth)
Interface for binnings used by the histogram handler.
Definition: TBinning.h:23
std::map< double, double > fSteps
List of ranges with common bin width.
Helper class creating user defined custom binning.
Double_t fMinimum
Minimum of the binning.
virtual void CreateBinEdges(TArrayD &edges) const
Exception thrown in case the minimum is not set.
Bool_t fMinimumSet
Define whether minimum is set. Attention: Bin edges will not be created without minimum.