00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "TROOT.h"
00014 #include "TClass.h"
00015 #include "TH2Poly.h"
00016 #include "TCutG.h"
00017 #include "TList.h"
00018 #include "TMath.h"
00019 #include "TMultiGraph.h"
00020 #include "TGraph.h"
00021 #include "TStyle.h"
00022 #include "TCanvas.h"
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <stdio.h>
00026 #include <ctype.h>
00027 #include "Riostream.h"
00028
00029 ClassImp(TH2Poly)
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 TH2Poly::TH2Poly()
00150 {
00151
00152
00153 Initialize(0., 0., 0., 0., 25, 25);
00154 SetName("NoName");
00155 SetTitle("NoTitle");
00156 SetFloat();
00157 }
00158
00159
00160
00161 TH2Poly::TH2Poly(const char *name,const char *title, Double_t xlow,Double_t xup
00162 , Double_t ylow,Double_t yup)
00163 {
00164
00165
00166
00167 Initialize(xlow, xup, ylow, yup, 25, 25);
00168 SetName(name);
00169 SetTitle(title);
00170 SetFloat(kFALSE);
00171 }
00172
00173
00174
00175 TH2Poly::TH2Poly(const char *name,const char *title,
00176 Int_t nX, Double_t xlow, Double_t xup,
00177 Int_t nY, Double_t ylow, Double_t yup)
00178 {
00179
00180
00181 Initialize(xlow, xup, ylow, yup, nX, nY);
00182 SetName(name);
00183 SetTitle(title);
00184 SetFloat(kFALSE);
00185 }
00186
00187
00188
00189 TH2Poly::~TH2Poly()
00190 {
00191
00192 }
00193
00194
00195
00196 Int_t TH2Poly::AddBin(TObject *poly)
00197 {
00198
00199
00200
00201
00202
00203 if (!poly) return 0;
00204
00205 if (fBins == 0) {fBins = new TList();}
00206
00207 fNcells++;
00208 TH2PolyBin *bin = new TH2PolyBin(poly, fNcells);
00209
00210
00211
00212 Bool_t flag = kFALSE;
00213 if (fFloat) {
00214 if (fXaxis.GetXmin() > bin->GetXMin()) {
00215 fXaxis.Set(100, bin->GetXMin(), fXaxis.GetXmax());
00216 flag = kTRUE;
00217 }
00218 if (fXaxis.GetXmax() < bin->GetXMax()) {
00219 fXaxis.Set(100, fXaxis.GetXmin(), bin->GetXMax());
00220 flag = kTRUE;
00221 }
00222 if (fYaxis.GetXmin() > bin->GetYMin()) {
00223 fYaxis.Set(100, bin->GetYMin(), fYaxis.GetXmax());
00224 flag = kTRUE;
00225 }
00226 if (fYaxis.GetXmax() < bin->GetYMax()) {
00227 fYaxis.Set(100, fYaxis.GetXmin(), bin->GetYMax());
00228 flag = kTRUE;
00229 }
00230 if (flag) ChangePartition(fCellX, fCellY);
00231 } else {
00232
00233 }
00234
00235 fBins->Add((TObject*) bin);
00236 SetNewBinAdded(kTRUE);
00237
00238
00239 AddBinToPartition(bin);
00240
00241 return fNcells;
00242 }
00243
00244
00245
00246 Int_t TH2Poly::AddBin(Int_t n, const Double_t *x, const Double_t *y)
00247 {
00248
00249
00250
00251
00252 TGraph *g = new TGraph(n, x, y);
00253 Int_t bin = AddBin(g);
00254 return bin;
00255 }
00256
00257
00258
00259 Int_t TH2Poly::AddBin(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
00260 {
00261
00262
00263
00264 Double_t x[] = {x1, x1, x2, x2};
00265 Double_t y[] = {y1, y2, y2, y1};
00266 TGraph *g = new TGraph(4, x, y);
00267 Int_t bin = AddBin(g);
00268 return bin;
00269 }
00270
00271
00272
00273 void TH2Poly::AddBinToPartition(TH2PolyBin *bin)
00274 {
00275
00276
00277
00278
00279 Int_t nl, nr, mb, mt;
00280 Double_t xclipl, xclipr, yclipb, yclipt;
00281 Double_t binXmax, binXmin, binYmax, binYmin;
00282
00283 binXmax = bin->GetXMax();
00284 binXmin = bin->GetXMin();
00285 binYmax = bin->GetYMax();
00286 binYmin = bin->GetYMin();
00287 nl = (Int_t)(floor((binXmin - fXaxis.GetXmin())/fStepX));
00288 nr = (Int_t)(floor((binXmax - fXaxis.GetXmin())/fStepX));
00289 mb = (Int_t)(floor((binYmin - fYaxis.GetXmin())/fStepY));
00290 mt = (Int_t)(floor((binYmax - fYaxis.GetXmin())/fStepY));
00291
00292
00293 if (nr>=fCellX) nr = fCellX-1;
00294 if (mt>=fCellY) mt = fCellY-1;
00295 if (nl<0) nl = 0;
00296 if (mb<0) mb = 0;
00297
00298 fNCells = fCellX*fCellY;
00299
00300
00301 for (int i = nl; i <= nr; i++) {
00302 xclipl = fXaxis.GetXmin() + i*fStepX;
00303 xclipr = xclipl + fStepX;
00304 for (int j = mb; j <= mt; j++) {
00305 yclipb = fYaxis.GetXmin() + j*fStepY;
00306 yclipt = yclipb + fStepY;
00307
00308
00309
00310 if ((binXmin >= xclipl) && (binXmax <= xclipr) &&
00311 (binYmax <= yclipt) && (binYmin >= yclipb)){
00312 fCells[i + j*fCellX].Add((TObject*) bin);
00313 fIsEmpty[i + j*fCellX] = kFALSE;
00314 return;
00315 }
00316
00317
00318 if (IsIntersecting(bin, xclipl, xclipr, yclipb, yclipt)) {
00319 fCells[i + j*fCellX].Add((TObject*) bin);
00320 fIsEmpty[i + j*fCellX] = kFALSE;
00321 continue;
00322 }
00323
00324 if((bin->IsInside(xclipl,yclipb)) || (bin->IsInside(xclipl,yclipt))){
00325 fCells[i + j*fCellX].Add((TObject*) bin);
00326 fIsEmpty[i + j*fCellX] = kFALSE;
00327 fCompletelyInside[i + fCellX*j] = kTRUE;
00328 continue;
00329 }
00330 if((bin->IsInside(xclipr,yclipb)) || (bin->IsInside(xclipr,yclipt))){
00331 fCells[i + j*fCellX].Add((TObject*) bin);
00332 fIsEmpty[i + j*fCellX] = kFALSE;
00333 fCompletelyInside[i + fCellX*j] = kTRUE;
00334 continue;
00335 }
00336 }
00337 }
00338 }
00339
00340
00341
00342 void TH2Poly::ChangePartition(Int_t n, Int_t m)
00343 {
00344
00345
00346
00347 fCellX = n;
00348 fCellY = m;
00349
00350 delete [] fCells;
00351
00352 fNCells = fCellX*fCellY;
00353 fCells = new TList [fNCells];
00354
00355 fStepX = (fXaxis.GetXmax() - fXaxis.GetXmin())/fCellX;
00356 fStepY = (fYaxis.GetXmax() - fYaxis.GetXmin())/fCellY;
00357
00358 delete [] fIsEmpty;
00359 delete [] fCompletelyInside;
00360 fIsEmpty = new Bool_t [fNCells];
00361 fCompletelyInside = new Bool_t [fNCells];
00362
00363
00364 for (int i = 0; i<fNCells; i++) {
00365 fIsEmpty[i] = kTRUE;
00366 fCompletelyInside[i] = kFALSE;
00367 }
00368
00369
00370 TIter next(fBins);
00371 TObject *obj;
00372
00373 while((obj = next())){
00374 AddBinToPartition((TH2PolyBin*) obj);
00375 }
00376 }
00377
00378
00379
00380 void TH2Poly::ClearBinContents()
00381 {
00382
00383
00384 TIter next(fBins);
00385 TObject *obj;
00386 TH2PolyBin *bin;
00387
00388
00389 while ((obj = next())) {
00390 bin = (TH2PolyBin*) obj;
00391 bin->ClearContent();
00392 }
00393
00394
00395 fTsumw = 0;
00396 fTsumwx = 0;
00397 fTsumwx2 = 0;
00398 fTsumwy = 0;
00399 fTsumwy2 = 0;
00400 fEntries = 0;
00401 }
00402
00403
00404
00405 TH1 *TH2Poly::DrawCopy(Option_t *option) const
00406 {
00407
00408
00409 TString opt = option;
00410 opt.ToLower();
00411 if (gPad && !opt.Contains("same")) gPad->Clear();
00412 TH2Poly *newth2 = (TH2Poly*)Clone();
00413 newth2->SetDirectory(0);
00414 newth2->SetBit(kCanDelete);
00415 newth2->AppendPad(option);
00416 return newth2;
00417 }
00418
00419
00420
00421 Int_t TH2Poly::FindBin(Double_t x, Double_t y, Double_t)
00422 {
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439 Int_t overflow = 0;
00440 if (y > fYaxis.GetXmax()) overflow += -1;
00441 else if (y > fYaxis.GetXmin()) overflow += -4;
00442 else overflow += -7;
00443 if (x > fXaxis.GetXmax()) overflow += -2;
00444 else if (x > fXaxis.GetXmin()) overflow += -1;
00445 if (overflow != -5) return overflow;
00446
00447
00448 Int_t n = (Int_t)(floor((x-fXaxis.GetXmin())/fStepX));
00449 Int_t m = (Int_t)(floor((y-fYaxis.GetXmin())/fStepY));
00450
00451
00452 if (n>=fCellX) n = fCellX-1;
00453 if (m>=fCellY) m = fCellY-1;
00454 if (n<0) n = 0;
00455 if (m<0) m = 0;
00456
00457 if (fIsEmpty[n+fCellX*m]) return -5;
00458
00459 TH2PolyBin *bin;
00460
00461 TIter next(&fCells[n+fCellX*m]);
00462 TObject *obj;
00463
00464
00465 while ((obj=next())) {
00466 bin = (TH2PolyBin*)obj;
00467 if (bin->IsInside(x,y)) return bin->GetBinNumber();
00468 }
00469
00470
00471 return -5;
00472 }
00473
00474
00475
00476 Int_t TH2Poly::Fill(Double_t x, Double_t y)
00477 {
00478
00479
00480
00481 return Fill(x, y, 1.0);
00482 }
00483
00484
00485
00486 Int_t TH2Poly::Fill(Double_t x, Double_t y, Double_t w)
00487 {
00488
00489
00490
00491 if (fNcells==0) return 0;
00492 Int_t overflow = 0;
00493 if (y > fYaxis.GetXmax()) overflow += -1;
00494 else if (y > fYaxis.GetXmin()) overflow += -4;
00495 else overflow += -7;
00496 if (x > fXaxis.GetXmax()) overflow += -2;
00497 else if(x > fXaxis.GetXmin()) overflow += -1;
00498 if (overflow != -5) {
00499 fOverflow[-overflow - 1]++;
00500 return 0;
00501 }
00502
00503
00504 Int_t n = (Int_t)(floor((x-fXaxis.GetXmin())/fStepX));
00505 Int_t m = (Int_t)(floor((y-fYaxis.GetXmin())/fStepY));
00506
00507
00508 if (n>=fCellX) n = fCellX-1;
00509 if (m>=fCellY) m = fCellY-1;
00510 if (n<0) n = 0;
00511 if (m<0) m = 0;
00512
00513 if (fIsEmpty[n+fCellX*m]) return 0;
00514
00515 TH2PolyBin *bin;
00516 Int_t bi;
00517
00518 TIter next(&fCells[n+fCellX*m]);
00519 TObject *obj;
00520
00521 while ((obj=next())) {
00522 bin = (TH2PolyBin*)obj;
00523 bi = bin->GetBinNumber()-1;
00524 if (bin->IsInside(x,y)) {
00525 bin->Fill(w);
00526
00527
00528 fTsumw = fTsumw + w;
00529 fTsumwx = fTsumwx + w*x;
00530 fTsumwx2 = fTsumwx2 + w*x*x;
00531 fTsumwy = fTsumwy + w*y;
00532 fTsumwy2 = fTsumwy2 + w*y*y;
00533 if (fSumw2.fN) fSumw2.fArray[bi] += w*w;
00534 fEntries++;
00535
00536 SetBinContentChanged(kTRUE);
00537
00538 return bin->GetBinNumber();
00539 }
00540 }
00541
00542 fOverflow[4]++;
00543 return 0;
00544 }
00545
00546
00547
00548 Int_t TH2Poly::Fill(const char* name, Double_t w)
00549 {
00550
00551
00552 TString sname(name);
00553
00554 TIter next(fBins);
00555 TObject *obj;
00556 TH2PolyBin *bin;
00557
00558 while ((obj = next())) {
00559 bin = (TH2PolyBin*) obj;
00560 if (!sname.CompareTo(bin->GetPolygon()->GetName())) {
00561 bin->Fill(w);
00562 fEntries++;
00563 SetBinContentChanged(kTRUE);
00564 return bin->GetBinNumber();
00565 }
00566 }
00567
00568 return 0;
00569 }
00570
00571
00572
00573 void TH2Poly::FillN(Int_t ntimes, const Double_t* x, const Double_t* y,
00574 const Double_t* w, Int_t stride)
00575 {
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 for (int i = 0; i < ntimes; i += stride) {
00586 Fill(x[i], y[i], w[i]);
00587 }
00588 }
00589
00590
00591
00592 Double_t TH2Poly::Integral(Option_t* option) const
00593 {
00594
00595
00596
00597
00598
00599 TString opt = option;
00600 opt.ToLower();
00601
00602 if ((opt.Contains("width")) || (opt.Contains("area"))) {
00603 Double_t w;
00604 Double_t integral = 0.;
00605
00606 TIter next(fBins);
00607 TObject *obj;
00608 TH2PolyBin *bin;
00609 while ((obj=next())) {
00610 bin = (TH2PolyBin*) obj;
00611 w = bin->GetArea();
00612 integral += w*(bin->GetContent());
00613 }
00614
00615 return integral;
00616 } else {
00617 return fTsumw;
00618 }
00619 }
00620
00621
00622
00623 Double_t TH2Poly::GetBinContent(Int_t bin) const
00624 {
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 if (bin>fNcells || bin==0) return 0;
00637 if (bin<0) return fOverflow[-bin - 1];
00638 return ((TH2PolyBin*) fBins->At(bin-1))->GetContent();
00639 }
00640
00641
00642
00643 Double_t TH2Poly::GetBinError(Int_t bin) const
00644 {
00645
00646
00647
00648
00649
00650 if (bin < 0) bin = 0;
00651 if (bin > (fNcells)) return 0;
00652 if (fBuffer) ((TH1*)this)->BufferEmpty();
00653 if (fSumw2.fN) {
00654 Double_t err2 = fSumw2.fArray[bin-1];
00655 return TMath::Sqrt(err2);
00656 }
00657 Double_t error2 = TMath::Abs(GetBinContent(bin));
00658 return TMath::Sqrt(error2);
00659 }
00660
00661
00662
00663 const char *TH2Poly::GetBinName(Int_t bin) const
00664 {
00665
00666
00667 if (bin > (fNcells)) return "";
00668 if (bin < 0) return "";
00669 return ((TH2PolyBin*) fBins->At(bin-1))->GetPolygon()->GetName();
00670 }
00671
00672
00673
00674 const char *TH2Poly::GetBinTitle(Int_t bin) const
00675 {
00676
00677
00678 if (bin > (fNcells)) return "";
00679 if (bin < 0) return "";
00680 return ((TH2PolyBin*) fBins->At(bin-1))->GetPolygon()->GetTitle();
00681 }
00682
00683
00684
00685 Double_t TH2Poly::GetMaximum() const
00686 {
00687
00688
00689 if (fNcells==0) return 0;
00690
00691 TH2PolyBin *b;
00692
00693 TIter next(fBins);
00694 TObject *obj;
00695 Double_t max,c;
00696
00697 max = ((TH2PolyBin*) next())->GetContent();
00698
00699 while ((obj=next())) {
00700 b = (TH2PolyBin*)obj;
00701 c = b->GetContent();
00702 if (c>max) max = c;
00703 }
00704 return max;
00705 }
00706
00707
00708
00709 Double_t TH2Poly::GetMaximum(Double_t maxval) const
00710 {
00711
00712
00713 if (fNcells==0) return 0;
00714
00715 TH2PolyBin *b;
00716
00717 TIter next(fBins);
00718 TObject *obj;
00719 Double_t max,c;
00720
00721 max = ((TH2PolyBin*) next())->GetContent();
00722
00723 while ((obj=next())) {
00724 b = (TH2PolyBin*)obj;
00725 c = b->GetContent();
00726 if (c>max && c<maxval) max=c;
00727 }
00728 return max;
00729 }
00730
00731
00732
00733 Double_t TH2Poly::GetMinimum() const
00734 {
00735
00736
00737 if (fNcells==0) return 0;
00738
00739 TH2PolyBin *b;
00740
00741 TIter next(fBins);
00742 TObject *obj;
00743 Double_t min,c;
00744
00745 min = ((TH2PolyBin*) next())->GetContent();
00746
00747 while ((obj=next())) {
00748 b = (TH2PolyBin*)obj;
00749 c = b->GetContent();
00750 if (c<min) min=c;
00751 }
00752 return min;
00753 }
00754
00755
00756
00757 Double_t TH2Poly::GetMinimum(Double_t minval) const
00758 {
00759
00760
00761 if (fNcells==0) return 0;
00762
00763 TH2PolyBin *b;
00764
00765 TIter next(fBins);
00766 TObject *obj;
00767 Double_t min,c;
00768
00769 min = ((TH2PolyBin*) next())->GetContent();
00770
00771 while ((obj=next())) {
00772 b = (TH2PolyBin*)obj;
00773 c = b->GetContent();
00774 if (c<min && c>minval) min=c;
00775 }
00776 return min;
00777 }
00778
00779
00780
00781 void TH2Poly::Honeycomb(Double_t xstart, Double_t ystart, Double_t a,
00782 Int_t k, Int_t s)
00783 {
00784
00785
00786
00787 Double_t numberOfHexagonsInTheRow;
00788 Double_t x[6], y[6];
00789 Double_t xloop, yloop, xtemp;
00790 xloop = xstart; yloop = ystart + a/2.0;
00791 for (int sCounter = 0; sCounter < s; sCounter++) {
00792
00793 xtemp = xloop;
00794
00795
00796 if(sCounter%2 == 0){numberOfHexagonsInTheRow = k;}
00797 else{numberOfHexagonsInTheRow = k - 1;}
00798
00799 for (int kCounter = 0; kCounter < numberOfHexagonsInTheRow; kCounter++) {
00800
00801
00802 x[0] = xtemp;
00803 y[0] = yloop;
00804 x[1] = x[0];
00805 y[1] = y[0] + a;
00806 x[2] = x[1] + a*TMath::Sqrt(3)/2.0;
00807 y[2] = y[1] + a/2.0;
00808 x[3] = x[2] + a*TMath::Sqrt(3)/2.0;
00809 y[3] = y[1];
00810 x[4] = x[3];
00811 y[4] = y[0];
00812 x[5] = x[2];
00813 y[5] = y[4] - a/2.0;
00814
00815 this->AddBin(6, x, y);
00816
00817
00818 xtemp += a*TMath::Sqrt(3);
00819 }
00820
00821
00822 if (sCounter%2 == 0) xloop += a*TMath::Sqrt(3)/2.0;
00823 else xloop -= a*TMath::Sqrt(3)/2.0;
00824 yloop += 1.5*a;
00825 }
00826 }
00827
00828
00829
00830 void TH2Poly::Initialize(Double_t xlow, Double_t xup,
00831 Double_t ylow, Double_t yup, Int_t n, Int_t m)
00832 {
00833
00834
00835 Int_t i;
00836 fDimension = 2;
00837
00838 fBins = 0;
00839 fNcells = 0;
00840
00841
00842 fXaxis.Set(100, xlow, xup);
00843 fYaxis.Set(100, ylow, yup);
00844
00845 for (i=0; i<9; i++) fOverflow[i] = 0.;
00846
00847
00848 fEntries = 0;
00849 fTsumw = 0.;
00850 fTsumwx = 0.;
00851 fTsumwx2 = 0.;
00852 fTsumwy2 = 0.;
00853 fTsumwy = 0.;
00854
00855 fCellX = n;
00856 fCellY = m;
00857
00858 fNCells = fCellX*fCellY;
00859 fCells = new TList [fNCells];
00860 fStepX = (fXaxis.GetXmax() - fXaxis.GetXmin())/fCellX;
00861 fStepY = (fYaxis.GetXmax() - fYaxis.GetXmin())/fCellY;
00862
00863 fIsEmpty = new Bool_t [fNCells];
00864 fCompletelyInside = new Bool_t [fNCells];
00865
00866 for (i = 0; i<fNCells; i++) {
00867 fIsEmpty[i] = kTRUE;
00868 fCompletelyInside[i] = kFALSE;
00869 }
00870
00871
00872 SetNewBinAdded(kFALSE);
00873 SetBinContentChanged(kFALSE);
00874 }
00875
00876
00877
00878 Bool_t TH2Poly::IsIntersecting(TH2PolyBin *bin,
00879 Double_t xclipl, Double_t xclipr,
00880 Double_t yclipb, Double_t yclipt)
00881 {
00882
00883
00884
00885 Int_t gn;
00886 Double_t *gx;
00887 Double_t *gy;
00888 Bool_t inter = kFALSE;
00889 TObject *poly = bin->GetPolygon();
00890
00891 if (poly->IsA() == TGraph::Class()) {
00892 TGraph *g = (TGraph*)poly;
00893 gx = g->GetX();
00894 gy = g->GetY();
00895 gn = g->GetN();
00896 inter = IsIntersectingPolygon(gn, gx, gy, xclipl, xclipr, yclipb, yclipt);
00897 }
00898
00899 if (poly->IsA() == TMultiGraph::Class()) {
00900 TMultiGraph *mg = (TMultiGraph*)poly;
00901 TList *gl = mg->GetListOfGraphs();
00902 if (!gl) return inter;
00903 TGraph *g;
00904 TIter next(gl);
00905 while ((g = (TGraph*) next())) {
00906 gx = g->GetX();
00907 gy = g->GetY();
00908 gn = g->GetN();
00909 inter = IsIntersectingPolygon(gn, gx, gy, xclipl, xclipr, yclipb, yclipt);
00910 if (inter) return inter;
00911 }
00912 }
00913
00914 return inter;
00915 }
00916
00917
00918 Bool_t TH2Poly::IsIntersectingPolygon(Int_t bn, Double_t *x, Double_t *y,
00919 Double_t xclipl, Double_t xclipr,
00920 Double_t yclipb, Double_t yclipt)
00921 {
00922
00923
00924
00925 Bool_t p0R, p0L, p0T, p0B, p0xM, p0yM, p1R, p1L, p1T, p1B, p1xM, p1yM, p0In, p1In;
00926
00927 for (int counter = 0; counter < (bn-1); counter++) {
00928
00929 p0L = x[counter] <= xclipl;
00930 p1L = x[counter + 1] <= xclipl;
00931 if (p0L && p1L) continue;
00932 p0R = x[counter] >= xclipr;
00933 p1R = x[counter + 1] >= xclipr;
00934 if (p0R && p1R) continue;
00935 p0T = y[counter] >= yclipt;
00936 p1T = y[counter + 1] >= yclipt;
00937 if (p0T && p1T) continue;
00938 p0B = y[counter] <= yclipb;
00939 p1B = y[counter + 1] <= yclipb;
00940 if (p0B && p1B) continue;
00941
00942
00943 p0xM = !p0R && !p0L;
00944 p0yM = !p0T && !p0B;
00945 p1xM = !p1R && !p1L;
00946 p1yM = !p1T && !p1B;
00947 p0In = p0xM && p0yM;
00948 p1In = p1xM && p1yM;
00949 if (p0In) {
00950 if (p1In) continue;
00951 return kTRUE;
00952 } else {
00953 if (p1In) return kTRUE;
00954 }
00955
00956
00957
00958
00959
00960 if (p0xM && p1xM) return kTRUE;
00961 if (p0yM && p1yM) return kTRUE;
00962
00963
00964
00965 Double_t xcoord[3], ycoord[3];
00966 xcoord[0] = x[counter];
00967 xcoord[1] = x[counter + 1];
00968 ycoord[0] = y[counter];
00969 ycoord[1] = y[counter + 1];
00970
00971 if (p0L) {
00972 if(p1T){
00973 xcoord[2] = xclipl;
00974 ycoord[2] = yclipb;
00975 if((TMath::IsInside(xclipl, yclipt, 3, xcoord, ycoord)) ||
00976 (TMath::IsInside(xclipr, yclipb, 3, xcoord, ycoord))) continue;
00977 else return kTRUE;
00978 } else if (p1B) {
00979 xcoord[2] = xclipl;
00980 ycoord[2] = yclipt;
00981 if((TMath::IsInside(xclipl, yclipb, 3, xcoord, ycoord)) ||
00982 (TMath::IsInside(xclipr, yclipt, 3, xcoord, ycoord))) continue;
00983 else return kTRUE;
00984 } else {
00985 if (p0T) {
00986 xcoord[2] = xclipl;
00987 ycoord[2] = yclipb;
00988 if (TMath::IsInside(xclipr, yclipt, 3, xcoord, ycoord)) continue;
00989 else return kTRUE;
00990 }
00991 if (p0B) {
00992 xcoord[2] = xclipl;
00993 ycoord[2] = yclipt;
00994 if (TMath::IsInside(xclipr, yclipb, 3, xcoord, ycoord)) continue;
00995 else return kTRUE;
00996 }
00997 }
00998 } else if (p0R) {
00999 if (p1T) {
01000 xcoord[2] = xclipl;
01001 ycoord[2] = yclipb;
01002 if ((TMath::IsInside(xclipr, yclipb, 3, xcoord, ycoord)) ||
01003 (TMath::IsInside(xclipl, yclipt, 3, xcoord, ycoord))) continue;
01004 else return kTRUE;
01005 } else if (p1B) {
01006 xcoord[2] = xclipl;
01007 ycoord[2] = yclipt;
01008 if ((TMath::IsInside(xclipl, yclipb, 3, xcoord, ycoord)) ||
01009 (TMath::IsInside(xclipr, yclipt, 3, xcoord, ycoord))) continue;
01010 else return kTRUE;
01011 } else{
01012 if (p0T) {
01013 xcoord[2] = xclipr;
01014 ycoord[2] = yclipb;
01015 if (TMath::IsInside(xclipl, yclipt, 3, xcoord, ycoord)) continue;
01016 else return kTRUE;
01017 }
01018 if (p0B) {
01019 xcoord[2] = xclipr;
01020 ycoord[2] = yclipt;
01021 if (TMath::IsInside(xclipl, yclipb, 3, xcoord, ycoord)) continue;
01022 else return kTRUE;
01023 }
01024 }
01025 }
01026 }
01027 return kFALSE;
01028 }
01029
01030
01031
01032 void TH2Poly::SavePrimitive(ostream &out, Option_t *option)
01033 {
01034
01035
01036 out <<" "<<endl;
01037 out <<" "<< ClassName() <<" *";
01038
01039
01040
01041 static Int_t hcounter = 0;
01042 TString histName = GetName();
01043 if (!fDirectory && !histName.Contains("Graph")) {
01044 hcounter++;
01045 histName += "__";
01046 histName += hcounter;
01047 }
01048 const char *hname = histName.Data();
01049
01050
01051 out << hname << " = new " << ClassName() << "(\"" << hname << "\", \""
01052 << GetTitle() << "\", " << fCellX << ", " << fXaxis.GetXmin() << ", " << fXaxis.GetXmax()
01053 << ", " << fCellY << ", " << fYaxis.GetXmin() << ", " << fYaxis.GetXmax() << ");" << endl;
01054
01055
01056 TIter next(fBins);
01057 TObject *obj;
01058 TH2PolyBin *th2pBin;
01059
01060 while((obj = next())){
01061 th2pBin = (TH2PolyBin*) obj;
01062 th2pBin->GetPolygon()->SavePrimitive(out, Form("th2poly%s",histName.Data()));
01063 }
01064
01065
01066 out<<" "<<endl;
01067 Int_t bin;
01068 for (bin=1;bin<=fNcells;bin++) {
01069 Double_t bc = GetBinContent(bin);
01070 if (bc) {
01071 out<<" "<<hname<<"->SetBinContent("<<bin<<","<<bc<<");"<<endl;
01072 }
01073 }
01074
01075
01076 if (fSumw2.fN) {
01077 for (bin=1;bin<=fNcells;bin++) {
01078 Double_t be = GetBinError(bin);
01079 if (be) {
01080 out<<" "<<hname<<"->SetBinError("<<bin<<","<<be<<");"<<endl;
01081 }
01082 }
01083 }
01084 TH1::SavePrimitiveHelp(out, hname, option);
01085 }
01086
01087
01088
01089 void TH2Poly::SetBinContent(Int_t bin, Double_t content)
01090 {
01091
01092
01093 if (bin > (fNcells)) return;
01094 ((TH2PolyBin*) fBins->At(bin-1))->SetContent(content);
01095 SetBinContentChanged(kTRUE);
01096 }
01097
01098
01099
01100 void TH2Poly::SetFloat(Bool_t flag)
01101 {
01102
01103
01104
01105 fFloat = flag;
01106 }
01107
01108
01109
01110 TH2PolyBin::TH2PolyBin()
01111 {
01112
01113
01114 fPoly = 0;
01115 fContent = 0.;
01116 fNumber = 0;
01117 fXmax = -1111;
01118 fXmin = -1111;
01119 fYmax = -1111;
01120 fYmin = -1111;
01121 fArea = 0;
01122 SetChanged(kTRUE);
01123 }
01124
01125
01126
01127 TH2PolyBin::TH2PolyBin(TObject *poly, Int_t bin_number)
01128 {
01129
01130
01131 fContent = 0.;
01132 fNumber = bin_number;
01133 fArea = 0.;
01134 fPoly = poly;
01135 fXmax = -1111;
01136 fXmin = -1111;
01137 fYmax = -1111;
01138 fYmin = -1111;
01139 SetChanged(kTRUE);
01140 }
01141
01142
01143
01144 TH2PolyBin::~TH2PolyBin()
01145 {
01146
01147
01148 if (fPoly) delete fPoly;
01149 }
01150
01151
01152
01153 Double_t TH2PolyBin::GetArea()
01154 {
01155
01156
01157 Int_t bn;
01158
01159 if (fArea == 0) {
01160 if (fPoly->IsA() == TGraph::Class()) {
01161 TGraph *g = (TGraph*)fPoly;
01162 bn = g->GetN();
01163 fArea = g->Integral(0,bn-1);
01164 }
01165
01166 if (fPoly->IsA() == TMultiGraph::Class()) {
01167 TMultiGraph *mg = (TMultiGraph*)fPoly;
01168 TList *gl = mg->GetListOfGraphs();
01169 if (!gl) return fArea;
01170 TGraph *g;
01171 TIter next(gl);
01172 while ((g = (TGraph*) next())) {
01173 bn = g->GetN();
01174 fArea = fArea + g->Integral(0,bn-1);
01175 }
01176 }
01177 }
01178
01179 return fArea;
01180 }
01181
01182
01183
01184 Double_t TH2PolyBin::GetXMax()
01185 {
01186
01187
01188 if (fXmax != -1111) return fXmax;
01189
01190 Int_t bn,i;
01191 Double_t *bx;
01192
01193 if (fPoly->IsA() == TGraph::Class()) {
01194 TGraph *g = (TGraph*)fPoly;
01195 bx = g->GetX();
01196 bn = g->GetN();
01197 fXmax = bx[0];
01198 for (i=1; i<bn; i++) {if (fXmax < bx[i]) fXmax = bx[i];}
01199 }
01200
01201 if (fPoly->IsA() == TMultiGraph::Class()) {
01202 TMultiGraph *mg = (TMultiGraph*)fPoly;
01203 TList *gl = mg->GetListOfGraphs();
01204 if (!gl) return fXmax;
01205 TGraph *g;
01206 TIter next(gl);
01207 Bool_t first = kTRUE;
01208 while ((g = (TGraph*) next())) {
01209 bx = g->GetX();
01210 bn = g->GetN();
01211 if (first) {fXmax = bx[0]; first = kFALSE;}
01212 for (i=0; i<bn; i++) {if (fXmax < bx[i]) fXmax = bx[i];}
01213 }
01214 }
01215
01216 return fXmax;
01217 }
01218
01219
01220
01221 Double_t TH2PolyBin::GetXMin()
01222 {
01223
01224
01225 if (fXmin != -1111) return fXmin;
01226
01227 Int_t bn,i;
01228 Double_t *bx;
01229
01230 if (fPoly->IsA() == TGraph::Class()) {
01231 TGraph *g = (TGraph*)fPoly;
01232 bx = g->GetX();
01233 bn = g->GetN();
01234 fXmin = bx[0];
01235 for (i=1; i<bn; i++) {if (fXmin > bx[i]) fXmin = bx[i];}
01236 }
01237
01238 if (fPoly->IsA() == TMultiGraph::Class()) {
01239 TMultiGraph *mg = (TMultiGraph*)fPoly;
01240 TList *gl = mg->GetListOfGraphs();
01241 if (!gl) return fXmin;
01242 TGraph *g;
01243 TIter next(gl);
01244 Bool_t first = kTRUE;
01245 while ((g = (TGraph*) next())) {
01246 bx = g->GetX();
01247 bn = g->GetN();
01248 if (first) {fXmin = bx[0]; first = kFALSE;}
01249 for (i=0; i<bn; i++) {if (fXmin > bx[i]) fXmin = bx[i];}
01250 }
01251 }
01252
01253 return fXmin;
01254 }
01255
01256
01257
01258 Double_t TH2PolyBin::GetYMax()
01259 {
01260
01261
01262 if (fYmax != -1111) return fYmax;
01263
01264 Int_t bn,i;
01265 Double_t *by;
01266
01267 if (fPoly->IsA() == TGraph::Class()) {
01268 TGraph *g = (TGraph*)fPoly;
01269 by = g->GetY();
01270 bn = g->GetN();
01271 fYmax = by[0];
01272 for (i=1; i<bn; i++) {if (fYmax < by[i]) fYmax = by[i];}
01273 }
01274
01275 if (fPoly->IsA() == TMultiGraph::Class()) {
01276 TMultiGraph *mg = (TMultiGraph*)fPoly;
01277 TList *gl = mg->GetListOfGraphs();
01278 if (!gl) return fYmax;
01279 TGraph *g;
01280 TIter next(gl);
01281 Bool_t first = kTRUE;
01282 while ((g = (TGraph*) next())) {
01283 by = g->GetY();
01284 bn = g->GetN();
01285 if (first) {fYmax = by[0]; first = kFALSE;}
01286 for (i=0; i<bn; i++) {if (fYmax < by[i]) fYmax = by[i];}
01287 }
01288 }
01289
01290 return fYmax;
01291 }
01292
01293
01294
01295 Double_t TH2PolyBin::GetYMin()
01296 {
01297
01298
01299 if (fYmin != -1111) return fYmin;
01300
01301 Int_t bn,i;
01302 Double_t *by;
01303
01304 if (fPoly->IsA() == TGraph::Class()) {
01305 TGraph *g = (TGraph*)fPoly;
01306 by = g->GetY();
01307 bn = g->GetN();
01308 fYmin = by[0];
01309 for (i=1; i<bn; i++) {if (fYmin > by[i]) fYmin = by[i];}
01310 }
01311
01312 if (fPoly->IsA() == TMultiGraph::Class()) {
01313 TMultiGraph *mg = (TMultiGraph*)fPoly;
01314 TList *gl = mg->GetListOfGraphs();
01315 if (!gl) return fYmin;
01316 TGraph *g;
01317 TIter next(gl);
01318 Bool_t first = kTRUE;
01319 while ((g = (TGraph*) next())) {
01320 by = g->GetY();
01321 bn = g->GetN();
01322 if (first) {fYmin = by[0]; first = kFALSE;}
01323 for (i=0; i<bn; i++) {if (fYmin > by[i]) fYmin = by[i];}
01324 }
01325 }
01326
01327 return fYmin;
01328 }
01329
01330
01331
01332 Bool_t TH2PolyBin::IsInside(Double_t x, Double_t y) const
01333 {
01334
01335
01336 Int_t in=0;
01337
01338 if (fPoly->IsA() == TGraph::Class()) {
01339 TGraph *g = (TGraph*)fPoly;
01340 in = g->IsInside(x, y);
01341 }
01342
01343 if (fPoly->IsA() == TMultiGraph::Class()) {
01344 TMultiGraph *mg = (TMultiGraph*)fPoly;
01345 in = mg->IsInside(x, y);
01346 }
01347
01348 return in;
01349 }