11from .svgdrawing
import attributemaps
12from .
import svgdrawing
13from datetime
import datetime
18from ROOT
import Belle2
21from ROOT
import gSystem
22gSystem.Load(
'libframework')
24gSystem.Load(
'libtracking')
30 Personal two dimensional event display based on scalable vector graphics
33 def __init__(self, output_folder=tempfile.gettempdir(), interactive=
True):
40 Target folder for the output
41 interactive : bool, optional
42 Switch to display each event to the user
and ask to
continue after each event
265 Property that collects the various names of the draw options to a list
266 that are not related to the CDC cellular automaton track finder.
267 @return list of strings naming the different switches that can be activated.
272 'draw_superlayer_boundaries',
274 'draw_interaction_point',
275 'draw_mcparticle_id',
276 'draw_mcparticle_pdgcode',
277 'draw_mcparticle_primary',
278 'draw_mcparticle_trajectories',
282 'draw_simhit_posflag',
283 'draw_simhit_pdgcode',
284 'draw_simhit_bkgtag',
292 'draw_recotrack_matching',
293 'draw_mcrecotrack_matching',
294 'draw_recotrack_seed_trajectories',
295 'draw_recotrack_fit_trajectories',
321 if not hasattr(self, name):
322 raise NameError(
'%s is not a valid draw option. Fix the misspelling.'
330 Property that collects the all names of the draw options to a list.
331 Note that some draw options only make sense after running the CDC
332 cellular automaton track finder.
333 @return list of strings naming the different switches that can be activated.
338 draw_options = [option
for option
in self.__dict__
339 if option.startswith(
'draw_')]
340 _draw_options = [option[1:]
for option
in self.__dict__
341 if option.startswith(
'_draw_')]
343 result.extend(draw_options)
344 result.extend(_draw_options)
351 Getter for the draw option that indicates
if all wires shall be drawn.
352 Since this has some performance impact
in animated events the wires
353 are prevented
from being drawn
in this case.
361 Setter for the option to draw all wires.
368 Initialisation method of the module.
369 Creates the output folder if it
is not present yet.
373 if not os.path.exists(output_folder):
374 print(
"CDCSVGDisplay.__init__ : Output folder '", output_folder,
376 answer = input(
'Create it? (y or n)')
378 os.makedirs(output_folder)
393 theCDCWireTopology = \
397 cppplotter.drawWires(theCDCWireTopology)
399 plotter.draw(theCDCWireTopology)
409 segment_relation_filter.initialize()
413 Begin run method of the module. Empty here.
420 Event method of the module. Draws the event into a new svg file.
444 basf2.B2INFO(
"Skip empty event")
453 styleDict = {
'stroke': attributemaps.ZeroDriftLengthColorMap(),
454 'stroke-width': attributemaps.ZeroDriftLengthStrokeWidthMap()}
462 styleDict = {
'stroke': attributemaps.TakenFlagColorMap(), }
470 styleDict = {
'stroke': attributemaps.MCParticleColorMap()}
478 styleDict = {
'stroke': attributemaps.MCPDGCodeColorMap()}
486 styleDict = {
'stroke': attributemaps.MCPrimaryColorMap()}
496 simHits_related_to_hits = [hit.getRelated(
'CDCSimHits')
497 for hit
in hit_storearray]
498 styleDict = {
'stroke-width':
'0.2'}
499 plotter.draw_iterable(simHits_related_to_hits, **styleDict)
506 styleDict = {
'stroke': attributemaps.PosFlagColorMap()}
515 styleDict = {
'stroke': attributemaps.RLColorMap()}
523 styleDict = {
'stroke': attributemaps.TOFColorMap()}
531 def color_map(iHit, hit):
532 simHit = hit.getRelated(
'CDCSimHits')
533 pdgCode = simHit.getPDGCode()
535 attributemaps.MCPDGCodeColorMap.color_by_pdgcode.get(pdgCode,
539 styleDict = {
'stroke': color_map}
547 styleDict = {
'stroke': attributemaps.BackgroundTagColorMap()}
555 def color_map(iHit, hit):
556 simHit = hit.getRelated(
'CDCSimHits')
557 bkgTag = simHit.getBackgroundTag()
558 color = (
'gray' if bkgTag
else 'red')
561 styleDict = {
'stroke': color_map}
570 print(
'No Python-function defined')
577 if cdchits_storearray:
578 simhits_related_to_cdchit = [cdchit.getRelated(
'CDCSimHits')
579 for cdchit
in cdchits_storearray]
582 simhits_by_mcparticle = {}
583 for simhit
in simhits_related_to_cdchit:
584 mcparticle = simhit.getRelated(
'MCParticles')
585 if not mcparticle ==
None:
586 mcTrackId = mcparticle.getArrayIndex()
587 simhits_by_mcparticle.setdefault(mcTrackId, [])
588 simhits_by_mcparticle[mcTrackId].append(simhit)
590 for simhits_for_mcparticle
in list(simhits_by_mcparticle.values()):
591 simhits_for_mcparticle.sort(key=
lambda simhit:
592 simhit.getFlightTime())
594 nSimHits = len(simhits_for_mcparticle)
595 for iSimHit
in range(nSimHits - 1):
596 fromSimHit = simhits_for_mcparticle[iSimHit]
597 toSimHit = simhits_for_mcparticle[iSimHit + 1]
599 styleDict = {
'stroke-width':
'0.2',
"stroke":
"black"}
617 plotter.draw(tangent, **styleDict)
624 styleDict = {
'stroke': attributemaps.ReassignedSecondaryMap()}
633 styleDict = {
'stroke': attributemaps.MCSegmentIdColorMap()}
639 cppplotter.drawClusters(
'CDCWireHitSuperClusterVector',
642 styleDict = {
'stroke': attributemaps.listColors}
643 plotter.draw_storevector(
'CDCWireHitSuperClusterVector', **styleDict)
651 styleDict = {
'stroke': attributemaps.listColors}
661 styleDict = {
'stroke': attributemaps.listColors}
668 "SegmentMCTrackIdColorMap",
"")
670 styleDict = {
'stroke': attributemaps.SegmentMCTrackIdColorMap()}
676 "SegmentFBInfoColorMap",
"")
678 styleDict = {
'stroke': attributemaps.SegmentFBInfoColorMap()}
684 "SegmentFirstInTrackIdColorMap",
"")
687 {
'stroke': attributemaps.SegmentFirstInTrackIdColorMap()}
693 "SegmentLastInTrackIdColorMap",
"")
696 {
'stroke': attributemaps.SegmentLastInTrackIdColorMap()}
703 "SegmentFirstNPassedSuperLayersColorMap",
"")
706 {
'stroke': attributemaps.SegmentFirstNPassedSuperLayersColorMap()}
713 "SegmentLastNPassedSuperLayersColorMap",
"")
716 {
'stroke': attributemaps.SegmentLastNPassedSuperLayersColorMap()}
721 cppplotter.drawSegmentPairs(
'CDCSegmentPairs',
'black',
'')
723 styleDict = {
"stroke":
"black"}
724 plotter.draw_storearray(
'CDCSegmentPairs', **styleDict)
732 if segment_storevector:
733 segments = segment_storevector.obj().unwrap()
734 axial_segments = [segment
for segment
in segments
735 if segment.getStereoType() == 0]
737 mc_axial_segment_pair_segment_filter = \
739 axial_segment_pair_relations = \
741 for startSegment
in axial_segments
742 for endSegment
in axial_segments)
744 def is_good_pair(pair):
745 weight = mc_axial_segment_pair_segment_filter(pair)
746 return weight == weight
748 good_axial_segment_pair_relations = [pair
for pair
in
749 axial_segment_pair_relations
if is_good_pair(pair)]
750 styleDict = {
"stroke":
"black"}
751 plotter.draw_iterable(good_axial_segment_pair_relations, **styleDict)
757 print(
'No Python-function defined')
764 if segment_storevector:
765 segments = segment_storevector.obj().unwrap()
766 axial_segments = [segment
for segment
in segments
767 if segment.getStereoType() == 0]
769 stereo_segments = [segment
for segment
in segments
770 if segment.getStereoType() != 0]
773 mc_axial_segment_pair_segment_filter = \
775 mc_segment_lookup = \
780 middleSegment, endSegment)
for startSegment
in
781 axial_segments
for middleSegment
in stereo_segments
782 for endSegment
in axial_segments)
784 def is_good_triple(triple):
785 start = triple.getStartSegment()
786 middle = triple.getMiddleSegment()
787 end = triple.getEndSegment()
790 mc_axial_segment_pair_segment_filter(triple)
792 if not pairWeight == pairWeight:
795 startToMiddleFBInfo = \
796 mc_segment_lookup.areAlignedInMCTrack(start, middle)
797 if abs(startToMiddleFBInfo) > 1:
800 middleToEndFBInfo = \
801 mc_segment_lookup.areAlignedInMCTrack(middle, end)
802 if abs(middleToEndFBInfo) > 1:
805 if startToMiddleFBInfo == middleToEndFBInfo:
810 good_segment_triples = [triple
for triple
in segment_triples
811 if is_good_triple(triple)]
813 styleDict = {
"stroke":
"black"}
814 plotter.draw_iterable(good_segment_triples, **styleDict)
819 print(
'No CPP-function defined')
821 styleDict = {
'stroke-width':
'0.2'}
822 plotter.draw_storearray(
'CDCTangentSegments', **styleDict)
827 cppplotter.drawAxialSegmentPairs(
'CDCAxialSegmentPairVector',
'',
'')
829 styleDict = {
'stroke': attributemaps.listColors}
830 plotter.draw_storevector(
'CDCAxialSegmentPairVector', **styleDict)
835 cppplotter.drawSegmentTriples(
'CDCSegmentTripleVector',
'',
'')
837 styleDict = {
'stroke': attributemaps.listColors}
838 plotter.draw_storevector(
'CDCSegmentTriples', **styleDict)
843 cppplotter.drawTracks(
'CDCTrackVector',
'',
'')
845 styleDict = {
'stroke': attributemaps.listColors}
846 plotter.draw_storevector(
'CDCTrackVector', **styleDict)
852 cppplotter.drawWrongRLHitsInTracks(
'CDCTrackVector')
854 styleDict = {
'stroke': attributemaps.WrongRLColorMap()}
859 wrapped_vector = pystoreobj.obj()
860 vector = wrapped_vector.get()
863 plotter.draw_iterable(list(track.items()), **styleDict)
870 styleDict = {
'stroke': attributemaps.WrongRLColorMap()}
875 wrapped_vector = pystoreobj.obj()
876 vector = wrapped_vector.get()
879 plotter.draw_iterable(list(track.items()), **styleDict)
886 styleDict = {
'stroke': attributemaps.listColors}
894 styleDict = {
'stroke': attributemaps.listColors}
902 print(
'No Python-function defined')
909 print(
'No Python-function defined')
914 cppplotter.drawInteractionPoint()
916 plotter.draw_interaction_point()
921 cppplotter.drawSuperLayerBoundaries()
923 plotter.draw_superlayer_boundaries()
928 cppplotter.drawOuterCDCWall(
'black')
929 cppplotter.drawInnerCDCWall(
'black')
931 styleDict = {
'stroke':
'black'}
932 plotter.draw_outer_cdc_wall(**styleDict)
933 plotter.draw_inner_cdc_wall(**styleDict)
938 cppplotter.drawMCParticleTrajectories(
"MCParticles",
'black',
'')
940 print(
"Python backend can not draw mc particles")
949 if segment_storevector:
950 segments = segment_storevector.obj().unwrap()
952 iterTrajectories = (segment.getTrajectory2D()
for segment
in segments)
953 plotter.draw_iterable(iterTrajectories)
957 cppplotter.drawSegmentTripleTrajectories(
"CDCSegmentTriples",
962 if segmentTriple_storearray:
963 iterSegmentTriples = iter(segmentTriple_storearray)
964 iterTrajectories = (segmentTriple.getTrajectory2D()
965 for segmentTriple
in iterSegmentTriples)
966 plotter.draw_iterable(iterTrajectories)
971 cppplotter.drawTrackTrajectories(
"CDCTrackVector",
974 styleDict = {
'stroke': attributemaps.listColors}
976 if track_storevector:
977 tracks = track_storevector.obj().unwrap()
978 iterTrajectories = (cdcTrack.getStartTrajectory3D().getTrajectory2D()
979 for cdcTrack
in tracks)
980 plotter.draw_iterable(iterTrajectories, **styleDict)
986 if recotrack_storearray:
987 def color_map(iTrajectory, trajectory):
989 return attributemaps.listColors[iTrajectory
990 % len(attributemaps.listColors)]
992 styleDict = {
'stroke': color_map}
995 for recotrack
in recotrack_storearray:
996 tMomentum = recotrack.getMomentumSeed()
997 charge = recotrack.getChargeSeed()
998 tPosition = recotrack.getPositionSeed()
999 time = recotrack.getTimeSeed()
1009 trajectories.append(trajectory)
1011 plotter.draw_iterable(trajectories, **styleDict)
1014 raise NotImplementedError
1021 raise NotImplementedError
1027 cppplotter.saveFile(cppfileName)
1029 plotter.saveSVGFile(fileName)
1033 print(
" Use the 'display' command to show the svg file", fileName,
1034 'generated for the last event')
1036 print(
" Use the 'display' command to show the svg file", cppfileName,
1037 'generated for the last event with cpp')
1041 subprocess.Popen([
'eog', fileName])
1043 subprocess.Popen([
'eog', cppfileName])
1047 input(
'Hit enter for next event')
1051 endRun method of the module. Empty here.
1058 terminate method of the module. Empty here.
1065 Generates a new unique name for the current event without the folder prefix
1069 output_basename = datetime.now().isoformat() +
'.svg'
1072 return output_basename
1076 Generates a new unique name for the current event
with the folder prefix
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
Class representing a pair of reconstructed axial segments in adjacent superlayer.
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
static const CDCMCSegment2DLookUp & getInstance()
Getter for the singletone instance.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Class representing a two dimensional reconstructed hit in the central drift chamber.
Helper class to generated the svg image from the various tracking objects.
Class representing a triple of reconstructed segments in adjacent superlayer.
Class representing a linear track piece between two oriented wire hits.
Particle trajectory as it is seen in xy projection represented as a circle.
Class representing a hit wire in the central drift chamber.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Filter for the construction of axial to axial segment pairs based on simple criteria.
Filter for the construction of segment pairs based on simple criteria without the common fit.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
A three dimensional vector.
draw_recotrack_fit_trajectories
Draw the output trackpoint trajectories.
draw_superclusters
Switch to draw the clusters generated by the finder.
draw_track_trajectories
Switch to draw the trajectories of the tracks generated by the finder.
use_time_in_filename
Use time instead of prefix in filename.
draw_tracks
Switch to draw the tracks generated by the finder.
prefilled_cppplotter
prefilled default is to use the C++ plotter
forward_fade
Switch to make the color of segments and tracks fade out in the forward direction.
draw_simhits
Switch to draw the CDCSimHits with momentum information.
_draw_wires
Switch to draw the wires.
draw_segment_trajectories
Switch to draw the trajectories fitted to the segments generated by the finder.
draw_wrong_rl_infos_in_tracks
Draw a red cdc hit of the rl info of the track reco hits is wrong, else a green one.
draw_takenflag
Switch to draw the CDCHits colored by the associated CDCWireHit taken flag.
def all_drawoptions(self)
draw_mcsegmentpairs
Switch to draw the axial to stereo segment pairs from Monte Carlo truth.
draw_recotrack_matching
Draw the output RecoTracks pattern recognition matching status.
draw_mcaxialsegmentpairs
Switch to draw the axial to axial segment pairs from Monte Carlo truth.
draw_mcparticle_pdgcode
Switch to draw the MCParticle::getPDGCode property.
interactive
Switch if the module shall show the event to the user and wait to continue or just generate the image...
draw_rlinfo
Switch to draw the CDCSimHits color coded by their local right left passage information.
draw_connect_tof
Switch to draw the CDCSimHits connected in the order of their getFlightTime for each Monte Carlo part...
draw_segmentpairs
Switch to draw the axial stereo segment pairs generated by the finder.
draw_simhit_bkgtag
Switch to draw the CDCSimHits color coded by their getBackgroundTag() property.
draw_simhit_tof
Switch to draw the CDCSimHits color coded by their time of flight.
draw_walls
Switch to draw the superlayer boundaries.
draw_recotracks
Draw the output RecoTracks.
draw_segmenttriple_trajectories
Switch to draw the trajectories fitted to the segment triples generated by the finder.
mc_reco_tracks_store_array_name
Name of the Monte Carlo reference RecoTracks store array.
draw_segment_fbinfos
Switch to draw the segments generated by the finder colored by the coalignment information (forward,...
draw_recotrack_seed_trajectories
Draw the output track seed trajectories.
draw_segment_lastNPassedSuperLayers
Switch to draw the segments generated by the finder colored by the number of passed superlayers assoc...
draw_nloops
Switch to draw the CDCHit colored by the number of loops passed.
draw_hits
Switch to draw the CDCHits.
cdc_hits_store_array_name
Name of the CDC Hits store array.
animate
Switch to make an animated event display by means of animated SVG.
draw_wrong_rl_infos_in_segments
Draw a red cdc hit of the rl info of the segment reco hits is wrong, else a green one.
use_python
Flag to use python.
draw_simhit_isbkg
Switch to draw the CDCSimHits red for getBackgroundTag() != bg_none.
draw_segment_lastInTrackIds
Switch to draw the segments generated by the finder colored by the second in track hit id.
cdc_wire_hit_cluster_store_obj_name
Name of the CDC Wire Hit Clusters.
def new_output_basename(self)
draw_mcparticle_id
Switch to draw the MCParticle::getArrayIndex property.
reco_tracks_store_array_name
Name of the RecoTracks store array.
draw_clusters
Switch to draw the clusters generated by the finder.
draw_axialsegmentpairs
Switch to draw the axial stereo segment pairs generated by the finder.
draw_interaction_point
Switch to draw the interaction point.
draw_mcrecotracks
Draw the MC reference RecoTracks.
draw_simhit_posflag
Switch to draw the CDCSimHits color coded by their getPosFlag() property.
draw_superlayer_boundaries
Switch to draw the superlayer boundaries.
def new_output_filename(self)
draw_segmenttriples
Switch to draw the segment triples generated by the finder.
draw_mcrecotrack_matching
Draw the MC reference RecoTracks pattern recognition matching status.
draw_mcsegments
Switch to draw the Monte Carlo segments as generated in CDCMCTrackStore.
def draw_wires(self, draw_wires)
draw_mcsegmenttriples
Switch to draw the segment triples from Monte Carlo truth.
draw_tangentsegments
Switch to draw the tangent segments generated by the finder.
draw_reassigned
Switch to draw the CDCSimHits color coded by their reassignement information to a different MCParticl...
draw_simhit_pdgcode
Switch to draw the CDCSimHits color coded by their getPDGCode() property.
filename_prefix
Filename prefix.
draw_mcparticle_primary
Switch to draw the MCParticle::hasStatus(c_PrimaryParticle) property.
draw_segment_firstNPassedSuperLayers
Switch to draw the segments generated by the finder colored by the number of passed superlayers assoc...
draw_segment_firstInTrackIds
Switch to draw the segments generated by the finder colored by the first in track hit id.
draw_mcparticle_trajectories
Switch to draw the ideal trajectory of the MCParticle.
draw_segment_mctrackids
Switch to draw the segments generated by the finder colored with the Monte Carlo track id.
prefilled_plotter
prefilled default is to use the python plotter
def __init__(self, output_folder=tempfile.gettempdir(), interactive=True)
draw_segments
Switch to draw the segments generated by the finder.
output_folder
Folder the images shall be saved to.
cdc_segment_vector_store_obj_name
Name of the CDC Reco Segment Vector.
file_number
Current file's number (used for making output filename)