BLCMDusertrackfilter Class Reference

Inheritance diagram for BLCMDusertrackfilter:

BLElement BLCallback BLManager::SteppingAction BLCommand

List of all members.


Detailed Description

class BLCMDusertrackfilter - implements a track filter using user code Each placement of this class implements a filter on all tracks entering its physical volume.

The filter is implemented in user code dynamically loaded at run time. The user code can kill or modify the input track, and can create any number of secondary tracks.

Public Member Functions

 BLCMDusertrackfilter ()
 Default constructor.
virtual ~BLCMDusertrackfilter ()
 Destructor.
BLElementclone ()
 clone()
 BLCMDusertrackfilter (const BLCMDusertrackfilter &r)
 Copy constructor.
G4String commandName ()
 commandName() returns "usertrackfilter".
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the usertrackfilter command.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for the command.
virtual void construct (G4RotationMatrix *relativeRotation, G4ThreeVector relativePosition, G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition)
 construct() will construct the usertrackfilter. Used for normal placements of a track filter object.
virtual G4double getLength ()
 getLength() returns this element's Length along the Z axis.
virtual G4double getWidth ()
 getWidth() returns this element's Width along the X axis.
virtual G4double getHeight ()
 getHeight() returns this element's height along the Y axis.
virtual G4bool isOK ()
 isOK() returns true.
void generatePoints (int npoints, std::vector< G4ThreeVector > &v)
 generatePoints() from BLElement
G4bool isOutside (G4ThreeVector &local, G4double tolerance)
 isOutside() from BLElement
void callback (int type)
 callback() from BLCallback.
void UserSteppingAction (const G4Step *step)
 UserSteppingAction() from BLManager::SteppingAction.

Private Attributes

G4double radius
G4double innerRadius
G4double height
G4double width
G4double length
G4String material
G4String color
G4double maxStep
G4String filterName
G4String init
G4VPhysicalVolume * thisVol
int steppingVerbose
BLUserTrackFilterfilter
G4VSolid * solid


Constructor & Destructor Documentation

BLCMDusertrackfilter::BLCMDusertrackfilter (  ) 

Default constructor.

References BLCMDTYPE_DATA, color, filter, filterName, height, init, innerRadius, length, material, maxStep, radius, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), solid, steppingVerbose, thisVol, and width.

Referenced by clone(), and command().

00123                                            : 
00124                         BLElement(), BLCallback(), BLManager::SteppingAction()
00125 {
00126         registerCommand(BLCMDTYPE_DATA);
00127         setSynopsis("Construct a usertrackfilter that filters tracks via user code.");
00128         setDescription("...");
00129         
00130         // initial field values
00131         radius = 0.0;
00132         innerRadius = 0.0;
00133         height = 0.0;
00134         width = 0.0;
00135         length = 1.0*mm;
00136         material = "";
00137         color = "1,1,1";
00138         maxStep = -99.0;
00139         filterName = "";
00140         init = "";
00141         solid = 0;
00142         filter = 0;
00143         thisVol = 0;
00144         steppingVerbose = 0;
00145 }

BLCMDusertrackfilter::~BLCMDusertrackfilter (  )  [virtual]

Destructor.

References solid.

00148 {
00149         if(solid) delete solid;
00150 }

BLCMDusertrackfilter::BLCMDusertrackfilter ( const BLCMDusertrackfilter r  ) 

Copy constructor.

References color, filter, filterName, height, init, innerRadius, length, material, maxStep, radius, solid, steppingVerbose, thisVol, and width.

00152                                                                         : BLElement(r), BLCallback(), BLManager::SteppingAction()
00153 {
00154         radius = r.radius;
00155         innerRadius = r.innerRadius;
00156         height = r.height;
00157         width = r.width;
00158         length = r.length;
00159         material = r.material;
00160         color = r.color;
00161         maxStep = r.maxStep;
00162         filterName = r.filterName;
00163         init = r.init;
00164         solid = r.solid;
00165         filter = r.filter;
00166         thisVol = 0;
00167         steppingVerbose = 0;
00168 }


