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
MinL3Algorithm Class Reference

#include <MinL3Algorithm.h>

Public Member Functions

void addEvent (const std::vector< float > &eventSquare, const int &maxCeta, const int &maxCphi, const float &energy)
 add event to the calculation of the calibration vector More...
 
std::vector< float > getSolution (bool resetsolution=true)
 get the solution at the end of the calibration 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)
 
 MinL3Algorithm (float kweight_=0., int squareMode_=5, int mineta_=1, int maxeta_=85, int minphi_=1, int maxphi_=20)
 
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...
 
void resetSolution ()
 reset for new iteration More...
 
 ~MinL3Algorithm ()
 Destructor. More...
 

Private Attributes

int countEvents
 
std::vector< float > Ewsum
 
float kweight
 
int maxeta
 
int maxphi
 
int mineta
 
int minphi
 
int Nchannels
 
int Nxtals
 
int squareMode
 
std::vector< float > wsum
 

Detailed Description

Implementation of the L3 Collaboration algorithm to solve a system Ax = B by minimization of |Ax-B| using an iterative linear approach This class is specific for the ECAL calibration

13.03.2007: R.Ofierzynski

Author
R.Ofierzynski, CERN

Definition at line 19 of file MinL3Algorithm.h.

Constructor & Destructor Documentation

MinL3Algorithm::MinL3Algorithm ( float  kweight_ = 0.,
int  squareMode_ = 5,
int  mineta_ = 1,
int  maxeta_ = 85,
int  minphi_ = 1,
int  maxphi_ = 20 
)

Default constructor kweight_ = event weight, squareMode_ = side length of the cluster square

Definition at line 10 of file MinL3Algorithm.cc.

References Ewsum, maxeta, maxphi, mineta, minphi, Nchannels, Nxtals, squareMode, and wsum.

11  :kweight(kweight_), squareMode(squareMode_), mineta(mineta_), maxeta(maxeta_), minphi(minphi_), maxphi(maxphi_), countEvents(0)
12 {
13  int Neta = maxeta - mineta + 1;
14  if (mineta * maxeta < 0) Neta--; // there's no eta index = 0
15  int Nphi = maxphi - minphi + 1;
16  if (Nphi <0) Nphi += 360;
17 
18  Nchannels = Neta * Nphi; // no. of channels, get it from edges of the region
19 
20  Nxtals = squareMode*squareMode; // no. of xtals in one event
21 
22  wsum.assign(Nchannels,0.);
23  Ewsum.assign(Nchannels,0.);
24 }
std::vector< float > wsum
std::vector< float > Ewsum
MinL3Algorithm::~MinL3Algorithm ( )

Destructor.

Definition at line 27 of file MinL3Algorithm.cc.

28 {
29 }

Member Function Documentation

void MinL3Algorithm::addEvent ( const std::vector< float > &  eventSquare,
const int &  maxCeta,
const int &  maxCphi,
const float &  energy 
)

add event to the calculation of the calibration vector

Definition at line 91 of file MinL3Algorithm.cc.

References countEvents, Ewsum, i, indexSqr2Reg(), kweight, Nxtals, funct::pow(), w(), and wsum.

Referenced by iterate().

92 {
93  countEvents++;
94 
95  float w, invsumXmatrix;
96  float eventw;
97  int iFull, i;
98  // Loop over the crystal matrix to find the sum
99  float sumXmatrix=0.;
100 
101  for (i=0; i<Nxtals; i++) { sumXmatrix+=eventSquare[i]; }
102 
103  // event weighting
104  eventw = 1 - fabs(1 - sumXmatrix/energy);
105  eventw = pow(eventw,kweight);
106 
107  if (sumXmatrix != 0.)
108  {
109  invsumXmatrix = 1/sumXmatrix;
110  // Loop over the crystal matrix (3x3,5x5,7x7) again and calculate the weights for each xtal
111  for (i=0; i<Nxtals; i++)
112  {
113  w = eventSquare[i] * invsumXmatrix;
114 
115  iFull = indexSqr2Reg(i, maxCeta, maxCphi);
116  if (iFull >= 0)
117  {
118  // with event weighting:
119  wsum[iFull] += w*eventw;
120  Ewsum[iFull] += (w*eventw * energy * invsumXmatrix);
121  // wsum[iFull] += w;
122  // Ewsum[iFull] += (w * energy * invsumXmatrix);
123  }
124  }
125  }
126  // else {std::cout << " Debug: dropping null event: " << countEvents << std::endl;}
127 }
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 > wsum
std::vector< float > Ewsum
T w() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::vector< float > MinL3Algorithm::getSolution ( bool  resetsolution = true)

