CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

DynamicTruncation Class Reference

#include <DynamicTruncation.h>

List of all members.

Public Types

typedef
TransientTrackingRecHit::ConstRecHitContainer 
ConstRecHitContainer
typedef
TransientTrackingRecHit::ConstRecHitPointer 
ConstRecHitPointer

Public Member Functions

 DynamicTruncation (const edm::Event &, const MuonServiceProxy &)
TransientTrackingRecHit::ConstRecHitContainer filter (const Trajectory &)
std::vector< double > getEstimators ()
void setThr (int, int)
 ~DynamicTruncation ()

Private Member Functions

void compatibleDets (TrajectoryStateOnSurface &, std::map< int, std::vector< DetId > > &)
void filteringAlgo (std::map< int, std::vector< DetId > > &)
double getBest (std::vector< DTRecSegment4D > &, TrajectoryStateOnSurface &, DTRecSegment4D &)
double getBest (std::vector< CSCSegment > &, TrajectoryStateOnSurface &, CSCSegment &)
ConstRecHitContainer sort (ConstRecHitContainer &)
void update (TrajectoryStateOnSurface &, ConstRecHitPointer)
void updateWithCSChits (ConstRecHitContainer &)
void updateWithDThits (ConstRecHitContainer &)

Private Attributes

std::map< CSCDetId, GlobalErrorcscApeMap
edm::ESHandle< CSCGeometrycscGeom
int CSCThr
TrajectoryStateOnSurface currentState
std::map< DTChamberId,
GlobalError
dtApeMap
int DTThr
std::vector< double > estimators
edm::ESHandle< MagneticFieldmagfield
DirectMuonNavigationnavigation
edm::ESHandle
< MuonDetLayerGeometry
navMuon
edm::ESHandle< Propagatorpropagator
edm::ESHandle< PropagatorpropagatorCompatibleDet
ConstRecHitContainer result
const edm::EventtheEvent
edm::ESHandle
< GlobalTrackingGeometry
theG
edm::ESHandle
< TransientTrackingRecHitBuilder
theMuonRecHitBuilder
const edm::EventSetuptheSetup
edm::ESHandle
< TrajectoryStateUpdator
updatorHandle

Detailed Description

Class: DynamicTruncation

Description: class for the dynamical stop of the KF according to the compatibility degree between the extrapolated track state and the reconstructed segment in the muon chambers

Date:
2011/11/29 07:50:36
Revision:
1.6

Authors : D. Pagano & G. Bruno - UCL Louvain

Definition at line 47 of file DynamicTruncation.h.


Member Typedef Documentation

Definition at line 52 of file DynamicTruncation.h.

Definition at line 51 of file DynamicTruncation.h.


Constructor & Destructor Documentation

DynamicTruncation::DynamicTruncation ( const edm::Event event,
const MuonServiceProxy &  theService 
)

Definition at line 52 of file DynamicTruncation.cc.

References cscGeom, event(), magfield, navigation, navMuon, propagator, propagatorCompatibleDet, theEvent, theG, theMuonRecHitBuilder, theSetup, and updatorHandle.

                                                                                             :
  DTThr(0), CSCThr(0) 
{
  theEvent = &event;
  theSetup = &theService.eventSetup();
  propagator = theService.propagator("SmartPropagator");
  propagatorCompatibleDet = theService.propagator("SteppingHelixPropagatorAny");
  theG = theService.trackingGeometry();
  theService.eventSetup().get<TransientRecHitRecord>().get("MuonRecHitBuilder",theMuonRecHitBuilder);
  theService.eventSetup().get<TrackingComponentsRecord>().get("KFUpdator",updatorHandle);
  theService.eventSetup().get<MuonGeometryRecord>().get(cscGeom);
  theService.eventSetup().get<MuonRecoGeometryRecord>().get(navMuon);
  theService.eventSetup().get<IdealMagneticFieldRecord>().get(magfield);
  navigation = new DirectMuonNavigation(theService.detLayerGeometry());
}
DynamicTruncation::~DynamicTruncation ( )

Definition at line 70 of file DynamicTruncation.cc.

References navigation.

                                      {
  if (navigation) delete navigation;
}

