CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
HouseholderDecomposition Class Reference

#include <HouseholderDecomposition.h>

Public Member Functions

 HouseholderDecomposition (int squareMode_=5, int mineta_=1, int maxeta_=85, int minphi_=1, int maxphi_=20)
 Default constructor. More...
 
int indexSqr2Reg (const int &sqrIndex, const int &maxCeta, const int &maxCphi)
 Method to translate from square indices to region indices. More...
 
std::vector< float > iterate (const std::vector< std::vector< float > > &eventMatrix, const std::vector< int > &VmaxCeta, const std::vector< int > &VmaxCphi, const std::vector< float > &energyVector, const int &nIter, const bool &normalizeFlag=false)
 
std::vector< float > iterate (const std::vector< std::vector< float > > &eventMatrix, const std::vector< int > &VmaxCeta, const std::vector< int > &VmaxCphi, const std::vector< float > &energyVectorOrig)
 Run the Householder Algorithm. Returns the vector of calibration coefficients. More...
 
std::vector< float > recalibrateEvent (const std::vector< float > &eventSquare, const int &maxCeta, const int &maxCphi, const std::vector< float > &recalibrateVector)
 Recalibrate before next iteration: give previous solution vector as argument. More...
 
std::vector< float > runRegional (const std::vector< std::vector< float > > &eventMatrix, const std::vector< int > &VmaxCeta, const std::vector< int > &VmaxCphi, const std::vector< float > &energyVector, const int &nIter, const int &regLength=5)
 
 ~HouseholderDecomposition ()
 Destructor. More...
 

Private Member Functions

bool decompose ()
 
void makeRegions (const int &regLength)
 
void solve (std::vector< float > &y)
 
std::vector< std::vector< float > > unzipMatrix (const std::vector< std::vector< float > > &eventMatrix, const std::vector< int > &VmaxCeta, const std::vector< int > &VmaxCphi)
 Unzips the skimmed matrix into a full matrix. More...
 

Private Attributes

std::vector< float > alpha
 
int countEvents
 
std::vector< float > energyVectorProc
 
std::vector< std::vector< float > > eventMatrixOrig
 
std::vector< std::vector< float > > eventMatrixProc
 
int maxeta
 
int maxphi
 
int mineta
 
int minphi
 
int Nchannels
 
int Neta
 
int Nevents
 
int Nphi
 
int Nxtals
 
std::vector< int > pivot
 
std::vector< int > regMaxEta
 
std::vector< int > regMaxPhi
 
std::vector< int > regMinEta
 
std::vector< int > regMinPhi
 
float sigmaReplacement
 
int squareMode
 

Detailed Description

Implementation of the QR decomposition of a matrix using Householder transformation

13.03.2007: R.Ofierzynski

Date:
2010/08/06 20:24:06
Revision:
1.4
Author
Lorenzo Agostino, R.Ofierzynski, CERN

Definition at line 19 of file HouseholderDecomposition.h.

Constructor & Destructor Documentation

HouseholderDecomposition::HouseholderDecomposition ( int  squareMode_ = 5,
int  mineta_ = 1,
int  maxeta_ = 85,
int  minphi_ = 1,
int  maxphi_ = 20 
)

Default constructor.

Definition at line 14 of file HouseholderDecomposition.cc.

References maxeta, maxphi, mineta, minphi, Nchannels, Neta, Nphi, Nxtals, sigmaReplacement, and squareMode.

15  :squareMode(squareMode_), countEvents(0),mineta(mineta_), maxeta(maxeta_), minphi(minphi_), maxphi(maxphi_)
16 {
17  Neta = maxeta - mineta + 1;
18  if (mineta * maxeta < 0) Neta--; // there's no eta index = 0
19  Nphi = maxphi - minphi + 1;
20  if (Nphi <0) Nphi += 360;
21 
22  Nchannels = Neta * Nphi; // no. of channels, get it from edges of the region
23 
24  Nxtals = squareMode*squareMode; // no. of xtals in one event
25 
26  sigmaReplacement = 0.00001; // the sum of columns is replaced by this value in case it is zero (e.g. dead crystal)
27 
28 }
HouseholderDecomposition::~HouseholderDecomposition ( )

Destructor.

Definition at line 30 of file HouseholderDecomposition.cc.

31 {
32 }

Member Function Documentation

bool HouseholderDecomposition::decompose ( )
private

Make decomposition input: m=number of events, n=number of channels, qr=event matrix output: qr = transformed event matrix, alpha, pivot returns a boolean value, true if decomposition worked, false if it didn't

Definition at line 347 of file HouseholderDecomposition.cc.

