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 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 15 of file GenericMinL3Algorithm.h.

Constructor & Destructor Documentation

GenericMinL3Algorithm::GenericMinL3Algorithm ( bool  normalise = false)

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

Definition at line 11 of file GenericMinL3Algorithm.cc.

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

Destructor.

Definition at line 18 of file GenericMinL3Algorithm.cc.

19 {
20 }

Member Function Documentation

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 23 of file GenericMinL3Algorithm.cc.

References i.

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

References gather_cfg::cout, i, j, normaliseFlag, pileupReCalc_HLTpaths::scale, and w().

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

Member Data Documentation

bool GenericMinL3Algorithm::normaliseFlag
private

Definition at line 37 of file GenericMinL3Algorithm.h.

Referenced by iterate().