Created
March 23, 2014 12:08
-
-
Save pgjones/9722241 to your computer and use it in GitHub Desktop.
Converts a space delimited file with `particle_type kinetic_energy time x_position y_position z_position` in to a RAT::DS root file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <RAT/DS/Root.hh> | |
#include <RAT/DS/MC.hh> | |
#include <RAT/DS/MCParticle.hh> | |
#include <TFile.h> | |
#include <TTree.h> | |
#include <fstream> | |
using namespace std; | |
void Convert( const char* inFileName, const char* outFileName ) | |
{ | |
TFile* rootFile = new TFile( outFileName, "RECREATE" ); | |
TTree* tree = new TTree( "T", "RAT Tree" ); | |
RAT::DS::Root* branchDS = new RAT::DS::Root(); | |
tree->Branch( "ds", branchDS->ClassName(), &branchDS, 32000, 99 ); | |
ifstream textFile( inFileName ); | |
int event = 0; | |
while( !textFile.eof() ) | |
{ | |
double particleType, kineticEnergy, time, xPosition, yPosition, zPosition; | |
textFile >> particleType >> kineticEnergy >> time >> xPosition >> yPosition >> zPosition; | |
RAT::DS::Root* ds = new RAT::DS::Root(); | |
RAT::DS::MC* mc = ds->GetMC(); | |
mc->SetMCTime( time ); // Event time or particle time?? | |
mc->SetEventID( event ); | |
RAT::DS::MCParticle* particle = mc->AddNewMCParticle(); | |
particle->SetPDGCode( particleType ); | |
particle->SetTime( 0 ); | |
particle->SetPos( TVector3( xPosition, yPosition, zPosition ) ); | |
//particle->SetMom( ); // Err?? | |
particle->SetKE( kineticEnergy ); | |
*branchDS = *ds; | |
tree->Fill(); | |
event++; | |
} | |
rootFile->Write(); | |
rootFile->Close(); | |
textFile.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment