14 :normaliseFlag(normalise)
25 std::vector<float>
GenericMinL3Algorithm::iterate(
const std::vector<std::vector<float> >& eventMatrix,
const std::vector<float>& energyVector,
const int nIter)
27 std::vector<float> solution;
28 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
29 int Nevents = eventMatrix.size();
30 int Nchannels = eventMatrix[0].size();
31 std::vector<float> theCalibVector(Nchannels,1.);
34 for (
int iter=1;iter<=nIter;iter++)
37 solution =
iterate(myEventMatrix, energyVector);
39 if (solution.empty())
return solution;
43 for (
int i=0;
i<Nchannels;
i++)
45 for (
int ievent = 0; ievent<Nevents; ievent++)
47 myEventMatrix[ievent][
i] *= solution[
i];
50 theCalibVector[
i] *= solution[
i];
55 return theCalibVector;
61 std::vector<float> solution;
62 std::vector<float> myEnergyVector(energyVector);
64 int Nevents = eventMatrix.size();
65 int Nchannels = eventMatrix[0].size();
68 if (Nevents !=
int(myEnergyVector.size()))
70 std::cout <<
"GenericMinL3Algorithm::iterate(): Error: bad matrix dimensions. Dropping out." << std::endl;
75 solution.assign(Nchannels,1.);
85 std::cout <<
"GenericMinL3Algorithm::iterate(): Normalising event data" << std::endl;
87 for (i=0; i<Nevents; i++)
90 for (j=0; j<Nchannels; j++) {sumOverEnergy += eventMatrix[
i][
j];}
91 sumOverEnergy /= myEnergyVector[
i];
92 scale += sumOverEnergy;
95 std::cout <<
" Normalisation = " << scale << std::endl;
97 for (i=0; i<Nevents; i++) {myEnergyVector[
i] *=
scale;}
102 float sum25, invsum25;
104 std::vector<float> wsum(Nchannels,0.);
105 std::vector<float> Ewsum(Nchannels,0.);
108 for (ievent = 0; ievent<Nevents; ievent++)
113 for (i=0; i<Nchannels; i++) { sum25+=eventMatrix[ievent][
i]; }
119 for (i=0; i<Nchannels; i++)
121 w = eventMatrix[ievent][
i] * invsum25;
123 Ewsum[
i] += (w * myEnergyVector[ievent] * invsum25);
126 else {
std::cout <<
" Debug: dropping null event: " << ievent << std::endl;}
131 for (i=0; i<Nchannels; i++)
134 { solution[
i]*=Ewsum[
i]/wsum[
i]; }
136 {
std::cout <<
"warning - no event data for crystal index " << i << std::endl; }
std::vector< float > iterate(const std::vector< std::vector< float > > &eventMatrix, const std::vector< float > &energyVector, int nIter)
~GenericMinL3Algorithm()
Destructor.
GenericMinL3Algorithm(bool normalise=false)