CMS 3D CMS Logo

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 IMACalibBlock::IMACalibBlock(const int numberOfElements)
15  : VEcalCalibBlock(numberOfElements), m_kaliVector(m_numberOfElements), m_kaliMatrix(evalX2Size()) {
16  reset();
17 }
18 
19 // -----------------------------------------------------
20 
22 
23 // -----------------------------------------------------
24 
25 void IMACalibBlock::Fill(std::map<int, double>::const_iterator MapBegin,
26  std::map<int, double>::const_iterator MapEnd,
27  double pTk,
28  double pSubtract,
29  double sigma) {
30  // std::cerr<<"\n\nfaccio il fill!\n";
31  double inverror = 1. / sigma;
32  //LP fist loop over energies
33  for (std::map<int, double>::const_iterator itMap1 = MapBegin; itMap1 != MapEnd; ++itMap1) {
34  // std::cerr<<"numero "<<itMap1->first<<" vale "<<itMap1->second<<"\t";
35  for (std::map<int, double>::const_iterator itMap2 = itMap1; itMap2 != MapEnd; ++itMap2) {
36  //LP calculate the chi square value
37  double dummy = itMap1->second * itMap2->second;
38  dummy *= inverror;
39  //LP fill the calib matrix
40  m_kaliMatrix.at(itMap1->first * m_numberOfElements + itMap2->first) += dummy;
41  } //LP second loop over xtals
42 
43  //LP calculate the vector value
44  double dummy = pTk;
45  dummy -= pSubtract; //LP borders
46  dummy *= itMap1->second;
47  dummy *= inverror;
48  //LP fill the calib vector
49  m_kaliVector.at(itMap1->first) += dummy;
50  } //LP first loop over energies
51  return;
52 }
53 
54 //------------------------------------------------------------
55 
57  int bef;
58  int aft;
59  for (unsigned int i = 0; i < m_numberOfElements; ++i) {
60  for (unsigned int j = i + 1; j < m_numberOfElements; ++j) {
61  bef = (i * m_numberOfElements + j);
62  aft = (j * m_numberOfElements + i);
63  m_kaliMatrix.at(aft) = m_kaliMatrix.at(bef);
64  } //LP second loop over xtals
65  } //LP first loop over xtals
66 
67  return;
68 }
69 
70 // ------------------------------------------------------------
71 
72 int IMACalibBlock::solve(int usingBlockSolver, double min, double max) {
73  complete();
74  // TH1F vettore ("vettore","vettore",10,-0.1,9.9);
75  // TH1F matrice ("matrice","matrice",100,-0.1,99.9);
76  CLHEP::HepMatrix kaliMatrix(m_numberOfElements, m_numberOfElements);
77  // for (std::vector<double>::iterator it = m_kaliVector.begin();
78  // it!= m_kaliVector.end();++it)
79  // vettore.Fill(it-m_kaliVector.begin(),*it);
80  riempiMtr(m_kaliMatrix, kaliMatrix);
81  // for (std::vector<double>::iterator it = m_kaliMatrix.begin();
82  // it!= m_kaliMatrix.end();++it)
83  // matrice.Fill(it-m_kaliMatrix.begin(),*it);
84  // TFile f ("fileInteressante.root","RECREATE");
85  // vettore.Write();
86  // matrice.Write();
87  CLHEP::HepVector kaliVector(m_numberOfElements);
88  riempiVtr(m_kaliVector, kaliVector);
89  //PG linear system solution
90  CLHEP::HepVector result = CLHEP::solve(kaliMatrix, kaliVector);
91  for (int i = 0; i < kaliVector.num_row(); ++i)
92  if (result.normsq() < min * kaliVector.num_row() || result.normsq() > max * kaliVector.num_row()) {
93  if (usingBlockSolver) {
94  edm::LogWarning("IML") << "using blocSlover " << std::endl;
95  BlockSolver()(kaliMatrix, kaliVector, result);
96  } else {
97  edm::LogWarning("IML") << "coeff out of range " << std::endl;
98  for (int i = 0; i < kaliVector.num_row(); ++i)
99  result[i] = 1.;
100  }
101  }
102  fillMap(result);
103  return 0;
104 }
105 
106 //------------------------------------------------------------
107 
109 
110 // ------------------------------------------------------------
111 
112 void IMACalibBlock::riempiMtr(const std::vector<double>& piena, CLHEP::HepMatrix& vuota) {
113  unsigned int max = m_numberOfElements;
114 
115  assert(piena.size() == max * max);
116  assert(vuota.num_row() == int(max));
117  assert(vuota.num_col() == int(max));
118  for (unsigned int i = 0; i < max; ++i)
119  for (unsigned int j = 0; j < max; ++j)
120  if (edm::isNotFinite(piena[i * max + j]))
121  vuota[i][j] = 0.;
122  else
123  vuota[i][j] = piena[i * max + j];
124 
125  return;
126 }
127 
128 // ------------------------------------------------------------
129 
130 void IMACalibBlock::riempiVtr(const std::vector<double>& pieno, CLHEP::HepVector& vuoto) {
131  int max = m_numberOfElements;
132  assert(vuoto.num_row() == max);
133  for (int i = 0; i < max; ++i)
134  if (edm::isNotFinite(pieno[i]))
135  vuoto[i] = 0.;
136  else
137  vuoto[i] = pieno[i];
138 
139  return;
140 }
141 
142 // ------------------------------------------------------------
143 
145  for (std::vector<double>::iterator vecIt = m_kaliVector.begin(); vecIt != m_kaliVector.end(); ++vecIt) {
146  *vecIt = 0.;
147  }
148 
149  for (std::vector<double>::iterator vecIt = m_kaliMatrix.begin(); vecIt != m_kaliMatrix.end(); ++vecIt) {
150  *vecIt = 0.;
151  }
152 }
153 
154 // ------------------------------------------------------------
155 //LP sta provando a fare i seguenti due metodi come locali. Speriamo di non fare stronzate.
156 
157 void IMACalibBlock::fillMap(const CLHEP::HepVector& result) {
158  for (unsigned int i = 0; i < m_numberOfElements; ++i) {
159  m_coefficients[i] = result[i];
160  }
161 
162  return;
163 }
IMACalibBlock::m_kaliMatrix
std::vector< double > m_kaliMatrix
matrix for the chi2 inversion
Definition: IMACalibBlock.h:57
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
IMACalibBlock::riempiVtr
void riempiVtr(const std::vector< double > &pieno, CLHEP::HepVector &vuoto)
copy a vector into a CLHEP object
Definition: IMACalibBlock.cc:130
VEcalCalibBlock
element for the single ECAL block intercalibration
Definition: VEcalCalibBlock.h:13
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
IMACalibBlock::complete
void complete()
complete the triangolar chi2 matrix to a sym one
Definition: IMACalibBlock.cc:56
IMACalibBlock::riempiMtr
void riempiMtr(const std::vector< double > &piena, CLHEP::HepMatrix &vuota)
copy a vector into a CLHEP object
Definition: IMACalibBlock.cc:112
min
T min(T a, T b)
Definition: MathUtil.h:58
BlockSolver.h
cms::cuda::assert
assert(be >=bs)
BlockSolver
solves at best the matrix invertion for calibration
Definition: BlockSolver.h:21
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
IMACalibBlock::Fill
void Fill(std::map< int, double >::const_iterator, std::map< int, double >::const_iterator, double pTk, double pSubtract, double sigma=1.) override
insert an entry
Definition: IMACalibBlock.cc:25
IMACalibBlock::fillMap
void fillMap(const CLHEP::HepVector &result)
fill the coefficients map from the CLHEP vector solution
Definition: IMACalibBlock.cc:157
IMACalibBlock::~IMACalibBlock
~IMACalibBlock() override
dtor
Definition: IMACalibBlock.cc:21
IMACalibBlock::reset
void reset() override
reset the chi2 matrices
Definition: IMACalibBlock.cc:144
IMACalibBlock::IMACalibBlock
IMACalibBlock(const int)
ctor
Definition: IMACalibBlock.cc:14
IMACalibBlock::evalX2Size
int evalX2Size()
give the size of a chi2 matrix
Definition: IMACalibBlock.cc:108
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
IMACalibBlock::m_kaliVector
std::vector< double > m_kaliVector
vector for the chi2 inversion
Definition: IMACalibBlock.h:55
IMACalibBlock::solve
int solve(int usingBlockSolver, double min, double max) override
solve the chi2 linear system
Definition: IMACalibBlock.cc:72
createfilelist.int
int
Definition: createfilelist.py:10
VEcalCalibBlock::m_coefficients
std::map< unsigned int, float > m_coefficients
map of coefficients
Definition: VEcalCalibBlock.h:38
isFinite.h
VEcalCalibBlock::m_numberOfElements
unsigned int m_numberOfElements
The only parameter!
Definition: VEcalCalibBlock.h:36
mps_fire.result
result
Definition: mps_fire.py:311
dummy
Definition: DummySelector.h:38
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
IMACalibBlock.h