CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

MuonResidualsFromTrack Class Reference

#include <MuonResidualsFromTrack.h>

List of all members.

Public Member Functions

const std::vector< DetIdchamberIds () const
MuonChamberResidualchamberResidual (DetId chamberId, int type)
TMatrixD choleskyCorrMatrix (DetId chamberId)
void clear ()
bool contains_TIDTEC () const
TMatrixDSym corrMatrix (DetId chamberId)
TMatrixDSym covMatrix (DetId chamberId)
const reco::TrackgetTrack ()
 MuonResidualsFromTrack (edm::ESHandle< GlobalTrackingGeometry > globalGeometry, const reco::Muon *mu, AlignableNavigator *navigator, double maxResidual)
 MuonResidualsFromTrack (edm::ESHandle< GlobalTrackingGeometry > globalGeometry, const Trajectory *traj, const reco::Track *trk, AlignableNavigator *navigator, double maxResidual)
double normalizedChi2 () const
double trackerChi2 () const
int trackerNumHits () const
double trackerRedChi2 () const
 ~MuonResidualsFromTrack ()

Private Member Functions

void addTrkCovMatrix (DetId, TrajectoryStateOnSurface &)

Private Attributes

std::vector< DetIdm_chamberIds
bool m_contains_TIDTEC
std::map< DetId,
MuonChamberResidual * > 
m_csc
std::map< DetId,
MuonChamberResidual * > 
m_dt13
std::map< DetId,
MuonChamberResidual * > 
m_dt2
double m_tracker_chi2
int m_tracker_numHits
std::map< DetId, TMatrixDSym > m_trkCovMatrix
TrajectoryStateCombiner m_tsoscomb
const reco::Muonmuon
const reco::Tracktrack

Detailed Description

Id:
MuonResidualsFromTrack.h,v 1.4 2011/10/12 23:40:24 khotilov Exp
Author:
J. Pivarski - Texas A&M University <pivarski@physics.tamu.edu>

Definition at line 32 of file MuonResidualsFromTrack.h.


Constructor & Destructor Documentation

MuonResidualsFromTrack::MuonResidualsFromTrack ( edm::ESHandle< GlobalTrackingGeometry globalGeometry,
const Trajectory traj,
const reco::Track trk,
AlignableNavigator navigator,
double  maxResidual 
)

Definition at line 30 of file MuonResidualsFromTrack.cc.