get the solution at the end of the calibration

Definition at line 130 of file MinL3Algorithm.cc.

References Ewsum, i, Nchannels, resetSolution(), and wsum.

Referenced by iterate().

131 {
132  std::vector<float> solution(Nchannels,1.);
133 
134  for (int i=0; i<Nchannels; i++)
135  {
136  if (wsum[i] != 0.)
137  { solution[i]*=Ewsum[i]/wsum[i];}
138  // else
139  // { std::cout << "warning - no event data for crystal index (reduced region) " << i << std::endl; }
140  }
141 
142  if (resetsolution) resetSolution();
143 
144  return solution;
145 }
int i
Definition: DBlmapReader.cc:9
std::vector< float > wsum
void resetSolution()
reset for new iteration
std::vector< float > Ewsum
int MinL3Algorithm::indexSqr2Reg ( const int &  sqrIndex,
const int &  maxCeta,
const int &  maxCphi 
)

method to translate from square indices to region indices

Definition at line 170 of file MinL3Algorithm.cc.

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

Referenced by addEvent(), and recalibrateEvent().

171 {
172  int regionIndex;
173 
174  // get the current eta, phi indices
175  int curr_eta = maxCeta - squareMode/2 + sqrIndex%squareMode;
176  if (curr_eta * maxCeta <= 0) {if (maxCeta > 0) curr_eta--; else curr_eta++; } // JUMP over 0
177 
178  int curr_phi = maxCphi - squareMode/2 + sqrIndex/squareMode;
179  if (curr_phi < 1) curr_phi += 360;
180  if (curr_phi > 360) curr_phi -= 360;
181 
182  bool negPhiDirection = (maxphi < minphi);
183  int iFullphi;
184 
185  regionIndex = -1;
186 
187  if (curr_eta >= mineta && curr_eta <= maxeta)
188  if ( (!negPhiDirection && (curr_phi >= minphi && curr_phi <= maxphi)) ||
189  (negPhiDirection && !(curr_phi >= minphi && curr_phi <= maxphi)) )
190  {
191  iFullphi = curr_phi - minphi;
192  if (iFullphi < 0) iFullphi += 360;
193  regionIndex = (curr_eta - mineta) * (maxphi - minphi + 1 + 360*negPhiDirection) + iFullphi;
194  }
195 
196  return regionIndex;
197 }
std::vector< float > MinL3Algorithm::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 
)

method doing the full calibration running 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

to be used also as recipe on how to use the calibration methods one-by-one <<

Definition at line 32 of file MinL3Algorithm.cc.

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

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

