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