CMS 3D CMS Logo

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

◆ citer_IDmap

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

Definition at line 25 of file MinL3AlgoUniv.h.

◆ IDmap

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

Definition at line 22 of file MinL3AlgoUniv.h.

◆ IDmapvalue

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

Definition at line 23 of file MinL3AlgoUniv.h.

◆ iter_IDmap

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

Definition at line 24 of file MinL3AlgoUniv.h.

Constructor & Destructor Documentation

◆ MinL3AlgoUniv()

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

Default constructor kweight_ = event weight

Definition at line 68 of file MinL3AlgoUniv.h.

68  : kweight(kweight_), countEvents(0) {
69  resetSolution();
70 }

◆ ~MinL3AlgoUniv()

template<class IDdet >
MinL3AlgoUniv< IDdet >::~MinL3AlgoUniv ( )

Destructor.

Definition at line 73 of file MinL3AlgoUniv.h.

73 {}

Member Function Documentation

◆ addEvent()

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

144  {
145  countEvents++;
146 
147  float w, invsumXmatrix;
148  float eventw;
149  // Loop over the crystal matrix to find the sum
150  float sumXmatrix = 0.;
151 
152  for (unsigned i = 0; i < myCluster.size(); i++) {
153  sumXmatrix += myCluster[i];
154  }
155 
156  // event weighting
157  eventw = 1 - fabs(1 - sumXmatrix / energy);
158  eventw = pow(eventw, kweight);
159 
160  if (sumXmatrix != 0.) {
161  invsumXmatrix = 1 / sumXmatrix;
162  // Loop over the crystal matrix (3x3,5x5,7x7) again and calculate the weights for each xtal
163  for (unsigned i = 0; i < myCluster.size(); i++) {
164  w = myCluster[i] * invsumXmatrix;
165 
166  // include the weights into wsum, Ewsum
167  iter_IDmap iwsum = wsum.find(idCluster[i]);
168  if (iwsum == wsum.end())
169  wsum.insert(IDmapvalue(idCluster[i], w * eventw));
170  else
171  iwsum->second += w * eventw;
172 
173  iter_IDmap iEwsum = Ewsum.find(idCluster[i]);
174  if (iEwsum == Ewsum.end())
175  Ewsum.insert(IDmapvalue(idCluster[i], (w * eventw * energy * invsumXmatrix)));
176  else
177  iEwsum->second += (w * eventw * energy * invsumXmatrix);
178  }
179  }
180  // else {std::cout << " Debug: dropping null event: " << countEvents << std::endl;}
181 }

Referenced by L3CalibBlock::Fill().

◆ getSolution()

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

184  {
185  IDmap solution;
186 
187  for (iter_IDmap i = wsum.begin(); i != wsum.end(); i++) {
188  iter_IDmap iEwsum = Ewsum.find(i->first);
189  float myValue = 1;
190  if (i->second != 0)
191  myValue = iEwsum->second / i->second;
192 
193  solution.insert(IDmapvalue(i->first, myValue));
194  }
195 
196  if (resetsolution)
197  resetSolution();
198 
199  return solution;
200 }

Referenced by L3CalibBlock::solve().

◆ iterate()

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

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

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

◆ recalibrateEvent()

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

211  {
212  std::vector<float> newCluster(myCluster);
213 
214  for (unsigned i = 0; i < myCluster.size(); i++) {
215  citer_IDmap icalib = newCalibration.find(idCluster[i]);
216  if (icalib != newCalibration.end()) {
217  newCluster[i] *= icalib->second;
218  } else {
219  std::cout << "No calibration available for this element." << std::endl;
220  }
221  }
222 
223  return newCluster;
224 }

◆ resetSolution()

template<class IDdet >
void MinL3AlgoUniv< IDdet >::resetSolution ( )

reset for new iteration

Definition at line 203 of file MinL3AlgoUniv.h.

203  {
204  wsum.clear();
205  Ewsum.clear();
206 }

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

Member Data Documentation

◆ countEvents

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

Definition at line 62 of file MinL3AlgoUniv.h.

◆ Ewsum

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

Definition at line 64 of file MinL3AlgoUniv.h.

◆ kweight

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

Definition at line 61 of file MinL3AlgoUniv.h.

◆ wsum

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

Definition at line 63 of file MinL3AlgoUniv.h.

mps_fire.i
i
Definition: mps_fire.py:428
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MinL3AlgoUniv::getSolution
IDmap getSolution(const bool resetsolution=true)
Definition: MinL3AlgoUniv.h:184
MinL3AlgoUniv::Ewsum
IDmap Ewsum
Definition: MinL3AlgoUniv.h:64
MinL3AlgoUniv::countEvents
int countEvents
Definition: MinL3AlgoUniv.h:62
MinL3AlgoUniv::IDmapvalue
IDmap::value_type IDmapvalue
Definition: MinL3AlgoUniv.h:23
MinL3AlgoUniv::iter_IDmap
IDmap::iterator iter_IDmap
Definition: MinL3AlgoUniv.h:24
w
const double w
Definition: UKUtility.cc:23
MinL3AlgoUniv::citer_IDmap
IDmap::const_iterator citer_IDmap
Definition: MinL3AlgoUniv.h:25
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
MinL3AlgoUniv::resetSolution
void resetSolution()
reset for new iteration
Definition: MinL3AlgoUniv.h:203
MinL3AlgoUniv::wsum
IDmap wsum
Definition: MinL3AlgoUniv.h:63
MinL3AlgoUniv::kweight
float kweight
Definition: MinL3AlgoUniv.h:61
MinL3AlgoUniv::recalibrateEvent
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
Definition: MinL3AlgoUniv.h:209
MinL3AlgoUniv::IDmap
std::map< IDdet, float > IDmap
Definition: MinL3AlgoUniv.h:22
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
MinL3AlgoUniv::addEvent
void addEvent(const std::vector< float > &myCluster, const std::vector< IDdet > &idCluster, const float &energy)
add event to the calculation of the calibration vector
Definition: MinL3AlgoUniv.h:142