References alpha, beta, eventMatrixProc, i, j, gen::k, Nchannels, Nevents, pivot, sigmaReplacement, mathSSE::sqrt(), and detailsBasic3DVector::y.

Referenced by iterate().

348 {
349  int i,j,jbar,k;
350  float beta,sigma,alphak,eventMatrixkk;
351  std::vector<float> y(Nchannels);
352  std::vector<float> sum(Nchannels);
353 
354  // std::cout << "Householder::decompose() started" << std::endl;
355 
356  for (j=0;j<Nchannels;j++)
357  {
358  // jth column sum: squared sum for each crystal
359  sum[j]=0.;
360  for (i=0;i<Nevents;i++)
361  sum[j]+=eventMatrixProc[i][j]*eventMatrixProc[i][j];
362 
363  // bookkeeping vector
364  pivot[j] = j;
365  }
366 
367  for (k=0;k<Nchannels;k++)
368  {
369  // kth Householder transformation
370  sigma = sum[k];
371  jbar = k;
372 
373  // go through all following columns
374  // find the largest sumSquared in the following columns
375  for (j=k+1;j<Nchannels;j++)
376  {
377  if (sum[j] > sigma)
378  {
379  sigma = sum[j];
380  jbar=j;
381  }
382  }
383 
384  if (jbar != k)
385  {
386  // column interchange:
387  // interchange within: bookkeeping vector, squaredSum, eventMatrixProc
388 
389  i = pivot[k];
390  pivot[k]=pivot[jbar];
391  pivot[jbar]=i;
392 
393  sum[jbar]=sum[k];
394  sum[k]=sigma;
395 
396  for (i=0;i<Nevents;i++)
397  {
398  sigma=eventMatrixProc[i][k];
400  eventMatrixProc[i][jbar]=sigma;
401  }
402  } // end column interchange
403 
404  // now store in sigma the squared sum of the readoutEnergies for this column(crystal)
405  sigma=0.;
406  for (i=k;i<Nevents;i++)
407  {
408  sigma+=eventMatrixProc[i][k]*eventMatrixProc[i][k];
409  }
410 
411  // found a zero-column, bail out
412  if (sigma == 0.)
413  {
414 // std::cout << "Householder::decompose() failed" << std::endl;
415 // return false;
416  // rof 14.12.2006: workaround to avoid failure of algorithm because of dead crystals:
417  sigma = sigmaReplacement;
418  // std::cout << "Householder::decompose - found zero column " << jbar << ", replacing sum of column elements by " << sigma << std::endl;
419  }
420 
421 
422  // the following paragraph acts only on the diagonal element:
423  // if element=0, then calculate alpha & beta
424 
425  // take the diagonal element
426  eventMatrixkk = eventMatrixProc[k][k];
427 
428  if (eventMatrixkk < 0.)
429  alpha[k] = sqrt(sigma);
430  else
431  alpha[k] = sqrt(sigma) * (-1.);
432 
433  alphak = alpha[k];
434 
435  beta = 1 / (sigma - eventMatrixkk * alphak);
436  // replace it
437  eventMatrixProc[k][k] = eventMatrixkk - alphak;
438 
439  for (j=k+1; j<Nchannels; j++)
440  {
441  y[j] = 0.;
442 
443  for (i=k; i<Nevents; i++)
444  {
445  y[j] += eventMatrixProc[i][k] * eventMatrixProc[i][j];
446  }
447 
448  y[j] *= beta;
449  }
450 
451  for (j=k+1; j<Nchannels; j++)
452  {
453  for (i=k; i<Nevents; i++)
454  {
455  eventMatrixProc[i][j] -= eventMatrixProc[i][k] * y[j];
456  sum[j] -= eventMatrixProc[k][j] * eventMatrixProc[k][j];
457  }
458  }
459  } // end of kth householder transformation
460 
461  // std::cout << "Householder::decompose() finished" << std::endl;
462 
463  return true;
464 }
const double beta
int i
Definition: DBlmapReader.cc:9
T sqrt(T t)
Definition: SSEVec.h:46
std::vector< std::vector< float > > eventMatrixProc
int j
Definition: DBlmapReader.cc:9
int k[5][pyjets_maxn]
int HouseholderDecomposition::indexSqr2Reg ( const int &  sqrIndex,
const int &  maxCeta,
const int &  maxCphi 
)

Method to translate from square indices to region indices.

Definition at line 529 of file HouseholderDecomposition.cc.

References maxeta, maxphi, mineta, minphi, and squareMode.

Referenced by recalibrateEvent(), runRegional(), and unzipMatrix().

