CMS 3D CMS Logo

TMarkov.cc
Go to the documentation of this file.
1 /*
2  * \class TMarkov
3  *
4  * \author: Patrice Verrecchia - CEA/Saclay
5  */
6 
8 
9 #include <iostream>
10 #include <cmath>
11 
12 //ClassImp(TMarkov)
13 
14 // Constructor...
16  // TMarkov
17  // ------ calcule les distributions invariantes de la chaine de TMarkov
18  // correspondantes au spectre original et retourne la dimension de u.
19  //
20 
21  fNPeakValues = 3;
22  fNbinu = 101;
23  init();
24 }
25 
26 // Destructor
28 
29 void TMarkov::init() {
30  int i;
31  for (i = 0; i < fNPeakValues; i++)
32  peak[i] = 0.;
33  for (i = 0; i < fNbinu; i++)
34  u[i] = 0.;
35  for (i = 0; i <= fNbinu; i++)
36  binu[i] = 0.;
37  return;
38 }
39 
40 int TMarkov::computeChain(int *bing) {
41  int i;
42  int k;
43  int nuprime;
44  int offset = 0;
45  int m;
46  int pass;
47  double sumUprime, sumU;
48  double jumpToNext, jumpToPrevious;
49  double chainToNext, chainToPrevious;
50  double aConst[101], uprime[101];
51 
52  pass = 0;
53  for (m = 3, i = 1, nuprime = 1; i < 101; i++) {
54  uprime[i] = 0.;
55  for (k = 1, jumpToNext = 0., jumpToPrevious = 0.; k <= m; k++) {
56  if (i + k < 101)
57  if (bing[i] > 0 || bing[i + k] > 0)
58  jumpToNext += exp((double)(bing[i + k] - bing[i]) / sqrt((double)(bing[i + k] + bing[i])));
59  if (i - k > 0)
60  if (bing[i] > 0 || bing[i - k] > 0)
61  jumpToPrevious += exp((double)(bing[i - k] - bing[i]) / sqrt((double)(bing[i - k] + bing[i])));
62  }
63  //printf(" jump %d to %d = %f\n",i,i+1,jumpToNext);
64  //printf(" jump %d to %d = %f\n",i,i-1,jumpToPrevious);
65  if (jumpToNext > 0. && jumpToPrevious > 0.) {
66  aConst[i] = -log(jumpToNext + jumpToPrevious);
67  chainToNext = aConst[i] + log(jumpToNext);
68  chainToPrevious = aConst[i] + log(jumpToPrevious);
69  uprime[i] = chainToNext - chainToPrevious;
70  nuprime++;
71  u[nuprime] = uprime[i];
72  if (pass == 0) {
73  offset = i - 1;
74  pass = 1;
75  }
76  }
77  }
78 
79  //for(i=1;i<101;i++)
80  //printf(" bin numero %d uprime = %f\n",i,uprime[i]);
81 
82  for (k = 3, sumUprime = u[2], sumU = u[2]; k < nuprime + 1; k++) {
83  sumU += u[k];
84  u[k] = sumU;
85  sumUprime += log(1. + exp(u[k] - u[k - 1]));
86  }
87 
88  u[1] = -sumUprime;
89 
90  for (k = 2; k < nuprime + 1; k++)
91  u[k] += u[1];
92 
93  for (i = 1; i < offset + 1; i++)
94  binu[i] = 0.;
95 
96  for (i = 1; i < nuprime + 1; i++) {
97  binu[i + offset] = exp(u[i]);
98  //printf(" bin numero %d log(u) = %f\n",i+offset,u[i]);
99  //printf(" bin numero %d u = %f\n",i+offset,exp(u[i]));
100  }
101 
102  return nuprime + offset;
103 }
104 
105 void TMarkov::peakFinder(int *bing) {
106  int firstBin = 0;
107  int lastBin = 0;
108  double barycentre = 0.;
109  double sum = 0.;
110  double maximum = 0.;
111 
112  int nu = computeChain(&bing[0]);
113 
114  for (int i = 1; i < nu + 1; i++) {
115  sum += binu[i];
116  barycentre += (double)i * binu[i];
117  if (binu[i] > maximum) {
118  maximum = binu[i];
119  imax = i;
120  }
121  }
122 
123  maximum *= 0.75;
124  for (int i = 1, pass = 0; i < nu + 1; i++) {
125  if (binu[i] > maximum) {
126  if (pass == 0) {
127  firstBin = i;
128  lastBin = i;
129  pass = 1;
130  } else {
131  lastBin = i;
132  }
133  }
134  }
135 
136  peak[0] = (barycentre / sum);
137  peak[1] = (double)(lastBin - firstBin + 1);
138  peak[2] = sum;
139 }
int imax
Definition: TMarkov.h:9
~TMarkov() override
Definition: TMarkov.cc:27
void init()
Definition: TMarkov.cc:29
int computeChain(int *)
Definition: TMarkov.cc:40
TMarkov()
Definition: TMarkov.cc:15
int fNbinu
Definition: TMarkov.h:8
T sqrt(T t)
Definition: SSEVec.h:23
double binu[102]
Definition: TMarkov.h:11
void peakFinder(int *)
Definition: TMarkov.cc:105
double u[101]
Definition: TMarkov.h:11
double peak[3]
Definition: TMarkov.h:10
int fNPeakValues
Definition: TMarkov.h:8