1 #ifndef MinL3AlgoUniv_H
2 #define MinL3AlgoUniv_H
19 template <
class IDdet>
22 typedef std::map<IDdet, float>
IDmap;
39 IDmap iterate(
const std::vector<std::vector<float> >& eventMatrix,
40 const std::vector<std::vector<IDdet> >& idMatrix,
41 const std::vector<float>& energyVector,
43 const bool& normalizeFlag =
false);
46 void addEvent(
const std::vector<float>& myCluster,
const std::vector<IDdet>& idCluster,
const float&
energy);
50 const std::vector<IDdet>& idCluster,
51 const IDmap& newCalibration);
67 template <
class IDdet>
72 template <
class IDdet>
75 template <
class IDdet>
77 const std::vector<std::vector<IDdet> >& idMatrix,
78 const std::vector<float>& energyVector,
80 const bool& normalizeFlag) {
81 int Nevents = eventMatrix.size();
85 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
86 std::vector<float> myEnergyVector(energyVector);
91 for (
int iter = 1; iter <= nIter; iter++) {
97 for (
i = 0;
i < Nevents;
i++) {
99 for (
unsigned j = 0;
j < myEventMatrix[
i].size();
j++) {
100 sumOverEnergy += myEventMatrix[
i][
j];
102 sumOverEnergy /= myEnergyVector[
i];
103 scale += sumOverEnergy;
107 for (
i = 0;
i < Nevents;
i++) {
108 myEnergyVector[
i] *=
scale;
113 for (
int iEvt = 0; iEvt < Nevents; iEvt++) {
114 addEvent(myEventMatrix[iEvt], idMatrix[iEvt], myEnergyVector[iEvt]);
116 iterSolution = getSolution();
117 if (iterSolution.empty())
121 for (
int ievent = 0; ievent < Nevents; ievent++) {
122 myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], idMatrix[ievent], iterSolution);
126 for (
iter_IDmap i = iterSolution.begin();
i != iterSolution.end();
i++) {
128 if (itotal == totalSolution.end()) {
131 itotal->second *=
i->second;
138 return totalSolution;
141 template <
class IDdet>
143 const std::vector<IDdet>& idCluster,
147 float w, invsumXmatrix;
150 float sumXmatrix = 0.;
152 for (
unsigned i = 0;
i < myCluster.size();
i++) {
153 sumXmatrix += myCluster[
i];
157 eventw = 1 - fabs(1 - sumXmatrix /
energy);
158 eventw =
pow(eventw, kweight);
160 if (sumXmatrix != 0.) {
161 invsumXmatrix = 1 / sumXmatrix;
163 for (
unsigned i = 0;
i < myCluster.size();
i++) {
164 w = myCluster[
i] * invsumXmatrix;
168 if (iwsum == wsum.end())
171 iwsum->second +=
w * eventw;
174 if (iEwsum == Ewsum.end())
177 iEwsum->second += (
w * eventw *
energy * invsumXmatrix);
183 template <
class IDdet>
191 myValue = iEwsum->second /
i->second;
202 template <
class IDdet>
208 template <
class IDdet>
210 const std::vector<IDdet>& idCluster,
211 const IDmap& newCalibration) {
212 std::vector<float> newCluster(myCluster);
214 for (
unsigned i = 0;
i < myCluster.size();
i++) {
216 if (icalib != newCalibration.end()) {
217 newCluster[
i] *= icalib->second;
219 std::cout <<
"No calibration available for this element." << std::endl;
226 #endif // MinL3AlgoUniv_H