BLCMDnewparticlentuple Class Reference

Inheritance diagram for BLCMDnewparticlentuple:

BLCommand BLManager::TrackingAction

List of all members.


Detailed Description

class BLCMDnewparticlentuple - NTuple for tracks where they are created.

Public Member Functions

 BLCMDnewparticlentuple ()
 BLCMDnewparticlentuple (BLCMDnewparticlentuple &r)
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
void PreUserTrackingAction (const G4Track *track)
 PreUserTrackingAction() from BLManager::TrackingAction.
void PostUserTrackingAction (const G4Track *track)
 PostUserTrackingAction() from BLManager::TrackingAction.

Private Attributes

G4String name
G4String format
G4String filename
G4String require
G4String coordinates
BLCoordinateType coordinateType
BLNTuplentuple
BLEvaluatoreval

Constructor & Destructor Documentation

BLCMDnewparticlentuple::BLCMDnewparticlentuple (  ) 

References BLCMDTYPE_DATA, BLCOORD_CENTERLINE, coordinates, coordinateType, BLCommand::description, eval, filename, format, BLNTuple::getFormatList(), name, ntuple, BLCommand::registerCommand(), require, BLCommand::setDescription(), and BLCommand::setSynopsis().

Referenced by command().

00063                                                : BLCommand(),
00064                                                 BLManager::TrackingAction()
00065 {
00066         registerCommand(BLCMDTYPE_DATA);
00067         setSynopsis("NTuple containing particle tracks when created.");
00068         setDescription("Note that initial beam particles are included, unless "
00069                 "require is set to 'Parent>0'. "
00070                 "NTuple Variables:\n"
00071                 "    x,y,z (mm)\n"
00072                 "    Px,Py,Pz (MeV/c)\n"
00073                 "    t (ns)\n"
00074                 "    PDGid (11=e-, 13=mu-, 22=gamma, 211=pi+, 2212=proton, ...)\n"
00075                 "    EventID (may be inexact above 16,777,215)\n"
00076                 "    TrackID\n"
00077                 "    ParentID (0 => primary particle)\n"
00078                 "    Weight (defaults to 1.0)\n\n"
00079                 "Valid Formats (ignore case): ");
00080         description += BLNTuple::getFormatList(); 
00081 
00082         name = "";
00083         format = "";
00084         filename = "";
00085         require = "";
00086         coordinates = "Centerline";
00087         coordinateType = BLCOORD_CENTERLINE;
00088         ntuple = 0;
00089         eval = 0;
00090 }

BLCMDnewparticlentuple::BLCMDnewparticlentuple ( BLCMDnewparticlentuple r  ) 

References coordinates, coordinateType, eval, filename, format, name, ntuple, and require.

00092                                                                         : BLCommand(r), 
00093                                                 BLManager::TrackingAction(r)
00094 {
00095         name = r.name;
00096         format = r.format;
00097         filename = r.filename;
00098         require = r.require;
00099         coordinates = r.coordinates;
00100         coordinateType = r.coordinateType;
00101         ntuple = 0;
00102         eval = 0;
00103 }


Member Function Documentation

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

Implements BLCommand.

00047 { return "newparticlentuple"; }

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

Implements BLCommand.

References BLCMDnewparticlentuple(), coordinates, coordinateType, BLNTuple::create(), eval, filename, format, BLCoordinates::getCoordinateType(), BLManager::getObject(), BLCommand::handleNamedArgs(), name, ntuple, BLCommand::print(), BLCommand::printError(), BLManager::registerTrackingAction(), require, and TrackFields.

00106 {
00107         if(argv.size() != 1) {
00108                 printError("Invalid newparticlentuple command -- need name");
00109                 return -1;
00110         }
00111 
00112         if(argv[0] == "default") {
00113                 handleNamedArgs(namedArgs);
00114                 return -1;
00115         }
00116 
00117         BLCMDnewparticlentuple *t = new BLCMDnewparticlentuple(defaultNewParticleNTuple);
00118         int retval = t->handleNamedArgs(namedArgs);
00119 
00120         // ascii->bltrackfile format, for accuracy and consistency of output
00121         for(unsigned i=0; i<t->format.size(); ++i)
00122                 t->format[i] = tolower(t->format[i]);
00123         if(t->format == "ascii")
00124                 t->format = "bltrackfile";
00125 
00126         t->name = argv[0];
00127         t->ntuple = BLNTuple::create(t->format,"NTuple",t->name,TrackFields,
00128                                                         t->filename);
00129 
00130         t->coordinateType = BLCoordinates::getCoordinateType(t->coordinates);
00131         if(t->require != "") t->eval = new BLEvaluator();
00132 
00133         t->print(argv[0]);
00134 
00135         BLManager::getObject()->registerTrackingAction(t);
00136 
00137         return retval;
00138 }

