BLCMDmovie Class Reference

Inheritance diagram for BLCMDmovie:

BLCommand BLCallback BLManager::SteppingAction BLManager::TrackingAction

List of all members.


Detailed Description

class BLCMDmovie - output NTuple-s suitable for a movie


Public Member Functions

 BLCMDmovie ()
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
void interpolate (double t, double &Zref, double &Ptot)
void dumpGeometry (G4VPhysicalVolume *phys, G4ThreeVector &parent_offset, G4RotationMatrix &parent_rot)
void dumpGeometry (G4VPhysicalVolume *phys)
void callback (int type)
 callback() from BLCallback.
void UserSteppingAction (const G4Step *step)
 UserSteppingAction() from BLManager::SteppingAction.
virtual void PreUserTrackingAction (const G4Track *track)
 from BLManager::TrackingAction
virtual void PostUserTrackingAction (const G4Track *track)
void referenceStep (const G4Track *track)
void beamStep (const G4Track *track)
void generateFakeReference ()

Private Attributes

G4String coordinates
BLCoordinateType coordinateType
BLNTupleoutline
BLNTuplereference
BLNTupletrace
BLNTupleelements
BLManagermanager
std::vector< double > timeV
std::vector< double > ZrefV
std::vector< double > PtotV


Constructor & Destructor Documentation

BLCMDmovie::BLCMDmovie (  ) 

References BLCMDTYPE_OTHER, coordinates, elements, manager, outline, reference, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), and trace.

00102                        : BLCallback(), BLManager::SteppingAction(),
00103                                                 timeV(), ZrefV(), PtotV()
00104 {
00105         registerCommand(BLCMDTYPE_OTHER);
00106         setSynopsis("Generate movie NTuple.");
00107         setDescription("This command outputs a set of NTuples suitable for "
00108                 "generating a movie.");
00109 
00110         // initialize class variables here
00111         coordinates = "Reference";
00112         outline = 0;
00113         reference = 0;
00114         trace = 0;
00115         elements = 0;
00116         manager = 0;
00117 }


Member Function Documentation

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

Implements BLCommand.

00071 { return "movie"; }

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

Implements BLCommand.

References BLCOORD_REFERENCE, coordinates, coordinateType, BLNTuple::create(), ElementFields, elements, generateFakeReference(), BLCoordinates::getCoordinateType(), BLManager::getObject(), BLCommand::handleNamedArgs(), manager, BLCommand::print(), reference, ReferenceFields, BLManager::registerBeamStep(), BLManager::registerCallback(), BLManager::registerReferenceParticleStep(), BLManager::registerTrackingAction(), trace, TrackFields, and BLCoordinates::useReferenceCoordinates().

00120 {
00121         manager = BLManager::getObject();
00122 
00123         handleNamedArgs(namedArgs);
00124 
00125         print("");
00126 
00127         coordinateType = BLCoordinates::getCoordinateType(coordinates);
00128 
00129         // register reference coords before registering ourselves
00130         if(coordinateType == BLCOORD_REFERENCE)
00131                 BLCoordinates::useReferenceCoordinates();
00132 
00133         manager->registerTrackingAction(this);
00134         manager->registerReferenceParticleStep(0,this);
00135         manager->registerBeamStep(0,this);
00136         manager->registerCallback(this,0);
00137         manager->registerCallback(this,1);
00138         manager->registerCallback(this,4);
00139 
00140         //outline = BLNTuple::create("root", "Movie", "Outline",
00141         //                                              OutlineFields, "");
00142         reference = BLNTuple::create("root", "Movie", "Reference", 
00143                                                         ReferenceFields, "");
00144         trace = BLNTuple::create("root", "Movie", "Tracks", 
00145                                                         TrackFields, "");
00146         elements = BLNTuple::create("root","Movie","Elements",ElementFields,"");
00147 
00148         if(coordinateType != BLCOORD_REFERENCE)
00149                 generateFakeReference();
00150 
00151         print("");
00152 
00153         return 0;
00154 }

void BLCMDmovie::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argString(), and coordinates.

00157 {
00158         argString(coordinates,"coordinates","Coordinates: global, centerline, or reference (default=r).");
00159 }       

