Get only a subrange of an histogram

Dear experts,

in the code [1], I wonder why I do have the output [2], actually I would expert to have the output [3]. When I draw hc, the axis is actually [-1,1]. Can you please tell me if there is a method to get output[3]?
My goal is to have hc, a copy of hgaus histogram with a different range such that when I perform any computation with hc histogram, it is perform on this new range?

Regards

[3]
min i: -2
max i: 2
min f: -1
max f: 1

[2]
min i: -2
max i: 2
min f: -2
max f: 2

[1]
void test(){

TH1D *hgaus = new TH1D (“hgaus”, “”, 100, -2, 2);

hgaus->FillRandom(“gaus”, 10000);

TH1D hc = (TH1D)hgaus->DrawClone();

cout<<"min i: "<GetXaxis()->GetXmin()<<endl;
cout<<"max i: "<GetXaxis()->GetXmax()<<endl;
hc->GetXaxis()->SetRangeUser(-1, 1);
cout<<"min f: "<GetXaxis()->GetXmin()<<endl;
cout<<"max f: "<GetXaxis()->GetXmax()<<endl;
hc->Draw();

}

{
   TH1D *hgaus = new TH1D ("hgaus", "", 100, -2, 2);
   hgaus->FillRandom("gaus", 10000);
   TH1D *hc = (TH1D*)hgaus->DrawClone();
   cout<<"min i: "<<hc->GetXaxis()->GetXmin()<<endl;
   cout<<"max i: "<<hc->GetXaxis()->GetXmax()<<endl;
   hc->GetXaxis()->SetLimits(-1, 1);
   cout<<"min f: "<<hc->GetXaxis()->GetXmin()<<endl;
   cout<<"max f: "<<hc->GetXaxis()->GetXmax()<<endl;
   hc->Draw();
}

Dear Couet,

thanks you for your answer. Using SetLimits() to change the x range of the histogram, I used the code [1] to computed KolmogorovTest() for different x-range but I found the same value [2]. So am I doing something wrong or does the KolmogorovTest always use the full range for the computation? If yes how can I force the KolmogorovTest() to use the range that I want?

[2]

ks: 0.986011

[1]
void test(){

TH1D *hgaus = new TH1D (“hgaus”, “”, 100, -2, 2);

hgaus->FillRandom(“gaus”, 10000);

hgaus->Fit(“gaus”);

TH1D hgausr = (TH1D)hgaus->DrawClone();
hgausr->GetXaxis()->SetLimits(-2, 2); // also tried SetLimits(-1, 1)

TF1 *fit=hgaus->GetFunction(“gaus”);
fit->SetNpx(hgaus->GetNbinsX());

TH1D hfitr=(TH1D)fit->GetHistogram();
hfitr->GetXaxis()->SetLimits(-2, 2); // also tried SetLimits(-1, 1)

double ks=hgausr->KolmogorovTest(hfitr);
cout<<"ks: "<<ks<<endl;

}