24
Gaudi Framework Tutorial, 2001 4 4 Accessing Event Data

Accessing Event Data

  • Upload
    milton

  • View
    20

  • Download
    0

Embed Size (px)

DESCRIPTION

Accessing Event Data. Objectives. 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. - PowerPoint PPT Presentation

Citation preview

Page 1: Accessing Event Data

Gaudi Framework Tutorial, 2001

44

Accessing Event DataAccessing Event Data

Page 2: Accessing Event Data

4-2 Gaudi Framework Tutorial, 2001

ObjectivesObjectives

After completing this lesson, you should After completing this lesson, you should be able to: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.

After completing this lesson, you should After completing this lesson, you should be able to: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.

Page 3: Accessing Event Data

4-3 Gaudi Framework Tutorial, 2001

Event Data Reside In Data StoreEvent Data Reside In Data Store

TreeTree - similar to file - similar to file systemsystem

IdentificationIdentification by path by path”/Event/MCEvent/MCEcalHit””/Event/MCEvent/MCEcalHit”

ObjectsObjects or or

ContainersContainers of objects of objectsObjectVector<Type>ObjectVector<Type>

TreeTree - similar to file - similar to file systemsystem

IdentificationIdentification by path by path”/Event/MCEvent/MCEcalHit””/Event/MCEvent/MCEcalHit”

ObjectsObjects or or

ContainersContainers of objects of objectsObjectVector<Type>ObjectVector<Type>

Page 4: Accessing Event Data

4-4 Gaudi Framework Tutorial, 2001

Containers: ObjectVector<T>Containers: ObjectVector<T>

ObjectVector<MCParticle>*ObjectVector<MCParticle>* p; p;......ObjectVector<MCParticle>::iterator i;ObjectVector<MCParticle>::iterator i;for( i=p->begin(); i != p->end(); i++ ) {for( i=p->begin(); i != p->end(); i++ ) { log << MSG::INFO << (*i)->particleID().id(); log << MSG::INFO << (*i)->particleID().id();}}

ObjectVector<MCParticle>*ObjectVector<MCParticle>* p; p;......ObjectVector<MCParticle>::iterator i;ObjectVector<MCParticle>::iterator i;for( i=p->begin(); i != p->end(); i++ ) {for( i=p->begin(); i != p->end(); i++ ) { log << MSG::INFO << (*i)->particleID().id(); log << MSG::INFO << (*i)->particleID().id();}}

•Templated classTemplated class

•What you fill in are What you fill in are pointers to Tpointers to T

•Iteration like STL vectorIteration like STL vector

•Templated classTemplated class

•What you fill in are What you fill in are pointers to Tpointers to T

•Iteration like STL vectorIteration like STL vector

Page 5: Accessing Event Data

4-5 Gaudi Framework Tutorial, 2001

Understanding Data Stores: LoadingUnderstanding Data Stores: Loading

(5) Register

DataService

Algorithm

(1) retrieveObject(…)

Try to accessan object data

(2) Search in Store

Data Store

Unsuccessful ifrequested object is

not present

ConverterConverterConverterConverter

(4) Request creation

(3) Request load

PersistencyService

ConversionService

Request dispatcherObjy, SICB,

ROOT,..

Page 6: Accessing Event Data

4-6 Gaudi Framework Tutorial, 2001

CaveatsCaveats

Consider Objects on the store asConsider Objects on the store asREAD-ONLYREAD-ONLY

• Do not modify existing objects!

• Do not destroy existing objects!

Never, never delete an object which is Never, never delete an object which is registered to the storeregistered to the store

• It’s not yours!

• It will only screw up others!

Consider Objects on the store asConsider Objects on the store asREAD-ONLYREAD-ONLY

• Do not modify existing objects!

• Do not destroy existing objects!

Never, never delete an object which is Never, never delete an object which is registered to the storeregistered to the store

• It’s not yours!

• It will only screw up others!

Page 7: Accessing Event Data

4-7 Gaudi Framework Tutorial, 2001

Data Access In AlgorithmsData Access In Algorithms

• Objects can be accessed using a SmartDataPtr<class-type>

• Usage similar to a normal pointer

• Objects can be accessed using a SmartDataPtr<class-type>

• Usage similar to a normal pointer

SmartDataPtr<Event> evt(eventSvc(),“/Event”);SmartDataPtr<Event> evt(eventSvc(),“/Event”);

