Belle II Software  release-06-00-14
EclPainter2D.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 //This module
9 #include <ecl/modules/eclDisplay/EclPainter2D.h>
10 
11 //Root
12 #include <TH2.h>
13 #include <TPad.h>
14 #include <TStyle.h>
15 
16 //ECL
17 #include <ecl/modules/eclDisplay/geometry.h>
18 #include <ecl/utility/ECLChannelMapper.h>
19 #include <ecl/modules/eclDisplay/MultilineWidget.h>
20 
21 
23 #define PALETTE_ID 55
24 
25 using namespace Belle2;
26 using namespace ECLDisplayUtility;
27 
29  EclPainter(data)
30 {
31  this->m_type = type;
32 
33  int max_x = getMaxX();
34  int max_y = getMaxY();
35  char obj_name[255];
36  getNewRootObjectName(obj_name, 255);
37 
38  m_hist = new TH2F(obj_name, "title", max_x, 1, max_x + 1,
39  max_y, 1, max_y + 1);
40 
41  m_hist->GetXaxis()->CenterTitle();
42  m_hist->GetXaxis()->SetTitleOffset(1.1);
43  m_hist->GetYaxis()->CenterTitle();
44  m_hist->GetYaxis()->SetTitleOffset(-1.1);
45  m_hist->GetZaxis()->CenterTitle();
46 
47  grid = 0;
48  hgrid = 0;
49 }
50 
52 {
53  delete m_hist;
54  delete grid;
55  if (hgrid)
56  delete hgrid;
57 }
58 
60 {
61  m_type = other.m_type;
62  m_hist = new TH2F(*other.m_hist);
63  hgrid = 0;
64  grid = 0;
65  initGrid();
66 }
67 
69 {
70  const char* name[3][3] = {
71  {"Events per channel", "Events per shaper"},
72  {"Energy per channel (MeV)", "Energy per shaper (MeV)"},
73  {"Time per channel (ns)", "Time per shaper (ns)"}
74  };
75  const char* zname[3] = {
76  "Events", "Energy (MeV)", "Time"
77  };
78 
79  TString title = TString(name[GetMode()][(int)m_type]) + " (" +
81 
82  m_hist->SetTitle(title);
83 
84  if (m_type == CHANNEL_2D) {
85  m_hist->GetXaxis()->SetTitle("Theta id");
86  m_hist->GetYaxis()->SetTitle("Phi id");
87  }
88  if (m_type == SHAPER_2D) {
89  m_hist->GetXaxis()->SetTitle("Shaper id");
90  m_hist->GetYaxis()->SetTitle("Collector id");
91  }
92  m_hist->GetZaxis()->SetTitle(zname[GetMode()]);
93 }
94 
96 {
97  if (m_type == CHANNEL_2D)
98  return 68;
99  else if (m_type == SHAPER_2D)
100  return 12;
101 
102  return 1;
103 }
105 {
106  if (m_type == CHANNEL_2D)
107  return 144;
108  else if (m_type == SHAPER_2D)
109  return 52;
110 
111  return 1;
112 }
113 
115 {
116  if (m_type == CHANNEL_2D)
117  return getData()->getThetaId(ch);
118  else if (m_type == SHAPER_2D)
119  return getMapper()->getShaperPosition(ch);
120 
121  return 0;
122 }
124 {
125  if (m_type == CHANNEL_2D)
126  return getData()->getPhiId(ch);
127  else if (m_type == SHAPER_2D)
128  return getMapper()->getCrateID(ch);
129 
130  return 0;
131 }
132 
134 {
135  /* Adding second TPad (layer) for the grid overlay */
136  grid = new TPad("grid", "", 0, 0, 1, 1);
137  grid->SetGrid();
138  grid->SetRightMargin(gPad->GetRightMargin());
139  // Setting transparent fill style.
140  grid->SetFillStyle(4000);
141  grid->SetFrameFillStyle(0);
142 }
143 
145 {
146  TVirtualPad* main = gPad;
147  grid->Draw("COLZ");
148  grid->cd();
149 
150  /* Creating grid */
151  char obj_name[255];
152  getNewRootObjectName(obj_name, 255);
153 
154  // NOTE: Root can't divide the histogram axes into more than 99
155  // primary sections, limiting the maximum grid cell size.
156  // To change this, new grid implementation might be necessary.
157  double max_y = getMaxY();
158  // Reducing the number of grid lines.
159  while (max_y >= 100) {
160  max_y /= 2;
161  }
162 
163  hgrid = new TH2C(obj_name, "", getMaxX(), 0, getMaxX(), max_y, 0, max_y);
164  hgrid->GetXaxis()->SetNdivisions(getMaxX());
165  hgrid->GetYaxis()->SetNdivisions(max_y);
166  // Hiding axis labels.
167  hgrid->GetYaxis()->SetLabelOffset(1e3);
168  hgrid->GetXaxis()->SetLabelOffset(1e3);
169  // Hiding axis ticks.
170  hgrid->GetYaxis()->SetTickLength(0.);
171  hgrid->GetXaxis()->SetTickLength(0.);
172 
173  hgrid->Draw();
174 
175  main->cd();
176 }
177 
178 void EclPainter2D::getInformation(int px, int py, MultilineWidget* panel)
179 {
180  EclPainter::getInformation(px, py, panel);
181 
182  char info[255];
183 
184  Float_t upx = gPad->AbsPixeltoX(px);
185  Float_t x = gPad->PadtoX(upx);
186  int binx = m_hist->GetXaxis()->FindBin(x);
187 
188  Float_t upy = gPad->AbsPixeltoY(py);
189  Float_t y = gPad->PadtoY(upy);
190  int biny = m_hist->GetYaxis()->FindBin(y);
191 
192  if (m_type == CHANNEL_2D) {
193  sprintf(info, "theta_id = %d", binx);
194  panel->setLine(1, info);
195  sprintf(info, "phi_id = %d", biny);
196  panel->setLine(2, info);
197  sprintf(info, "channel_id = %d", getData()->getChannel(biny, binx));
198  panel->setLine(3, info);
199  }
200  if (m_type == SHAPER_2D) {
201  sprintf(info, "crate_id = %d", biny);
202  panel->setLine(1, info);
203  sprintf(info, "shaper_id = %d (%d)", (biny - 1) * 12 + binx, binx);
204  panel->setLine(2, info);
205  }
206 }
207 
209 {
210  return m_type;
211 }
212 
213 // In case of ECL cylinder net drawing, results are intended
214 // to be drawn on the histogram with the following properties:
215 // nbinsx : 46, xlow : 0, xup : 46
216 // nbinsy : 144, ylow : 0, yup : 144
218 {
219  setTitles();
220 
221  EclData* data = getData();
222 
223  const int* ev_counts = data->getEventCounts();
224  const float* energy_sums = data->getEnergySums();
225 
226  m_hist->Reset();
227  for (int i = 1; i <= getData()->getCrystalCount(); i++) {
228  if (!data->isCrystalInSubsystem(i, getDisplayedSubsystem())) continue;
229 
230  int id_x = channelToSegIdX(i);
231  int id_y = channelToSegIdY(i);
232  if (GetMode())
233  m_hist->Fill(id_x, id_y, energy_sums[i]);
234  else
235  m_hist->Fill(id_x, id_y, ev_counts[i]);
236  }
237 
238  gStyle->SetNumberContours(255);
239  gStyle->SetPalette(PALETTE_ID);
240 
241  m_hist->GetXaxis()->SetTicks("+-");
242  m_hist->GetYaxis()->SetTicks("+-");
243 
244  m_hist->Draw("COLZ");
245 
246  initGrid();
247  drawGrid();
248 }
int getCrateID(int iCOPPERNode, int iFINESSE)
get crate number by given COPPER node number and FINESSE number
int getShaperPosition(int cellID)
get position of the shaper in the crate by given CellId
This class contains data for ECLSimHit's and provides several relevant conversion functions for bette...
Definition: EclData.h:31
int getThetaId(int ch)
ECL CellId -> theta_id.
Definition: EclData.cc:286
int getPhiId(int ch)
ECL CellId -> phi_id.
Definition: EclData.cc:276
static int getCrystalCount()
Get number of crystals in ECL.
Definition: EclData.cc:146
Painter for EclData, 2D histograms.
Definition: EclPainter2D.h:26
~EclPainter2D()
Destructor for EclPainter subclass.
Definition: EclPainter2D.cc:51
Type m_type
Display subtypes of this class.
Definition: EclPainter2D.h:56
void cloneFrom(const EclPainter2D &other)
Clone attributes from other EclPainter2D.
Definition: EclPainter2D.cc:59
int channelToSegIdX(int channel)
Convert channel id to X bin number.
Type
Subtype of histogram to draw.
Definition: EclPainter2D.h:29
@ CHANNEL_2D
(theta_id:phi_id) histogram.
Definition: EclPainter2D.h:30
@ SHAPER_2D
(shaper:crate) histogram.
Definition: EclPainter2D.h:31
int getMaxX()
Returns number of X bins.
Definition: EclPainter2D.cc:95
void setTitles()
Update histogram titles.
Definition: EclPainter2D.cc:68
TH2C * hgrid
The grid itself, drawn in drawGrid().
Definition: EclPainter2D.h:61
virtual void getInformation(int px, int py, MultilineWidget *panel) override
Sets the information to be displayed in the provided MultilineWidget.
void initGrid()
Initialize grid for drawGrid().
Type getType()
Return subtype of ECLPainter2D.
int channelToSegIdY(int channel)
Convert channel id to Y bin number.
TPad * grid
Grid pad, drawn in drawGrid().
Definition: EclPainter2D.h:63
void drawGrid()
Draw grid over histogram.
int getMaxY()
Returns number of Y bins.
EclPainter2D(EclData *data, Type type)
Constructor for EclPainter subclass.
Definition: EclPainter2D.cc:28
TH2F * m_hist
Displayed histogram.
Definition: EclPainter2D.h:58
virtual void Draw() override
Redraw the canvas.
Painter for EclData, parent class, created with EclPainterFactory.
Definition: EclPainter.h:29
EclData * getData()
Return currently displayed EclData.
Definition: EclPainter.h:46
EclData::EclSubsystem getDisplayedSubsystem()
Get currently displayed ECL subsystem.
Definition: EclPainter.cc:50
virtual void getInformation(int px, int py, MultilineWidget *panel)
Sets the information to be displayed in the provided MultilineWidget.
Definition: EclPainter.cc:71
TString getSubsystemTitle(EclData::EclSubsystem subsys)
Return title of ECL subsystem to use in painter.
Definition: EclPainter.cc:55
void getNewRootObjectName(char *buf, int size)
Make unique name for next root object.
Definition: EclPainter.cc:87
ECL::ECLChannelMapper * getMapper()
Return currently set ECLChannelMapper.
Definition: EclPainter.cc:40
Widget which contains the dynamic amount of TGLabel objects.
void setLine(int line_id, const char *text)
Set content of the specified line to 'text'.
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:75