1 #ifndef MinL3AlgoUniv_H
2 #define MinL3AlgoUniv_H
23 typedef std::map<IDdet,float>
IDmap;
40 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);
43 void addEvent(
const std::vector<float>& myCluster,
const std::vector<IDdet>& idCluster,
const float&
energy);
46 std::vector<float>
recalibrateEvent(
const std::vector<float>& myCluster,
const std::vector<IDdet>& idCluster,
const IDmap& newCalibration);
68 :kweight(kweight_), countEvents(0)
83 int Nevents = eventMatrix.size();
87 std::vector<std::vector<float> > myEventMatrix(eventMatrix);
88 std::vector<float> myEnergyVector(energyVector);
93 for (
int iter=1;iter<=nIter;iter++)
102 for (i=0; i<Nevents; i++)
105 for (
unsigned j=0;
j<myEventMatrix[
i].size();
j++) {sumOverEnergy += myEventMatrix[
i][
j];}
106 sumOverEnergy /= myEnergyVector[
i];
107 scale += sumOverEnergy;
111 for (i=0; i<Nevents; i++) {myEnergyVector[
i] *=
scale;}
115 for (
int iEvt=0; iEvt < Nevents; iEvt++)
117 addEvent(myEventMatrix[iEvt], idMatrix[iEvt], myEnergyVector[iEvt]);
119 iterSolution = getSolution();
120 if (iterSolution.empty())
return iterSolution;
123 for (
int ievent = 0; ievent<Nevents; ievent++)
125 myEventMatrix[ievent] = recalibrateEvent(myEventMatrix[ievent], idMatrix[ievent], iterSolution);
129 for (
iter_IDmap i = iterSolution.begin(); i != iterSolution.end(); i++)
131 iter_IDmap itotal = totalSolution.find(i->first);
132 if (itotal == totalSolution.end())
134 totalSolution.insert(
IDmapvalue(i->first,i->second));
138 itotal->second *= i->second;
145 return totalSolution;
149 template<
class IDdet>
154 float w, invsumXmatrix;
159 for (
unsigned i=0;
i<myCluster.size();
i++) { sumXmatrix += myCluster[
i]; }
162 eventw = 1 - fabs(1 - sumXmatrix/energy);
163 eventw =
pow(eventw,kweight);
165 if (sumXmatrix != 0.)
167 invsumXmatrix = 1/sumXmatrix;
169 for (
unsigned i=0;
i<myCluster.size();
i++)
171 w = myCluster[
i] * invsumXmatrix;
175 if (iwsum == wsum.end()) wsum.insert(
IDmapvalue(idCluster[i],w*eventw));
176 else iwsum->second += w*eventw;
179 if (iEwsum == Ewsum.end()) Ewsum.insert(
IDmapvalue(idCluster[i], (w*eventw * energy * invsumXmatrix) ));
180 else iEwsum->second += (w*eventw * energy * invsumXmatrix);
187 template<
class IDdet>
196 if (
i->second != 0) myValue = iEwsum->second /
i->second;
201 if (resetsolution) resetSolution();
207 template<
class IDdet>
215 template<
class IDdet>
218 std::vector<float> newCluster(myCluster);
220 for (
unsigned i=0;
i<myCluster.size();
i++)
223 if (icalib != newCalibration.end())
225 newCluster[
i] *= icalib->second;
229 std::cout <<
"No calibration available for this element." << std::endl;
238 #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
~MinL3AlgoUniv()
Destructor.
Container::value_type value_type
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