Member Function Documentation

BLElement* BLCMDusertrackfilter::clone (  )  [inline, virtual]

clone()

Implements BLElement.

References BLCMDusertrackfilter().

00073 { return new BLCMDusertrackfilter(*this); }

G4String BLCMDusertrackfilter::commandName (  )  [inline, virtual]

commandName() returns "usertrackfilter".

Implements BLCommand.

00079 { return "usertrackfilter"; }

int BLCMDusertrackfilter::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the usertrackfilter command.

Implements BLCommand.

References BLCMDusertrackfilter(), filter, filterName, BLCommand::getMaterial(), BLUserTrackFilter::getName(), BLManager::getObject(), BLCommand::handleNamedArgs(), init, material, BLCommand::print(), BLCommand::printError(), BLManager::registerCallback(), BLElement::setName(), and BLUserTrackFilter::setup().

00171 {
00172         if(argv.size() != 1) {
00173                 printError("usertrackfilter: Invalid command, must have name");
00174                 return -1;
00175         }
00176 
00177         if(argv[0] == "default") {
00178                 return defaultUserTrackFilter.handleNamedArgs(namedArgs);
00179         }
00180 
00181         BLCMDusertrackfilter *t = 
00182                         new BLCMDusertrackfilter(defaultUserTrackFilter);
00183         t->setName(argv[0]);
00184         int retval = t->handleNamedArgs(namedArgs);
00185 
00186         // check material exists
00187         if(t->material.size() > 0) getMaterial(t->material,false);
00188 
00189         t->print(argv[0]);
00190 
00191         // find the BLUserTrackFilter
00192         G4String knownFilters;
00193         std::vector<BLUserCode*> list = BLManager::getObject()->
00194                                         getUserCodeInstances("usertrackfilter");
00195         for(unsigned i=0; i<list.size(); ++i) {
00196                 if(t->filterName == list[i]->getName()) {
00197                         t->filter = dynamic_cast<BLUserTrackFilter*>(list[i]);
00198                         break;
00199                 }
00200                 knownFilters += list[i]->getName();
00201                 knownFilters += " ";
00202         }
00203         if(!t->filter) {
00204                 printError("usertrackfilter: cannot find UserTrackFilter '%s'",
00205                         t->filterName.c_str());
00206                 printError("       known Filters: %s\n",knownFilters.c_str());
00207         }
00208 
00209         // call the user's setup
00210         if(t->filter) t->filter->setup(t->init.c_str());
00211 
00212         // register callback for after tracking
00213         BLManager::getObject()->registerCallback(t,2);
00214 
00215         return retval;
00216 }

void BLCMDusertrackfilter::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for the command.

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argString(), color, filterName, height, init, innerRadius, length, material, maxStep, radius, and width.

00219 {
00220         argDouble(radius,"radius","The radius of the circular element (mm).");
00221         argDouble(innerRadius,"innerRadius","The inner radius of the circular element (0 mm, solid).");
00222         argDouble(height,"height","The height of the rectangular element (mm).");
00223         argDouble(width,"width","The width of the rectangular element (mm).");
00224         argDouble(length,"length","The length of the element (mm).");
00225         argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm).");
00226         argString(material,"material","The material of the element.");
00227         argString(color,"color","The color of the element (''=invisible).");
00228         argString(filterName,"filterName","Name of the UserTrackFilter.");
00229         argString(filterName,"filter","Synonym for filterName.");
00230         argString(init,"init","Initialization string passed to user setup().");
00231 }

void BLCMDusertrackfilter::construct ( G4RotationMatrix *  relativeRotation,
G4ThreeVector  relativePosition,
G4LogicalVolume *  parent,
G4String  parentName,
G4RotationMatrix *  parentRotation,
G4ThreeVector  parentPosition 
) [virtual]

construct() will construct the usertrackfilter. Used for normal placements of a track filter object.

