File indexing completed on 2025-01-31 09:21:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include <cmath>
0045 #include <G4Polyline.hh>
0046 #include <G4Circle.hh>
0047 #include <G4Polyhedron.hh>
0048 #include <G4ThreeVector.hh>
0049 #include <G4VisAttributes.hh>
0050 #include <G4VGraphicsScene.hh>
0051 #include <G4AffineTransform.hh>
0052 #include <G4Transform3D.hh>
0053 #include <G4Point3D.hh>
0054 #include <G4SystemOfUnits.hh>
0055 #include "CexmcScenePrimitives.hh"
0056 #include "CexmcScenePrimitivesMessenger.hh"
0057 #include "CexmcSetup.hh"
0058 #include "CexmcCommon.hh"
0059
0060
0061 namespace
0062 {
0063 G4double CexmcRadialLineWidth( 2.0 );
0064 G4double CexmcRadialLineCapScreenSize( 4.0 );
0065 G4double CexmcMarkerScreenSize( 2.0 );
0066 G4double CexmcICHlLineLineWidth( 1.0 );
0067 G4Colour CexmcDefaultSPColour( 1.0, 1.0, 1.0 );
0068 }
0069
0070
0071 CexmcScenePrimitives::CexmcScenePrimitives( CexmcSetup * setup_ ) :
0072 setup( setup_ ), markTargetCenter( false ), highlightInnerCrystals( false ),
0073 messenger( NULL )
0074 {
0075 messenger = new CexmcScenePrimitivesMessenger( this );
0076 SetGlobalDescription( CexmcScenePrimitivesDescription );
0077 spColours[ CexmcTargetCenterMark_SP ] = CexmcDefaultSPColour;
0078 spColours[ CexmcRadialLine_SP ] = CexmcDefaultSPColour;
0079 spColours[ CexmcInnerCrystalsHl_SP ] = CexmcDefaultSPColour;
0080 }
0081
0082
0083 CexmcScenePrimitives::~CexmcScenePrimitives()
0084 {
0085 delete messenger;
0086 }
0087
0088
0089 void CexmcScenePrimitives::DescribeYourselfTo( G4VGraphicsScene & scene )
0090 {
0091 if ( markTargetCenter )
0092 MarkTargetCenter( scene );
0093 if ( highlightInnerCrystals )
0094 HighlightInnerCrystals( scene );
0095 for ( CexmcRadialLines::const_iterator k( radialLines.begin() );
0096 k != radialLines.end(); ++k )
0097 {
0098 DrawRadialLine( scene, &*k );
0099 }
0100 }
0101
0102
0103 void CexmcScenePrimitives::MarkTargetCenter( G4VGraphicsScene & scene )
0104 {
0105 G4Circle circle;
0106 circle.SetScreenSize( CexmcMarkerScreenSize );
0107 circle.SetFillStyle( G4Circle::filled );
0108 circle.SetVisAttributes( spColours[ CexmcTargetCenterMark_SP ] );
0109
0110 const G4AffineTransform & transform( setup->GetTargetTransform() );
0111 G4Transform3D transform3D( G4RotationMatrix(),
0112 transform.NetTranslation() );
0113
0114 scene.BeginPrimitives( transform3D );
0115 scene.AddPrimitive( circle );
0116 scene.EndPrimitives();
0117 }
0118
0119
0120 void CexmcScenePrimitives::DrawRadialLine( G4VGraphicsScene & scene,
0121 const CexmcRadialLine * rLine )
0122 {
0123 G4double theta( rLine->theta * deg );
0124 G4double phi( rLine->phi * deg );
0125 G4double length( rLine->length * cm );
0126 G4Point3D radialLineEnd( - std::sin( theta ) * std::cos( phi ) * length,
0127 std::sin( theta ) * std::sin( phi ) * length,
0128 std::cos( theta ) * length );
0129
0130 G4Polyline line;
0131 line.push_back( G4ThreeVector() );
0132 line.push_back( radialLineEnd );
0133
0134 G4VisAttributes visAttributes( spColours[ CexmcRadialLine_SP ] );
0135 visAttributes.SetLineWidth( CexmcRadialLineWidth );
0136 line.SetVisAttributes( visAttributes );
0137
0138 G4Circle circle;
0139 circle.SetScreenSize( CexmcRadialLineCapScreenSize );
0140 circle.SetFillStyle( G4Circle::filled );
0141 circle.SetVisAttributes( spColours[ CexmcRadialLine_SP ] );
0142
0143 const G4AffineTransform & transform( setup->GetTargetTransform() );
0144 G4Transform3D transform3D( G4RotationMatrix(),
0145 transform.NetTranslation() );
0146
0147 scene.BeginPrimitives( transform3D );
0148 scene.AddPrimitive( circle );
0149 scene.AddPrimitive( line );
0150 scene.EndPrimitives();
0151 }
0152
0153
0154 void CexmcScenePrimitives::HighlightInnerCrystals( G4VGraphicsScene & scene )
0155 {
0156 const CexmcSetup::CalorimeterGeometryData & calorimeterGeometry(
0157 setup->GetCalorimeterGeometry() );
0158 G4double icWidth( calorimeterGeometry.crystalWidth *
0159 ( calorimeterGeometry.nCrystalsInRow - 2 ) / 2 );
0160 G4double icHeight( calorimeterGeometry.crystalHeight *
0161 ( calorimeterGeometry.nCrystalsInColumn - 2 ) / 2 );
0162 G4double icLength( calorimeterGeometry.crystalLength / 2 );
0163 icWidth = icWidth < 0 ? 0 : icWidth;
0164 icHeight = icHeight < 0 ? 0 : icHeight;
0165
0166 G4PolyhedronBox innerCrystals( icWidth, icHeight, icLength );
0167 G4VisAttributes visAttributes( spColours[ CexmcInnerCrystalsHl_SP ] );
0168 visAttributes.SetLineWidth( CexmcICHlLineLineWidth );
0169 innerCrystals.SetVisAttributes( visAttributes );
0170
0171 const G4AffineTransform & transformLeft(
0172 setup->GetCalorimeterLeftTransform() );
0173 G4Transform3D transform3DLeft(
0174 transformLeft.NetRotation().inverse(),
0175 transformLeft.NetTranslation() );
0176 const G4AffineTransform & transformRight(
0177 setup->GetCalorimeterRightTransform() );
0178 G4Transform3D transform3DRight(
0179 transformRight.NetRotation().inverse(),
0180 transformRight.NetTranslation() );
0181
0182 scene.BeginPrimitives( transform3DLeft );
0183 scene.AddPrimitive( innerCrystals );
0184 scene.EndPrimitives();
0185 scene.BeginPrimitives( transform3DRight );
0186 scene.AddPrimitive( innerCrystals );
0187 scene.EndPrimitives();
0188 }
0189