Re: Problem with tpavetext and histogram cloning

From: Eduard Avetisyan <Eduard.Avetisyan_at_desy.de>
Date: Tue, 13 Mar 2012 13:01:03 +0100

Hi Melinda,

On Tue, 13 Mar 2012, Melinda Siciliano wrote:

> Hi Olivier,
>
> My problem is that at every cycles I want to change message on the
> TPaveText blue. As it is now in the macro, at every cycle a new TPaveText
> blue is added on the histogram. I would like to have only one TPaveTExt
> blue and change at every cycle the message on it.
Put an iterator on histos[0]->GetListOfFunctions() and check if there's already a TPaveText on it. If yes - don't create a new one but only modify the contents.

Btw, I thought GetListOfPrimitives() would be more appropriate, right?

Cheers

        Eduard

>
> Cheers,
>
> Melinda
>
> On Tue, Mar 13, 2012 at 11:22 AM, Olivier Couet <Olivier.Couet_at_cern.ch>wrote:
>
> > Oops ... sorry you already are using TPaveText .....
> > Forget my comment in the previous email..
> >
> > On Mar 13, 2012, at 11:21 AM, Olivier Couet wrote:
> >
> > Hi Melinda,
> >
> > try:
> > histos[...]->SetStats(0);
> >
> > Note that the way you handle stats is a bit unusual. The stats are
> > handle automatically in
> > principal. I guess you have your reasons . For me it would be more logical
> > to
> > add only TPaveText. Up to you .
> >
> > Olivier
> >
> > On Mar 13, 2012, at 9:50 AM, Melinda Siciliano wrote:
> >
> > Hi Olivier,
> >
> > Thanks a lot!
> >
> > I have a second question: how can I avoid the multiple TPavetext on the
> > histogram? Every time that I add a TPaveText is superimposed on the
> > previous and I want that only one TPavetext.
> >
> > Thanks for you help,
> >
> > Melinda
> >
> > On Mon, Mar 12, 2012 at 11:43 AM, Olivier Couet <Olivier.Couet_at_cern.ch>wrote:
> >
> >> Here is your macro modified
> >> Add(pave) was wrong ... pave is an array ...
> >> I put pave[1] you need to revisit the logic.
> >> I did some other mods .. do a diff...
> >>
> >> void tryhistos()
> >> {
> >> TH1F *histos[3];
> >> for (Int_t i=0;i<3;i++) {
> >> histos[i]=new TH1F(Form("histoname%d",i),Form("histotitle%d",i),
> >> 300,-0.5,29.5);
> >> }
> >> TCanvas *c1=new TCanvas("c1","c1");
> >> c1->Divide(1,3);
> >> TCanvas *c2=new TCanvas("c2","c2");
> >> c2->Divide(1,3);
> >>
> >> for(Int_t iii=0;iii<5;iii++){
> >> printf("n1 %d\n",iii);
> >> for (Int_t j=0;j<3;j++) {
> >> histos[0]->FillRandom("gaus",10000);
> >> histos[1]->FillRandom("landau",10000);
> >> histos[2]->FillRandom("expo",10000);
> >> }
> >> }
> >>
> >> TPaveText *pave[2];
> >> TH1 *histos2[3];
> >>
> >> for (Int_t hh=0;hh<5;hh++) {
> >> for (Int_t uu=0;uu<2;uu++) {
> >> pave[uu]=new TPaveText(0.3,0.88,0.9,0.99,"NDC");
> >> pave[uu]->AddText(Form("text %d",uu));
> >> pave[uu]->AddText(Form("text 2 %d",uu));
> >> pave[uu]->SetFillColor(4);
> >> pave[uu]->SetBorderSize(1);
> >> pave[uu]->SetLineWidth(1);
> >> }
> >> histos[0]->GetListOfFunctions()->Add(pave[1]);
> >> histos[1]->GetListOfFunctions()->Add(pave[1]);
> >> histos[2]->GetListOfFunctions()->Add(pave[1]);
> >> for(Int_t gg=0;gg<3;gg++)
> >> histos2[gg]=(TH1*)histos[gg]->Clone(Form("%s_cpy"
> >> ,histos[gg]->GetName()));
> >> c1->cd();
> >>
> >> for (Int_t z =0;z<3;z++) {
> >> c1->cd(z+1);
> >> histos[z]->Draw();
> >> c1->Update();
> >> }
> >>
> >> c2->cd();
> >> for (Int_t z =0;z<3;z++) {
> >> c2->cd(z+1);
> >> histos2[z]->DrawCopy();
> >> c2->Update();
> >> }
> >> }
> >> }
> >>
> >>
> >>
> >> On Mar 10, 2012, at 3:50 PM, Melinda Siciliano wrote:
> >>
> >> Dear all,
> >>
> >> I have a problem with the histograms cloning and it is reproduced in the
> >> macro I attached in the email. The error appears only if I add I the
> >> TPaveText to the histograms. I would like to know also how it is possible
> >> to avoid that the TPavetext are superimposed at every cycle. Have I to
> >> remove the TPaveText at the beginning of the new cycle? Does the clones
> >> have problems if some functions are attached to the histogram?
> >>
> >> I added below the log of the error.
> >>
> >> Cheers,
> >>
> >> Melinda
> >>
> >>
> >> The lines below might hint at the cause of the crash.
> >> If they do not help you then please submit a bug report at
> >> http://root.cern.ch/bugs. Please post the ENTIRE stack trace
> >> from above as an attachment in addition to anything else
> >> that might help us fixing this issue.
> >> ===========================================================
> >> #5 0x0000000000000000 in ?? ()
> >> #6 0x00007fba5d57555c in TClass::GetActualClass(void const*) const ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libCore.so.5.33
> >> #7 0x00007fba59f4078b in TBufferFile::WriteObjectAny(void const*, TClass
> >> const*) () from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #8 0x00007fba5d559a30 in TList::Streamer(TBuffer&) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libCore.so.5.33
> >> #9 0x00007fba59f428f2 in TBufferFile::WriteFastArray(void**, TClass
> >> const*, int, bool, TMemberStreamer*) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #10 0x00007fba5a0107b8 in int
> >> TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int,
> >> int, int) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #11 0x00007fba59f88ebe in
> >> TStreamerInfoActions::GenericWriteAction(TBuffer&, void*,
> >> TStreamerInfoActions::TConfiguration const*) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #12 0x00007fba59f3d2b5 in
> >> TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&,
> >> void*) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #13 0x00007fba59f3d355 in TBufferFile::WriteClassBuffer(TClass const*,
> >> void*)
> >> () from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #14 0x00007fba594d941a in TH1::Streamer(TBuffer&) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libHist.so
> >> #15 0x00007fba5d59e76a in TStreamerBase::WriteBuffer(TBuffer&, char*) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libCore.so.5.33
> >> #16 0x00007fba5a0117f5 in int
> >> TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int,
> >> int, int) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #17 0x00007fba59f88ebe in
> >> TStreamerInfoActions::GenericWriteAction(TBuffer&, void*,
> >> TStreamerInfoActions::TConfiguration const*) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #18 0x00007fba59f3d2b5 in
> >> TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&,
> >> void*) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #19 0x00007fba59f3d355 in TBufferFile::WriteClassBuffer(TClass const*,
> >> void*)
> >> () from /home/msicilia/work/alisoft/alice/root/trunk/lib/libRIO.so
> >> #20 0x00007fba5d4d1bdc in TDirectory::CloneObject(TObject const*, bool) ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libCore.so.5.33
> >> #21 0x00007fba5d4ea09d in TNamed::Clone(char const*) const ()
> >> from /home/msicilia/work/alisoft/alice/root/trunk/lib/libCore.so.5.33
> >> ===========================================================
> >>
> >> <tryhistos.C>
> >>
> >>
> >>
> >
> >
> >
>
Received on Tue Mar 13 2012 - 13:01:13 CET

This archive was generated by hypermail 2.2.0 : Tue Mar 13 2012 - 17:50:01 CET