CMS 3D CMS Logo

Public Member Functions | Private Attributes

TrackListCombiner Class Reference

#include <TrackListCombiner.h>

Inheritance diagram for TrackListCombiner:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

virtual void produce (edm::Event &ev, const edm::EventSetup &es)
 TrackListCombiner (const edm::ParameterSet &ps)
 ~TrackListCombiner ()

Private Attributes

std::vector< std::string > trackProducers

Detailed Description

Definition at line 11 of file TrackListCombiner.h.


Constructor & Destructor Documentation

TrackListCombiner::TrackListCombiner ( const edm::ParameterSet ps) [explicit]

Definition at line 19 of file TrackListCombiner.cc.

References edm::ParameterSet::getParameter().

{
  trackProducers = ps.getParameter<vector<string> >("trackProducers");

  produces<reco::TrackCollection>();
  produces<reco::TrackExtraCollection>();
  produces<TrackingRecHitCollection>();
  produces<vector<Trajectory> >();
  produces<TrajTrackAssociationCollection>();
}
TrackListCombiner::~TrackListCombiner ( )

Definition at line 31 of file TrackListCombiner.cc.

{
}

Member Function Documentation

void TrackListCombiner::produce ( edm::Event ev,
const edm::EventSetup es 
) [virtual]

Implements edm::EDProducer.

Definition at line 36 of file TrackListCombiner.cc.

References edm::Event::getByLabel(), i, getHLTprescales::index, reco::Track::innerDetId(), reco::Track::innerMomentum(), reco::Track::innerOk(), reco::Track::innerPosition(), reco::Track::innerStateCovariance(), reco::TrackBase::iter1, reco::TrackBase::iter2, reco::TrackBase::iter3, LogTrace, reco::Track::outerDetId(), reco::Track::outerMomentum(), reco::Track::outerOk(), reco::Track::outerPosition(), reco::Track::outerStateCovariance(), edm::Event::put(), reco::Track::recHit(), reco::Track::recHitsSize(), reco::Track::seedDirection(), reco::Track::seedRef(), reco::TrackBase::setAlgorithm(), and reco::TrackBase::undefAlgorithm.

{
  auto_ptr<reco::TrackCollection>          recoTracks
      (new reco::TrackCollection);
  auto_ptr<reco::TrackExtraCollection>     recoTrackExtras
      (new reco::TrackExtraCollection);
  auto_ptr<TrackingRecHitCollection>       recoHits
      (new TrackingRecHitCollection);
  auto_ptr<vector<Trajectory> >            recoTrajectories
      (new vector<Trajectory>);
  auto_ptr<TrajTrackAssociationCollection> recoTrajTrackMap
      (new TrajTrackAssociationCollection());

  LogTrace("MinBiasTracking")
    << "[TrackListCombiner]";

  // Go through all track producers
  int i = 1;
  for(vector<string>::iterator trackProducer = trackProducers.begin();
                               trackProducer!= trackProducers.end();
                               trackProducer++, i++)
  {
    reco::TrackBase::TrackAlgorithm algo;
    switch(i) 
    {
      case 1:  algo = reco::TrackBase::iter1; break;
      case 2:  algo = reco::TrackBase::iter2; break;
      case 3:  algo = reco::TrackBase::iter3; break;
      default: algo = reco::TrackBase::undefAlgorithm;
    }

    edm::Handle<vector<Trajectory> > theTrajectoryCollection;
    edm::Handle<TrajTrackAssociationCollection> theAssoMap;  

    ev.getByLabel(*trackProducer, theTrajectoryCollection);
    ev.getByLabel(*trackProducer, theAssoMap);

    LogTrace("MinBiasTracking")
      << " [TrackListCombiner] " << *trackProducer
      << " : " << theAssoMap->size();

    
    // The track collection iterators
    TrajTrackAssociationCollection::const_iterator anAssociation;  
    TrajTrackAssociationCollection::const_iterator lastAssociation;
    anAssociation = theAssoMap->begin();
    lastAssociation = theAssoMap->end();

    // Build the map of correspondance between reco tracks and sim tracks
    for ( ; anAssociation != lastAssociation; ++anAssociation )
    { 
      edm::Ref<vector<Trajectory> > aTrajectoryRef = anAssociation->key;
      reco::TrackRef aTrackRef = anAssociation->val;
      
      // A copy of the track
      reco::Track aRecoTrack(*aTrackRef);

      // Set algorithm
      aRecoTrack.setAlgorithm(algo);

      recoTracks->push_back(aRecoTrack);      

      // A copy of the hits
      unsigned nh = aRecoTrack.recHitsSize();
      for(unsigned ih=0; ih<nh; ++ih)
      {
        TrackingRecHit *hit = aRecoTrack.recHit(ih)->clone();
        recoHits->push_back(hit);
      }
      
      // A copy of the trajectories
      recoTrajectories->push_back(*aTrajectoryRef);
      
    }
  }

  LogTrace("MinBiasTracking")
    << " [TrackListCombiner] allTracks : " << recoTracks->size()
                                    << "|" << recoTrajectories->size();

  // Save the tracking recHits
  edm::OrphanHandle<TrackingRecHitCollection> theRecoHits = ev.put(recoHits);
  
  // Create the track extras and add the references to the rechits
  unsigned hits = 0;
  unsigned nTracks = recoTracks->size();
  recoTrackExtras->reserve(nTracks); // To save some time at push_back
  for(unsigned index = 0; index < nTracks; ++index )
  { 
    reco::Track& aTrack = recoTracks->at(index);
    reco::TrackExtra aTrackExtra(aTrack.outerPosition(),
                                 aTrack.outerMomentum(),
                                 aTrack.outerOk(),
                                 aTrack.innerPosition(),
                                 aTrack.innerMomentum(),
                                 aTrack.innerOk(),
                                 aTrack.outerStateCovariance(),
                                 aTrack.outerDetId(),
                                 aTrack.innerStateCovariance(),
                                 aTrack.innerDetId(),
                                 aTrack.seedDirection(),
                                 aTrack.seedRef());
    
    unsigned nHits = aTrack.recHitsSize();
    for ( unsigned int ih=0; ih<nHits; ++ih)
      aTrackExtra.add(TrackingRecHitRef(theRecoHits,hits++));
    recoTrackExtras->push_back(aTrackExtra);
  }
  
  // Save the track extras
  edm::OrphanHandle<reco::TrackExtraCollection> theRecoTrackExtras =
    ev.put(recoTrackExtras);
  
  // Add the reference to the track extra in the tracks
  for(unsigned index = 0; index<nTracks; ++index)
  { 
    const reco::TrackExtraRef theTrackExtraRef(theRecoTrackExtras,index);
    (recoTracks->at(index)).setExtra(theTrackExtraRef);
  }
  
  // Save the tracks
  edm::OrphanHandle<reco::TrackCollection> theRecoTracks = ev.put(recoTracks);
  
  // Save the trajectories
  edm::OrphanHandle<vector<Trajectory> > theRecoTrajectories =
    ev.put(recoTrajectories);
  
  // Create and set the trajectory/track association map 
  for(unsigned index = 0; index<nTracks; ++index)
  { 
    edm::Ref<vector<Trajectory> > trajRef( theRecoTrajectories, index );
    edm::Ref<reco::TrackCollection>    tkRef( theRecoTracks, index );
    recoTrajTrackMap->insert(trajRef,tkRef);
  }
  
  // Save the association map
  ev.put(recoTrajTrackMap);
}

Member Data Documentation

std::vector<std::string> TrackListCombiner::trackProducers [private]

Definition at line 19 of file TrackListCombiner.h.