BLCMDtrackermode Class Reference

Inheritance diagram for BLCMDtrackermode:

BLCommand BLCallback

List of all members.


Detailed Description

class BLCMDtrackermode sets the mode for all trackers, and manages track fitting.

modes: true normal g4beamline operation; the "true" track is tracked. Same as if no trackermode command was given. fit special BLRunManager mode in which the Root file from an earlier run is read for the TrackerHits NTuple, and a track is fit to each such track. both special BLRunManager mode in which a single event is simulated, and then a track is fitted to the first track in each tracker. Primarily for testing.

Public Member Functions

 BLCMDtrackermode ()
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
void callback (int type)
 callback() from BLCallback. Implements the event loop for mode=fit and mode=both.
const G4String & getMode () const

Private Attributes

G4String filename
G4String mode
G4bool registered


Constructor & Destructor Documentation

BLCMDtrackermode::BLCMDtrackermode (  ) 

References BLCMDTYPE_CONTROL, filename, mode, BLCommand::registerCommand(), registered, BLCommand::setDescription(), and BLCommand::setSynopsis().

01608                                    : BLCommand(), BLCallback()
01609 {
01610         registerCommand(BLCMDTYPE_CONTROL);
01611         setSynopsis("Sets mode for all trackers, manages track fitting.");
01612         setDescription("USAGE: trackermode mode [file=...]\n"
01613                 " mode can be any of:\n"
01614                 "    true     tracks true tracks (normal operation)\n"
01615                 "    fit      fits tracks to previous 'true' output\n"
01616                 "    both     does both true and fit at once\n"
01617                 "'fit' requires the filename argument to be the output of "
01618                 "a previous 'true' run (filename is ignored in other modes); "
01619                 "each tracker processes all of its tracks in the file. "
01620                 "'true' mode simply denotes the standard G4beamline "
01621                 "operation, and the simulated tracks are taken to be the "
01622                 "'true' tracks of the system; the response of the tracker(s) "
01623                 "to these tracks is then simulated in 'fit' mode. 'both' "
01624                 "tracks a 'true' event, and then a fit is peerformed in each "
01625                 "tracker for which its first track hit all trackerplane-s.\n\n"
01626                 "Note that in 'true' "
01627                 "mode every track that hits all trackerplane-s is considered, "
01628                 "but in 'both' mode only the first track of the event can be "
01629                 "considered.\n\n"
01630                 "One trackermode command controls the mode of all trackers. "
01631                 "'true' mode is normal G4beamline operation, and is the same "
01632                 "as if no trackermode command was present.\n\n"
01633                 "Note that the geometry of the system must not change "
01634                 "between a 'true' run and a 'fit' run. You can, however, "
01635                 "make small variations in fields to explore how errors in "
01636                 "setting them will affect the fitted tracks. The trackerplane "
01637                 "command can simulate survey errors.\n\n"
01638                 "NOTE: the trackermode command must preceed all tracker "
01639                 "commands in the input file."
01640         );
01641 
01642         filename = "";
01643         mode = "true";
01644         registered = false;
01645 }


Member Function Documentation

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

Implements BLCommand.

00413 { return "trackermode"; }

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

Implements BLCommand.

References filename, BLManager::getObject(), BLCommand::handleNamedArgs(), BLCMDtracker::list, mode, BLCommand::print(), BLCommand::printError(), BLManager::registerCallback(), and registered.

01648 {
01649         if(registered) {
01650                 printError("trackermode: Multiple commands not allowed");
01651                 return -1;
01652         }
01653 
01654         if(BLCMDtracker::list.size() > 0) {
01655                 // Ordering is required for the callbacks to work properly.
01656                 printError("trackermode: must preceed all tracker commands.");
01657                 return -1;
01658         }
01659 
01660         handleNamedArgs(namedArgs);
01661 
01662         if(argv.size() >= 1) mode = argv[0];
01663 
01664         if(mode == "true") {
01665                 ;
01666         } else if(mode == "fit") {
01667                 if(filename == "") 
01668                         printError("trackermode: mode 'fit' requires a file\n");
01669         } else if(mode == "both") {
01670                 ;
01671         } else {
01672                 printError("trackermode: invalid mode '%s'\n",mode.c_str());
01673                 mode = "true";
01674         }
01675 
01676         if(!registered) {
01677                 if(mode == "true")
01678                         BLManager::getObject()->registerCallback(this,0);
01679                 else
01680                         BLManager::getObject()->registerCallback(this,3);
01681                 registered = true;
01682         }
01683 
01684         print(mode);
01685 
01686         return 0;
01687 }

