Kamil Sedlak 2009-05-18

This is the first version of the muSR simulation code (musrSim)
based on the merged codes of Kamil Sedlak and Toni Shiroka.
It should be a running version of the simulation code, however 
it has not been very well tested, therefore it will probably
need some further development.
This commit is contained in:
2009-05-18 09:59:52 +00:00
commit fcd5eea567
66 changed files with 13320 additions and 0 deletions

160
include/BLEngeFunction.hh Normal file
View File

@ -0,0 +1,160 @@
// BLEngeFunction.hh
/*
This source file is part of G4beamline, http://g4beamline.muonsinc.com
Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
http://www.gnu.org/copyleft/gpl.html
*/
#ifndef BLENGEFUNCTION_HH
#define BLENGEFUNCTION_HH
#include <math.h>
/** enum BLEngeType specifies the default parameters of BLEngeFunction.
**/
enum BLEngeType { ENGE_BLOCK, ENGE_BEND, ENGE_QUAD, ENGE_OTHER };
/** class EngeFunction implements the Enge function for fringe fields.
*
* z is the distance from the nominal edge, with z=0 being the edge.
* it should be divided by the aperture diameter or full width/height.
* z<0 is inside, z>0 is outside.
*
* See the COSY reference manual (pp 32-35) for suggested values of
* a1-a6, or use the ENGE_BEND or ENGE_QUAD types (which come from there).
* http://cosy.pa.msu.edu/cosymanu/index.html
*
* Mathematica was used to compute the derivatives.
**/
class BLEngeFunction {
BLEngeType type;
double a1,a2,a3,a4,a5,a6;
public:
/// default constructor.
BLEngeFunction() { type=ENGE_BLOCK; set(0,0,0,0,0,0); }
/// constructor for common magnet types.
BLEngeFunction(BLEngeType t) {
switch(t) {
case ENGE_BLOCK:
case ENGE_OTHER:
set(0,0,0,0,0,0);
break;
case ENGE_BEND:
set(0.478959,1.911289,-1.185953,1.630554,-1.082657,0.318111);
break;
case ENGE_QUAD:
set(0.296471,4.533219,-2.270982,1.068627,-0.036391,0.022261);
break;
}
type = t;
}
/// general constructor.
BLEngeFunction(double _a1, double _a2, double _a3, double _a4,
double _a5, double _a6) {
set(_a1,_a2,_a3,_a4,_a5,_a6);
}
/// set the parameters.
void set(double _a1, double _a2, double _a3, double _a4,
double _a5, double _a6) {
a1=_a1; a2=_a2; a3=_a3; a4=_a4; a5=_a5; a6=_a6;
if(a1==0.0 && a2==0.0 && a3==0.0 && a4==0.0 && a5==0.0 &&
a6==0.0)
type = ENGE_BLOCK;
else
type = ENGE_OTHER;
}
/// evaluate the Enge function at z.
double operator()(double z) const {
if(type == ENGE_BLOCK) return (z<=0.0 ? 1.0 : 0.0);
if(z < -4.0) return 1.0;
if(z > 4.0) return 0.0;
return 1.0/(1.0+exp(a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6))))));
}
/// evaluate the derivative of the Enge function at z.
double prime(double z) const {
if(type == ENGE_BLOCK) return 0.0;
if(fabs(z) > 4.0) return 0.0;
double exp1 = exp(a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6)))));
return -exp1/(1.0+exp1)/(1.0+exp1)*
(a2+z*(2.0*a3+z*(3.0*a4+z*(4.0*a5+z*5.0*a6))));
}
double first(double z) { return prime(z); }
/// evaluate the second derivative of the Enge function at z.
double second(double z) const {
if(type == ENGE_BLOCK) return 0.0;
if(fabs(z) > 4.0) return 0.0;
double f1 = a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6))));
double f2 = (a2+2*a3*z+3*a4*z*z+4*a5*z*z*z+5*a6*z*z*z*z);
double f3 = (2*a3+6*a4*z+12*a5*z*z+20*a6*z*z*z);
double exp1 = exp(f1);
return exp1*((exp1-1.0)*f2*f2-(1.0+exp1)*f3)/
(1.0+exp1)/(1.0+exp1)/(1.0+exp1);
}
/// evaluate the third derivative of the Enge function at z.
double third(double z) const {
if(type == ENGE_BLOCK) return 0.0;
if(fabs(z) > 4.0) return 0.0;
double f1 = a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6))));
double f2 = a2+z*(2*a3+z*(3*a4+4*a5*z+5*a6*z*z));
double f3 = 2*(a3+z*(3*a4+2*z*(3*a5+5*a6*z)));
double f4 = a4+2.0*z*(2.0*a5+5.0*a6*z);
double exp1 = exp(f1);
double onepexp1 = 1.0 + exp1;
return -exp1*(6*exp1*exp1*f2*f2*f2-6*exp1*f2*(f2*f2+f3)*onepexp1
+(f2*f2*f2+3*f2*f3+6*f4)*onepexp1*onepexp1)
/(onepexp1*onepexp1*onepexp1*onepexp1);
}
/// evaluate the fourth derivative of the Enge function at z.
double fourth(double z) const {
if(type == ENGE_BLOCK) return 0.0;
if(fabs(z) > 4.0) return 0.0;
double f1 = a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6))));
double f2 = a2+z*(2*a3+z*(3*a4+4*a5*z+5*a6*z*z));
double f3 = 2*(a3+z*(3*a4+2*z*(3*a5+5*a6*z)));
double f4 = a4+2.0*z*(2.0*a5+5.0*a6*z);
double f5 = a5 + 5*a6*z;
double exp1 = exp(f1);
double onepexp1 = 1.0 + exp1;
return -exp1*(-24*exp1*exp1*exp1*f2*f2*f2*f2+onepexp1*
(36*exp1*exp1*f2*f2*(f2*f2+f3)-2*exp1*(7*f2*f2*f2*f2
+18*f2*f2*f3+3*f3*f3+24*f2*f4)*onepexp1
+(f2*f2*f2*f2+6*f2*f2*f3+3*f3*f3+24*f2*f4+24*f5)
*onepexp1*onepexp1))
/(onepexp1*onepexp1*onepexp1*onepexp1*onepexp1);
}
/// evaluate the fifth derivative of the Enge function at z.
double fifth(double z) const {
if(type == ENGE_BLOCK) return 0.0;
if(fabs(z) > 4.0) return 0.0;
double f1 = a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6))));
double f2 = a2+z*(2*a3+z*(3*a4+4*a5*z+5*a6*z*z));
double f3 = 2*(a3+z*(3*a4+2*z*(3*a5+5*a6*z)));
double f4 = a4+2.0*z*(2.0*a5+5.0*a6*z);
double f5 = a5 + 5*a6*z;
double exp1 = exp(f1);
double onepexp1 = 1.0 + exp1;
return -exp1/(onepexp1*onepexp1*onepexp1*onepexp1*onepexp1*onepexp1)
*(120*exp1*exp1*exp1*exp1*f2*f2*f2*f2*f2
-240*exp1*exp1*exp1*f2*f2*f2*(f2*f2+f3)*onepexp1
+onepexp1*onepexp1*(30*exp1*exp1*f2*(5*f2*f2*f2*f2
+12*f2*f2*f3+3*f3*f3+12*f2*f4)-10*exp1*(3*f2*f2*f2*f2*f2
+14*f2*f2*f2*f3+9*f2*f3*f3+36*f2*f2*f4+12*f3*f4+24*f2*f5)
*onepexp1+(120*a6+f2*f2*f2*f2*f2+10*f2*f2*f2*f3+60*f2*f2*f4
+60*f3*f4+15*f2*(f3*f3+8*f5))*onepexp1*onepexp1));
}
/// return the type of Enge function
BLEngeType getType() const { return type; }
};
#endif // BLENGEFUNCTION_HH

171
include/F04ElementField.hh Normal file
View File

