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. | |
BLElement * | clone () |
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 |
BLUserTrackFilter * | filter |
G4VSolid * | solid |
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().
00125 : 00126 BLElement(), BLCallback(), BLManager::SteppingAction() 00127 { 00128 registerCommand(BLCMDTYPE_DATA); 00129 setSynopsis("Construct a usertrackfilter that filters tracks via user code."); 00130 setDescription("..."); 00131 00132 // initial field values 00133 radius = 0.0; 00134 innerRadius = 0.0; 00135 height = 0.0; 00136 width = 0.0; 00137 length = 1.0*mm; 00138 material = ""; 00139 color = "1,1,1"; 00140 maxStep = -99.0; 00141 filterName = ""; 00142 init = ""; 00143 solid = 0; 00144 filter = 0; 00145 thisVol = 0; 00146 steppingVerbose = 0; 00147 }
BLCMDusertrackfilter::~BLCMDusertrackfilter | ( | ) | [virtual] |
BLCMDusertrackfilter::BLCMDusertrackfilter | ( | const BLCMDusertrackfilter & | r | ) |
Copy constructor.
References color, filter, filterName, height, init, innerRadius, length, material, maxStep, radius, solid, steppingVerbose, thisVol, and width.
00154 : BLElement(r), BLCallback(), BLManager::SteppingAction() 00155 { 00156 radius = r.radius; 00157 innerRadius = r.innerRadius; 00158 height = r.height; 00159 width = r.width; 00160 length = r.length; 00161 material = r.material; 00162 color = r.color; 00163 maxStep = r.maxStep; 00164 filterName = r.filterName; 00165 init = r.init; 00166 solid = r.solid; 00167 filter = r.filter; 00168 thisVol = 0; 00169 steppingVerbose = 0; 00170 }
BLElement* BLCMDusertrackfilter::clone | ( | ) | [inline, virtual] |
Implements BLElement.
References BLCMDusertrackfilter().
00075 { return new BLCMDusertrackfilter(*this); }
G4String BLCMDusertrackfilter::commandName | ( | ) | [inline, virtual] |
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().
00173 { 00174 if(argv.size() != 1) { 00175 printError("usertrackfilter: Invalid command, must have name"); 00176 return -1; 00177 } 00178 00179 if(argv[0] == "default") { 00180 return defaultUserTrackFilter.handleNamedArgs(namedArgs); 00181 } 00182 00183 BLCMDusertrackfilter *t = 00184 new BLCMDusertrackfilter(defaultUserTrackFilter); 00185 t->setName(argv[0]); 00186 int retval = t->handleNamedArgs(namedArgs); 00187 00188 // check material exists 00189 if(t->material.size() > 0) getMaterial(t->material,false); 00190 00191 t->print(argv[0]); 00192 00193 // find the BLUserTrackFilter 00194 G4String knownFilters; 00195 std::vector<BLUserCode*> list = BLManager::getObject()-> 00196 getUserCodeInstances("usertrackfilter"); 00197 for(unsigned i=0; i<list.size(); ++i) { 00198 if(t->filterName == list[i]->getName()) { 00199 t->filter = dynamic_cast<BLUserTrackFilter*>(list[i]); 00200 break; 00201 } 00202 knownFilters += list[i]->getName(); 00203 knownFilters += " "; 00204 } 00205 if(!t->filter) { 00206 printError("usertrackfilter: cannot find UserTrackFilter '%s'", 00207 t->filterName.c_str()); 00208 printError(" known Filters: %s\n",knownFilters.c_str()); 00209 } 00210 00211 // call the user's setup 00212 if(t->filter) t->filter->setup(t->init.c_str()); 00213 00214 // register callback for after tracking 00215 BLManager::getObject()->registerCallback(t,2); 00216 00217 return retval; 00218 }
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.
00221 { 00222 argDouble(radius,"radius","The radius of the circular element (mm)."); 00223 argDouble(innerRadius,"innerRadius","The inner radius of the circular element (0 mm, solid)."); 00224 argDouble(height,"height","The height of the rectangular element (mm)."); 00225 argDouble(width,"width","The width of the rectangular element (mm)."); 00226 argDouble(length,"length","The length of the element (mm)."); 00227 argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm)."); 00228 argString(material,"material","The material of the element."); 00229 argString(color,"color","The color of the element (''=invisible)."); 00230 argString(filterName,"filterName","Name of the UserTrackFilter."); 00231 argString(filterName,"filter","Synonym for filterName."); 00232 argString(init,"init","Initialization string passed to user setup()."); 00233 }
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.
00241 { 00242 steppingVerbose = Param.getInt("steppingVerbose"); 00243 00244 G4Material *mat; 00245 if(material != "") 00246 mat = getMaterial(material); 00247 else 00248 mat = parent->GetMaterial(); 00249 00250 G4String thisname = parentName+getName(); 00251 00252 if(!solid) { 00253 if(radius > 0.0) { 00254 solid = new G4Tubs(thisname+"Tubs", innerRadius, radius, 00255 length/2.0, 0.0, 2.0*pi); 00256 } else if(height > 0.0 && width > 0.0) { 00257 solid = new G4Box(thisname+"Box",width/2.0, 00258 height/2.0,length/2.0); 00259 } else { 00260 printError("usertrackfilter::construct %s INVALID - no " 00261 "radius or height&width",thisname.c_str()); 00262 return; 00263 } 00264 } 00265 G4LogicalVolume *lv = new G4LogicalVolume(solid,mat, thisname+"LogVol"); 00266 lv->SetVisAttributes(getVisAttrib(color)); 00267 if(maxStep < 0.0) maxStep = Param.getDouble("maxStep"); 00268 lv->SetUserLimits(new G4UserLimits(maxStep)); 00269 00270 // geant4 rotation convention is backwards from g4beamline 00271 G4RotationMatrix *g4rot = 0; 00272 if(relativeRotation) 00273 g4rot = new G4RotationMatrix(relativeRotation->inverse()); 00274 00275 G4VPhysicalVolume *pv = new G4PVPlacement(g4rot, relativePosition, 00276 lv,thisname,parent,false,0); 00277 thisVol = pv; 00278 00279 // get globalRotation and globalPosition 00280 G4RotationMatrix *globalRotation = 0; 00281 if(relativeRotation && parentRotation) { 00282 globalRotation = 00283 new G4RotationMatrix(*parentRotation * *relativeRotation); 00284 } else if(relativeRotation) { 00285 globalRotation = relativeRotation; 00286 } else if(parentRotation) { 00287 globalRotation = parentRotation; 00288 } 00289 G4ThreeVector globalPosition(relativePosition + parentPosition); 00290 if(globalRotation) 00291 globalPosition = *globalRotation * relativePosition + 00292 parentPosition; 00293 00294 BLManager::getObject()->registerSteppingAction(pv,this); 00295 00296 printf("usertrackfilter::Construct %s parent=%s relZ=%.1f globZ=%.1f\n", 00297 thisname.c_str(),parentName.c_str(),relativePosition[2], 00298 globalPosition[2]); 00299 }
virtual G4double BLCMDusertrackfilter::getLength | ( | ) | [inline, virtual] |
getLength() returns this element's Length along the Z axis.
Implements BLElement.
References length.
00099 { return length; }
virtual G4double BLCMDusertrackfilter::getWidth | ( | ) | [inline, virtual] |
getWidth() returns this element's Width along the X axis.
Implements BLElement.
References width.
00102 { return width; }
virtual G4double BLCMDusertrackfilter::getHeight | ( | ) | [inline, virtual] |
getHeight() returns this element's height along the Y axis.
Implements BLElement.
References height.
00105 { return height; }
virtual G4bool BLCMDusertrackfilter::isOK | ( | ) | [inline, virtual] |
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.
00302 { 00303 if(radius > 0.0) 00304 generateTubs(npoints, innerRadius, radius, 0.0, 360.0*deg, length, v); 00305 else 00306 generateBox(npoints,width,height,length,v); 00307 }
G4bool BLCMDusertrackfilter::isOutside | ( | G4ThreeVector & | local, | |
G4double | tolerance | |||
) | [virtual] |
isOutside() from BLElement
Implements BLElement.
References height, innerRadius, length, radius, and width.
00310 { 00311 if(radius > 0.0) { 00312 G4double r = sqrt(local[0]*local[0]+local[1]*local[1]); 00313 return r > radius-tolerance || r < innerRadius+tolerance || 00314 fabs(local[2]) > length/2.0-tolerance; 00315 } else { 00316 return fabs(local[0]) > width/2.0-tolerance || 00317 fabs(local[1]) > height/2.0-tolerance || 00318 fabs(local[2]) > length/2.0-tolerance; 00319 } 00320 }
void BLCMDusertrackfilter::callback | ( | int | type | ) | [virtual] |
callback() from BLCallback.
Reimplemented from BLCallback.
References BLUserTrackFilter::complete(), filter, and init.
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.
00330 { 00331 // get basic physical-volume info 00332 G4StepPoint *prePoint = step->GetPreStepPoint(); 00333 if(!prePoint) return; 00334 G4VPhysicalVolume *preVol = prePoint->GetPhysicalVolume(); 00335 if(!preVol) return; 00336 G4StepPoint *postPoint = step->GetPostStepPoint(); 00337 if(!postPoint) return; 00338 G4VPhysicalVolume *postVol = postPoint->GetPhysicalVolume(); 00339 if(!postVol) return; 00340 00341 // return if not entering thisVol 00342 if(preVol == postVol || postVol != thisVol) return; 00343 00344 G4Track *track = step->GetTrack(); 00345 int trackID = track->GetTrackID(); 00346 int eventID = BLManager::getObject()->getEventID(); 00347 std::vector<G4Track*> secondaries; 00348 00349 if(filter) filter->filter(track,eventID,secondaries,steppingVerbose); 00350 00351 // (Geant4 handles weight differently here) 00352 postPoint->SetWeight(track->GetWeight()); 00353 00354 // prevent user from screwing up trackID 00355 track->SetTrackID(trackID); 00356 00357 for(unsigned i=0; i<secondaries.size(); ++i) { 00358 G4Track *t = secondaries[i]; 00359 t->SetTrackID(0); 00360 t->SetParentID(track->GetTrackID()); 00361 G4EventManager::GetEventManager()->GetTrackingManager()-> 00362 GimmeSecondaries()->push_back(t); 00363 } 00364 }
G4double BLCMDusertrackfilter::radius [private] |
Referenced by BLCMDusertrackfilter(), construct(), defineNamedArgs(), generatePoints(), and isOutside().
G4double BLCMDusertrackfilter::innerRadius [private] |
Referenced by BLCMDusertrackfilter(), construct(), defineNamedArgs(), generatePoints(), and isOutside().
G4double BLCMDusertrackfilter::height [private] |
Referenced by BLCMDusertrackfilter(), construct(), defineNamedArgs(), generatePoints(), getHeight(), and isOutside().
G4double BLCMDusertrackfilter::width [private] |
Referenced by BLCMDusertrackfilter(), construct(), defineNamedArgs(), generatePoints(), getWidth(), and isOutside().
G4double BLCMDusertrackfilter::length [private] |
Referenced by BLCMDusertrackfilter(), construct(), defineNamedArgs(), generatePoints(), getLength(), and isOutside().
G4String BLCMDusertrackfilter::material [private] |
Referenced by BLCMDusertrackfilter(), command(), construct(), and defineNamedArgs().
G4String BLCMDusertrackfilter::color [private] |
Referenced by BLCMDusertrackfilter(), construct(), and defineNamedArgs().
G4double BLCMDusertrackfilter::maxStep [private] |
Referenced by BLCMDusertrackfilter(), construct(), and defineNamedArgs().
G4String BLCMDusertrackfilter::filterName [private] |
Referenced by BLCMDusertrackfilter(), command(), and defineNamedArgs().
G4String BLCMDusertrackfilter::init [private] |
Referenced by BLCMDusertrackfilter(), callback(), command(), and defineNamedArgs().
G4VPhysicalVolume* BLCMDusertrackfilter::thisVol [private] |
Referenced by BLCMDusertrackfilter(), construct(), and UserSteppingAction().
int BLCMDusertrackfilter::steppingVerbose [private] |
Referenced by BLCMDusertrackfilter(), construct(), and UserSteppingAction().
BLUserTrackFilter* BLCMDusertrackfilter::filter [private] |
Referenced by BLCMDusertrackfilter(), callback(), command(), and UserSteppingAction().
G4VSolid* BLCMDusertrackfilter::solid [private] |
Referenced by BLCMDusertrackfilter(), construct(), and ~BLCMDusertrackfilter().