void BLCMDmovie::interpolate ( double  t,
double &  Zref,
double &  Ptot 
)

References BLAssert, PtotV, timeV, and ZrefV.

Referenced by beamStep().

00162 {
00163         if(timeV.size() < 2) {
00164                 Zref = 0.0;
00165                 Ptot = 0.0;
00166                 return;
00167         }
00168 
00169         // simple linear search
00170         unsigned i;
00171         for(i=1; i<timeV.size(); ++i) {
00172                 if(t < timeV[i]) break;
00173         }
00174         if(i >= timeV.size()) i = timeV.size() - 1;
00175         // now i points to the second entry to use for linear interpolation
00176         // (extrapolates the first or last pair if t is too small or too big).
00177         BLAssert(i > 0 && i < timeV.size());
00178         double f = (t - timeV[i-1])/(timeV[i] - timeV[i-1]);
00179         Zref = (1.0-f)*ZrefV[i-1] + f*ZrefV[i];
00180         Ptot = (1.0-f)*PtotV[i-1] + f*PtotV[i];
00181 }

void BLCMDmovie::dumpGeometry ( G4VPhysicalVolume *  phys,
G4ThreeVector &  parent_offset,
G4RotationMatrix &  parent_rot 
)

References BLNTuple::appendRow(), BLAssert, coordinateType, elements, BLCoordinates::getCoords(), N_POINTS_ON_SURFACE, NElementFields, and BLCoordinates::setGlobal().

Referenced by callback().

00209 {
00210         static BLCoordinates coord;
00211         static int number=0;
00212 
00213         G4ThreeVector my_offset = parent_offset + 
00214                                 parent_rot * phys->GetObjectTranslation();
00215         G4RotationMatrix my_rot = 
00216                         parent_rot * phys->GetObjectRotationValue();
00217         G4LogicalVolume *log = phys->GetLogicalVolume();
00218         const G4VisAttributes *va = log->GetVisAttributes();
00219         if(va->IsVisible()) {
00220                 G4VSolid *solid = log->GetSolid();
00221                 double Xmin=DBL_MAX, Xmax=-DBL_MAX, Ymin=DBL_MAX, Ymax=-DBL_MAX;
00222                 double Zmin=DBL_MAX, Zmax=-DBL_MAX;
00223                 // find the element's extent in the desired coordinates by
00224                 // generating points on its surface -- simple but slow.
00225                 for(int i=0; i<N_POINTS_ON_SURFACE; ++i) {
00226                         G4ThreeVector p = solid->GetPointOnSurface();
00227                         p = my_rot * p + my_offset;
00228 #ifdef DISPLAY_VISIBLE_MARKERS
00229 display_dot(&p);
00230 #endif
00231                         coord.setGlobal(p,0.0);
00232                         coord.getCoords(coordinateType,p);
00233                         if(Xmin > p[0]) Xmin = p[0];
00234                         if(Xmax < p[0]) Xmax = p[0];
00235                         if(Ymin > p[1]) Ymin = p[1];
00236                         if(Ymax < p[1]) Ymax = p[1];
00237                         if(Zmin > p[2]) Zmin = p[2];
00238                         if(Zmax < p[2]) Zmax = p[2];
00239                 }
00240                 BLAssert(NElementFields == 10);
00241                 double data[NElementFields];
00242                 data[0] = ++number;
00243                 data[1] = Xmin;
00244                 data[2] = Xmax;
00245                 data[3] = Ymin;
00246                 data[4] = Ymax;
00247                 data[5] = Zmin;
00248                 data[6] = Zmax;
00249                 data[7] = va->GetColor().GetRed();
00250                 data[8] = va->GetColor().GetGreen();
00251                 data[9] = va->GetColor().GetBlue();
00252                 elements->appendRow(data,NElementFields);
00253         }
00254         int n = log->GetNoDaughters();
00255         for(int i=0; i<n; ++i) {
00256                 G4VPhysicalVolume *p = log->GetDaughter(i);
00257                 if(!p) continue;
00258                 dumpGeometry(p,my_offset,my_rot);
00259         }
00260 }

void BLCMDmovie::dumpGeometry ( G4VPhysicalVolume *  phys  ) 

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

callback() from BLCallback.