References AlignableNavigator::alignableFromDetId(), TrajectoryMeasurement::backwardPredictedState(), CSCDetId::chamber(), clear(), MuonSubdetId::CSC, MuonSubdetId::DT, CSCDetId::endcap(), TrajectoryMeasurement::forwardPredictedState(), TrackingRecHit::geographicalId(), TrackingRecHit::isValid(), TrajectoryStateOnSurface::isValid(), CSCDetId::layer(), TrajectoryStateOnSurface::localError(), TrackingRecHit::localPosition(), TrajectoryStateOnSurface::localPosition(), TrackingRecHit::localPositionError(), m_chamberIds, m_contains_TIDTEC, m_csc, m_dt13, m_dt2, m_tracker_chi2, m_tracker_numHits, m_tsoscomb, Trajectory::measurements(), DetId::Muon, LocalTrajectoryError::positionError(), TrajectoryMeasurement::recHit(), CSCDetId::ring(), CSCDetId::station(), DTSuperLayerId::superlayer(), StripSubdetector::TEC, StripSubdetector::TID, align::Tracker, PV3DBase< T, PVType, FrameType >::x(), and LocalError::xx().

  : track(trk)
{
  clear();

  std::vector<TrajectoryMeasurement> measurements = traj->measurements();
  for (std::vector<TrajectoryMeasurement>::const_iterator im = measurements.begin();  im != measurements.end();  ++im) {
    TrajectoryMeasurement meas = *im;
    const TransientTrackingRecHit *hit = &(*meas.recHit());
    DetId id = hit->geographicalId();

    if (hit->isValid()) {
      TrajectoryStateOnSurface tsos = m_tsoscomb(meas.forwardPredictedState(), meas.backwardPredictedState());
      if (tsos.isValid()  &&  fabs(tsos.localPosition().x() - hit->localPosition().x()) < maxResidual) {

        if (id.det() == DetId::Tracker) {
          double xresid = tsos.localPosition().x() - hit->localPosition().x();
          double xresiderr2 = tsos.localError().positionError().xx() + hit->localPositionError().xx();

          m_tracker_numHits++;
          m_tracker_chi2 += xresid * xresid / xresiderr2;

          if (id.subdetId() == StripSubdetector::TID  ||  id.subdetId() == StripSubdetector::TEC) m_contains_TIDTEC = true;
        }

        else if (id.det() == DetId::Muon  &&  id.subdetId() == MuonSubdetId::DT) {
          const DTChamberId chamberId(id.rawId());
          const DTSuperLayerId superLayerId(id.rawId());

          // have we seen this chamber before?
          if (m_dt13.find(chamberId) == m_dt13.end()  &&  m_dt2.find(chamberId) == m_dt2.end()) {
            m_chamberIds.push_back(chamberId);
            //addTrkCovMatrix(chamberId, tsos); // only for the 1st hit
          }

          if (superLayerId.superlayer() == 2) {
            if (m_dt2.find(chamberId) == m_dt2.end()) {
              AlignableDetOrUnitPtr chamberAlignable = navigator->alignableFromDetId(chamberId);
              m_dt2[chamberId] = new MuonDT2ChamberResidual(globalGeometry, navigator, chamberId, chamberAlignable);
            }

            m_dt2[chamberId]->addResidual(&tsos, hit);
          }

          else {
            if (m_dt13.find(chamberId) == m_dt13.end()) {
              AlignableDetOrUnitPtr chamberAlignable = navigator->alignableFromDetId(chamberId);
              m_dt13[chamberId] = new MuonDT13ChamberResidual(globalGeometry, navigator, chamberId, chamberAlignable);
            }

            m_dt13[chamberId]->addResidual(&tsos, hit);
          }
        }

        else if (id.det() == DetId::Muon  &&  id.subdetId() == MuonSubdetId::CSC) {
          const CSCDetId cscDetId(id.rawId());
          const CSCDetId chamberId(cscDetId.endcap(), cscDetId.station(), cscDetId.ring(), cscDetId.chamber());

          // not sure why we sometimes get layer == 0
          if (cscDetId.layer() == 0) continue;

          // have we seen this chamber before?
          if (m_csc.find(chamberId) == m_csc.end())
          {
            m_chamberIds.push_back(chamberId);
            //addTrkCovMatrix(chamberId, tsos); // only for the 1st hit
            AlignableDetOrUnitPtr chamberAlignable = navigator->alignableFromDetId(chamberId);
            m_csc[chamberId] = new MuonCSCChamberResidual(globalGeometry, navigator, chamberId, chamberAlignable);
          }

          m_csc[chamberId]->addResidual(&tsos, hit);
        }

      } // end if track propagation is valid
    } // end if hit is valid
  } // end loop over measurments
}
MuonResidualsFromTrack::MuonResidualsFromTrack ( edm::ESHandle< GlobalTrackingGeometry globalGeometry,
const reco::Muon mu,
AlignableNavigator navigator,
double  maxResidual 
)

Definition at line 112 of file MuonResidualsFromTrack.cc.

