AliPhysics  3b4a69f (3b4a69f)
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 
25  TBinning(),
26  fMinimum(-10000.),
27  fMinimumSet(kFALSE),
28  fSteps()
29 {
30 }
31 
32 void TCustomBinning::AddStep(double maximum, double binwidth){
33  if(fSteps.find(maximum) != fSteps.end()){
34  printf("TCustomBinning - Maximum already defined\n");
35  return;
36  }
37  fSteps.insert(std::pair<double, double>(maximum, binwidth));
38 }
39 
40 void TCustomBinning::CreateBinEdges(TArrayD &binedges) const {
41  if(!fMinimumSet){
42  throw MinNotSetException();
43  }
44 
45  // sort the ranges
46  std::vector<double> keys;
47  for(auto it : fSteps) keys.push_back(it.first);
48  std::sort(keys.begin(), keys.end(), std::less<double>());
49  std::map<double, double> sortedsteps;
50  for(auto it : keys)
51  sortedsteps.insert(std::pair<double, double>(it, fSteps.find(it)->second));
52 
53 
54  std::vector<double> tmpedges;
55  Double_t currentmin = fMinimum;
56  tmpedges.push_back(currentmin);
57  for(auto range : sortedsteps){
58  while((currentmin < range.first) && (TMath::Abs(currentmin - range.first) > DBL_EPSILON)){
59  currentmin += range.second;
60  tmpedges.push_back(currentmin);
61  }
62  }
63 
64  binedges.Set(tmpedges.size());
65  int bincounter = 0;
66  for(auto binedge : tmpedges) binedges[bincounter++] = binedge;
67 }
68 
70  return new TCustomBinning(*this);
71 }
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:21
std::map< double, double > fSteps
List of ranges with common bin width.
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.