Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:49

0001 /** \file
0002  *
0003  * \author Stefano Lacaprara - INFN Legnaro <stefano.lacaprara@pd.infn.it>
0004  * \author Riccardo Bellan - INFN TO <riccardo.bellan@cern.ch>
0005  */
0006 
0007 /* This Class Header */
0008 #include "RecoLocalMuon/DTSegment/src/DTHitPairForFit.h"
0009 
0010 /* Collaborating Class Header */
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 
0013 /* C++ Headers */
0014 #include <iostream>
0015 using namespace std;
0016 
0017 /* ====================================================================== */
0018 
0019 /// Constructor
0020 DTHitPairForFit::DTHitPairForFit(const DTRecHit1DPair& pair,
0021                                  const DTSuperLayer& sl,
0022                                  const edm::ESHandle<DTGeometry>& dtGeom) {
0023   theWireId = pair.wireId();
0024   theDigiTime = pair.digiTime();
0025 
0026   const DTLayer* layer = dtGeom->layer(theWireId.layerId());
0027 
0028   // transform the Local position in Layer-rf in a SL local position
0029   theLeftPos = sl.toLocal(layer->toGlobal(pair.componentRecHit(DTEnums::Left)->localPosition()));
0030   theRightPos = sl.toLocal(layer->toGlobal(pair.componentRecHit(DTEnums::Right)->localPosition()));
0031 
0032   // TODO how do I transform an error from local to global?
0033   theError = pair.componentRecHit(DTEnums::Left)->localPositionError();
0034   // theError =
0035   //   layer->surface().toLocal(sl.surface().toGlobal(pair.componentRecHit(DTEnums::Left)->localPositionError()));
0036 }
0037 
0038 /// Destructor
0039 DTHitPairForFit::~DTHitPairForFit() {}
0040 
0041 /* Operations */
0042 LocalPoint DTHitPairForFit::localPosition(DTEnums::DTCellSide s) const {
0043   if (s == DTEnums::Left)
0044     return theLeftPos;
0045   else if (s == DTEnums::Right)
0046     return theRightPos;
0047   else {
0048     throw cms::Exception("DTHitPairForFit") << " localPosition called with undef LR code" << endl;
0049     return LocalPoint();
0050   }
0051 }
0052 
0053 pair<bool, bool> DTHitPairForFit::isCompatible(const LocalPoint& posIni, const LocalVector& dirIni) const {
0054   pair<bool, bool> ret;
0055   LocalPoint segPosAtZLeft = posIni + dirIni * (theLeftPos.z() - posIni.z()) / dirIni.z();
0056   LocalPoint segPosAtZRight = posIni + dirIni * (theRightPos.z() - posIni.z()) / dirIni.z();
0057   float dxLeft = fabs(theLeftPos.x() - segPosAtZLeft.x());
0058   float dxRight = fabs(theRightPos.x() - segPosAtZRight.x());
0059   float exx = sqrt(theError.xx());
0060   // if both below 3 sigma, return both
0061   // if both at 10 sigma or above, return none
0062   // if one is below N sigma and one above, for 10>=N>=3, match only that one, otherwise none
0063   if (std::max(dxLeft, dxRight) < 3 * exx) {
0064     ret = make_pair(true, true);
0065   } else if (std::min(dxLeft, dxRight) >= 10 * exx) {
0066     ret = make_pair(false, false);
0067   } else {
0068     float sigmasL = floorf(dxLeft / exx), sigmasR = floorf(dxRight / exx);
0069     ret.first = (sigmasL < sigmasR);
0070     ret.second = (sigmasR < sigmasL);
0071   }
0072   return ret;
0073 }
0074 
0075 bool DTHitPairForFit::operator<(const DTHitPairForFit& hit) const {
0076   //SL if same layer use x() for strict ordering
0077   if (id() == hit.id())
0078     return (theLeftPos.x() < hit.localPosition(DTEnums::Left).x());
0079   return (id() < hit.id());
0080 }
0081 
0082 bool DTHitPairForFit::operator==(const DTHitPairForFit& hit) const {
0083   return (id() == hit.id() && fabs(digiTime() - hit.digiTime()) < 0.1);
0084 }
0085 
0086 ostream& operator<<(ostream& out, const DTHitPairForFit& hit) {
0087   out << hit.leftPos() << " " << hit.rightPos();
0088   return out;
0089 }