Skip to content

Commit b27d792

Browse files
committed
Tracks Cleaning added
1 parent 8d21d45 commit b27d792

File tree

2 files changed

+95
-30
lines changed

2 files changed

+95
-30
lines changed

DQM_SiPM.py

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,27 @@ def __init__(self, infile):
3434
for i, l in enumerate(self.raw_conf):
3535
if l[0] == '#':
3636
continue
37-
l = l[0:-1].split(' ')
38-
if '-->Pri' in l[0]:
37+
l = l[0:-1].split()
38+
if '-->Print' in l[0]:
3939
self.plots = l[1:]
4040
print "Plots expected:"
4141
print self.plots
4242
elif '-->XYcenter' in l[0]:
4343
self.xy_center = [float(l[1]), float(l[2]), float(l[3])]
44+
elif '-->TracksCleaning' in l[0]:
45+
self.TracksCleaning = {}
46+
cuts = ''
47+
for aux in l[1:]:
48+
if aux[:7] == 'CutOnCh':
49+
self.TracksCleaning['ch'] = int(aux[7:])
50+
print 'Cuts from ch', int(aux[7:]), 'will be used for cleaning tracks'
51+
else:
52+
cuts += aux + ' && '
53+
if len(cuts) > 3:
54+
self.TracksCleaning['cuts'] = cuts[:-4]
55+
print 'Cleaning tracks with:', cuts[:-4]
56+
else:
57+
self.TracksCleaning['cuts'] = ''
4458
elif len(self.labels) == 0:
4559
self.labels = l[1:]
4660
else:
@@ -187,7 +201,32 @@ def define_range_around_peak(h, perc = [0.4, 0.4], Range=[0.0, 99999.0]):
187201
rt.gStyle.SetStatH(0.1);
188202
rt.gStyle.SetHistLineWidth(2);
189203

204+
'''=========================== AllTracks ==========================='''
205+
if 'AllTracks' in configurations.plots:
206+
name = 'h_alltracks'
207+
title = 'All tracks at z_DUT[0]'
208+
209+
var = 'y_dut[0]:x_dut[0]'
210+
dy = configurations.xy_center[1]
211+
dx = configurations.xy_center[0]
212+
width = configurations.xy_center[2]
213+
214+
h = rt.TH2D(name, title, 100, -width+dx, width+dx, 100, -width+dy, width+dy)
215+
h.SetXTitle('x [mm]')
216+
h.SetYTitle('y [mm]')
217+
218+
sel = ''
219+
if hasattr(configurations, 'TracksCleaning'):
220+
sel += configurations.TracksCleaning['cuts']
221+
chain.Project(name, var, sel)
222+
223+
canvas['AllTracks'] = rt.TCanvas('c_allTracks', 'c_allTracks', 800, 600)
224+
h.DrawCopy('colz')
225+
226+
canvas['AllTracks'].Update()
227+
canvas['AllTracks'].SaveAs(out_dir + '/AllTracks.png')
190228

229+
'''======================= Channels loop ==========================='''
191230
for k in configurations.ch_ordered:
192231
print '---> Channel', k
193232
conf = configurations.channel[k]
@@ -212,19 +251,17 @@ def define_range_around_peak(h, perc = [0.4, 0.4], Range=[0.0, 99999.0]):
212251
chain.Project(name, 'amp['+str(k)+']')
213252

214253
Range = [0.0, 9999999.0]
215-
if 'amp_min' in conf.keys():
216-
conf['amp_min'] = float(conf['amp_min'])
217-
Range[0] = conf['amp_min']
218-
if 'amp_max' in conf.keys():
219-
conf['amp_max'] = float(conf['amp_max'])
220-
Range[1] = conf['amp_max']
254+
if 'cut' in conf.keys():
255+
if conf['cut'][0] in ['a', 'A']:
256+
if 'min' in conf.keys():
257+
Range[0] = float(conf['min'])
258+
if 'max' in conf.keys():
259+
Range[1] = float(conf['max'])
221260

222-
x_low, x_up, n_pk = define_range_around_peak(h, [0.35, 0.3], Range)
261+
x_low, x_up, n_pk = define_range_around_peak(h, [0.2, 0.2], Range)
223262

224263
canvas['amp'][k] = rt.TCanvas('c_amp_'+str(k), 'c_amp_'+str(k), 800, 600)
225264
h.DrawCopy('E')
226-
line.DrawLine(x_low, 0, x_low, h.GetMaximum())
227-
line.DrawLine(x_up, 0, x_up, h.GetMaximum())
228265

229266
gr = rt.TGraph(1)
230267
gr.SetPoint(0, h.GetBinCenter(n_pk), h.GetBinContent(n_pk))
@@ -235,10 +272,15 @@ def define_range_around_peak(h, perc = [0.4, 0.4], Range=[0.0, 99999.0]):
235272
if h.GetMaximum() > 5*h.GetBinContent(n_pk):
236273
canvas['amp'][k].SetLogy()
237274

275+
if 'cut' in conf.keys():
276+
if conf['cut'][0] in ['a', 'A']:
277+
selection += ' && (amp[{}]>{} && amp[{}]<{})'.format(k, x_low, k, x_up)
278+
line.DrawLine(x_low, 0, x_low, h.GetMaximum())
279+
line.DrawLine(x_up, 0, x_up, h.GetMaximum())
280+
238281
canvas['amp'][k].Update()
239282
canvas['amp'][k].SaveAs(out_dir + '/Amp_ch{:02d}.png'.format(k))
240283