if ( !evt ) {if ( !evt ) { !error!!error!}}

SmartDataPtr<Event> evt(eventSvc(),“/Event”);SmartDataPtr<Event> evt(eventSvc(),“/Event”);

if ( !evt ) {if ( !evt ) { !error!!error!}}

Do not forget to check validityDo not forget to check validity

Page 8: Accessing Event Data

4-8 Gaudi Framework Tutorial, 2001

SmartDataPtr IngredientsSmartDataPtr Ingredients

SmartDataPtr<Event> SmartDataPtr<Event>

evt( eventSvc(), “/Event” );evt( eventSvc(), “/Event” );

SmartDataPtr<Event> SmartDataPtr<Event>

evt( eventSvc(), “/Event” );evt( eventSvc(), “/Event” );

• Template class type• Template class type

• Data store manager: Pointer to service• Data store manager: Pointer to service

• Item identifier: location of the object• Item identifier: location of the object

Page 9: Accessing Event Data

4-9 Gaudi Framework Tutorial, 2001

SmartDataPtr UsageSmartDataPtr Usage

SmartDataPtr<Event> evt(eventSvc(),“/Event”);SmartDataPtr<Event> evt(eventSvc(),“/Event”);

if ( evt ) {if ( evt ) {

MsgStream log(msgSvc(), name());MsgStream log(msgSvc(), name());

log << MSG::INFO << “Run#:” << evt->run()log << MSG::INFO << “Run#:” << evt->run()

<< endreq;<< endreq;

}}

SmartDataPtr<Event> evt(eventSvc(),“/Event”);SmartDataPtr<Event> evt(eventSvc(),“/Event”);

if ( evt ) {if ( evt ) {

MsgStream log(msgSvc(), name());MsgStream log(msgSvc(), name());

log << MSG::INFO << “Run#:” << evt->run()log << MSG::INFO << “Run#:” << evt->run()

<< endreq;<< endreq;

}}

This will trigger some actionThis will trigger some action

…this as well…this as well

• If invalid the evt->run() will cause access violation (core dump)

• If invalid the evt->run() will cause access violation (core dump)

Page 10: Accessing Event Data

4-10 Gaudi Framework Tutorial, 2001

Relationships Between ObjectsRelationships Between Objects

• Objects have relationships between each other

• Objects have relationships between each other

MCParticleMCParticle MCVertexMCVertex0..1 m_originMCVertex0..1 m_originMCVertex

0..n m_decayMCVertices0..n m_decayMCVertices

• Vertices are also connected to particles, but this we neglect here...

• Vertices are also connected to particles, but this we neglect here...

Page 11: Accessing Event Data

4-11 Gaudi Framework Tutorial, 2001

Implementing RelationshipsImplementing Relationships

• 0..1 Relationships can be implemented using a SmartRef<class-type>

• Usage similar to a normal pointer

• 0..n Relationships are implemented using a SmartRefVector<class-type>…an array of SmartRef<class-type>

• Allow for late data loading

• 0..1 Relationships can be implemented using a SmartRef<class-type>

• Usage similar to a normal pointer

• 0..n Relationships are implemented using a SmartRefVector<class-type>…an array of SmartRef<class-type>

• Allow for late data loading

Page 12: Accessing Event Data

4-12 Gaudi Framework Tutorial, 2001

Using These RelationshipsUsing These Relationships

class MCParticle {class MCParticle {

......

SmartRef<MCVertex> m_originVertex;SmartRef<MCVertex> m_originVertex;

......

MCVertex* originMCVertex() {MCVertex* originMCVertex() {

return m_originMCVertex;return m_originMCVertex;

}}

}; };

class MCParticle {class MCParticle {

......

SmartRef<MCVertex> m_originVertex;SmartRef<MCVertex> m_originVertex;

......

MCVertex* originMCVertex() {MCVertex* originMCVertex() {

return m_originMCVertex;return m_originMCVertex;

}}

}; };

…load data and trigger conversion

…load data and trigger conversion

See Doxygen code documentationSee Doxygen code documentation

Page 13: Accessing Event Data

4-13 Gaudi Framework Tutorial, 2001

Using SmartRef<type>Using SmartRef<type>

MCParticle* p = new MCParticle();MCParticle* p = new MCParticle();

SmartRef<MCParticle> ref;SmartRef<MCParticle> ref;

