CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Attributes
MinL3AlgoUniv< IDdet > Class Template Reference

#include <MinL3AlgoUniv.h>

Public Types

typedef IDmap::const_iterator citer_IDmap
 
typedef std::map< IDdet, float > IDmap
 
typedef IDmap::value_type IDmapvalue
 
typedef IDmap::iterator iter_IDmap
 

Public Member Functions

void addEvent (const std::vector< float > &myCluster, const std::vector< IDdet > &idCluster, const float &energy)
 add event to the calculation of the calibration vector More...
 
IDmap getSolution (const bool resetsolution=true)
 
IDmap iterate (const std::vector< std::vector< float > > &eventMatrix, const std::vector< std::vector< IDdet > > &idMatrix, const std::vector< float > &energyVector, const int &nIter, const bool &normalizeFlag=false)
 
 MinL3AlgoUniv (float kweight_=0.)
 
std::vector< float > recalibrateEvent (const std::vector< float > &myCluster, const std::vector< IDdet > &idCluster, const IDmap &newCalibration)
 recalibrate before next iteration: give previous solution vector as argument More...
 
void resetSolution ()
 reset for new iteration More...
 
 ~MinL3AlgoUniv ()
 Destructor. More...
 

Private Attributes

int countEvents
 
IDmap Ewsum
 
float kweight
 
IDmap wsum
 

Detailed Description

template<class IDdet>
class MinL3AlgoUniv< IDdet >

Implementation of the L3 Collaboration algorithm to solve a system Ax = B by minimization of |Ax-B| using an iterative linear approach This class should be universal, i.e. working with DetIds or whatever else will be invented to identify Subdetector parts The bookkeeping of the cluster size and its elements has to be done by the user.

Date:
2007/08/23 12:38:02
Revision:
1.2
Author
R.Ofierzynski, CERN

Definition at line 22 of file MinL3AlgoUniv.h.

Member Typedef Documentation

template<class IDdet>
typedef IDmap::const_iterator MinL3AlgoUniv< IDdet >::citer_IDmap

Definition at line 28 of file MinL3AlgoUniv.h.

template<class IDdet>
typedef std::map<IDdet,float> MinL3AlgoUniv< IDdet >::IDmap

Definition at line 25 of file MinL3AlgoUniv.h.

template<class IDdet>
typedef IDmap::value_type MinL3AlgoUniv< IDdet >::IDmapvalue

Definition at line 26 of file MinL3AlgoUniv.h.

template<class IDdet>
typedef IDmap::iterator MinL3AlgoUniv< IDdet >::iter_IDmap

Definition at line 27 of file MinL3AlgoUniv.h.

Constructor & Destructor Documentation

template<class IDdet >
MinL3AlgoUniv< IDdet >::MinL3AlgoUniv ( float  kweight_ = 0.)

Default constructor kweight_ = event weight

Definition at line 69 of file MinL3AlgoUniv.h.

References MinL3AlgoUniv< IDdet >::resetSolution().

70  :kweight(kweight_), countEvents(0)
71 {
72  resetSolution();
73 }
void resetSolution()
reset for new iteration
template<class IDdet >
MinL3AlgoUniv< IDdet >::~MinL3AlgoUniv ( )

Destructor.

Definition at line 77 of file MinL3AlgoUniv.h.

78 {
79 }

Member Function Documentation

template<class IDdet>
void MinL3AlgoUniv< IDdet >::addEvent ( const std::vector< float > &  myCluster,
const std::vector< IDdet > &  idCluster,
const float &  energy 
)

add event to the calculation of the calibration vector

Definition at line 152 of file MinL3AlgoUniv.h.

References i, funct::pow(), and w().

Referenced by L3CalibBlock::Fill().

