1 #include "AntarcticaBackground.h" 2 #include "TGraphAntarctica.h" 3 #include "TVirtualPad.h" 4 #include "TPaletteAxis.h" 7 #include "TObjString.h" 12 #include "TGToolTip.h" 21 static int numAntarcticaBackgrounds = 0;
24 AntarcticaBackground::AntarcticaBackground(RampdemReader::dataSet dataSet, Int_t coarseness)
25 : TProfile2D(), hDummy() {
26 init(dataSet, coarseness);
30 AntarcticaBackground::~AntarcticaBackground(){
42 void AntarcticaBackground::init(RampdemReader::dataSet dataSet, Int_t coarseness){
44 fName = Form(
"%s%d", getDefaultName(), numAntarcticaBackgrounds);
45 numAntarcticaBackgrounds++;
49 fCoarseness = coarseness;
50 needRemakeHist =
true;
60 needRemakeGrid =
true;
66 TString palSetterName = TString::Format(
"%sPalSetter", fName.Data());
67 fPalSetter =
new TExec(palSetterName,Form(
"%s->setPalette()", fName.Data()));
68 TString palUnsetterName = TString::Format(
"%sPalSetter", fName.Data());
69 fPalUnsetter =
new TExec(palUnsetterName,Form(
"%s->unsetPalette()", fName.Data()));
73 hDummy.SetBins(2, -9e30, -8e30, 1, -9e30, -8e30);
74 fShowColorAxis =
true;
77 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) 78 palettes[RampdemReader::rampdem] = kLightTerrain;
79 palettes[RampdemReader::bed] = kLake;
80 palettes[RampdemReader::icemask_grounded_and_shelves] = kLightTerrain;
81 palettes[RampdemReader::surface] = kLightTerrain;
82 palettes[RampdemReader::thickness] = kRedBlue;
87 fDrawBasesOnTop =
true;
92 void AntarcticaBackground::setPalette(){
95 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) 98 std::map<RampdemReader::dataSet, EColorPalette>::iterator it = palettes.find(fDataSet);
100 if(it != palettes.end()){
103 fOldPalette.resize(gStyle->GetNumberOfColors());
104 for(UInt_t i=0; i < fOldPalette.size(); i++){
105 fOldPalette[i] = gStyle->GetColorPalette(i);
107 fOldGrayScale = TColor::IsGrayscale();
109 TColor::SetGrayscale(fGrayScale);
110 gStyle->SetPalette(it->second,0,opacity);
113 std::cerr << __PRETTY_FUNCTION__ <<
" requires ROOT version at least 6" << std::endl;
119 void AntarcticaBackground::unsetPalette(){
122 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) 123 TColor::SetGrayscale(fOldGrayScale);
124 if(fOldPalette.size() > 0){
125 gStyle->SetPalette(fOldPalette.size(), &fOldPalette[0]);
130 std::cerr << __PRETTY_FUNCTION__ <<
" requires ROOT version at least 6" << std::endl;
140 void AntarcticaBackground::updateHist(){
146 Int_t firstX = fXaxis.GetFirst();
147 Int_t lastX = fXaxis.GetLast();
148 Int_t firstY = fYaxis.GetFirst();
149 Int_t lastY = fYaxis.GetLast();
151 Double_t lowX = fXaxis.GetBinLowEdge(firstX);
152 Double_t highX = fXaxis.GetBinUpEdge(lastX);
153 Double_t lowY = fXaxis.GetBinLowEdge(firstY);
154 Double_t highY = fXaxis.GetBinUpEdge(lastY);
161 Double_t xMin, xMax, yMin, yMax;
171 for(
int by=0; by <= GetNbinsY() + 1; by++){
172 for(
int bx=0; bx <= GetNbinsX() + 1; bx++){
173 SetBinContent(bx, by, 0);
177 SetBins(nx, xMin, xMax, ny, yMin, yMax);
184 for(
int by=1; by <= GetNbinsY(); by++){
185 for(
int bx=1; bx <= GetNbinsX(); bx++){
186 double val = GetBinContent(bx, by);
199 hDummy.SetBinContent(1, fMinVal);
200 hDummy.SetBinContent(2, fMinVal);
201 hDummy.SetMaximum(fMaxVal);
202 hDummy.SetMinimum(fMinVal);
207 fXaxis.SetRangeUser(lowX, highX);
208 fYaxis.SetRangeUser(lowY, highY);
218 GetXaxis()->SetNdivisions(0, kFALSE);
219 GetYaxis()->SetNdivisions(0, kFALSE);
221 needRemakeGrid =
false;
229 Int_t AntarcticaBackground::GetCoarseness()
const{
235 void AntarcticaBackground::SetToolTip(Bool_t toolTip){
236 fUseToolTip = toolTip;
238 if(fToolTip && !fUseToolTip){
244 fToolTip =
new TGToolTip();
245 fToolTip->SetBackgroundColor(kWhite);
250 Bool_t AntarcticaBackground::GetToolTip()
const{
255 void AntarcticaBackground::SetCoarseness(Int_t coarseness){
259 std::cerr <<
"Warning in " << __PRETTY_FUNCTION__ <<
", coarsenesss must be >= 1. Setting coareness = " 260 << AntarcticaBackgroundDefaults::defaultCoarseness << std::endl;
261 coarseness = AntarcticaBackgroundDefaults::defaultCoarseness;
264 needRemakeHist = fCoarseness == coarseness ? false :
true;
265 fCoarseness = coarseness;
270 RampdemReader::dataSet AntarcticaBackground::GetDataSet()
const{
276 void AntarcticaBackground::SetDataSet(RampdemReader::dataSet dataSet){
278 needRemakeHist = dataSet == fDataSet ? false :
true;
289 void AntarcticaBackground::updateBases(){
291 if(grBases.size()==0){
292 for(UInt_t b=0; b < BaseList::getNumBases(); b++){
295 gr->SetMarkerStyle(8);
296 gr->SetMarkerColor(kMagenta);
297 gr->SetEditable(
false);
299 gr->SetDrawOption(
"p");
304 grBases.push_back(gr);
308 updateGPadPrims(grBases, fBases,
"p", fDrawBasesOnTop);
312 void AntarcticaBackground::updateGrid(){
316 const int minLat = -90 + fDeltaLat;
317 const int maxLat = -60;
322 for(Int_t lat = minLat; lat<= maxLat; lat += fDeltaLat){
324 gr->SetLineColor(kGray);
325 const Double_t deltaLon = 360./fGridPoints;
326 for(
int i=0; i < fGridPoints; i++){
327 Double_t theLat = lat;
328 Double_t theLon = i*deltaLon;
329 gr->
SetPoint(gr->GetN(), theLon, theLat);
332 gr->SetEditable(
false);
333 gr->SetTitle(Form(
"Grid: Lat %d", lat));
334 grGrids.push_back(gr);
338 for(Int_t lon = -180; lon < 180; lon+= fDeltaLon){
340 gr->SetLineColor(kGray);
341 const Double_t deltaLat = double(maxLat - -90)/fGridPoints;
342 for(
int i=0; i < fGridPoints; i++){
343 Double_t theLat = -90 + deltaLat*i;
344 Double_t theLon = lon;
345 gr->
SetPoint(gr->GetN(), theLon, theLat);
347 gr->SetEditable(
false);
348 gr->SetTitle(Form(
"Grid: Lon %d", lon));
349 grGrids.push_back(gr);
352 needRemakeGrid =
false;
355 updateGPadPrims(grGrids, fGrid,
"l");
365 void AntarcticaBackground::updateGPadPrims(std::vector<TGraphAntarctica*>& grs, Bool_t drawThem, Option_t* opt,
bool drawGraphsOnTop){
369 TVirtualPad* fPad = gPad;
371 TList* prims = fPad->GetListOfPrimitives();
373 if(drawThem && fDrawnSelf){
377 TObjLink *thisLink = prims->FirstLink();
382 thisLink = thisLink->Next();
386 if(thisLink->GetObject()==
this){
393 TObjLink* antarcticaStuff = thisLink->Next();
401 std::vector<TObject*> tempObjs;
402 std::vector<TString> tempOpts;
403 while(antarcticaStuff){
404 tempObjs.push_back(antarcticaStuff->GetObject());
405 tempOpts.push_back(antarcticaStuff->GetOption());
406 antarcticaStuff = antarcticaStuff->Next();
410 for(UInt_t i=0; i < tempObjs.size(); i++){
411 prims->RecursiveRemove(tempObjs.at(i));
419 for(UInt_t i=0; i < tempObjs.size(); i++){
420 prims->AddLast(tempObjs.at(i), tempOpts.at(i));
423 for(UInt_t grInd=0; grInd < grs.size(); grInd++){
425 prims->AddLast(gr, opt);
430 for(UInt_t grInd=0; grInd < grs.size(); grInd++){
432 prims->AddLast(gr, opt);
435 for(UInt_t i=0; i < tempObjs.size(); i++){
436 prims->AddLast(tempObjs.at(i), tempOpts.at(i));
442 for(UInt_t grInd=0; grInd < grs.size(); grInd++){
443 TGraph* gr = grs.at(grInd);
444 prims->RecursiveRemove(gr);
456 void AntarcticaBackground::deleteGrid(){
459 while(grGrids.size() > 0){
461 TGraph* gr = grGrids.back();
463 TVirtualPad* fPad = gPad;
465 TList* prims = gPad->GetListOfPrimitives();
467 prims->RecursiveRemove(gr);
479 void AntarcticaBackground::SetGridDivisions(Int_t deltaLon, Int_t deltaLat){
481 needRemakeGrid = fDeltaLon == deltaLon && fDeltaLat == deltaLat ? false :
true;
482 fDeltaLon = deltaLon;
483 fDeltaLat = deltaLat;
497 gROOT->MakeDefCanvas();
502 if(opt2 == AntarcticaBackgroundDefaults::drawOpt){
504 fShowColorAxis =
true;
506 if(opt2.Contains(
"z")){
507 fShowColorAxis =
true;
510 fShowColorAxis =
false;
515 opt3.ReplaceAll(
"z",
"");
518 TProfile2D::Draw(opt3);
524 hDummy.Draw(
"colz same");
532 TProfile2D::Draw(opt3);
535 fPalUnsetter->Draw();
540 ResetColorAxis(
true);
541 fXaxis.SetAxisColor(kWhite);
542 fYaxis.SetAxisColor(kWhite);
543 fXaxis.SetTitleOffset(9999);
544 fYaxis.SetTitleOffset(9999);
545 fXaxis.SetLabelOffset(9999);
546 fYaxis.SetLabelOffset(9999);
553 SetBit(kMustCleanup);
559 SetToolTip(fToolTip);
567 void AntarcticaBackground::setPadMargins(){
568 gPad->SetTopMargin(0.1);
569 gPad->SetBottomMargin(0.02);
570 gPad->SetLeftMargin(0.1);
571 gPad->SetRightMargin(0.02);
577 gPad->SetFrameLineColor(0);
578 gPad->SetFrameLineWidth(0);
579 gPad->SetFrameBorderSize(0);
597 TPaletteAxis *palette = (TPaletteAxis*) hDummy.GetListOfFunctions()->FindObject(
"palette");
599 palette->SetX1NDC(AntarcticaBackgroundDefaults::zAxisRightMargin);
600 palette->SetX2NDC(AntarcticaBackgroundDefaults::zAxisRightMargin + AntarcticaBackgroundDefaults::zAxisWidth);
601 palette->SetY1NDC(AntarcticaBackgroundDefaults::zAxisTopBottomMargin);
602 palette->SetY2NDC(AntarcticaBackgroundDefaults::zAxisTopBottomMargin + AntarcticaBackgroundDefaults::zAxisHeight);
604 TAxis* zAxis = GetZaxis();
606 zAxis->SetTitleSize(AntarcticaBackgroundDefaults::zAxisTextSize);
607 zAxis->SetLabelSize(AntarcticaBackgroundDefaults::zAxisTextSize);
609 TAxis* zAxis2 = hDummy.GetZaxis();
611 zAxis2->SetTitleSize(AntarcticaBackgroundDefaults::zAxisTextSize);
612 zAxis2->SetLabelSize(AntarcticaBackgroundDefaults::zAxisTextSize);
615 zAxis2->SetTitleOffset(2);
622 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ <<
", couldn't find dummy color axis! " << std::endl;
631 void AntarcticaBackground::SetRampdem(
bool useRampdem){
632 SetDataSet(RampdemReader::rampdem);
635 Bool_t AntarcticaBackground::GetRampdem()
const {
636 return fDataSet == RampdemReader::rampdem;
639 void AntarcticaBackground::SetBed(
bool useBed){
640 SetDataSet(RampdemReader::bed);
643 Bool_t AntarcticaBackground::GetBed()
const {
644 return fDataSet == RampdemReader::bed;
647 void AntarcticaBackground::SetIcemask(
bool useIcemask){
648 SetDataSet(RampdemReader::icemask_grounded_and_shelves);
651 Bool_t AntarcticaBackground::GetIcemask()
const {
652 return fDataSet == RampdemReader::icemask_grounded_and_shelves;
655 void AntarcticaBackground::SetSurface(
bool useSurface){
656 SetDataSet(RampdemReader::surface);
659 Bool_t AntarcticaBackground::GetSurface()
const {
660 return fDataSet == RampdemReader::surface;
663 void AntarcticaBackground::SetThickness(
bool useThickness){
664 SetDataSet(RampdemReader::thickness);
667 Bool_t AntarcticaBackground::GetThickness()
const {
668 return fDataSet == RampdemReader::thickness;
671 void AntarcticaBackground::SetGrid(Bool_t grid){
677 Bool_t AntarcticaBackground::GetGrid()
const {
682 void AntarcticaBackground::SetShowBases(Bool_t showBases){
687 Bool_t AntarcticaBackground::GetShowBases()
const {
692 void AntarcticaBackground::SetGrayScale(
bool grayScale){
693 fGrayScale = grayScale;
696 Bool_t AntarcticaBackground::GetGrayScale()
const {
701 void AntarcticaBackground::SetShowColorAxis(
bool showColorAxis){
702 fShowColorAxis = showColorAxis;
704 hDummy.SetDrawOption(
"colz same");
705 ResetColorAxis(
true);
708 hDummy.SetDrawOption(
"col same");
723 updateToolTip(event, x, y);
724 TProfile2D::ExecuteEvent(event, x, y);
745 if(fScaleMax != newMax || fScaleMin != newMin){
747 double currentMax = -DBL_MAX;
748 double currentMin = DBL_MAX;
750 if(fScaleMax == fScaleMin){
754 for(
int by=1; by <= GetNbinsY(); by++){
755 for(
int bx=1; bx <= GetNbinsX(); bx++){
757 Int_t bin = GetBin(bx, by);
758 double binEntries = GetBinEntries(bin);
761 double val = GetBinContent(bx, by);
763 currentMin = val < currentMin ? val : currentMin;
764 currentMax = val > currentMax ? val : currentMax;
770 currentMax = fScaleMax;
771 currentMin = fScaleMin;
774 double currentDelta = currentMax - currentMin;
775 double newDelta = newMax - newMin;
777 for(
int by=1; by <= GetNbinsY(); by++){
778 for(
int bx=1; bx <= GetNbinsX(); bx++){
781 Int_t bin = GetBin(bx, by);
782 double binEntries = GetBinEntries(bin);
786 double val = GetBinContent(bx, by);
787 double frac = (val - currentMin)/currentDelta;
793 double newVal = newMin + frac*newDelta;
794 SetBinContent(bx, by, newVal);
795 SetBinEntries(bin, 1);
823 void AntarcticaBackground::updateToolTip(Int_t event, Int_t x, Int_t y,
const char* extraInfo){
826 Double_t easting = gPad->AbsPixeltoX(x);
827 Double_t northing = gPad->AbsPixeltoY(y);
828 Double_t val = GetBinContent(FindBin(easting, northing));
833 TString theToolTipText = Form(
"Lon %4.2lf\nLat %4.2lf\n%4.2f%s", lon, lat, val, fToolTipUnits.Data());
836 theToolTipText += TString::Format(
"\n%s", extraInfo);
842 fToolTip->SetText(theToolTipText.Data());
843 TCanvas* theCan = gPad->GetCanvas();
844 Int_t topX = theCan->GetWindowTopX();
845 Int_t topY = theCan->GetWindowTopY();
847 const int xOffset = 10;
848 const int yOffset = 10 + fToolTip->GetHeight()/2;
851 fToolTip->Show(topX + x + xOffset, topY + y + yOffset);
854 TProfile2D::ExecuteEvent(event, x, y);
863 void AntarcticaBackground::setToolTipUnits(){
865 TObjArray* tokens = tempAxisTitle.Tokenize(
"(");
867 Bool_t gotUnits =
false;
868 int nTokens = tokens->GetEntries();
871 TString afterOpenParen = ((TObjString*) tokens->At(1))->GetString();
872 TObjArray* tokens2 = afterOpenParen.Tokenize(
")");
873 int nTokens2 = tokens2->GetEntries();
876 fToolTipUnits =
" (" + TString(((TObjString*) tokens2->At(0))->GetString()) +
")";
void ExecuteEvent(Int_t event, Int_t x, Int_t y)
static void getNumXY(Int_t &numX, Int_t &numY, RampdemReader::dataSet dataSet=rampdem)
virtual void Draw(Option_t *opt="")
static void getMapCoordinates(double &xMin, double &yMin, double &xMax, double &yMax, RampdemReader::dataSet=rampdem)
void scale(double newMin, double newMax)
Does not persist in ROOT!
void ResetColorAxis(bool trigger_redraw=false)
static const char * dataSetToAxisTitle(RampdemReader::dataSet dataSet)
static TProfile2D * fillThisHist(TProfile2D *theHist, RampdemReader::dataSet dataSet)
virtual void SetPoint(Int_t i, Double_t lon, Double_t lat)
static void EastingNorthingToLonLat(Double_t easting, Double_t northing, Double_t &lon, Double_t &lat)