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