CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
GenericMinL3Algorithm Class Reference

#include <GenericMinL3Algorithm.h>

Public Member Functions

 GenericMinL3Algorithm (bool normalise=false)
 
std::vector< float > iterate (const std::vector< std::vector< float > > &eventMatrix, const std::vector< float > &energyVector, int nIter)
 
std::vector< float > iterate (const std::vector< std::vector< float > > &eventMatrix, const std::vector< float > &energyVector)
 
 ~GenericMinL3Algorithm ()
 Destructor. More...
 

Private Attributes

bool normaliseFlag
 

Detailed Description

Implementation of the L3 Collaboration algorithm to solve a system Ax = B by minimization of |Ax-B| using an iterative linear approach

Author
R.Ofierzynski, CERN

Definition at line 14 of file GenericMinL3Algorithm.h.

Constructor & Destructor Documentation

◆ GenericMinL3Algorithm()

GenericMinL3Algorithm::GenericMinL3Algorithm ( bool  normalise = false)

Default constructor CAVEAT: use normalise = true only if you know what you're doing!

Definition at line 10 of file GenericMinL3Algorithm.cc.

11  : normaliseFlag(normalise)
12 // if normalize=true: for all events sum the e25ovTRP. then take the mean value and rescale all TrP
13 {}

◆ ~GenericMinL3Algorithm()

GenericMinL3Algorithm::~GenericMinL3Algorithm ( )

Destructor.

Definition at line 15 of file GenericMinL3Algorithm.cc.

15 {}

Member Function Documentation

◆ iterate() [1/2]

std::vector< float > GenericMinL3Algorithm::iterate ( const std::vector< std::vector< float > > &  eventMatrix,
const std::vector< float > &  energyVector,
int  nIter 
)

run the Minimization L3 Algorithm "nIter" number of times, recalibrating the event matrix after each iteration with the new solution returns the vector of calibration coefficients built from all iteration solutions

Definition at line 17 of file GenericMinL3Algorithm.cc.

References mps_fire::i.

19  {
20  std::vector<float> solution;
21  std::vector<std::vector<float> > myEventMatrix(eventMatrix);
22  int Nevents = eventMatrix.size(); // Number of events to calibrate with
23  int Nchannels = eventMatrix[0].size(); // Number of channel coefficients
24  std::vector<float> theCalibVector(Nchannels, 1.);
25 
26  // Iterate the correction
27  for (int iter = 1; iter <= nIter; iter++) {
28  // make one iteration
29  solution = iterate(myEventMatrix, energyVector);
30 
31  if (solution.empty())
32  return solution;
33  // R.O.: or throw an exception, what's the standard CMS way ?
34 
35  // re-calibrate eventMatrix with solution
36  for (int i = 0; i < Nchannels; i++) {
37  for (int ievent = 0; ievent < Nevents; ievent++) {
38  myEventMatrix[ievent][i] *= solution[i];
39  }
40  // save solution into theCalibVector
41  theCalibVector[i] *= solution[i];
42  }
43 
44  } // end iterate the correction
45 
46  return theCalibVector;
47 }
std::vector< float > iterate(const std::vector< std::vector< float > > &eventMatrix, const std::vector< float > &energyVector, int nIter)

◆ iterate() [2/2]

std::vector< float > GenericMinL3Algorithm::iterate ( const std::vector< std::vector< float > > &  eventMatrix,
const std::vector< float > &  energyVector 
)

perform one iteration using the Minimization L3 Algorithm returns the vector of calibration coefficients

Definition at line 49 of file GenericMinL3Algorithm.cc.

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, normaliseFlag, isotrackNtupler::scale, and w().

50  {
51  std::vector<float> solution;
52  std::vector<float> myEnergyVector(energyVector);
53 
54  int Nevents = eventMatrix.size(); // Number of events to calibrate with
55  int Nchannels = eventMatrix[0].size(); // Number of channel coefficients
56 
57  // Sanity check
58  if (Nevents != int(myEnergyVector.size())) {
59  std::cout << "GenericMinL3Algorithm::iterate(): Error: bad matrix dimensions. Dropping out." << std::endl;
60  return solution; // empty vector !
61  }
62 
63  // initialize the solution vector with 1.
64  solution.assign(Nchannels, 1.);
65 
66  int ievent, i, j;
67 
68  // if normalization flag is set, normalize energies
69  float sumOverEnergy;
70  if (normaliseFlag) {
71  float scale = 0.;
72 
73  std::cout << "GenericMinL3Algorithm::iterate(): Normalising event data" << std::endl;
74 
75  for (i = 0; i < Nevents; i++) {
76  sumOverEnergy = 0.;
77  for (j = 0; j < Nchannels; j++) {
78  sumOverEnergy += eventMatrix[i][j];
79  }
80  sumOverEnergy /= myEnergyVector[i];
81  scale += sumOverEnergy;
82  }
83  scale /= Nevents;
84  std::cout << " Normalisation = " << scale << std::endl;
85 
86  for (i = 0; i < Nevents; i++) {
87  myEnergyVector[i] *= scale;
88  }
89  } // end normalize energies
90 
91  // This is where the real work goes on...
92  float sum25, invsum25;
93  float w; // weight for event
94  std::vector<float> wsum(Nchannels, 0.); // sum of weights for a crystal
95  std::vector<float> Ewsum(Nchannels, 0.); // sum of products of weight*Etrue/E25
96 
97  // Loop over events
98  for (ievent = 0; ievent < Nevents; ievent++) {
99  // Loop over the 5x5 to find the sum
100  sum25 = 0.;
101 
102  for (i = 0; i < Nchannels; i++) {
103  sum25 += eventMatrix[ievent][i];
104  } //*calibs[i];
105 
106  if (sum25 != 0.) {
107  invsum25 = 1 / sum25;
108  // Loop over the 5x5 again and calculate the weights for each xtal
109  for (i = 0; i < Nchannels; i++) {
110  w = eventMatrix[ievent][i] * invsum25; // * calibs[i]
111  wsum[i] += w;
112  Ewsum[i] += (w * myEnergyVector[ievent] * invsum25);
113  }
114  } else {
115  std::cout << " Debug: dropping null event: " << ievent << std::endl;
116  }
117 
118  } // end Loop over events
119 
120  // Apply correction factors to all channels not in the margin
121  for (i = 0; i < Nchannels; i++) {
122  if (wsum[i] != 0.) {
123  solution[i] *= Ewsum[i] / wsum[i];
124  } else {
125  std::cout << "warning - no event data for crystal index " << i << std::endl;
126  }
127  }
128 
129  return solution;
130 }
T w() const

Member Data Documentation

◆ normaliseFlag

bool GenericMinL3Algorithm::normaliseFlag
private

Definition at line 36 of file GenericMinL3Algorithm.h.

Referenced by iterate().