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 - Old.
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(Event& evt, Env& env)
void beginRun(Event& evt, Env& env)
void beginCalibCycle(Event& evt, Env& env)
void event(Event& evt, Env& env)
void endCalibCycle(Event& evt, Env& env)
void endRun(Event& evt, Env& env)
void endJob(Event& evt, 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:
...
Code Block |
---|
title | my_ana_pkg/include/my_ana_mod.h |
---|
|
#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
|
Code Block |
---|
title | my_ana_pkg/src/my_ana_mod.cpp |
---|
|
#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());
}
}
}
|
...
Code Block |
---|
title | my_ana_pkg/include/my_ana_mod.h |
---|
|
#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);
virtual void endJob(Event& evt, Env& env);
private:
double m_threshold;
unsigned long m_count;
unsigned long m_total;
};
}
#endif // MY_ANA_PKG_MY_ANA_MOD_H
|
Code Block |
---|
title | my_ana_pkg/src/my_ana_mod.cpp |
---|
|
#include "my_ana_pkg/my_ana_mod.h"
#include "MsgLogger/MsgLogger.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)
, m_threshold(0.0)
, m_count(0)
, m_total(0)
{
m_threshold = config("threshold");
}
my_ana_mod::~my_ana_mod ()
{
}
void
my_ana_mod::event(Event& evt, Env& env)
{
// get beam data
boost::shared_ptr<Psana::Bld::BldDataEBeam> ebeam = evt.get(Source());
if (ebeam.get()) {
if (ebeam->ebeamL3Energy() > m_threshold) {
++ m_count;
}
++ m_total;
}
}
void
my_ana_mod::endJob(Event& evt, Env& env)
{
MsgLog(name(), info, "Fraction of events with energy>" << m_threshold
<< " is " << m_count*100.0/m_total << "%");
}
}
|
...
More interesting example is to run two instances of the same module in a job with different set of parameters. For this just replace the content of psana.cfg with this:
Code Block |
---|
% psana /reg/d/psdm/AMO/amo14110/xtc/e43-r0100-s0*
[info:[psana]
modules = my_ana_pkg.my_ana_mod:thresh4390] Fraction of events with energy>4390 is 55.613%
[info:my_ana_pkg.my_ana_mod:thresh4400] Fraction of events with energy>4400 is 15.9316%
|
and run again:
Code Block |
---|
[psana]
modules = my_ana_pkg.my_ana_mod:thresh4390]
threshold = 4390
[my_ana_pkg.my_ana_mod:thresh4400]
threshold = 4400
|
and run again:
Code Block |
---|
% psana /reg/d/psdm/AMO/amo14110/xtc/e43-r0100-s0*
[info:my_ana_pkg.my_ana_mod:thresh4390]
threshold = 4390
[ Fraction of events with energy>4390 is 55.613%
[info:my_ana_pkg.my_ana_mod:thresh4400]
threshold = 4400 Fraction of events with energy>4400 is 15.9316%
|