Member Function Documentation

void DynamicTruncation::compatibleDets ( TrajectoryStateOnSurface ,
std::map< int, std::vector< DetId > > &   
) [private]

Referenced by filter().

TransientTrackingRecHit::ConstRecHitContainer DynamicTruncation::filter ( const Trajectory traj)

Definition at line 76 of file DynamicTruncation.cc.

References compatibleDets(), cscApeMap, currentState, DetId::det(), dtApeMap, error, filteringAlgo(), TrajectoryMeasurement::forwardPredictedState(), TrackingRecHit::geographicalId(), edm::EventSetup::get(), TrajectoryStateOnSurface::globalPosition(), PV3DBase< T, PVType, FrameType >::mag(), Trajectory::measurements(), TrajectoryMeasurement::recHit(), result, theSetup, align::Tracker, and update().

Referenced by GlobalMuonRefitter::refit().

                                                                                            {
  result.clear();

  // Fill the map with the APE chamber by chamber (DT)
  // IT ALSO WORKS IF APE IS 0
  edm::ESHandle<AlignmentErrors> dtAlignmentErrors;
  theSetup->get<DTAlignmentErrorRcd>().get( dtAlignmentErrors );
  for ( std::vector<AlignTransformError>::const_iterator it = dtAlignmentErrors->m_alignError.begin();
        it != dtAlignmentErrors->m_alignError.end(); it++ ) {
    CLHEP::HepSymMatrix error = (*it).matrix();
    GlobalError glbErr(error[0][0], error[1][0], error[1][1], error[2][0], error[2][1], error[2][2]);
    DTChamberId DTid((*it).rawId());    
    dtApeMap.insert( pair<DTChamberId, GlobalError> (DTid, glbErr) ); 
  }
  
  // Fill the map with the APE chamber by chamber (CSC)
  // IT ALSO WORKS IF APE IS 0
  edm::ESHandle<AlignmentErrors> cscAlignmentErrors;
  theSetup->get<CSCAlignmentErrorRcd>().get( cscAlignmentErrors );
  for ( std::vector<AlignTransformError>::const_iterator it = cscAlignmentErrors->m_alignError.begin();
        it != cscAlignmentErrors->m_alignError.end(); it++ ) {
    CLHEP::HepSymMatrix error = (*it).matrix();
    GlobalError glbErr(error[0][0], error[1][0], error[1][1], error[2][0], error[2][1], error[2][2]);
    CSCDetId CSCid((*it).rawId());
    cscApeMap.insert( pair<CSCDetId, GlobalError> (CSCid, glbErr) );
  }

  // Put the tracker hits in the final vector and get the last tracker valid measure
  std::vector<TrajectoryMeasurement> muonMeasurements = traj.measurements();
  TrajectoryMeasurement lastTKm = muonMeasurements.front();
  for (std::vector<TrajectoryMeasurement>::const_iterator imT = muonMeasurements.begin(); imT != muonMeasurements.end(); imT++ ) {
    if ( !(*imT).recHit()->isValid() ) continue;
    const TransientTrackingRecHit* hit = &(*(*imT).recHit());
    if (hit->geographicalId().det() == DetId::Tracker) {
      result.push_back((*imT).recHit());
      if (!(*imT).forwardPredictedState().isValid()) continue;
      if ((*imT).forwardPredictedState().globalPosition().mag() 
          > lastTKm.forwardPredictedState().globalPosition().mag()) lastTKm = *imT;
    }
  }

  // get the last (forward) predicted state for the tracker
  currentState = lastTKm.forwardPredictedState();
  
  // update the state with the last tracker measure
  update(currentState, lastTKm.recHit());

  // use the navigation to get the list of compatible dets
  map<int, std::vector<DetId> > detMap;
  compatibleDets(currentState, detMap);
  
  // selects the muon hits for the final refit
  filteringAlgo(detMap);
  
  return result;
}
void DynamicTruncation::filteringAlgo ( std::map< int, std::vector< DetId > > &  ) [private]

Definition at line 208 of file DynamicTruncation.cc.

