HeatMap.cxx
Go to the documentation of this file.
2 
3 #include "TH2.h"
4 
5 namespace quad
6 {
7  // -------------------------------------------------------------------------
8  HeatMap::HeatMap(int _Nz, double _minz, double _maxz,
9  int _Nx, double _minx, double _maxx)
10  : minz(_minz), minx(_minx), maxz(_maxz), maxx(_maxx), Nx(_Nx), Nz(_Nz),
11  map(Nz*Nx, 0)
12  {
13  }
14 
15  // -------------------------------------------------------------------------
16  std::unique_ptr<TH2F> HeatMap::AsTH2() const
17  {
18  auto h = std::make_unique<TH2F>("", "", Nz, minz, maxz, Nx, minx, maxx);
19  for(unsigned int i = 0; i < map.size(); ++i){
20  h->SetBinContent((i/Nx)+1, (i%Nx)+1, map[i]);
21  }
22 
23  double maxz = 0;
24  for(int i = 0; i < (h->GetNbinsX()+2)*(h->GetNbinsY()+2); ++i){
25  maxz = std::max(maxz, h->GetBinContent(i));
26  }
27 
28  // Slim out bins with low population (reduces output file size)
29  for(int i = 0; i < (h->GetNbinsX()+2)*(h->GetNbinsY()+2); ++i){
30  if(h->GetBinContent(i) < .05*maxz) h->SetBinContent(i, 0);
31  }
32 
33  h->Sumw2(false); // Drop all the errors
34 
35  return h;
36  }
37 }
const double minz
Definition: HeatMap.h:24
const double minx
Definition: HeatMap.h:24
const int Nx
Definition: HeatMap.h:25
static int max(int a, int b)
const double maxx
Definition: HeatMap.h:24
HeatMap(int _Nz, double _minz, double _maxz, int _Nx, double _minx, double _maxx)
Definition: HeatMap.cxx:8
const int Nz
Definition: HeatMap.h:25
std::unique_ptr< TH2F > AsTH2() const
Definition: HeatMap.cxx:16
const double maxz
Definition: HeatMap.h:24
std::vector< float > map
Definition: HeatMap.h:27