References AlignableNavigator::alignableFromDetId(), reco::MuonSegmentMatch::BelongsToTrackByDR, reco::MuonSegmentMatch::BestInStationByDR, clear(), gather_cfg::cout, CSC(), GeomDetEnumerators::DT, DTRecSegment4D::hasPhi(), DTRecSegment4D::hasZed(), reco::Muon::innerTrack(), reco::Muon::isTrackerMuon(), m_chamberIds, m_csc, m_dt13, m_dt2, m_tracker_chi2, m_tracker_numHits, reco::Muon::matches(), muon, DetId::Muon, and track.

  : muon(mu)
{
  clear();
  assert( muon->isTrackerMuon() && muon->innerTrack().isNonnull());
  track = muon->innerTrack().get();
  
  m_tracker_chi2 = muon->innerTrack()->chi2();
  m_tracker_numHits = muon->innerTrack()->ndof() + 5;
  m_tracker_numHits = m_tracker_numHits > 0 ? m_tracker_numHits : 0 ;
  
  /*
  for (trackingRecHit_iterator hit = muon->innerTrack()->recHitsBegin();  hit != muon->innerTrack()->recHitsEnd();  ++hit)
  {
    DetId id = (*hit)->geographicalId();
    if (id.det() == DetId::Tracker)
    {
      m_tracker_numHits++;
      if (id.subdetId() == StripSubdetector::TID  ||  id.subdetId() == StripSubdetector::TEC) m_contains_TIDTEC = true;
    }
  }
  */
  
  for (std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();  
       chamberMatch != muon->matches().end();  chamberMatch++)
  {
    if (chamberMatch->id.det() != DetId::Muon ) continue;
    
    for (std::vector<reco::MuonSegmentMatch>::const_iterator segMatch = chamberMatch->segmentMatches.begin();
         segMatch != chamberMatch->segmentMatches.end();  ++segMatch)
    {
      // select the only segment that belongs to track and is the best in station by dR
      if (! (segMatch->isMask(reco::MuonSegmentMatch::BestInStationByDR) &&
             segMatch->isMask(reco::MuonSegmentMatch::BelongsToTrackByDR)) ) continue;
      
      if (chamberMatch->id.subdetId() == MuonSubdetId::DT)
      {
        const DTChamberId chamberId(chamberMatch->id.rawId());

        DTRecSegment4DRef segmentDT = segMatch->dtSegmentRef;
        const DTRecSegment4D* segment = segmentDT.get();
        if (segment == 0)  continue;
        
        if ( segment->hasPhi()  &&  fabs(chamberMatch->x - segMatch->x) > maxResidual ) continue;
        if ( segment->hasZed()  &&  fabs(chamberMatch->y - segMatch->y) > maxResidual ) continue;
          
        // have we seen this chamber before?
        if (m_dt13.find(chamberId) == m_dt13.end()  &&  m_dt2.find(chamberId) == m_dt2.end()) {
          m_chamberIds.push_back(chamberId);
        }

        if (segment->hasZed())
        {
          if (m_dt2.find(chamberId) == m_dt2.end())
          {
            AlignableDetOrUnitPtr chamberAlignable = navigator->alignableFromDetId(chamberId);
            m_dt2[chamberId] = new MuonTrackDT2ChamberResidual(globalGeometry, navigator, chamberId, chamberAlignable);
          }
          else std::cout<<"multi segment match to tmuon: dt2  -- should not happen!"<<std::endl;
          m_dt2[chamberId]->setSegmentResidual(&(*chamberMatch), &(*segMatch));
        }
        if (segment->hasPhi())
        {
          if (m_dt13.find(chamberId) == m_dt13.end())
          {
            AlignableDetOrUnitPtr chamberAlignable = navigator->alignableFromDetId(chamberId);
            m_dt13[chamberId] = new MuonTrackDT13ChamberResidual(globalGeometry, navigator, chamberId, chamberAlignable);
          }
          else std::cout<<"multi segment match to tmuon: dt13  -- should not happen!"<<std::endl;
          m_dt13[chamberId]->setSegmentResidual(&(*chamberMatch), &(*segMatch));
        }
      }

      else if (chamberMatch->id.subdetId() == MuonSubdetId::CSC) 
      {
        const CSCDetId cscDetId(chamberMatch->id.rawId());
        const CSCDetId chamberId(cscDetId.chamberId());

        if ( fabs(chamberMatch->x - segMatch->x) > maxResidual ) continue;

        // have we seen this chamber before?
        if (m_csc.find(chamberId) == m_csc.end())
        {
          m_chamberIds.push_back(chamberId);
          AlignableDetOrUnitPtr chamberAlignable = navigator->alignableFromDetId(chamberId);
          m_csc[chamberId] = new MuonTrackCSCChamberResidual(globalGeometry, navigator, chamberId, chamberAlignable);
        }
        else std::cout<<"multi segment match to tmuon: csc  -- should not happen!"<<std::endl;
        m_csc[chamberId]->setSegmentResidual(&(*chamberMatch), &(*segMatch));
      }

    }
  }
}
MuonResidualsFromTrack::~MuonResidualsFromTrack ( )

