478 for s
in systemAndPlanes:
479 for l
in range(systemAndPlanes[s]):
480 ut.bookHist(h,
'hitmult_'+
str(s*10+l),
'hit mult / plane '+
str(s*10+l),61,-0.5,60.5)
481 ut.bookHist(h,
'hit_'+
str(s*10+l),
'channel map / plane '+
str(s*10+l),160,-0.5,159.5)
482 if s==3: ut.bookHist(h,
'bar_'+
str(s*10+l),
'hit map / plane '+
str(s*10+l),60,-0.5,59.5)
483 else: ut.bookHist(h,
'bar_'+
str(s*10+l),
'hit map / plane '+
str(s*10+l),10,-0.5,9.5)
484 ut.bookHist(h,
'sig_'+
str(s*10+l),
'signal / plane '+
str(s*10+l),200,0.0,200.)
485 if s==2: ut.bookHist(h,
'sigS_'+
str(s*10+l),
'signal / plane '+
str(s*10+l),200,0.0,200.)
486 ut.bookHist(h,
'sigL_'+
str(s*10+l),
'signal / plane '+
str(s*10+l),200,0.0,200.)
487 ut.bookHist(h,
'sigR_'+
str(s*10+l),
'signal / plane '+
str(s*10+l),200,0.0,200.)
488 ut.bookHist(h,
'Tsig_'+
str(s*10+l),
'signal / plane '+
str(s*10+l),200,0.0,200.)
489 ut.bookHist(h,
'occ_'+
str(s*10+l),
'channel occupancy '+
str(s*10+l),100,0.0,200.)
490 ut.bookHist(h,
'occTag_'+
str(s*10+l),
'channel occupancy '+
str(s*10+l),100,0.0,200.)
492 ut.bookHist(h,
'leftvsright_1',
'Veto hits in left / right',10,-0.5,9.5,10,-0.5,9.5)
493 ut.bookHist(h,
'leftvsright_2',
'US hits in left / right',10,-0.5,9.5,10,-0.5,9.5)
494 ut.bookHist(h,
'leftvsright_3',
'DS hits in left / right',2,-0.5,1.5,2,-0.5,1.5)
495 ut.bookHist(h,
'leftvsright_signal_1',
'Veto signal in left / right',100,-0.5,200.,100,-0.5,200.)
496 ut.bookHist(h,
'leftvsright_signal_2',
'US signal in left / right',100,-0.5,200.,100,-0.5,200.)
497 ut.bookHist(h,
'leftvsright_signal_3',
'DS signal in left / right',100,-0.5,200.,100,-0.5,200.)
499 ut.bookHist(h,
'dtime',
'delta event time; dt [ns]',100,0.0,1000.)
500 ut.bookHist(h,
'dtimeu',
'delta event time; dt [us]',100,0.0,1000.)
501 ut.bookHist(h,
'dtimem',
'delta event time; dt [ms]',100,0.0,1000.)
503 ut.bookHist(h,
'bs',
'beam spot',100,-100.,10.,100,0.,80.)
504 ut.bookHist(h,
'bsDS',
'beam spot',60,-0.5,59.5,60,-0.5,59.5)
505 ut.bookHist(h,
'slopes',
'track slopes',100,-0.1,0.1,100,-0.1,0.1)
508 ut.bookHist(h,sdict[s]+
'Mult',
'QDCs vs nr hits',200,0.,800.,200,0.,300.)
512 if Nev < 0 : Nev = eventTree.GetEntries()
513 eventTree.GetEvent(0)
514 t0 = eventTree.EventHeader.GetEventTime()/freq
515 listOfHits = {1:[],2:[],3:[]}
517 for event
in eventTree:
519 if N%options.heartBeat == 0: print(
'event ',N,
' ',time.ctime())
523 listOfHits[1].clear()
524 listOfHits[2].clear()
525 listOfHits[3].clear()
526 for s
in systemAndPlanes:
527 for l
in range(systemAndPlanes[s]): mult[s*10+l]=0
528 for aHit
in event.Digi_MuFilterHits:
529 if not aHit.isValid():
continue
530 detID = aHit.GetDetectorID()
531 if aHit.isVertical(): withX =
True
533 l = (detID%10000)//1000
542 if not key
in planes: planes[key] = {}
543 sumSignal =
map2Dict(aHit,
'SumOfSignals')
544 planes[key][bar] = [sumSignal[
'SumL'],sumSignal[
'SumR']]
545 nSiPMs = aHit.GetnSiPMs()
546 nSides = aHit.GetnSides()
548 allChannels =
map2Dict(aHit,
'GetAllSignals')
549 for c
in allChannels:
550 listOfHits[s].append(allChannels[c])
556 for c
in allChannels:
559 Sleft+=allChannels[c]
562 Sright+=allChannels[c]
563 rc = h[
'leftvsright_'+
str(s)].Fill(Nleft,Nright)
564 rc = h[
'leftvsright_signal_'+
str(s)].Fill(Sleft,Sright)
566 for c
in allChannels:
567 channel = bar*nSiPMs*nSides + c
568 rc = h[
'hit_'+
str(s)+
str(l)].Fill(
int(channel))
569 rc = h[
'bar_'+
str(s)+
str(l)].Fill(bar)
571 elif c<nSiPMs: rc = h[
'sigL_'+
str(s)+
str(l)].Fill(allChannels[c])
572 else : rc = h[
'sigR_'+
str(s)+
str(l)].Fill(allChannels[c])
573 rc = h[
'sig_'+
str(s)+
str(l)].Fill(allChannels[c])
577 nhits = len(listOfHits[s])
579 for i
in range(nhits):
580 rc = h[sdict[s]+
'Mult'].Fill(nhits, listOfHits[s][i])
581 for s
in systemAndPlanes:
582 for l
in range(systemAndPlanes[s]):
583 rc = h[
'hitmult_'+
str(s*10+l)].Fill(mult[s*10+l])
587 if len(planes[key]) > 2: maxOneBar =
False
590 S = {1:[1800,800,2,1],2:[1800,1500,2,3],3:[1800,1800,2,4]}
592 ut.bookCanvas(h,
'hitmaps' +
str(s),
' ',S[s][0],S[s][1],S[s][2],S[s][3])
593 ut.bookCanvas(h,
'barmaps'+
str(s),
' ',S[s][0],S[s][1],S[s][2],S[s][3])
594 ut.bookCanvas(h,
'signal' +
str(s),
' ',S[s][0],S[s][1],S[s][2],S[s][3])
595 ut.bookCanvas(h,
'Tsignal' +
str(s),
' ',S[s][0],S[s][1],S[s][2],S[s][3])
597 for l
in range(systemAndPlanes[s]):
599 if s==3
and n==7: n=8
600 tc = h[
'hitmaps'+
str(s)].cd(n)
603 tc = h[
'barmaps'+
str(s)].cd(n)
605 tc = h[
'signal'+
str(s)].cd(n)
607 tc = h[
'Tsignal'+
str(s)].cd(n)
608 h[
'Tsig_'+tag].Draw()
610 ut.bookCanvas(h,
'hitmult',
'hit multiplicities per plane',2000,1600,4,3)
612 for s
in systemAndPlanes:
613 for l
in range(systemAndPlanes[s]):
614 tc = h[
'hitmult'].cd(k)
617 rc = h[
'hitmult_'+
str(s*10+l)].Draw()
619 ut.bookCanvas(h,
'VETO',
' ',1200,1800,1,2)
621 tc = h[
'VETO'].cd(l+1)
622 hname =
'hit_'+
str(1)+
str(l)
627 y = h[
'hit_'+
str(1)+
str(l)].GetMaximum()
628 lname =
'L'+
str(n)+hname
629 h[lname] = ROOT.TLine(x,0,x,y)
630 h[lname].SetLineColor(ROOT.kRed)
631 h[lname].SetLineStyle(9)
632 h[lname].Draw(
'same')
634 ut.bookCanvas(h,
'USBars',
' ',1200,900,1,1)
635 colours = {0:ROOT.kOrange,1:ROOT.kRed,2:ROOT.kGreen,3:ROOT.kBlue,4:ROOT.kMagenta,5:ROOT.kCyan,
636 6:ROOT.kAzure,7:ROOT.kPink,8:ROOT.kSpring}
638 h[
'bar_2'+
str(i)].SetLineColor(colours[i])
639 h[
'bar_2'+
str(i)].SetLineWidth(2)
640 h[
'bar_2'+
str(i)].SetStats(0)
642 h[
'bar_21'].Draw(
'same')
643 h[
'bar_22'].Draw(
'same')
644 h[
'bar_23'].Draw(
'same')
645 h[
'bar_24'].Draw(
'same')
646 h[
'lbar2']=ROOT.TLegend(0.6,0.6,0.99,0.99)
648 h[
'lbar2'].AddEntry(h[
'bar_2'+
str(i)],
'plane '+
str(i+1),
"f")
651 h[
'hit_3'+
str(i)].SetLineColor(colours[i])
652 h[
'hit_3'+
str(i)].SetLineWidth(2)
653 h[
'hit_3'+
str(i)].SetStats(0)
656 h[
'hit_3'+
str(i)].Draw(
'same')
657 h[
'lbar3']=ROOT.TLegend(0.6,0.6,0.99,0.99)
659 h[
'lbar3'].AddEntry(h[
'hit_3'+
str(i)],
'plane '+
str(i+1),
"f")
662 ut.bookCanvas(h,
'LR',
' ',1800,900,3,2)
664 h[
'leftvsright_'+
str(1)].Draw(
'textBox')
666 h[
'leftvsright_'+
str(2)].Draw(
'textBox')
668 h[
'leftvsright_'+
str(3)].Draw(
'textBox')
670 h[
'leftvsright_signal_1'].SetMaximum(h[
'leftvsright_signal_1'].GetBinContent(10,10))
671 h[
'leftvsright_signal_2'].SetMaximum(h[
'leftvsright_signal_2'].GetBinContent(10,10))
672 h[
'leftvsright_signal_3'].SetMaximum(h[
'leftvsright_signal_3'].GetBinContent(10,10))
673 h[
'leftvsright_signal_'+
str(1)].Draw(
'colz')
675 h[
'leftvsright_signal_'+
str(2)].Draw(
'colz')
677 h[
'leftvsright_signal_'+
str(3)].Draw(
'colz')
679 ut.bookCanvas(h,
'LRinEff',
' ',1800,450,3,1)
681 h[
'lLRinEff'+
str(s)]=ROOT.TLegend(0.6,0.54,0.99,0.93)
682 name =
'leftvsright_signal_'+
str(s)
683 h[name+
'0Y'] = h[name].ProjectionY(name+
'0Y',1,1)
684 h[name+
'0X'] = h[name].ProjectionX(name+
'0X',1,1)
685 h[name+
'1X'] = h[name].ProjectionY(name+
'1Y')
686 h[name+
'1Y'] = h[name].ProjectionX(name+
'1X')
687 tc = h[
'LRinEff'].cd(s)
689 h[name+
'0X'].SetStats(0)
690 h[name+
'0Y'].SetStats(0)
691 h[name+
'1X'].SetStats(0)
692 h[name+
'1Y'].SetStats(0)
693 h[name+
'0X'].SetLineColor(ROOT.kRed)
694 h[name+
'0Y'].SetLineColor(ROOT.kGreen)
695 h[name+
'1X'].SetLineColor(ROOT.kMagenta)
696 h[name+
'1Y'].SetLineColor(ROOT.kCyan)
697 h[name+
'0X'].SetMaximum(max(h[name+
'1X'].GetMaximum(),h[name+
'1Y'].GetMaximum()))
699 h[name+
'0Y'].Draw(
'same')
700 h[name+
'1X'].Draw(
'same')
701 h[name+
'1Y'].Draw(
'same')
703 h[
'lLRinEff'+
str(s)].AddEntry(h[name+
'0X'],
'left with no signal right',
"f")
704 h[
'lLRinEff'+
str(s)].AddEntry(h[name+
'0Y'],
'right with no signal left',
"f")
705 h[
'lLRinEff'+
str(s)].AddEntry(h[name+
'1X'],
'left all',
"f")
706 h[
'lLRinEff'+
str(s)].AddEntry(h[name+
'1Y'],
'right all',
"f")
707 h[
'lLRinEff'+
str(s)].Draw()
709 ut.bookCanvas(h,
'signalUSVeto',
' ',1200,1600,3,7)
712 for plane
in range(2):
713 for side
in [
'L',
'R',
'S']:
714 tc = h[
'signalUSVeto'].cd(l)
716 if side==
'S':
continue
717 h[
'sig'+side+
'_'+
str( s*10+plane)].Draw()
719 for plane
in range(5):
720 for side
in [
'L',
'R',
'S']:
721 tc = h[
'signalUSVeto'].cd(l)
723 h[
'sig'+side+
'_'+
str( s*10+plane)].Draw()
724 ut.bookCanvas(h,
'signalDS',
' ',900,1600,2,7)
727 for plane
in range(7):
728 for side
in [
'L',
'R']:
729 tc = h[
'signalDS'].cd(l)
731 h[
'sig'+side+
'_'+
str( s*10+plane)].Draw()
734 for canvas
in [
'signalUSVeto',
'LR',
'USBars']:
737 for canvas
in [
'hitmaps',
'barmaps',
'signal',
'Tsignal']:
739 h[canvas+
str(s)].Update()
1084 zUS0 = zPos[
'MuFilter'][20] - 10
1085 zUS4 = zPos[
'MuFilter'][24] + 10
1086 for x
in [
'',
'-small']:
1087 ut.bookHist(h,
'shower'+x,
'energy vs z',200,0.,10000.,20,zUS0,zUS4)
1088 ut.bookHist(h,
'showerX'+x,
'energy vs z',200,0.,10000.,20,zUS0,zUS4)
1089 ut.bookHist(h,
'wshower'+x,
'z weighted energy ',100,-300.,0.)
1090 ut.bookHist(h,
'zyshower'+x,
'y vs z weighted energy ',20,zUS0,zUS4,11,-0.5,10.5)
1091 for p
in range(systemAndPlanes[2]):
1092 ut.bookHist(h,
'SvsL'+
str(p),
'small vs large Sipms plane' +
str(p)+
';large [QCD]; small [QCD] ',100,0.1,250.,100,0.1,100.)
1093 if Nev < 0 : Nev = eventTree.GetEntries()
1095 for event
in eventTree:
1100 for aHit
in eventTree.Digi_MuFilterHits:
1101 if not aHit.isValid():
continue
1102 detID = aHit.GetDetectorID()
1103 s = aHit.GetDetectorID()//10000
1105 p = (aHit.GetDetectorID()//1000)%10
1107 rc = h[
'SvsL'+
str(p)].Fill(S[
'SumL'],S[
'SumS'])
1108 plane = (aHit.GetDetectorID()//1000)%10
1109 bar = aHit.GetDetectorID()%100
1110 if not plane
in UShits:
1114 UShitsBar[100+plane]={}
1115 if not bar
in UShitsBar[plane]:
1116 UShitsBar[plane][bar]=0
1117 UShitsBar[100+plane][bar]=0
1118 UShits[plane]+=S[
'Sum']
1119 UShitsBar[plane][bar]+=S[
'Sum']
1120 UShits[100+plane]+=S[
'SumS']
1121 UShitsBar[100+plane][bar]+=S[
'SumS']
1123 for plane
in UShits:
1124 z = zPos[
'MuFilter'][s*10+plane%100]
1126 if plane > 99: x=
'-small'
1127 rc = h [
'shower'+x].Fill(UShits[plane],z)
1129 if UShits[0]>750: rc = h[
'showerX'+x].Fill(UShits[plane],z)
1130 rc = h [
'wshower'+x].Fill(z,UShits[plane])
1131 for bar
in UShitsBar[plane]:
1132 rc = h [
'zyshower'+x].Fill(z,bar,UShitsBar[plane][bar])
1133 ut.bookCanvas(h,
'lego',
'',900,1600,1,2)
1134 energy = {46:180,49:180,56:140,58:140,72:240,73:240,74:240,89:300,90:300,91:300}
1135 gain = {46:2.5,49:3.65,52:3.65,54:2.5,56:2.5,58:3.65,72:1.0,73:2.5,74:3.65,86:3.65,87:2.5,88:1.0,89:3.65,90:2.5,91:1.0}
1136 tc = h[
'lego'].cd(1)
1141 if options.runNumber
in energy: text +=
"E=%5.1F"%(energy[options.runNumber])
1142 if options.runNumber
in gain: text +=
" with gain=%5.2F"%(gain[options.runNumber])
1143 h [
'zyshower'].SetTitle(text+
';z [cm]; y [bar number];QDC')
1144 h [
'zyshower'].SetStats(0)
1145 h [
'zyshower'].Draw(
'lego2')
1146 tc = h[
'lego'].cd(2)
1149 h [
'zyshower-small'].SetTitle(
'small sipms;z [cm]; y [bar number];QDC')
1150 h [
'zyshower-small'].SetStats(0)
1151 h [
'zyshower-small'].Draw(
'lego2')
1152 myPrint(h[
'lego'],
'shower',withRootFile=
True)
1154 ut.bookCanvas(h,
'CorLS',
'',900,1200,1,5)
1155 h[
'SvsL'] = h[
'SvsL0'].Clone(
'SvsL')
1156 h[
'SvsL'].SetTitle(
'small vs large Sipms all planes')
1157 for p
in range(1,systemAndPlanes[2]):
1158 h[
'SvsL'].Add(h[
'SvsL'+
str(p)])
1159 h[
'SvsL'].SetStats(0)
1160 for p
in range(systemAndPlanes[2]):
1161 tc = h[
'CorLS'].cd(p+1)
1162 h[
'SvsL'+
str(p)].SetStats(0)
1163 h[
'SvsL'+
str(p)].Draw(
'colz')
1164 myPrint(h[
'CorLS'],
'QCDsmallCSQCDlarge')
1298def Mufi_Efficiency(Nev=options.nEvents,optionTrack=options.trackType,withReco='True',NbinsRes=100,X=10.):
1300 projs = {1:
'Y',0:
'X'}
1302 for s
in range(1,nScifi+1):
1304 ut.bookHist(h,
'dtScifivsX_'+
str(s)+projs[p],
'dt vs x track '+projs[p]+
";X [cm]; dt [ns]",100,-10.,40.,260,-8.,5.)
1305 ut.bookHist(h,
'clN_'+
str(s)+projs[p],
'cluster size '+projs[p],10,-0.5,9.5)
1306 ut.bookHist(h,
'dtScifivsdL_'+
str(s),
'dt vs dL '+
str(s)+
";X [cm]; dt [ns]",100,-40.,0.,200,-5.,5.)
1308 for s
in systemAndPlanes:
1309 for l
in range(systemAndPlanes[s]):
1310 ut.bookHist(h,
'dtLRvsX_'+sdict[s]+
str(s*10+l),
'dt vs x track '+
str(s*10+l)+
";X [cm]; dt [ns]",100,-70.,30.,260,-8.,5.)
1311 ut.bookHist(h,
'atLRvsX_'+sdict[s]+
str(s*10+l),
'mean time - T0track vs x '+
str(s*10+l)+
";X [cm]; dt [ns]",20,-70.,30.,250,-10.,15.0)
1312 ut.bookHist(h,
'VetoatLRvsX_'+sdict[s]+
str(s*10+l),
'mean time - T0Veto vs x '+
str(s*10+l)+
";X [cm]; dt [ns]",20,-70.,30.,250,-10.,15.0)
1315 if s==3: scale = 0.4
1316 for side
in [
'',
'L',
'R',
'S']:
1317 for proj
in [
'X',
'Y']:
1318 xmin = -X*NbinsRes/100. * scale
1320 ut.bookHist(h,
'res'+proj+
'_'+sdict[s]+side+
str(s*10+l),
'residual '+proj+
str(s*10+l)+
1321 '; residual [cm]; local position [cm]',NbinsRes,xmin,xmax,100,-100.,100.)
1322 ut.bookHist(h,
'gres'+proj+
'_'+sdict[s]+side+
str(s*10+l),
'residual '+proj+
str(s*10+l)+
1323 '; residual [cm]; global position [cm]',NbinsRes,xmin,xmax,100,-100.,100.)
1324 if side==
'S':
continue
1327 ut.bookHist(h,
'resBar'+proj+
'_'+sdict[s]+
str(s*10+l),
'residual '+proj+
str(s*10+l)+
1328 '; residual [cm]; bar number',NbinsRes,xmin,xmax,7,-0.5,6.5)
1330 ut.bookHist(h,
'track_'+sdict[s]+
str(s*10+l),
'track x/y '+
str(s*10+l)+
';X [cm];Y [cm]',100,-90.,10.,100,-20.,80.)
1331 ut.bookHist(h,
'locBarPos_'+sdict[s]+
str(s*10+l),
'bar sizes;X [cm];Y [cm]',100,-100,100,100,-100,100)
1332 ut.bookHist(h,
'locEx_'+sdict[s]+
str(s*10+l),
'loc track pos;X [cm];Y [cm]',100,-100,100,100,-100,100)
1333 for bar
in range(systemAndBars[s]):
1334 key = sdict[s]+
str(s*10+l)+
'_'+
str(bar)
1336 ut.bookHist(h,
'dtLRvsX_'+key,
'dt vs x track '+
str(s*10+l)+
";X [cm]; dt [ns]",100,-70.,30.,260,-8.,5.)
1337 ut.bookHist(h,
'dtF1LRvsX_'+key,
'dt vs x track '+
str(s*10+l)+
";X [cm]; dt [ns]",100,-70.,30.,260,-8.,5.)
1338 ut.bookHist(h,
'dtfastLRvsX_'+key,
'dt vs x track '+
str(s*10+l)+
";X [cm]; dt [ns]",100,-70.,30.,260,-8.,5.)
1339 ut.bookHist(h,
'atLRvsX_'+key,
'dt vs x track '+
str(s*10+l)+
";X [cm]; dt [ns]",100,-70.,30.,260,-8.,5.)
1341 ut.bookHist(h,
'nSiPMs'+side+
'_'+key,
'#sipms',16,-0.5,15.5,20,0.,100.)
1342 ut.bookHist(h,
'tvsX'+side+
'_'+key,
"t-t0 vs x track;X [cm]; dt [ns]",100,-70.,30.,200,-12.,12.)
1343 ut.bookHist(h,
'tFastvsX'+side+
'_'+key,
"t-t0 vs x track;X [cm]; dt [ns]",100,-70.,30.,200,-12.,12.)
1344 for i
in range(systemAndChannels[s][1]+systemAndChannels[s][0]):
1346 ut.bookHist(h,
'signalS'+side+
'_'+key+
'-c'+
str(i),
'signal',200,0.,100.,20,0.,100.)
1348 ut.bookHist(h,
'signal'+side+
'_'+key+
'-c'+
str(i),
'signal',200,0.,100.,20,0.,100.)
1350 ut.bookHist(h,
'sigmaTDC'+side+
'_'+key+
'-c'+
str(i),
'rms TDC ;dt [ns]',200,-10.0,10.0)
1351 ut.bookHist(h,
'TDCcalib'+side+
'_'+key+
'-c'+
str(i),
'rms TDC ;dt [ns]',200,-10.0,10.0)
1352 ut.bookHist(h,
'sigmaQDC'+side+
'_'+key+
'-c'+
str(i),
'rms QDC ; QDC ',200,-50.0,50.)
1353 ut.bookHist(h,
'tvsX'+side+
'_'+key+
'-c'+
str(i),
"t-t0 vs x track;X [cm]; dt [ns]",100,-70.,30.,200,-12.,12.)
1355 ut.bookHist(h,
'signalT'+side+
'_'+key,
'signal',400,0.,400.,20,0.,100.)
1356 ut.bookHist(h,
'signalTS'+side+
'_'+key,
'signal',400,0.,400.,20,0.,100.)
1357 ut.bookHist(h,
'signal'+side+
'_'+key,
'signal',200,0.,100.,20,0.,100.)
1359 ut.bookHist(h,
'resVETOY_1',
'channel vs residual 1',NbinsRes,xmin,xmax,112,-0.5,111.5)
1360 ut.bookHist(h,
'resVETOY_2',
'channel vs residual 2',NbinsRes,xmin,xmax,112,-0.5,111.5)
1361 ut.bookHist(h,
'resVETOX_3',
'channel vs residual 3',NbinsRes,xmin,xmax,112,-0.5,111.5)
1363 ut.bookHist(h,
'trackslxy',
'track direction',200,-0.1,0.1,200,-0.1,0.1)
1364 ut.bookHist(h,
'trackslxy_badChi2',
'track direction',200,-0.1,0.1,200,-0.1,0.1)
1365 ut.bookHist(h,
'tracksChi2Ndof',
'chi2/ndof',100,0.0,100.,10,-0.5,9.5)
1366 ut.bookHist(h,
'NdofvsNMeas',
'ndof Nmeas',20,-0.5,19.5,20,-0.5,19.5)
1368 if Nev < 0 : Nev = eventTree.GetEntries()
1370 for event
in eventTree:
1371 rc = eventTree.GetEvent(N)
1375 for aTrack
in Reco_MuonTracks: aTrack.Delete()
1376 Reco_MuonTracks.Clear()
1377 if optionTrack==
'DS': rc = trackTask.ExecuteTask(
"DS")
1378 else : rc = trackTask.ExecuteTask(
"Scifi")
1379 if not Reco_MuonTracks.GetEntries()==1:
continue
1380 theTrack = Reco_MuonTracks[0]
1381 if not theTrack.getFitStatus().isFitConverged()
and optionTrack!=
'DS':
1384 state = theTrack.getFittedState(0)
1385 pos = state.getPos()
1386 mom = state.getMom()
1387 slopeX= mom.X()/mom.Z()
1388 slopeY= mom.Y()/mom.Z()
1389 if abs(slopeX)>0.25:
continue
1390 if abs(slopeY)>0.1:
continue
1393 fitStatus = theTrack.getFitStatus()
1394 chi2Ndof = fitStatus.getChi2()/(fitStatus.getNdf()+1E-10)
1395 rc = h[
'tracksChi2Ndof'].Fill(chi2Ndof,fitStatus.getNdf())
1396 rc = h[
'NdofvsNMeas'].Fill(fitStatus.getNdf(),theTrack.getNumPointsWithMeasurement())
1399 if not hasattr(event,
"Cluster_Scifi"):
1400 if hasattr(trackTask,
"clusScifi"):
1401 trackTask.clusScifi.Clear()
1402 trackTask.scifiCluster()
1403 clusters = trackTask.clusScifi
1405 clusters = event.Cluster_Scifi
1407 for aCluster
in clusters:
1408 for nHit
in range(event.Digi_ScifiHits.GetEntries()):
1409 if event.Digi_ScifiHits[nHit].GetDetectorID()==aCluster.GetFirst():
1410 DetID2Key[aCluster.GetFirst()] = nHit
1411 for aCluster
in clusters:
1412 detID = aCluster.GetFirst()
1413 s =
int(detID/1000000)
1414 p=
int(detID/100000)%10
1415 rc = h[
'clN_'+
str(s)+projs[p]].Fill(aCluster.GetN())
1417 if chi2Ndof> 9
and optionTrack!=
'DS':
1418 rc = h[
'trackslxy_badChi2'].Fill(mom.x()/mom.Mag(),mom.y()/mom.Mag())
1420 rc = h[
'trackslxy'].Fill(mom.x()/mom.Mag(),mom.y()/mom.Mag())
1422 if optionTrack==
'DS':
1427 for nM
in range(theTrack.getNumPointsWithMeasurement()):
1428 M = theTrack.getPointWithMeasurement(nM)
1429 W = M.getRawMeasurement()
1430 detID = W.getDetId()
1432 aHit = event.Digi_MuFilterHits[ hkey ]
1433 if aHit.isVertical():
continue
1434 allTDCs =
map2Dict(aHit,
'GetAllTimes')
1435 if (0
in allTDCs)
and (1
in allTDCs) : T0s.append( (allTDCs[0]+allTDCs[1])*TDC2ns/2. )
1437 lam = (zPos[
'MuFilter'][32]-pos.z())/mom.z()
1438 xEx,yEx = lam*mom.x(),pos.y()+lam*mom.y()
1440 L = ROOT.TMath.Sqrt( (lam*mom.x())**2 + (lam*mom.y())**2 + (zPos[
'MuFilter'][32]-pos.z())**2)
1441 ToF = L / u.speedOfLight
1442 T0track = (T0s[0]+T0s[1]-ToF)/2.
1444 deltaZ02 = (zPos[
'MuFilter'][32]-zPos[
'MuFilter'][30])
1447 M = theTrack.getPointWithMeasurement(0)
1448 W = M.getRawMeasurement()
1449 detID = W.getDetId()
1450 aHit = event.Digi_ScifiHits[ DetID2Key[detID] ]
1455 clkey = W.getHitId()
1456 aCl = clusters[clkey]
1457 T0track = aCl.GetTime() - L0
1458 TZero = aCl.GetTime()
1461 for nM
in range(theTrack.getNumPointsWithMeasurement()):
1462 state = theTrack.getFittedState(nM)
1463 posM = state.getPos()
1464 M = theTrack.getPointWithMeasurement(nM)
1465 W = M.getRawMeasurement()
1466 detID = W.getDetId()
1467 clkey = W.getHitId()
1468 aCl = clusters[clkey]
1469 aHit = event.Digi_ScifiHits[ DetID2Key[detID] ]
1471 if aHit.isVertical(): X = B-posM
1475 dT = aCl.GetTime() - L - T0track - (posM[2] -Z0track)/u.speedOfLight
1476 ss =
str(aHit.GetStation())
1479 if aHit.isVertical():
1482 rc = h[
'dtScifivsX_'+ss+prj].Fill(X.Mag(),dT)
1483 times[ss+prj]=[aCl.GetTime(),L*v,detID,l]
1484 for s
in range(1,nScifi+1):
1485 if str(s)+
'X' in times
and str(s)+
'Y' in times:
1486 deltaT = times[
str(s)+
'X'][0] - times[
str(s)+
'Y'][0]
1487 deltaL = times[
str(s)+
'X'][1] - times[
str(s)+
'Y'][1]
1488 rc = h[
'dtScifivsdL_'+
str(s)].Fill(deltaL,deltaT)
1494 for s
in systemAndPlanes:
1495 for p
in range(systemAndPlanes[s]):
1498 muHits[s*10+2*p+1]=[]
1501 for p
in range(systemAndPlanes[s]): muHits[s*10+p]=[]
1502 for aHit
in event.Digi_MuFilterHits:
1503 if not aHit.isValid():
continue
1504 s = aHit.GetDetectorID()//10000
1505 p = (aHit.GetDetectorID()//1000)%10
1506 bar = (aHit.GetDetectorID()%1000)%60
1509 if aHit.isVertical():
1511 if p==3: plane = s*10+2*p
1512 else: plane = s*10+2*p
1513 muHits[plane].append(aHit)
1517 Z0Veto = zPos[
'MuFilter'][1*10+0]
1518 dZ = zPos[
'MuFilter'][1*10+1] - zPos[
'MuFilter'][1*10+0]
1520 for p
in range(systemAndPlanes[s]-1):
1522 if len(muHits[plane])!=1:
continue
1523 aHit = muHits[plane][0]
1525 zEx = zPos[
'MuFilter'][s*10+plane]
1526 lam = (zEx-pos.z())/mom.z()
1527 xEx,yEx = pos.x()+lam*mom.x(),pos.y()+lam*mom.y()
1528 detID = aHit.GetDetectorID()
1530 D = (A[1]+B[1])/2. - yEx
1531 if abs(D)>5:
continue
1532 avT[plane] = aHit.GetImpactT()
1535 T0Veto = (avT[10]+(avT[11]-dZ/u.speedOfLight))/2.
1537 vetoHits = {0:[],1:[], 2:[]}
1540 for plane
in range(systemAndPlanes[s]):
1541 zEx = zPos[
'MuFilter'][s*10+plane]
1542 lam = (zEx-pos.z())/mom.z()
1543 xEx,yEx = pos.x()+lam*mom.x(),pos.y()+lam*mom.y()
1545 if plane ==0: tag = 1
1546 else: tag = plane -1
1548 for aHit
in muHits[s*10+tag]:
1549 detID = aHit.GetDetectorID()
1551 if aHit.isVertical() : D = (A[0]+B[0])/2. - xEx
1552 else: D = (A[1]+B[1])/2. - yEx
1553 if abs(D)<5: tagged =
True
1555 rc = h[
'track_'+sdict[s]+
str(s*10+plane)].Fill(xEx,yEx)
1556 for aHit
in muHits[s*10+plane]:
1557 detID = aHit.GetDetectorID()
1558 bar = (detID%1000)%60
1559 nSiPMs = aHit.GetnSiPMs()
1560 nSides = aHit.GetnSides()
1563 globEx = array(
'd',[xEx,yEx,zEx])
1564 locEx = array(
'd',[0,0,0])
1565 nav.MasterToLocal(globEx,locEx)
1566 locPos = 0.5* (locA+locB)
1567 globPos = 0.5 * (globA+globB)
1568 dy = locPos[1] - locEx[1]
1569 dx = locPos[0] - locEx[0]
1570 gdy = globPos[1] - globEx[1]
1571 gdx = globPos[0] - globEx[0]
1572 rc = h[
'locBarPos_'+sdict[s]+
str(s*10+plane)].Fill( locPos[0],locPos[1])
1573 rc = h[
'locEx_'+sdict[s]+
str(s*10+plane)].Fill( locEx[0],locEx[1])
1574 rc = h[
'resY_'+sdict[s]+
str(s*10+plane)].Fill(dy,locEx[0])
1575 rc = h[
'resX_'+sdict[s]+
str(s*10+plane)].Fill(dx,locEx[1])
1576 rc = h[
'gresY_'+sdict[s]+
str(s*10+plane)].Fill(gdy,globEx[0])
1577 rc = h[
'gresX_'+sdict[s]+
str(s*10+plane)].Fill(gdx,globEx[1])
1580 left,right,smallL,smallR,Sleft,Sright,SleftS,SrightS = 0,0,0,0,0,0,0,0
1583 vetoHits[plane].append( [gdy,bar] )
1584 rc = h[
'resBarY_'+sdict[s]+
str(s*10+plane)].Fill(gdy,bar)
1586 vetoHits[plane].append( [gdx,bar] )
1587 rc = h[
'resBarX_'+sdict[s]+
str(s*10+plane)].Fill(gdx,bar)
1591 nc = x + 2*nSiPMs*bar
1592 h[
'resVETOY_'+
str(plane+1)].Fill(dy,nc)
1595 h[
'resVETOX_'+
str(plane+1)].Fill(dx,nc)
1603 rc = h[
'resY_'+sdict[s]+
'L'+
str(s*10+plane)].Fill(dy,locEx[1])
1604 rc = h[
'resX_'+sdict[s]+
'L'+
str(s*10+plane)].Fill(dx,locEx[0])
1605 rc = h[
'gresY_'+sdict[s]+
'L'+
str(s*10+plane)].Fill(gdy,globEx[1])
1606 rc = h[
'gresX_'+sdict[s]+
'L'+
str(s*10+plane)].Fill(gdx,globEx[0])
1608 rc = h[
'resY_'+sdict[s]+
'R'+
str(s*10+plane)].Fill(dy,locEx[1])
1609 rc = h[
'resX_'+sdict[s]+
'R'+
str(s*10+plane)].Fill(dx,locEx[0])
1610 rc = h[
'gresY_'+sdict[s]+
'R'+
str(s*10+plane)].Fill(gdy,globEx[1])
1611 rc = h[
'gresX_'+sdict[s]+
'R'+
str(s*10+plane)].Fill(gdx,globEx[0])
1612 if s==2
and (smallL>0
or smallR>0):
1613 rc = h[
'resY_'+sdict[s]+
'S'+
str(s*10+plane)].Fill(dy,locEx[1])
1614 rc = h[
'resX_'+sdict[s]+
'S'+
str(s*10+plane)].Fill(dx,locEx[0])
1615 rc = h[
'gresY_'+sdict[s]+
'S'+
str(s*10+plane)].Fill(gdy,globEx[1])
1616 rc = h[
'gresX_'+sdict[s]+
'S'+
str(s*10+plane)].Fill(gdx,globEx[0])
1618 if aHit.isVertical() : dist = abs(dx)
1620 if aHit.isVertical():
1621 dL = locA[1]- locEx[1]
1622 dR = locEx[1] - locB[1]
1624 dR = locA[0] - locEx[0]
1625 dL = locEx[0] - locB[0]
1626 barName = sdict[s]+
str(s*10+plane)+
'_'+
str(bar)
1627 rc = h[
'nSiPMsL_'+barName].Fill(left,dL)
1628 rc = h[
'nSiPMsR_'+barName].Fill(right,dR)
1633 rc = h[
'signalSL_'+barName+
'-c'+
str(x)].Fill(qcd,dL)
1636 rc = h[
'signalL_'+barName+
'-c'+
str(x)].Fill(qcd,dL)
1640 rc = h[
'signalSR_'+barName+
'-c'+
str(x-nSiPMs)].Fill(qcd,dR)
1643 rc = h[
'signalR_'+barName+
'-c'+
str(x-nSiPMs)].Fill(qcd,dR)
1645 rc = h[
'signalTL_'+barName].Fill(Sleft,dL)
1646 rc = h[
'signalTR_'+barName].Fill(Sright,dR)
1647 rc = h[
'signalTSL_'+barName].Fill(SleftS,dL)
1648 rc = h[
'signalTSR_'+barName].Fill(SrightS,dR)
1651 allTDCs =
map2Dict(aHit,
'GetAllTimes')
1652 if not aHit.isVertical():
1653 dt = aHit.GetDeltaT()
1654 dtF = aHit.GetFastDeltaT()
1655 mtVeto = aHit.GetImpactT() - T0Veto - (globPos[2] - Z0Veto)/u.speedOfLight
1656 h[
'dtLRvsX_'+sdict[s]+
str(s*10+plane)].Fill(xEx,dt*TDC2ns)
1657 h[
'dtLRvsX_'+barName].Fill(xEx,dt*TDC2ns)
1658 if (1
in allTDCs)
and (9
in allTDCs): h[
'dtF1LRvsX_'+barName].Fill(xEx,(allTDCs[1]-allTDCs[9])*TDC2ns)
1659 h[
'dtfastLRvsX_'+barName].Fill(xEx,dtF*TDC2ns)
1661 tcor = (globPos[2] - Z0track)/deltaZ02 * ToF
1662 mtTrack = aHit.GetImpactT() - T0track - tcor
1663 h[
'atLRvsX_'+sdict[s]+
str(s*10+plane)].Fill(xEx,mtTrack)
1664 h[
'atLRvsX_'+barName].Fill(xEx,mtTrack)
1667 dt = allTDCs[i]*TDC2ns-T0track - tcor
1669 if i<nSiPMs: h[
'tvsXL_'+barName+
'-c'+
str(i)].Fill(xEx,dt)
1671 h[
'tvsXR_'+barName+
'-c'+
str(i-nSiPMs)].Fill(xEx,dt)
1673 h[
'VetoatLRvsX_'+sdict[s]+
str(s*10+plane)].Fill(xEx,mtVeto)
1676 meanL,meanR,nL,nR=0,0,0,0
1680 if i==4: t0Left = allTDCs[i]
1681 if i==12: t0Right = allTDCs[i]
1693 if i<nSiPMs
and nL>0:
1694 key = sdict[s]+
str(s*10+plane)+
'_'+
str(bar)+
'-c'+
str(i)
1695 rc = h[
'sigmaTDCL_'+key].Fill( (allTDCs[i]-meanL/nL)*TDC2ns )
1696 if t0Left<900: rc = h[
'TDCcalibL_'+key].Fill( (allTDCs[i]-t0Left)*TDC2ns )
1697 elif not(i<nSiPMs)
and nR>0:
1698 key = sdict[s]+
str(s*10+plane)+
'_'+
str(bar)+
'-c'+
str(i-nSiPMs)
1699 rc = h[
'sigmaTDCR_'+key].Fill((allTDCs[i]-meanR/nR)*TDC2ns )
1700 if t0Right<900: rc = h[
'TDCcalibR_'+key].Fill( (allTDCs[i]-t0Right)*TDC2ns )
1702 meanL,meanR,nL,nR=0,0,0,0
1713 if i<nSiPMs
and nL>0:
1714 key = sdict[s]+
str(s*10+plane)+
'_'+
str(bar)+
'-c'+
str(i)
1715 rc = h[
'sigmaQDCL_'+key].Fill( (S[i]-meanL/nL) )
1716 elif not(i<nSiPMs)
and nR>0:
1717 key = sdict[s]+
str(s*10+plane)+
'_'+
str(bar)+
'-c'+
str(i-nSiPMs)
1718 rc = h[
'sigmaQDCR_'+key].Fill((S[i]-meanR/nR) )
1721 for l
in range(systemAndPlanes[s]):
1722 for side
in [
'L',
'R']:
1723 for bar
in range(systemAndBars[s]):
1724 key =
'sigmaTDC'+side+
'_'+sdict[s]+
str(s*10+l)+
'_'+
str(bar)
1725 h[key]=h[key+
'-c0'].Clone(key)
1727 for i
in range(systemAndChannels[s][1]+systemAndChannels[s][0]):
1728 h[key].Add(h[key+
'-c'+
str(i)])
1730 ut.writeHists(h,
'MuFilterEff_run'+
str(options.runNumber)+
'.root')
1736 if hasattr(x,
'Reset'): x.Reset()
1737 ut.readHists(h,
'MuFilterEff_run'+
str(options.runNumber)+
'.root',withProj=
False)
1739 for plane
in range(5):
1740 for bar
in range(10):
1743 if T==
'T': nloop = 1
1744 else: nloop = systemAndChannels[s][1]+systemAndChannels[s][0]
1745 for i
in range(nloop):
1747 name =
'signal'+T+p+
'_US'+
str(s*10+plane)+
'_'+
str(bar)
1748 if nloop>1: name +=
'-c'+
str(i)
1750 for x
in [
'M',
'C',
'W',
'S',
'E']:
1751 h[x+name]=histo.ProjectionY(x+name)
1753 h[x+name].SetTitle(histo.GetName()+
';distance [cm]')
1754 for n
in range(1,h[
'M'+name].GetNbinsX()+1):
1755 h[name+
'-X'+
str(n)] = h[name].ProjectionX(name+
'-X'+
str(n),n,n)
1756 tmp = h[name+
'-X'+
str(n)]
1757 h[
'C'+name].SetBinContent(n,-1)
1758 h[
'E'+name].SetBinContent(n,tmp.GetEntries())
1759 if tmp.GetEntries()>50:
1760 print(
'Fit ',options.runNumber,name,n)
1761 if T==
'T': bmin,bmax = 10,tmp.GetMaximumBin()
1762 else: bmin,bmax = 0,30
1763 for k
in range(tmp.GetMaximumBin(),1,-1):
1764 if tmp.GetBinContent(k)<2:
1767 for k
in range(tmp.GetMaximumBin(),tmp.GetNbinsX()):
1768 if tmp.GetBinContent(k) + tmp.GetBinContent(k+1)<2:
1771 res =
fit_langau(tmp,
'LQ',0.8*tmp.GetBinCenter(bmin),1.5*tmp.GetBinCenter(bmax))
1772 if not res:
continue
1773 if not res.IsValid():
continue
1774 h[
'C'+name].SetBinContent(n,res.Chi2()/res.Ndf())
1775 h[
'M'+name].SetBinContent(n,res.Parameter(1))
1776 h[
'M'+name].SetBinError(n,res.ParError(1))
1777 h[
'W'+name].SetBinContent(n,res.Parameter(0))
1778 h[
'W'+name].SetBinError(n,res.ParError(0))
1779 h[
'S'+name].SetBinContent(n,res.Parameter(3))
1780 h[
'S'+name].SetBinError(n,res.ParError(3))
1781 name =
'nSiPMs'+p+
'_US'+
str(s*10+plane)+
'_'+
str(bar)
1784 h[x+name]=histo.ProjectionY(x+name)
1786 h[x+name].SetTitle(histo.GetName()+
';distance [cm]')
1787 for n
in range(1,h[x+name].GetNbinsX()+1):
1788 tmp = h[name].ProjectionX(
'tmp',n,n)
1789 if tmp.GetEntries()<10:
continue
1790 h[x+name].SetBinContent(n,tmp.GetMean())
1791 h[x+name].SetBinError(n,tmp.GetRMS())
1796 for plane
in range(4):
1798 name =
'signal'+p+
'_DS'+
str(s*10+plane)
1799 h[name]=h[name+
'_'+
str(0)].Clone(name)
1800 for bar
in range(60):
1801 h[name].Add(h[name+
'_'+
str(bar)])
1804 for x
in [
'M',
'W',
'S']:
1805 h[x+name]=histo.ProjectionY(x+name)
1807 h[x+name].SetTitle(histo.GetName()+
';distance [cm]')
1808 for n
in range(1,h[
'M'+name].GetNbinsX()+1):
1809 h[name+
'-X'+
str(n)] = h[name].ProjectionX(name+
'-X'+
str(n),n,n)
1810 tmp = h[name+
'-X'+
str(n)]
1811 if tmp.GetEntries()>50:
1812 print(
'Fit ',options.runNumber,name,n)
1814 for k
in range(tmp.GetMaximumBin(),1,-1):
1815 if tmp.GetBinContent(k)<2:
1818 res =
fit_langau(tmp,
'LQ',0.8*tmp.GetBinCenter(bmin),1.5*tmp.GetBinCenter(bmax))
1819 if not res:
continue
1820 if not res.IsValid():
continue
1821 h[
'M'+name].SetBinContent(n,res.Parameter(1))
1822 h[
'M'+name].SetBinError(n,res.ParError(1))
1823 h[
'W'+name].SetBinContent(n,res.Parameter(0))
1824 h[
'W'+name].SetBinError(n,res.ParError(0))
1825 h[
'S'+name].SetBinContent(n,res.Parameter(3))
1826 h[
'S'+name].SetBinError(n,res.ParError(3))
1828 ut.writeHists(h,
'LandauFits_run'+
str(options.runNumber)+
'.root')
1857 if readhisto: ut.readHists(h,
'LandauFits_run'+
str(options.runNumber)+
'.root',withProj=
False)
1858 langau = ROOT.TF1(
'Langau',langaufun,0.,100.,4)
1859 ut.bookCanvas(h,
'CsignalT',
'',1200,2000,2,5)
1860 ut.bookCanvas(h,
'WsignalT',
'',1200,2000,2,5)
1861 ut.bookCanvas(h,
'SsignalT',
'',1200,2000,2,5)
1862 ut.bookCanvas(h,
'Msignal1',
'',900,600,1,1)
1863 ut.bookCanvas(h,
'MsignalT',
'',1200,2000,2,5)
1864 ut.bookCanvas(h,
'MsignalT1',
'',900,600,1,1)
1865 ut.bookCanvas(h,
'NnSiPMs1',
'',900,600,1,1)
1866 ut.bookCanvas(h,
'NnSiPMs',
'',1200,2000,2,5)
1869 name =
'signal'+T+
'L_US22_5-X10'
1870 tc = h[
'Msignal'+T+
'1'].cd()
1873 stats = h[name].FindObject(
'stats')
1874 stats.SetOptFit(1111111)
1875 stats.SetX1NDC(0.51)
1876 stats.SetY1NDC(0.54)
1877 stats.SetX2NDC(0.98)
1878 stats.SetY2NDC(0.94)
1880 myPrint(h[
'Msignal'+T+
'1'],
'signal'+T+
'1')
1881 tc = h[
'NnSiPMs1'].cd(1)
1882 h[
'nSiPMs1'] = h[
'nSiPMsL_US21_5'].ProjectionX(
'nSiPMs1',1,9)
1883 h[
'nSiPMs1'].Draw(
'hist')
1885 myPrint(h[
'NnSiPMs1'],
'nSiPMs1')
1889 ut.bookCanvas(h,
'Mpvs',
'',2400,1200,1,2)
1890 ut.bookCanvas(h,
'attLs',
'',2400,1200,1,2)
1891 tc = h[
'Mpvs'].cd(1)
1892 h[
'attLengthL'],h[
'attLengthR'],h[
'attLengthLC'],h[
'attLengthRC']= ROOT.TGraph(),ROOT.TGraph(),ROOT.TGraph(),ROOT.TGraph()
1893 h[
'mpv0L'],h[
'mpv0R'],h[
'mpv0LC'],h[
'mpv0RC'] = ROOT.TGraph(),ROOT.TGraph(),ROOT.TGraph(),ROOT.TGraph()
1897 for plane
in range(5):
1898 for bar
in range(10):
1899 if t==
'T': nloop = 1
1900 else: nloop = systemAndChannels[s][1]+systemAndChannels[s][0]
1901 for i
in range(nloop):
1903 name =
'Msignal'+t+p+
'_US'+
str(s*10+plane)+
'_'+
str(bar)
1904 chi2N =
'Csignal'+t+p+
'_US'+
str(s*10+plane)+
'_'+
str(bar)
1907 chi2N +=
'-c'+
str(i)
1910 for i
in range(1,h[chi2N].GetNbinsX()+1):
1911 funL = h[name[1:]+
'-X'+
str(i)].GetFunction(
'langau')
1912 if not funL:
continue
1913 if not funL.GetParameter(1)>0:
continue
1914 mpvRelErr = funL.GetParError(1)/funL.GetParameter(1)*ROOT.TMath.Sqrt(h[name[1:]+
'-X'+
str(i)].GetEntries())
1916 print(
'exclude bin ',name,i,mpvRelErr,h[name[1:]+
'-X'+
str(i)].GetEntries())
1918 if len(limits)==0
and h[chi2N].GetBinContent(i)>0
and h[chi2N].GetBinContent(i)<9:
1919 limits.append(h[chi2N].GetBinCenter(i))
1921 for i
in range(h[chi2N].GetNbinsX(),1,-1):
1922 funL = h[name[1:]+
'-X'+
str(i)].GetFunction(
'langau')
1923 if not funL:
continue
1924 if not funL.GetParameter(1)>0:
continue
1925 mpvRelErr = funL.GetParError(1)/funL.GetParameter(1)*ROOT.TMath.Sqrt(h[name[1:]+
'-X'+
str(i)].GetEntries())
1927 print(
'exclude bin ',name,i,mpvRelErr,h[name[1:]+
'-X'+
str(i)].GetEntries())
1929 if len(limits)==1
and h[chi2N].GetBinContent(i)>0
and h[chi2N].GetBinContent(i)<9:
1930 limits.append(h[chi2N].GetBinCenter(i))
1938 h[
'mpv0'+tag].SetPoint(nk,X,-1)
1939 h[
'attLength'+tag].SetPoint(nk,X,0)
1942 rc = h[name].Fit(
'expo',
'SQ',
'',limits[0],limits[1])
1943 fun = h[name].GetFunction(
'expo')
1944 fun.SetLineColor(barColor[bar%10])
1953 h[
'mpv0'+tag].SetPoint(nk,X,val)
1954 h[
'attLength'+tag].SetPoint(nk,X,-1./res.Parameter(1))
1957 ut.bookHist(h,
'hMpvs',
';stations with bars; MPV [QCD]',101,-0.5,50.5)
1958 ut.bookHist(h,
'hAttl',
';plane number; att length [cm]',101,-0.5,50.5)
1959 params = {
'hMpvs':[
'Mpvs',20,
'mpv0',0.],
'hAttl':[
'attLs',0.,
'attLength',-2000.]}
1960 side = {
'L':[ROOT.kBlue,
''],
'R':[ROOT.kRed,
'same']}
1963 h[P].SetMaximum(params[P][1])
1964 h[P].SetMinimum(params[P][3])
1968 for tag
in [
'',
'C']:
1969 tc = h[params[P][0]].cd(1)
1970 if tag ==
'C': tc = h[params[P][0]].cd(2)
1974 h[params[P][2]+S+tag].SetMarkerStyle(92)
1976 h[params[P][2]+S+tag].SetMarkerSize(1)
1977 h[params[P][2]+S+tag].SetMarkerStyle(71)
1978 else: h[params[P][2]+S+tag].SetMarkerSize(2)
1979 h[params[P][2]+S+tag].SetMarkerColor(side[S][0])
1980 h[params[P][2]+S+tag].Draw(
'P'+side[S][1])
1983 myPrint(h[
'attLs'],
'AttLength')
1986 tMax = {
'CsignalT':0,
'MsignalT':0,
'NnSiPMs':0,
'WsignalT':0,
'SsignalT':0}
1987 for plane
in range(5):
1990 for bar
in range(10):
1991 name = t+p+
'_US'+
str(s*10+plane)+
'_'+
str(bar)
1992 nmax = h[name].GetBinContent(h[name].GetMaximumBin())
1993 err = h[name].GetBinError(h[name].GetMaximumBin())
1994 if err/nmax > 0.2:
continue
1995 if nmax > tMax[t]: tMax[t]=nmax
1996 for plane
in range(5):
2000 for bar
in range(10):
2001 color = barColor[bar%10]
2002 name = t+p+
'_US'+
str(s*10+plane)+
'_'+
str(bar)
2004 h[name].SetMarkerStyle(34)
2005 h[name].SetMarkerColor(color)
2006 h[name].SetLineColor(color)
2008 if len(tc.GetListOfPrimitives())>0: dropt=
'same'
2009 h[name].SetMinimum(0.)
2010 h[name].SetMaximum(tMax[t]*1.1)
2011 if name.find(
'CsignalT')==0:
2012 h[name].SetTitle(
'station '+p+
' '+
str(plane+1)+
';chi2/nDoF')
2013 if name.find(
'MsignalT')==0:
2014 h[name].SetTitle(
'QDC sum station '+p+
' '+
str(plane+1)+
';d [cm];QDC')
2015 elif name.find(
'SsignalT')==0:
2016 h[name].SetTitle(
'sigma '+p+
' '+
str(plane+1)+
';d [cm];QDC')
2017 elif name.find(
'WsignalT')==0:
2018 h[name].SetTitle(
'width '+p+
' '+
str(plane+1)+
';d [cm];QDC')
2019 if t==
'MsignalT': rc = h[name].Draw(
'P'+dropt)
2020 else: rc = h[name].Draw(
'PL'+dropt)
2022 tc = h[
'NnSiPMs1'].cd(1)
2023 h[name].SetMinimum(3)
2024 if k>1: dropt =
'same'
2027 for t
in [
'MsignalT',
'NnSiPMs',
'WsignalT',
'SsignalT']:
myPrint(h[t],t)
2028 myPrint(h[
'NnSiPMs1'],
'nSiPMsAll')
2031 ut.bookCanvas(h,
'Msignal1',
'',900,600,1,1)
2033 tc = h[
'Msignal1'].cd()
2034 name =
'signalR_DS31-X11'
2037 stats = h[name].FindObject(
'stats')
2038 stats.SetOptFit(1111111)
2039 stats.SetX1NDC(0.51)
2040 stats.SetY1NDC(0.54)
2041 stats.SetX2NDC(0.98)
2042 stats.SetY2NDC(0.94)
2044 myPrint(h[
'Msignal1'],
'signalDS1')
2046 ut.bookCanvas(h,
'MDsignal2d',
'',900,600,2,4)
2048 for plane
in range(4):
2050 tc = h[
'MDsignal2d'].cd(k)
2051 h[
'signal'+p+
'_DS3'+
str(plane)].SetTitle(
'; QDC ;d [cm]')
2052 h[
'signal'+p+
'_DS3'+
str(plane)].Draw(
'colz')
2054 myPrint(h[
'MDsignal2d'],
'MDsignal2d')
2055 ut.bookCanvas(h,
'MDSsignal',
'',1200,900,1,1)
2056 plColor={0:ROOT.kBlue,1:ROOT.kGreen,2:ROOT.kCyan,3:ROOT.kOrange}
2057 pMarker={
'L':22,
'R':23}
2060 for plane
in range(4):
2061 hist = h[
'Msignal'+p+
'_DS3'+
str(plane)]
2062 if hist.GetEntries()<1:
continue
2064 hist.SetTitle(
";distance [cm]")
2065 hist.SetMarkerStyle(pMarker[p])
2066 hist.SetMarkerColor(plColor[plane])
2067 hist.SetLineColor(plColor[plane])
2068 if p==
'R' or plane%2==1: rc=hist.Fit(
'expo',
'S',
'',0,60)
2069 if p==
'L' and plane%2==0: rc=hist.Fit(
'expo',
'S',
'',20,80)
2071 if res: slopes[
str(plane)+p]=[res.Parameter(1),res.ParError(1)]
2072 hist.GetFunction(
'expo').SetLineColor(plColor[plane])
2074 h[
'MsignalR_DS30'].SetMaximum(60)
2075 h[
'MsignalR_DS30'].Draw()
2078 for plane
in range(4):
2079 hist = h[
'Msignal'+p+
'_DS3'+
str(plane)]
2080 if hist.GetEntries()<1:
continue
2083 if plane%2==1: pp=
'T'
2084 txt =
"%i%s (%5.1F+/-%5.1F)cm"%(plane,pp,-1./slopes[
str(plane)+p][0],slopes[
str(plane)+p][1]/slopes[
str(plane)+p][0]**2)
2085 latex.DrawLatexNDC(0.3,0+y,txt)
2087 myPrint(h[
'MDSsignal'],
'DSattenuation')
2130 ut.readHists(h,options.path+
"MuFilterEff_run"+
str(r)+
".root",withProj=
False)
2132 h[
'tdcCalib'+sdict[s]] = {}
2133 for l
in range(systemAndPlanes[s]):
2134 for bar
in range(systemAndBars[s]):
2135 for side
in [
'L',
'R']:
2136 key = sdict[s]+
str(s*10+l)+
'_'+
str(bar)
2137 for i
in range(systemAndChannels[s][1]+systemAndChannels[s][0]):
2138 if i==t0_channel:
continue
2139 j = side+
'_'+key+
'-c'+
str(i)
2142 h[
'tdcCalib'+sdict[s]][j] =[0,0,0,0]
2143 if h[x].GetEntries()>10:
2144 rc = h[x].Fit(
'gaus',
'SNQ')
2145 rc = h[x].Fit(
'gaus',
'SNQ')
2148 h[
'tdcCalib'+sdict[s]][j] =[res.Parameter(1),res.ParError(1),res.Parameter(2),res.ParError(2)]
2150 for l
in range(systemAndPlanes[s]):
2151 tag = sdict[s]+
str(l)
2152 ut.bookCanvas(h,
'sigmaTDC_'+tag,
'TDC RMS',2000,600,systemAndBars[s],2)
2153 ut.bookCanvas(h,
'TDCcalib_'+tag,
'TDC TDCi-T0',2000,600,systemAndBars[s],2)
2154 ut.bookCanvas(h,
'sigmaQDC_'+tag,
'QDC RMS',2000,600,systemAndBars[s],2)
2156 for bar
in range(systemAndBars[s]):
2157 for side
in [
'L',
'R']:
2158 key = sdict[s]+
str(10*s+l)+
'_'+
str(bar)
2159 for i
in range(systemAndChannels[s][1]+systemAndChannels[s][0]):
2160 j = side+
'_'+key+
'-c'+
str(i)
2161 for x
in [
'sigmaTDC_'+tag,
'TDCcalib_'+tag,
'sigmaQDC_'+tag]:
2162 if x.find(
'calib')>0
and (i==t0_channel):
continue
2165 if i==0
and x.find(
'calib')<0: opt=
""
2166 if i==1
and x.find(
'calib')>0: opt=
""
2167 aHist = x.split(
'_')[0]+j
2168 h[aHist].SetLineColor(barColor[i])
2169 if x.find(
'QDC')>0: h[aHist].GetXaxis().SetRangeUser(-15,15)
2170 else: h[aHist].GetXaxis().SetRangeUser(-5,5)
2172 h[aHist].Draw(opt+
'HIST')
2174 myPrint(h[
'sigmaTDC'+tag],
'TDCrms'+tag)
2175 myPrint(h[
'TDCcalib'+tag],
'TDCcalib'+tag)
2176 myPrint(h[
'sigmaQDC'+tag],
'QDCrms'+tag)
2178 ut.bookHist(h,
'TDCcalibMean_'+tag,
';SiPM channel ; [ns]',160,0.,160.)
2179 ut.bookHist(h,
'TDCcalibSigma_'+tag,
';SiPM channel ; [ns]',160,0.,160.)
2180 h[
'gTDCcalibMean_'+tag]=ROOT.TGraphErrors()
2181 h[
'gTDCcalibSigma_'+tag]=ROOT.TGraphErrors()
2183 x =
'TDCcalib'+sdict[s]
2184 tmp = h[
'tdcCalib'+sdict[s]][x]
2186 if x[0]==
'R': side = 1
2190 xbin =
int(bar)*16+side*8+
int(c)
2191 tag = sdict[s]+
"_"+
str(l)
2192 rc = h[
'TDCcalibMean_'+tag].SetBinContent(xbin+1,tmp[0])
2193 rc = h[
'TDCcalibMean_'+tag].SetBinError(xbin+1,tmp[1])
2194 rc = h[
'TDCcalibSigma_'+tag].SetBinContent(xbin+1,tmp[2])
2195 rc = h[
'TDCcalibSigma_'+tag].SetBinError(xbin+1,tmp[3])
2197 ut.bookCanvas(h,
'tTDCcalib'+sdict[s],
'TDC calib',2400,1800,2,5)
2198 for l
in range(systemAndPlanes[s]):
2199 tag = sdict[s]+
"_"+
str(l)
2200 aHistS = h[
'TDCcalibSigma_'+tag]
2201 aHistM = h[
'TDCcalibMean_'+tag]
2203 for i
in range(1,aHistS.GetNbinsX()):
2204 if aHistS.GetBinContent(i)>0:
2205 h[
'gTDCcalibSigma_'+tag].SetPoint(k,i-1,aHistS.GetBinContent(i))
2206 h[
'gTDCcalibSigma_'+tag].SetPointError(k,0.5,aHistS.GetBinError(i))
2207 h[
'gTDCcalibMean_'+tag].SetPoint(k,i-1,aHistM.GetBinContent(i))
2208 h[
'gTDCcalibMean_'+tag].SetPointError(k,0.5,aHistM.GetBinError(i))
2211 planeColor = {0:ROOT.kBlue,1:ROOT.kRed,2:ROOT.kGreen,3:ROOT.kCyan,4:ROOT.kMagenta}
2212 for l
in range(systemAndPlanes[s]):
2213 tag = sdict[s]+
"_"+
str(l)
2214 tc = h[
'tTDCcalib'].cd(2*l+1)
2215 aHistS = h[
'TDCcalibSigma_'+tag]
2217 aHistS.SetMaximum(2.0)
2219 h[
'gTDCcalibSigma_'+tag].SetLineColor(planeColor[l])
2220 h[
'gTDCcalibSigma_'+tag].Draw(
'same')
2222 for l
in range(systemAndPlanes[s]):
2223 tag = sdict[s]+
"_"+
str(l)
2224 tc = h[
'tTDCcalib'+sdict[s]]+cd(2*l+2)
2225 aHistM = h[
'TDCcalibMean_'+tag]
2227 aHistM.SetMaximum(2.0)
2228 aHistM.SetMinimum(-2.0)
2230 h[
'gTDCcalibMean_'+tag].SetLineColor(planeColor[l])
2231 h[
'gTDCcalibMean_'+tag].Draw(
'same')
2232 myPrint(h[
'tTDCcalib'+sdict[s]],
'TDCcalibration'+sdict[s])
2237 if hasattr(x,
'Reset'): x.Reset()
2238 ut.readHists(h,
'MuFilterEff_run'+
str(options.runNumber)+
'.root',withProj=
False)
2239 ut.bookCanvas(h,
'dummy',
'',900,800,1,1)
2241 if options.runNumber<100: S = [2]
2244 for side
in [
'L',
'R']:
2245 if s==1: ut.bookCanvas(h,mode+
'Time'+side+
'-'+
str(s),
'',1800,800,2,1)
2246 if s==2: ut.bookCanvas(h,mode+
'Time'+side+
'-'+
str(s),
'',1800,1500,2,3)
2248 for plane
in range(systemAndPlanes[s]):
2250 nbars += systemAndBars[s]
2251 ut.bookHist(h,mode+
'tsigma_'+
str(s),
';'+
str(systemAndBars[s])+
'*station + bar number;#sigma_{t} [ns]',nbars,-0.5,nbars-0.5)
2254 resultsT0 = h[
'resultsT0']
2256 tc = h[
'dummy'].cd()
2260 for l
in range(systemAndPlanes[s]):
2262 for side
in [
'L',
'R']:
2263 resultsT0[s][l][side]={}
2264 for bar
in range(systemAndBars[s]):
2265 resultsT0[s][l][side][bar]={}
2266 for sipm
in range(systemAndChannels[s][0]+systemAndChannels[s][1]):
2267 resultsT0[s][l][side][bar][sipm] = {}
2268 key = sdict[s]+
str(s*10+l)+
'_'+
str(bar)
2269 name =
'tvsX'+side+
'_'+key+
'-c'+
str(sipm)
2271 h[tname] = h[name].ProjectionX(tname)
2273 h[
'g_'+name] = ROOT.TGraphErrors()
2276 xax = h[tname].GetXaxis()
2277 yax = h[tname].GetYaxis()
2278 yax.SetTitle(
'#sigma_{t} [ns]')
2280 for j
in range(1,xax.GetNbins()+1):
2281 jname = name+
'-X'+
str(j)
2282 h[jname] = h[name].ProjectionY(jname,j,j)
2283 if h[jname].GetEntries()<minContent:
continue
2284 rc = h[jname].Fit(
'gaus',
'SQ0')
2287 h[tname].SetBinContent(j,res.Parameter(2))
2288 h[tname].SetBinError(j,res.ParError(2))
2289 g.SetPoint(np,xax.GetBinCenter(j),res.Parameter(1))
2290 g.SetPointError(np,xax.GetBinCenter(j),res.ParError(1))
2294 resultsT0[s][l][side][bar][sipm][
'meanSigma'] = A[0]
2295 resultsT0[s][l][side][bar][sipm][
'errorSigma'] = A[1]
2296 rc = g.Fit(
'pol1',
'SQ')
2298 if not res:
continue
2299 resultsT0[s][l][side][bar][sipm][
'velocity'] = 1./res.Parameter(1)
2303 ut.bookHist(h,
'allV_'+
str(s),
';sipm channel;[cm/ns]',800,0.,800.)
2304 ut.bookHist(h,
'allVdis_'+
str(s),
';[cm/ns]',100,-20.,20.)
2305 h[
'gallV_'+
str(s)] = ROOT.TGraph()
2308 for l
in resultsT0[s]:
2309 for side
in resultsT0[s][l]:
2310 for bar
in resultsT0[s][l][side]:
2311 for sipm
in resultsT0[s][l][side][bar]:
2312 X = resultsT0[s][l][side][bar][sipm]
2315 rc = h[
'allV_'+
str(s)].Fill(np,V)
2317 h[
'gallV_'+
str(s)].SetPoint(nx,np,abs(V))
2319 rc = h[
'allVdis_'+
str(s)].Fill(V)
2321 ut.bookCanvas(h,
'sV'+
str(s),
'',1600,800,1,1)
2322 tc = h[
'sV'+
str(s)].cd()
2323 h[
'allVdis_'+
str(s)].SetStats(0)
2324 h[
'allV_'+
str(s)].SetStats(0)
2325 rc = h[
'allVdis_'+
str(s)].Fit(
'gaus',
'S',
'',-18,-8)
2327 rc = h[
'allVdis_'+
str(s)].Fit(
'gaus',
'S+',
'',8,18)
2330 txt.DrawLatexNDC(0.3,0.5,
"v=%5.2F cm/ns"%(resL.Parameter(1)))
2331 txt.DrawLatexNDC(0.3,0.4,
"v=+%5.2F cm/ns"%(resR.Parameter(1)))
2332 myPrint(h[
'sV'+
str(s)],sdict[s]+
'signalSpeedSum')
2333 hist = h[
'allV_'+
str(s)]
2338 h[
'gallV_'+
str(s)].SetMarkerStyle(29)
2339 h[
'gallV_'+
str(s)].SetMarkerSize(1.5)
2340 h[
'gallV_'+
str(s)].SetMarkerColor(ROOT.kBlue)
2341 h[
'gallV_'+
str(s)].Draw(
'P')
2344 for l
in range(systemAndPlanes[s]):
2345 for side
in [
'L',
'R']:
2347 h[
'sideLines'].append(ROOT.TLine(xchan,hist.GetMinimum(),xchan,hist.GetMaximum()) )
2348 L = h[
'sideLines'][len(h[
'sideLines'])-1]
2349 L.SetLineColor(ROOT.kGreen)
2352 myPrint(h[
'sV'+
str(s)],sdict[s]+
'signalSpeedChannel')
2355 h[
'gallSigm_'+
str(s)] = ROOT.TGraphErrors()
2356 ut.bookHist(h,
'allSigm_'+
str(s),
';SiPM channel ; [ns]',800,0.,800.)
2357 hist = h[
'allSigm_'+
str(s)]
2358 ut.bookCanvas(h,
'sS'+
str(s),
'',1600,800,1,1)
2361 for l
in resultsT0[s]:
2362 for side
in resultsT0[s][l]:
2363 for bar
in resultsT0[s][l][side]:
2364 for sipm
in resultsT0[s][l][side][bar]:
2365 X = resultsT0[s][l][side][bar][sipm]
2366 if 'meanSigma' in X:
2369 h[
'gallSigm_'+
str(s)].SetPoint(nx,np,V)
2370 h[
'gallSigm_'+
str(s)].SetPointError(nx,0.5,E)
2375 for l
in resultsT0[s]:
2376 for bar
in resultsT0[s][l][side]:
2377 for side
in resultsT0[s][l]:
2378 txt =
'%s%i %i %s:'%(sdict[s],10*s+l,bar,side)
2379 for sipm
in resultsT0[s][l][side][bar]:
2380 X = resultsT0[s][l][side][bar][sipm]
2383 if 'meanSigma' in X:
2386 txt +=
' %5.0F+/-%5.0F '%(V*1000,E*1000)
2389 tc = h[
'sS'+
str(s)].cd()
2390 hist.SetMaximum(1.5)
2394 h[
'gallSigm_'+
str(s)].SetMarkerStyle(29)
2395 h[
'gallSigm_'+
str(s)].SetMarkerSize(1.5)
2396 h[
'gallSigm_'+
str(s)].SetMarkerColor(ROOT.kBlue)
2397 h[
'gallSigm_'+
str(s)].Draw(
'P')
2400 for l
in range(systemAndPlanes[s]):
2401 for side
in [
'L',
'R']:
2403 h[
'sideLines'].append(ROOT.TLine(xchan,0.,xchan,hist.GetMaximum()) )
2404 L = h[
'sideLines'][len(h[
'sideLines'])-1]
2405 L.SetLineColor(ROOT.kGreen)
2407 myPrint(h[
'sS'+
str(s)],sdict[s]+
'SigmaChannel')
2410 tc = h[
'dummy'].cd()
2412 for l
in range(systemAndPlanes[s]):
2413 for bar
in range(systemAndBars[s]):
2414 for side
in [
'L',
'R']:
2415 txt=
str(s*10+l)+side+
"_"+
str(bar)
2416 for sipm
in range(systemAndChannels[s][0]+systemAndChannels[s][1]):
2418 X = resultsT0[s][side][bar][sipm]
2419 if len(X)==2: txt+=
" "+
"%5.2F"%(X[
'meanSigma'] )
2420 else: txt+=
" "+
"%5.2F"%(-1)
2421 key = sdict[s]+
str(s*10+l)+
'_'+
str(bar)
2422 name =
'tvsX'+side+
'_'+key+
'-c'+
str(sipm)
2424 h[name].Draw(
'colz')
2425 myPrint(h[
'dummy'],name+
'X',withRootFile=
False)
2427 os.system(
"convert -delay 120 -loop 0 *X.png TDCallChannels_"+sdict[s]+
".gif")
2428 os.system(
"rm *X.png")
2431 maxRes = {1:0.6,2:1.0,3:0.6}
2434 if hasattr(x,
'Reset'): x.Reset()
2435 ut.readHists(h,
'MuFilterEff_run'+
str(options.runNumber)+
'.root',withProj=
False)
2436 ut.bookCanvas(h,
'dummy',
'',900,800,1,1)
2438 if options.runNumber<100: S = [2,3]
2440 results = h[
'results']
2441 for mode
in [
'',
'fast',
'F1']:
2444 results[mode][s] = {}
2445 if s==1: ut.bookCanvas(h,mode+
'TimeLR-'+
str(s),
'',1800,800,2,1)
2446 if s==2: ut.bookCanvas(h,mode+
'TimeLR-'+
str(s),
'',1800,1500,2,3)
2447 if s==3: ut.bookCanvas(h,mode+
'TimeLR-'+
str(s),
'',900,1500,1,3)
2449 for plane
in range(systemAndPlanes[s]):
2451 nbars += systemAndBars[s]
2452 ut.bookHist(h,mode+
'tsigma_'+
str(s),
';'+
str(systemAndBars[s])+
'*station + bar number;#sigma_{t} [ns]',nbars,-0.5,nbars-0.5)
2454 for plane
in range(systemAndPlanes[s]):
2456 results[mode][s][plane]={}
2457 for bar
in range(systemAndBars[s]):
2458 results[mode][s][plane][bar]={}
2459 tc = h[
'dummy'].cd()
2460 name0 =
'dt'+mode+
'LRvsX_'+sdict[s]+
str(s*10+plane)+
'_'+
str(bar)
2461 name =
'Rdt'+mode+
'LRvsX_'+sdict[s]+
str(s*10+plane)+
'_'+
str(bar)
2462 tname = mode+
'TimeRes_'+sdict[s]+
str(s*10+plane)+
'_'+
str(bar)
2463 h[name] = h[name0].Clone(name)
2464 h[tname] = h[name].ProjectionX(tname)
2466 h[
'g_'+name] = ROOT.TGraphErrors()
2469 xax = h[tname].GetXaxis()
2470 yax = h[tname].GetYaxis()
2471 yax.SetTitle(
'#sigma_{t} [ns]')
2472 ymin = h[name].GetYaxis().GetBinCenter(1)
2473 ymax = h[name].GetYaxis().GetBinCenter(h[name].GetYaxis().GetNbins())
2475 for j
in range(1,xax.GetNbins()+1):
2476 jname = name+
'-X'+
str(j)
2477 h[jname] = h[name].ProjectionY(jname,j,j)
2478 if h[jname].GetSumOfWeights()<minContent:
continue
2479 xx = h[jname].GetBinCenter(h[jname].GetMaximumBin())
2480 xmin = max(ymin,xx-2.)
2481 xmax = min(ymax,xx+2.)
2482 rc = h[jname].Fit(
'gaus',
'SQL',
'',xmin,xmax)
2484 h[tname].SetBinContent(j,res.Parameter(2))
2485 h[tname].SetBinError(j,res.ParError(2))
2486 g.SetPoint(np,xax.GetBinCenter(j),res.Parameter(1))
2487 g.SetPointError(np,xax.GetBinCenter(j),res.ParError(1))
2491 h[mode+
'tsigma_'+
str(s)].SetBinContent(plane*systemAndBars[s]+bar,A[0])
2492 h[mode+
'tsigma_'+
str(s)].SetBinError(plane*systemAndBars[s]+bar,A[1])
2493 rc = g.Fit(
'pol1',
'SQ')
2495 if not res:
continue
2496 results[mode][s][plane][bar][
'velocity'] = 2./res.Parameter(1)
2500 color = barColor[bar%10]
2501 h[tname].SetMaximum(maxRes[s])
2502 h[tname].SetStats(0)
2503 h[tname].SetMarkerStyle(34)
2504 h[tname].SetMarkerColor(color)
2505 h[tname].SetLineColor(color)
2506 tc = h[mode+
'TimeLR-'+
str(s)].cd(k)
2507 h[tname].Draw(
'P'+opt)
2508 h[tname].Draw(
'HISTLSAME')
2511 ut.bookCanvas(h,mode+
'dummy'+sdict[s],
'',900,800,1,1)
2512 tc = h[mode+
'dummy'+sdict[s]].cd()
2514 name = mode+
'tsigma_'+
str(s)
2516 h[name].SetMarkerColor(ROOT.kBlue)
2517 h[name].SetMarkerStyle(34)
2518 h[name].SetMarkerSize(2)
2519 X = h[name].GetXaxis()
2521 X.SetNdivisions(505)
2523 myPrint(h[mode+
'dummy'+sdict[s]],mode+
'TimeResol-'+sdict[s])
2524 myPrint(h[mode+
'TimeLR-'+
str(s)],mode+
'TimeResol-'+sdict[s]+
'vsX')
2527 tc = h[
'dummy'].cd()
2529 for l
in range(systemAndPlanes[s]):
2531 if l==4
and s==3:
continue
2532 for bar
in range(systemAndBars[s]):
2533 name =
'dtLRvsX_'+sdict[s]+
str(s*10+l)+
'_'+
str(bar)
2534 if h[name].GetSumOfWeights()>50: h[name].Draw(
'colz')
2535 myPrint(h[
'dummy'],
str(l)+
'-'+
str(bar).zfill(2)+
'Xanimat',withRootFile=
False)
2536 os.system(
"convert -delay 120 -loop 0 *Xanimat-run"+
str(options.runNumber)+
".png TDCvsX_"+sdict[s]+
"-animat.gif")
2537 os.system(
"rm *Xanimat-run*.png")
2541 h[
'galldtV_'+
str(s)] = ROOT.TGraph()
2542 if s==3: ut.bookHist(h,
'alldtV_'+
str(s),
';bar;[cm/ns]',180,0.,180.)
2543 if s==2: ut.bookHist(h,
'alldtV_'+
str(s),
';bar;[cm/ns]',800,0.,800.)
2544 if s==1: ut.bookHist(h,
'alldtV_'+
str(s),
';bar;[cm/ns]',15,0.,15.)
2545 ut.bookHist(h,
'alldtVdis_'+
str(s),
';[cm/ns]',100,10.,20.)
2548 for plane
in range(systemAndPlanes[s]):
2550 for bar
in range(systemAndBars[s]):
2551 X = results[mode][s][plane][bar]
2555 h[
'galldtV_'+
str(s)].SetPoint(nx,np,abs(V))
2557 rc = h[
'alldtVdis_'+
str(s)].Fill(abs(V))
2559 ut.bookCanvas(h,
'sdtV'+
str(s),
'',1600,800,1,1)
2560 tc = h[
'sdtV'+
str(s)].cd()
2561 h[
'alldtVdis_'+
str(s)].SetStats(0)
2562 h[
'alldtV_'+
str(s)].SetStats(0)
2563 rc = h[
'alldtVdis_'+
str(s)].Fit(
'gaus',
'SL',
'',10,18)
2566 txt.DrawLatexNDC(0.3,0.5,
"v=%5.2F cm/ns"%(res.Parameter(1)))
2567 myPrint(h[
'sdtV'+
str(s)],sdict[s]+
'dTsignalSpeedSum')
2568 hist = h[
'alldtV_'+
str(s)]
2573 h[
'galldtV_'+
str(s)].SetMarkerStyle(29)
2574 h[
'galldtV_'+
str(s)].SetMarkerSize(1.5)
2575 h[
'galldtV_'+
str(s)].SetMarkerColor(ROOT.kBlue)
2576 h[
'galldtV_'+
str(s)].Draw(
'P')
2577 myPrint(h[
'sdtV'+
str(s)],sdict[s]+
'dTsignalSpeed')
2599 ut.bookCanvas(h,
'area',
'',900,900,1,1)
2600 hname =
'track_'+sdict[s]+
str(s)+
str(p)
2603 h[hname].SetStats(0)
2604 h[hname].SetTitle(
'')
2605 h[hname].Draw(
'colz'+opt)
2606 mufi = geo.modules[
'MuFilter']
2607 if opt==
'': h[
'lines'] = []
2609 latex.SetTextColor(ROOT.kRed)
2610 latex.SetTextSize(0.03)
2611 for bar
in range(systemAndBars[s]):
2612 mufi.GetPosition(s*10000+p*1000+bar,A,B)
2614 botL = ROOT.TVector3(A.X(),A.Y()-barw,0)
2615 botR = ROOT.TVector3(B.X(),B.Y()-barw,0)
2616 topL = ROOT.TVector3(A.X(),A.Y()+barw,0)
2617 topR = ROOT.TVector3(B.X(),B.Y()+barw,0)
2618 lines.append(ROOT.TLine(topL.X(),topL.Y(),topR.X(),topR.Y()))
2619 lines.append(ROOT.TLine(botL.X(),botL.Y(),botR.X(),botR.Y()))
2620 lines.append(ROOT.TLine(botL.X(),botL.Y(),topL.X(),topL.Y()))
2621 lines.append(ROOT.TLine(botR.X(),botR.Y(),topR.X(),topR.Y()))
2622 if s<3
or (s==3
and bar%5==0): latex.DrawLatex(botR.X()-5.,botR.Y()+0.3,barName)
2624 for n
in range(N-4,N):
2626 l.SetLineColor(color)
2628 for l
in lines: l.Draw(
'same')
2629 latex.DrawLatexNDC(0.2,0.2,
"Right")
2630 latex.DrawLatexNDC(0.8,0.2,
"Left")
2633 linesV = h[
'linesV']
2634 for bar
in range(systemAndBars[s]):
2635 mufi.GetPosition(s*10000+(p+1)*1000+bar+60,A,B)
2636 topL = ROOT.TVector3(A.X()+barw,A.Y(),0)
2637 botL = ROOT.TVector3(B.X()+barw,B.Y(),0)
2638 topR = ROOT.TVector3(A.X()-barw,A.Y(),0)
2639 botR = ROOT.TVector3(B.X()-barw,B.Y(),0)
2640 linesV.append(ROOT.TLine(topL.X(),topL.Y(),topR.X(),topR.Y()))
2641 linesV.append(ROOT.TLine(topR.X(),topR.Y(),botR.X(),botR.Y()))
2642 linesV.append(ROOT.TLine(botR.X(),botR.Y(),botL.X(),botL.Y()))
2643 linesV.append(ROOT.TLine(botL.X(),botL.Y(),topL.X(),topL.Y()))
2645 if bar%5==0: latex.DrawLatex(topR.X(),topR.Y()+2,barName)
2647 l.SetLineColor(ROOT.kRed)
2671 if readHists: ut.readHists(h,
'MuFilterEff_run'+
str(options.runNumber)+
'.root',withProj=
False)
2673 ut.bookCanvas(h,
'Tracks',
'',900,1600,1,2)
2675 h[
'tracksChi2Ndof'].Draw(
'colz')
2677 h[
'trackslxy'].Draw(
'colz')
2680 a1 = ROOT.RooRealVar(
"alpha",
"alpha", 2, 1e-3, 10.)
2681 p1 = ROOT.RooRealVar(
"n",
"n", 1, 1e-3, 10.)
2683 if local: res =
'res'
2685 for proj
in [
'X',
'Y']:
2687 if proj==
"Y": ut.bookCanvas(h,
'EVetoUS'+proj,
'',1200,2000,2,7)
2688 if proj==
"Y": ut.bookCanvas(h,
'EDS'+proj,
'',1400,2100,2,3)
2690 ut.bookCanvas(h,
'EDS'+proj,
'',1000,2000,2,4)
2691 ut.bookCanvas(h,
'EVeto'+proj,
'',800,400,2,1)
2693 ut.bookCanvas(h,
'EVetoUS'+proj,
'',1200,2000,4,8)
2694 ut.bookCanvas(h,
'EDS'+proj,
'',1200,2000,3,7)
2696 residualsAndSigma = {}
2698 if mode ==
"S" and s==2
and proj==
"X":
continue
2701 if s<3: tname =
'EVetoUS'+proj
2702 else: tname =
'EDS'+proj
2703 for plane
in range(systemAndPlanes[s]):
2704 if mode ==
"S" and s==1
and proj==
"X" and plane<2:
continue
2705 if s==1
and plane==2:
2706 if proj==
"Y":
continue
2707 tname =
'EVeto'+proj
2708 if s==3
and proj==
"X" and (plane%2==0
and plane<5):
continue
2709 if s==3
and proj==
"Y" and (plane%2==1
or plane==6):
continue
2711 key = sy+
str(s*10+plane)
2712 h[
'track_' + key].Draw(
'colz')
2714 for side
in [
'L',
'R',
'S']:
2715 if side==
'S' and (s==3
or mode==
'S') :
continue
2716 if side==
'R' and (mode==
'S') :
continue
2720 hname = res+proj+
'_'+key
2722 hname = res+proj+
'_'+sy+side+
str(s*10+plane)
2723 resH = h[hname].ProjectionX(hname+
'_proj')
2725 if s==3: resH.GetXaxis().SetRangeUser(-4.,4.)
2726 else: resH.GetXaxis().SetRangeUser(-10.,10.)
2728 binw = resH.GetBinWidth(1)
2729 if resH.GetEntries()>10:
2731 x = ROOT.RooRealVar(
"x",
"residual [cm]", -10., 10.)
2732 mu = ROOT.RooRealVar(
"mu",
"mu", resH.GetMean(), resH.GetMean()-1, resH.GetMean()+1)
2733 width = ROOT.RooRealVar(
"width",
"width", resH.GetRMS(), 1e-5, resH.GetRMS()+2)
2734 dcbPdf = ROOT.RooCrystalBall(
"dcbPdf",
"DoubleSidedCB", x, mu, width, a1, p1,
True)
2735 roofit_hist = ROOT.RooDataHist(
"roofit_hist",
"roofit_hist", ROOT.RooArgList(x), ROOT.RooFit.Import(resH))
2736 fitResult = dcbPdf.fitTo(roofit_hist, ROOT.RooFit.PrintLevel(-1), ROOT.RooFit.Save(
True))
2738 roofit_hist.plotOn(pl)
2741 latex.DrawLatexNDC(0.13,0.8,
"#mu = {:.3f} +/- {:.3f}".format(mu.getVal(), mu.getError()))
2742 latex.DrawLatexNDC(0.13,0.7,
"#sigma = {:.3f} +/- {:.3f}".format(width.getVal(), width.getError()))
2744 # changed to CB fit function so commenting the modified Gaussian fit
2745 # Keeping it however since Thomas was able to get resolutions ~ bar_size/sqrt(12) in 2022.
2746 # For the 2024 data that is not the case, so swapped with CB
2747 myGauss = ROOT.TF1('gauss','abs([0])*'+str(binw)+'/(abs([2])*sqrt(2*pi))*exp(-0.5*((x-[1])/[2])**2)+abs([3])',4)
2748 myGauss.SetParameter(0,resH.GetEntries())
2749 myGauss.SetParameter(1,0)
2750 myGauss.SetParameter(2,2.)
2751 rc = resH.Fit(myGauss,'SL','',-15.,15.)
2752 fitResult = rc.Get()
2754 if not (s*10+plane)
in residualsAndSigma:
2755 residualsAndSigma[s*10+plane] = [mu.getVal()/u.mm,mu.getError()/u.mm,abs(width.getVal()/u.cm),width.getError()/u.cm]
2759 stats = resH.FindObject('stats')
2760 stats.SetOptFit(111111)
2761 stats.SetX1NDC(0.63)
2762 stats.SetY1NDC(0.25)
2763 stats.SetX2NDC(0.98)
2764 stats.SetY2NDC(0.94)
2765 tracks = h['track_'+key].GetEntries()
2767 eff = fitResult.Parameter(0)/tracks
2768 effErr = fitResult.ParError(0)/tracks
2769 latex.DrawLatexNDC(0.2,0.8,'eff=%5.2F+/-%5.2F%%'%(eff,effErr))
2771 if 'EVetoUS'+proj
in h:
myPrint(h[
'EVetoUS'+proj],
'EVetoUS'+proj)
2772 if 'EVeto'+proj
in h:
myPrint(h[
'EVeto'+proj],
'EVeto'+proj)
2773 if 'EDS'+proj
in h:
myPrint(h[
'EDS'+proj],
'EDS'+proj)
2775 h[
'gResiduals'], h[
'gSigma'] = ROOT.TGraphErrors(), ROOT.TGraphErrors()
2777 for sp
in residualsAndSigma:
2778 h[
'gResiduals'].SetPoint(k,sp,residualsAndSigma[sp][0])
2779 h[
'gResiduals'].SetPointError(k,0.5,residualsAndSigma[sp][1])
2780 h[
'gSigma'].SetPoint(k,sp,residualsAndSigma[sp][2])
2781 h[
'gSigma'].SetPointError(k,0.5,residualsAndSigma[sp][3])
2783 h[
'gResiduals'].SetLineWidth(2)
2784 h[
'gSigma'].SetLineWidth(2)
2785 ut.bookCanvas(h,
'MufiRes'+proj,
'Mufi residuals',750,750,1,1)
2786 tc = h[
'MufiRes'+proj].cd()
2787 h[
'gResiduals'].SetTitle(
';station; offset [mm]')
2788 h[
'gResiduals'].Draw(
"AP")
2789 ut.bookCanvas(h,
'MufiSigm',
'Mufi sigma',750,750,1,1)
2790 tc = h[
'MufiSigm'].cd()
2791 h[
'gSigma'].SetTitle(
';station; #sigma [cm]')
2792 h[
'gSigma'].Draw(
"AP")
2793 myPrint(h[
'MufiRes'+proj],
'MufiResiduals'+proj)
2794 myPrint(h[
'MufiSigm'],
'MufiSigma'+proj)
2796 ut.bookCanvas(h,
'TVE',
'',800,900,1,nVeto)
2797 ut.bookCanvas(h,
'TUS',
'',800,2000,1,5)
2798 ut.bookCanvas(h,
'TDS',
'',800,1200,1,3)
2799 latex.SetTextColor(ROOT.kRed)
2801 S = {1:
'TVE',2:
'TUS',3:
'TDS'}
2806 for plane
in range(systemAndPlanes[s]):
2807 if s==1
and proj==
"X" and plane<2:
continue
2808 if s==1
and plane==2:
2809 if proj==
"Y":
continue
2810 if s==3
and proj==
"X" and (plane%2==0
and plane<5):
continue
2811 if s==3
and proj==
"Y" and (plane%2==1
or plane==6):
continue
2814 key = sy+
str(s*10+plane)
2815 hist = h[
'dtLRvsX_'+key]
2816 if hist.GetSumOfWeights()==0:
continue
2818 tmp = h[
'track_'+key].ProjectionX()
2819 rc = tmp.Fit(
'gaus',
'S')
2821 fmin = res.Parameter(1) - 3*res.Parameter(2)
2822 fmax = res.Parameter(1) + 3*res.Parameter(2)
2824 xmin = max( hist.GetXaxis().GetBinCenter(1), fmin)
2825 xmax = min( hist.GetXaxis().GetBinCenter(hist.GetNbinsX()), fmax)
2826 hist.GetXaxis().SetRangeUser(xmin,xmax)
2827 hist.GetYaxis().SetRange(1,hist.GetNbinsY())
2828 rc = hist.ProjectionY().Fit(
'gaus',
'S')
2830 ymin = max( hist.GetYaxis().GetBinCenter(1), -5*res.Parameter(2))
2831 ymax = min( hist.GetYaxis().GetBinCenter(hist.GetNbinsY()), 5*res.Parameter(2))
2832 hist.GetYaxis().SetRangeUser(ymin,ymax)
2835 h[
'gdtLRvsX_'+key] = ROOT.TGraph()
2836 g = h[
'gdtLRvsX_'+key]
2837 xproj = hist.ProjectionX(
'tmpx')
2838 if xproj.GetSumOfWeights()==0:
continue
2840 Lmin = hist.GetSumOfWeights() * 0.005
2841 for nx
in range(hist.GetXaxis().FindBin(xmin),hist.GetXaxis().FindBin(xmax)):
2842 tmp = hist.ProjectionY(
'tmp',nx,nx)
2843 if tmp.GetEntries()<Lmin:
continue
2844 X = hist.GetXaxis().GetBinCenter(nx)
2845 rc = tmp.Fit(
'gaus',
'NQS')
2847 if not res: dt = tmp.GetMean()
2848 else: dt = res.Parameter(1)
2851 g.SetLineColor(ROOT.kRed)
2854 rc = g.Fit(
'pol1',
'SQ',
'',xmin,xmax)
2855 g.GetFunction(
'pol1').SetLineColor(ROOT.kGreen)
2856 g.GetFunction(
'pol1').SetLineWidth(2)
2858 if not result:
continue
2859 m = 1./result.Parameter(1)
2860 b = -result.Parameter(0) * m
2863 txt =
'X = %5.1F #frac{cm}{ns} #times #frac{1}{2}#Deltat %s %5.1F '%(m*2,sign,abs(b))
2864 latex.SetTextSize(0.07)
2865 latex.DrawLatexNDC(0.2,0.8,txt)
2866 myPrint(h[
'TVE'],
'dTvsX_Veto')
2871 colors = {1:ROOT.kGreen,2:ROOT.kRed,3:ROOT.kBlue}
2872 ut.bookCanvas(h,
'relT',
'',800,1000,1,7)
2873 for s
in systemAndPlanes:
2874 for plane
in range(systemAndPlanes[s]):
2875 hname =
'atLRvsX_'+sdict[s]+
str(s*10+plane)
2876 h[hname+
'_proj'] = h[hname].ProjectionY(hname+
'_proj')
2877 h[hname+
'_proj'].SetLineColor(colors[s])
2878 h[hname+
'_proj'].SetStats(0)
2879 h[hname+
'_proj'].SetTitle(
'; #Deltat [ns]')
2880 if s==1
and plane == 0: h[hname+
'_proj'] .Draw()
2881 else: h[hname+
'_proj'] .Draw(
'same')
2885 ut.bookCanvas(h,
'veto',
'',800,1600,1,7)
2887 for plane
in range(systemAndPlanes[s]):
2888 if plane<2: hname =
'resBarY_'+sdict[s]+
str(s*10+plane)
2889 elif plane==2: hname =
'resBarX_'+sdict[s]+
str(s*10+plane)
2890 for nbar
in range(1,h[hname].GetNbinsY()+1):
2891 vname =
'veto'+
str(s*10+plane)+
'_'+
str(nbar)
2892 h[vname] = h[hname].ProjectionX(vname,nbar+1,nbar+1)
2893 binw = h[vname].GetBinWidth(1)
2894 myGauss = ROOT.TF1(
'gauss',
'abs([0])*'+
str(binw)+
'/(abs([2])*sqrt(2*pi))*exp(-0.5*((x-[1])/[2])**2)+abs([3])',4)
2895 myGauss.SetParameter(0,resH.GetEntries())
2896 myGauss.SetParameter(1,0)
2897 myGauss.SetParameter(2,2.)
2898 rc = h[vname].Fit(myGauss,
'SL',
'',-15.,15.)
2899 fitResult = rc.Get()
3420def Scifi_residuals(Nev=options.nEvents,NbinsRes=100,xmin=-2000.,alignPar=False,unbiased = True,minEnergy=False,remakeClusters=options.remakeScifiClusters,nproc=1):
3421 projs = {1:
'V',0:
'H'}
3422 scifi = geo.modules[
'Scifi']
3423 nScifi = scifi.GetConfParI(
"Scifi/nscifi")
3424 nMats = scifi.GetConfParI(
"Scifi/nmats")
3426 for s
in range(1, nScifi+1):
3431 ut.bookHist(h,
'res'+proj+
'_Scifi'+
str(s*10+o),
'residual '+proj+
str(s*10+o)+
'; [#mum]',NbinsRes,xmin,xmax)
3432 ut.bookHist(h,
'resX'+proj+
'_Scifi'+
str(s*10+o),
'residual '+proj+
str(s*10+o)+
'; [#mum]',NbinsRes,xmin,xmax,100,-50.,0.)
3433 ut.bookHist(h,
'resY'+proj+
'_Scifi'+
str(s*10+o),
'residual '+proj+
str(s*10+o)+
'; [#mum]',NbinsRes,xmin,xmax,100,10.,60.)
3434 ut.bookHist(h,
'resC'+proj+
'_Scifi'+
str(s*10+o),
'residual '+proj+
str(s*10+o)+
'; [#mum]',NbinsRes,xmin,xmax,128*4*nMats+10,-0.5,128*4*nMats-0.5+10)
3435 ut.bookHist(h,
'track_Scifi'+
str(s*10+o),
'track x/y '+
str(s*10+o),80,-70.,10.,80,0.,80.)
3436 ut.bookHist(h,
'trackChi2/ndof',
'track chi2/ndof vs ndof',100,0,100,20,0,20)
3437 ut.bookHist(h,
'trackSlopes',
'track slope; x [mrad]; y [mrad]',1000,-100,100,1000,-100,100)
3438 parallelToZ = ROOT.TVector3(0., 0., 1.)
3440 if Nev < 0 : Nev = eventTree.GetEntries()
3444 if not x.find(
'Rot')>0:
3450 for iproc
in range(nproc):
3452 if nproc>1: pid = os.fork()
3455 print(
"Could not create a child process")
3462 if iproc==(nproc-1): nstop = Nev
3463 for k
in range(nstart,nstop):
3465 eventTree.GetEvent(k)
3467 trackTypes = [0,0,0,0,0]
3468 for aTrack
in Reco_MuonTracks:
3469 if aTrack.GetUniqueID()==1:
3471 fstate = aTrack.getFittedState()
3472 mom = fstate.getMom()
3473 if abs(mom.X()/mom.Z())<0.1:
3476 for i
in range(30,40): mult[i]=0
3477 for aHit
in eventTree.Digi_MuFilterHits:
3478 if not aHit.isValid():
continue
3479 detID = aHit.GetDetectorID()
3482 l = (detID%10000)//1000
3490 if mult[35]==1
and mult[34]==1: trackTypes[4]+=1
3492 if aTrack.GetUniqueID()==3: trackTypes[3]+=1
3493 if not (trackTypes[4]==1):
continue
3496 if event.GetBranch(
"Reco_MuonTracks"):
3497 for aTrack
in event.Reco_MuonTracks: aTrack.Delete()
3499 if not hasattr(event,
"Cluster_Scifi")
or alignPar
or remakeClusters:
3500 if hasattr(trackTask,
"clusScifi"):
3501 trackTask.clusScifi.Clear()
3502 trackTask.scifiCluster()
3503 clusters = trackTask.clusScifi
3505 clusters = event.Cluster_Scifi
3508 for aCl
in clusters:
3509 so = aCl.GetFirst()//100000
3510 if not so
in sortedClusters: sortedClusters[so]=[]
3511 sortedClusters[so].append(aCl)
3514 if len(sortedClusters)<2*nScifi:
continue
3516 for s
in sortedClusters:
3517 if len(sortedClusters[s])>1: goodEvent=
False
3518 if not goodEvent:
continue
3520 for s
in range(1, nScifi+1):
3523 if unbiased
or s==1:
3525 for so
in sortedClusters:
3526 if so//10 == s
and unbiased:
continue
3527 for x
in sortedClusters[so]:
3530 theTrack = trackTask.fitTrack(hitlist)
3531 if not hasattr(theTrack,
"getFittedState"):
3534 fitStatus = theTrack.getFitStatus()
3535 if not fitStatus.isFitConverged()
or theTrack.getNumPointsWithMeasurement()<2*(nScifi-1):
3539 rc = h[
'trackChi2/ndof'].Fill(fitStatus.getChi2()/(fitStatus.getNdf()+1E-10),fitStatus.getNdf() )
3540 fstate = theTrack.getFittedState()
3541 mom = fstate.getMom()
3542 rc = h[
'trackSlopes'].Fill(mom.X()/mom.Z()*1000,mom.Y()/mom.Z()*1000)
3544 if not validTrack
and not unbiased:
break
3548 z = zPos[
'Scifi'][testPlane]
3549 rep = ROOT.genfit.RKTrackRep(13)
3550 state = ROOT.genfit.StateOnPlane(rep)
3554 for m
in range(0,theTrack.getNumPointsWithMeasurement()):
3555 st = theTrack.getFittedState(m)
3557 if abs(z-Pos.z())<mZmin:
3558 mZmin = abs(z-Pos.z())
3561 print(
"something wrong here with measurements",mClose,mZmin,theTrack.getNumPointsWithMeasurement())
3563 fstate = theTrack.getFittedState(mClose)
3564 pos,mom = fstate.getPos(),fstate.getMom()
3565 rep.setPosMom(state,pos,mom)
3566 NewPosition = ROOT.TVector3(0., 0., z)
3567 rep.extrapolateToPlane(state, NewPosition, parallelToZ )
3568 pos = state.getPos()
3569 xEx,yEx = pos.x(),pos.y()
3570 rc = h[
'track_Scifi'+
str(testPlane)].Fill(xEx,yEx)
3571 for aCl
in sortedClusters[testPlane]:
3572 aCl.GetPosition(A,B)
3573 detID = aCl.GetFirst()
3574 channel = detID%1000 + ((detID%10000)//1000)*128 + (detID%100000//10000)*512
3577 uCrossv= (B-A).Cross(mom)
3578 doca = pq.Dot(uCrossv)/uCrossv.Mag()
3579 rc = h[
'resC'+projs[o]+
'_Scifi'+
str(testPlane)].Fill(doca/u.um,channel)
3580 rc = h[
'res'+projs[o]+
'_Scifi'+
str(testPlane)].Fill(doca/u.um)
3581 rc = h[
'resX'+projs[o]+
'_Scifi'+
str(testPlane)].Fill(doca/u.um,xEx)
3582 rc = h[
'resY'+projs[o]+
'_Scifi'+
str(testPlane)].Fill(doca/u.um,yEx)
3584 if unbiased: theTrack.Delete()
3585 if not unbiased
and validTrack: theTrack.Delete()
3588 ut.writeHists(h,
'tmp_'+
str(iproc))
3593 pid,exit_code = os.wait()
3594 if pid == 0: time.sleep(100)
3597 for i
in range(nproc):
3598 ut.readHists(h,
'tmp_'+
str(i))
3601 P = {
'':
'',
'X':
'colz',
'Y':
'colz',
'C':
'colz'}
3602 h[
'globalPos'] = {
'meanH':ROOT.TGraphErrors(),
'sigmaH':ROOT.TGraphErrors(),
'meanV':ROOT.TGraphErrors(),
'sigmaV':ROOT.TGraphErrors()}
3603 h[
'globalPosM'] = {
'meanH':ROOT.TGraphErrors(),
'sigmaH':ROOT.TGraphErrors(),
'meanV':ROOT.TGraphErrors(),
'sigmaV':ROOT.TGraphErrors()}
3604 globalPos = h[
'globalPos']
3606 x = ROOT.RooRealVar(
"x",
"residual [cm]", xmin, xmax)
3607 a1 = ROOT.RooRealVar(
"alpha",
"alpha", 2, 1e-3, 10.)
3608 p1 = ROOT.RooRealVar(
"n",
"n", 1, 1e-3, 10.)
3610 ut.bookCanvas(h,
'scifiRes'+proj,
'',1600,1900,2,5)
3613 for s
in range(1, nScifi+1):
3616 tc = h[
'scifiRes'+proj].cd(k)
3618 hname =
'res'+proj+projs[o]+
'_Scifi'+
str(so)
3619 h[hname].Draw(P[proj])
3622 mu = ROOT.RooRealVar(
"mu",
"mu", h[hname].GetMean(), h[hname].GetMean()-200, h[hname].GetMean()+200)
3623 width = ROOT.RooRealVar(
"width",
"width", h[hname].GetRMS(), 1e-5, h[hname].GetRMS()+1e+3)
3624 Par = {
'mean':mu,
'sigma':width}
3625 dcbPdf = ROOT.RooCrystalBall(
"dcbPdf",
"DoubleSidedCB", x, mu, width, a1, p1,
True)
3626 roofit_hist = ROOT.RooDataHist(
"roofit_hist",
"roofit_hist", ROOT.RooArgList(x), ROOT.RooFit.Import(h[hname]))
3627 fitResult = dcbPdf.fitTo(roofit_hist, ROOT.RooFit.PrintLevel(-1), ROOT.RooFit.Save(
True))
3629 roofit_hist.plotOn(pl)
3632 latex.DrawLatexNDC(0.13,0.8,
"#mu = {:.3f} +/- {:.3f}".format(mu.getVal(), mu.getError()))
3633 latex.DrawLatexNDC(0.13,0.7,
"#sigma = {:.3f} +/- {:.3f}".format(width.getVal(), width.getError()))
3636 globalPos[p+projs[o]].SetPoint(s-1,s,Par[p].getVal())
3637 globalPos[p+projs[o]].SetPointError(s-1,0.5,Par[p].getError())
3638 globalPos[p+projs[o]].SetMarkerStyle(21)
3639 globalPos[p+projs[o]].SetMarkerColor(ROOT.kBlue)
3641 for m
in range(nMats):
3642 h[hname+
str(m)] = h[hname].ProjectionX(hname+
str(m),m*512,m*512+512)
3643 mu = ROOT.RooRealVar(
"mu",
"residual [cm]", h[hname+
str(m)].GetMean(), h[hname+
str(m)].GetMean()-200, h[hname+
str(m)].GetMean()+200)
3644 width = ROOT.RooRealVar(
"width",
"width", h[hname+
str(m)].GetRMS(), 1e-5, h[hname+
str(m)].GetRMS()+1e+3)
3645 dcbPdf = ROOT.RooCrystalBall(
"dcbPdf",
"DoubleSidedCB", x, mu, width, a1, p1,
True)
3646 roofit_hist = ROOT.RooDataHist(
"roofit_hist",
"roofit_hist", ROOT.RooArgList(x), ROOT.RooFit.Import(h[hname+
str(m)]))
3647 fitResult = dcbPdf.fitTo(roofit_hist, ROOT.RooFit.PrintLevel(-1), ROOT.RooFit.Save(
True))
3648 if not fitResult:
continue
3650 roofit_hist.plotOn(pl)
3654 h[
'globalPosM'][p+projs[o]].SetPoint(j[o], s*10+m,Par[p].getVal())
3655 h[
'globalPosM'][p+projs[o]].SetPointError(j[o],0.5,Par[p].getError())
3657 h[
'globalPosM'][p+projs[o]].SetMarkerStyle(21)
3658 h[
'globalPosM'][p+projs[o]].SetMarkerColor(ROOT.kBlue)
3660 S = ctypes.c_double()
3661 M = ctypes.c_double()
3664 ut.bookCanvas(h,p,p,750,750,1,1)
3666 if p.find(
'mean')<0: globalPos[p].SetTitle(p+
';station; #sigma [#mum]')
3667 else: globalPos[p].SetTitle(p+
';station; offset [#mum]')
3668 globalPos[p].Draw(
"ALP")
3669 if p.find(
'mean')==0:
3670 for n
in range(globalPos[p].GetN()):
3671 rc = globalPos[p].GetPoint(n,S,M)
3672 E = globalPos[p].GetErrorY(n)
3673 print(
"station %i: offset %s = %5.2F um sigma = %5.2F um"%(S.value,p[4:5],M.value,E))
3675 if p[4:5] ==
"V": s+=1
3676 alignResult[
"Scifi/LocD"+
str(s)] = [M.value,E]
3678 for p
in h[
'globalPosM']:
3679 ut.bookCanvas(h,p+
'M',p,750,750,1,1)
3681 if p.find(
'mean')<0: h[
'globalPosM'][p].SetTitle(p+
';mat ; #sigma [#mum]')
3682 else: h[
'globalPosM'][p].SetTitle(p+
';mat ; offset [#mum]')
3683 h[
'globalPosM'][p].Draw(
"ALP")
3684 if p.find(
'mean')==0:
3685 for n
in range(h[
'globalPosM'][p].GetN()):
3686 rc = h[
'globalPosM'][p].GetPoint(n,S,M)
3687 E = h[
'globalPosM'][p].GetErrorY(n)
3688 print(
"station %i: offset %s = %5.2F um sigma = %5.2F um"%(S.value,p[4:5],M.value,E))
3690 if p[4:5] ==
"V": s+=1
3691 alignResult[
"Scifi/LocM"+
str(s)] = [M.value,E]