Reimplemented from BLCallback.

References dumpGeometry(), BLManager::getWorldPhysicalVolume(), and manager.

00263 {
00264         if(type == 0)  {        // pre-tune callback
00265         } else if(type == 1) {  // post-reference callback
00266                 G4ThreeVector offset;
00267                 G4RotationMatrix rot;
00268                 printf("Generating Movie/Elements NTuple... "); fflush(stdout);
00269                 dumpGeometry(manager->getWorldPhysicalVolume(),offset,rot);
00270                 printf("Done.\n"); fflush(stdout);
00271         } else if(type == 4) {  // visualization
00272 #ifdef DISPLAY_VISIBLE_MARKERS
00273                 G4ThreeVector offset;
00274                 G4RotationMatrix rot;
00275                 printf("Generating Movie/Elements NTuple... "); fflush(stdout);
00276                 dumpGeometry(manager->getWorldPhysicalVolume(),offset,rot);
00277                 printf("Done.\n"); fflush(stdout);
00278                 display_dot(0);
00279 #endif
00280         }
00281 }

void BLCMDmovie::UserSteppingAction ( const G4Step *  step  )  [virtual]

UserSteppingAction() from BLManager::SteppingAction.

Implements BLManager::SteppingAction.

References BEAM, beamStep(), BLCOORD_REFERENCE, coordinateType, BLManager::getState(), IDLE, manager, REFERENCE, referenceStep(), SPECIAL, TUNE, and VISUAL.

00284 {
00285         switch(manager->getState()) {
00286         case IDLE:
00287                 break;
00288         case VISUAL:
00289                 break;
00290         case TUNE:
00291                 break;
00292         case REFERENCE:
00293                 if(coordinateType == BLCOORD_REFERENCE)
00294                         referenceStep(step->GetTrack());
00295                 break;
00296         case BEAM:
00297                 beamStep(step->GetTrack());
00298                 break;
00299         case SPECIAL:
00300                 break;
00301         }
00302 }

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

from BLManager::TrackingAction

Implements BLManager::TrackingAction.

References BLCOORD_REFERENCE, coordinateType, BLManager::getState(), manager, REFERENCE, and referenceStep().

00305 {
00306         if(manager->getState() == REFERENCE && 
00307            coordinateType == BLCOORD_REFERENCE)
00308                 referenceStep(track);
00309         //@ if(manager->getState() == BEAM) beamStep(track);
00310 }

void BLCMDmovie::PostUserTrackingAction ( const G4Track *  track  )  [virtual]

void BLCMDmovie::referenceStep ( const G4Track *  track  ) 

References BLNTuple::appendRow(), BLAssert, BLCOORD_CENTERLINE, BLCoordinates::getCoords(), BLCoordinates::getMostRecentReferenceZ(), BLCoordinates::isValid(), NReferenceFields, PtotV, reference, timeV, and ZrefV.

Referenced by PostUserTrackingAction(), PreUserTrackingAction(), and UserSteppingAction().

00321 {
00322         G4ThreeVector posGlobal = track->GetPosition();
00323         G4ThreeVector posCL = posGlobal;
00324         G4double Zref = BLCoordinates::getMostRecentReferenceZ();
00325         G4double time = track->GetGlobalTime();
00326         G4ThreeVector momentum = track->GetMomentum();
00327 
00328         // transform to centerline coordinates
00329         BLCoordinates *c = (BLCoordinates *)track->GetUserInformation();
00330         if(c && c->isValid()) {
00331                 c->getCoords(BLCOORD_CENTERLINE,posCL);
00332         }
00333 
00334         // enter this step into interpolation vectors.
00335         if(timeV.size() == 0 || time-timeV.back() > 1.0*picosecond) {
00336                 timeV.push_back(time);
00337                 ZrefV.push_back(Zref);
00338                 PtotV.push_back(momentum.mag());
00339         }
00340 
00341         BLAssert(NReferenceFields == 9);
00342         double data[NReferenceFields];
00343         data[0] = time/ns;
00344         data[1] = Zref/mm;
00345         data[2] = posCL[0]/mm;
00346         data[3] = posCL[1]/mm;
00347         data[4] = posCL[2]/mm;
00348         data[5] = posGlobal[0]/mm;
00349         data[6] = posGlobal[1]/mm;
00350         data[7] = posGlobal[2]/mm;
00351         data[8] = momentum.mag()/MeV;
00352 
00353         reference->appendRow(data,NReferenceFields);
00354 }

