#include <float.h>
#include "Healoption.h"
#include "Hparam.h"
#include "TClass.h"
#include "TColor.h"
#include "TCrown.h"
#include "TCutG.h"
#include "TGaxis.h"
#include "TGraphDelaunay.h"
#include "TF1.h"
#include "TLatex.h"
#include "TMath.h"
#include "TPad.h"
#include "TPainter3dAlgorithms.h"
#include "TPaveText.h"
#include "TROOT.h"
#include "TStyle.h"
#include "TText.h"
#include "TVirtualPadEditor.h"
#include "THealPix.h"
#include "THealPainter.h"
#include "THealPaletteAxis.h"
static THealPix* gCurrentHeal = 0;
static Healoption_t Healoption;
static Hparam_t Healparam;
static const Int_t kNMAX = 2000;
static const Double_t d2r = TMath::DegToRad();
ClassImp(THealPainter)
THealPainter::THealPainter()
{
fHeal = 0;
fXaxis = 0;
fYaxis = 0;
fZaxis = 0;
fFunctions = 0;
}
THealPainter::~THealPainter()
{
}
Int_t THealPainter::DistancetoPrimitive(Int_t px, Int_t py)
{
return 0;
}
void THealPainter::DrawPanel()
{
gCurrentHeal = fHeal;
if(!gPad){
Error("DrawPanel", "need to draw HEALPix first");
return;
}
TVirtualPadEditor* editor = TVirtualPadEditor::GetPadEditor();
editor->Show();
gROOT->ProcessLine(Form("((TCanvas*)0x%lx)->Selected((TVirtualPad*)0x%lx, (TObject*)0x%lx, 1)", gPad->GetCanvas(), gPad, fHeal));
}
void THealPainter::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
}
TList* THealPainter::GetContourList(Double_t contour) const
{
TGraphDelaunay* dt;
TList* hl = fHeal->GetListOfFunctions();
dt = (TGraphDelaunay*)hl->FindObject("TGraphDelaunay");
if(!dt) return 0;
return 0;
}
Bool_t THealPainter::IsInside(Int_t bin , Int_t )
{
for (Int_t i=0;i<fNcuts;i++) {
Double_t x, y;
fHeal->GetBinCenter(bin, x, y);
if(!fHeal->IsDegree()){
x *= TMath::RadToDeg();
y *= TMath::RadToDeg();
}
if(Healoption.System == kGalactic || Healoption.System == kLatLong){
x -= 180;
y = 90 - y;
} else if(Healoption.System == kCelestial){
y = 90 - y;
}
if (fCutsOpt[i] > 0) {
if (!fCuts[i]->IsInside(x,y)) return kFALSE;
} else {
if (fCuts[i]->IsInside(x,y)) return kFALSE;
}
}
return kTRUE;
}
Bool_t THealPainter::IsInside(Double_t x, Double_t y)
{
for(Int_t i = 0; i < fNcuts; i++){
if(fCutsOpt[i] > 0){
if(!fCuts[i]->IsInside(x,y)) return kFALSE;
} else {
if(fCuts[i]->IsInside(x,y)) return kFALSE;
}
}
return kTRUE;
}
Int_t THealPainter::MakeChopt(Option_t* choptin)
{
if(gPad->GetLogx() || gPad->GetLogy()){
Error("MakeChopt", "logarithmic X/Y axis is not supported.");
}
char *l;
char chopt[128];
Int_t nch = strlen(choptin);
strcpy(chopt,choptin);
Healoption.Axis = Healoption.Heal = Healoption.Same = Healoption.Func =
Healoption.Scat = Healoption.Color = Healoption.Contour = Healoption.Logz =
Healoption.Lego = Healoption.Surf = Healoption.Off = Healoption.Tri =
Healoption.AxisPos = Healoption.Box = 0;
Healoption.List = 0;
Healoption.Zscale = 0;
Healoption.FrontBox = 1;
Healoption.BackBox = 1;
Healoption.System = kThetaPhi;
Healoption.Proj = kEquirect;
Healoption.Xinv = 0;
Healoption.Yinv = 0;
Healoption.HighRes = 0;
Healoption.Zero = 0;
MakeCuts(chopt);
for (Int_t i = 0;i < nch; i++) chopt[i] = toupper(chopt[i]);
Healoption.Scat = 1;
if(!nch) Healoption.Heal = 1;
if(fFunctions->First()) Healoption.Func = 2;
l = strstr(chopt,"GL");
if (l) {
strncpy(l," ",2);
}
l = strstr(chopt,"X+");
if (l) {
Healoption.AxisPos = 10;
strncpy(l," ",2);
}
l = strstr(chopt,"Y+");
if (l) {
Healoption.AxisPos += 1;
strncpy(l," ",2);
}
if((Healoption.AxisPos == 10 || Healoption.AxisPos == 1) && (nch == 2)) Healoption.Heal = 1;
if(Healoption.AxisPos == 11 && nch == 4) Healoption.Heal = 1;
l = strstr(chopt, "THETAPHI");
if(l){
if(nch == 8) Healoption.Heal = 1;
Healoption.System = kThetaPhi;
strncpy(l, " ", 8);
}
l = strstr(chopt, "GALACTIC");
if(l){
if(nch == 8) Healoption.Heal = 1;
Healoption.System = kGalactic;
strncpy(l, " ", 8);
}
l = strstr(chopt, "CELESTIAL");
if(l){
if(nch == 9) Healoption.Heal = 1;
Healoption.System = kCelestial;
strncpy(l, " ", 9);
}
l = strstr(chopt, "LATLONG");
if(l){
if(nch == 7) Healoption.Heal = 1;
Healoption.System = kLatLong;
strncpy(l, " ", 7);
}
l = strstr(chopt, "EQUIRECT");
if(l){
if(nch == 8) Healoption.Heal = 1;
Healoption.Proj = kEquirect;
strncpy(l, " ", 8);
}
l = strstr(chopt, "HAMMER");
if(l){
if(nch == 6) Healoption.Heal = 1;
Healoption.Proj = kHammer;
strncpy(l, " ", 6);
}
l = strstr(chopt, "LAMBERT1");
if(l){
if(nch == 8) Healoption.Heal = 1;
Healoption.Proj = kLambert;
strncpy(l, " ", 8);
}
l = strstr(chopt, "LAMBERT2");
if(l){
if(nch == 8) Healoption.Heal = 1;
Healoption.Proj = kLambert + 10;
strncpy(l, " ", 8);
}
l = strstr(chopt, "LAMBERT");
if(l){
if(nch == 7) Healoption.Heal = 1;
Healoption.Proj = kLambert;
strncpy(l, " ", 7);
}
l = strstr(chopt, "POLAR1");
if(l){
if(nch == 6) Healoption.Heal = 1;
Healoption.Proj = kPolar;
strncpy(l, " ", 6);
}
l = strstr(chopt, "POLAR2");
if(l){
if(nch == 6) Healoption.Heal = 1;
Healoption.Proj = kPolar + 10;
strncpy(l, " ", 6);
}
l = strstr(chopt, "POLAR");
if(l){
if(nch == 5) Healoption.Heal = 1;
Healoption.Proj = kPolar;
strncpy(l, " ", 5);
}
l = strstr(chopt, "XINV");
if(l){
if(nch == 4) Healoption.Heal = 1;
Healoption.Xinv = 1;
strncpy(l, " ", 4);
}
l = strstr(chopt, "YINV");
if(l){
if(nch == 4) Healoption.Heal = 1;
Healoption.Yinv = 1;
strncpy(l, " ", 4);
}
l = strstr(chopt,"SAMES");
if (l) {
if (nch == 5) Healoption.Heal = 1;
Healoption.Same = 2;
strncpy(l," ",5);
}
l = strstr(chopt,"SAME");
if (l) {
if (nch == 4) Healoption.Heal = 1;
Healoption.Same = 1;
strncpy(l," ",4);
}
l = strstr(chopt,"LEGO");
if (l) {
Healoption.Scat = 0;
Healoption.Lego = 1; strncpy(l," ",4);
if (l[4] == '1') { Healoption.Lego = 11; l[4] = ' '; }
if (l[4] == '2') { Healoption.Lego = 12; l[4] = ' '; }
l = strstr(chopt,"FB"); if (l) { Healoption.FrontBox = 0; strncpy(l," ",2); }
l = strstr(chopt,"BB"); if (l) { Healoption.BackBox = 0; strncpy(l," ",2); }
l = strstr(chopt,"0"); if (l) { Healoption.Zero = 1; strncpy(l," ",1); }
}
l = strstr(chopt,"SURF");
if (l) {
Healoption.Scat = 0;
Healoption.Surf = 1; strncpy(l," ",4);
if (l[4] == '1') { Healoption.Surf = 11; l[4] = ' '; }
if (l[4] == '2') { Healoption.Surf = 12; l[4] = ' '; }
if (l[4] == '3') { Healoption.Surf = 13; l[4] = ' '; }
if (l[4] == '4') { Healoption.Surf = 14; l[4] = ' '; }
if (l[4] == '5') { Healoption.Surf = 15; l[4] = ' '; }
if (l[4] == '6') { Healoption.Surf = 16; l[4] = ' '; }
l = strstr(chopt,"FB"); if (l) { Healoption.FrontBox = 0; strncpy(l," ",2); }
l = strstr(chopt,"BB"); if (l) { Healoption.BackBox = 0; strncpy(l," ",2); }
}
l = strstr(chopt,"LIST"); if (l) { Healoption.List = 1; strncpy(l," ",4);}
l = strstr(chopt,"CONT");
if (l) {
Healoption.Scat = 0;
Healoption.Contour = 1; strncpy(l," ",4);
if (l[4] == '1') { Healoption.Contour = 11; l[4] = ' '; }
if (l[4] == '2') { Healoption.Contour = 12; l[4] = ' '; }
if (l[4] == '3') { Healoption.Contour = 13; l[4] = ' '; }
if (l[4] == '4') { Healoption.Contour = 14; l[4] = ' '; }
if (l[4] == '5') { Healoption.Contour = 15; l[4] = ' '; }
}
l = strstr(chopt,"BOX" ); if (l) { Healoption.Box = 1; strncpy(l," ",3); }
l = strstr(chopt,"COLZ"); if (l) { Healoption.Color = 2; strncpy(l," ",4); Healoption.Scat = 0; Healoption.Zscale = 1;}
l = strstr(chopt,"COL" ); if (l) { Healoption.Color = 1; strncpy(l," ", 3); Healoption.Scat = 0; }
l = strstr(chopt,"FUNC"); if (l) { Healoption.Func = 2; strncpy(l," ",4); Healoption.Heal = 0; }
l = strstr(chopt,"HEAL"); if (l) { Healoption.Heal = 2; strncpy(l," ",4); Healoption.Func = 0;}
l = strstr(chopt,"AXIS"); if (l) { Healoption.Axis = 1; strncpy(l," ",4); }
l = strstr(chopt,"AXIG"); if (l) { Healoption.Axis = 2; strncpy(l," ",4); }
l = strstr(chopt,"SCAT"); if (l) { Healoption.Scat = 1; strncpy(l," ",4); }
if (strstr(chopt,"A")) Healoption.Axis = -1;
if (strstr(chopt,"][")) {Healoption.Off =1; Healoption.Heal =1;}
if (strstr(chopt,"Z")) Healoption.Zscale =1;
if (strstr(chopt,"H")) Healoption.Heal =2;
if (strstr(chopt,"9")) Healoption.HighRes = 1;
if (Healoption.Surf == 15) {
if (Healoption.System == kPOLAR || Healoption.System == kCARTESIAN) {
Healoption.Surf = 13;
Warning("MakeChopt","option SURF5 is not supported in Cartesian and Polar modes");
}
}
Healoption.Logz = gPad->GetLogz();
return 1;
}
Int_t THealPainter::MakeCuts(char* choptin)
{
fNcuts = 0;
char *left = (char*)strchr(choptin,'[');
if (!left) return 0;
char *right = (char*)strchr(choptin,']');
if (!right) return 0;
Int_t nch = right-left;
if (nch < 2) return 0;
char *cuts = left+1;
*right = 0;
char *comma, *minus;
Int_t i;
while(1) {
comma = strchr(cuts,',');
if (comma) *comma = 0;
minus = strchr(cuts,'-');
if (minus) cuts = minus+1;
while (*cuts == ' ') cuts++;
Int_t nc = strlen(cuts);
while (cuts[nc-1] == ' ') {cuts[nc-1] = 0; nc--;}
TIter next(gROOT->GetListOfSpecials());
TCutG *cut=0;
TObject *obj;
while ((obj = next())) {
if (!obj->InheritsFrom(TCutG::Class())) continue;
if (strcmp(obj->GetName(),cuts)) continue;
cut = (TCutG*)obj;
break;
}
if (cut) {
fCuts[fNcuts] = cut;
fCutsOpt[fNcuts] = 1;
if (minus) fCutsOpt[fNcuts] = -1;
fNcuts++;
}
if (!comma) break;
cuts = comma+1;
}
for (i=0;i<=nch;i++) left[i] = ' ';
return fNcuts;
}
void THealPainter::Paint(Option_t* option)
{
THealPix* oldheal = gCurrentHeal;
gCurrentHeal = fHeal;
THealPix* healsave = fHeal;
Double_t minsav = fHeal->GetMinimumStored();
if(!MakeChopt(option)){
return;
}
if(Healoption.Proj%10 == kLambert || Healoption.Proj%10 == kPolar){
fXaxis->Set(1, -180., 180.);
fYaxis->Set(1, -180., 180.);
} else {
if(Healoption.System == kThetaPhi){
fXaxis->Set(1, 0., 360.);
fYaxis->Set(1, 0., 180.);
} else if(Healoption.System == kGalactic || Healoption.System == kLatLong){
fXaxis->Set(1, -180., 180.);
fYaxis->Set(1, -90., 90.);
} else if(Healoption.System == kCelestial){
fXaxis->Set(1, 0., 360.);
fYaxis->Set(1, -90., 90.);
}
}
fXbuf = new Double_t[kNMAX];
fYbuf = new Double_t[kNMAX];
TView* view = gPad->GetView();
if(view){
if(!Healoption.Lego && !Healoption.Surf && !Healoption.Tri){
delete view;
gPad->SetView(0);
}
}
PaintTable(option);
fHeal->SetMinimum(minsav);
if(Healoption.Func){
Healoption_t hoptsave = Healoption;
Hparam_t hparsave = Healparam;
PaintFunction(option);
SetHealPix(healsave);
Healoption = hoptsave;
Healparam = hparsave;
}
gCurrentHeal = oldheal;
delete [] fXbuf;
delete [] fYbuf;
}
void THealPainter::PaintAxis(Bool_t drawGridOnly)
{
if(Healoption.Axis == -1){
return;
}
if(Healoption.Same && Healoption.Axis <= 0){
return;
}
static char chopt[10] = "";
Double_t gridl = 0;
Int_t ndiv, ndivsave;
Int_t useHealparam = 0;
Double_t umin, umax, uminsave, umaxsave;
Short_t xAxisPos = Healoption.AxisPos/10;
Short_t yAxisPos = Healoption.AxisPos - 10*xAxisPos;
Double_t axmin = gPad->GetUxmin();
Double_t axmax = gPad->GetUxmax();
Double_t aymin = gPad->GetUymin();
Double_t aymax = gPad->GetUymax();
char* cw = 0;
TGaxis axis;
if(Healoption.Contour == 14){
useHealparam = 1;
}
if(Healoption.Same){
TObject *obj;
TIter next(gPad->GetListOfPrimitives());
while((obj = next())){
if(strstr(obj->GetDrawOption(), "cont4")){
useHealparam = 1;
break;
}
}
}
Int_t ndivx = fXaxis->GetNdivisions();
if (ndivx > 1000) {
Int_t nx2 = ndivx/100;
Int_t nx1 = TMath::Max(1, ndivx%100);
ndivx = 100*nx2 + Int_t(Float_t(nx1)*gPad->GetAbsWNDC());
}
axis.SetTextAngle(0);
axis.ImportAxisAttributes(fXaxis);
chopt[0] = 0;
strcat(chopt, "SDH");
if (ndivx < 0) strcat(chopt, "N");
if (gPad->GetGridx()) {
gridl = (aymax-aymin)/(gPad->GetY2() - gPad->GetY1());
strcat(chopt, "W");
}
ndiv = TMath::Abs(ndivx);
if (useHealparam) {
umin = Healparam.xmin;
umax = Healparam.xmax;
} else {
umin = axmin;
umax = axmax;
}
if (fXaxis->GetTimeDisplay()) {
strcat(chopt,"t");
if (strlen(fXaxis->GetTimeFormatOnly()) == 0) {
axis.SetTimeFormat(fXaxis->ChooseTimeFormat(Healparam.xmax-Healparam.xmin));
}
}
Double_t xAxisYPos1, xAxisYPos2;
if (xAxisPos == 1) {
xAxisYPos1 = aymax;
xAxisYPos2 = aymin;
} else {
xAxisYPos1 = aymin;
xAxisYPos2 = aymax;
}
uminsave = umin;
umaxsave = umax;
ndivsave = ndiv;
axis.SetOption(chopt);
if (xAxisPos) {
strcat(chopt, "-");
gridl = -gridl;
}
axis.PaintAxis(axmin, xAxisYPos1,
axmax, xAxisYPos1,
umin, umax, ndiv, chopt, gridl, drawGridOnly);
if (gPad->GetTickx()) {
if (xAxisPos) {
cw=strstr(chopt,"-");
*cw='z';
} else {
strcat(chopt, "-");
}
if (gPad->GetTickx() < 2) strcat(chopt, "U");
if ((cw=strstr(chopt,"W"))) *cw='z';
axis.SetTitle("");
axis.PaintAxis(axmin, xAxisYPos2,
axmax, xAxisYPos2,
uminsave, umaxsave, ndivsave, chopt, gridl, drawGridOnly);
}
Int_t ndivy = fYaxis->GetNdivisions();
axis.ImportAxisAttributes(fYaxis);
chopt[0] = 0;
strcat(chopt, "SDH");
if (ndivy < 0) strcat(chopt, "N");
if (gPad->GetGridy()) {
gridl = (axmax-axmin)/(gPad->GetX2() - gPad->GetX1());
strcat(chopt, "W");
}
ndiv = TMath::Abs(ndivy);
if (useHealparam) {
umin = Healparam.ymin;
umax = Healparam.ymax;
} else {
umin = aymin;
umax = aymax;
}
if (fYaxis->GetTimeDisplay()) {
strcat(chopt,"t");
if (strlen(fYaxis->GetTimeFormatOnly()) == 0) {
axis.SetTimeFormat(fYaxis->ChooseTimeFormat(Healparam.ymax-Healparam.ymin));
}
}
Double_t yAxisXPos1, yAxisXPos2;
if (yAxisPos == 1) {
yAxisXPos1 = axmax;
yAxisXPos2 = axmin;
} else {
yAxisXPos1 = axmin;
yAxisXPos2 = axmax;
}
uminsave = umin;
umaxsave = umax;
ndivsave = ndiv;
axis.SetOption(chopt);
if (yAxisPos) {
strcat(chopt, "+L");
gridl = -gridl;
}
axis.PaintAxis(yAxisXPos1, aymin,
yAxisXPos1, aymax,
umin, umax, ndiv, chopt, gridl, drawGridOnly);
if (gPad->GetTicky()) {
if (gPad->GetTicky() < 2) {
strcat(chopt, "U");
axis.SetTickSize(-fYaxis->GetTickLength());
} else {
strcat(chopt, "+L");
}
if ((cw=strstr(chopt,"W"))) *cw='z';
axis.SetTitle("");
axis.PaintAxis(yAxisXPos2, aymin,
yAxisXPos2, aymax,
uminsave, umaxsave, ndivsave, chopt, gridl, drawGridOnly);
}
}
void THealPainter::PaintColorLevels(Option_t* option)
{
Double_t zmin = fHeal->GetMinimum();
Double_t zmax = fHeal->GetMaximum();
if(Healoption.Logz){
if(zmin > 0){
zmin = TMath::Log10(zmin);
zmax = TMath::Log10(zmax);
} else {
return;
}
}
Double_t dz = zmax - zmin;
if(dz <= 0){
return;
}
Style_t fillsav = fHeal->GetFillStyle();
Style_t colsav = fHeal->GetFillColor();
fHeal->SetFillStyle(1001);
fHeal->TAttFill::Modify();
Int_t ncolors = gStyle->GetNumberOfColors();
Int_t ndiv = fHeal->GetContour();
if(ndiv == 0){
ndiv = gStyle->GetNumberContours();
fHeal->SetContour(ndiv);
}
Int_t ndivz = TMath::Abs(ndiv);
if(fHeal->TestBit(THealPix::kUserContour) == 0){
fHeal->SetContour(ndiv);
}
Double_t scale = ndivz/dz;
Int_t color;
Double_t xmin = gPad->GetUxmin();
Double_t xmax = gPad->GetUxmax();
Double_t ymin = gPad->GetUymin();
Double_t ymax = gPad->GetUymax();
for(Int_t bin = 0; bin < fHeal->GetNpix(); bin++){
Double_t z = fHeal->GetBinContent(bin);
if(z == 0 && (zmin >= 0 || Healoption.Logz)){
continue;
}
if(Healoption.Logz){
z = z > 0 ? TMath::Log10(z) : zmin;
}
if(z < zmin){
continue;
}
Int_t n;
Double_t x[5], y[5], xdiv[5], ydiv[5];
Bool_t used[5];
Bool_t divided = false;
if(!Vertices(bin, n, x, y, xdiv, ydiv, used, divided, xmin, xmax, ymin, ymax)){
continue;
}
if(fHeal->TestBit(THealPix::kUserContour)){
Double_t zc = fHeal->GetContourLevelPad(0);
if (z < zc) continue;
color = -1;
for(Int_t k = 0; k < ndiv; k++){
zc = fHeal->GetContourLevelPad(k);
if(z < zc){
continue;
} else {
color++;
}
}
} else {
color = Int_t(0.01 + (z - zmin)*scale);
}
Int_t theColor = Int_t((color + 0.99)*Float_t(ncolors)/Float_t(ndivz));
if(theColor > ncolors - 1){
theColor = ncolors - 1;
}
fHeal->SetFillColor(gStyle->GetColorPalette(theColor));
fHeal->TAttFill::Modify();
gPad->PaintFillArea(n, x, y);
if(divided) gPad->PaintFillArea(n, xdiv, ydiv);
}
if(Healoption.Zscale){
PaintPalette();
}
fHeal->SetFillStyle(fillsav);
fHeal->SetFillColor(colsav);
fHeal->TAttFill::Modify();
}
void THealPainter::PaintBoxes(Option_t* option)
{
Double_t xmin = gPad->GetUxmin();
Double_t xmax = gPad->GetUxmax();
Double_t ymin = gPad->GetUymin();
Double_t ymax = gPad->GetUymax();
Double_t zmin = fHeal->GetMinimum();
Double_t zmax = fHeal->GetMaximum();
if(Healoption.Logz){
if(zmin > 0){
zmin = TMath::Log10(zmin*0.1);
zmax = TMath::Log10(zmax);
} else {
return;
}
} else {
zmax = TMath::Max(TMath::Abs(zmin), TMath::Abs(zmax));
zmin = 0;
}
if(Healoption.Same){
THealPix* heal;
TIter next(gPad->GetListOfPrimitives());
while((heal = (THealPix*)next())) {
if(!heal->InheritsFrom(THealPix::Class())) continue;
zmin = heal->GetMinimum();
zmax = heal->GetMaximum();
if(Healoption.Logz){
zmax = TMath::Log10(zmax);
if(zmin <= 0){
zmin = TMath::Log10(zmax*0.001);
} else {
zmin = TMath::Log10(zmin);
}
}
break;
}
}
Double_t zratio, dz = zmax - zmin;
for(Int_t bin = 0; bin < fHeal->GetNpix(); bin++){
Double_t z = fHeal->GetBinContent(bin);
if(z == 0 && (zmin >= 0 || Healoption.Logz)){
continue;
}
if(Healoption.Logz){
z = z > 0 ? TMath::Log10(z) : zmin;
}
if(z < zmin){
continue;
}
Int_t n;
Double_t x[6], y[6], xdiv[6], ydiv[6];
Bool_t used[5];
Bool_t divided = false;
if(!Vertices(bin, n, x, y, xdiv, ydiv, used, divided, xmin, xmax, ymin, ymax)){
continue;
}
x[n] = x[0];
y[n] = y[0];
gPad->PaintPolyLine(n + 1, x, y);
if(divided){
xdiv[n] = xdiv[0];
ydiv[n] = ydiv[0];
gPad->PaintPolyLine(n + 1, xdiv, ydiv);
}
}
}
void THealPainter::PaintContour(Option_t* option)
{
}
void THealPainter::PaintFrame()
{
if(Healoption.Same){
return;
}
RecalculateRange();
if(Healoption.Lego || Healoption.Surf || Healoption.Tri ||
Healoption.Contour == 14) {
TObject* frame = gPad->FindObject("TFrame");
if(frame){
gPad->GetListOfPrimitives()->Remove(frame);
}
return;
}
gPad->PaintPadFrame(Healparam.xmin, Healparam.ymin, Healparam.xmax, Healparam.ymax);
}
void THealPainter::PaintFunction(Option_t*)
{
TObjOptLink* lnk = (TObjOptLink*)fFunctions->FirstLink();
TObject* obj;
while(lnk){
obj = lnk->GetObject();
TVirtualPad *padsave = gPad;
if(obj->InheritsFrom(TF1::Class())){
if (obj->TestBit(TF1::kNotDraw) == 0) obj->Paint("lsame");
} else {
obj->Paint(lnk->GetOption());
}
lnk = (TObjOptLink*)lnk->Next();
padsave->cd();
}
}
void THealPainter::PaintLego(Option_t* option)
{
}
void THealPainter::PaintPalette()
{
THealPaletteAxis* palette = (THealPaletteAxis*)fFunctions->FindObject("palette");
TView* view = gPad->GetView();
if(palette){
if(view){
if(!palette->TestBit(THealPaletteAxis::kHasView)) {
delete palette;
palette = 0;
}
} else {
if(palette->TestBit(THealPaletteAxis::kHasView)){
delete palette; palette = 0;
}
}
}
if(!palette){
Double_t xup = gPad->GetUxmax();
Double_t x2 = gPad->PadtoX(gPad->GetX2());
Double_t ymin = gPad->PadtoY(gPad->GetUymin());
Double_t ymax = gPad->PadtoY(gPad->GetUymax());
Double_t xr = 0.05*(gPad->GetX2() - gPad->GetX1());
Double_t xmin = gPad->PadtoX(xup + 0.1*xr);
Double_t xmax = gPad->PadtoX(xup + xr);
if(xmax > x2){
xmax = gPad->PadtoX(gPad->GetX2() - 0.01*xr);
}
palette = new THealPaletteAxis(xmin, ymin, xmax, ymax, fHeal);
palette->Paint();
}
}
void THealPainter::PaintScatterPlot(Option_t* option)
{
}
void THealPainter::PaintStat(Int_t dostat, TF1* fit)
{
}
void THealPainter::PaintSurface(Option_t* option)
{
}
void THealPainter::PaintTable(Option_t* option)
{
if(!TableInit()){
return;
}
PaintFrame();
if(fHeal->GetEntries() != 0 && Healoption.Axis <= 0){
if(Healoption.Scat) PaintScatterPlot(option);
if(Healoption.Box) PaintBoxes(option);
if(Healoption.Color) PaintColorLevels(option);
if(Healoption.Contour) PaintContour(option);
}
if(Healoption.Lego) PaintLego(option);
if(Healoption.Surf && !Healoption.Contour) PaintSurface(option);
if(Healoption.Tri) PaintTriangles(option);
if(!Healoption.Lego && !Healoption.Surf && !Healoption.Tri) PaintAxis(kFALSE);
PaintTitle();
TF1* fit = 0;
TIter next(fFunctions);
TObject *obj;
while((obj = next())){
if (obj->InheritsFrom(TF1::Class())) {
fit = (TF1*)obj;
break;
}
}
if(Healoption.Same != 1){
if (!fHeal->TestBit(THealPix::kNoStats)) {
PaintStat(gStyle->GetOptStat(), fit);
}
}
}
void THealPainter::PaintTitle()
{
if(Healoption.Same){
return;
}
if(fHeal->TestBit(THealPix::kNoTitle)){
return;
}
Int_t nt = strlen(fHeal->GetTitle());
TPaveText* title = 0;
TObject* obj;
TIter next(gPad->GetListOfPrimitives());
while((obj = next())) {
if(!obj->InheritsFrom(TPaveText::Class())){
continue;
}
title = (TPaveText*)obj;
if(strcmp(title->GetName(), "title")){
title = 0;
continue;
}
break;
}
if(nt == 0 || gStyle->GetOptTitle() <= 0){
if(title){
delete title;
}
return;
}
Double_t ht = gStyle->GetTitleH();
Double_t wt = gStyle->GetTitleW();
if(ht <= 0){
ht = 1.1*gStyle->GetTitleFontSize();
}
if(ht <= 0){
ht = 0.05;
}
if(wt <= 0){
TLatex l;
l.SetTextSize(ht);
l.SetTitle(fHeal->GetTitle());
ht = TMath::Max(ht, 1.2*l.GetYsize()/(gPad->GetY2() - gPad->GetY1()));
Double_t wndc = l.GetXsize()/(gPad->GetX2() - gPad->GetX1());
wt = TMath::Min(0.7, 0.02+wndc);
}
if(title){
TText *t0 = (TText*)title->GetLine(0);
if(t0){
if(!strcmp(t0->GetTitle(), fHeal->GetTitle())){
return;
}
t0->SetTitle(fHeal->GetTitle());
if(wt > 0){
title->SetX2NDC(title->GetX1NDC() + wt);
}
}
return;
}
Int_t talh = gStyle->GetTitleAlign()/10;
if(talh < 1){
talh = 1;
if(talh > 3){
talh = 3;
}
}
Int_t talv = gStyle->GetTitleAlign()%10;
if(talv < 1){
talv = 1;
if(talv > 3){
talv = 3;
}
}
Double_t xpos, ypos;
xpos = gStyle->GetTitleX();
ypos = gStyle->GetTitleY();
if(talh == 2) xpos = xpos-wt/2.;
if(talh == 3) xpos = xpos-wt;
if(talv == 2) ypos = ypos+ht/2.;
if(talv == 1) ypos = ypos+ht;
TPaveText *ptitle = new TPaveText(xpos, ypos - ht, xpos + wt, ypos, "blNDC");
ptitle->SetFillColor(gStyle->GetTitleFillColor());
ptitle->SetFillStyle(gStyle->GetTitleStyle());
ptitle->SetName("title");
ptitle->SetBorderSize(gStyle->GetTitleBorderSize());
ptitle->SetTextColor(gStyle->GetTitleTextColor());
ptitle->SetTextFont(gStyle->GetTitleFont(""));
if(gStyle->GetTitleFont("")%10 > 2){
ptitle->SetTextSize(gStyle->GetTitleFontSize());
}
ptitle->AddText(fHeal->GetTitle());
ptitle->SetBit(kCanDelete);
ptitle->Draw();
ptitle->Paint();
}
void THealPainter::PaintTriangles(Option_t* option)
{
}
void THealPainter::ProcessMessage(const char *mess, const TObject *obj)
{
}
void THealPainter::RecalculateRange()
{
if(Healoption.Same){
return;
}
Double_t xmin = Healparam.xmin;
Double_t xmax = Healparam.xmax;
Double_t ymin = Healparam.ymin;
Double_t ymax = Healparam.ymax;
Double_t xmin_aid, ymin_aid, xmax_aid, ymax_aid;
if(Healoption.Proj == 1){
} else if(Healoption.Proj == 2){
} else if(Healoption.Proj == 3){
} else if(Healoption.Proj == 4){
}
Healparam.xmin = xmin;
Healparam.xmax = xmax;
Healparam.ymin = ymin;
Healparam.ymax = ymax;
Double_t dx = xmax - xmin;
Double_t dy = ymax - ymin;
Double_t dxr = dx/(1 - gPad->GetLeftMargin() - gPad->GetRightMargin());
Double_t dyr = dy/(1 - gPad->GetBottomMargin() - gPad->GetTopMargin());
gPad->Range(xmin - dxr*gPad->GetLeftMargin(),
ymin - dyr*gPad->GetBottomMargin(),
xmax + dxr*gPad->GetRightMargin(),
ymax + dyr*gPad->GetTopMargin());
gPad->RangeAxis(xmin, ymin, xmax, ymax);
}
void THealPainter::SetHealPix(THealPix* heal)
{
if(heal == 0) return;
fHeal = heal;
fXaxis = heal->GetXaxis();
fYaxis = heal->GetYaxis();
fZaxis = heal->GetZaxis();
fFunctions = fHeal->GetListOfFunctions();
}
Int_t THealPainter::TableInit()
{
static const char* where = "TableInit";
Int_t first, last;
Double_t yMARGIN = gStyle->GetHistTopMargin();
Double_t zmin, zmax;
Int_t maximum = 0;
Int_t minimum = 0;
if(fHeal->GetMaximumStored() != -1111) maximum = 1;
if(fHeal->GetMinimumStored() != -1111) minimum = 1;
first = fXaxis->GetFirst();
last = fXaxis->GetLast();
Healparam.xlast = last;
Healparam.xfirst = first;
Healparam.xlowedge = fXaxis->GetBinLowEdge(first);
Healparam.xbinsize = fXaxis->GetBinWidth(first);
Healparam.xmin = Healparam.xlowedge;
Healparam.xmax = fXaxis->GetBinLowEdge(last) + fXaxis->GetBinWidth(last);
first = fYaxis->GetFirst();
last = fYaxis->GetLast();
Healparam.ylast = last;
Healparam.yfirst = first;
Healparam.ylowedge = fYaxis->GetBinLowEdge(first);
Healparam.ybinsize = fYaxis->GetBinWidth(first);
if(!Healparam.ybinsize){
Healparam.ybinsize = 1;
}
Healparam.ymin = Healparam.ylowedge;
Healparam.ymax = fYaxis->GetBinLowEdge(last) + fYaxis->GetBinWidth(last);
Double_t bigp = TMath::Power(10, 32);
zmax = -bigp;
zmin = bigp;
Double_t allchan = 0;
for(Int_t i = 0; i <= fHeal->GetNpix(); i++){
Double_t c1 = fHeal->GetBinContent(i);
zmax = TMath::Max(zmax,c1);
zmin = TMath::Min(zmin, c1);
allchan += c1;
}
if(maximum) zmax = fHeal->GetMaximumStored();
if(minimum) zmin = fHeal->GetMinimumStored();
if(Healoption.Logz && zmax <= 0) {
if(!Healoption.Same){
Error(where, "log scale is requested but maximum is less or equal 0 (%f)", zmax);
}
return 0;
}
if(zmin >= zmax){
if(Healoption.Logz){
if(zmax > 0){
zmin = 0.001*zmax;
} else {
if(!Healoption.Same){
Error(where, "log scale is requested but maximum is less or equal 0 (%f)", zmax);
}
return 0;
}
}
}
Healparam.allchan = allchan;
Double_t factor = allchan;
if(fHeal->GetNormFactor() > 0) factor = fHeal->GetNormFactor();
if(allchan) factor /= allchan;
if(factor == 0) factor = 1;
Healparam.factor = factor;
zmax = factor*zmax;
zmin = factor*zmin;
Double_t c1 = zmax;
if(TMath::Abs(zmin) > TMath::Abs(c1)){
c1 = zmin;
}
if(Healoption.Logz){
if(zmin <= 0){
zmin = TMath::Min((Double_t)1, (Double_t)0.001*zmax);
fHeal->SetMinimum(zmin);
}
zmin = TMath::Log10(zmin);
if(!minimum){
zmin += TMath::Log10(0.5);
}
zmax = TMath::Log10(zmax);
if(!maximum){
zmax += TMath::Log10(2*(0.9/0.95));
}
goto LZMIN;
}
if(!maximum){
zmax += yMARGIN*(zmax - zmin);
}
if(!minimum){
if(gStyle->GetHistMinimumZero()){
if(zmin >= 0){
zmin = 0;
} else {
zmin -= yMARGIN*(zmax - zmin);
}
} else {
Double_t dzmin = yMARGIN*(zmax - zmin);
if(zmin >= 0 && (zmin - dzmin <= 0)){
zmin = 0;
} else {
zmin -= dzmin;
}
}
}
LZMIN:
Healparam.zmin = zmin;
Healparam.zmax = zmax;
Healparam.baroffset = fHeal->GetBarOffset();
Healparam.barwidth = fHeal->GetBarWidth();
return 1;
}
Bool_t THealPainter::Vertices(Int_t bin, Int_t& n, Double_t* x, Double_t* y,
Double_t* xdiv, Double_t* ydiv,
Bool_t* used, Bool_t& divided,
Double_t xmin, Double_t xmax,
Double_t ymin, Double_t ymax)
{
Double_t theta, phi;
fHeal->GetBinCenter(bin, theta, phi);
if(!fHeal->IsDegree()){
theta *= TMath::RadToDeg();
phi *= TMath::RadToDeg();
}
if(Healoption.System == kGalactic || Healoption.System == kLatLong){
theta = 90 - theta;
phi -= 180;
} else if(Healoption.System == kCelestial){
theta = 90 - theta;
}
if(!IsInside(phi, theta)){
return false;
}
for(Int_t i = 0; i < 5; i++) used[i] = true;
n = fHeal->GetBinVertices(bin, x, y);
if(Healoption.System == kGalactic || Healoption.System == kLatLong){
if(x[0] >= 180. && x[1] >= 180. && x[2] >= 180. && x[3] >= 180. &&
(n == 4 || (n == 5 && x[4] >= 180.))){
for(Int_t j = 0; j < n; j++){
x[j] -= 360.;
}
}
for(Int_t j = 0; j < n; j++){
y[j] = 90. - y[j];
}
} else if(Healoption.System == kCelestial){
for(Int_t j = 0; j < n; j++){
y[j] = 90. - y[j];
}
}
if(Healoption.Proj == kHammer){
if(Healoption.System == kGalactic || Healoption.System == kLatLong){
for(Int_t j = 0; j < n; j++){
Double_t lng = x[j]*d2r;
Double_t lat = y[j]*d2r;
x[j] = 180*TMath::Cos(lat)*TMath::Sin(lng/2.)
/TMath::Sqrt(1. + TMath::Cos(lat)*TMath::Cos(lng/2.));
y[j] = 90.*TMath::Sin(lat)
/TMath::Sqrt(1. + TMath::Cos(lat)*TMath::Cos(lng/2.));
if(x[j] > 180*TMath::Cos(lat) || x[j] < -180*TMath::Cos(lat)) used[j] = false;
}
} else if(Healoption.System == kCelestial){
for(Int_t j = 0; j < n; j++){
Double_t lng = (x[j] - 180.)*d2r;
Double_t lat = y[j]*d2r;
x[j] = 180. + 180*TMath::Cos(lat)*TMath::Sin(lng/2.)
/TMath::Sqrt(1. + TMath::Cos(lat)*TMath::Cos(lng/2.));
y[j] = 90.*TMath::Sin(lat)
/TMath::Sqrt(1. + TMath::Cos(lat)*TMath::Cos(lng/2.));
if(x[j] > 180. + 180*TMath::Cos(lat) || x[j] < 180. - 180*TMath::Cos(lat)) used[j] = false;
}
} else {
for(Int_t j = 0; j < n; j++){
Double_t lng = (x[j] - 180.)*d2r;
Double_t lat = (90. - y[j])*d2r;
x[j] = 180. + 180*TMath::Cos(lat)*TMath::Sin(lng/2.)
/TMath::Sqrt(1. + TMath::Cos(lat)*TMath::Cos(lng/2.));
y[j] = 90. - 90.*TMath::Sin(lat)
/TMath::Sqrt(1. + TMath::Cos(lat)*TMath::Cos(lng/2.));
if(x[j] > 180. + 180*TMath::Cos(lat) || x[j] < 180. - 180*TMath::Cos(lat)) used[j] = false;
}
}
} else if(Healoption.Proj == kLambert + 10){
for(Int_t j = 0; j < n; j++){
Double_t sint = TMath::Sin(y[j]*d2r);
Double_t z = TMath::Cos(y[j]*d2r);
Double_t tmp = (z < 1) ? 180.*sint/TMath::Sqrt(2.*(1 - z)) : 180.;
x[j] = tmp*TMath::Cos(x[j]*d2r);
y[j] = tmp*TMath::Sin(x[j]*d2r);
}
} else if(Healoption.Proj == kLambert){
for(Int_t j = 0; j < n; j++){
Double_t y_ = (180. - y[j])*d2r;
Double_t sint = TMath::Sin(y_);
Double_t z = TMath::Cos(y_);
Double_t tmp = (z < 1) ? 180.*sint/TMath::Sqrt(2.*(1 - z)) : 180.;
x[j] = tmp*TMath::Cos(x[j]*d2r);
y[j] = tmp*TMath::Sin(x[j]*d2r);
}
} else if(Healoption.Proj == kPolar + 10){
for(Int_t j = 0; j < n; j++){
Double_t r = 180. - y[j];
Double_t phi = x[j]*d2r;
x[j] = r*TMath::Cos(phi);
y[j] = r*TMath::Sin(phi);
}
} else if(Healoption.Proj == kPolar){
for(Int_t j = 0; j < n; j++){
Double_t r = y[j];
Double_t phi = x[j]*d2r;
x[j] = r*TMath::Cos(phi);
y[j] = r*TMath::Sin(phi);
}
} else {
if(Healoption.System == kGalactic || Healoption.System == kLatLong){
for(Int_t j = 0; j < n; j++){
if(x[j] > 180. || x[j] < -180.) used[j] = false;
}
} else if(Healoption.System == kCelestial){
for(Int_t j = 0; j < n; j++){
if(x[j] > 360. || x[j] < 0.) used[j] = false;
}
} else {
for(Int_t j = 0; j < n; j++){
if(x[j] > 360. || x[j] < 0.) used[j] = false;
}
}
}
if(Healoption.Xinv == 1){
for(Int_t j = 0; j < n; j++){
x[j] = -x[j] + xmax + xmin;
}
}
if(Healoption.Yinv == 1){
for(Int_t j = 0; j < n; j++){
y[j] = -y[j] + ymax + ymin;
}
}
Bool_t isInsidePlotArea = kFALSE;
for(Int_t i = 0; i < n; i++){
if(xmin <= x[i] && x[i] <= xmax && ymin <= y[i] && y[i] <= ymax){
isInsidePlotArea |= kTRUE;
break;
}
}
if(!isInsidePlotArea){
return false;
}
Int_t nSav = n;
for(Int_t i = 0; i < nSav; i++){
if(!used[i]){
divided = true;
for(Int_t j = i; j < nSav - 1; j++){
x[j] = x[j+1];
y[j] = y[j+1];
}
for(Int_t j = 0; j < nSav - 1; j++){
xdiv[j] = -1.*x[j];
ydiv[j] = y[j];
if(Healoption.System != kGalactic && Healoption.System != kLatLong) xdiv[j] += 360.;
}
n--;
break;
}
}
return true;
}