MINT2
DalitzHistoStackSet.cpp
Go to the documentation of this file.
2 #include "TCanvas.h"
3 #include "TList.h"
4 #include "TPaletteAxis.h"
5 #include "TStyle.h"
6 
7 using namespace std;
8 using namespace MINT;
9 
11  : DalitzSet<THStack>()
12  , _ncol(0)
13  , _palette(0)
14  , _max(0)
15  , _min(0)
16  , _h2ForPalette(0)
17 {
18 }
19 
21  : DalitzSet<THStack>(other)
22  , _histograms(other._histograms)
23  , _h2ForPalette(other._h2ForPalette)
24 {
25  setColourPalette(other._ncol, other._palette, other._max);
26 }
27 
30  std::string thisName = name() + "_stack " + coord.name();
31  counted_ptr<THStack> ptr(new THStack(thisName.c_str(),thisName.c_str()));
32  return ptr;
33 }
34 
36  , const counted_ptr<TH1>& histo){
37  if(0 == histo) return;
38  if(0 == (*this)[coord]){
39  (*this)[coord] = makeHStack(coord);
40  }
41  _histograms.push_back(histo);
42  ((*this)[coord])->Add(histo.get());
43 }
45  add(histo.coord(), histo.histo());
46 }
48  for(map< DalitzCoordSet, DalitzHistogram>::const_iterator it = hL.begin();
49  it != hL.end();
50  it++){
51  this->add(it->second);
52  }
53  return;
54 }
55 
57  if(_ncol <= 0 || 0 == _palette){
58  counted_ptr<TH2F> ptr(0);
59  _h2ForPalette = ptr;
60  }
61  gStyle->SetPalette(_ncol, _palette);
62  gStyle->SetNumberContours(_ncol);
63 
64 
65  counted_ptr<TH2F> h2(new TH2F("blub", "bla", 2, 0, 2, 2, 0, 2));
66  h2->Fill(0.5, 0.5, 0.5*_min);
67  h2->Fill(1.5, 1.5, _min);
68  h2->Fill(0.5, 1.5, 0.5*_max);
69  h2->Fill(1.5, 0.5, _max);
70  TCanvas can;
71  h2->Draw("COLZ");
72  can.Print("colourScale.eps");
73  _h2ForPalette = h2;
74 }
75 
78  return _h2ForPalette;
79 }
80 
81 
83  if(0 == getH2ForPalette()) return 0;
84  return (TPaletteAxis*) getH2ForPalette()->GetListOfFunctions()->FindObject("palette");
85 }
86 
87 bool DalitzHistoStackSet::draw(const std::string& baseName
88  , const std::string& drawOpt
89  , const std::string& format
90  ) const{
91  bool sc=true;
92 
93  TPaletteAxis* pa = getPaletteAxis();
94 
95  cout << "Hello from DalitzHistoStackSet::draw"
96  << " with " << this->size() << " histo stacks" << endl;
97 
98  for(map< DalitzCoordSet, counted_ptr<THStack> >::const_iterator
99  it = this->begin();
100  it != this->end();
101  it++){
102  if(0 == it->second){
103  cout << "it->second is 0" << endl;
104  continue;
105  }
106  TCanvas can;
107  DalitzCoordSet c(it->first);
108  string fname = baseName + c.nameFileSave() + "." + format;
109 
110  it->second->Draw(drawOpt.c_str());
111  cout << "drew histostack of size " << it->second->GetHists()->GetSize()
112  << endl;
113  if(0 != pa) pa->Draw("SAME");
114  can.Print(fname.c_str());
115  cout << "printed histo to file " << fname << endl;
116  }
117  return sc;
118 }
119 
120 void DalitzHistoStackSet::setColourPalette(int nCol, int* pal, double max, double min){
121  if(0 == pal) return;
122  if(0 == nCol) return;
123 
124  if(0 != _palette) delete[] _palette;
125  _ncol=nCol;
126  _palette = new int[_ncol];
127  for(int i=0; i < _ncol; i++) _palette[i] = pal[i];
128  _max = max;
129  _min = min;
130 }
131 
133  if(0 != _palette) delete[] _palette;
134 }
135 
136 //
137 //
std::string nameFileSave() const
TPaletteAxis * getPaletteAxis() const
MINT::const_counted_ptr< TH1 > histo() const
std::map< Key, Val >::iterator end()
Definition: PolymorphMap.h:29
virtual void add(const DalitzCoordSet &coord, const MINT::counted_ptr< TH1 > &histo)
MINT::counted_ptr< TH2F > getH2ForPalette() const
MINT::counted_ptr< THStack > makeHStack(const DalitzCoordSet &coord) const
bool draw(const std::string &baseName="", const std::string &drawOpt="HIST", const std::string &format="eps") const
MINT::counted_ptr< TH2F > _h2ForPalette
const DalitzCoordSet & coord() const
std::vector< MINT::counted_ptr< TH1 * > > _histograms
std::string name() const
std::map< Key, Val >::iterator begin()
Definition: PolymorphMap.h:26
const std::string & name() const
Definition: DalitzSet.h:60
void setColourPalette(int nCol, int *pal, double max, double min=0.000001)
X * get() const
Definition: counted_ptr.h:123