@ -0,0 +1,171 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
#ifndef F04ElementField_h
#define F04ElementField_h 1
#include "globals.hh"
#include "G4Navigator.hh"
#include "G4TransportationManager.hh"
#include "G4UserLimits.hh"
#include "G4VisAttributes.hh"
// class F04ElementField - interface for the EM field of one element
// This is the interface class used by GlobalField to compute the field
// value at a given point[].
// An element that represents an element with an EM field will
// derive a class from this one and implement the computation for the
// element. The construct() function will add the derived object into
// GlobalField.
class F04ElementField
{
private:
F04ElementField& operator=(const F04ElementField&);
public:
/// Constructor.
F04ElementField(const G4ThreeVector, G4LogicalVolume*);
/// the actual implementation constructs the F04ElementField
void construct();
/// Destructor.
virtual ~F04ElementField() { if (aNavigator) delete aNavigator; }
/// setMaxStep(G4double) sets the max. step size
void setMaxStep(G4double s)
{
maxStep = s;
userLimits->SetMaxAllowedStep(maxStep);
lvolume->SetUserLimits(userLimits);
}
/// getMaxStep() returns the max. step size
G4double getMaxStep() { return maxStep; }
/// setColor(G4String) sets the color
void setColor(G4String c)
{
color = c;
lvolume->SetVisAttributes(getVisAttribute(color));
}
/// getColor() returns the color
G4String getColor() { return color; }
/// getVisAttribute() returns the appropriate G4VisAttributes.
static G4VisAttributes* getVisAttribute(G4String color);
/// setGlobalPoint() ensures that the point is within the global
/// bounding box of this ElementField's global coordinates.
/// Normally called 8 times for the corners of the local bounding
/// box, after a local->global coordinate transform.
/// If never called, the global bounding box is infinite.
/// BEWARE: if called only once, the bounding box is just a point.
void setGlobalPoint(const G4double point[4])
{
if(minX == -DBL_MAX || minX > point[0]) minX = point[0];
if(minY == -DBL_MAX || minY > point[1]) minY = point[1];
if(minZ == -DBL_MAX || minZ > point[2]) minZ = point[2];
if(maxX == DBL_MAX || maxX < point[0]) maxX = point[0];
if(maxY == DBL_MAX || maxY < point[1]) maxY = point[1];
if(maxZ == DBL_MAX || maxZ < point[2]) maxZ = point[2];
}
/// isInBoundingBox() returns true if the point is within the
/// global bounding box - global coordinates.
bool isInBoundingBox(const G4double point[4]) const
{
if(point[2] < minZ || point[2] > maxZ) return false;
if(point[0] < minX || point[0] > maxX) return false;
if(point[1] < minY || point[1] > maxY) return false;
return true;
}
/// addFieldValue() will add the field value for this element to field[].
/// Implementations must be sure to verify that point[] is within
/// the field region, and do nothing if not.
/// point[] is in global coordinates and geant4 units; x,y,z,t.
/// field[] is in geant4 units; Bx,By,Bz,Ex,Ey,Ez.
/// For efficiency, the caller may (but need not) call
/// isInBoundingBox(point), and only call this function if that
/// returns true.
virtual void
addFieldValue(const G4double point[4], G4double field[6]) const = 0;
virtual G4double getLength() = 0;
virtual G4double getWidth() = 0;
virtual G4double getHeight() = 0;
void SetElementFieldName(G4String name) {elementFieldName=name;}
G4String GetElementFieldName() {return elementFieldName;}
void SetEventNrDependentField(G4double initialField, G4double finalField, G4int nrOfSteps);
std::map<G4int,G4double> GetEventNrDependentField() const {return changeFieldInStepsMap;}
void SetElementFieldValueIfNeeded(G4int eventNr);
virtual G4double GetNominalFieldValue() = 0;
virtual void SetNominalFieldValue(G4double newFieldValue) =0;
protected:
G4LogicalVolume* lvolume;
G4AffineTransform global2local;
// F04ElementField(const F04ElementField&);
private:
static G4Navigator* aNavigator;
G4String color;
G4ThreeVector center;
G4double minX, minY, minZ, maxX, maxY,maxZ;
G4double maxStep;
G4UserLimits* userLimits;
G4String elementFieldName;
std::map<G4int,G4double> changeFieldInStepsMap;
};
#endif

View File

@ -0,0 +1,73 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
#ifndef F04FieldMessenger_h
#define F04FieldMessenger_h 1
#include "globals.hh"
#include "G4UImessenger.hh"
class F04GlobalField;
class G4UIdirectory;
class G4UIcmdWithAString;
class G4UIcmdWithAnInteger;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithoutParameter;
class F04FieldMessenger: public G4UImessenger
{
public:
F04FieldMessenger(F04GlobalField* );
~F04FieldMessenger();
void SetNewValue(G4UIcommand*, G4String);
void SetNewValue(G4UIcommand*, G4int);
private:
F04GlobalField* fGlobalField;
G4UIdirectory* detDir;
G4UIcmdWithAnInteger* fStepperCMD;
G4UIcmdWithADoubleAndUnit* fMinStepCMD;
G4UIcmdWithADoubleAndUnit* fDeltaChordCMD;
G4UIcmdWithADoubleAndUnit* fDeltaOneStepCMD;
G4UIcmdWithADoubleAndUnit* fDeltaIntersectionCMD;
G4UIcmdWithADoubleAndUnit* fEpsMinCMD;
G4UIcmdWithADoubleAndUnit* fEpsMaxCMD;
G4UIcmdWithoutParameter* fUpdateCMD;
};
#endif

195
include/F04GlobalField.hh Normal file
View File

@ -0,0 +1,195 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
#ifndef F04GlobalField_h
#define F04GlobalField_h 1
#include <vector>
#include "G4FieldManager.hh"
#include "G4PropagatorInField.hh"
#include "G4MagIntegratorStepper.hh"
#include "G4ChordFinder.hh"
//#include "G4MagneticField.hh"
#include "G4ElectroMagneticField.hh"
#include "G4Mag_EqRhs.hh"
#include "G4Mag_SpinEqRhs.hh"
#include "G4EqMagElectricField.hh"
#include "G4EqEMFieldWithSpin.hh"
#include "F04FieldMessenger.hh"
#include "F04ElementField.hh"
// F04GlobalField - handles the global ElectroMagnetic field
//
// There is a single G04GlobalField object.
//
// The field from each individual beamline element is given by a
// ElementField object. Any number of overlapping ElementField
// objects can be added to the global field. Any element that
// represents an element with an EM field must add the appropriate
// ElementField to the global GlobalField object.
typedef std::vector<F04ElementField*> FieldList;
class F04GlobalField : public G4ElectroMagneticField {
//class F04GlobalField : public G4MagneticField {
private:
F04GlobalField();
F04GlobalField(const F04GlobalField&);
public:
~F04GlobalField();
private:
F04GlobalField& operator=(const F04GlobalField&);
void setupArray();
public:
/// getObject() returns the single F04GlobalField object.
/// It is constructed, if necessary.
static F04GlobalField* getObject();
//
static G4bool Exists() {if (object==NULL) {return false;} else {return true;}; }
/// GetFieldValue() returns the field value at a given point[].
/// field is really field[6]: Bx,By,Bz,Ex,Ey,Ez.
/// point[] is in global coordinates: x,y,z,t.
void GetFieldValue(const G4double* point, G4double* field) const;
/// DoesFieldChangeEnergy() returns true.
// cks - for testing just on magnetic field use DoesFieldChangeEnergy()=false;
G4bool DoesFieldChangeEnergy() const { return true; }
// G4bool DoesFieldChangeEnergy() const { return false; }
/// addElementField() adds the ElementField object for a single
/// element to the global field.
void addElementField(F04ElementField* f) { if (fields) fields->push_back(f); }
/// clear() removes all ElementField-s from the global object,
/// and destroys them. Used before the geometry is completely
/// re-created.
void clear();
/// updates all field tracking objects and clear()
void updateField();
/// Set the Stepper types
void SetStepperType( G4int i ) { fStepperType = i; }
/// Set the Stepper
void SetStepper();
/// Set the minimum step length
void SetMinStep(G4double s) { minStep = s; G4cout<<"F04GlobalField::SetMinStep: minStep set to "<<minStep/mm<<" mm."<<G4endl; }
/// Set the delta chord length
void SetDeltaChord(G4double s) { deltaChord = s; }
/// Set the delta one step length
void SetDeltaOneStep(G4double s) { deltaOneStep = s; }
/// Set the delta intersection length
void SetDeltaIntersection(G4double s) { deltaIntersection = s; }
/// Set the minimum eps length
void SetEpsMin(G4double s) { epsMin = s; }
/// Set the maximum eps length
void SetEpsMax(G4double s) { epsMax = s; }
/// Return the list of Element Fields
FieldList* getFields() { return fields; }
// G4bool DoesAnyFieldValueNeedsToBeChanged(G4int eventNumber) {return globalChangeFieldInStepsMap[eventNumber];}
void CheckWhetherAnyNominalFieldValueNeedsToBeChanged(G4int eventNumber);
// Add point, at which user wishes to print out the field value
void AddPointForFieldTesting(G4ThreeVector point) {pointsAtWhichUserWantsToPrintFieldValue.push_back(point);}
// Print field value at all points user wished to be print out:
void PrintFieldAtRequestedPoints() const;
protected:
/// Get the global field manager
G4FieldManager* GetGlobalFieldManager();
private:
static F04GlobalField* object;
G4int nfp;
G4bool first;
FieldList* fields;
const F04ElementField **fp;
std::vector<G4ThreeVector> pointsAtWhichUserWantsToPrintFieldValue;
private:
G4int fStepperType;
G4double minStep;
G4double deltaChord;
G4double deltaOneStep;
G4double deltaIntersection;
G4double epsMin;
G4double epsMax;
// G4Mag_EqRhs* fEquation;
// G4Mag_SpinEqRhs* fEquation;
// G4EqMagElectricField* fEquation;
G4EqEMFieldWithSpin* fEquation;
G4FieldManager* fFieldManager;
G4PropagatorInField* fFieldPropagator;
G4MagIntegratorStepper* fStepper;
G4ChordFinder* fChordFinder;
F04FieldMessenger* fFieldMessenger;
std::map<G4int,G4bool> globalChangeFieldInStepsMap;
};
#endif

71
include/MuDecayChannel.hh Normal file
View File

