2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
8 //____________________________________________________________________
9 HistValProfile::HistValProfile( bool trigger_conversion_all,
10 const std::string& name, const std::string& title,
11 int nbins, const double& xmin, const double& xmax,
12 const double& profparmin, const double& profparmax )
15 m_h1 = new TProfile(name.c_str(),title.c_str(),nbins,xmin,xmax,profparmin,profparmax,profile_test_erroroption());
16 m_h2 = TProfile_LW::create(name.c_str(),title.c_str(),nbins,xmin,xmax,profparmin,profparmax,profile_test_erroroption());
17 HistValProfile::compareMetaData();
19 if (trigger_conversion_all)
20 triggerConversionToROOTHist();
24 //____________________________________________________________________
25 template <class TFloat>
26 HistValProfile::HistValProfile( bool trigger_conversion_all,
27 const std::string& name, const std::string& title,
28 int nbins, const TFloat* xbins )
31 m_h1 = new TProfile(name.c_str(),title.c_str(),nbins,xbins,profile_test_erroroption());
32 m_h2 = TProfile_LW::create(name.c_str(),title.c_str(),nbins,xbins,profile_test_erroroption());
33 HistValProfile::compareMetaData();
34 if (trigger_conversion_all)
35 triggerConversionToROOTHist();
38 //____________________________________________________________________
39 HistValProfile::~HistValProfile()
43 LWHist::safeDelete(m_h2);
46 //____________________________________________________________________
47 unsigned HistValProfile::getXAxis_NBins() const
49 return std::as_const(*m_h1).GetXaxis()->GetNbins();
52 //____________________________________________________________________
53 unsigned HistValProfile::getYAxis_NBins() const
55 return std::as_const(*m_h1).GetYaxis()->GetNbins();
58 //____________________________________________________________________
59 void HistValProfile::fill(const double& x, const double& y)
63 this->binContentsChanged();
66 //____________________________________________________________________
67 void HistValProfile::fill(const double& x, const double& y, const double& w)
69 if (w<0) return;//Latest root gives NaN's in case of negative weights => not worth reproducing that.
74 this->binContentsChanged();
77 //____________________________________________________________________
78 void HistValProfile::setBinEntries(unsigned bin, const double& entries)
81 return;//Fixme: this is because of some NaN resulting from ROOT internals which I can't reproduce.
82 //(entries==0 ignored due to internals being to weird)
83 m_h1->SetBinEntries(bin,entries);
84 m_h2->SetBinEntries(bin,entries);
85 this->binContentsChanged();
88 //____________________________________________________________________
89 void HistValProfile::setBinContent(unsigned bin, const double& content)
91 m_h1->SetBinContent(bin,content);
92 m_h2->SetBinContent(bin,content);
93 this->binContentsChanged();
96 //____________________________________________________________________
97 void HistValProfile::setBinError(unsigned bin, const double& error)
101 m_h1->SetBinError(bin,error);
102 m_h2->SetBinError(bin,error);
103 this->binContentsChanged();
106 //____________________________________________________________________
107 void HistValProfile::setBinInfo(unsigned bin, const double& entries, const double& content,const double& error)
110 return;//Fixme: this is because of some NaN resulting from ROOT internals which I can't reproduce.
111 m_h1->SetBinEntries(bin,entries);
112 m_h1->SetBinContent(bin,content);
113 m_h1->SetBinError(bin,error);
114 m_h2->SetBinInfo(bin,entries,content,error);
115 this->binContentsChanged();
118 //____________________________________________________________________
119 void HistValProfile::compareBinContents() const
121 HistValFunctions::test("GetNbinsX()",int(m_h1->GetNbinsX()), int(m_h2->GetNbinsX()));
122 int n = m_h1->GetNbinsX();
123 std::ostringstream s;
124 for (int i=0;i<=n+1;++i) {
125 double entries_1 = m_h1->GetBinEntries(i);
126 double content_1 = m_h1->GetBinContent(i);
127 double error_1 = m_h1->GetBinError(i);
128 double entries_2 = m_h2->GetBinEntries(i);
129 double content_2 = m_h2->GetBinContent(i);
130 double error_2 = m_h2->GetBinError(i);
131 double entries_3, content_3, error_3;
132 const double errorCompatEpsilon(1.0e-3);
133 m_h2->GetBinInfo(i,entries_3, content_3, error_3);
134 if (!HistValFunctions::compatible(entries_1,entries_2)) {
135 s << "[TProfile vs. TProfile_LW] GetBinEntries("<<i<<", nbins="<<n<<", ninternalbins="<<n+2<<")";
136 HistValFunctions::test(s.str(),entries_1,entries_2);
138 if (!HistValFunctions::compatible(content_1,content_2)) {
139 s << "[TProfile vs. TProfile_LW] GetBinContent("<<i<<", nbins="<<n<<", ninternalbins="<<n+2<<")";
140 HistValFunctions::test(s.str(),content_1,content_2);
142 if (!HistValFunctions::floatCompat(error_1,error_2,errorCompatEpsilon)) {
143 s << "[TProfile vs. TProfile_LW] GetBinError("<<i<<", nbins="<<n<<", ninternalbins="<<n+2<<")";
144 HistValFunctions::test(s.str(),error_1,error_2);
146 if (!HistValFunctions::compatible(entries_1,entries_3)) {
147 s << "[TProfile vs. TProfile_LW] entries from GetBinInfo("<<i<<", nbins="<<n<<", ninternalbins="<<n+2<<")";
148 HistValFunctions::test(s.str(),entries_1,entries_3);
150 if (!HistValFunctions::compatible(content_1,content_3)) {
151 s << "[TProfile vs. TProfile_LW] content from GetBinInfo("<<i<<", nbins="<<n<<", ninternalbins="<<n+2<<")";
152 HistValFunctions::test(s.str(),content_1,content_3);
154 if (!HistValFunctions::floatCompat(error_1,error_3,errorCompatEpsilon)) {
155 s << "[TProfile vs. TProfile_LW] error from GetBinInfo("<<i<<", nbins="<<n<<", ninternalbins="<<n+2<<")";
156 HistValFunctions::test(s.str(),error_1,error_3);
161 //____________________________________________________________________
162 void HistValProfile::compareMetaData()
164 HistValFunctions::compareMetaData(m_h1, m_h2);
167 //____________________________________________________________________
168 void HistValProfile::compareTH1s()
172 assert(m_h1->GetName()[0]==':');
175 std::string name1(m_h1->GetName());
177 TProfile * th1_gen(0);
179 m_h1->SetName((name1+"tmp").c_str());
180 LWHistControls::setCleanupOnGetROOT(false);
181 m_h2->SetName("tmpname");
182 th1_gen = m_h2->getROOTHist();
183 LWHistControls::setCleanupOnGetROOT(true);
185 th1_gen = m_h2->getROOTHist();
190 HistValFunctions::testfailed("getROOTHist(..) returns null!");
193 HistValFunctions::test("[TH1-level] GetName()",std::string("tmpname"),th1_gen->GetName());
195 HistValFunctions::test("[TH1-level] GetName()",&(m_h1->GetName()[11]),th1_gen->GetName());//"stripping off "::trigger::"
197 //Test various meta data including type and other state data:
198 HistValFunctions::test("[TH1-level] GetTitle()",m_h1->GetTitle(), th1_gen->GetTitle());
199 HistValFunctions::test("[TH1-level] ClassName()",m_h1->ClassName(), th1_gen->ClassName());
201 HistValFunctions::test("[TH1-level] GetYmin()",m_h1->GetYmin(), th1_gen->GetYmin());
202 HistValFunctions::test("[TH1-level] GetYmax()",m_h1->GetYmax(), th1_gen->GetYmax());
204 HistValFunctions::compareBinContents_1D(m_h1,th1_gen,true/*relaxedErrorComparison*/);
205 HistValFunctions::compareFields(m_h1,th1_gen);
207 //NB: ROOT very suspicious behaviour!!!: When calling GetStats
208 //(directly or from GetRMS, GetMean, GetRMSError, GetMeanError), and
209 //fTsumwy and fTsumwy2 are both 0, it casts away the constness and
210 //sets those two variables. ARRRGH. Thus we don't call any of those
213 // -> And all other supported state data...
214 // HistValFunctions::test("[TH1-level] GetRMS()",m_h1->GetRMS(), th1_gen->GetRMS());
215 // HistValFunctions::test("[TH1-level] GetMean()",m_h1->GetMean(), th1_gen->GetMean());
216 // HistValFunctions::test("[TH1-level] GetMeanError()",m_h1->GetMeanError(), th1_gen->GetMeanError());
217 //HistValFunctions::test("[TH1-level] ComputeIntegral()",m_h1->ComputeIntegral(), th1_gen->ComputeIntegral());
218 HistValFunctions::test("[TH1-level] Integral()",m_h1->Integral(), th1_gen->Integral());
220 //TODO: Compare more axes values (like min and max, nbins etc.)!!
221 const TArrayD * h1_xbins = m_h1->GetXaxis()->GetXbins();
222 const TArrayD * gen_xbins = th1_gen->GetXaxis()->GetXbins();
223 if ((h1_xbins!=0)!=(gen_xbins!=0))
224 HistValFunctions::testfailed("2D hist has inconsistent presence of xbins");
225 if (h1_xbins&&gen_xbins)
226 HistValFunctions::test("[TH1-level] GetXaxis()->GetXbins()->GetSize()",h1_xbins->GetSize(), gen_xbins->GetSize());
228 HistValFunctions::compareBinContents_1D(m_h1, m_h2,true/*relaxedErrorComparison*/);
229 HistValFunctions::compareBinContents_1D(th1_gen, m_h2,true/*relaxedErrorComparison*/);
230 HistValFunctions::compareBinContents_1D(th1_gen, m_h1,true/*relaxedErrorComparison*/);
231 HistValFunctions::compareMetaData(static_cast<TProfile*>(th1_gen), m_h2,true/*ignore name*/);
232 HistValFunctions::compareMetaData(m_h1, m_h2,true/*ignore name*/);
235 LWHistVal::clearKeptROOTHist(m_h2);//deletes th1_gen
236 m_h1->SetName(name1.c_str());
237 m_h2->SetName(name1.c_str());
241 //____________________________________________________________________
242 void HistValProfile::compareFastLoop()
247 //____________________________________________________________________
248 void HistValProfile::setXAxis_BinLabel(unsigned bin, const char* label)
250 m_h1->GetXaxis()->SetBinLabel(bin,label);
251 m_h2->GetXaxis()->SetBinLabel(bin,label);
252 this->titleOrNameWasChanged();
255 //____________________________________________________________________
256 void HistValProfile::setYAxis_BinLabel(unsigned bin, const char* label)
258 m_h1->GetYaxis()->SetBinLabel(bin,label);
259 m_h2->GetYaxis()->SetBinLabel(bin,label);
260 this->titleOrNameWasChanged();
263 //____________________________________________________________________
264 void HistValProfile::setXAxis_LabelSize(float s)
266 m_h1->GetXaxis()->SetLabelSize(s);
267 m_h2->GetXaxis()->SetLabelSize(s);
268 this->titleOrNameWasChanged();
271 //____________________________________________________________________
272 void HistValProfile::setYAxis_LabelSize(float s)
274 m_h1->GetYaxis()->SetLabelSize(s);
275 m_h2->GetYaxis()->SetLabelSize(s);
276 this->titleOrNameWasChanged();
279 //____________________________________________________________________
280 void HistValProfile::setXAxis_Title(const std::string&t)
282 m_h1->GetXaxis()->SetTitle(t.c_str());
283 m_h2->GetXaxis()->SetTitle(t.c_str());
284 this->titleOrNameWasChanged();
287 //____________________________________________________________________
288 void HistValProfile::setYAxis_Title(const std::string&t)
290 m_h1->GetYaxis()->SetTitle(t.c_str());
291 m_h2->GetYaxis()->SetTitle(t.c_str());
292 this->titleOrNameWasChanged();
295 //____________________________________________________________________
296 void HistValProfile::setZAxis_Title(const std::string&t)
298 m_h1->GetZaxis()->SetTitle(t.c_str());
299 m_h2->GetZaxis()->SetTitle(t.c_str());
300 this->titleOrNameWasChanged();
303 //____________________________________________________________________
304 void HistValProfile::SetMarkerColor( short c)
306 m_h1->SetMarkerColor(c);
307 m_h2->SetMarkerColor(c);
308 this->titleOrNameWasChanged();
311 //____________________________________________________________________
312 void HistValProfile::SetMarkerStyle( short s )
314 m_h1->SetMarkerStyle(s);
315 m_h2->SetMarkerStyle(s);
316 assert(m_h1->GetMarkerStyle()==s);
317 assert(m_h2->GetMarkerStyle()==s);
318 this->titleOrNameWasChanged();
321 //____________________________________________________________________
322 void HistValProfile::SetMarkerSize( float sz)
324 m_h1->SetMarkerSize(sz);
325 m_h2->SetMarkerSize(sz);
326 this->titleOrNameWasChanged();
329 //____________________________________________________________________
330 void HistValProfile::setMinimum( const double& m )
334 this->titleOrNameWasChanged();
337 //____________________________________________________________________
338 void HistValProfile::setMaximum( const double& m )
342 this->titleOrNameWasChanged();
345 //____________________________________________________________________
346 void HistValProfile::setName(const std::string& name)
348 m_h1->SetName(convertedRootName(name).c_str());
349 m_h2->SetName(name.c_str());
350 this->titleOrNameWasChanged();
353 //____________________________________________________________________
354 void HistValProfile::setTitle(const std::string& title)
356 m_h1->SetTitle(title.c_str());
357 m_h2->SetTitle(title.c_str());
358 this->titleOrNameWasChanged();
361 //____________________________________________________________________
362 void HistValProfile::setNameTitle(const std::string& name,
363 const std::string& title)
365 m_h1->SetNameTitle(convertedRootName(name).c_str(),title.c_str());
366 m_h2->SetNameTitle(name.c_str(),title.c_str());
367 this->titleOrNameWasChanged();