# Rotate a figure 90 degrees

I am working with a detector built out of hexagons, so to represent it in a 2D histogram I am using TH2Poly and Honeycomb, but I can only draw this histogram with the hexagons oriented 90 degrees off of what they are in the detector (the attached image would need to be rotated CW 90 degrees to match). I figure this could be solved if one could draw the hexagons in the other orientation from the start, or just rotate the figure after putting all the data in. I haven’t been able to find out how to do either of those things, any help?

I solved this myself by just making a copy of the TH2Poly::Honeycomb function and altering it a bit to draw the other orientation of hexagons

Dear @samfred ,

I am glad you could solve your problem! Can you maybe share the modifications to the functions that you did?

@couet may be interested in helping you introducing those changes to ROOT so that also other users may benefit.

Cheers,
Vincenzo

Sure, here’s what I used

``````#include "TH2Poly.h"

void honeycomb_transpose(TH2Poly * hist, Double_t xstart, Double_t ystart, Double_t a,Int_t k, Int_t s) {

// a is the side length of the hexagon

Double_t numberOfHexagonsInTheRow;
Double_t x, y;
Double_t xloop, yloop, ytemp;
xloop = xstart; yloop = ystart + a*TMath::Sqrt(3)/2.0;
for (int sCounter = 0; sCounter < s; sCounter++) {

ytemp = yloop; // Resets the temp variable

// Determine the number of hexagons in that row
if(sCounter%2 == 0){numberOfHexagonsInTheRow = k;}
else{numberOfHexagonsInTheRow = k - 1;}

for (int kCounter = 0; kCounter <  numberOfHexagonsInTheRow; kCounter++) {

// Go around the hexagon
x = xloop;
y = ytemp;
x = x + a/2.0;
y = y + a*TMath::Sqrt(3)/2.0;
x = x + a;
y = y;
x = x + a/2.0;
y = y;
x = x;
y = y - a*TMath::Sqrt(3)/2.0;
x = x;
y = y;

// Go up
ytemp += a*TMath::Sqrt(3);
}

// Increment the starting position
if (sCounter%2 == 0) yloop += a*TMath::Sqrt(3)/2.0;
else                 yloop -= a*TMath::Sqrt(3)/2.0;
xloop += 1.5*a;
}
}
``````

Which is, again, only a slight alteration of what the normal honeycomb function does with coordinates and whatnot.

Thanks. I’ll look at it.

I tried your code with this small example:

``````{
TCanvas *chc = new TCanvas("chc","chc",600,600);

TH2Poly *hc = new TH2Poly();
hc->Honeycomb(0,0,.1,25,25);
hc->SetName("hc");
hc->SetTitle("Option COLZ");
hc->Fill(2.,2.,10.);
hc->Fill(2.,1.,20.);
hc->Fill(3.,3.,1.);

hc->Draw("colz l");
}
``````

I get this:

On the left your code, on the right the current code. Both are valid. We can make it optional.

@samfred : This is what I have now:

``````{
TCanvas *C = new TCanvas("C","C",1200,600);
C->Divide(2,1);

TH2Poly *hc1 = new TH2Poly();
hc1->Honeycomb(0,0,.1,5,5);
hc1->SetTitle("Option V (default)");
hc1->SetStats(0);
hc1->Fill(.1, .1, 15.);
hc1->Fill(.4, .4, 10.);
hc1->Fill(.5, .5, 20.);

TH2Poly *hc2 = new TH2Poly();
hc2->Honeycomb(0,0,.1,5,5,"h");
hc2->SetTitle("Option H");
hc2->SetStats(0);
hc2->Fill(.1, .1, 15.);
hc2->Fill(.4, .4, 10.);
hc2->Fill(.5, .5, 20.);

C->cd(1)->SetGrid(); hc1->Draw("colz L");
C->cd(2)->SetGrid(); hc2->Draw("colz L");
}
``````

`Honeycomb` has now an option parameter which can be `V` or `H`. Is it ok for you ?

Here is the corresponding PR: Implement options for Honeycomb by couet · Pull Request #13343 · root-project/root · GitHub

Wow that’s awesome, thank you so much!

1 Like

I’ll merge it asap.

Done, it is now in master.