Definition at line 208 of file MuonResidualsFromTrack.cc.

References m_csc, m_dt13, and m_dt2.

{
  for (std::map<DetId,MuonChamberResidual*>::const_iterator residual = m_dt13.begin();  residual != m_dt13.end();  ++residual) {
    delete residual->second;
  }
  for (std::map<DetId,MuonChamberResidual*>::const_iterator residual = m_dt2.begin();  residual != m_dt2.end();  ++residual) {
    delete residual->second;
  }
  for (std::map<DetId,MuonChamberResidual*>::const_iterator residual = m_csc.begin();  residual != m_csc.end();  ++residual) {
    delete residual->second;
  }
}

Member Function Documentation

void MuonResidualsFromTrack::addTrkCovMatrix ( DetId  chamberId,
TrajectoryStateOnSurface tsos 
) [private]

Definition at line 19 of file MuonResidualsFromTrack.cc.

References i, j, TrajectoryStateOnSurface::localError(), m_trkCovMatrix, and LocalTrajectoryError::matrix().

{
  const AlgebraicSymMatrix55 cov55 = tsos.localError().matrix();
  TMatrixDSym cov44(4);
  // change indices from q/p,dxdz,dydz,x,y   to   x,y,dxdz,dydz
  int subs[4] = { 3, 4, 1, 2 };
  for (int i=0;i<4;i++) for (int j=0;j<4;j++)  cov44(i,j) = cov55( subs[i], subs[j] );
  m_trkCovMatrix[chamberId] = cov44;
}
const std::vector<DetId> MuonResidualsFromTrack::chamberIds ( ) const [inline]
MuonChamberResidual * MuonResidualsFromTrack::chamberResidual ( DetId  chamberId,
int  type 
)
TMatrixD MuonResidualsFromTrack::choleskyCorrMatrix ( DetId  chamberId)

Definition at line 326 of file MuonResidualsFromTrack.cc.

References corrMatrix(), gather_cfg::cout, convertSQLiteXML::ok, and query::result.

{
  TMatrixD result(4,4);
  TMatrixDSym corr44 = corrMatrix(chamberId);

  // get an upper triangular matrix U such that corr = U^T * U
  TDecompChol decomp(corr44);
  bool ok = decomp.Decompose();
  result = decomp.GetU();

  std::cout<<"MuonResidualsFromTrack:: corr cholesky after:"<<std::endl;
  result.Print();

  if (!ok){std::cout<<"MuonResidualsFromTrack:: corr decomposition failed!"<<std::endl;}
  return result;
}
void MuonResidualsFromTrack::clear ( void  )

Definition at line 222 of file MuonResidualsFromTrack.cc.

References m_chamberIds, m_contains_TIDTEC, m_csc, m_dt13, m_dt2, m_tracker_chi2, m_tracker_numHits, and m_trkCovMatrix.

Referenced by MuonResidualsFromTrack().

{
  m_tracker_numHits = 0;
  m_tracker_chi2 = 0.;
  m_contains_TIDTEC = false;
  m_chamberIds.clear();
  m_dt13.clear();
  m_dt2.clear();
  m_csc.clear();
  m_trkCovMatrix.clear();
}
bool MuonResidualsFromTrack::contains_TIDTEC ( ) const [inline]
TMatrixDSym MuonResidualsFromTrack::corrMatrix ( DetId  chamberId)

Definition at line 311 of file MuonResidualsFromTrack.cc.

References gather_cfg::cout, covMatrix(), convertSQLiteXML::ok, and query::result.

Referenced by choleskyCorrMatrix().

