CMS 3D CMS Logo

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

AlignableNavigator Class Reference

#include <AlignableNavigator.h>

List of all members.

Public Types

typedef std::map< DetId,
AlignableDetOrUnitPtr
MapType
typedef MapType::value_type PairType

Public Member Functions

std::vector
< AlignableDetOrUnitPtr
alignableDetOrUnits ()
 return all AlignableDetOrUnitPtrs
AlignableDetOrUnitPtr alignableFromDetId (const DetId &detid)
 Returns AlignableDetOrUnitPtr corresponding to given DetId.
AlignableDetOrUnitPtr alignableFromGeomDet (const GeomDet *geomDet)
 Returns AlignableDetOrUnitPtr corresponding to given GeomDet.
 AlignableNavigator (AlignableExtras *extras, Alignable *tracker, Alignable *muon=0)
 Constructor from one or two Alignables.
 AlignableNavigator (Alignable *tracker, Alignable *muon=0)
 Constructor from one or two Alignables.
 AlignableNavigator (std::vector< Alignable * > alignables)
 Constructor from list of Alignbable.
std::vector
< AlignableDetOrUnitPtr
alignablesFromHits (const TransientTrackingRecHit::ConstRecHitContainer &hitVec)
 Returns vector of AlignableDetOrUnitPtr for given vector of Hits.
std::vector
< AlignableDetOrUnitPtr
alignablesFromHits (const std::vector< const TransientTrackingRecHit * > &hitvec)
 Returns vector AlignableDetOrUnitPtr for given vector of Hits.
bool detAndSubdetInMap (const DetId &detid) const
 Given a DetId, returns true if DetIds with this detector and subdetector id are in the map (not necessarily the exact DetId)
int size (void)
 Returns number of elements in map.

Private Member Functions

unsigned int recursiveGetId (Alignable *alignable)

Private Attributes

std::vector< std::pair< int,
int > > 
theDetAndSubdet
MapType theMap

Detailed Description

A class to navigate from a DetId to the corresponding AlignableDetOrUnitPtr. A map is created at construction time from all sub-structures of the constructor's argument(s) that are AlignableDet or AlignableDetUnit.

Definition at line 25 of file AlignableNavigator.h.


Member Typedef Documentation

Definition at line 39 of file AlignableNavigator.h.

typedef MapType::value_type AlignableNavigator::PairType

Definition at line 40 of file AlignableNavigator.h.


Constructor & Destructor Documentation

AlignableNavigator::AlignableNavigator ( Alignable tracker,
Alignable muon = 0 
) [explicit]

Constructor from one or two Alignables.

Definition at line 18 of file AlignableNavigator.cc.

References recursiveGetId(), and theMap.

