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().

01630                                    : BLCommand(), BLCallback()
01631 {
01632         registerCommand(BLCMDTYPE_CONTROL);
01633         setSynopsis("Sets mode for all trackers, manages track fitting.");
01634         setDescription("USAGE: trackermode mode [file=...]\n"
01635                 " mode can be any of:\n"
01636                 "    true     tracks true tracks (normal operation)\n"
01637                 "    fit      fits tracks to previous 'true' output\n"
01638                 "    both     does both true and fit at once\n"
01639                 "'fit' requires the filename argument to be the output of "
01640                 "a previous 'true' run (filename is ignored in other modes); "
01641                 "each tracker processes all of its tracks in the file. "
01642                 "'true' mode simply denotes the standard G4beamline "
01643                 "operation, and the simulated tracks are taken to be the "
01644                 "'true' tracks of the system; the response of the tracker(s) "
01645                 "to these tracks is then simulated in 'fit' mode. 'both' "
01646                 "tracks a 'true' event, and then a fit is peerformed in each "
01647                 "tracker for which its first track hit all trackerplane-s.\n\n"
01648                 "Note that in 'true' "
01649                 "mode every track that hits all trackerplane-s is considered, "
01650                 "but in 'both' mode only the first track of the event can be "
01651                 "considered.\n\n"
01652                 "In fit mode, the filename argument MUST be different from "
01653                 "the parameter 'histoFile', because this run must not "
01654                 "overwrite the Root file from the previous (true) run.\n\n"
01655                 "One trackermode command controls the mode of all trackers. "
01656                 "'true' mode is normal G4beamline operation, and is the same "
01657                 "as if no trackermode command was present.\n\n"
01658                 "Note that the geometry of the system must not change "
01659                 "between a 'true' run and a 'fit' run. You can, however, "
01660                 "make small variations in fields to explore how errors in "
01661                 "setting them will affect the fitted tracks. The trackerplane "
01662                 "command can simulate survey errors.\n\n"
01663                 "NOTE: the trackermode command must preceed all tracker "
01664                 "commands in the input file."
01665         );
01666 
01667         filename = "";
01668         mode = "true";
01669         registered = false;
01670 }


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(), BLParam::getString(), BLCommand::handleNamedArgs(), BLCMDtracker::list, mode, Param, BLCommand::print(), BLCommand::printError(), BLManager::registerCallback(), and registered.

01673 {
01674         if(registered) {
01675                 printError("trackermode: Multiple commands not allowed");
01676                 return -1;
01677         }
01678 
01679         if(BLCMDtracker::list.size() > 0) {
01680                 // Ordering is required for the callbacks to work properly.
01681                 printError("trackermode: must preceed all tracker commands.");
01682                 return -1;
01683         }
01684 
01685         handleNamedArgs(namedArgs);
01686 
01687         if(argv.size() >= 1) mode = argv[0];
01688 
01689         if(mode == "true") {
01690                 ;
01691         } else if(mode == "fit") {
01692                 if(filename == "") 
01693                         printError("trackermode: mode 'fit' requires a file\n");
01694                 if(filename == Param.getString("histoFile") ||
01695                    filename == (G4String)(Param.getString("histoFile")+".root"))
01696                         // Immediate fatal exception, trying not to clobber
01697                         // the Root file from the previous (true) run
01698                         G4Exception("trackermode","Overwriting input file",
01699                                 FatalException, 
01700                                 "filename must be different from histoFile");
01701         } else if(mode == "both") {
01702                 ;
01703         } else {
01704                 printError("trackermode: invalid mode '%s'\n",mode.c_str());
01705                 mode = "true";
01706         }
01707 
01708         if(!registered) {
01709                 if(mode == "true")
01710                         BLManager::getObject()->registerCallback(this,0);
01711                 else
01712                         BLManager::getObject()->registerCallback(this,3);
01713                 registered = true;
01714         }
01715 
01716         print(mode);
01717 
01718         return 0;
01719 }

void BLCMDtrackermode::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argString(), and filename.

01722 {
01723         argString(filename,"filename","Filename to read for fitting tracks.");
01724         argString(filename,"file","Synonym for filename.");
01725 }

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(), BLAssert, BLTRACKER_FIT, BLTRACKER_TRUE, BLRunManager::endEvent(), BLRunManager::endRun(), filename, BLManager::GeneratePrimaries(), BLRunManager::getEventManager(), BLManager::getObject(), BLRunManager::getObject(), BLManager::getPhysics(), BLRunManager::getRunAborted(), BLParam::getString(), BLCMDtracker::list, mode, NORMAL, Param, BLCommand::printError(), BLPhysics::setDoStochastics(), and BLManager::setState().

01728 {
01729         if(BLCMDtracker::list.size() == 0) {
01730                 G4Exception("trackermode","No trackers",FatalException, "");
01731         }
01732 
01733         if(mode == "true") {
01734                 BLAssert(type == 0);
01735                 for(unsigned i=0; i<BLCMDtracker::list.size(); ++i) {
01736                         BLCMDtracker::list[i]->setMode(BLTRACKER_TRUE);
01737                 }
01738                 return;
01739         } else if(mode == "fit") {
01740                 BLAssert(type==3);
01741                 if(filename == Param.getString("histoFile") ||
01742                    filename == (G4String)(Param.getString("histoFile")+".root"))
01743                         // probably already clobbered the Root file (user
01744                         // could change histoFile between command() and here)
01745                         G4Exception("trackermode","Overwriting input file",
01746                                 FatalException, 
01747                                 "filename must be different from histoFile");
01748                 for(unsigned i=0; i<BLCMDtracker::list.size(); ++i) {
01749                         BLCMDtracker::list[i]->handlePreviousTracks(filename);
01750                 }
01751                 return;
01752         } else if(mode != "both") {
01753                 printError("trackermode::callback: invalid mode '%s'",
01754                         mode.c_str());
01755                 return;
01756         }
01757         
01758         BLAssert(type==3);
01759 
01760         BLRunManager *runmgr = BLRunManager::getObject();
01761         G4EventManager *evmgr = runmgr->getEventManager();
01762         BLManager *mgr = BLManager::getObject();
01763 
01764         printf("================== Prepare Tracking Beam for Tracker Fit ==================\n");
01765         mgr->getPhysics()->setDoStochastics(NORMAL);
01766         runmgr->beginRun();
01767 
01768         printf("================== Begin Tracking Beam for Tracker Fit ===============\n");
01769         mgr->setState(BEAM);
01770 
01771         for(;;) {
01772                 runmgr->beginEvent(0);
01773                 G4Event *currentEvent = (G4Event *)runmgr->GetCurrentEvent();
01774                 mgr->GeneratePrimaries(currentEvent);
01775                 if(runmgr->getRunAborted()) break;
01776                 for(unsigned i=0; i<BLCMDtracker::list.size(); ++i)
01777                         BLCMDtracker::list[i]->setMode(BLTRACKER_TRUE);
01778                 evmgr->ProcessOneEvent(currentEvent);
01779                 if(runmgr->getRunAborted()) break;
01780                 for(unsigned i=0; i<BLCMDtracker::list.size(); ++i) {
01781                         BLCMDtracker::list[i]->setMode(BLTRACKER_FIT);
01782                         BLCMDtracker::list[i]->fitTrack();
01783                 }
01784                 runmgr->endEvent();
01785                 delete currentEvent;
01786                 currentEvent = 0;
01787         } 
01788 
01789         runmgr->endRun();
01790 }

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