CMS 3D CMS Logo

Public Types | Public Member Functions | Private Attributes

TrackAssociatorByChi2 Class Reference

#include <TrackAssociatorByChi2.h>

Inheritance diagram for TrackAssociatorByChi2:
TrackAssociatorBase

List of all members.

Public Types

typedef std::map< double,
SimTrack
Chi2SimMap
typedef std::pair< reco::Track,
Chi2SimMap
RecoToSimPair
typedef std::vector
< RecoToSimPair
RecoToSimPairAssociation

Public Member Functions

double associateRecoToSim (reco::TrackCollection::const_iterator, TrackingParticleCollection::const_iterator, const reco::BeamSpot &) const
 compare reco::TrackCollection and TrackingParticleCollection iterators: returns the chi2
reco::RecoToSimCollection associateRecoToSim (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 Association Reco To Sim with Collections.
reco::RecoToSimCollection associateRecoToSim (edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 compare reco to sim the handle of reco::Track and TrackingParticle collections
reco::SimToRecoCollection associateSimToReco (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 Association Sim To Reco with Collections.
reco::SimToRecoCollection associateSimToReco (edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 compare reco to sim the handle of reco::Track and TrackingParticle collections
RecoToSimPairAssociation compareTracksParam (const reco::TrackCollection &, const edm::SimTrackContainer &, const edm::SimVertexContainer &, const reco::BeamSpot &) const
 compare collections reco to sim
double compareTracksParam (reco::TrackCollection::const_iterator, edm::SimTrackContainer::const_iterator, const math::XYZTLorentzVectorD, GlobalVector, reco::TrackBase::CovarianceMatrix, const reco::BeamSpot &) const
 compare reco::TrackCollection and edm::SimTrackContainer iterators: returns the chi2
std::pair< bool,
reco::TrackBase::ParameterVector
parametersAtClosestApproach (Basic3DVector< double >, Basic3DVector< double >, float, const reco::BeamSpot &) const
 propagate the track parameters of TrackinParticle from production vertex to the point of closest approach to the beam line.
 TrackAssociatorByChi2 (const edm::ESHandle< MagneticField > mF, double chi2Cut, bool onlyDiag, edm::InputTag beamspotSrc)
 Constructor with magnetic field, double, bool and InputTag.
 TrackAssociatorByChi2 (const edm::ESHandle< MagneticField > mF, edm::ParameterSet conf)
 Constructor with PSet.
 ~TrackAssociatorByChi2 ()
 Destructor.

Private Attributes

edm::InputTag bsSrc
double chi2cut
bool onlyDiagonal
edm::ESHandle< MagneticFieldtheMF

Detailed Description

Class that performs the association of reco::Tracks and TrackingParticles evaluating the chi2 of reco tracks parameters and sim tracks parameters. The cut can be tuned from the config file: see data/TrackAssociatorByChi2.cfi. Note that the Association Map is filled with -ch2 and not chi2 because it is ordered using std::greater: the track with the lowest association chi2 will be the first in the output map.It is possible to use only diagonal terms (associator by pulls) seeting onlyDiagonal = true in the PSet

Date:
2010/05/18 15:40:39
Revision:
1.27
Author:
cerati, magni

Definition at line 30 of file TrackAssociatorByChi2.h.


Member Typedef Documentation

typedef std::map<double, SimTrack> TrackAssociatorByChi2::Chi2SimMap

Definition at line 33 of file TrackAssociatorByChi2.h.

Definition at line 34 of file TrackAssociatorByChi2.h.

Definition at line 35 of file TrackAssociatorByChi2.h.


Constructor & Destructor Documentation

TrackAssociatorByChi2::TrackAssociatorByChi2 ( const edm::ESHandle< MagneticField mF,
edm::ParameterSet  conf 
) [inline]

Constructor with PSet.

Definition at line 38 of file TrackAssociatorByChi2.h.

References onlyDiagonal, and theMF.

                                                                                  :
    chi2cut(conf.getParameter<double>("chi2cut")),
    onlyDiagonal(conf.getParameter<bool>("onlyDiagonal")),
    bsSrc(conf.getParameter<edm::InputTag>("beamSpot")) {
    theMF=mF;  
    if (onlyDiagonal)
      edm::LogInfo("TrackAssociator") << " ---- Using Off Diagonal Covariance Terms = 0 ---- " <<  "\n";
    else 
      edm::LogInfo("TrackAssociator") << " ---- Using Off Diagonal Covariance Terms != 0 ---- " <<  "\n";
  }
TrackAssociatorByChi2::TrackAssociatorByChi2 ( const edm::ESHandle< MagneticField mF,
double  chi2Cut,
bool  onlyDiag,
edm::InputTag  beamspotSrc 
) [inline]

Constructor with magnetic field, double, bool and InputTag.

Definition at line 50 of file TrackAssociatorByChi2.h.

References bsSrc, chi2cut, onlyDiagonal, and theMF.

                                                                                                                    {
    chi2cut=chi2Cut;
    onlyDiagonal=onlyDiag;
    theMF=mF;  
    bsSrc = beamspotSrc;
  }
TrackAssociatorByChi2::~TrackAssociatorByChi2 ( ) [inline]

Destructor.

Definition at line 58 of file TrackAssociatorByChi2.h.

{}

Member Function Documentation

double TrackAssociatorByChi2::associateRecoToSim ( reco::TrackCollection::const_iterator  ,
TrackingParticleCollection::const_iterator  ,
const reco::BeamSpot  
) const

compare reco::TrackCollection and TrackingParticleCollection iterators: returns the chi2

Referenced by KVFTest::analyze(), and associateRecoToSim().

RecoToSimCollection TrackAssociatorByChi2::associateRecoToSim ( const edm::RefToBaseVector< reco::Track > &  tC,
const edm::RefVector< TrackingParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const [virtual]

Association Reco To Sim with Collections.

Implements TrackAssociatorBase.

Definition at line 160 of file TrackAssociatorByChi2.cc.

References edm::RefToBaseVector< T >::begin(), ExpressReco_HICollisions_FallBack::chi2, edm::RefToBaseVector< T >::end(), edm::Event::getByLabel(), i, edm::AssociationMap< Tag >::insert(), j, LogDebug, LogTrace, reco::BeamSpot::position(), edm::AssociationMap< Tag >::post_insert(), edm::RefVector< C, T, F >::product(), and edm::RefVector< C, T, F >::size().

                                                                                                {
  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
  e->getByLabel(bsSrc,recoBeamSpotHandle);
  reco::BeamSpot bs = *recoBeamSpotHandle;      

  RecoToSimCollection  outputCollection;
  double chi2;

  TrackingParticleCollection tPC;
  if (tPCH.size()!=0)  tPC = *tPCH.product();

  int tindex=0;
  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){

    LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
                                << "rec::Track #"<<tindex<<" with pt=" << (*rt)->pt() <<  "\n"
                                << "===========================================" << "\n";
 
    TrackBase::ParameterVector rParameters = (*rt)->parameters();

    TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
    if (onlyDiagonal){
      for (unsigned int i=0;i<5;i++){
        for (unsigned int j=0;j<5;j++){
          if (i!=j) recoTrackCovMatrix(i,j)=0;
        }
      }
    } 

    recoTrackCovMatrix.Invert();

    int tpindex =0;
    for (TrackingParticleCollection::const_iterator tp=tPC.begin(); tp!=tPC.end(); tp++, ++tpindex){
        
      //skip tps with a very small pt
      //if (sqrt(tp->momentum().perp2())<0.5) continue;
      Basic3DVector<double> momAtVtx(tp->momentum().x(),tp->momentum().y(),tp->momentum().z());
      Basic3DVector<double> vert=(Basic3DVector<double>) tp->vertex();

      std::pair<bool,reco::TrackBase::ParameterVector> params = parametersAtClosestApproach(vert, momAtVtx, tp->charge(), bs);
      if (params.first){
        TrackBase::ParameterVector sParameters=params.second;
        
        TrackBase::ParameterVector diffParameters = rParameters - sParameters;
        
        chi2 = ROOT::Math::Similarity(diffParameters, recoTrackCovMatrix);
        chi2 /= 5;
        
        LogTrace("TrackAssociator") << "====TP index=" << tpindex << "  RECO TRACK index="<<tindex<<" WITH PT=" << (*rt)->pt() << "====\n" 
                                    << "qoverp sim: " << sParameters[0] << "\n" 
                                    << "lambda sim: " << sParameters[1] << "\n" 
                                    << "phi    sim: " << sParameters[2] << "\n" 
                                    << "dxy    sim: " << sParameters[3] << "\n" 
                                    << "dsz    sim: " << sParameters[4] << "\n" 
                                    << ": " /*<< */ << "\n" 
                                    << "qoverp rec: " << (*rt)->qoverp() << " err: " << (*rt)->error(0) << "\n"
                                    << "lambda rec: " << (*rt)->lambda() << " err: " << (*rt)->error(1) << "\n"
                                    << "phi    rec: " << (*rt)->phi() << " err: " << (*rt)->error(2) << "\n"
                                    << "dxy    rec: " << (*rt)->dxy(bs.position()) << " err: " << (*rt)->error(3) << "\n"
                                    << "dsz    rec: " << (*rt)->dsz(bs.position()) << " err: " << (*rt)->error(4) << "\n"
                                    << ": " /*<< */ << "\n" 
                                    << "chi2: " << chi2 << "\n";
        
        if (chi2<chi2cut) {
          outputCollection.insert(tC[tindex], 
                                  std::make_pair(edm::Ref<TrackingParticleCollection>(tPCH, tpindex),
                                                 -chi2));//-chi2 because the Association Map is ordered using std::greater
        }
      }
    }
  }
  outputCollection.post_insert();
  return outputCollection;
}
reco::RecoToSimCollection TrackAssociatorByChi2::associateRecoToSim ( edm::Handle< edm::View< reco::Track > > &  tCH,
edm::Handle< TrackingParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const [inline, virtual]

compare reco to sim the handle of reco::Track and TrackingParticle collections

Reimplemented from TrackAssociatorBase.

Definition at line 96 of file TrackAssociatorByChi2.h.

References associateRecoToSim(), and event().

                                                                                      {
    return TrackAssociatorBase::associateRecoToSim(tCH,tPCH,event,setup);
  }
reco::SimToRecoCollection TrackAssociatorByChi2::associateSimToReco ( edm::Handle< edm::View< reco::Track > > &  tCH,
edm::Handle< TrackingParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const [inline, virtual]

compare reco to sim the handle of reco::Track and TrackingParticle collections

Reimplemented from TrackAssociatorBase.

Definition at line 104 of file TrackAssociatorByChi2.h.

References associateSimToReco(), and event().

                                                                                      {
    return TrackAssociatorBase::associateSimToReco(tCH,tPCH,event,setup);
  }  
SimToRecoCollection TrackAssociatorByChi2::associateSimToReco ( const edm::RefToBaseVector< reco::Track > &  tC,
const edm::RefVector< TrackingParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const [virtual]

Association Sim To Reco with Collections.

Implements TrackAssociatorBase.

Definition at line 240 of file TrackAssociatorByChi2.cc.

References edm::RefToBaseVector< T >::begin(), ExpressReco_HICollisions_FallBack::chi2, edm::RefToBaseVector< T >::end(), edm::Event::getByLabel(), i, edm::AssociationMap< Tag >::insert(), j, LogDebug, LogTrace, reco::BeamSpot::position(), edm::AssociationMap< Tag >::post_insert(), edm::RefVector< C, T, F >::product(), edm::RefVector< C, T, F >::size(), and mathSSE::sqrt().

Referenced by associateSimToReco().

                                                                                                 {
  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
  e->getByLabel(bsSrc,recoBeamSpotHandle);
  reco::BeamSpot bs = *recoBeamSpotHandle;      

  SimToRecoCollection  outputCollection;
  double chi2;

  TrackingParticleCollection tPC;
  if (tPCH.size()!=0)  tPC = *tPCH.product();

  int tpindex =0;
  for (TrackingParticleCollection::const_iterator tp=tPC.begin(); tp!=tPC.end(); tp++, ++tpindex){
    
    //skip tps with a very small pt
    //if (sqrt(tp->momentum().perp2())<0.5) continue;
    
    LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
                                << "TrackingParticle #"<<tpindex<<" with pt=" << sqrt(tp->momentum().perp2()) << "\n"
                                << "===========================================" << "\n";
    
    Basic3DVector<double> momAtVtx(tp->momentum().x(),tp->momentum().y(),tp->momentum().z());
    Basic3DVector<double> vert(tp->vertex().x(),tp->vertex().y(),tp->vertex().z());
    
    std::pair<bool,reco::TrackBase::ParameterVector> params = parametersAtClosestApproach(vert, momAtVtx, tp->charge(), bs);
    if (params.first){
      TrackBase::ParameterVector sParameters=params.second;
      
      int tindex=0;
      for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
        
        TrackBase::ParameterVector rParameters = (*rt)->parameters();

        TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
        if (onlyDiagonal) {
          for (unsigned int i=0;i<5;i++){
            for (unsigned int j=0;j<5;j++){
              if (i!=j) recoTrackCovMatrix(i,j)=0;
            }
          }
        }
        
        recoTrackCovMatrix.Invert();
        
        TrackBase::ParameterVector diffParameters = rParameters - sParameters;
        
        chi2 = ROOT::Math::Similarity(recoTrackCovMatrix, diffParameters);
        chi2 /= 5;
        
        LogTrace("TrackAssociator") << "====TP index=" << tpindex << "  RECO TRACK index="<<tindex<<" WITH PT=" << (*rt)->pt() << "====\n" 
                                    << "qoverp sim: " << sParameters[0] << "\n" 
                                    << "lambda sim: " << sParameters[1] << "\n" 
                                    << "phi    sim: " << sParameters[2] << "\n" 
                                    << "dxy    sim: " << sParameters[3] << "\n" 
                                    << "dsz    sim: " << sParameters[4] << "\n" 
                                    << ": " /*<< */ << "\n" 
                                    << "qoverp rec: " << (*rt)->qoverp() << " err: " << (*rt)->error(0) << "\n"
                                    << "lambda rec: " << (*rt)->lambda() << " err: " << (*rt)->error(1) << "\n"
                                    << "phi    rec: " << (*rt)->phi() << " err: " << (*rt)->error(2) << "\n"
                                    << "dxy    rec: " << (*rt)->dxy(bs.position()) << " err: " << (*rt)->error(3) << "\n"
                                    << "dsz    rec: " << (*rt)->dsz(bs.position()) << " err: " << (*rt)->error(4) << "\n"
                                    << ": " /*<< */ << "\n" 
                                    << "chi2: " << chi2 << "\n";
        
        if (chi2<chi2cut) {
          outputCollection.insert(edm::Ref<TrackingParticleCollection>(tPCH, tpindex),
                                  std::make_pair(tC[tindex],
                                                 -chi2));//-chi2 because the Association Map is ordered using std::greater
        }
      }
    }
  }
  outputCollection.post_insert();
  return outputCollection;
}
double TrackAssociatorByChi2::compareTracksParam ( reco::TrackCollection::const_iterator  ,
edm::SimTrackContainer::const_iterator  ,
const math::XYZTLorentzVectorD  ,
GlobalVector  ,
reco::TrackBase::CovarianceMatrix  ,
const reco::BeamSpot  
) const

compare reco::TrackCollection and edm::SimTrackContainer iterators: returns the chi2

TrackAssociatorByChi2::RecoToSimPairAssociation TrackAssociatorByChi2::compareTracksParam ( const reco::TrackCollection rtColl,
const edm::SimTrackContainer stColl,
const edm::SimVertexContainer svColl,
const reco::BeamSpot bs 
) const

compare collections reco to sim

Definition at line 38 of file TrackAssociatorByChi2.cc.

References ExpressReco_HICollisions_FallBack::chi2, i, j, and ExpressReco_HICollisions_FallBack::track.

                                                                       {
  
  RecoToSimPairAssociation outputVec;

  for (TrackCollection::const_iterator track=rtColl.begin(); track!=rtColl.end(); track++){
     Chi2SimMap outMap;

    TrackBase::ParameterVector rParameters = track->parameters();

    TrackBase::CovarianceMatrix recoTrackCovMatrix = track->covariance();
    if (onlyDiagonal){
      for (unsigned int i=0;i<5;i++){
        for (unsigned int j=0;j<5;j++){
          if (i!=j) recoTrackCovMatrix(i,j)=0;
        }
      }
    }
    recoTrackCovMatrix.Invert();

    for (SimTrackContainer::const_iterator st=stColl.begin(); st!=stColl.end(); st++){

      Basic3DVector<double> momAtVtx(st->momentum().x(),st->momentum().y(),st->momentum().z());
      Basic3DVector<double> vert = (Basic3DVector<double>)  svColl[st->vertIndex()].position();

      std::pair<bool,reco::TrackBase::ParameterVector> params = parametersAtClosestApproach(vert, momAtVtx, st->charge(), bs);
      if (params.first){
        TrackBase::ParameterVector sParameters = params.second;
      
        TrackBase::ParameterVector diffParameters = rParameters - sParameters;
        double chi2 = ROOT::Math::Dot(diffParameters * recoTrackCovMatrix, diffParameters);
        chi2/=5;
        if (chi2<chi2cut) outMap[chi2]=*st;
      }
    }
    outputVec.push_back(RecoToSimPair(*track,outMap));
  }
  return outputVec;
}
pair< bool, TrackBase::ParameterVector > TrackAssociatorByChi2::parametersAtClosestApproach ( Basic3DVector< double >  vertex,
Basic3DVector< double >  momAtVtx,
float  charge,
const reco::BeamSpot bs 
) const

propagate the track parameters of TrackinParticle from production vertex to the point of closest approach to the beam line.

Definition at line 132 of file TrackAssociatorByChi2.cc.

References FreeTrajectoryState::charge(), funct::cos(), Geom::halfPi(), PV3DBase< T, PVType, FrameType >::mag(), FreeTrajectoryState::momentum(), L1TEmulatorMonitor_cff::p, PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::phi(), FreeTrajectoryState::position(), funct::sin(), PV3DBase< T, PVType, FrameType >::theta(), TrajectoryStateClosestToBeamLine::trackStateAtPCA(), v, PV3DBase< T, PVType, FrameType >::x(), Basic3DVector< T >::x(), PV3DBase< T, PVType, FrameType >::y(), Basic3DVector< T >::y(), PV3DBase< T, PVType, FrameType >::z(), and Basic3DVector< T >::z().

Referenced by VertexFitterResult::fill().

                                                                            {
  
  TrackBase::ParameterVector sParameters;
  try {
    FreeTrajectoryState ftsAtProduction(GlobalPoint(vertex.x(),vertex.y(),vertex.z()),
                                        GlobalVector(momAtVtx.x(),momAtVtx.y(),momAtVtx.z()),
                                        TrackCharge(charge),
                                        theMF.product());
    TSCBLBuilderNoMaterial tscblBuilder;
    TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,bs);//as in TrackProducerAlgorithm
    
    GlobalPoint v = tsAtClosestApproach.trackStateAtPCA().position();
    GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
    sParameters[0] = tsAtClosestApproach.trackStateAtPCA().charge()/p.mag();
    sParameters[1] = Geom::halfPi() - p.theta();
    sParameters[2] = p.phi();
    sParameters[3] = (-v.x()*sin(p.phi())+v.y()*cos(p.phi()));
    sParameters[4] = v.z()*p.perp()/p.mag() - (v.x()*p.x()+v.y()*p.y())/p.perp() * p.z()/p.mag();
    
    return pair<bool,TrackBase::ParameterVector>(true,sParameters);
  } catch ( ... ) {
    return pair<bool,TrackBase::ParameterVector>(false,sParameters);
  }
}

Member Data Documentation

Definition at line 114 of file TrackAssociatorByChi2.h.

Referenced by TrackAssociatorByChi2().

Definition at line 112 of file TrackAssociatorByChi2.h.

Referenced by TrackAssociatorByChi2().

Definition at line 113 of file TrackAssociatorByChi2.h.

Referenced by TrackAssociatorByChi2().

Definition at line 111 of file TrackAssociatorByChi2.h.

Referenced by TrackAssociatorByChi2().