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

Date:
2010/08/06 20:24:06
Revision:
1.2
Author
R.Ofierzynski, CERN

Definition at line 17 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 13 of file GenericMinL3Algorithm.cc.

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

Destructor.

Definition at line 20 of file GenericMinL3Algorithm.cc.

21 {
22 }

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

References i.

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

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

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

Referenced by iterate().