
///\file "B5/.README.txt"
///\brief Example B5 README page

/*! \page ExampleB5 Example B5

  Example B5 implements a double-arm spectrometer with wire chambers, 
  hodoscopes and calorimeters.  Event simulation and collection are 
  enabled, as well as event display and analysis.


\section B5_s1 GEOMETRY

   The spectrometer consists of two detector arms
   (see B5DetectorConstruction).  One arm provides 
   position and timing information of the incident particle while the 
   other collects position, timing and energy information of the particle
   after it has been deflected by a magnetic field centered at the 
   spectrometer pivot point.
 
     - First arm:  box filled with air, also containing:
         - 1 hodoscope (15 vertical strips of plastic scintillator)
         - 1 drift chamber (5 horizontal argon gas layers with a 
                          "virtual wire" at the center of each layer)

     - Second arm:  box filled with air, also containing:
         - 1 hodoscope (25 vertical strips of plastic scintillator)
         - 1 drift chamber (5 horizontal argon gas layers with a 
                          "virtual wire" at the center of each layer)
         - 1 electromagnetic calorimeter: 
               a box sub-divided along x,y and z
               axes into cells of CsI 
         - 1 hadronic calorimeter: 
               a box sub-divided along x,y, and z axes
               into cells of lead, with a layer of 
               plastic scintillator placed at the center 
               of each cell
     
     - Magnetic field region: air-filled cylinder which contains
                              the field (see B5MagneticField)

   The maximum step limit in the magnetic field region is also set 
   via the G4UserLimits class in a similar way as in Example B2
   (see \ref B2_s6 in B2 example documentation).

   The rotation angle of the second arm and the magnetic field value
   can be set via the interactive commands defined using the G4GenericMessenger 
   class.                      

\section B5_s2 PHYSICS

   This example uses the reference hadronic physics list, FTFP_BERT,
   and also adds the G4StepLimiter process.

\section B5_s3 ACTION INITALIZATION

   B5ActionInitialization class
   instantiates and registers to Geant4 kernel all user action classes.
   
   While in sequential mode the action classes are instatiated just once,
   via invoking the method:
      B5ActionInitialization::Build() 
   in multi-threading mode the same method is invoked for each thread worker
   and so all user action classes are defined thread-local.

   A run action class is instantiated both thread-local 
   and global that's why its instance is created also in the method
      B5ActionInitialization::BuildForMaster() 
   which is invoked only in multi-threading mode.

\section B5_s4 PRIMARY GENERATOR

   The primary generator action class employs the G4ParticleGun. 
   The primary kinematics consists of a single particle which is 
   is sent in the direction of the first spectrometer arm. 

   The type of the particle and its several properties can be changed 
   via the  G4 built-in commands of  the G4ParticleGun class or
   this example command defined using the G4GenericMessenger class.
       
  
\section B5_s5 EVENT

   An event consists of the generation of a single particle which is 
   transported through the first spectrometer arm.  Here, a scintillator 
   hodoscope records the reference time of the particle before it passes
   through a drift chamber where the particle position is measured. 
   Momentum analysis is performed as the particle passes through a magnetic
   field at the spectrometer pivot and then into the second spectrometer 
   arm.  In the second arm, the particle passes through another hodoscope
   and drift chamber before interacting in the electromagnetic calorimeter.
   Here it is likely that particles will induce electromagnetic showers.  
   The shower energy is recorded in a three-dimensional array of CsI 
   crystals.  Secondary particles from the shower, as well as primary 
   particles which do not interact in the CsI crystals, pass into the 
   hadronic calorimeter.  Here, the remaining energy is collected in a 
   three-dimensional array of scintillator-lead sandwiches.

   Several aspects of the event may be changed interactively by the user:
     - angle of the second spectrometer arm
     - strength of magnetic field
     - initial particle type
     - initial momentum and angle
     - momentum and angle spreads
     - type of initial particle may be randomized
     
   The initial particle type can be changed using the G4ParticleGun command:
\verbatim
/gun/particle particleName
\endverbatim
       
   The UI commands specific to this example are available in /B5 command 
   directory:
\verbatim
/B5/detector/armAngle angle unit
/B5/field/value field unit
/B5/generator/momentum  value unit
/B5/generator/sigmaMomentum value unit
/B5/generator/sigmaAngle value unit
/B5/generator/randomizePrimary [true|false]
\endverbatim
     
   They are implemented in 
    - B5DetectorConstruction::DefineCommands(), 
    - B5MagneticField::DefineCommands() and 
    - B5PrimaryGeneratorAction::DefineCommands() methods 
   using G4GenericMessenger class.

   In first execution of B5EventAction::BeginOfEventAction()
   the hits collections identifiers are saved in data members of the class
   and used in B5EventAction::EndOfEventAction() for accessing
   the hists collections and filling the accounted information in defined
   histograms and ntuples and printing its summary in a log file.
   The frequency of printing can be tuned with the built-in command
\verbatim
/run/printProgress  frequency
\endverbatim

\section B5_s6 DETECTOR RESPONSE

  All the information required to simulate and analyze an event is 
  recorded in hits.  This information is recorded in the following 
  sensitive detectors:

    - hodoscope: 
        - particle time
        - strip ID, position and rotation
          - see B5HodoscopeSD, B5HodoscopeHit

    - drift chamber: 
        - particle time
        - particle position
        - layer ID
          - see B5DriftChamberSD, B5DriftChamberHit classes 
 
    - electromagnetic calorimeter: 
        - energy deposited in cell
        - cell ID, position and rotation
          - see B5EmCalorimeterSD, B5EmCalorimeterHit classes 
  
    - hadronic calorimeter:   
        - energy deposited in cell
        - cell column ID and row ID, position and rotation
          - see B5HadCalorimeterSD, B5HadCalorimeterHit classes 

     The hit classes include methods GetAttDefs and CreateAttValues to define
     and then fill extra "HepRep-style" Attributes that the visualization system
     can use to present extra information about the hits.
     For example, if you pick a B5HadCalorimeterHit in OpenGL or a HepRep viewer,
     you will be shown the hit's "Hit Type", "Column ID", "Row ID",
     "Energy Deposited" and "Position".
     These attributes are essentially arbitrary extra pieces of information
     (integers, doubles or strings) that are carried through the visualization.      
     Each attribute is defined once in G4AttDef object and then is filled for
     each hit in a G4AttValue object.
     These attributes can also be used by commands to filter which hits are drawn:
     /vis/filtering/hits/drawByAttribute
     Detector Geometry and trajectories also carry HepRep-style attributes,
     but these are filled automatically in the base classes.
     HepRep is further described at the 
     <a href="http://www.slac.stanford.edu/~perl/heprep/"> HepRep Home Page </a>

\section B5_s7 ANALYSIS

   The analysis tools are used to accumulate statistics.
   Histograms and an ntuple are created in B5RunAction::B5RunAction() 
   constructor for the following quantities:

   - 1D histograms:
     - Number of hits in Chamber 1
     - Number of hits in Chamber 2

   - 2D histograms:
     - Drift Chamber 1 X vs Y positions
     - Drift Chamber 2 X vs Y positions
   
   - Ntuple:
     - Number of hits in Chamber 1
     - Number of hits in Chamber 2
     - Total energy deposit in EM calorimeter
     - Total energy deposit in Hadronic calorimeter
     - Time of flight in Hodoscope 1
     - Time of flight in Hodoscope 2
     - Vector of energy deposits in EM calorimeter cells
     - Vector of energy deposits in Hadronic calorimeter cells

   The histograms and ntuple are saved in the output file in a format
   according to a technology selected in B5Analysis.hh.

   When running in multi-threading mode, the histograms and ntuple accumulated 
   on threads are automatically merged in a single output file.

\section B5_s8 BUILD OPTIONS
  
  This example can be built with excluding use of visualization and/or
  Geant4 user interface using G4VIS_USE and G4UI_USE compiler options
  (see exampleB5.cc).
  These options are defined by default with Geant4 configuration;
  they can be switched off at compilation time via the CMake options 
  G4VIS_NONE or G4UI_NONE or via the environment variables of the 
  same name if using GNUmake build.

<hr>

The following paragraphs are common to all basic examples

\section B5_A VISUALISATION

   The visualization manager is set via the G4VisExecutive class
   in the main () function in exampleB5.cc.    
   The initialisation of the drawing is done via a set of /vis/ commands
   in the macro vis.mac. This macro is automatically read from
   the main function when the example is used in interactive running mode.

   By default, vis.mac opens an OpenGL viewer (/vis/open OGL).
   The user can change the initial viewer by commenting out this line
   and instead uncommenting one of the other /vis/open statements, such as
   HepRepFile or DAWNFILE (which produce files that can be viewed with the
   HepRApp and DAWN viewers, respectively).  Note that one can always
   open new viewers at any time from the command line.  For example, if
   you already have a view in, say, an OpenGL window with a name
   "viewer-0", then
\verbatim
/vis/open DAWNFILE
\endverbatim
   then to get the same view
\verbatim
/vis/viewer/copyView viewer-0
\endverbatim
   or to get the same view *plus* scene-modifications
\verbatim
/vis/viewer/set/all viewer-0
\endverbatim
   then to see the result
\verbatim
/vis/viewer/flush
\endverbatim

   The DAWNFILE, HepRepFile drivers are always available
   (since they require no external libraries), but the OGL driver requires
   that the Geant4 libraries have been built with the OpenGL option.

   vis.mac has additional commands that demonstrate additional functionality
   of the vis system, such as displaying text, axes, scales, date, logo and
   shows how to change viewpoint and style.
   To see even more commands use help or ls or browse the available UI commands
   in the Application Developers Guide.

   For more information on visualization, including information on how to
   install and run DAWN, OpenGL and HepRApp, see the visualization tutorials,
   for example,\n
   - <a href="http://geant4.slac.stanford.edu/Presentations/vis/G4OpenGLTutorial/G4OpenGLTutorial.html">
     OpenGL Tutorial </a>
   - <a href="http://geant4.slac.stanford.edu/Presentations/vis/G4DAWNTutorial/G4DAWNTutorial.html">
     DAWN Tutorial </a>
   - <a href="http://geant4.slac.stanford.edu/Presentations/vis/G4HepRAppTutorial/G4HepRAppTutorial.html">
     HepRApp Tutorial </a>

   The tracks are automatically drawn at the end of each event, accumulated
   for all events and erased at the beginning of the next run.


\section B5_B USER INTERFACES
 
  This example can be built with excluding visualization and/or
  Geant4 user interface via G4VIS_USE and G4UI_USE compiler options 
  (see exampleB5.cc).
  These options are defined by default with Geant4 configuration;
  they can switched off at compilation time via the CMake options 
  G4VIS_NONE or G4UI_NONE or via the environment variables of the 
  same name if using GNUmake build.

   
\section B5_C HOW TO RUN

   - Execute exampleB5 in the 'interactive mode' with visualization
\verbatim
% exampleB5
and type in the commands from run1.mac line by line:
Idle> /control/verbose 2
Idle> /tracking/verbose 1
Idle> /run/beamOn 10 
Idle> ...
Idle> exit
\endverbatim                
      or
\verbatim
Idle> /control/execute run1.mac
....
Idle> exit
\endverbatim                

   - Execute exampleB5 in the 'batch' mode from macro files 
   (without visualization)
\verbatim
% exampleB5 run2.mac
% exampleB5 exampleB5.in > exampleB5.out
\endverbatim                
*/

