-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotDrifTime.C
More file actions
217 lines (153 loc) · 6.05 KB
/
plotDrifTime.C
File metadata and controls
217 lines (153 loc) · 6.05 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include "functions.h"
string basename="2018Apr11liquefaction/Day3_allLiquid/cathodeANDanode/";
string fields[] = {"noField", "K-22GK22_25Vcm", "K-45GK45_50Vcm", "K-135GK135_150Vcm", "K-405GK405_450Vcm", "K-900GK900_1000Vcm", "K-1600GK1100_1500Vcm"};
string divisions[] = {"200mVdiv", "100mVdiv", "100mVdiv", "100mVdiv", "100mVdiv", "100mVdiv", "100mVdiv"};
string fieldNice[] = {"No field", "25 V/cm", "50 V/cm", "150 V/cm", "450 V/cm", "1000 V/cm", "1500 V/cm"};
int numToAverage[] = { 20, 20, 20, 20, 20, 10, 10, 10};
double scaleY[2] = {0.1, 0.2};
int avgSomeGraphs(string filename, TGraph **g, int nmax, TGraph *fibreOut);
void getPurity(TGraph *gK, double output[4], int igraph, int ifield);
TGraph *noiseTemplatePS;
void getTheNumbers(int ifield, double dip[2], double drift[2], int numToAverage);
void plotDrifTime(){
gErrorIgnoreLevel = kWarning;
double dip[2];
double drift[2];
for (int ifield=0; ifield<7; ifield++){
getTheNumbers(ifield, dip, drift, numToAverage[ifield]);
printf("%15s: -(%5.2f +/- %5.2f), %5.2f +/- %5.2f \n", fields[ifield].c_str(), dip[0], dip[1], drift[0], drift[1]);
}
}
void getTheNumbers(int ifield, double dip[2], double drift[2], int numToAverage){
TGraph *someCathode[1000];
string fnameOut = basename + fields[ifield] + "_FibreOut_" + divisions[ifield] + ".ch4.traces_averages.root";
TFile *finOut = new TFile(fnameOut.c_str(), "read");
TGraph *fibreOut = (TGraph*)finOut->Get("zeroedAvg");
string fname = basename + fields[ifield] + "_FibreIn_" + divisions[ifield] + ".ch4.traces_averages.root";
TFile *finIn = new TFile(fname.c_str(), "read");
noiseTemplatePS = (TGraph*)finIn->Get("avgPowerSpectrum");
string fnameIn = basename + fields[ifield] + "_FibreIn_" + divisions[ifield] + ".ch4.traces.root";
int ntot = avgSomeGraphs(fnameIn, someCathode, numToAverage, fibreOut);
double thisoutput[4];
TH1D *hDip = new TH1D("hDip", "", 100, 0, 300 );
TH1D *hDrift = new TH1D("hDrift", "", 100, 0, 30 );
for (int i=0; i<ntot; i++){
getPurity(someCathode[i], thisoutput, i, ifield);
hDip->Fill(TMath::Abs(thisoutput[0]*1e3));
hDrift->Fill(thisoutput[3]*1e6);
// cout << thisoutput[0] << " " << thisoutput[3] << endl;
}
gStyle->SetOptStat("MR");
TCanvas *c = new TCanvas("c");
hDip->SetTitle(";Cathode dip [mV];Entries");
hDip->Draw();
c->Print(Form("plots/HistoDip_%s.png", fields[ifield].c_str()));
dip[0] = hDip->GetMean();
dip[1] = hDip->GetRMS();
TCanvas *c2 = new TCanvas("c2");
hDrift->SetTitle(";Rising time [#musec];Entries");
hDrift->Draw();
c2->Print(Form("plots/HistoRisingTime_%s.png", fields[ifield].c_str()));
drift[0] = hDrift->GetMean();
drift[1] = hDrift->GetRMS();
finOut->Close();
finIn->Close();
delete hDip;
delete hDrift;
delete c;
delete c2;
}
int avgSomeGraphs(string filename, TGraph **g, int nmax, TGraph *fibreOut){
TFile *f = new TFile(filename.c_str(), "read");
TGraph *graphs[1000];
int count = 0;
int ntot = 0;
double newy[10005];
double newx[10005];
for (int i=0; i<1000; i++){
// cout << i << endl;
graphs[count] = (TGraph*) f->Get(Form("graph%i", i+1));
if(!graphs[count]) break;
count++;
if (count==nmax){
g[ntot] = getZeroedAverage( count, graphs );
// //TGraph *gtemp = getFilteredAverage( count, graphs, noiseTemplatePS, 0.1 );
g[ntot] = subtractGraphs(g[ntot], fibreOut);
zeroBaseline(g[ntot]);
g[ntot] = smoothGraph(g[ntot], 50);
count = 0;
ntot++;
// delete gtemp;
}
}
f->Close();
// cout << ntot << endl;
return ntot;
}
void getPurity(TGraph *gK, double output[4], int igraph, int ifield){
int nK = gK->GetN();
double *xK = gK->GetX();
double *yK = gK->GetY();
double minK = 999999;
double minKtime = 0;
for (int ip=2000; ip<nK*0.75; ip++){
if (yK[ip]<minK){
minK = yK[ip];
minKtime = xK[ip];
}
}
minKtime*=1e6;
// cout << "Min K and time are " << minK << " " << minKtime << endl;
// double t0 = 85;
// double lifetime = - (minKtime-t0)/TMath::Log(maxGK/TMath::Abs(minK));
// cout << "The electrons lifetime is " << lifetime << endl;
gK->SetTitle(Form(";Time [s];Amplitude [V]"));
gK->GetYaxis()->SetRangeUser(-scaleY[1], scaleY[1]);
double xmin = gK->GetXaxis()->GetBinLowEdge(0);
double xmax = gK->GetXaxis()->GetBinUpEdge(nK);
TLine *l0 = new TLine(xmin, 0, xmax, 0);
l0->SetLineStyle(2);
TF1 *func = new TF1("func",fittingFunction,0.04E-3,0.24E-3,4);
func->SetParameters(2, 40, -0.5, 90.);
func->SetParLimits(0, 1, 20);
func->SetParLimits(1, 10, 100);
func->SetParLimits(2, -100, 0);
func->SetParLimits(3, 10, 100);
func->SetParName(0, "#sigma");
func->SetParName(1, "#tau_{D}");
func->SetParName(2, "a");
func->SetParName(3, "t_0");
gStyle->SetOptFit(1);
// Fit histogram in range defined by function
gK->Fit("func","RQ");
// cout << func->GetParameter(0) << " " << func->GetParameter(1) << " " << func->GetParameter(2) << " " << func->GetParameter(3) << endl;
double fittedMinK = func->GetMinimum(0.04E-3,0.24E-3);
double fittedMinKtime = func->GetMinimumX(0.04E-3,0.24E-3);
double fittedKstartTime = 0;
double tempx, tempy;
for (int ip=0; ip<nK; ip++){
tempx = xK[ip];
tempy = func->Eval(xK[ip]);
if (tempy<0.01*fittedMinK){
// cout << ip << " " << tempx << " " << tempy << " " << endl;
fittedKstartTime = tempx;
break;
}
}
double fittedDriftTime = fittedMinKtime - fittedKstartTime;
// cout << "Fitted Cathode min " << fittedMinK << endl;
// cout << "Fitted Cathode min time " << fittedMinKtime << endl;
// cout << "Fitted Cathode start time " << fittedKstartTime << endl;
// cout << "Fitted drift time " << fittedDriftTime << endl;
output[0] = fittedMinK;
output[1] = fittedMinKtime;
output[2] = fittedKstartTime;
output[3] = fittedDriftTime;
if (igraph==0){
TCanvas *c1 = new TCanvas("c1");
gK->Draw("Al");
l0->Draw();
c1->Print(Form("plots/ExampleAverage_%s.png", fields[ifield].c_str()));
delete c1;
}
}