Vassili Maroussov | 1 Sep 2007 11:19
Picon
Picon

[ROOT] TVirtualFitter.SetParameter bug

Dear ROOTers,

I encountered the following problem with setting parameters for 
TVirtualFitter: if I'm trying to set parameters not sequentially 
(par[0],par[1],par[2],...) but in an arbitrary order, like 
par[0],par[2],par[1], the result is wrong. It looks like 
TVirtualFitter.SetParameter(...) ignores its' first parameter. Please 
see the script attached.

Regards,

Vassili

Attachment (fitter.C): text/x-c++, 941 bytes
John Zoidberg | 1 Sep 2007 19:12
Picon
Gravatar

[ROOT] Unable to use a class containing TLorentzVector...

I created a class called lotsofdata containing arrays of ints and TLorentzvectors.
For some strange reason, whenever I try to initialize a variable with that class, the macro exits ROOT directly without any message.

Here is a simplified version of the problem:

#define MAXBGD 40000

#include <fstream>
#include <iostream>
#include "TLorentzVector.h"
using namespace std;

class lotsofdata
{
    public:
        TLorentzVector PlBg[MAXBGD];
        TLorentzVector MinBg[MAXBGD];
        int PlBg_PDG[MAXBGD];
        int MinBg_PDG[MAXBGD];
        int PlBg_mamaPDG[MAXBGD];
        int MinBg_mamaPDG[MAXBGD];

    public:
        lotsofdata(void);
        ~lotsofdata(void);
        int Save(char* filename); /**< save class as binary */
        int Load(char* filename); /**< load class from binary */

        //ClassDef(lotsofdata,1);  //special for ROOT
};

//ClassImp(lotsofdata); //special for ROOT

//constructor
lotsofdata::lotsofdata()
{}

//destructor
lotsofdata::~lotsofdata()
{}

//save class
int lotsofdata::Save(char* filename)
{
    cout<<"SAVING AS BINARY"<<endl;
    ofstream ofs(filename, ios::binary);
    ofs.write((char *)this, sizeof(lotsofdata));
    return(0);
}

//load class
int lotsofdata::Load(char* filename)
{
    cout<<"LOADING FROM BINARY"<<endl;
    ifstream ifs(filename, ios::binary);

    // if fstream cannot open file
    if ( !ifs )
    {
        cerr << "WARNING: File could not be opened." << endl;
        return(1);
    } // end if

    ifs.read((char *)this, sizeof(lotsofdata));
    return(0);
}

void mystery(void)
{
    lotsofdata titi;
}

I compile it with .L mystery.C+ and then run mystery().

If the TLorentzVector lines are commented, I stay inside ROOT, if not, it exits without any message (even if I add cout or printf before initializing titi).

What's the problem with including TLorentzVectors in a class and how can I solve it?

Vassili Maroussov | 1 Sep 2007 19:36
Picon
Picon

[ROOT] TVectorD.Use

Dear ROOTers,

If to create a TVectorD, then to assign its' content with TVectorD.Use(Int_t npnt, Double_t *data),  deleting of the TVectorD doesn't free the memory, associated with the data. Is it a design feature or a bug?

Regards,

Vassili

Axel Naumann | 2 Sep 2007 12:27
Picon
Picon

Re: [ROOT] Unable to use a class containing TLorentzVector...

Hi John,

you probably exhaust your program's stack space. You request all your
data to be allocated on the stack, and there is simply not enough space.
Use "new" to allocate it on the heap.

Also:
* Don't use fixed-size C arrays; use std::vectors<LorentzVector> instead.
* Consider creating a class that contains one entry each, and then
create a vector of that class, instead of doing it the other way around.
* _Please_ use ROOT I/O. Your binary I/O will break _much_ sooner than
you think. E.g. when we change TObject (not that we will, but we could)
you will be unable to read any of your data back. With ROOT I/O this
can't happen. There are plenty more examples of how and when your
primitive binary I/O will break (32 vs. 64 bit, different OS, different
compiler...)

Cheers, Axel.

