diff --git a/doc/user_manual/chSpecialElements.tex b/doc/user_manual/chSpecialElements.tex index 24f01b79b..d706deefa 100644 --- a/doc/user_manual/chSpecialElements.tex +++ b/doc/user_manual/chSpecialElements.tex @@ -1625,29 +1625,6 @@ \section{Collimation} \label{sec:collimat} This database including the name, length, orientation and material of every single collimator of the ring (1 file per Collimation System Phase though). Apart from these two, the other required SixTrack files are produced via MAD-X and its conversion module. -\paragraph{Collimator Database}~\\ - -The collimator database is stored in files named \texttt{CollDB\_V6.500\_[type]\_st.[beam].data}, with \texttt{[type]} being either inj for injection case or low $b$ for collision case, and \texttt{[beam]} being $b1$ or $b2$. -These files contain mechanical and optical data related to the collimators planned for LHC. (Note that at present only Phase I collimators have a length different from zero) - -A sample block of either one of these input files follows: - -\begin{cverbatim} -TCP.D6L7.B1 <-- collimator name in capital letters -tcp.d6l7.b1 <-- collimator name in minimal letters -5.7 <-- collimator nominal opening (in sigma units) -C <-- collimator material (C = graphite, CU = copper, W=tungsten) - 0.2000000000000000 <-- collimator length [m] - 1.5710000000000000 <-- collimator angle [rad] - 0.0000000000000000 <-- collimator offset [m] - 90.4467000000000070 <-- design Beta x [m] -156.4360000000000070 <-- design Beta y [m] -# <-- line jump to next block -\end{cverbatim} - -The introduction of the optic parameter $\beta$ allows studies of error scenarios (orbit distortion, beta-beating\index{beta-beating}) and/or to see the effect of misaligned collimators. -This structure is then repeated within the file for each of the collimators to be included in the study. - % ================================================================================================================================ % \subsection{Collimation Input Block} \label{sec:coll:input} @@ -1664,7 +1641,6 @@ \subsection{Collimation Input Block} \label{sec:coll:input} \paragraph{Format Description:}~\\ From SixTrack version 5.2.5 and on, the main format of the \texttt(COLL) block is a set of keyword/value lines. -This format is described in Section~\ref(sec:coll:newfmt). For backwards compatibility, the old format is still supported, and it is described in Section~\ref{sec:coll:oldfmt}. When encountering the \texttt{COLL} block, the parser will check if the first line of the block is a single value, and if it is, it will conclude that the block is in the old format. @@ -1673,8 +1649,6 @@ \subsection{Collimation Input Block} \label{sec:coll:input} Note that the old and new format cannot be inter-mixed. The old format is parsed based on the line number, and must follow exactly the format described in Table~\ref{tab:COLL_INP}. -\subsubsection{New Format}\label{sec:coll:newfmt} - The keyword/value formated block is described below. The keywords mostly correspond to the keywords listed in Table~\ref{tab:COLL_INP}. @@ -1688,6 +1662,9 @@ \subsubsection{New Format}\label{sec:coll:newfmt} The filename of the database of collimators. This entry is required. +The format of the database is described in Section~\ref{Sec:CollDB}. +It is also possible to load the old style database format. +If so, a converted database is written to the simulation folder with an added file extension \texttt{.new}. \paragraph{Beam Energy (Required)} \texttt{ENERGY energy[MeV]}\\ @@ -1821,10 +1798,9 @@ \subsubsection{New Format}\label{sec:coll:newfmt} \paragraph{One-Sided Collimators} \texttt{DO\_ONESIDE true|false}\\ -Switches on or off the collimator being one-sided. -That is, only positive jaw. -If the negative jaw is to be used, it is necessary to turn collimator by 180 degrees in the collimator database file. -Default value is \texttt{false}. +This feature has been removed. +The collimators or collimator families that are to be treated as one-sided are now set in the collimator database file. +See Section~\ref{Sec:CollDB}. \paragraph{Beta-Beating} \texttt{BETA\_BEAT xbeat xbeat\_phase ybeat ybeat\_phase}\\ @@ -1912,11 +1888,6 @@ \subsubsection{New Format}\label{sec:coll:newfmt} Deduce \texttt{SYSTILT} to \texttt{RMSTILT} instead of adding. This value defaults to \texttt{false}. -% \paragraph{Cut Halo File (CERN Flag)} \texttt{CERN true|false}\\ - -% Switches on or off whether to cut halo files in separate pieces, one per 64 particles. -% This value defaults to \texttt{false}. - \paragraph{Cut Sigmas} \texttt{SIGSECUT sigma\_xy sigma\_r}\\ Sigma cuts for \texttt{tracks2.dat} controlled by the \texttt{WRITE\_TRACKS} flag. @@ -1940,7 +1911,189 @@ \subsubsection{New Format}\label{sec:coll:newfmt} % ================================================================================================================================ % -\subsubsection{Old Format}\label{sec:coll:oldfmt} +\subsection{The Collimator Database}\label{Sec:CollDB} + +Collimators require specific settings, which are provided in a dedicated collimator database. +The file is specified with the \texttt{COLLDB} keyword in the \texttt{COLL} block in \texttt{fort.3}. +See Section~\ref{sec:coll:input}. + +Only the new database format is described in this section, but it is possible to load a file with the old format. +The old format has been deprecated due to having a single column of parameters that are not straight-forward to read (by humans) and difficult to extend with new features. +If an old database file is specified, a converted database is written with the same file name plus an added extension \texttt{.new}. +New features added to the collimation module will not be supported by the old format. + +\paragraph{Database Structure}~\\ + +The database is split into two sections. +The first (main) section lists all the collimators and their default parameters. +The second section, separated from the first by the keyword \texttt{SETTINGS}, contains additional settings for specific collimators or families of collimators. +The second section is parsed following similar logic to the \texttt{fort.3} input block, but has a different set of keywords. +The second section is optional. + +\subsubsection{Main Database Section} + +The main section of the database consists of a list of collimator family declarations, followed by a list of collimators. +The family declaration is optional, but it makes it easier to assign parameters to a group of collimators instead of specifying each one individually. +In the main section, this is used to provide the default collimator opening. + +The collimator family settings are povided in exactly the same way as the \texttt{NISG\_FAM} keyword in the \texttt{COLL} block in \texttt{fort.3}. +The keyword takes a family name and a collimator opening setting as input parameters. +The settings in \texttt{fort.3} overrides the settings of the database. + +The collimator key settings are provided in a table of either 6 or 8 columns. +The latter two columns are optional. +The formats are as follows: + +\bigskip +\begin{tabular}{@{}llp{0.7\linewidth}} + \texttt{elemname} & char & The single element name of the collimator. \\ + \texttt{opening} & char/float & The family name as defined above, or if no family, the collimator opening in units of sigma. \\ + \texttt{material} & char(4) & The material of the collimator. \\ + \texttt{length} & float & The length of the collimator in metres. \\ + \texttt{angle} & float & The skew angle (i.e. about the longitudinal axis) of the collimator in degrees. \\ + \texttt{offset} & float & The offset of the collimator on the cleaning plane in metres. \\ + \texttt{beta\_x} & float & The Twiss $\beta_x$ of the collimator in metres (optional). \\ + \texttt{beta\_y} & float & The Twiss $\beta_y$ of the collimator in metres (optional). \\ +\end{tabular} + +\paragraph{Example}~ + +\begin{cverbatim} +# Families +NSIG_FAM tcp3 12.000000 +NSIG_FAM tcsg3 15.600000 +NSIG_FAM tcsm3 999.000000 +NSIG_FAM tcla3 17.600000 +# Collimators +# name opening mat. length[m] angle[deg] offset[m] beta_x[m] beta_y[m] +tclx.4r1.b1 tclp Iner 1.000000 0.000000 0.000000 6812.605863 4597.092632 +tcl.5r1.b1 tclp CU 1.000000 0.000000 0.000000 902.616764 1935.588447 +tcl.6r1.b1 tclp Iner 1.000000 0.000000 0.000000 142.965006 1166.200842 +tctph.4l2.b1 tcth2 Iner 1.000000 0.000000 0.000000 84.519178 104.259232 +tctpv.4l2.b1 tctv2 Iner 1.000000 90.000000 0.000000 86.619339 103.111681 +tdi.4l2.b1 tdi CU 4.000000 90.000000 0.000000 144.175250 96.678174 +tclia.4r2 tcli C 1.000000 90.000000 0.000000 98.565386 160.118523 +tclib.6r2.b1 tcli C 1.000000 90.000000 0.000000 149.324152 63.396485 +tcp.6l3.b1 tcp3 C 0.600000 0.000000 0.000000 131.520626 144.694013 +tcsg.5l3.b1 tcsg3 C 1.000000 0.000000 0.000000 54.604612 298.623904 +tcsg.4r3.b1 tcsg3 C 1.000000 0.000000 0.000000 26.209714 395.196297 +tcsg.a5r3.b1 tcsg3 C 1.000000 170.799865 0.000000 35.867692 344.111324 +tcsg.b5r3.b1 tcsg3 C 1.000000 11.400000 0.000000 45.537821 312.677533 +tcla.a5r3.b1 tcla3 Iner 1.000000 90.000000 0.000000 142.529342 176.013077 +tcla.b5r3.b1 tcla3 Iner 1.000000 0.000000 0.000000 151.614782 168.687046 +tcla.6r3.b1 tcla3 Iner 1.000000 0.000000 0.000000 129.435749 168.706418 +tcla.7r3.b1 tcla3 Iner 1.000000 0.000000 0.000000 66.935067 92.241046 +tcth.6l5.b1 tcth5 CuCD 1.000000 0.000000 0.000000 1262.953872 303.824116 +tctv.6l5.b1 tctv5 CuCD 1.000000 90.000000 0.000000 1322.390819 361.810773 +tctxh.4l5.b1 tcth5 CuCD 1.000000 0.000000 0.000000 4673.450003 7076.790857 +\end{cverbatim} + +\subsubsection{Additional Collimator Settings} + +Further collimator settings can be provided at the bottom of the database file separated by the \texttt{SETTINGS} keyword. +Currently, only one-sided collimators can be specified in this section. + +\paragraph{One-Sided Collimators} \texttt{ONESIDED name 1|2}\\ + +One-sided treatment of collimators can be achieved by setting this flag.\index{one-sided collimator} +The \texttt{name} can either be a collimator name or a family name. +The last parameter specifies either jaw 1 (i.e. at $x$>0 in the collimator reference system) or jaw 2 (i.e. at $x$<0 in the collimator reference system). +If jaw 2 is selected, the collimator is rotated by 180 degrees, as only the positive $x$ side is treated when one-sided is enabled. + +\paragraph{Example}~ + +\begin{cverbatim} +SETTINGS +ONESIDED tcdqa.a4r6.b1 1 +ONESIDED tcdqa.c4r6.b1 1 +ONESIDED tcdqa.b4r6.b1 1 +\end{cverbatim} + +% ================================================================================================================================ % + +\subsection{Collimation with Geant4} + +It is possible to use the particle-matter scattering physics of Geant4 within SixTrack. +To do this, the G4COLLIMATION flag must be added at build time, with an appropriate Geant4 library existing in your path. +Many standard collimation features are currently not implemented. +Particle longitudinal dynamics are also not currently implemented. +The \texttt{GNT4} block specified below must be used in addition to the standard collimation block in the standard \texttt{fort.3} file. \index{GNT4} \index{Geant4} + +\bigskip +\begin{tabular}{@{}lp{0.8\linewidth}} + \textbf{Keyword} & \texttt{GNT4}\index{GNT4} \\ + \textbf{Data lines} & Variable, see below. \\ + \textbf{Format} & This module uses a keyword, value format. See below. +\end{tabular} + +\bigskip + +\paragraph{Select Physics List} \texttt{PHYSICS phys}\\ + +The \texttt{PHYSICS} flag selects which physics list to use in Geant4. +If no flag is specified, the simulation will default to FTFP\_BERT. +Any Geant4 physics list is allowed. +Please see \url{http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/PhysicsListGuide/html/index.html} for more details. + +\bigskip +\begin{tabular}{@{}llp{0.7\linewidth}} + \texttt{phys} & char & The name of the physics list to use. +\end{tabular} + +\paragraph{Select Particles to Return to SixTrack} \texttt{RETURN type}\\ + +The \texttt{RETURN} flag selects which types of particles to return back to SixTrack after performing collimation. +Only charged particles are returned; neutral particles are always killed. +Possible options are \texttt{STABLE}, which will return all stable particles, \texttt{IONS}, which takes back all ions (not including protons), and to specify by individual PDG id numbers. +Both particles and anti-particles should be specified separately. +Multiple copies of the \texttt{RETURN} flag can be used to precisely select which particles are of interest. + +If no flag is specified, all particles are returned, including ones that should decay. + +\bigskip +\begin{tabular}{@{}llp{0.7\linewidth}} + \texttt{type} & char/int & The particles to send back to SixTrack after tracking through Geant4. +\end{tabular} + +\paragraph{Select Relative Energy Cut} \texttt{RELENERGYCUT cut}\\ + +The \texttt{RELENERGYCUT} flag selects an energy cut as a fraction of the energy of the reference particle. +For example, 0.5 will cut at half the energy of the reference particle. + +\bigskip +\begin{tabular}{@{}llp{0.7\linewidth}} + \texttt{cut} & float & The cut value to use. +\end{tabular} + +\paragraph{Select Absolute Energy Cut} \texttt{ABSENERGYCUT cut}\\ + +The \texttt{ABSENERGYCUT} flag selects an absolute energy cut, and if a particle's energy goes below this value, it will be killed. +This value is specified in GeV. + +\bigskip +\begin{tabular}{@{}llp{0.7\linewidth}} + \texttt{cut} & float & The cut value to use in GeV. +\end{tabular} + +\paragraph{Select Range Cut} \texttt{RANGECUT\_MM cut}\\ + +The \texttt{RANGECUT\_MM} flag selects a range cut for particle production in Geant4. +This value is specified in mm. +The unit of this cut may change in the future. + +\bigskip +\begin{tabular}{@{}llp{0.7\linewidth}} + \texttt{cut} & float & The cut value to use in mm. +\end{tabular} + +\paragraph{Enable Debugging Output} \texttt{DEBUG}\\ + +The \texttt{DEBUG} flag enables some additional debugging output in Geant4. +Warning: the level of output can be very verbose with a large number of particles. + +% ================================================================================================================================ % + +\subsection{Old Input Format}\label{sec:coll:oldfmt} The old input block format is illustrated in the following example, and the associated variable which each value is described in Table~\ref{tab:COLL_INP}. @@ -1967,6 +2120,29 @@ \subsubsection{Old Format}\label{sec:coll:oldfmt} NEXT----------------------------------------------------------------------------- \end{cverbatim} +\paragraph{Old Collimator Database Format}~\\ + +The collimator database is stored in files named \texttt{CollDB\_V6.500\_[type]\_st.[beam].data}, with \texttt{[type]} being either inj for injection case or low $b$ for collision case, and \texttt{[beam]} being $b1$ or $b2$. +These files contain mechanical and optical data related to the collimators planned for LHC. (Note that at present only Phase I collimators have a length different from zero) + +A sample block of either one of these input files follows: + +\begin{cverbatim} +TCP.D6L7.B1 <-- collimator name in capital letters +tcp.d6l7.b1 <-- collimator name in minimal letters +5.7 <-- collimator nominal opening (in sigma units) +C <-- collimator material (C = graphite, CU = copper, W=tungsten) + 0.2000000000000000 <-- collimator length [m] + 1.5710000000000000 <-- collimator angle [rad] + 0.0000000000000000 <-- collimator offset [m] + 90.4467000000000070 <-- design Beta x [m] +156.4360000000000070 <-- design Beta y [m] +# <-- line jump to next block +\end{cverbatim} + +The introduction of the optic parameter $\beta$ allows studies of error scenarios (orbit distortion, beta-beating\index{beta-beating}) and/or to see the effect of misaligned collimators. +This structure is then repeated within the file for each of the collimators to be included in the study. + \bigskip \begin{center} \begin{longtable}{| p{0.5cm} | p{2.4cm} | p{1.2cm} | >{\raggedright\arraybackslash}p{11.4cm}|} @@ -2214,88 +2390,6 @@ \subsubsection{Old Format}\label{sec:coll:oldfmt} \hline \end{longtable} \end{center} - -\subsection{Collimation with Geant4} - -It is possible to use the beam-material scattering physics engine from Geant4 with SixTrack. -To do this, the G4COLLIMATION flag must be added at build time, with an appropriate Geant4 library exiting in your path. -Many standard collimation features are currently not implemented. -Particle longitudinal dynamics are also not currently implemented. -The \texttt{GNT4} block specified below must be used in addition to the standard collimation block. \index{GNT4} \index{Geant4} - -\bigskip -\begin{tabular}{@{}lp{0.8\linewidth}} - \textbf{Keyword} & \texttt{GNT4}\index{GNT4} \\ - \textbf{Data lines} & Variable, see below. \\ - \textbf{Format} & This module uses a keyword, value format. See below. -\end{tabular} - -\bigskip - -\paragraph{Select Physics List} \texttt{PHYSICS phys}\\ - -The \texttt{PHYSICS} flag selects which physics list to use in Geant4. -If no flag is specified, the simulation will default to FTFP\_BERT. -Any Geant4 physics list is allowed. -Please see \url{http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/PhysicsListGuide/html/index.html} for more details. - -\bigskip -\begin{tabular}{@{}llp{0.7\linewidth}} - \texttt{phys} & char & The name of the physics list to use. -\end{tabular} - -\paragraph{Select Particles to Return to SixTrack} \texttt{RETURN type}\\ - -The \texttt{RETURN} flag selects which types of particles to return back to SixTrack after performing collimation. -Only charged particles are returned; neutral particles are always killed. -Possible options are \texttt{STABLE}, which will return all stable particles, \texttt{IONS}, which takes back all ions (not including protons), and to specify by individual PDG id numbers. -Both particles and anti-particles should be specified separately. -Multiple copies of the \texttt{RETURN} flag can be used to precisely select which particles are of interest. - -If no flag is specified, all particles are returned, including ones that should decay. - -\bigskip -\begin{tabular}{@{}llp{0.7\linewidth}} - \texttt{type} & char/int & The particles to send back to SixTrack after tracking through Geant4. -\end{tabular} - - -\paragraph{Select Relative Energy Cut} \texttt{RELENERGYCUT cut}\\ - -The \texttt{RELENERGYCUT} flag selects an energy cut as a fraction of the energy of the reference particle. -For example, 0.5 will cut at half the energy of the reference particle. - -\bigskip -\begin{tabular}{@{}llp{0.7\linewidth}} - \texttt{cut} & float & The cut value to use. -\end{tabular} - -\paragraph{Select Absolute Energy Cut} \texttt{ABSENERGYCUT cut}\\ - -The \texttt{ABSENERGYCUT} flag selects an absolute energy cut, and if a particle's energy goes below this value, it will be killed. -This value is specified in GeV. - -\bigskip -\begin{tabular}{@{}llp{0.7\linewidth}} - \texttt{cut} & float & The cut value to use in GeV. -\end{tabular} - -\paragraph{Select Range Cut} \texttt{RANGECUT\_MM cut}\\ - -The \texttt{RANGECUT\_MM} flag selects a range cut for particle production in Geant4. -This value is specified in mm. -The unit of this cut may change in the future. - -\bigskip -\begin{tabular}{@{}llp{0.7\linewidth}} - \texttt{cut} & float & The cut value to use in mm. -\end{tabular} - -\paragraph{Enable Debugging Output} \texttt{DEBUG}\\ - -The \texttt{DEBUG} flag enables some additional debugging output in Geant4. -Warning: the level of output can be very verbose with a large number of particles. - % ================================================================================================================================ % \section{Fringe Fields} \label{sec:ffield} diff --git a/source/coll_db.f90 b/source/coll_db.f90 index 4c2c7aa0c..e443961d5 100644 --- a/source/coll_db.f90 +++ b/source/coll_db.f90 @@ -23,8 +23,9 @@ module coll_db logical, public, save :: cdb_doNSig = .false. ! Use the sigmas from fort.3 instead of DB integer, public, save :: cdb_nColl = 0 ! Number of collimators integer, public, save :: cdb_nFam = 0 ! Number of collimator families + integer, public, save :: cdb_setPos = 0 ! The position in the DB file where the settings start - ! Database arrays + ! Main Database Arrays character(len=:), allocatable, public, save :: cdb_cName(:) ! Collimator name character(len=:), allocatable, public, save :: cdb_cNameUC(:) ! Collimator name upper case character(len=:), allocatable, public, save :: cdb_cMaterial(:) ! Collimator material @@ -38,6 +39,9 @@ module coll_db real(kind=fPrec), allocatable, public, save :: cdb_cBy(:) ! Collimator beta y logical, allocatable, public, save :: cdb_cFound(:) ! Found in lattice + ! Additional Settings Arrays + integer, allocatable, public, save :: cdb_cSides(:) ! 0 = two-sided, or 1,2 for single side 1 or 2 + ! Family Arrays character(len=:), allocatable, public, save :: cdb_famName(:) ! Family name real(kind=fPrec), allocatable, public, save :: cdb_famNSig(:) ! Family sigma @@ -48,12 +52,19 @@ module coll_db contains +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-03-19 +! Updated: 2019-08-30 +! Change the size of the collimator database arrays +! ================================================================================================ ! subroutine cdb_allocDB use parpro use mod_alloc use numerical_constants + ! Main Database Arrays call alloc(cdb_cName, mNameLen, cdb_nColl, " ", "cdb_cName") call alloc(cdb_cNameUC, mNameLen, cdb_nColl, " ", "cdb_cNameUC") call alloc(cdb_cMaterial, 4, cdb_nColl, " ", "cdb_cMaterial") @@ -67,8 +78,17 @@ subroutine cdb_allocDB call alloc(cdb_cBy, cdb_nColl, zero, "cdb_cBy") call alloc(cdb_cFound, cdb_nColl, .false., "cdb_cFound") + ! Additional Settings Arrays + call alloc(cdb_cSides, cdb_nColl, 0, "cdb_cSides") + end subroutine cdb_allocDB +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-03-19 +! Updated: 2019-08-30 +! Change the size of the collimator family arrays +! ================================================================================================ ! subroutine cdb_allocFam use parpro @@ -80,14 +100,16 @@ subroutine cdb_allocFam end subroutine cdb_allocFam +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-03-19 +! Updated: 2019-08-30 +! Change the size of other arrays depending on external size parameters +! ================================================================================================ ! subroutine cdb_expand_arrays(nele_new) - use mod_alloc - integer, intent(in) :: nele_new - call alloc(cdb_elemMap,nele_new,0,"cdb_elemMap") - end subroutine cdb_expand_arrays ! ================================================================================================ ! @@ -142,6 +164,11 @@ subroutine cdb_readCollDB call cdb_readDB_newFormat end if + if(cdb_setPos > 0) then + ! The DB has additional SETTINGS, parse them + call cdb_readDBSettings + end if + #ifdef ROOT call cdb_writeDB_ROOT #endif @@ -185,6 +212,13 @@ subroutine cdb_readCollDB end subroutine cdb_readCollDB +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-03-19 +! Updated: 2019-08-30 +! Parsing the collimator section of the new database format. That is, the sigma settings and the +! collimator descriptions. The parsing ends when it reaches the SETTINGS keyword. +! ================================================================================================ ! subroutine cdb_readDB_newFormat use parpro @@ -205,6 +239,8 @@ subroutine cdb_readDB_newFormat iLine = 0 iColl = 0 + write(lout,"(a)") "COLLDB> Reading collimator database, new format" + call f_requestUnit(cdb_fileName, dbUnit) call f_open(unit=dbUnit,file=cdb_fileName,formatted=.true.,mode="r",status="old",err=fErr) if(fErr) then @@ -227,6 +263,13 @@ subroutine cdb_readDB_newFormat write(lerr,"(a,i0)") "COLLDB> ERROR Failed to parse database line ",iLine call prror end if + if(nSplit == 0) goto 10 ! Skip empty lines + + if(lnSplit(1) == "SETTINGS") then + write(lout,"(a,i0)") "COLLDB> SETTINGS flag encountered in collimator database on line ",iLine + cdb_setPos = iLine + goto 20 + end if if(lnSplit(1) == "NSIG_FAM") then ! Collimator Family @@ -294,6 +337,12 @@ subroutine cdb_readDB_newFormat end subroutine cdb_readDB_newFormat +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-03-19 +! Updated: 2019-09-02 +! Parses the old style database format with one calue per line. +! ================================================================================================ ! subroutine cdb_readDB_oldFormat use crcoall @@ -305,26 +354,15 @@ subroutine cdb_readDB_oldFormat character(len=mInputLn) inLine character(len=cdb_fNameLen) famName logical cErr - integer j, dbUnit, dbNew, ioStat, iLine, famID + integer j, dbUnit, ioStat, iLine, famID cErr = .false. + write(lout,"(a)") "COLLDB> Reading collimator database, old format" + call f_requestUnit(cdb_fileName, dbUnit) call f_open(unit=dbUnit,file=cdb_fileName,formatted=.true.,mode="r",status="old") - call f_requestUnit(trim(cdb_fileName)//".new", dbNew) - call f_open(unit=dbNew,file=trim(cdb_fileName)//".new",formatted=.true.,mode="w",status="replace") - - write(dbNew,"(a)") "# Automatically converted collimator DB from old format file '"//trim(cdb_fileName)//"'" - write(dbNew,"(a)") "# Families" - do j=1,cdb_nFam - write(dbNew,"(a,1x,a16,1x,f13.6)") "NSIG_FAM",cdb_famName(j),cdb_famNSig(j) - end do - write(dbNew,"(a)") "# Collimators" - - write(dbNew,"(1a,a47,1x,a16,1x,a4,5(1x,a13))") "#",chr_rPad(" name",47),& - "opening","mat.","length[m]","angle[deg]","offset[m]","beta_x[m]","beta_y[m]" - read(dbUnit,*,iostat=ioStat) inLine iLine = 1 if(ioStat /= 0) goto 100 @@ -406,7 +444,59 @@ subroutine cdb_readDB_oldFormat cdb_cNSig(j) = cdb_cNSigOrig(j) end if cdb_cFamily(j) = famID - if(famID > 0) then + + end do + + call f_freeUnit(dbUnit) + + return + +100 continue + write(lerr,"(2(a,i0))") "COLLDB> ERROR Cannot read DB file line ",iLine,", iostat = ",ioStat + call prror + +end subroutine cdb_readDB_oldFormat + +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-03-19 +! Updated: 2019-09-02 +! Write a copy of the old style DB in new DB format. +! ================================================================================================ ! +subroutine cdb_writeDB_newFromOld + + use crcoall + use string_tools + use mod_units + use numerical_constants + + character(len=cdb_fNameLen) famName + integer j, dbNew + + if(cdb_dbOld .eqv. .false.) then + ! Already have a new format DB + return + end if + + write(lout,"(a)") "COLLDB> Converting old format DB to new format to file '"//trim(cdb_fileName)//".new'" + + call f_requestUnit(trim(cdb_fileName)//".new", dbNew) + call f_open(unit=dbNew,file=trim(cdb_fileName)//".new",formatted=.true.,mode="w",status="replace") + + write(dbNew,"(a)") "# Automatically converted collimator DB from old format file '"//trim(cdb_fileName)//"'" + write(dbNew,"(a)") "# Families" + do j=1,cdb_nFam + write(dbNew,"(a,1x,a16,1x,f13.6)") "NSIG_FAM",cdb_famName(j),cdb_famNSig(j) + end do + write(dbNew,"(a)") "#" + write(dbNew,"(a)") "# Collimators" + + write(dbNew,"(1a,a47,1x,a16,1x,a4,5(1x,a13))") "#",chr_rPad(" name",47),& + "opening/fam","mat.","length[m]","angle[deg]","offset[m]","beta_x[m]","beta_y[m]" + + do j=1,cdb_nColl + if(cdb_cFamily(j) > 0) then + famName = cdb_famName(cdb_cFamily(j)) write(dbNew,"(a48,1x,a16,1x,a4,5(1x,f13.6))") cdb_cName(j),& chr_lPad(trim(famName),16),cdb_cMaterial(j),cdb_cLength(j),cdb_cRotation(j)/rad,& cdb_cOffset(j),cdb_cBx(j),cdb_cBy(j) @@ -415,21 +505,155 @@ subroutine cdb_readDB_oldFormat cdb_cNSig(j),cdb_cMaterial(j),cdb_cLength(j),cdb_cRotation(j)/rad,& cdb_cOffset(j),cdb_cBx(j),cdb_cBy(j) end if - end do - call f_close(dbUnit) + write(dbNew,"(a)") "#" + write(dbNew,"(a)") "# Additional Collimator Settings" + write(dbNew,"(a)") "SETTINGS" + + ! Onesided Collimators + do j=1,cdb_nColl + if(cdb_cSides(j) > 0) then + write(dbNew,"(a,1x,a48,1x,i1)") "ONESIDED",cdb_cName(j),cdb_cSides(j) + end if + end do flush(dbNew) - call f_close(dbNew) + call f_freeUnit(dbNew) + +end subroutine cdb_writeDB_newFromOld + +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-08-30 +! Updated: 2019-08-30 +! Parse additional settings from the collimator database. This is treated separately since this +! section is parsed in a standard name/value format like an input block in fort.3 +! ================================================================================================ ! +subroutine cdb_readDBSettings + + use parpro + use crcoall + use string_tools + use mod_units + use mod_alloc + use numerical_constants + + character(len=:), allocatable :: lnSplit(:) + character(len=mInputLn) inLine + integer i, dbUnit, ioStat, nSplit, iLine, iColl, iFam, iTemp + logical cErr, fErr, isFam + + fErr = .false. + cErr = .false. + iLine = 0 + + write(lout,"(a)") "COLLDB> Reading additional settings from collimator database" + + call f_requestUnit(cdb_fileName, dbUnit) + call f_open(unit=dbUnit,file=cdb_fileName,formatted=.true.,mode="r",status="old",err=fErr) + if(fErr) then + write(lerr,"(a)") "COLLDB> ERROR Cannot read from '"//trim(cdb_fileName)//"'" + call prror + end if + +10 continue + iLine = iLine + 1 + + read(dbUnit,"(a)",end=20,iostat=ioStat) inLine + if(iLine <= cdb_setPos) goto 10 ! Skip already parsed lines + + if(ioStat /= 0) then + write(lerr,"(a)") "COLLDB> ERROR Cannot read from '"//trim(cdb_fileName)//"'" + call prror + end if + if(inLine(1:1) == "#") goto 10 + + call chr_split(inLine, lnSplit, nSplit, cErr) + if(cErr) then + write(lerr,"(a)") "COLLDB> ERROR Failed to parse database line" + goto 30 + end if + if(nSplit == 0) goto 10 ! Skip empty lines + + ! Look up the target collimator or family + iFam = -1 + iColl = -1 + isFam = .false. + if(nSplit >= 2) then + iFam = cdb_getFamilyID(lnSplit(2)) + iColl = cdb_getCollimatorID(lnSplit(2)) + if(iFam == -1 .and. iColl == -1) then + write(lerr,"(a)") "COLLDB> ERROR Could not find '"//trim(lnSplit(2))//"' in neither collimator nor family database" + goto 30 + end if + if(iFam > 0 .and. iColl > 0) then + write(lerr,"(a)") "COLLDB> ERROR Found '"//trim(lnSplit(2))//"' in both collimator and family database" + goto 30 + end if + isFam = iFam > 0 + else + write(lerr,"(a)") "COLLDB> ERROR Each keyword in the SETTINGS section of the collimator database requires "//& + "a target collimator or family name" + goto 30 + end if + + ! Parse the keywords + select case(lnSplit(1)) + + case("ONESIDED") ! Treatment of one-sided collimators + + if(nSplit /= 3) then + write(lerr,"(a,i0)") "COLLDB> ERROR ONESIDED expects 2 values, got ",nSplit-1 + write(lerr,"(a)") "COLLDB> ONESIDED collname|famname 1|2" + goto 30 + end if + call chr_cast(lnSplit(3), iTemp, cErr) + if(iTemp /= 1 .and. iTemp /= 2) then + write(lerr,"(a,i0)") "COLLDB> ERROR ONESIDED collimator value must be 1 or 2, got ",iTemp + goto 30 + end if + if(isFam) then + do i=1,cdb_nColl + if(cdb_cFamily(iFam) == iFam) then + if(iTemp == 2) then + call cdb_rotateCollimator(i, pi) + write(lout,"(a,i0,a)") "COLLDB> Collimator family '"//trim(lnSplit(2))//& + "' is set as one-sided and rotated by pi (",iTemp,")" + else + write(lout,"(a,i0,a)") "COLLDB> Collimator family '"//trim(lnSplit(2))//"' is set as one-sided (",iTemp,")" + end if + cdb_cSides(i) = 1 + end if + end do + else + if(iTemp == 2) then + call cdb_rotateCollimator(iColl, pi) + write(lout,"(a,i0,a)") "COLLDB> Collimator '"//trim(lnSplit(2))//"' is set as one-sided and rotated by pi (",iTemp,")" + else + write(lout,"(a,i0,a)") "COLLDB> Collimator '"//trim(lnSplit(2))//"' is set as one-sided (",iTemp,")" + end if + cdb_cSides(iColl) = 1 + end if + + case default + write(lerr,"(a)") "COLLDB> ERROR Unknown keyword '"//trim(lnSplit(1))//"' in SETTINGS section" + goto 30 + + end select + goto 10 + +20 continue + + call f_close(dbUnit) return -100 continue - write(lerr,"(2(a,i0))") "COLLDB> ERROR Cannot read DB file line ",iLine,", iostat = ",ioStat +30 continue + write(lerr,"(a,i0)") "COLLDB> ERROR Collimator DB '"//trim(cdb_fileName)//"' on line ",iLine call prror -end subroutine cdb_readDB_oldFormat +end subroutine cdb_readDBSettings #ifdef ROOT subroutine cdb_writeDB_ROOT @@ -506,6 +730,30 @@ subroutine cdb_writeDB_HDF5 end subroutine cdb_writeDB_HDF5 #endif +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-09-02 +! Updated: 2019-09-02 +! Rotate a collimater by rAngle radians +! Note: does not check that zero <= rAngle <= twopi +! ================================================================================================ ! +subroutine cdb_rotateCollimator(collID, rAngle) + + use numerical_constants + + integer, intent(in) :: collID + real(kind=fPrec), intent(in) :: rAngle + + cdb_cRotation(collID) = cdb_cRotation(collID) + rAngle + if(cdb_cRotation(collID) >= twopi) then + cdb_cRotation(collID) = modulo(cdb_cRotation(collID), twopi) + end if + if(cdb_cRotation(collID) < zero) then + cdb_cRotation(collID) = cdb_cRotation(collID) + twopi + end if + +end subroutine cdb_rotateCollimator + ! ================================================================================================ ! ! V.K. Berglyd Olsen, BE-ABP-HSS ! Created: 2019-03-22 @@ -559,6 +807,29 @@ integer function cdb_getFamilyID(famName) result(famID) end function cdb_getFamilyID +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-08-30 +! Updated: 2019-08-30 +! Find a collimator in the database and returns its ID +! ================================================================================================ ! +integer function cdb_getCollimatorID(collName) result(collID) + + character(len=*), intent(in) :: collName + integer i + + collID = -1 + if(cdb_nColl > 0) then + do i=1,cdb_nColl + if(cdb_cName(i) == collName) then + collID = i + exit + end if + end do + end if + +end function cdb_getCollimatorID + ! ================================================================================================ ! ! V.K. Berglyd Olsen, BE-ABP-HSS ! Created: 2019-03-21 @@ -640,6 +911,10 @@ subroutine cdb_writeDB end subroutine cdb_writeDB +! ================================================================================================ ! +! Compatibility Functions for old collimation code assuming LHC naming convention +! ================================================================================================ ! + ! ================================================================================================ ! ! V.K. Berglyd Olsen, BE-ABP-HSS ! Created: 2019-03-19 @@ -740,4 +1015,34 @@ subroutine cdb_generateFamName(inElem, famName) end subroutine cdb_generateFamName +! ================================================================================================ ! +! V.K. Berglyd Olsen, BE-ABP-HSS +! Created: 2019-09-02 +! Updated: 2019-09-02 +! Checks for one sided collimators from old input block and DB using the COLL block flag and +! hardcoded onesided treatment for TCDQ and roman pots. +! ================================================================================================ ! +subroutine cdb_setLHCOnesided(doOneSide) + + use crcoall + + logical, intent(in) :: doOneSide + + integer i + + if(cdb_dbOld .eqv. .false.) then + ! Only do this if we're using the old DB format + return + end if + + do i=1,cdb_nColl + cdb_cSides(i) = 0 + if((cdb_cNameUC(i)(1:3) == "TCP" .and. doOneSide) .or. cdb_cNameUC(i)(1:4) == "TCDQ" .or. cdb_cNameUC(i)(1:5) == "TCXRP") then + cdb_cSides(i) = 1 + write(lout,"(a)") "COLLDB> Collimator '"//trim(cdb_cName(i))//"' is treated as one-sided" + end if + end do + +end subroutine cdb_setLHCOneSided + end module coll_db diff --git a/source/collimation.f90 b/source/collimation.f90 index baaae8a97..84f21eb4c 100644 --- a/source/collimation.f90 +++ b/source/collimation.f90 @@ -220,7 +220,7 @@ module collimation real(kind=fPrec), save :: remitx_dist,remity_dist,remitx_collgap,remity_collgap - logical, save :: firstcoll,found,onesided + logical, save :: firstcoll,found integer rnd_lux,rnd_k1,rnd_k2 integer, save :: myix,myktrack @@ -592,7 +592,7 @@ end subroutine collimation_expand_arrays ! This routine is called once at the start of the simulation and can be used to do any initial ! configuration and/or file loading. ! ================================================================================================ ! -subroutine collimate_init() +subroutine collimate_init use crcoall use parpro @@ -886,8 +886,10 @@ subroutine collimate_init() call f_requestUnit('CollPositions.dat', CollPositions_unit) open(unit=CollPositions_unit, file='CollPositions.dat') - ! Read collimator database - call cdb_readCollDB + ! Collimator Database + call cdb_readCollDB ! Read the collimator DB + call cdb_setLHCOnesided(do_oneside) ! Set LHC onesided collimators + call cdb_writeDB_newFromOld ! Write a copy of the db in new format, if provided in old format ! Then do any implementation specific initial loading #ifdef COLLIMATE_K2 @@ -1139,13 +1141,10 @@ subroutine collimate_parseInputLine(inLine, iLine, iErr) call chr_cast(lnSplit(2), rnd_seed, iErr) case("DO_ONESIDE") - if(nSplit /= 2) then - write(lerr,"(a,i0)") "COLL> ERROR DO_ONESIDE expects 1 value, got ",nSplit-1 - write(lerr,"(a)") "COLL> DO_ONESIDE true|false" - iErr = .true. - return - end if - call chr_cast(lnSplit(2), do_oneside, iErr) + write(lerr,"(a)") "COLL> ERROR The new COLLIMATION block no longer supports the DO_ONESIDE flag" + write(lerr,"(a)") "COLL> The feature has been moved the the collimator database" + iErr = .true. + return case("WRITE_DIST") if(nSplit /= 2) then @@ -2291,6 +2290,7 @@ subroutine collimate_do_collimator(stracki) real(kind=fPrec), intent(in) :: stracki integer j,jjj + logical onesided #ifdef G4COLLIMATION integer :: g4_lostc @@ -2663,8 +2663,10 @@ subroutine collimate_do_collimator(stracki) !++ Do the collimation tracking enom_gev = myenom*c1m3 -!++ Allow primaries to be one-sided, if requested - if ((cdb_cNameUC(icoll)(1:3).eq.'TCP' .or. cdb_cNameUC(icoll)(1:3).eq.'COL') .and. do_oneside) then + ! Allow treatment of collimators as one-sided + if(cdb_cSides(icoll) == 1) then + onesided = .true. + else if(cdb_cSides(icoll) == 2) then onesided = .true. else onesided = .false. @@ -2688,15 +2690,6 @@ subroutine collimate_do_collimator(stracki) & flukaname) else -!GRD-SR, 09-02-2006 -!Force the treatment of the TCDQ equipment as a onsided collimator. -!Both for Beam 1 and Beam 2, the TCDQ is at positive x side. -! if(cdb_cNameUC(icoll)(1:4).eq.'TCDQ' ) onesided = .true. -! to treat all collimators onesided -! -> only for worst case TCDQ studies - if(cdb_cNameUC(icoll)(1:4).eq.'TCDQ') onesided = .true. - if(cdb_cNameUC(icoll)(1:5).eq.'TCXRP') onesided = .true. - !==> SLICE here is possible ! ! SR, 29-08-2005: Slice the collimator jaws in 'n_slices' pieces diff --git a/test/collimation_new-db_new-block/CollDB-HLLHC.dat b/test/collimation_new-db_new-block/CollDB-HLLHC.dat index 738050e54..631c1bf67 100644 --- a/test/collimation_new-db_new-block/CollDB-HLLHC.dat +++ b/test/collimation_new-db_new-block/CollDB-HLLHC.dat @@ -79,3 +79,9 @@ tcth.6l1.b1 tcth1 CuCD 1.00 tctv.6l1.b1 tctv1 CuCD 1.000000 90.000000 0.000000 1322.390717 361.810771 tctxh.4l1.b1 tcth1 CuCD 1.000000 0.000000 0.000000 4673.449650 7076.790797 tctpv.4l1.b1 tctv1 CuCD 1.000000 90.000000 0.000000 4761.459948 7383.238344 +# +# Additional Collimator Settings +SETTINGS +ONESIDED tcdqa.a4r6.b1 1 +ONESIDED tcdqa.c4r6.b1 1 +ONESIDED tcdqa.b4r6.b1 1 diff --git a/test/collimation_new-db_new-block/fort.3 b/test/collimation_new-db_new-block/fort.3 index 3f1ab32a4..fe6bf6897 100644 --- a/test/collimation_new-db_new-block/fort.3 +++ b/test/collimation_new-db_new-block/fort.3 @@ -98,7 +98,6 @@ COLLIMATION------------------------------------------------------------- SIGSECUT 1 1 DO_NOMINAL off - DO_ONESIDE off DO_MINGAP off WRITE_DIST on diff --git a/test/collimation_old-db_new-block/fort.3 b/test/collimation_old-db_new-block/fort.3 index 41bc66208..5b17703ad 100644 --- a/test/collimation_old-db_new-block/fort.3 +++ b/test/collimation_old-db_new-block/fort.3 @@ -98,7 +98,6 @@ COLLIMATION------------------------------------------------------------- SIGSECUT 1 1 DO_NOMINAL off - DO_ONESIDE off DO_MINGAP off WRITE_DIST on