530 {
531  int regionIndex;
532 
533  // get the current eta, phi indices
534  int curr_eta = maxCeta - squareMode/2 + sqrIndex%squareMode;
535  if (curr_eta * maxCeta <= 0) {if (maxCeta > 0) curr_eta--; else curr_eta++; } // JUMP over 0
536 
537  int curr_phi = maxCphi - squareMode/2 + sqrIndex/squareMode;
538  if (curr_phi < 1) curr_phi += 360;
539  if (curr_phi > 360) curr_phi -= 360;
540 
541  bool negPhiDirection = (maxphi < minphi);
542  int iFullphi;
543 
544  regionIndex = -1;
545 
546  if (curr_eta >= mineta && curr_eta <= maxeta)
547  if ( (!negPhiDirection && (curr_phi >= minphi && curr_phi <= maxphi)) ||
548  (negPhiDirection && !(curr_phi >= minphi && curr_phi <= maxphi)) )
549  {
550  iFullphi = curr_phi - minphi;
551  if (iFullphi < 0) iFullphi += 360;
552  regionIndex = (curr_eta - mineta) * (maxphi - minphi + 1 + 360*negPhiDirection) + iFullphi;
553  }
554 
555  return regionIndex;
556 }
std::vector< float > HouseholderDecomposition::iterate ( const std::vector< std::vector< float > > &  eventMatrix,
const std::vector< int > &  VmaxCeta,
const std::vector< int > &  VmaxCphi,
const std::vector< float > &  energyVector,
const int &  nIter,
const bool &  normalizeFlag = false 
)

Run the Householder Algorithm several times (nIter). Returns the final vector of calibration coefficients. Comment from author: unless you do a new selection in between the iterations you don't need to run more than once; a second iteration on the same events does not improve the result in this case

Definition at line 134 of file HouseholderDecomposition.cc.

References i, j, Nchannels, Nevents, Nxtals, recalibrateEvent(), and pileupReCalc_HLTpaths::scale.

Referenced by ElectronCalibration::endJob(), ElectronCalibrationUniv::endJob(), and runRegional().

135 {
136  Nevents = eventMatrix.size(); // Number of events to calibrate with
137 
138  std::vector<float> totalSolution(Nchannels,1.);
139  std::vector<float> iterSolution;
140  std::vector<std::vector<float> > myEventMatrix(eventMatrix);
141  std::vector<float> myEnergyVector(energyVector);
142 
143  int i, j;
144 
145  // Iterate the correction
146  for (int iter=1;iter<=nIter;iter++)
147  {
148 
149  // if normalization flag is set, normalize energies
150  float sumOverEnergy;
151  if (normalizeFlag)
152  {
153  float scale = 0.;
154 
155  for (i=0; i<Nevents; i++)
156  {
157  sumOverEnergy = 0.;
158  for (j=0; j<Nxtals; j++) {sumOverEnergy += myEventMatrix[i][j];}
159  sumOverEnergy /= myEnergyVector[i];
160  scale += sumOverEnergy;
161  }
162  scale /= Nevents;
163 
164  for (i=0; i<Nevents; i++) {myEnergyVector[i] *= scale;}
165  } // end normalize energies
166 
167 
168 
169  // now the real work starts:
170  iterSolution = iterate(myEventMatrix,VmaxCeta,VmaxCphi,myEnergyVector);
171 
172  if (iterSolution.empty()) return iterSolution;
173 
174  // re-calibrate eventMatrix with solution
175  for (int ievent = 0; ievent<Nevents; ievent++)
176  {
177  myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
178  }
179 
180  for (int i=0; i<Nchannels; i++)
181  {
182  // save solution into theCalibVector
183  totalSolution[i] *= iterSolution[i];
184  }
185 
186  } // end iterate correction
187 
188  return totalSolution;
189 }
int i
Definition: DBlmapReader.cc:9
std::vector< float > recalibrateEvent(const std::vector< float > &eventSquare, const int &maxCeta, const int &maxCphi, const std::vector< float > &recalibrateVector)
Recalibrate before next iteration: give previous solution vector as argument.
std::vector< float > iterate(const std::vector< std::vector< float > > &eventMatrix, const std::vector< int > &VmaxCeta, const std::vector< int > &VmaxCphi, const std::vector< float > &energyVector, const int &nIter, const bool &normalizeFlag=false)
int j
Definition: DBlmapReader.cc:9
std::vector< float > HouseholderDecomposition::iterate ( const std::vector< std::vector< float > > &  eventMatrix,
const std::vector< int > &  VmaxCeta,
const std::vector< int > &  VmaxCphi,
const std::vector< float > &  energyVectorOrig 
)