MCParticle* p = new MCParticle();MCParticle* p = new MCParticle();

SmartRef<MCParticle> ref;SmartRef<MCParticle> ref;

Assignment from raw pointerAssignment from raw pointer

Assignment to raw pointerAssignment to raw pointer

UsageUsage

HepLorentzVector& mom4 = p->fourMomentum();HepLorentzVector& mom4 = p->fourMomentum();

HepLorentzVector mom4_2 = ref->fourMomentum();HepLorentzVector mom4_2 = ref->fourMomentum();

HepLorentzVector& mom4 = p->fourMomentum();HepLorentzVector& mom4 = p->fourMomentum();

HepLorentzVector mom4_2 = ref->fourMomentum();HepLorentzVector mom4_2 = ref->fourMomentum();

ref = p;ref = p;ref = p;ref = p;

p = ref;p = ref;p = ref;p = ref;

Page 14: Accessing Event Data

4-14 Gaudi Framework Tutorial, 2001

Specify Event Data InputSpecify Event Data Input

EventSelector.Input = {“FILE=‘sicbmc.dat’”};[ {“Spec-1”, ... ,“Spec-n”} ]

EventSelector.Input = {“FILE=‘sicbmc.dat’”};[ {“Spec-1”, ... ,“Spec-n”} ]

• Event data input is specified in the job options

• “Spec” is an array of qualified strings:”KEY1=‘VALUE1’ … KEYn=‘VALUEn’”

• Event data input is specified in the job options

• “Spec” is an array of qualified strings:”KEY1=‘VALUE1’ … KEYn=‘VALUEn’”

Page 15: Accessing Event Data

4-15 Gaudi Framework Tutorial, 2001

Specify SICB Event InputSpecify 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.

• Retrieve JobIDs from the bookkeeping web page.

• Our main data source is SICB output.

Page 16: Accessing Event Data

4-16 Gaudi Framework Tutorial, 2001

Specify Other Event InputSpecify Other Event Input

KEY VALUE EXAMPLE

DATAFILE <file-name> =‘/afs/…/myfile.dat’

TYPE <technology> =‘ROOT’

COLLECTION <tuple-name> =‘MyCollection’

SELECTION <SQL-preselection> =‘NTRACK>50’

FUNCTION <name> =‘MySelector’

Page 17: Accessing Event Data

4-17 Gaudi Framework Tutorial, 2001

Hands On: Print B0 DecaysHands On: Print B0 Decays

•Use particle property serviceUse particle property service– See “User Guide” chapter 12.5

•Retrieve MCParticles from event storeRetrieve MCParticles from event store– “/Event/MC/MCParticles”

•Filter out the BFilter out the B00 particles particles– Part. member particleID().id() is Geant 3 particle code

•For each BFor each B0 0 Loop over all decay vertices Loop over all decay vertices and print the decay particles and print the decay particles

– recursion ?

•Use particle property serviceUse particle property service– See “User Guide” chapter 12.5

•Retrieve MCParticles from event storeRetrieve MCParticles from event store– “/Event/MC/MCParticles”

•Filter out the BFilter out the B00 particles particles– Part. member particleID().id() is Geant 3 particle code

•For each BFor each B0 0 Loop over all decay vertices Loop over all decay vertices and print the decay particles and print the decay particles

– recursion ?

Page 18: Accessing Event Data

4-18 Gaudi Framework Tutorial, 2001

DecayTreeAlgorithm.cpp: Add HeadersDecayTreeAlgorithm.cpp: Add Headers

#include "CLHEP/Units/PhysicalConstants.h"#include "CLHEP/Units/PhysicalConstants.h"

#include "GaudiKernel/IParticlePropertySvc.h"#include "GaudiKernel/IParticlePropertySvc.h"

#include "GaudiKernel/ParticleProperty.h"#include "GaudiKernel/ParticleProperty.h"

#include "GaudiKernel/SmartDataPtr.h"#include "GaudiKernel/SmartDataPtr.h"

#include "LHCbEvent/MCParticle.h"#include "LHCbEvent/MCParticle.h"

#include "LHCbEvent/MCVertex.h"#include "LHCbEvent/MCVertex.h"

#include "CLHEP/Units/PhysicalConstants.h"#include "CLHEP/Units/PhysicalConstants.h"

#include "GaudiKernel/IParticlePropertySvc.h"#include "GaudiKernel/IParticlePropertySvc.h"

