WriteAlg.cpp
Go to the documentation of this file.
1 // Framework include files
5 
8 
9 // Example related include files
10 #include "WriteAlg.h"
11 
12 // Event Model related classes
13 #include "Event.h"
14 #include "MyTrack.h"
15 #include "MyVertex.h"
16 
18 
19 //--------------------------------------------------------------------
20 // Initialize
21 //--------------------------------------------------------------------
23  return StatusCode::SUCCESS;
24 }
25 
26 //--------------------------------------------------------------------
27 // Execute
28 //--------------------------------------------------------------------
30  StatusCode sc;
31 
32  static int evtnum = 0;
33  static int runnum = 999;
34 
35  Rndm::Numbers rndmflat(randSvc(), Rndm::Flat(0.,1.));
36  Rndm::Numbers rndmgauss(randSvc(), Rndm::Gauss(10.,1.));
37 
38  // Create the Event header and set it as "root" of the event store
39  Event* event = new Event();
40  event->setEvent(++evtnum);
41  event->setRun(runnum);
42  event->setTime(Gaudi::Time());
43 
44  auto evtmgr = eventSvc().as<IDataManagerSvc>();
45  sc = evtmgr->setRoot("/Event", event);
46  if( sc.isFailure() ) {
47  error() << "Unable to register /Event object" << endmsg;
48  return sc;
49  }
50  // Create containers
51  MyTrackVector* myTracks = new MyTrackVector();
52  MyVertexVector* myVertices = new MyVertexVector();
53  // Create the primary trackm and vector
54  MyTrack* ptrack = new MyTrack((float)rndmgauss(),(float)rndmgauss(),(float)rndmgauss());
55  MyVertex* dvertex = new MyVertex(0,0,0);
56  ptrack->setDecayVertex(dvertex);
57  ptrack->setEvent(event);
58  dvertex->setMotherTrack(ptrack);
59  myTracks->add( ptrack );
60  myVertices->add ( dvertex );
61  // loop over first decays...
62  int n = (int)(rndmflat() * 100.);
63  for( int i = 0; i < n; i++ ) {
64  // Create new track
65  MyTrack* t = new MyTrack((float)rndmgauss(),(float)rndmgauss(),(float)rndmgauss());
66  myTracks->add ( t );
67  t->setEvent(event);
68  dvertex->addDaughterTrack(t);
69  if( rndmflat() > 0.5 ) {
70  MyVertex* dv = new MyVertex(rndmflat(),rndmflat(),rndmflat()*10.);
71  myVertices->add ( dv );
72  dv->setMotherTrack(t);
73  int m = (int)(rndmflat() * 10.);
74  for( int j = 0; j < m; j++ ) {
75  MyTrack* dt = new MyTrack(t->px()/m,t->py()/m,t->pz()/m);
76  myTracks->add ( dt );
77  dt->setEvent(event);
78  dv->addDaughterTrack(dt);
79  }
80  }
81  }
82 
83  sc = eventSvc()->registerObject("/Event","MyTracks",myTracks);
84  if( sc.isFailure() ) {
85  error() << "Unable to register MyTracks" << endmsg;
86  return sc;
87  }
88  sc = eventSvc()->registerObject("/Event","MyVertices",myVertices);
89  if( sc.isFailure() ) {
90  error() << "Unable to register MyVertices" << endmsg;
91  return sc;
92  }
93 
94  // All done
95  info() << "Generated event " << evtnum << endmsg;
96  return StatusCode::SUCCESS;
97 }
98 
99 //--------------------------------------------------------------------
100 // Finalize
101 //--------------------------------------------------------------------
103  return StatusCode::SUCCESS;
104 }
virtual StatusCode finalize()
Finalize.
Definition: WriteAlg.cpp:102
def initialize()
Definition: AnalysisTest.py:12
Essential information of the event used in examples It can be identified by "/Event".
Definition: Event.h:23
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
virtual long add(ContainedObject *pObject)
ObjectContainerBase overload: Add an object to the container.
void setDecayVertex(MyVertex *decay)
Access to event object.
Definition: MyTrack.h:89
void setMotherTrack(MyTrack *value)
Update pointer to mother particle (by a C++ pointer or a smart reference)
Definition: MyVertex.h:60
float py() const
Accessors: Retrieve y-component of the track momentum.
Definition: MyTrack.h:49
Parameters for the Gauss random number generation.
void setEvent(Event *evt)
Access to event object.
Definition: MyTrack.h:64
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
virtual StatusCode execute()
Event callback.
Definition: WriteAlg.cpp:29
Random number accessor This small class encapsulates the use of the random number generator...
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:110
KeyedContainer< MyVertex > MyVertexVector
Definition: MyVertex.h:95
Based on seal::Time.
Definition: Time.h:213
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
float px() const
Accessors: Retrieve x-component of the track momentum.
Definition: MyTrack.h:47
constexpr double m
Definition: SystemOfUnits.h:93
Parameters for the flat random number generation within boundaries [minimum, maximum].
WriteAlg class for the RootIOExample.
Definition: WriteAlg.h:14
void addDaughterTrack(MyTrack *value)
Retrieve pointer to vector of daughter particles (const or non-const)
Definition: MyVertex.h:72
float pz() const
Accessors: Retrieve z-component of the track momentum.
Definition: MyTrack.h:51
SmartIF< IRndmGenSvc > & randSvc() const
AIDA-based NTuple service Returns a pointer to the AIDATuple service if present.
Simple class that represents a vertex for testing purposes.
Definition: MyVertex.h:23
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
KeyedContainer< MyTrack > MyTrackVector
Definition: MyTrack.h:94
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244