Run the Householder Algorithm. Returns the vector of calibration coefficients.

Definition at line 193 of file HouseholderDecomposition.cc.

References alpha, gather_cfg::cout, decompose(), alignCSCRings::e, energyVectorProc, eventMatrixOrig, eventMatrixProc, i, j, Nchannels, Nevents, pivot, solve(), and unzipMatrix().

194 {
195  std::vector<float> solution;
196 
197  Nevents=eventMatrix.size(); // Number of events to calibrate with
198 
199  if (Nchannels > Nevents)
200  {
201  std::cout << "Householder::runIter(): more channels to calibrate than events available. " << std::endl;
202  std::cout << " Nchannels=" << Nchannels << std::endl;
203  std::cout << " Nevents=" << Nevents << std::endl;
204  std::cout << " ****************** ERROR *********************" << std::endl;
205  return solution; // empty vector
206  }
207 
208  // input: eventMatrixOrig - the unzipped matrix
209  eventMatrixOrig = unzipMatrix(eventMatrix,VmaxCeta,VmaxCphi);
210 
211  if (eventMatrixOrig.size() != energyVectorOrig.size())
212  {
213  std::cout << "Householder::runIter(): matrix dimensions non-conformant. " << std::endl;
214  std::cout << " energyVectorOrig.size()=" << energyVectorOrig.size() << std::endl;
215  std::cout << " eventMatrixOrig.size()=" << eventMatrixOrig.size() << std::endl;
216  std::cout << " ****************** ERROR *********************" << std::endl;
217  return solution; // empty vector
218  }
219 
220 
221  int i,j;
223  energyVectorProc = energyVectorOrig; // copy energyVectorOrig vector
224  std::vector<float> e(Nchannels);
225  alpha.assign(Nchannels,0.);
226  pivot.assign(Nchannels,0);
227 
228 
229  //--------------------
230  bool decomposeSuccess = decompose();
231 
232  if( !decomposeSuccess )
233  {
234  std::cout << "Householder::runIter(): Failed: Singular condition in decomposition."<< std::endl;
235  std::cout << "***************** PROBLEM in DECOMPOSITION *************************"<<std::endl;
236  return solution; // empty vector
237  }
238 
239  /* DBL_EPSILON: Difference between 1.0 and the minimum float greater than 1.0 */
240  float mydbleps = 2.22045e-16; //DBL_EPSILON;
241  float etasqr = mydbleps*mydbleps;
242  // std::cout << "LOOK at DBL_EPSILON :" << mydbleps <<std::endl;
243 
244 
245  //--------------------
246  // apply transformations to rhs - find solution vector
247  solution.assign(Nchannels,0.);
248  solve(solution);
249 
250 
251  // compute residual vector energyVectorProc
252  for (i=0;i<Nevents;i++)
253  {
254  energyVectorProc[i] = energyVectorOrig[i];
255  for (j=0; j<Nchannels; j++)
256  {
257  energyVectorProc[i]-=eventMatrixOrig[i][j]*solution[j];
258  }
259  }
260 
261 
262  //--------------------
263  // compute first correction vector e
264  solve(e);
265 
266  float normy0=0.;
267  float norme1=0.;
268  float norme0;
269 
270 
271 
272 
273  for (i=0;i<Nchannels;i++)
274  {
275  normy0 += solution[i] * solution[i];
276  norme1 += e[i] * e[i];
277  }
278 
279 // std::cout << "Householder::runIter(): applying first correction";
280 // std::cout << " normy0 = " << normy0;
281 // std::cout << " norme1 = " << norme1 << std::endl;
282 
283  // not attempt at obtaining the solution is made unless the norm of the first
284  // correction is significantly smaller than the norm of the initial solution
285  if (norme1>(0.0625*normy0))
286  {
287  // std::cout << "Householder::runIter(): first correction is too large. Failed." << std::endl;
288  }
289 
290  // improve the solution
291  for (i=0; i<Nchannels; i++)
292  {
293  solution[i]+=e[i];
294  }
295 
296  // std::cout << "Householder::runIter(): improving solution...." << std::endl;
297 
298  //--------------------
299  // only continue iteration if the correction was significant
300  while (norme1>(etasqr*normy0))
301  {
302  // std::cout << "Householder::runIter(): norme1 = " << norme1 << std::endl;
303 
304  for (i=0; i<Nevents; i++)
305  {
306  energyVectorProc[i] = energyVectorOrig[i];
307  for (j=0; j<Nchannels; j++)
308  {
309  energyVectorProc[i] -= eventMatrixOrig[i][j] * solution[j];
310  }
311  }
312 
313  // compute next correction vector
314  solve(e);
315 
316  norme0 = norme1;
317  norme1 = 0.;
318 
319  for (i=0;i<Nchannels;i++)
320  {
321  norme1+=e[i]*e[i];
322  }
323 
324  // terminate iteration if the norm of the new correction failed to decrease
325  // significantly compared to the norm of the previous correction
326  if (norme1>(0.0625*norme0)) break;
327 
328  // apply correction vector
329  for (i=0;i<Nchannels;i++)
330  {
331  solution[i]+=e[i];
332  }
333  }
334 
335  //clean up
336  eventMatrixOrig.clear();
337  eventMatrixProc.clear();
338  energyVectorProc.clear();
339  alpha.clear();
340  pivot.clear();
341 
342 
343  return solution;
344 }
int i
Definition: DBlmapReader.cc:9
void solve(std::vector< float > &y)
std::vector< std::vector< float > > eventMatrixProc
int j
Definition: DBlmapReader.cc:9
std::vector< std::vector< float > > eventMatrixOrig
std::vector< float > energyVectorProc
std::vector< std::vector< float > > unzipMatrix(const std::vector< std::vector< float > > &eventMatrix, const std::vector< int > &VmaxCeta, const std::vector< int > &VmaxCphi)
Unzips the skimmed matrix into a full matrix.
tuple cout
Definition: gather_cfg.py:121
void HouseholderDecomposition::makeRegions ( const int &  regLength)
private