241-
selection += ' && (amp[{}]>{} && amp[{}]<{})'.format(k, x_low, k, x_up)
242284

243285
'''=========================== Integral ==========================='''
244286
if 'Int' in configurations.plots:
@@ -247,27 +289,41 @@ def define_range_around_peak(h, perc = [0.4, 0.4], Range=[0.0, 99999.0]):
247289
name = 'h_int_'+str(k)
248290
title = 'Integral channel '+str(k)
249291
int_aux = -np.concatenate(list(tree2array(chain, 'integral['+str(k)+']', 'integral['+str(k)+'] != 0')))
250-
h = rt.TH1D(name, title, 100, np.percentile(int_aux, 0.1), np.percentile(int_aux, 99.9))
292+
h = rt.TH1D(name, title, 100, np.percentile(int_aux, 0.1), np.max(int_aux))
251293
h.SetXTitle('Integral [pC]')
252294
h.SetYTitle('Events / {:.1f} pC'.format(h.GetBinWidth(1)))
253295
chain.Project(name, '-integral['+str(k)+']', '-integral['+str(k)+'] != 0')
254296

255-
x_low, x_up, n_pk = define_range_around_peak(h, [0.25, 0.3])
297+
Range = [0.0, 9999999.0]
298+
if 'cut' in conf.keys():
299+
if conf['cut'][0] in ['i', 'I']:
300+
if 'min' in conf.keys():
301+
Range[0] = float(conf['min'])
302+
if 'max' in conf.keys():
303+
Range[1] = float(conf['max'])
256304

257-
if conf['idx_ref'] >= 0:
258-
res = h.Fit('landau','LQSR', '', x_low, x_up)
305+
x_low, x_up, n_pk = define_range_around_peak(h, [0.25, 0.3], Range)
306+
307+
h.DrawCopy('E')
308+
309+
gr = rt.TGraph(1)
310+
gr.SetPoint(0, h.GetBinCenter(n_pk), h.GetBinContent(n_pk))
311+
gr.SetMarkerStyle(23)
312+
gr.SetMarkerColor(2)
313+
gr.Draw("P")
259314

260315
if(h.GetMaximum() - h.GetMinimum() > 5000):
261316
canvas['int'][k].SetLogy()
262-
h.DrawCopy('E')
263-
line.DrawLine(x_low, 0, x_low, h.GetMaximum())
264-
line.DrawLine(x_up, 0, x_up, h.GetMaximum())
317+
318+
if 'cut' in conf.keys():
319+
if conf['cut'][0] in ['i', 'I']:
320+
selection += ' && (-integral[{}]>{} && -integral[{}]<{})'.format(k, x_low, k, x_up)
321+
line.DrawLine(x_low, 0, x_low, h.GetMaximum())
322+
line.DrawLine(x_up, 0, x_up, h.GetMaximum())
265323

266324
canvas['int'][k].Update()
267325
canvas['int'][k].SaveAs(out_dir + '/Int_ch{:02d}.png'.format(k))
268326

269-
selection += ' && (-integral[{}]>{} && -integral[{}]<{})'.format(k, x_low, k, x_up)
270-
271327
'''=========================== Risetime ======================================='''
272328
if 'Risetime' in configurations.plots:
273329
print '\tRisetime'
@@ -323,6 +379,14 @@ def define_range_around_peak(h, perc = [0.4, 0.4], Range=[0.0, 99999.0]):
323379

324380
'''=========================== Track position ==========================='''
325381
if conf['idx_dut'] >= 0:
382+
if hasattr(configurations, 'TracksCleaning'):
383+
selection += ' && ' + configurations.TracksCleaning['cuts']
384+
385+
if 'ch' in configurations.TracksCleaning.keys():
386+
ch = configurations.TracksCleaning['ch']
387+
if ch < k:
388+
selection += ' && ' + configurations.channel[ch]['sel']
389+
326390
var = 'y_dut[{}]:x_dut[{}]'.format(conf['idx_dut'], conf['idx_dut'])
327391
dy = configurations.xy_center[1]
328392
dx = configurations.xy_center[0]

config/FNAL_TB_1811/VME_vr1.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#-->Print: Amp PosRaw PosWeight TimeResRaw TimeCorrected
2-
-->Print: Amp Int PosRaw PosWeight WaveColor TimeResRaw TimeCorrected
3-
-->XYcenter-width: 20 20 30
4-
ch_num idx_time idx_dut idx_ref var_ref amp_min amp_max
5-
9 2 0 -1 gaus_mean 20 200
6-
14 2 0 -1 None 600 1200
7-
15 2 0 -1 None 600 1200
8-
18 2 0 -1 gaus_mean 20 200
9-
24 2 0 -1 None 200 800
10-
25 2 0 18 LP2_20 200 800
2+
-->Print: AllTracks Amp Int PosRaw PosWeight WaveColor TimeResRaw
3+
-->XYcenter-width: 20 25 20
4+
-->TracksCleaning: CutOnCh9 ntracks==1 chi2<5
5+
ch_num idx_time idx_dut idx_ref var_ref cut min max
6+
9 1 0 -1 gaus_mean I 0 200
7+
14 1 0 -1 None A 600 1200
8+
15 1 0 -1 None A 600 1200
9+
18 2 0 -1 gaus_mean I 0 200
10+
24 2 0 -1 None A 200 800
11+
25 2 0 -1 None A 200 800

0 commit comments

Comments
 (0)