RootMaker 1.0
A program to convert output from the PIBIDS simulation to a format readable by ROOT.
dumproot.cc
Go to the documentation of this file.
00001 #define xstr(s) str(s)
00002 #define str(s) #s
00003 #define NUMBER_OF_TUBES 40
00004 
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 
00008 #include "TFile.h"
00009 #include "TTree.h"
00010 
00019 struct EventHit
00020 {
00021   double time; 
00022 
00023   float UFSP; 
00024   float LFSP; 
00025   float BSP; 
00026   float Ge; 
00027 
00028   float DET[NUMBER_OF_TUBES];  // energy in detector
00029 };
00030 
00033 struct Event
00034 {
00035   int eventno; 
00036   int A; 
00037   int Z; 
00038 
00039   EventHit hit[3]; // 0 normally implantation, 1 decay, 2 spurious
00040 };
00041 
00042 int main(int argc , char **argv ) 
00043 {
00044   if (argc < 3)
00045     {
00046       fprintf (stderr,"Usage: %s <infile.txt> <outfile.root>\n",argv[0]);
00047       exit(1);
00048     }
00049   
00050   TFile hfile(argv[2],"RECREATE");
00051   
00052   // Create a ROOT Tree
00053   
00054   TTree *tree = new TTree("T","Simulation result.");
00055   
00056   Event event;
00057   
00058   // Create branches.
00059   
00060   tree->Branch("event", &event.eventno,
00061                "eventno/I:A/I:Z/I");
00062   
00063   //hopefully implantation.
00064   tree->Branch("hit1",  &event.hit[0].time,
00065                "h1T/D:h1UFSP/F:h1LFSP/F:h1BSP/F:h1Ge/F:h1DET[" xstr(NUMBER_OF_TUBES) "]/F");
00066   //hopefully decay.
00067   tree->Branch("hit2",  &event.hit[1].time,
00068                "h2T/D:h2UFSP/F:h2LFSP/F:h2BSP/F:h2Ge/F:h2DET[" xstr(NUMBER_OF_TUBES) "]/F");
00069   //some other decay?
00070   tree->Branch("hit2",  &event.hit[2].time,
00071                "h3T/D:h3UFSP/F:h3LFSP/F:h3BSP/F:h3Ge/F:h2DET[" xstr(NUMBER_OF_TUBES) "]/F");
00072   
00073   FILE * inputFile = fopen(argv[1],"r");
00074   if(inputFile==NULL)
00075     {
00076       fprintf (stderr,"Could not open input file, exiting.");
00077       exit(1);
00078     }
00079   
00080   int numberOfFoundEvents = 0;
00081   int currentHitPtr=0;
00082   while(!feof(inputFile))
00083     {
00084       int tmpEventNo, tmpA, tmpZ;
00085       double tmpTime;
00086       float tmpUFSP, tmpLFSP, tmpBSP, tmpGe;
00087       float tmpTube[NUMBER_OF_TUBES];
00088       
00089       //event# Z A time upper lower back Ge Tubes[0-39]
00090       fscanf(inputFile,"%d %d %d",&tmpEventNo, &tmpA, &tmpZ);
00091       
00092       fscanf(inputFile, "%le", &tmpTime);
00093       
00094       fscanf(inputFile,"%e %e %e %e", &tmpUFSP, &tmpLFSP, &tmpBSP, &tmpGe);
00095       
00096       for(int i = 0; i<NUMBER_OF_TUBES; i++)
00097         {
00098           fscanf(inputFile,"%e",&tmpTube[i]);
00099         }
00100       
00101       if(event.eventno!=tmpEventNo) //Create new event.
00102         {
00103           if(numberOfFoundEvents>0) //don't fill the tree if there is nothing to fill it with.
00104             tree->Fill();
00105           currentHitPtr=0;
00106           ++numberOfFoundEvents;
00107         }
00108       if(currentHitPtr==0)
00109         {
00110           memset(&event,0,sizeof(event));
00111         }
00112       if(currentHitPtr<2)
00113         {
00114           event.eventno=tmpEventNo;
00115           event.A = tmpA; 
00116           event.Z = tmpZ;
00117           event.hit[currentHitPtr].time=tmpTime;
00118           event.hit[currentHitPtr].UFSP=tmpUFSP;
00119           event.hit[currentHitPtr].LFSP=tmpLFSP;
00120           event.hit[currentHitPtr].BSP=tmpBSP;
00121           event.hit[currentHitPtr].Ge=tmpGe;
00122           for(int i = 0; i<NUMBER_OF_TUBES; i++)
00123             {
00124               event.hit[currentHitPtr].DET[i]=tmpTube[i];
00125             }     
00126         }
00127       ++currentHitPtr;
00128     }
00129   ++numberOfFoundEvents;
00130   tree->Fill();
00131   
00132   fclose(inputFile);
00133   hfile.Write();
00134   hfile.Close();
00135   printf("A total of %d events was processed.\n",numberOfFoundEvents);
00136   return 0;
00137 }
00138 
00139 
 All Classes Files Functions Variables

Back to the main page of the Precalibrated Ion Beam Identification Detector project

Created by Rikard Lundmark