BLCMDvirtualdetector Class Reference

Inheritance diagram for BLCMDvirtualdetector:

BLElement BLCommand

List of all members.


Detailed Description

class BLCMDvirtualdetector - implements a VirtualDetector Each placement of this class generates an NTuple of the beam as it enters the physical volume of the VirtualDetector.

This is therefore a "perfect" detector in that it does not perturb the beam at all, and intrinsically has the resolution of a float (it measures position and momentum and time).

The NTuple for a virtualdetector can be added to a BLCMDntuple by including a pattern that matches its name in the 'detectors' argument to the ntuple command.

Note that if a BLCoordinates instance is linked into the track, its centerline coordinates are used; otherwise global coordinates are used.

Public Member Functions

 BLCMDvirtualdetector ()
 Default constructor.
virtual ~BLCMDvirtualdetector ()
 Destructor.
BLElementclone ()
 clone()
 BLCMDvirtualdetector (const BLCMDvirtualdetector &r)
 Copy constructor.
G4String commandName ()
 commandName() returns "virtualdetector".
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the virtualdetector command.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for the command.
void argChanged ()
 argChanged() does internal computations after some arg changed
void help (bool detailed)
 help() prints help text.
virtual void construct (G4RotationMatrix *relativeRotation, G4ThreeVector relativePosition, G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition)
 construct() will construct the virtualdetector. Used for normal placements of a VirtualDetector 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

Private Attributes

G4double radius
G4double innerRadius
G4double height
G4double width
G4double length
G4String material
G4String color
G4VSolid * solid
G4double maxStep
G4int noSingles
G4String format
G4String filename
G4String require
G4int referenceParticle
G4String coordinates
G4int kill
BLCoordinateType coordinateType


Constructor & Destructor Documentation

BLCMDvirtualdetector::BLCMDvirtualdetector (  ) 

Default constructor.

References BLCMDTYPE_DATA, BLCOORD_CENTERLINE, color, coordinates, coordinateType, filename, format, height, innerRadius, kill, length, material, maxStep, noSingles, radius, referenceParticle, BLCommand::registerCommand(), require, BLCommand::setDescription(), BLCommand::setSynopsis(), solid, and width.

Referenced by clone(), and command().

00167                                            : BLElement()
00168 {
00169         registerCommand(BLCMDTYPE_DATA);
00170         setSynopsis("Construct a VirtualDetector that generates an NTuple.");
00171         setDescription("A VirtualDetector generates an NTuple of any track when it\n"
00172                 "enters the physical volume of the VirtualDetector. It may\n"
00173                 "be placed via multiple place commands (usually with a "
00174                 "'rename=det#' argument to distinguish the different placements).\n"
00175                 "If material is not specified, it uses the material of the\n"
00176                 "enclosing element. Every placement creates an individual NTuple.\n"
00177                 "For a circular VirtualDetector give radius; for a\n"
00178                 "rectangular one give height and width; length is usually\n"
00179                 "left at 1 mm, but can be set to correspond to the length "
00180                 "of a physical detector.\n"
00181                 "The NTuple by default uses centerline coordinates.\n"
00182                 "The NTuple of the virtualdetector can be included in an "
00183                 "ntuple command by including a pattern that matches its name "
00184                 "in the 'detectors' argument to the ntuple command. Note that "
00185                 "must match the name as placed (i.e. includes rename=), not "
00186                 "the name given to this command. The noSingles argument may be "
00187                 "useful in this case to avoid a huge NTuple of singles (an "
00188                 "empty NTuple may be created).\n\n"
00189                 "Note that secondary particles created within the virtualdetector "
00190                 "will not get an entry until they have taken one step. "
00191                 "They are guaranteed to do so.\n\n"
00192                 "The standard NTuple fields are:\n"
00193                 "    x,y,z (mm)\n"
00194                 "    Px,Py,Pz (MeV/c)\n"
00195                 "    t (ns)\n"
00196                 "    PDGid (11=e-, 13=mu-, 22=gamma, 211=pi+, 2212=proton, ...)\n"
00197                 "    EventID (may be inexact above 16,777,215)\n"
00198                 "    TrackID\n"
00199                 "    ParentID (0 => primary particle)\n"
00200                 "    Weight (defaults to 1.0)\n\n"
00201                 "The following additional fields are appended for "
00202                 "format=Extended, format=asciiExtended, and "
00203                 "format=rootExtended:\n"
00204                 "    Bx, By, Bz (Tesla)\n"
00205                 "    Ex, Ey, Ez (Megavolts/meter)\n"
00206                 "    ProperTime (ns)\n"
00207                 "    PathLength (mm)\n"
00208                 "    PolX, PolY, PolZ (polarization)\n"
00209                 "    InitialKE (MeV when track was created)\n\n"
00210                 "Valid Formats (ignore case): ");
00211         
00212         // initial field values
00213         radius = 0.0;
00214         innerRadius = 0.0;
00215         height = 0.0;
00216         width = 0.0;
00217         length = 1.0*mm;
00218         material = "";
00219         color = "1,1,1";
00220         solid = 0;
00221         maxStep = -99.0;
00222         noSingles = 0;
00223         format = "";
00224         filename = "";
00225         require = "";
00226         referenceParticle = 0;
00227         coordinates = "Centerline";
00228         kill = 0;
00229         coordinateType = BLCOORD_CENTERLINE;
00230 }

