Scaling trouble with TProfile adding weighted MC samples

Hi!

I have some trouble when adding TProfiles from MC samples that need weights. Please find below a mock-up that demonstrates my problems. The full application is adding MC samples normalized to luminosity.

Let’s say I have two samples with the same physics “normalization”. Sample 1 has only 1/10th of the statistics of sample 2 -> I have to scale sample 2 down by a factor 10 before I can add histograms. But for TProfiles I can’t call Scale because it doesn’t represent counts but the mean value of some distribution. To get the correct result I need to call Add with a weight of 1/10.

The problem I have with this is that I need two pretty different approaches to do the same task, i.e. I can’t just first scale all histograms and profiles of the samples separately and then hadd them.

Do you have any idea how to unify my workflow?

Best,

Sebastian

``````{

TRandom* gRandom = new TRandom3(0);

TH1D* h1 = new TH1D("h1","h1",100,-5,5); h1.Sumw2();
TH1D* h2 = new TH1D("h2","h2",100,-5,5); h2.Sumw2();

TProfile* p1 = new TProfile("p1","p1", 10, 0, 1); p1.Sumw2();
TProfile* p2 = new TProfile("p2","p2", 10, 0, 1); p2.Sumw2();

for(UInt_t n=0; n != 10000; ++n) {

const Double_t ran = gRandom->Gaus(0,2);
const Double_t ran2 = gRandom->Uniform();

if(ran >= 0) {

// sample 1 has only 1/10th of the statistics of sample 2
if(n % 10 == 0) {
h1->Fill(ran);
p1->Fill(ran2, 1);
}

} else {

h2->Fill(ran);
p2->Fill(ran2, 2);

}

}

TCanvas* c = new TCanvas("c","c",800,400);
c->Divide(2);

// histogram

c.cd(1);

h2->Scale(1/10.);

h2->Draw("");
h1->Draw("same");

hcomb = (TH1D*)h1->Clone();
hcomb->Draw("histsame");

// profile

c.cd(2);

//p2->Scale(1/10.); // wrong

p1->Draw();
p2->Draw("same");

pcomb = (TProfile*)p1->Clone();