Implements BLElement.

References color, BLParam::getDouble(), BLParam::getInt(), BLCommand::getMaterial(), BLElement::getName(), BLManager::getObject(), BLCommand::getVisAttrib(), height, innerRadius, length, material, maxStep, Param, BLCommand::printError(), radius, BLManager::registerSteppingAction(), solid, steppingVerbose, thisVol, and width.

00239 {
00240         steppingVerbose = Param.getInt("steppingVerbose");
00241 
00242         G4Material *mat;
00243         if(material != "")
00244                 mat = getMaterial(material);
00245         else
00246                 mat = parent->GetMaterial();
00247 
00248         G4String thisname = parentName+getName();
00249 
00250         if(!solid) {
00251                 if(radius > 0.0) {
00252                         solid = new G4Tubs(thisname+"Tubs", innerRadius, radius,
00253                                         length/2.0, 0.0, 2.0*pi);
00254                 } else if(height > 0.0 && width > 0.0) {
00255                         solid = new G4Box(thisname+"Box",width/2.0,
00256                                         height/2.0,length/2.0);
00257                 } else {
00258                         printError("usertrackfilter::construct %s INVALID - no "
00259                                 "radius or height&width",thisname.c_str());
00260                         return;
00261                 }
00262         }
00263         G4LogicalVolume *lv = new G4LogicalVolume(solid,mat, thisname+"LogVol");
00264         lv->SetVisAttributes(getVisAttrib(color));
00265         if(maxStep < 0.0) maxStep = Param.getDouble("maxStep");
00266         lv->SetUserLimits(new G4UserLimits(maxStep));
00267 
00268         // geant4 rotation convention is backwards from g4beamline
00269         G4RotationMatrix *g4rot = 0;
00270         if(relativeRotation)
00271                 g4rot = new G4RotationMatrix(relativeRotation->inverse());
00272 
00273         G4VPhysicalVolume *pv = new G4PVPlacement(g4rot, relativePosition,
00274                                         lv,thisname,parent,false,0);
00275         thisVol = pv;
00276 
00277         // get globalRotation and globalPosition
00278         G4RotationMatrix *globalRotation = 0;
00279         if(relativeRotation && parentRotation) {
00280                 globalRotation = 
00281                     new G4RotationMatrix(*parentRotation * *relativeRotation);
00282         } else if(relativeRotation) {
00283                 globalRotation = relativeRotation;
00284         } else if(parentRotation) {
00285                 globalRotation = parentRotation;
00286         }
00287         G4ThreeVector globalPosition(relativePosition + parentPosition);
00288         if(globalRotation)
00289                 globalPosition = *globalRotation * relativePosition +
00290                                 parentPosition;
00291 
00292         BLManager::getObject()->registerSteppingAction(pv,this);
00293 
00294         printf("usertrackfilter::Construct %s parent=%s relZ=%.1f globZ=%.1f\n",
00295                 thisname.c_str(),parentName.c_str(),relativePosition[2],
00296                 globalPosition[2]);
00297 }

virtual G4double BLCMDusertrackfilter::getLength (  )  [inline, virtual]

getLength() returns this element's Length along the Z axis.

Implements BLElement.

References length.

00097 { return length; }

virtual G4double BLCMDusertrackfilter::getWidth (  )  [inline, virtual]

getWidth() returns this element's Width along the X axis.

Implements BLElement.

References width.

00100 { return width; }

virtual G4double BLCMDusertrackfilter::getHeight (  )  [inline, virtual]

getHeight() returns this element's height along the Y axis.

Implements BLElement.

References height.

00103 { return height; }

virtual G4bool BLCMDusertrackfilter::isOK (  )  [inline, virtual]

isOK() returns true.

Implements BLElement.

00106 { return true; }

void BLCMDusertrackfilter::generatePoints ( int  npoints,
std::vector< G4ThreeVector > &  v 
) [virtual]

generatePoints() from BLElement