Determines the regions used for splitting of the full matrix and calibrating separately used by the public runRegional method

Definition at line 579 of file HouseholderDecomposition.cc.

References abs, i, j, mineta, minphi, Neta, Nphi, regMaxEta, regMaxPhi, regMinEta, regMinPhi, and squareMode.

Referenced by runRegional().

580 {
581  // int regFrame = regLength/2;
582  int regFrame = squareMode/2;
583  // first eta:
584  int remEta = Neta % regLength;
585  if (remEta > regLength/2) remEta -= regLength;
586  int numSubRegEta = Neta / regLength + (remEta < 0)*1;
587 
588  int addtoEta = remEta / numSubRegEta;
589  int addtomoreEta = remEta % numSubRegEta; // add "addtomore" number of times (addto+1), remaining times add just (addto)
590 
591  // then phi:
592  int remPhi = Nphi % regLength;
593  if (remPhi > regLength/2) remPhi -= regLength;
594  int numSubRegPhi = Nphi / regLength + (remPhi < 0)*1;
595 
596  int addtoPhi = remPhi / numSubRegPhi;
597  int addtomorePhi = remPhi % numSubRegPhi; // add "addtomore" number of times (addto+-1), remaining times add just (addto)
598 
599  // now put it all together
600  int addedLengthEta = 0;
601  int addedLengthPhi = 0;
602  int startIndexEta = mineta;
603  int startIndexPhi;
604  int endIndexEta = 0;
605  int endIndexPhi;
606  for (int i=0; i < numSubRegEta; i++)
607  {
608  addedLengthEta = regLength + addtoEta + addtomoreEta/abs(addtomoreEta)*(i<abs(addtomoreEta));
609  endIndexEta = startIndexEta + addedLengthEta - 1;
610 
611  startIndexPhi = minphi;
612  endIndexPhi = 0;
613  for (int j=0; j < numSubRegPhi; j++)
614  {
615  addedLengthPhi = regLength + addtoPhi + addtomorePhi/abs(addtomorePhi)*(j<abs(addtomorePhi));
616  endIndexPhi = startIndexPhi + addedLengthPhi - 1;
617 
618  regMinPhi.push_back(startIndexPhi - regFrame*(j!=0) );
619  regMaxPhi.push_back(endIndexPhi + regFrame*(j!=(numSubRegPhi-1)) );
620  regMinEta.push_back(startIndexEta - regFrame*(i!=0) );
621  regMaxEta.push_back(endIndexEta + regFrame*(i!=(numSubRegEta-1)) );
622 
623  startIndexPhi = endIndexPhi + 1;
624  }
625  startIndexEta = endIndexEta + 1;
626  }
627 
628 // // print it all
629 // std::cout << "Householder::makeRegions created the following regions for calibration:" << std::endl;
630 // for (int i=0; i<regMinEta.size(); i++)
631 // std::cout << "Region " << i << ": eta = " << regMinEta[i] << " to " << regMaxEta[i] << ", phi = " << regMinPhi[i] << " to " << regMaxPhi[i] << std::endl;
632 
633 }
int i
Definition: DBlmapReader.cc:9
#define abs(x)
Definition: mlp_lapack.h:159
int j
Definition: DBlmapReader.cc:9
std::vector< float > HouseholderDecomposition::recalibrateEvent ( const std::vector< float > &  eventSquare,
const int &  maxCeta,
const int &  maxCphi,
const std::vector< float > &  recalibrateVector 
)

