Computing Methods in High Energy Physics

Computing Methods in High Energy Physics

COMPUTING METHODS IN HIGH ENERGY PHYSICS S. Lehti and V.Karim¨aki Helsinki Institute of Physics Spring 2010 Lecture 1 Spring 2010 COMPUTING METHODS IN HIGH ENERGY PHYSICS (page 1) S. Lehti and V.Karim¨aki Lecture 1 Outline: Practical 'hands-on' course for comput- • Short review to Unix basics,latex,makefile,cvs ing in high energy physics. • FORTRAN Credits: 5op (3ov), 13 lectures + 6 ex- • C++ ercises + home exam. Exercises split in two to have 12 x 1h exercises. • ROOT Recommended prerequisites: Introduc- • Combining programming languages tion to particle physics and programming • Cross section and branching ratio calculations skills. • Event generators Literature: Recommending an advanced • Detector simulation and reconstruction C++ book for reference. • Fast simulations • Grid computing Spring 2010 COMPUTING METHODS IN HIGH ENERGY PHYSICS (page 2) S. Lehti and V.Karim¨aki Lecture 1 Short review to Unix basics Unix Shells completion of each stage. The Shell is a program that runs automatically when you log in to a Unix/linux system. The Shell Name History Shell forms the interface between users and the sh (Bourne) The original shell rest of the system. It reads each command you csh,tcsh,zsh The C shell. Bourne Again Shell, from the type at your terminal and interprets what you bash have asked for. The Shell is very much like a GNU project rc More C than csh, also from GNU programming language with features like • variables • control structures (if,while,..) • subroutines File Handling • parameter passing Most Unix commands take input from the terminal • interrupt handling keyboard and send output to the terminal monitor. These features provide you with the capability to To redirect the output use > symbol: design your own tools. Shell scripting is ideal for $ ls > myfiles any small utilities that perform relatively simple Likewise you can redirect the input with the < sym- task, where efficiency is less important than easy bol: configuration, maintenance and portability. You $ wc -l < myfiles can use the shell to organize process control, so The need for redirection becomes more apparent in commands run in predetermined sequence, de- shell programming. pendent on the successful Spring 2010 COMPUTING METHODS IN HIGH ENERGY PHYSICS (page 3) S. Lehti and V.Karim¨aki Lecture 1 Short review to Unix basics Shell Programming Pipes Suppose you have a file called 'test' which contains The standard output of one process (or program) unix commands. There are different ways to get can be the standard input of another process. the system to execute those commands. One is When this is done a "pipeline" is formed. The giving the filename as an argument to the shell pipe operator is the j symbol. Examples: command, or one can use the command source in $ ls | sort which case the current shell is used $ ls | sort | more $ csh test (or sh test) $ ls | sort | grep btag | more $ source test Here the standard output from left becomes the One can also give the executing rights to the file standard input to the right of j. and then run it Pipelines provide a flexible and powerful mech- $ chmod 755 test anism for doing jobs easily and quickly, without $ test the need to construct special purpose tools. Ex- Here the number coding in the chmod command isting tools can be combined. Another useful comes from rwxrwxrwx with rwx being binary num- command: ber: rwx=111=7 and r-x=101=5. You can check $ find . -name "*.cpp" | xargs the rights of your files with the -l option of the ls grep btag command. This is searching every file in this directory and A shell script starts usually with a line which tells any subdirectory with ending cpp and containing which program is used to execute the file. The line the string btag. looks like this (for bourne shell) #!/bin/sh Spring 2010 COMPUTING METHODS IN HIGH ENERGY PHYSICS (page 4) S. Lehti and V.Karim¨aki Lecture 1 Short review to Unix basics Comments start with a # and continue to the • set end of a line. The shell syntax depends on which • set name shell is in use. At CERN people have been us- • set name = word ing widely csh (tcsh), but also bash as the linux • set name = (wordlist) default has gained ground. It's up to you which • set name[index] = word shell you prefer. The first three forms are used with scalar variables, whereas the last two are used with array variables. csh The setenv command is used to create new environ- Variables are used to hold temporary values and ment variables. Environment variables are passed manage changeable information. There are two to shell scripts and invoked commands, which can types of variables: reference the variables without first defining them. • Shell variables • setenv • Environment variables • setenv name value Shell variables are defined locally in the shell, To obtain the value of a variable a reference whereas environment variables are defined for $fnameg is used. Example the shell and all the child processes that are mv a.out analysis $fCHANNELg $RUN.out started from it. Here the variables CHANNEL and RUN contains The set command is used to create new local some values. A reference $f#nameg returns the variables and assign a value to them. Some dif- number of elements in array, and $f?nameg returns ferent methods of invoking the set command are 1 if the variable is set, 0 otherwise. as follows: Spring 2010 COMPUTING METHODS IN HIGH ENERGY PHYSICS (page 5) S. Lehti and V.Karim¨aki Lecture 1 Short review to Unix basics In addition to ordinary variables, a set of special An example csh script variables is available. #!/bin/csh if( ! $f?ENVIRONMENTg ) setenv ENVIRONMENT INTERACTIVE if( $ENVIRONMENT != "BATCH" ) then Variable Description if( ! $f?SCRATCHg ) then echo Setting workdir to HOME $0 Shorthand for $argv[0] setenv WORKDIR $HOME else $1,$2,...,$9 Shorthand for $argv[n] echo Setting workdir to SCRATCH setenv WORKDIR $SCRATCH $* Equivalent to $argv[*] endif setenv LS SUBCWD $PWD $$ Process number of the shell endif $< input from file #################################### setenv INPUTFILE analysis.in #setenv DATAPATH $LS SUBCWD/data setenv DATAPATH /mnt/data/data Conditional statements are created with #################################### if( expression ) then make else cd $WORKDIR if( -f $INPUTFILE ) rm $INPUTFILE endif cp -f $LS SUBCWD/$INPUTFILE $WORKDIR setenv LD LIBRARY PATH $LS SUBCWD/../lib:$fLD LIBRARY PATHg echo and loops with echo START EXECUTION OF JOB echo foreach name (wordlist) $LS SUBCWD/../bin/$fCHANNELg analysis.exe >& analysis.out if( -f $WORKDIR/analysis.out ) mv $WORKDIR/analysis.out $LS SUBCWD end echo echo JOB FINISHED while ( expression ) echo end exit Spring 2010 COMPUTING METHODS IN HIGH ENERGY PHYSICS (page 6) S. Lehti and V.Karim¨aki Lecture 1 Short review to Unix basics bash test expression In bash the standard sh assignment to set vari- [expression] ables is used The other form of flow control is the case-esac name = value block. Bash supports several types of loops: for, The array variables can be set in two ways, either while, until and select loops. All loops in bash can by setting a single element be exit by giving the built-in break command. name[index] = value or multiple elements at once Perl name = (value1; ::; valueN) Perl has become the language of choice for many Exporting variables for use in the environment Unix-based programs, including server support for export name WWW pages. Perl is a simple yet useful program- export name = value ming language that provides the convenience of Arithmetic evaluation is performed when the fol- shell scripts and the power and flexibility of high- lowing form is encountered: $(( expression )). level programming languages. In perl the variable The basic if statement syntax is can be a string, integer or floating-point number. if list ; then All scalar variables start with the dollar sign $. The else following assignments are all legal in perl: fi $variable = 1; Most often the list given to an if statement is one $variable = "my string"; or more test commands, which can be invoked $variable = 3.14; by calling the test as follows: Spring 2010 COMPUTING METHODS IN HIGH ENERGY PHYSICS (page 7) S. Lehti and V.Karim¨aki Lecture 1 Short review to Unix basics To do arithmetic in Perl, the following operators An example Perl script #!/usr/local/bin/perl are supported: + - * / ** %. Logical operators ############################################### are divided into two classes, numeric and string. $ibg = 2020; $eventsPerFile = 500; The numeric logical operators are <, >, ==, $allEvents = 100000; <=, >=, !=, jj, && and !. The logical operator $firstEvent = 1; $BatchQueue = "1nw"; that work with strings are lt, gt, eq, le, ge and $Jobfile = ”offlineAnalysis.job”; ne. The most common assignment operator is $runNumber = 1; =. Autoincrement ++ and decrement - - are ############################################### $pwd = $ENVf'PWD'g; also available. Strings can be combined with . $orca = rindex("$pwd","ORCA"); $slash = index("$pwd","/",$orca); and .= operators, for example $ORCA Version = substr("$pwd",$orca,$slash-$orca); $famos = rindex("$pwd","FAMOS"); $a = "be" . "witched"; $slash = index("$pwd","/",$famos); $a = "be"; $a .= "witched"; $FAMOS Version = substr("$pwd",$famos,$slash-$famos); $ORCA VERSION = $ORCA Version; The if conditional statement has the following if($famos > $orca) f $ORCA VERSION = $FAMOS Version; structure: if (expr) f..g. Repeating statement g can be made using while and until, looping can print "Submitting $ORCA VERSION job(s)nn"; be done with the for statement. ###############################################

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us