Discussion:
[ROOT] Problem creating directories in TFile
James Jackson
2007-03-28 12:07:15 UTC
Permalink
I have a TFile, within which I create a directory (e.g. with file-
mkdir("Dir1")). If, from another section of my code, and given a
pointer to the file object, I run the following code:

file->cd();
file->cd("Dir1");
file->mkdir("Dir2");
file->cd("Dir2");

The result is that Dir2 is created under the file 'root' directory,
and not as a subdirectory of Dir1. This is with version 5.13.04e.

Any help appreciated,

Regards,
James Jackson
Roland Kuhn
2007-03-28 18:22:15 UTC
Permalink
Hi James!
Post by James Jackson
I have a TFile, within which I create a directory (e.g. with file-
mkdir("Dir1")). If, from another section of my code, and given a
file->cd();
This sets gDirectory = file.
Post by James Jackson
file->cd("Dir1");
This makes the previous line superfluous by setting gDirectory to
file:/Dir1.
Post by James Jackson
file->mkdir("Dir2");
This tells file to create a new subdirectory, which will of course be
file:/Dir2. Should you have used gDirectory->mkdir("Dir2") that would
have been different.
Post by James Jackson
file->cd("Dir2");
This sets gDirectory to file:/Dir2
Post by James Jackson
The result is that Dir2 is created under the file 'root' directory,
and not as a subdirectory of Dir1. This is with version 5.13.04e.
I don't see anything wrong here...

Ciao,
Roland

--
TU Muenchen, Physik-Department E18, James-Franck-Str., 85748 Garching
Telefon 089/289-12575; Telefax 089/289-12570
--
CERN office: 892-1-D23 phone: +41 22 7676540 mobile: +41 76 487 4482
--
Any society that would give up a little liberty to gain a little
security will deserve neither and lose both. - Benjamin Franklin
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GS/CS/M/MU d-(++) s:+ a-> C+++ UL++++ P+++ L+++ E(+) W+ !N K- w--- M
+ !V Y+
PGP++ t+(++) 5 R+ tv-- b+ DI++ e+++>++++ h---- y+++
------END GEEK CODE BLOCK------
Datao Gong
2007-03-28 21:42:33 UTC
Permalink
hi,Rooters,
I have a question about using TF1. I have to define a user-defined
function to fit histogram. If i define this function as a class member
function, it has to be a static member function. This requirement
bring me some troubles to pass member data to configure this function.
If i do not want to define the member data to be static type,
is there any easy way to pass by this problem?

Thanks a lot,

Datao
Rene Brun
2007-04-02 15:34:24 UTC
Permalink
Only static functions are accepted by the fitting functions.
In the CVS version an extension of TH1::Fit accepts fits with member
functions of classes
deriving from TF1 and redefining the function TF1::EvalPar. See an
example of use
in the attachment.

Rene Brun
Post by Datao Gong
hi,Rooters,
I have a question about using TF1. I have to define a user-defined
function to fit histogram. If i define this function as a class member
function, it has to be a static member function. This requirement
bring me some troubles to pass member data to configure this function.
If i do not want to define the member data to be static type,
is there any easy way to pass by this problem?
Thanks a lot,
Datao
Datao Gong
2007-04-02 15:39:36 UTC
Permalink
Thanks Rene! It is what i want.:)

Datao
Post by Rene Brun
Only static functions are accepted by the fitting functions.
In the CVS version an extension of TH1::Fit accepts fits with member
functions of classes
deriving from TF1 and redefining the function TF1::EvalPar. See an example of
use
in the attachment.
Rene Brun
Post by Datao Gong
hi,Rooters,
I have a question about using TF1. I have to define a user-defined
function to fit histogram. If i define this function as a class member
function, it has to be a static member function. This requirement
bring me some troubles to pass member data to configure this function.
If i do not want to define the member data to be static type,
is there any easy way to pass by this problem?
Thanks a lot,
Datao
Rene Brun
2007-04-03 14:24:59 UTC
Permalink
It looks like you have 0 or negative values in your scaler.eps plot.
I suggest setting a minimum (say 1) in your histogram.

