-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindTauElec.C
More file actions
188 lines (135 loc) · 5.63 KB
/
findTauElec.C
File metadata and controls
188 lines (135 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "FFTtools.h"
#include "FFTWComplex.h"
#include "RFSignal.h"
#include "functions.h"
double xmin = 0.05E-3;
double xmax = 0.015E-3;
double ymin = -0.8;
double ymax = +0.8;
//string basename = "2018Apr11liquefaction/Day3_allLiquid/cathodeANDanode/";
string whichAvg[4] = {"justAvg", "filteredAvg", "zeroedAvg", "fancyFilteredAvg"};
void findTauElec(string basename, string fieldname, string divname, string preamp){
string outfile = basename + fieldname + "_" + divname + "_" + preamp + "_signals.root";
string outcanvas = basename + fieldname + "_" + divname + "_" + preamp + "_tauelec";
cout << "Output file is " << outfile << endl;
string chname[2] = {"ch3", "ch4"};
string chnamenice[2] = {"anode", "Cathode"};
double timedelay=0;
string stimedelay = basename + fieldname + "_FibreIn_" + divname + "_" + preamp + ".ch1.traces_averages.root";
TFile *ftimedelay = new TFile (stimedelay.c_str(), "read");
TGraph *gtimedelay = (TGraph*)ftimedelay->Get("justAvg");
double *xTimeDelay = gtimedelay->GetX();
double *yTimeDelay = gtimedelay->GetY();
double baseY = yTimeDelay[0];
double step = 2.5;
for (int ip=0; ip<gtimedelay->GetN(); ip++){
if (yTimeDelay[ip]>(baseY+step)){
timedelay = xTimeDelay[ip];
break;
}
}
ftimedelay->Close();
timedelay = 811*1E-6;
cout << "The time delay is " << timedelay << endl;
double newy[20000];
double newx[20000];
TFile *out = new TFile(outfile.c_str(), "recreate");
double finalNumbers[2][3]; // [0 anode, 1 cathode] [0 amplitude, 1 start time, 2 peak time]
for (int iavg=0; iavg<1; iavg++){
for (int ich=1; ich<2; ich++){
string f1 = basename + fieldname + "_FibreIn_" + divname + "_" + preamp + "." + chname[ich] +".traces_averages.root";
//string f2 = basename + fieldname + "_FibreOut_" + divname + "_" + preamp + "."+ chname[ich] + ".traces_averages.root";
TFile *file1 = new TFile(f1.c_str(), "read");
//TFile *file2 = new TFile(f2.c_str(), "read");
TGraph *g1 = (TGraph*)file1->Get(whichAvg[iavg].c_str());
g1->SetName("g1");
//TGraph *g2;
//bool isFibreOut;
//g2 = (TGraph*)file2->Get(whichAvg[iavg].c_str());
//g2->SetName("g2");
//isFibreOut = true;
file1->Close();
//file2->Close();
g1 = FFTtools::translateGraph(g1, -timedelay);
//g2 = FFTtools::translateGraph(g2, -timedelay);
int N = g1->GetN();
double *x = g1->GetX();
double *y1 = g1->GetY();
//double *y2 = g2->GetY();
for (int i=0; i<N; i++){
//if (isFibreOut) newy[i] = y1[i] - y2[i];
//else
newy[i] = y1[i];
newx[i] = x[i];
}
TGraph *gdiff = new TGraph(N, newx, newy);
// TGraph *gdiff = subtractNoise(g1, g2);
TCanvas *c = new TCanvas("c");
c->Divide(1,2);
c->cd(1);
g1->SetLineColor(kBlue);
//g2->SetLineColor(kRed);
g1->GetXaxis()->SetRangeUser(xmin, xmax);
g1->GetYaxis()->SetRangeUser(ymin, ymax);
g1->Draw("Al");
//g2->Draw("l");
c->cd(2);
gdiff->GetXaxis()->SetRangeUser(xmin, xmax);
gdiff->GetYaxis()->SetRangeUser(ymin, ymax);
gdiff->Draw("Al");
out->cd();
c->Write((chnamenice[ich]+"_"+whichAvg[iavg]+"_canvas").c_str());
gdiff->Write((chnamenice[ich]+"_"+whichAvg[iavg]).c_str());
// gdiff = FFTtools::translateGraph(gdiff, -gdiff->GetX()[0]);
zeroBaseline(gdiff);
// removeGarbage(gdiff);
TGraph *gdiff2 = smoothGraph(gdiff, 10);
gdiff2->Write((chnamenice[ich]+"_"+whichAvg[iavg]+"_smoothed").c_str());
if (iavg==0){
gStyle->SetOptFit(1);
gStyle->SetStatY(0.4);
gStyle->SetStatX(0.9);
gStyle->SetStatW(0.2);
gStyle->SetStatH(0.2);
TCanvas *ctemp = new TCanvas ("ctemp");
gdiff2->SetTitle(Form("%s;Time (s);Amplitude (V)", preamp.c_str()));
gdiff2->Draw("Al");
// TF1 *func = new TF1("func",greenFunction2,-0.1E-3,0.7E-3,4);
// func->SetParameters(0.01, 0.1, 500, 6);
// func->SetParName(0, "Q (pC)");
// // func->SetParLimits(0, 1e-6, 2e-6);
// func->SetParName(1, "C (pF)");
// // func->FixParameter(1, 0.1);
// func->SetParLimits(1, 0.1, 0.2);
// func->SetParName(2, "R (M#Omega)");
// //func->SetParLimits(2, 490, 510);
// func->SetParName(3, "t_0 (#mus)");
TF1 *func = new TF1("func",greenFunction,-0.30E-3,1.2E-3,4);
//par[0] = Q*G, par[1]=tau_el
func->SetParameters(2.6, 43, 20,3);
func->SetParName(0, "Gain x Q ");
//func->SetParLimits(0, 2, 3);
func->SetParName(1, "Tau (#mus)");
//func->SetParLimits(1, 40, 45);
func->SetParName(2, "Rise (#mus)");
func->SetParName(3, "Shift (#mus)");
//func->SetParName(2, "t_0 (#mus)");
//func->SetParLimits(2, -10, 10);
gdiff2->Fit("func","R");
func->Draw("same");
double tauelec = func->GetParameter(1)*func->GetParameter(2);
ctemp->Update();
TLatex *text = new TLatex();
//text->DrawTextNDC(0.5, 0.5, Form("#tau_{elec} = %3.2f #mus", tauelec));
ctemp->Print((outcanvas+".png").c_str());
ctemp->Print((outcanvas+".pdf").c_str());
ctemp->Print((outcanvas+".C").c_str());
}
//delete gdiff;
// delete gdiff2;
//delete c;
file1->Close();
//file2->Close();
}
}
}