CMS 3D CMS Logo

GenericMinL3Algorithm.cc
Go to the documentation of this file.
1 
9 
11  : normaliseFlag(normalise)
12 // if normalize=true: for all events sum the e25ovTRP. then take the mean value and rescale all TrP
13 {}
14 
16 
17 std::vector<float> GenericMinL3Algorithm::iterate(const std::vector<std::vector<float> >& eventMatrix,
18  const std::vector<float>& energyVector,
19  const int nIter) {
20  std::vector<float> solution;
21  std::vector<std::vector<float> > myEventMatrix(eventMatrix);
22  int Nevents = eventMatrix.size(); // Number of events to calibrate with
23  int Nchannels = eventMatrix[0].size(); // Number of channel coefficients
24  std::vector<float> theCalibVector(Nchannels, 1.);
25 
26  // Iterate the correction
27  for (int iter = 1; iter <= nIter; iter++) {
28  // make one iteration
29  solution = iterate(myEventMatrix, energyVector);
30 
31  if (solution.empty())
32  return solution;
33  // R.O.: or throw an exception, what's the standard CMS way ?
34 
35  // re-calibrate eventMatrix with solution
36  for (int i = 0; i < Nchannels; i++) {
37  for (int ievent = 0; ievent < Nevents; ievent++) {
38  myEventMatrix[ievent][i] *= solution[i];
39  }
40  // save solution into theCalibVector
41  theCalibVector[i] *= solution[i];
42  }
43 
44  } // end iterate the correction
45 
46  return theCalibVector;
47 }
48 
49 std::vector<float> GenericMinL3Algorithm::iterate(const std::vector<std::vector<float> >& eventMatrix,
50  const std::vector<float>& energyVector) {
51  std::vector<float> solution;
52  std::vector<float> myEnergyVector(energyVector);
53 
54  int Nevents = eventMatrix.size(); // Number of events to calibrate with
55  int Nchannels = eventMatrix[0].size(); // Number of channel coefficients
56 
57  // Sanity check
58  if (Nevents != int(myEnergyVector.size())) {
59  std::cout << "GenericMinL3Algorithm::iterate(): Error: bad matrix dimensions. Dropping out." << std::endl;
60  return solution; // empty vector !
61  }
62 
63  // initialize the solution vector with 1.
64  solution.assign(Nchannels, 1.);
65 
66  int ievent, i, j;
67 
68  // if normalization flag is set, normalize energies
69  float sumOverEnergy;
70  if (normaliseFlag) {
71  float scale = 0.;
72 
73  std::cout << "GenericMinL3Algorithm::iterate(): Normalising event data" << std::endl;
74 
75  for (i = 0; i < Nevents; i++) {
76  sumOverEnergy = 0.;
77  for (j = 0; j < Nchannels; j++) {
78  sumOverEnergy += eventMatrix[i][j];
79  }
80  sumOverEnergy /= myEnergyVector[i];
81  scale += sumOverEnergy;
82  }
83  scale /= Nevents;
84  std::cout << " Normalisation = " << scale << std::endl;
85 
86  for (i = 0; i < Nevents; i++) {
87  myEnergyVector[i] *= scale;
88  }
89  } // end normalize energies
90 
91  // This is where the real work goes on...
92  float sum25, invsum25;
93  float w; // weight for event
94  std::vector<float> wsum(Nchannels, 0.); // sum of weights for a crystal
95  std::vector<float> Ewsum(Nchannels, 0.); // sum of products of weight*Etrue/E25
96 
97  // Loop over events
98  for (ievent = 0; ievent < Nevents; ievent++) {
99  // Loop over the 5x5 to find the sum
100  sum25 = 0.;
101 
102  for (i = 0; i < Nchannels; i++) {
103  sum25 += eventMatrix[ievent][i];
104  } //*calibs[i];
105 
106  if (sum25 != 0.) {
107  invsum25 = 1 / sum25;
108  // Loop over the 5x5 again and calculate the weights for each xtal
109  for (i = 0; i < Nchannels; i++) {
110  w = eventMatrix[ievent][i] * invsum25; // * calibs[i]
111  wsum[i] += w;
112  Ewsum[i] += (w * myEnergyVector[ievent] * invsum25);
113  }
114  } else {
115  std::cout << " Debug: dropping null event: " << ievent << std::endl;
116  }
117 
118  } // end Loop over events
119 
120  // Apply correction factors to all channels not in the margin
121  for (i = 0; i < Nchannels; i++) {
122  if (wsum[i] != 0.) {
123  solution[i] *= Ewsum[i] / wsum[i];
124  } else {
125  std::cout << "warning - no event data for crystal index " << i << std::endl;
126  }
127  }
128 
129  return solution;
130 }
GenericMinL3Algorithm::GenericMinL3Algorithm
GenericMinL3Algorithm(bool normalise=false)
Definition: GenericMinL3Algorithm.cc:10
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.scale
scale
Definition: HLT_FULL_cff.py:6634
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GenericMinL3Algorithm::iterate
std::vector< float > iterate(const std::vector< std::vector< float > > &eventMatrix, const std::vector< float > &energyVector, int nIter)
Definition: GenericMinL3Algorithm.cc:17
w
const double w
Definition: UKUtility.cc:23
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
GenericMinL3Algorithm::~GenericMinL3Algorithm
~GenericMinL3Algorithm()
Destructor.
Definition: GenericMinL3Algorithm.cc:15
GenericMinL3Algorithm::normaliseFlag
bool normaliseFlag
Definition: GenericMinL3Algorithm.h:36
GenericMinL3Algorithm.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66