Skip to content

Commit

Permalink
add setting of polarization in macro
Browse files Browse the repository at this point in the history
  • Loading branch information
cipriangal committed Dec 1, 2015
1 parent c4c4c3a commit 7aee8fa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
1 change: 1 addition & 0 deletions include/mscMessenger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private:

G4UIcmdWithAnInteger *nrUnitsCmd;
G4UIcmdWithADoubleAndUnit *radThickCmd;
G4UIcmdWithAString *polCmd;

// G4UIcmdWithAnInteger *seedCmd;
// G4UIcmdWithABool *kryptCmd;
Expand Down
5 changes: 2 additions & 3 deletions include/mscPrimaryGeneratorAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ public:

virtual void GeneratePrimaries(G4Event* event);

// set methods
void SetRandomFlag(G4bool value);

void SetPolarization(G4String val){polarization = val;}
private:
G4ParticleGun* fParticleGun; // G4 particle gun
G4String polarization;
};

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Expand Down
4 changes: 3 additions & 1 deletion msc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ int main(int argc,char** argv)

// Set user action classes
//
runManager->SetUserAction(new mscPrimaryGeneratorAction());
mscPrimaryGeneratorAction *prigen=new mscPrimaryGeneratorAction();
runManager->SetUserAction( prigen );
mscMess->SetPriGen(prigen);
//
runManager->SetUserAction(new mscRunAction());
//
Expand Down
10 changes: 9 additions & 1 deletion src/mscMessenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ mscMessenger::mscMessenger(){
radThickCmd->SetGuidance(" use before setNrUnits");
radThickCmd->SetParameterName("radThickness", false);

polCmd = new G4UIcmdWithAString("/msc/PrimaryEventGen/setPolarization",this);
polCmd->SetGuidance(" Set the polarization direction for each event:");
polCmd->SetGuidance(" default L; accepted: L, mL, V, mV");
polCmd->SetParameterName("radThickness", false);

}

mscMessenger::~mscMessenger(){
delete nrUnitsCmd;
delete radThickCmd;
delete polCmd;
}


Expand All @@ -50,8 +56,10 @@ void mscMessenger::SetNewValue(G4UIcommand* cmd, G4String newValue){
fdetcon->SetNrUnits( val );
fdetcon->UpdateGeometry();
}else if( cmd == radThickCmd ){
G4double val = radThickCmd->GetNewIntValue(newValue);
G4double val = radThickCmd->GetNewDoubleValue(newValue);
fdetcon->SetRadiatorThickness( val );
}else if( cmd == polCmd ){
fprigen->SetPolarization( newValue );
}

}
45 changes: 28 additions & 17 deletions src/mscPrimaryGeneratorAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

mscPrimaryGeneratorAction::mscPrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction(),
fParticleGun(0)
fParticleGun(0),
polarization("V")
{
G4int nofParticles = 1;
fParticleGun = new G4ParticleGun(nofParticles);
Expand Down Expand Up @@ -46,24 +47,34 @@ void mscPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
// on DetectorConstruction class we get world volume
// from G4LogicalVolumeStore
//
G4double worldZHalfLength = 0;
G4LogicalVolume* worlLV
= G4LogicalVolumeStore::GetInstance()->GetVolume("World");
G4Box* worldBox = 0;
if ( worlLV) worldBox = dynamic_cast< G4Box*>(worlLV->GetSolid());
if ( worldBox ) {
worldZHalfLength = worldBox->GetZHalfLength();
}
else {
G4cerr << "World volume of box not found." << G4endl;
G4cerr << "Perhaps you have changed geometry." << G4endl;
G4cerr << "The gun will be place in the center." << G4endl;
}
// G4double worldZHalfLength = 0;
// G4LogicalVolume* worlLV
// = G4LogicalVolumeStore::GetInstance()->GetVolume("World");
// G4Box* worldBox = 0;
// if ( worlLV) worldBox = dynamic_cast< G4Box*>(worlLV->GetSolid());
// if ( worldBox ) {
// worldZHalfLength = worldBox->GetZHalfLength();
// }
// else {
// G4cerr << __PRETTY_FUNCTION__ <<" :"<<G4endl;
// G4cerr << " World volume of box not found." << G4endl;
// G4cerr << " Perhaps you have changed geometry." << G4endl;
// G4cerr << " The gun will be place in the center." << G4endl;
// }

// Set gun position
fParticleGun->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength - 10.*cm));
//fParticleGun->SetParticlePolarization(G4ThreeVector(0.,0.,1.)); //L
fParticleGun->SetParticlePolarization(G4ThreeVector(0.,1.,0.)); //V
fParticleGun->SetParticlePosition(G4ThreeVector(0., 0., - 10.*cm));

if(polarization=="V"){
fParticleGun->SetParticlePolarization(G4ThreeVector(0.,1.,0.));
}else if(polarization=="L"){
fParticleGun->SetParticlePolarization(G4ThreeVector(0.,0.,1.));
}else if(polarization=="mL"){
fParticleGun->SetParticlePolarization(G4ThreeVector(0.,0.,-1.));
}else if(polarization=="mV"){
fParticleGun->SetParticlePolarization(G4ThreeVector(0.,-1.,0.));
}else
fParticleGun->SetParticlePolarization(G4ThreeVector(0.,0.,1.));//default longitudinal

fParticleGun->GeneratePrimaryVertex(anEvent);
}
Expand Down

0 comments on commit 7aee8fa

Please sign in to comment.