#include "GaudiKernel/ParticleProperty.h"#include "GaudiKernel/ParticleProperty.h"

#include "GaudiKernel/SmartDataPtr.h"#include "GaudiKernel/SmartDataPtr.h"

#include "LHCbEvent/MCParticle.h"#include "LHCbEvent/MCParticle.h"

#include "LHCbEvent/MCVertex.h"#include "LHCbEvent/MCVertex.h"

Page 19: Accessing Event Data

4-19 Gaudi Framework Tutorial, 2001

Using IParticlePropertySvcUsing IParticlePropertySvc...DecayTreeAlgorithm.h......DecayTreeAlgorithm.h...

IParticleProperySvc* m_ppSvc;IParticleProperySvc* m_ppSvc; std::string m_partName; std::string m_partName; long m_partID; long m_partID;

...DecayTreeAlgorithm::initialize()......DecayTreeAlgorithm::initialize()...

m_ppSvc = 0;m_ppSvc = 0; StatusCode sc = service("ParticlePropertySvc", m_ppSvc ); StatusCode sc = service("ParticlePropertySvc", m_ppSvc ); if( !sc.isSuccess() ) if( !sc.isSuccess() ) {{ // You have to handle the error!// You have to handle the error! }}

ParticleProperty* partProp = m_ppSvc->find( m_partName );ParticleProperty* partProp = m_ppSvc->find( m_partName ); if ( 0 == partProp ) { if ( 0 == partProp ) { // You have to handle the error!// You have to handle the error! }} m_partID = partProp->geantID(); m_partID = partProp->geantID();

...DecayTreeAlgorithm.h......DecayTreeAlgorithm.h...

IParticleProperySvc* m_ppSvc;IParticleProperySvc* m_ppSvc; std::string m_partName; std::string m_partName; long m_partID; long m_partID;

...DecayTreeAlgorithm::initialize()......DecayTreeAlgorithm::initialize()...

m_ppSvc = 0;m_ppSvc = 0; StatusCode sc = service("ParticlePropertySvc", m_ppSvc ); StatusCode sc = service("ParticlePropertySvc", m_ppSvc ); if( !sc.isSuccess() ) if( !sc.isSuccess() ) {{ // You have to handle the error!// You have to handle the error! }}

ParticleProperty* partProp = m_ppSvc->find( m_partName );ParticleProperty* partProp = m_ppSvc->find( m_partName ); if ( 0 == partProp ) { if ( 0 == partProp ) { // You have to handle the error!// You have to handle the error! }} m_partID = partProp->geantID(); m_partID = partProp->geantID();

Page 20: Accessing Event Data

4-20 Gaudi Framework Tutorial, 2001

Hands On: Retrieve MCParticlesHands On: Retrieve MCParticles

SmartDataPtr<MCParticleVector> SmartDataPtr<MCParticleVector> parts(eventSvc(), “/Event/MC/MCParticles”); parts(eventSvc(), “/Event/MC/MCParticles”);

if ( parts ) {if ( parts ) {

… … loop over particles …loop over particles …

}}

SmartDataPtr<MCParticleVector> SmartDataPtr<MCParticleVector> parts(eventSvc(), “/Event/MC/MCParticles”); parts(eventSvc(), “/Event/MC/MCParticles”);

if ( parts ) {if ( parts ) {

… … loop over particles …loop over particles …

}}

#include “GaudiKernel/SmartDataPtr.h”#include “GaudiKernel/SmartDataPtr.h”#include “GaudiKernel/SmartDataPtr.h”#include “GaudiKernel/SmartDataPtr.h”

Page 21: Accessing Event Data

4-21 Gaudi Framework Tutorial, 2001

Hands On: Loop Over MCParticlesHands On: Loop Over MCParticles

MCParticleVector::const_iterator i;MCParticleVector::const_iterator i;

for(i=parts->begin();i != parts->end(); i++ ) {for(i=parts->begin();i != parts->end(); i++ ) {

if ( (*i)->particleID().id() == m_partID ){if ( (*i)->particleID().id() == m_partID ){

printDecayTree( *i );printDecayTree( *i );

}}

}}

MCParticleVector::const_iterator i;MCParticleVector::const_iterator i;

for(i=parts->begin();i != parts->end(); i++ ) {for(i=parts->begin();i != parts->end(); i++ ) {

if ( (*i)->particleID().id() == m_partID ){if ( (*i)->particleID().id() == m_partID ){

printDecayTree( *i );printDecayTree( *i );

}}

}}

New member functionNew member function

Page 22: Accessing Event Data

4-22 Gaudi Framework Tutorial, 2001

Hands On: Print DecaysHands On: Print Decays

For each selected particle: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

For each selected particle: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

Page 23: Accessing Event Data

4-23 Gaudi Framework Tutorial, 2001

Loop Over Decay VerticesLoop Over Decay Vertices

const SmartRefVector<MCVertex>& decays = mother->decayMCVertices();const SmartRefVector<MCVertex>& decays = mother->decayMCVertices();

SmartRefVector<MCVertex>::const_iterator iv;SmartRefVector<MCVertex>::const_iterator iv;

for (iv = decays.begin(); iv != decays.end(); iv++ ) {for (iv = decays.begin(); iv != decays.end(); iv++ ) {

const SmartRefVector<MCParticle>& daughters = const SmartRefVector<MCParticle>& daughters =

(*iv)->daughterMCParticles();(*iv)->daughterMCParticles();

SmartRefVector<MCParticle>::const_iterator idau;SmartRefVector<MCParticle>::const_iterator idau;

for (idau=daughters.begin(); idau!=daughters.end(); idau++ ) {for (idau=daughters.begin(); idau!=daughters.end(); idau++ ) {

printDecayTree( 0, printDecayTree( 0, " | |", *idau );, *idau );

}}

}}

const SmartRefVector<MCVertex>& decays = mother->decayMCVertices();const SmartRefVector<MCVertex>& decays = mother->decayMCVertices();

SmartRefVector<MCVertex>::const_iterator iv;SmartRefVector<MCVertex>::const_iterator iv;

for (iv = decays.begin(); iv != decays.end(); iv++ ) {for (iv = decays.begin(); iv != decays.end(); iv++ ) {

const SmartRefVector<MCParticle>& daughters = const SmartRefVector<MCParticle>& daughters =

(*iv)->daughterMCParticles();(*iv)->daughterMCParticles();

SmartRefVector<MCParticle>::const_iterator idau;SmartRefVector<MCParticle>::const_iterator idau;

for (idau=daughters.begin(); idau!=daughters.end(); idau++ ) {for (idau=daughters.begin(); idau!=daughters.end(); idau++ ) {

printDecayTree( 0, printDecayTree( 0, " | |", *idau );, *idau );

}}

}}

Page 24: Accessing Event Data

4-24 Gaudi Framework Tutorial, 2001

printDecayTreeprintDecayTreevoid DecayTreeAlgorithm::printDecayTree(long depth, const std::string& prefix, const MCParticle* mother) { MsgStream log(msgSvc(), name()); const SmartRefVector<MCVertex>& decays = mother->decayMCVertices(); ParticleProperty* p = m_ppSvc->find( mother->particleID().id() ); log << MSG::INFO << depth << prefix.substr(0, prefix.length()-1) << "+--->" << p->particle() << endreq;

if ( depth < m_depth ) { SmartRefVector<MCVertex>::const_iterator iv; for ( iv = decays.begin(); iv != decays.end(); iv++ ) { const SmartRefVector<MCParticle>& daughters = (*iv)->daughterMCParticles(); SmartRefVector<MCParticle>::const_iterator idau; for ( idau = daughters.begin(); idau != daughters.end(); idau++ ) { printDecayTree( depth+1, prefix+" |", *idau ); } } }}

void DecayTreeAlgorithm::printDecayTree(long depth, const std::string& prefix, const MCParticle* mother) { MsgStream log(msgSvc(), name()); const SmartRefVector<MCVertex>& decays = mother->decayMCVertices(); ParticleProperty* p = m_ppSvc->find( mother->particleID().id() ); log << MSG::INFO << depth << prefix.substr(0, prefix.length()-1) << "+--->" << p->particle() << endreq;

if ( depth < m_depth ) { SmartRefVector<MCVertex>::const_iterator iv; for ( iv = decays.begin(); iv != decays.end(); iv++ ) { const SmartRefVector<MCParticle>& daughters = (*iv)->daughterMCParticles(); SmartRefVector<MCParticle>::const_iterator idau; for ( idau = daughters.begin(); idau != daughters.end(); idau++ ) { printDecayTree( depth+1, prefix+" |", *idau ); } } }}