How to access to Monte Carlo Truth information for the Recontructed Primary Vertices ?

This section describes the tool for extraction of the Monte Carlo truth information for the Recontructed Primary Vertices.


The association of the reconstructed primary vertices to Monte Carlo truth is a delicate task. Even the definition of "the correctly reconstructed primary vertex" is ambiguous. One can rely on the number of true Monte Carlo tracks or on the distance between the Reconstructed and Monte Carlo vertices. In an obvious way the definition depends on the use-case. For some application the distance-based association is fine, for some application the definition based on the count of number of tracks is fine. LoKi offers the low-level utility which is able for each pair of Primary Reconstructed and Primary Monte Carlo vertex to evaluate both quantities:

  1. Number of tracks from the Primary Monte Carlo Vertex, which are used in the Reconstructed Primary Vertex
  2. -distance between the Reconstructed Primary vertex and Primary Monte Carlo Vertex

Basing on these two quantities one is able to make the decisions about the association for the Reconstructed and Monte Carlo primary vertices. (As usual, my lines will not make a decision for you...)

Essentially the association is done for all combinations of Reconstructed and Monte Carlo primary vertices..


The actual association is done in a form of the relation tables which are used to describe the association of Reconstructed Primary Vertices of C++ type LHCb::RecVertex with Monte Carlo primary vertices of C++ type LHCb::MCVertex. Each link carries the certain weight of the C++ type std::pair. The first element of the pair represent the number of true tracks fro the given Monte Carlo vertex which are used for the Recontructed Primary Vertex, and the second element of the pair corresponds to the -distance between the Recontructed Primary vertex and Primary Monte Carlo Vertex.

The actual types for direct relations (Recontructed PV Monte Carlo PV) is defined through the typedef LHCb::PV2MC in the file $DAVINCIMCKERNEL/Kernel/PV2MC.h. The actual types for inverse relations ( Monte Carlo PV Reconstructed PV) is defined through the typedef LHCb::MC2MV in $DAVINCIMCKERNEL/Kernel/PV2MC.h.

The configuration

The relation table is created by the algorithm LoKi_PV2MCAlg. The location of the relation tabel in Transient Event Store is defined to be LHCb::PV2MCLocation::Default (see here)

It is possible to run the algorithm explicitl, but it is also possible to use DataOnDemandSvc to build the table on-demand. The proper configuration is activated by inclusion of the line:

 1000# define the configurtaion through Data-On-Demand
 1010import LoKiPhysMC.PV2MC_Configuration 

The direct usage of the relation table

The relation table could be extracted from the Gaudi Transient Store using the regular method get:

 1000// get the relation table from TES:
 1010const LHCb::PV2MC* table = get<LHCb::PV2MC> ( LHCb::PV2MCLocation::Default ) ;

For the given recontructed primary vertex one can extract all links in one go:

 1000// get one primary vertex:
 1010const LHCb::RecVertex* primary = ... ;
 1030// extract from the relation table all related Monte Carlo primary vertices:
 1040LHCb::PV2MC::Range links = table->relations ( primary ) ;
 1060info () << " number of links:  " << links.size() << endreq ;

Please note that number of links will be always equal to number of the primary Monte Carlo vertices.

And one can make a loop over all the related Monte Carlo primary vertices and ot get the association information:

 1000// the explicit loop over all links 
 1010for ( LHCb::MV2MC::Range::iterator ilink = links.begin() ; links.end() != ilink ; ++ilink ) 
 1030   // get the Monte Carlo primary vertex:
 1040   const LHCb::MCVertex* mc = ilink -> to () ; ///< get the related Monte Carlo primary vertex 
 1050    // get the number of tracks form this Monte Carlo vertex:
 1060   const unsigned int  nTracks = ilink -> weight() . first ;
 1070   // get chi2 distance between recontucted and Monte Carlo vertices:
 1080   const double chi2 = ilink -> weight() . second ;
 1100  info () << " \t\tThe link # " <<  ( ilink-links.begin() )  
 1110              << " MC-key = "       << mc->key()
 1120              << " # tracks = "     <<    nTracks 
 1130              << " chi2 = "         <<    chi2    << endreq ;

