Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Histo2Dvar.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 //
31 // MODULE: Histo2DVar.cc
32 //
33 // Version: 1.0
34 // Date: 09/03/00
35 // Author: P R Truscott, F Lei
36 // Organisation: DERA UK
37 // Customer: ESA/ESTEC, NOORDWIJK
38 // Contract: 12115/96/NL/JG Work Order No. 3
39 //
40 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 //
42 // CHANGE HISTORY
43 // --------------
44 //
45 // 30 June 1999, P R Truscott, DERA UK
46 // Version number update 0.b.2 -> 0.b.3, but no functional change.
47 //
48 //
49 // 28 August 1999, F Lei, DERA UK
50 // Version number update 0.b.3 -> 0.b.4, but no functional change.
51 //
52 // 17 September 1999, P R Truscott, DERA UK
53 // Version number update 0.b.4 -> 0.b.5, but no functional change.
54 //
55 // 09 March 2000, P R Truscott, DERA UK
56 // Update 0.b.3 -> 1.0, for compliance with ISO ANSI C++ (no functional change).
57 //
58 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 //
61 #include "Histo2DVar.hh"
63 //
65  double *epx_list, size_t epx_list_len, side x_conv,
66  double *epy_list, size_t epy_list_len, side y_conv)
67 {
68  //
69  //
70  // Set the name of the histogram, define the x and y VariableLengthPartitions
71  // and reset the contents of the histogram.
72  //
73  theName = name;
74  side x_conv_list[256] = {LEFT};
75  size_t i;
76  for (i=0; i<epx_list_len; i++) {x_conv_list[i]=x_conv;}
78  (epx_list, epx_list_len, x_conv_list, epx_list_len);
79 
80  side y_conv_list[256] = {LEFT};
81  for (i=0; i<epy_list_len; i++) {y_conv_list[i]=y_conv;}
83  (epy_list, epy_list_len, y_conv_list, epy_list_len);
84 
85  reset();
86  return;
87 }
89 //
91 {
92  //
93  //
94  // Set default name and partitions, and reset the contents of the histogram.
95  //
96  theName = "Blank Array";
99 
100  reset();
101  return;
102 }
104 //
106 {
107  int i(0);
108  int j(0);
109  for (i=0; i<256; i++) {
110  for (j=0; j<256; j++) {
111  totalWeight[i][j] = 0.;
112  totalWeightSquared[i][j] = 0.;
113  nEvents[i][j] = 0;
114  }
115  }
116 
117  for (i=0; i<2; i++) {
118  for (j=0; j<2; j++) {
119  uoflowTotalWeight[i][j] = 0.;
120  uoflowTotalWeightSquared[i][j] = 0.;
121  uoflownEvents[i][j] = 0;
122  }
123  }
124 }
126 //
127 void Histo2DVar::fill (double x_point, double y_point, double weight = 1.0)
128 {
129  //
130  //
131  // Determine the bin numbers for the points x_point and y_point.
132  //
133  int i = (x_part.get_elem_bin(&x_point));
134  int j = (y_part.get_elem_bin(&y_point));
135 
136  if (i == BIN_UNDERFLOW || i == BIN_OVERFLOW ||
137  j == BIN_UNDERFLOW || j == BIN_OVERFLOW) {
138 
139  //
140  //
141  // Underflow or overflow condition - modify uoflow variables.
142  //
143  HistSpecialBin xSpecialBin(inrange);
144  if (i == BIN_UNDERFLOW) {xSpecialBin = underflow_bin;}
145  else if (i == BIN_OVERFLOW) {xSpecialBin = overflow_bin;}
146 
147  HistSpecialBin ySpecialBin(inrange);
148  if (j == BIN_UNDERFLOW) {ySpecialBin = underflow_bin;}
149  else if (j == BIN_OVERFLOW) {ySpecialBin = overflow_bin;}
150 
151  uoflowTotalWeight[xSpecialBin][ySpecialBin] += weight;
152  uoflowTotalWeightSquared[xSpecialBin][ySpecialBin] += weight*weight;
153  uoflownEvents[xSpecialBin][ySpecialBin]++;
154  }
155  else {
156  //
157  //
158  // The data point referred to by x_point and y_point is within the
159  // histogrammed area - modify conventional histogram variables.
160  //
161  totalWeight[i][j] += weight;
162  totalWeightSquared[i][j] += weight*weight;
163  nEvents[i][j]++;
164 
165  uoflowTotalWeight[inrange][inrange] += weight;
166  uoflowTotalWeightSquared[inrange][inrange] += weight*weight;
167  uoflownEvents[inrange][inrange]++;
168 
169  }
170  nAllEvents++;
171 }
173 //
174 double Histo2DVar::get_bin_value (int i, int j)
175 {
176  //
177  //
178  // Determine if i lies within the range of the histogram x-axis.
179  //
180  HistSpecialBin xSpecialBin(inrange);
181  if (size_t(i) > (x_part.total_bins()-1)) {xSpecialBin = overflow_bin;}
182  else if (i < 0) {xSpecialBin = underflow_bin;}
183 
184  //
185  //
186  // Determine if j lies within the range of the histogram y-axis.
187  //
188  HistSpecialBin ySpecialBin(inrange);
189  if (size_t(j) > (y_part.total_bins()-1)) {ySpecialBin = overflow_bin;}
190  else if (j < 0) {ySpecialBin = underflow_bin;}
191 
192  //
193  //
194  // If i and j are within range, output the conventional histogram variables.
195  // Otherwise output uoflow variables.
196  //
197  double value(0.);
198  if (xSpecialBin == inrange && ySpecialBin == inrange) {
199  value = totalWeight[i][j];}
200  else {
201  value = uoflowTotalWeight[xSpecialBin][ySpecialBin];}
202 
203  return value;
204 }
206 //
207 double Histo2DVar::get_bin_error (int i, int j)
208 {
209  //
210  //
211  // Determine if i lies within the range of the histogram x-axis.
212  //
213  HistSpecialBin xSpecialBin(inrange);
214  if (size_t(i) > (x_part.total_bins()-1)) {xSpecialBin = overflow_bin;}
215  else if (i < 0) {xSpecialBin = underflow_bin;}
216 
217  //
218  //
219  // Determine if j lies within the range of the histogram y-axis.
220  //
221  HistSpecialBin ySpecialBin(inrange);
222  if (size_t(j) > (y_part.total_bins()-1)) {ySpecialBin = overflow_bin;}
223  else if (j < 0) {ySpecialBin = underflow_bin;}
224 
225  //
226  //
227  // If i and j are within range, output the conventional histogram variables.
228  // Otherwise output uoflow variables.
229  //
230  double error(0.);
231  if (xSpecialBin == inrange && ySpecialBin == inrange)
232  // {error = sqrt(totalWeightSquared[i][j] -
233  // totalWeight[i][j]*totalWeight[i][j]);}
234  {
235  if (nEvents[i][j]>0) {
236  error = totalWeight[i][j]/std::sqrt((G4double) nEvents[i][j]);
237  }else {
238  error = 0.;} }
239  else
240  {error = std::sqrt(uoflowTotalWeightSquared[xSpecialBin][ySpecialBin] -
241  uoflowTotalWeight[xSpecialBin][ySpecialBin]*
242  uoflowTotalWeight[xSpecialBin][ySpecialBin]);}
243  return error;
244 }
245 
247 //
248 void Histo2DVar::div (double r)
249 {
250  //
251  //
252  // Apply division to the conventional histogram variables.
253  //
254  int i(0);
255  int j(0);
256  for (i = 0; i < 3; i ++)
257  {
258  for (j = 0; j < 3; j++)
259  {
260  uoflowTotalWeight[i][j] = uoflowTotalWeight[i][j] / r;
261  uoflowTotalWeightSquared[i][j] = uoflowTotalWeightSquared[i][j] / r;
262  }
263  }
264 
265  //
266  //
267  // Apply division to the uoflow variables.
268  //
269  for (i = 0; i < int(x_part.total_bins()); i ++)
270  {
271  for (j = 0; j < int(y_part.total_bins()); j++)
272  {
273  totalWeight[i][j] = totalWeight[i][j] / r;
274  totalWeightSquared[i][j] = totalWeightSquared[i][j] / r /r;
275  }
276  }
277 }