![]() |
RootMaker 1.0
A program to convert output from the PIBIDS simulation to a format readable by ROOT.
|
File containing the RootMaker software source code. More...
#include <stdlib.h>
#include <stdio.h>
#include "TFile.h"
#include "TTree.h"
Go to the source code of this file.
Classes | |
struct | EventHit |
Constitutes an event hit. More... | |
struct | Event |
Constitues an event (3 event hits + event number and A-Z information). More... | |
Defines | |
#define | xstr(s) str(s) |
#define | str(s) #s |
#define | NUMBER_OF_TUBES 40 |
Functions | |
int | main (int argc, char **argv) |
File containing the RootMaker software source code.
Definition in file dumproot.cc.
int main | ( | int | argc, |
char ** | argv | ||
) |
argc | Numer of arguments |
argv | ArgumentsMain function |
Definition at line 42 of file dumproot.cc.
References Event::eventno, and EventHit::time.
{ if (argc < 3) { fprintf (stderr,"Usage: %s <infile.txt> <outfile.root>\n",argv[0]); exit(1); } TFile hfile(argv[2],"RECREATE"); // Create a ROOT Tree TTree *tree = new TTree("T","Simulation result."); Event event; // Create branches. tree->Branch("event", &event.eventno, "eventno/I:A/I:Z/I"); //hopefully implantation. tree->Branch("hit1", &event.hit[0].time, "h1T/D:h1UFSP/F:h1LFSP/F:h1BSP/F:h1Ge/F:h1DET[" xstr(NUMBER_OF_TUBES) "]/F"); //hopefully decay. tree->Branch("hit2", &event.hit[1].time, "h2T/D:h2UFSP/F:h2LFSP/F:h2BSP/F:h2Ge/F:h2DET[" xstr(NUMBER_OF_TUBES) "]/F"); //some other decay? tree->Branch("hit2", &event.hit[2].time, "h3T/D:h3UFSP/F:h3LFSP/F:h3BSP/F:h3Ge/F:h2DET[" xstr(NUMBER_OF_TUBES) "]/F"); FILE * inputFile = fopen(argv[1],"r"); if(inputFile==NULL) { fprintf (stderr,"Could not open input file, exiting."); exit(1); } int numberOfFoundEvents = 0; int currentHitPtr=0; while(!feof(inputFile)) { int tmpEventNo, tmpA, tmpZ; double tmpTime; float tmpUFSP, tmpLFSP, tmpBSP, tmpGe; float tmpTube[NUMBER_OF_TUBES]; //event# Z A time upper lower back Ge Tubes[0-39] fscanf(inputFile,"%d %d %d",&tmpEventNo, &tmpA, &tmpZ); fscanf(inputFile, "%le", &tmpTime); fscanf(inputFile,"%e %e %e %e", &tmpUFSP, &tmpLFSP, &tmpBSP, &tmpGe); for(int i = 0; i<NUMBER_OF_TUBES; i++) { fscanf(inputFile,"%e",&tmpTube[i]); } if(event.eventno!=tmpEventNo) //Create new event. { if(numberOfFoundEvents>0) //don't fill the tree if there is nothing to fill it with. tree->Fill(); currentHitPtr=0; ++numberOfFoundEvents; } if(currentHitPtr==0) { memset(&event,0,sizeof(event)); } if(currentHitPtr<2) { event.eventno=tmpEventNo; event.A = tmpA; event.Z = tmpZ; event.hit[currentHitPtr].time=tmpTime; event.hit[currentHitPtr].UFSP=tmpUFSP; event.hit[currentHitPtr].LFSP=tmpLFSP; event.hit[currentHitPtr].BSP=tmpBSP; event.hit[currentHitPtr].Ge=tmpGe; for(int i = 0; i<NUMBER_OF_TUBES; i++) { event.hit[currentHitPtr].DET[i]=tmpTube[i]; } } ++currentHitPtr; } ++numberOfFoundEvents; tree->Fill(); fclose(inputFile); hfile.Write(); hfile.Close(); printf("A total of %d events was processed.\n",numberOfFoundEvents); return 0; }