References CSC(), CSCThr, currentState, GeomDetEnumerators::DT, MuonSubdetId::DT, DTThr, estimators, getBest(), ChamberSegmentUtility::getCSClist(), ChamberSegmentUtility::getCSCRHmap(), ChamberSegmentUtility::getDTlist(), ChamberSegmentUtility::getDTRHmap(), TrajectoryStateOnSurface::isValid(), j, MAX_THR, DetId::Muon, propagator, result, sort(), DTChamberId::station(), CSCDetId::station(), theEvent, theG, theMuonRecHitBuilder, theSetup, updateWithCSChits(), and updateWithDThits().

Referenced by filter().

                                                                         {
  ChamberSegmentUtility getSegs(*theEvent, *theSetup);
  for (unsigned int iDet = 0; iDet < detMap.size(); ++iDet) {
    double bestLayerValue = MAX_THR;
    bool isDTorCSC = false;
    ConstRecHitContainer layerRH;
    std::vector<DetId> chamber = detMap[iDet];
    for (unsigned int j = 0; j < chamber.size(); ++j) {
      DetId id = chamber[j];
      
      if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT) {
        isDTorCSC = true;
        
        DTChamberId DTid(id);

        std::vector<DTRecSegment4D> allDTsegs;
        std::map<int, std::vector<DTRecSegment4D> >::const_iterator dtIter = getSegs.getDTlist().find(DTid.station());
        if (dtIter != getSegs.getDTlist().end()){
          allDTsegs = dtIter->second;
        }
        std::vector<DTRecSegment4D>::size_type sz = allDTsegs.size();
        for (unsigned int iSeg=0; iSeg<sz; ++iSeg) {
          
          // Propagate the state to the current chamber
          TrajectoryStateOnSurface tsosdt = propagator->propagate(currentState, 
                                                                  theG->idToDet(allDTsegs[iSeg].chamberId())->surface());
          if (!tsosdt.isValid()) continue;

          std::vector<DTRecSegment4D> DTsegs;
          DTsegs.push_back(allDTsegs[iSeg]); 
          
          DTRecSegment4D bestDTSeg;
          double bestChamberValue = getBest(DTsegs, tsosdt, bestDTSeg);
          if (bestChamberValue < bestLayerValue) bestLayerValue = bestChamberValue;
          
          // Check if the best estimator value is below the THR and then get the RH componing the segment
          if (bestChamberValue >= DTThr || bestChamberValue > bestLayerValue) continue; 
          layerRH.clear();
          std::vector<DTRecHit1D> DTrh = getSegs.getDTRHmap(bestDTSeg);
          for (std::vector<DTRecHit1D>::iterator it = DTrh.begin(); it != DTrh.end(); it++) {
            layerRH.push_back(theMuonRecHitBuilder->build(&*it));
          }
        }
      }
      if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
        isDTorCSC = true;
        CSCDetId CSCid(id);
        
        std::vector<CSCSegment> allCSCsegs;
        std::map<int, std::vector<CSCSegment> >::const_iterator cscIter = getSegs.getCSClist().find(CSCid.station()); 
        if (cscIter != getSegs.getCSClist().end()){
          allCSCsegs = cscIter->second;
        }
        
        std::vector<CSCSegment>::size_type sz = allCSCsegs.size();
        for (unsigned int iSeg=0; iSeg<sz; ++iSeg) {
          
          // Propagate the state to the current chamber
          TrajectoryStateOnSurface tsoscsc = propagator->propagate(currentState, 
                                                                   theG->idToDet(allCSCsegs[iSeg].cscDetId())->surface());
          if (!tsoscsc.isValid()) continue;
          
          std::vector<CSCSegment> CSCsegs;
          CSCsegs.push_back(allCSCsegs[iSeg]);
          
          CSCSegment bestCSCSeg;
          double bestChamberValue = getBest(CSCsegs, tsoscsc, bestCSCSeg);
          if (bestChamberValue < bestLayerValue) bestLayerValue = bestChamberValue;
          
          // Check if the best estimator value is below the THR and then get the RH componing the segment
          if (bestChamberValue >= CSCThr || bestChamberValue > bestLayerValue) continue;
          layerRH.clear();
          std::vector<CSCRecHit2D> CSCrh = getSegs.getCSCRHmap(bestCSCSeg);
          for (std::vector<CSCRecHit2D>::iterator it = CSCrh.begin(); it != CSCrh.end(); ++it) {
            layerRH.push_back(theMuonRecHitBuilder->build(&*it));
          }
        }
      }
    }

    if (isDTorCSC) {
      if (bestLayerValue < MAX_THR) estimators.push_back(bestLayerValue);
      else estimators.push_back(-1);
    }

    if (layerRH.size() > 0) {                                                                                                                                          
      for (ConstRecHitContainer::iterator it = layerRH.begin(); it != layerRH.end(); ++it) {                                                                         
        result.push_back((*it));                                                                                                                                         
      }                                                                                                                                                                
      
      // sort the vector                                                                                                                                             
      layerRH = sort(layerRH);                                                                                                                                         
      
      // update the currentState using all rh                                                                                                             
      DetId id = layerRH.front()->geographicalId();                                                                                                      
      if (id.subdetId() == MuonSubdetId::DT) updateWithDThits(layerRH);                                                                                 
      else updateWithCSChits(layerRH);                                                                                                                 
    }
    layerRH.clear();                                                                                                                                                    
  }
}  
double DynamicTruncation::getBest ( std::vector< CSCSegment > &  segs,
TrajectoryStateOnSurface tsos,
CSCSegment bestCSCSeg 
) [private]

