CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimpleMetricsUpdator.cc
Go to the documentation of this file.
1 //#include "Alignment/KalmanAlignmentAlgorithm/plugins/SimpleMetricsUpdator.h"
2 #include "SimpleMetricsUpdator.h"
3 
6 
8 
9 
10 
13  theMinDeltaPerp(0.), theMaxDeltaPerp(0.), theMinDeltaZ(0.), theMaxDeltaZ(0.),
14  theGeomDist(0.), theMetricalThreshold(0)
15 {
16  short int maxDistance = config.getUntrackedParameter< int >( "MaxMetricsDistance", 3 );
17  theMetricsCalculator.setMaxDistance( maxDistance );
18 
19  std::vector< unsigned int > dummy;
20  theExcludedSubdetIds = config.getUntrackedParameter< std::vector<unsigned int> >( "ExcludedSubdetIds", dummy );
21 
22  theASCFlag = config.getUntrackedParameter< bool >( "ApplyAdditionalSelectionCriterion", false );
23  if ( theASCFlag )
24  {
25  theMinDeltaPerp = config.getParameter< double >( "MinDeltaPerp" );
26  theMaxDeltaPerp = config.getParameter< double >( "MaxDeltaPerp" );
27  theMinDeltaZ = config.getParameter< double >( "MinDeltaZ" );
28  theMaxDeltaZ = config.getParameter< double >( "MaxDeltaZ" );
29  theGeomDist = config.getParameter< double >( "GeomDist" );
30  theMetricalThreshold = config.getParameter< unsigned int >( "MetricalThreshold" );
31  }
32 
33  edm::LogInfo("Alignment") << "@SUB=SimpleMetricsUpdator::SimpleMetricsUpdator "
34  << "\nInstance of MetricsCalculator created (MaxMetricsDistance = " << maxDistance << ").";
35 }
36 
37 
38 void SimpleMetricsUpdator::update( const std::vector< Alignable* > & alignables )
39 {
40  std::vector< Alignable* > alignablesForUpdate;
41  std::vector< Alignable* >::const_iterator it;
42 
43  for ( it = alignables.begin(); it != alignables.end(); ++it )
44  {
45  unsigned int subdetId = static_cast< unsigned int >( (*it)->geomDetId().subdetId() );
46 
47  if ( std::find( theExcludedSubdetIds.begin(), theExcludedSubdetIds.end(), subdetId ) == theExcludedSubdetIds.end() )
48  {
49  alignablesForUpdate.push_back( *it );
50  }
51  }
52 
53  theMetricsCalculator.updateDistances( alignablesForUpdate );
54 }
55 
56 
57 const std::vector< Alignable* >
58 SimpleMetricsUpdator::additionalAlignables( const std::vector< Alignable* > & alignables )
59 {
60  std::vector< Alignable* > result;
61  std::vector< Alignable* >::const_iterator itAD;
62 
63  std::map< Alignable*, short int > updateList;
64  std::map< Alignable*, short int >::iterator itUL;
65 
66  std::set< Alignable* > alignablesFromUpdateList;
67  std::set< Alignable* >::iterator itAUL;
68 
69  // make union of all lists
70  for ( itAD = alignables.begin(); itAD != alignables.end(); itAD++ )
71  {
72  updateList = theMetricsCalculator.getDistances( *itAD );
73  for ( itUL = updateList.begin(); itUL != updateList.end(); itUL++ )
74  {
75  // extra selection criterion
76  if ( theASCFlag && !additionalSelectionCriterion( *itAD, itUL->first, itUL->second ) ) continue;
77 
78  alignablesFromUpdateList.insert( itUL->first );
79  }
80  updateList.clear();
81  }
82 
83  // make final list of modules for update
84  for ( itAUL = alignablesFromUpdateList.begin(); itAUL != alignablesFromUpdateList.end(); itAUL++ )
85  {
86  if ( find( alignables.begin(), alignables.end(), *itAUL ) == alignables.end() )
87  {
88  result.push_back( *itAUL );
89  }
90  }
91 
92  return result;
93 }
94 
95 
96 const std::map< Alignable*, short int >
97 SimpleMetricsUpdator::additionalAlignablesWithDistances( const std::vector< Alignable* > & alignables )
98 {
99  std::map< Alignable*, short int > result;
100  std::map< Alignable*, short int > updateList;
101  std::map< Alignable*, short int >::iterator itUL;
102  std::map< Alignable*, short int >::iterator itFind;
103 
104  std::vector< Alignable* >::const_iterator itAD;
105 
106  // make union of all lists
107  for ( itAD = alignables.begin(); itAD != alignables.end(); itAD++ )
108  {
109  updateList = theMetricsCalculator.getDistances( *itAD );
110  for ( itUL = updateList.begin(); itUL != updateList.end(); itUL++ )
111  {
112  itFind = result.find( itUL->first );
113  if ( itFind == result.end() )
114  {
115  result[itUL->first] = itUL->second;
116  }
117  else if ( itFind->second < itUL->second )
118  {
119  itFind->second = itUL->second;
120  }
121  }
122  }
123 
124  for ( itAD = alignables.begin(); itAD != alignables.end(); itAD++ )
125  {
126  itFind = result.find( *itAD );
127  if ( itFind != result.end() ) result.erase( itFind );
128  }
129 
130  return result;
131 }
132 
133 
134 bool
136  Alignable* const& additionalAli,
137  short int metricalDist ) const
138 {
139  if ( metricalDist <= theMetricalThreshold ) return true;
140 
141  const DetId detId( referenceAli->geomDetId() );
142 
143  const align::PositionType& pos1 = referenceAli->globalPosition();
144  const align::PositionType& pos2 = additionalAli->globalPosition();
145 
146  bool barrelRegion = ( detId.subdetId()%2 != 0 );
147 
148  if ( barrelRegion )
149  {
150  double perp1 = pos1.perp();
151  double perp2 = pos2.perp();
152  double deltaPerp = perp2 - perp1;
153 
154  if ( ( deltaPerp < theMinDeltaPerp ) || ( deltaPerp > theMaxDeltaPerp ) ) return false;
155  }
156  else
157  {
158  double z1 = pos1.z();
159  double z2 = pos2.z();
160  double signZ = ( z1 > 0. ) ? 1. : -1;
161  double deltaZ = signZ*( z2 - z1 );
162 
163  if ( ( deltaZ < theMinDeltaZ ) || ( deltaZ > theMaxDeltaZ ) ) return false;
164  }
165 
166  double r1 = pos1.mag();
167  double r2 = pos2.mag();
168  double sp = pos1.x()*pos2.x() + pos1.y()*pos2.y() + pos1.z()*pos2.z();
169 
170  double dist = sqrt( r2*r2 - sp*sp/r1/r1 );
171  return ( dist < theGeomDist );
172 }
173 
174 
virtual const std::map< Alignable *, short int > additionalAlignablesWithDistances(const std::vector< Alignable * > &alignables)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
T perp() const
Definition: PV3DBase.h:71
void setMaxDistance(short int maxDistance)
Set maximum distance to be stored.
virtual void update(const std::vector< Alignable * > &alignables)
T y() const
Definition: PV3DBase.h:62
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
T mag() const
Definition: PV3DBase.h:66
SimpleMetricsUpdator(const edm::ParameterSet &config)
T sqrt(T t)
Definition: SSEVec.h:46
T z() const
Definition: PV3DBase.h:63
tuple result
Definition: query.py:137
virtual const std::vector< Alignable * > additionalAlignables(const std::vector< Alignable * > &alignables)
bool additionalSelectionCriterion(Alignable *const &referenceAli, Alignable *const &additionalAli, short int metricalDist) const
Definition: DetId.h:20
std::vector< unsigned int > theExcludedSubdetIds
T perp2() const
Squared magnitude of transverse component.
void updateDistances(const std::vector< Alignable * > &alignables)
Update list of distances with a set Alignables.
KalmanAlignmentMetricsCalculator theMetricsCalculator
const SingleDistancesList & getDistances(Alignable *i) const
#define DEFINE_EDM_PLUGIN(factory, type, name)
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:129
T x() const
Definition: PV3DBase.h:61
const DetId & geomDetId() const
Definition: Alignable.h:177