45 std::cout <<
" new tcanvas" << std::endl;
46 fCanvas =
new TCanvas (
"TMVA Monitoring",
"Monitoring", 1000, 500);
47 std::cout <<
" draw" << std::endl;
49 std::cout <<
" update" << std::endl;
50 GetCanvas ()->Update();
51 std::cout <<
" process events" << std::endl;
52 gSystem->ProcessEvents();
53 std::cout <<
" run app" << std::endl;
55 std::cout <<
" run app executed" << std::endl;
57 gStyle->SetOptStat (0);
63 GetCanvas ()->Modified();
64 GetCanvas ()->Update();
65 gSystem->ProcessEvents();
68 TCanvas* GetCanvas () {
return fCanvas; }
70 void pads (
int numPads);
71 void create (std::string histoName,
int bins,
double min,
double max);
72 void create (std::string histoName,
int bins,
double min,
double max,
int bins2,
double min2,
double max2);
73 void addPoint (std::string histoName,
double x);
74 void addPoint (std::string histoName,
double x,
double y);
75 void plot (std::string histoName, std::string options =
"L",
int pad = 0, EColor color = kBlue);
76 void clear (std::string histoName);
77 bool exists (std::string histoName);
78 bool exists (TH1F* dummy, std::string histoName);
79 bool exists (TH2F* dummy, std::string histoName);
83 TH1F* getHistogram (
const TH1F* dummy, std::string histoName,
int bins = 0,
double min = 0,
double max = 0);
84 TH2F* getHistogram (
const TH2F* dummy, std::string histoName,
int bins = 0,
double min = 0,
double max = 0,
int bins2 = 0,
double min2 = 0,
double max2 = 0);
93 std::map<std::string, TH1F*> m_histos1D;
94 std::map<std::string, TH2F*> m_histos2D;
99 inline bool Monitoring::exists (TH1F* , std::string histoName)
101 auto it = m_histos1D.find (histoName);
102 if (it != m_histos1D.end ())
107 inline bool Monitoring::exists (TH2F* , std::string histoName)
109 auto it2 = m_histos2D.find (histoName);
110 if (it2 != m_histos2D.end ())
116 inline bool Monitoring::exists (std::string histoName)
118 TH1F* dummy1D (NULL);
119 TH2F* dummy2D (NULL);
120 return exists (dummy1D, histoName) || exists (dummy2D, histoName);
123 inline void Monitoring::pads (
int numPads)
125 TCanvas* canvas = GetCanvas ();
127 std::cout <<
"divide canvas " << canvas <<
" into " << numPads <<
"numPads" << std::endl;
128 GetCanvas ()->DivideSquare (numPads);
132 inline void Monitoring::create (std::string histoName,
int bins,
double min,
double max)
135 getHistogram (dummy, histoName, bins, min, max);
138 inline void Monitoring::create (std::string histoName,
int bins,
double min,
double max,
int bins2,
double min2,
double max2)
141 getHistogram (dummy, histoName, bins, min, max, bins2, min2, max2);
146 inline TH1F* Monitoring::getHistogram (
const TH1F* , std::string histoName,
int bins,
double min,
double max)
148 auto it = m_histos1D.find (histoName);
149 if (it != m_histos1D.end ())
151 std::cout <<
"new 1D histogram " << histoName << std::endl;
152 TH1F* histogram = m_histos1D.insert (std::make_pair (histoName,
new TH1F (histoName.c_str (), histoName.c_str (), bins, min, max))).first->second;
157 inline TH2F* Monitoring::getHistogram (
const TH2F* , std::string histoName,
int bins,
double min,
double max,
int bins2,
double min2,
double max2)
160 auto it = m_histos2D.find (histoName);
161 if (it != m_histos2D.end ())
163 std::cout <<
"new 2D histogram " << histoName << std::endl;
164 TH2F* histogram = m_histos2D.insert (std::make_pair (histoName,
new TH2F (histoName.c_str (), histoName.c_str (), bins, min, max, bins2, min2, max2))).first->second;
169 inline void Monitoring::addPoint (std::string histoName,
double x)
172 TH1F* hist = getHistogram (dummy, histoName, 100, 0, 1);
176 inline void Monitoring::addPoint (std::string histoName,
double x,
double y)
179 TH2F* hist = getHistogram (dummy, histoName, 100, 0, 1, 100, 0, 1);
183 inline void Monitoring::clear (std::string histoName)
186 if (!exists (histoName))
192 if (exists (hist1D, histoName))
194 hist1D = getHistogram (hist1D, histoName, 100, 0,1);
199 if (exists (hist2D, histoName))
201 hist2D = getHistogram (hist2D, histoName, 100, 0,1,100,0,1);
207 inline void Monitoring::plot (std::string histoName, std::string options,
int pad, EColor color)
209 TCanvas* canvas = GetCanvas ();
211 auto it1D = m_histos1D.find (histoName);
212 if (it1D != m_histos1D.end ())
215 TH1F* histogram = getHistogram (dummy, histoName);
217 histogram->SetLineColor (color);
218 histogram->SetMarkerColor (color);
220 histogram->Draw (options.c_str ());
225 auto it2D = m_histos2D.find (histoName);
226 if (it2D != m_histos2D.end ())
229 TH2F* histogram = getHistogram (dummy, histoName);
231 histogram->SetLineColor (color);
232 histogram->SetMarkerColor (color);
234 histogram->Draw (options.c_str ());