Recalibrate before next iteration: give previous solution vector as argument.

Definition at line 514 of file HouseholderDecomposition.cc.

References i, indexSqr2Reg(), and Nxtals.

Referenced by iterate(), and runRegional().

515 {
516  std::vector<float> newEventSquare(eventSquare);
517  int iFull;
518 
519  for (int i=0; i<Nxtals; i++)
520  {
521  iFull = indexSqr2Reg(i, maxCeta, maxCphi);
522  if (iFull >=0)
523  newEventSquare[i] *= recalibrateVector[iFull];
524  }
525  return newEventSquare;
526 }
int i
Definition: DBlmapReader.cc:9
int indexSqr2Reg(const int &sqrIndex, const int &maxCeta, const int &maxCphi)
Method to translate from square indices to region indices.
std::vector< float > HouseholderDecomposition::runRegional ( const std::vector< std::vector< float > > &  eventMatrix,
const std::vector< int > &  VmaxCeta,
const std::vector< int > &  VmaxCphi,
const std::vector< float > &  energyVector,
const int &  nIter,
const int &  regLength = 5 
)

Run Regional HouseholderAlgorithm (fast version), that splits matrix into regional matrices and inverts them separately. Returns the final vector of calibration coefficients. input: eventMatrix - the skimmed event matrix, VmaxCeta, VmaxCphi - vectors containing eta and phi indices of the maximum containment crystal for each event, energyVector - the energy vector, nIter - number of iterations to be performed, regLength - default length of the region (in eta- and phi-indices), regLength=5 recommended Comment from author: if you use the same events, 2 iterations are recommended; the second iteration gives corrections of the order of 0.0001

Definition at line 35 of file HouseholderDecomposition.cc.

References i, indexSqr2Reg(), iterate(), makeRegions(), maxeta, maxphi, mineta, minphi, Nchannels, Nevents, Nphi, Nxtals, recalibrateEvent(), regMaxEta, regMaxPhi, regMinEta, regMinPhi, and squareMode.

Referenced by ElectronCalibration::endJob(), and ElectronCalibrationUniv::endJob().

