2D histogram subtraction

Dear Root experts,
Hi !
I have two 2D histograms of identical dimensions (0, 4096) & total bins (4096). I want to subtract ‘hist 2’ from ‘hist 1’ , but only after multiplyig the bin contents of X & Y axis of ‘hist 2’ by factors 0.3 & 0. 2 respectively. Also I want to do this only selectively, i.e. only for those bins of ‘hist 1’, which have non zero entries. I know that In case of a simple subtraction (without any selection) with common multiplying factor (say 0.2) , it can be done in the following way -
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
TFile *f1 = new TFile(“f1.root”, “read”);
TH2F h1 = (TH2F)f1->Get(“hist1”);
//
TFile *f2 = new TFile(“f2.root”, “read”);
TH2F h2 = (TH2F)f2->Get(“hist2”);
TH2F h_out = (TH2F)h1->Clone(“difference”);
h_out->Add(h2, -0.2);
h_out->Draw();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

But this selectively subtraction with different factors for X & Y axis is a new problem to me and therefore don’t know how to do it.
So if possible, please suggest me the way to do it with an example.
cylab123

You can do something like:

[code]TFile *f1 = new TFile(“f1.root”, “read”);
TH2F h1 = (TH2F)f1->Get(“hist1”);
//
TFile *f2 = new TFile(“f2.root”, “read”);
TH2F h2 = (TH2F)f2->Get(“hist2”);
TH2F h_out = (TH2F)h1->Clone(“difference”);

int nx = h_out->GetXaxis()->GetNbins();
int ny = h_out->GetYaxis()->GetNbins();
for (int i=1;i<=nx;i++) {
for (int j=1;j<=ny;j++) {
double c1 =h_out->GetBinContent(i,j);
if (c1 > 0) {
double c2 =h2->GetBinContent(i,j);
h_out->SetBinContent(i,j,c1-0.2*c2);
}
}
}

h_out->Draw();

[/code]
Rene