@ -0,0 +1,71 @@
// Geant4 simulation for MuSR
// AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI
// DATE : 2008-05
//
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4MuonDecayChannel.hh,v 1.6 2006/06/29 19:23:35 gunter Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
// ------------------------------------------------------------
// GEANT 4 class header file
//
// History: first implementation, based on object model of
// 30 May 1997 H.Kurashige
// ------------------------------------------------------------
#ifndef MuDecayChannel_h
#define MuDecayChannel_h 1
#include "G4ios.hh"
#include "globals.hh"
#include "G4VDecayChannel.hh"
class MuDecayChannel :public G4VDecayChannel
{
// Class Decription
// This class describes muon decay kinemtics.
// This version neglects muon polarization
// assumes the pure V-A coupling
// gives incorrect energy spectrum for neutrinos
//
public: // With Description
//Constructors
MuDecayChannel(const G4String& theParentName,
G4double theBR);
// Destructor
virtual ~MuDecayChannel();
public: // With Description
virtual G4DecayProducts *DecayIt(G4double);
};
#endif

View File

@ -0,0 +1,130 @@
// Geant4 simulation for MuSR
// AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI
// DATE : 2008-05
//
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// ------------------------------------------------------------
// GEANT 4 class header file
//
// History:
// 17 August 2004 P.Gumplinger and T.MacPhail
// samples Michel spectrum including 1st order
// radiative corrections
// Reference: Florian Scheck "Muon Physics", in Physics Reports
// (Review Section of Physics Letters) 44, No. 4 (1978)
// 187-248. North-Holland Publishing Company, Amsterdam
// at page 210 cc.
//
// W.E. Fisher and F. Scheck, Nucl. Phys. B83 (1974) 25.
//
// ------------------------------------------------------------
#ifndef MuDecayChannelWithSpin_hh
#define MuDecayChannelWithSpin_hh 1
#include "globals.hh"
#include "G4ThreeVector.hh"
#include "MuDecayChannel.hh"
class MuDecayChannelWithSpin : public MuDecayChannel
{
// Class Decription
// This class describes muon decay kinemtics.
// This version assumes V-A coupling with 1st order radiative correctons,
// the standard model Michel parameter values, but
// gives incorrect energy spectrum for neutrinos
public: // With Description
//Constructors
MuDecayChannelWithSpin(const G4String& theParentName,
G4double theBR);
// Destructor
virtual ~MuDecayChannelWithSpin();
public: // With Description
virtual G4DecayProducts *DecayIt(G4double);
void SetPolarization(G4ThreeVector);
const G4ThreeVector& GetPolarization() const;
private:
G4ThreeVector parent_polarization;
// Radiative Correction Factors
G4double F_c(G4double x, G4double x0);
G4double F_theta(G4double x, G4double x0);
G4double R_c(G4double x);
G4double EMMU;
G4double EMASS;
};
inline void MuDecayChannelWithSpin::SetPolarization(G4ThreeVector polar)
{
parent_polarization = polar;
}
inline const G4ThreeVector& MuDecayChannelWithSpin::GetPolarization() const
{
return parent_polarization;
}
inline G4double MuDecayChannelWithSpin::F_c(G4double x, G4double x0)
{
G4double omega = std::log(EMMU/EMASS);
G4double f_c;
f_c = (5.+17.*x-34.*x*x)*(omega+std::log(x))-22.*x+34.*x*x;
f_c = (1.-x)/(3.*x*x)*f_c;
f_c = (6.-4.*x)*R_c(x)+(6.-6.*x)*std::log(x) + f_c;
f_c = (fine_structure_const/twopi) * (x*x-x0*x0) * f_c;
return f_c;
}
inline G4double MuDecayChannelWithSpin::F_theta(G4double x, G4double x0)
{
G4double omega = std::log(EMMU/EMASS);
G4double f_theta;
f_theta = (1.+x+34*x*x)*(omega+std::log(x))+3.-7.*x-32.*x*x;
f_theta = f_theta + ((4.*(1.-x)*(1.-x))/x)*std::log(1.-x);
f_theta = (1.-x)/(3.*x*x) * f_theta;
f_theta = (2.-4.*x)*R_c(x)+(2.-6.*x)*std::log(x)-f_theta;
f_theta = (fine_structure_const/twopi) * (x*x-x0*x0) * f_theta;
return f_theta;
}
#endif

70
include/meyer.hh Normal file
View File

@ -0,0 +1,70 @@
// Geant4 simulation for MuSR
// AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI
// DATE : 2008-05
//
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//*
// LOW ENERGY MUON SPIN RELAXATION, ROTATION, RADIATION Geant4 SIMULATION
// ID : MEYER.hh , v 1.0
// AUTHOR: Taofiq PARAISO
// DATE : 2005-04
//
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
//
// & &&&&&&&&&& &&&&&&& &&&&&&&&
// & & && && & &&
// & & & & & & &&
// & &&&&&&& & & &&&&&& &&&&&&&&
// & & & && & & &&
// & & && & & && && & &
// &&&&&&&&&& &&&&&&&&&& & &&&&& && &&&&&&& & &&
// &
// &
// &
// &
// MEYER
/*
fIRST IMPLEMENTATION BY ANLSEM,H. IN FORTRAN
C++ CONVERSION T.K.PARAISO 04-2005
!!! IMPORTANT !!!
Notice:
Tables definition changes between FORTRAN and C++:
1/ Fortran indices start at 1 and C++ indices start at 0
2/ Tables are defined as table[column][row] in Fortran
table[row][column] in c++
usefull reference
http://gershwin.ens.fr/vdaniel/Doc-Locale/Langages-Program-Scientific/Fortran/Tutorial/arrays.htm
*/
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
#ifndef meyer_h
#define meyer_h 1
#include <iomanip>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <ios>
#include "globals.hh"
class meyer
{
public:
meyer();
~meyer();
void GFunctions(double*, double*, double);
void Get_F_Function_Meyer(double tau, double Ekin, double Z1, double Z2, double m1, double m2);
void F_Functions_Meyer( double tau,double thetaSchlange,double *f1,double *f2);
void Get_F_Function(double tau,double theta, double Ekin, double Z1, double Z2, double m1, double m2, double* F);
};
#endif

View File

@ -0,0 +1,60 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrDetectorConstruction_h
#define musrDetectorConstruction_h 1
#include "globals.hh"
#include "G4VUserDetectorConstruction.hh"
#include "G4ThreeVector.hh"
#include "G4RotationMatrix.hh"
#include "G4FieldManager.hh"
#include <map>
class G4Tubs;
class G4Box;
class G4Cons;
class G4Trd;
class G4LogicalVolume;
class G4VPhysicalVolume;
class G4Material;
class musrDetectorMessenger;
class musrScintSD;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrDetectorConstruction : public G4VUserDetectorConstruction
{
public:
musrDetectorConstruction();
~musrDetectorConstruction();
public:
G4VPhysicalVolume* Construct();
void UpdateGeometry();
void SetInputParameterFileName(G4String fileName) {parameterFileName=fileName;};
void ReportGeometryProblem(char myString[501]);
void ReportProblemInStearingFile(char* myString);
G4Material* CharToMaterial(char myString[100]);
G4LogicalVolume* FindLogicalVolume(G4String LogicalVolumeName);
void SetColourOfLogicalVolume(G4LogicalVolume* pLogVol,char* colour);
private:
G4String parameterFileName; // name of the file with the geometry parameters
G4bool checkOverlap; // parameter to check ovelaping volumes
G4double largestAcceptableStep; // parameter defining largest step in the magnetic field
musrScintSD* aScintSD;
musrDetectorMessenger* detectorMessenger; // pointer to the Messenger
std::map<std::string,G4RotationMatrix*> pointerToRotationMatrix;
std::map<std::string,G4FieldManager*> pointerToField;
private:
void DefineMaterials();
};
#endif

View File

