StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFtpcSlowSimLibs.cc
1 // $Id: StFtpcSlowSimLibs.cc,v 1.4 2009/11/14 12:42:27 jcs Exp $
2 // $Log: StFtpcSlowSimLibs.cc,v $
3 // Revision 1.4 2009/11/14 12:42:27 jcs
4 // make corrections to avoid warnings which appeared with system upgrade
5 //
6 // Revision 1.3 2007/01/15 15:02:20 jcs
7 // replace printf, cout and gMesMgr with Logger
8 //
9 // Revision 1.2 2003/09/02 17:58:16 perev
10 // gcc 3.2 updates + WarnOff
11 //
12 // Revision 1.1 2000/11/23 10:16:43 hummler
13 // New FTPC slow simulator in pure maker form
14 //
15 //
17 // Author: W.G.Gong
18 // Email: gong@mppmu.mpg.de
19 // Date: Oct 25, 1996
21 
22 #include <Stiostream.h>
23 #include <math.h>
24 #include "StMessMgr.h"
25 
26 
27 int Locate(const int npt, const float* x, const float xx)
28 {
29 //
30 // Locate the index in the array for a given value
31 // array x should be a monotonical array
32 //
33  int jlow = 0;
34  int jup = npt-1;
35  int jmid;
36  int rising = (x[npt-1] > x[0]) ? (1) : (0) ;
37 
38  if ( (rising && (xx > x[jup] || xx < x[jlow])) ||
39  (!rising && (xx < x[jup] || xx > x[jlow])) ) {
40  LOG_WARN << "Locate(): xx is out of range!" << endm;
41  return 0;
42  }
43 
44  while (jup-jlow-1 ) {
45  jmid = (jlow + jup)/2;
46 
47  if ( (rising && (xx > x[jmid])) ||
48  (!rising && (xx < x[jmid])) ) {
49  jlow = jmid;
50  }
51  else {
52  jup = jmid;
53  }
54  }
55 
56  return jlow;
57 }
58