CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoLocalMuon/DTSegment/src/DTHitPairForFit.cc

Go to the documentation of this file.
00001 
00009 /* This Class Header */
00010 #include "RecoLocalMuon/DTSegment/src/DTHitPairForFit.h"
00011 
00012 /* Collaborating Class Header */
00013 #include "FWCore/Utilities/interface/Exception.h"
00014 
00015 /* C++ Headers */
00016 #include <iostream>
00017 using namespace std;
00018 
00019 /* ====================================================================== */
00020 
00022 DTHitPairForFit::DTHitPairForFit(const DTRecHit1DPair& pair,
00023                                  const DTSuperLayer& sl,
00024                                  const edm::ESHandle<DTGeometry>& dtGeom) {
00025 
00026   theWireId = pair.wireId();
00027   theDigiTime = pair.digiTime();
00028   
00029   const DTLayer* layer = dtGeom->layer(theWireId.layerId());
00030 
00031   // transform the Local position in Layer-rf in a SL local position
00032   theLeftPos =
00033     sl.toLocal(layer->toGlobal(pair.componentRecHit(DTEnums::Left)->localPosition()));
00034   theRightPos =
00035     sl.toLocal(layer->toGlobal(pair.componentRecHit(DTEnums::Right)->localPosition()));
00036 
00037   // TODO how do I transform an error from local to global?
00038   theError = pair.componentRecHit(DTEnums::Left)->localPositionError();
00039   // theError =
00040   //   layer->surface().toLocal(sl.surface().toGlobal(pair.componentRecHit(DTEnums::Left)->localPositionError()));
00041   
00042 }
00043 
00045 DTHitPairForFit::~DTHitPairForFit() {
00046 }
00047 
00048 /* Operations */ 
00049 LocalPoint DTHitPairForFit::localPosition(DTEnums::DTCellSide s) const {
00050   if (s==DTEnums::Left) return theLeftPos;
00051   else if (s==DTEnums::Right) return theRightPos;
00052   else{ 
00053     throw cms::Exception("DTHitPairForFit")<<" localPosition called with undef LR code"<<endl;
00054     return LocalPoint();
00055   }
00056 }
00057 
00058 pair<bool,bool> 
00059 DTHitPairForFit::isCompatible(const LocalPoint& posIni,
00060                               const LocalVector& dirIni) const {
00061 
00062 
00063     pair<bool,bool> ret;
00064     LocalPoint segPosAtZLeft  = posIni+dirIni*(theLeftPos.z() -posIni.z())/dirIni.z();
00065     LocalPoint segPosAtZRight = posIni+dirIni*(theRightPos.z()-posIni.z())/dirIni.z();
00066     float dxLeft  = fabs(theLeftPos.x() - segPosAtZLeft.x());
00067     float dxRight = fabs(theRightPos.x() - segPosAtZRight.x());
00068     float exx = sqrt(theError.xx());
00069     // if both below 3 sigma, return both
00070     // if both at 10 sigma or above, return none
00071     // if one is below N sigma and one above, for 10>=N>=3, match only that one, otherwise none
00072     if (std::max(dxLeft, dxRight) < 3*exx) {
00073         ret = make_pair(true,true);
00074     } else if (std::min(dxLeft, dxRight) >= 10*exx) {
00075         ret = make_pair(false,false);
00076     } else {
00077         float sigmasL = floorf(dxLeft/exx), sigmasR = floorf(dxRight/exx);
00078         ret.first  = ( sigmasL < sigmasR );
00079         ret.second = ( sigmasR < sigmasL );
00080     } 
00081     return ret;
00082 }
00083 
00084 bool DTHitPairForFit::operator<(const DTHitPairForFit& hit) const {
00085   //SL if same layer use x() for strict ordering
00086   if (id()==hit.id()) 
00087     return (theLeftPos.x() < hit.localPosition(DTEnums::Left).x());
00088   return (id() < hit.id());
00089 }
00090 
00091 bool DTHitPairForFit::operator==(const DTHitPairForFit& hit) const {
00092   return  (id() == hit.id() && fabs(digiTime() - hit.digiTime()) < 0.1 );
00093 }
00094 
00095 ostream& operator<<(ostream& out, const DTHitPairForFit& hit) {
00096   out << hit.leftPos() << " " << hit.rightPos() ;
00097   return out;
00098 }