CMS 3D CMS Logo

MinL3Algorithm Class Reference

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. More...

#include <Calibration/Tools/interface/MinL3Algorithm.h>

List of all members.

Public Member Functions

void addEvent (const vector< float > &eventSquare, const int &maxCeta, const int &maxCphi, const float &energy)
 add event to the calculation of the calibration vector
vector< float > getSolution (bool resetsolution=true)
 get the solution at the end of the calibration
int indexSqr2Reg (const int &sqrIndex, const int &maxCeta, const int &maxCphi)
 method to translate from square indices to region indices
vector< float > iterate (const vector< vector< float > > &eventMatrix, const vector< int > &VmaxCeta, const vector< int > &VmaxCphi, const 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 <<
 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.
vector< float > recalibrateEvent (const vector< float > &eventSquare, const int &maxCeta, const int &maxCphi, const vector< float > &recalibrateVector)
 recalibrate before next iteration: give previous solution vector as argument
void resetSolution ()
 reset for new iteration
 ~MinL3Algorithm ()
 Destructor.

Private Attributes

int countEvents
vector< float > Ewsum
float kweight
int maxeta
int maxphi
int mineta
int minphi
int Nchannels
int Nxtals
int squareMode
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 23 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.

00013   :kweight(kweight_), squareMode(squareMode_), mineta(mineta_), maxeta(maxeta_), minphi(minphi_), maxphi(maxphi_), countEvents(0)
00014 {
00015   int Neta = maxeta - mineta + 1;
00016   if (mineta * maxeta < 0) Neta--; // there's no eta index = 0
00017   int Nphi = maxphi - minphi + 1;
00018   if (Nphi <0) Nphi += 360;
00019   
00020   Nchannels = Neta * Nphi; // no. of channels, get it from edges of the region
00021 
00022   Nxtals = squareMode*squareMode; // no. of xtals in one event
00023 
00024   wsum.assign(Nchannels,0.);
00025   Ewsum.assign(Nchannels,0.);
00026 }

MinL3Algorithm::~MinL3Algorithm (  ) 

Destructor.

Definition at line 29 of file MinL3Algorithm.cc.

00030 {
00031 }


Member Function Documentation

void MinL3Algorithm::addEvent ( const 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(), w, and wsum.

Referenced by iterate().

00094 {
00095   countEvents++;
00096 
00097   float w, invsumXmatrix;
00098   float eventw;
00099   int iFull, i;
00100   // Loop over the crystal matrix to find the sum
00101   float sumXmatrix=0.;
00102       
00103   for (i=0; i<Nxtals; i++) { sumXmatrix+=eventSquare[i]; }
00104       
00105   // event weighting
00106   eventw = 1 - fabs(1 - sumXmatrix/energy);
00107   eventw = pow(eventw,kweight);
00108       
00109   if (sumXmatrix != 0.)
00110     {
00111       invsumXmatrix = 1/sumXmatrix;
00112       // Loop over the crystal matrix (3x3,5x5,7x7) again and calculate the weights for each xtal
00113       for (i=0; i<Nxtals; i++) 
00114         {               
00115           w = eventSquare[i] * invsumXmatrix;
00116 
00117           iFull = indexSqr2Reg(i, maxCeta, maxCphi);
00118           if (iFull >= 0)
00119             {
00120               // with event weighting:
00121               wsum[iFull] += w*eventw;
00122               Ewsum[iFull] += (w*eventw * energy * invsumXmatrix);
00123               //              wsum[iFull] += w;
00124               //              Ewsum[iFull] += (w * energy * invsumXmatrix);
00125             }
00126         }
00127     }
00128   //  else {cout << " Debug: dropping null event: " << countEvents << endl;}
00129 }

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().

00133 {
00134   vector<float> solution(Nchannels,1.);
00135 
00136   for (int i=0; i<Nchannels; i++) 
00137     {
00138       if (wsum[i] != 0.) 
00139         { solution[i]*=Ewsum[i]/wsum[i];}
00140       //      else 
00141       //        { cout << "warning - no event data for crystal index (reduced region) " << i << endl; }
00142     }
00143   
00144   if (resetsolution) resetSolution();
00145 
00146   return solution;
00147 }

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().

00173 {
00174   int regionIndex;
00175 
00176   // get the current eta, phi indices
00177   int curr_eta = maxCeta - squareMode/2 + sqrIndex%squareMode;
00178   if (curr_eta * maxCeta <= 0) {if (maxCeta > 0) curr_eta--; else curr_eta++; }  // JUMP over 0
00179 
00180   int curr_phi = maxCphi - squareMode/2 + sqrIndex/squareMode;
00181   if (curr_phi < 1) curr_phi += 360;
00182   if (curr_phi > 360) curr_phi -= 360;
00183 
00184   bool negPhiDirection = (maxphi < minphi);
00185   int iFullphi;
00186 
00187   regionIndex = -1;
00188 
00189   if (curr_eta >= mineta && curr_eta <= maxeta)
00190     if ( (!negPhiDirection && (curr_phi >= minphi && curr_phi <= maxphi)) ||
00191          (negPhiDirection && !(curr_phi >= minphi && curr_phi <= maxphi))      ) 
00192       {
00193         iFullphi = curr_phi - minphi;
00194         if (iFullphi < 0) iFullphi += 360;
00195         regionIndex = (curr_eta - mineta) * (maxphi - minphi + 1 + 360*negPhiDirection) + iFullphi;
00196       }
00197 
00198   return regionIndex;
00199 }

vector< float > MinL3Algorithm::iterate ( const vector< vector< float > > &  eventMatrix,
const vector< int > &  VmaxCeta,
const vector< int > &  VmaxCphi,
const 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, iter, j, Nchannels, Nxtals, recalibrateEvent(), and scale.

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

00035 {
00036   int Nevents = eventMatrix.size(); // Number of events to calibrate with
00037 
00038   vector<float> totalSolution(Nchannels,1.);
00039   vector<float> iterSolution;
00040   vector<vector<float> > myEventMatrix(eventMatrix);
00041   vector<float> myEnergyVector(energyVector);
00042 
00043   int i, j;
00044 
00045   // Iterate the correction
00046   for (int iter=1;iter<=nIter;iter++) 
00047     {
00048 
00049       // if normalization flag is set, normalize energies
00050       float sumOverEnergy;
00051       if (normalizeFlag)
00052         {
00053           float scale = 0.;
00054           
00055           for (i=0; i<Nevents; i++)
00056             {
00057               sumOverEnergy = 0.;
00058               for (j=0; j<Nxtals; j++) {sumOverEnergy += myEventMatrix[i][j];}
00059               sumOverEnergy /= myEnergyVector[i];
00060               scale += sumOverEnergy;
00061             }
00062           scale /= Nevents;
00063           
00064           for (i=0; i<Nevents; i++) {myEnergyVector[i] *= scale;}         
00065         } // end normalize energies
00066 
00067       // now the real work starts:
00068       for (int iEvt=0; iEvt < Nevents; iEvt++)
00069         {
00070           addEvent(myEventMatrix[iEvt], VmaxCeta[iEvt], VmaxCphi[iEvt], myEnergyVector[iEvt]);
00071         }
00072       iterSolution = getSolution();
00073       if (iterSolution.empty()) return iterSolution;
00074 
00075       // re-calibrate eventMatrix with solution
00076       for (int ievent = 0; ievent<Nevents; ievent++)
00077         {
00078           myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
00079         }
00080 
00081       for (int i=0; i<Nchannels; i++) 
00082         {
00083           // save solution into theCalibVector
00084           totalSolution[i] *= iterSolution[i];
00085         }
00086       //      resetSolution(); // reset for new iteration, now: getSolution does it automatically if not vetoed
00087     } // end iterate correction
00088 
00089   return totalSolution;
00090 }

vector< float > MinL3Algorithm::recalibrateEvent ( const vector< float > &  eventSquare,
const int maxCeta,
const int maxCphi,
const 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().

00158 {
00159   vector<float> newEventSquare(eventSquare);
00160   int iFull;
00161 
00162   for (int i=0; i<Nxtals; i++) 
00163     {
00164       iFull = indexSqr2Reg(i, maxCeta, maxCphi);
00165       if (iFull >=0)
00166         newEventSquare[i] *= recalibrateVector[iFull];
00167     }
00168   return newEventSquare;
00169 }

void MinL3Algorithm::resetSolution (  ) 

reset for new iteration

Definition at line 150 of file MinL3Algorithm.cc.

References Ewsum, Nchannels, and wsum.

Referenced by getSolution().

00151 {
00152   wsum.assign(Nchannels,0.);
00153   Ewsum.assign(Nchannels,0.);
00154 }


Member Data Documentation

int MinL3Algorithm::countEvents [private]

Definition at line 60 of file MinL3Algorithm.h.

Referenced by addEvent().

vector<float> MinL3Algorithm::Ewsum [private]

Definition at line 63 of file MinL3Algorithm.h.

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

float MinL3Algorithm::kweight [private]

Definition at line 57 of file MinL3Algorithm.h.

Referenced by addEvent().

int MinL3Algorithm::maxeta [private]

Definition at line 59 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::maxphi [private]

Definition at line 59 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::mineta [private]

Definition at line 59 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::minphi [private]

Definition at line 59 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

int MinL3Algorithm::Nchannels [private]

Definition at line 61 of file MinL3Algorithm.h.

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

int MinL3Algorithm::Nxtals [private]

Definition at line 61 of file MinL3Algorithm.h.

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

int MinL3Algorithm::squareMode [private]

Definition at line 58 of file MinL3Algorithm.h.

Referenced by indexSqr2Reg(), and MinL3Algorithm().

vector<float> MinL3Algorithm::wsum [private]

Definition at line 62 of file MinL3Algorithm.h.

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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:28:16 2009 for CMSSW by  doxygen 1.5.4