1212#include " G4UIcmdWithAString.hh"
1313#include " G4UIcmdWithADoubleAndUnit.hh"
1414#include " G4UIcmdWithoutParameter.hh"
15+ #include " G4UIcmdWith3Vector.hh"
1516#include " G4GeometryManager.hh"
17+ #include " G4RunManager.hh"
18+ #include " GlueXPhysicsList.hh"
19+ #include " GlueXPrimaryGeneratorAction.hh"
20+ #include " GlueXBeamConversionProcess.hh"
1621
1722GlueXDetectorMessenger::GlueXDetectorMessenger (GlueXDetectorConstruction* myDet)
1823:myDetector(myDet)
@@ -32,7 +37,7 @@ GlueXDetectorMessenger::GlueXDetectorMessenger(GlueXDetectorConstruction* myDet)
3237
3338 StepMaxCmd = new G4UIcmdWithADoubleAndUnit (" /hdgeant4/det/stepMax" ,this );
3439 StepMaxCmd->SetGuidance (" Define a step max" );
35- StepMaxCmd->SetParameterName (" stepMax" ,false );
40+ StepMaxCmd->SetParameterName (" stepMax" ,true , true );
3641 StepMaxCmd->SetUnitCategory (" Length" );
3742 StepMaxCmd->AvailableForStates (G4State_Idle);
3843
@@ -45,6 +50,30 @@ GlueXDetectorMessenger::GlueXDetectorMessenger(GlueXDetectorConstruction* myDet)
4550 CloseGeomCmd = new G4UIcmdWithoutParameter (" /hdgeant4/closeGeometry" ,this );
4651 CloseGeomCmd->SetGuidance (" Explicitly close the geometry." );
4752 CloseGeomCmd->AvailableForStates (G4State_Idle);
53+
54+ RadiatorAnglesCmd = new G4UIcmdWith3Vector (" /hdgeant4/diamondAngles" ,this );
55+ RadiatorAnglesCmd->SetGuidance (" Control the diamond radiator orientation." );
56+ RadiatorAnglesCmd->SetGuidance (" Arguments are theta_x, theta_y, theta_z" );
57+ RadiatorAnglesCmd->SetGuidance (" in radians, applied in the order theta_x," );
58+ RadiatorAnglesCmd->SetGuidance (" followed by theta_y, followed by theta_z." );
59+ RadiatorAnglesCmd->SetParameterName (" theta_x" ," theta_y" ," theta_z" ,true ,true );
60+ RadiatorAnglesCmd->AvailableForStates (G4State_Idle);
61+
62+ TargetNuclPolCmd = new G4UIcmdWith3Vector (" /hdgeant4/targetNuclearPolarization" ,this );
63+ TargetNuclPolCmd->SetGuidance (" Control the primary target nuclear polarization." );
64+ TargetNuclPolCmd->SetGuidance (" Arguments are pol_x, pol_y, pol_z" );
65+ TargetNuclPolCmd->SetGuidance (" in fractions, normalized to a unit vector" );
66+ TargetNuclPolCmd->SetGuidance (" for 100% polarization." );
67+ TargetNuclPolCmd->SetParameterName (" pol_x" ," pol_y" ," pol_z" ,true ,true );
68+ TargetNuclPolCmd->AvailableForStates (G4State_Idle);
69+
70+ TargetElecPolCmd = new G4UIcmdWith3Vector (" /hdgeant4/targetElectronPolarization" ,this );
71+ TargetElecPolCmd->SetGuidance (" Control the primary target electron polarization." );
72+ TargetElecPolCmd->SetGuidance (" Arguments are pol_x, pol_y, pol_z" );
73+ TargetElecPolCmd->SetGuidance (" in fractions, normalized to a unit vector" );
74+ TargetElecPolCmd->SetGuidance (" for 100% polarization." );
75+ TargetElecPolCmd->SetParameterName (" pol_x" ," pol_y" ," pol_z" ,true ,true );
76+ TargetElecPolCmd->AvailableForStates (G4State_Idle);
4877}
4978
5079GlueXDetectorMessenger::~GlueXDetectorMessenger ()
@@ -53,6 +82,10 @@ GlueXDetectorMessenger::~GlueXDetectorMessenger()
5382 delete StepMaxCmd;
5483 delete detDir;
5584 delete hdgeant4Dir;
85+ delete OpenGeomCmd;
86+ delete RadiatorAnglesCmd;
87+ delete TargetNuclPolCmd;
88+ delete TargetElecPolCmd;
5689}
5790
5891void GlueXDetectorMessenger::SetNewValue (G4UIcommand* command,G4String newValue)
@@ -62,11 +95,121 @@ void GlueXDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
6295 }
6396 else if (command == StepMaxCmd) {
6497 myDetector->SetMaxStep (StepMaxCmd->GetNewDoubleValue (newValue));
98+ std::cout << " MaxStep is now " << StepMaxCmd->GetCurrentValue () << std::endl;
6599 }
66100 else if (command == OpenGeomCmd) {
67101 G4GeometryManager::GetInstance ()->OpenGeometry ();
68102 }
69103 else if (command == CloseGeomCmd) {
70104 G4GeometryManager::GetInstance ()->CloseGeometry ();
71105 }
106+ else if (command == RadiatorAnglesCmd) {
107+ G4ThreeVector angles (RadiatorAnglesCmd->GetNew3VectorValue (newValue));
108+ std::map<CobremsGeneration*, int >::iterator igen;
109+ int assigned (0 );
110+ for (igen = CobremsGeneration::CobremsGenerators.begin ();
111+ igen != CobremsGeneration::CobremsGenerators.end ();
112+ igen++)
113+ {
114+ igen->first ->setTargetOrientation (angles[0 ], angles[1 ], angles[2 ]);
115+ std::cout << " radiator angles are now "
116+ << RadiatorAnglesCmd->GetCurrentValue () << std::endl;
117+ assigned += igen->second ;
118+ }
119+ if (!assigned) {
120+ std::cerr << " CobremsGeneration has not been started yet, you must start"
121+ << " up the photon beam generator before attempting to set"
122+ << " the radiator orientation." << std::endl;
123+ }
124+ }
125+ else if (command == TargetNuclPolCmd) {
126+ G4ThreeVector polar (RadiatorAnglesCmd->GetNew3VectorValue (newValue));
127+ const GlueXPhysicsList *phy = dynamic_cast <const GlueXPhysicsList*>
128+ (G4RunManager::GetRunManager ()->GetUserPhysicsList ());
129+ GlueXBeamConversionProcess *con = (GlueXBeamConversionProcess*)
130+ phy->getBeamConversionProcess ();
131+ if (con != 0 && polar.mag () <= 1 ) {
132+ double nucl[3 ];
133+ double elec[3 ];
134+ con->getTargetPolarization (nucl, elec);
135+ nucl[0 ] = polar[0 ];
136+ nucl[1 ] = polar[1 ];
137+ nucl[2 ] = polar[2 ];
138+ con->setTargetPolarization (nucl, elec);
139+ }
140+ else {
141+ std::cerr << " polarization vector normalization >1, assignment failed."
142+ << std::endl;
143+ }
144+ std::cout << " target nuclear polarization vector is now "
145+ << TargetNuclPolCmd->GetCurrentValue () << std::endl;
146+ }
147+ else if (command == TargetElecPolCmd) {
148+ G4ThreeVector polar (RadiatorAnglesCmd->GetNew3VectorValue (newValue));
149+ const GlueXPhysicsList *phy = dynamic_cast <const GlueXPhysicsList*>
150+ (G4RunManager::GetRunManager ()->GetUserPhysicsList ());
151+ GlueXBeamConversionProcess *con = (GlueXBeamConversionProcess*)
152+ phy->getBeamConversionProcess ();
153+ if (con != 0 && polar.mag () <= 1 ) {
154+ double nucl[3 ];
155+ double elec[3 ];
156+ con->getTargetPolarization (nucl, elec);
157+ elec[0 ] = polar[0 ];
158+ elec[1 ] = polar[1 ];
159+ elec[2 ] = polar[2 ];
160+ con->setTargetPolarization (nucl, elec);
161+ }
162+ else {
163+ std::cerr << " polarization vector normalization >1, assignment failed."
164+ << std::endl;
165+ }
166+ std::cout << " target electron polarization vector is now "
167+ << TargetElecPolCmd->GetCurrentValue () << std::endl;
168+ }
169+ }
170+
171+ G4String GlueXDetectorMessenger::GetCurrentValue (G4UIcommand* command)
172+ {
173+ G4String cv;
174+ if (command == StepMaxCmd) {
175+ cv = StepMaxCmd->ConvertToString (myDetector->GetMaxStep (cm));
176+ }
177+ else if (command == RadiatorAnglesCmd) {
178+ G4ThreeVector angles;
179+ std::map<CobremsGeneration*, int >::iterator igen;
180+ for (igen = CobremsGeneration::CobremsGenerators.begin ();
181+ igen != CobremsGeneration::CobremsGenerators.end ();
182+ igen++)
183+ {
184+ angles[0 ] = igen->first ->getTargetThetax ();
185+ angles[1 ] = igen->first ->getTargetThetay ();
186+ angles[2 ] = igen->first ->getTargetThetaz ();
187+ cv = RadiatorAnglesCmd->ConvertToString (angles);
188+ }
189+ }
190+ else if (command == TargetNuclPolCmd) {
191+ const GlueXPhysicsList *phy = dynamic_cast <const GlueXPhysicsList*>
192+ (G4RunManager::GetRunManager ()->GetUserPhysicsList ());
193+ if (phy != 0 ) {
194+ GlueXBeamConversionProcess *con = (GlueXBeamConversionProcess*)
195+ phy->getBeamConversionProcess ();
196+ double nucl[3 ];
197+ double elec[3 ];
198+ con->getTargetPolarization (nucl, elec);
199+ cv = TargetNuclPolCmd->ConvertToString (G4ThreeVector (nucl[0 ], nucl[1 ], nucl[2 ]));
200+ }
201+ }
202+ else if (command == TargetElecPolCmd) {
203+ const GlueXPhysicsList *phy = dynamic_cast <const GlueXPhysicsList*>
204+ (G4RunManager::GetRunManager ()->GetUserPhysicsList ());
205+ if (phy != 0 ) {
206+ GlueXBeamConversionProcess *con = (GlueXBeamConversionProcess*)
207+ phy->getBeamConversionProcess ();
208+ double nucl[3 ];
209+ double elec[3 ];
210+ con->getTargetPolarization (nucl, elec);
211+ cv = TargetElecPolCmd->ConvertToString (G4ThreeVector (elec[0 ], elec[1 ], elec[2 ]));
212+ }
213+ }
214+ return cv;
72215}
0 commit comments