Adding parameter TPad * to Draw Methods

Hello Rooters,

I was wondering whether it would be possible to tell an drawable object (ie. a histogram) in which pad it should be drawn. Imagine the follwing code:

[code]{
TCanvas * MyC = new TCanvas(“c0”,“test”,-1,1,367,367);
MyC->Divide(1,2,0.0001,0.0001);
MyC->ToggleEventStatus();
for (Int_t i=1;i<=2;++i)
{
MyC->cd(i);
gPad->SetRightMargin(0.15);
gPad->SetLeftMargin(0.15);
gPad->SetTopMargin(0.15);
gPad->SetBottomMargin(0.15);
}

TH2D * twod = new TH2D("hpxpy","py vs px",40,-4,4,40,-4,4);
TH1D * oned = new TH1D("hpx","px",40,-4,4);
twod->SetOption("col z");
Double_t px,py;
for (Int_t i = 0; i < 50000; i++)
{
	gRandom->Rannor(px,py);
	twod->Fill(px,py);
	oned->Fill(px);
}

	
MyC->cd(1);		//avoid this//
twod->Draw();

MyC->cd(2);		//avoid this//
oned->Draw();

}
[/code]
Wouldn’t it be much nicer to draw the histograms this way:... twod->Draw("",(TPad*)MyC->GetPad(1)); oned->Draw("",(TPad*)MyC->GetPad(2)); ?

In order to draw classes like that, one would have to rewrite the Draw() Methods of the different classes only slightly.
For example change TH1::Draw(Option_t = “”) to TH1::Draw(Option_t = “”, TPad *pad=0) and :[code]
void TH1::Draw(Option_t option,TPad pad)
{
if (pad) gPad = pad; //only this needs to be added

TString opt = option;
opt.ToLower();
if (gPad) {
	if (!gPad->IsEditable()) (gROOT->GetMakeDefCanvas())();
	if (opt.Contains("same")) {
	if (opt.Contains("same") && gPad->GetListOfPrimitives()->GetSize()==0) opt.ReplaceAll("same","");
} else {
	//the following statement is necessary in case one attempts to draw
	//a temporary histogram already in the current pad
	if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
	gPad->Clear();
}
} else {
	if (opt.Contains("same")) opt.ReplaceAll("same","");
}
AppendPad(opt.Data());

}[/code]

Is there something that might conflict with such a scheme? Or can this be done?

Thank you,
Lutz

Your proposal cannot be implemented. It would mean that you can drawn an object only in one pad!, because the Draw option would have to be stored in the object itself. The inverse would be possible, ie
pad.Draw(myobject, options), but gives problems with the code generators (saving the canvas/pads as canvas.C

Rene