33 {
34  int Nevents = eventMatrix.size(); // Number of events to calibrate with
35 
36  std::vector<float> totalSolution(Nchannels,1.);
37  std::vector<float> iterSolution;
38  std::vector<std::vector<float> > myEventMatrix(eventMatrix);
39  std::vector<float> myEnergyVector(energyVector);
40 
41  int i, j;
42 
43  // Iterate the correction
44  for (int iter=1;iter<=nIter;iter++)
45  {
46 
47  // if normalization flag is set, normalize energies
48  float sumOverEnergy;
49  if (normalizeFlag)
50  {
51  float scale = 0.;
52 
53  for (i=0; i<Nevents; i++)
54  {
55  sumOverEnergy = 0.;
56  for (j=0; j<Nxtals; j++) {sumOverEnergy += myEventMatrix[i][j];}
57  sumOverEnergy /= myEnergyVector[i];
58  scale += sumOverEnergy;
59  }
60  scale /= Nevents;
61 
62  for (i=0; i<Nevents; i++) {myEnergyVector[i] *= scale;}
63  } // end normalize energies
64 
65  // now the real work starts:
66  for (int iEvt=0; iEvt < Nevents; iEvt++)
67  {
68  addEvent(myEventMatrix[iEvt], VmaxCeta[iEvt], VmaxCphi[iEvt], myEnergyVector[iEvt]);
69  }
70  iterSolution = getSolution();
71  if (iterSolution.empty()) return iterSolution;
72 
73  // re-calibrate eventMatrix with solution
74  for (int ievent = 0; ievent<Nevents; ievent++)
75  {
76  myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
77  }
78 
79  for (int i=0; i<Nchannels; i++)
80  {
81  // save solution into theCalibVector
82  totalSolution[i] *= iterSolution[i];
83  }
84  // resetSolution(); // reset for new iteration, now: getSolution does it automatically if not vetoed
85  } // end iterate correction
86 
87  return totalSolution;
88 }
int i
Definition: DBlmapReader.cc:9
std::vector< float > getSolution(bool resetsolution=true)
get the solution at the end of the calibration
int j
Definition: DBlmapReader.cc:9
void addEvent(const std::vector< float > &eventSquare, const int &maxCeta, const int &maxCphi, const float &energy)
add event to the calculation of the calibration vector
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 > MinL3Algorithm::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 155 of file MinL3Algorithm.cc.

References i, indexSqr2Reg(), and Nxtals.

Referenced by iterate().

156 {
157  std::vector<float> newEventSquare(eventSquare);
158  int iFull;
159 
160  for (int i=0; i<Nxtals; i++)
161  {
162  iFull = indexSqr2Reg(i, maxCeta, maxCphi);
163  if (iFull >=0)
164  newEventSquare[i] *= recalibrateVector[iFull];
165  }
166  return newEventSquare;
167 }
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
void MinL3Algorithm::resetSolution ( )

reset for new iteration

Definition at line 148 of file MinL3Algorithm.cc.

References Ewsum, Nchannels, and wsum.

Referenced by getSolution().

149 {
150  wsum.assign(Nchannels,0.);
151  Ewsum.assign(Nchannels,0.);
152 }
std::vector< float > wsum
std::vector< float > Ewsum

Member Data Documentation

int MinL3Algorithm::countEvents
private

Definition at line 56 of file MinL3Algorithm.h.

Referenced by addEvent().

std::vector<float> MinL3Algorithm::Ewsum
private

Definition at line 59 of file MinL3Algorithm.h.

Referenced by addEvent(), getSolution(), MinL3Algorithm(), and resetSolution().

float MinL3Algorithm::kweight
private

Definition at line 53 of file MinL3Algorithm.h.

Referenced by addEvent().

int MinL3Algorithm::maxeta
private

Definition at line 55 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::maxphi
private

Definition at line 55 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::mineta
private

Definition at line 55 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::minphi
private

Definition at line 55 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::Nchannels
private

Definition at line 57 of file MinL3Algorithm.h.

Referenced by getSolution(), iterate(), MinL3Algorithm(), and resetSolution().

int MinL3Algorithm::Nxtals
private

Definition at line 57 of file MinL3Algorithm.h.

Referenced by addEvent(), iterate(), MinL3Algorithm(), and recalibrateEvent().

int MinL3Algorithm::squareMode
private

Definition at line 54 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

std::vector<float> MinL3Algorithm::wsum
private

Definition at line 58 of file MinL3Algorithm.h.

Referenced by addEvent(), getSolution(), MinL3Algorithm(), and resetSolution().