Definition at line 144 of file DynamicTruncation.cc.

References cscApeMap, i, MAX_THR, edm::second(), theG, tmp, ErrorFrameTransformer::transform(), and StateSegmentMatcher::value().

Referenced by filteringAlgo().

                                                                                                                     {
  unsigned int i = 0;
  double val = MAX_THR;
  std::vector<CSCSegment>::size_type sz = segs.size();
  for (i=0; i<sz; i++) {
    LocalError apeLoc; //default constructor is all zeroes, OK
    apeLoc = ErrorFrameTransformer().transform(cscApeMap.find(segs[i].cscDetId())->second, theG->idToDet(segs[i].cscDetId())->surface());
    StateSegmentMatcher estim(&tsos, &segs[i], &apeLoc);
    double tmp = estim.value();
    if (tmp < val) {
      bestCSCSeg = segs[i];
      val = tmp;
    }
  }
  return val;
}
double DynamicTruncation::getBest ( std::vector< DTRecSegment4D > &  segs,
TrajectoryStateOnSurface tsos,
DTRecSegment4D bestDTSeg 
) [private]

Definition at line 163 of file DynamicTruncation.cc.

References dtApeMap, i, MAX_THR, edm::second(), theG, tmp, ErrorFrameTransformer::transform(), and StateSegmentMatcher::value().

                                                                                                                            {
  unsigned int i = 0;
  double val = MAX_THR;
  std::vector<DTRecSegment4D>::size_type sz = segs.size();
  for (i=0; i<sz; i++) {
    LocalError apeLoc; //default constructor is all zeroes, OK
    apeLoc = ErrorFrameTransformer().transform(dtApeMap.find(segs[i].chamberId())->second, theG->idToDet(segs[i].chamberId())->surface());
    StateSegmentMatcher estim(&tsos, &segs[i], &apeLoc); 
    double tmp = estim.value();                                                                                                                                              
    if (tmp < val) {
      bestDTSeg = segs[i];
      val = tmp;
    }
  }
  return val;
}
std::vector<double> DynamicTruncation::getEstimators ( ) [inline]

Definition at line 65 of file DynamicTruncation.h.

References estimators.

{return estimators;};
void DynamicTruncation::setThr ( int  bThr,
int  eThr 
)

Definition at line 135 of file DynamicTruncation.cc.

References CSCThr, DTThr, and MAX_THR.

Referenced by GlobalMuonRefitter::refit().

                                                 {
  if (bThr <= MAX_THR && bThr >= 0) DTThr  = bThr; // DT thr 
  else DTThr = MAX_THR;
  if (eThr <= MAX_THR && eThr >= 0) CSCThr = eThr; // CSC thr
  else CSCThr = MAX_THR;
}
TransientTrackingRecHit::ConstRecHitContainer DynamicTruncation::sort ( ConstRecHitContainer recHits) [private]

