CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IMACalibBlock.cc
Go to the documentation of this file.
1 
12 #include "TH1F.h"
13 #include "TFile.h"
14 #include <cassert>
15 
16 // -----------------------------------------------------
17 
18 
19 IMACalibBlock::IMACalibBlock (const int numberOfElements):
20  VEcalCalibBlock (numberOfElements) ,
21  m_kaliVector (m_numberOfElements) ,
22  m_kaliMatrix (evalX2Size ())
23 {
24  reset () ;
25 }
26 
27 
28 // -----------------------------------------------------
29 
30 
32 {
33 }
34 
35 
36 // -----------------------------------------------------
37 
38 
39 void
40 IMACalibBlock::Fill (std::map<int,double>::const_iterator MapBegin,
41  std::map<int,double>::const_iterator MapEnd ,
42  double pTk,
43  double pSubtract,
44  double sigma)
45 {
46 // std::cerr<<"\n\nfaccio il fill!\n";
47  double inverror = 1./sigma ;
48  //LP fist loop over energies
49  for (std::map<int,double>::const_iterator itMap1 =MapBegin ;
50  itMap1 !=MapEnd ;
51  ++itMap1)
52  {
53 // std::cerr<<"numero "<<itMap1->first<<" vale "<<itMap1->second<<"\t";
54  for (std::map<int,double>::const_iterator itMap2 = itMap1 ;
55  itMap2 !=MapEnd ;
56  ++itMap2)
57  {
58  //LP calculate the chi square value
59  double dummy = itMap1->second * itMap2->second;
60  dummy *= inverror ;
61  //LP fill the calib matrix
62  m_kaliMatrix.at(itMap1->first*m_numberOfElements +itMap2->first) += dummy ;
63  } //LP second loop over xtals
64 
65  //LP calculate the vector value
66  double dummy = pTk ;
67  dummy -= pSubtract ; //LP borders
68  dummy *= itMap1->second ;
69  dummy *= inverror ;
70  //LP fill the calib vector
71  m_kaliVector.at(itMap1->first) += dummy ;
72  } //LP first loop over energies
73  return ;
74 }
75 
76 
77 //------------------------------------------------------------
78 
79 
80 void
82 {
83  int bef;
84  int aft;
85  for (unsigned int i=0; i<m_numberOfElements;++i)
86  {
87  for (unsigned int j=i+1; j< m_numberOfElements; ++j)
88  {
89  bef = (i*m_numberOfElements+j);
90  aft = (j*m_numberOfElements +i);
91  m_kaliMatrix.at(aft) = m_kaliMatrix.at(bef) ;
92  } //LP second loop over xtals
93  } //LP first loop over xtals
94 
95  return ;
96  }
97 
98 
99 // ------------------------------------------------------------
100 
101 
102 int
103 IMACalibBlock::solve (int usingBlockSolver, double min, double max)
104 {
105  complete () ;
106 // TH1F vettore ("vettore","vettore",10,-0.1,9.9);
107 // TH1F matrice ("matrice","matrice",100,-0.1,99.9);
108  CLHEP::HepMatrix kaliMatrix (m_numberOfElements,m_numberOfElements) ;
109 // for (std::vector<double>::iterator it = m_kaliVector.begin();
110 // it!= m_kaliVector.end();++it)
111 // vettore.Fill(it-m_kaliVector.begin(),*it);
112  riempiMtr (m_kaliMatrix , kaliMatrix) ;
113 // for (std::vector<double>::iterator it = m_kaliMatrix.begin();
114 // it!= m_kaliMatrix.end();++it)
115 // matrice.Fill(it-m_kaliMatrix.begin(),*it);
116 // TFile f ("fileInteressante.root","RECREATE");
117 // vettore.Write();
118 // matrice.Write();
119  CLHEP::HepVector kaliVector (m_numberOfElements) ;
120  riempiVtr (m_kaliVector , kaliVector) ;
121  //PG linear system solution
122  CLHEP::HepVector result = CLHEP::solve (kaliMatrix,kaliVector) ;
123  for (int i = 0 ; i < kaliVector.num_row () ; ++i)
124  if (result.normsq () < min * kaliVector.num_row () ||
125  result.normsq () > max * kaliVector.num_row ())
126  {
127  if (usingBlockSolver)
128  {
129  edm::LogWarning ("IML") << "using blocSlover " << std::endl ;
130  BlockSolver() (kaliMatrix,kaliVector,result) ;
131  }
132  else
133  {
134  edm::LogWarning ("IML") <<"coeff out of range " <<std::endl;
135  for (int i = 0 ; i < kaliVector.num_row () ; ++i)
136  result[i] = 1. ;
137  }
138  }
139  fillMap(result);
140  return 0;
141 }
142 
143 
144 //------------------------------------------------------------
145 
146 
147 inline int
149  {
150 
152  }
153 
154 
155 // ------------------------------------------------------------
156 
157 
158 void
159 IMACalibBlock::riempiMtr (const std::vector<double> & piena,
160  CLHEP::HepMatrix & vuota)
161  {
162  unsigned int max = m_numberOfElements ;
163 
164  assert (piena.size () == max * max) ;
165  assert (vuota.num_row () == int(max)) ;
166  assert (vuota.num_col () == int(max)) ;
167  for (unsigned int i = 0 ; i < max ; ++i)
168  for (unsigned int j = 0 ; j < max ; ++j)
169  if (edm::isNotFinite (piena[i*max + j])) vuota[i][j] = 0. ;
170  else vuota[i][j] = piena[i*max + j] ;
171 
172  return ;
173  }
174 
175 
176 // ------------------------------------------------------------
177 
178 void
179 IMACalibBlock::riempiVtr (const std::vector<double> & pieno,
180  CLHEP::HepVector & vuoto)
181  {
182 
183  int max = m_numberOfElements ;
184  assert (vuoto.num_row () == max) ;
185  for (int i = 0 ; i < max ; ++i)
186  if (edm::isNotFinite (pieno[i])) vuoto[i] = 0. ;
187  else vuoto[i] = pieno[i] ;
188 
189  return ;
190  }
191 
192 
193 // ------------------------------------------------------------
194 
195 
196 void
198 {
199 
200  for (std::vector<double>::iterator vecIt = m_kaliVector.begin () ;
201  vecIt != m_kaliVector.end ();
202  ++vecIt)
203  {
204  *vecIt = 0. ;
205  }
206 
207  for (std::vector<double>::iterator vecIt = m_kaliMatrix.begin () ;
208  vecIt != m_kaliMatrix.end ();
209  ++vecIt)
210  {
211  *vecIt = 0. ;
212  }
213 
214 }
215 
216 
217 // ------------------------------------------------------------
218 //LP sta provando a fare i seguenti due metodi come locali. Speriamo di non fare stronzate.
219 
220 
221 void
222 IMACalibBlock::fillMap (const CLHEP::HepVector & result)
223 {
224 
225  for (unsigned int i=0; i < m_numberOfElements; ++i)
226  {
227  m_coefficients[i] = result[i] ;
228  }
229 
230  return ;
231 }
232 
int i
Definition: DBlmapReader.cc:9
IMACalibBlock(const int)
ctor
void Fill(std::map< int, double >::const_iterator, std::map< int, double >::const_iterator, double pTk, double pSubtract, double sigma=1.)
insert an entry
element for the single ECAL block intercalibration
#define min(a, b)
Definition: mlp_lapack.h:161
std::vector< double > m_kaliVector
vector for the chi2 inversion
Definition: IMACalibBlock.h:61
bool isNotFinite(T x)
Definition: isFinite.h:10
void riempiMtr(const std::vector< double > &piena, CLHEP::HepMatrix &vuota)
copy a vector into a CLHEP object
const T & max(const T &a, const T &b)
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
std::vector< double > m_kaliMatrix
matrix for the chi2 inversion
Definition: IMACalibBlock.h:63
void riempiVtr(const std::vector< double > &pieno, CLHEP::HepVector &vuoto)
copy a vector into a CLHEP object
~IMACalibBlock()
dtor
int evalX2Size()
give the size of a chi2 matrix
solves at best the matrix invertion for calibration
Definition: BlockSolver.h:25
int solve(int usingBlockSolver, double min, double max)
solve the chi2 linear system
std::map< unsigned int, float > m_coefficients
map of coefficients
void reset()
reset the chi2 matrices
unsigned int m_numberOfElements
The only parameter!
void fillMap(const CLHEP::HepVector &result)
fill the coefficients map from the CLHEP vector solution
void complete()
complete the triangolar chi2 matrix to a sym one