CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Alignment/MuonAlignmentAlgorithms/src/MuonDT2ChamberResidual.cc

Go to the documentation of this file.
00001 /* 
00002  * $Id: MuonDT2ChamberResidual.cc,v 1.3 2011/10/12 23:40:24 khotilov Exp $
00003  */
00004 
00005 #include "Alignment/MuonAlignmentAlgorithms/interface/MuonDT2ChamberResidual.h"
00006 
00007 MuonDT2ChamberResidual::MuonDT2ChamberResidual(edm::ESHandle<GlobalTrackingGeometry> globalGeometry, AlignableNavigator *navigator,
00008                                                DetId chamberId, AlignableDetOrUnitPtr chamberAlignable)
00009   : MuonHitsChamberResidual(globalGeometry, navigator, chamberId, chamberAlignable)
00010 {
00011   m_type = MuonChamberResidual::kDT2; 
00012   align::GlobalVector zDirection(0., 0., 1.);
00013   m_sign = m_globalGeometry->idToDet(m_chamberId)->toLocal(zDirection).y() > 0. ? 1. : -1.; 
00014 }
00015 
00016 void MuonDT2ChamberResidual::addResidual(const TrajectoryStateOnSurface *tsos, const TransientTrackingRecHit *hit)
00017 {
00018   DetId id = hit->geographicalId();
00019 
00020   align::LocalPoint hitChamberPos = m_chamberAlignable->surface().toLocal(m_globalGeometry->idToDet(id)->toGlobal(hit->localPosition()));
00021   align::LocalPoint tsosChamberPos = m_chamberAlignable->surface().toLocal(m_globalGeometry->idToDet(id)->toGlobal(tsos->localPosition()));
00022 
00023   double residual = tsosChamberPos.y() - hitChamberPos.y();  // residual is track minus hit
00024   double weight = 1. / hit->localPositionError().xx();  // weight linear fit by hit-only local error (yes, xx: layer x is chamber y)
00025   double layerPosition = tsosChamberPos.z();  // the layer's position in the chamber's coordinate system
00026   double layerHitPos = hitChamberPos.z();
00027 
00028   m_numHits++;
00029 
00030   // "x" is the layerPosition, "y" is the residual (this is a linear fit to residual versus layerPosition)
00031   m_residual_1 += weight;
00032   m_residual_x += weight * layerPosition;
00033   m_residual_y += weight * residual;
00034   m_residual_xx += weight * layerPosition * layerPosition;
00035   m_residual_xy += weight * layerPosition * residual;
00036 
00037   // "x" is the layerPosition, "y" is chamberx (this is a linear fit to chamberx versus layerPosition)
00038   m_trackx_1 += weight;
00039   m_trackx_x += weight * layerPosition;
00040   m_trackx_y += weight * tsosChamberPos.x();
00041   m_trackx_xx += weight * layerPosition * layerPosition;
00042   m_trackx_xy += weight * layerPosition * tsosChamberPos.x();
00043 
00044   // "x" is the layerPosition, "y" is chambery (this is a linear fit to chambery versus layerPosition)
00045   m_tracky_1 += weight;
00046   m_tracky_x += weight * layerPosition;
00047   m_tracky_y += weight * tsosChamberPos.y();
00048   m_tracky_xx += weight * layerPosition * layerPosition;
00049   m_tracky_xy += weight * layerPosition * tsosChamberPos.y();
00050 
00051   m_hitx_1 += weight;
00052   m_hitx_x += weight * layerHitPos;
00053   m_hitx_y += weight * hitChamberPos.x();
00054   m_hitx_xx += weight * layerHitPos * layerHitPos;
00055   m_hitx_xy += weight * layerHitPos * hitChamberPos.x();
00056 
00057   m_hity_1 += weight;
00058   m_hity_x += weight * layerHitPos;
00059   m_hity_y += weight * hitChamberPos.y();
00060   m_hity_xx += weight * layerHitPos * layerHitPos;
00061   m_hity_xy += weight * layerHitPos * hitChamberPos.y();
00062 
00063   m_localIDs.push_back(id);
00064   m_localResids.push_back(tsos->localPosition().x() - hit->localPosition().x());
00065   m_individual_x.push_back(layerPosition);
00066   m_individual_y.push_back(residual);
00067   m_individual_weight.push_back(weight);
00068   
00069   if (m_numHits>1) segment_fit();
00070 }