@ -0,0 +1,49 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrDetectorMessenger_h
#define musrDetectorMessenger_h 1
#include "globals.hh"
#include "G4UImessenger.hh"
class musrDetectorConstruction;
class G4UIdirectory;
class G4UIcmdWithAString;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAnInteger;
class G4UIcmdWithoutParameter;
class G4UIcmdWith3Vector;
class G4UIcmdWith3VectorAndUnit;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrDetectorMessenger: public G4UImessenger
{
public:
musrDetectorMessenger(musrDetectorConstruction*);
~musrDetectorMessenger();
void SetNewValue(G4UIcommand*, G4String);
private:
musrDetectorConstruction* myDetector;
G4UIdirectory* musrDir;
G4UIdirectory* detDir;
G4UIdirectory* runDir;
G4UIcmdWithAString* Ignore1Cmd;
G4UIcmdWithAString* Ignore2Cmd;
G4UIcmdWithAnInteger* RunIDSetCmd;
G4UIcmdWithAnInteger* RandomOptionCmd;
G4UIcmdWithAnInteger* HowOftenToPrintEventCmd;
G4UIcmdWithAnInteger* RndmEventToSaveSeedsCmd;
G4UIcmdWithoutParameter* UpdateCmd;
public:
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif

View File

@ -0,0 +1,29 @@
#ifndef musrErrorMessage_h
#define musrErrorMessage_h 1
#include <map>
#include "globals.hh"
enum SEVERITY {INFO, WARNING, SERIOUS, FATAL};
typedef struct
{
SEVERITY mesSeverity;
int nTimes;
} ErrorStruct;
class musrErrorMessage {
public:
musrErrorMessage();
~musrErrorMessage();
static musrErrorMessage* GetInstance();
void musrError(SEVERITY severity, G4String message, G4bool silent);
void PrintErrorSummary();
private:
static musrErrorMessage* pointerToErrors;
G4int nErrors;
// std::map<G4String,int> ErrorMapping;
std::map<G4String,ErrorStruct> ErrorMapping;
std::map<SEVERITY,G4String> severityWord;
};
#endif

View File

@ -0,0 +1,43 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrEventAction_h
#define musrEventAction_h 1
#include "globals.hh"
#include "G4UserEventAction.hh"
class G4Timer;
class G4Event;
class musrMagneticField;
class musrTabulatedField3D;
class musrTabulatedField2D;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrEventAction : public G4UserEventAction
{
public:
musrEventAction();
~musrEventAction();
public:
void BeginOfEventAction(const G4Event*);
void EndOfEventAction(const G4Event*);
static musrEventAction* GetInstance();
private:
// pointer to this class
static musrEventAction* pointer;
//
G4Timer* timer;
// Variables for the time-dependent magnetic field
G4bool timeDependentField;
time_t timeOfRunStart;
public:
static G4int nHowOftenToPrintEvent;
static G4double maximumRunTimeAllowed;
};
#endif

View File

@ -0,0 +1,80 @@
// Geant4 simulation for MuSR
// AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI
// DATE : 2008-05
//
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// Muonium Formation according to yield.cc function (through GetYields method).
// Id : musrMuFormation.hh, v 1.4
// Author: Taofiq PARAISO, T. Shiroka
// Date : 2007-12
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#ifndef musrMuFormation_h
#define musrMuFormation_h 1
#include "G4VDiscreteProcess.hh"
#include "G4ParticleTable.hh"
#include "yields.hh"
/*! musrMuFormation class defines the muonium formation process in the Carbon foil
* according to yields from Gonin's paper Sci. Rev. Instrum. 65(3), 648-652 (1994).
* \image html yields3.gif The muonium formation yields.
* The main parameters are the foil thickness and muon energy. For a given energy,
* a corresponding proportion of the muons will be converted into Muonium.
* Concretely, the muon is eliminated and replaced by a Muonium with identical
* properties, including time, energy, momentum, position etc.
*
* The process is executed at the END of a step, i.e. the muon is converted into
* Muonium AFTER flying through the Carbon foil (see also yields.hh). */
class musrMuFormation : public G4VDiscreteProcess
{
public:
musrMuFormation(const G4String& name = "MuFormation", // process description
G4ProcessType aType = fElectromagnetic);
~musrMuFormation();
//! - Main method. Muonium formation process is executed at the END of a step. */
G4VParticleChange* PostStepDoIt(
const G4Track&,
const G4Step&);
G4double GetMeanFreePath(const G4Track& aTrack,
G4double previousStepSize,
G4ForceCondition* condition);
//! Condition for process application (step Object).
G4bool CheckCondition(const G4Step& aStep);
//! Condition for process application (step Pointer).
G4bool CheckCondition(const G4Step* aStep);
G4String p_name;
G4bool condition;
void GetDatas( const G4Step* aStep);
// model parameters
G4ParticleTable* particleTable;
G4ParticleDefinition* particle;
Yields Gonin;
G4double yvector[3];
G4double rnd;
G4DynamicParticle *DP;
//! The particle change object.
G4VParticleChange fParticleChange;
void PrepareSecondary(const G4Track&);
G4Track* aSecondary;
void InitializeSecondaries(const G4Track&);
};
#endif

57
include/musrMuScatter.hh Normal file
View File

@ -0,0 +1,57 @@
// Geant4 simulation for MuSR
// AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI
// DATE : 2008-05
//
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// Muonium "Scattering"
// Id : musrMuScatter.hh, v 1.4
// Author: Taofiq PARAISO, T. Shiroka
// Date : 2007-12
// Notes : Simplified model for Mu scattering. Spin effects have been excluded.
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*!
* musrMuScatter class defines the Muonium scattering process. It implements a very
* basic model which assumes Muonium looses its electron as soon as it enters any
* material (except for vacuum and CFoil). The class has only a PostStepDoIt method.
* The in-flight Muonium spin precession has been supressed. */
#ifndef musrMuScatter_h
#define musrMuScatter_h 1
#include "G4VDiscreteProcess.hh"
class musrMuScatter : public G4VDiscreteProcess
{
public:
musrMuScatter(const G4String& name="MuScatt", // process description
G4ProcessType aType = fGeneral);
~musrMuScatter();
//! \mm The actions are taken at the end of the step.
G4VParticleChange* PostStepDoIt(const G4Track&,
const G4Step&);
G4double GetMeanFreePath(const G4Track& aTrack,
G4double previousStepSize,
G4ForceCondition* condition);
//! The condition for applying the process.
G4bool CheckCondition(const G4Step& aStep);
G4bool condition;
G4double itime, gtime, ftime,deltatime;
G4String p_name;
G4DynamicParticle *DP;
G4ParticleChange fParticleChange;
void PrepareSecondary(const G4Track&);
G4Track* aSecondary;
void InitializeSecondaries(const G4Track&);
};
#endif

77
include/musrMuonium.hh Normal file
View File

@ -0,0 +1,77 @@
// Geant4 simulation for MuSR
// AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI
// DATE : 2008-05
//
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: musrMuonium.hh,v 1.10 2006/06/29 19:20:21 gunter Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
// ------------------------------------------------------------
// GEANT 4 class header file
//
// History: first implementation, based on object model of
// 4-th April 1996, G.Cosmo
// ****************************************************************
// New implementation as a utility class M.Asai, 26 July 2004
// ----------------------------------------------------------------
#ifndef musrMuonium_h
#define musrMuonium_h 1
#include "globals.hh"
#include "G4ios.hh"
#include "G4ParticleDefinition.hh"
// ######################################################################
// ### MUONIUM ###
// ######################################################################
class musrMuonium : public G4ParticleDefinition
{
private:
static musrMuonium* theInstance;
musrMuonium(){}
~musrMuonium(){}
public:
static musrMuonium* Definition();
static musrMuonium* MuoniumDefinition();
static musrMuonium* Muonium();
};
#endif

44
include/musrParameters.hh Normal file
View File

@ -0,0 +1,44 @@
#ifndef musrParameters_h
#define musrParameters_h 1
#include "globals.hh"
class musrParameters {
public:
musrParameters(G4String steeringFileName);
~musrParameters();
static musrParameters* GetInstance();
static G4String mySteeringFileName; // name of the steering file (e.g. the *.mac file)
static G4bool storeOnlyEventsWithHits; // variable specifying whether to store interesting
// or all events into the ROOT tree. (default = true)
static G4int storeOnlyEventsWithHitInDetID; // simillar to "storeOnlyEventsWithHits". The event is stored
// only and only if there was a hit in the detector with the ID
// equal to storeOnlyEventsWithHitInDetID.
// The storeOnlyEventsWithHitInDetID has to be non zero.
static G4double signalSeparationTime; // minimim time separation between two subsequent signal
static G4bool storeOnlyTheFirstTimeHit; // if true, only the hit that happened first will be
// stored, anything else will be ignored
// (usefull for some special studies, not for a serious simulation)
static G4bool killAllPositrons; // if true, all positron tracks will be deleted (usefull for the studies of the muon beam)
static G4bool killAllGammas; //
static G4bool killAllNeutrinos; //
//cks static G4bool includeMuoniumProcesses; // If true, includes Muonium formation and all
//cks // other Mu-related processes in the simulation
static G4bool boolG4GeneralParticleSource; // if true, G4GeneralParticleSource will be initialised instead of G4ParticleGun
// - needed for the radioactive source
static G4bool boolG4OpticalPhotons; // if true, optical photons will be used (in the sensitive scintillators)
static G4bool field_DecayWithSpin; // if true, then the routins for calculating the magnetic field will
// use more precise argument. This variable is set to "true" by
// the SteppinAction and reset to "false" in the GetFieldValue.
// It is being changed on step by step basis.
static G4int nrOfEventsToBeGenerated; // Nr of events to be simulated in this run (set by /run/beamOn command)
private:
static musrParameters* pointerToParameters;
G4bool boolG4RegionRequested; // variable used internally just to check that no new volume is defined after
// a G4Region has been requested - perhaps unnecessary check, but just to be on the safe side
};
#endif

View File

@ -0,0 +1,52 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrPhysicsList_h
#define musrPhysicsList_h 1
#include "G4VUserPhysicsList.hh"
#include "globals.hh"
//cks Added to have Geant default muon decay with spin
#include "G4DecayWithSpin.hh"
//#include "musrDecayWithSpin.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrPhysicsList: public G4VUserPhysicsList
{
public:
musrPhysicsList();
~musrPhysicsList();
protected:
// Construct particle and physics
void ConstructParticle();
void ConstructProcess();
void SetCuts();
protected:
// these methods Construct particles
void ConstructBosons();
void ConstructLeptons();
void ConstructMesons();
void ConstructBaryons();
protected:
// these methods Construct physics processes and register them
void ConstructGeneral();
void ConstructEM();
private:
// char myProcesses[100];
// G4String parameterFileName; // name of the file with the physics list defined
void ReportProblemWithProcessDefinition(char myString[501]);
G4Region* FindG4Region(G4String regionName, char* lineOfSteeringFile);
char eMessage[200];
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif

View File

@ -0,0 +1,108 @@
#ifndef musrPrimaryGeneratorAction_h
#define musrPrimaryGeneratorAction_h 1
#include "G4VUserPrimaryGeneratorAction.hh"
#include "globals.hh"
#include "Randomize.hh"
#include "G4ThreeVector.hh"
#include "G4ParticleDefinition.hh"
#include <stdio.h>
#include <vector>
class G4GeneralParticleSource;
class G4ParticleGun;
class G4Event;
class musrDetectorConstruction;
class musrPrimaryGeneratorMessenger;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
class musrPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
{
public:
musrPrimaryGeneratorAction(musrDetectorConstruction*);
~musrPrimaryGeneratorAction();
public:
void GeneratePrimaries(G4Event*);
void SetRndmFlag(G4String val) { rndmFlag = val;}
void Setvertex(G4ThreeVector v) {x0=v[0]; y0=v[1]; z0=v[2];}
void SetvertexSigma(G4ThreeVector v) {xSigma=v[0]; ySigma=v[1]; zSigma=v[2];}
void SetvertexBoundary(G4ThreeVector v) {rMaxAllowed=v[0]; zMinAllowed=v[1]; zMaxAllowed=v[2];}
void SetKEnergy(G4double val);
void SetMomentum(G4double val) {p0=val;}
void SetMomentumSmearing(G4double val) {pSigma=val;}
void SetMomentumBoundary(G4ThreeVector v){pMinAllowed=v[0]; pMaxAllowed=v[1];}
void SetTilt(G4ThreeVector v) {xangle0=v[0]; yangle0=v[1];}
void SetSigmaTilt(G4ThreeVector v) {xangleSigma=v[0]; yangleSigma=v[1];}
void SetPitch(G4double val) {pitch=val;}
void SetInitialMuonPolariz(G4ThreeVector vIniPol);
void SetInitialPolarizFraction(G4double val) {
if ((val>1.)||(val<-1.)) {
G4cout<<"musrPrimaryGeneratorAction.hh: SetInitialPolarizFraction(): polarisation fraction out of range ("<<val<<")"<<G4endl;
exit(1);
}
polarisFraction=val;
}
void SetMuonDecayTimeLimits(G4ThreeVector decayTimeLimits);
void SetTurtleInput(G4String turtleFileName);
void SetTurtleInputFileToEventNo(G4int lineNumberOfTurtleFile);
void SetTurtleZ0(G4double val) {z0_InitialTurtle=val;}
void SetOrReadTheRandomNumberSeeds(G4int eventID);
void SetTurtleMomentumBite (G4ThreeVector smearingParam)
{turtleMomentumBite=true; turtleMomentumP0=smearingParam[0]*MeV; turtleSmearingFactor=smearingParam[1]*0.01;}
static G4String GetPrimaryName();
private:
G4ParticleGun* particleGun; // pointer a to G4 service class
G4GeneralParticleSource* particleSource; // pointer to the G4GeneralParticleSource, needed for radioactive samples
musrDetectorConstruction* musrDetector; // pointer to the geometry
musrPrimaryGeneratorMessenger* gunMessenger; // messenger of this class
G4String rndmFlag; // flag for a random impact point
// cks Implement also alpha and proton particles for the simulation of Juan Pablo Urrego
G4ParticleDefinition* alphaParticle;
G4ParticleDefinition* protonParticle;
// csk
static G4String thePrimaryParticleName ;
G4double x0, y0, z0, xSigma, ySigma, zSigma, rMaxAllowed, zMinAllowed, zMaxAllowed;
G4double p0, pSigma, pMinAllowed, pMaxAllowed;
G4double xangle0, yangle0, xangleSigma, yangleSigma, pitch;
G4bool UnpolarisedMuonBeam, TransversalyUnpolarisedMuonBeam;
G4double xPolarisIni, yPolarisIni, zPolarisIni;
G4double polarisFraction;
G4double muonDecayTimeMin;
G4double muonDecayTimeMax;
G4double muonMeanLife;
// For the Turtle input:
FILE* fTurtleFile;
G4bool takeMuonsFromTurtleFile;
G4double z0_InitialTurtle; // z0 at whith the turtle file was generated.
G4int numberOfGeneratedEvents; // number of generated events at the input (e.g. including Turtle events out of the beampipe)
G4bool boolPrintInfoAboutGeneratedParticles;
G4bool turtleMomentumBite;
G4double turtleMomentumP0;
G4double turtleSmearingFactor;
public:
static G4bool setRandomNrSeedAccordingEventNr;
static G4bool setRandomNrSeedFromFile;
static G4bool setRandomNrSeedFromFile_RNDM;
static G4int nRndmEventToSaveSeeds;
static std::vector<int> * GetPointerToSeedVector();
G4double decaytime;
private:
static std::vector<int> * pointerToSeedVector;
};
#endif

View File

@ -0,0 +1,46 @@
#ifndef musrPrimaryGeneratorMessenger_h
#define musrPrimaryGeneratorMessenger_h 1
#include "G4UImessenger.hh"
#include "globals.hh"
class musrPrimaryGeneratorAction;
class G4UIcmdWithAString;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithADouble;
class G4UIcmdWithAnInteger;
class G4UIcmdWith3VectorAndUnit;
class G4UIcmdWith3Vector;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
class musrPrimaryGeneratorMessenger: public G4UImessenger
{
public:
musrPrimaryGeneratorMessenger(musrPrimaryGeneratorAction*);
~musrPrimaryGeneratorMessenger();
void SetNewValue(G4UIcommand*, G4String);
private:
musrPrimaryGeneratorAction* musrAction;
G4UIcmdWith3VectorAndUnit* setvertexCmd;
G4UIcmdWith3VectorAndUnit* setvertexSigmaCmd;
G4UIcmdWith3VectorAndUnit* setvertexBoundaryCmd;
G4UIcmdWithADoubleAndUnit* setKEnergyCmd;
G4UIcmdWithADoubleAndUnit* setMomentumCmd;
G4UIcmdWithADoubleAndUnit* setMomentumSmearingCmd;
G4UIcmdWith3VectorAndUnit* setMomentumBoundaryCmd;
G4UIcmdWith3VectorAndUnit* setTiltAngleCmd;
G4UIcmdWith3VectorAndUnit* setSigmaTiltAngleCmd;
G4UIcmdWithADoubleAndUnit* setPitchCmd;
G4UIcmdWith3Vector* setMuonPolarizCmd;
G4UIcmdWithADouble* setMuonPolarizFractionCmd;
G4UIcmdWith3VectorAndUnit* setMuonDecayTimeCmd;
G4UIcmdWithAString* setTurtleCmd;
G4UIcmdWithADoubleAndUnit* setTurtleZ0Cmd;
G4UIcmdWith3Vector* setTurtleMomentumBite;
G4UIcmdWithAnInteger* setTurtleEventNrCmd;
};
#endif

49
include/musrQuadrupole.hh Normal file
View File

@ -0,0 +1,49 @@
#ifndef musrQuadrupole_h
#define musrQuadrupole_h 1
#include "globals.hh"
#include "F04ElementField.hh"
#include "F04GlobalField.hh"
//#include "G4ios.hh"
#include "BLEngeFunction.hh"
//#include <fstream>
//#include <vector>
//#include <cmath>
const G4double FRINGE_ACCURACY=1.0e-4;
class musrQuadrupole : public F04ElementField
{
public:
musrQuadrupole(G4double halflengthVal, G4double fieldRadiusVal, G4double gradientVal, G4double fringeFactorVal, G4LogicalVolume* logVolume, G4ThreeVector positionOfTheCenter);
// musrQuadrupole is based on "BLCMDgenericquad" class of the G4beamline package.
//
/// Destructor.
virtual ~musrQuadrupole() {}
/// addFieldValue() adds the field for this solenoid into field[].
/// point[] is in global coordinates.
void addFieldValue( const G4double Point[4], G4double* field) const;
G4double GetNominalFieldValue();
void SetNominalFieldValue(G4double newFieldValue);
// getWidth(), getHeight(), getLength(), return the dimensions of the field
// (used to define the boundary of the field)
virtual G4double getWidth() { return 2*fieldRadius; } // x coordinate
virtual G4double getHeight() { return 2*fieldRadius; } // y coordinate
virtual G4double getLength() { return 2*fringeMaxZ; } //{ return 2*halflength; } // z coordinate
private:
G4double gradient;
G4double fieldRadius;
G4double halflength;
G4double fringeMaxZ;
G4double fringeDepth;
BLEngeFunction enge;
};
#endif

291
include/musrRootOutput.hh Normal file
View File

@ -0,0 +1,291 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrRootOutput_h
#define musrRootOutput_h 1
//#include "G4UserRunAction.hh"
#include "globals.hh"
#include "G4ThreeVector.hh"
// ROOT
#include "TFile.h"
#include "TTree.h"
#include "TH1.h"
#include "TH2.h"
#include "TVectorD.h"
//
#include <map>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrRootOutput {
public:
musrRootOutput();
~musrRootOutput();
static musrRootOutput* GetRootInstance();
public:
void BeginOfRunAction();
void EndOfRunAction();
void FillEvent();
void ClearAllRootVariables();
void SetVolumeIDMapping(std::string logivol, int volumeID);
G4int ConvertVolumeToID(std::string logivol);
G4int ConvertProcessToID(std::string processName);
void SetSpecialSaveVolumeDefined() {boolIsAnySpecialSaveVolumeDefined=true;};
// Getting variables (just for debugging)
G4double GetDecayPositionZ() {return muDecayPosZ_t;};
G4double GetDecayTime() {return muDecayTime_t*microsecond;};
G4double GetTimeInTarget() {return muTargetTime_t*microsecond;};
// Setting variables common to the whole event:
void SetRunID (G4int id) {runID_t = id;};
void SetEventID (G4int id) {eventID_t = id;};
void SetDecayDetectorID (std::string detectorName) {muDecayDetID_t = SensDetectorMapping[detectorName];};
void SetBField (G4double F[6]) {B_t[0]=F[0]/tesla; B_t[1]=F[1]/tesla; B_t[2]=F[2]/tesla;
B_t[3]=F[3]/tesla; B_t[4]=F[4]/tesla; B_t[5]=F[5]/tesla;};
void SetDecayPolarisation (G4ThreeVector pol) {muDecayPolX_t=pol.x(); muDecayPolY_t=pol.y(); muDecayPolZ_t=pol.z();};
void SetDecayPosition (G4ThreeVector pos) {muDecayPosX_t=pos.x()/mm; muDecayPosY_t=pos.y()/mm;
muDecayPosZ_t=pos.z()/mm;};
void SetEventWeight (G4double w) {weight_t *= w;}
void SetDetectorInfo (G4int nDetectors, G4int ID, G4int particleID, G4double edep,
G4double edep_el, G4double edep_pos,
G4double edep_gam, G4double edep_mup,G4int nsteps, G4double length, G4double t1,
G4double t2, G4double x, G4double y, G4double z,
G4double ek, G4double ekVertex, G4double xVertex, G4double yVertex, G4double zVertex,
G4int idVolVertex, G4int idProcVertex, G4int idTrackVertex) ;
void SetDetectorInfoVvv (G4int nDetectors,
G4double ekVertex, G4double xVertex, G4double yVertex, G4double zVertex,
G4int idVolVertex, G4int idProcVertex, G4int idTrackVertex, G4int particleID) ;
void SetSaveDetectorInfo (G4int ID, G4int particleID, G4double ke, G4double x, G4double y, G4double z,
G4double px, G4double py, G4double pz) ;
void SetInitialMuonParameters(G4double x, G4double y, G4double z, G4double px, G4double py, G4double pz,
G4double xpolaris, G4double ypolaris, G4double zpolaris) {
muIniPosX_t=x; muIniPosY_t=y; muIniPosZ_t=z;
muIniMomX_t=px; muIniMomY_t=py; muIniMomZ_t=pz;
muIniPolX_t=xpolaris; muIniPolY_t=ypolaris; muIniPolZ_t=zpolaris;
}
void PrintInitialMuonParameters() {
G4cout<<"musrRootOutput.hh: Initial muon parameters: x="<<muIniPosX_t<<", y="<<muIniPosY_t<<", z="<<muIniPosZ_t
<<", px="<<muIniMomX_t << ", py="<<muIniMomY_t<<", pz="<<muIniMomZ_t<<G4endl;
G4cout<<" polx="<<muIniPolX_t<<", poly="<<muIniPolY_t<<", polz="<<muIniPolZ_t<<G4endl;
G4cout<<" numberOfGeneratedEvents = "<<GeantParametersD[7]<<G4endl;
}
void SetPolInTarget(G4ThreeVector pol) {muTargetPolX_t=pol.x(); muTargetPolY_t=pol.y(); muTargetPolZ_t=pol.z();};
void SetTimeInTarget(G4double time) {muTargetTime_t = time/microsecond;};
void SetPolInM0(G4ThreeVector pol) {muM0PolX_t=pol.x(); muM0PolY_t=pol.y(); muM0PolZ_t=pol.z();};
void SetTimeInM0(G4double time) {muM0Time_t = time/microsecond;};
void SetPolInM1(G4ThreeVector pol) {muM1PolX_t=pol.x(); muM1PolY_t=pol.y(); muM1PolZ_t=pol.z();};
void SetTimeInM1(G4double time) {muM1Time_t = time/microsecond;};
void SetPolInM2(G4ThreeVector pol) {muM2PolX_t=pol.x(); muM2PolY_t=pol.y(); muM2PolZ_t=pol.z();};
void SetTimeInM2(G4double time) {muM2Time_t = time/microsecond;};
void SetInitialPositronMomentum(G4ThreeVector mom) {posIniMomx_t=mom.x(); posIniMomy_t=mom.y(); posIniMomz_t=mom.z();};
void SetDecayTime(G4double time) {muDecayTime_t=time/microsecond;};
void SetNrFieldNomVal(G4int n) {nFieldNomVal = n;}
void SetFieldNomVal(G4int i, G4double value);
G4int GetNrOfVolumes() {return det_nMax;}
void SetBFieldIntegral(G4double BxInt,G4double ByInt,G4double BzInt,G4double BzInt1,G4double BzInt2,G4double BzInt3) {
BxIntegral_t=BxInt/m/tesla; ByIntegral_t=ByInt/m/tesla; BzIntegral_t=BzInt/m/tesla;
BzIntegral1_t=BzInt1/m/tesla;BzIntegral2_t=BzInt2/mm;BzIntegral3_t=BzInt3/mm;
}
void StoreGeantParameter(Int_t i, Double_t value) {
if (i<maxNGeantParameters) { GeantParametersD[i]=value; }
else {G4cout<<"musrRootOutput.hh::StoreGeantParameter: index="<<i<<" out of range"
<<" (maxNGeantParameters=" <<maxNGeantParameters<<")"<<G4endl;}
};
TH2F *htest1, *htest2;
TH1F *htest3, *htest4, *htest5, *htest6, *htest7, *htest8;
public:
static G4bool store_runID;
static G4bool store_eventID;
static G4bool store_weight;
static G4bool store_BFieldAtDecay;
static G4bool store_muIniPosX;
static G4bool store_muIniPosY;
static G4bool store_muIniPosZ;
static G4bool store_muIniMomX;
static G4bool store_muIniMomY;
static G4bool store_muIniMomZ;
static G4bool store_muIniPolX;
static G4bool store_muIniPolY;
static G4bool store_muIniPolZ;
static G4bool store_muDecayDetID;
static G4bool store_muDecayPosX;
static G4bool store_muDecayPosY;
static G4bool store_muDecayPosZ;
static G4bool store_muDecayTime;
static G4bool store_muDecayPolX;
static G4bool store_muDecayPolY;
static G4bool store_muDecayPolZ;
static G4bool store_muTargetTime;
static G4bool store_muTargetPolX;
static G4bool store_muTargetPolY;
static G4bool store_muTargetPolZ;
static G4bool store_muM0Time;
static G4bool store_muM0PolX;
static G4bool store_muM0PolY;
static G4bool store_muM0PolZ;
static G4bool store_muM1Time;
static G4bool store_muM1PolX;
static G4bool store_muM1PolY;
static G4bool store_muM1PolZ;
static G4bool store_muM2Time;
static G4bool store_muM2PolX;
static G4bool store_muM2PolY;
static G4bool store_muM2PolZ;
static G4bool store_posIniMomX;
static G4bool store_posIniMomY;
static G4bool store_posIniMomZ;
static G4bool store_det_ID;
static G4bool store_det_edep;
static G4bool store_det_edep_el;
static G4bool store_det_edep_pos;
static G4bool store_det_edep_gam;
static G4bool store_det_edep_mup;
static G4bool store_det_nsteps;
static G4bool store_det_length;
static G4bool store_det_start;
static G4bool store_det_end;
static G4bool store_det_x;
static G4bool store_det_y;
static G4bool store_det_z;
static G4bool store_det_kine;
static G4bool store_det_VrtxKine;
static G4bool store_det_VrtxX;
static G4bool store_det_VrtxY;
static G4bool store_det_VrtxZ;
static G4bool store_det_VrtxVolID;
static G4bool store_det_VrtxProcID;
static G4bool store_det_VrtxTrackID;
static G4bool store_det_VrtxParticleID;
static G4bool store_det_VvvKine;
static G4bool store_det_VvvX;
static G4bool store_det_VvvY;
static G4bool store_det_VvvZ;
static G4bool store_det_VvvVolID;
static G4bool store_det_VvvProcID;
static G4bool store_det_VvvTrackID;
static G4bool store_det_VvvParticleID;
static G4bool store_fieldNomVal;
static G4bool store_fieldIntegralBx;
static G4bool store_fieldIntegralBy;
static G4bool store_fieldIntegralBz;
static G4bool store_fieldIntegralBz1;
static G4bool store_fieldIntegralBz2;
static G4bool store_fieldIntegralBz3;
static G4int oldEventNumberInG4EqEMFieldWithSpinFunction;
private:
TFile* rootFile;
TTree* rootTree;
static musrRootOutput* pointerToRoot;
static const Int_t maxNGeantParameters=30;
Double_t GeantParametersD[maxNGeantParameters]; // parameters transfered from GEANT to Root
// 0 ... fieldOption: 0 ... no field, 1 ... uniform, 2 ... gaussian, 3 ... from table
// 1 ... fieldValue: intensity of the magnetic field
// 2 ... minimum of the generated decay time of the muon (in microsecond)
// 3 ... maximum of the generated decay time of the muon (in microsecond)
// 4 ... muon mean life time (in microsecond)
// 5 ... nr. of the last generated event
// 6 ... run number
// 7 ... numberOfGeneratedEvents (i.e. number of the generated events;
// in case of Turtle nr. of events tried);
// Variables common to the whole event:
Int_t runID_t;
Int_t eventID_t;
Double_t weight_t;
Double_t B_t[6];
Double_t muIniPosX_t, muIniPosY_t, muIniPosZ_t;
Double_t muIniMomX_t, muIniMomY_t, muIniMomZ_t;
Double_t muIniPolX_t, muIniPolY_t, muIniPolZ_t;
Int_t muDecayDetID_t;
Double_t muDecayPolX_t, muDecayPolY_t, muDecayPolZ_t;
Double_t muTargetTime_t, muTargetPolX_t, muTargetPolY_t, muTargetPolZ_t;
Double_t muM0Time_t, muM0PolX_t, muM0PolY_t, muM0PolZ_t;
Double_t muM1Time_t, muM1PolX_t, muM1PolY_t, muM1PolZ_t;
Double_t muM2Time_t, muM2PolX_t, muM2PolY_t, muM2PolZ_t;
Double_t muDecayPosX_t, muDecayPosY_t, muDecayPosZ_t;
Double_t muDecayTime_t;
Double_t posIniMomx_t, posIniMomy_t, posIniMomz_t;
public:
static const Int_t maxNFieldnNominalValues=30;
private:
Int_t nFieldNomVal;
Double_t fieldNomVal[maxNFieldnNominalValues];
Double_t BxIntegral_t, ByIntegral_t, BzIntegral_t;
Double_t BzIntegral1_t, BzIntegral2_t, BzIntegral3_t;
// Variables for a particle in a given detector within the event
public:
static const Int_t maxNSubTracks=30;
private:
// Variables for the activity inside a given detector
public:
static const Int_t det_nMax=100; // must be by 1 higher than the real number of detector "hits", because
// else the detector nr. 0 is counted (0 is used if no
// SensDetectorMapping correspond to a given logical volume).
private:
G4int det_n;
G4int det_ID[det_nMax];
G4double det_edep[det_nMax];
G4int det_nsteps[det_nMax];
G4double det_length[det_nMax];
G4double det_edep_el[det_nMax];
G4double det_edep_pos[det_nMax];
G4double det_edep_gam[det_nMax];
G4double det_edep_mup[det_nMax];
G4double det_time_start[det_nMax];
G4double det_time_end[det_nMax];
G4double det_x[det_nMax];
G4double det_y[det_nMax];
G4double det_z[det_nMax];
G4double det_kine[det_nMax];
G4double det_VrtxKine[det_nMax];
G4double det_VrtxX[det_nMax];
G4double det_VrtxY[det_nMax];
G4double det_VrtxZ[det_nMax];
G4int det_VrtxVolID[det_nMax];
G4int det_VrtxProcID[det_nMax];
G4int det_VrtxTrackID[det_nMax];
G4int det_VrtxParticleID[det_nMax];
G4double det_VvvKine[det_nMax];
G4double det_VvvX[det_nMax];
G4double det_VvvY[det_nMax];
G4double det_VvvZ[det_nMax];
G4int det_VvvVolID[det_nMax];
G4int det_VvvProcID[det_nMax];
G4int det_VvvTrackID[det_nMax];
G4int det_VvvParticleID[det_nMax];
public:
static const Int_t save_nMax=2000;
private:
G4int save_n;
G4int save_detID[save_nMax];
G4int save_particleID[save_nMax];
G4double save_ke[save_nMax];
G4double save_x[save_nMax];
G4double save_y[save_nMax];
G4double save_z[save_nMax];
G4double save_px[save_nMax];
G4double save_py[save_nMax];
G4double save_pz[save_nMax];
G4bool boolIsAnySpecialSaveVolumeDefined;
std::map<std::string,int> SensDetectorMapping;
std::map<std::string,int> ProcessIDMapping;
};
#endif

36
include/musrRunAction.hh Normal file
View File

@ -0,0 +1,36 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrRunAction_h
#define musrRunAction_h 1
#include "G4UserRunAction.hh"
#include "globals.hh"
#include "musrRootOutput.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class G4Timer;
class G4Run;
class musrRunAction : public G4UserRunAction
{
public:
musrRunAction();
~musrRunAction();
public:
void BeginOfRunAction(const G4Run*);
void EndOfRunAction(const G4Run*);
private:
G4Timer* timer;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif

139
include/musrScintHit.hh Normal file
View File

@ -0,0 +1,139 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrScintHit_h
#define musrScintHit_h 1
#include "G4VHit.hh"
#include "G4THitsCollection.hh"
#include "G4Allocator.hh"
#include "G4ThreeVector.hh"
#include "G4MagneticField.hh"
#include "globals.hh"
#include "G4ios.hh"
// ROOT
#include "TFile.h"
#include "TTree.h"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrScintHit : public G4VHit
{
public:
musrScintHit();
~musrScintHit();
musrScintHit(const musrScintHit&);
const musrScintHit& operator=(const musrScintHit&);
G4int operator==(const musrScintHit&) const;
// bool operator() (musrScintHit hit1, musrScintHit hit2) { return (hit1.globalTime<hit2.globalTime);}
inline void* operator new(size_t);
inline void operator delete(void*);
void Draw();
void Print();
public:
void SetParticleName (G4String name) {particleName = name; }
void SetParticleID (G4int id) {particleID = id; }
void SetTrackID (G4int track) { trackID = track; }
void SetEdep (G4double de) { edep = de; }
void SetPrePos (G4ThreeVector xyz){ pre_pos = xyz; }
void SetPostPos (G4ThreeVector xyz){ post_pos = xyz; }
void SetPol (G4ThreeVector ijk){pol = ijk;}
void SetLogVolName (G4String logivol) {logicalVolume = logivol;}
void SetGlobTime (G4double gt) { globalTime = gt;}
void SetFirstStepInVolumeFlag (G4bool flag) { firstStepInVolume=flag;}
void SetLastStepInVolumeFlag (G4bool flag) { lastStepInVolume=flag;}
void SetKineticEnergy (G4double en) { kineticEnergy = en;}
void SetStepLength (G4double length) { stepLength = length;}
void SetRunID(G4int i) {runID=i;}
void SetEventID(G4int i) {eventID=i;}
void SetVertexPosition(G4ThreeVector xyz) {vertexPosition = xyz; }
void SetVertexKineticEnergy(G4double Ek) {vertexKineticEnergy = Ek; }
void SetLogicalVolumeAtVertex(G4String logivol) {logicalVolumeAtVertex = logivol; }
void SetCreatorProcessName(G4String name) {creatorProcess = name; }
// void SetVerboseLevel (G4int n) { G4int musrScintHit::verboseLevel=n;};
G4String GetParticleName() {return particleName; }
G4int GetParticleID() {return particleID; }
G4int GetTrackID() { return trackID; }
G4double GetEdep() { return edep; }
G4ThreeVector GetPrePos(){ return pre_pos; }
G4ThreeVector GetPostPos(){ return post_pos; }
G4ThreeVector GetPol(){ return pol; }
G4String GetLogVolName() { return logicalVolume; }
G4double GetGlobalTime() { return globalTime; }
G4bool GetFirstStepInVolumeFlag() {return firstStepInVolume;}
G4bool GetLastStepInVolumeFlag() {return lastStepInVolume;}
G4double GetKineticEnergy() { return kineticEnergy; }
G4double GetStepLength() {return stepLength; }
G4double* GetBField () {return BF;}
G4int GetRunID() {return runID;}
G4int GetEventID() {return eventID;}
G4ThreeVector GetVertexPosition() { return vertexPosition; }
G4double GetVertexKineticEnergy() { return vertexKineticEnergy; }
G4String GetLogicalVolumeAtVertex() { return logicalVolumeAtVertex; }
G4String GetCreatorProcessName() { return creatorProcess; }
G4double point[4];
G4double B[6];
const G4Field *mfield;
private:
G4String particleName;
G4int particleID;
G4int trackID;
G4double edep;
G4ThreeVector pre_pos;
G4ThreeVector post_pos;
G4ThreeVector pol;
G4String logicalVolume;
G4double globalTime;
G4bool firstStepInVolume;
G4bool lastStepInVolume;
G4double kineticEnergy;
G4double stepLength;
G4int eventID;
G4int runID;
G4double BF[6];
G4ThreeVector vertexPosition; // Position of the vertex at which the actual track was created
G4double vertexKineticEnergy; // Kinetic energy of the track when it was created
G4String logicalVolumeAtVertex;
G4String creatorProcess;
static G4int ScintMultihit;
static G4int runIDoldScint;
static G4int eventIDoldScint;
static G4int NIS;
static G4int ScintChamberNbold;
static G4int verboseLevel;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
typedef G4THitsCollection<musrScintHit> musrScintHitsCollection;
extern G4Allocator<musrScintHit> musrScintHitAllocator;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
inline void* musrScintHit::operator new(size_t)
{
void *aHit;
aHit = (void *) musrScintHitAllocator.MallocSingle();
return aHit;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
inline void musrScintHit::operator delete(void *aHit)
{
musrScintHitAllocator.FreeSingle((musrScintHit*) aHit);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif

38
include/musrScintSD.hh Normal file
View File

@ -0,0 +1,38 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrScintSD_h
#define musrScintSD_h 1
#include "G4VSensitiveDetector.hh"
#include "musrScintHit.hh"
#include "musrRootOutput.hh"
class G4Step;
class G4HCofThisEvent;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrScintSD : public G4VSensitiveDetector
{
public:
musrScintSD(G4String);
~musrScintSD();
void Initialize(G4HCofThisEvent*);
G4bool ProcessHits(G4Step*, G4TouchableHistory*);
void EndOfEvent(G4HCofThisEvent*);
private:
musrScintHitsCollection* scintCollection;
G4bool myStoreOnlyEventsWithHits;
G4int myStoreOnlyEventsWithHitInDetID;
G4double mySignalSeparationTime;
G4bool myStoreOnlyTheFirstTimeHit;
G4bool boolIsVvvInfoRequested;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif

View File

@ -0,0 +1,73 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#ifndef musrSteppingAction_h
#define musrSteppingAction_h 1
#include "G4UserSteppingAction.hh"
#include "G4ProcessManager.hh"
#include "globals.hh"
#include "musrRootOutput.hh"
#include <fstream>
class G4Timer;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrSteppingAction : public G4UserSteppingAction
{
public:
static musrSteppingAction* GetInstance();
musrSteppingAction();
~musrSteppingAction();
void UserSteppingAction(const G4Step *theStep);
void DoAtTheBeginningOfEvent();
void SetLogicalVolumeAsSpecialSaveVolume(G4String logicName, G4int volumeID);
void SetVolumeForMuonEventReweighting(G4String logicName, G4int weight);
G4bool GetInfoAboutOldTrack(G4int trackID, G4int& parentTrackID, G4int& particleID, G4double& vertexKine,
G4ThreeVector& vertexPosition, G4String& vertexLogVol, G4String& vertexProcess);
G4bool AreTracksCommingFromSameParent(G4int trackID1, G4int trackID2, G4String volumeName);
static const G4int maxNumberOfOldTracks=200;
G4bool IsVvvInfoRequested() {return boolIsVvvInfoRequested;}
void SetVvvInfoRequested(G4bool boolvar) {boolIsVvvInfoRequested = boolvar;}
void SetCalculationOfFieldIntegralRequested(G4bool decision) {boolCalculateFieldIntegral = decision;}
private:
musrRootOutput* myRootOutput;
G4Timer* timer;
time_t realTimeWhenThisEventStarted;
static musrSteppingAction* pointer;
G4bool muAlreadyWasInTargetInThisEvent;
G4bool muAlreadyWasInM0InThisEvent;
G4bool muAlreadyWasInM1InThisEvent;
G4bool muAlreadyWasInM2InThisEvent;
G4bool radioactiveElectronAlreadySavedInThisEvent;
G4bool boolIsAnySpecialSaveVolumeDefined;
G4bool boolIsVvvInfoRequested;
std::map<G4String,G4int> saveVolumeMapping;
G4String lastActualVolume;
G4bool boolMuonEventReweighting;
G4bool boolCalculateFieldIntegral;
std::map<G4String,G4int> volumeMuonWeightMapping;
G4int indexOfOldTrack;
std::map<G4int,G4int> myOldTracksMap;
G4int particleID_oldTrack[maxNumberOfOldTracks];
G4int parentTrackID_oldTrack[maxNumberOfOldTracks];
G4double vertexKine_oldTrack[maxNumberOfOldTracks];
G4ThreeVector vertexPosition_oldTrack[maxNumberOfOldTracks];
G4String vertexLogVol_oldTrack[maxNumberOfOldTracks];
G4String vertexProcess_oldTrack[maxNumberOfOldTracks];
// for field integral along the muon path (if its calculation is requested by the user)
G4double BxIntegral, ByIntegral, BzIntegral;
G4double BzIntegral1, BzIntegral2, BzIntegral3;
G4double CoordinateForFieldIntegral[4];
G4double FieldForFieldIntegral[6];
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif

View File

@ -0,0 +1,26 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrSteppingVerbose;
#ifndef musrSteppingVerbose_h
#define musrSteppingVerbose_h 1
#include "G4SteppingVerbose.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class musrSteppingVerbose : public G4SteppingVerbose
{
public:
musrSteppingVerbose();
~musrSteppingVerbose();
void StepInfo();
void TrackingStarted();
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif

View File

@ -0,0 +1,68 @@
#ifndef musrTabulatedElementField_h
#define musrTabulatedElementField_h 1
#include "globals.hh"
#include "F04ElementField.hh"
#include "F04GlobalField.hh"
#include "G4ios.hh"
#include <fstream>
#include <vector>
#include <cmath>
class musrTabulatedElementField : public F04ElementField
{
public:
musrTabulatedElementField(const char* filename, const char* fldTableType, G4double fieldValue, G4LogicalVolume* logVolume, G4ThreeVector positionOfTheCenter);
// "lenUnit" is the unit in which the grid coordinates are specified in the table
// "fieldNormalisation" is the normalisation that has to be applied on the field values in the table
// such that the values correspond do 1T nominal value
// "fieldValue" is the field value (in T) that is required (i.e. values normalised to 1T will be
// multiplied by this value).
/// Destructor.
virtual ~musrTabulatedElementField() {}
/// addFieldValue() adds the field for this solenoid into field[].
/// point[] is in global coordinates.
void addFieldValue( const G4double Point[4], G4double* field) const;
void addFieldValue2D( const G4double Point[4], G4double* field) const;
void addFieldValue3D( const G4double Point[4], G4double* field) const;
G4double GetNominalFieldValue();
void SetNominalFieldValue(G4double newFieldValue);
// getWidth(), getHeight(), getLength(), return the dimensions of the field
// (used to define the boundary of the field)
virtual G4double getWidth() {return maximumWidth;} // x coordinate
virtual G4double getHeight() {return maximumHeight;} // y coordinate
virtual G4double getLength() {return maximumLength;} // z coordinate
private:
// Storage space for the table
std::vector< std::vector< std::vector< double > > > xField;
std::vector< std::vector< std::vector< double > > > yField;
std::vector< std::vector< std::vector< double > > > zField;
std::vector< std::vector< double > > xField2D;
std::vector< std::vector< double > > zField2D;
// The dimensions of the table
int nx,ny,nz;
// The units of the field
char fieldTableType[100];
G4String fUnit;
double fieUnit;
char fldType;
int fldDim;
// The physical limits of the defined region
double minimumx, maximumx, minimumy, maximumy, minimumz, maximumz;
// The physical extent of the defined region
double dx, dy, dz;
double ffieldValue;
double maximumWidth, maximumHeight, maximumLength;
void Invert(const char* indexToInvert);
};
#endif

View File

@ -0,0 +1,45 @@
// Geant4 simulation for MuSR
// AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI
// DATE : 2008-05
//
#ifndef UNIFORM_BFIELD_HH
#define UNIFORM_BFIELD_HH
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "F04ElementField.hh"
#include "F04GlobalField.hh"
// UniformField implements a constant electromagnetic field in any direction. TS
class musrUniformField : public F04ElementField
{
public:
musrUniformField(G4double EMF[6], G4double half_X, G4double half_Y, G4double half_Z, G4LogicalVolume*, G4ThreeVector);
virtual ~musrUniformField() {}
// TS: Define the two newly added VIRTUAL functions of F04ElementField
G4double GetNominalFieldValue();
void SetNominalFieldValue(G4double newFieldValue);
virtual G4double getLength() { return fieldLength; }
virtual G4double getWidth() { return fieldWidth; }
virtual G4double getHeight() { return fieldHeight; }
G4bool isOutside(G4ThreeVector& local) const;
G4bool isWithin (G4ThreeVector& local) const;
void addFieldValue(const G4double point[4], G4double field[6]) const;
private:
G4double EMfield[6];
G4double fieldLength;
G4double fieldWidth;
G4double fieldHeight;
};
#endif

44
include/yields.hh Normal file
View File

@ -0,0 +1,44 @@
// Geant4 simulation for MuSR
// AUTHOR: Toni SHIROKA, Paul Scherrer Institut, PSI
// DATE : 2008-05
//
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// Muonium yields as a function of initial mu+ energies.
// The method GetYields is used by MuFormation.
// Id : yields.cc, v 1.1
// Author: Taofiq PARAISO, T. Shiroka
// Date : 2007-12
// Notes : First implemented in Fortran by A. Hofer
// C++ conversion by T.K. Paraiso 04-2005
// Slight modifications by T. Shiroka
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#ifndef Yields_h
#define Yield_h 1
#include "globals.hh"
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The Muonium Yield function as well as the parameters are taken from:
M. Gonin, R. Kallenbach, P. Bochsler: "Charge exchange of hydrogen atoms
in carbon foils at 0.4 - 120 keV", Rev.Sci.Instrum. 65 (3), March 1994
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
class Yields
{
public:
Yields(); // Class constructor
~Yields(); // Class destructor
void GetYields(double E, double mass, double yvector[]);
private: // Some internal variables
double Q_zero, Q_minus, D;
double Yield_minus, Yield_zero, Yield_plus;
double aux1, aux2, aux3; // Auxiliary variables
};
#endif