TLines in Divided Canvas

Hi to everybody,
I got a problem with drawing lines in divided canvas.
The code is inserted in a function, the function is called with TCanvas* nscanvas as an argument. nscanvas was divided with nscanvas->Divide(1,3) before calling my function.
Here is the code

//before I load data for filling Graphs and Histo

 // OFFSET GRAPH

    nscanvas->cd(2); 
    float yoffset_min = -maxoffset*0.1;
    float yoffset_max = maxoffset*1.2;
    if(yoffset_max<1e-10)yoffset_max=1;
 
    TH2S* foffset = new TH2S("poffset",title,1,ltime[0],ltime[counter-1],1,yoffset_min,yoffset_max);
    foffset->SetXTitle("Date");
    foffset->SetYTitle("Offset [THRDAC]");
    foffset->SetNdivisions(8);
    foffset->GetXaxis()->SetTimeDisplay(1);
    foffset->GetXaxis()->SetTimeFormat("%m/%y");
    foffset->Draw();

    //some graphics

    TLine line;
    TText text;

    line.SetLineStyle(3);
    line.SetLineWidth(0.3); 
    line.SetLineColor(15);
    TDatime t(2008,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2008
    t.Set(2007,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2007  
    t.Set(2006,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2006
    t.Set(2005,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2005
    t.Set(2004,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2004
    t.Set(2003,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2003
    t.Set(2002,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2002
    t.Set(2001,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2001
    t.Set(2000,1,1,0,0,0);
    line.DrawLine(t.Convert(),yoffset_min,t.Convert(),yoffset_max); // start 2000
    
    text.SetTextColor(16);
    
    float pos=yoffset_min+(yoffset_max-yoffset_min)*.93;
    
    text.DrawText( 913000000,pos,"1999"); 
    text.DrawText( 948000000,pos,"2000"); 
    text.DrawText( 982000000,pos,"2001");
    text.DrawText(1016000000,pos,"2002"); 
    text.DrawText(1047000000,pos,"2003"); 
    text.DrawText(1078000000,pos,"2004"); 
    text.DrawText(1109000000,pos,"2005");
    text.DrawText(1140000000,pos,"2006"); 
    text.DrawText(1171000000,pos,"2007"); 
    text.DrawText(1202000000,pos,"2008"); 
    
    text.SetTextColor(1);
    gPad->Update();
    
    for (Int_t chip=0; chip<nchips; chip++) {                                          //offset Graph
      if(i==0 && unbdchip_empty[chip])continue;
      TGraphErrors* goffset = new TGraphErrors(counter, ltime, offset_act+chip*nentries,0,eoffset_act+chip*nentries);
      sprintf(label, "Chip %d", chip);
      legend->AddEntry(goffset, label, "p"); 
      goffset->SetMarkerColor(color[chip]);
      goffset->SetMarkerStyle(24);
      goffset->SetMarkerSize(0.5);
      goffset->Draw("p");
      goffset->SetLineColor(color[chip]);
 
    }
    legend->Draw();
    gPad->Update();
    

The cose runs and draws my graph, but it doesn’t Draw lines and text!
I tried drawing lines without using Datetime, but it draws line on the entire pad, not on first one only.
I thanks in advance everyone who will help me!

Please post a running script that we can execute.

Rene

Hi Rene,
sorry for the delay in my reply.
My script is part of a class, so I couldn’t really post an executable script. I tried to write a macro with the same problem but I didn’t manage to do this.
I think that the really problem is probably that the TCanvas is defined in the function that call my script so when I try to do Draw.Line it draws on the entire pad and not on first or second part of the Canvas.
If it can be useful I can post the entire function but it won’t run anyway because some variables are defined in other places in the class and data are stored in files.
Thank you for your help

This symptom means that you do not canvas->cd(pad_number)
Again, I cannot tell you more without a concrete piece of code.

Rene

Hi Pietro,

could it be that you didn’t apply a range on each of the pads?
Like this,
canv(1)->Range(0, 0, 60, 50); etc.

(I didn’t really have a very thorough look at your piece of code
so excuse me if I’m wrong) :blush:

Eleni