1 #ifndef MinL3AlgoUniv_H
2 #define MinL3AlgoUniv_H
25 typedef std::map<IDdet,float>
IDmap;
42 IDmap iterate(
const std::vector<std::vector<float> >& eventMatrix,
const std::vector<std::vector<IDdet> >& idMatrix,
const std::vector<float>& energyVector,
const int& nIter,
const bool& normalizeFlag =
false);
45 void addEvent(
const std::vector<float>& myCluster,
const std::vector<IDdet>& idCluster,
const float&
energy);
48 std::vector<float>
recalibrateEvent(
const std::vector<float>& myCluster,
const std::vector<IDdet>& idCluster,
const IDmap& newCalibration);
70 :kweight(kweight_), countEvents(0)
85 int Nevents = eventMatrix.size();
89 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
90 std::vector<float> myEnergyVector(energyVector);
95 for (
int iter=1;iter<=nIter;iter++)
104 for (i=0; i<Nevents; i++)
107 for (
unsigned j=0;
j<myEventMatrix[
i].size();
j++) {sumOverEnergy += myEventMatrix[
i][
j];}
108 sumOverEnergy /= myEnergyVector[
i];
109 scale += sumOverEnergy;
113 for (i=0; i<Nevents; i++) {myEnergyVector[
i] *= scale;}
117 for (
int iEvt=0; iEvt < Nevents; iEvt++)
119 addEvent(myEventMatrix[iEvt], idMatrix[iEvt], myEnergyVector[iEvt]);
121 iterSolution = getSolution();
122 if (iterSolution.empty())
return iterSolution;
125 for (
int ievent = 0; ievent<Nevents; ievent++)
127 myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], idMatrix[ievent], iterSolution);
131 for (
iter_IDmap i = iterSolution.begin(); i != iterSolution.end(); i++)
133 iter_IDmap itotal = totalSolution.find(i->first);
134 if (itotal == totalSolution.end())
136 totalSolution.insert(
IDmapvalue(i->first,i->second));
140 itotal->second *= i->second;
147 return totalSolution;
151 template<
class IDdet>
156 float w, invsumXmatrix;
161 for (
unsigned i=0;
i<myCluster.size();
i++) { sumXmatrix += myCluster[
i]; }
164 eventw = 1 - fabs(1 - sumXmatrix/energy);
165 eventw =
pow(eventw,kweight);
167 if (sumXmatrix != 0.)
169 invsumXmatrix = 1/sumXmatrix;
171 for (
unsigned i=0;
i<myCluster.size();
i++)
173 w = myCluster[
i] * invsumXmatrix;
177 if (iwsum == wsum.end()) wsum.insert(
IDmapvalue(idCluster[i],w*eventw));
178 else iwsum->second += w*eventw;
181 if (iEwsum == Ewsum.end()) Ewsum.insert(
IDmapvalue(idCluster[i], (w*eventw * energy * invsumXmatrix) ));
182 else iEwsum->second += (w*eventw * energy * invsumXmatrix);
189 template<
class IDdet>
198 if (
i->second != 0) myValue = iEwsum->second /
i->second;
203 if (resetsolution) resetSolution();
209 template<
class IDdet>
217 template<
class IDdet>
220 std::vector<float> newCluster(myCluster);
222 for (
unsigned i=0;
i<myCluster.size();
i++)
225 if (icalib != newCalibration.end())
227 newCluster[
i] *= icalib->second;
231 std::cout <<
"No calibration available for this element." << std::endl;
240 #endif // MinL3AlgoUniv_H
void addEvent(const std::vector< float > &myCluster, const std::vector< IDdet > &idCluster, const float &energy)
add event to the calculation of the calibration vector
Container::value_type value_type
IDmap::value_type IDmapvalue
IDmap::iterator iter_IDmap
~MinL3AlgoUniv()
Destructor.
std::vector< float > recalibrateEvent(const std::vector< float > &myCluster, const std::vector< IDdet > &idCluster, const IDmap &newCalibration)
recalibrate before next iteration: give previous solution vector as argument
MinL3AlgoUniv(float kweight_=0.)
std::map< IDdet, float > IDmap
void resetSolution()
reset for new iteration
IDmap getSolution(const bool resetsolution=true)
IDmap iterate(const std::vector< std::vector< float > > &eventMatrix, const std::vector< std::vector< IDdet > > &idMatrix, const std::vector< float > &energyVector, const int &nIter, const bool &normalizeFlag=false)
Power< A, B >::type pow(const A &a, const B &b)
IDmap::const_iterator citer_IDmap