How to scale the recently drawn histogram?

Dear Readers,

I’ve got the following problem. I want to scale a histogram which is created using the
TTree::Draw-command. Therefore I fetch the pointer to the temporary histogram which
was created (GetPrimitive) and then I scale it. So far so good, but doing the same thing
for another tree (and maybe other draw-command) the previous histogram gets scaled
again and not the new one.

I know that I could add some >>h1 or so to the draw-command and then fetch h1, but I
don’t want to do that, because I apply the draw-command from another routine in runtime.

The question is, … how do I get the pointer to the new created histogram?

I reduced the code to the basics, first, two histograms are drawn (“same”), and then two
histograms are drawn which should both be scaled the same way, but only the first one
is scaled twice and the second isn’t.

void htemp(){
    TFile *file1 = TFile::Open(
"rfio:///castor/cern.ch/grid/atlas/datafiles/ctb/realdata/11.0.3.v1/cbnt_RecExTB_Combined_1103_v1_2102225.00001.root");
    TTree *t1 = (TTree*)file1->Get("TB/tree");
    TFile *file2 = TFile::Open(
"rfio:///afs/cern.ch/user/s/speckmay/localscratch/ergebnisse/sim-reco/ctb.2225.G4Ctb_CBNT.pi-_180GeV_eta_00.45_Mag_0.0.v4.1102.root");
    TTree *t2 = (TTree*)file2->Get("TB/tree");

    t1->SetLineColor( kBlack );
    t1->SetMarkerColor( kBlack );

    t2->SetLineColor( kRed );
    t2->SetMarkerColor( kRed );

    TCut cut = "cl_eemb2_topo[0]>10000";

    // normal
    new TCanvas();
    t1->SetLineColor( kBlack );
    t1->SetMarkerColor( kBlack );
    t1->Draw("cl_eemb2_topo[0]",cut,"P");

    t2->SetLineColor( kRed );
    t2->SetMarkerColor( kRed );
    t2->Draw("cl_eemb2_topo[0]",cut,"HISTsame");

    TH1 *htemp;
    TH1 *htemp2;

    // problem
    new TCanvas();
    t1->Draw("cl_eemb2_topo[0]",cut,"P");
    htemp = (TH1*)gPad->GetPrimitive("htemp");
    cout << "1 " << htemp << std::endl;
    htemp->Scale( 1./10. ); // <<============== scales the actual histogram

    t2->Draw("cl_eemb2_topo[0]",cut,"HISTsame");
    htemp2 = (TH1*)gPad->GetPrimitive("htemp");
    cout << "2 " << htemp2 << endl;
    htemp2->Scale( 1./10. ); // <<============== scales the previous histogram again
}

Is there a possibility to get the pointer to the recently created hist or do I have to find
another way?

Thanks for your help,
Peter

TH1 *htemp1;
TH1 *htemp2;

t1->Draw("cl_eemb2_topo[0]>>htemp1",cut,"");
htemp1 = (TH1*)gPad->GetPrimitive("htemp1");
cout << "1 " << htemp1 << endl;
htemp1->Scale( 1./10. );

t2->Draw("cl_eemb2_topo[0]>>htemp2",cut,"same");
htemp2 = (TH1*)gPad->GetPrimitive("htemp2");
cout << "2 " << htemp2 << endl;
htemp2->Scale (1./10.);

gPad->Modified();

Jan