13 : squareMode(squareMode_), countEvents(0), mineta(mineta_), maxeta(maxeta_), minphi(minphi_), maxphi(maxphi_) {
31 const std::vector<int>& VmaxCeta,
32 const std::vector<int>& VmaxCphi,
33 const std::vector<float>& energyVector,
35 const int& regLength) {
41 std::vector<float> totalSolution(
Nchannels, 1.);
42 std::vector<float> iterSolution(
Nchannels, 1.);
43 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
46 for (
int iter = 1; iter <= nIter; iter++) {
48 for (
unsigned int ireg = 0; ireg <
regMinEta.size(); ireg++) {
49 std::vector<float> regIterSolution, regEnergyVector;
50 std::vector<int> regVmaxCeta, regVmaxCphi;
51 std::vector<std::vector<float> > regEventMatrix;
58 for (
unsigned int ia = 0; ia < VmaxCeta.size(); ia++) {
62 regVmaxCeta.push_back(VmaxCeta[ia]);
63 regVmaxCphi.push_back(VmaxCphi[ia]);
65 std::vector<float> regEvent = myEventMatrix[ia];
66 float regEnergy = energyVector[ia];
68 int iFullReg = regionalHH.
indexSqr2Reg(
i2, VmaxCeta[ia], VmaxCphi[ia]);
71 regEnergy -= regEvent[
i2];
75 regEventMatrix.push_back(regEvent);
76 regEnergyVector.push_back(regEnergy);
83 regIterSolution = regionalHH.
iterate(regEventMatrix, regVmaxCeta, regVmaxCphi, regEnergyVector);
88 for (
unsigned int i1 = 0;
i1 < regIterSolution.size();
i1++) {
89 int regFrame = regLength / 2;
91 int currRegEta =
i1 / currRegPhiRange +
regMinEta[ireg];
92 int currRegPhi =
i1 % currRegPhiRange + regMinPhi[ireg];
95 if ((currRegEta >= (regMinEta[ireg] + regFrame * (!(regMinEta[ireg] ==
mineta)))) &&
97 (currRegPhi >= (regMinPhi[ireg] + regFrame * (!(regMinPhi[ireg] ==
minphi)))) &&
100 iterSolution[newindex] = regIterSolution[
i1];
105 if (iterSolution.empty())
109 for (
int ievent = 0; ievent <
Nevents; ievent++) {
110 myEventMatrix[ievent] =
recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
115 totalSolution[
i] *= iterSolution[
i];
120 return totalSolution;
124 const std::vector<int>& VmaxCeta,
125 const std::vector<int>& VmaxCphi,
126 const std::vector<float>& energyVector,
128 const bool& normalizeFlag) {
131 std::vector<float> totalSolution(
Nchannels, 1.);
132 std::vector<float> iterSolution;
133 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
134 std::vector<float> myEnergyVector(energyVector);
139 for (
int iter = 1; iter <= nIter; iter++) {
145 for (i = 0; i <
Nevents; i++) {
147 for (j = 0; j <
Nxtals; j++) {
148 sumOverEnergy += myEventMatrix[
i][
j];
150 sumOverEnergy /= myEnergyVector[
i];
151 scale += sumOverEnergy;
155 for (i = 0; i <
Nevents; i++) {
156 myEnergyVector[
i] *=
scale;
161 iterSolution =
iterate(myEventMatrix, VmaxCeta, VmaxCphi, myEnergyVector);
163 if (iterSolution.empty())
167 for (
int ievent = 0; ievent <
Nevents; ievent++) {
168 myEventMatrix[ievent] =
recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
173 totalSolution[
i] *= iterSolution[
i];
178 return totalSolution;
182 const std::vector<int>& VmaxCeta,
183 const std::vector<int>& VmaxCphi,
184 const std::vector<float>& energyVectorOrig) {
185 std::vector<float> solution;
190 std::cout <<
"Householder::runIter(): more channels to calibrate than events available. " << std::endl;
193 std::cout <<
" ****************** ERROR *********************" << std::endl;
201 std::cout <<
"Householder::runIter(): matrix dimensions non-conformant. " << std::endl;
202 std::cout <<
" energyVectorOrig.size()=" << energyVectorOrig.size() << std::endl;
204 std::cout <<
" ****************** ERROR *********************" << std::endl;
218 if (!decomposeSuccess) {
219 std::cout <<
"Householder::runIter(): Failed: Singular condition in decomposition." << std::endl;
220 std::cout <<
"***************** PROBLEM in DECOMPOSITION *************************" << std::endl;
225 float mydbleps = 2.22045e-16;
226 float etasqr = mydbleps * mydbleps;
235 for (i = 0; i <
Nevents; i++) {
251 normy0 += solution[
i] * solution[
i];
252 norme1 += e[
i] * e[
i];
261 if (norme1 > (0.0625 * normy0)) {
274 while (norme1 > (etasqr * normy0)) {
277 for (i = 0; i <
Nevents; i++) {
291 norme1 += e[
i] * e[
i];
296 if (norme1 > (0.0625 * norme0))
317 float beta, sigma, alphak, eventMatrixkk;
341 if (sum[j] > sigma) {
358 for (i = 0; i <
Nevents; i++) {
367 for (i = k; i <
Nevents; i++) {
386 if (eventMatrixkk < 0.)
393 beta = 1 / (sigma - eventMatrixkk * alphak);
400 for (i = k; i <
Nevents; i++) {
408 for (i = k; i <
Nevents; i++) {
431 for (i = j; i <
Nevents; i++) {
436 for (i = j; i <
Nevents; i++) {
443 for (i = Nchannels - 2; i >= 0; i--) {
461 const std::vector<float>& recalibrateVector) {
462 std::vector<float> newEventSquare(eventSquare);
468 newEventSquare[
i] *= recalibrateVector[iFull];
470 return newEventSquare;
478 if (curr_eta * maxCeta <= 0) {
497 if ((!negPhiDirection && (curr_phi >=
minphi && curr_phi <=
maxphi)) ||
498 (negPhiDirection && !(curr_phi >=
minphi && curr_phi <=
maxphi))) {
499 iFullphi = curr_phi -
minphi;
502 regionIndex = (curr_eta -
mineta) * (
maxphi - minphi + 1 + 360 * negPhiDirection) + iFullphi;
509 const std::vector<std::vector<float> >& eventMatrix,
510 const std::vector<int>& VmaxCeta,
511 const std::vector<int>& VmaxCphi) {
512 std::vector<std::vector<float> > fullMatrix;
521 foo[iFull] = eventMatrix[
i][
k];
523 fullMatrix.push_back(foo);
533 int remEta =
Neta % regLength;
534 if (remEta > regLength / 2)
536 int numSubRegEta =
Neta / regLength + (remEta < 0) * 1;
538 int addtoEta = remEta / numSubRegEta;
540 remEta % numSubRegEta;
543 int remPhi =
Nphi % regLength;
544 if (remPhi > regLength / 2)
546 int numSubRegPhi =
Nphi / regLength + (remPhi < 0) * 1;
548 int addtoPhi = remPhi / numSubRegPhi;
550 remPhi % numSubRegPhi;
553 int addedLengthEta = 0;
554 int addedLengthPhi = 0;
555 int startIndexEta =
mineta;
559 for (
int i = 0;
i < numSubRegEta;
i++) {
560 addedLengthEta = regLength + addtoEta + addtomoreEta /
abs(addtomoreEta) * (
i <
abs(addtomoreEta));
561 endIndexEta = startIndexEta + addedLengthEta - 1;
565 for (
int j = 0;
j < numSubRegPhi;
j++) {
566 addedLengthPhi = regLength + addtoPhi + addtomorePhi /
abs(addtomorePhi) * (
j <
abs(addtomorePhi));
567 endIndexPhi = startIndexPhi + addedLengthPhi - 1;
569 regMinPhi.push_back(startIndexPhi - regFrame * (
j != 0));
570 regMaxPhi.push_back(endIndexPhi + regFrame * (
j != (numSubRegPhi - 1)));
571 regMinEta.push_back(startIndexEta - regFrame * (
i != 0));
572 regMaxEta.push_back(endIndexEta + regFrame * (
i != (numSubRegEta - 1)));
574 startIndexPhi = endIndexPhi + 1;
576 startIndexEta = endIndexEta + 1;
void solve(std::vector< float > &y)
std::vector< std::vector< float > > eventMatrixProc
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 makeRegions(const int ®Length)
std::vector< int > regMinPhi
std::vector< int > regMinEta
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)
std::vector< int > regMaxEta
int indexSqr2Reg(const int &sqrIndex, const int &maxCeta, const int &maxCphi)
Method to translate from square indices to region indices.
Abs< T >::type abs(const T &t)
std::vector< float > energyVectorProc
std::vector< float > runRegional(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 int ®Length=5)
std::vector< std::vector< float > > unzipMatrix(const std::vector< std::vector< float > > &eventMatrix, const std::vector< int > &VmaxCeta, const std::vector< int > &VmaxCphi)
Unzips the skimmed matrix into a full matrix.
~HouseholderDecomposition()
Destructor.
HouseholderDecomposition(int squareMode_=5, int mineta_=1, int maxeta_=85, int minphi_=1, int maxphi_=20)
Default constructor.
std::vector< float > alpha
std::vector< std::vector< float > > eventMatrixOrig
std::vector< int > regMaxPhi