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.

Author
R.Ofierzynski, CERN

Definition at line 20 of file MinL3AlgoUniv.h.

Member Typedef Documentation

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

Definition at line 26 of file MinL3AlgoUniv.h.

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

Definition at line 23 of file MinL3AlgoUniv.h.

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

Definition at line 24 of file MinL3AlgoUniv.h.

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

Definition at line 25 of file MinL3AlgoUniv.h.

Constructor & Destructor Documentation

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

Default constructor kweight_ = event weight

Definition at line 67 of file MinL3AlgoUniv.h.

References MinL3AlgoUniv< IDdet >::resetSolution().

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

Destructor.

Definition at line 75 of file MinL3AlgoUniv.h.

76 {
77 }

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 150 of file MinL3AlgoUniv.h.

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

Referenced by L3CalibBlock::Fill().

151 {
152  countEvents++;
153 
154  float w, invsumXmatrix;
155  float eventw;
156  // Loop over the crystal matrix to find the sum
157  float sumXmatrix=0.;
158 
159  for (unsigned i=0; i<myCluster.size(); i++) { sumXmatrix += myCluster[i]; }
160 
161  // event weighting
162  eventw = 1 - fabs(1 - sumXmatrix/energy);
163  eventw = pow(eventw,kweight);
164 
165  if (sumXmatrix != 0.)
166  {
167  invsumXmatrix = 1/sumXmatrix;
168  // Loop over the crystal matrix (3x3,5x5,7x7) again and calculate the weights for each xtal
169  for (unsigned i=0; i<myCluster.size(); i++)
170  {
171  w = myCluster[i] * invsumXmatrix;
172 
173  // include the weights into wsum, Ewsum
174  iter_IDmap iwsum = wsum.find(idCluster[i]);
175  if (iwsum == wsum.end()) wsum.insert(IDmapvalue(idCluster[i],w*eventw));
176  else iwsum->second += w*eventw;
177 
178  iter_IDmap iEwsum = Ewsum.find(idCluster[i]);
179  if (iEwsum == Ewsum.end()) Ewsum.insert(IDmapvalue(idCluster[i], (w*eventw * energy * invsumXmatrix) ));
180  else iEwsum->second += (w*eventw * energy * invsumXmatrix);
181  }
182  }
183  // else {std::cout << " Debug: dropping null event: " << countEvents << std::endl;}
184 }
int i
Definition: DBlmapReader.cc:9
IDmap::value_type IDmapvalue
Definition: MinL3AlgoUniv.h:24
IDmap::iterator iter_IDmap
Definition: MinL3AlgoUniv.h:25
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 188 of file MinL3AlgoUniv.h.

References i.

Referenced by L3CalibBlock::solve().

189 {
190  IDmap solution;
191 
192  for (iter_IDmap i = wsum.begin(); i != wsum.end(); i++)
193  {
194  iter_IDmap iEwsum = Ewsum.find(i->first);
195  float myValue = 1;
196  if (i->second != 0) myValue = iEwsum->second / i->second;
197 
198  solution.insert(IDmapvalue(i->first,myValue));
199  }
200 
201  if (resetsolution) resetSolution();
202 
203  return solution;
204 }
int i
Definition: DBlmapReader.cc:9
IDmap::value_type IDmapvalue
Definition: MinL3AlgoUniv.h:24
IDmap::iterator iter_IDmap
Definition: MinL3AlgoUniv.h:25
std::map< IDdet, float > IDmap
Definition: MinL3AlgoUniv.h:23
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 81 of file MinL3AlgoUniv.h.

References i, getDQMSummary::iter, j, and pileupReCalc_HLTpaths::scale.

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

82 {
83  int Nevents = eventMatrix.size(); // Number of events to calibrate with
84 
85  IDmap totalSolution;
86  IDmap iterSolution;
87  std::vector<std::vector<float> > myEventMatrix(eventMatrix);
88  std::vector<float> myEnergyVector(energyVector);
89 
90  int i;
91 
92  // Iterate the correction
93  for (int iter=1;iter<=nIter;iter++)
94  {
95 
96  // if normalization flag is set, normalize energies
97  float sumOverEnergy;
98  if (normalizeFlag)
99  {
100  float scale = 0.;
101 
102  for (i=0; i<Nevents; i++)
103  {
104  sumOverEnergy = 0.;
105  for (unsigned j=0; j<myEventMatrix[i].size(); j++) {sumOverEnergy += myEventMatrix[i][j];}
106  sumOverEnergy /= myEnergyVector[i];
107  scale += sumOverEnergy;
108  }
109  scale /= Nevents;
110 
111  for (i=0; i<Nevents; i++) {myEnergyVector[i] *= scale;}
112  } // end normalize energies
113 
114  // now the real work starts:
115  for (int iEvt=0; iEvt < Nevents; iEvt++)
116  {
117  addEvent(myEventMatrix[iEvt], idMatrix[iEvt], myEnergyVector[iEvt]);
118  }
119  iterSolution = getSolution();
120  if (iterSolution.empty()) return iterSolution;
121 
122  // re-calibrate eventMatrix with solution
123  for (int ievent = 0; ievent<Nevents; ievent++)
124  {
125  myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], idMatrix[ievent], iterSolution);
126  }
127 
128  // save solution into theCalibVector
129  for (iter_IDmap i = iterSolution.begin(); i != iterSolution.end(); i++)
130  {
131  iter_IDmap itotal = totalSolution.find(i->first);
132  if (itotal == totalSolution.end())
133  {
134  totalSolution.insert(IDmapvalue(i->first,i->second));
135  }
136  else
137  {
138  itotal->second *= i->second;
139  }
140  }
141 
142  // resetSolution(); // reset for new iteration, now: getSolution does it automatically if not vetoed
143  } // end iterate correction
144 
145  return totalSolution;
146 }
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:24
IDmap::iterator iter_IDmap
Definition: MinL3AlgoUniv.h:25
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:23
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 216 of file MinL3AlgoUniv.h.

References gather_cfg::cout, and i.

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

reset for new iteration

Definition at line 208 of file MinL3AlgoUniv.h.

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

209 {
210  wsum.clear();
211  Ewsum.clear();
212 }

Member Data Documentation

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

Definition at line 58 of file MinL3AlgoUniv.h.

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

Definition at line 60 of file MinL3AlgoUniv.h.

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

Definition at line 57 of file MinL3AlgoUniv.h.

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

Definition at line 59 of file MinL3AlgoUniv.h.