Re: [ibsimu-forum] Manual Data Extraction
Status: Beta
Brought to you by:
tvkalvas
|
From: Kalvas, T. <tan...@jy...> - 2025-10-20 06:24:06
|
Hi!
This is something that has been done quite often in our projects.
Here is an example code that reads the pdb.dat and produces a profile sweep along X-axis. It produces a set of txt-files with Y and Z coordinates of each particle. This is roughly what you wanted.
// Read pdb
std::ifstream is_pdb( "pdb.dat" );
if( !is_pdb.good() )
throw( Error( ERROR_LOCATION, (std::string)"couldn\'t open file \'pdb.dat\'" ) );
ParticleDataBase3D pdb( is_pdb, geom );
is_pdb.close();
// Profile sweep
for( double x = 0.09; x <= geom.max(0); x += 0.005 ) {
TrajectoryDiagnosticData tdata;
std::vector <trajectory_diagnostic_e> diag;
diag.push_back( DIAG_CHARGE );
diag.push_back( DIAG_Y );
diag.push_back( DIAG_Z );
pdb.trajectories_at_plane( tdata, AXIS_X, x, diag );
std::vector<double> y;
std::vector<double> z;
// Go through particles, choose Q of interest
for( uint32_t i = 0; i < tdata.traj_size(); i++ ) {
int q = (int)round(tdata(i,0));
if( q == q_select ) {
y.push_back( tdata(i,1) );
z.push_back( tdata(i,2) );
}
}
// Profile output
std::stringstream ss;
ss << std::setw(3) << std::setfill('0') << 1000.0*x;
std::string filename = "profile_" + symbol + to_string(q_select) + "_" + ss.str() + ".txt";
std::ofstream ostr( filename.c_str() );
for( size_t i = 0; i < y.size(); i++ )
ostr << y[i] << " " << z[i] << "\n";
ostr.close();
}
--
Taneli Kalvas
Ph.D., Staff Scientist
Department of Physics, room FL104
P.O. Box 35 (YFL)
40014 University of Jyväskylä, Finland
Mobile: +358-44-314-1602
Fax: +358-14-617-411
Email: tan...@jy...
________________________________
From: PUYANDEH HOOMAN <hoo...@hi...>
Sent: Monday, October 20, 2025 8:17
To: ibs...@li... <ibs...@li...>
Subject: [ibsimu-forum] Manual Data Extraction
Dear All,
I intend to develop an extractor to extract the data from pdb.dat manually according to user's desire. For example, the extractor reads pdb.dat and extract the x-y beam profile from z=0.0 to z=0.036 with 1 mm step-size. Then, it prints the frame by frame extracted data into separate .dat files. This is really good for making evolution animations. Not only profile, but also emittance and anything that can be extracted from pdb.dat.
My main question is, 'How can I read pdb.dat? And how to determine my parameters (e.g., x-y plane) for data extraction?' I could not find a way for reading the binary pattern of pdb.dat. I could not open it with a text editor either because it is not readable.
Yours,
Hooman Puyandeh
|