/
smalltilecosmics.C
322 lines (274 loc) · 11.5 KB
/
smalltilecosmics.C
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#include <algorithm> // for min_element, max_element
//double peconvert = 0.00502; // volts per photoelectrion
double peconvert = 0.00035; // volts per photoelectrion
void doit(const char*);
void doit(const char*, const int);
void doit(const char*, const int, const double, const double);
void smalltilecosmics()
{
//doit("20151113-1617"); // checked 20160106
//doit("20151116-1617",50,20,100); // checked 20160106
//doit("20151118-1422"); // checked 20160106
//doit("20151123-1130",50,20,100); // checked 20160106
//doit("20151221-1413",100,20,100); // checked 20160106
//doit("20151229-1254",100,20,100); // checked 20160106, horrible statistics...
//doit("20160104-1449"); // checked 20160106
doit("20160129-1800",100,250.0,1500.0); // low gain, need to adjust peconvert...
}
void doit(const char *basename)
{
doit(basename,100,15.0,60.0);
}
void doit(const char *basename, const int nbins)
{
doit(basename,nbins,15.0,60.0);
}
void doit(const char *basename, const int nbins, const double lofit, const double hifit)
{
// --- read in the data and create a vector with all the values
// --- note that this code requires an duplicates to have already been cleaned out
// --- this is automatically fixed with the new version of the DAQ/stepper code
// --- but the user would do well do double check all output files anyway
ifstream fin1(Form("TEMP/%s_Unaveraged_VMin1.txt",basename));
double content;
vector<double> voltage1;
while(fin1>>content)
{
voltage1.push_back(content);
}
fin1.close();
cout << voltage1.size() << endl;
// --- do the same for SiPM2
ifstream fin2(Form("TEMP/%s_Unaveraged_VMin2.txt",basename));
vector<double> voltage2;
while(fin2>>content)
{
voltage2.push_back(content);
}
fin2.close();
cout << voltage2.size() << endl;
// --- get the number of entries and the min and max
int number = voltage1.size();
double max = *max_element(voltage1.begin(),voltage1.end());
double min = *min_element(voltage1.begin(),voltage1.end());
cout << max << endl;
cout << min << endl;
// --- use the min and max to calculate a range for the histogram
double newmax = min*-0.95;
double newmin = max*-1.05 - newmax*0.1;
// --- create the new histogram
TH1D *h1 = new TH1D("h1","",nbins,newmin,newmax);
TH1D *h2 = new TH1D("h2","",nbins,newmin,newmax);
TH1D *hsum = new TH1D("hsum","",nbins,2*newmin,2*newmax);
TH2D *hh1v2 = new TH2D("hh1v2","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2
TH2D *hhSvA = new TH2D("hhSvA","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry
TH2D *hh1v2_cut1 = new TH2D("hh1v2_cut1","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2
TH2D *hhSvA_cut1 = new TH2D("hhSvA_cut1","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry
TH2D *hh1v2_cut2 = new TH2D("hh1v2_cut2","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2
TH2D *hhSvA_cut2 = new TH2D("hhSvA_cut2","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry
vector<double> sum;
vector<double> asym;
// --- loop over the vector to fill the histogram
for(int i=0; i<number; i++)
{
// --- SiPM1
h1->Fill(-voltage1[i]);
// --- SiPM2
h2->Fill(-voltage2[i]);
// --- SiPM1 vs SiPM2
hh1v2->Fill(-voltage1[i],-voltage2[i]);
// --- sum vs asymmetry
double tempsum = -voltage1[i] + -voltage2[i];
double tempasym = (voltage1[i] - voltage2[i]) / (-voltage1[i] + -voltage2[i]);
hsum->Fill(tempsum);
hhSvA->Fill(tempsum,tempasym);
sum.push_back(tempsum);
asym.push_back(tempasym);
// --- now do some cuts...
if(fabs(tempasym)<0.4)
{
hh1v2_cut1->Fill(-voltage1[i],-voltage2[i]);
hhSvA_cut1->Fill(tempsum,tempasym);
}
if((voltage1[i]<(voltage2[i]+20*peconvert))&&(voltage2[i]<(voltage1[i]+20*peconvert)))
{
hh1v2_cut2->Fill(-voltage1[i],-voltage2[i]);
hhSvA_cut2->Fill(tempsum,tempasym);
}
}
// --- make a canvas and draw the histogram
TCanvas *c1 = new TCanvas("c1","",800,800);
// --- rescale the histograms from volts to photoelectrons
h1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
h1->GetXaxis()->SetTitle("Number of photoelectrons");
h1->GetYaxis()->SetTitle("Counts");
// --- define Landau function and draw
// --- don't fit yet because the data have tons of ugly low voltage1 background
double height = 1049;
double mu = 23;
double sigma = 3;
//TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",newmin/peconvert,newmax/peconvert);
TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",2*newmin/peconvert,2*newmax/peconvert);
fun->SetParameter(0,height);
fun->SetParameter(1,mu);
fun->SetParameter(2,sigma);
double bgscale = 650; // guess...
c1->SetLogy(0);
c1->Clear();
hh1v2->Draw("colz");
hh1v2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2->GetXaxis()->SetTitle("#pe SiPM1");
hh1v2->GetYaxis()->SetTitle("#pe SiPM2");
c1->SetLogz(0);
c1->Print(Form("Cosmics/%s_cosmics_1v2.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_1v2.pdf",basename));
c1->SetLogz(1);
c1->Print(Form("Cosmics/%s_cosmics_1v2_log.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_1v2_log.pdf",basename));
hhSvA->Draw("colz");
hhSvA->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
hhSvA->GetXaxis()->SetTitle("Sum");
hhSvA->GetYaxis()->SetTitle("Asymmetry");
c1->SetLogz(0);
c1->Print(Form("Cosmics/%s_cosmics_SvA.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_SvA.pdf",basename));
c1->SetLogz(1);
c1->Print(Form("Cosmics/%s_cosmics_SvA_log.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_SvA_log.pdf",basename));
// --- now for some cuts...
c1->SetLogz(0);
hh1v2_cut1->Draw("colz");
hh1v2_cut1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2_cut1->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2_cut1->GetXaxis()->SetTitle("#pe SiPM1");
hh1v2_cut1->GetYaxis()->SetTitle("#pe SiPM2");
TLatex *tex1 = new TLatex(0.2,0.8,"|Asymmetry|<0.4");
tex1->SetTextSize(0.05);
tex1->SetNDC(kTRUE);
tex1->Draw();
c1->SetLogz(0);
c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1.pdf",basename));
c1->SetLogz(1);
c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1_log.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1_log.pdf",basename));
hhSvA_cut1->Draw("colz");
hhSvA_cut1->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
hhSvA_cut1->GetXaxis()->SetTitle("Sum");
hhSvA_cut1->GetYaxis()->SetTitle("Asymmetry");
tex1->Draw();
c1->SetLogz(0);
c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1.pdf",basename));
c1->SetLogz(1);
c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1_log.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1_log.pdf",basename));
c1->SetLogz(0);
hh1v2_cut2->Draw("colz");
hh1v2_cut2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2_cut2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
hh1v2_cut2->GetXaxis()->SetTitle("#pe SiPM1");
hh1v2_cut2->GetYaxis()->SetTitle("#pe SiPM2");
TLatex *tex2 = new TLatex(0.2,0.8,"SiPMA < SiPMB + 20");
tex2->SetTextSize(0.05);
tex2->SetNDC(kTRUE);
tex2->Draw();
c1->SetLogz(0);
c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2.pdf",basename));
c1->SetLogz(1);
c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2_log.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2_log.pdf",basename));
hhSvA_cut2->Draw("colz");
hhSvA_cut2->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
hhSvA_cut2->GetXaxis()->SetTitle("Sum");
hhSvA_cut2->GetYaxis()->SetTitle("Asymmetry");
tex2->Draw();
c1->SetLogz(0);
c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2.pdf",basename));
c1->SetLogz(1);
c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2_log.png",basename));
c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2_log.pdf",basename));
hsum->SetLineColor(kBlack);
hsum->SetLineWidth(2);
hsum->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
//hsum->GetXaxis()->SetRangeUser(0.0,120.0);
hsum->GetXaxis()->SetTitle("Number of photoelectrons SiPM1+SiPM2");
hsum->Draw();
c1->Print(Form("Cosmics/%s_temp.png",basename));
c1->Print(Form("Cosmics/%s_temp.pdf",basename));
hsum->SetMaximum(30);
c1->Print(Form("Cosmics/%s_templow.png",basename));
c1->Print(Form("Cosmics/%s_templow.pdf",basename));
c1->SetLogy();
hsum->SetMaximum(1.1*h1->GetBinContent(hsum->GetMaximumBin()));
c1->Print(Form("Cosmics/%s_templog.png",basename));
c1->Print(Form("Cosmics/%s_templog.pdf",basename));
// ---------------------------------------------------------
bgscale = 100;
h1->Fit(fun,"","",lofit,hifit);
fun->SetLineColor(kRed);
fun->SetLineWidth(2);
fun->Draw("same");
cout << fun->GetChisquare() << "/" << fun->GetNDF() << endl;
c1->SetLogy(0);
c1->Print(Form("Cosmics/%s_tempfit.png",basename));
c1->Print(Form("Cosmics/%s_tempfit.pdf",basename));
h1->SetMaximum(175);
c1->Print(Form("Cosmics/%s_templowfit.png",basename));
c1->Print(Form("Cosmics/%s_templowfit.pdf",basename));
h1->SetMaximum(100);
c1->Print(Form("Cosmics/%s_tempLOWfit.png",basename));
c1->Print(Form("Cosmics/%s_tempLOWfit.pdf",basename));
c1->SetLogy(1);
h1->SetMaximum(1.1*h1->GetBinContent(h1->GetMaximumBin()));
c1->Print(Form("Cosmics/%s_templogfit.png",basename));
c1->Print(Form("Cosmics/%s_templogfit.pdf",basename));
c1->Clear();
h1->Draw();
double hax = fun->GetParameter(0);
double mux = fun->GetParameter(1);
double six = fun->GetParameter(2);
fun->SetParameter(0,0.95*hax);
fun->SetParameter(1,mux);
fun->SetParameter(2,1.1*six);
//fun->Draw("same");
//h1->Fit(simplefun,"","",0,60);
TF1 *fun2 = new TF1("fun2","([0]/sqrt(6.28))*TMath::Exp(-0.5*((x-[1])/[2] + TMath::Exp(-(x-[1])/[2])))",2*newmin/peconvert,2*newmax/peconvert);
// fun2->SetParameter(0,hax);
// fun2->SetParameter(1,mux);
// fun2->SetParameter(2,six);
// fun2->SetParameter(0,93);
// fun2->SetParameter(1,35);
// fun2->SetParameter(2,5);
fun2->SetParameter(0,93);
fun2->SetParameter(1,500);
fun2->SetParameter(2,100);
//fun2->SetLineColor(kBlack);
h1->Fit(fun2,"","",lofit,hifit);
fun2->Draw("same");
cout << fun2->GetChisquare() << "/" << fun2->GetNDF() << endl;
double par1 = fun2->GetParameter(1);
TLine line(par1,0,par1,0.24*fun2->GetParameter(0));
line.Draw();
c1->SetLogy(0);
c1->Print(Form("Cosmics/%s_tempffit.png",basename));
c1->Print(Form("Cosmics/%s_tempffit.pdf",basename));
h1->SetMaximum(25);
c1->Print(Form("Cosmics/%s_templowffit.png",basename));
c1->Print(Form("Cosmics/%s_templowffit.pdf",basename));
h1->SetMaximum(0.3*fun2->GetParameter(0));
TLatex *tex = new TLatex(0.6,0.8,Form("MPV = %.1f #pm %.1f",fun2->GetParameter(1),fun2->GetParError(1)));
tex->SetNDC();
tex->SetTextSize(0.05);
tex->Draw();
//h1->GetXaxis()->SetRangeUser(0.0,130.0); // new...
c1->Print(Form("Cosmics/SmallTileCosmics_%s_tempLOWffit.png",basename));
c1->Print(Form("Cosmics/SmallTileCosmics_%s_tempLOWffit.pdf",basename));
c1->SetLogy(1);
h1->SetMaximum(1.1*h1->GetBinContent(h1->GetMaximumBin()));
c1->Print(Form("Cosmics/%s_templogffit.png",basename));
c1->Print(Form("Cosmics/%s_templogffit.pdf",basename));
}