13 :squareMode(squareMode_), countEvents(0),mineta(mineta_), maxeta(maxeta_), minphi(minphi_), maxphi(maxphi_)
33 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)
40 std::vector<float> totalSolution(
Nchannels,1.);
41 std::vector<float> iterSolution(
Nchannels,1.);
42 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
45 for (
int iter=1;iter<=nIter;iter++)
48 for (
unsigned int ireg=0; ireg<
regMinEta.size(); ireg++)
50 std::vector<float> regIterSolution, regEnergyVector;
51 std::vector<int> regVmaxCeta, regVmaxCphi;
52 std::vector<std::vector<float> > regEventMatrix;
58 for (
unsigned int ia=0; ia<VmaxCeta.size(); ia++)
64 regVmaxCeta.push_back(VmaxCeta[ia]);
65 regVmaxCphi.push_back(VmaxCphi[ia]);
67 std::vector<float> regEvent = myEventMatrix[ia];
68 float regEnergy = energyVector[ia];
69 for (
int i2=0; i2<
Nxtals; i2++)
71 int iFullReg = regionalHH.
indexSqr2Reg(i2, VmaxCeta[ia], VmaxCphi[ia]);
74 regEnergy -= regEvent[i2];
78 regEventMatrix.push_back(regEvent);
79 regEnergyVector.push_back(regEnergy);
86 regIterSolution = regionalHH.
iterate(regEventMatrix, regVmaxCeta, regVmaxCphi, regEnergyVector);
91 for (
unsigned int i1=0; i1<regIterSolution.size(); i1++)
93 int regFrame = regLength/2;
95 int currRegEta = i1 / currRegPhiRange +
regMinEta[ireg];
96 int currRegPhi = i1 % currRegPhiRange + regMinPhi[ireg];
99 if ( (currRegEta >= (regMinEta[ireg]+regFrame*(!(regMinEta[ireg]==
mineta))) ) &&
101 (currRegPhi >= (regMinPhi[ireg]+regFrame*(!(regMinPhi[ireg]==
minphi))) ) &&
105 iterSolution[newindex] = regIterSolution[i1];
110 if (iterSolution.empty())
return iterSolution;
113 for (
int ievent = 0; ievent<
Nevents; ievent++)
115 myEventMatrix[ievent] =
recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
121 totalSolution[
i] *= iterSolution[
i];
126 return totalSolution;
131 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)
135 std::vector<float> totalSolution(
Nchannels,1.);
136 std::vector<float> iterSolution;
137 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
138 std::vector<float> myEnergyVector(energyVector);
143 for (
int iter=1;iter<=nIter;iter++)
155 for (j=0; j<
Nxtals; j++) {sumOverEnergy += myEventMatrix[
i][j];}
156 sumOverEnergy /= myEnergyVector[
i];
157 scale += sumOverEnergy;
167 iterSolution =
iterate(myEventMatrix,VmaxCeta,VmaxCphi,myEnergyVector);
169 if (iterSolution.empty())
return iterSolution;
172 for (
int ievent = 0; ievent<
Nevents; ievent++)
174 myEventMatrix[ievent] =
recalibrateEvent(myEventMatrix[ievent], VmaxCeta[ievent], VmaxCphi[ievent], iterSolution);
180 totalSolution[
i] *= iterSolution[
i];
185 return totalSolution;
190 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)
192 std::vector<float> solution;
198 std::cout <<
"Householder::runIter(): more channels to calibrate than events available. " << std::endl;
201 std::cout <<
" ****************** ERROR *********************" << std::endl;
210 std::cout <<
"Householder::runIter(): matrix dimensions non-conformant. " << std::endl;
211 std::cout <<
" energyVectorOrig.size()=" << energyVectorOrig.size() << std::endl;
213 std::cout <<
" ****************** ERROR *********************" << std::endl;
229 if( !decomposeSuccess )
231 std::cout <<
"Householder::runIter(): Failed: Singular condition in decomposition."<< std::endl;
232 std::cout <<
"***************** PROBLEM in DECOMPOSITION *************************"<<std::endl;
237 float mydbleps = 2.22045e-16;
238 float etasqr = mydbleps*mydbleps;
272 normy0 += solution[
i] * solution[
i];
273 norme1 += e[
i] * e[
i];
282 if (norme1>(0.0625*normy0))
297 while (norme1>(etasqr*normy0))
323 if (norme1>(0.0625*norme0))
break;
347 float beta,sigma,alphak,eventMatrixkk;
425 if (eventMatrixkk < 0.)
432 beta = 1 / (sigma - eventMatrixkk * alphak);
491 for (i=Nchannels-2; i>=0; i--)
513 std::vector<float> newEventSquare(eventSquare);
520 newEventSquare[
i] *= recalibrateVector[iFull];
522 return newEventSquare;
532 if (curr_eta * maxCeta <= 0) {
if (maxCeta > 0) curr_eta--;
else curr_eta++; }
535 if (curr_phi < 1) curr_phi += 360;
536 if (curr_phi > 360) curr_phi -= 360;
544 if ( (!negPhiDirection && (curr_phi >=
minphi && curr_phi <=
maxphi)) ||
545 (negPhiDirection && !(curr_phi >=
minphi && curr_phi <=
maxphi)) )
547 iFullphi = curr_phi -
minphi;
548 if (iFullphi < 0) iFullphi += 360;
549 regionIndex = (curr_eta -
mineta) * (
maxphi - minphi + 1 + 360*negPhiDirection) + iFullphi;
557 std::vector< std::vector<float> > fullMatrix;
568 foo[iFull] = eventMatrix[
i][
k];
570 fullMatrix.push_back(foo);
581 int remEta =
Neta % regLength;
582 if (remEta > regLength/2) remEta -= regLength;
583 int numSubRegEta =
Neta / regLength + (remEta < 0)*1;
585 int addtoEta = remEta / numSubRegEta;
586 int addtomoreEta = remEta % numSubRegEta;
589 int remPhi =
Nphi % regLength;
590 if (remPhi > regLength/2) remPhi -= regLength;
591 int numSubRegPhi =
Nphi / regLength + (remPhi < 0)*1;
593 int addtoPhi = remPhi / numSubRegPhi;
594 int addtomorePhi = remPhi % numSubRegPhi;
597 int addedLengthEta = 0;
598 int addedLengthPhi = 0;
599 int startIndexEta =
mineta;
603 for (
int i=0;
i < numSubRegEta;
i++)
605 addedLengthEta = regLength + addtoEta + addtomoreEta/
abs(addtomoreEta)*(
i<
abs(addtomoreEta));
606 endIndexEta = startIndexEta + addedLengthEta - 1;
610 for (
int j=0; j < numSubRegPhi; j++)
612 addedLengthPhi = regLength + addtoPhi + addtomorePhi/
abs(addtomorePhi)*(j<
abs(addtomorePhi));
613 endIndexPhi = startIndexPhi + addedLengthPhi - 1;
615 regMinPhi.push_back(startIndexPhi - regFrame*(j!=0) );
616 regMaxPhi.push_back(endIndexPhi + regFrame*(j!=(numSubRegPhi-1)) );
617 regMinEta.push_back(startIndexEta - regFrame*(
i!=0) );
618 regMaxEta.push_back(endIndexEta + regFrame*(
i!=(numSubRegEta-1)) );
620 startIndexPhi = endIndexPhi + 1;
622 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
Abs< T >::type abs(const T &t)
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