Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TH2Poly.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// TH2Poly v2.1
3// Author: Olivier Couet, Deniz Gunceler, Danilo Piparo
4
5/*************************************************************************
6 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "TH2Poly.h"
14#include "TMultiGraph.h"
15#include "TGraph.h"
16#include "Riostream.h"
17#include "TList.h"
18#include "TMath.h"
19#include <cassert>
20
22
23/** \class TH2Poly
24 \ingroup Histograms
252D Histogram with Polygonal Bins
26
27## Overview
28`TH2Poly` is a 2D Histogram class (TH2) allowing to define polygonal
29bins of arbitrary shape.
30
31Each bin in the `TH2Poly` histogram is a `TH2PolyBin` object.
32`TH2PolyBin` is a very simple class containing the vertices (stored
33as `TGraph`s or `TMultiGraph`s ) and contents of the polygonal
34bin as well as several related functions.
35
36Essentially, a `TH2Poly` is a TList of `TH2PolyBin` objects
37with methods to manipulate them.
38
39Bins are defined using one of the `AddBin()` methods. The bin definition
40should be done before filling.
41
42The histogram can be filled with `Fill(Double_t x, Double_t y, Double_t w)
43`. `w` is the weight.
44If no weight is specified, it is assumed to be 1.
45
46Not all histogram's area need to be binned. Filling an area without bins,
47will falls into the overflows. Adding a bin is not retroactive; it doesn't
48affect previous fillings. A `Fill()` call, that
49was previously ignored due to the lack of a bin at the specified location, is
50not reconsidered when that location is binned later.
51
52If there are two overlapping bins, the first one in the list will be incremented
53by `Fill()`.
54
55The histogram may automatically extends its limits if a bin outside the
56histogram limits is added. This is done when the default constructor (with no
57arguments) is used. It generates a histogram with no limits along the X and Y
58axis. Adding bins to it will extend it up to a proper size.
59
60`TH2Poly` implements a partitioning algorithm to speed up bins' filling
61(see the "Partitioning Algorithm" section for details).
62The partitioning algorithm divides the histogram into regions called cells.
63The bins that each cell intersects are recorded in an array of `TList`s.
64When a coordinate in the histogram is to be filled; the method (quickly) finds
65which cell the coordinate belongs. It then only loops over the bins
66intersecting that cell to find the bin the input coordinate corresponds to.
67The partitioning of the histogram is updated continuously as each bin is added.
68The default number of cells on each axis is 25. This number could be set to
69another value in the constructor or adjusted later by calling the
70`ChangePartition(Int_t, Int_t)` method. The partitioning algorithm is
71considerably faster than the brute force algorithm (i.e. checking if each bin
72contains the input coordinates), especially if the histogram is to be filled
73many times.
74
75The following very simple macro shows how to build and fill a `TH2Poly`:
76~~~ {.cpp}
77{
78 auto h2p = new TH2Poly();
79
80 Double_t x1[] = {0, 5, 6};
81 Double_t y1[] = {0, 0, 5};
82 Double_t x2[] = {0, -1, -1, 0};
83 Double_t y2[] = {0, 0, -1, 3};
84 Double_t x3[] = {4, 3, 0, 1, 2.4};
85 Double_t y3[] = {4, 3.7, 1, 3.7, 2.5};
86
87 h2p->AddBin(3, x1, y1);
88 h2p->AddBin(4, x2, y2);
89 h2p->AddBin(5, x3, y3);
90
91 h2p->Fill(0.1, 0.01, 3);
92 h2p->Fill(-0.5, -0.5, 7);
93 h2p->Fill(-0.7, -0.5, 1);
94 h2p->Fill(1, 3, 1.5);
95}
96~~~
98More examples can be found in th2polyBoxes.C, th2polyEurope.C, th2polyHoneycomb.C
99and th2polyUSA.C.
100
101## Partitioning Algorithm
102The partitioning algorithm forms an essential part of the `TH2Poly`
103class. It is implemented to speed up the filling of bins.
105With the brute force approach, the filling is done in the following way: An
106iterator loops over all bins in the `TH2Poly` and invokes the
107method `IsInside()` for each of them.
108This method checks if the input location is in that bin. If the filling
109coordinate is inside, the bin is filled. Looping over all the bin is
110very slow.
111
112The alternative is to divide the histogram into virtual rectangular regions
113called "cells". Each cell stores the pointers of the bins intersecting it.
114When a coordinate is to be filled, the method finds which cell the coordinate
115falls into. Since the cells are rectangular, this can be done very quickly.
116It then only loops over the bins associated with that cell and calls `IsInside()`
117only on that bins. This reduces considerably the number of bins on which `IsInside()`
118is called and therefore speed up by a huge factor the filling compare to the brute force
119approach where `IsInside()` is called for all bins.
120
121The addition of bins to the appropriate cells is done when the bin is added
122to the histogram. To do this, `AddBin()` calls the
123`AddBinToPartition()` method.
124This method adds the input bin to the partitioning matrix.
125
126The number of partition cells per axis can be specified in the constructor.
127If it is not specified, the default value of 25 along each axis will be
128assigned. This value was chosen because it is small enough to avoid slowing
129down AddBin(), while being large enough to enhance Fill() by a considerable
130amount. Regardless of how it is initialized at construction time, it can be
131changed later with the `ChangePartition()` method.
132`ChangePartition()` deletes the
133old partition matrix and generates a new one with the specified number of cells
134on each axis.
135
136The optimum number of partition cells per axis changes with the number of
137times `Fill()` will be called. Although partitioning greatly speeds up
138filling, it also adds a constant time delay into the code. When `Fill()`
139is to be called many times, it is more efficient to divide the histogram into
140a large number cells. However, if the histogram is to be filled only a few
141times, it is better to divide into a small number of cells.
142*/
143
144////////////////////////////////////////////////////////////////////////////////
145/// Default Constructor. No boundaries specified.
146
148{
149 Initialize(0., 0., 0., 0., 25, 25);
150 SetName("NoName");
151 SetTitle("NoTitle");
152 SetFloat();
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Constructor with specified name and boundaries,
157/// but no partition cell number.
158
159TH2Poly::TH2Poly(const char *name,const char *title, Double_t xlow,Double_t xup
160 , Double_t ylow,Double_t yup)
161{
162 Initialize(xlow, xup, ylow, yup, 25, 25);
163 SetName(name);
164 SetTitle(title);
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Constructor with specified name and boundaries and partition cell number.
170
171TH2Poly::TH2Poly(const char *name,const char *title,
172 Int_t nX, Double_t xlow, Double_t xup,
173 Int_t nY, Double_t ylow, Double_t yup)
174{
175 Initialize(xlow, xup, ylow, yup, nX, nY);
176 SetName(name);
177 SetTitle(title);
179}
180
181/////////////////////////////////////////////////////////////////////////////////
182/// Copy constructor
183TH2Poly::TH2Poly(const TH2Poly & rhs) : TH2(), fCells(nullptr),
184fIsEmpty(nullptr), fCompletelyInside(nullptr), fBins(nullptr) {
185 rhs.Copy(*this);
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Destructor.
190
192{
193 delete[] fCells;
194 delete[] fIsEmpty;
195 delete[] fCompletelyInside;
196 // delete at the end the bin List since it owns the objects
197 delete fBins;
198}
199
200/////////////////////////////////////////////////////////////////////////////////
201/// Assignment operator
203 if (this != &rhs)
204 rhs.Copy(*this);
205 return *this;
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Copy function for TH2Poly
210
211void TH2Poly::Copy(TObject &newobj) const
212{
213 // copy first TH2 information
214 TH2::Copy(newobj);
215 auto & newth2p = dynamic_cast<TH2Poly &>(newobj);
216 newth2p.SetName(GetName());
217 newth2p.SetTitle(GetTitle());
218
219 newth2p.fCellX = fCellX;
220 newth2p.fCellY = fCellY;
221 newth2p.fNCells = fNCells;
222 newth2p.fStepX = fStepX;
223 newth2p.fStepY = fStepY;
224
225 // deallocate previous arrays, if existing
226 delete[] newth2p.fCells;
227 delete[] newth2p.fIsEmpty;
228 delete[] newth2p.fCompletelyInside;
229 // allocate arrays
230 newth2p.fCells = new TList [fNCells];
231 newth2p.fIsEmpty = new Bool_t [fNCells]; // Empty partition
232 newth2p.fCompletelyInside = new Bool_t [fNCells]; // Cell is completely inside bin
233 // Initializes the flags
234 for (int i = 0; i<fNCells; i++) {
235 newth2p.fIsEmpty[i] = fIsEmpty[i];
236 newth2p.fCompletelyInside[i] = fCompletelyInside[i];
237 }
238 // need to use Clone to copy the contained bin list
239 delete newth2p.fBins; // in case there was something before there
240 if (!fBins) {
241 newth2p.fBins = nullptr;
242 }
243 else {
244 newth2p.fBins = dynamic_cast<TList *>(fBins->Clone());
245 if (!newth2p.fBins)
246 Error("Copy","Error cloning the TH2Poly bin list");
247 else {
248 // add bins in the fCells partition. We need to add the TH2PolyBin objects
249 // of the new copied histograms. For this we call AddBinToPartition
250 // we could probably optimize this by implementing a copy of the partition
251 for (auto bin : *(newth2p.fBins)) {
252 newth2p.AddBinToPartition(dynamic_cast<TH2PolyBin*>(bin));
253 }
254 }
255 }
256 // copy overflow contents
257 for(int i = 0; i < kNOverflow; i++ ) {
258 newth2p.fOverflow[i] = fOverflow[i];
259 }
260 // copy other data members
261 newth2p.fFloat = fFloat;
262 newth2p.fNewBinAdded = fNewBinAdded;
263 newth2p.fBinContentChanged = fBinContentChanged;
264}
265
266
267////////////////////////////////////////////////////////////////////////////////
268/// Create appropriate histogram bin.
269/// e.g. TH2Poly creates TH2PolyBin,
270/// TProfile2Poly creates TProfile2PolyBin
271/// This is done so that TH2Poly::AddBin does not have to be duplicated,
272/// but only create needs to be reimplemented for additional histogram types
273
275{
276 if (!poly) return nullptr;
277
278 if (fBins == nullptr) {
279 fBins = new TList();
280 fBins->SetOwner();
281 }
282
283 fNcells++;
284 Int_t ibin = fNcells - kNOverflow;
285 // if structure fsumw2 is created extend it
286 if (fSumw2.fN) fSumw2.Set(fNcells);
287 return new TH2PolyBin(poly, ibin);
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Adds a new bin to the histogram. It can be any object having the method
292/// IsInside(). It returns the bin number in the histogram. It returns 0 if
293/// it failed to add. To allow the histogram limits to expand when a bin
294/// outside the limits is added, call SetFloat() before adding the bin.
295
297{
298 auto *bin = CreateBin(poly);
299 Int_t ibin = fNcells-kNOverflow;
300 if(!bin) return 0;
301
302 // If the bin lies outside histogram boundaries, then extends the boundaries.
303 // Also changes the partition information accordingly
304 Bool_t flag = kFALSE;
305 if (fFloat) {
306 if (fXaxis.GetXmin() > bin->GetXMin()) {
307 fXaxis.Set(100, bin->GetXMin(), fXaxis.GetXmax());
308 flag = kTRUE;
309 }
310 if (fXaxis.GetXmax() < bin->GetXMax()) {
311 fXaxis.Set(100, fXaxis.GetXmin(), bin->GetXMax());
312 flag = kTRUE;
313 }
314 if (fYaxis.GetXmin() > bin->GetYMin()) {
315 fYaxis.Set(100, bin->GetYMin(), fYaxis.GetXmax());
316 flag = kTRUE;
317 }
318 if (fYaxis.GetXmax() < bin->GetYMax()) {
319 fYaxis.Set(100, fYaxis.GetXmin(), bin->GetYMax());
320 flag = kTRUE;
321 }
322 if (flag) ChangePartition(fCellX, fCellY);
323 } else {
324 /*Implement polygon clipping code here*/
325 }
326
327 fBins->Add((TObject*) bin);
329
330 // Adds the bin to the partition matrix
332
333 return ibin;
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Adds a new bin to the histogram. The number of vertices and their (x,y)
338/// coordinates are required as input. It returns the bin number in the
339/// histogram.
340
342{
343 TGraph *g = new TGraph(n, x, y);
344 Int_t bin = AddBin(g);
345 return bin;
346}
347
348////////////////////////////////////////////////////////////////////////////////
349/// Add a new bin to the histogram. The bin shape is a rectangle.
350/// It returns the bin number of the bin in the histogram.
351
353{
354 Double_t x[] = {x1, x1, x2, x2, x1};
355 Double_t y[] = {y1, y2, y2, y1, y1};
356 TGraph *g = new TGraph(5, x, y);
357 Int_t bin = AddBin(g);
358 return bin;
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Performs the operation: this = this + c1*h1.
363
365{
366 Int_t bin;
367
368 TH2Poly *h1p = (TH2Poly *)h1;
369
370 // Check if number of bins is the same.
371 if (h1p->GetNumberOfBins() != GetNumberOfBins()) {
372 Error("Add", "Attempt to add histograms with different number of bins");
373 return kFALSE;
374 }
375
376 // Check if the bins are the same.
377 TList *h1pBins = h1p->GetBins();
378 TH2PolyBin *thisBin, *h1pBin;
379 for (bin = 1; bin <= GetNumberOfBins(); bin++) {
380 thisBin = (TH2PolyBin *)fBins->At(bin - 1);
381 h1pBin = (TH2PolyBin *)h1pBins->At(bin - 1);
382 if (thisBin->GetXMin() != h1pBin->GetXMin() ||
383 thisBin->GetXMax() != h1pBin->GetXMax() ||
384 thisBin->GetYMin() != h1pBin->GetYMin() ||
385 thisBin->GetYMax() != h1pBin->GetYMax()) {
386 Error("Add", "Attempt to add histograms with different bin limits");
387 return kFALSE;
388 }
389 }
390
391
392 // Create Sumw2 if h1p has Sumw2 set
393 if (fSumw2.fN == 0 && h1p->GetSumw2N() != 0) Sumw2();
394
395 // statistics can be preserved only in case of positive coefficients
396 // otherwise with negative c1 (histogram subtraction) one risks to get negative variances
397 Bool_t resetStats = (c1 < 0);
398 Double_t s1[kNstat] = {0};
399 Double_t s2[kNstat] = {0};
400 if (!resetStats) {
401 // need to initialize to zero s1 and s2 since
402 // GetStats fills only used elements depending on dimension and type
403 GetStats(s1);
404 h1->GetStats(s2);
405 }
406 // get number of entries now because afterwards UpdateBinContent will change it
407 Double_t entries = TMath::Abs( GetEntries() + c1 * h1->GetEntries() );
408
409
410 // Perform the Add.
411 Double_t factor = 1;
412 if (h1p->GetNormFactor() != 0)
413 factor = h1p->GetNormFactor() / h1p->GetSumOfWeights();
414 for (bin = 0; bin < fNcells; bin++) {
415 Double_t y = this->RetrieveBinContent(bin) + c1 * h1p->RetrieveBinContent(bin);
416 UpdateBinContent(bin, y);
417 if (fSumw2.fN) {
418 Double_t esq = factor * factor * h1p->GetBinErrorSqUnchecked(bin);
419 fSumw2.fArray[bin] += c1 * c1 * factor * factor * esq;
420 }
421 }
422
423 // update statistics (do here to avoid changes by SetBinContent)
424 if (resetStats) {
425 // statistics need to be reset in case coefficient are negative
426 ResetStats();
427 } else {
428 for (Int_t i = 0; i < kNstat; i++) {
429 if (i == 1) s1[i] += c1 * c1 * s2[i];
430 else s1[i] += c1 * s2[i];
431 }
432 PutStats(s1);
433 SetEntries(entries);
434 }
435 return kTRUE;
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// Adds the input bin into the partition cell matrix. This method is called
440/// in AddBin() and ChangePartition().
441
443{
444 // Cell Info
445 Int_t nl, nr, mb, mt; // Max/min indices of the cells that contain the bin
446 Double_t xclipl, xclipr, yclipb, yclipt; // x and y coordinates of a cell
447 Double_t binXmax, binXmin, binYmax, binYmin; // The max/min bin coordinates
448
449 binXmax = bin->GetXMax();
450 binXmin = bin->GetXMin();
451 binYmax = bin->GetYMax();
452 binYmin = bin->GetYMin();
453 nl = (Int_t)(floor((binXmin - fXaxis.GetXmin())/fStepX));
454 nr = (Int_t)(floor((binXmax - fXaxis.GetXmin())/fStepX));
455 mb = (Int_t)(floor((binYmin - fYaxis.GetXmin())/fStepY));
456 mt = (Int_t)(floor((binYmax - fYaxis.GetXmin())/fStepY));
457
458 // Make sure the array indices are correct.
459 if (nr>=fCellX) nr = fCellX-1;
460 if (mt>=fCellY) mt = fCellY-1;
461 if (nl<0) nl = 0;
462 if (mb<0) mb = 0;
463
464 // number of cells in the grid
465 //N.B. not to be confused with fNcells (the number of bins) !
467
468 // Loop over all cells
469 for (int i = nl; i <= nr; i++) {
470 xclipl = fXaxis.GetXmin() + i*fStepX;
471 xclipr = xclipl + fStepX;
472 for (int j = mb; j <= mt; j++) {
473 yclipb = fYaxis.GetXmin() + j*fStepY;
474 yclipt = yclipb + fStepY;
475
476 // If the bin is completely inside the cell,
477 // add that bin to the cell then return
478 if ((binXmin >= xclipl) && (binXmax <= xclipr) &&
479 (binYmax <= yclipt) && (binYmin >= yclipb)){
480 fCells[i + j*fCellX].Add((TObject*) bin);
481 fIsEmpty[i + j*fCellX] = kFALSE; // Makes the cell non-empty
482 return;
483 }
484
485 // If any of the sides of the cell intersect with any side of the bin,
486 // add that bin then continue
487 if (IsIntersecting(bin, xclipl, xclipr, yclipb, yclipt)) {
488 fCells[i + j*fCellX].Add((TObject*) bin);
489 fIsEmpty[i + j*fCellX] = kFALSE; // Makes the cell non-empty
490 continue;
491 }
492 // If a corner of the cell is inside the bin and since there is no
493 // intersection, then that cell completely inside the bin.
494 if((bin->IsInside(xclipl,yclipb)) || (bin->IsInside(xclipl,yclipt))){
495 fCells[i + j*fCellX].Add((TObject*) bin);
496 fIsEmpty[i + j*fCellX] = kFALSE; // Makes the cell non-empty
498 continue;
499 }
500 if((bin->IsInside(xclipr,yclipb)) || (bin->IsInside(xclipr,yclipt))){
501 fCells[i + j*fCellX].Add((TObject*) bin);
502 fIsEmpty[i + j*fCellX] = kFALSE; // Makes the cell non-empty
504 continue;
505 }
506 }
507 }
508}
509
510////////////////////////////////////////////////////////////////////////////////
511/// Changes the number of partition cells in the histogram.
512/// Deletes the old partition and constructs a new one.
513
515{
516 fCellX = n; // Set the number of cells
517 fCellY = m; // Set the number of cells
518
519 delete [] fCells; // Deletes the old partition
520
521 // number of cells in the grid
522 //N.B. not to be confused with fNcells (the number of bins) !
524 fCells = new TList [fNCells]; // Sets an empty partition
525
528
529 delete [] fIsEmpty;
530 delete [] fCompletelyInside;
531 fIsEmpty = new Bool_t [fNCells];
533
534 // Initializes the flags
535 for (int i = 0; i<fNCells; i++) {
536 fIsEmpty[i] = kTRUE;
538 }
539
540 // TList iterator
541 TIter next(fBins);
542 TObject *obj;
543
544 while((obj = next())){ // Loop over bins and add them to the partition
546 }
547}
548
549////////////////////////////////////////////////////////////////////////////////
550/// Make a complete copy of the underlying object. If 'newname' is set,
551/// the copy's name will be set to that name.
552
553TObject* TH2Poly::Clone(const char* newname) const
554{
555 // TH1::Clone relies on ::Copy to implemented by the derived class.
556 // Until this is implemented, revert to the much slower default version
557 // (and possibly non-thread safe).
558
559 return TNamed::Clone(newname);
560}
561
562////////////////////////////////////////////////////////////////////////////////
563/// Clears the contents of all bins in the histogram.
564
566{
567 TIter next(fBins);
568 TObject *obj;
569 TH2PolyBin *bin;
570
571 // Clears the bin contents
572 while ((obj = next())) {
573 bin = (TH2PolyBin*) obj;
574 bin->ClearContent();
575 }
576
577 // Clears the statistics
578 fTsumw = 0;
579 fTsumw2 = 0;
580 fTsumwx = 0;
581 fTsumwx2 = 0;
582 fTsumwy = 0;
583 fTsumwy2 = 0;
584 fEntries = 0;
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// Reset this histogram: contents, errors, etc.
589
591{
592 TIter next(fBins);
593 TObject *obj;
594 TH2PolyBin *bin;
595
596 // Clears the bin contents
597 while ((obj = next())) {
598 bin = (TH2PolyBin*) obj;
599 bin->ClearContent();
600 }
601
602 TH2::Reset(opt);
603}
604
605////////////////////////////////////////////////////////////////////////////////
606/// Returns the bin number of the bin at the given coordinate. -1 to -9 are
607/// the overflow and underflow bins. overflow bin -5 is the unbinned areas in
608/// the histogram (also called "the sea"). The third parameter can be left
609/// blank.
610/// The overflow/underflow bins are:
611///~~~ {.cpp}
612/// -1 | -2 | -3
613/// -------------
614/// -4 | -5 | -6
615/// -------------
616/// -7 | -8 | -9
617///~~~
618/// where -5 means is the "sea" bin (i.e. unbinned areas)
619
621{
622
623 // Checks for overflow/underflow
624 Int_t overflow = 0;
625 if (y > fYaxis.GetXmax()) overflow += -1;
626 else if (y > fYaxis.GetXmin()) overflow += -4;
627 else overflow += -7;
628 if (x > fXaxis.GetXmax()) overflow += -2;
629 else if (x > fXaxis.GetXmin()) overflow += -1;
630 if (overflow != -5) return overflow;
631
632 // Finds the cell (x,y) coordinates belong to
633 Int_t n = (Int_t)(floor((x-fXaxis.GetXmin())/fStepX));
634 Int_t m = (Int_t)(floor((y-fYaxis.GetXmin())/fStepY));
635
636 // Make sure the array indices are correct.
637 if (n>=fCellX) n = fCellX-1;
638 if (m>=fCellY) m = fCellY-1;
639 if (n<0) n = 0;
640 if (m<0) m = 0;
641
642 if (fIsEmpty[n+fCellX*m]) return -5;
643
644 TH2PolyBin *bin;
645
646 TIter next(&fCells[n+fCellX*m]);
647 TObject *obj;
648
649 // Search for the bin in the cell
650 while ((obj=next())) {
651 bin = (TH2PolyBin*)obj;
652 if (bin->IsInside(x,y)) return bin->GetBinNumber();
653 }
654
655 // If the search has not returned a bin, the point must be on "the sea"
656 return -5;
657}
658
659////////////////////////////////////////////////////////////////////////////////
660/// Increment the bin containing (x,y) by 1.
661/// Uses the partitioning algorithm.
662
664{
665 return Fill(x, y, 1.0);
666}
667
668////////////////////////////////////////////////////////////////////////////////
669/// Increment the bin containing (x,y) by w.
670/// Uses the partitioning algorithm.
671
673{
674 // see GetBinCOntent for definition of overflow bins
675 // in case of weighted events store weight square in fSumw2.fArray
676 // but with this indexing:
677 // fSumw2.fArray[0:kNOverflow-1] : sum of weight squares for the overflow bins
678 // fSumw2.fArray[kNOverflow:fNcells] : sum of weight squares for the standard bins
679 // where fNcells = kNOverflow + Number of bins. kNOverflow=9
680
681 if (fNcells <= kNOverflow) return 0;
682
683 // create sum of weight square array if weights are different than 1
684 if (!fSumw2.fN && w != 1.0 && !TestBit(TH1::kIsNotW) ) Sumw2();
685
686 Int_t overflow = 0;
687 if (y > fYaxis.GetXmax()) overflow += -1;
688 else if (y > fYaxis.GetXmin()) overflow += -4;
689 else overflow += -7;
690 if (x > fXaxis.GetXmax()) overflow += -2;
691 else if(x > fXaxis.GetXmin()) overflow += -1;
692 if (overflow != -5) {
693 fOverflow[-overflow - 1]+= w;
694 if (fSumw2.fN) fSumw2.fArray[-overflow - 1] += w*w;
695 return overflow;
696 }
697
698 // Finds the cell (x,y) coordinates belong to
699 Int_t n = (Int_t)(floor((x-fXaxis.GetXmin())/fStepX));
700 Int_t m = (Int_t)(floor((y-fYaxis.GetXmin())/fStepY));
701
702 // Make sure the array indices are correct.
703 if (n>=fCellX) n = fCellX-1;
704 if (m>=fCellY) m = fCellY-1;
705 if (n<0) n = 0;
706 if (m<0) m = 0;
707
708 if (fIsEmpty[n+fCellX*m]) {
709 fOverflow[4]+= w;
710 if (fSumw2.fN) fSumw2.fArray[4] += w*w;
711 return -5;
712 }
713
714 TH2PolyBin *bin;
715 Int_t bi;
716
717 TIter next(&fCells[n+fCellX*m]);
718 TObject *obj;
719
720 while ((obj=next())) {
721 bin = (TH2PolyBin*)obj;
722 // needs to account offset in array for overflow bins
723 bi = bin->GetBinNumber()-1+kNOverflow;
724 if (bin->IsInside(x,y)) {
725 bin->Fill(w);
726
727 // Statistics
728 fTsumw = fTsumw + w;
729 fTsumw2 = fTsumw2 + w*w;
730 fTsumwx = fTsumwx + w*x;
731 fTsumwx2 = fTsumwx2 + w*x*x;
732 fTsumwy = fTsumwy + w*y;
733 fTsumwy2 = fTsumwy2 + w*y*y;
734 if (fSumw2.fN) {
735 assert(bi < fSumw2.fN);
736 fSumw2.fArray[bi] += w*w;
737 }
738 fEntries++;
739
741
742 return bin->GetBinNumber();
743 }
744 }
745
746 fOverflow[4]+= w;
747 if (fSumw2.fN) fSumw2.fArray[4] += w*w;
748 return -5;
749}
750
751////////////////////////////////////////////////////////////////////////////////
752/// Increment the bin named "name" by w.
753
755{
756 TString sname(name);
757
758 TIter next(fBins);
759 TObject *obj;
760 TH2PolyBin *bin;
761
762 while ((obj = next())) {
763 bin = (TH2PolyBin*) obj;
764 if (!sname.CompareTo(bin->GetPolygon()->GetName())) {
765 bin->Fill(w);
766 fEntries++;
768 return bin->GetBinNumber();
769 }
770 }
771
772 return 0;
773}
774
775////////////////////////////////////////////////////////////////////////////////
776/// Fills a 2-D histogram with an array of values and weights.
777///
778/// \param [in] ntimes: number of entries in arrays x and w
779/// (array size must be ntimes*stride)
780/// \param [in] x: array of x values to be histogrammed
781/// \param [in] y: array of y values to be histogrammed
782/// \param [in] w: array of weights
783/// \param [in] stride: step size through arrays x, y and w
784
785void TH2Poly::FillN(Int_t ntimes, const Double_t* x, const Double_t* y,
786 const Double_t* w, Int_t stride)
787{
788 for (int i = 0; i < ntimes; i += stride) {
789 Fill(x[i], y[i], w[i]);
790 }
791}
792
793////////////////////////////////////////////////////////////////////////////////
794/// Returns the integral of bin contents.
795/// By default the integral is computed as the sum of bin contents.
796/// If option "width" or "area" is specified, the integral is the sum of
797/// the bin contents multiplied by the area of the bin.
798
800{
801 TString opt = option;
802 opt.ToLower();
803
804 Double_t w;
805 Double_t integral = 0.;
806
807 TIter next(fBins);
808 TObject *obj;
809 TH2PolyBin *bin;
810 if ((opt.Contains("width")) || (opt.Contains("area"))) {
811 while ((obj = next())) {
812 bin = (TH2PolyBin *)obj;
813 w = bin->GetArea();
814 integral += w * (bin->GetContent());
815 }
816 } else {
817 // need to recompute integral in case SetBinContent was called.
818 // fTsumw cannot be used since it is not updated in that case
819 while ((obj = next())) {
820 bin = (TH2PolyBin *)obj;
821 integral += (bin->GetContent());
822 }
823 }
824 return integral;
825}
826
827////////////////////////////////////////////////////////////////////////////////
828/// Returns the content of the input bin
829/// Bin numbers are from [1,nbins] and
830/// for the overflow/underflow/sea bins the range is [-9,-1]:
831///~~~ {.cpp}
832/// -1 | -2 | -3
833/// ---+----+----
834/// -4 | -5 | -6
835/// ---+----+----
836/// -7 | -8 | -9
837///~~~
838/// where -5 is the "sea" bin (i.e. unbinned areas)
839
841{
842 if (bin > GetNumberOfBins() || bin == 0 || bin < -kNOverflow) return 0;
843 if (bin<0) return fOverflow[-bin - 1];
844 return ((TH2PolyBin*) fBins->At(bin-1))->GetContent();
845}
846
847////////////////////////////////////////////////////////////////////////////////
848/// Returns the value of error associated to bin number bin.
849/// If the sum of squares of weights has been defined (via Sumw2),
850/// this function returns the sqrt(sum of w2).
851/// otherwise it returns the sqrt(contents) for this bin.
852/// Bins are in range [1:nbins] and for bin < 0 in range [-9:-1] it returns errors for overflow bins.
853/// See also TH2Poly::GetBinContent
854
856{
857 if (bin == 0 || bin > GetNumberOfBins() || bin < - kNOverflow) return 0;
858 if (fBuffer) ((TH1*)this)->BufferEmpty();
859 // in case of weighted events the sum of the weights are stored in a different way than
860 // a normal histogram
861 // fSumw2.fArray[0:kNOverflow-1] : sum of weight squares for the overflow bins (
862 // fSumw2.fArray[kNOverflow:fNcells] : sum of weight squares for the standard bins
863 // fNcells = kNOverflow (9) + Number of bins
864 if (fSumw2.fN) {
865 Int_t binIndex = (bin > 0) ? bin+kNOverflow-1 : -(bin+1);
866 Double_t err2 = fSumw2.fArray[binIndex];
867 return TMath::Sqrt(err2);
868 }
869 Double_t error2 = TMath::Abs(GetBinContent(bin));
870 return TMath::Sqrt(error2);
871}
872
873////////////////////////////////////////////////////////////////////////////////
874/// Return the number of bins :
875/// it should be the size of the bin list
877 Int_t nbins = fNcells-kNOverflow;
878 if (nbins != (fBins ? fBins->GetSize() : 0))
879 Fatal("GetNumberOfBins","Object has an invalid number of bins");
880 return nbins;
881}
882
883////////////////////////////////////////////////////////////////////////////////
884/// Set the bin Error.
885/// Re-implementation for TH2Poly given the different bin indexing in the
886/// stored squared error array.
887/// See also notes in TH1::SetBinError
888///
889/// Bins are in range [1:nbins] and for bin < 0 in the range [-9:-1] the errors is set for the overflow bins
890
891
893{
894 if (bin == 0 || bin > GetNumberOfBins() || bin < - kNOverflow) return;
895 if (!fSumw2.fN) Sumw2();
897 // see comment in GetBinError for special convention of bin index in fSumw2 array
898 Int_t binIndex = (bin > 0) ? bin+kNOverflow-1 : -(bin+1);
899 fSumw2.fArray[binIndex] = error * error;
900}
901
902
903
904////////////////////////////////////////////////////////////////////////////////
905/// Returns the bin name.
906
907const char *TH2Poly::GetBinName(Int_t bin) const
908{
909 if (bin > GetNumberOfBins()) return "";
910 if (bin <= 0) return "";
911 return ((TH2PolyBin*) fBins->At(bin-1))->GetPolygon()->GetName();
912}
913
914////////////////////////////////////////////////////////////////////////////////
915/// Returns the bin title.
916
917const char *TH2Poly::GetBinTitle(Int_t bin) const
918{
919 if (bin > GetNumberOfBins()) return "";
920 if (bin <= 0) return "";
921 return ((TH2PolyBin*) fBins->At(bin-1))->GetPolygon()->GetTitle();
922}
923
924////////////////////////////////////////////////////////////////////////////////
925/// Returns the maximum value of the histogram.
926
928{
929 if (fNcells <= kNOverflow) return 0;
930 if (fMaximum != -1111) return fMaximum;
931
932 TH2PolyBin *b;
933
934 TIter next(fBins);
935 TObject *obj;
936 Double_t max,c;
937
938 max = ((TH2PolyBin*) next())->GetContent();
939
940 while ((obj=next())) {
941 b = (TH2PolyBin*)obj;
942 c = b->GetContent();
943 if (c>max) max = c;
944 }
945 return max;
946}
947
948////////////////////////////////////////////////////////////////////////////////
949/// Returns the maximum value of the histogram that is less than maxval.
950
952{
953 if (fNcells <= kNOverflow) return 0;
954 if (fMaximum != -1111) return fMaximum;
955
956 TH2PolyBin *b;
957
958 TIter next(fBins);
959 TObject *obj;
960 Double_t max,c;
961
962 max = ((TH2PolyBin*) next())->GetContent();
963
964 while ((obj=next())) {
965 b = (TH2PolyBin*)obj;
966 c = b->GetContent();
967 if (c>max && c<maxval) max=c;
968 }
969 return max;
970}
971
972////////////////////////////////////////////////////////////////////////////////
973/// Returns the minimum value of the histogram.
974
976{
977 if (fNcells <= kNOverflow) return 0;
978 if (fMinimum != -1111) return fMinimum;
979
980 TH2PolyBin *b;
981
982 TIter next(fBins);
983 TObject *obj;
984 Double_t min,c;
985
986 min = ((TH2PolyBin*) next())->GetContent();
987
988 while ((obj=next())) {
989 b = (TH2PolyBin*)obj;
990 c = b->GetContent();
991 if (c<min) min=c;
992 }
993 return min;
994}
995
996////////////////////////////////////////////////////////////////////////////////
997/// Returns the minimum value of the histogram that is greater than minval.
998
1000{
1001 if (fNcells <= kNOverflow) return 0;
1002 if (fMinimum != -1111) return fMinimum;
1003
1004 TH2PolyBin *b;
1005
1006 TIter next(fBins);
1007 TObject *obj;
1008 Double_t min,c;
1009
1010 min = ((TH2PolyBin*) next())->GetContent();
1011
1012 while ((obj=next())) {
1013 b = (TH2PolyBin*)obj;
1014 c = b->GetContent();
1015 if (c<min && c>minval) min=c;
1016 }
1017 return min;
1018}
1019
1020////////////////////////////////////////////////////////////////////////////////
1021/// Bins the histogram using a honeycomb structure
1022/// If the option "v" is specified, the hexagons are drawn "vertically" (default).
1023/// If the option "h" is selected they are drawn "horizontally".
1024
1026{
1027 TString opt = option;
1028 opt.ToLower();
1029 Double_t numberOfHexagonsInTheRow;
1030 Double_t x[6], y[6];
1031 Double_t xloop = xstart, yloop, xtemp, ytemp;
1032
1033 // Add the bins
1034 if (opt.Contains("v")) {
1035 yloop = ystart + a / 2.0;
1036 for (int sCounter = 0; sCounter < s; sCounter++) {
1037 xtemp = xloop;
1038 // Determine the number of hexagons in that row
1039 if (sCounter%2 == 0)
1040 numberOfHexagonsInTheRow = k;
1041 else
1042 numberOfHexagonsInTheRow = k - 1;
1043
1044 for (int kCounter = 0; kCounter < numberOfHexagonsInTheRow; kCounter++) {
1045 // Go around the hexagon
1046 x[0] = xtemp;
1047 y[0] = yloop;
1048 x[1] = x[0];
1049 y[1] = y[0] + a;
1050 x[2] = x[1] + a * TMath::Sqrt(3) / 2.0;
1051 y[2] = y[1] + a / 2.0;
1052 x[3] = x[2] + a * TMath::Sqrt(3) / 2.0;
1053 y[3] = y[1];
1054 x[4] = x[3];
1055 y[4] = y[0];
1056 x[5] = x[2];
1057 y[5] = y[4] - a/2.0;
1058 this->AddBin(6, x, y);
1059 // Go right
1060 xtemp += a * TMath::Sqrt(3);
1061 }
1062 // Increment the starting position
1063 if (sCounter%2 == 0)
1064 xloop += a * TMath::Sqrt(3) / 2.0;
1065 else
1066 xloop -= a * TMath::Sqrt(3) / 2.0;
1067 yloop += 1.5 * a;
1068 }
1069 } else if (opt.Contains("h")) {
1070 yloop = ystart + a*TMath::Sqrt(3)/2.0;
1071 for (int sCounter = 0; sCounter < s; sCounter++) {
1072 ytemp = yloop;
1073 // Determine the number of hexagons in that row
1074 if (sCounter%2 == 0)
1075 numberOfHexagonsInTheRow = k;
1076 else
1077 numberOfHexagonsInTheRow = k - 1;
1078 for (int kCounter = 0; kCounter < numberOfHexagonsInTheRow; kCounter++) {
1079 // Go around the hexagon
1080 x[0] = xloop;
1081 y[0] = ytemp;
1082 x[1] = x[0] + a/2.0;
1083 y[1] = y[0] + a * TMath::Sqrt(3) / 2.0;
1084 x[2] = x[1] + a;
1085 y[2] = y[1];
1086 x[3] = x[2] + a/2.0;
1087 y[3] = y[0];
1088 x[4] = x[2];
1089 y[4] = y[3] - a * TMath::Sqrt(3) / 2.0;
1090 x[5] = x[1];
1091 y[5] = y[4];
1092 this->AddBin(6, x, y);
1093 // Go up
1094 ytemp += a * TMath::Sqrt(3);
1095 }
1096 // Increment the starting position
1097 if (sCounter%2 == 0)
1098 yloop += a * TMath::Sqrt(3) / 2.0;
1099 else
1100 yloop -= a * TMath::Sqrt(3) / 2.0;
1101 xloop += 1.5 * a;
1102 }
1103 } else {
1104 Error("Honeycomb", "Unknown option");
1105 }
1106
1107}
1108
1109////////////////////////////////////////////////////////////////////////////////
1110/// Initializes the TH2Poly object. This method is called by the constructor.
1111
1113 Double_t ylow, Double_t yup, Int_t n, Int_t m)
1114{
1115 Int_t i;
1116 fDimension = 2; //The dimension of the histogram
1117
1118 fBins = nullptr;
1120
1121 // Sets the boundaries of the histogram
1122 fXaxis.Set(100, xlow, xup);
1123 fYaxis.Set(100, ylow, yup);
1124
1125 for (i=0; i<9; i++) fOverflow[i] = 0.;
1126
1127 // Statistics
1128 fEntries = 0; // The total number of entries
1129 fTsumw = 0.; // Total amount of content in the histogram
1130 fTsumw2 = 0.; // Sum square of the weights
1131 fTsumwx = 0.; // Weighted sum of x coordinates
1132 fTsumwx2 = 0.; // Weighted sum of the squares of x coordinates
1133 fTsumwy2 = 0.; // Weighted sum of the squares of y coordinates
1134 fTsumwy = 0.; // Weighted sum of y coordinates
1135
1136 fCellX = n; // Set the number of cells to default
1137 fCellY = m; // Set the number of cells to default
1138
1139 // number of cells in the grid
1140 //N.B. not to be confused with fNcells (the number of bins) !
1142 fCells = new TList [fNCells]; // Sets an empty partition
1143 fStepX = (fXaxis.GetXmax() - fXaxis.GetXmin())/fCellX; // Cell width
1144 fStepY = (fYaxis.GetXmax() - fYaxis.GetXmin())/fCellY; // Cell height
1145
1146 fIsEmpty = new Bool_t [fNCells]; // Empty partition
1147 fCompletelyInside = new Bool_t [fNCells]; // Cell is completely inside bin
1148
1149 for (i = 0; i<fNCells; i++) { // Initializes the flags
1150 fIsEmpty[i] = kTRUE;
1152 }
1153
1154 // 3D Painter flags
1157}
1158
1159////////////////////////////////////////////////////////////////////////////////
1160/// Returns kTRUE if the input bin is intersecting with the
1161/// input rectangle (xclipl, xclipr, yclipb, yclipt)
1162
1164 Double_t xclipl, Double_t xclipr,
1165 Double_t yclipb, Double_t yclipt)
1166{
1167 Int_t gn;
1168 Double_t *gx;
1169 Double_t *gy;
1170 Bool_t inter = kFALSE;
1171 TObject *poly = bin->GetPolygon();
1172
1173 if (poly->IsA() == TGraph::Class()) {
1174 TGraph *g = (TGraph*)poly;
1175 gx = g->GetX();
1176 gy = g->GetY();
1177 gn = g->GetN();
1178 inter = IsIntersectingPolygon(gn, gx, gy, xclipl, xclipr, yclipb, yclipt);
1179 }
1180
1181 if (poly->IsA() == TMultiGraph::Class()) {
1182 TMultiGraph *mg = (TMultiGraph*)poly;
1183 TList *gl = mg->GetListOfGraphs();
1184 if (!gl) return inter;
1185 TGraph *g;
1186 TIter next(gl);
1187 while ((g = (TGraph*) next())) {
1188 gx = g->GetX();
1189 gy = g->GetY();
1190 gn = g->GetN();
1191 inter = IsIntersectingPolygon(gn, gx, gy, xclipl, xclipr,
1192 yclipb, yclipt);
1193 if (inter) return inter;
1194 }
1195 }
1196
1197 return inter;
1198}
1199
1200////////////////////////////////////////////////////////////////////////////////
1201/// Returns kTRUE if the input polygon (bn, x, y) is intersecting with the
1202/// input rectangle (xclipl, xclipr, yclipb, yclipt)
1203
1205 Double_t xclipl, Double_t xclipr,
1206 Double_t yclipb, Double_t yclipt)
1207{
1208 Bool_t p0R, p0L, p0T, p0B, p0xM, p0yM, p1R, p1L, p1T;
1209 Bool_t p1B, p1xM, p1yM, p0In, p1In;
1210
1211 for (int counter = 0; counter < (bn-1); counter++) {
1212 // If both are on the same side, return kFALSE
1213 p0L = x[counter] <= xclipl; // Point 0 is on the left
1214 p1L = x[counter + 1] <= xclipl; // Point 1 is on the left
1215 if (p0L && p1L) continue;
1216 p0R = x[counter] >= xclipr; // Point 0 is on the right
1217 p1R = x[counter + 1] >= xclipr; // Point 1 is on the right
1218 if (p0R && p1R) continue;
1219 p0T = y[counter] >= yclipt; // Point 0 is at the top
1220 p1T = y[counter + 1] >= yclipt; // Point 1 is at the top
1221 if (p0T && p1T) continue;
1222 p0B = y[counter] <= yclipb; // Point 0 is at the bottom
1223 p1B = y[counter + 1] <= yclipb; // Point 1 is at the bottom
1224 if (p0B && p1B) continue;
1225
1226 // Checks to see if any are inside
1227 p0xM = !p0R && !p0L; // Point 0 is inside along x
1228 p0yM = !p0T && !p0B; // Point 1 is inside along x
1229 p1xM = !p1R && !p1L; // Point 0 is inside along y
1230 p1yM = !p1T && !p1B; // Point 1 is inside along y
1231 p0In = p0xM && p0yM; // Point 0 is inside
1232 p1In = p1xM && p1yM; // Point 1 is inside
1233 if (p0In) {
1234 if (p1In) continue;
1235 return kTRUE;
1236 } else {
1237 if (p1In) return kTRUE;
1238 }
1239
1240 // We know by now that the points are not in the same side and not inside.
1241
1242 // Checks to see if they are opposite
1243
1244 if (p0xM && p1xM) return kTRUE;
1245 if (p0yM && p1yM) return kTRUE;
1246
1247 // We now know that the points are in different x and y indices
1248
1249 Double_t xcoord[3], ycoord[3];
1250 xcoord[0] = x[counter];
1251 xcoord[1] = x[counter + 1];
1252 ycoord[0] = y[counter];
1253 ycoord[1] = y[counter + 1];
1254
1255 if (p0L) {
1256 if(p1T){
1257 xcoord[2] = xclipl;
1258 ycoord[2] = yclipb;
1259 if((TMath::IsInside(xclipl, yclipt, 3, xcoord, ycoord)) ||
1260 (TMath::IsInside(xclipr, yclipb, 3, xcoord, ycoord))) continue;
1261 else return kTRUE;
1262 } else if (p1B) {
1263 xcoord[2] = xclipl;
1264 ycoord[2] = yclipt;
1265 if((TMath::IsInside(xclipl, yclipb, 3, xcoord, ycoord)) ||
1266 (TMath::IsInside(xclipr, yclipt, 3, xcoord, ycoord))) continue;
1267 else return kTRUE;
1268 } else { // p1yM
1269 if (p0T) {
1270 xcoord[2] = xclipl;
1271 ycoord[2] = yclipb;
1272 if (TMath::IsInside(xclipr, yclipt, 3, xcoord, ycoord)) continue;
1273 else return kTRUE;
1274 }
1275 if (p0B) {
1276 xcoord[2] = xclipl;
1277 ycoord[2] = yclipt;
1278 if (TMath::IsInside(xclipr, yclipb, 3, xcoord, ycoord)) continue;
1279 else return kTRUE;
1280 }
1281 }
1282 } else if (p0R) {
1283 if (p1T) {
1284 xcoord[2] = xclipl;
1285 ycoord[2] = yclipb;
1286 if ((TMath::IsInside(xclipr, yclipb, 3, xcoord, ycoord)) ||
1287 (TMath::IsInside(xclipl, yclipt, 3, xcoord, ycoord))) continue;
1288 else return kTRUE;
1289 } else if (p1B) {
1290 xcoord[2] = xclipl;
1291 ycoord[2] = yclipt;
1292 if ((TMath::IsInside(xclipl, yclipb, 3, xcoord, ycoord)) ||
1293 (TMath::IsInside(xclipr, yclipt, 3, xcoord, ycoord))) continue;
1294 else return kTRUE;
1295 } else{ // p1yM
1296 if (p0T) {
1297 xcoord[2] = xclipr;
1298 ycoord[2] = yclipb;
1299 if (TMath::IsInside(xclipl, yclipt, 3, xcoord, ycoord)) continue;
1300 else return kTRUE;
1301 }
1302 if (p0B) {
1303 xcoord[2] = xclipr;
1304 ycoord[2] = yclipt;
1305 if (TMath::IsInside(xclipl, yclipb, 3, xcoord, ycoord)) continue;
1306 else return kTRUE;
1307 }
1308 }
1309 }
1310 }
1311 return kFALSE;
1312}
1313
1314////////////////////////////////////////////////////////////////////////////////
1315/// Merge TH2Polys
1316/// Given the special nature of the TH2Poly, the merge is implemented in
1317/// terms of subsequent TH2Poly::Add calls.
1319{
1320 for (auto h2pAsObj : *coll) {
1321 if (!Add((TH1*)h2pAsObj, 1.)) {
1322 Warning("Merge", "An issue was encountered during the merge operation.");
1323 return 0L;
1324 }
1325 }
1326 return GetEntries();
1327}
1328
1329////////////////////////////////////////////////////////////////////////////////
1330/// Save primitive as a C++ statement(s) on output stream out
1331
1332void TH2Poly::SavePrimitive(std::ostream &out, Option_t *option)
1333{
1334 out <<" "<<std::endl;
1335 out <<" "<< ClassName() <<" *";
1336
1337 //histogram pointer has by default the histogram name.
1338 //however, in case histogram has no directory, it is safer to add a
1339 //incremental suffix
1340 static Int_t hcounter = 0;
1341 TString histName = GetName();
1342 if (!fDirectory && !histName.Contains("Graph")) {
1343 hcounter++;
1344 histName += "__";
1345 histName += hcounter;
1346 }
1347 const char *hname = histName.Data();
1348
1349 //Construct the class initialization
1350 out << hname << " = new " << ClassName() << "(\"" << hname << "\", \""
1351 << GetTitle() << "\", " << fCellX << ", " << fXaxis.GetXmin()
1352 << ", " << fXaxis.GetXmax()
1353 << ", " << fCellY << ", " << fYaxis.GetXmin() << ", "
1354 << fYaxis.GetXmax() << ");" << std::endl;
1355
1356 // Save Bins
1357 TIter next(fBins);
1358 TObject *obj;
1359 TH2PolyBin *th2pBin;
1360
1361 while((obj = next())){
1362 th2pBin = (TH2PolyBin*) obj;
1363 th2pBin->GetPolygon()->SavePrimitive(out,
1364 TString::Format("th2poly%s",histName.Data()));
1365 }
1366
1367 // save bin contents
1368 out<<" "<<std::endl;
1369 Int_t bin;
1370 for (bin=1;bin<=GetNumberOfBins();bin++) {
1371 Double_t bc = GetBinContent(bin);
1372 if (bc) {
1373 out<<" "<<hname<<"->SetBinContent("<<bin<<","<<bc<<");"<<std::endl;
1374 }
1375 }
1376
1377 // save bin errors
1378 if (fSumw2.fN) {
1379 for (bin=1;bin<=GetNumberOfBins();bin++) {
1380 Double_t be = GetBinError(bin);
1381 if (be) {
1382 out<<" "<<hname<<"->SetBinError("<<bin<<","<<be<<");"<<std::endl;
1383 }
1384 }
1385 }
1386 TH1::SavePrimitiveHelp(out, hname, option);
1387}
1388
1389////////////////////////////////////////////////////////////////////////////////
1390/// Multiply this histogram by a constant c1.
1391
1393{
1394 for( int i = 0; i < this->GetNumberOfBins(); i++ ) {
1395 this->SetBinContent(i+1, c1*this->GetBinContent(i+1));
1396 }
1397 for( int i = 0; i < kNOverflow; i++ ) {
1398 this->SetBinContent(-i-1, c1*this->GetBinContent(-i-1) );
1399 }
1400}
1401
1402////////////////////////////////////////////////////////////////////////////////
1403/// Sets the contents of the input bin to the input content
1404/// Negative values between -1 and -9 are for the overflows and the sea
1405
1407{
1408 if (bin > GetNumberOfBins() || bin == 0 || bin < -9 ) return;
1409 if (bin > 0) {
1410 ((TH2PolyBin*) fBins->At(bin-1))->SetContent(content);
1411 }
1412 else
1413 fOverflow[-bin - 1] = content;
1414
1416 fEntries++;
1417}
1418
1419////////////////////////////////////////////////////////////////////////////////
1420/// When set to kTRUE, allows the histogram to expand if a bin outside the
1421/// limits is added.
1422
1424{
1425 fFloat = flag;
1426}
1427
1428////////////////////////////////////////////////////////////////////////////////
1429/// Return "true" if the point (x,y) is inside the bin of binnr.
1430
1432{
1433 if (!fBins) return false;
1434 TH2PolyBin* bin = (TH2PolyBin*)fBins->At(binnr);
1435 if (!bin) return false;
1436 return bin->IsInside(x,y);
1437}
1438
1439void TH2Poly::GetStats(Double_t *stats) const
1440{
1441 stats[0] = fTsumw;
1442 stats[1] = fTsumw2;
1443 stats[2] = fTsumwx;
1444 stats[3] = fTsumwx2;
1445 stats[4] = fTsumwy;
1446 stats[5] = fTsumwy2;
1447 stats[6] = fTsumwxy;
1448}
1449
1450/** \class TH2PolyBin
1451 \ingroup Histograms
1452Helper class to represent a bin in the TH2Poly histogram
1453*/
1454
1455////////////////////////////////////////////////////////////////////////////////
1456/// Default constructor.
1457
1459{
1460 fPoly = nullptr;
1461 fContent = 0.;
1462 fNumber = 0;
1463 fXmax = -1111;
1464 fXmin = -1111;
1465 fYmax = -1111;
1466 fYmin = -1111;
1467 fArea = 0;
1469}
1470
1471////////////////////////////////////////////////////////////////////////////////
1472/// Normal constructor.
1473
1475{
1476 fContent = 0.;
1477 fNumber = bin_number;
1478 fArea = 0.;
1479 fPoly = poly;
1480 fXmax = -1111;
1481 fXmin = -1111;
1482 fYmax = -1111;
1483 fYmin = -1111;
1485}
1486
1487////////////////////////////////////////////////////////////////////////////////
1488/// Destructor.
1489
1491{
1492 if (fPoly) delete fPoly;
1493}
1494
1495////////////////////////////////////////////////////////////////////////////////
1496/// Returns the area of the bin.
1497
1499{
1500 Int_t bn;
1501
1502 if (fArea == 0) {
1503 if (fPoly->IsA() == TGraph::Class()) {
1504 TGraph *g = (TGraph*)fPoly;
1505 bn = g->GetN();
1506 fArea = g->Integral(0,bn-1);
1507 }
1508
1509 if (fPoly->IsA() == TMultiGraph::Class()) {
1511 TList *gl = mg->GetListOfGraphs();
1512 if (!gl) return fArea;
1513 TGraph *g;
1514 TIter next(gl);
1515 while ((g = (TGraph*) next())) {
1516 bn = g->GetN();
1517 fArea = fArea + g->Integral(0,bn-1);
1518 }
1519 }
1520 }
1521
1522 return fArea;
1523}
1524
1525////////////////////////////////////////////////////////////////////////////////
1526/// Returns the maximum value for the x coordinates of the bin.
1527
1529{
1530 if (fXmax != -1111) return fXmax;
1531
1532 Int_t bn,i;
1533 Double_t *bx;
1534
1535 if (fPoly->IsA() == TGraph::Class()) {
1536 TGraph *g = (TGraph*)fPoly;
1537 bx = g->GetX();
1538 bn = g->GetN();
1539 fXmax = bx[0];
1540 for (i=1; i<bn; i++) {if (fXmax < bx[i]) fXmax = bx[i];}
1541 }
1542
1543 if (fPoly->IsA() == TMultiGraph::Class()) {
1545 TList *gl = mg->GetListOfGraphs();
1546 if (!gl) return fXmax;
1547 TGraph *g;
1548 TIter next(gl);
1549 Bool_t first = kTRUE;
1550 while ((g = (TGraph*) next())) {
1551 bx = g->GetX();
1552 bn = g->GetN();
1553 if (first) {fXmax = bx[0]; first = kFALSE;}
1554 for (i=0; i<bn; i++) {if (fXmax < bx[i]) fXmax = bx[i];}
1555 }
1556 }
1557
1558 return fXmax;
1559}
1560
1561////////////////////////////////////////////////////////////////////////////////
1562/// Returns the minimum value for the x coordinates of the bin.
1563
1565{
1566 if (fXmin != -1111) return fXmin;
1567
1568 Int_t bn,i;
1569 Double_t *bx;
1570
1571 if (fPoly->IsA() == TGraph::Class()) {
1572 TGraph *g = (TGraph*)fPoly;
1573 bx = g->GetX();
1574 bn = g->GetN();
1575 fXmin = bx[0];
1576 for (i=1; i<bn; i++) {if (fXmin > bx[i]) fXmin = bx[i];}
1577 }
1578
1579 if (fPoly->IsA() == TMultiGraph::Class()) {
1581 TList *gl = mg->GetListOfGraphs();
1582 if (!gl) return fXmin;
1583 TGraph *g;
1584 TIter next(gl);
1585 Bool_t first = kTRUE;
1586 while ((g = (TGraph*) next())) {
1587 bx = g->GetX();
1588 bn = g->GetN();
1589 if (first) {fXmin = bx[0]; first = kFALSE;}
1590 for (i=0; i<bn; i++) {if (fXmin > bx[i]) fXmin = bx[i];}
1591 }
1592 }
1593
1594 return fXmin;
1595}
1596
1597////////////////////////////////////////////////////////////////////////////////
1598/// Returns the maximum value for the y coordinates of the bin.
1599
1601{
1602 if (fYmax != -1111) return fYmax;
1603
1604 Int_t bn,i;
1605 Double_t *by;
1606
1607 if (fPoly->IsA() == TGraph::Class()) {
1608 TGraph *g = (TGraph*)fPoly;
1609 by = g->GetY();
1610 bn = g->GetN();
1611 fYmax = by[0];
1612 for (i=1; i<bn; i++) {if (fYmax < by[i]) fYmax = by[i];}
1613 }
1614
1615 if (fPoly->IsA() == TMultiGraph::Class()) {
1617 TList *gl = mg->GetListOfGraphs();
1618 if (!gl) return fYmax;
1619 TGraph *g;
1620 TIter next(gl);
1621 Bool_t first = kTRUE;
1622 while ((g = (TGraph*) next())) {
1623 by = g->GetY();
1624 bn = g->GetN();
1625 if (first) {fYmax = by[0]; first = kFALSE;}
1626 for (i=0; i<bn; i++) {if (fYmax < by[i]) fYmax = by[i];}
1627 }
1628 }
1629
1630 return fYmax;
1631}
1632
1633////////////////////////////////////////////////////////////////////////////////
1634/// Returns the minimum value for the y coordinates of the bin.
1635
1637{
1638 if (fYmin != -1111) return fYmin;
1639
1640 Int_t bn,i;
1641 Double_t *by;
1642
1643 if (fPoly->IsA() == TGraph::Class()) {
1644 TGraph *g = (TGraph*)fPoly;
1645 by = g->GetY();
1646 bn = g->GetN();
1647 fYmin = by[0];
1648 for (i=1; i<bn; i++) {if (fYmin > by[i]) fYmin = by[i];}
1649 }
1650
1651 if (fPoly->IsA() == TMultiGraph::Class()) {
1653 TList *gl = mg->GetListOfGraphs();
1654 if (!gl) return fYmin;
1655 TGraph *g;
1656 TIter next(gl);
1657 Bool_t first = kTRUE;
1658 while ((g = (TGraph*) next())) {
1659 by = g->GetY();
1660 bn = g->GetN();
1661 if (first) {fYmin = by[0]; first = kFALSE;}
1662 for (i=0; i<bn; i++) {if (fYmin > by[i]) fYmin = by[i];}
1663 }
1664 }
1665
1666 return fYmin;
1667}
1668
1669////////////////////////////////////////////////////////////////////////////////
1670/// Return "true" if the point (x,y) is inside the bin.
1671
1673{
1674 Int_t in=0;
1675
1676 if (fPoly->IsA() == TGraph::Class()) {
1677 TGraph *g = (TGraph*)fPoly;
1678 in = g->IsInside(x, y);
1679 }
1680
1681 if (fPoly->IsA() == TMultiGraph::Class()) {
1683 in = mg->IsInside(x, y);
1684 }
1685
1686 return in;
1687}
1688
1689////////////////////////////////////////////////////////////////////////////////
1690// RE-implement dummy functions to avoid users calling the
1691// corresponding implementations in TH1 or TH2
1692////////////////////////////////////////////////////////////////////////////////
1693
1694////////////////////////////////////////////////////////////////////////////////
1695/// NOT IMPLEMENTED for TH2Poly
1697{
1698 Error("Add", "Not implemented for TH2Poly");
1699 return kFALSE;
1700}
1701
1702////////////////////////////////////////////////////////////////////////////////
1703/// NOT IMPLEMENTED for TH2Poly
1705{
1706 Error("Add", "Not implemented for TH2Poly");
1707 return kFALSE;
1708}
1709
1710////////////////////////////////////////////////////////////////////////////////
1711/// NOT IMPLEMENTED for TH2Poly
1713{
1714 Error("Divide", "Not implemented for TH2Poly");
1715 return kFALSE;
1716}
1717
1718////////////////////////////////////////////////////////////////////////////////
1719/// NOT IMPLEMENTED for TH2Poly
1721{
1722 Error("Multiply", "Not implemented for TH2Poly");
1723 return kFALSE;
1724}
1725////////////////////////////////////////////////////////////////////////////////
1726/// NOT IMPLEMENTED for TH2Poly
1728{
1729 Error("ComputeIntegral", "Not implemented for TH2Poly");
1730 return TMath::QuietNaN();
1731}
1732////////////////////////////////////////////////////////////////////////////////
1733/// NOT IMPLEMENTED for TH2Poly
1735{
1736 Error("FFT", "Not implemented for TH2Poly");
1737 return nullptr;
1738}
1739////////////////////////////////////////////////////////////////////////////////
1740/// NOT IMPLEMENTED for TH2Poly
1742{
1743 Error("GetAsymmetry", "Not implemented for TH2Poly");
1744 return nullptr;
1745}
1746////////////////////////////////////////////////////////////////////////////////
1747/// NOT IMPLEMENTED for TH2Poly
1749{
1750 Error("Interpolate", "Not implemented for TH2Poly");
1751 return TMath::QuietNaN();
1752}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define a(i)
Definition RSha256.hxx:99
#define s1(x)
Definition RSha256.hxx:91
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
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
@ kCounter
Definition TDataType.h:34
Option_t Option_t option
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:110
Double_t * fArray
Definition TArrayD.h:30
void Set(Int_t n) override
Set size of this array to n doubles.
Definition TArrayD.cxx:106
Int_t fN
Definition TArray.h:38
Double_t GetXmax() const
Definition TAxis.h:140
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition TAxis.cxx:794
Double_t GetXmin() const
Definition TAxis.h:139
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.
TObject * Clone(const char *newname="") const override
Make a clone of an collection using the Streamer facility.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
1-Dim function class
Definition TF1.h:233
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
static TClass * Class()
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
Double_t * fBuffer
[fBufferSize] entry buffer
Definition TH1.h:108
Int_t fNcells
Number of bins(1D), cells (2D) +U/Overflows.
Definition TH1.h:89
virtual void GetStats(Double_t *stats) const
fill the array stats from the contents of this histogram The array stats must be correctly dimensione...
Definition TH1.cxx:7801
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6686
Double_t fTsumw
Total Sum of weights.
Definition TH1.h:96
Double_t fTsumw2
Total Sum of squares of weights.
Definition TH1.h:97
Double_t fTsumwx2
Total Sum of weight*X*X.
Definition TH1.h:99
virtual Double_t GetNormFactor() const
Definition TH1.h:301
@ kIsNotW
Histogram is forced to be not weighted even when the histogram is filled with weighted.
Definition TH1.h:172
TDirectory * fDirectory
! Pointer to directory holding this histogram
Definition TH1.h:109
Double_t fMaximum
Maximum value for plotting.
Definition TH1.h:100
Int_t fDimension
! Histogram dimension (1, 2 or 3 dim)
Definition TH1.h:110
virtual void SetContent(const Double_t *content)
Replace bin contents by the contents of array content.
Definition TH1.cxx:8366
virtual void SavePrimitiveHelp(std::ostream &out, const char *hname, Option_t *option="")
Helper function for the SavePrimitive functions from TH1 or classes derived from TH1,...
Definition TH1.cxx:7347
virtual Double_t GetBinErrorSqUnchecked(Int_t bin) const
Definition TH1.h:448
Double_t fMinimum
Minimum value for plotting.
Definition TH1.h:101
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4423
void SetName(const char *name) override
Change the name of this histogram.
Definition TH1.cxx:8928
virtual void ResetStats()
Reset the statistics including the number of entries and replace with values calculated from bin cont...
Definition TH1.cxx:7870
virtual void SetBinErrorOption(EBinErrorOpt type)
Definition TH1.h:381
@ kNstat
Size of statistics data (up to TProfile3D)
Definition TH1.h:184
Double_t fEntries
Number of entries.
Definition TH1.h:95
@ kNormal
Errors with Normal (Wald) approximation: errorUp=errorLow= sqrt(N)
Definition TH1.h:65
TAxis fXaxis
X axis descriptor.
Definition TH1.h:90
TArrayD fSumw2
Array of sum of squares of weights.
Definition TH1.h:104
virtual Int_t GetSumw2N() const
Definition TH1.h:315
TAxis fYaxis
Y axis descriptor.
Definition TH1.h:91
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
Definition TH1.cxx:7885
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:8988
virtual void SetEntries(Double_t n)
Definition TH1.h:390
Double_t fTsumwx
Total Sum of weight*X.
Definition TH1.h:98
Helper class to represent a bin in the TH2Poly histogram.
Definition TH2Poly.h:25
Double_t GetXMin()
Returns the minimum value for the x coordinates of the bin.
Definition TH2Poly.cxx:1564
~TH2PolyBin() override
Destructor.
Definition TH2Poly.cxx:1490
Double_t GetYMax()
Returns the maximum value for the y coordinates of the bin.
Definition TH2Poly.cxx:1600
Double_t GetArea()
Returns the area of the bin.
Definition TH2Poly.cxx:1498
void ClearContent()
Definition TH2Poly.h:32
void Fill(Double_t w)
Definition TH2Poly.h:33
Double_t GetYMin()
Returns the minimum value for the y coordinates of the bin.
Definition TH2Poly.cxx:1636
Double_t fArea
Bin area.
Definition TH2Poly.h:51
Double_t fContent
Bin content.
Definition TH2Poly.h:52
Bool_t IsInside(Double_t x, Double_t y) const
Return "true" if the point (x,y) is inside the bin.
Definition TH2Poly.cxx:1672
Double_t fXmax
X maximum value.
Definition TH2Poly.h:55
Int_t fNumber
Bin number of the bin in TH2Poly.
Definition TH2Poly.h:49
TH2PolyBin()
Default constructor.
Definition TH2Poly.cxx:1458
Double_t fYmax
Y maximum value.
Definition TH2Poly.h:56
Double_t GetXMax()
Returns the maximum value for the x coordinates of the bin.
Definition TH2Poly.cxx:1528
Double_t GetContent() const
Definition TH2Poly.h:35
Double_t fYmin
Y minimum value.
Definition TH2Poly.h:54
void SetChanged(Bool_t flag)
Definition TH2Poly.h:44
Int_t GetBinNumber() const
Definition TH2Poly.h:37
Double_t fXmin
X minimum value.
Definition TH2Poly.h:53
TObject * GetPolygon() const
Definition TH2Poly.h:38
TObject * fPoly
Object holding the polygon definition.
Definition TH2Poly.h:50
2D Histogram with Polygonal Bins
Definition TH2Poly.h:66
Bool_t Multiply(TF1 *, Double_t) override
NOT IMPLEMENTED for TH2Poly.
Definition TH2Poly.cxx:1720
void UpdateBinContent(Int_t bin, Double_t content) override
Raw update of bin content on internal data structure see convention for numbering bins in TH1::GetBin...
Definition TH2Poly.h:180
TH2Poly & operator=(const TH2Poly &rhs)
Assignment operator.
Definition TH2Poly.cxx:202
TList * GetBins()
Returns the TList of all bins in the histogram.
Definition TH2Poly.h:101
void ClearBinContents()
Clears the contents of all bins in the histogram.
Definition TH2Poly.cxx:565
Double_t fOverflow[kNOverflow]
Overflow bins.
Definition TH2Poly.h:159
@ kNOverflow
Definition TH2Poly.h:157
Bool_t fFloat
When set to kTRUE, allows the histogram to expand if a bin outside the limits is added.
Definition TH2Poly.h:167
Double_t ComputeIntegral(Bool_t) override
NOT IMPLEMENTED for TH2Poly.
Definition TH2Poly.cxx:1727
Bool_t IsIntersecting(TH2PolyBin *bin, Double_t xclipl, Double_t xclipr, Double_t yclipb, Double_t yclipt)
Returns kTRUE if the input bin is intersecting with the input rectangle (xclipl, xclipr,...
Definition TH2Poly.cxx:1163
void SetFloat(Bool_t flag=true)
When set to kTRUE, allows the histogram to expand if a bin outside the limits is added.
Definition TH2Poly.cxx:1423
Double_t Integral(Option_t *option="") const override
Returns the integral of bin contents.
Definition TH2Poly.cxx:799
virtual TH2PolyBin * CreateBin(TObject *poly)
Create appropriate histogram bin.
Definition TH2Poly.cxx:274
Double_t GetBinContent(Int_t bin) const override
Returns the content of the input bin Bin numbers are from [1,nbins] and for the overflow/underflow/se...
Definition TH2Poly.cxx:840
Bool_t * fIsEmpty
[fNCells] The array that returns true if the cell at the given coordinate is empty
Definition TH2Poly.h:165
Double_t RetrieveBinContent(Int_t bin) const override
Raw retrieval of bin content on internal data structure see convention for numbering bins in TH1::Get...
Definition TH2Poly.h:177
TList * fBins
List of bins. The list owns the contained objects.
Definition TH2Poly.h:170
void AddBinToPartition(TH2PolyBin *bin)
Adds the input bin into the partition cell matrix.
Definition TH2Poly.cxx:442
Bool_t fBinContentChanged
!For the 3D Painter
Definition TH2Poly.h:169
Int_t Fill(Double_t x, Double_t y) override
Increment the bin containing (x,y) by 1.
Definition TH2Poly.cxx:663
Int_t GetNumberOfBins() const
Return the number of bins : it should be the size of the bin list.
Definition TH2Poly.cxx:876
void SetBinContentChanged(Bool_t flag)
Definition TH2Poly.h:122
void GetStats(Double_t *stats) const override
Fill the array stats from the contents of this histogram The array stats must be correctly dimensione...
Definition TH2Poly.cxx:1439
Bool_t * fCompletelyInside
[fNCells] The array that returns true if the cell at the given coordinate is completely inside a bin
Definition TH2Poly.h:166
TH2Poly()
Default Constructor. No boundaries specified.
Definition TH2Poly.cxx:147
Bool_t IsInsideBin(Int_t binnr, Double_t x, Double_t y)
Return "true" if the point (x,y) is inside the bin of binnr.
Definition TH2Poly.cxx:1431
Bool_t fNewBinAdded
!For the 3D Painter
Definition TH2Poly.h:168
void Copy(TObject &newth2p) const override
Copy function for TH2Poly.
Definition TH2Poly.cxx:211
void SetBinError(Int_t bin, Double_t error) override
Set the bin Error.
Definition TH2Poly.cxx:892
const char * GetBinTitle(Int_t bin) const
Returns the bin title.
Definition TH2Poly.cxx:917
void SetNewBinAdded(Bool_t flag)
Definition TH2Poly.h:124
void Scale(Double_t c1=1, Option_t *option="") override
Multiply this histogram by a constant c1.
Definition TH2Poly.cxx:1392
void ChangePartition(Int_t n, Int_t m)
Changes the number of partition cells in the histogram.
Definition TH2Poly.cxx:514
virtual Double_t Interpolate(Double_t, Double_t)
NOT IMPLEMENTED for TH2Poly.
Definition TH2Poly.cxx:1748
Double_t GetMinimum() const
Returns the minimum value of the histogram.
Definition TH2Poly.cxx:975
const char * GetBinName(Int_t bin) const
Returns the bin name.
Definition TH2Poly.cxx:907
Double_t fStepX
Definition TH2Poly.h:164
void FillN(Int_t ntimes, const Double_t *x, const Double_t *y, const Double_t *w, Int_t stride=1) override
Fills a 2-D histogram with an array of values and weights.
Definition TH2Poly.cxx:785
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH2Poly.cxx:553
Int_t fNCells
Number of partition cells: fCellX*fCellY.
Definition TH2Poly.h:162
Int_t FindBin(Double_t x, Double_t y, Double_t z=0) override
Returns the bin number of the bin at the given coordinate.
Definition TH2Poly.cxx:620
Bool_t Divide(TF1 *, Double_t) override
NOT IMPLEMENTED for TH2Poly.
Definition TH2Poly.cxx:1712
void Initialize(Double_t xlow, Double_t xup, Double_t ylow, Double_t yup, Int_t n, Int_t m)
Initializes the TH2Poly object. This method is called by the constructor.
Definition TH2Poly.cxx:1112
Int_t fCellX
Number of partition cells in the x-direction of the histogram.
Definition TH2Poly.h:160
~TH2Poly() override
Destructor.
Definition TH2Poly.cxx:191
virtual Int_t AddBin(TObject *poly)
Adds a new bin to the histogram.
Definition TH2Poly.cxx:296
Double_t GetBinError(Int_t bin) const override
Returns the value of error associated to bin number bin.
Definition TH2Poly.cxx:855
Bool_t IsIntersectingPolygon(Int_t bn, Double_t *x, Double_t *y, Double_t xclipl, Double_t xclipr, Double_t yclipb, Double_t yclipt)
Returns kTRUE if the input polygon (bn, x, y) is intersecting with the input rectangle (xclipl,...
Definition TH2Poly.cxx:1204
Bool_t Add(const TH1 *h1, Double_t c1) override
Performs the operation: this = this + c1*h1.
Definition TH2Poly.cxx:364
virtual TH1 * GetAsymmetry(TH1 *, Double_t, Double_t)
NOT IMPLEMENTED for TH2Poly.
Definition TH2Poly.cxx:1741
void Honeycomb(Double_t xstart, Double_t ystart, Double_t a, Int_t k, Int_t s, Option_t *option="v")
Bins the histogram using a honeycomb structure If the option "v" is specified, the hexagons are drawn...
Definition TH2Poly.cxx:1025
Long64_t Merge(TCollection *) override
Merge TH2Polys Given the special nature of the TH2Poly, the merge is implemented in terms of subseque...
Definition TH2Poly.cxx:1318
void SetBinContent(Int_t bin, Double_t content) override
Sets the contents of the input bin to the input content Negative values between -1 and -9 are for the...
Definition TH2Poly.cxx:1406
Double_t GetMaximum() const
Returns the maximum value of the histogram.
Definition TH2Poly.cxx:927
void Reset(Option_t *option) override
Reset this histogram: contents, errors, etc.
Definition TH2Poly.cxx:590
Double_t fStepY
Dimensions of a partition cell.
Definition TH2Poly.h:164
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TH2Poly.cxx:1332
TH1 * FFT(TH1 *, Option_t *) override
NOT IMPLEMENTED for TH2Poly.
Definition TH2Poly.cxx:1734
TList * fCells
[fNCells] The array of TLists that store the bins that intersect with each cell. List do not own the ...
Definition TH2Poly.h:163
Int_t fCellY
Number of partition cells in the y-direction of the histogram.
Definition TH2Poly.h:161
Service class for 2-D histogram classes.
Definition TH2.h:30
void Copy(TObject &hnew) const override
Copy.
Definition TH2.cxx:380
Double_t fTsumwxy
Total Sum of weight*X*Y.
Definition TH2.h:36
void Reset(Option_t *option="") override
Reset this histogram: contents, errors, etc.
Definition TH2.cxx:2600
Double_t fTsumwy2
Total Sum of weight*Y*Y.
Definition TH2.h:35
Double_t fTsumwy
Total Sum of weight*Y.
Definition TH2.h:34
void PutStats(Double_t *stats) override
Replace current statistics with the values in array stats.
Definition TH2.cxx:2485
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:83
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:355
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition TMultiGraph.h:34
TList * GetListOfGraphs() const
Definition TMultiGraph.h:68
static TClass * Class()
virtual Int_t IsInside(Double_t x, Double_t y) const
Return 1 if the point (x,y) is inside one of the graphs 0 otherwise.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition TNamed.cxx:74
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
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:199
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition TObject.cxx:751
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1015
virtual TClass * IsA() const
Definition TObject.h:243
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:457
const char * Data() const
Definition TString.h:376
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:632
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5
Bool_t IsInside(T xp, T yp, Int_t np, T *x, T *y)
Function which returns kTRUE if point xp,yp lies inside the polygon defined by the np points in array...
Definition TMath.h:1233
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
Definition TMath.h:902
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
TMarker m
Definition textangle.C:8