36 {
37  // make regions
38  makeRegions(regLength);
39 
40  Nevents = eventMatrix.size(); // Number of events to calibrate with
41 
42  std::vector<float> totalSolution(Nchannels,1.);
43  std::vector<float> iterSolution(Nchannels,1.);
44  std::vector<std::vector<float> > myEventMatrix(eventMatrix);
45  std::vector<float> myEnergyVector(energyVector);
46 
47  // loop over nIter
48  for (int iter=1;iter<=nIter;iter++)
49  {
50  // loop over regions
51  for (unsigned int ireg=0; ireg<regMinEta.size(); ireg++)
52  {
53  std::vector<float> regIterSolution, regEnergyVector;
54  std::vector<int> regVmaxCeta, regVmaxCphi;
55  std::vector<std::vector<float> > regEventMatrix;
56 
57  // initialize new instance with regional min,max indices
58  HouseholderDecomposition regionalHH(squareMode,regMinEta[ireg],regMaxEta[ireg],regMinPhi[ireg],regMaxPhi[ireg]);
59 
60  // copy all events in region into new eventmatrix, energyvector, VmaxCeta, VmaxCphi
61  for (unsigned int ia=0; ia<VmaxCeta.size(); ia++)
62  {
63  if ((VmaxCeta[ia] >= regMinEta[ireg]) && (VmaxCeta[ia] <= regMaxEta[ireg])
64  && (VmaxCphi[ia] >= regMinPhi[ireg]) && (VmaxCphi[ia] <= regMaxPhi[ireg]))
65  {
66  // save event, calculate new eventmatrix(truncated) and energy
67  regVmaxCeta.push_back(VmaxCeta[ia]);
68  regVmaxCphi.push_back(VmaxCphi[ia]);
69 
70  std::vector<float> regEvent = myEventMatrix[ia];
71  float regEnergy = energyVector[ia];
72  for (int i2=0; i2<Nxtals; i2++)
73  {
74  int iFullReg = regionalHH.indexSqr2Reg(i2, VmaxCeta[ia], VmaxCphi[ia]);
75  if (iFullReg <0) // crystal outside
76  {
77  regEnergy -= regEvent[i2];
78  regEvent[i2] = 0.;
79  }
80  }
81  regEventMatrix.push_back(regEvent);
82  regEnergyVector.push_back(regEnergy);
83  }
84  }
85 
86  // calibrate
87  // std::cout << "HouseholderDecomposition::runRegional - Starting calibration of region " << ireg << ": eta "
88  // << regMinEta[ireg] << " to " << regMaxEta[ireg] << ", phi " << regMinPhi[ireg] << " to " << regMaxPhi[ireg] << std::endl;
89  regIterSolution = regionalHH.iterate(regEventMatrix, regVmaxCeta, regVmaxCphi, regEnergyVector);
90  // std::cout << "HouseholderDecomposition::runRegional - calibration of region finished. " << std::endl;
91 
92  // save solution into global iterSolution
93  // don't forget to delete the ones that are on the border !
94  for (unsigned int i1=0; i1<regIterSolution.size(); i1++)
95  {
96  int regFrame = regLength/2;
97  int currRegPhiRange = regMaxPhi[ireg] - regMinPhi[ireg] + 1;
98  int currRegEta = i1 / currRegPhiRange + regMinEta[ireg];
99  int currRegPhi = i1 % currRegPhiRange + regMinPhi[ireg];
100  int newindex = -100;
101  // if crystal well inside:
102  if ( (currRegEta >= (regMinEta[ireg]+regFrame*(!(regMinEta[ireg]==mineta))) ) &&
103  (currRegEta <= (regMaxEta[ireg]-regFrame*(!(regMaxEta[ireg]==maxeta))) ) &&
104  (currRegPhi >= (regMinPhi[ireg]+regFrame*(!(regMinPhi[ireg]==minphi))) ) &&
105  (currRegPhi <= (regMaxPhi[ireg]-regFrame*(!(regMaxPhi[ireg]==maxphi))) ) )
106  {
107  newindex = (currRegEta-mineta)*Nphi + currRegPhi-minphi;
108  iterSolution[newindex] = regIterSolution[i1];
109  }
110  }
111  } // end loop over regions
112 
113  if (iterSolution.empty()) return iterSolution;
114 
115  // re-calibrate eventMatrix with solution
116  for (int ievent = 0; ievent<Nevents; ievent++)
117  {
118  myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
119  }
120 
121  // save solution into theCalibVector
122  for (int i=0; i<Nchannels; i++)
123  {
124  totalSolution[i] *= iterSolution[i];
125  }
126 
127  } // end loop over nIter
128 
129  return totalSolution;
130 
131 }
int i
Definition: DBlmapReader.cc:9
std::vector< float > recalibrateEvent(const std::vector< float > &eventSquare, const int &maxCeta, const int &maxCphi, const std::vector< float > &recalibrateVector)
Recalibrate before next iteration: give previous solution vector as argument.
void makeRegions(const int &regLength)
void HouseholderDecomposition::solve ( std::vector< float > &  y)
private

Apply transformations to rhs output: r = residual vector (energy vector), y = solution

Definition at line 467 of file HouseholderDecomposition.cc.

References alpha, energyVectorProc, eventMatrixProc, i, j, Nchannels, Nevents, pivot, and detailsBasic3DVector::z.

Referenced by iterate().

468 {
469  std::vector<float> z(Nchannels,0.);
470 
471  float gamma;
472  int i,j;
473 
474  // std::cout << "Householder::solve() begin" << std::endl;
475 
476  for (j=0; j<Nchannels; j++)
477  {
478  // apply jth transformation to the right hand side
479  gamma = 0.;
480  for (i=j; i<Nevents; i++)
481  {
482  gamma += eventMatrixProc[i][j] * energyVectorProc[i];
483  }
484  gamma /= (alpha[j] * eventMatrixProc[j][j]);
485 
486  for (i=j; i<Nevents; i++)
487  {
488  energyVectorProc[i] += gamma * eventMatrixProc[i][j];
489  }
490  }
491 
492  z[Nchannels-1] = energyVectorProc[Nchannels-1] / alpha[Nchannels-1];
493 
494  for (i=Nchannels-2; i>=0; i--)
495  {
496  z[i] = energyVectorProc[i];
497  for (j=i+1; j<Nchannels; j++)
498  {
499  z[i] -= eventMatrixProc[i][j]*z[j];
500  }
501  z[i] /= alpha[i];
502  }
503 
504  for (i=0; i<Nchannels; i++)
505  {
506  y[pivot[i]] = z[i];
507  }
508 
509  // std::cout << "Householder::solve() finished." << std::endl;
510 
511 }
int i
Definition: DBlmapReader.cc:9
double double double z
std::vector< std::vector< float > > eventMatrixProc
int j
Definition: DBlmapReader.cc:9
std::vector< float > energyVectorProc
std::vector< std::vector< float > > HouseholderDecomposition::unzipMatrix ( const std::vector< std::vector< float > > &  eventMatrix,
const std::vector< int > &  VmaxCeta,
const std::vector< int > &  VmaxCphi 
)
private

