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. | |
BLElement * | clone () |
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 |
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().
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 uses centerline coordinates, if available.\n" 00182 "NTuple Variables:\n" 00183 " X,Y,Z (mm)\n" 00184 " Px,Py,Pz (MeV/c)\n" 00185 " T (ns)\n" 00186 " PDGid (11=e-, 13=mu-, 22=gamma, 211=pi+, 2212=proton, ...)\n" 00187 " EventNum (inexact above 16,777,215)\n" 00188 " TrackID\n" 00189 " ParentID (0 => primary particle)\n" 00190 " Weight (defaults to 1.0)\n" 00191 "\nThe NTuple of the virtualdetector can be included in an " 00192 "ntuple command by including a pattern that matches its name " 00193 "in the 'detectors' argument to the ntuple. Note that must " 00194 "match the name as placed (i.e. includes rename=), not the " 00195 "name given to this command. The noSingles argument may be " 00196 "useful in this case to avoid a huge NTuple of singles.\n\n" 00197 "Note that secondari particles created in the virtualdetector " 00198 "will not get an atry until they have taken one step.\n\n" 00199 "Valid Formats (ignore case): "); 00200 description += BLNTuple::getFormatList(); 00201 00202 // initial field values 00203 radius = 0.0; 00204 innerRadius = 0.0; 00205 height = 0.0; 00206 width = 0.0; 00207 length = 1.0*mm; 00208 material = ""; 00209 color = "1,1,1"; 00210 solid = 0; 00211 maxStep = -99.0; 00212 noSingles = 0; 00213 format = "root"; 00214 filename = ""; 00215 require = ""; 00216 referenceParticle = 0; 00217 coordinates = "Centerline"; 00218 kill = 0; 00219 coordinateType = BLCOORD_CENTERLINE; 00220 }
BLCMDvirtualdetector::~BLCMDvirtualdetector | ( | ) | [virtual] |
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.
00227 : BLElement(r) 00228 { 00229 radius = r.radius; 00230 innerRadius = r.innerRadius; 00231 height = r.height; 00232 width = r.width; 00233 length = r.length; 00234 material = r.material; 00235 color = r.color; 00236 solid = r.solid; 00237 maxStep = r.maxStep; 00238 noSingles = r.noSingles; 00239 format = r.format; 00240 filename = r.filename; 00241 referenceParticle = r.referenceParticle; 00242 coordinates = r.coordinates; 00243 kill = r.kill; 00244 require = r.require; 00245 coordinateType = r.coordinateType; 00246 }
BLElement* BLCMDvirtualdetector::clone | ( | ) | [inline, virtual] |
Implements BLElement.
References BLCMDvirtualdetector().
00093 { return new BLCMDvirtualdetector(*this); }
G4String BLCMDvirtualdetector::commandName | ( | ) | [inline, virtual] |
int BLCMDvirtualdetector::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
command() implements the virtualdetector command.
Implements BLCommand.
References BLCMDvirtualdetector(), coordinates, coordinateType, BLCoordinates::getCoordinateType(), BLParam::getDouble(), BLCommand::getMaterial(), BLCommand::handleNamedArgs(), material, maxStep, Param, BLCommand::print(), BLCommand::printError(), and BLElement::setName().
00249 { 00250 if(argv.size() != 1) { 00251 printError("virtualdetector: Invalid command, must have name"); 00252 return -1; 00253 } 00254 00255 if(argv[0] == "default") { 00256 return defaultVirtualDetector.handleNamedArgs(namedArgs); 00257 } 00258 00259 BLCMDvirtualdetector *t = new BLCMDvirtualdetector(defaultVirtualDetector); 00260 t->setName(argv[0]); 00261 int retval = t->handleNamedArgs(namedArgs); 00262 00263 t->coordinateType = BLCoordinates::getCoordinateType(t->coordinates); 00264 00265 if(t->maxStep < 0.0) t->maxStep = Param.getDouble("maxStep"); 00266 00267 // check material exists 00268 if(t->material.size() > 0) getMaterial(t->material,false); 00269 00270 t->print(argv[0]); 00271 00272 return retval; 00273 }
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.
00276 { 00277 argDouble(radius,"radius","The radius of the circular VirtualDetector (mm)."); 00278 argDouble(innerRadius,"innerRadius","The inner radius of the circular VirtualDetector (0 mm, solid)."); 00279 argDouble(height,"height","The height of the rectangular VirtualDetector (mm)."); 00280 argDouble(width,"width","The width of the rectangular VirtualDetector (mm)."); 00281 argDouble(length,"length","The length of the VirtualDetector (mm)."); 00282 argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm)."); 00283 argString(material,"material","The material of the VirtualDetector."); 00284 argString(color,"color","The color of the VirtualDetector (''=invisible)."); 00285 argInt(noSingles,"noSingles","Set to 1 to omit the NTuple for singles."); 00286 argString(format,"format","NTuple format: (see above for list)."); 00287 argString(filename,"filename","filename ('' uses name to determine filename)"); 00288 argString(filename,"file","alias for filename"); 00289 argString(require,"require","Expression which must be nonzero to include the track (default=1)",false); 00290 argInt(referenceParticle,"referenceParticle","Set to 1 to include the Reference Particle."); 00291 argString(coordinates,"coordinates","Coordinates: global, centerline, or reference (default=c)."); 00292 argInt(kill,"kill","Set to 1 kill all tracks after entering them into NTuple(s)."); 00293 }
void BLCMDvirtualdetector::argChanged | ( | ) | [virtual] |
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.
00306 { 00307 G4Material *mat; 00308 if(material != "") 00309 mat = getMaterial(material); 00310 else 00311 mat = parent->GetMaterial(); 00312 00313 G4String thisname = parentName+getName(); 00314 00315 if(!solid) { 00316 if(radius > 0.0) { 00317 solid = new G4Tubs(thisname+"Tubs", innerRadius, radius, 00318 length/2.0, 0.0, 2.0*pi); 00319 } else if(height > 0.0 && width > 0.0) { 00320 solid = new G4Box(thisname+"Box",width/2.0, 00321 height/2.0,length/2.0); 00322 } else { 00323 printError("virtualdetector::construct %s INVALID - no " 00324 "radius or height&width",thisname.c_str()); 00325 return; 00326 } 00327 } 00328 G4LogicalVolume *lv = new G4LogicalVolume(solid,mat, thisname+"LogVol"); 00329 lv->SetVisAttributes(getVisAttrib(color)); 00330 if(maxStep < 0.0) maxStep = Param.getDouble("maxStep"); 00331 lv->SetUserLimits(new G4UserLimits(maxStep)); 00332 00333 // geant4 rotation convention is backwards from g4beamline 00334 G4RotationMatrix *g4rot = 0; 00335 if(relativeRotation) 00336 g4rot = new G4RotationMatrix(relativeRotation->inverse()); 00337 00338 G4VPhysicalVolume *pv = new G4PVPlacement(g4rot, relativePosition, 00339 lv,thisname,parent,false,0); 00340 00341 // get globalRotation and globalPosition 00342 G4RotationMatrix *globalRotation = 0; 00343 if(relativeRotation && parentRotation) { 00344 globalRotation = 00345 new G4RotationMatrix(*parentRotation * *relativeRotation); 00346 } else if(relativeRotation) { 00347 globalRotation = relativeRotation; 00348 } else if(parentRotation) { 00349 globalRotation = parentRotation; 00350 } 00351 G4ThreeVector globalPosition(relativePosition + parentPosition); 00352 if(globalRotation) 00353 globalPosition = *globalRotation * relativePosition + 00354 parentPosition; 00355 00356 BLVirtualDetectorNTuple *nt = new BLVirtualDetectorNTuple(format, 00357 "VirtualDetector",thisname,pv,noSingles,filename, 00358 require,coordinateType,kill); 00359 00360 BLManager::getObject()->registerBeamStep(pv,nt); 00361 if(referenceParticle != 0 || nt->needsReference()) 00362 BLManager::getObject()->registerReferenceParticleStep(pv,nt); 00363 00364 printf("BLCMDvirtualdetector::Construct %s parent=%s relZ=%.1f globZ=%.1f\n", 00365 thisname.c_str(),parentName.c_str(),relativePosition[2], 00366 globalPosition[2]); 00367 }
virtual G4double BLCMDvirtualdetector::getLength | ( | ) | [inline, virtual] |
getLength() returns this element's Length along the Z axis.
Implements BLElement.
References length.
00120 { return length; }
virtual G4double BLCMDvirtualdetector::getWidth | ( | ) | [inline, virtual] |
getWidth() returns this element's Width along the X axis.
Implements BLElement.
References width.
00123 { return width; }
virtual G4double BLCMDvirtualdetector::getHeight | ( | ) | [inline, virtual] |
getHeight() returns this element's height along the Y axis.
Implements BLElement.
References height.
00126 { return height; }
virtual G4bool BLCMDvirtualdetector::isOK | ( | ) | [inline, virtual] |
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.
00499 { 00500 if(radius > 0.0) 00501 generateTubs(npoints, innerRadius, radius, 0.0, 360.0*deg, length, v); 00502 else 00503 generateBox(npoints,width,height,length,v); 00504 }
G4bool BLCMDvirtualdetector::isOutside | ( | G4ThreeVector & | local, | |
G4double | tolerance | |||
) | [virtual] |
isOutside() from BLElement
Implements BLElement.
References height, innerRadius, length, radius, and width.
00507 { 00508 if(radius > 0.0) { 00509 G4double r = sqrt(local[0]*local[0]+local[1]*local[1]); 00510 return r > radius-tolerance || r < innerRadius+tolerance || 00511 fabs(local[2]) > length/2.0-tolerance; 00512 } else { 00513 return fabs(local[0]) > width/2.0-tolerance || 00514 fabs(local[1]) > height/2.0-tolerance || 00515 fabs(local[2]) > length/2.0-tolerance; 00516 } 00517 }
G4double BLCMDvirtualdetector::radius [private] |
Referenced by argChanged(), BLCMDvirtualdetector(), construct(), defineNamedArgs(), generatePoints(), and isOutside().
G4double BLCMDvirtualdetector::innerRadius [private] |
Referenced by BLCMDvirtualdetector(), construct(), defineNamedArgs(), generatePoints(), and isOutside().
G4double BLCMDvirtualdetector::height [private] |
Referenced by argChanged(), BLCMDvirtualdetector(), construct(), defineNamedArgs(), generatePoints(), getHeight(), and isOutside().
G4double BLCMDvirtualdetector::width [private] |
Referenced by argChanged(), BLCMDvirtualdetector(), construct(), defineNamedArgs(), generatePoints(), getWidth(), and isOutside().
G4double BLCMDvirtualdetector::length [private] |
Referenced by BLCMDvirtualdetector(), construct(), defineNamedArgs(), generatePoints(), getLength(), and isOutside().
G4String BLCMDvirtualdetector::material [private] |
Referenced by BLCMDvirtualdetector(), command(), construct(), and defineNamedArgs().
G4String BLCMDvirtualdetector::color [private] |
Referenced by BLCMDvirtualdetector(), construct(), and defineNamedArgs().
G4VSolid* BLCMDvirtualdetector::solid [private] |
Referenced by BLCMDvirtualdetector(), construct(), and ~BLCMDvirtualdetector().
G4double BLCMDvirtualdetector::maxStep [private] |
Referenced by BLCMDvirtualdetector(), command(), construct(), and defineNamedArgs().
G4int BLCMDvirtualdetector::noSingles [private] |
Referenced by BLCMDvirtualdetector(), construct(), and defineNamedArgs().
G4String BLCMDvirtualdetector::format [private] |
Referenced by BLCMDvirtualdetector(), construct(), and defineNamedArgs().
G4String BLCMDvirtualdetector::filename [private] |
Referenced by BLCMDvirtualdetector(), construct(), and defineNamedArgs().
G4String BLCMDvirtualdetector::require [private] |
Referenced by BLCMDvirtualdetector(), construct(), and defineNamedArgs().
G4int BLCMDvirtualdetector::referenceParticle [private] |
Referenced by BLCMDvirtualdetector(), construct(), and defineNamedArgs().
G4String BLCMDvirtualdetector::coordinates [private] |
Referenced by BLCMDvirtualdetector(), command(), and defineNamedArgs().
G4int BLCMDvirtualdetector::kill [private] |
Referenced by BLCMDvirtualdetector(), construct(), and defineNamedArgs().
Referenced by BLCMDvirtualdetector(), command(), and construct().