153 {
154  countEvents++;
155 
156  float w, invsumXmatrix;
157  float eventw;
158  // Loop over the crystal matrix to find the sum
159  float sumXmatrix=0.;
160 
161  for (unsigned i=0; i<myCluster.size(); i++) { sumXmatrix += myCluster[i]; }
162 
163  // event weighting
164  eventw = 1 - fabs(1 - sumXmatrix/energy);
165  eventw = pow(eventw,kweight);
166 
167  if (sumXmatrix != 0.)
168  {
169  invsumXmatrix = 1/sumXmatrix;
170  // Loop over the crystal matrix (3x3,5x5,7x7) again and calculate the weights for each xtal
171  for (unsigned i=0; i<myCluster.size(); i++)
172  {
173  w = myCluster[i] * invsumXmatrix;
174 
175  // include the weights into wsum, Ewsum
176  iter_IDmap iwsum = wsum.find(idCluster[i]);
177  if (iwsum == wsum.end()) wsum.insert(IDmapvalue(idCluster[i],w*eventw));
178  else iwsum->second += w*eventw;
179 
180  iter_IDmap iEwsum = Ewsum.find(idCluster[i]);
181  if (iEwsum == Ewsum.end()) Ewsum.insert(IDmapvalue(idCluster[i], (w*eventw * energy * invsumXmatrix) ));
182  else iEwsum->second += (w*eventw * energy * invsumXmatrix);
183  }
184  }
185  // else {std::cout << " Debug: dropping null event: " << countEvents << std::endl;}
186 }
int i
Definition: DBlmapReader.cc:9
IDmap::value_type IDmapvalue
Definition: MinL3AlgoUniv.h:26
IDmap::iterator iter_IDmap
Definition: MinL3AlgoUniv.h:27
T w() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
template<class IDdet >
MinL3AlgoUniv< IDdet >::IDmap MinL3AlgoUniv< IDdet >::getSolution ( const bool  resetsolution = true)

get the solution at the end of the calibration as a map between DetIds and calibration constant

Definition at line 190 of file MinL3AlgoUniv.h.

References i.

Referenced by L3CalibBlock::solve().

191 {
192  IDmap solution;
193 
194  for (iter_IDmap i = wsum.begin(); i != wsum.end(); i++)
195  {
196  iter_IDmap iEwsum = Ewsum.find(i->first);
197  float myValue = 1;
198  if (i->second != 0) myValue = iEwsum->second / i->second;
199 
200  solution.insert(IDmapvalue(i->first,myValue));
201  }
202 
203  if (resetsolution) resetSolution();
204 
205  return solution;
206 }
int i
Definition: DBlmapReader.cc:9
IDmap::value_type IDmapvalue
Definition: MinL3AlgoUniv.h:26
IDmap::iterator iter_IDmap
Definition: MinL3AlgoUniv.h:27
std::map< IDdet, float > IDmap
Definition: MinL3AlgoUniv.h:25
void resetSolution()
reset for new iteration
template<class IDdet>
MinL3AlgoUniv< IDdet >::IDmap MinL3AlgoUniv< IDdet >::iterate ( const std::vector< std::vector< float > > &  eventMatrix,
const std::vector< std::vector< IDdet > > &  idMatrix,
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

also to be used also as recipe on how to use the calibration methods << one-by-one with a re-selection of the events in between the iterations<<

Definition at line 83 of file MinL3AlgoUniv.h.

References i, j, and pileupReCalc_HLTpaths::scale.

Referenced by ElectronCalibrationUniv::endJob(), and hcalCalib::Terminate().

84 {
85  int Nevents = eventMatrix.size(); // Number of events to calibrate with
86 
87  IDmap totalSolution;
88  IDmap iterSolution;
89  std::vector<std::vector<float> > myEventMatrix(eventMatrix);
90  std::vector<float> myEnergyVector(energyVector);
91 
92  int i;
93 
94  // Iterate the correction
95  for (int iter=1;iter<=nIter;iter++)
96  {
97 
98  // if normalization flag is set, normalize energies
99  float sumOverEnergy;
100  if (normalizeFlag)
101  {
102  float scale = 0.;
103 
104  for (i=0; i<Nevents; i++)
105  {
106  sumOverEnergy = 0.;
107  for (unsigned j=0; j<myEventMatrix[i].size(); j++) {sumOverEnergy += myEventMatrix[i][j];}
108  sumOverEnergy /= myEnergyVector[i];
109  scale += sumOverEnergy;
110  }
111  scale /= Nevents;
112 
113  for (i=0; i<Nevents; i++) {myEnergyVector[i] *= scale;}
114  } // end normalize energies
115 
116  // now the real work starts:
117  for (int iEvt=0; iEvt < Nevents; iEvt++)
118  {
119  addEvent(myEventMatrix[iEvt], idMatrix[iEvt], myEnergyVector[iEvt]);
120  }
121  iterSolution = getSolution();
122  if (iterSolution.empty()) return iterSolution;
123 
124  // re-calibrate eventMatrix with solution
125  for (int ievent = 0; ievent<Nevents; ievent++)
126  {
127  myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], idMatrix[ievent], iterSolution);
128  }
129 
130  // save solution into theCalibVector
131  for (iter_IDmap i = iterSolution.begin(); i != iterSolution.end(); i++)
132  {
133  iter_IDmap itotal = totalSolution.find(i->first);
134  if (itotal == totalSolution.end())
135  {
136  totalSolution.insert(IDmapvalue(i->first,i->second));
137  }
138  else
139  {
140  itotal->second *= i->second;
141  }
142  }
143 
144  // resetSolution(); // reset for new iteration, now: getSolution does it automatically if not vetoed
145  } // end iterate correction
146 
147  return totalSolution;
148 }
int i
Definition: DBlmapReader.cc:9
void addEvent(const std::vector< float > &myCluster, const std::vector< IDdet > &idCluster, const float &energy)
add event to the calculation of the calibration vector
IDmap::value_type IDmapvalue
Definition: MinL3AlgoUniv.h:26
IDmap::iterator iter_IDmap
Definition: MinL3AlgoUniv.h:27
int j
Definition: DBlmapReader.cc:9
std::vector< float > recalibrateEvent(const std::vector< float > &myCluster, const std::vector< IDdet > &idCluster, const IDmap &newCalibration)
recalibrate before next iteration: give previous solution vector as argument
std::map< IDdet, float > IDmap
Definition: MinL3AlgoUniv.h:25
IDmap getSolution(const bool resetsolution=true)
template<class IDdet>
std::vector< float > MinL3AlgoUniv< IDdet >::recalibrateEvent ( const std::vector< float > &  myCluster,
const std::vector< IDdet > &  idCluster,
const IDmap newCalibration 
)

