Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
THnBase.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Axel Naumann (2011-12-20)
3
4/*************************************************************************
5 * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "THnBase.h"
13
14#include "TAxis.h"
15#include "TBrowser.h"
16#include "TError.h"
17#include "TClass.h"
18#include "TF1.h"
19#include "TH1D.h"
20#include "TH2D.h"
21#include "TH3D.h"
22#include "THn.h"
23#include "THnSparse.h"
24#include "TMath.h"
25#include "TRandom.h"
26#include "TVirtualPad.h"
27
28#include "HFitInterface.h"
29#include "Fit/DataRange.h"
30#include "Fit/SparseData.h"
33
34
35/** \class THnBase
36 \ingroup Hist
37Multidimensional histogram base.
38Defines common functionality and interfaces for THn, THnSparse.
39*/
40
42
43////////////////////////////////////////////////////////////////////////////////
44/// Construct a THnBase with "dim" dimensions,
45/// "nbins" holds the number of bins for each dimension;
46/// "xmin" and "xmax" the minimal and maximal value for each dimension.
47/// The arrays "xmin" and "xmax" can be NULL; in that case SetBinEdges()
48/// must be called for each dimension.
49
50THnBase::THnBase(const char* name, const char* title, Int_t dim,
51 const Int_t* nbins, const Double_t* xmin, const Double_t* xmax):
52TNamed(name, title), fNdimensions(dim), fAxes(dim), fBrowsables(dim),
53fEntries(0), fTsumw(0), fTsumw2(-1.), fTsumwx(dim), fTsumwx2(dim),
54fIntegral(0), fIntegralStatus(kNoInt)
55{
56 for (Int_t i = 0; i < fNdimensions; ++i) {
57 TAxis* axis = new TAxis(nbins[i], xmin ? xmin[i] : 0., xmax ? xmax[i] : 1.);
58 axis->SetName(TString::Format("axis%d", i));
59 fAxes.AddAtAndExpand(axis, i);
60 }
61 SetTitle(title);
63}
64
65THnBase::THnBase(const char *name, const char *title, Int_t dim, const Int_t *nbins,
66 const std::vector<std::vector<double>> &xbins)
67 : TNamed(name, title), fNdimensions(dim), fAxes(dim), fBrowsables(dim), fEntries(0), fTsumw(0), fTsumw2(-1.),
68 fTsumwx(dim), fTsumwx2(dim), fIntegral(0), fIntegralStatus(kNoInt)
69{
70 if (Int_t(xbins.size()) != fNdimensions) {
71 Error("THnBase", "Mismatched number of dimensions %d with number of bin edge vectors %zu", fNdimensions,
72 xbins.size());
73 }
74 for (Int_t i = 0; i < fNdimensions; ++i) {
75 if (Int_t(xbins[i].size()) != (nbins[i] + 1)) {
76 Error("THnBase", "Mismatched number of bins %d with number of bin edges %zu", nbins[i], xbins[i].size());
77 }
78 TAxis *axis = new TAxis(nbins[i], xbins[i].data());
79 axis->SetName(TString::Format("axis%d", i));
80 fAxes.AddAtAndExpand(axis, i);
81 }
82 SetTitle(title);
84}
85
87 : TNamed(other), fNdimensions(other.fNdimensions), fAxes(fNdimensions), fBrowsables(fNdimensions),
88 fEntries(other.fEntries), fTsumw(other.fTsumw), fTsumw2(other.fTsumw2), fTsumwx(other.fTsumwx),
89 fTsumwx2(other.fTsumwx2), fIntegral(other.fIntegral), fIntegralStatus(other.fIntegralStatus)
90{
91
92 for (Int_t i = 0; i < fNdimensions; ++i) {
93 TAxis *axis = new TAxis(*static_cast<TAxis *>(other.fAxes[i]));
94 fAxes.AddAtAndExpand(axis, i);
95 }
97}
98
100{
101
102 if (this == &other)
103 return *this;
104
105 TNamed::operator=(other);
109 fEntries = other.fEntries;
110 fTsumw = other.fTsumw;
111 fTsumw2 = other.fTsumw2;
112 fTsumwx = other.fTsumwx;
113 fTsumwx2 = other.fTsumwx2;
114 fIntegral = other.fIntegral;
116
117 for (Int_t i = 0; i < fNdimensions; ++i) {
118 TAxis *axis = new TAxis(*static_cast<TAxis *>(other.fAxes[i]));
119 fAxes.AddAtAndExpand(axis, i);
120 }
121 fAxes.SetOwner();
122
123 return *this;
124}
125
127 : TNamed(other), fNdimensions(other.fNdimensions), fAxes(other.fAxes), fBrowsables(fNdimensions),
128 fEntries(other.fEntries), fTsumw(other.fTsumw), fTsumw2(other.fTsumw2), fTsumwx(other.fTsumwx),
129 fTsumwx2(other.fTsumwx2), fIntegral(std::move(other.fIntegral)), fIntegralStatus(other.fIntegralStatus)
130{
131
132 other.fAxes.SetOwner(false);
133 other.fAxes.Clear();
134 fAxes.SetOwner();
135}
136
138{
139
140 if (this == &other)
141 return *this;
142
143 TNamed::operator=(other);
144 fNdimensions = other.fNdimensions;
145 fAxes = other.fAxes;
147 fEntries = other.fEntries;
148 fTsumw = other.fTsumw;
149 fTsumw2 = other.fTsumw2;
150 fTsumwx = other.fTsumwx;
151 fTsumwx2 = other.fTsumwx2;
152 fIntegral = std::move(other.fIntegral);
153 fIntegralStatus = other.fIntegralStatus;
154
155 other.fAxes.SetOwner(false);
156 other.fAxes.Clear();
157 fAxes.SetOwner();
158
159 return *this;
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Destruct a THnBase
164
166 if (fIntegralStatus != kNoInt)
167 fIntegral.clear();
168}
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Create a new THnBase object that is of the same type as *this,
173/// but with dimensions and bins given by axes.
174/// If keepTargetAxis is true, the axes will keep their original xmin / xmax,
175/// else they will be restricted to the range selected (first / last).
176
177THnBase* THnBase::CloneEmpty(const char* name, const char* title,
178 const TObjArray* axes, Bool_t keepTargetAxis) const
179{
180 THnBase* ret = (THnBase*)IsA()->New();
181 Int_t chunkSize = 1024 * 16;
183 chunkSize = ((const THnSparse*)this)->GetChunkSize();
184 }
185 ret->Init(name, title, axes, keepTargetAxis, chunkSize);
186 return ret;
187}
188
189
190////////////////////////////////////////////////////////////////////////////////
191/// Initialize axes and name.
192
193void THnBase::Init(const char* name, const char* title,
194 const TObjArray* axes, Bool_t keepTargetAxis,
195 Int_t chunkSize /*= 1024 * 16*/)
196{
197 SetNameTitle(name, title);
198
199 TIter iAxis(axes);
200 const TAxis* axis = nullptr;
201 Int_t pos = 0;
202 Int_t *nbins = new Int_t[axes->GetEntriesFast()];
203 while ((axis = (TAxis*)iAxis())) {
204 TAxis* reqaxis = new TAxis(*axis);
205 if (!keepTargetAxis && axis->TestBit(TAxis::kAxisRange)) {
206 Int_t binFirst = axis->GetFirst();
207 // The lowest egde of the underflow is meaningless.
208 if (binFirst == 0)
209 binFirst = 1;
210 Int_t binLast = axis->GetLast();
211 // The overflow edge is implicit.
212 if (binLast > axis->GetNbins())
213 binLast = axis->GetNbins();
214 Int_t nBins = binLast - binFirst + 1;
215 if (axis->GetXbins()->GetSize()) {
216 // non-uniform bins:
217 reqaxis->Set(nBins, axis->GetXbins()->GetArray() + binFirst - 1);
218 } else {
219 // uniform bins:
220 reqaxis->Set(nBins, axis->GetBinLowEdge(binFirst), axis->GetBinUpEdge(binLast));
221 }
222 reqaxis->ResetBit(TAxis::kAxisRange);
223 }
224
225 nbins[pos] = reqaxis->GetNbins();
226 fAxes.AddAtAndExpand(reqaxis, pos++);
227 }
228 fAxes.SetOwner();
229
231 InitStorage(nbins, chunkSize);
234 delete [] nbins;
235}
236
237
238////////////////////////////////////////////////////////////////////////////////
239/// Create an empty histogram with name and title with a given
240/// set of axes. Create a TH1D/TH2D/TH3D, depending on the number
241/// of elements in axes.
242
243TH1* THnBase::CreateHist(const char* name, const char* title,
244 const TObjArray* axes,
245 Bool_t keepTargetAxis ) const {
246 const int ndim = axes->GetSize();
247
248 TH1* hist = nullptr;
249 // create hist with dummy axes, we fix them later.
250 if (ndim == 1)
251 hist = new TH1D(name, title, 1, 0., 1.);
252 else if (ndim == 2)
253 hist = new TH2D(name, title, 1, 0., 1., 1, 0., 1.);
254 else if (ndim == 3)
255 hist = new TH3D(name, title, 1, 0., 1., 1, 0., 1., 1, 0., 1.);
256 else {
257 Error("CreateHist", "Cannot create histogram %s with %d dimensions!", name, ndim);
258 return nullptr;
259 }
260
261 TAxis* hax[3] = {hist->GetXaxis(), hist->GetYaxis(), hist->GetZaxis()};
262 for (Int_t d = 0; d < ndim; ++d) {
263 TAxis* reqaxis = (TAxis*)(*axes)[d];
264 hax[d]->SetTitle(reqaxis->GetTitle());
265 if (!keepTargetAxis && reqaxis->TestBit(TAxis::kAxisRange)) {
266 // axis cannot extend to underflow/overflows (fix ROOT-8781)
267 Int_t binFirst = std::max(reqaxis->GetFirst(),1);
268 Int_t binLast = std::min(reqaxis->GetLast(), reqaxis->GetNbins() );
269 Int_t nBins = binLast - binFirst + 1;
270 if (reqaxis->GetXbins()->GetSize()) {
271 // non-uniform bins:
272 hax[d]->Set(nBins, reqaxis->GetXbins()->GetArray() + binFirst - 1);
273 } else {
274 // uniform bins:
275 hax[d]->Set(nBins, reqaxis->GetBinLowEdge(binFirst), reqaxis->GetBinUpEdge(binLast));
276 }
277 } else {
278 if (reqaxis->GetXbins()->GetSize()) {
279 // non-uniform bins:
280 hax[d]->Set(reqaxis->GetNbins(), reqaxis->GetXbins()->GetArray());
281 } else {
282 // uniform bins:
283 hax[d]->Set(reqaxis->GetNbins(), reqaxis->GetXmin(), reqaxis->GetXmax());
284 }
285 }
286 }
287
288 hist->Rebuild();
289
290 return hist;
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Create a THn / THnSparse object from a histogram deriving from TH1.
295
296THnBase* THnBase::CreateHnAny(const char* name, const char* title,
297 const TH1* h, Bool_t sparse, Int_t chunkSize)
298{
299 // Get the dimension of the TH1
300 int ndim = h->GetDimension();
301
302 if (ndim > 3) {
303 ::Error("THnBase::CreateHnAny", "Can only handle 1..3 dimensional histograms!");
304 return nullptr;
305 }
306
307 // Axis properties
308 int nbins[3] = {0,0,0};
309 double minRange[3] = {0.,0.,0.};
310 double maxRange[3] = {0.,0.,0.};
311 const TAxis* axis[3] = { h->GetXaxis(), h->GetYaxis(), h->GetZaxis() };
312 for (int i = 0; i < ndim; ++i) {
313 nbins[i] = axis[i]->GetNbins();
314 minRange[i] = axis[i]->GetXmin();
315 maxRange[i] = axis[i]->GetXmax();
316 }
317
318 // Create the corresponding THnSparse, depending on the storage
319 // type of the TH1. The class name will be "TH??\0" where the first
320 // ? is 1,2 or 3 and the second ? indicates the storage as C, S,
321 // I, L, F or D.
322 THnBase* s = nullptr;
323 const char* cname( h->ClassName() );
324 if (cname[0] == 'T' && cname[1] == 'H'
325 && cname[2] >= '1' && cname[2] <= '3' && cname[4] == 0) {
326
327#define R__THNBCASE(TAG) \
328if (sparse) { \
329s = new _NAME2_(THnSparse,TAG)(name, title, ndim, nbins, \
330minRange, maxRange, chunkSize); \
331} else { \
332s = new _NAME2_(THn,TAG)(name, title, ndim, nbins, \
333minRange, maxRange); \
334} \
335break;
336
337 switch (cname[3]) {
338 case 'F': R__THNBCASE(F);
339 case 'D': R__THNBCASE(D);
340 case 'I': R__THNBCASE(I);
341 case 'L': R__THNBCASE(L);
342 case 'S': R__THNBCASE(S);
343 case 'C': R__THNBCASE(C);
344 }
345#undef R__THNBCASE
346 }
347 if (!s) {
348 ::Warning("THnSparse::CreateHnAny", "Unknown Type of Histogram");
349 return nullptr;
350 }
351
352 for (int i = 0; i < ndim; ++i) {
353 s->GetAxis(i)->SetTitle(axis[i]->GetTitle());
354 }
355
356 // Get the array to know the number of entries of the TH1
357 const TArray *array = dynamic_cast<const TArray*>(h);
358 if (!array) {
359 ::Warning("THnSparse::CreateHnAny", "Unknown Type of Histogram");
360 return nullptr;
361 }
362
363 s->Add(h);
364 return s;
365}
366
367
368////////////////////////////////////////////////////////////////////////////////
369/// Create a THnSparse (if "sparse") or THn from "hn", possibly
370/// converting THn <-> THnSparse.
371
372THnBase* THnBase::CreateHnAny(const char* name, const char* title,
373 const THnBase* hn, Bool_t sparse,
374 Int_t chunkSize /*= 1024 * 16*/)
375{
376 TClass* type = nullptr;
377 if (hn->InheritsFrom(THnSparse::Class())) {
378 if (sparse) type = hn->IsA();
379 else {
380 char bintype;
381 if (hn->InheritsFrom(THnSparseD::Class())) bintype = 'D';
382 else if (hn->InheritsFrom(THnSparseF::Class())) bintype = 'F';
383 else if (hn->InheritsFrom(THnSparseL::Class())) bintype = 'L';
384 else if (hn->InheritsFrom(THnSparseI::Class())) bintype = 'I';
385 else if (hn->InheritsFrom(THnSparseS::Class())) bintype = 'S';
386 else if (hn->InheritsFrom(THnSparseC::Class())) bintype = 'C';
387 else {
388 hn->Error("CreateHnAny", "Type %s not implemented; please inform the ROOT team!",
389 hn->IsA()->GetName());
390 return nullptr;
391 }
392 type = TClass::GetClass(TString::Format("THn%c", bintype));
393 }
394 } else if (hn->InheritsFrom(THn::Class())) {
395 if (!sparse) type = hn->IsA();
396 else {
397 char bintype = 0;
398 if (hn->InheritsFrom(THnD::Class())) bintype = 'D';
399 else if (hn->InheritsFrom(THnF::Class())) bintype = 'F';
400 else if (hn->InheritsFrom(THnC::Class())) bintype = 'C';
401 else if (hn->InheritsFrom(THnS::Class())) bintype = 'S';
402 else if (hn->InheritsFrom(THnI::Class())) bintype = 'I';
403 else if (hn->InheritsFrom(THnL::Class()) || hn->InheritsFrom(THnL64::Class())) bintype = 'L';
404 if (bintype) {
405 type = TClass::GetClass(TString::Format("THnSparse%c", bintype));
406 }
407 }
408 } else {
409 hn->Error("CreateHnAny", "Unhandled type %s, not deriving from THn nor THnSparse!",
410 hn->IsA()->GetName());
411 return nullptr;
412 }
413 if (!type) {
414 hn->Error("CreateHnAny", "Unhandled type %s, please inform the ROOT team!",
415 hn->IsA()->GetName());
416 return nullptr;
417 }
418
419 THnBase* ret = (THnBase*)type->New();
420 ret->Init(name, title, hn->GetListOfAxes(),
421 kFALSE /*keepTargetAxes*/, chunkSize);
422
423 ret->Add(hn);
424 return ret;
425}
426
427
428////////////////////////////////////////////////////////////////////////////////
429/// Fill the THnBase with the bins of hist that have content
430/// or error != 0.
431
432void THnBase::Add(const TH1* hist, Double_t c /*=1.*/)
433{
434 Long64_t nbins = hist->GetNcells();
435 int x[3] = {0,0,0};
436 for (int i = 0; i < nbins; ++i) {
437 double value = hist->GetBinContent(i);
438 double error = hist->GetBinError(i);
439 if (!value && !error) continue;
440 hist->GetBinXYZ(i, x[0], x[1], x[2]);
442 SetBinError(x, error * c);
443 }
444}
445
446////////////////////////////////////////////////////////////////////////////////
447/// Fit a THnSparse with function f
448///
449/// since the data is sparse by default a likelihood fit is performed
450/// merging all the regions with empty bins for better performance efficiency
451///
452/// Since the THnSparse is not drawn no graphics options are passed
453/// Here is the list of possible options
454///
455/// = "I" Use integral of function in bin instead of value at bin center
456/// = "X" Use chi2 method (default is log-likelihood method)
457/// = "U" Use a User specified fitting algorithm (via SetFCN)
458/// = "Q" Quiet mode (minimum printing)
459/// = "V" Verbose mode (default is between Q and V)
460/// = "E" Perform better Errors estimation using Minos technique
461/// = "B" Use this option when you want to fix one or more parameters
462/// and the fitting function is like "gaus", "expo", "poln", "landau".
463/// = "M" More. Improve fit results
464/// = "R" Use the Range specified in the function range
465
467{
468
469 Foption_t fitOption;
470
471 if (!TH1::FitOptionsMake(option,fitOption)) return 0;
472
473 // The function used to fit cannot be stored in a THnSparse. It
474 // cannot be drawn either. Perhaps in the future.
475 fitOption.Nostore = true;
476 // Use likelihood fit if not specified
477 if (!fitOption.Chi2) fitOption.Like = true;
478 // create range and minimizer options with default values
480 for ( int i = 0; i < GetNdimensions(); ++i ) {
481 TAxis *axis = GetAxis(i);
482 range.AddRange(i, axis->GetXmin(), axis->GetXmax());
483 }
485
486 return ROOT::Fit::FitObject(this, f , fitOption , minOption, goption, range);
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// Generate an n-dimensional random tuple based on the histogrammed
491/// distribution. If subBinRandom, the returned tuple will be additionally
492/// randomly distributed within the randomized bin, using a flat
493/// distribution.
494
495void THnBase::GetRandom(Double_t *rand, Bool_t subBinRandom /* = kTRUE */)
496{
497 // check whether the integral array is valid
500
501 // generate a random bin
502 Double_t p = gRandom->Rndm();
503 Long64_t idx = TMath::BinarySearch(GetNbins() + 1, fIntegral.data(), p);
504 const Int_t nStaticBins = 40;
505 Int_t bin[nStaticBins];
506 Int_t* pBin = bin;
507 if (GetNdimensions() > nStaticBins) {
508 pBin = new Int_t[GetNdimensions()];
509 }
510 GetBinContent(idx, pBin);
511
512 // convert bin coordinates to real values
513 for (Int_t i = 0; i < fNdimensions; i++) {
514 rand[i] = GetAxis(i)->GetBinCenter(pBin[i]);
515
516 // randomize the vector within a bin
517 if (subBinRandom)
518 rand[i] += (gRandom->Rndm() - 0.5) * GetAxis(i)->GetBinWidth(pBin[i]);
519 }
520 if (pBin != bin) {
521 delete [] pBin;
522 }
523
524 return;
525}
526
527////////////////////////////////////////////////////////////////////////////////
528/// Check whether bin coord is in range, as defined by TAxis::SetRange().
529
531{
532 Int_t min = 0;
533 Int_t max = 0;
534 for (Int_t i = 0; i < fNdimensions; ++i) {
535 TAxis *axis = GetAxis(i);
536 if (!axis->TestBit(TAxis::kAxisRange)) continue;
537 min = axis->GetFirst();
538 max = axis->GetLast();
539 if (coord[i] < min || coord[i] > max)
540 return kFALSE;
541 }
542 return kTRUE;
543}
544
545////////////////////////////////////////////////////////////////////////////////
546/// Project all bins into a ndim-dimensional THn / THnSparse (whatever
547/// *this is) or if (ndim < 4 and !wantNDim) a TH1/2/3 histogram,
548/// keeping only axes in dim (specifying ndim dimensions).
549/// If "option" contains:
550/// - "E" errors will be calculated.
551/// - "A" ranges of the target axes will be ignored.
552/// - "O" original axis range of the target axes will be
553/// kept, but only bins inside the selected range
554/// will be filled.
555
557 Bool_t wantNDim,
558 Option_t* option /*= ""*/) const
559{
561 name +="_proj";
562
563 for (Int_t d = 0; d < ndim; ++d) {
564 name += "_";
565 name += dim[d];
566 }
567
568 TString title(GetTitle());
569 Ssiz_t posInsert = title.First(';');
570 if (posInsert == kNPOS) {
571 title += " projection ";
572 for (Int_t d = 0; d < ndim; ++d)
573 title += GetAxis(dim[d])->GetTitle();
574 } else {
575 for (Int_t d = ndim - 1; d >= 0; --d) {
576 title.Insert(posInsert, GetAxis(d)->GetTitle());
577 if (d)
578 title.Insert(posInsert, ", ");
579 }
580 title.Insert(posInsert, " projection ");
581 }
582
583 TObjArray newaxes(ndim);
584 for (Int_t d = 0; d < ndim; ++d) {
585 newaxes.AddAt(GetAxis(dim[d]),d);
586 }
587
588 THnBase* hn = nullptr;
589 TH1* hist = nullptr;
590 TObject* ret = nullptr;
591
592 Bool_t* hadRange = nullptr;
593 Bool_t ignoreTargetRange = (option && (strchr(option, 'A') || strchr(option, 'a')));
594 Bool_t keepTargetAxis = ignoreTargetRange || (option && (strchr(option, 'O') || strchr(option, 'o')));
595 if (ignoreTargetRange) {
596 hadRange = new Bool_t[ndim];
597 for (Int_t d = 0; d < ndim; ++d){
598 TAxis *axis = GetAxis(dim[d]);
599 hadRange[d] = axis->TestBit(TAxis::kAxisRange);
601 }
602 }
603
604 if (wantNDim)
605 ret = hn = CloneEmpty(name, title, &newaxes, keepTargetAxis);
606 else
607 ret = hist = CreateHist(name, title, &newaxes, keepTargetAxis);
608
609 if (keepTargetAxis) {
610 // make the whole axes visible, i.e. unset the range
611 if (wantNDim) {
612 for (Int_t d = 0; d < ndim; ++d) {
613 hn->GetAxis(d)->SetRange(0, 0);
614 }
615 } else {
616 hist->GetXaxis()->SetRange(0, 0);
617 hist->GetYaxis()->SetRange(0, 0);
618 hist->GetZaxis()->SetRange(0, 0);
619 }
620 }
621
622 Bool_t haveErrors = GetCalculateErrors();
623 Bool_t wantErrors = haveErrors || (option && (strchr(option, 'E') || strchr(option, 'e')));
624
625 Int_t* bins = new Int_t[ndim];
626 Long64_t myLinBin = 0;
627
628 THnIter iter(this, kTRUE /*use axis range*/);
629
630 while ((myLinBin = iter.Next()) >= 0) {
631 Double_t v = GetBinContent(myLinBin);
632
633 for (Int_t d = 0; d < ndim; ++d) {
634 bins[d] = iter.GetCoord(dim[d]);
635 if (!keepTargetAxis && GetAxis(dim[d])->TestBit(TAxis::kAxisRange)) {
636 Int_t binOffset = GetAxis(dim[d])->GetFirst();
637 // Don't subtract even more if underflow is alreday included:
638 if (binOffset > 0) --binOffset;
639 bins[d] -= binOffset;
640 }
641 }
642
643 Long64_t targetLinBin = -1;
644 if (!wantNDim) {
645 if (ndim == 1) targetLinBin = bins[0];
646 else if (ndim == 2) targetLinBin = hist->GetBin(bins[0], bins[1]);
647 else if (ndim == 3) targetLinBin = hist->GetBin(bins[0], bins[1], bins[2]);
648 } else {
649 targetLinBin = hn->GetBin(bins, kTRUE /*allocate*/);
650 }
651
652 if (wantErrors) {
653 Double_t err2 = 0.;
654 if (haveErrors) {
655 err2 = GetBinError2(myLinBin);
656 } else {
657 err2 = v;
658 }
659 if (wantNDim) {
660 hn->AddBinError2(targetLinBin, err2);
661 } else {
662 Double_t preverr = hist->GetBinError(targetLinBin);
663 hist->SetBinError(targetLinBin, TMath::Sqrt(preverr * preverr + err2));
664 }
665 }
666
667 // only _after_ error calculation, or sqrt(v) is taken into account!
668 if (wantNDim)
669 hn->AddBinContent(targetLinBin, v);
670 else
671 hist->AddBinContent(targetLinBin, v);
672 }
673
674 delete [] bins;
675
676 if (wantNDim) {
677 hn->SetEntries(fEntries);
678 } else {
679 if (!iter.HaveSkippedBin()) {
680 hist->SetEntries(fEntries);
681 } else {
682 // re-compute the entries
683 // in case of error calculation (i.e. when Sumw2() is set)
684 // use the effective entries for the entries
685 // since this is the only way to estimate them
686 hist->ResetStats();
687 Double_t entries = hist->GetEffectiveEntries();
688 if (!wantErrors) {
689 // to avoid numerical rounding
690 entries = TMath::Floor(entries + 0.5);
691 }
692 hist->SetEntries(entries);
693 }
694 }
695
696 if (hadRange) {
697 // reset kAxisRange bit:
698 for (Int_t d = 0; d < ndim; ++d)
699 GetAxis(dim[d])->SetBit(TAxis::kAxisRange, hadRange[d]);
700
701 delete [] hadRange;
702 }
703
704 return ret;
705}
706
707////////////////////////////////////////////////////////////////////////////////
708/// Scale contents and errors of this histogram by c:
709/// this = this * c
710/// It does not modify the histogram's number of entries.
711
713{
714
715 Double_t nEntries = GetEntries();
716 // Scale the contents & errors
717 Bool_t haveErrors = GetCalculateErrors();
718 Long64_t i = 0;
719 THnIter iter(this);
720 while ((i = iter.Next()) >= 0) {
721 // Get the content of the bin from the current histogram
723 SetBinContent(i, c * v);
724 if (haveErrors) {
725 Double_t err2 = GetBinError2(i);
726 SetBinError2(i, c * c * err2);
727 }
728 }
729 SetEntries(nEntries);
730}
731
732////////////////////////////////////////////////////////////////////////////////
733/// Add() implementation for both rebinned histograms and those with identical
734/// binning. See THnBase::Add().
735
737{
738 if (fNdimensions != h->GetNdimensions()) {
739 Warning("RebinnedAdd", "Different number of dimensions, cannot carry out operation on the histograms");
740 return;
741 }
742
743 // Trigger error calculation if h has it
744 if (!GetCalculateErrors() && h->GetCalculateErrors())
745 Sumw2();
746 Bool_t haveErrors = GetCalculateErrors();
747
748 Double_t* x = nullptr;
749 if (rebinned) {
750 x = new Double_t[fNdimensions];
751 }
752 Int_t* coord = new Int_t[fNdimensions];
753
754 // Expand the exmap if needed, to reduce collisions
755 Long64_t numTargetBins = GetNbins() + h->GetNbins();
756 Reserve(numTargetBins);
757
758 Long64_t i = 0;
759 THnIter iter(h);
760 // Add to this whatever is found inside the other histogram
761 while ((i = iter.Next(coord)) >= 0) {
762 // Get the content of the bin from the second histogram
763 Double_t v = h->GetBinContent(i);
764
765 Long64_t mybinidx = -1;
766 if (rebinned) {
767 // Get the bin center given a coord
768 for (Int_t j = 0; j < fNdimensions; ++j)
769 x[j] = h->GetAxis(j)->GetBinCenter(coord[j]);
770
771 mybinidx = GetBin(x, kTRUE /* allocate*/);
772 } else {
773 mybinidx = GetBin(coord, kTRUE /*allocate*/);
774 }
775
776 if (haveErrors) {
777 Double_t err2 = h->GetBinError2(i) * c * c;
778 AddBinError2(mybinidx, err2);
779 }
780 // only _after_ error calculation, or sqrt(v) is taken into account!
781 AddBinContent(mybinidx, c * v);
782 }
783
784 delete [] coord;
785 delete [] x;
786
787 // add also the statistics
788 fTsumw += c * h->fTsumw;
789 if (haveErrors) {
790 fTsumw2 += c * c * h->fTsumw2;
791 if (h->fTsumwx.fN == fNdimensions && h->fTsumwx2.fN == fNdimensions) {
792 for (Int_t d = 0; d < fNdimensions; ++d) {
793 fTsumwx[d] += c * h->fTsumwx[d];
794 fTsumwx2[d] += c * h->fTsumwx2[d];
795 }
796 }
797 }
798
799 Double_t nEntries = GetEntries() + c * h->GetEntries();
800 SetEntries(nEntries);
801}
802
803////////////////////////////////////////////////////////////////////////////////
804/// Add contents of h scaled by c to this histogram:
805/// this = this + c * h
806/// Note that if h has Sumw2 set, Sumw2 is automatically called for this
807/// if not already set.
808
810{
811 // Check consistency of the input
812 if (!CheckConsistency(h, "Add")) return;
813
815}
816
817////////////////////////////////////////////////////////////////////////////////
818/// Add contents of h scaled by c to this histogram:
819/// this = this + c * h
820/// Note that if h has Sumw2 set, Sumw2 is automatically called for this
821/// if not already set.
822/// In contrast to Add(), RebinnedAdd() does not require consistent binning of
823/// this and h; instead, each bin's center is used to determine the target bin.
824
826{
827 AddInternal(h, c, kTRUE);
828}
829
830
831////////////////////////////////////////////////////////////////////////////////
832/// Merge this with a list of THnBase's. All THnBase's provided
833/// in the list must have the same bin layout!
834
836{
837 if (!list) return 0;
838 if (list->IsEmpty()) return (Long64_t)GetEntries();
839
840 Long64_t sumNbins = GetNbins();
841 TIter iter(list);
842 const TObject* addMeObj = nullptr;
843 while ((addMeObj = iter())) {
844 const THnBase* addMe = dynamic_cast<const THnBase*>(addMeObj);
845 if (addMe) {
846 sumNbins += addMe->GetNbins();
847 }
848 }
849 Reserve(sumNbins);
850
851 iter.Reset();
852 while ((addMeObj = iter())) {
853 const THnBase* addMe = dynamic_cast<const THnBase*>(addMeObj);
854 if (!addMe)
855 Error("Merge", "Object named %s is not THnBase! Skipping it.",
856 addMeObj->GetName());
857 else
858 Add(addMe);
859 }
860 return (Long64_t)GetEntries();
861}
862
863
864////////////////////////////////////////////////////////////////////////////////
865/// Multiply this histogram by histogram h
866/// this = this * h
867/// Note that if h has Sumw2 set, Sumw2 is automatically called for this
868/// if not already set.
869
871{
872 // Check consistency of the input
873 if(!CheckConsistency(h, "Multiply"))return;
874
875 // Trigger error calculation if h has it
876 Bool_t wantErrors = kFALSE;
877 if (GetCalculateErrors() || h->GetCalculateErrors())
878 wantErrors = kTRUE;
879
880 if (wantErrors) Sumw2();
881
882 Double_t nEntries = GetEntries();
883 // Now multiply the contents: in this case we have the intersection of the sets of bins
884 Int_t* coord = new Int_t[fNdimensions];
885 Long64_t i = 0;
886 THnIter iter(this);
887 // Add to this whatever is found inside the other histogram
888 while ((i = iter.Next(coord)) >= 0) {
889 // Get the content of the bin from the current histogram
891 // Now look at the bin with the same coordinates in h
892 Long64_t idxh = h->GetBin(coord);
893 Double_t v2 = 0.;
894 if (idxh >= 0) v2 = h->GetBinContent(idxh);
895 SetBinContent(i, v1 * v2);
896 if (wantErrors) {
897 Double_t err1 = GetBinError(i) * v2;
898 Double_t err2 = 0.;
899 if (idxh >= 0) err2 = h->GetBinError(idxh) * v1;
900 SetBinError(i, TMath::Sqrt((err2 * err2 + err1 * err1)));
901 }
902 }
903 SetEntries(nEntries);
904
905 delete [] coord;
906}
907
908////////////////////////////////////////////////////////////////////////////////
909/// Performs the operation: this = this*c*f1
910/// if errors are defined, errors are also recalculated.
911///
912/// Only bins inside the function range are recomputed.
913/// IMPORTANT NOTE: If you intend to use the errors of this histogram later
914/// you should call Sumw2 before making this operation.
915/// This is particularly important if you fit the histogram after
916/// calling Multiply()
917
919{
920 Int_t* coord = new Int_t[fNdimensions];
922
923 Bool_t wantErrors = GetCalculateErrors();
924 if (wantErrors) Sumw2();
925
926 Long64_t i = 0;
927 THnIter iter(this);
928 // Add to this whatever is found inside the other histogram
929 while ((i = iter.Next(coord)) >= 0) {
931
932 // Get the bin coordinates given an index array
933 for (Int_t j = 0; j < fNdimensions; ++j)
934 x[j] = GetAxis(j)->GetBinCenter(coord[j]);
935
936 if (!f->IsInside(x))
937 continue;
939
940 // Evaluate function at points
941 Double_t fvalue = f->EvalPar(x, nullptr);
942
943 SetBinContent(i, c * fvalue * value);
944 if (wantErrors) {
945 Double_t error = GetBinError(i);
946 SetBinError(i, c * fvalue * error);
947 }
948 }
949
950 delete [] x;
951 delete [] coord;
952}
953
954////////////////////////////////////////////////////////////////////////////////
955/// Divide this histogram by h
956/// this = this/(h)
957/// Note that if h has Sumw2 set, Sumw2 is automatically called for
958/// this if not already set.
959/// The resulting errors are calculated assuming uncorrelated content.
960
962{
963 // Check consistency of the input
964 if (!CheckConsistency(h, "Divide"))return;
965
966 // Trigger error calculation if h has it
967 Bool_t wantErrors=GetCalculateErrors();
968 if (!GetCalculateErrors() && h->GetCalculateErrors())
969 wantErrors=kTRUE;
970
971 // Remember original histogram statistics
972 Double_t nEntries = fEntries;
973
974 if (wantErrors) Sumw2();
975 Bool_t didWarn = kFALSE;
976
977 // Now divide the contents: also in this case we have the intersection of the sets of bins
978 Int_t* coord = new Int_t[fNdimensions];
979 Long64_t i = 0;
980 THnIter iter(this);
981 // Add to this whatever is found inside the other histogram
982 while ((i = iter.Next(coord)) >= 0) {
983 // Get the content of the bin from the first histogram
985 // Now look at the bin with the same coordinates in h
986 Long64_t hbin = h->GetBin(coord);
987 Double_t v2 = h->GetBinContent(hbin);
988 if (!v2) {
989 v1 = 0.;
990 v2 = 1.;
991 if (!didWarn) {
992 Warning("Divide(h)", "Histogram h has empty bins - division by zero! Setting bin to 0.");
993 didWarn = kTRUE;
994 }
995 }
996 SetBinContent(i, v1 / v2);
997 if (wantErrors) {
998 Double_t err1 = GetBinError(i) * v2;
999 Double_t err2 = h->GetBinError(hbin) * v1;
1000 Double_t b22 = v2 * v2;
1001 Double_t err = (err1 * err1 + err2 * err2) / (b22 * b22);
1002 SetBinError2(i, err);
1003 }
1004 }
1005 delete [] coord;
1006 SetEntries(nEntries);
1007}
1008
1009////////////////////////////////////////////////////////////////////////////////
1010/// Replace contents of this histogram by multiplication of h1 by h2
1011/// this = (c1*h1)/(c2*h2)
1012/// Note that if h1 or h2 have Sumw2 set, Sumw2 is automatically called for
1013/// this if not already set.
1014/// The resulting errors are calculated assuming uncorrelated content.
1015/// However, if option ="B" is specified, Binomial errors are computed.
1016/// In this case c1 and c2 do not make real sense and they are ignored.
1017
1019{
1020
1021 TString opt = option;
1022 opt.ToLower();
1023 Bool_t binomial = kFALSE;
1024 if (opt.Contains("b")) binomial = kTRUE;
1025
1026 // Check consistency of the input
1027 if (!CheckConsistency(h1, "Divide") || !CheckConsistency(h2, "Divide"))return;
1028 if (!c2) {
1029 Error("Divide","Coefficient of dividing histogram cannot be zero");
1030 return;
1031 }
1032
1033 Reset();
1034
1035 // Trigger error calculation if h1 or h2 have it
1036 if (!GetCalculateErrors() && (h1->GetCalculateErrors()|| h2->GetCalculateErrors() != 0))
1037 Sumw2();
1038
1039 // Count filled bins
1040 Long64_t nFilledBins=0;
1041
1042 // Now divide the contents: we have the intersection of the sets of bins
1043
1044 Int_t* coord = new Int_t[fNdimensions];
1045 memset(coord, 0, sizeof(Int_t) * fNdimensions);
1046 Bool_t didWarn = kFALSE;
1047
1048 Long64_t i = 0;
1049 THnIter iter(h1);
1050 // Add to this whatever is found inside the other histogram
1051 while ((i = iter.Next(coord)) >= 0) {
1052 // Get the content of the bin from the first histogram
1054 // Now look at the bin with the same coordinates in h2
1055 Long64_t h2bin = h2->GetBin(coord);
1056 Double_t v2 = h2->GetBinContent(h2bin);
1057 if (!v2) {
1058 v1 = 0.;
1059 v2 = 1.;
1060 if (!didWarn) {
1061 Warning("Divide(h1, h2)", "Histogram h2 has empty bins - division by zero! Setting bin to 0.");
1062 didWarn = kTRUE;
1063 }
1064 }
1065 nFilledBins++;
1066 Long64_t myBin = GetBin(coord);
1067 SetBinContent(myBin, c1 * v1 / c2 / v2);
1068 if(GetCalculateErrors()){
1069 Double_t err1 = h1->GetBinError(i);
1070 Double_t err2 = h2->GetBinError(h2bin);
1071 Double_t errSq = 0.;
1072 if (binomial) {
1073 if (v1 != v2) {
1074 Double_t w = v1 / v2;
1075 err2 *= w;
1076 errSq = TMath::Abs( ( (1. - 2.*w) * err1 * err1 + err2 * err2 ) / (v2 * v2) );
1077 }
1078 } else {
1079 c1 *= c1;
1080 c2 *= c2;
1081 Double_t b22 = v2 * v2 * c2;
1082 err1 *= v2;
1083 err2 *= v1;
1084 errSq = c1 * c2 * (err1 * err1 + err2 * err2) / (b22 * b22);
1085 }
1086 SetBinError2(myBin, errSq);
1087 }
1088 }
1089
1090 delete [] coord;
1091 SetFilledBins(nFilledBins);
1092
1093 // Set as entries in the result histogram the entries in the numerator
1095}
1096
1097////////////////////////////////////////////////////////////////////////////////
1098/// Consistency check on (some of) the parameters of two histograms (for operations).
1099
1100Bool_t THnBase::CheckConsistency(const THnBase *h, const char *tag) const
1101{
1102 if (fNdimensions != h->GetNdimensions()) {
1103 Warning(tag, "Different number of dimensions, cannot carry out operation on the histograms");
1104 return kFALSE;
1105 }
1106 for (Int_t dim = 0; dim < fNdimensions; dim++){
1107 if (GetAxis(dim)->GetNbins() != h->GetAxis(dim)->GetNbins()) {
1108 Warning(tag, "Different number of bins on axis %i, cannot carry out operation on the histograms", dim);
1109 return kFALSE;
1110 }
1111 }
1112 return kTRUE;
1113}
1114
1115////////////////////////////////////////////////////////////////////////////////
1116/// Set the axis # of bins and bin limits on dimension idim
1117
1118void THnBase::SetBinEdges(Int_t idim, const Double_t* bins)
1119{
1120 TAxis* axis = (TAxis*) fAxes[idim];
1121 axis->Set(axis->GetNbins(), bins);
1122}
1123
1124////////////////////////////////////////////////////////////////////////////////
1125/// Change (i.e. set) the title.
1126///
1127/// If title is in the form "stringt;string0;string1;string2 ..."
1128/// the histogram title is set to stringt, the title of axis0 to string0,
1129/// of axis1 to string1, of axis2 to string2, etc, just like it is done
1130/// for TH1/TH2/TH3.
1131/// To insert the character ";" in one of the titles, one should use "#;"
1132/// or "#semicolon".
1133
1134void THnBase::SetTitle(const char *title)
1135{
1136 fTitle = title;
1137 fTitle.ReplaceAll("#;",2,"#semicolon",10);
1138
1139 Int_t endHistTitle = fTitle.First(';');
1140 if (endHistTitle >= 0) {
1141 // title contains a ';' so parse the axis titles
1142 Int_t posTitle = endHistTitle + 1;
1143 Int_t lenTitle = fTitle.Length();
1144 Int_t dim = 0;
1145 while (posTitle > 0 && posTitle < lenTitle && dim < fNdimensions){
1146 Int_t endTitle = fTitle.Index(";", posTitle);
1147 TString axisTitle = fTitle(posTitle, endTitle - posTitle);
1148 axisTitle.ReplaceAll("#semicolon", 10, ";", 1);
1149 GetAxis(dim)->SetTitle(axisTitle);
1150 dim++;
1151 if (endTitle > 0)
1152 posTitle = endTitle + 1;
1153 else
1154 posTitle = -1;
1155 }
1156 // Remove axis titles from histogram title
1157 fTitle.Remove(endHistTitle, lenTitle - endHistTitle);
1158 }
1159
1160 fTitle.ReplaceAll("#semicolon", 10, ";", 1);
1161
1162}
1163
1164////////////////////////////////////////////////////////////////////////////////
1165/// Combine the content of "group" neighboring bins into
1166/// a new bin and return the resulting THnBase.
1167/// For group=2 and a 3 dimensional histogram, all "blocks"
1168/// of 2*2*2 bins will be put into a bin.
1169
1171{
1172 Int_t* ngroup = new Int_t[GetNdimensions()];
1173 for (Int_t d = 0; d < GetNdimensions(); ++d)
1174 ngroup[d] = group;
1175 THnBase* ret = RebinBase(ngroup);
1176 delete [] ngroup;
1177 return ret;
1178}
1179
1180////////////////////////////////////////////////////////////////////////////////
1181/// Combine the content of "group" neighboring bins for each dimension
1182/// into a new bin and return the resulting THnBase.
1183/// For group={2,1,1} and a 3 dimensional histogram, pairs of x-bins
1184/// will be grouped.
1185
1187{
1188 Int_t ndim = GetNdimensions();
1189 TString name(GetName());
1190 for (Int_t d = 0; d < ndim; ++d)
1191 name += TString::Format("_%d", group[d]);
1192
1193
1194 TString title(GetTitle());
1195 Ssiz_t posInsert = title.First(';');
1196 if (posInsert == kNPOS) {
1197 title += " rebin ";
1198 for (Int_t d = 0; d < ndim; ++d)
1199 title += TString::Format("{%d}", group[d]);
1200 } else {
1201 for (Int_t d = ndim - 1; d >= 0; --d)
1202 title.Insert(posInsert, TString::Format("{%d}", group[d]));
1203 title.Insert(posInsert, " rebin ");
1204 }
1205
1206 TObjArray newaxes(ndim);
1207 newaxes.SetOwner();
1208 for (Int_t d = 0; d < ndim; ++d) {
1209 newaxes.AddAt(new TAxis(*GetAxis(d) ),d);
1210 if (group[d] > 1) {
1211 TAxis* newaxis = (TAxis*) newaxes.At(d);
1212 Int_t newbins = (newaxis->GetNbins() + group[d] - 1) / group[d];
1213 if (newaxis->GetXbins() && newaxis->GetXbins()->GetSize()) {
1214 // variable bins
1215 Double_t *edges = new Double_t[newbins + 1];
1216 for (Int_t i = 0; i < newbins + 1; ++i)
1217 if (group[d] * i <= newaxis->GetNbins())
1218 edges[i] = newaxis->GetXbins()->At(group[d] * i);
1219 else edges[i] = newaxis->GetXmax();
1220 newaxis->Set(newbins, edges);
1221 delete [] edges;
1222 } else {
1223 newaxis->Set(newbins, newaxis->GetXmin(), newaxis->GetXmax());
1224 }
1225 }
1226 }
1227
1228 THnBase* h = CloneEmpty(name.Data(), title.Data(), &newaxes, kTRUE);
1229 Bool_t haveErrors = GetCalculateErrors();
1230 Bool_t wantErrors = haveErrors;
1231
1232 Int_t* bins = new Int_t[ndim];
1233 Int_t* coord = new Int_t[fNdimensions];
1234
1235 Long64_t i = 0;
1236 THnIter iter(this);
1237 while ((i = iter.Next(coord)) >= 0) {
1239 for (Int_t d = 0; d < ndim; ++d) {
1240 bins[d] = TMath::CeilNint( (double) coord[d]/group[d] );
1241 }
1242 Long64_t idxh = h->GetBin(bins, kTRUE /*allocate*/);
1243
1244 if (wantErrors) {
1245 // wantErrors == haveErrors, thus:
1246 h->AddBinError2(idxh, GetBinError2(i));
1247 }
1248
1249 // only _after_ error calculation, or sqrt(v) is taken into account!
1250 h->AddBinContent(idxh, v);
1251 }
1252
1253 delete [] bins;
1254 delete [] coord;
1255
1256 h->SetEntries(fEntries);
1257
1258 return h;
1259
1260}
1261
1262////////////////////////////////////////////////////////////////////////////////
1263/// Clear the histogram
1264
1265void THnBase::ResetBase(Option_t * /*option = ""*/)
1266{
1267 fEntries = 0.;
1268 fTsumw = 0.;
1269 fTsumw2 = -1.;
1270 if (fIntegralStatus != kNoInt) {
1271 fIntegral.clear();
1273 }
1274}
1275
1276////////////////////////////////////////////////////////////////////////////////
1277/// Calculate the integral of the histogram
1278
1280{
1281 // delete old integral
1282 if (fIntegralStatus != kNoInt) {
1283 fIntegral.clear();
1285 }
1286
1287 // check number of bins
1288 if (GetNbins() == 0) {
1289 Error("ComputeIntegral", "The histogram must have at least one bin.");
1290 return 0.;
1291 }
1292
1293 // allocate integral array
1294 fIntegral.resize(GetNbins() + 1);
1295 fIntegral[0] = 0.;
1296
1297 // fill integral array with contents of regular bins (non over/underflow)
1298 Int_t* coord = new Int_t[fNdimensions];
1299 Long64_t i = 0;
1300 THnIter iter(this);
1301 while ((i = iter.Next(coord)) >= 0) {
1303
1304 // check whether the bin is regular
1305 bool regularBin = true;
1306 for (Int_t dim = 0; dim < fNdimensions; dim++) {
1307 if (coord[dim] < 1 || coord[dim] > GetAxis(dim)->GetNbins()) {
1308 regularBin = false;
1309 break;
1310 }
1311 }
1312
1313 // if outlayer, count it with zero weight
1314 if (!regularBin) v = 0.;
1315
1316 fIntegral[i + 1] = fIntegral[i] + v;
1317 }
1318 delete [] coord;
1319
1320 // check sum of weights
1321 if (fIntegral[GetNbins()] == 0.) {
1322 Error("ComputeIntegral", "No hits in regular bins (non over/underflow).");
1323 fIntegral.clear();
1324 return 0.;
1325 }
1326
1327 // normalize the integral array
1328 for (Long64_t j = 0; j <= GetNbins(); ++j)
1330
1331 // set status to valid
1333 return fIntegral[GetNbins()];
1334}
1335
1336////////////////////////////////////////////////////////////////////////////////
1337/// Print bin with linex index "idx".
1338/// For valid options see PrintBin(Long64_t idx, Int_t* bin, Option_t* options).
1339
1340void THnBase::PrintBin(Long64_t idx, Option_t* options) const
1341{
1342 Int_t* coord = new Int_t[fNdimensions];
1343 PrintBin(idx, coord, options);
1344 delete [] coord;
1345}
1346
1347////////////////////////////////////////////////////////////////////////////////
1348/// Print one bin. If "idx" is != -1 use that to determine the bin,
1349/// otherwise (if "idx" == -1) use the coordinate in "bin".
1350/// If "options" contains:
1351/// - '0': only print bins with an error or content != 0
1352/// Return whether the bin was printed (depends on options)
1353
1355{
1356 Double_t v = -42;
1357 if (idx == -1) {
1358 idx = GetBin(bin);
1359 v = GetBinContent(idx);
1360 } else {
1361 v = GetBinContent(idx, bin);
1362 }
1363
1364 Double_t err = 0.;
1365 if (GetCalculateErrors()) {
1366 if (idx != -1) {
1367 err = GetBinError(idx);
1368 }
1369 }
1370
1371 if (v == 0. && err == 0. && options && strchr(options, '0')) {
1372 // suppress zeros, and we have one.
1373 return kFALSE;
1374 }
1375
1376 TString coord;
1377 for (Int_t dim = 0; dim < fNdimensions; ++dim) {
1378 coord += bin[dim];
1379 coord += ',';
1380 }
1381 coord.Remove(coord.Length() - 1);
1382
1383 if (GetCalculateErrors()) {
1384 Printf("Bin at (%s) = %g (+/- %g)", coord.Data(), v, err);
1385 } else {
1386 Printf("Bin at (%s) = %g", coord.Data(), v);
1387 }
1388
1389 return kTRUE;
1390}
1391
1392////////////////////////////////////////////////////////////////////////////////
1393/// Print "howmany" entries starting at "from". If "howmany" is -1, print all.
1394/// If "options" contains:
1395/// - 'x': print in the order of axis bins, i.e. (0,0,...,0), (0,0,...,1),...
1396/// - '0': only print bins with content != 0
1397
1398void THnBase::PrintEntries(Long64_t from /*=0*/, Long64_t howmany /*=-1*/,
1399 Option_t* options /*=0*/) const
1400{
1401 if (from < 0) from = 0;
1402 if (howmany == -1) howmany = GetNbins();
1403
1404 Int_t* bin = new Int_t[fNdimensions];
1405
1406 if (options && (strchr(options, 'x') || strchr(options, 'X'))) {
1407 Int_t* nbins = new Int_t[fNdimensions];
1408 for (Int_t dim = fNdimensions - 1; dim >= 0; --dim) {
1409 nbins[dim] = GetAxis(dim)->GetNbins();
1410 bin[dim] = from % nbins[dim];
1411 from /= nbins[dim];
1412 }
1413
1414 for (Long64_t i = 0; i < howmany; ++i) {
1415 if (!PrintBin(-1, bin, options))
1416 ++howmany;
1417 // Advance to next bin:
1418 ++bin[fNdimensions - 1];
1419 for (Int_t dim = fNdimensions - 1; dim >= 0; --dim) {
1420 if (bin[dim] >= nbins[dim]) {
1421 bin[dim] = 0;
1422 if (dim > 0) {
1423 ++bin[dim - 1];
1424 } else {
1425 howmany = -1; // aka "global break"
1426 }
1427 }
1428 }
1429 }
1430 delete [] nbins;
1431 } else {
1432 for (Long64_t i = from; i < from + howmany; ++i) {
1433 if (!PrintBin(i, bin, options))
1434 ++howmany;
1435 }
1436 }
1437 delete [] bin;
1438}
1439
1440////////////////////////////////////////////////////////////////////////////////
1441/// Print a THnBase. If "option" contains:
1442/// - 'a': print axis details
1443/// - 'm': print memory usage
1444/// - 's': print statistics
1445/// - 'c': print its content, too (this can generate a LOT of output!)
1446/// Other options are forwarded to PrintEntries().
1447
1448void THnBase::Print(Option_t* options) const
1449{
1450 Bool_t optAxis = options && (strchr(options, 'A') || (strchr(options, 'a')));
1451 Bool_t optMem = options && (strchr(options, 'M') || (strchr(options, 'm')));
1452 Bool_t optStat = options && (strchr(options, 'S') || (strchr(options, 's')));
1453 Bool_t optContent = options && (strchr(options, 'C') || (strchr(options, 'c')));
1454
1455 Printf("%s (*0x%zx): \"%s\" \"%s\"", IsA()->GetName(), (size_t)this, GetName(), GetTitle());
1456 Printf(" %d dimensions, %g entries in %lld filled bins", GetNdimensions(), GetEntries(), GetNbins());
1457
1458 if (optAxis) {
1459 for (Int_t dim = 0; dim < fNdimensions; ++dim) {
1460 TAxis* axis = GetAxis(dim);
1461 Printf(" axis %d \"%s\": %d bins (%g..%g), %s bin sizes", dim,
1462 axis->GetTitle(), axis->GetNbins(), axis->GetXmin(), axis->GetXmax(),
1463 (axis->GetXbins() ? "variable" : "fixed"));
1464 }
1465 }
1466
1467 if (optStat) {
1468 Printf(" %s error calculation", (GetCalculateErrors() ? "with" : "without"));
1469 if (GetCalculateErrors()) {
1470 Printf(" Sum(w)=%g, Sum(w^2)=%g", GetSumw(), GetSumw2());
1471 for (Int_t dim = 0; dim < fNdimensions; ++dim) {
1472 Printf(" axis %d: Sum(w*x)=%g, Sum(w*x^2)=%g", dim, GetSumwx(dim), GetSumwx2(dim));
1473 }
1474 }
1475 }
1476
1477 if (optMem && InheritsFrom(THnSparse::Class())) {
1478 const THnSparse* hsparse = dynamic_cast<const THnSparse*>(this);
1479 Printf(" coordinates stored in %d chunks of %d entries\n %g of bins filled using %g of memory compared to an array",
1480 hsparse->GetNChunks(), hsparse->GetChunkSize(),
1481 hsparse->GetSparseFractionBins(), hsparse->GetSparseFractionMem());
1482 }
1483
1484 if (optContent) {
1485 Printf(" BIN CONTENT:");
1486 PrintEntries(0, -1, options);
1487 }
1488}
1489
1490
1491////////////////////////////////////////////////////////////////////////////////
1492/// Browse a THnSparse: create an entry (ROOT::THnSparseBrowsable) for each
1493/// dimension.
1494
1496{
1497 if (fBrowsables.IsEmpty()) {
1498 for (Int_t dim = 0; dim < fNdimensions; ++dim) {
1500 }
1502 }
1503
1504 for (Int_t dim = 0; dim < fNdimensions; ++dim) {
1505 b->Add(fBrowsables[dim]);
1506 }
1507}
1508
1509
1510
1511
1512/** \class ROOT::Internal::THnBaseBinIter
1513 Iterator over THnBase bins (internal implementation).
1514*/
1515
1516/// Destruct a bin iterator.
1517
1519 // Not much to do, but pin vtable
1520}
1521
1522
1523
1524/** \class THnIter
1525 Iterator over THnBase bins
1526*/
1527
1529
1531 // Destruct a bin iterator.
1532 delete fIter;
1533}
1534
1535
1536/** \class ROOT::Internal::THnBaseBrowsable
1537 TBrowser helper for THnBase.
1538*/
1539
1540
1542
1543////////////////////////////////////////////////////////////////////////////////
1544/// Construct a THnBaseBrowsable.
1545
1547fHist(hist), fAxis(axis), fProj(nullptr)
1548{
1549 TString axisName = hist->GetAxis(axis)->GetName();
1550 if (axisName.IsNull()) {
1551 axisName = TString::Format("axis%d", axis);
1552 }
1553
1554 SetNameTitle(axisName,
1555 TString::Format("Projection on %s of %s", axisName.Data(),
1556 hist->IsA()->GetName()).Data());
1557}
1558
1559////////////////////////////////////////////////////////////////////////////////
1560/// Destruct a THnBaseBrowsable.
1561
1563{
1564 delete fProj;
1565}
1566
1567////////////////////////////////////////////////////////////////////////////////
1568/// Browse an axis of a THnBase, i.e. draw its projection.
1569
1571{
1572 if (!fProj) {
1573 fProj = fHist->Projection(fAxis);
1574 }
1575 fProj->Draw(b ? b->GetDrawOption() : "");
1576 gPad->Update();
1577}
1578
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:124
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
#define R__THNBCASE(TAG)
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
#define gPad
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition DataRange.h:35
void AddRange(unsigned int icoord, double xmin, double xmax)
add a range [xmin,xmax] for the new coordinate icoord Adding a range does not delete existing one,...
Definition DataRange.cxx:94
virtual ~THnBaseBinIter()
Destruct a bin iterator.
Definition THnBase.cxx:1518
TBrowser helper for THnBase.
Definition THnBase.h:297
~THnBaseBrowsable() override
Destruct a THnBaseBrowsable.
Definition THnBase.cxx:1562
THnBaseBrowsable(THnBase *hist, Int_t axis)
Construct a THnBaseBrowsable.
Definition THnBase.cxx:1546
void Browse(TBrowser *b) override
Browse an axis of a THnBase, i.e. draw its projection.
Definition THnBase.cxx:1570
Double_t At(Int_t i) const
Definition TArrayD.h:79
void Set(Int_t n) override
Set size of this array to n doubles.
Definition TArrayD.cxx:106
const Double_t * GetArray() const
Definition TArrayD.h:43
Abstract array base class.
Definition TArray.h:31
Int_t GetSize() const
Definition TArray.h:47
Class to manage histogram axis.
Definition TAxis.h:31
const char * GetTitle() const override
Returns title of object.
Definition TAxis.h:135
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:478
const TArrayD * GetXbins() const
Definition TAxis.h:136
Double_t GetXmax() const
Definition TAxis.h:140
@ kAxisRange
Definition TAxis.h:65
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition TAxis.cxx:518
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition TAxis.cxx:794
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:469
Double_t GetXmin() const
Definition TAxis.h:139
Int_t GetNbins() const
Definition TAxis.h:125
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:1052
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition TAxis.cxx:540
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:528
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:458
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:4978
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2968
Collection abstract base class.
Definition TCollection.h:65
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Bool_t IsEmpty() const
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
1-Dim function class
Definition TF1.h:233
static void RejectPoint(Bool_t reject=kTRUE)
Static function to set the global flag to reject points the fgRejectPoint global flag is tested by al...
Definition TF1.cxx:3683
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:664
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
virtual Double_t GetEffectiveEntries() const
Number of effective entries of the histogram.
Definition TH1.cxx:4444
virtual void Rebuild(Option_t *option="")
Using the current bin info, recompute the arrays for contents and errors.
Definition TH1.cxx:7051
TAxis * GetZaxis()
Definition TH1.h:326
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
Definition TH1.cxx:1266
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition TH1.cxx:9028
static Int_t FitOptionsMake(Option_t *option, Foption_t &Foption)
Decode string choptin and fill fitOption structure.
Definition TH1.cxx:4616
TAxis * GetXaxis()
Definition TH1.h:324
virtual void GetBinXYZ(Int_t binglobal, Int_t &binx, Int_t &biny, Int_t &binz) const
Return binx, biny, binz corresponding to the global bin number globalbin see TH1::GetBin function abo...
Definition TH1.cxx:4938
virtual Int_t GetNcells() const
Definition TH1.h:300
virtual Int_t GetBin(Int_t binx, Int_t biny=0, Int_t binz=0) const
Return Global bin number corresponding to binx,y,z.
Definition TH1.cxx:4925
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
Definition TH1.cxx:9171
TAxis * GetYaxis()
Definition TH1.h:325
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4419
virtual void ResetStats()
Reset the statistics including the number of entries and replace with values calculated from bin cont...
Definition TH1.cxx:7867
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5025
virtual void SetEntries(Double_t n)
Definition TH1.h:390
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:338
3-D histogram with a double per channel (see TH1 documentation)
Definition TH3.h:344
Multidimensional histogram base.
Definition THnBase.h:43
virtual void Sumw2()=0
void SetEntries(Double_t entries)
Definition THnBase.h:192
virtual void SetFilledBins(Long64_t)
Definition THnBase.h:105
void Browse(TBrowser *b) override
Browse a THnSparse: create an entry (ROOT::THnSparseBrowsable) for each dimension.
Definition THnBase.cxx:1495
virtual void InitStorage(Int_t *nbins, Int_t chunkSize)=0
Double_t GetBinError(const Int_t *idx) const
Definition THnBase.h:187
void SetBinError(const Int_t *idx, Double_t e)
Definition THnBase.h:189
Double_t fEntries
Number of entries, spread over chunks.
Definition THnBase.h:48
Double_t GetSumw2() const
Definition THnBase.h:212
Bool_t IsInRange(Int_t *coord) const
Check whether bin coord is in range, as defined by TAxis::SetRange().
Definition THnBase.cxx:530
TFitResultPtr Fit(TF1 *f1, Option_t *option="", Option_t *goption="")
Fit a THnSparse with function f.
Definition THnBase.cxx:466
void AddBinContent(const Int_t *x, Double_t v=1.)
Definition THnBase.h:191
void Scale(Double_t c)
Scale contents and errors of this histogram by c: this = this * c It does not modify the histogram's ...
Definition THnBase.cxx:712
virtual void SetBinError2(Long64_t bin, Double_t e2)=0
TObjArray * GetListOfAxes()
Definition THnBase.h:128
TH1 * CreateHist(const char *name, const char *title, const TObjArray *axes, Bool_t keepTargetAxis) const
Create an empty histogram with name and title with a given set of axes.
Definition THnBase.cxx:243
Bool_t PrintBin(Long64_t idx, Int_t *coord, Option_t *options) const
Print one bin.
Definition THnBase.cxx:1354
Double_t GetSumwx(Int_t dim) const
Definition THnBase.h:213
@ kNoInt
Definition THnBase.h:55
@ kValidInt
Definition THnBase.h:56
Bool_t CheckConsistency(const THnBase *h, const char *tag) const
Consistency check on (some of) the parameters of two histograms (for operations).
Definition THnBase.cxx:1100
Int_t GetNdimensions() const
Definition THnBase.h:140
~THnBase() override
Destruct a THnBase.
Definition THnBase.cxx:165
static THnBase * CreateHnAny(const char *name, const char *title, const TH1 *h1, Bool_t sparse, Int_t chunkSize=1024 *16)
Create a THn / THnSparse object from a histogram deriving from TH1.
Definition THnBase.cxx:296
TArrayD fTsumwx2
Total sum of weight*X*X for each dimension.
Definition THnBase.h:52
void ResetBase(Option_t *option="")
Clear the histogram.
Definition THnBase.cxx:1265
virtual Long64_t GetNbins() const =0
THnBase * RebinBase(Int_t group) const
Combine the content of "group" neighboring bins into a new bin and return the resulting THnBase.
Definition THnBase.cxx:1170
TClass * IsA() const override
Definition THnBase.h:289
TObjArray fAxes
Axes of the histogram.
Definition THnBase.h:46
void SetBinEdges(Int_t idim, const Double_t *bins)
Set the axis # of bins and bin limits on dimension idim.
Definition THnBase.cxx:1118
Bool_t GetCalculateErrors() const
Definition THnBase.h:141
void AddInternal(const THnBase *h, Double_t c, Bool_t rebinned)
Add() implementation for both rebinned histograms and those with identical binning.
Definition THnBase.cxx:736
void SetTitle(const char *title) override
Change (i.e.
Definition THnBase.cxx:1134
void PrintEntries(Long64_t from=0, Long64_t howmany=-1, Option_t *options=nullptr) const
Print "howmany" entries starting at "from".
Definition THnBase.cxx:1398
enum THnBase::@83 fIntegralStatus
! status of integral
Double_t GetBinContent(const Int_t *idx) const
Definition THnBase.h:195
void Add(const THnBase *h, Double_t c=1.)
Add contents of h scaled by c to this histogram: this = this + c * h Note that if h has Sumw2 set,...
Definition THnBase.cxx:809
Double_t fTsumw2
Total sum of weights squared; -1 if no errors are calculated.
Definition THnBase.h:50
virtual void Reserve(Long64_t)
Definition THnBase.h:104
THnBase()
Definition THnBase.h:61
Double_t GetEntries() const
Definition THnBase.h:138
virtual Double_t GetBinError2(Long64_t linidx) const =0
virtual void Reset(Option_t *option="")=0
void SetBinContent(const Int_t *idx, Double_t v)
Definition THnBase.h:205
void Multiply(const THnBase *h)
Multiply this histogram by histogram h this = this * h Note that if h has Sumw2 set,...
Definition THnBase.cxx:870
void Divide(const THnBase *h)
Divide this histogram by h this = this/(h) Note that if h has Sumw2 set, Sumw2 is automatically calle...
Definition THnBase.cxx:961
void Print(Option_t *option="") const override
Print a THnBase.
Definition THnBase.cxx:1448
Double_t GetSumwx2(Int_t dim) const
Definition THnBase.h:214
TObjArray fBrowsables
! Browser-helpers for each axis
Definition THnBase.h:47
Double_t GetSumw() const
Definition THnBase.h:211
TObject * ProjectionAny(Int_t ndim, const Int_t *dim, Bool_t wantNDim, Option_t *option="") const
Project all bins into a ndim-dimensional THn / THnSparse (whatever *this is) or if (ndim < 4 and !...
Definition THnBase.cxx:556
void GetRandom(Double_t *rand, Bool_t subBinRandom=kTRUE)
Generate an n-dimensional random tuple based on the histogrammed distribution.
Definition THnBase.cxx:495
TAxis * GetAxis(Int_t dim) const
Definition THnBase.h:130
THnBase * CloneEmpty(const char *name, const char *title, const TObjArray *axes, Bool_t keepTargetAxis) const
Create a new THnBase object that is of the same type as *this, but with dimensions and bins given by ...
Definition THnBase.cxx:177
Long64_t Merge(TCollection *list)
Merge this with a list of THnBase's.
Definition THnBase.cxx:835
Double_t fTsumw
Total sum of weights.
Definition THnBase.h:49
virtual Long64_t GetBin(const Int_t *idx) const =0
Double_t ComputeIntegral()
Calculate the integral of the histogram.
Definition THnBase.cxx:1279
virtual void AddBinError2(Long64_t bin, Double_t e2)=0
void RebinnedAdd(const THnBase *h, Double_t c=1.)
Add contents of h scaled by c to this histogram: this = this + c * h Note that if h has Sumw2 set,...
Definition THnBase.cxx:825
Int_t fNdimensions
Number of dimensions.
Definition THnBase.h:45
void Init(const char *name, const char *title, const TObjArray *axes, Bool_t keepTargetAxis, Int_t chunkSize=1024 *16)
Initialize axes and name.
Definition THnBase.cxx:193
THnBase & operator=(const THnBase &other)
Definition THnBase.cxx:99
std::vector< Double_t > fIntegral
! vector with bin weight sums
Definition THnBase.h:53
TArrayD fTsumwx
Total sum of weight*X for each dimension.
Definition THnBase.h:51
Iterator over THnBase bins.
Definition THnBase.h:330
Bool_t HaveSkippedBin() const
Definition THnBase.h:345
Int_t GetCoord(Int_t dim) const
Definition THnBase.h:344
~THnIter() override
Definition THnBase.cxx:1530
Long64_t Next(Int_t *coord=nullptr)
Return the next bin's index.
Definition THnBase.h:340
static TClass * Class()
Efficient multidimensional histogram.
Definition THnSparse.h:37
Double_t GetSparseFractionBins() const
Return the amount of filled bins over all bins.
Double_t GetSparseFractionMem() const
Return the amount of used memory over memory that would be used by a non-sparse n-dimensional histogr...
Int_t GetNChunks() const
Definition THnSparse.h:89
Int_t GetChunkSize() const
Definition THnSparse.h:88
static TClass * Class()
static TClass * Class()
static TClass * Class()
void Reset()
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
TString fTitle
Definition TNamed.h:33
void Clear(Option_t *option="") override
Set name and title to empty strings ("").
Definition TNamed.cxx:64
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition TNamed.cxx:51
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition TNamed.cxx:154
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntriesFast() const
Definition TObjArray.h:58
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
Bool_t IsEmpty() const override
Definition TObjArray.h:65
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:201
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:962
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:976
void ResetBit(UInt_t f)
Definition TObject.h:200
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:419
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
TString & Insert(Ssiz_t pos, const char *s)
Definition TString.h:663
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:538
const char * Data() const
Definition TString.h:378
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:706
Bool_t IsNull() const
Definition TString.h:416
TString & Remove(Ssiz_t pos)
Definition TString.h:687
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:634
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:653
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
TH1F * h1
Definition legend1.C:5
return c2
Definition legend2.C:14
#define F(x, y, z)
#define I(x, y, z)
TFitResultPtr FitObject(TH1 *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
fitting function for a TH1 (called from TH1::Fit)
Definition HFitImpl.cxx:972
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition TMath.h:680
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Int_t CeilNint(Double_t x)
Returns the nearest integer of TMath::Ceil(x).
Definition TMath.h:674
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Definition TMathBase.h:347
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
int Like
Definition Foption.h:34
int Nostore
Definition Foption.h:41
int Chi2
Definition Foption.h:32