CMS 3D CMS Logo

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 18 of file MinL3Algorithm.h.

Constructor & Destructor Documentation

◆ MinL3Algorithm()

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

◆ ~MinL3Algorithm()

MinL3Algorithm::~MinL3Algorithm ( )

Destructor.

Definition at line 33 of file MinL3Algorithm.cc.

33 {}

Member Function Documentation

◆ addEvent()

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 95 of file MinL3Algorithm.cc.

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

Referenced by iterate().

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

◆ getSolution()

std::vector< float > MinL3Algorithm::getSolution ( bool  resetsolution = true)

get the solution at the end of the calibration

Definition at line 134 of file MinL3Algorithm.cc.

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

Referenced by iterate().

134  {
135  std::vector<float> solution(Nchannels, 1.);
136 
137  for (int i = 0; i < Nchannels; i++) {
138  if (wsum[i] != 0.) {
139  solution[i] *= Ewsum[i] / wsum[i];
140  }
141  // else
142  // { std::cout << "warning - no event data for crystal index (reduced region) " << i << std::endl; }
143  }
144 
145  if (resetsolution)
146  resetSolution();
147 
148  return solution;
149 }
std::vector< float > wsum
void resetSolution()
reset for new iteration
std::vector< float > Ewsum

◆ indexSqr2Reg()

int MinL3Algorithm::indexSqr2Reg ( const int &  sqrIndex,
const int &  maxCeta,
const int &  maxCphi 
)

method to translate from square indices to region indices

Definition at line 171 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) {
177  if (maxCeta > 0)
178  curr_eta--;
179  else
180  curr_eta++;
181  } // JUMP over 0
182 
183  int curr_phi = maxCphi - squareMode / 2 + sqrIndex / squareMode;
184  if (curr_phi < 1)
185  curr_phi += 360;
186  if (curr_phi > 360)
187  curr_phi -= 360;
188 
189  bool negPhiDirection = (maxphi < minphi);
190  int iFullphi;
191 
192  regionIndex = -1;
193 
194  if (curr_eta >= mineta && curr_eta <= maxeta)
195  if ((!negPhiDirection && (curr_phi >= minphi && curr_phi <= maxphi)) ||
196  (negPhiDirection && !(curr_phi >= minphi && curr_phi <= maxphi))) {
197  iFullphi = curr_phi - minphi;
198  if (iFullphi < 0)
199  iFullphi += 360;
200  regionIndex = (curr_eta - mineta) * (maxphi - minphi + 1 + 360 * negPhiDirection) + iFullphi;
201  }
202 
203  return regionIndex;
204 }

◆ iterate()

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 35 of file MinL3Algorithm.cc.

References addEvent(), getSolution(), mps_fire::i, dqmiolumiharvest::j, Nchannels, Nxtals, recalibrateEvent(), and pfClustersFromCombinedCaloHF_cfi::scale.

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

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

◆ recalibrateEvent()

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 156 of file MinL3Algorithm.cc.

References mps_fire::i, indexSqr2Reg(), and Nxtals.

Referenced by iterate().

159  {
160  std::vector<float> newEventSquare(eventSquare);
161  int iFull;
162 
163  for (int i = 0; i < Nxtals; i++) {
164  iFull = indexSqr2Reg(i, maxCeta, maxCphi);
165  if (iFull >= 0)
166  newEventSquare[i] *= recalibrateVector[iFull];
167  }
168  return newEventSquare;
169 }
int indexSqr2Reg(const int &sqrIndex, const int &maxCeta, const int &maxCphi)
method to translate from square indices to region indices

◆ resetSolution()

void MinL3Algorithm::resetSolution ( )

reset for new iteration

Definition at line 151 of file MinL3Algorithm.cc.

References Ewsum, Nchannels, and wsum.

Referenced by getSolution().

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

Member Data Documentation

◆ countEvents

int MinL3Algorithm::countEvents
private

Definition at line 60 of file MinL3Algorithm.h.

Referenced by addEvent().

◆ Ewsum

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

Definition at line 63 of file MinL3Algorithm.h.

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

◆ kweight

float MinL3Algorithm::kweight
private

Definition at line 57 of file MinL3Algorithm.h.

Referenced by addEvent().

◆ maxeta

int MinL3Algorithm::maxeta
private

Definition at line 59 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

◆ maxphi

int MinL3Algorithm::maxphi
private

Definition at line 59 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

◆ mineta

int MinL3Algorithm::mineta
private

Definition at line 59 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

◆ minphi

int MinL3Algorithm::minphi
private

Definition at line 59 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

◆ Nchannels

int MinL3Algorithm::Nchannels
private

Definition at line 61 of file MinL3Algorithm.h.

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

◆ Nxtals

int MinL3Algorithm::Nxtals
private

Definition at line 61 of file MinL3Algorithm.h.

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

◆ squareMode

int MinL3Algorithm::squareMode
private

Definition at line 58 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

◆ wsum

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

Definition at line 62 of file MinL3Algorithm.h.

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