All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
WriteAlg.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/SmartDataPtr.h"
3 #include "GaudiKernel/MsgStream.h"
4 #include "GaudiKernel/RndmGenerators.h"
5 
6 #include "GaudiKernel/IDataProviderSvc.h"
7 #include "GaudiKernel/IDataManagerSvc.h"
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  MsgStream log(msgSvc(), name());
36  Rndm::Numbers rndmflat(randSvc(), Rndm::Flat(0.,1.));
37  Rndm::Numbers rndmgauss(randSvc(), Rndm::Gauss(10.,1.));
38 
39  // Create the Event header and set it as "root" of the event store
40  Event* event = new Event();
41  event->setEvent(++evtnum);
42  event->setRun(runnum);
43  event->setTime(Gaudi::Time());
44 
45  auto evtmgr = eventSvc().as<IDataManagerSvc>();
46  sc = evtmgr->setRoot("/Event", event);
47  if( sc.isFailure() ) {
48  log << MSG::ERROR << "Unable to register /Event object" << endmsg;
49  return sc;
50  }
51  // Create containers
52  MyTrackVector* myTracks = new MyTrackVector();
53  MyVertexVector* myVertices = new MyVertexVector();
54  // Create the primary trackm and vector
55  MyTrack* ptrack = new MyTrack((float)rndmgauss(),(float)rndmgauss(),(float)rndmgauss());
56  MyVertex* dvertex = new MyVertex(0,0,0);
57  ptrack->setDecayVertex(dvertex);
58  ptrack->setEvent(event);
59  dvertex->setMotherTrack(ptrack);
60  myTracks->add( ptrack );
61  myVertices->add ( dvertex );
62  // loop over first decays...
63  int n = (int)(rndmflat() * 100.);
64  for( int i = 0; i < n; i++ ) {
65  // Create new track
66  MyTrack* t = new MyTrack((float)rndmgauss(),(float)rndmgauss(),(float)rndmgauss());
67  myTracks->add ( t );
68  t->setEvent(event);
69  dvertex->addDaughterTrack(t);
70  if( rndmflat() > 0.5 ) {
71  MyVertex* dv = new MyVertex(rndmflat(),rndmflat(),rndmflat()*10.);
72  myVertices->add ( dv );
73  dv->setMotherTrack(t);
74  int m = (int)(rndmflat() * 10.);
75  for( int j = 0; j < m; j++ ) {
76  MyTrack* dt = new MyTrack(t->px()/m,t->py()/m,t->pz()/m);
77  myTracks->add ( dt );
78  dt->setEvent(event);
79  dv->addDaughterTrack(dt);
80  }
81  }
82  }
83 
84  sc = eventSvc()->registerObject("/Event","MyTracks",myTracks);
85  if( sc.isFailure() ) {
86  log << MSG::ERROR << "Unable to register MyTracks" << endmsg;
87  return sc;
88  }
89  sc = eventSvc()->registerObject("/Event","MyVertices",myVertices);
90  if( sc.isFailure() ) {
91  log << MSG::ERROR << "Unable to register MyVertices" << endmsg;
92  return sc;
93  }
94 
95  // All done
96  log << MSG::INFO << "Generated event " << evtnum << endmsg;
97  return StatusCode::SUCCESS;
98 }
99 
100 //--------------------------------------------------------------------
101 // Finalize
102 //--------------------------------------------------------------------
104  return StatusCode::SUCCESS;
105 }
virtual StatusCode finalize()
Finalize.
Definition: WriteAlg.cpp:103
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
def initialize()
Definition: AnalysisTest.py:12
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Essential information of the event used in examples It can be identified by "/Event".
Definition: Event.h:23
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
virtual StatusCode execute()
Event callback.
Definition: WriteAlg.cpp:29
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:919
Random number accessor This small class encapsulates the use of the random number generator...
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].
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
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
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Algorithm.cpp:1001