BLCMDprofile Class Reference

Inheritance diagram for BLCMDprofile:

BLCommand BLCallback

List of all members.


Detailed Description

class BLCMDprofile will print profile information at a list of Z positions.

Public Member Functions

 BLCMDprofile ()
 Constructor.
 BLCMDprofile (BLCMDprofile &r)
virtual G4String commandName ()
 commandName() returns "profile".
virtual int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the profile command.
virtual void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for this command.
virtual void callback (int type)
 callback from BLCallback.

Private Attributes

G4String z
G4String zloop
G4String require
G4String file
G4String particle
G4String coordinates
BLCoordinateType coordinateType
std::vector< Entry * > entries
unsigned place
FILE * fd
G4ParticleDefinition * pd

Classes

struct  Entry

Constructor & Destructor Documentation

BLCMDprofile::BLCMDprofile (  ) 

Constructor.

References BLCMDTYPE_DATA, BLCOORD_CENTERLINE, coordinates, coordinateType, fd, file, particle, pd, place, BLCommand::registerCommand(), require, BLCommand::setDescription(), BLCommand::setSynopsis(), z, and zloop.

Referenced by command().

00089                            : BLCommand(), BLCallback(), entries()
00090 {
00091         registerCommand(BLCMDTYPE_DATA);
00092         setSynopsis("write beam profile information to a file");
00093         setDescription("This command accumulates the moments of the track\n"
00094                         "distributions during the run, and at the end of\n"
00095                         "run prints the mean, sigma, emittance, alpha, and\n"
00096                         "beta (Twiss parameters) for the tracks. Each z\n"
00097                         "position generates a line in the output file.\n\n"
00098                         "Each value in z and zloop can be an expression using "
00099                         "double constants and the usual C operators and "
00100                         "functions.");
00101 
00102         z = "";
00103         zloop = "";
00104         require = "";
00105         file = "-";
00106         particle = "mu+";
00107         coordinates = "Centerline";
00108         coordinateType = BLCOORD_CENTERLINE;
00109         place = 0;
00110         fd = 0;
00111         pd = 0;
00112 }

BLCMDprofile::BLCMDprofile ( BLCMDprofile r  ) 

References coordinates, coordinateType, fd, file, particle, pd, place, require, z, and zloop.

00114                                           : BLCommand(r), 
00115                 BLCallback(), entries()
00116 {
00117         z = r.z;
00118         zloop = r.zloop;
00119         require = r.require;
00120         file = r.file;
00121         particle = r.particle;
00122         coordinates = r.coordinates;
00123         coordinateType = r.coordinateType;
00124         place = r.place;
00125         fd = 0;
00126         pd = 0;
00127 }


Member Function Documentation

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

commandName() returns "profile".

Implements BLCommand.

00075 { return "profile"; }

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

command() implements the profile command.

Implements BLCommand.

References BLCMDprofile(), coordinates, coordinateType, entries, fd, file, BLCoordinates::getCoordinateType(), BLCommand::getList(), BLManager::getObject(), BLCommand::handleNamedArgs(), particle, pd, BLCommand::print(), BLCommand::printError(), BLManager::registerCallback(), BLManager::registerZStep(), require, z, and zloop.

00130 {
00131         BLCMDprofile *p = new BLCMDprofile(defaultProfile);
00132 
00133         int retval = p->handleNamedArgs(namedArgs);
00134 
00135         p->coordinateType = BLCoordinates::getCoordinateType(p->coordinates);
00136 
00137         if(p->file == "-") {
00138                 p->fd = stdout;
00139         } else {
00140                 p->fd = fopen(p->file.c_str(),"w");
00141                 if(!p->fd) printError("profile: Cannot write file '%s'",
00142                                                         p->file.c_str());
00143         }
00144 
00145         p->pd =  G4ParticleTable::GetParticleTable()->FindParticle(p->particle);
00146         if(!p->pd) printError("profile: unknown particle '%s'\n",p->particle.c_str());
00147 
00148         BLEvaluator eval;
00149 
00150         // register the z position(s) in the string z
00151         std::vector<G4double> vect = getList(p->z,",");
00152         if(vect.size() > 0) {
00153                 for(unsigned i=0; i<vect.size(); ++i) {
00154                         Entry *e = new Entry(vect[i],p->require,p->pd,
00155                                                         p->coordinateType);
00156                         BLManager::getObject()->registerZStep(vect[i],e,4);
00157                         p->entries.push_back(e);
00158                 }
00159         } else if(p->z.size() > 0) {
00160                 printError("printf: Syntax error in z");
00161         }
00162 
00163         // register the z position(s) in the string zloop
00164         vect = getList(p->zloop,",:");
00165         if(vect.size() == 3) {
00166                 if(vect[2] < 1.0*mm || vect[0] > vect[1]) {
00167                         printError("printf: invalid zloop '%s'",
00168                                                         p->zloop.c_str());
00169                 } else {
00170                         while(vect[0] <= vect[1]) {
00171                             Entry *e = new Entry(vect[0],p->require,p->pd,
00172                                                         p->coordinateType);
00173                             BLManager::getObject()->registerZStep(vect[0],
00174                                                                 e,4);
00175                             p->entries.push_back(e);
00176                             vect[0] += vect[2];
00177                         }
00178                 }
00179         } else if(p->zloop.size() > 0) {
00180                 printError("printf: invalid zloop '%s'",p->zloop.c_str());
00181         }
00182 
00183         BLManager::getObject()->registerCallback(p,2);
00184 
00185         p->print("");
00186 
00187         return retval;
00188 }

void BLCMDprofile::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for this command.

Reimplemented from BLCommand.

