This class simply computes the mean and sigma of the time stepping of BLRunManager, and enters them into an NTuple. It optinally generates an NTuple of field values at specified points in global coordinates.
Public Member Functions | |
BLCMDcollective () | |
G4String | commandName () |
int | command (BLArgumentVector &argv, BLArgumentMap &namedArgs) |
void | defineNamedArgs () |
void | setupFieldPoint (G4String v) |
virtual void | beginCollectiveTracking (std::vector< BLTrackData > &v) |
virtual void | collectiveStep (std::vector< BLTrackData > &v) |
virtual void | endCollectiveTracking (std::vector< BLTrackData > &v) |
Private Attributes | |
G4double | deltaT |
G4String | format |
G4String | filenamePrefix |
BLNTuple * | timeNtuple |
std::vector< G4ThreeVector > | point |
std::vector< BLNTuple * > | fieldNtuple |
BLRunManager * | runManager |
BLGlobalField * | globalField |
int | nstep |
long | prevTime |
long | startTime |
BLCMDcollective::BLCMDcollective | ( | ) |
References BLCMDTYPE_OTHER, deltaT, filenamePrefix, format, globalField, nstep, prevTime, BLCommand::registerCommand(), runManager, BLCommand::setDescription(), BLCommand::setSynopsis(), startTime, BLTime::time(), BLTime::timems(), and timeNtuple.
00069 : point(), fieldNtuple() 00070 { 00071 registerCommand(BLCMDTYPE_OTHER); 00072 setSynopsis("Monitor collective computation"); 00073 setDescription("This command computes the means and sigmas related " 00074 "to the time stepping in BLRunManager (global coordinates), " 00075 "generating a TimeStep NTuple. If the simulation has " 00076 "multiple bunches, this NTuple combines them all (and is thus " 00077 "almost useless).\n\n" 00078 "This command can also generate field NTuple-s at specified " 00079 "points in x,y,z -- unnamed parameters should be 'x,y,z' " 00080 "values for monitoring E and B fields (global coordinates).\n\n" 00081 "NOTE: This command must come AFTER other commands that " 00082 "compute collective fields; otherwise stale field values " 00083 "will be used from the previous time step. If deltaT is set " 00084 "> 0.0, this command will put the RunManager into collective " 00085 "mode and set its deltaT; otherwise the previous commands " 00086 "should do that, and this command won't modify deltaT."); 00087 00088 // initialize class variables here 00089 deltaT = -1.0*ns; 00090 format = ""; 00091 filenamePrefix = ""; 00092 timeNtuple = 0; 00093 runManager = 0; // not available, yet -- see command(...) 00094 globalField = 0; // not available, yet -- see command(...) 00095 nstep = 0; 00096 prevTime = BLTime::timems(); 00097 startTime = BLTime::time(); 00098 }
G4String BLCMDcollective::commandName | ( | ) | [inline, virtual] |
int BLCMDcollective::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
Implements BLCommand.
References BLNTuple::create(), deltaT, filenamePrefix, format, BLGlobalField::getObject(), BLRunManager::getObject(), globalField, BLCommand::handleNamedArgs(), BLCommand::print(), BLRunManager::registerCollectiveComputation(), runManager, BLRunManager::setCollectiveMode(), BLRunManager::setDeltaT(), setupFieldPoint(), and timeNtuple.
00101 { 00102 runManager = BLRunManager::getObject(); 00103 globalField = BLGlobalField::getObject(); 00104 00105 handleNamedArgs(namedArgs); 00106 00107 runManager->registerCollectiveComputation(this); 00108 if(deltaT > 0.0) { 00109 runManager->setCollectiveMode(true); 00110 runManager->setDeltaT(deltaT); 00111 } 00112 00113 // setup the NTuple-s 00114 timeNtuple = BLNTuple::create(format, "NTuples", "TimeStep", 00115 "t:Ntracks:meanDT:sigmaDT:meanX:sigmaX:meanY:sigmaY:meanZ:sigmaZ:cpuTime", 00116 filenamePrefix+"TimeStep"); 00117 assert(timeNtuple != 0); 00118 00119 print(""); 00120 00121 for(unsigned i=0; i<argv.size(); ++i) 00122 setupFieldPoint(argv[i]); 00123 00124 return 0; 00125 }
void BLCMDcollective::defineNamedArgs | ( | ) | [virtual] |
Reimplemented from BLCommand.
References BLCommand::argDouble(), BLCommand::argString(), deltaT, filenamePrefix, and format.
00128 { 00129 argDouble(deltaT,"deltaT","Time step (-1 ns).",ns); 00130 argString(format,"format","Format of NTuples."); 00131 argString(filenamePrefix,"filenamePrefix","Prefix of NTuple filenames."); 00132 }
void BLCMDcollective::setupFieldPoint | ( | G4String | v | ) |
References BLNTuple::create(), fieldNtuple, filenamePrefix, format, BLCommand::getList(), point, and BLCommand::printError().
Referenced by command().
00135 { 00136 std::vector<double> vv = getList(v,","); 00137 if(vv.size() != 3) { 00138 printError("collective: invalid field point '%s'", 00139 v.c_str()); 00140 return; 00141 } 00142 point.push_back(G4ThreeVector(vv[0],vv[1],vv[2])); 00143 fieldNtuple.push_back(BLNTuple::create(format, "Field", v, 00144 "x:y:z:t:Bx:By:Bz:Ex:Ey:Ez",filenamePrefix+v)); 00145 printf(" Sample Fields: %s\n",v.c_str()); 00146 }
void BLCMDcollective::beginCollectiveTracking | ( | std::vector< BLTrackData > & | v | ) | [virtual] |
Reimplemented from BLCollectiveComputation.
References nstep, prevTime, startTime, BLTime::time(), and BLTime::timems().
00149 { 00150 printf("beginCollectiveTracking %d tracks\n",(int)v.size()); 00151 fflush(stdout); 00152 00153 nstep = 0; 00154 prevTime = BLTime::timems(); 00155 startTime = BLTime::time(); 00156 }
void BLCMDcollective::collectiveStep | ( | std::vector< BLTrackData > & | v | ) | [virtual] |
Implements BLCollectiveComputation.
References BLNTuple::appendRow(), fieldNtuple, fmax, BLGlobalField::GetFieldValue(), BLRunManager::getStepTime(), globalField, nstep, point, prevTime, runManager, BLTime::timems(), and timeNtuple.
00159 { 00160 #define fmax(A,B) ((A)>(B) ? (A) : (B)) 00161 ++nstep; 00162 long time = BLTime::timems(); 00163 float cpuTime = (float)(time-prevTime)/1000.0f; 00164 prevTime = time; 00165 00166 // compute means and sigmas of DT, X, Y, and Z. 00167 G4double stepTime = runManager->getStepTime(); 00168 G4double sumDT=0.0, sumDT2=0.0, sumX=0.0, sumX2=0.0, 00169 sumY=0.0, sumY2=0.0, sumZ=0.0, sumZ2=0.0; 00170 int active=0; 00171 G4double meanZ=gsl_nan(); 00172 for(unsigned i=0; i<v.size(); ++i) { 00173 // get the track pointer, and verify track is alive 00174 G4Track *track = v[i].track; 00175 G4TrackStatus trackStatus = track->GetTrackStatus(); 00176 if(trackStatus != fAlive && trackStatus != fStopButAlive) 00177 continue; 00178 ++active; 00179 G4ThreeVector position = track->GetPosition(); 00180 G4double time = track->GetGlobalTime(); 00181 G4double dt = time - stepTime; 00182 sumDT += dt; 00183 sumDT2 += dt*dt; 00184 sumX += position[0]; 00185 sumX2 += position[0]*position[0]; 00186 sumY += position[1]; 00187 sumY2 += position[1]*position[1]; 00188 sumZ += position[2]; 00189 sumZ2 += position[2]*position[2]; 00190 } 00191 if(active >= 1) { 00192 G4double meanDT = sumDT/active; 00193 G4double sigmaDT = sqrt(fmax(sumDT2/active - meanDT*meanDT,0.0)); 00194 G4double meanX = sumX/active; 00195 G4double sigmaX = sqrt(fmax(sumX2/active - meanX*meanX,0.0)); 00196 G4double meanY = sumY/active; 00197 G4double sigmaY = sqrt(fmax(sumY2/active - meanY*meanY,0.0)); 00198 meanZ = sumZ/active; 00199 G4double sigmaZ = sqrt(fmax(sumZ2/active - meanZ*meanZ,0.0)); 00200 double data[11]; 00201 data[0] = stepTime; 00202 data[1] = active; 00203 data[2] = meanDT; 00204 data[3] = sigmaDT; 00205 data[4] = meanX; 00206 data[5] = sigmaX; 00207 data[6] = meanY; 00208 data[7] = sigmaY; 00209 data[8] = meanZ; 00210 data[9] = sigmaZ; 00211 data[10] = cpuTime; 00212 assert(timeNtuple != 0); 00213 timeNtuple->appendRow(data,sizeof(data)/sizeof(data[0])); 00214 00215 for(unsigned i=0; i<point.size(); ++i) { 00216 G4ThreeVector p=point[i]; 00217 double pp[4],ff[6]; 00218 pp[0] = p[0]; 00219 pp[1] = p[1]; 00220 pp[2] = p[2]; 00221 pp[3] = stepTime; 00222 globalField->GetFieldValue(pp,ff); 00223 double data[10]; 00224 data[0] = p[0]/mm; 00225 data[1] = p[1]/mm; 00226 data[2] = p[2]/mm; 00227 data[3] = stepTime/ns; 00228 data[4] = ff[0]/tesla; 00229 data[5] = ff[1]/tesla; 00230 data[6] = ff[2]/tesla; 00231 data[7] = ff[3]/(megavolt/meter); 00232 data[8] = ff[4]/(megavolt/meter); 00233 data[9] = ff[5]/(megavolt/meter); 00234 assert(i < fieldNtuple.size()); 00235 fieldNtuple[i]->appendRow(data,sizeof(data)/sizeof(data[0])); 00236 } 00237 } 00238 printf("CollectiveStep %d t=%.3f %d tracks (%d active) meanZ=%.3f\n", 00239 nstep,runManager->getStepTime(),(int)v.size(),active,meanZ); 00240 fflush(stdout); 00241 }
void BLCMDcollective::endCollectiveTracking | ( | std::vector< BLTrackData > & | v | ) | [virtual] |
Reimplemented from BLCollectiveComputation.
References startTime, and BLTime::time().
00244 { 00245 long time = BLTime::time() - startTime; 00246 printf("endCollectiveTracking %d tracks %ld seconds\n",(int)v.size(), 00247 time); 00248 fflush(stdout); 00249 }
G4double BLCMDcollective::deltaT [private] |
Referenced by BLCMDcollective(), command(), and defineNamedArgs().
G4String BLCMDcollective::format [private] |
Referenced by BLCMDcollective(), command(), defineNamedArgs(), and setupFieldPoint().
G4String BLCMDcollective::filenamePrefix [private] |
Referenced by BLCMDcollective(), command(), defineNamedArgs(), and setupFieldPoint().
BLNTuple* BLCMDcollective::timeNtuple [private] |
Referenced by BLCMDcollective(), collectiveStep(), and command().
std::vector<G4ThreeVector> BLCMDcollective::point [private] |
Referenced by collectiveStep(), and setupFieldPoint().
std::vector<BLNTuple*> BLCMDcollective::fieldNtuple [private] |
Referenced by collectiveStep(), and setupFieldPoint().
BLRunManager* BLCMDcollective::runManager [private] |
Referenced by BLCMDcollective(), collectiveStep(), and command().
BLGlobalField* BLCMDcollective::globalField [private] |
Referenced by BLCMDcollective(), collectiveStep(), and command().
int BLCMDcollective::nstep [private] |
Referenced by beginCollectiveTracking(), BLCMDcollective(), and collectiveStep().
long BLCMDcollective::prevTime [private] |
Referenced by beginCollectiveTracking(), BLCMDcollective(), and collectiveStep().
long BLCMDcollective::startTime [private] |
Referenced by beginCollectiveTracking(), BLCMDcollective(), and endCollectiveTracking().