The complete example, tested with DaVinci v19r6 is attached to this page as DV_PV2MC_Ex1.cpp, the configuration file is available as DV_PV2MC_Ex1.opts

The usage of the relation table through IPV2MC tool

One can also access the relation table though the helper tool, which implements IPV2MC abstract interface. The abstract interafce is defined in the file $DAVINCIMCKERNELROOT/Kernel/IPV2MC.h. Essentially it provides few methods for accession the following tables:

  1. the direct relation table LHCb::PV2MC for Recontructed to Monte Carlo Primary Vertices
  2. the inverse relation table LHCb::MC2PV for Monte Carlo to Recontructed Primary Vertices
  3. the direct relation table LHCb::PV2Collision for Recontructed Primary Vertices to Generator Collisions
  4. the inverse relation table LHCb::Collision2PV for Generator Collision objects to the Recontructed Primary Vertices

All types are defined in the file $DAVINCIMCKERNELROOT/Kernel/PV2MC.h and essentially the various template for the generic class IRelationWeighted.

The usage of the tool is fairly trivial:

 1000#include "Kernel/IPV2MC.h"
 1020class MyAlg : public DVAlgorithm 
 1060   // the tool 
 1070   IPV2MC* m_pv2mc  ; ///< the tool 
 1100StatusCode MyAlf::initialize() 
 1120 ...
 1130 m_pv2mc = tool<IPV2MC>( "LoKi_PV2MC/PV2MC:PUBLIC" , this ) ;

As soon as the ltool is aquired one can get the relation tables directly form the tool:

 1000// get the relation table from the tool:
 1020const LHCb::PV2MC* table = m_pv2mc -> pv2MC() ;

The complete example, tested with DaVinci v19r6 is attached to this page as DV_PV2MC_Ex2.cpp, the configuration file is available as DV_PV2MC_Ex1.opts

How to get the list of all Primary Monte Carlo vertices?

There are few ways to get the list of all Primary Monte Carlo vertices. Probably the most simple one is by usage of LHCb::MCVertex::isPrimary method:

 1000// get all Monte Carlo vertices from TES:
 1010const LHCb::MCVertex::Container* mcvertices = get<LHCb::MCVertex::Container> ( LHCb::MCVertexLocation::Default ) ;
 1030// prepare the output container of vertices:
 1040typedef std::vector<const LHCb::MCVertex*> VERTICES ;
 1050VERTICES primaries ;
 1070// select all Monte Carlo  Primary Vertices:
 1080for ( LHCb::MCVertex::Container::const_iterator imc = mcvertices->begin() ; mcvertices->end() != imc ; ++imc ) 
 1100   const LHCb::MCVertex* mcv = *imc ;
 1110   if ( 0 == mcv || !mcv->isPrimary() ) { continue ; }
 1120   primaries.push_back ( mcv ) ;

How to get the corresponding Primary Monte Carlo vertex for Monte Carlo objects?

For any Monte Carlo object one can directly access the corresponding Monte Carlo primary vertex using the function LoKi::MC2Collision::primaryVertex from the file $DAVINCIMCKERNELROOT/Kernel/MC2Collision.h:

 1000#include "Kernel/MC2Collision.h"
 1030// *ANY* Monte Carlo object:
 1040MCOBJECT* object = ... ;
 1060// get the corresponding Monte Carlo Primary  vertex 
 1070const LHCb::MCVertex* mcpv = LHCb::MC2Collision::primaryVertex ( object ) ;

The functions are defined for the following Monte Carlo Objects:


Please note that one needs to "getpack" the version of Phys/LoKiPhysMC package which is v6r2 or more recent.

-- Vanya BELYAEV - 05 Nov 2007

Topic attachments
I Attachment History Action Size Date Who Comment
C source code filecpp DV_PV2MC_Ex1.cpp r1 manage 5.3 K 2007-11-05 - 17:02 VanyaBelyaev  
Unknown file formatopts DV_PV2MC_Ex1.opts r1 manage 1.7 K 2007-11-05 - 17:04 VanyaBelyaev  
C source code filecpp DV_PV2MC_Ex2.cpp r1 manage 5.7 K 2007-11-05 - 17:03 VanyaBelyaev  
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r4 - 2009-07-27 - VanyaBelyaev
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    LHCb All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback