CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompositeAlignmentDerivativesExtractor.cc
Go to the documentation of this file.
2 
7 
9 
10 //--------------------------------------------------------------------------------------
12 CompositeAlignmentDerivativesExtractor( const std::vector< Alignable* > & alignables,
13  const std::vector< AlignableDet* > & alignableDets,
14  const std::vector< TrajectoryStateOnSurface > & tsos )
15 {
16  std::vector<AlignableDetOrUnitPtr> detOrUnits;
17  detOrUnits.reserve(alignableDets.size());
18 
19  std::vector<AlignableDet*>::const_iterator it, itEnd;
20  for (it = alignableDets.begin(), itEnd = alignableDets.end(); it != itEnd; ++it)
21  detOrUnits.push_back(AlignableDetOrUnitPtr(*it));
22 
23  extractCurrentAlignment( alignables, detOrUnits, tsos );
24 }
25 
26 //--------------------------------------------------------------------------------------
28 CompositeAlignmentDerivativesExtractor( const std::vector< Alignable* > & alignables,
29  const std::vector< AlignableDetOrUnitPtr > & alignableDets,
30  const std::vector< TrajectoryStateOnSurface > & tsos )
31 {
32  extractCurrentAlignment( alignables, alignableDets, tsos );
33 }
34 
35 //--------------------------------------------------------------------------------------
36 
38 extractCurrentAlignment( const std::vector< Alignable* > & alignables,
39  const std::vector< AlignableDetOrUnitPtr > & alignableDets,
40  const std::vector< TrajectoryStateOnSurface > & tsos )
41 {
42 
43  // sanity check
44  if ( alignables.size() != alignableDets.size() )
45  {
46  edm::LogError("CompositeAlignmentDerivativesExtractor")
47  << "Inconsistent length of arguments: alignables=" << alignables.size()
48  << ", alignableDets=" << alignableDets.size();
49  return;
50  }
51 
52  if ( alignables.size() != tsos.size() )
53  {
54  edm::LogError("CompositeAlignmentDerivativesExtractor")
55  << "Inconsistent length of arguments: alignables=" << alignables.size()
56  << ", tsos=" << tsos.size();
57  return;
58  }
59 
60  std::vector< Alignable* >::const_iterator itAlignable = alignables.begin();
61  std::vector< AlignableDetOrUnitPtr >::const_iterator itAlignableDet = alignableDets.begin();
62  std::vector< TrajectoryStateOnSurface >::const_iterator itTsos = tsos.begin();
63 
64  int nRow = 0;
65  int nCollumn = 0;
66  unsigned int nAlignables = 0;
67 
68  std::vector< AlgebraicMatrix > subDerivatives;
69  std::vector< AlgebraicVector > subCorrectionTerm;
70 
71 
72  // get the individual derivatives and correction term and determine the dimension
73  while ( itAlignable != alignables.end() )
74  {
75  // Get the current estimate on the alignment parameters
76  AlgebraicVector subAlignmentParameters =
77  ( *itAlignable )->alignmentParameters()->selectedParameters();
78 
79  // Get the derivatives or the local coordinates w.r.t. the corresponding alignment parameters
80  AlgebraicMatrix subAlignmentDerivatives =
81  ( *itAlignable )->alignmentParameters()->selectedDerivatives( *itTsos, *itAlignableDet );
82 
83  subDerivatives.push_back( subAlignmentDerivatives.T() );
84  subCorrectionTerm.push_back( subAlignmentDerivatives.T()*subAlignmentParameters );
85 
86  nRow += 2;
87  // check if it is the first occurrence of this Alignable
88  if ( count( alignables.begin(), itAlignable, *itAlignable ) == 0 )
89  {
90  // matrix is transposed -> num_row() instead of num_col()
91  nCollumn += subAlignmentDerivatives.num_row();
92  nAlignables++;
93  }
94 
95  itAlignable++;
96  itAlignableDet++;
97  itTsos++;
98  }
99 
100  // construct derivatives and correction term with the right dimension
101  theDerivatives = AlgebraicMatrix( nRow, nCollumn, 0 );
102  theCorrectionTerm = AlgebraicVector( nRow, 0 );
103 
104  if ( alignables.size() == nAlignables )
105  // One hit per alignable
106  extractWithoutMultipleHits( subCorrectionTerm, subDerivatives );
107  else
108  // At least one alignable has two hits
109  extractWithMultipleHits( subCorrectionTerm, subDerivatives, alignables );
110 
111  return;
112 
113 }
114 
115 //--------------------------------------------------------------------------------------
116 
118 extractWithoutMultipleHits( const std::vector< AlgebraicVector > & subCorrectionTerm,
119  const std::vector< AlgebraicMatrix > & subDerivatives )
120 {
121  std::vector< AlgebraicVector >::const_iterator itSubCorrectionTerm = subCorrectionTerm.begin();
122  std::vector< AlgebraicMatrix >::const_iterator itSubDerivatives = subDerivatives.begin();
123 
124  int iRow = 1;
125  int iCollumn = 1;
126 
127  // Fill in the individual terms
128  while ( itSubCorrectionTerm != subCorrectionTerm.end() )
129  {
130  theCorrectionTerm.sub( iRow, *itSubCorrectionTerm );
131  theDerivatives.sub( iRow, iCollumn, *itSubDerivatives );
132 
133  iRow += 2;
134  iCollumn += ( *itSubDerivatives ).num_col();
135 
136  itSubCorrectionTerm++;
137  itSubDerivatives++;
138  }
139 
140  return;
141 }
142 
143 //--------------------------------------------------------------------------------------
144 
146 extractWithMultipleHits( const std::vector< AlgebraicVector > & subCorrectionTerm,
147  const std::vector< AlgebraicMatrix > & subDerivatives,
148  const std::vector< Alignable* > & alignables )
149 {
150 
151  std::vector< AlgebraicVector >::const_iterator itSubCorrectionTerm = subCorrectionTerm.begin();
152  std::vector< AlgebraicMatrix >::const_iterator itSubDerivatives = subDerivatives.begin();
153  std::vector< Alignable* >::const_iterator itAlignables = alignables.begin();
154  std::vector< Alignable* >::const_iterator itPosition;
155  std::vector< Alignable* >::const_iterator itLastPosition;
156 
157  int iRow = 1;
158 
159  // Fill in the individual terms
160  while ( itAlignables != alignables.end() )
161  {
162  theCorrectionTerm.sub( iRow, *itSubCorrectionTerm );
163 
164  int iCollumn = 1;
165  int iAlignable = 0;
166 
167  itLastPosition = find( alignables.begin(), itAlignables, *itAlignables );
168 
169  for ( itPosition = alignables.begin(); itPosition != itLastPosition; itPosition++ )
170  {
171  if ( count( alignables.begin(), itPosition, *itPosition ) == 0 )
172  iCollumn += subDerivatives[iAlignable].num_col();
173  iAlignable++;
174  }
175 
176  theDerivatives.sub( iRow, iCollumn, *itSubDerivatives );
177 
178  iRow += 2;
179 
180  itAlignables++;
181  itSubCorrectionTerm++;
182  itSubDerivatives++;
183  }
184 
185  return;
186 }
187 
void extractWithMultipleHits(const std::vector< AlgebraicVector > &subCorrectionTerm, const std::vector< AlgebraicMatrix > &subDerivatives, const std::vector< Alignable * > &alignables)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
CompositeAlignmentDerivativesExtractor(const std::vector< Alignable * > &alignables, const std::vector< AlignableDet * > &alignableDets, const std::vector< TrajectoryStateOnSurface > &tsos)
deprecated constructor for backward compatibility (use mor general AlignableDetOrUnitPtr) ...
CLHEP::HepMatrix AlgebraicMatrix
void extractCurrentAlignment(const std::vector< Alignable * > &alignables, const std::vector< AlignableDetOrUnitPtr > &alignableDets, const std::vector< TrajectoryStateOnSurface > &tsos)
void extractWithoutMultipleHits(const std::vector< AlgebraicVector > &subCorrectionTerm, const std::vector< AlgebraicMatrix > &subDerivatives)
CLHEP::HepVector AlgebraicVector