CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Alignment/MuonAlignmentAlgorithms/src/MuonCSCChamberResidual.cc

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