void BLCMDmovie::beamStep ( const G4Track *  track  ) 

References BLNTuple::appendRow(), BLAssert, BLCOORD_REFERENCE, coordinateType, BLCoordinates::getCoords(), BLManager::getExternalParentID(), BLManager::getExternalTrackID(), BLManager::getObject(), BLCoordinates::getRotation(), interpolate(), BLCoordinates::isValid(), NTrackFields, and trace.

Referenced by PostUserTrackingAction(), and UserSteppingAction().

00357 {
00358         G4RunManager* runmgr = G4RunManager::GetRunManager();
00359         const G4Event* event = runmgr->GetCurrentEvent();
00360         int evNum = event->GetEventID();
00361         G4ThreeVector position = track->GetPosition();
00362         G4double time = track->GetGlobalTime();
00363         G4ThreeVector momentum = track->GetMomentum();
00364 
00365         // transform to desired coordinates
00366         BLCoordinates *c = (BLCoordinates *)track->GetUserInformation();
00367         if(c && c->isValid()) {
00368                 c->getCoords(coordinateType,position);
00369                 momentum = c->getRotation() * momentum;
00370         }
00371 
00372         // subtract interpolated Zref and Pref for reference coords
00373         if(coordinateType == BLCOORD_REFERENCE) {
00374                 double Zref, Pref;
00375                 interpolate(time,Zref,Pref);
00376                 position[2] -= Zref;
00377                 momentum[2] -= Pref;
00378         }
00379 
00380         BLAssert(NTrackFields == 12);
00381         double data[NTrackFields];
00382         data[0] = position[0]/mm;               // x (mm)
00383         data[1] = position[1]/mm;               // y (mm)
00384         data[2] = position[2]/mm;               // z (mm)
00385         data[3] = momentum[0]/MeV;              // Px (MeV/c)
00386         data[4] = momentum[1]/MeV;              // Py (MeV/c)
00387         data[5] = momentum[2]/MeV;              // Pz (MeV/c)
00388         data[6] = time/ns;                      // t (ns)
00389         data[7] = track->GetDefinition()->GetPDGEncoding();
00390         data[8] = evNum;                                // Event ID
00391         data[9] = 
00392             BLManager::getObject()->getExternalTrackID(track);
00393         data[10] = 
00394             BLManager::getObject()->getExternalParentID(track);
00395         data[11] = track->GetWeight();          // Weight
00396 
00397         trace->appendRow(data,NTrackFields);
00398 }

void BLCMDmovie::generateFakeReference (  ) 

References BLNTuple::appendRow(), BLAssert, NReferenceFields, and reference.

Referenced by command().

00401 {
00402         BLAssert(NReferenceFields == 9);
00403         double data[NReferenceFields];
00404         data[0] = -(DBL_MAX/4.0);
00405         data[1] = -(DBL_MAX/4.0);
00406         data[2] = 0.0;
00407         data[3] = 0.0;
00408         data[4] = 0.0;
00409         data[5] = 0.0;
00410         data[6] = 0.0;
00411         data[7] = 0.0;
00412         data[8] = 0.0;
00413         reference->appendRow(data,NReferenceFields);
00414 
00415         data[0] = (DBL_MAX/4.0);
00416         data[1] = (DBL_MAX/4.0);
00417         reference->appendRow(data,NReferenceFields);
00418 }


Member Data Documentation

G4String BLCMDmovie::coordinates [private]

Referenced by BLCMDmovie().

Referenced by beamStep(), BLCMDmovie(), and command().

Referenced by BLCMDmovie(), command(), and dumpGeometry().

std::vector<double> BLCMDmovie::timeV [private]

Referenced by interpolate(), and referenceStep().

std::vector<double> BLCMDmovie::ZrefV [private]

Referenced by interpolate(), and referenceStep().

std::vector<double> BLCMDmovie::PtotV [private]

Referenced by interpolate(), and referenceStep().


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