561 n_tracks_stereo12 = 0
562 n_recognized_stereo12 = 0
563 n_clones_stereo12 = 0
564 n_ghosts_stereo12 = 0
565 n_others_stereo12 = 0
573 true_track_ids_y12 = []
574 true_track_ids_stereo12 = []
575 true_track_ids_34 = []
577 n_true_track_hits_y12 = {}
578 n_true_track_hits_stereo12 = {}
579 n_true_track_hits_34 = {}
581 n_true_track_hits_1 = {}
582 n_true_track_hits_2 = {}
583 n_true_track_hits_3 = {}
584 n_true_track_hits_4 = {}
586 for ahit
in self.
sTree.MufluxSpectrometerPoint:
588 track_id = ahit.GetTrackID()
590 detID = ahit.GetDetectorID()
591 statnb = detID // 10000000
592 vnb = (detID - statnb * 10000000) // 1000000
594 is_y12 = (statnb == 1) * (vnb == 0) + (statnb == 2) * (vnb == 1)
595 is_stereo12 = (statnb == 1) * (vnb == 1) + (statnb == 2) * (vnb == 0)
596 is_34 = (statnb == 3) + (statnb == 4)
599 if track_id
in n_true_track_hits_1:
600 n_true_track_hits_1[track_id] += 1
602 n_true_track_hits_1[track_id] = 1
605 if track_id
in n_true_track_hits_2:
606 n_true_track_hits_2[track_id] += 1
608 n_true_track_hits_2[track_id] = 1
611 if track_id
in n_true_track_hits_3:
612 n_true_track_hits_3[track_id] += 1
614 n_true_track_hits_3[track_id] = 1
617 if track_id
in n_true_track_hits_4:
618 n_true_track_hits_4[track_id] += 1
620 n_true_track_hits_4[track_id] = 1
623 if track_id
in n_true_track_hits_y12:
624 n_true_track_hits_y12[track_id] += 1
626 n_true_track_hits_y12[track_id] = 1
629 if track_id
in n_true_track_hits_stereo12:
630 n_true_track_hits_stereo12[track_id] += 1
632 n_true_track_hits_stereo12[track_id] = 1
635 if track_id
in n_true_track_hits_34:
636 n_true_track_hits_34[track_id] += 1
638 n_true_track_hits_34[track_id] = 1
643 elif mode ==
'3hits':
646 if mode ==
'all' or mode ==
'3hits':
647 for key
in n_true_track_hits_y12.keys():
648 if n_true_track_hits_y12[key] >= min_hits:
649 true_track_ids_y12.append(key)
651 for key
in n_true_track_hits_stereo12.keys():
652 if n_true_track_hits_stereo12[key] >= min_hits:
653 true_track_ids_stereo12.append(key)
655 for key
in n_true_track_hits_34.keys():
656 if n_true_track_hits_34[key] >= min_hits:
657 true_track_ids_34.append(key)
661 for key
in n_true_track_hits_y12.keys():
662 if key
in n_true_track_hits_1
and key
in n_true_track_hits_2:
663 if key
in n_true_track_hits_3
and key
in n_true_track_hits_4:
664 if n_true_track_hits_y12[key] >= min_hits:
665 true_track_ids_y12.append(key)
667 for key
in n_true_track_hits_stereo12.keys():
668 if key
in n_true_track_hits_1
and key
in n_true_track_hits_2:
669 if key
in n_true_track_hits_3
and key
in n_true_track_hits_4:
670 if n_true_track_hits_stereo12[key] >= min_hits:
671 true_track_ids_stereo12.append(key)
673 for key
in n_true_track_hits_34.keys():
674 if key
in n_true_track_hits_1
and key
in n_true_track_hits_2:
675 if key
in n_true_track_hits_3
and key
in n_true_track_hits_4:
676 if n_true_track_hits_34[key] >= min_hits:
677 true_track_ids_34.append(key)
681 n_tracks_y12 = len(true_track_ids_y12)
682 n_tracks_stereo12 = len(true_track_ids_stereo12)
683 n_tracks_34 = len(true_track_ids_34)
685 found_track_ids_y12 = []
686 found_track_ids_stereo12 = []
687 found_track_ids_34 = []
689 for i_track
in track_hit_ids.keys():
691 atrack = track_hit_ids[i_track]
692 atrack_y12 = atrack[
'y12']
693 atrack_stereo12 = atrack[
'stereo12']
694 atrack_34 = atrack[
'34']
695 atrack_y_tagger = atrack[
'y_tagger']
697 if len(atrack_y12) > 0:
698 reco_hit_ids_y12 = []
699 for i_hit
in atrack_y12:
700 ahit = self.
sTree.MufluxSpectrometerPoint[i_hit[
'digiHit']]
701 reco_hit_ids_y12.append(ahit.GetTrackID())
702 frac_y12, tmax_y12 = self.
fracMCsame(reco_hit_ids_y12)
704 if tmax_y12
in true_track_ids_y12
and tmax_y12
not in found_track_ids_y12:
705 n_recognized_y12 += 1
706 found_track_ids_y12.append(tmax_y12)
707 elif tmax_y12
in true_track_ids_y12
and tmax_y12
in found_track_ids_y12:
709 elif tmax_y12
not in true_track_ids_y12:
715 if len(atrack_stereo12) > 0:
716 reco_hit_ids_stereo12 = []
717 for i_hit
in atrack_stereo12:
718 ahit = self.
sTree.MufluxSpectrometerPoint[i_hit[
'digiHit']]
719 reco_hit_ids_stereo12.append(ahit.GetTrackID())
720 frac_stereo12, tmax_stereo12 = self.
fracMCsame(reco_hit_ids_stereo12)
721 if frac_stereo12 >= 0.7:
722 if tmax_stereo12
in true_track_ids_stereo12
and tmax_stereo12
not in found_track_ids_stereo12:
723 n_recognized_stereo12 += 1
724 found_track_ids_stereo12.append(tmax_stereo12)
725 elif tmax_stereo12
in true_track_ids_stereo12
and tmax_stereo12
in found_track_ids_stereo12:
726 n_clones_stereo12 += 1
727 elif tmax_stereo12
not in true_track_ids_stereo12:
728 n_others_stereo12 += 1
730 n_ghosts_stereo12 += 1
733 if len(atrack_34) > 0:
735 for i_hit
in atrack_34:
736 ahit = self.
sTree.MufluxSpectrometerPoint[i_hit[
'digiHit']]
737 reco_hit_ids_34.append(ahit.GetTrackID())
738 frac_34, tmax_34 = self.
fracMCsame(reco_hit_ids_34)
740 if tmax_34
in true_track_ids_34
and tmax_34
not in found_track_ids_34:
742 found_track_ids_34.append(tmax_34)
743 elif tmax_34
in true_track_ids_34
and tmax_34
in found_track_ids_34:
745 elif tmax_34
not in true_track_ids_34:
750 output = (n_tracks_y12, n_recognized_y12, n_clones_y12, n_ghosts_y12, n_others_y12,
751 n_tracks_stereo12, n_recognized_stereo12, n_clones_stereo12, n_ghosts_stereo12, n_others_stereo12,
752 n_tracks_34, n_recognized_34, n_clones_34, n_ghosts_34, n_others_34)
1182 hitPosLists_noT4 = {}
1184 stationCrossed_noT4 = {}
1186 trackDigiHits_noT4 = {}
1188 trackMomentums_noT4 = {}
1189 trackCandidates = []
1190 trackCandidates_noT4 = []
1191 trackCandidates_all = []
1198 if self.
sTree.GetBranch(
"MufluxSpectrometerPoint"):
1199 if global_variables.withT0:
1205 elif self.
sTree.GetBranch(
"Digi_MufluxSpectrometerHits"):
1209 print(
'No branches "MufluxSpectrometer" or "Digi_MufluxSpectrometerHits".')
1212 if global_variables.realPR:
1218 for i_track
in track_hits.keys():
1220 atrack = track_hits[i_track]
1221 atrack_y12 = atrack[
'y12']
1222 atrack_stereo12 = atrack[
'stereo12']
1223 atrack_34 = atrack[
'34']
1224 atrack_smeared_hits = list(atrack_y12) + list(atrack_stereo12) + list(atrack_34)
1225 atrack_p = np.abs(atrack[
'p'])
1226 atrack_y_in_magnet = atrack[
'y_in_magnet']
1227 atrack_x_in_magnet = atrack[
'x_in_magnet']
1229 for sm
in atrack_smeared_hits:
1233 station = int(detID/10000000)
1237 if trID
not in hitPosLists:
1238 hitPosLists[trID] = ROOT.std.vector(
'TVectorD')()
1239 stationCrossed[trID] = {}
1240 trackDigiHits[trID] = []
1241 trackMomentums[trID] = atrack_p
1242 m = array(
'd',[sm[
'xtop'],sm[
'ytop'],sm[
'z'],sm[
'xbot'],sm[
'ybot'],sm[
'z'],sm[
'dist']])
1243 hitPosLists[trID].push_back(ROOT.TVectorD(7,m))
1244 if station
not in stationCrossed[trID]:
1245 stationCrossed[trID][station]=0
1246 stationCrossed[trID][station]+=1
1247 trackDigiHits[trID].append(sm[
'digiHit'])
1250 if (int(detID/1000000)!=40):
1251 if trID
not in hitPosLists_noT4:
1252 hitPosLists_noT4[trID] = ROOT.std.vector(
'TVectorD')()
1253 stationCrossed_noT4[trID] = {}
1254 trackDigiHits_noT4[trID] = []
1255 trackMomentums_noT4[trID] = atrack_p
1256 m_noT4 = array(
'd',[sm[
'xtop'],sm[
'ytop'],sm[
'z'],sm[
'xbot'],sm[
'ybot'],sm[
'z'],sm[
'dist']])
1257 hitPosLists_noT4[trID].push_back(ROOT.TVectorD(7,m_noT4))
1258 if station
not in stationCrossed_noT4[trID]:
1259 stationCrossed_noT4[trID][station]=0
1260 stationCrossed_noT4[trID][station]+=1
1261 trackDigiHits_noT4[trID].append(sm[
'digiHit'])
1266 if not self.
sTree.GetBranch(
"MufluxSpectrometerPoint"):
1267 print(
'Fake PatRec is impossible. No "MufluxSpectrometerPoint" branch.')
1275 station = int(detID/10000000)
1276 vnb = (detID - station * 10000000) // 1000000
1277 is_y12 = (station == 1) * (vnb == 0) + (station == 2) * (vnb == 1)
1278 is_stereo12 = (station == 1) * (vnb == 1) + (station == 2) * (vnb == 0)
1279 is_34 = (station == 3) + (station == 4)
1281 trID = self.
sTree.MufluxSpectrometerPoint[sm[
'digiHit']].GetTrackID()
1284 if trID
not in track_hits:
1285 atrack = {
'y12': [],
'stereo12': [],
'34': []}
1286 track_hits[trID] = atrack
1288 track_hits[trID][
'y12'].append(sm)
1290 track_hits[trID][
'stereo12'].append(sm)
1292 track_hits[trID][
'34'].append(sm)
1295 if trID
not in hitPosLists:
1296 hitPosLists[trID] = ROOT.std.vector(
'TVectorD')()
1297 stationCrossed[trID] = {}
1298 trackDigiHits[trID] = []
1299 trackMomentums[trID] = 3.
1300 m = array(
'd',[sm[
'xtop'],sm[
'ytop'],sm[
'z'],sm[
'xbot'],sm[
'ybot'],sm[
'z'],sm[
'dist']])
1301 hitPosLists[trID].push_back(ROOT.TVectorD(7,m))
1302 if station
not in stationCrossed[trID]:
1303 stationCrossed[trID][station]=0
1304 stationCrossed[trID][station]+=1
1305 trackDigiHits[trID].append(sm[
'digiHit'])
1308 if (int(detID/1000000)!=40):
1309 if trID
not in hitPosLists_noT4:
1310 hitPosLists_noT4[trID] = ROOT.std.vector(
'TVectorD')()
1311 stationCrossed_noT4[trID] = {}
1312 trackDigiHits_noT4[trID] = []
1313 trackMomentums_noT4[trID] = 3.
1314 m_noT4 = array(
'd',[sm[
'xtop'],sm[
'ytop'],sm[
'z'],sm[
'xbot'],sm[
'ybot'],sm[
'z'],sm[
'dist']])
1315 hitPosLists_noT4[trID].push_back(ROOT.TVectorD(7,m_noT4))
1316 if station
not in stationCrossed_noT4[trID]:
1317 stationCrossed_noT4[trID][station]=0
1318 stationCrossed_noT4[trID][station]+=1
1319 trackDigiHits_noT4[trID].append(sm[
'digiHit'])
1323 for atrack
in hitPosLists:
1328 if not abs(pdg)==13:
1331 meas = hitPosLists[atrack]
1332 mom_init = trackMomentums[atrack]
1340 charge = self.
PDG.GetParticle(pdg).Charge()/(3.)
1341 posM = ROOT.TVector3(0, 0, 0)
1342 momM = ROOT.TVector3(0,0,mom_init * u.GeV)
1344 covM = ROOT.TMatrixDSym(6)
1346 if global_variables.withT0:
1347 resolution = resolution*1.4
1349 covM[i][i] = resolution*resolution
1350 covM[0][0]=resolution*resolution*100.
1351 for i
in range(3,6):
1352 covM[i][i] = ROOT.TMath.Power(resolution / nM / ROOT.TMath.Sqrt(3), 2)
1354 rep = ROOT.genfit.RKTrackRep(pdg)
1356 stateSmeared = ROOT.genfit.MeasuredStateOnPlane(rep)
1357 rep.setPosMomCov(stateSmeared, posM, momM, covM)
1359 seedState = ROOT.TVectorD(6)
1360 seedCov = ROOT.TMatrixDSym(6)
1361 rep.get6DStateCov(stateSmeared, seedState, seedCov)
1362 theTrack = ROOT.genfit.Track(rep, seedState, seedCov)
1363 hitCov = ROOT.TMatrixDSym(7)
1364 hitCov[6][6] = resolution*resolution
1366 tp = ROOT.genfit.TrackPoint(theTrack)
1367 measurement = ROOT.genfit.WireMeasurement(m,hitCov,1,6,tp)
1368 measurement.setMaxDistance(1.85*u.cm)
1370 tp.addRawMeasurement(measurement)
1371 theTrack.insertPoint(tp)
1372 trackCandidates_all.append([theTrack,atrack])
1376 for atrack
in hitPosLists:
1381 if not abs(pdg)==13:
1384 meas = hitPosLists[atrack]
1385 mom_init = trackMomentums[atrack]
1390 if len(stationCrossed[atrack]) < 4 :
1393 charge = self.
PDG.GetParticle(pdg).Charge()/(3.)
1394 posM = ROOT.TVector3(0, 0, 0)
1395 momM = ROOT.TVector3(0,0,mom_init * u.GeV)
1397 covM = ROOT.TMatrixDSym(6)
1399 if global_variables.withT0:
1400 resolution = resolution*1.4
1402 covM[i][i] = resolution*resolution
1403 covM[0][0]=resolution*resolution*100.
1404 for i
in range(3,6):
1405 covM[i][i] = ROOT.TMath.Power(resolution / nM / ROOT.TMath.Sqrt(3), 2)
1407 rep = ROOT.genfit.RKTrackRep(pdg)
1409 stateSmeared = ROOT.genfit.MeasuredStateOnPlane(rep)
1410 rep.setPosMomCov(stateSmeared, posM, momM, covM)
1412 seedState = ROOT.TVectorD(6)
1413 seedCov = ROOT.TMatrixDSym(6)
1414 rep.get6DStateCov(stateSmeared, seedState, seedCov)
1415 theTrack = ROOT.genfit.Track(rep, seedState, seedCov)
1416 hitCov = ROOT.TMatrixDSym(7)
1417 hitCov[6][6] = resolution*resolution
1419 tp = ROOT.genfit.TrackPoint(theTrack)
1420 measurement = ROOT.genfit.WireMeasurement(m,hitCov,1,6,tp)
1421 measurement.setMaxDistance(1.85*u.cm)
1423 tp.addRawMeasurement(measurement)
1424 theTrack.insertPoint(tp)
1425 trackCandidates.append([theTrack,atrack])
1428 for atrack
in hitPosLists_noT4:
1433 if not abs(pdg)==13:
1435 meas = hitPosLists_noT4[atrack]
1436 mom_init = trackMomentums_noT4[atrack]
1441 if len(stationCrossed[atrack]) < 3 :
1444 charge = self.
PDG.GetParticle(pdg).Charge()/(3.)
1445 posM = ROOT.TVector3(0, 0, 0)
1446 momM = ROOT.TVector3(0,0,mom_init * u.GeV)
1448 covM = ROOT.TMatrixDSym(6)
1450 if global_variables.withT0:
1451 resolution = resolution*1.4
1453 covM[i][i] = resolution*resolution
1454 covM[0][0]=resolution*resolution*100.
1455 for i
in range(3,6):
1456 covM[i][i] = ROOT.TMath.Power(resolution / nM / ROOT.TMath.Sqrt(3), 2)
1458 rep = ROOT.genfit.RKTrackRep(pdg)
1460 stateSmeared = ROOT.genfit.MeasuredStateOnPlane(rep)
1461 rep.setPosMomCov(stateSmeared, posM, momM, covM)
1463 seedState = ROOT.TVectorD(6)
1464 seedCov = ROOT.TMatrixDSym(6)
1465 rep.get6DStateCov(stateSmeared, seedState, seedCov)
1466 theTrack = ROOT.genfit.Track(rep, seedState, seedCov)
1467 hitCov = ROOT.TMatrixDSym(7)
1468 hitCov[6][6] = resolution*resolution
1470 tp = ROOT.genfit.TrackPoint(theTrack)
1471 measurement = ROOT.genfit.WireMeasurement(m,hitCov,1,6,tp)
1472 measurement.setMaxDistance(1.85*u.cm)
1474 tp.addRawMeasurement(measurement)
1475 theTrack.insertPoint(tp)
1476 trackCandidates_noT4.append([theTrack,atrack])
1478 if global_variables.debug:
1483 detID = ahit[
'detID']
1484 station = int(detID/10000000)
1485 vnb = (detID - station * 10000000) // 1000000
1486 is_y12 = (station == 1) * (vnb == 0) + (station == 2) * (vnb == 1)
1487 is_stereo12 = (station == 1) * (vnb == 1) + (station == 2) * (vnb == 0)
1488 is_34 = (station == 3) + (station == 4)
1490 z_hits_y.append(ahit[
'z'])
1491 x_hits_y.append(ahit[
'xtop'])
1492 plt.figure(figsize=(22, 6))
1493 plt.subplot(1, 2, 1)
1494 plt.scatter(z_hits_y, x_hits_y, color=
'b')
1496 z_tagger_hits_y = []
1497 x_tagger_hits_y = []
1499 detID = ahit[
'detID']
1500 station = detID // 10000
1501 direction = (detID - station * 10000) // 1000
1502 if direction == 1
or detID < 10:
1503 z_tagger_hits_y.append(ahit[
'z'])
1504 x_tagger_hits_y.append((ahit[
'xtop'] + ahit[
'xbot']) / 2.)
1505 plt.scatter(z_tagger_hits_y, x_tagger_hits_y, color=
'b')
1507 for i_track
in track_hits:
1508 atrack = track_hits[i_track]
1509 atrack_y12 = atrack[
'y12']
1510 atrack_stereo12 = atrack[
'stereo12']
1511 atrack_34 = atrack[
'34']
1512 atrack_tagger = atrack[
'y_tagger']
1513 atrack_y = list(atrack_y12) + list(atrack_34) + list(atrack_tagger)
1514 z_atrack_y = [ahit[
'z']
for ahit
in atrack_y]
1515 x_atrack_y = [ahit[
'xtop']
for ahit
in atrack_y]
1516 plt.scatter(z_atrack_y, x_atrack_y, color=np.random.rand(3,))
1524 plt.subplot(1, 2, 2)
1526 detID = ahit[
'detID']
1527 station = int(detID/10000000)
1528 vnb = (detID - station * 10000000) // 1000000
1529 is_y12 = (station == 1) * (vnb == 0) + (station == 2) * (vnb == 1)
1530 is_stereo12 = (station == 1) * (vnb == 1) + (station == 2) * (vnb == 0)
1531 is_34 = (station == 3) + (station == 4)
1532 if is_y12
or is_stereo12:
1533 xbot, xtop = ahit[
'xbot'], ahit[
'xtop']
1534 ybot, ytop = ahit[
'ybot'], ahit[
'ytop']
1535 plt.plot([ybot, ytop], [xbot, xtop], color=
'b')
1537 for i_track
in track_hits:
1538 atrack = track_hits[i_track]
1539 atrack_y12 = atrack[
'y12']
1540 atrack_stereo12 = atrack[
'stereo12']
1541 atrack_34 = atrack[
'34']
1542 atrack_tagger = atrack[
'y_tagger']
1543 atrack_12 = list(atrack_y12) + list(atrack_stereo12)
1544 color = np.random.rand(3,)
1545 for ahit
in atrack_12:
1546 xbot, xtop = ahit[
'xbot'], ahit[
'xtop']
1547 ybot, ytop = ahit[
'ybot'], ahit[
'ytop']
1548 plt.plot([ybot, ytop], [xbot, xtop], color=color)
1555 plt.savefig(
'pics/event_'+str(self.
iEvent)+
'.pdf', format=
'pdf', bbox_inches=
'tight')
1564 if self.
sTree.GetBranch(
"MufluxSpectrometerPoint"):
1567 (n_tracks, n_recognized, n_clones, n_ghosts, n_others) = self.
target_metrics(track_hits)
1568 h[
'Reco_target'].Fill(
"N total", n_tracks)
1569 h[
'Reco_target'].Fill(
"N recognized tracks", n_recognized)
1570 h[
'Reco_target'].Fill(
"N clones", n_clones)
1571 h[
'Reco_target'].Fill(
"N ghosts", n_ghosts)
1572 h[
'Reco_target'].Fill(
"N others", n_others)
1574 (n_tracks, n_recognized, n_clones, n_ghosts, n_others) = self.
muon_metrics(track_hits)
1575 h[
'Reco_muon'].Fill(
"N total", n_tracks)
1576 h[
'Reco_muon'].Fill(
"N recognized tracks", n_recognized)
1577 h[
'Reco_muon'].Fill(
"N clones", n_clones)
1578 h[
'Reco_muon'].Fill(
"N ghosts", n_ghosts)
1579 h[
'Reco_muon'].Fill(
"N others", n_others)
1582 h[
'Reco_muon_with_tagger'].Fill(
"N total", n_tracks)
1583 h[
'Reco_muon_with_tagger'].Fill(
"N recognized tracks", n_recognized)
1584 h[
'Reco_muon_with_tagger'].Fill(
"N clones", n_clones)
1585 h[
'Reco_muon_with_tagger'].Fill(
"N ghosts", n_ghosts)
1586 h[
'Reco_muon_with_tagger'].Fill(
"N others", n_others)
1588 (n_tracks, n_recognized, n_clones, n_ghosts, n_others) = self.
muon_metrics_vs_p(track_hits)
1590 (n_tracks, n_recognized, n_clones, n_ghosts, n_others) = self.
all_tracks_metrics(track_hits)
1591 h[
'Reco_all_tracks'].Fill(
"N total", n_tracks)
1592 h[
'Reco_all_tracks'].Fill(
"N recognized tracks", n_recognized)
1593 h[
'Reco_all_tracks'].Fill(
"N clones", n_clones)
1594 h[
'Reco_all_tracks'].Fill(
"N ghosts", n_ghosts)
1595 h[
'Reco_all_tracks'].Fill(
"N others", n_others)
1598 (n_tracks_y12, n_recognized_y12, n_clones_y12, n_ghosts_y12, n_others_y12,
1599 n_tracks_stereo12, n_recognized_stereo12, n_clones_stereo12, n_ghosts_stereo12, n_others_stereo12,
1600 n_tracks_34, n_recognized_34, n_clones_34, n_ghosts_34, n_others_34) = self.
recognition_metrics(track_hits)
1602 h[
'NTrueTracks'].Fill(
"Stations 1&2, Y views", n_tracks_y12)
1603 h[
'NTrueTracks'].Fill(
"Stations 1&2, Stereo views", n_tracks_stereo12)
1604 h[
'NTrueTracks'].Fill(
"Stations 3&4", n_tracks_34)
1606 h[
'Reco_y12'].Fill(
"N total", n_tracks_y12)
1607 h[
'Reco_y12'].Fill(
"N recognized tracks", n_recognized_y12)
1608 h[
'Reco_y12'].Fill(
"N clones", n_clones_y12)
1609 h[
'Reco_y12'].Fill(
"N ghosts", n_ghosts_y12)
1610 h[
'Reco_y12'].Fill(
"N others", n_others_y12)
1612 h[
'Reco_stereo12'].Fill(
"N total", n_tracks_stereo12)
1613 h[
'Reco_stereo12'].Fill(
"N recognized tracks", n_recognized_stereo12)
1614 h[
'Reco_stereo12'].Fill(
"N clones", n_clones_stereo12)
1615 h[
'Reco_stereo12'].Fill(
"N ghosts", n_ghosts_stereo12)
1616 h[
'Reco_stereo12'].Fill(
"N others", n_others_stereo12)
1618 h[
'Reco_34'].Fill(
"N total", n_tracks_34)
1619 h[
'Reco_34'].Fill(
"N recognized tracks", n_recognized_34)
1620 h[
'Reco_34'].Fill(
"N clones", n_clones_34)
1621 h[
'Reco_34'].Fill(
"N ghosts", n_ghosts_34)
1622 h[
'Reco_34'].Fill(
"N others", n_others_34)
1625 (n_tracks_y12, n_recognized_y12, n_clones_y12, n_ghosts_y12, n_others_y12,
1626 n_tracks_stereo12, n_recognized_stereo12, n_clones_stereo12, n_ghosts_stereo12, n_others_stereo12,
1627 n_tracks_34, n_recognized_34, n_clones_34, n_ghosts_34, n_others_34) = self.
recognition_metrics(track_hits, mode=
'3hits')
1629 h[
'NTrueTracks_3hits'].Fill(
"Stations 1&2, Y views", n_tracks_y12)
1630 h[
'NTrueTracks_3hits'].Fill(
"Stations 1&2, Stereo views", n_tracks_stereo12)
1631 h[
'NTrueTracks_3hits'].Fill(
"Stations 3&4", n_tracks_34)
1633 h[
'Reco_y12_3hits'].Fill(
"N total", n_tracks_y12)
1634 h[
'Reco_y12_3hits'].Fill(
"N recognized tracks", n_recognized_y12)
1635 h[
'Reco_y12_3hits'].Fill(
"N clones", n_clones_y12)
1636 h[
'Reco_y12_3hits'].Fill(
"N ghosts", n_ghosts_y12)
1637 h[
'Reco_y12_3hits'].Fill(
"N others", n_others_y12)
1639 h[
'Reco_stereo12_3hits'].Fill(
"N total", n_tracks_stereo12)
1640 h[
'Reco_stereo12_3hits'].Fill(
"N recognized tracks", n_recognized_stereo12)
1641 h[
'Reco_stereo12_3hits'].Fill(
"N clones", n_clones_stereo12)
1642 h[
'Reco_stereo12_3hits'].Fill(
"N ghosts", n_ghosts_stereo12)
1643 h[
'Reco_stereo12_3hits'].Fill(
"N others", n_others_stereo12)
1645 h[
'Reco_34_3hits'].Fill(
"N total", n_tracks_34)
1646 h[
'Reco_34_3hits'].Fill(
"N recognized tracks", n_recognized_34)
1647 h[
'Reco_34_3hits'].Fill(
"N clones", n_clones_34)
1648 h[
'Reco_34_3hits'].Fill(
"N ghosts", n_ghosts_34)
1649 h[
'Reco_34_3hits'].Fill(
"N others", n_others_34)
1652 (n_tracks_y12, n_recognized_y12, n_clones_y12, n_ghosts_y12, n_others_y12,
1653 n_tracks_stereo12, n_recognized_stereo12, n_clones_stereo12, n_ghosts_stereo12, n_others_stereo12,
1654 n_tracks_34, n_recognized_34, n_clones_34, n_ghosts_34, n_others_34) = self.
recognition_metrics(track_hits, mode=
'Tr4')
1656 h[
'NTrueTracks_Tr4'].Fill(
"Stations 1&2, Y views", n_tracks_y12)
1657 h[
'NTrueTracks_Tr4'].Fill(
"Stations 1&2, Stereo views", n_tracks_stereo12)
1658 h[
'NTrueTracks_Tr4'].Fill(
"Stations 3&4", n_tracks_34)
1660 h[
'Reco_y12_Tr4'].Fill(
"N total", n_tracks_y12)
1661 h[
'Reco_y12_Tr4'].Fill(
"N recognized tracks", n_recognized_y12)
1662 h[
'Reco_y12_Tr4'].Fill(
"N clones", n_clones_y12)
1663 h[
'Reco_y12_Tr4'].Fill(
"N ghosts", n_ghosts_y12)
1664 h[
'Reco_y12_Tr4'].Fill(
"N others", n_others_y12)
1666 h[
'Reco_stereo12_Tr4'].Fill(
"N total", n_tracks_stereo12)
1667 h[
'Reco_stereo12_Tr4'].Fill(
"N recognized tracks", n_recognized_stereo12)
1668 h[
'Reco_stereo12_Tr4'].Fill(
"N clones", n_clones_stereo12)
1669 h[
'Reco_stereo12_Tr4'].Fill(
"N ghosts", n_ghosts_stereo12)
1670 h[
'Reco_stereo12_Tr4'].Fill(
"N others", n_others_stereo12)
1672 h[
'Reco_34_Tr4'].Fill(
"N total", n_tracks_34)
1673 h[
'Reco_34_Tr4'].Fill(
"N recognized tracks", n_recognized_34)
1674 h[
'Reco_34_Tr4'].Fill(
"N clones", n_clones_34)
1675 h[
'Reco_34_Tr4'].Fill(
"N ghosts", n_ghosts_34)
1676 h[
'Reco_34_Tr4'].Fill(
"N others", n_others_34)
1680 n_true_track_hits_y12 = {}
1681 n_true_track_hits_stereo12 = {}
1682 n_true_track_hits_34 = {}
1683 for ahit
in self.
sTree.MufluxSpectrometerPoint:
1685 track_id = ahit.GetTrackID()
1687 detID = ahit.GetDetectorID()
1688 statnb = detID // 10000000
1689 vnb = (detID - statnb * 10000000) // 1000000
1691 is_y12 = (statnb == 1) * (vnb == 0) + (statnb == 2) * (vnb == 1)
1692 is_stereo12 = (statnb == 1) * (vnb == 1) + (statnb == 2) * (vnb == 0)
1693 is_34 = (statnb == 3) + (statnb == 4)
1696 if track_id
in n_true_track_hits_y12:
1697 n_true_track_hits_y12[track_id] += 1
1699 n_true_track_hits_y12[track_id] = 1
1701 if track_id
in n_true_track_hits_stereo12:
1702 n_true_track_hits_stereo12[track_id] += 1
1704 n_true_track_hits_stereo12[track_id] = 1
1706 if track_id
in n_true_track_hits_34:
1707 n_true_track_hits_34[track_id] += 1
1709 n_true_track_hits_34[track_id] = 1
1711 for key
in n_true_track_hits_y12.keys():
1712 n = n_true_track_hits_y12[key]
1713 h[
'NHits_true_y12'].Fill(n)
1714 for key
in n_true_track_hits_stereo12.keys():
1715 n = n_true_track_hits_stereo12[key]
1716 h[
'NHits_true_stereo12'].Fill(n)
1717 for key
in n_true_track_hits_34.keys():
1718 n = n_true_track_hits_34[key]
1719 h[
'NHits_true_34'].Fill(n)
1721 for i_track
in track_hits.keys():
1722 atrack = track_hits[i_track]
1723 atrack_y12 = atrack[
'y12']
1724 atrack_stereo12 = atrack[
'stereo12']
1725 atrack_34 = atrack[
'34']
1727 if len(atrack_y12) > 0:
1728 h[
'NHits_reco_y12'].Fill(len(atrack_y12))
1729 if len(atrack_stereo12) > 0:
1730 h[
'NHits_reco_stereo12'].Fill(len(atrack_stereo12))
1731 if len(atrack_34) > 0:
1732 h[
'NHits_reco_34'].Fill(len(atrack_34))
1737 for entry
in trackCandidates:
1742 if not theTrack.checkConsistency():
1743 print(
'Problem with track before fit, not consistent',atrack,theTrack)
1746 try: self.
fitter.processTrack(theTrack)
1748 print(
"genfit failed to fit track")
1751 if not theTrack.checkConsistency():
1754 fitStatus = theTrack.getFitStatus()
1755 nmeas = fitStatus.getNdf()
1756 chi2 = fitStatus.getChi2()/nmeas
1757 pvalue = fitStatus.getPVal()
1761 h[
'nmeas'].Fill(nmeas)
1762 h[
'chi2'].Fill(chi2)
1763 h[
'p-value'].Fill(pvalue)
1765 fittedState = theTrack.getFittedState()
1766 fittedMom = fittedState.getMomMag()
1767 h[
'p-fittedtracks'].Fill(fittedMom)
1768 h[
'1/p-fittedtracks'].Fill(1./fittedMom)
1769 Px,Py,Pz = fittedState.getMom().x(),fittedState.getMom().y(),fittedState.getMom().z()
1771 Pt = ROOT.TMath.Sqrt(Px*Px+Py*Py)
1772 h[
'p/pt'].Fill(P,Pt)
1773 h[
'pt-fittedtracks'].Fill(Pt)
1774 h[
'1/pt-fittedtracks'].Fill(1./Pt)
1776 if self.
sTree.GetBranch(
"MufluxSpectrometerPoint"):
1779 for digi_hit
in trackDigiHits[atrack]:
1780 ahit = self.
sTree.MufluxSpectrometerPoint[digi_hit]
1781 atrack_ids.append(ahit.GetTrackID())
1785 Pttruth = ROOT.TMath.Sqrt(Ptruthx*Ptruthx+Ptruthy*Ptruthy)
1786 h[
'p/pt_truth'].Fill(Ptruth,Pttruth)
1787 perr = (P - Ptruth) / Ptruth
1788 pterr = (Pt - Pttruth) / Pttruth
1789 h[
'p_rel_error'].Fill(perr)
1790 h[
'pt_rel_error'].Fill(pterr)
1792 mom_init = trackMomentums[atrack]
1793 print(
"P_precalc, P_truth: ", mom_init, Ptruth)
1799 pxpztrue = Ptruthx/Ptruthz
1800 pypztrue = Ptruthy/Ptruthz
1801 h[
'Px/Pzfitted'].Fill(pxpzfitted)
1802 h[
'Py/Pzfitted'].Fill(pypzfitted)
1803 h[
'Px/Pztrue'].Fill(pxpztrue)
1804 h[
'Py/Pztrue'].Fill(pypztrue)
1805 h[
'Px/Pzfitted-Px/Pztruth'].Fill(Ptruth,pxpzfitted-pxpztrue)
1806 h[
'Py/Pzfitted-Py/Pztruth'].Fill(Ptruth,pypzfitted-pypztrue)
1807 h[
'ptruth'].Fill(Ptruth)
1808 delPOverP = (P/Ptruth)-1
1809 invdelPOverP = (Ptruth/P)-1
1811 if invdelPOverP < -0.8:
1812 print(
"invdelPOverP = ",invdelPOverP)
1813 print(
"Ptruth =",Ptruth,
" Pfitted =",P)
1814 for n
in range(hitPosLists[atrack].size()):
1815 print(
"hit=",n,
" x(top) ",hitPosLists[atrack][n][0],
" y(top) ",hitPosLists[atrack][n][1],
" z ",hitPosLists[atrack][n][2],
" x(bot) ",hitPosLists[atrack][n][3],
" y(bot) ", hitPosLists[atrack][n][4],
" dist ", hitPosLists[atrack][n][6])
1816 nMufluxHits = self.
sTree.MufluxSpectrometerPoint.GetEntriesFast()
1817 for i
in range(nMufluxHits):
1818 MufluxHit = self.
sTree.MufluxSpectrometerPoint[i]
1819 if ((hitPosLists[atrack][n][0]+1.8 > MufluxHit.GetX()) or(hitPosLists[atrack][n][3]+1.8 > MufluxHit.GetX()))
and ((hitPosLists[atrack][n][0]-1.8<MufluxHit.GetX())
or (hitPosLists[atrack][n][3]-1.8<MufluxHit.GetX()))
and (hitPosLists[atrack][n][2]+1.>MufluxHit.GetZ())
and (hitPosLists[atrack][n][2]-1.<MufluxHit.GetZ()):
1820 print(
"hit x=",MufluxHit.GetX(),
" y=",MufluxHit.GetY(),
" z=",MufluxHit.GetZ())
1823 h[
'delPOverP'].Fill(Ptruth,delPOverP)
1824 h[
'invdelPOverP'].Fill(Ptruth,invdelPOverP)
1825 h[
'deltaPOverP'].Fill(Ptruth,delPOverP)
1826 h[
'Pfitted-Pgun'].Fill(Pgun,P)
1830 print(
"problem with fittedstate")
1834 for entry
in trackCandidates_noT4:
1839 if not theTrack.checkConsistency():
1840 print(
'Problem with track before fit, not consistent',atrack,theTrack)
1843 try: self.
fitter.processTrack(theTrack)
1845 print(
"genfit failed to fit track")
1848 if not theTrack.checkConsistency():
1849 print(
'Problem with track after fit, not consistent',atrack,theTrack)
1851 fitStatus = theTrack.getFitStatus()
1852 nmeas = fitStatus.getNdf()
1853 chi2 = fitStatus.getChi2()/nmeas
1854 pvalue = fitStatus.getPVal()
1858 h[
'nmeas-noT4'].Fill(nmeas)
1859 h[
'chi2-noT4'].Fill(chi2)
1860 h[
'p-value-noT4'].Fill(pvalue)
1863 fittedState = theTrack.getFittedState()
1864 fittedMom = fittedState.getMomMag()
1865 h[
'p-fittedtracks-noT4'].Fill(fittedMom)
1866 h[
'1/p-fittedtracks-noT4'].Fill(1./fittedMom)
1867 Px,Py,Pz = fittedState.getMom().x(),fittedState.getMom().y(),fittedState.getMom().z()
1869 Pt = ROOT.TMath.Sqrt(Px*Px+Py*Py)
1870 h[
'p/pt_noT4'].Fill(P,Pt)
1871 h[
'pt-fittedtracks-noT4'].Fill(Pt)
1872 h[
'1/pt-fittedtracks-noT4'].Fill(1./Pt)
1874 if self.
sTree.GetBranch(
"MufluxSpectrometerPoint"):
1877 for digi_hit
in trackDigiHits_noT4[atrack]:
1878 ahit = self.
sTree.MufluxSpectrometerPoint[digi_hit]
1879 atrack_ids.append(ahit.GetTrackID())
1883 Pttruth = ROOT.TMath.Sqrt(Ptruthx*Ptruthx+Ptruthy*Ptruthy)
1884 h[
'p/pt_truth_noT4'].Fill(Ptruth,Pttruth)
1885 perr = (P - Ptruth) / Ptruth
1886 pterr = (Pt - Pttruth) / Pttruth
1887 h[
'p_rel_error_noT4'].Fill(perr)
1888 h[
'pt_rel_error_noT4'].Fill(pterr)
1894 pxpztrue = Ptruthx/Ptruthz
1895 pypztrue = Ptruthy/Ptruthz
1896 h[
'Px/Pzfitted-Px/Pztruth-noT4'].Fill(Ptruth,pxpzfitted-pxpztrue)
1897 h[
'Py/Pzfitted-Py/Pztruth-noT4'].Fill(Ptruth,pypzfitted-pypztrue)
1898 h[
'Px/Pzfitted-noT4'].Fill(pxpzfitted)
1899 h[
'Py/Pzfitted-noT4'].Fill(pypzfitted)
1900 h[
'Px/Pztrue-noT4'].Fill(pxpztrue)
1901 h[
'Py/Pztrue-noT4'].Fill(pypztrue)
1903 h[
'ptruth-noT4'].Fill(Ptruth)
1904 delPOverP = (P/Ptruth)-1
1905 invdelPOverP = (Ptruth/P)-1
1906 h[
'delPOverP-noT4'].Fill(Ptruth,delPOverP)
1907 h[
'invdelPOverP-noT4'].Fill(Ptruth,invdelPOverP)
1908 h[
'deltaPOverP-noT4'].Fill(Ptruth,delPOverP)
1909 h[
'Pfitted-Pgun-noT4'].Fill(Pgun,P)
1912 print(
"noT4 track: problem with fittedstate")
1916 for entry
in trackCandidates_all:
1921 if not theTrack.checkConsistency():
1922 print(
'Problem with track before fit, not consistent',atrack,theTrack)
1925 try: self.
fitter.processTrack(theTrack)
1927 print(
"genfit failed to fit track")
1930 if not theTrack.checkConsistency():
1931 print(
'Problem with track after fit, not consistent',atrack,theTrack)
1933 fitStatus = theTrack.getFitStatus()
1934 nmeas = fitStatus.getNdf()
1935 chi2 = fitStatus.getChi2()/nmeas
1936 pvalue = fitStatus.getPVal()
1940 h[
'nmeas-all'].Fill(nmeas)
1941 h[
'chi2-all'].Fill(chi2)
1942 h[
'p-value-all'].Fill(pvalue)
1945 fittedState = theTrack.getFittedState()
1946 fittedMom = fittedState.getMomMag()
1947 h[
'p-fittedtracks-all'].Fill(fittedMom)
1948 h[
'1/p-fittedtracks-all'].Fill(1./fittedMom)
1949 Px,Py,Pz = fittedState.getMom().x(),fittedState.getMom().y(),fittedState.getMom().z()
1951 Pt = ROOT.TMath.Sqrt(Px*Px+Py*Py)
1952 h[
'p/pt_all'].Fill(P,Pt)
1953 h[
'pt-fittedtracks-all'].Fill(Pt)
1954 h[
'1/pt-fittedtracks-all'].Fill(1./Pt)
1956 if self.
sTree.GetBranch(
"MufluxSpectrometerPoint"):
1959 for digi_hit
in trackDigiHits_noT4[atrack]:
1960 ahit = self.
sTree.MufluxSpectrometerPoint[digi_hit]
1961 atrack_ids.append(ahit.GetTrackID())
1965 Pttruth = ROOT.TMath.Sqrt(Ptruthx*Ptruthx+Ptruthy*Ptruthy)
1966 h[
'p/pt_truth_all'].Fill(Ptruth,Pttruth)
1967 perr = (P - Ptruth) / Ptruth
1968 pterr = (Pt - Pttruth) / Pttruth
1969 h[
'p_rel_error_all'].Fill(perr)
1970 h[
'pt_rel_error_all'].Fill(pterr)
1976 pxpztrue = Ptruthx/Ptruthz
1977 pypztrue = Ptruthy/Ptruthz
1978 h[
'Px/Pzfitted-Px/Pztruth-all'].Fill(Ptruth,pxpzfitted-pxpztrue)
1979 h[
'Py/Pzfitted-Py/Pztruth-all'].Fill(Ptruth,pypzfitted-pypztrue)
1980 h[
'Px/Pzfitted-all'].Fill(pxpzfitted)
1981 h[
'Py/Pzfitted-all'].Fill(pypzfitted)
1982 h[
'Px/Pztrue-all'].Fill(pxpztrue)
1983 h[
'Py/Pztrue-all'].Fill(pypztrue)
1985 h[
'ptruth-all'].Fill(Ptruth)
1986 delPOverP = (P/Ptruth)-1
1987 invdelPOverP = (Ptruth/P)-1
1988 h[
'delPOverP-all'].Fill(Ptruth,delPOverP)
1989 h[
'invdelPOverP-all'].Fill(Ptruth,invdelPOverP)
1990 h[
'deltaPOverP-all'].Fill(Ptruth,delPOverP)
1991 h[
'Pfitted-Pgun-all'].Fill(Pgun,P)
1994 print(
"All tracks: problem with fittedstate")
1999 if not global_variables.debug:
2000 theTrack.prune(
"CFL")
2003 if global_variables.debug:
2004 print(
'save track',theTrack,chi2,nM,fitStatus.isFitConverged())