BLCMDvirtualdetector::~BLCMDvirtualdetector (  )  [virtual]

Destructor.

References solid.

00233 {
00234         if(solid) delete solid;
00235 }

BLCMDvirtualdetector::BLCMDvirtualdetector ( const BLCMDvirtualdetector r  ) 

Copy constructor.

References color, coordinates, coordinateType, filename, format, height, innerRadius, kill, length, material, maxStep, noSingles, radius, referenceParticle, require, solid, and width.

00237                                                                         : BLElement(r)
00238 {
00239         radius = r.radius;
00240         innerRadius = r.innerRadius;
00241         height = r.height;
00242         width = r.width;
00243         length = r.length;
00244         material = r.material;
00245         color = r.color;
00246         solid = r.solid;
00247         maxStep = r.maxStep;
00248         noSingles = r.noSingles;
00249         format = r.format;
00250         filename = r.filename;
00251         referenceParticle = r.referenceParticle;
00252         coordinates = r.coordinates;
00253         kill = r.kill;
00254         require = r.require;
00255         coordinateType = r.coordinateType;
00256 }


Member Function Documentation

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

clone()

Implements BLElement.

References BLCMDvirtualdetector().

00087 { return new BLCMDvirtualdetector(*this); }

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

commandName() returns "virtualdetector".

Implements BLCommand.

00093 { return "virtualdetector"; }

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

command() implements the virtualdetector command.

Implements BLCommand.

References BLCMDvirtualdetector(), coordinates, coordinateType, format, BLCoordinates::getCoordinateType(), BLParam::getDouble(), BLCommand::getMaterial(), BLCommand::handleNamedArgs(), material, maxStep, Param, BLCommand::print(), BLCommand::printError(), and BLElement::setName().

00259 {
00260         if(argv.size() != 1) {
00261                 printError("virtualdetector: Invalid command, must have name");
00262                 return -1;
00263         }
00264 
00265         if(argv[0] == "default") {
00266                 return handleNamedArgs(namedArgs);
00267         }
00268 
00269         BLCMDvirtualdetector *t = new BLCMDvirtualdetector(defaultVirtualDetector);
00270         t->setName(argv[0]);
00271         int retval = t->handleNamedArgs(namedArgs);
00272 
00273         t->coordinateType = BLCoordinates::getCoordinateType(t->coordinates);
00274 
00275         if(t->maxStep < 0.0) t->maxStep = Param.getDouble("maxStep");
00276 
00277         // check material exists
00278         if(t->material.size() > 0) getMaterial(t->material,false);
00279 
00280         // ascii->bltrackfile format, for accuracy and consistency of output
00281         for(unsigned i=0; i<t->format.size(); ++i)
00282                 t->format[i] = tolower(t->format[i]);
00283         if(t->format == "ascii")
00284                 t->format = "bltrackfile";
00285 
00286         t->print(argv[0]);
00287 
00288         return retval;
00289 }