Unzips the skimmed matrix into a full matrix.

Definition at line 558 of file HouseholderDecomposition.cc.

References i, indexSqr2Reg(), gen::k, Nchannels, Nevents, and Nxtals.

Referenced by iterate().

559 {
560  std::vector< std::vector<float> > fullMatrix;
561 
562  int iFull;
563 
564  for (int i=0; i<Nevents; i++)
565  {
566  std::vector<float> foo(Nchannels,0.);
567  for (int k=0; k<Nxtals; k++)
568  {
569  iFull = indexSqr2Reg(k, VmaxCeta[i], VmaxCphi[i]);
570  if (iFull >=0)
571  foo[iFull] = eventMatrix[i][k];
572  }
573  fullMatrix.push_back(foo);
574  }
575 
576  return fullMatrix;
577 }
int i
Definition: DBlmapReader.cc:9
int indexSqr2Reg(const int &sqrIndex, const int &maxCeta, const int &maxCphi)
Method to translate from square indices to region indices.
int k[5][pyjets_maxn]

Member Data Documentation

std::vector<float> HouseholderDecomposition::alpha
private

Definition at line 77 of file HouseholderDecomposition.h.

Referenced by decompose(), iterate(), and solve().

int HouseholderDecomposition::countEvents
private

Definition at line 71 of file HouseholderDecomposition.h.

std::vector<float> HouseholderDecomposition::energyVectorProc
private

Definition at line 76 of file HouseholderDecomposition.h.

Referenced by iterate(), and solve().

std::vector< std::vector<float> > HouseholderDecomposition::eventMatrixOrig
private

Definition at line 74 of file HouseholderDecomposition.h.

Referenced by iterate().

std::vector< std::vector<float> > HouseholderDecomposition::eventMatrixProc
private

Definition at line 75 of file HouseholderDecomposition.h.

Referenced by decompose(), iterate(), and solve().

int HouseholderDecomposition::maxeta
private

Definition at line 72 of file HouseholderDecomposition.h.

Referenced by HouseholderDecomposition(), indexSqr2Reg(), and runRegional().

int HouseholderDecomposition::maxphi
private

Definition at line 72 of file HouseholderDecomposition.h.

Referenced by HouseholderDecomposition(), indexSqr2Reg(), and runRegional().

int HouseholderDecomposition::mineta
private
int HouseholderDecomposition::minphi
private
int HouseholderDecomposition::Nchannels
private
int HouseholderDecomposition::Neta
private

Definition at line 72 of file HouseholderDecomposition.h.

Referenced by HouseholderDecomposition(), and makeRegions().

int HouseholderDecomposition::Nevents
private

Definition at line 73 of file HouseholderDecomposition.h.

Referenced by decompose(), iterate(), runRegional(), solve(), and unzipMatrix().

int HouseholderDecomposition::Nphi
private

Definition at line 72 of file HouseholderDecomposition.h.

Referenced by HouseholderDecomposition(), makeRegions(), and runRegional().

int HouseholderDecomposition::Nxtals
private
std::vector<int> HouseholderDecomposition::pivot
private

Definition at line 78 of file HouseholderDecomposition.h.

Referenced by decompose(), iterate(), and solve().

std::vector<int> HouseholderDecomposition::regMaxEta
private

Definition at line 80 of file HouseholderDecomposition.h.

Referenced by makeRegions(), and runRegional().

std::vector<int> HouseholderDecomposition::regMaxPhi
private

Definition at line 80 of file HouseholderDecomposition.h.

Referenced by makeRegions(), and runRegional().

std::vector<int> HouseholderDecomposition::regMinEta
private

Definition at line 80 of file HouseholderDecomposition.h.

Referenced by makeRegions(), and runRegional().

std::vector<int> HouseholderDecomposition::regMinPhi
private

Definition at line 80 of file HouseholderDecomposition.h.

Referenced by makeRegions(), and runRegional().

float HouseholderDecomposition::sigmaReplacement
private

Definition at line 81 of file HouseholderDecomposition.h.

Referenced by decompose(), and HouseholderDecomposition().

int HouseholderDecomposition::squareMode
private