Go to the documentation of this file.00001
00008 #include "Calibration/EcalCalibAlgos/interface/IMACalibBlock.h"
00009 #include "Calibration/Tools/interface/BlockSolver.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Utilities/interface/isFinite.h"
00012 #include "TH1F.h"
00013 #include "TFile.h"
00014 #include <cassert>
00015
00016
00017
00018
00019 IMACalibBlock::IMACalibBlock (const int numberOfElements):
00020 VEcalCalibBlock (numberOfElements) ,
00021 m_kaliVector (m_numberOfElements) ,
00022 m_kaliMatrix (evalX2Size ())
00023 {
00024 reset () ;
00025 }
00026
00027
00028
00029
00030
00031 IMACalibBlock::~IMACalibBlock()
00032 {
00033 }
00034
00035
00036
00037
00038
00039 void
00040 IMACalibBlock::Fill (std::map<int,double>::const_iterator MapBegin,
00041 std::map<int,double>::const_iterator MapEnd ,
00042 double pTk,
00043 double pSubtract,
00044 double sigma)
00045 {
00046
00047 double inverror = 1./sigma ;
00048
00049 for (std::map<int,double>::const_iterator itMap1 =MapBegin ;
00050 itMap1 !=MapEnd ;
00051 ++itMap1)
00052 {
00053
00054 for (std::map<int,double>::const_iterator itMap2 = itMap1 ;
00055 itMap2 !=MapEnd ;
00056 ++itMap2)
00057 {
00058
00059 double dummy = itMap1->second * itMap2->second;
00060 dummy *= inverror ;
00061
00062 m_kaliMatrix.at(itMap1->first*m_numberOfElements +itMap2->first) += dummy ;
00063 }
00064
00065
00066 double dummy = pTk ;
00067 dummy -= pSubtract ;
00068 dummy *= itMap1->second ;
00069 dummy *= inverror ;
00070
00071 m_kaliVector.at(itMap1->first) += dummy ;
00072 }
00073 return ;
00074 }
00075
00076
00077
00078
00079
00080 void
00081 IMACalibBlock::complete ()
00082 {
00083 int bef;
00084 int aft;
00085 for (unsigned int i=0; i<m_numberOfElements;++i)
00086 {
00087 for (unsigned int j=i+1; j< m_numberOfElements; ++j)
00088 {
00089 bef = (i*m_numberOfElements+j);
00090 aft = (j*m_numberOfElements +i);
00091 m_kaliMatrix.at(aft) = m_kaliMatrix.at(bef) ;
00092 }
00093 }
00094
00095 return ;
00096 }
00097
00098
00099
00100
00101
00102 int
00103 IMACalibBlock::solve (int usingBlockSolver, double min, double max)
00104 {
00105 complete () ;
00106
00107
00108 CLHEP::HepMatrix kaliMatrix (m_numberOfElements,m_numberOfElements) ;
00109
00110
00111
00112 riempiMtr (m_kaliMatrix , kaliMatrix) ;
00113
00114
00115
00116
00117
00118
00119 CLHEP::HepVector kaliVector (m_numberOfElements) ;
00120 riempiVtr (m_kaliVector , kaliVector) ;
00121
00122 CLHEP::HepVector result = CLHEP::solve (kaliMatrix,kaliVector) ;
00123 for (int i = 0 ; i < kaliVector.num_row () ; ++i)
00124 if (result.normsq () < min * kaliVector.num_row () ||
00125 result.normsq () > max * kaliVector.num_row ())
00126 {
00127 if (usingBlockSolver)
00128 {
00129 edm::LogWarning ("IML") << "using blocSlover " << std::endl ;
00130 BlockSolver() (kaliMatrix,kaliVector,result) ;
00131 }
00132 else
00133 {
00134 edm::LogWarning ("IML") <<"coeff out of range " <<std::endl;
00135 for (int i = 0 ; i < kaliVector.num_row () ; ++i)
00136 result[i] = 1. ;
00137 }
00138 }
00139 fillMap(result);
00140 return 0;
00141 }
00142
00143
00144
00145
00146
00147 inline int
00148 IMACalibBlock::evalX2Size ()
00149 {
00150
00151 return m_numberOfElements* m_numberOfElements;
00152 }
00153
00154
00155
00156
00157
00158 void
00159 IMACalibBlock::riempiMtr (const std::vector<double> & piena,
00160 CLHEP::HepMatrix & vuota)
00161 {
00162 unsigned int max = m_numberOfElements ;
00163
00164 assert (piena.size () == max * max) ;
00165 assert (vuota.num_row () == int(max)) ;
00166 assert (vuota.num_col () == int(max)) ;
00167 for (unsigned int i = 0 ; i < max ; ++i)
00168 for (unsigned int j = 0 ; j < max ; ++j)
00169 if (edm::isNotFinite (piena[i*max + j])) vuota[i][j] = 0. ;
00170 else vuota[i][j] = piena[i*max + j] ;
00171
00172 return ;
00173 }
00174
00175
00176
00177
00178 void
00179 IMACalibBlock::riempiVtr (const std::vector<double> & pieno,
00180 CLHEP::HepVector & vuoto)
00181 {
00182
00183 int max = m_numberOfElements ;
00184 assert (vuoto.num_row () == max) ;
00185 for (int i = 0 ; i < max ; ++i)
00186 if (edm::isNotFinite (pieno[i])) vuoto[i] = 0. ;
00187 else vuoto[i] = pieno[i] ;
00188
00189 return ;
00190 }
00191
00192
00193
00194
00195
00196 void
00197 IMACalibBlock::reset ()
00198 {
00199
00200 for (std::vector<double>::iterator vecIt = m_kaliVector.begin () ;
00201 vecIt != m_kaliVector.end ();
00202 ++vecIt)
00203 {
00204 *vecIt = 0. ;
00205 }
00206
00207 for (std::vector<double>::iterator vecIt = m_kaliMatrix.begin () ;
00208 vecIt != m_kaliMatrix.end ();
00209 ++vecIt)
00210 {
00211 *vecIt = 0. ;
00212 }
00213
00214 }
00215
00216
00217
00218
00219
00220
00221 void
00222 IMACalibBlock::fillMap (const CLHEP::HepVector & result)
00223 {
00224
00225 for (unsigned int i=0; i < m_numberOfElements; ++i)
00226 {
00227 m_coefficients[i] = result[i] ;
00228 }
00229
00230 return ;
00231 }
00232