How to redefine the range of axis for a defined object in TH2Poly class

ROOT Version: 6.22
Platform: UBuntu 20.04

Dear experts,

I would like to redefine the started X and Y value for a defined object, because I want to dynamic allocate the started X and Y in a loop. I have no idea about achieving it.
The following is a simplified codes, both the new and old setting are shown in one plot.
TH2Poly *hc = new TH2Poly();
hc->SetTitle(“Honeycomb example”);
hc->Honeycomb(0,0,1,40,40);
hc->Clear();
hc->Honeycomb(-5,-5,1,40,40);
Could you please give me some advice?
Thank you very much.

Best regards,
Jiechen

Here is an example setting the range of the X axis. But i am not sure that’s what you are looking for. But that can help to start the discussion:

{
   TH2Poly *hc = new TH2Poly();
   hc->SetTitle("Honeycomb example");
   hc->Honeycomb(0,0,.1,25,25);
   TRandom ran;
   for (int i = 0; i<30000; i++) hc->Fill(ran.Gaus(2.,1), ran.Gaus(2.,1),ran.Gaus(2,1));
   hc->Draw("colz");
   hc->GetXaxis()->SetRangeUser(1,2);
}

Dear couet,

Thank you for reply.
The following figure is plot from the code I mentioned, the red frame is given by the first range of X, Y start axis, the green frame is given by the second range of X, Y start axis. I would like to clean the first frame while I change the X, Y start axis.
I am not sure whether the plot can be update while the axis of X, Y is changed, because I want to allocate changed axis of X, Y in a loop to save computer resource.

Best regards

What do you mean exactly by that ? “erase” the first frame ? it all depends how you produced this plot. Can you provide a small example reproducing what you are doing ? that will help to understand what you are trying to do.

Dear couet,

Sorry for confusion, the attachment is the code.
In the loop, I would like to change point “hc” as the start axis of X and Y is changed, however,
the axis of filling content is not changed means the “hc” is the same.
Could you please help me to check it? Thank you very much.
liubianxing1.C (1.1 KB)

Best regards

I cleaned up a bit your code (indentation etc.). Now it is:

void liubianxing1() {
   double asyinzi=1;
   const int bin=40;
   const double pitch=5e-3*asyinzi;
   const double sid=2.88675e-3*asyinzi;
   double xstart=-0.1*asyinzi;
   double ystart=(-0.1-pitch/sqrt(3)/6*5)*asyinzi;

   TH2Poly *hc = new TH2Poly();
   hc->SetTitle("Honeycomb example");
   //   hc->Honeycomb(xstart,ystart,sid,bin,bin);
   double xc,yc;double ii,jj;

   for(int i=0;i<10;i++){
      xstart=-0.1+i*pitch;
      ystart=-0.1;
      hc->Honeycomb(xstart,ystart,sid,bin,bin);
      cout<<xstart<<"\t"<<ystart<<endl;
      for (int j=0;j<1;j++) {
         hc->Fill(0.,0.);
      }
      jj = hc->GetNumberOfBins();
      for (int k=1;k<jj+1;k++) {ii= hc->GetBinContent(k);
         if (ii>0) {
            yc = 0+(k/bin+1);
            if ((k/bin)%2==0) xc=0+((k/bin)/2+k)%bin;
            else xc=0+((k/bin)/2+k)%bin;
            cout<<xc<<"\t"<<yc<<endl;
         }
      }
      hc->Clear();
   }
//hc->Draw("COLZ0");
}

It gives me this output:

Processing liubianxing1.C...
-0.1	-0.1
20	24
-0.095	-0.1
20	24
-0.09	-0.1
20	24
-0.085	-0.1
20	24
-0.08	-0.1
20	24
-0.075	-0.1
20	24
-0.07	-0.1
20	24
-0.065	-0.1
20	24
-0.06	-0.1
20	24
-0.055	-0.1
20	24
root [1] 

I am not sur to understand what should I modify to help you ?

Dear couet,
Thank you for reply.
The output means the bin of the filling point is not changed with the “hc” ( that is to say the start X and Y are the same for the “hc” ), the expected output are
-0.1 -0.1
20 24
-0.095 -0.1
19 24
-0.09 -0.1
18 24
-0.085 -0.1
17 24
-0.08 -0.1
16 24
-0.075 -0.1
15 24
-0.07 -0.1
14 24
-0.065 -0.1
13 24
-0.06 -0.1
12 24
-0.055 -0.1
11 24

I am not sure whether any way could achieve it?

Best regards

I have difficulties to understand your code. The Honeycomb method is designed to define TH2Poly bins as a regular grid in a honeycomb structure and is typically intended to be used once during the creation of the TH2Poly. However, in your code, you use a loop with 10 iterations, modifying the TH2Poly binning in each iteration. What is the purpose of such a loop? It doesn’t seem to make much sense to me.

Dear couet,
Thanks for explanation, now I could understand based on your illustration.
Actually, I expected to create a relative big grid as shown on the figure,
the blue region is grid 500500, the red region is the potential interested gird with 4040, the red region is random for each loop. Surely, we can create a blue region and clear the bin content in each loop, but the calculation is slow due to the big grid filled each time. Therefore, I try to create a dynamic red region by changing the start axis of X and Y.

Best regards

Okay, I believe your honeycomb should be the large 500x500 grid (but keep in mind that 500x500 is quite large and could consume a lot of memory). You define it once and you fill in the red parts (if I understand correctly what you’re trying to do).

By the way, why do you need a honeycomb for this? Wouldn’t a regular 2D histogram suffice?

Dear couet,

Thanks for your consideration, using a honeycomb is to simulate the shape of readout pad.
Could the regular 2D histogram achieve the function?

Best regards

If you need the simulation of the shapes of readout pad, yes, you are right. TH2Poly should be used. The TH2 histograms have only squared shape bins.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.