John Zoidberg wrote:
> I created a class called lotsofdata containing arrays of ints and
> TLorentzvectors.
> For some strange reason, whenever I try to initialize a variable with
> that class, the macro exits ROOT directly without any message.
> 
> Here is a simplified version of the problem:
> 
> #define MAXBGD 40000
> 
> #include <fstream>
> #include <iostream>
> #include "TLorentzVector.h"
> using namespace std;
> 
> class lotsofdata
> {
>     public:
>         TLorentzVector PlBg[MAXBGD];
>         TLorentzVector MinBg[MAXBGD];
>         int PlBg_PDG[MAXBGD];
>         int MinBg_PDG[MAXBGD];
>         int PlBg_mamaPDG[MAXBGD];
>         int MinBg_mamaPDG[MAXBGD];
> 
>     public:
>         lotsofdata(void);
>         ~lotsofdata(void);
>         int Save(char* filename); /**≤ save class as binary */
>         int Load(char* filename); /**≤ load class from binary */
> 
>         //ClassDef(lotsofdata,1);  //special for ROOT
> };
> 
> //ClassImp(lotsofdata); //special for ROOT
> 
> //constructor
> lotsofdata::lotsofdata()
> {}
> 
> //destructor
> lotsofdata::~lotsofdata()
> {}
> 
> //save class
> int lotsofdata::Save(char* filename)
> {
>     cout<<"SAVING AS BINARY"<<endl;
>     ofstream ofs(filename, ios::binary);
>     ofs.write((char *)this, sizeof(lotsofdata));
>     return(0);
> }
> 
> //load class
> int lotsofdata::Load(char* filename)
> {
>     cout<<"LOADING FROM BINARY"<<endl;
>     ifstream ifs(filename, ios::binary);
> 
>     // if fstream cannot open file
>     if ( !ifs )
>     {
>         cerr << "WARNING: File could not be opened." << endl;
>         return(1);
>     } // end if
> 
>     ifs.read((char *)this, sizeof(lotsofdata));
>     return(0);
> }
> 
> void mystery(void)
> {
>     lotsofdata titi;
> }
> 
> I compile it with .L mystery.C+ and then run mystery().
> 
> If the TLorentzVector lines are commented, I stay inside ROOT, if not,
> it exits without any message (even if I add cout or printf before
> initializing titi).
> 
> What's the problem with including TLorentzVectors in a class and how can
> I solve it?
> 

Rene Brun | 2 Sep 2007 15:38
Picon
Picon

Re: [ROOT] TVirtualFitter.SetParameter bug

Hi vassili,

This seems to be a problem with Minuit2. It is OK with Minuit.
Lorenzo will investigate as soon as he will be back online.
Thanks for reporting this problem.

Rene Brun

Vassili Maroussov wrote:
> Dear ROOTers,
>
> I encountered the following problem with setting parameters for 
> TVirtualFitter: if I'm trying to set parameters not sequentially 
> (par[0],par[1],par[2],...) but in an arbitrary order, like 
> par[0],par[2],par[1], the result is wrong. It looks like 
> TVirtualFitter.SetParameter(...) ignores its' first parameter. Please 
> see the script attached.
>
> Regards,
>
> Vassili
>
>

LU Xianguo | 3 Sep 2007 19:42
Picon
Gravatar

[ROOT] command in TMinuit to only calculate the covariance matrix

Hi rooters,
 
Does somebody know that :
 
what is the command telling TMinuit to
calculate the covariance matrix with the
current parameter values and NOT do minimization ?
 
Thanks very much !
 
Best Regards,
Xianguo

--
Take flight into the sky, beyond the moon, beyond my mind.

LU, Xianguo

DESY-HERMES
Notkestrasse 85
Hamburg, 22607
Germany

TEL: 0049-40-89983898 (o)
EMAIL:
xianguo.lu <at> desy.de
sinov <at> 163.com (Chinese)
Lorenzo Moneta | 4 Sep 2007 03:19
Picon
Picon

Re: [ROOT] command in TMinuit to only calculate the covariance matrix

You have to use 

TMinuit::mnemat(Double_t *emat, Int_t ndim)

where emat is a pointer to an array previously declared with size 
ndim*ndim,  where ndim are the number of free parameters. 

  Best Regards

 Lorenzo

On 3 Sep 2007, at 19:42, LU Xianguo wrote:

Hi rooters,
 
Does somebody know that :
 
what is the command telling TMinuit to
calculate the covariance matrix with the
current parameter values and NOT do minimization ?
 
Thanks very much !
 
Best Regards,
Xianguo

--
Take flight into the sky, beyond the moon, beyond my mind.

LU, Xianguo

DESY-HERMES
Notkestrasse 85
Hamburg, 22607
Germany

TEL: 0049-40-89983898 (o)
EMAIL:
xianguo.lu <at> desy.de
sinov <at> 163.com (Chinese)

Tom Roberts | 10 Sep 2007 17:16
Favicon

[ROOT] setting icon for TGMainFrame

