From a31549b1f178447a03fc06f99a9ee1dd9033bbb9 Mon Sep 17 00:00:00 2001 From: Dave Gaskell Date: Fri, 21 Jun 2024 13:26:02 -0400 Subject: [PATCH] Make variables double precision in tree --- util/root_tree/froot.c | 32 ++++++++++++++++++++++++++++---- util/root_tree/make_root_tree.f | 5 +++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/util/root_tree/froot.c b/util/root_tree/froot.c index 0f80929..1b23f29 100644 --- a/util/root_tree/froot.c +++ b/util/root_tree/froot.c @@ -21,7 +21,7 @@ using namespace std; extern "C" { void initrootnt_(const char *title, const char *access, int ltitle, int laccess); void reinitrootnt_(const char *access, int laccess); - void addntbranch_(float *element, const char *chtag, int ltag); + void addntbranch_(double *element, const char *chtag, int ltag); void fillntbranch_(const char *chtag, int ltag); int getnumbranches_(); void rootntoutp_(); @@ -87,6 +87,30 @@ char *truestr(const char *str, int len) return tstr; }//truestr-> +//-------------------------------------------------------------------------- +char *leaftruestr(const char *str, int len) + // Converts a Fortran character string str of length len into a properly + // formed C character string with '\0' at the end; trims blank spaces + // at the end of the string + // DJG: This version adds the definition of the data type to put in the leaf of the branch + // DJG: ("/D"=double) +{ + int tlen=0; + char tem; +/*Counts non-blank charachters in a string str until a first blank character + or the end of the string is met*/ + + while (str[tlen] !=' ' && (tlen < len ) && (tem=str[tlen++],tem)) ; + + + char *tstr = new char[tlen+2]; + strncpy(tstr,str,tlen); + tstr[tlen]='/'; + tstr[tlen+1]='D'; + tstr[tlen+2]='\0'; + + return tstr; +}//truestr-> void teststr_(const char *str,int lstr) { @@ -151,10 +175,10 @@ void reinitrootnt_(const char *access, int laccess) //------------------------------------------------------------------------ - void addntbranch_(float *element, const char *chtag, int ltag) + void addntbranch_(double *element, const char *chtag, int ltag) //Add an ntuple branch pointing at a Fortran variable element { - nt->Branch(truestr(chtag,ltag),element, truestr(chtag,ltag)); + nt->Branch(truestr(chtag,ltag), element, leaftruestr(chtag,ltag)); return; }//addntbranch_ -> @@ -204,7 +228,7 @@ void printnt_() ////////////////////////////////////////////////////////////////////////// void initrootnt_(const char *title, const char *access, int ltitle, int laccess){return;} void reinitrootnt_(const char *access, int laccess){return;} - void addntbranch_(float *element, const char *chtag, int ltag){return;} + void addntbranch_(double *element, const char *chtag, int ltag){return;} void fillntbranch_(const char *chtag, int ltag){return;} int getnumbranches_(){return;} void printnt_(){return;} diff --git a/util/root_tree/make_root_tree.f b/util/root_tree/make_root_tree.f index d6b538b..12a26f0 100644 --- a/util/root_tree/make_root_tree.f +++ b/util/root_tree/make_root_tree.f @@ -13,13 +13,13 @@ program make_root_tree external GetNumBranches real*8 ntup(80) - real*4 ntup_out(80) + real*8 ntup_out(80) parameter(nev=10000000) io=99 c input filename - write(6,*) 'Enter filename to convert (without .bin extesntion)' + write(6,*) 'Enter filename to convert (without .bin extension)' read(5,*) rawname i=index(rawname,' ') filename='../../worksim/'//rawname(1:i-1)//'.bin' @@ -36,6 +36,7 @@ program make_root_tree do i=1,NtupleSize read(io) NtupleTag(i) call AddNtBranch(ntup_out(i),NtupleTag(i)) + write(6,*) NtupleTag(i) enddo c now loop over events