void BLCMDvirtualdetector::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for the command.

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), color, coordinates, filename, format, height, innerRadius, kill, length, material, maxStep, noSingles, radius, referenceParticle, require, and width.

00292 {
00293         argDouble(radius,"radius","The radius of the circular VirtualDetector (mm).");
00294         argDouble(innerRadius,"innerRadius","The inner radius of the circular VirtualDetector (0 mm, solid).");
00295         argDouble(height,"height","The height of the rectangular VirtualDetector (mm).");
00296         argDouble(width,"width","The width of the rectangular VirtualDetector (mm).");
00297         argDouble(length,"length","The length of the VirtualDetector (mm).");
00298         argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm).");
00299         argString(material,"material","The material of the VirtualDetector.");
00300         argString(color,"color","The color of the VirtualDetector (''=invisible).");
00301         argInt(noSingles,"noSingles","Set to 1 to omit the NTuple for singles.");
00302         argString(format,"format","NTuple format: (see above for list).");
00303         argString(filename,"filename","filename ('' uses name to determine filename)");
00304         argString(filename,"file","alias for filename");
00305         argString(require,"require","Expression which must be nonzero to include the track (default=1)",false);
00306         argInt(referenceParticle,"referenceParticle","Set to 1 to include the Reference Particle.");
00307         argString(coordinates,"coordinates","Coordinates: global, centerline, or reference (default=c).");
00308         argInt(kill,"kill","Set to 1 kill all tracks after entering them into NTuple(s).");
00309 }

void BLCMDvirtualdetector::argChanged (  )  [virtual]

argChanged() does internal computations after some arg changed

Reimplemented from BLCommand.

References height, radius, and width.

00312 {
00313         if(radius > 0.0) width = height = radius*2.0;
00314 }

void BLCMDvirtualdetector::help ( bool  detailed  )  [inline, virtual]

help() prints help text.

Reimplemented from BLCommand.

References BLCommand::description, BLTrackNTuple::getFormatList(), and BLCommand::help().

00105                                  {
00106                 if(description[description.size()-2] == ':')
00107                         description += BLTrackNTuple::getFormatList(); 
00108                 BLCommand::help(detailed);
00109         }

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

construct() will construct the virtualdetector. Used for normal placements of a VirtualDetector object.

Implements BLElement.

References color, coordinateType, filename, format, BLParam::getDouble(), BLCommand::getMaterial(), BLElement::getName(), BLManager::getObject(), BLCommand::getVisAttrib(), height, innerRadius, kill, length, material, maxStep, BLVirtualDetectorNTuple::needsReference(), noSingles, Param, BLCommand::printError(), radius, referenceParticle, BLManager::registerBeamStep(), BLManager::registerReferenceParticleStep(), require, solid, and width.

