Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VariableLengthPartition.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: VariableLengthParition.cc
32 //
33 // Version: 1.0
34 // Date: 09/03/00
35 // Author: P R Truscott
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 // 28 August 1999, F Lei, DERA UK
49 // Version number update 0.b.3 -> 0.b.4, but no functional change.
50 //
51 // 17 September 1999, F Lei & P R Truscott, DERA UK
52 // Version 0.b.5
53 // Now uses STL rather than RW vectors.
54 //
55 // 09 March 2000, P R Truscott, DERA UK
56 // Update 0.b.3 -> 1.0, for compliance with ISO ANSI C++.
57 //
58 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 //
62 
63 #include <iostream>
65 //
67  (double *ep_list, size_t ep_list_len,
68  side *ep_conv, size_t )
69 {
70  //
71  //
72  // Transfer over bin-edge information to the STL vector.
73  //
74  bin.insert(bin.begin(), ep_list, ep_list+ep_list_len);
75  nbin = bin.size()-1;
76  conv = *ep_conv;
77  return;
78 }
80 //
82 {
83  conv = LEFT;
84  return;
85 }
87 //
88 long VariableLengthPartition::get_elem_bin (double *data_point)
89 {
90  //
91  //
92  // Find out whether *data_point falls below of exceeds the range of the
93  // binning scheme.
94  //
95  int loc (0);
96  if ((conv == LEFT && *data_point > bin[nbin]) ||
97  (conv == RIGHT && *data_point >= bin[nbin])) {
98  loc = BIN_OVERFLOW;}
99  else if ((conv == LEFT && *data_point <= *bin.begin()) ||
100  (conv == RIGHT && *data_point < *bin.begin())) {
101  loc = BIN_UNDERFLOW;}
102  else {
103  //
104  //
105  // *data_point is in range - perform a binary search.
106  //
107  int upperLimit = bin.size()-1;
108  int lowerLimit = 0;
109  loc = (upperLimit-1)/2;
110  while (*data_point < bin[loc] || *data_point > bin[loc+1]) {
111  if (*data_point < bin[loc]) {upperLimit = loc;}
112  else {lowerLimit = loc;}
113  loc = (upperLimit+lowerLimit)/2;
114  }
115  if (bin[loc] == *data_point && conv == RIGHT) {
116  loc++;}
117  }
118  return loc;
119 }
121 //
123 {
124  return bin[bin_id];
125 }
127 
128