Implements BLElement.

References BLElement::generateBox(), BLElement::generateTubs(), height, innerRadius, length, radius, and width.

00300 {
00301         if(radius > 0.0)
00302                 generateTubs(npoints, innerRadius, radius, 0.0, 360.0*deg, length, v);
00303         else
00304                 generateBox(npoints,width,height,length,v);
00305 }

G4bool BLCMDusertrackfilter::isOutside ( G4ThreeVector &  local,
G4double  tolerance 
) [virtual]

isOutside() from BLElement

Implements BLElement.

References height, innerRadius, length, radius, and width.

00308 {
00309         if(radius > 0.0) {
00310                 G4double r = sqrt(local[0]*local[0]+local[1]*local[1]);
00311                 return r > radius-tolerance || r < innerRadius+tolerance ||
00312                         fabs(local[2]) > length/2.0-tolerance;
00313         } else {
00314                 return fabs(local[0]) > width/2.0-tolerance ||
00315                         fabs(local[1]) > height/2.0-tolerance ||
00316                         fabs(local[2]) > length/2.0-tolerance;
00317         }
00318 }

void BLCMDusertrackfilter::callback ( int  type  )  [virtual]

callback() from BLCallback.

Reimplemented from BLCallback.

References BLUserTrackFilter::complete(), filter, and init.

00321 {
00322         if(type == 2) {
00323                 if(filter) filter->complete(init.c_str());
00324         }
00325 }

void BLCMDusertrackfilter::UserSteppingAction ( const G4Step *  step  )  [virtual]

UserSteppingAction() from BLManager::SteppingAction.

Implements BLManager::SteppingAction.

References BLUserTrackFilter::filter(), filter, BLManager::getEventID(), BLManager::getObject(), steppingVerbose, and thisVol.

00328 {
00329         // get basic physical-volume info
00330         G4StepPoint *prePoint = step->GetPreStepPoint();
00331         if(!prePoint) return;
00332         G4VPhysicalVolume *preVol = prePoint->GetPhysicalVolume();
00333         if(!preVol) return;
00334         G4StepPoint *postPoint = step->GetPostStepPoint();
00335         if(!postPoint) return;
00336         G4VPhysicalVolume *postVol = postPoint->GetPhysicalVolume();
00337         if(!postVol) return;
00338         
00339         // return if not entering thisVol
00340         if(preVol == postVol || postVol != thisVol) return;
00341 
00342         G4Track *track = step->GetTrack();
00343         int trackID = track->GetTrackID();
00344         int eventID = BLManager::getObject()->getEventID();
00345         std::vector<G4Track*> secondaries;
00346 
00347         if(filter) filter->filter(track,eventID,secondaries,steppingVerbose);
00348 
00349         // (Geant4 handles weight differently here)
00350         postPoint->SetWeight(track->GetWeight());
00351 
00352         // prevent user from screwing up trackID
00353         track->SetTrackID(trackID);
00354 
00355         for(unsigned i=0; i<secondaries.size(); ++i) {
00356                 G4Track *t = secondaries[i];
00357                 t->SetTrackID(0);
00358                 t->SetParentID(track->GetTrackID());
00359                 G4EventManager::GetEventManager()->GetTrackingManager()->
00360                         GimmeSecondaries()->push_back(t);
00361         }
00362 }


Member Data Documentation

G4double BLCMDusertrackfilter::radius [private]

G4double BLCMDusertrackfilter::height [private]

G4double BLCMDusertrackfilter::width [private]

G4double BLCMDusertrackfilter::length [private]

G4String BLCMDusertrackfilter::material [private]

G4String BLCMDusertrackfilter::color [private]

G4double BLCMDusertrackfilter::maxStep [private]

G4String BLCMDusertrackfilter::init [private]

G4VPhysicalVolume* BLCMDusertrackfilter::thisVol [private]

G4VSolid* BLCMDusertrackfilter::solid [private]


The documentation for this class was generated from the following file:
g4beamline