[Gate-users] How to transfer the “.root” to “.dat” !?

Tony tucadaica at yahoo.com
Thu Feb 9 00:06:45 CET 2012


Hi Marc,

Thanks a lot for your file and your great help to others' questions. Although I am not the one who asked this question, I really appreciate what you have done to this mail list. 

I am a new Gate user who have learned much information from this mail list. I have been searching the archive for a while and have found that you have answered many questions but lots of your questions have not been answered :| I wish I could help you but they are beyond my knowledge.
Wish you all the best with your research.

Cheers,


________________________________
 From: Marc Chamberland <mchamber at connect.carleton.ca>
To: Spencer Lu <spencerbaibai at gmail.com> 
Cc: Gate-users at lists.opengatecollaboration.org 
Sent: Wednesday, 8 February 2012 11:16 PM
Subject: Re: [Gate-users] How to transfer the “.root” to “.dat” !?
 
My attachment did not make it to the mailing list.

Here's the macro I was using (just save it as a .cpp file):


/* extractLOR.cpp
*
* ROOT MACRO
* 
* Extract the LOR from the ROOT output
*
*/

{
    gROOT->Reset();
    
#include "Riostream.h"
    
    Int_t i, nevents;    //index i and number of event
    Double_t time;    //time of event
    Float_t x1, y1, z1, x2, y2, z2;    //endpoints of the LOR
    ofstream fout;    //output file
    fout.open("lor_resoSim1.txt");    //store the LOR in the file lor.txt
    
    TFile *f = new TFile("./resoSim1.root");    //replace "output.root" by your root file
    TTree *t = f->Get("Coincidences");    //this is where you tell it what "tree" you want to access: coincidences, singles, or I don't know what else
    
    //here, you get the address of all the info you want (but you don't get the actual values yet)
    t->SetBranchAddress("globalPosX1", &x1);
    t->SetBranchAddress("globalPosY1", &y1);
    t->SetBranchAddress("globalPosZ1", &z1);
    t->SetBranchAddress("globalPosX2", &x2);
    t->SetBranchAddress("globalPosY2", &y2);
    t->SetBranchAddress("globalPosZ2", &z2);
    t->SetBranchAddress("time1", &time);
    /*NOTE: the "name" of the info you want (e.g. "globalPosX1", or "time1") can be found in the root file;
     1) Open the root file in root: root yourRootFile.root
     2) Type: TBrowser t
     3) Navigate to your root file and open it
     4) Go into the Coincidences directory ("tree", in the root lingo)
     5) All the "leaves" you see are the information stored for each coincidence; this is where the "globalPosX1" and "time1" come from
     */
    
    nevents = t->GetEntries();    //I need the total number of events in order to loop adequately over all events
    
    //it's in this loop that you actually extract all the info that you just told root you wanted
    for (i = 0; i < nevents; i++) {
        t->GetEntry(i);    //here, you're accessing event #i; all your variables from above now get the values desired
        //write these values to a .txt file:
        fout << x1 << "\t" << y1 << "\t" << z1 << "\t";
        fout << x2 << "\t" << y2 << "\t" << z2 << "\t";
        fout << time*1000 << "\n";
    }
        
        fout.close();
}




Cheers!
Marc



__________________________


Marc Chamberland, MSc
PhD candidate
Department of Physics
Carleton University
Ottawa (ON)

Le 2012-02-08 à 4:10 AM, Spencer Lu a écrit :

> Dear,all
> 
> 
> Excuse me, How to transfer the *“.root”* to *“.dat”*  ??
> 
> 
> Since I found that when I used the “Parameterized fanbeam collimator” in
> Gate,
> 
> the ASCII output (.dat) won’t change while the "fanbeam collimator’s
> parameter" changes
> 
> Only the Root output works!!
> 
> But i have to get the root’s original data (like ASCII output) to reconstruct
> the image!
> 
> 
> 
> Thank you !
> 
> Best Regards
> 
> 
> 
> Spencer Lu
> 
> Medical Imgaing Processing Lab (MIPL)
> 
> Department of Biomedical Engineering and Environmental Sciences,
> 
> National Tsing-Hua University, Taiwan
> _______________________________________________
> Gate-users mailing list
> Gate-users at lists.opengatecollaboration.org
> http://lists.opengatecollaboration.org/mailman/listinfo/gate-users

_______________________________________________
Gate-users mailing list
Gate-users at lists.opengatecollaboration.org
http://lists.opengatecollaboration.org/mailman/listinfo/gate-users


More information about the Gate-users mailing list