Title: Accessing Event Data
1Accessing Event Data
2Objectives
- After completing this lesson, you should be able
to - Understand how objects are delivered to user
algorithms. - Retrieve objects from the event data store within
an algorithm. - Use relationships between objects.
- Specify event data input.
3Event Data Reside In Data Store
- Tree - similar to file system
- Identification by path/Event/MCEvent/MCEcalHit
- Objects or
- Containers of objectsObjectVectorltTypegt
4Containers ObjectVectorltTgt
- Templated class
- What you fill in are pointers to T
- Iteration like STL vector
ObjectVectorltMCParticlegt p...ObjectVectorltMCPa
rticlegtiterator ifor( ip-gtbegin() i !
p-gtend() i ) log ltlt MSGINFO ltlt
(i)-gtparticleID().id()
5Understanding Data Stores Loading
Try to accessan object data
6Caveats
- Consider Objects on the store asREAD-ONLY
- Do not modify existing objects!
- Do not destroy existing objects!
- Never, never delete an object which is registered
to the store - Its not yours!
- It will only screw up others!
7Data Access In Algorithms
- Objects can be accessed using a
SmartDataPtrltclass-typegt - Usage similar to a normal pointer
- SmartDataPtrltEventgt evt(eventSvc(),/Event)
- if ( !evt ) !error!
Do not forget to check validity
8SmartDataPtr Ingredients
- SmartDataPtrltEventgt evt( eventSvc(), /Event )
- Data store manager Pointer to service
- Item identifier location of the object
9SmartDataPtr Usage
- SmartDataPtrltEventgt evt(eventSvc(),/Event)
- if ( evt )
- MsgStream log(msgSvc(), name())
- log ltlt MSGINFO ltlt Run ltlt evt-gtrun()
- ltlt endreq
This will trigger some action
this as well
- If invalid the evt-gtrun() will cause access
violation (core dump)
10Relationships Between Objects
- Objects have relationships between each other
- Vertices are also connected to particles, but
this we neglect here...
11Implementing Relationships
- 0..1 Relationships can be implemented using a
SmartRefltclass-typegt - Usage similar to a normal pointer
- 0..n Relationships are implemented using a
SmartRefVectorltclass-typegtan array of
SmartRefltclass-typegt - Allow for late data loading
12Using These Relationships
class MCParticle ... SmartRefltMCVertexgt
m_originVertex ... MCVertex
originMCVertex() return m_originMCVertex
See Doxygen code documentation
load data and trigger conversion
13Using SmartReflttypegt
MCParticle p new MCParticle() SmartRefltMCParti
clegt ref
Assignment from raw pointer
ref p
p ref
Assignment to raw pointer
Usage
HepLorentzVector mom4 p-gtfourMomentum() HepLo
rentzVector mom4_2 ref-gtfourMomentum()
14Specify Event Data Input
EventSelector.Input FILEsicbmc.dat
Spec-1, ... ,Spec-n
- Event data input is specified in the job options
- Spec is an array of qualified
stringsKEY1VALUE1 KEYnVALUEn
15Specify SICB Event Input
Input Type KEY VALUE SICB data file FILE
/afs//myfile.dat SICB data from
JOBID JOBID 16835
- Retrieve JobIDs from the bookkeeping web page.
- Our main data source is SICB output.
16Specify Other Event Input
KEY VALUE EXAMPLE DATAFIL
E ltfile-namegt /afs//myfile.dat TYPE
lttechnologygt ROOT COLLECTIO
N lttuple-namegt MyCollection SELECTION
ltSQL-preselectiongt NTRACKgt50 FUNCTION
ltnamegt MySelector
17Hands On Print B0 Decays
- Use particle property service
- See User Guide chapter 12.5
- Retrieve MCParticles from event store
- /Event/MC/MCParticles
- Filter out the B0 particles
- Part. member particleID().id() is Geant 3
particle code - For each B0 Loop over all decay vertices and
print the decay particles - recursion ?
18DecayTreeAlgorithm.cpp Add Headers
include "CLHEP/Units/PhysicalConstants.h" includ
e "GaudiKernel/IParticlePropertySvc.h" include
"GaudiKernel/ParticleProperty.h" include
"GaudiKernel/SmartDataPtr.h" include
"LHCbEvent/MCParticle.h" include
"LHCbEvent/MCVertex.h"
19Using IParticlePropertySvc
...DecayTreeAlgorithm.h... IParticleProperySvc
m_ppSvc stdstring m_partName
long m_partID ...DecayTreeAlgorit
hminitialize()... m_ppSvc 0 StatusCode
sc service("ParticlePropertySvc", m_ppSvc )
if( !sc.isSuccess() ) // You have to handle
the error! ParticleProperty partProp
m_ppSvc-gtfind( m_partName ) if ( 0 partProp
) // You have to handle the error!
m_partID partProp-gtgeantID()
20Hands On Retrieve MCParticles
include GaudiKernel/SmartDataPtr.h
SmartDataPtrltMCParticleVectorgt
parts(eventSvc(), /Event/MC/MCParticles) if (
parts ) loop over particles
21Hands On Loop Over MCParticles
MCParticleVectorconst_iterator
i for(iparts-gtbegin()i ! parts-gtend() i )
if ( (i)-gtparticleID().id() m_partID )
printDecayTree( i )
New member function
22Hands On Print Decays
- For each selected particle
- Loop over decay vertices
- Print all daughters
- If daughters have decay vertices
- recurse
- If you run out of time, just print someparticle
property
23Loop Over Decay Vertices
const SmartRefVectorltMCVertexgt decays
mother-gtdecayMCVertices() SmartRefVectorltMCVert
exgtconst_iterator iv for (iv
decays.begin() iv ! decays.end() iv )
const SmartRefVectorltMCParticlegt daughters
(iv)-gtdaughterMCParticles()
SmartRefVectorltMCParticlegtconst_iterator idau
for (idaudaughters.begin()
idau!daughters.end() idau )
printDecayTree( 0, " ", idau )
24printDecayTree
void DecayTreeAlgorithmprintDecayTree(long
depth,
const stdstring prefix,
const MCParticle mother)
MsgStream log(msgSvc(), name()) const
SmartRefVectorltMCVertexgt decays
mother-gtdecayMCVertices() ParticleProperty p
m_ppSvc-gtfind( mother-gtparticleID().id() )
log ltlt MSGINFO ltlt depth ltlt prefix.substr(0,
prefix.length()-1) ltlt "---gt" ltlt
p-gtparticle() ltlt endreq if ( depth lt m_depth )
SmartRefVectorltMCVertexgtconst_iterator
iv for ( iv decays.begin() iv !
decays.end() iv ) const
SmartRefVectorltMCParticlegt daughters
(iv)-gtdaughterMCParticles()
SmartRefVectorltMCParticlegtconst_iterator idau
for ( idau daughters.begin() idau !
daughters.end() idau )
printDecayTree( depth1, prefix" ", idau )