ATLAS Offline Software
ZdcSignalSinc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include <iostream>
7 
8 #include "ZdcRec/ZdcSignalSinc.h"
9 
10 
12  : m_n_Slices(nSlc)
13  , m_AmpThresh(5.)
14  , m_tClock (25.)
15  , m_Pi(4*atan(double(1.)))
16 {
17  m_buf = new double[m_n_Slices];
18  m_Time = 0.;
19  m_Amp = 0.;
20  m_Err = e_noData;
21  m_Warn = 0;
22 
23  m_p = 0;
24  m_np = 0;
25 
26  m_wfm[0] = 0. ;
27  m_wfm[1] = 0. ;
28  m_wfm[2] = 0. ;
29 
30  m_tim[0] = 0. ;
31  m_tim[1] = 0. ;
32  m_tim[2] = 0. ;
33 
34  m_dt = 0.;
35 
36  m_AAAA = 0;
37 
38 }
39 
41 
42 int ZdcSignalSinc::process(double *buf, double gain, double ped,
43  double frac, bool corr) {
44 
45  m_Time = 0.;
46  m_Amp = 0.;
47  m_Err = e_OK;
48  m_Warn = 0;
49 
50  if (ped==0) ped=buf[0];
51  for (double *p=m_buf;p<m_buf+m_n_Slices;p++) {
52  double a = *(buf++);
53  //std::cout << "ZDC+++ A" << a << std::endl;
54  if (a>1015) {
55  m_Err = e_Overflow;
56  return m_Err;
57  }
58  *p = a-ped;
59  }
60  if (frac<=0.) {
62  return m_Err;
63  }
64 
65  int imax = -1;
66  if (m_buf[0 ]-m_buf[1 ]>m_AmpThresh) {
67  imax = 0;
68  m_Warn += 1;
69  }
70 
72  if (imax<0) {
73  imax = m_n_Slices-1;
74  m_Warn += 2;
75  } else {
77  return m_Err;
78  }
79  }
80 
81  for (int i=1;i<m_n_Slices-1;i++) {
82  double da1 = m_buf[i]-m_buf[i-1];
83  double da2 = m_buf[i]-m_buf[i+1];
84  if (da1>0. && da2>=0.) {
85  if (da1>m_AmpThresh || da2>m_AmpThresh) {
86  if (imax<0) imax = i;
87  else {
89  return m_Err;
90  }
91  }
92  }
93  }
94 
95  if (imax<0) {
96  m_Err = e_noSignal;
97  return m_Err;
98  }
99 
100  if (imax==1) m_Warn += 4;
101 
102  if (imax>=2) {
103  // printf("%d %f %f\n",imax,m_buf[imax-2],m_AmpThresh);
104  if (m_buf[imax-2]>m_AmpThresh) m_p = imax-2;
105  else m_p = imax-1;
106  } else m_p = imax;
107 
108  m_np = m_n_Slices-m_p;
109 
110  double t_peak = findpeak(imax-m_p);
111  if (m_Err) return m_Err;
112 
113  if (frac>=1.) m_Time = t_peak;
114  else m_Time = fraction(frac,t_peak);
115  m_Amp = waveform(t_peak);
116 
117  //std::cout << "ZDC+++ m_AMP " << m_Amp << std::endl;
118 
119  /*
120  printf("aap: %d %d %d ",imax, m_p, m_np);
121  for (int i=0;i<m_n_Slices;i++) printf("%6.1f ",m_buf[i]);
122  printf(" %6.1f %6.1f %6.1f\n",t_peak*m_tClock,m_Time*m_tClock,m_Amp);
123  */
124 
125  if (gain==1.) {
126  if (m_Amp<200.) m_Warn += 8;
127  if (m_Amp>900.) m_Warn += 16;
128  } else {
129  if (m_Amp< 50.) m_Warn += 8;
130  if (m_Amp>250.) m_Warn += 16;
131  }
132  m_Amp *= gain;
134  if (corr) {
135  int off = int(10.+m_Time/m_tClock)-10;
136  double t = m_Time - off*m_tClock;
137 
138  if (t< 5.) t = 0.056836274872111 + 1.532763686481279 *t
139  + 0.229808343735056 *t*t - 0.0365636647119192 *t*t*t;
140  else if (t<16.) t = -1.28974955223497 + 2.653578699334604 *t
141  - 0.1371240146140209*t*t + 0.00281211806384422*t*t*t;
142  else t = -42.18688740322650 + 8.61752055701946 *t
143  - 0.4259239806065329*t*t + 0.00753849507486617*t*t*t;
144 
145  m_Time = off*m_tClock + t;
146  }
147 
148  return m_Err;
149 }
150 
151 int ZdcSignalSinc::getError() const {return m_Err;}
152 int ZdcSignalSinc::getWarning() const {return m_Warn;}
153 double ZdcSignalSinc::getTime() const {return m_Time;}
154 double ZdcSignalSinc::getAmp() const {return m_Amp;}
155 
156 double ZdcSignalSinc::waveform(double t) {
157  double f = 0.;
158  for (int i=0; i<m_np; i++) {
159  double x = m_Pi*(t-i);
160  if (x) f += m_buf[m_p+i]*sin(x)/x;
161  else f += m_buf[m_p+i];
162  }
163  return f;
164 }
165 
166 double ZdcSignalSinc::fraction(double frac, double tpeak) {
167  m_tim[0] = 0.; m_wfm[0] = waveform(m_tim[0]);
168  m_tim[1] = tpeak; m_wfm[1] = waveform(m_tim[1]);
169  m_dt = tpeak/2.;
170  double thr = frac*m_wfm[1];
171  while(m_wfm[0]>thr) {
172  m_tim[0] -= 0.1;
173  m_wfm[0] = waveform(m_tim[0]);
174  if (m_tim[0]<-2.) {
175  m_tim[0] = 0.;
176  m_wfm[0] = waveform(m_tim[0]);
178  break;
179  }
180  }
181 
182  while (m_dt>0.001) {
183  double t = m_tim[0] + m_dt;
184  double f = waveform(t);
185  if (f>thr) {m_tim[1] = t; m_wfm[1] = f;}
186  else {m_tim[0] = t; m_wfm[0] = f;}
187  m_dt /= 2.;
188  }
189  return (m_tim[0]+m_tim[1])/2.;
190 }
191 
193 
194  m_tim[0] = im; m_tim[1]=im+0.5; m_tim[2]=im+1.;
195  for (int i=0;i<3;i++) m_wfm[i]=waveform(m_tim[i]);
196  m_dt = 0.5;
197  double t = findpeak();
198  return t;
199 }
200 
202  if (m_dt<0.001) return m_tim[1];
203 
204  if (m_wfm[0]<m_wfm[1]) {
205  if (m_wfm[2]<=m_wfm[1]) {
206  m_dt /=2.;
207  double t1 = m_tim[1]-m_dt;
208  double f1 = waveform(t1);
209  if (f1>m_wfm[1]) {
210  m_tim[2] = m_tim[1]; m_wfm[2] = m_wfm[1];
211  m_tim[1] = t1; m_wfm[1] = f1;
212  } else {
213  double t2 = m_tim[1]+m_dt;
214  double f2 = waveform(t2);
215  if (f2>m_wfm[1]) {
216  m_tim[0] = m_tim[1]; m_wfm[0] = m_wfm[1];
217  m_tim[1] = t2; m_wfm[1] = f2;
218  } else {
219  m_tim[0] = t1; m_wfm[0] = f1;
220  m_tim[2] = t2; m_wfm[2] = f2;
221  }
222  }
223  } else {
224  m_tim[0] = m_tim[1]; m_wfm[0] = m_wfm[1];
225  m_tim[1] = m_tim[2]; m_wfm[1] = m_wfm[2];
226  m_tim[2] += m_dt; m_wfm[2] = waveform(m_tim[2]);
227  }
228  } else {
229  if (m_wfm[2]<=m_wfm[1]) {
230  m_tim[2] = m_tim[1]; m_wfm[2] = m_wfm[1];
231  m_tim[1] = m_tim[0]; m_wfm[1] = m_wfm[0];
232  m_tim[0] -= m_dt; m_wfm[0] = waveform(m_tim[0]);
233  return findpeak();
234  } else {
236  return 0.;
237  }
238  }
239  return findpeak();
240 }
241 
242 
243 
ZdcSignalSinc::m_tClock
const double m_tClock
Definition: ZdcSignalSinc.h:35
ZdcSignalSinc::ZdcSignalSinc
ZdcSignalSinc(int)
Definition: ZdcSignalSinc.cxx:11
ZdcSignalSinc::m_Pi
const double m_Pi
Definition: ZdcSignalSinc.h:36
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ZdcSignalSinc::e_noSignal
@ e_noSignal
Definition: ZdcSignalSinc.h:17
ZdcSignalSinc.h
ZdcSignalSinc::fraction
double fraction(double, double)
Definition: ZdcSignalSinc.cxx:166
ZdcSignalSinc::getError
int getError() const
Definition: ZdcSignalSinc.cxx:151
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
ZdcSignalSinc::findpeak
double findpeak()
Definition: ZdcSignalSinc.cxx:201
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
python.atlas_oh.im
im
Definition: atlas_oh.py:167
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ZdcSignalSinc::process
int process(double *, double gain=1., double ped=0., double frac=1., bool corr=true)
Definition: ZdcSignalSinc.cxx:42
x
#define x
ZdcSignalSinc::m_Warn
int m_Warn
Definition: ZdcSignalSinc.h:40
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
read_hist_ntuple.f2
f2
Definition: read_hist_ntuple.py:20
ZdcSignalSinc::m_Amp
double m_Amp
Definition: ZdcSignalSinc.h:38
ZdcSignalSinc::m_Time
double m_Time
Definition: ZdcSignalSinc.h:37
ZdcSignalSinc::m_tim
double m_tim[3]
Definition: ZdcSignalSinc.h:53
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
ZdcSignalSinc::m_p
int m_p
Definition: ZdcSignalSinc.h:46
ZdcSignalSinc::m_AAAA
int m_AAAA
Definition: ZdcSignalSinc.h:54
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:257
ZdcSignalSinc::getAmp
double getAmp() const
Definition: ZdcSignalSinc.cxx:154
ZdcSignalSinc::m_dt
double m_dt
Definition: ZdcSignalSinc.h:53
ZdcSignalSinc::getTime
double getTime() const
Definition: ZdcSignalSinc.cxx:153
ZdcSignalSinc::e_wrongFrac
@ e_wrongFrac
Definition: ZdcSignalSinc.h:16
hist_file_dump.f
f
Definition: hist_file_dump.py:135
ZdcSignalSinc::waveform
double waveform(double t)
Definition: ZdcSignalSinc.cxx:156
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
imax
int imax(int i, int j)
Definition: TileLaserTimingTool.cxx:33
ZdcSignalSinc::m_AmpThresh
const double m_AmpThresh
Definition: ZdcSignalSinc.h:34
ZdcSignalSinc::m_n_Slices
const int m_n_Slices
Definition: ZdcSignalSinc.h:33
ZdcSignalSinc::e_localMinimum
@ e_localMinimum
Definition: ZdcSignalSinc.h:17
ZdcSignalSinc::e_noData
@ e_noData
Definition: ZdcSignalSinc.h:16
ZdcSignalSinc::m_Err
int m_Err
Definition: ZdcSignalSinc.h:39
ZdcSignalSinc::e_wrongSignal
@ e_wrongSignal
Definition: ZdcSignalSinc.h:17
Example_ReadSampleNoise.ped
ped
Definition: Example_ReadSampleNoise.py:45
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
a
TList * a
Definition: liststreamerinfos.cxx:10
ZdcSignalSinc::m_buf
double * m_buf
Definition: ZdcSignalSinc.h:44
ZdcSignalSinc::~ZdcSignalSinc
~ZdcSignalSinc()
Definition: ZdcSignalSinc.cxx:40
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
ZdcSignalSinc::e_Overflow
@ e_Overflow
Definition: ZdcSignalSinc.h:16
ZdcSignalSinc::e_OK
@ e_OK
Definition: ZdcSignalSinc.h:16
ZdcSignalSinc::m_np
int m_np
Definition: ZdcSignalSinc.h:47
ZdcSignalSinc::getWarning
int getWarning() const
Definition: ZdcSignalSinc.cxx:152
ZdcSignalSinc::m_wfm
double m_wfm[3]
Definition: ZdcSignalSinc.h:53
read_hist_ntuple.f1
f1
Definition: read_hist_ntuple.py:4