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.


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[6], y[6];
    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[0] = xloop;
            y[0] = ytemp;
            x[1] = x[0] + a/2.0;
            y[1] = y[0] + a*TMath::Sqrt(3)/2.0;
            x[2] = x[1] + a;
            y[2] = y[1];
            x[3] = x[2] + a/2.0;
            y[3] = y[0];
            x[4] = x[2];
            y[4] = y[3] - a*TMath::Sqrt(3)/2.0;
            x[5] = x[1];
            y[5] = y[4];

            hist->AddBin(6, x, 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->SetTitle("Option COLZ");

   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);

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

   TH2Poly *hc2 = new TH2Poly();
   hc2->SetTitle("Option H");
   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.