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