12 :normaliseFlag(normalise)
23 std::vector<float>
GenericMinL3Algorithm::iterate(
const std::vector<std::vector<float> >& eventMatrix,
const std::vector<float>& energyVector,
const int nIter)
25 std::vector<float> solution;
26 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
27 int Nevents = eventMatrix.size();
28 int Nchannels = eventMatrix[0].size();
29 std::vector<float> theCalibVector(Nchannels,1.);
32 for (
int iter=1;iter<=nIter;iter++)
35 solution =
iterate(myEventMatrix, energyVector);
37 if (solution.empty())
return solution;
41 for (
int i=0;
i<Nchannels;
i++)
43 for (
int ievent = 0; ievent<Nevents; ievent++)
45 myEventMatrix[ievent][
i] *= solution[
i];
48 theCalibVector[
i] *= solution[
i];
53 return theCalibVector;
59 std::vector<float> solution;
60 std::vector<float> myEnergyVector(energyVector);
62 int Nevents = eventMatrix.size();
63 int Nchannels = eventMatrix[0].size();
66 if (Nevents !=
int(myEnergyVector.size()))
68 std::cout <<
"GenericMinL3Algorithm::iterate(): Error: bad matrix dimensions. Dropping out." << std::endl;
73 solution.assign(Nchannels,1.);
83 std::cout <<
"GenericMinL3Algorithm::iterate(): Normalising event data" << std::endl;
85 for (i=0; i<Nevents; i++)
88 for (j=0; j<Nchannels; j++) {sumOverEnergy += eventMatrix[
i][
j];}
89 sumOverEnergy /= myEnergyVector[
i];
90 scale += sumOverEnergy;
93 std::cout <<
" Normalisation = " << scale << std::endl;
95 for (i=0; i<Nevents; i++) {myEnergyVector[
i] *=
scale;}
100 float sum25, invsum25;
102 std::vector<float> wsum(Nchannels,0.);
103 std::vector<float> Ewsum(Nchannels,0.);
106 for (ievent = 0; ievent<Nevents; ievent++)
111 for (i=0; i<Nchannels; i++) { sum25+=eventMatrix[ievent][
i]; }
117 for (i=0; i<Nchannels; i++)
119 w = eventMatrix[ievent][
i] * invsum25;
121 Ewsum[
i] += (w * myEnergyVector[ievent] * invsum25);
124 else {
std::cout <<
" Debug: dropping null event: " << ievent << std::endl;}
129 for (i=0; i<Nchannels; i++)
132 { solution[
i]*=Ewsum[
i]/wsum[
i]; }
134 {
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)