Definition at line 340 of file DynamicTruncation.cc.

References i, j, mag(), n, and swap().

Referenced by filteringAlgo().

                                                                                                 {
  unsigned int i=0;
  unsigned int j=0;
  ConstRecHitContainer::size_type n = recHits.size();
  for(i=1; i<n; ++i)
    for(j=n-1; j>=i; --j)
      {
        if(recHits[j-1]->globalPosition().mag() > recHits[j]->globalPosition().mag())
          {
            swap (recHits[j-1],recHits[j]);
          }
      }
  return recHits;
}
void DynamicTruncation::update ( TrajectoryStateOnSurface tsos,
ConstRecHitPointer  rechit 
) [private]

Definition at line 312 of file DynamicTruncation.cc.

References currentState, TrajectoryStateOnSurface::isValid(), groupFilesInBlocks::temp, and updatorHandle.

Referenced by filter().

                                                                                        {
  TrajectoryStateOnSurface temp = updatorHandle->update(tsos, *rechit);
  if (temp.isValid()) currentState = updatorHandle->update(tsos, *rechit);
}
void DynamicTruncation::updateWithCSChits ( ConstRecHitContainer recHits) [private]

Definition at line 329 of file DynamicTruncation.cc.

References cscGeom, currentState, GeomDet::geographicalId(), TrajectoryStateOnSurface::isValid(), propagator, groupFilesInBlocks::temp, theG, and updatorHandle.

Referenced by filteringAlgo().

                                                                       {
  for (ConstRecHitContainer::const_iterator it = recHits.begin(); it != recHits.end(); ++it) {
    const CSCLayer* cscChamber = cscGeom->layer((*it)->det()->geographicalId());
    CSCDetId layid = cscChamber->geographicalId();
    TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(layid)->surface());
    if (temp.isValid()) currentState = updatorHandle->update(temp, **it);
  }
}
void DynamicTruncation::updateWithDThits ( ConstRecHitContainer recHits) [private]

Definition at line 319 of file DynamicTruncation.cc.

References currentState, propagator, groupFilesInBlocks::temp, theG, and updatorHandle.

Referenced by filteringAlgo().

                                                                      {
  for (ConstRecHitContainer::const_iterator it = recHits.begin(); it != recHits.end(); ++it) {
    DTLayerId layid((*it)->det()->geographicalId());
    TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(layid)->surface());
    if (temp.isValid()) currentState = updatorHandle->update(temp, **it);
  }
}

Member Data Documentation

Definition at line 98 of file DynamicTruncation.h.

Referenced by filter(), and getBest().

Definition at line 86 of file DynamicTruncation.h.

Referenced by DynamicTruncation(), and updateWithCSChits().

Definition at line 81 of file DynamicTruncation.h.

Referenced by filteringAlgo(), and setThr().

Definition at line 97 of file DynamicTruncation.h.

Referenced by filter(), and getBest().

int DynamicTruncation::DTThr [private]

Definition at line 80 of file DynamicTruncation.h.

Referenced by filteringAlgo(), and setThr().

std::vector<double> DynamicTruncation::estimators [private]

Definition at line 94 of file DynamicTruncation.h.

Referenced by filteringAlgo(), and getEstimators().

Definition at line 91 of file DynamicTruncation.h.

Referenced by DynamicTruncation().

Definition at line 89 of file DynamicTruncation.h.

Referenced by DynamicTruncation().

Definition at line 84 of file DynamicTruncation.h.

Referenced by GeometricSearchDet::compatibleDets(), and DynamicTruncation().

Definition at line 78 of file DynamicTruncation.h.

Referenced by filter(), and filteringAlgo().

Definition at line 92 of file DynamicTruncation.h.

Referenced by DynamicTruncation(), and filteringAlgo().

Definition at line 87 of file DynamicTruncation.h.

Referenced by DynamicTruncation(), and filteringAlgo().

Definition at line 93 of file DynamicTruncation.h.

Referenced by DynamicTruncation(), filter(), and filteringAlgo().

Definition at line 88 of file DynamicTruncation.h.

Referenced by DynamicTruncation(), update(), updateWithCSChits(), and updateWithDThits().