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