Aitoff plots with X-axis reversed

Hi all,

I have built a 2D histogram defined in the ranges from -180 to 180 in X and from -90 to 90 in Y (it is a sky map with galactic latitude vs galactic longitude).

I would like to plot this histogram using an AITOFF projection, but with the X axis reversed, i.e. I want the galactic longitude +180° to appear on the left side of the plot and the galactic longitude -180° to appear on the right side of the plot.

I know that a possible solution is to make a copy of my original histogram and fill it by changing the original X values into -X.

However, is there any trick/option that I can use to do the plot without defining and filling a new histogram?

This is on our program of work. Right now the only way will be to make a new histogram (as you said) and also redraw the axis in the reverse way like in the following example. But that’s only tricks.

reverseaxis ()
{
   TH2F *hpxpy  = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
   Float_t px, py;
   TRandom r;
   for (Int_t i = 0; i < 25000; i++) {
      r.Rannor(px,py);
      hpxpy->Fill(px,py);
   }
   TCanvas *c1 = new TCanvas("c1");
   hpxpy->Draw("colz");
   ReverseXAxis(hpxpy);
   ReverseYAxis(hpxpy);
}

ReverseXAxis (TH1 *h)
{
   // Remove the current axis
   h->GetXaxis()->SetLabelOffset(999);
   h->GetXaxis()->SetTickLength(0);

   // Redraw the new axis
   gPad->Update();
   TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
                                gPad->GetUymin(),
                                gPad->GetUxmin(),
                                gPad->GetUymin(),
                                h->GetXaxis()->GetXmin(),
                                h->GetXaxis()->GetXmax(),
                                510,"-");
   newaxis->SetLabelOffset(-0.03);
   newaxis->Draw();
}

ReverseYAxis (TH1 *h)
{
   // Remove the current axis
   h->GetYaxis()->SetLabelOffset(999);
   h->GetYaxis()->SetTickLength(0);

   // Redraw the new axis
   gPad->Update();
   TGaxis *newaxis = new TGaxis(gPad->GetUxmin(),
                                gPad->GetUymax(),
                                gPad->GetUxmin()-0.001,
                                gPad->GetUymin(),
                                h->GetYaxis()->GetXmin(),
                                h->GetYaxis()->GetXmax(),
                                510,"+");
   newaxis->SetLabelOffset(-0.03);
   newaxis->Draw();
}

Thanks for your answer.

I already found this trick looking at the forum and at the documentation, but I was wondering if there was a faster way to do the same job.

I have also another question about the representation of AITOFF plots (just about graphics).

In the attached macro I have defined two histograms with different latitude bins. In the first one I have defined 180 latitude bins with 1° spacing, while in the second one I have defined 200 latitude bins with 0.01 spacing in sin(latitude), in such a way that the solid angle is the same for all bins.

If you look at the plots, it seems that in the second plot the polar caps are missing (the poles are white). Is there a way to eliminate this feature?
test.C (1.21 KB)

I guess it is because the bins ate the end of the vertical axis of the second histogram are bigger than the other bins whereas the top histo has equidistant bins. You can see that is you plot the histogram with the option “box”. by the way i am not completely sure the aitoff option has been implemented in case of non equidistant bins.