void BLCMDnewparticlentuple::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argString(), coordinates, filename, format, and require.

00141 {
00142         argString(format,"format","The NTuple format (see above for list).");
00143         argString(filename,"filename","The filename for the NTuple.");
00144         argString(filename,"file","Synonym for filename.");
00145         argString(require,"require","Expression which must be nonzero to include the track (default=1)",false);
00146         argString(coordinates,"coordinates","Coordinates: global, centerline, or reference (default=c).");
00147 }

void BLCMDnewparticlentuple::PreUserTrackingAction ( const G4Track *  track  )  [virtual]

PreUserTrackingAction() from BLManager::TrackingAction.

Implements BLManager::TrackingAction.

References BLNTuple::appendRow(), BEAM, BLCOORD_REFERENCE, coordinateType, eval, BLEvaluator::evaluate(), BLCoordinates::getCoords(), BLManager::getExternalParentID(), BLManager::getExternalTrackID(), BLManager::getObject(), BLCoordinates::getRotation(), BLManager::getState(), BLEvaluator::isOK(), BLCoordinates::isValid(), NTrackFields, ntuple, BLCommand::printError(), require, and BLEvaluator::setTrackVariables().

00150 {
00151         // only use reference coordinates when they are valid
00152         BLManagerState state = BLManager::getObject()->getState();
00153         if(coordinateType == BLCOORD_REFERENCE && state != BEAM) return;
00154 
00155         if(eval) {
00156                 eval->setTrackVariables(track,coordinateType);
00157                 G4double v = eval->evaluate(require);
00158                 if(!eval->isOK()) {
00159                         BLCommand::printError("newparticlentuple: invalid expression require='%s'\n",
00160                                 require.c_str());
00161                         delete eval;
00162                         eval = 0;
00163                         v = 1.0;
00164                 }
00165                 if(v == 0.0) return;
00166         }
00167 
00168         G4RunManager* runmgr = G4RunManager::GetRunManager();
00169         const G4Event* event = runmgr->GetCurrentEvent();
00170         int evId = event->GetEventID();
00171         G4ThreeVector position = track->GetPosition();
00172         G4double time = track->GetGlobalTime();
00173         G4ThreeVector momentum = track->GetMomentum();
00174 
00175         // transform to desired coordinates, if available
00176         BLCoordinates *c = (BLCoordinates *)track->GetUserInformation();
00177         if(c && c->isValid()) {
00178                 c->getCoords(coordinateType,position);
00179                 momentum = c->getRotation() * momentum;
00180         }
00181 
00182         float data[12];
00183         data[0] = position[0]/mm;               // x (mm)
00184         data[1] = position[1]/mm;               // y (mm)
00185         data[2] = position[2]/mm;               // z (mm)
00186         data[3] = momentum[0]/MeV;              // Px (MeV/c)
00187         data[4] = momentum[1]/MeV;              // Py (MeV/c)
00188         data[5] = momentum[2]/MeV;              // Pz (MeV/c)
00189         data[6] = time/ns;                      // t (ns)
00190         data[7] = track->GetDefinition()->GetPDGEncoding();
00191         data[8] = evId;                         // Event ID
00192         data[9] = 
00193             BLManager::getObject()->getExternalTrackID(track);
00194         data[10] = 
00195             BLManager::getObject()->getExternalParentID(track);
00196         data[11] = track->GetWeight();          // Weight
00197 
00198         if(ntuple) ntuple->appendRow(data,NTrackFields);
00199 }

void BLCMDnewparticlentuple::PostUserTrackingAction ( const G4Track *  track  )  [inline, virtual]


Member Data Documentation

G4String BLCMDnewparticlentuple::name [private]

Referenced by BLCMDnewparticlentuple(), and command().

G4String BLCMDnewparticlentuple::format [private]

G4String BLCMDnewparticlentuple::require [private]


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