Association of Reconstructed and Simulated Vertices

Complete: 2


Vertex association can associate reconstructed vertices with simulated vertices and vice versa. Vertex association picks up where track association leaves off and uses a very similar interface. The track association is described in the track reconstruction section of the software guide. You must use CMSSW 1.4.0 or later to run the vertex association.

Using vertex association tools

Vertex association is meant to be called by the user. This is necessary for a couple of different reasons:

  1. You can use several different track reconstruction algorithms
  2. Users can create their own vertices (there is no canonical list)

Example code in SimTracker/VertexAssociation/test/ shows how to do the vertex association:

void testVertexAssociator::analyze(const edm::Event& event, const edm::EventSetup& setup)
  using namespace edm;
  using namespace reco;

First, we have to retrieve from the event the handles to all the products we want. In this case, we will use the CTF tracks with material and the primary vertices formed by them.

  Handle<reco::TrackCollection> trackCollectionH;
  const  reco::TrackCollection  tC = *(trackCollectionH.product());

  Handle<SimTrackContainer> simTrackCollection;
  event.getByLabel("g4SimHits", simTrackCollection);
  const SimTrackContainer simTC = *(simTrackCollection.product());

  Handle<SimVertexContainer> simVertexCollection;
  event.getByLabel("g4SimHits", simVertexCollection);
  const SimVertexContainer simVC = *(simVertexCollection.product());

  edm::Handle<TrackingParticleCollection>  TPCollectionH ;
  const TrackingParticleCollection tPC   = *(TPCollectionH.product());

  edm::Handle<TrackingVertexCollection>  TVCollectionH ;
  const TrackingVertexCollection tVC   = *(TVCollectionH.product());

  edm::Handle<reco::VertexCollection>  primaryVertexH ;
  const reco::VertexCollection primaryVertexCollection   = *(primaryVertexH.product());

Now, we have to run the track association between the reco::Tracks and the TrackingParticles. Here we choose to run the association by SimHits. We do the association both ways: reco to sim and sim to reco since they will both be used later in vertex association. Another set of track associators by the Chi2 of the track parameters also exists.

  reco::RecoToSimCollection p = associatorByHits->associateRecoToSim (trackCollectionH,TPCollectionH,&event );

  reco::SimToRecoCollection s2rTracks = associatorByHits->associateSimToReco (trackCollectionH,TPCollectionH,&event );

The next step is to use the output of the track associator to associate reconstructed vertices to TrackingVertices. We'll also do the reverse: associating TrackingVertices to reconstructed vertices

  reco::VertexRecoToSimCollection vR2S = associatorByTracks ->
  cout << " Running Sim To Reco" << endl;
  reco::VertexSimToRecoCollection vS2R = associatorByTracks ->

Now that we have two EDM association maps (vR2S & vS2R) we can loop through them and plot various quantities

  for (reco::VertexRecoToSimCollection::const_iterator iR2S = vR2S.begin();
       iR2S != vR2S.end(); ++iR2S) {
    math::XYZPoint recoPos = (iR2S -> key) -> position();
    double nreco = (iR2S -> key)->tracksSize();
    std::vector<std::pair<TrackingVertexRef, double> > vVR = iR2S -> val;

Each reco::Vertex gives us a vector of TrackingVertex. This loop (below) goes through them. We can extract the postion of the simulated and reconstructed vertices and plot differences.

    for (std::vector<std::pair<TrackingVertexRef, double> >::const_iterator
        iMatch = vVR.begin(); iMatch != vVR.end(); ++iMatch) {
        TrackingVertexRef trueV =  iMatch->first;
        HepLorentzVector simVec = (iMatch->first)->position();
        double ntrue = trueV->daughterTracks().size();
        math::XYZPoint simPos = math::XYZPoint(simVec.x(),simVec.y(),simVec.z());
        double qual  = iMatch->second;
        double xmiss = simPos.X() - recoPos.X();
        double ymiss = simPos.Y() - recoPos.Y();
        double zmiss = simPos.Z() - recoPos.Z();
        double rmiss = sqrt(xmiss*xmiss+ymiss*ymiss+zmiss*zmiss);

        xMiss->Fill(simPos.X() - recoPos.X());
        yMiss->Fill(simPos.Y() - recoPos.Y());
        zMiss->Fill(simPos.Z() - recoPos.Z());



Now we do a similar thing, but from the other side; we start with the TrackingVertices and loop over the vector of reco::Vertex associated with them.

 for (reco::VertexSimToRecoCollection::const_iterator iS2R = vS2R.begin();
       iS2R != vS2R.end(); ++iS2R) {

    TrackingVertexRef simVertex = (iS2R -> key);
    HepLorentzVector simVec = simVertex->position();
    math::XYZPoint   simPos = math::XYZPoint(simVec.x(),simVec.y(),simVec.z());
    double ntrue = simVertex->daughterTracks().size();
    std::vector<std::pair<VertexRef, double> > recoVertices = iS2R->val;
    for (std::vector<std::pair<VertexRef, double> >::const_iterator iMatch = recoVertices.begin();
         iMatch != recoVertices.end(); ++iMatch) {
      VertexRef recoV = iMatch->first;
      double qual  = iMatch->second;
      math::XYZPoint recoPos = (iMatch -> first) -> position();
      double nreco = (iMatch->first)->tracksSize();

      double xmiss = simPos.X() - recoPos.X();
      double ymiss = simPos.Y() - recoPos.Y();
      double zmiss = simPos.Z() - recoPos.Z();
      double rmiss = sqrt(xmiss*xmiss+ymiss*ymiss+zmiss*zmiss);

      sr_xMiss->Fill(simPos.X() - recoPos.X());
      sr_yMiss->Fill(simPos.Y() - recoPos.Y());
      sr_zMiss->Fill(simPos.Z() - recoPos.Z());



At the moment, there is only one way to associate vertices (by which tracks make up the simulated and reconstructed vertices) and the collection of vertices you want to associate must be "put" into the event before association.

Review Status

Editor/Reviewer and date Comments
Main.ewv - 11 May 2007 page author

Responsible: Main.ewv (Eric Vaandering)
Last reviewed by:

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r6 - 2008-01-23 - CMSUserSupport

    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic 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