@@ -252,9 +252,9 @@ def define_range_around_peak(h, perc = [0.4, 0.4], m = 0):
252252 h .SetXTitle ('Risetime [ns]' )
253253 h .SetYTitle ('Events / {:.1f} ns' .format (h .GetBinWidth (1 )))
254254 if conf ['idx_ref' ] == - 1 :#do not apply cut again on reference channels
255- cut = conf [ 'amp_sel' ]
255+ cut = selection
256256 else :
257- cut = conf [ 'amp_sel' ] + '&&' + configurations .channel [conf ['idx_ref' ]]['amp_sel ' ]
257+ cut = selection + '&&' + configurations .channel [conf ['idx_ref' ]]['sel ' ]
258258
259259 chain .Project (name , 'risetime[' + str (k )+ ']' , cut )
260260
@@ -347,7 +347,8 @@ def define_range_around_peak(h, perc = [0.4, 0.4], m = 0):
347347
348348 selection = conf ['sel' ] + ' && ' + configurations .channel [conf ['idx_ref' ]]['sel' ] + ' && {} != 0' .format (time_var )
349349
350- delta_t = np .concatenate (list (tree2array (chain , var_dT , selection )))
350+ # delta_t = np.concatenate(list(tree2array(chain, var_dT, selection)))
351+ delta_t = tree2array (chain , var_dT , selection ).flatten ()
351352 if ( len (delta_t ) == 0 ):
352353 print 'Empty delta'
353354 continue
@@ -379,146 +380,147 @@ def define_range_around_peak(h, perc = [0.4, 0.4], m = 0):
379380 delta_t = np .concatenate (list (tree2array (chain , var_dT , selection )))
380381 arr = {}
381382
382- '''=========================== Time resolution vs impact point ==========================='''
383- i_s = conf ['idx_dut' ]
383+ if 'TimeCorrected' in configurations .plots :
384+ '''=========================== Time resolution vs impact point ==========================='''
385+ i_s = conf ['idx_dut' ]
384386
385- name = 'c_space_corr' + str (k )
386- canvas ['space_corr' ][k ] = rt .TCanvas (name , name , 1000 , 600 )
387- canvas ['space_corr' ][k ].Divide (2 )
387+ name = 'c_space_corr' + str (k )
388+ canvas ['space_corr' ][k ] = rt .TCanvas (name , name , 1000 , 600 )
389+ canvas ['space_corr' ][k ].Divide (2 )
388390
389- selection += ' && ntracks == 1 && chi2 < 8'
390- delta_t = np .concatenate (list (tree2array (chain , var_dT , selection )))
391+ selection += ' && ntracks == 1 && chi2 < 8'
392+ delta_t = np .concatenate (list (tree2array (chain , var_dT , selection )))
393+
394+ add_sel = ''
395+ for i , c in enumerate (['x' , 'y' ]):
396+ conf [c ] = {}
397+ pos = np .concatenate (list (tree2array (chain , c + '_dut[0]' , selection )))
398+ conf [c ]['pl' ] = np .percentile (pos , 5 )
399+ conf [c ]['ph' ] = np .percentile (pos , 90 )
400+ add_sel += ' && ' + c + '_dut[' + str (i_s )+ '] > ' + str (conf [c ]['pl' ]) + ' && ' + c + '_dut[' + str (i_s )+ '] < ' + str (conf [c ]['ph' ])
401+
402+ canvas ['space_corr' ][k ].cd (i + 1 )
403+ h = create_TH2D (np .column_stack ((pos , delta_t )), name = c + name , title = 'Time resolution ' + c + ' dependence' ,
404+ binning = [50 , conf [c ]['pl' ]- 4 , conf [c ]['ph' ]+ 4 , 50 , median - 2 * width , median + 2 * width ],
405+ axis_title = [c + ' [mm]' , '#DeltaT [ns]' ]
406+ )
407+
408+ h .DrawCopy ('COLZ' )
409+
410+ prof = h .ProfileX ('prof_' + c )
411+ prof .SetLineColor (2 )
412+ prof .SetLineWidth (2 )
391413
392- add_sel = ''
393- for i , c in enumerate (['x' , 'y' ]):
394- conf [c ] = {}
395- pos = np .concatenate (list (tree2array (chain , c + '_dut[0]' , selection )))
396- conf [c ]['pl' ] = np .percentile (pos , 5 )
397- conf [c ]['ph' ] = np .percentile (pos , 90 )
398- add_sel += ' && ' + c + '_dut[' + str (i_s )+ '] > ' + str (conf [c ]['pl' ]) + ' && ' + c + '_dut[' + str (i_s )+ '] < ' + str (conf [c ]['ph' ])
414+ f = rt .TF1 (c + '_fit' ,'[0]+[1]*x+[2]*x^2' ,conf [c ]['pl' ], conf [c ]['ph' ])
399415
400- canvas ['space_corr' ][k ].cd (i + 1 )
401- h = create_TH2D (np .column_stack ((pos , delta_t )), name = c + name , title = 'Time resolution ' + c + ' dependence' ,
402- binning = [50 , conf [c ]['pl' ]- 4 , conf [c ]['ph' ]+ 4 , 50 , median - 2 * width , median + 2 * width ],
403- axis_title = [c + ' [mm]' , '#DeltaT [ns]' ]
404- )
416+ aux_t = delta_t [np .logical_and (pos > conf [c ]['pl' ], pos < conf [c ]['ph' ])]
417+ pos = pos [np .logical_and (pos > conf [c ]['pl' ], pos < conf [c ]['ph' ])]
418+ coeff , r , rank , s = np .linalg .lstsq (np .column_stack ((0 * pos + 1 , pos , pos ** 2 )), aux_t )
419+ for j ,a in enumerate (coeff ):
420+ f .SetParameter (j , a )
421+ conf [c ]['coeff' ] = np .flipud (coeff )
422+ f .SetLineColor (6 )
423+ f .DrawCopy ('SAMEL' )
405424
406- h .DrawCopy ('COLZ' )
425+ prof .DrawCopy ('SAMEE' )
426+
427+ canvas ['space_corr' ][k ].Update ()
428+ canvas ['space_corr' ][k ].SaveAs (out_dir + '/TimeResolution_Position_dependece_ch' + str (k )+ '.png' )
429+
430+
431+ line = rt .TLine ()
432+ line .SetLineColor (6 )
433+ line .SetLineStyle (7 )
434+ line .SetLineWidth (3 )
435+ for can in [canvas ['pos' ][k ], canvas ['w_pos' ][k ]]:
436+ can .cd ()
437+ line .DrawLine (conf ['x' ]['pl' ], conf ['y' ]['pl' ], conf ['x' ]['pl' ], conf ['y' ]['ph' ])
438+ line .DrawLine (conf ['x' ]['ph' ], conf ['y' ]['pl' ], conf ['x' ]['ph' ], conf ['y' ]['ph' ])
439+ line .DrawLine (conf ['x' ]['pl' ], conf ['y' ]['pl' ], conf ['x' ]['ph' ], conf ['y' ]['pl' ])
440+ line .DrawLine (conf ['x' ]['pl' ], conf ['y' ]['ph' ], conf ['x' ]['ph' ], conf ['y' ]['ph' ])
441+ canvas ['w_pos' ][k ].SaveAs (out_dir + '/PositionXY_amp_weight_ch' + str (k )+ '.png' )
442+ canvas ['pos' ][k ].SaveAs (out_dir + '/PositionXY_raw_ch' + str (k )+ '.png' )
407443
408- prof = h .ProfileX ('prof_' + c )
409- prof .SetLineColor (2 )
444+ selection += add_sel
445+ arr ['x' ] = np .concatenate (list (tree2array (chain , 'x_dut[0]' , selection )))
446+ arr ['y' ] = np .concatenate (list (tree2array (chain , 'y_dut[0]' , selection )))
447+ delta_t = np .concatenate (list (tree2array (chain , var_dT , selection )))
448+
449+ dt_space_corrected = np .copy (delta_t )
450+ for c in ['x' , 'y' ]:
451+ dt_space_corrected -= np .polyval (conf [c ]['coeff' ], arr [c ])
452+
453+ h = create_TH1D (dt_space_corrected , 'h_delta_space_corr' + str (k ), 'Time resolution space corrected ch ' + str (k ),
454+ binning = [ None , np .min (dt_space_corrected ), np .max (dt_space_corrected )],
455+ axis_title = [var_dT + ' [ns]' , 'Events' ])
456+
457+ canvas ['t_res_space' ][k ] = rt .TCanvas ('c_t_res_space' + str (k ), 'c_t_res_raw' + str (k ), 700 , 500 )
458+ h .DrawCopy ('E1' )
459+ canvas ['t_res_space' ][k ].Update ()
460+ canvas ['t_res_space' ][k ].SaveAs (out_dir + '/TimeResolution_space_ch' + str (k )+ '.png' )
461+
462+ '''=========================== Time resolution vs amplitude ==========================='''
463+ conf ['amp' ] = {}
464+ print selection
465+ arr ['amp' ] = np .concatenate (list (tree2array (chain , 'amp[' + str (k )+ ']' , selection )))
466+ canvas ['dt_vs_amp' ][k ] = rt .TCanvas ('dt_vs_amp' + str (k ), 'dt_vs_amp' + str (k ), 1200 , 600 )
467+ canvas ['dt_vs_amp' ][k ].Divide (2 )
468+
469+ h = create_TH2D (np .column_stack ((arr ['amp' ], delta_t )), name = 'h_amp_dip' , title = 'h_amp_dip' ,
470+ binning = [50 , np .min (arr ['amp' ]), np .max (arr ['amp' ]), 50 , np .min (delta_t ), np .max (delta_t )],
471+ axis_title = ['Amp [mV]' , '#DeltaT [ns]' ]
472+ )
473+ canvas ['dt_vs_amp' ][k ].cd (1 )
474+ h .DrawCopy ('colz' )
475+ prof = h .ProfileX ('prof_amp' )
476+ prof .SetLineColor (6 )
410477 prof .SetLineWidth (2 )
478+ prof .DrawCopy ('SAMEE1' )
411479
412- f = rt .TF1 (c + '_fit' ,'[0]+[1]*x+[2]*x^2' ,conf [c ]['pl' ], conf [c ]['ph' ])
480+ f = rt .TF1 ('amp_fit' + str (k ),'[0]+[1]*x+[2]*x^2' , np .min (arr ['amp' ]), np .max (arr ['amp' ]))
481+ f .DrawCopy ('SAMEL' )
413482
414- aux_t = delta_t [np .logical_and (pos > conf [c ]['pl' ], pos < conf [c ]['ph' ])]
415- pos = pos [np .logical_and (pos > conf [c ]['pl' ], pos < conf [c ]['ph' ])]
416- coeff , r , rank , s = np .linalg .lstsq (np .column_stack ((0 * pos + 1 , pos , pos ** 2 )), aux_t )
483+ coeff , r , rank , s = np .linalg .lstsq (np .column_stack ((0 * arr ['amp' ]+ 1 , arr ['amp' ], arr ['amp' ]** 2 )), delta_t )
417484 for j ,a in enumerate (coeff ):
418485 f .SetParameter (j , a )
419- conf [c ]['coeff' ] = np .flipud (coeff )
486+ conf ['amp' ]['coeff' ] = np .flipud (coeff )
420487 f .SetLineColor (6 )
488+ f .SetLineStyle (9 )
421489 f .DrawCopy ('SAMEL' )
422490
423- prof .DrawCopy ('SAMEE' )
424491
425- canvas ['space_corr' ][k ].Update ()
426- canvas ['space_corr' ][k ].SaveAs (out_dir + '/TimeResolution_Position_dependece_ch' + str (k )+ '.png' )
492+ dt_amp_corrected = np .copy (delta_t ) - np .polyval (conf ['amp' ]['coeff' ], arr ['amp' ])
427493
494+ h = create_TH1D (dt_amp_corrected , 'h_delta_amp_corr' + str (k ), 'Time resolution amp corrected' ,
495+ binning = [ None , np .min (dt_amp_corrected ), np .max (dt_amp_corrected )],
496+ axis_title = [var_dT + ' [ns]' , 'Events' ])
497+ canvas ['dt_vs_amp' ][k ].cd (2 )
498+ h .Fit ('gaus' , 'LQR' ,'' , np .percentile (dt_amp_corrected , 1 ), np .percentile (dt_amp_corrected , 99 ))
499+ h .DrawCopy ('E1' )
428500
429- line = rt .TLine ()
430- line .SetLineColor (6 )
431- line .SetLineStyle (7 )
432- line .SetLineWidth (3 )
433- for can in [canvas ['pos' ][k ], canvas ['w_pos' ][k ]]:
434- can .cd ()
435- line .DrawLine (conf ['x' ]['pl' ], conf ['y' ]['pl' ], conf ['x' ]['pl' ], conf ['y' ]['ph' ])
436- line .DrawLine (conf ['x' ]['ph' ], conf ['y' ]['pl' ], conf ['x' ]['ph' ], conf ['y' ]['ph' ])
437- line .DrawLine (conf ['x' ]['pl' ], conf ['y' ]['pl' ], conf ['x' ]['ph' ], conf ['y' ]['pl' ])
438- line .DrawLine (conf ['x' ]['pl' ], conf ['y' ]['ph' ], conf ['x' ]['ph' ], conf ['y' ]['ph' ])
439- canvas ['w_pos' ][k ].SaveAs (out_dir + '/PositionXY_amp_weight_ch' + str (k )+ '.png' )
440- canvas ['pos' ][k ].SaveAs (out_dir + '/PositionXY_raw_ch' + str (k )+ '.png' )
501+ canvas ['dt_vs_amp' ][k ].Update ()
502+ canvas ['dt_vs_amp' ][k ].SaveAs (out_dir + '/TimeResolution_amp_ch' + str (k )+ '.png' )
441503
442- selection += add_sel
443- arr [ 'x' ] = np . concatenate ( list ( tree2array ( chain , 'x_dut[0]' , selection )))
444- arr [ 'y' ] = np .concatenate ( list ( tree2array ( chain , 'y_dut[0]' , selection )) )
445- delta_t = np .concatenate ( list ( tree2array ( chain , var_dT , selection )) )
504+ '''=========================== Time resolution w/ one-shot corrections ==========================='''
505+ def create_regression_input ( x , y , amp ):
506+ out = ( np .ones_like ( x ), x , y , amp , x ** 2 , y ** 2 , amp ** 2 , x * y , amp * x , amp * y )
507+ return np .column_stack ( out )
446508
447- dt_space_corrected = np .copy (delta_t )
448- for c in ['x' , 'y' ]:
449- dt_space_corrected -= np .polyval (conf [c ]['coeff' ], arr [c ])
450-
451- h = create_TH1D (dt_space_corrected , 'h_delta_space_corr' + str (k ), 'Time resolution space corrected ch ' + str (k ),
452- binning = [ None , np .min (dt_space_corrected ), np .max (dt_space_corrected )],
453- axis_title = [var_dT + ' [ns]' , 'Events' ])
454-
455- canvas ['t_res_space' ][k ] = rt .TCanvas ('c_t_res_space' + str (k ), 'c_t_res_raw' + str (k ), 700 , 500 )
456- h .DrawCopy ('E1' )
457- canvas ['t_res_space' ][k ].Update ()
458- canvas ['t_res_space' ][k ].SaveAs (out_dir + '/TimeResolution_space_ch' + str (k )+ '.png' )
459-
460- '''=========================== Time resolution vs amplitude ==========================='''
461- conf ['amp' ] = {}
462- print selection
463- arr ['amp' ] = np .concatenate (list (tree2array (chain , 'amp[' + str (k )+ ']' , selection )))
464- canvas ['dt_vs_amp' ][k ] = rt .TCanvas ('dt_vs_amp' + str (k ), 'dt_vs_amp' + str (k ), 1200 , 600 )
465- canvas ['dt_vs_amp' ][k ].Divide (2 )
466-
467- h = create_TH2D (np .column_stack ((arr ['amp' ], delta_t )), name = 'h_amp_dip' , title = 'h_amp_dip' ,
468- binning = [50 , np .min (arr ['amp' ]), np .max (arr ['amp' ]), 50 , np .min (delta_t ), np .max (delta_t )],
469- axis_title = ['Amp [mV]' , '#DeltaT [ns]' ]
470- )
471- canvas ['dt_vs_amp' ][k ].cd (1 )
472- h .DrawCopy ('colz' )
473- prof = h .ProfileX ('prof_amp' )
474- prof .SetLineColor (6 )
475- prof .SetLineWidth (2 )
476- prof .DrawCopy ('SAMEE1' )
477-
478- f = rt .TF1 ('amp_fit' + str (k ),'[0]+[1]*x+[2]*x^2' , np .min (arr ['amp' ]), np .max (arr ['amp' ]))
479- f .DrawCopy ('SAMEL' )
480-
481- coeff , r , rank , s = np .linalg .lstsq (np .column_stack ((0 * arr ['amp' ]+ 1 , arr ['amp' ], arr ['amp' ]** 2 )), delta_t )
482- for j ,a in enumerate (coeff ):
483- f .SetParameter (j , a )
484- conf ['amp' ]['coeff' ] = np .flipud (coeff )
485- f .SetLineColor (6 )
486- f .SetLineStyle (9 )
487- f .DrawCopy ('SAMEL' )
488-
489-
490- dt_amp_corrected = np .copy (delta_t ) - np .polyval (conf ['amp' ]['coeff' ], arr ['amp' ])
491-
492- h = create_TH1D (dt_amp_corrected , 'h_delta_amp_corr' + str (k ), 'Time resolution amp corrected' ,
493- binning = [ None , np .min (dt_amp_corrected ), np .max (dt_amp_corrected )],
494- axis_title = [var_dT + ' [ns]' , 'Events' ])
495- canvas ['dt_vs_amp' ][k ].cd (2 )
496- h .Fit ('gaus' , 'LQR' ,'' , np .percentile (dt_amp_corrected , 1 ), np .percentile (dt_amp_corrected , 99 ))
497- h .DrawCopy ('E1' )
498-
499- canvas ['dt_vs_amp' ][k ].Update ()
500- canvas ['dt_vs_amp' ][k ].SaveAs (out_dir + '/TimeResolution_amp_ch' + str (k )+ '.png' )
501-
502- '''=========================== Time resolution w/ one-shot corrections ==========================='''
503- def create_regression_input (x , y , amp ):
504- out = (np .ones_like (x ), x , y , amp , x ** 2 , y ** 2 , amp ** 2 , x * y , amp * x , amp * y )
505- return np .column_stack (out )
506-
507- inputs = create_regression_input (arr ['x' ], arr ['y' ], arr ['amp' ])
508- coeff , r , rank , s = np .linalg .lstsq (inputs , delta_t )
509-
510- dt_corr = delta_t - np .dot (inputs , coeff )
511-
512- h = create_TH1D (dt_corr , 'h_dt_corr' + str (k ), 'Time resolution one-shot correction' ,
513- binning = [ None , np .min (dt_corr ), np .max (dt_corr )],
514- axis_title = [var_dT + ' [ns]' , 'Events' ])
515-
516- f = rt .TF1 ('f_corr' + str (k ),'gaus' , np .percentile (dt_corr , 3 ), np .percentile (dt_corr , 97 ))
517- h .Fit ('f_corr' + str (k ), 'LQR+' )
518- canvas ['dt_corr' ][k ] = rt .TCanvas ('c_dt_corr' + str (k ), 'c_dt_corr' + str (k ), 800 , 600 )
519- h .DrawCopy ('E1' )
520- f .SetLineColor (2 )
521- f .DrawCopy ('SAMEL' )
522-
523- canvas ['dt_corr' ][k ].Update ()
524- canvas ['dt_corr' ][k ].SaveAs (out_dir + '/TimeResolution_OneShot_ch' + str (k )+ '.png' )
509+ inputs = create_regression_input (arr ['x' ], arr ['y' ], arr ['amp' ])
510+ coeff , r , rank , s = np .linalg .lstsq (inputs , delta_t )
511+
512+ dt_corr = delta_t - np .dot (inputs , coeff )
513+
514+ h = create_TH1D (dt_corr , 'h_dt_corr' + str (k ), 'Time resolution one-shot correction' ,
515+ binning = [ None , np .min (dt_corr ), np .max (dt_corr )],
516+ axis_title = [var_dT + ' [ns]' , 'Events' ])
517+
518+ f = rt .TF1 ('f_corr' + str (k ),'gaus' , np .percentile (dt_corr , 3 ), np .percentile (dt_corr , 97 ))
519+ h .Fit ('f_corr' + str (k ), 'LQR+' )
520+ canvas ['dt_corr' ][k ] = rt .TCanvas ('c_dt_corr' + str (k ), 'c_dt_corr' + str (k ), 800 , 600 )
521+ h .DrawCopy ('E1' )
522+ f .SetLineColor (2 )
523+ f .DrawCopy ('SAMEL' )
524+
525+ canvas ['dt_corr' ][k ].Update ()
526+ canvas ['dt_corr' ][k ].SaveAs (out_dir + '/TimeResolution_OneShot_ch' + str (k )+ '.png' )
0 commit comments