My Root application is implemented as a TGMainFrame. How can I set the 
icon for this window? The documentation is obscure ("... this is 
typically done via the window manager", but no hint how to do that).

I need to handle Windows, Linux, and Mac OS X, and have versions of my 
icon in .ico, .png, and .icns formats.

Tom Roberts

Tom Roberts | 10 Sep 2007 19:24
Favicon

Re: [ROOT] setting icon for TGMainFrame

This is driving me crazy! Here's my code (inside a large macro):

         // set Gui.IconPath
         char tmp[1024];
         sprintf(tmp,"%s:%s",getenv("HOME"),
				gEnv->GetValue("Gui.IconPath","."));
         assert(strlen(tmp)<sizeof(tmp)); // snprintf() not available
         gEnv->SetValue("Gui.IconPath",tmp);
printf("Gui.IconPath='%s'\n",gEnv->GetValue("Gui.IconPath","."));

         window = new TGMainFrame(gClient->GetRoot(),200,200,
				kVerticalFrame);
         window->SetIconPixmap("historooticon.png");

Here's the output on Linux:

Gui.IconPath='/home/tjrob:/home/tjrob/icons:/home/tjrob/root/icons:.'
root [1] .!ls -l /home/tjrob/historooticon.png
-rw-r--r-- 1 tjrob tjrob 591 Sep 10 11:56 /home/tjrob/historooticon.png

That output looks fine, BUT I GET THE WRONG ICON (the default X-windows 
"X").

If I copy historooticon.png to either /home/tjrob/root/icons or "." then 
I get the correct icon.

What is going on? Why doesn't it use the updated Gui.IconPath?

Tom Roberts

Ilka Antcheva wrote:
> Hi Tom,
> 
> Define for your class const TGPicture *fIconPic;
> In your class constructor use:
> fIconPic = SetIconPixmap("your_icon.png");
> In your class destructor (to avoid memory leak):
> if (fIconPic) gClient->FreePicture(fIconPic);
> 
> If you need to specify in addition the special path to the icon 
> directory, you may have a look at 
> http://root.cern.ch/phpBB2/viewtopic.php?t=5390
> 
> Cheers, Ilka
> 
> Tom Roberts wrote:
>> My Root application is implemented as a TGMainFrame. How can I set the 
>> icon for this window? The documentation is obscure ("... this is 
>> typically done via the window manager", but no hint how to do that).
>>
>> I need to handle Windows, Linux, and Mac OS X, and have versions of my 
>> icon in .ico, .png, and .icns formats.
>>
>>
>> Tom Roberts
>>

Valeri Onuchin | 10 Sep 2007 20:06
Picon
Picon

RE: [ROOT] setting icon for TGMainFrame

Hi Tom,

1. try to use TString  for cases "// snprintf() not available"
2. in SetIconPixmap("historooticon.png") you must
specify full path name to the icon file. i.e.
/home/tjrob/root/icons/historooticon.png

Another possibility one can embed an icon into application,
the code is below. We can provide a helper method for this.

Regards. Valeriy

// in fact, an XPM file can be included as
// #include "bld_rgb.xpm"

/* XPM */
char *bld_rgb[] = {
/* width height num_colors chars_per_pixel */
"    32    32        3            1",
/* colors */
". c #008000",
"# c #ff0000",
"a c #0000ff",
/* pixels */
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"#########............aaaaaaaaaaa"
};

TGMainFrame *window = new TGMainFrame(gClient->GetRoot(),200,200);
TImage *img = TImage::Create();
img->SetImageBuffer(bld_rgb, TImage::kXpm);
gVirtualX->SetIconPixmap(window->GetId(), img->GetPixmap());
delete img;
window->MapRaised();

-----Original Message-----
From: owner-roottalk <at> root.cern.ch on behalf of Tom Roberts
Sent: Mon 9/10/2007 7:24 PM
To: 'ROOT Talk'
Subject: Re: [ROOT] setting icon for TGMainFrame

This is driving me crazy! Here's my code (inside a large macro):

         // set Gui.IconPath
         char tmp[1024];
         sprintf(tmp,"%s:%s",getenv("HOME"),
				gEnv->GetValue("Gui.IconPath","."));
         assert(strlen(tmp)<sizeof(tmp)); // snprintf() not available
         gEnv->SetValue("Gui.IconPath",tmp);
printf("Gui.IconPath='%s'\n",gEnv->GetValue("Gui.IconPath","."));

         window = new TGMainFrame(gClient->GetRoot(),200,200,
				kVerticalFrame);
         window->SetIconPixmap("historooticon.png");

Here's the output on Linux:

Gui.IconPath='/home/tjrob:/home/tjrob/icons:/home/tjrob/root/icons:.'
root [1] .!ls -l /home/tjrob/historooticon.png
-rw-r--r-- 1 tjrob tjrob 591 Sep 10 11:56 /home/tjrob/historooticon.png

That output looks fine, BUT I GET THE WRONG ICON (the default X-windows 
"X").

If I copy historooticon.png to either /home/tjrob/root/icons or "." then 
I get the correct icon.

What is going on? Why doesn't it use the updated Gui.IconPath?

Tom Roberts

Ilka Antcheva wrote:
> Hi Tom,
> 
> Define for your class const TGPicture *fIconPic;
> In your class constructor use:
> fIconPic = SetIconPixmap("your_icon.png");
> In your class destructor (to avoid memory leak):
> if (fIconPic) gClient->FreePicture(fIconPic);
> 
> If you need to specify in addition the special path to the icon 
> directory, you may have a look at 
> http://root.cern.ch/phpBB2/viewtopic.php?t=5390
> 
> Cheers, Ilka
> 
> Tom Roberts wrote:
>> My Root application is implemented as a TGMainFrame. How can I set the 
>> icon for this window? The documentation is obscure ("... this is 
>> typically done via the window manager", but no hint how to do that).
>>
>> I need to handle Windows, Linux, and Mac OS X, and have versions of my 
>> icon in .ico, .png, and .icns formats.
>>
>>
>> Tom Roberts
>>


Gmane