Diana Software
CheckOFShape.C
Go to the documentation of this file.
1  {
2  // gSystem->Load("/opt/local/libexec/boost/1.76/lib/libboost_thread-mt");
3  // gSystem->Load("/opt/local/lib/libcrypto");
4  // gSystem->Load("/opt/local/lib/libssl");
5  gROOT->Reset();
6  gSystem->Load("libpq");
7  gSystem->Load("libqroot");
8  gSystem->Load("libthreadwrapper");
9  gSystem->Load("libbase");
10  gSystem->Load("libcoretools");
11  gSystem->Load("libglobalrw");
12  gSystem->Load("libqstyle");
13  gSystem->Load("libdbbase");
14  gSystem->Load("librundatadb");
15  gSystem->Load("libdianadata");
16  gSystem->Load("libcalderdata");
17  gSystem->Load("libcaldertools");
18  gSystem->Load("libqstyleloader");
19  gSystem->Load("liboptimumfilter");
20  using namespace Diana;
21  TF1 a; QVector b;
22 
23 
24  double fs = 1;
25  int N = 2048*fs;
26  int Ne = 1e3;
27  double t0 = 200*fs;
28  double taur = 10*fs;
29  double taud = 200*fs;
30  double taur_dev = 1;
31  double taud_dev = 1;
32  double sigma = 1*sqrt(fs);
33  double amp = 10;
34 
35  QVector an(N);
36  an.Initialize(sigma*sigma*N);
37  QVector ap(N);
38  ap.Initialize(0);
39 
40  for(int i = 0; i < N; i++) {
41  double t = i-t0;
42  if(t < 0) continue;
43  ap[i] += -exp(-t/taur) + exp(-t/taud);
44  }
45  int apmaxindex = ap.GetMaxIndex();
46  double max = ap.GetMax()-ap[0];
47  ap/=max;
48  max = 1;
49 
50  QOptimumFilter of(ap,an,-1,false);
53  double cbase = ap1filtered2.GetMean(t0*3./4);
54  double cgain = ap1filtered2.GetMax()-ap1filtered2.GetMin();
55  // std::cout<<"cgain: "<<cgain<<" cbase: "<<cbase<<std::endl;
56  double ofbase = ap1filtered2.GetMean(3./4*t0);
58  ap1filtered2 /= cgain;
59  int maxpos = ap1filtered2.GetMaxIndex();
63  for(int i = maxpos; i > 0; i--) {
64  if((ap1filtered2.GetMax()-ap1filtered2[i])<0.8) {
65  deltat20 = maxpos-i;
66  }
67  if((ap1filtered2.GetMax()-ap1filtered2[i])<0.5) {
68  deltat50 = maxpos-i;
69  }
70  if((ap1filtered2.GetMax()-ap1filtered2[i])<0.2) {
71  deltat80 = maxpos-i;
72  }
73 
74  }
75  /*
76  deltat80 += maxpos-ap.GetMaxIndex();
77  deltat50 += maxpos-ap.GetMaxIndex();
78  deltat20 += maxpos-ap.GetMaxIndex();
79  */
80  std::cout<<deltat20<<" "<<deltat50<<" "<<deltat80<<std::endl;
81 
82 
83  double sigma_of = of.GetFilteredNoiseRMS();
85  // amp *= sigma_of;
86 
87  std::cout<<"Simga OF: "<<sigma_of<<" amp: "<<amp<<std::endl;
88  //std::cout<<"Simga OF2: "<<sigma_of2<<std::endl;;
89 
90  TH1D* ahisto = new TH1D("ahisto","ahisto",sqrt(Ne),amp*0.2,amp*1.5);
91  TH1D* lhisto = new TH1D("lhisto","lhisto",sqrt(Ne),0,50);
92  TH1D* rhisto = new TH1D("rhisto","rhisto",sqrt(Ne),0,50);
93  TH1D* chisto = new TH1D("chisto","chisto",sqrt(Ne),0,2);
94  TH1D* jhisto = new TH1D("jhisto","jhisto",240,-30,30);
95  TH1D* shisto = new TH1D("shisto","shisto",sqrt(Ne),0,amp);
96 
97  TH1D* ahisto2 = new TH1D("ahisto2","ahisto2",sqrt(Ne),amp*0.2,amp*1.5);
98  TH1D* lhisto2 = new TH1D("lhisto2","lhisto2",sqrt(Ne),0,50);
99  TH1D* rhisto2 = new TH1D("rhisto2","rhisto2",sqrt(Ne),0,50);
100  TH1D* chisto2 = new TH1D("chisto2","chisto2",sqrt(Ne),0,2);
101  TH1D* jhisto2 = new TH1D("jhisto2","jhisto2",50*taur,-5*taur,5*taur);
102  TH1D* shisto2 = new TH1D("shisto2","shisto2",sqrt(Ne),0,amp);
103 
104  TRandom rand;
105  rand.SetSeed(0);
106 
107 
108  int success = 0, success2 = 0;
109  for(int e = 0; e < Ne; e++) {
110  if(e%100 == 0) cout<<"Event: "<<e<<std::endl;
111 
112  double shift=rand.Uniform(-4*taur,4*taur);
113  QVector signal(N),signal2(N);
114  QVector noise(N),noise2(N);
115  signal.Initialize(0);
116  signal2.Initialize(0);
117  noise.Initialize(0);
118  noise2.Initialize(0);
119 
120  for(int i = 0; i < N; i++) {
121  double t = double(i-t0)-shift;
122  noise[i] += rand.Gaus(0,sigma);
123  noise2[i] += rand.Gaus(0,sigma);
124  if(t < 0) continue;
125  signal[i] += (-exp(-t/taur) + exp(-t/taud));
126  signal2[i] +=(-exp(-t/taur/taur_dev) + exp(-t/taud/taud_dev));
127  }
128  signal *= amp/signal.GetMax();
129  signal2 *= amp/signal2.GetMax()/1.15;
130  signal += noise;
131  signal2 += noise2;
132 
133 
134  QError err;
135  err = of.Filter(signal);
136  if(err != QERR_SUCCESS) continue;
138  if(err != QERR_SUCCESS) continue;
139  double jitter,chi2,amplitude,integral,left,right;
140  err = of.GetInterpolated(jitter,chi2,amplitude,integral,left,right);
141  if(err != QERR_SUCCESS) continue;
142  ahisto->Fill(amplitude);
143  lhisto->Fill(left);
144  rhisto->Fill(right);
145  chisto->Fill(chi2);
146  jhisto->Fill(jitter-shift);
147 
148  err = of.Filter(signal2);
149  if(err != QERR_SUCCESS) continue;
151  if(err != QERR_SUCCESS) continue;
152  double jitter2,chi22,amplitude2,integral2,left2,right2;
153  err = of.GetInterpolated(jitter2,chi22,amplitude2,integral2,left2,right2);
154  if(err != QERR_SUCCESS) continue;
155  ahisto2->Fill(amplitude2);
156  lhisto2->Fill(left2);
157  rhisto2->Fill(right2);
158  chisto2->Fill(chi22);
159  jhisto2->Fill(jitter2-shift);
160 
161  success++;
162 
163 
164  double fac = 1.5;
165  err = of2.Filter(signal);
166  if(err != QERR_SUCCESS) continue;
167  double t1=0,t2=0;
168  for(int i = maxpos+jitter; i >0; i--) {
169  if(amplitude-of2.GetFilteredShifted()[i] < 0.25*amplitude) t2 = i;
170  if(amplitude-of2.GetFilteredShifted()[i] < 0.75*amplitude) t1 = i;
171  }
172  //shisto->Fill(t2-t1);
174  shisto->Fill(diff/cgain);
175 
176  err = of2.Filter(signal2);
177  if(err != QERR_SUCCESS) continue;
178 
179  t1=0,t2=0;
180  for(int i = maxpos+jitter2; i >0; i--) {
181  if(amplitude2-of2.GetFilteredShifted()[i] < 0.25*amplitude) t2 = i;
182  if(amplitude2-of2.GetFilteredShifted()[i] < 0.75*amplitude) t1 = i;
183  }
184  //shisto2->Fill(t2-t1);
185 
187  shisto2->Fill(diff2/cgain);
188 
190 
191  if(success2 == 1) {
192  TCanvas * cs = new TCanvas("cs","cs",800,600);
193  signal2.GetGraph()->Draw("AL");
194  QVector ofwave_man = of2.GetFilteredShifted();
195  ofbase = ofwave_man.GetMean(3./4*t0);
196  ofwave_man -= ofbase;
197  ofwave_man /= cgain;
198 
199  TGraph* ofwave = ofwave_man.GetGraph();
200  TGraph* offilter = (of2.GetFilterTD()/of2.GetFilterTD().GetMax()*amp).GetGraph();
201 
202  ofwave->SetLineColor(kRed);
203  ofwave->Draw("LSAME");
204  TGraph* apgraph = (ap.Shift(shift)*(amp/max)).GetGraph();
205  apgraph->SetLineColor(kBlue);
206  apgraph->Draw("LSAME");
207  offilter->SetLineColor(kGreen);
208  offilter->Draw("LSAME");
209  cs->SaveAs("checkof_wave.pdf");
210  return;
211  }
212 
213 
214 
215  }
216  std::cout<<"Successfull filtering : "<<double(success)/Ne*100<<" %"<<std::endl;
217  std::cout<<"Successfull filtering 2: "<<double(success2)/Ne*100<<" %"<<std::endl;
218 
219  TCanvas* c1 = new TCanvas("checkof","checkof",1200,800);
220  c1->Divide(3,2);
221  c1->cd(1);
222  ahisto2->SetLineColor(kRed);
223  ahisto2->Draw();
224  ahisto->Draw("SAME");
225 
226  c1->cd(2);
227  jhisto2->SetLineColor(kRed);
228  jhisto2->Draw();
229  jhisto->Draw("SAME");
230  c1->cd(3);
231  chisto2->SetLineColor(kRed);
232  chisto2->Draw();
233  chisto->Draw("SAME");
234  c1->cd(4);
235  lhisto2->SetLineColor(kRed);
236  lhisto2->Draw();
237  lhisto->Draw("SAME");
238  c1->cd(5);
239  rhisto2->SetLineColor(kRed);
240  rhisto2->Draw();
241  rhisto->Draw("SAME");
242  c1->cd(6);
243  shisto2->SetLineColor(kRed);
244  shisto2->Draw();
245  shisto->Draw("SAME");
246  TF1* fg = new TF1("fg","gaus");
247  shisto->Fit(fg);
248  double m1,s1,m2,s2;
249  m1 = fg->GetParameter(1);
250  s1 = fg->GetParameter(2);
251  shisto2->Fit(fg);
252  m2 = fg->GetParameter(1);
253  s2 = fg->GetParameter(2);
254  double dp = (m1-m2)/sqrt(s1*s1+s2*s2);
255  std::cout<<"DP: "<<dp<<std::endl;
256 
257  c1->SaveAs("checkof.pdf");
258 
259 
260  }
int deltat50
Definition: CheckOFShape.C:60
double amp
Definition: CheckOFShape.C:33
success2
Definition: CheckOFShape.C:189
double t0
Definition: CheckOFShape.C:27
double taud
Definition: CheckOFShape.C:29
double s2
Definition: CheckOFShape.C:248
double s1
Definition: CheckOFShape.C:248
QOptimumFilter of(ap, an,-1, false)
int Ne
Definition: CheckOFShape.C:26
int deltat80
Definition: CheckOFShape.C:61
double sigma
Definition: CheckOFShape.C:32
err
Definition: CheckOFShape.C:148
double cbase
Definition: CheckOFShape.C:53
double taur_dev
Definition: CheckOFShape.C:30
double m2
Definition: CheckOFShape.C:248
int maxpos
Definition: CheckOFShape.C:59
TF1 a
Definition: CheckOFShape.C:21
double taur
Definition: CheckOFShape.C:28
int N
Definition: CheckOFShape.C:25
QVector b
Definition: CheckOFShape.C:21
QVector an(N)
int apmaxindex
Definition: CheckOFShape.C:45
QOptimumShapeFilter of2(ap, an,-1, false, 2)
double diff
Definition: CheckOFShape.C:173
double cgain
Definition: CheckOFShape.C:54
double ofbase
Definition: CheckOFShape.C:56
double m1
Definition: CheckOFShape.C:248
double max
Definition: CheckOFShape.C:46
double fs
Definition: CheckOFShape.C:24
int deltat20
Definition: CheckOFShape.C:62
double taud_dev
Definition: CheckOFShape.C:31
double dp
Definition: CheckOFShape.C:254
TF1 * fg
Definition: CheckOFShape.C:246
ap
Definition: CheckOFShape.C:47
QVector ap1filtered2
Definition: CheckOFShape.C:52
double diff2
Definition: CheckOFShape.C:186
double sigma_of
Definition: CheckOF.C:57
success
Definition: CheckOF.C:112
double sigma_of2
Definition: CheckOF.C:58
@ QERR_SUCCESS
Definition: QError.hh:27
Diana::QVector exp(const Diana::QVector &v)
Definition: QVector.cc:833
error class with error type and description
Definition: QError.hh:115
Optimum filter implemented with windowing and zeros.
QError GetInterpolated(double &jitter, double &chi2, double &amplitude, double &integral, double &left, double &right) const
get values at interpolated chi^2 minimum. Three points around the minimum are used for a parabolic in...
Diana::QVector GetFilteredShifted() const
get filtered and shifted samples by fMaxPos
QError SetJitter(JitterMode mode, int start=0)
double GetFilteredNoiseRMS() const
expected noise rms after the filter
Diana::QVector GetFilterTD() const
kernel of the filter in the time domain
QError Filter(const Diana::QVector &p)
filter. In case of failure an error is returned.
Filter based on optimum filter tailored to preserve the shape of the original signal.
const Diana::QVector & GetOriginalAveragePulseFilteredShifted()
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...