Rene Brun
Hello,
I want to draw 3 curves in logarithm coordinate in a PAD,but failed to get
a figure like log.eps after getting the scaler.eps figure.
What can I do ? Thanks!
with best wishes,
Fengrong Zhu
Institute of High Energy Physics,
C.A.S P.R.C
--
Open WebMail Project (http://openwebmail.org)
------- End of Forwarded Message -------
with best wishes,
Fengrong Zhu
Institute of High Energy Physics,
C.A.S P.R.C
--
Open WebMail Project (http://openwebmail.org)
Olivier Couet
2007-04-03 14:46:44 UTC
Permalink
In case you still have the problem after René's suggestion, send me a small example macro reproducing the problem.
Cheers, Olivier Couet

-----Original Message-----
From: owner-***@pcroot.cern.ch [mailto:owner-***@pcroot.cern.ch] On Behalf Of Rene Brun
Sent: Tuesday, April 03, 2007 4:25 PM
To: Zhu FengRong
Cc: ***@pcroot.cern.ch
Subject: [ROOT] Re: Fw: about logarithm

It looks like you have 0 or negative values in your scaler.eps plot.
I suggest setting a minimum (say 1) in your histogram.

Rene Brun
Hello,
I want to draw 3 curves in logarithm coordinate in a PAD,but failed
to get a figure like log.eps after getting the scaler.eps figure.
What can I do ? Thanks!
with best wishes,
Fengrong Zhu
Institute of High Energy Physics,
C.A.S P.R.C
--
Open WebMail Project (http://openwebmail.org)
------- End of Forwarded Message -------
with best wishes,
Fengrong Zhu
Institute of High Energy Physics,
C.A.S P.R.C
--
Open WebMail Project (http://openwebmail.org)
Datao Gong
2007-04-03 21:48:13 UTC
Permalink
Rene,
Yes. It works. I defined a class myFit inherited from TF1.
class MyFit : public TF1
{
...
ClassDef(MyFit,1)
};

ClassImp(MyFit);

In the fitting routine:
TH1F* th1;
MyFit* fitfunc = new MyFit("myfit",minX,maxX);
...
th1->Fit(fitfunc,option);
...

Then i write the fitted histogram to a root file.

th1->Write();
...

The problem is when i use function pointer and TF1, the fitted curve
appears when i draw the histogram in the root file. When i use MyFit,
the fitted curve does not show when i re-draw the histogram in the root
file. The fitted parameter box does show the fitted parameters. Do i need
to do something to save the curve?

Thanks,

Datao
Post by Rene Brun
Only static functions are accepted by the fitting functions.
In the CVS version an extension of TH1::Fit accepts fits with member
functions of classes
deriving from TF1 and redefining the function TF1::EvalPar. See an example of
use
in the attachment.
Rene Brun
Post by Datao Gong
hi,Rooters,
I have a question about using TF1. I have to define a user-defined
function to fit histogram. If i define this function as a class member
function, it has to be a static member function. This requirement
bring me some troubles to pass member data to configure this function.
If i do not want to define the member data to be static type,
is there any easy way to pass by this problem?
Thanks a lot,
Datao
Rene Brun
2007-04-04 06:39:29 UTC
Permalink
Datao,

Are you using the CVS version? Fitting with a function derived from TF1
will work with any version
of ROOT, but the drawing of the function will only work with the CVS
version.

Rene Brun
Post by Datao Gong
Rene,
Yes. It works. I defined a class myFit inherited from TF1.
class MyFit : public TF1
{
...
ClassDef(MyFit,1)
};
ClassImp(MyFit);
TH1F* th1;
MyFit* fitfunc = new MyFit("myfit",minX,maxX);
...
th1->Fit(fitfunc,option);
...
Then i write the fitted histogram to a root file.
th1->Write();
...
The problem is when i use function pointer and TF1, the fitted curve
appears when i draw the histogram in the root file. When i use MyFit,
the fitted curve does not show when i re-draw the histogram in the root
file. The fitted parameter box does show the fitted parameters. Do i
need to do something to save the curve?
Thanks,
Datao
Post by Rene Brun
Only static functions are accepted by the fitting functions.
In the CVS version an extension of TH1::Fit accepts fits with member
functions of classes
deriving from TF1 and redefining the function TF1::EvalPar. See an
example of use
in the attachment.
Rene Brun
Post by Datao Gong
hi,Rooters,
I have a question about using TF1. I have to define a user-defined
function to fit histogram. If i define this function as a class member
function, it has to be a static member function. This requirement
bring me some troubles to pass member data to configure this function.
If i do not want to define the member data to be static type,
is there any easy way to pass by this problem?
Thanks a lot,
Datao
Gero Flucke
2007-03-30 14:48:56 UTC
Permalink
Post by James Jackson
I have a TFile, within which I create a directory (e.g. with file-
mkdir("Dir1")). If, from another section of my code, and given a pointer to
file->cd();
file->cd("Dir1");
file->mkdir("Dir2");
file->cd("Dir2");
The result is that Dir2 is created under the file 'root' directory, and not as
a subdirectory of Dir1. This is with version 5.13.04e.
Dear James,
what you probably want to do is

file->cd("Dir1");
gDirectory->mkdir("Dir2");
file->cd("Dir1/Dir2");

Cheers

Gero

--
-----------------------------------------------------------------------
Gero Flucke office: DESY, Bldg. 67b, room 24
Inst. f. Experimentalphysik fon: +49 (0)40 8998 2955
Universitaet Hamburg fax: +49 (0)40 8998 2959
Luruper Chaussee 149 at CERN: Bldg. 32 office 3-B20
22761 Hamburg fon: +41 (0)22 76-77557
Germany
Continue reading on narkive:
Search results for '[ROOT] Problem creating directories in TFile' (Questions and Answers)
10
replies
what are the keys on a macbook pro keyboard?
started 2008-03-27 12:45:56 UTC
laptops & notebooks
Loading...