recalibrate before next iteration: give previous solution vector as argument

Definition at line 218 of file MinL3AlgoUniv.h.

References gather_cfg::cout, and i.

219 {
220  std::vector<float> newCluster(myCluster);
221 
222  for (unsigned i=0; i<myCluster.size(); i++)
223  {
224  citer_IDmap icalib = newCalibration.find(idCluster[i]);
225  if (icalib != newCalibration.end())
226  {
227  newCluster[i] *= icalib->second;
228  }
229  else
230  {
231  std::cout << "No calibration available for this element." << std::endl;
232  }
233 
234  }
235 
236  return newCluster;
237 }
int i
Definition: DBlmapReader.cc:9
tuple cout
Definition: gather_cfg.py:121
IDmap::const_iterator citer_IDmap
Definition: MinL3AlgoUniv.h:28
template<class IDdet >
void MinL3AlgoUniv< IDdet >::resetSolution ( )

reset for new iteration

Definition at line 210 of file MinL3AlgoUniv.h.

Referenced by MinL3AlgoUniv< IDdet >::MinL3AlgoUniv(), and L3CalibBlock::reset().

211 {
212  wsum.clear();
213  Ewsum.clear();
214 }

Member Data Documentation

template<class IDdet>
int MinL3AlgoUniv< IDdet >::countEvents
private

Definition at line 60 of file MinL3AlgoUniv.h.

template<class IDdet>
IDmap MinL3AlgoUniv< IDdet >::Ewsum
private

Definition at line 62 of file MinL3AlgoUniv.h.

template<class IDdet>
float MinL3AlgoUniv< IDdet >::kweight
private

Definition at line 59 of file MinL3AlgoUniv.h.

template<class IDdet>
IDmap MinL3AlgoUniv< IDdet >::wsum
private

Definition at line 61 of file MinL3AlgoUniv.h.