15 :squareMode(squareMode_), countEvents(0),mineta(mineta_), maxeta(maxeta_), minphi(minphi_), maxphi(maxphi_)
35 std::vector<float>
HouseholderDecomposition::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& regLength)
42 std::vector<float> totalSolution(
Nchannels,1.);
43 std::vector<float> iterSolution(
Nchannels,1.);
44 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
45 std::vector<float> myEnergyVector(energyVector);
48 for (
int iter=1;iter<=nIter;iter++)
51 for (
unsigned int ireg=0; ireg<
regMinEta.size(); ireg++)
53 std::vector<float> regIterSolution, regEnergyVector;
54 std::vector<int> regVmaxCeta, regVmaxCphi;
55 std::vector<std::vector<float> > regEventMatrix;
61 for (
unsigned int ia=0; ia<VmaxCeta.size(); ia++)
67 regVmaxCeta.push_back(VmaxCeta[ia]);
68 regVmaxCphi.push_back(VmaxCphi[ia]);
70 std::vector<float> regEvent = myEventMatrix[ia];
71 float regEnergy = energyVector[ia];
72 for (
int i2=0; i2<
Nxtals; i2++)
74 int iFullReg = regionalHH.
indexSqr2Reg(i2, VmaxCeta[ia], VmaxCphi[ia]);
77 regEnergy -= regEvent[i2];
81 regEventMatrix.push_back(regEvent);
82 regEnergyVector.push_back(regEnergy);
89 regIterSolution = regionalHH.
iterate(regEventMatrix, regVmaxCeta, regVmaxCphi, regEnergyVector);
94 for (
unsigned int i1=0; i1<regIterSolution.size(); i1++)
96 int regFrame = regLength/2;
98 int currRegEta = i1 / currRegPhiRange +
regMinEta[ireg];
99 int currRegPhi = i1 % currRegPhiRange + regMinPhi[ireg];
102 if ( (currRegEta >= (regMinEta[ireg]+regFrame*(!(regMinEta[ireg]==
mineta))) ) &&
104 (currRegPhi >= (regMinPhi[ireg]+regFrame*(!(regMinPhi[ireg]==
minphi))) ) &&
108 iterSolution[newindex] = regIterSolution[i1];
113 if (iterSolution.empty())
return iterSolution;
116 for (
int ievent = 0; ievent<
Nevents; ievent++)
118 myEventMatrix[ievent] =
recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
124 totalSolution[
i] *= iterSolution[
i];
129 return totalSolution;
134 std::vector<float>
HouseholderDecomposition::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)
138 std::vector<float> totalSolution(
Nchannels,1.);
139 std::vector<float> iterSolution;
140 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
141 std::vector<float> myEnergyVector(energyVector);
146 for (
int iter=1;iter<=nIter;iter++)
158 for (j=0; j<
Nxtals; j++) {sumOverEnergy += myEventMatrix[
i][
j];}
159 sumOverEnergy /= myEnergyVector[
i];
160 scale += sumOverEnergy;
170 iterSolution =
iterate(myEventMatrix,VmaxCeta,VmaxCphi,myEnergyVector);
172 if (iterSolution.empty())
return iterSolution;
175 for (
int ievent = 0; ievent<
Nevents; ievent++)
177 myEventMatrix[ievent] =
recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
183 totalSolution[
i] *= iterSolution[
i];
188 return totalSolution;
193 std::vector<float>
HouseholderDecomposition::iterate(
const std::vector<std::vector<float> >& eventMatrix,
const std::vector<int>& VmaxCeta,
const std::vector<int>& VmaxCphi,
const std::vector<float>& energyVectorOrig)
195 std::vector<float> solution;
201 std::cout <<
"Householder::runIter(): more channels to calibrate than events available. " << std::endl;
204 std::cout <<
" ****************** ERROR *********************" << std::endl;
213 std::cout <<
"Householder::runIter(): matrix dimensions non-conformant. " << std::endl;
214 std::cout <<
" energyVectorOrig.size()=" << energyVectorOrig.size() << std::endl;
216 std::cout <<
" ****************** ERROR *********************" << std::endl;
232 if( !decomposeSuccess )
234 std::cout <<
"Householder::runIter(): Failed: Singular condition in decomposition."<< std::endl;
235 std::cout <<
"***************** PROBLEM in DECOMPOSITION *************************"<<std::endl;
240 float mydbleps = 2.22045e-16;
241 float etasqr = mydbleps*mydbleps;
275 normy0 += solution[
i] * solution[
i];
276 norme1 += e[
i] * e[
i];
285 if (norme1>(0.0625*normy0))
300 while (norme1>(etasqr*normy0))
326 if (norme1>(0.0625*norme0))
break;
350 float beta,sigma,alphak,eventMatrixkk;
428 if (eventMatrixkk < 0.)
435 beta = 1 / (sigma - eventMatrixkk * alphak);
494 for (i=Nchannels-2; i>=0; i--)
516 std::vector<float> newEventSquare(eventSquare);
523 newEventSquare[
i] *= recalibrateVector[iFull];
525 return newEventSquare;
535 if (curr_eta * maxCeta <= 0) {
if (maxCeta > 0) curr_eta--;
else curr_eta++; }
538 if (curr_phi < 1) curr_phi += 360;
539 if (curr_phi > 360) curr_phi -= 360;
547 if ( (!negPhiDirection && (curr_phi >=
minphi && curr_phi <=
maxphi)) ||
548 (negPhiDirection && !(curr_phi >=
minphi && curr_phi <=
maxphi)) )
550 iFullphi = curr_phi -
minphi;
551 if (iFullphi < 0) iFullphi += 360;
552 regionIndex = (curr_eta -
mineta) * (
maxphi - minphi + 1 + 360*negPhiDirection) + iFullphi;
560 std::vector< std::vector<float> > fullMatrix;
571 foo[iFull] = eventMatrix[
i][
k];
573 fullMatrix.push_back(foo);
584 int remEta =
Neta % regLength;
585 if (remEta > regLength/2) remEta -= regLength;
586 int numSubRegEta =
Neta / regLength + (remEta < 0)*1;
588 int addtoEta = remEta / numSubRegEta;
589 int addtomoreEta = remEta % numSubRegEta;
592 int remPhi =
Nphi % regLength;
593 if (remPhi > regLength/2) remPhi -= regLength;
594 int numSubRegPhi =
Nphi / regLength + (remPhi < 0)*1;
596 int addtoPhi = remPhi / numSubRegPhi;
597 int addtomorePhi = remPhi % numSubRegPhi;
600 int addedLengthEta = 0;
601 int addedLengthPhi = 0;
602 int startIndexEta =
mineta;
606 for (
int i=0;
i < numSubRegEta;
i++)
608 addedLengthEta = regLength + addtoEta + addtomoreEta/
abs(addtomoreEta)*(
i<
abs(addtomoreEta));
609 endIndexEta = startIndexEta + addedLengthEta - 1;
613 for (
int j=0;
j < numSubRegPhi;
j++)
615 addedLengthPhi = regLength + addtoPhi + addtomorePhi/
abs(addtomorePhi)*(
j<
abs(addtomorePhi));
616 endIndexPhi = startIndexPhi + addedLengthPhi - 1;
618 regMinPhi.push_back(startIndexPhi - regFrame*(
j!=0) );
619 regMaxPhi.push_back(endIndexPhi + regFrame*(
j!=(numSubRegPhi-1)) );
620 regMinEta.push_back(startIndexEta - regFrame*(
i!=0) );
621 regMaxEta.push_back(endIndexEta + regFrame*(
i!=(numSubRegEta-1)) );
623 startIndexPhi = endIndexPhi + 1;
625 startIndexEta = endIndexEta + 1;
void solve(std::vector< float > &y)
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.
std::vector< std::vector< float > > eventMatrixProc
std::vector< std::vector< float > > eventMatrixOrig
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< int > regMaxPhi