1 #ifndef MinL3AlgoUniv_H
2 #define MinL3AlgoUniv_H
19 template <
class IDdet>
22 typedef std::map<IDdet, float>
IDmap;
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>
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++) {
127 iter_IDmap itotal = totalSolution.find(i->first);
128 if (itotal == totalSolution.end()) {
129 totalSolution.insert(
IDmapvalue(i->first, i->second));
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())
169 wsum.insert(
IDmapvalue(idCluster[i], w * eventw));
171 iwsum->second += w * eventw;
174 if (iEwsum == Ewsum.end())
175 Ewsum.insert(
IDmapvalue(idCluster[i], (w * eventw * energy * invsumXmatrix)));
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
void addEvent(const std::vector< float > &myCluster, const std::vector< IDdet > &idCluster, const float &energy)
add event to the calculation of the calibration vector
IDmap::value_type IDmapvalue
IDmap::iterator iter_IDmap
std::map< IDdet, float > IDmap
Container::value_type value_type
~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.)
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