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

Date:
2007/03/14 13:55:40
Revision:
1.4
Author
R.Ofierzynski, CERN

Definition at line 21 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 12 of file MinL3Algorithm.cc.

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

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

Destructor.

Definition at line 29 of file MinL3Algorithm.cc.

30 {
31 }

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

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

Referenced by iterate().

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

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

Referenced by iterate().

133 {
134  std::vector<float> solution(Nchannels,1.);
135 
136  for (int i=0; i<Nchannels; i++)
137  {
138  if (wsum[i] != 0.)
139  { solution[i]*=Ewsum[i]/wsum[i];}
140  // else
141  // { std::cout << "warning - no event data for crystal index (reduced region) " << i << std::endl; }
142  }
143 
144  if (resetsolution) resetSolution();
145 
146  return solution;
147 }
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 172 of file MinL3Algorithm.cc.

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

Referenced by addEvent(), and recalibrateEvent().

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

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

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

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

References i, indexSqr2Reg(), and Nxtals.

Referenced by iterate().

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

int MinL3Algorithm::countEvents
private

Definition at line 58 of file MinL3Algorithm.h.

Referenced by addEvent().

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

Definition at line 61 of file MinL3Algorithm.h.

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

float MinL3Algorithm::kweight
private

Definition at line 55 of file MinL3Algorithm.h.

Referenced by addEvent().

int MinL3Algorithm::maxeta
private

Definition at line 57 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::maxphi
private

Definition at line 57 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::mineta
private

Definition at line 57 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::minphi
private

Definition at line 57 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::Nchannels
private

Definition at line 59 of file MinL3Algorithm.h.

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

int MinL3Algorithm::Nxtals
private

Definition at line 59 of file MinL3Algorithm.h.

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

int MinL3Algorithm::squareMode
private

Definition at line 56 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

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

Definition at line 60 of file MinL3Algorithm.h.

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