{ // Dimensions of cylinder Double_t a=0.8.,b=2.5.,h=2.5; Int_t nDiscrCyl = 10;//3; //binwidth Double_t dr = (b-a)/(nDiscrCyl-1); Double_t dphi = TMath::Pi()*2/nDiscrCyl; Double_t dz = h/(nDiscrCyl-1); TH3F *h3cyl = new TH3F("h3","test", nDiscrCyl,a-dr/2,b+dr/2, nDiscrCyl+1,0-dphi/2,TMath::Pi()*2+dphi/2, nDiscrCyl,0-dz/2,h+dz/2); TRandom3 rand; for (int i=0;i<100000;i++) { double r = rand.Gaus(1.5,0.2); double phi = rand.Gaus(3.,1.5); double z = rand.Gaus(1.4,0.2); h3cyl->Fill(r,phi,z); } h3cyl->Draw("glbox"); cout<Interpolate(1.5,2,0.1)<2*TMath::Pi()) phi -= TMath::Pi()*2; //if ( r>=b || r<=a || zp<=0 || zp>=h ) { // within domain if ( r>b || rh ) { // within domain + border h3cart->SetBinContent(xi+1,yi+1,zi+1,0); } else { // cout<SetBinContent(xi+1,yi+1,zi+1,h3cyl->Interpolate(r,phi,zp)); } } } } h3cart->Draw("glbox"); }