{
  theMap.clear();

  const unsigned int numNonDets = this->recursiveGetId(tracker) + this->recursiveGetId(muon);

  if (numNonDets) {
    edm::LogWarning("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
                                 << theMap.size() << ", but found also " << numNonDets 
                                 << " Alignables that have DetId!=0,\nbeing neither "
                                 << "AlignableDet nor AlignableDetUnit. This will "
                                 << "lead to an exception in case alignableFromDetId(..) "
                                 << "is called for one of these DetIds.\n" 
                                 << "If there is no exception, you can ignore this message.";
  } else {
    edm::LogInfo("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
                              << theMap.size() << ".";
  }
}
AlignableNavigator::AlignableNavigator ( AlignableExtras extras,
Alignable tracker,
Alignable muon = 0 
) [explicit]

Constructor from one or two Alignables.

Definition at line 39 of file AlignableNavigator.cc.

References AlignableExtras::components(), recursiveGetId(), and theMap.

{
  theMap.clear();

  unsigned int numNonDets = this->recursiveGetId(tracker) + this->recursiveGetId(muon);

  if (extras) {
    align::Alignables allExtras = extras->components();
    for ( std::vector<Alignable*>::iterator it = allExtras.begin(); it != allExtras.end(); ++it ) {
      numNonDets += this->recursiveGetId(*it);
    }
  }

  if (numNonDets) {
    edm::LogWarning("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
                                 << theMap.size() << ", but found also " << numNonDets 
                                 << " Alignables that have DetId!=0,\nbeing neither "
                                 << "AlignableDet nor AlignableDetUnit. This will "
                                 << "lead to an exception in case alignableFromDetId(..) "
                                 << "is called for one of these DetIds.\n" 
                                 << "If there is no exception, you can ignore this message.";
  } else {
    edm::LogInfo("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
                              << theMap.size() << ".";
  }
}
AlignableNavigator::AlignableNavigator ( std::vector< Alignable * >  alignables) [explicit]

Constructor from list of Alignbable.

Definition at line 67 of file AlignableNavigator.cc.

References recursiveGetId(), and theMap.

{
  theMap.clear();

  unsigned int numNonDets = 0;
  for ( std::vector<Alignable*>::iterator it = alignables.begin(); it != alignables.end(); ++it ) {
    numNonDets += this->recursiveGetId(*it);
  }
  if (numNonDets) {
    edm::LogWarning("Alignment") <<"@SUB=AlignableNavigator" << "Created with map of size "
                                 << theMap.size() << ", but found also " << numNonDets 
                                 << " Alignables that have DetId!=0,\nbeing neither "
                                 << "AlignableDet nor AlignableDetUnit. This will "
                                 << "lead to an exception in case alignableFromDetId(..) "
                                 << "is called for one of these DetIds.\n" 
                                 << "If there is no exception, you can ignore this message.";
  } else {
    edm::LogInfo("Alignment") <<"@SUB=AlignableNavigator" << "created with map of size "
                              << theMap.size() << ".";
  }
}

Member Function Documentation

std::vector< AlignableDetOrUnitPtr > AlignableNavigator::alignableDetOrUnits ( )

return all AlignableDetOrUnitPtrs

Definition at line 195 of file AlignableNavigator.cc.

References query::result, and theMap.

{
  std::vector<AlignableDetOrUnitPtr> result;
  result.reserve(theMap.size());

  for (MapType::const_iterator iIdAli = theMap.begin(); iIdAli != theMap.end(); ++iIdAli) {
    result.push_back(iIdAli->second);
  }

  return result;
}
AlignableDetOrUnitPtr AlignableNavigator::alignableFromDetId ( const DetId detid)
AlignableDetOrUnitPtr AlignableNavigator::alignableFromGeomDet ( const GeomDet geomDet)
std::vector< AlignableDetOrUnitPtr > AlignableNavigator::alignablesFromHits ( const TransientTrackingRecHit::ConstRecHitContainer hitVec)

Returns vector of AlignableDetOrUnitPtr for given vector of Hits.

Definition at line 180 of file AlignableNavigator.cc.

References query::result.

{

  std::vector<AlignableDetOrUnitPtr> result;
  result.reserve(hitVec.size());
  
  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it
         = hitVec.begin(), iEnd = hitVec.end(); it != iEnd; ++it) {
    result.push_back(this->alignableFromDetId((*it)->geographicalId()));
  }

  return result;
}
std::vector< AlignableDetOrUnitPtr > AlignableNavigator::alignablesFromHits ( const std::vector< const TransientTrackingRecHit * > &  hitvec)

Returns vector AlignableDetOrUnitPtr for given vector of Hits.

Definition at line 164 of file AlignableNavigator.cc.

References alignableFromDetId(), and query::result.

Referenced by SingleTrajectoryUpdator::process(), HIPAlignmentAlgorithm::run(), and MuonMillepedeAlgorithm::run().

{
  std::vector<AlignableDetOrUnitPtr> result;
  result.reserve(hitvec.size());

  for(std::vector<const TransientTrackingRecHit*>::const_iterator ih
        = hitvec.begin(), iEnd = hitvec.end(); ih != iEnd; ++ih) {
    result.push_back(this->alignableFromDetId((*ih)->geographicalId()));
  }

  return result;
}
bool AlignableNavigator::detAndSubdetInMap ( const DetId detid) const

Given a DetId, returns true if DetIds with this detector and subdetector id are in the map (not necessarily the exact DetId)

Definition at line 208 of file AlignableNavigator.cc.

References DetId::det(), i, DetId::subdetId(), and theDetAndSubdet.

Referenced by AlignmentMonitorTemplate::event(), AlignmentMonitorMuonResiduals::event(), recursiveGetId(), HIPAlignmentAlgorithm::run(), and MuonMillepedeAlgorithm::run().

{
   int det = detid.det();
   int subdet = detid.subdetId();
   for (std::vector<std::pair<int, int> >::const_iterator i = theDetAndSubdet.begin();  i != theDetAndSubdet.end();  ++i) {
      if (det == i->first  &&  subdet == i->second) return true;
   }
   return false;
}
unsigned int AlignableNavigator::recursiveGetId ( Alignable alignable) [private]

Add recursively DetId-AlignableDetOrUnitPtr pairs to map. Returns number of Alignables with DetId!=0 which are (illegaly) neither AlignableDet nor AlignableDetUnit and are thus not added to the map.

Definition at line 110 of file AlignableNavigator.cc.

References align::AlignableDet, Alignable::alignableObjectId(), Alignable::components(), detAndSubdetInMap(), Alignable::geomDetId(), theDetAndSubdet, and theMap.

Referenced by AlignableNavigator().

{
  // Recursive method to get the detIds of an alignable and its childs
  // and add them to the map.
  // Returns number of Alignables with DetId which are neither AlignableDet
  // nor AlignableDetUnit and are thus not added to the map.

  if (!alignable) return 0;

  unsigned int nProblem = 0;
  const DetId detId(alignable->geomDetId());
  if (detId.rawId()) {
    
    AlignableDet *aliDet;
    AlignableDetUnit *aliDetUnit;
    AlignableBeamSpot *aliBeamSpot;

    if ((aliDet = dynamic_cast<AlignableDet*>(alignable))) {
      
      theMap.insert( PairType( detId, aliDet ) );
    
    } else if ((aliDetUnit = dynamic_cast<AlignableDetUnit*>(alignable))) {

      theMap.insert( PairType( detId, aliDetUnit ) );

    } else if ((aliBeamSpot = dynamic_cast<AlignableBeamSpot*>(alignable))) {

      theMap.insert( PairType( detId, aliBeamSpot ) );

    } else {
      
      nProblem = 1; // equivalent to '++nProblem;' which could confuse to be ina loop...
      // Cannot be an exception since it happens (illegaly) in Muon DT hierarchy:
      //         throw cms::Exception("BadLogic") 
      //           << "[AlignableNavigator::recursiveGetId] Alignable with DetId " << detId.rawId() 
      //           << " neither AlignableDet nor AlignableDetUnit";
    }
    
    if (!nProblem && !this->detAndSubdetInMap(detId)) {
      theDetAndSubdet.push_back(std::pair<int, int>( detId.det(), detId.subdetId() ));
    }
  }
  std::vector<Alignable*> comp = alignable->components();
  if ( alignable->alignableObjectId() != align::AlignableDet
       || comp.size() > 1 ) { // Non-glued AlignableDets contain themselves
    for ( std::vector<Alignable*>::iterator it = comp.begin(); it != comp.end(); ++it ) {
      nProblem += this->recursiveGetId(*it);
    }
  }
  return nProblem;
}
int AlignableNavigator::size ( void  ) [inline]

Returns number of elements in map.

Definition at line 60 of file AlignableNavigator.h.

References theMap.

{ return theMap.size(); }

Member Data Documentation

std::vector<std::pair<int,int> > AlignableNavigator::theDetAndSubdet [private]

Definition at line 72 of file AlignableNavigator.h.

Referenced by detAndSubdetInMap(), and recursiveGetId().