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 BLNTuple 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
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, BLCommand::description, filename, format, BLNTuple::getFormatList(), height, innerRadius, kill, length, material, maxStep, noSingles, radius, referenceParticle, BLCommand::registerCommand(), require, BLCommand::setDescription(), BLCommand::setSynopsis(), solid, and width.

Referenced by clone(), and command().

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

BLCMDvirtualdetector::~BLCMDvirtualdetector (  )  [virtual]

Destructor.

References solid.

00221 {
00222         if(solid) delete solid;
00223 }

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.

00225                                                                         : BLElement(r)
00226 {
00227         radius = r.radius;
00228         innerRadius = r.innerRadius;
00229         height = r.height;
00230         width = r.width;
00231         length = r.length;
00232         material = r.material;
00233         color = r.color;
00234         solid = r.solid;
00235         maxStep = r.maxStep;
00236         noSingles = r.noSingles;
00237         format = r.format;
00238         filename = r.filename;
00239         referenceParticle = r.referenceParticle;
00240         coordinates = r.coordinates;
00241         kill = r.kill;
00242         require = r.require;
00243         coordinateType = r.coordinateType;
00244 }


Member Function Documentation

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

clone()

Implements BLElement.

References BLCMDvirtualdetector().

00089 { return new BLCMDvirtualdetector(*this); }

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

commandName() returns "virtualdetector".

Implements BLCommand.

00095 { 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().

00247 {
00248         if(argv.size() != 1) {
00249                 printError("virtualdetector: Invalid command, must have name");
00250                 return -1;
00251         }
00252 
00253         if(argv[0] == "default") {
00254                 return defaultVirtualDetector.handleNamedArgs(namedArgs);
00255         }
00256 
00257         BLCMDvirtualdetector *t = new BLCMDvirtualdetector(defaultVirtualDetector);
00258         t->setName(argv[0]);
00259         int retval = t->handleNamedArgs(namedArgs);
00260 
00261         t->coordinateType = BLCoordinates::getCoordinateType(t->coordinates);
00262 
00263         if(t->maxStep < 0.0) t->maxStep = Param.getDouble("maxStep");
00264 
00265         // check material exists
00266         if(t->material.size() > 0) getMaterial(t->material,false);
00267 
00268         // ascii->bltrackfile format, for accuracy and consistency of output
00269         for(unsigned i=0; i<t->format.size(); ++i)
00270                 t->format[i] = tolower(t->format[i]);
00271         if(t->format == "ascii")
00272                 t->format = "bltrackfile";
00273 
00274         t->print(argv[0]);
00275 
00276         return retval;
00277 }

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.

00280 {
00281         argDouble(radius,"radius","The radius of the circular VirtualDetector (mm).");
00282         argDouble(innerRadius,"innerRadius","The inner radius of the circular VirtualDetector (0 mm, solid).");
00283         argDouble(height,"height","The height of the rectangular VirtualDetector (mm).");
00284         argDouble(width,"width","The width of the rectangular VirtualDetector (mm).");
00285         argDouble(length,"length","The length of the VirtualDetector (mm).");
00286         argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm).");
00287         argString(material,"material","The material of the VirtualDetector.");
00288         argString(color,"color","The color of the VirtualDetector (''=invisible).");
00289         argInt(noSingles,"noSingles","Set to 1 to omit the NTuple for singles.");
00290         argString(format,"format","NTuple format: (see above for list).");
00291         argString(filename,"filename","filename ('' uses name to determine filename)");
00292         argString(filename,"file","alias for filename");
00293         argString(require,"require","Expression which must be nonzero to include the track (default=1)",false);
00294         argInt(referenceParticle,"referenceParticle","Set to 1 to include the Reference Particle.");
00295         argString(coordinates,"coordinates","Coordinates: global, centerline, or reference (default=c).");
00296         argInt(kill,"kill","Set to 1 kill all tracks after entering them into NTuple(s).");
00297 }

void BLCMDvirtualdetector::argChanged (  )  [virtual]

argChanged() does internal computations after some arg changed

Reimplemented from BLCommand.

References height, radius, and width.

00300 {
00301         if(radius > 0.0) width = height = radius*2.0;
00302 }

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.

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

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

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

Implements BLElement.

References length.

00116 { return length; }

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

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

Implements BLElement.

References width.

00119 { return width; }

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

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

Implements BLElement.

References height.

00122 { return height; }

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

isOK() returns true.

Implements BLElement.

00125 { 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.

00497 {
00498         if(radius > 0.0)
00499                 generateTubs(npoints, innerRadius, radius, 0.0, 360.0*deg, length, v);
00500         else
00501                 generateBox(npoints,width,height,length,v);
00502 }

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

isOutside() from BLElement

Implements BLElement.

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

00505 {
00506         if(radius > 0.0) {
00507                 G4double r = sqrt(local[0]*local[0]+local[1]*local[1]);
00508                 return r > radius-tolerance || r < innerRadius+tolerance ||
00509                         fabs(local[2]) > length/2.0-tolerance;
00510         } else {
00511                 return fabs(local[0]) > width/2.0-tolerance ||
00512                         fabs(local[1]) > height/2.0-tolerance ||
00513                         fabs(local[2]) > length/2.0-tolerance;
00514         }
00515 }


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