Diana Software
CheckOF.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  int N = 2048;
25  int Ne = 1e3;
26  double t0 = 200;
27  double taur = 10;
28  double taud = 200;
29  double taur_dev = 1.0;
30  double taud_dev = 1.0;
31  double sigma = 1;
32  double amp = 100; // in sigma_of
33 
34  QVector an(N);
35  an.Initialize(sigma*sigma*N);
36  QVector ap(N);
37  ap.Initialize(0);
38  QVector ap2(N);
39  ap2.Initialize(0);
40 
41  for(int i = 0; i < N; i++) {
42  double t = i-t0;
43  if(t < 0) continue;
44  ap[i] += -exp(-t/taur) + exp(-t/taud);
45  }
46  int apmaxindex = ap.GetMaxIndex();
47  for(int i = apmaxindex; i > 0; i--) {
48  ap2[i] = ap[i];
49  ap2[2*apmaxindex-i] = ap[i];
50  }
51  ap2 = ap;
52 
53  double max = ap.GetMax()-ap[0];
54 
55  QOptimumFilter of(ap,an,-1,false);
56  QOptimumFilter of2(ap2,an,-1,false);
59  amp *= sigma_of;
60  std::cout<<"Simga OF: "<<sigma_of<<" amp: "<<amp<<std::endl;
61  std::cout<<"Simga OF2: "<<sigma_of<<std::endl;;
62 
63  TH1D* ahisto = new TH1D("ahisto","ahisto",sqrt(Ne),amp-5*sigma_of,amp+5*sigma_of);
64  TH1D* lhisto = new TH1D("lhisto","lhisto",sqrt(Ne),0,10);
65  TH1D* rhisto = new TH1D("rhisto","rhisto",sqrt(Ne),0,10);
66  TH1D* chisto = new TH1D("chisto","chisto",sqrt(Ne),0,2);
67  TH1D* jhisto = new TH1D("jhisto","jhisto",240,-30,30);
68 
69  TH1D* ahisto2 = new TH1D("ahisto2","ahisto2",sqrt(Ne),amp-5*sigma_of,amp+5*sigma_of);
70  TH1D* lhisto2 = new TH1D("lhisto2","lhisto2",sqrt(Ne),0,10);
71  TH1D* rhisto2 = new TH1D("rhisto2","rhisto2",sqrt(Ne),0,10);
72  TH1D* chisto2 = new TH1D("chisto2","chisto2",sqrt(Ne),0,2);
73  TH1D* jhisto2 = new TH1D("jhisto2","jhisto2",50*taur,-5*taur,5*taur);
74 
75  TRandom rand;
76  rand.SetSeed(0);
77 
78 
79  int success = 0, success2 = 0;
80  for(int e = 0; e < Ne; e++) {
81  if(e%100 == 0) cout<<"Event: "<<e<<std::endl;
82 
83  double shift=rand.Uniform(-4*taur,4*taur);
84  QVector signal(N),signal2(N);
85  signal.Initialize(0);
86  signal2.Initialize(0);
87  for(int i = 0; i < N; i++) {
88  double t = double(i-t0)-shift;
89  signal[i] += rand.Gaus(0,sigma);
90  signal2[i] += rand.Gaus(0,sigma);
91  if(t < 0) continue;
92  signal[i] += amp/max*(-exp(-t/taur) + exp(-t/taud));
93  signal2[i] += amp/max*(-exp(-t/taur/taur_dev) + exp(-t/taud/taud_dev));
94  }
95 
96 
97 
98  //return;
99  QError err;
100  err = of.Filter(signal);
101  if(err != QERR_SUCCESS) continue;
103  if(err != QERR_SUCCESS) continue;
104  double jitter,chi2,amplitude,integral,left,right;
105  err = of.GetInterpolated(jitter,chi2,amplitude,integral,left,right);
106  if(err != QERR_SUCCESS) continue;
107  ahisto->Fill(amplitude);
108  lhisto->Fill(left);
109  rhisto->Fill(right);
110  chisto->Fill(chi2);
111  jhisto->Fill(jitter-shift);
113 
114  err = of2.Filter(signal2);
115  if(err != QERR_SUCCESS) continue;
117  if(err != QERR_SUCCESS) continue;
118  double jitter2,chi22,amplitude2,integral2,left2,right2;
119  err = of2.GetInterpolated(jitter2,chi22,amplitude2,integral2,left2,right2);
120  if(err != QERR_SUCCESS) continue;
121  ahisto2->Fill(amplitude2);
122  lhisto2->Fill(left2);
123  rhisto2->Fill(right2);
124  chisto2->Fill(chi22);
125  jhisto2->Fill(jitter2-shift);
126  success2++;
127 
128 
129  if(e == 0) {
130  TCanvas * cs = new TCanvas("cs","cs",800,600);
131  signal.GetGraph()->Draw("AL");
132  TGraph* ofwave = of.GetFilteredShifted().GetGraph();
133 
134  ofwave->SetLineColor(kRed);
135  ofwave->Draw("LSAME");
136  TGraph* apgraph = (ap.Shift(shift)*(amp/max)).GetGraph();
137  apgraph->SetLineColor(kBlue);
138  apgraph->Draw("LSAME");
139  cs->SaveAs("checkof_wave.pdf");
140  }
141 
142 
143 
144  }
145  std::cout<<"Successfull filtering : "<<double(success)/Ne*100<<" %"<<std::endl;
146  std::cout<<"Successfull filtering 2: "<<double(success2)/Ne*100<<" %"<<std::endl;
147 
148  TCanvas* c1 = new TCanvas("checkof","checkof",1200,800);
149  c1->Divide(3,2);
150  c1->cd(1);
151  ahisto2->SetLineColor(kRed);
152  ahisto2->Draw();
153  ahisto->Draw("SAME");
154 
155  c1->cd(2);
156  jhisto2->SetLineColor(kRed);
157  jhisto2->Draw();
158  jhisto->Draw("SAME");
159  c1->cd(3);
160  chisto2->SetLineColor(kRed);
161  chisto2->Draw();
162  chisto->Draw("SAME");
163  c1->cd(4);
164  lhisto2->SetLineColor(kRed);
165  lhisto2->Draw();
166  lhisto->Draw("SAME");
167  c1->cd(5);
168  rhisto2->SetLineColor(kRed);
169  rhisto2->Draw();
170  rhisto->Draw("SAME");
171  c1->SaveAs("checkof.pdf");
172 
173 
174  }
success2
Definition: CheckOFShape.C:189
double max
Definition: CheckOF.C:53
double amp
Definition: CheckOF.C:32
double t0
Definition: CheckOF.C:26
double taud
Definition: CheckOF.C:28
ap2
Definition: CheckOF.C:51
double sigma_of
Definition: CheckOF.C:57
QOptimumFilter of(ap, an,-1, false)
int Ne
Definition: CheckOF.C:25
double sigma
Definition: CheckOF.C:31
err
Definition: CheckOF.C:114
double taur_dev
Definition: CheckOF.C:29
TF1 a
Definition: CheckOF.C:21
double taur
Definition: CheckOF.C:27
int N
Definition: CheckOF.C:24
QVector b
Definition: CheckOF.C:21
QOptimumFilter of2(ap2, an,-1, false)
QVector an(N)
int apmaxindex
Definition: CheckOF.C:46
success
Definition: CheckOF.C:112
QVector ap(N)
double taud_dev
Definition: CheckOF.C:30
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
QError Filter(const Diana::QVector &p)
filter. In case of failure an error is returned.
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...