#include <BLTrackNTuple.hh>
This class implements two new formats that add additional fields to the NTuple: asciiEnhanced, rootEnhanced.
Public Member Functions | |
virtual | ~BLTrackNTuple () |
Destructor. | |
void | close () |
close() will close the ntuple | |
void | appendTrack (const G4Track *track) |
appendTrack() appends the data for this Track to the NTuple. Uses arguments to create(): If the require expression is nonempty and evaluates to zero, no entry is made to the NTuple or callbacks. If noSingles is nonzero, the NTuple itself is not filled, but callbacks are made (to fill NTuples created by the ntuple command). | |
void | appendTrack (const G4Track *track, double time, G4ThreeVector position, G4ThreeVector momentum, double properTime, double trackLength) |
appendTrack() appends the data for this Track, with updated values of the other arguments | |
G4String | getName () const |
getName() returns the name of the NTuple (not including category) | |
G4String | getFields () |
getFields() returns a colon-separated list of the fields. | |
virtual void | annotate (G4String line) |
annotate() will add an annotation line to any ASCII format. Normally line should begin with a "#", and have no "\r" or "\n". line == "" will output an empty line to ASCII files. Ignored for NTuples that don't support annotations. | |
virtual bool | needsReference () |
needsReference() returns true if this NTuple needs the Reference particle. | |
Static Public Member Functions | |
static BLTrackNTuple * | create (G4String format, G4String category, G4String name, G4String filename, BLCoordinateType coordinateType=BLCOORD_CENTERLINE, G4String _require="", int _noSingles=0) |
create() will create a new NTuple for writing. Note that the field names are handled internally, and that the format can change the fields used. format must be a known format of NTuple ("" is default). "category/name" is the name of the NTuple (the "/" may be omitted if category is null, depending on format). filename is a hint, and is not used by all formats. coordinateType is the type of coordiantes to use. require is an expression using track variables that must be nonzero to enter a Step into the NTuple. If noSingles is nonzero, the NTuple itself is not filled, but callbacks are made (to fill NTuples created by the ntuple command). | |
static G4String | getFormatList () |
getFormatList() returns a list of known formats. This class implements asciiEnhanced and rootEnhanced. | |
Protected Member Functions | |
BLTrackNTuple () | |
Constructor. | |
Private Attributes | |
BLNTuple * | ntuple |
G4String | require |
BLEvaluator * | eval |
int | noSingles |
int | nFields |
BLCoordinateType | coordinateType |
BLTrackNTuple::BLTrackNTuple | ( | ) | [protected] |
Constructor.
References BLCOORD_CENTERLINE, coordinateType, eval, nFields, noSingles, ntuple, and require.
Referenced by create().
00035 { 00036 ntuple = 0; 00037 require = ""; 00038 eval = 0; 00039 noSingles = 0; 00040 nFields = 0; 00041 coordinateType = BLCOORD_CENTERLINE; 00042 }
virtual BLTrackNTuple::~BLTrackNTuple | ( | ) | [inline, virtual] |
void BLTrackNTuple::close | ( | ) | [inline] |
close() will close the ntuple
References BLNTuple::close(), and ntuple.
Referenced by TraceNTuple::close().
BLTrackNTuple * BLTrackNTuple::create | ( | G4String | format, | |
G4String | category, | |||
G4String | name, | |||
G4String | filename, | |||
BLCoordinateType | coordinateType = BLCOORD_CENTERLINE , |
|||
G4String | _require = "" , |
|||
int | _noSingles = 0 | |||
) | [static] |
create() will create a new NTuple for writing. Note that the field names are handled internally, and that the format can change the fields used. format must be a known format of NTuple ("" is default). "category/name" is the name of the NTuple (the "/" may be omitted if category is null, depending on format). filename is a hint, and is not used by all formats. coordinateType is the type of coordiantes to use. require is an expression using track variables that must be nonzero to enter a Step into the NTuple. If noSingles is nonzero, the NTuple itself is not filled, but callbacks are made (to fill NTuples created by the ntuple command).
References BLTrackNTuple(), coordinateType, BLNTuple::create(), eval, EXTENDED, fieldNames, nFields, noSingles, ntuple, require, STANDARD, and TRACE.
Referenced by BLVirtualDetectorNTuple::BLVirtualDetectorNTuple(), BLCMDnewparticlentuple::command(), BLCMDbeamlossntuple::command(), BLCMDzntuple::Entry::Entry(), TimeNTuple::TimeNTuple(), and TraceNTuple::TraceNTuple().
00047 { 00048 BLTrackNTuple *t = new BLTrackNTuple(); 00049 t->require = _require; 00050 t->noSingles = _noSingles; 00051 t->coordinateType = _coordinateType; 00052 t->nFields = STANDARD; 00053 00054 if(t->require != "") t->eval = new BLEvaluator(); 00055 00056 // get nFields and fields based on format 00057 for(G4String::size_type i=0; i<format.size(); ++i) 00058 format[i] = tolower(format[i]); 00059 G4String::size_type j=format.find("trace"); 00060 if(j != format.npos) { 00061 t->nFields = TRACE; 00062 format.erase(j,format.npos); 00063 } 00064 j=format.find("extended"); 00065 if(j != format.npos) { 00066 t->nFields = EXTENDED; 00067 format.erase(j,format.npos); 00068 } 00069 j=format.find("for009"); 00070 if(j != format.npos) { 00071 t->nFields = TRACE; 00072 } 00073 G4String fields=fieldNames[0]; 00074 for(int i=1; i<t->nFields; ++i) { 00075 fields += ":"; 00076 fields += fieldNames[i]; 00077 } 00078 00079 t->ntuple = BLNTuple::create(format,category,name,fields,filename); 00080 if(!t->ntuple) { 00081 delete t; 00082 t = 0; 00083 } 00084 return t; 00085 }
void BLTrackNTuple::appendTrack | ( | const G4Track * | track | ) |
appendTrack() appends the data for this Track to the NTuple. Uses arguments to create(): If the require expression is nonempty and evaluates to zero, no entry is made to the NTuple or callbacks. If noSingles is nonzero, the NTuple itself is not filled, but callbacks are made (to fill NTuples created by the ntuple command).
Referenced by TraceNTuple::appendTrace(), BLCMDbeamlossntuple::PostUserTrackingAction(), BLCMDnewparticlentuple::PreUserTrackingAction(), BLVirtualDetectorNTuple::UserSteppingAction(), TimeNTuple::UserSteppingAction(), and BLCMDzntuple::Entry::UserZSteppingAction().
00088 { 00089 appendTrack(track,track->GetGlobalTime(),track->GetPosition(), 00090 track->GetMomentum(),track->GetProperTime(), 00091 track->GetTrackLength()); 00092 }
void BLTrackNTuple::appendTrack | ( | const G4Track * | track, | |
double | time, | |||
G4ThreeVector | position, | |||
G4ThreeVector | momentum, | |||
double | properTime, | |||
double | trackLength | |||
) |
appendTrack() appends the data for this Track, with updated values of the other arguments
References BLNTuple::appendRow(), B, BLAssert, coordinateType, BLNTuple::doCallbacks(), E, eval, BLEvaluator::evaluate(), EXTENDED, fieldNames, BLCoordinates::getCoords(), BLManager::getExternalParentID(), BLManager::getExternalTrackID(), BLGlobalField::GetFieldValue(), BLGlobalField::getObject(), BLManager::getObject(), BLCoordinates::getRotation(), BLEvaluator::isOK(), BLCoordinates::isValid(), nFields, noSingles, ntuple, require, STANDARD, and TRACE.
00097 { 00098 G4RunManager* runmgr = G4RunManager::GetRunManager(); 00099 const G4Event* event = runmgr->GetCurrentEvent(); 00100 int evId = event->GetEventID(); 00101 G4ThreeVector globalPosition = position; 00102 00103 // transform to desired coordinates, if available 00104 BLCoordinates *coord = (BLCoordinates *)track->GetUserInformation(); 00105 if(coord && coord->isValid()) { 00106 coord->getCoords(coordinateType,position); 00107 momentum = coord->getRotation() * momentum; 00108 } else { 00109 printf("BLCMDvirtualdetector::SteppingAction: track has no " 00110 "BLCoordinates object\n"); 00111 } 00112 00113 double data[EXTENDED]; 00114 BLAssert((unsigned int)nFields <= sizeof(data)/sizeof(data[0])); 00115 data[0] = position[0]/mm; // x (mm) 00116 data[1] = position[1]/mm; // y (mm) 00117 data[2] = position[2]/mm; // z (mm) 00118 data[3] = momentum[0]/MeV; // Px (MeV/c) 00119 data[4] = momentum[1]/MeV; // Py (MeV/c) 00120 data[5] = momentum[2]/MeV; // Pz (MeV/c) 00121 data[6] = time/ns; // t (ns) 00122 data[7] = track->GetDefinition()->GetPDGEncoding(); 00123 data[8] = evId; // Event ID 00124 data[9] = BLManager::getObject()->getExternalTrackID(track); 00125 data[10] = BLManager::getObject()->getExternalParentID(track); 00126 data[11] = track->GetWeight(); // Weight 00127 if(nFields > STANDARD) { 00128 G4double field[6], point[4]; 00129 point[0] = globalPosition[0]; 00130 point[1] = globalPosition[1]; 00131 point[2] = globalPosition[2]; 00132 point[3] = time; 00133 BLGlobalField::getObject()->GetFieldValue(point,field); 00134 G4ThreeVector B(field[0],field[1],field[2]); 00135 G4ThreeVector E(field[3],field[4],field[5]); 00136 if(coord && coord->isValid()) { 00137 B = coord->getRotation() * B; 00138 E = coord->getRotation() * E; 00139 } 00140 data[12] = B[0]/tesla; 00141 data[13] = B[1]/tesla; 00142 data[14] = B[2]/tesla; 00143 data[15] = E[0]/(megavolt/meter); 00144 data[16] = E[1]/(megavolt/meter); 00145 data[17] = E[2]/(megavolt/meter); 00146 } 00147 if(nFields > TRACE) { 00148 G4ThreeVector pol, vertexPosition; 00149 pol = track->GetPolarization(); 00150 if(coord && coord->isValid()) { 00151 pol = coord->getRotation() * pol; 00152 } 00153 vertexPosition = track->GetVertexPosition(); 00154 data[18] = properTime/ns; 00155 data[19] = trackLength/mm; 00156 data[20] = pol[0]; 00157 data[21] = pol[1]; 00158 data[22] = pol[2]; 00159 data[23] = vertexPosition[0]/mm; 00160 data[24] = vertexPosition[1]/mm; 00161 data[25] = vertexPosition[2]/mm; 00162 data[26] = (time - track->GetLocalTime())/ns; 00163 data[27] = track->GetVertexKineticEnergy()/MeV; 00164 } 00165 00166 // implement require 00167 if(eval) { 00168 for(int i=0; i<nFields; ++i) 00169 eval->setVariable(fieldNames[i],data[i]); 00170 double v=eval->evaluate(require.c_str()); 00171 if(!eval->isOK()) 00172 G4Exception("BLTrackNTuple", 00173 "Invalid require expression", 00174 FatalException,require); 00175 if(fabs(v) < 1.0e-16) return; 00176 } 00177 00178 if(noSingles) 00179 ntuple->doCallbacks(data,nFields); 00180 else 00181 ntuple->appendRow(data,nFields); // calls coCallbacks() 00182 }
G4String BLTrackNTuple::getName | ( | ) | const [inline] |
getName() returns the name of the NTuple (not including category)
References BLNTuple::getName(), and ntuple.
G4String BLTrackNTuple::getFields | ( | ) | [inline] |
getFields() returns a colon-separated list of the fields.
References BLNTuple::getFields(), and ntuple.
virtual void BLTrackNTuple::annotate | ( | G4String | line | ) | [inline, virtual] |
annotate() will add an annotation line to any ASCII format. Normally line should begin with a "#", and have no "\r" or "\n". line == "" will output an empty line to ASCII files. Ignored for NTuples that don't support annotations.
References BLNTuple::annotate(), and ntuple.
Referenced by TraceNTuple::annotate().
virtual bool BLTrackNTuple::needsReference | ( | ) | [inline, virtual] |
needsReference() returns true if this NTuple needs the Reference particle.
References BLNTuple::needsReference(), and ntuple.
Referenced by BLCMDzntuple::callback(), and BLVirtualDetectorNTuple::needsReference().
00100 { return ntuple->needsReference(); }
G4String BLTrackNTuple::getFormatList | ( | ) | [static] |
getFormatList() returns a list of known formats. This class implements asciiEnhanced and rootEnhanced.
References BLNTuple::getFormatList().
Referenced by BLCMDzntuple::help(), BLCMDvirtualdetector::help(), BLCMDtrace::help(), BLCMDtimentuple::help(), BLCMDnewparticlentuple::help(), and BLCMDbeamlossntuple::help().
00185 { 00186 G4String s = BLNTuple::getFormatList(); 00187 s += " Extended asciiExtended"; 00188 if(s.find("root") != s.npos) s += " rootExtended"; 00189 return s; 00190 }
BLNTuple* BLTrackNTuple::ntuple [private] |
Referenced by annotate(), appendTrack(), BLTrackNTuple(), close(), create(), getFields(), getName(), needsReference(), and ~BLTrackNTuple().
G4String BLTrackNTuple::require [private] |
Referenced by appendTrack(), BLTrackNTuple(), and create().
BLEvaluator* BLTrackNTuple::eval [private] |
Referenced by appendTrack(), BLTrackNTuple(), create(), and ~BLTrackNTuple().
int BLTrackNTuple::noSingles [private] |
Referenced by appendTrack(), BLTrackNTuple(), and create().
int BLTrackNTuple::nFields [private] |
Referenced by appendTrack(), BLTrackNTuple(), and create().
Referenced by appendTrack(), BLTrackNTuple(), and create().