CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
15 // Constructor...
17 {
18  // TMarkov
19  // ------ calcule les distributions invariantes de la chaine de TMarkov
20  // correspondantes au spectre original et retourne la dimension de u.
21  //
22 
23  fNPeakValues=3;
24  fNbinu=101;
25  init();
26 }
27 
28 // Destructor
30 {
31 }
32 
34 {
35  int i;
36  for(i=0;i<fNPeakValues;i++) peak[i]=0.;
37  for(i=0;i<fNbinu;i++) u[i]=0.;
38  for(i=0;i<=fNbinu;i++) binu[i]=0.;
39  return ;
40 }
41 
42 int TMarkov::computeChain(int *bing)
43 {
44  int i;int k;int nuprime;int offset=0;int m;int pass;
45  double sumUprime,sumU;
46  double jumpToNext,jumpToPrevious;
47  double chainToNext,chainToPrevious;
48  double aConst[101],uprime[101];
49 
50  pass=0;
51  for(m=3,i=1,nuprime=1;i<101;i++)
52  {
53  uprime[i]=0.;
54  for(k=1,jumpToNext=0.,jumpToPrevious=0.;k<=m;k++)
55  {
56  if(i+k < 101)
57  if(bing[i] > 0 || bing[i+k] > 0)
58  jumpToNext += exp( (double)(bing[i+k]-bing[i])
59  /sqrt((double)(bing[i+k]+bing[i])));
60  if(i-k > 0)
61  if(bing[i] > 0 || bing[i-k] > 0)
62  jumpToPrevious += exp( (double)(bing[i-k]-bing[i])
63  /sqrt((double)(bing[i-k]+bing[i])));
64  }
65  //printf(" jump %d to %d = %f\n",i,i+1,jumpToNext);
66  //printf(" jump %d to %d = %f\n",i,i-1,jumpToPrevious);
67  if(jumpToNext > 0. && jumpToPrevious > 0.)
68  {
69  aConst[i] = -log(jumpToNext+jumpToPrevious);
70  chainToNext = aConst[i]+log(jumpToNext);
71  chainToPrevious = aConst[i]+log(jumpToPrevious);
72  uprime[i]=chainToNext - chainToPrevious;
73  nuprime++; u[nuprime] = uprime[i];
74  if(pass == 0)
75  { offset=i-1; pass=1;}
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  {
84  sumU += u[k]; 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  {
98  binu[i+offset] = exp(u[i]);
99  //printf(" bin numero %d log(u) = %f\n",i+offset,u[i]);
100  //printf(" bin numero %d u = %f\n",i+offset,exp(u[i]));
101 
102  }
103 
104  return nuprime+offset;
105 }
106 
107 void TMarkov::peakFinder(int *bing)
108 {
109  int firstBin=0;int lastBin=0;
110  double barycentre=0.;
111  double sum=0.;
112  double maximum=0.;
113 
114  int nu= computeChain(&bing[0]);
115 
116  for(int i=1;i<nu+1;i++)
117  {
118  sum += binu[i];
119  barycentre += (double)i * binu[i];
120  if(binu[i] > maximum)
121  { maximum=binu[i]; imax=i; }
122  }
123 
124  maximum *= 0.75;
125  for(int i=1,pass=0;i<nu+1;i++) {
126  if(binu[i] > maximum) {
127  if(pass == 0) {
128  firstBin=i;
129  lastBin=i;
130  pass=1;
131  } else {
132  lastBin=i;
133  }
134  }
135  }
136 
137  peak[0] = (barycentre/sum);
138  peak[1]= (double)(lastBin-firstBin+1);
139  peak[2]= sum;
140 }
int i
Definition: DBlmapReader.cc:9
int imax
Definition: TMarkov.h:12
void init()
Definition: TMarkov.cc:33
virtual ~TMarkov()
Definition: TMarkov.cc:29
int computeChain(int *)
Definition: TMarkov.cc:42
TMarkov()
Definition: TMarkov.cc:16
int fNbinu
Definition: TMarkov.h:11
T sqrt(T t)
Definition: SSEVec.h:18
double binu[102]
Definition: TMarkov.h:14
void peakFinder(int *)
Definition: TMarkov.cc:107
double u[101]
Definition: TMarkov.h:14
double peak[3]
Definition: TMarkov.h:13
return(e1-e2)*(e1-e2)+dp *dp
int fNPeakValues
Definition: TMarkov.h:11