Miind
RootCanvasNoMPI.cpp
Go to the documentation of this file.
1 
2 // Copyright (c) 2005 - 2015 Marc de Kamps
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution.
11 // * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
12 // without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
16 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
17 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
18 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 //
20 #ifdef WANTROOT
21 #ifndef ENABLE_MPI
22 
23 #include <vector>
24 #include <iostream>
25 #include <cassert>
26 #include <algorithm>
28 #include <TCanvas.h>
29 #include <TH2F.h>
30 #include <TApplication.h>
31 #include <TStyle.h>
32 
33 const int CANVAS_X_DIMENSION = 800;
34 const int CANVAS_Y_DIMENSION = 800;
35 const int NUMBER_HISTO_CHANNELS = 500;
36 
37 // need one global application object
38 TApplication APPLICATION("application",0,0);
39 TStyle* MPILib::RootCanvas::_p_style = new TStyle;
40 
41 std::unique_ptr<TCanvas> MPILib::RootCanvas::_p_canvas(nullptr);
42 std::vector<MPILib::NodeId> MPILib::RootCanvas::_vec_id(0);
43 
44 std::vector<int> MPILib::RootCanvas::_vec_scratch(0);
45 bool MPILib::RootCanvas::_b_rendering_started = false;
46 TH2F* MPILib::RootCanvas::_p_hist_state = 0;
47 TH2F* MPILib::RootCanvas::_p_hist_rate = 0;
48 
49 TPad* MPILib::RootCanvas::_p_pad_state = 0;
50 TPad* MPILib::RootCanvas::_p_pad_rate = 0;
51 
52 using namespace MPILib;
53 
54 RootCanvas::RootCanvas(const CanvasParameter& par_canvas):
55 _par_canvas(par_canvas)
56 {
57 }
58 
59 CanvasParameter RootCanvas::getCanvasParameter() const
60 {
61  return _par_canvas;
62 }
63 
64 int RootCanvas::PadId(NodeId id) const
65 {
66  std::vector<NodeId>::iterator iter = find(_vec_id.begin(), _vec_id.end(), id);
67  return (iter != _vec_id.end()) ? iter - _vec_id.begin() + 1 : -1;
68 }
69 
70 void RootCanvas::Render(report::ReportType type, NodeId id, TGraph* p_graph){
71 
72  if (! _b_rendering_started){
73  initializeCanvas();
74  _b_rendering_started = true;
75  }
76 
77  int index = PadId(id);
78 
79  if (type == report::STATE && index >= 0){
80  _p_pad_state->cd(index);
81  _p_hist_state->Draw();
82  p_graph->Draw("L");
83  }
84 
85  if (type == report::RATE && index >= 0){
86  _p_pad_rate->cd(index);
87  _p_hist_rate->Draw();
88  p_graph->Draw("L");
89  }
90 
91  AddToCycle(id);
92  if (IsCycleComplete() )
93  _p_canvas->Update();
94 }
95 
96 void RootCanvas::AddToCycle(NodeId id)
97 {
98  // could be more efficient but rendering takes a lot of time anyway; this will not be the performance bottleneck
99  std::vector<NodeId>::iterator iter = std::find(_vec_id.begin(),_vec_id.end(),id);
100  if (iter == _vec_id.end())
101  return;
102 
103  int i = iter - _vec_id.begin();
104  _vec_scratch[i] = 1;
105 }
106 
107 bool RootCanvas::IsCycleComplete(){
108  std::vector<int>::iterator iter;
109  iter = std::find(_vec_scratch.begin(),_vec_scratch.end(),0);
110  if (iter == _vec_scratch.end()){
111  for (iter = _vec_scratch.begin(); iter != _vec_scratch.end(); iter++)
112  *iter = 0;
113  return true;
114  }
115  else
116  return false;
117 }
118 
119 void RootCanvas::addNode(NodeId id)
120 {
121  if (find(_vec_id.begin(),_vec_id.end(),id) == _vec_id.end())
122  _vec_id.push_back(id);
123 // else
124 // nothing: multiple attempts to display the same node will simply be ignored
125 
126 }
127 
128 void RootCanvas::initializeCanvas(){
129 
130  _p_canvas = std::unique_ptr<TCanvas>(new TCanvas("MIIND_CANVAS","MIIND",CANVAS_X_DIMENSION,CANVAS_Y_DIMENSION));
131 
132  gStyle->SetOptStat(0);
133 
134  _p_pad_rate = new TPad("rate", "", 0.05,0.05, 0.45, 0.95);
135  _p_pad_state = new TPad("state","", 0.55,0.05, 0.95, 0.95);
136 
137  _p_hist_state = new TH2F("state_histo","", NUMBER_HISTO_CHANNELS ,_par_canvas._state_min,_par_canvas._state_max, NUMBER_HISTO_CHANNELS,_par_canvas._dense_min,_par_canvas._dense_max);
138  _p_hist_rate = new TH2F("rate_histo", "", NUMBER_HISTO_CHANNELS, _par_canvas._t_min,_par_canvas._t_max,NUMBER_HISTO_CHANNELS,_par_canvas._f_min,_par_canvas._f_max);
139 
140  this->SetMaximumDensity();
141  this->SetMaximumRate();
142 
143  Number number_of_drawable_populations = _vec_id.size();
144  _vec_scratch = std::vector<int>(number_of_drawable_populations,0.);
145  _p_pad_rate->Draw();
146  _p_pad_state->Draw();
147  _p_pad_rate->cd();
148  _p_pad_rate->Divide(1,number_of_drawable_populations, 1e-5, 1e-5);
149 
150 
151  _p_pad_state->cd();
152  _p_pad_state->Divide(1,number_of_drawable_populations, 1e-5, 1e-5);
153 
154  _p_canvas->cd();
155  _p_canvas->Update();
156 }
157 
158 
159 void RootCanvas::SetMaximumDensity() const
160 {
161  if ( _par_canvas._dense_max > 0 ){
162  int n_x = _p_hist_state->GetXaxis()->GetNbins();
163  int n_y = _p_hist_state->GetYaxis()->GetNbins();
164  double y_min = _p_hist_state->GetYaxis()->GetXmin();
165 
166  _p_hist_state->SetBins
167  (
168  n_x,
169  _par_canvas._state_min,
170  _par_canvas._state_max,
171  n_y,
172  y_min,
173  _par_canvas._dense_max
174  );
175 
176  }
177 }
178 
179 void RootCanvas::SetMaximumRate() const
180 {
181  if ( _par_canvas._f_max > 0 )
182  {
183  int n_x = _p_hist_rate->GetXaxis()->GetNbins();
184  int n_y = _p_hist_rate->GetYaxis()->GetNbins();
185  double y_min = _p_hist_rate->GetYaxis()->GetXmin();
186 
187  _p_hist_rate->SetBins
188  (
189  n_x,
190  _par_canvas._t_min,
191  _par_canvas._t_max,
192  n_y,
193  y_min,
194  _par_canvas._f_max
195  );
196  }
197 }
198 
199 #endif // ENABLE_MPI
200 #endif // don't bother if you don't want ROOT
201 
unsigned int Number
Auxiliary class, stores the boundaries of the histograms shown in the running canvas.
unsigned int NodeId
The objective is find a numerical solution for this equation This requires a numerical representation of the density We will work in the state space of a two dimensional and define a mesh there We first give two examples and then define the general procedure and given in Table for given fixed Delta g see Fig and we will denote coordinates in this dimension by a small letter $v The second dimension can be used to represent parameters as varied as and will represented by $w A strip is constructed by choosing two neighbouring points in state e g and integrating the vector field for a time $T that is assumed to be an integer multiple of a period of time Delta which we assume to be a defining characteristic of the grid Let then the set of points the set of points which is quadrilateral in shape The quadrilateral should be but not necessarily as long as they are but it is convenient to number them in order of creation In the we will assume that strip numbers created by the integration procedure start and are so that the numbers i in each identify a unique strip Strip no is reserved for stationary points There may or more cells in strip The number of cells in strip $i denoted by with $i the strip number and $j the cell as the i
Definition: 2D.hpp:145