{
  TMatrixDSym result(4);
  TMatrixDSym cov44 = covMatrix(chamberId);

  // invert it using cholesky decomposition
  TDecompChol decomp(cov44);
  bool ok = decomp.Invert(result);
  std::cout<<"MuonResidualsFromTrack:: corr after:"<<std::endl;
  result.Print();

  if (!ok){std::cout<<"MuonResidualsFromTrack:: cov inversion failed!"<<std::endl;}
  return result;
}
TMatrixDSym MuonResidualsFromTrack::covMatrix ( DetId  chamberId)

Definition at line 267 of file MuonResidualsFromTrack.cc.

References gather_cfg::cout, m_csc, m_dt13, m_dt2, m_trkCovMatrix, and query::result.

Referenced by corrMatrix().

{
  TMatrixDSym result(4);
  std::cout<<"MuonResidualsFromTrack:: cov initial:"<<std::endl;
  result.Print();
  if (m_trkCovMatrix.find(chamberId) == m_trkCovMatrix.end())
  {
    std::cout<<"MuonResidualsFromTrack:: cov does not exist!"<<std::endl;
    return result;
  }
  result = m_trkCovMatrix[chamberId];

  std::cout<<"MuonResidualsFromTrack:: cov before:"<<std::endl;
  result.Print();

  // add segment's errors in quadratures to track's covariance matrix
  double r_err;
  if (m_csc.find(chamberId) == m_csc.end())
  {
    r_err = m_csc[chamberId]->residual_error();
    result(0,0) += r_err*r_err;
    r_err = m_csc[chamberId]->resslope_error();
    result(2,2) += r_err*r_err;
  }
  if (m_dt13.find(chamberId) == m_dt13.end())
  {
    r_err = m_dt13[chamberId]->residual_error();
    result(0,0) += r_err*r_err;
    r_err = m_dt13[chamberId]->resslope_error();
    result(2,2) += r_err*r_err;
  }
  if (m_dt2.find(chamberId) == m_dt2.end())
  {
    r_err = m_dt2[chamberId]->residual_error();
    result(1,1) += r_err*r_err;
    r_err = m_dt2[chamberId]->resslope_error();
    result(3,3) += r_err*r_err;
  }
  std::cout<<"MuonResidualsFromTrack:: cov after:"<<std::endl;
  result.Print();

  return result;
}
const reco::Track* MuonResidualsFromTrack::getTrack ( ) [inline]
double MuonResidualsFromTrack::normalizedChi2 ( ) const
double MuonResidualsFromTrack::trackerChi2 ( ) const [inline]

Definition at line 55 of file MuonResidualsFromTrack.h.

References m_tracker_chi2.

{ return m_tracker_chi2; }
int MuonResidualsFromTrack::trackerNumHits ( ) const [inline]
double MuonResidualsFromTrack::trackerRedChi2 ( ) const

Definition at line 235 of file MuonResidualsFromTrack.cc.

References m_tracker_chi2, and m_tracker_numHits.

Referenced by normalizedChi2(), and AlignmentMonitorMuonVsCurvature::processMuonResidualsFromTrack().

{
  if (m_tracker_numHits > 5) return m_tracker_chi2 / double(m_tracker_numHits - 5);
  else return -1.;
}

Member Data Documentation

Definition at line 76 of file MuonResidualsFromTrack.h.

Referenced by chamberIds(), clear(), and MuonResidualsFromTrack().

Definition at line 74 of file MuonResidualsFromTrack.h.

Referenced by clear(), contains_TIDTEC(), and MuonResidualsFromTrack().

std::map<DetId,TMatrixDSym> MuonResidualsFromTrack::m_trkCovMatrix [private]

Definition at line 78 of file MuonResidualsFromTrack.h.

Referenced by addTrkCovMatrix(), clear(), and covMatrix().

Definition at line 70 of file MuonResidualsFromTrack.h.

Referenced by MuonResidualsFromTrack().

Definition at line 86 of file MuonResidualsFromTrack.h.

Referenced by MuonResidualsFromTrack(), and normalizedChi2().

Definition at line 83 of file MuonResidualsFromTrack.h.

Referenced by getTrack(), MuonResidualsFromTrack(), and normalizedChi2().