This section will guide you trough the steps necessary to perform simple analysis in a C++ analysis framework (psana). For more detailed description of psana consult Psana User Manual.
User modules in psana are the instances of the C++ class which must inherit from a special base class psana::Module
. There are several methods in the base class which can be overriden in the subclass (event() must always be implemented):
void beginJob(Env& env)
void beginRun(Env& env)
void beginCalibCycle(Env& env)
void event(Event& evt, Env& env)
void endCalibCycle(Env& env)
void endRun(Env& env)
void endJob(Env& env)
To start with the doing analysis one should have user release setup first as explained in Packages and Releases. If you have not done it yet create a package for your analysis with some unique name:
newrel ana-current my_ana_rel # to make user release cd my_ana_rel sit_setup # never forget this! newpkg my_ana_pkg # to make package for analysis code
Good place to start writing analysis module is to create skeleton module from existing template:
mkdir my_ana_pkg/src my_ana_pkg/include codegen -l psana-module my_ana_pkg my_ana_mod
This will create files my_ana_pkg/include/my_ana_mod.h
and my_ana_pkg/src/my_ana_mod.cpp
which you need to edit and fill with some useful code. Start your favorite editor:
vi my_ana_pkg/src/my_ana_mod.cpp my_ana_pkg/include/my_ana_mod.h
For example purposes we are going to use beam line data and print few interesting values on every event. For that the code will be quite simple (excluding comments):
#ifndef MY_ANA_PKG_MY_ANA_MOD_H #define MY_ANA_PKG_MY_ANA_MOD_H #include "psana/Module.h" namespace my_ana_pkg { class my_ana_mod : public Module { public: my_ana_mod (const std::string& name) ; virtual ~my_ana_mod () ; virtual void event(Event& evt, Env& env); }; } #endif // MY_ANA_PKG_MY_ANA_MOD_H
#include "my_ana_pkg/my_ana_mod.h" #include "MsgLogger/MsgLogger.h" #include "PSEvt/EventId.h" #include "psddl_psana/bld.ddl.h" // This declares this class as psana module using namespace my_ana_pkg; PSANA_MODULE_FACTORY(my_ana_mod) namespace my_ana_pkg { my_ana_mod::my_ana_mod (const std::string& name) : Module(name) { } my_ana_mod::~my_ana_mod () { } void my_ana_mod::event(Event& evt, Env& env) { // get event time PSTime::Time evtTime; boost::shared_ptr<PSEvt::EventId> eventId = evt.get(); if (eventId.get()) { evtTime = eventId->time(); } // get beam data boost::shared_ptr<Psana::Bld::BldDataEBeam> ebeam = evt.get(Source()); if (ebeam.get()) { MsgLog(name(), info, "time: " << evtTime << ", charge: " << ebeam->ebeamCharge() << ", energy: " << ebeam->ebeamL3Energy()); } } }
After you finished editing your module build everything in the release:
scons
To run this analysis start pyana giving it module name and input files:
psana -m my_ana_pkg.my_ana_mod /reg/d/psdm/AMO/amo14110/xtc/e43-r0100-s0*
which should produce output similar to this:
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.043360843-07, charge: 0.233403, energy: 4393.24 [info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.093381914-07, charge: 0.248759, energy: 4380.69 [info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.143398446-07, charge: 0.243547, energy: 4384.99 [info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.193412744-07, charge: 0.249897, energy: 4393.3 [info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.243427879-07, charge: 0.248667, energy: 4389.08 [info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.293446716-07, charge: 0.245666, energy: 4392.14 [info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.343468975-07, charge: 0.251093, energy: 4389.05 [info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.393488859-07, charge: 0.253302, energy: 4389.31 ...