Chapter 5 Advanced usage of WHIZARD
In the preceding chapters we have described the use of WHIZARD as a stand-alone program. As such, it is able to calculate total cross sections and to generate events on the partonic level, or even on the hadronic level if fragmentation is enabled. The events can be analyzed online (on the partonic level) or written to file (on the partonic or on the hadronic level). This already covers many real-life applications of a Monte-Carlo integration and event-generation package. For the theorist, it may be sufficient to calculate a total cross section with a given set of parameters and to plot differential distributions. For an experimental simulation, the generated event files can be used for further processing. However, one encounters situations where a more elaborate framework is desired. For instance, one would like to consider multiple sets of cuts, energies and parameter sets. For each set, the input file has to be modified, the program has to be run, and the results have to be stored somewhere in order to be compared later. This can easily become cumbersome, and it is desirable to have a generic approach. Another common problem is the selection of a certain subclass of Feynman diagrams contributing to a given process, either for speeding up the calculation by dropping irrelevant terms, or for getting a better understanding of the relative weight of interfering subprocesses. Some possibilities are described in the following sections. 5.1 Feynman diagram selectionsWhile the matrix element generators called by WHIZARD, by default, generate an amplitude which corresponds to the complete set of Feynman diagrams which connect a given initial and final state, there are problems where only a subset is needed. Therefore, WHIZARD has support for diagram selections. Since O’Mega does not use Feynman diagrams, this option is available only when using the CompHEP and MadGraph matrix element generators. (O’Mega, however, supports restrictions on the internal lines of an amplitude. This is explained below in Sec. 5.2.) Since the CompHEP and MadGraph matrix element generators are considered to be deprecated features we describe Feynman diagram selection here only briefly. The selection must be made before the final executable is generated. In the configuration file, the process must be marked accordingly by the letter “s” in the last column, for instance: # Processes # Tag In Out Method Option #===================================================== cc3 e1,E1 e2,N2,u,D chep s
Note that this makes sense only for the methods Since the user usually does not know diagram numbers in advance, it is possible to do an empty run of the matrix element generators first. If the command make diagrams
is issued, matrix element generation is started as usual, but the
Fortran95 source code is not actually generated (at least, with
CompHEP: for the other generators it makes little difference).
Instead, after this command is completed, you will find PostScript
files with Feynman diagrams in graphical representation in the
subdirectory make proc or even make prg install WHIZARD should read the selection files and take into account only the specified subsets of diagrams. You may control this by looking at the PostScript output this second pass will produce: it should contain only the Feynman diagrams you have selected. Needless to say, this feature should be used with great care. By violating electroweak or even electromagnetic gauge invariance, the results may be off by far, since delicate cancellations may have been spoiled. As a rule, never delete diagrams in any gauge other than unitarity gauge (in the CompHEP) case, and remember which diagrams have been selected (i.e., save the PostScript file somewhere) when storing results, since the output of the WHIZARD executable itself does not contain any hint that only a subset of Feynman diagrams have been taken into account. In many cases the same effect can also be achieved in a simpler way by putting some parameter to extreme values. For instance, instead of removing Higgs diagrams by hand, one may set the Higgs mass to a very large value — the results will then be valid in any gauge. 5.2 Restrictions on intermediate statesAs an alternative (and often more convenient) method for selecting Feynman diagrams, the O’Mega interface supports restrictions on internal lines.1 As an example, the following specification selects the resonant WW diagrams, analogous to the previous example: # Processes # Tag In Out Method Option #===================================================== cc3 e1,E1 e1,N1,u,D omega r: 3+4~W-&&5+6~W+
Simultaneous requirements for a process are concatenated by The following examples select only diagrams with an s-channel and t-channel γ*, respectively: cc_gamma_s e1,E1 e1,N1,u,D omega r: 3+4+5+6~A cc_gamma_t e1,E1 e1,N1,u,D omega r: 1+3~A The in- and out-particles are numbered consecutively. The tilde selects only diagrams where the specified combination of momenta corresponds to the propagator for the given particle. A question mark instead of a particle name stands for all possible propagators with the specified momentum combination. These particle names have to follow the O’Mega notation; they are not translated by WHIZARD as in the process specification. For colored intermediate states, WHIZARD takes care automatically that the intermediate particle can appear in different color flow combinations (in WHIZARD 2 this is handled directly by O’Mega itself in the matrix element generation). It is important to keep in mind that such a selection typically violates gauge invariance, since the intermediate particle is not forced on shell. (An on-shell option is also present in O’Mega, but not yet supported by WHIZARD.) The ww_or_zz e1,E1 e1,N1,E1,n1 omega r: 3+4~W- && 5+6~W+ || 3+5~Z && 4+6~Z
AND and OR relations can be grouped by parantheses Currently, WHIZARD does not interpret or use such restrictions for its phase space setup, so the possible speedup is constrained to the matrix element evaluation. Nevertheless, this feature can be very useful. Such an option is foreseen for a future release of WHIZARD 2, however. 5.3 User-defined spectra and structure functions
It is possible to insert arbitrary beam spectra into the WHIZARD
code. If the corresponding code is included in the The comments in the In the input file, for each beam there is a master switch
Apart from user-defined spectra, user-defined structure functions can
be inserted. They are handled in an exactly analogous way (with
The efficiency of the program in the presence of user-defined spectra or structure functions depends on the way they are implemented by the user. It is straightforward to insert the corresponding functions in a literal way as functions f(x) where x is the beam energy fraction. However, if f is strongly peaked this might lead to poor performance. In many cases one rather should apply a variable transformation
where x=g(y). The user interface allows for this, where the input parameters are identified with y and the output parameters x=g(y) can be different. In that case, the spectral function f(x)=f(g(y)) has to be multiplied by the Jacobian dg/dy within the structure function code. The implementation can be checked by making use of the “test” matrix elements (Sec. 4.1.2). You may set up a placeholder process like sftest e1,E1 A,A test where the final state is massless and remove all cuts (in the example,
set
which is usually known. Furthermore, the energy distribution of the final state should reproduce the structure function shape. In the current implementation, beam polarization (if any) cannot be accessed or modified by the user spectra or structure functions. Beam polarization will be kept unchanged if the in- and out-particle of the corresponding splitting coincide (as for ISR), and it will be ignored in the opposite case (as for PDFs). 5.4 User-defined cutsIn many applications the built-in capabilities for cuts are not sufficient. If cuts are defined using the standard interface, all cuts are composed such that an event is only retained if it passes all cuts (logical and). There can be several windows in one cut variable, but beyond that it is not possible to compose cuts by a logical or. Furthermore, you may be missing your favorite cut model in the list of predefined variables. Note that WHIZARD 2 revised this model and makes the definition of almost arbitrary functions for cuts on (combinations of) particles possible. User-defined cut algorithms can easily be placed in the The As an example, let us implement a cut such that an event is accepted if there is a photon with energy larger than 50 GeV. (This is not possible by the built-in cut capabilities, since for a generic process we do not know which photon to check.) To this end, we first make a copy of the standard (no-op) user file, which then can be changed: cd whizard-src
The file ! This minimal cut function accepts everything function cut (p, code, mode) result (accept) type(four_momentum), dimension(:), intent(in) :: p integer, dimension(:), intent(in) :: code integer, intent(in) :: mode logical :: accept select case (mode) case default accept = .true. end select end function cut and change it as follows: ! This cut function accepts an event only if there is a photon with ! energy larger than 50 GeV function cut (p, code, mode) result (accept) type(four_momentum), dimension(:), intent(in) :: p integer, dimension(:), intent(in) :: code integer, intent(in) :: mode logical :: accept integer :: i select case (mode) case (1) accept = .false. do i = 1, size (code) if (code(i) == PHOTON .and. energy (p(i)) > 50) then accept = .true. end if end do case default accept = .true. end select end function cut
We have inserted a loop over all outgoing particles, such that the
code can be applied to an arbitrary process. For each particle
When WHIZARD is now (re-)compiled and installed, make whizard install
the user code becomes part of the program. To activate it, the
&integration_input ... user_cut_mode = 1 /
since in the function defined above, the ! Activating additional preselection cuts in user.f90: Mode # 1 in the screen output, and the cross section and event distribution should reflect the new cut condition. 5.5 Reweighting matrix elementsBeyond the possibility to apply arbitrary cuts, the user might be interested in reweighting events. One should distinguish two different situations:
It is perfectly possible to combine the two approaches: One may define
one or more reweighting functions in the 5.6 Command-line options
WHIZARD allows to specify options on the command line. Options are
available both in long form (double dashes) and in short form (a
single dash). For instance, the following command executes WHIZARD
in subdirectory ./whizard -nd tmp --process_input ’process_id = "ee_nnh"’ 5.6.1 General optionsThese options are executed by WHIZARD before any files are read or written
If a working directory different from the default one is chosen by the
./whizard --directory tmp --integration_input ’read_model_file="./whizard"’
When a 5.6.2 Options for setting parameters
Parameters can be set not just in the input file, but also on the
command line. The command-line parameters are read after all
input files have been read; they override settings in the
input file(s). Thus, one can set up a generic input file
./whizard -p ’process_id="ee_nnh" sqrts=800’ -P ’mH = 130’ Note that the option arguments are interpreted verbatim as if they were contained in the input file, so string values have to be enclosed by extra quotes.
5.7 Tables and file managementThe WHIZARD program, after it has been compiled with a specific list of processes, may be viewed as a kind of filter: It takes as input
and transforms the information contained within into output files, namely
For a second WHIZARD run, the input files have to be edited, and the output files will be overwritten if they have not been moved to a different location. Instead of doing this by hand, one could write a script that executes a loop where in each iteration the relevant line in the input file is modified, the program is run, and the output files are renamed or moved such that they do not get overwritten. Here is such a script: #!/usr/bin/perl # Loop over the total energy, write a table and store the results # in subdirectories $sqrts_min = 350; $sqrts_max = 800; $sqrts_step = 50; # These files will be preserved @outfiles = ("whizard.out", "whizard.grb", "whizard.evt"); # This will become the table of results $resultfile = "whizard.out"; $table = sprintf(" %-10s %-20s %-20s\n", "sqrts [GeV]", "Total cross section [fb]", "Integration error [fb]"); # Main loop for ($sqrts=$sqrts_min; $sqrts<=$sqrts_max; $sqrts=$sqrts+$sqrts_step) { # Read the input file template, modify the sqrts entry, and write the # new input file $infile = "whizard.in.0"; $outfile = "whizard.in"; open(INFILE, $infile) or die "Can't open $infile for reading"; open(OUTFILE, ">$outfile") or die "Can't open $outfile for writing"; while (<INFILE>) { s/sqrts = \d+/sqrts = $sqrts/; print OUTFILE; } close(OUTFILE); close(INFILE); # Run WHIZARD print "\n**** sqrts = $sqrts ****\n"; $stat = system("./whizard"); $stat==0 or die "WHIZARD run exited abnormally"; # Extract the integration results and add them to the table open(RESULTS, "grep 'integral =' $resultfile|") or die "Grep failed on $resultfile"; while(<RESULTS>) { ($dummy, $equals, $integral) = split; } close(RESULTS); open(RESULTS, "grep 'error =' $resultfile|") or die "Grep failed on $resultfile"; while(<RESULTS>) { ($dummy, $equals, $error) = split; } close(RESULTS); $table .= sprintf(" %10g %20g %20g\n", $sqrts, $integral, $error); # Create a subdirectory and move the results there $dirname = "sqrts=$sqrts"; mkdir($dirname, oct("0755")) or die "Can't mkdir $dirname"; foreach $file(@outfiles) { system("mv", $file, $dirname); } } print "\n*** Results:\n"; print $table; print "*** End of WHIZARD runs\n"; exit 0;
The script assumes that the subdirectories do not yet exist, and that
you have a template This kind of task can be formalized further. The program whizwrap takes care of loops over parameters and provides a convenient management of output files. It is called from the command line; the kind of task to be performed by WHIZARD is specified in terms of command-line options. Note that within WHIZARD 2 these tasks can be easily steered from the input file by means of its powerful interpreter language SINDARIN. Cf. the manual of WHIZARD 2 for the details. 5.8 WHIZARD as a subroutine libraryA more ambitious enterprise is the integration of WHIZARD into a larger framework which may also account for the subsequent steps of experimental simulation and analysis. Even if this is not desired, it may be useful to access WHIZARD by subroutine calls in wrapper programs written in Fortran, C, or other program languages. To make this possible, WHIZARD is organized as a set of libraries (in the UNIX sense). When the configuration file (the process list) has been specified, instead of making a stand-alone executable by make prg one may generate the libraries only make libs which then can be linked with a user-supplied main program. To facilitate this procedure, after executing make libs, the
user will find the generated libraries in the subdirectory bin/whizard.ld -o my_whizard my_main.o to generate his own version of WHIZARD.6 Here is a main program that performs the same task as the script shown in the preceding section: ! Loop over the total energy, write a table and store the results in ! separate output files. program my_main use kinds ! Defines the default real kind use whizard ! Defines the WHIZARD subroutines implicit none ! No implicit typing ! Parameters integer, parameter :: n_values = 10 real(kind=default), parameter :: sqrts_min = 350, sqrts_max = 800 ! Variables integer :: i character(len=14+3) :: filename ! Tables real(kind=default), dimension(n_values) :: & sqrts, integral, error, chi2, efficiency ! Main loop do i = 1, n_values ! Calculate energy, set filename accordingly sqrts(i) = ((i-1) * sqrts_max + (n_values-i) * sqrts_min) / (n_values-1) write(filename, "(A14,I3)") "whizard_sqrts=", nint(sqrts(i)) call whizard_set_filename (filename) ! Read input and override energy setting write (*,*) write (*, "(A,1x,I3,1x,A)") "*** sqrts =", nint(sqrts(i)), "***" call whizard_read_input whizard_input%sqrts = sqrts(i) ! Integrate, record result, generate events call whizard_integrate call whizard_get_results (i, integral(i), error(i), chi2(i), efficiency(i)) call whizard_generate call whizard_end end do ! Write table write (*,*) write (*, "(A)") "*** Results:" write (*, "(1x,A15,2x,A25,2x,A25)") "sqrts [GeV]", & "Total cross section [fb]", "Integration error [fb]" do i = 1, n_values write (*, "(1x,G15.5,2x,G25.5,2x,G25.5)") & sqrts(i), integral(i), error(i) end do write (*, "(A)") "*** End of WHIZARD runs" end program my_main
The meaning of the individual subroutine calls is described in detail
in the following section. Note that parameters in the input block can
be accessed via the object whizard_input%sqrts = sqrts
while variables in the whizard_input%par%mh = 115are and beam parameters are accessed like whizard_input%beam(1)%PDF_nset = 43 5.9 Interface of the WHIZARD module
All subroutines described in this section are accessed via the
module use whizard in the preamble.7 For other programming languages, the subroutines are accessed by a platform-dependent prefix. For instance, the NAG compiler preprends the string whizard_MP_ to all names in the module whizard, so the subroutine whizard_integrate is accessed by the name whizard_MP_whizard_integrate. The access to arguments in subroutine calls may also be platform-dependent. 5.9.1 Auxiliary routinesThe following routines are needed only if some non-standard behavior of WHIZARD is intended. They closely match the command-line arguments described in Sec. 5.6.
5.9.2 Standard routinesThe following routines are called, directly or indirectly, in standard WHIZARD runs. The explicit interface allows for calling them directly without reference to the main program.
|