CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/Alignment/KalmanAlignmentAlgorithm/plugins/SimpleMetricsUpdator.cc

Go to the documentation of this file.
00001 //#include "Alignment/KalmanAlignmentAlgorithm/plugins/SimpleMetricsUpdator.h"
00002 #include "SimpleMetricsUpdator.h"
00003 
00004 #include "Alignment/KalmanAlignmentAlgorithm/interface/KalmanAlignmentMetricsUpdatorPlugin.h"
00005 #include "Alignment/CommonAlignment/interface/Alignable.h"
00006 
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 
00010 
00011 SimpleMetricsUpdator::SimpleMetricsUpdator( const edm::ParameterSet & config ) : 
00012   KalmanAlignmentMetricsUpdator( config ),
00013   theMinDeltaPerp(0.), theMaxDeltaPerp(0.), theMinDeltaZ(0.), theMaxDeltaZ(0.),
00014   theGeomDist(0.), theMetricalThreshold(0)
00015 {
00016   short int maxDistance = config.getUntrackedParameter< int >( "MaxMetricsDistance", 3 );
00017   theMetricsCalculator.setMaxDistance( maxDistance );
00018 
00019   std::vector< unsigned int > dummy;
00020   theExcludedSubdetIds = config.getUntrackedParameter< std::vector<unsigned int> >( "ExcludedSubdetIds", dummy );
00021 
00022   theASCFlag =  config.getUntrackedParameter< bool >( "ApplyAdditionalSelectionCriterion", false );
00023   if ( theASCFlag )
00024   {
00025     theMinDeltaPerp = config.getParameter< double >( "MinDeltaPerp" );
00026     theMaxDeltaPerp = config.getParameter< double >( "MaxDeltaPerp" );
00027     theMinDeltaZ = config.getParameter< double >( "MinDeltaZ" );
00028     theMaxDeltaZ = config.getParameter< double >( "MaxDeltaZ" );
00029     theGeomDist = config.getParameter< double >( "GeomDist" );
00030     theMetricalThreshold = config.getParameter< unsigned int >( "MetricalThreshold" );
00031   }
00032 
00033   edm::LogInfo("Alignment") << "@SUB=SimpleMetricsUpdator::SimpleMetricsUpdator "
00034                             << "\nInstance of MetricsCalculator created (MaxMetricsDistance = " << maxDistance << ").";
00035 }
00036 
00037 
00038 void SimpleMetricsUpdator::update( const std::vector< Alignable* > & alignables )
00039 {
00040   std::vector< Alignable* > alignablesForUpdate;
00041   std::vector< Alignable* >::const_iterator it;
00042 
00043   for ( it = alignables.begin(); it != alignables.end(); ++it )
00044   {
00045     unsigned int subdetId = static_cast< unsigned int >( (*it)->geomDetId().subdetId() );
00046 
00047     if ( std::find( theExcludedSubdetIds.begin(), theExcludedSubdetIds.end(), subdetId ) == theExcludedSubdetIds.end() )
00048     {
00049       alignablesForUpdate.push_back( *it );
00050     }
00051   }
00052 
00053   theMetricsCalculator.updateDistances( alignablesForUpdate );
00054 }
00055 
00056 
00057 const std::vector< Alignable* >
00058 SimpleMetricsUpdator::additionalAlignables( const std::vector< Alignable* > & alignables )
00059 {
00060   std::vector< Alignable* > result;
00061   std::vector< Alignable* >::const_iterator itAD;
00062 
00063   std::map< Alignable*, short int > updateList;
00064   std::map< Alignable*, short int >::iterator itUL;
00065 
00066   std::set< Alignable* > alignablesFromUpdateList;
00067   std::set< Alignable* >::iterator itAUL;
00068 
00069   // make union of all lists
00070   for ( itAD = alignables.begin(); itAD != alignables.end(); itAD++ )
00071   {
00072     updateList = theMetricsCalculator.getDistances( *itAD );
00073     for ( itUL = updateList.begin(); itUL != updateList.end(); itUL++ )
00074     {
00075       // extra selection criterion
00076       if ( theASCFlag && !additionalSelectionCriterion( *itAD, itUL->first, itUL->second ) ) continue;
00077 
00078       alignablesFromUpdateList.insert( itUL->first );
00079     }
00080     updateList.clear();
00081   }
00082 
00083   // make final list of modules for update
00084   for ( itAUL = alignablesFromUpdateList.begin(); itAUL != alignablesFromUpdateList.end(); itAUL++ )
00085   {
00086     if ( find( alignables.begin(), alignables.end(), *itAUL ) == alignables.end() )
00087     {
00088       result.push_back( *itAUL );
00089     }
00090   }
00091 
00092   return result;
00093 }
00094 
00095 
00096 const std::map< Alignable*, short int >
00097 SimpleMetricsUpdator::additionalAlignablesWithDistances( const std::vector< Alignable* > & alignables )
00098 {
00099   std::map< Alignable*, short int > result;
00100   std::map< Alignable*, short int > updateList;
00101   std::map< Alignable*, short int >::iterator itUL;
00102   std::map< Alignable*, short int >::iterator itFind;
00103 
00104   std::vector< Alignable* >::const_iterator itAD;
00105 
00106   // make union of all lists
00107   for ( itAD = alignables.begin(); itAD != alignables.end(); itAD++ )
00108   {
00109     updateList = theMetricsCalculator.getDistances( *itAD );
00110     for ( itUL = updateList.begin(); itUL != updateList.end(); itUL++ )
00111     {
00112       itFind = result.find( itUL->first );
00113       if ( itFind == result.end() )
00114       {
00115         result[itUL->first] = itUL->second;
00116       }
00117       else if ( itFind->second < itUL->second )
00118       {
00119         itFind->second = itUL->second;
00120       }
00121     }
00122   }
00123 
00124   for ( itAD = alignables.begin(); itAD != alignables.end(); itAD++ )
00125   {
00126     itFind = result.find( *itAD );
00127     if ( itFind != result.end() ) result.erase( itFind );
00128   }
00129 
00130   return result;
00131 }
00132 
00133 
00134 bool
00135 SimpleMetricsUpdator::additionalSelectionCriterion( Alignable* const& referenceAli,
00136                                                     Alignable* const& additionalAli,
00137                                                     short int metricalDist ) const
00138 {
00139   if ( metricalDist <= theMetricalThreshold ) return true;
00140 
00141   const DetId detId( referenceAli->geomDetId() );
00142 
00143   const align::PositionType& pos1 = referenceAli->globalPosition(); 
00144   const align::PositionType& pos2 = additionalAli->globalPosition(); 
00145 
00146   bool barrelRegion = ( detId.subdetId()%2 != 0 );
00147 
00148   if ( barrelRegion )
00149   {
00150     double perp1 = pos1.perp();
00151     double perp2 = pos2.perp();
00152     double deltaPerp = perp2 - perp1;
00153 
00154     if ( ( deltaPerp < theMinDeltaPerp ) || ( deltaPerp > theMaxDeltaPerp ) ) return false;
00155   }
00156   else
00157   {
00158     double z1 = pos1.z();
00159     double z2 = pos2.z();
00160     double signZ = ( z1 > 0. ) ? 1. : -1;
00161     double deltaZ = signZ*( z2 - z1 );
00162 
00163     if ( ( deltaZ < theMinDeltaZ ) || ( deltaZ > theMaxDeltaZ ) ) return false;
00164   }
00165 
00166   double r1 = pos1.mag();
00167   double r2 = pos2.mag();
00168   double sp = pos1.x()*pos2.x() + pos1.y()*pos2.y() + pos1.z()*pos2.z();
00169 
00170   double dist = sqrt( r2*r2 - sp*sp/r1/r1 );
00171   return ( dist < theGeomDist );
00172 }
00173 
00174 
00175 DEFINE_EDM_PLUGIN( KalmanAlignmentMetricsUpdatorPlugin, SimpleMetricsUpdator, "SimpleMetricsUpdator" );