void BLCMDtrackermode::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argString(), and filename.

01690 {
01691         argString(filename,"filename","Filename to read for fitting tracks.");
01692         argString(filename,"file","Synonym for filename.");
01693 }

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

callback() from BLCallback. Implements the event loop for mode=fit and mode=both.

Reimplemented from BLCallback.

References BEAM, BLRunManager::beginEvent(), BLRunManager::beginRun(), BLTRACKER_FIT, BLTRACKER_TRUE, BLRunManager::endEvent(), BLRunManager::endRun(), filename, BLManager::GeneratePrimaries(), BLRunManager::getEventManager(), BLManager::getObject(), BLRunManager::getObject(), BLManager::getPhysics(), BLRunManager::getRunAborted(), BLCMDtracker::list, mode, NORMAL, BLCommand::printError(), BLPhysics::setDoStochastics(), and BLManager::setState().

01696 {
01697         if(BLCMDtracker::list.size() == 0) {
01698                 G4Exception("trackermode","No trackers",FatalException, "");
01699         }
01700 
01701         if(mode == "true") {
01702                 assert(type == 0);
01703                 for(unsigned i=0; i<BLCMDtracker::list.size(); ++i) {
01704                         BLCMDtracker::list[i]->setMode(BLTRACKER_TRUE);
01705                 }
01706                 return;
01707         } else if(mode == "fit") {
01708                 assert(type==3);
01709                 for(unsigned i=0; i<BLCMDtracker::list.size(); ++i) {
01710                         BLCMDtracker::list[i]->handlePreviousTracks(filename);
01711                 }
01712                 return;
01713         } else if(mode != "both") {
01714                 printError("trackermode::callback: invalid mode '%s'",
01715                         mode.c_str());
01716                 return;
01717         }
01718         
01719         assert(mode == "both");
01720         assert(type==3);
01721 
01722         BLRunManager *runmgr = BLRunManager::getObject();
01723         G4EventManager *evmgr = runmgr->getEventManager();
01724         BLManager *mgr = BLManager::getObject();
01725 
01726         printf("================== Prepare Tracking Beam for Tracker Fit ==================\n");
01727         mgr->getPhysics()->setDoStochastics(NORMAL);
01728         runmgr->beginRun();
01729 
01730         printf("================== Begin Tracking Beam for Tracker Fit ===============\n");
01731         mgr->setState(BEAM);
01732 
01733         for(;;) {
01734                 runmgr->beginEvent(0);
01735                 G4Event *currentEvent = (G4Event *)runmgr->GetCurrentEvent();
01736                 mgr->GeneratePrimaries(currentEvent);
01737                 if(runmgr->getRunAborted()) break;
01738                 for(unsigned i=0; i<BLCMDtracker::list.size(); ++i)
01739                         BLCMDtracker::list[i]->setMode(BLTRACKER_TRUE);
01740                 evmgr->ProcessOneEvent(currentEvent);
01741                 if(runmgr->getRunAborted()) break;
01742                 for(unsigned i=0; i<BLCMDtracker::list.size(); ++i) {
01743                         BLCMDtracker::list[i]->setMode(BLTRACKER_FIT);
01744                         BLCMDtracker::list[i]->fitTrack();
01745                 }
01746                 runmgr->endEvent();
01747                 delete currentEvent;
01748                 currentEvent = 0;
01749         } 
01750 
01751         runmgr->endRun();
01752 }

const G4String& BLCMDtrackermode::getMode (  )  const [inline]

References mode.

Referenced by BLCMDtracker::callback().

00423 { return mode; }


Member Data Documentation

G4String BLCMDtrackermode::filename [private]

G4String BLCMDtrackermode::mode [private]

G4bool BLCMDtrackermode::registered [private]

Referenced by BLCMDtrackermode(), and command().


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