00322 {
00323         G4Material *mat;
00324         if(material != "")
00325                 mat = getMaterial(material);
00326         else
00327                 mat = parent->GetMaterial();
00328 
00329         G4String thisname = parentName+getName();
00330 
00331         if(!solid) {
00332                 if(radius > 0.0) {
00333                         solid = new G4Tubs(thisname+"Tubs", innerRadius, radius,
00334                                         length/2.0, 0.0, 2.0*pi);
00335                 } else if(height > 0.0 && width > 0.0) {
00336                         solid = new G4Box(thisname+"Box",width/2.0,
00337                                         height/2.0,length/2.0);
00338                 } else {
00339                         printError("virtualdetector::construct %s INVALID - no "
00340                                 "radius or height&width",thisname.c_str());
00341                         return;
00342                 }
00343         }
00344         G4LogicalVolume *lv = new G4LogicalVolume(solid,mat, thisname+"LogVol");
00345         lv->SetVisAttributes(getVisAttrib(color));
00346         if(maxStep < 0.0) maxStep = Param.getDouble("maxStep");
00347         lv->SetUserLimits(new G4UserLimits(maxStep));
00348 
00349         // geant4 rotation convention is backwards from g4beamline
00350         G4RotationMatrix *g4rot = 0;
00351         if(relativeRotation)
00352                 g4rot = new G4RotationMatrix(relativeRotation->inverse());
00353 
00354         G4VPhysicalVolume *pv = new G4PVPlacement(g4rot, relativePosition,
00355                                         lv,thisname,parent,false,0);
00356 
00357         // get globalRotation and globalPosition
00358         G4RotationMatrix *globalRotation = 0;
00359         if(relativeRotation && parentRotation) {
00360                 globalRotation = 
00361                     new G4RotationMatrix(*parentRotation * *relativeRotation);
00362         } else if(relativeRotation) {
00363                 globalRotation = relativeRotation;
00364         } else if(parentRotation) {
00365                 globalRotation = parentRotation;
00366         }
00367         G4ThreeVector globalPosition(relativePosition + parentPosition);
00368         if(globalRotation)
00369                 globalPosition = *globalRotation * relativePosition +
00370                                 parentPosition;
00371 
00372         BLVirtualDetectorNTuple *nt = new BLVirtualDetectorNTuple(format,
00373                         "VirtualDetector",thisname,pv,noSingles,filename,
00374                         require,coordinateType,kill);
00375 
00376         BLManager::getObject()->registerBeamStep(pv,nt);
00377         if(referenceParticle != 0 || nt->needsReference())
00378                 BLManager::getObject()->registerReferenceParticleStep(pv,nt);
00379 
00380         printf("BLCMDvirtualdetector::Construct %s parent=%s relZ=%.1f globZ=%.1f\n",
00381                 thisname.c_str(),parentName.c_str(),relativePosition[2],
00382                 globalPosition[2]);
00383 }

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

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

Implements BLElement.

References length.

00121 { return length; }

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

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

Implements BLElement.

References width.

00124 { return width; }

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

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

Implements BLElement.

References height.

00127 { return height; }

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

isOK() returns true.

Implements BLElement.

00130 { return true; }

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

generatePoints() from BLElement

Implements BLElement.

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

00433 {
00434         if(radius > 0.0)
00435                 generateTubs(npoints, innerRadius, radius, 0.0, 360.0*deg, length, v);
00436         else
00437                 generateBox(npoints,width,height,length,v);
00438 }

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

isOutside() from BLElement

Implements BLElement.

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

00441 {
00442         if(radius > 0.0) {
00443                 G4double r = sqrt(local[0]*local[0]+local[1]*local[1]);
00444                 return r > radius-tolerance || r < innerRadius+tolerance ||
00445                         fabs(local[2]) > length/2.0-tolerance;
00446         } else {
00447                 return fabs(local[0]) > width/2.0-tolerance ||
00448                         fabs(local[1]) > height/2.0-tolerance ||
00449                         fabs(local[2]) > length/2.0-tolerance;
00450         }
00451 }


Member Data Documentation

G4double BLCMDvirtualdetector::radius [private]

G4double BLCMDvirtualdetector::height [private]

G4double BLCMDvirtualdetector::width [private]

G4double BLCMDvirtualdetector::length [private]

G4String BLCMDvirtualdetector::material [private]

G4String BLCMDvirtualdetector::color [private]

G4VSolid* BLCMDvirtualdetector::solid [private]

G4double BLCMDvirtualdetector::maxStep [private]

G4String BLCMDvirtualdetector::format [private]

G4String BLCMDvirtualdetector::filename [private]

G4String BLCMDvirtualdetector::require [private]

G4int BLCMDvirtualdetector::kill [private]


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