References BLCommand::argString(), coordinates, file, particle, require, z, and zloop.

00191 {
00192         argString(z,"z","Comma-separated list of Z positions for profiling (mm)");
00193         argString(zloop,"zloop","Loop in z, first:last:incr (mm)");
00194         argString(require,"require","logical expression for cutting (default=true)");
00195         argString(particle,"particle","Name of particle to profile (default=mu+)");
00196         argString(file,"file","Output filename (default=stdout)");
00197         argString(file,"filename","Synonym for file");
00198         argString(coordinates,"coordinates","Coordinates: centerline or reference (default=c).");
00199 }

void BLCMDprofile::callback ( int  type  )  [virtual]

callback from BLCallback.

Reimplemented from BLCallback.

References determinant(), entries, fd, file, pd, and z.

00258 {
00259         // after beam tracking is complete, write the beam profile data
00260         if(type != 2 || !fd) return;
00261         fprintf(fd,"# g4beamline profile\n");
00262         fprintf(fd,"#Z N meanX sigmaX meanY sigmaY emitX emitY emitTrans betaX betaY betaTrans alphaX alphaY alphaTrans meanP\n");
00263         fprintf(fd,"#mm - mm mm mm mm mm-rad mm-rad mm-rad mm mm mm - - - MeV/c\n");
00264         for(unsigned i=0; i<entries.size(); ++i) {
00265                 int n = entries[i]->n;
00266                 G4double sumW = entries[i]->sumW;
00267                 if(n <= 0 || fabs(sumW) < 1.0e-12) continue;
00268                 G4double meanX = entries[i]->sumX/sumW;
00269                 G4double meanY = entries[i]->sumY/sumW;
00270                 G4double meanPx = entries[i]->sumPx/sumW;
00271                 G4double meanPy = entries[i]->sumPy/sumW;
00272                 G4double meanPz = entries[i]->sumPz/sumW;
00273                 G4double meanPtot = entries[i]->sumPtot/sumW;
00274                 G4double **M = entries[i]->M;
00275                 M[0][0] = M[0][0]/sumW - meanX*meanX;
00276                 M[0][1] = M[0][1]/sumW - meanX*meanPx;
00277                 M[0][2] = M[0][2]/sumW - meanX*meanY;
00278                 M[0][3] = M[0][3]/sumW - meanX*meanPy;
00279                 M[1][0] = M[1][0]/sumW - meanPx*meanX;
00280                 M[1][1] = M[1][1]/sumW - meanPx*meanPx;
00281                 M[1][2] = M[1][2]/sumW - meanPx*meanY;
00282                 M[1][3] = M[1][3]/sumW - meanPx*meanPy;
00283                 M[2][0] = M[2][0]/sumW - meanY*meanX;
00284                 M[2][1] = M[2][1]/sumW - meanY*meanPx;
00285                 M[2][2] = M[2][2]/sumW - meanY*meanY;
00286                 M[2][3] = M[2][3]/sumW - meanY*meanPy;
00287                 M[3][0] = M[3][0]/sumW - meanPy*meanX;
00288                 M[3][1] = M[3][1]/sumW - meanPy*meanPx;
00289                 M[3][2] = M[3][2]/sumW - meanPy*meanY;
00290                 M[3][3] = M[3][3]/sumW - meanPy*meanPy;
00291                 G4double sigmaX = sqrt(M[0][0]);
00292                 G4double sigmaY = sqrt(M[2][2]);
00293                 G4double mass = pd->GetPDGMass();
00294                 G4double emitX = sqrt(M[0][0]*M[1][1]-M[1][0]*M[0][1])/mass;
00295                 G4double emitY = sqrt(M[2][2]*M[3][3]-M[3][2]*M[2][3])/mass;
00296                 G4double emitTrans = sqrt(sqrt(determinant(M,4)))/mass;
00297                 G4double alphaX = -M[0][1]/mass/emitTrans;
00298                 G4double alphaY = -M[2][3]/mass/emitTrans;
00299                 G4double alphaTrans = (alphaX+alphaY)/2.0;
00300                 G4double betaX = M[0][0]*meanPz/mass/emitTrans;
00301                 G4double betaY= M[2][2]*meanPz/mass/emitTrans;
00302                 G4double betaTrans = (betaX+betaY)/2.0;
00303                 fprintf(fd,"%.1f %d %.3f %.3f %.3f %.3f %.4g %.4g %.4g %.4g %.4g %.4g %.4g %.4g %.4g %.4g\n",
00304                         entries[i]->z,n,meanX,sigmaX,meanY,sigmaY,emitX,emitY,emitTrans,
00305                         betaX,betaY,betaTrans,alphaX,alphaY,alphaTrans,meanPtot/MeV);
00306         }
00307         if(fd != stdout)
00308                 fclose(fd);
00309         printf("profile: wrote '%s'\n",file.c_str());
00310 }


Member Data Documentation

G4String BLCMDprofile::z [private]

G4String BLCMDprofile::zloop [private]

G4String BLCMDprofile::require [private]

G4String BLCMDprofile::file [private]

G4String BLCMDprofile::particle [private]

G4String BLCMDprofile::coordinates [private]

Referenced by BLCMDprofile(), and command().

std::vector<Entry*> BLCMDprofile::entries [private]

Referenced by callback(), and command().

unsigned BLCMDprofile::place [private]

Referenced by BLCMDprofile().

FILE* BLCMDprofile::fd [private]

Referenced by BLCMDprofile(), callback(), and command().

G4ParticleDefinition* BLCMDprofile::pd [private]

Referenced by BLCMDprofile(), callback(), and command().


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