Re: Projection of two TH1 objects

From: Andy Mastbaum <mastbaum_at_hep.upenn.edu>
Date: Thu, 10 Feb 2011 12:42:45 -0500


Do you perhaps just want to multiply them?

{

gStyle->SetPalette(1);

TH1F *h1 = new TH1F("h1","foo",20,-10,10); TH1F *h2 = new TH1F("h2","bar",20,-10,10); for(unsigned i=0; i<5000; i++) {
  h1->Fill(gRandom->Gaus(0,4),1);
  h2->Fill(gRandom->Gaus(0,4),1);
}

TH2F *h3 = new TH2F("h3","baz",20,-10,10,20,-10,10); for(unsigned i=0; i<h1->GetNbinsX(); i++)

   for(unsigned j=0; j<h2->GetNbinsX(); j++)      h3->SetBinContent(i,j,h1->GetBinContent(i)*h2->GetBinContent(j));

TCanvas c1;
c1.Divide(1,3);

c1->cd(1);
h1->DrawNormalized();
c1->cd(2);
h2->DrawNormalized();
c1->cd(3);
h3->DrawNormalized("surf1");

}

It's a reasonable thing to do but sort of misleading depending on the application... it makes it look like you've sampled the entire 2D space when you haven't.

Or maybe this isn't what you meant at all.

Andy

On 02/10/2011 09:58 AM, Mario Kadastik wrote:
>> Actually my aim is to extract the values from two TH1F histos and then would make 2D histo by projection on each other.
>
> Yes, maybe it's a stupid question but I cannot figure out what you mean under the projection on each other part. So if both are gaussians, what do you expect the end result to be in 2D? Or if one is sin(x) and other is cos(x), then what would that mean. I'm probably just confused, but please elaborate.
>
> Thanks,
>
> Mario Kadastik, PhD
> Researcher
>
> ---
> "Physics is like sex, sure it may have practical reasons, but that's not why we do it"
> -- Richard P. Feynman
>
>

multiply.png
Received on Thu Feb 10 2011 - 18:44:07 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 10 2011 - 23:50:01 CET