SpaceView.cpp
Go to the documentation of this file.
1 //File: SpaceView.cpp
2 //Brief: A histogramming interface that draws module number on one axis and channel number on the other.
3 //Author: Andrew Olivier aolivier@ur.rochester.edu
4 
5 //Include header
6 #include "plot/SpaceView.h"
7 
8 //ROOT includes
9 #include "TStyle.h"
10 
11 //Local includes
12 #include "StyleSentry.cpp"
13 
14 //c++ includes
15 #include <iostream>
16 
17 namespace CRT
18 {
20  {
21  hist.SetStats(false);
22  //auto zAxis = hist.GetZaxis();
23  //TODO: x and y labels based on approximate module positions?
24  }
25 
27  {
28  auto main = GetMainPad(); //Observer pointer
29  main->Divide(2);
30 
31  //Set up upstream pad
32  main->cd(1);
33  gPad->SetLogz();
34 
35  //Set up downstream pad
36  main->cd(2);
37  gPad->SetLogz();
38  }
39 
41  {
42  const auto binLimit = 4*ChannelsPerModule*2; //Frames are 4 modules high. 2 strips per module to simulate offsets of "bottom" strip layer
43  fUpstream = TH2D(("upstream"+name).c_str(), ("Upstream;cartoon x;cartoon y;"+zTitle).c_str(), binLimit, 0, binLimit, binLimit, 0, binLimit);
45 
46  fDownstream = TH2D(("downstream"+name).c_str(), ("Downstream;cartoon x;cartoon y;"+zTitle).c_str(), binLimit, 0, binLimit, binLimit, 0, binLimit);
48 
49  SetupPads();
50  }
51 
52  SpaceView::SpaceView(TPad* pad, const std::string& name, const std::string& title, const std::string& zTitle): ChannelView(pad)
53  {
54  const auto binLimit = 4*ChannelsPerModule*2;
55  std::cout << "binLimit is " << binLimit << " = 4*" << ChannelsPerModule << "*2\n";
56  fUpstream = TH2D(("upstream"+name).c_str(), ("Upstream;cartoon x;cartoon y;"+zTitle).c_str(), binLimit, 0, binLimit, binLimit, 0, binLimit);
57  fDownstream = TH2D(("downstream"+name).c_str(), ("Downstream;cartoon x;cartoon y;"+zTitle).c_str(), binLimit, 0, binLimit, binLimit, 0, binLimit);
58 
61 
62  SetupPads();
63  }
64 
65  SpaceView::SpaceView(const double zMax, const std::string& name, const std::string& title, const std::string& zTitle): SpaceView(name, title, zTitle)
66  {
67  fUpstream.SetMaximum(zMax);
68  fDownstream.SetMaximum(zMax);
69  }
70 
71  SpaceView::SpaceView(TPad* pad, const double zMax, const std::string& name, const std::string& title, const std::string& zTitle): SpaceView(pad, name, title, zTitle)
72  {
73  fUpstream.SetMaximum(zMax);
74  fDownstream.SetMaximum(zMax);
75  }
76 
77  void SpaceView::doFill(const size_t module, const size_t channel, const double weight)
78  {
79  doSomething((module < NModules/2l)?fUpstream:fDownstream, module, channel,
80  [&weight](auto& hist, const auto x, const auto y) { hist.Fill(x, y, weight); });
81  }
82 
83  template <class FUNC>
84  void SpaceView::doSomething(TH2& hist, const size_t module, const size_t channel, FUNC&& func)
85  {
86  //When doing things like this in the future, a frame would be a good logical abstraction layer.
87  const size_t local = module%16;
88  const int nXBins = hist.GetXaxis()->GetNbins(), nYBins = hist.GetYaxis()->GetNbins(), endOfFrame = 2l*ChannelsPerModule*2l;
89  //Frames are 2 modules x 2 modules. 2 columns per strip
90  const bool secondLayer = (channel > 32);
91 
92  std::cout << "module is " << module << ", channel is " << channel << ", local is " << local << ".\n";
93  if(local < 2) //Top beam-left
94  {
95  const auto xbin = endOfFrame-(local*ChannelsPerModule+channel)*2+secondLayer;
96  std::cout << "Filling beam-left with subtraction at xbin=" << xbin << "\n";
97  for(int ybin = endOfFrame; ybin < nYBins; ++ybin)
98  {
99  //Fill both strips that this channel overlaps
100  func(hist, xbin, ybin);
101  func(hist, xbin-1, ybin);
102  }
103  }
104  else if(local > 13) //Top beam-right
105  {
106  const auto xbin = nXBins-((local-14)*ChannelsPerModule+channel)*2+secondLayer;
107  std::cout << "Filling beam-right with subtraction at xbin=" << xbin << "\n";
108  for(int ybin = endOfFrame; ybin < nYBins; ++ybin)
109  {
110  //Fill both strips that this channel overlaps
111  func(hist, xbin, ybin);
112  func(hist, xbin-1, ybin);
113  }
114  }
115  else if(local > 5 && local < 10) //Bottom vertical module
116  {
117  const auto xbin = ((local-6)*ChannelsPerModule+channel)*2-secondLayer; //Entire face is 4 modules x 4 modules
118  std::cout << "Filling at xbin=" << xbin << "\n";
119  for(int ybin = 0; ybin < endOfFrame; ++ybin)
120  {
121  //Fill both strips that this channel overlaps
122  func(hist, xbin, ybin);
123  func(hist, xbin+1, ybin);
124  }
125  }
126  else if(local < 6) //Beam-left horizontal module
127  {
128  const auto ybin = nYBins-((local-2)*ChannelsPerModule+channel)*2+secondLayer; //Entire face is 4 modules x 4 modules
129  std::cout << "Filling at ybin=" << ybin << "\n";
130  for(int xbin = 0; xbin < endOfFrame; ++xbin)
131  {
132  //Fill both strips that this channel overlaps
133  func(hist, xbin, ybin);
134  func(hist, xbin, ybin-1);
135  }
136  }
137  else //Beam-right horizontal module
138  {
139  const auto ybin = ((local-10)*ChannelsPerModule+channel)*2-secondLayer; //Entire face is 4 modules x 4 modules
140  std::cout << "Filling at ybin=" << ybin << "\n";
141  for(int xbin = endOfFrame; xbin < nXBins; ++xbin)
142  {
143  //Fill both strips that this channel overlaps
144  func(hist, xbin, ybin);
145  func(hist, xbin, ybin+1);
146  }
147  }
148  }
149 
150  void SpaceView::doSetValue(const size_t module, const size_t channel, const double value)
151  {
152  doSomething((channel < 32)?fUpstream:fDownstream, module, channel,
153  [&value](auto& hist, const auto x, const auto y) { hist.SetBinContent(x, y, value); });
154  }
155 
156  void SpaceView::doDraw(const char* option)
157  {
158  util::StyleSentry old; //Save the old style during this function so I don't change it
159 
160  gStyle->SetOptStat(0);
161  fUpstream.UseCurrentStyle();
162  fDownstream.UseCurrentStyle();
163 
164  auto main = GetMainPad();
165  main->cd(1);
166  fUpstream.Draw(option);
167 
168  main->cd(2);
169  fDownstream.Draw(option);
170  }
171 
172  void SpaceView::doReset(const char* option)
173  {
174  fUpstream.Reset(option);
175  fDownstream.Reset(option);
176  }
177 }
static QCString name
Definition: declinfo.cpp:673
TH2D fDownstream
Definition: SpaceView.h:34
void ConfigHistogram(TH2 &hist)
Definition: SpaceView.cpp:19
std::string string
Definition: nybbler.cc:12
virtual void doFill(const size_t module, const size_t channel, const double weight) override
Definition: SpaceView.cpp:77
virtual void doDraw(const char *option) override
Definition: SpaceView.cpp:156
uint8_t channel
Definition: CRTFragment.hh:201
static QStrList * l
Definition: config.cpp:1044
weight
Definition: test.py:257
TPad * GetMainPad()
Definition: ChannelView.h:47
void SetupPads()
Definition: SpaceView.cpp:26
static constexpr size_t ChannelsPerModule
Definition: ChannelView.h:45
static constexpr size_t NModules
Definition: ChannelView.h:44
void doSomething(TH2 &hist, const size_t channel, const size_t module, FUNC &&func)
Definition: SpaceView.cpp:84
TH2D fUpstream
Definition: SpaceView.h:33
SpaceView(const std::string &name="CRTEvd", const std::string &title="CRT Event Display", const std::string &zTitle="Hits")
Definition: SpaceView.cpp:40
def func()
Definition: docstring.py:7
virtual void doReset(const char *option) override
Definition: SpaceView.cpp:172
list x
Definition: train.py:276
virtual void doSetValue(const size_t module, const size_t channel, const double value) override
Definition: SpaceView.cpp:150