CMS 3D CMS Logo

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