CMS 3D CMS Logo

Public Member Functions | Private Attributes

MinL3Algorithm Class Reference

#include <MinL3Algorithm.h>

List of all members.

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
std::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
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
void resetSolution ()
 reset for new iteration
 ~MinL3Algorithm ()
 Destructor.

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:
2010/08/06 20:24:06
Revision:
1.5
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.

  :kweight(kweight_), squareMode(squareMode_), mineta(mineta_), maxeta(maxeta_), minphi(minphi_), maxphi(maxphi_), countEvents(0)
{
  int Neta = maxeta - mineta + 1;
  if (mineta * maxeta < 0) Neta--; // there's no eta index = 0
  int Nphi = maxphi - minphi + 1;
  if (Nphi <0) Nphi += 360;
  
  Nchannels = Neta * Nphi; // no. of channels, get it from edges of the region

  Nxtals = squareMode*squareMode; // no. of xtals in one event

  wsum.assign(Nchannels,0.);
  Ewsum.assign(Nchannels,0.);
}
MinL3Algorithm::~MinL3Algorithm ( )

Destructor.

Definition at line 29 of file MinL3Algorithm.cc.

{
}

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(), w(), and wsum.

Referenced by iterate().

{
  countEvents++;

  float w, invsumXmatrix;
  float eventw;
  int iFull, i;
  // Loop over the crystal matrix to find the sum
  float sumXmatrix=0.;
      
  for (i=0; i<Nxtals; i++) { sumXmatrix+=eventSquare[i]; }
      
  // event weighting
  eventw = 1 - fabs(1 - sumXmatrix/energy);
  eventw = pow(eventw,kweight);
      
  if (sumXmatrix != 0.)
    {
      invsumXmatrix = 1/sumXmatrix;
      // Loop over the crystal matrix (3x3,5x5,7x7) again and calculate the weights for each xtal
      for (i=0; i<Nxtals; i++) 
        {               
          w = eventSquare[i] * invsumXmatrix;

          iFull = indexSqr2Reg(i, maxCeta, maxCphi);
          if (iFull >= 0)
            {
              // with event weighting:
              wsum[iFull] += w*eventw;
              Ewsum[iFull] += (w*eventw * energy * invsumXmatrix);
              //              wsum[iFull] += w;
              //              Ewsum[iFull] += (w * energy * invsumXmatrix);
            }
        }
    }
  //  else {std::cout << " Debug: dropping null event: " << countEvents << std::endl;}
}
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().

{
  std::vector<float> solution(Nchannels,1.);

  for (int i=0; i<Nchannels; i++) 
    {
      if (wsum[i] != 0.) 
        { solution[i]*=Ewsum[i]/wsum[i];}
      //      else 
      //        { std::cout << "warning - no event data for crystal index (reduced region) " << i << std::endl; }
    }
  
  if (resetsolution) resetSolution();

  return solution;
}
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().

{
  int regionIndex;

  // get the current eta, phi indices
  int curr_eta = maxCeta - squareMode/2 + sqrIndex%squareMode;
  if (curr_eta * maxCeta <= 0) {if (maxCeta > 0) curr_eta--; else curr_eta++; }  // JUMP over 0

  int curr_phi = maxCphi - squareMode/2 + sqrIndex/squareMode;
  if (curr_phi < 1) curr_phi += 360;
  if (curr_phi > 360) curr_phi -= 360;

  bool negPhiDirection = (maxphi < minphi);
  int iFullphi;

  regionIndex = -1;

  if (curr_eta >= mineta && curr_eta <= maxeta)
    if ( (!negPhiDirection && (curr_phi >= minphi && curr_phi <= maxphi)) ||
         (negPhiDirection && !(curr_phi >= minphi && curr_phi <= maxphi))      ) 
      {
        iFullphi = curr_phi - minphi;
        if (iFullphi < 0) iFullphi += 360;
        regionIndex = (curr_eta - mineta) * (maxphi - minphi + 1 + 360*negPhiDirection) + iFullphi;
      }

  return regionIndex;
}
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, recalibrateEvent(), and pileupReCalc_HLTpaths::scale.

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

{
  int Nevents = eventMatrix.size(); // Number of events to calibrate with

  std::vector<float> totalSolution(Nchannels,1.);
  std::vector<float> iterSolution;
  std::vector<std::vector<float> > myEventMatrix(eventMatrix);
  std::vector<float> myEnergyVector(energyVector);

  int i, j;

  // Iterate the correction
  for (int iter=1;iter<=nIter;iter++) 
    {

      // if normalization flag is set, normalize energies
      float sumOverEnergy;
      if (normalizeFlag)
        {
          float scale = 0.;
          
          for (i=0; i<Nevents; i++)
            {
              sumOverEnergy = 0.;
              for (j=0; j<Nxtals; j++) {sumOverEnergy += myEventMatrix[i][j];}
              sumOverEnergy /= myEnergyVector[i];
              scale += sumOverEnergy;
            }
          scale /= Nevents;
          
          for (i=0; i<Nevents; i++) {myEnergyVector[i] *= scale;}         
        } // end normalize energies

      // now the real work starts:
      for (int iEvt=0; iEvt < Nevents; iEvt++)
        {
          addEvent(myEventMatrix[iEvt], VmaxCeta[iEvt], VmaxCphi[iEvt], myEnergyVector[iEvt]);
        }
      iterSolution = getSolution();
      if (iterSolution.empty()) return iterSolution;

      // re-calibrate eventMatrix with solution
      for (int ievent = 0; ievent<Nevents; ievent++)
        {
          myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
        }

      for (int i=0; i<Nchannels; i++) 
        {
          // save solution into theCalibVector
          totalSolution[i] *= iterSolution[i];
        }
      //      resetSolution(); // reset for new iteration, now: getSolution does it automatically if not vetoed
    } // end iterate correction

  return totalSolution;
}
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().

{
  std::vector<float> newEventSquare(eventSquare);
  int iFull;

  for (int i=0; i<Nxtals; i++) 
    {
      iFull = indexSqr2Reg(i, maxCeta, maxCphi);
      if (iFull >=0)
        newEventSquare[i] *= recalibrateVector[iFull];
    }
  return newEventSquare;
}
void MinL3Algorithm::resetSolution ( )

reset for new iteration

Definition at line 150 of file MinL3Algorithm.cc.

References Ewsum, Nchannels, and wsum.

Referenced by getSolution().

{
  wsum.assign(Nchannels,0.);
  Ewsum.assign(Nchannels,0.);
}

Member Data Documentation

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

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

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