Adding histograms to prove adding in quadrature works

Hi, I am trying to prove that my adding in quadrature works through histograms. I have 2 histograms with different distributions I need to add but am having trouble. I am trying to add histogram h and histogram f. Here is my code:

void Distribution(){
  TRandom3 a;
  THStack *hs = new THStack("hs","Overlap Distribution");
  TH1D *h = new TH1D("h", "h", 100, 500, 600);
  for(int i = 0; i<100000; i++){
    double val1 = a.Gaus(550, 16);
    h->Fill(val1);
    // h->SetFillColor(kRed);
  }
  hs->Add(h);
  TH1D *f = new TH1D("f", "f", 100, 500, 600);
  for(int i = 0; i<100000; i++){
    double val2 = a.Gaus(550, 8);
    f->Fill(val2);
  }
  hs->Add(f);
  TH1D *d = new TH1D("d", "d", 100, 500, 600);
  for(int i = 0; i<100000; i++){
    double val3 = a.Gaus(550, 17.8);
    d->Fill(val3);
  }
  hs->Add(d);
  TH1D *v = new TH1D("v","v", 100, 500, 600);
  v = h->Add(f);
  hs->Add(v);
  hs->Draw();
}

v->Add(h, f);

Thanks that seemed to work

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