\documentclass[11pt,english,a4paper]{article}

% Specify EDMS number and version - status (released, draft, obsolete)
\def\edms{xxx}
\def\rev{1.0}
\def\status{draft}
\usepackage{palatino}
\linespread{1.05} 

\usepackage{pdflscape}




%\newcommand*{\AllCalibri}{}
% has to be compiled with lualatex or xelatex
\ifdefined\AllCalibri
\usepackage{unicode-math}
\usepackage{amsmath}
\usepackage{xltxtra}
\setmainfont{Calibri}
\setmathfont{Calibri}
\linespread{1.15} 
\fi

\usepackage{graphicx}
%\usepackage{subfigure}
\usepackage{booktabs}
\usepackage{color}
\usepackage{xspace}
\usepackage{lscape}
\usepackage{tabularx}
\usepackage{floatrow}
\usepackage{hyperref}
\usepackage{cite}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{footnote}
\usepackage{multirow}

\usepackage{wasysym}
%\usepackage{siunitx}
\usepackage{xcolor}
\usepackage[toc,page]{appendix}
\usepackage{tikzpagenodes}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{rotating}
\usepackage{tablefootnote}
\usepackage{multirow}
\usepackage{hyperref}
%\usepackage{amsmath,amsfonts,amssymb}
%\usepackage{amsmath}
%\usepackage{mathtools}
%\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}

\usepackage{pdflscape}
\usepackage{float}

\usepackage{array}
\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}

\widowpenalty=10000
\clubpenalty=10000

\hypersetup{
	colorlinks=true,       % false: boxed links; true: colored links
    linkcolor=blue,          % color of internal links
    citecolor=blue,        % color of links to bibliography
    filecolor=blue,      % color of file links
    urlcolor=blue          % color of external links
}


\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}
%% A simple dot to overcome graphicx limitations
\newcommand{\lyxdot}{.}


%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.

%\usepackage{tgpagella}


\usepackage{epsfig}

\textheight 240mm               
\textwidth 165mm                
\voffset -1.7cm                 
\hoffset -2.1cm                 

\def\Cred{\special{ps:1 0 0 setrgbcolor}}
\def\Cgreen{\special{ps:0 0.8 0 setrgbcolor}}
\def\Cblue{\special{ps:0 0 1 setrgbcolor}}
\def\Cblack{\special{ps:0 0 0 setrgbcolor}}
 
% Next,  we define today's date in European format (done automatically)
\def\today{\number\day\space
     \ifcase\month\or
       January\or February\or March\or April\or May\or June\or
       July\or August\or September\or October\or November\or December\fi
     \space\number\year}
 
\newcommand{{\inch}}{\ifmmode{}^{\prime\kern-.5pt\prime}%
                   \else  ${}^{\prime\kern-.5pt\prime}$\fi}

\parskip12pt plus 1pt minus 1pt
\topsep0pt plus 1pt


\def\s{\rule{0pt}{2.5ex}} 
 
\newcommand{\TDepac}[1]{\setlength{\unitlength}{0.5cm}
            \begin{picture}(16,11)
            \put(-0.5,-2.0){\rotatebox{90}{
             \mbox{\includegraphics*[height=9cm]{#1.ps}}
             } }
            \end{picture}
                         }

\newcommand{\TDbox}[1]{\setlength{\unitlength}{1cm}
            \begin{picture}(16,10)
            \begin{picture}(16,10)
             \put(1.2,-0.2){\rotatebox{90}{
             \mbox{\includegraphics*[height=14cm]{#1.ps}}
              }}
            \end{picture} }
 
%\hyphenation {wash-out}
\def\@oddhead{}\def\@evenhead{}
\def\@oddfoot{\rm\rightmark \hfil Page \thepage}
\def\@evenfoot{\@oddfoot}


\makeatother

%\usepackage{babel}
\newcommand{\gev}{\ensuremath{\mathrm{\,Ge\kern -0.1em V}}\xspace}
\newcommand{\tev}{\ensuremath{\mathrm{\,Te\kern -0.1em V}}\xspace}
\newcommand{\mev}{\ensuremath{\mathrm{\,Me\kern -0.1em V}}\xspace}
\newcommand{\kev}{\ensuremath{\mathrm{\,ke\kern -0.1em V}}\xspace}
\newcommand{\gevDivc}{\ensuremath{\mathrm{\,Ge\kern -0.1em V\kern -0.1em }/\kern -0.1em \mathrm{c}}\xspace}
\newcommand{\expnum}[2]{\ensuremath{#1\times10^{#2}}}
\newcommand{\highlight}[1]{{\bf \color{red} #1}}
\newcommand{\isotope}[2]{\ensuremath{^{\mathrm{#2}}\mathrm{#1}}}

\newcommand{\card}[1]{\large{\texttt{#1}}\normalsize}

\begin{document}

%\pagenumbering { }

\renewcommand{\thefootnote}{\fnsymbol{footnote}} \setcounter{footnote}{0}

%--------------------------Title page-----------------------------------

\begin{titlepage}


\begin{tikzpicture}[remember picture,overlay]
	\node[anchor=west, xshift=4.5cm,yshift=-1.5cm] at (current page.north west) % CERN Logo
	  {\includegraphics[width=2.2cm]{figures/cernlogo.png}};
	%\node[anchor=west, xshift=7.0cm,yshift=-1.5cm] at (current page.north west) % if 2nd Logo (e.g. HiLumi) needed
	%  {\includegraphics[width=3.5cm]{figures/HiLumi-logo-REF-No-Background.png}};
\end{tikzpicture}%

\vspace{8mm}

\begin{tabular}{c}
\textbf{\large ORGANISATION EUROPEENNE POUR LA RECHERCHE NUCLEAIRE}{\Large{} }\tabularnewline
\textbf{\large EUROPEAN ORGANIZATION FOR NUCLEAR RESEARCH}{\Large{} }\tabularnewline
{\large Laboratoire Europ\'een pour la Physique des Particules} \tabularnewline
{\large European Laboratory for Particle Physics} \tabularnewline
\end{tabular}

\vspace{8mm}

\centerline{\textbf{\large Occupational Health \& Safety and Environmental Protection Unit}{\large }}{\large \par}

\vspace{8mm}


\rightline{\textbf{\textit{\large Summer Student Report}}{\large }}{\large \par}
\rightline{\today}
\vspace{8mm}

% Document title
\begin{center}
	{ \textbf{\Large Investigating binning strategies for luminosity profiles}\\
	\vspace{8mm}
	Gabriel Pajda\\
	Supervisor: Vasiliki Kouskoura
	{\Large{}
}}  
\par\end{center}{\Large \par}

% Document authors and reviewers 
\vspace{8mm}

% Short summary
\begin{center}
{\textbf{\textit{Summary}}}
\par\end{center}

The Radiation Protection assessments regularly involve the prediction of residual ambient dose equivalent rates with dedicated codes coupled to FLUKA and the prediction of the activation of components. For these calculations, binned luminosity data has to be supplied as input. The investigation of several binning strategies with respect to luminosity profiles of the LHC for Run 3 and the relevant cool-down times during TS, YETS and Long Shutdowns is of high importance. 


\end{titlepage}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Modifications page
\clearpage \newpage{}
\setcounter{page}{2}

% Table of contents can be switched off if prefered
{\hypersetup{linkcolor=black}
% or \hypersetup{linkcolor=black}, if the colorlinks=true option of hyperref is used

\tableofcontents
\listoffigures
\listoftables
 \newpage{}
}

%my settings
%\pagestyle{myheadings}
%\markright{\emph{EDMS \# \edms}}


\section{Introduction}
\label{Intro}

During the operation of the LHC the surroundings of the accelerator are being irradiated. As a result radioisotopes are created and then decay into their daughters. CERN needs to monitor the specific activity of different radioisotopes so to ensure that the accelerator is safe to access. This involves estimating the activity after different cooldown times using analytical and statistical models.

These models use irradiation profiles as a measure of how much the accelerator is irradiated over time. Accelerator data for a single run contains thousands of luminosity data points. However, such a huge amount of data is impractical to use in the models as it would require enormous amounts of computation. Additionally, it is inefficient to have detailed information on the early stages of the run as most of the short-lived radioisotopes will decay away by its end while the long-lived ones will be unaffected by the finer binning. On the other hand, a courser binning at the end of the run will significantly affect the activity of short-lived isotopes.

A solution to this problem is to simplify the luminosity profile by hand. The bins in the profile are grouped into longer time intervals divided by technical stops so to approximate the original profile with fewer bins. The most recent period is grouped into finer intervals of roughly equal irradiation rate so to represent accurately short-lived radioisotopes.

The aim of this project was to automate the grouping of bins in luminosity profiles and then to test some binning strategies so to see how they affect the simulated activities. I developed two different ways of grouping bins	 both of which can be parametrised so to achieve different effects. Then I used the profiles constructed this way so to calculate the activities of a number of radioisotopes with different half-lives and compared it to a simulation that used the original data.

The results of the comparison depend significantly on the shape of the luminosity profile. When the bins are grouped into intervals of exponentially decreasing length, groupings with different exponents often diverge for different half-lives. A different method of grouping that compares the averages of bins and their time length achieves better precision for some of the chosen radioisotopes although it requires more tuning so to get the right amount of bins.




\section{Dataset and methods}
\label{Data}

The data was sourced from CERN accelerator statistics \cite{AS}. It's for the period from June 2015 to December 2018 and contains about 3800 data points. It contains the integral luminosity at the CMS detector in inverse attobarns at time stamps in milliseconds. The first step in processing the data is converting the cumulative time into time intervals in seconds and converting the integral luminosity into luminosity rates in inverse picobarns per second.

The grouping was performed in two different ways. The first way involves defining some limits from 0 to 1 which then are fitted to the length of the luminosity profile. Then the bins of the luminosity profile within some limits are grouped together. The method allows to specify the number of bins in the output and then generates the limits at either equal time intervals or exponentially decreasing time intervals with a user defined exponent.

The second way of grouping involves defining some conditions that all the bins in a grouping must satisfy and then grouping the bins into the largest possible groups. The conditions can be either on the bins' luminosity rates, a rolling average of the luminosity rates or the length of the time intervals. If the absolute difference of the two chosen quantities is smaller than either of the quantities times a variable tolerance then the two bins can be grouped together. The tolerance is an arbitrary function of the normalised length of the luminosity profile and will determine the shape of the grouping. The length of the grouping starting at each point is calculated and then the bins are grouped starting from the longest possible grouping. Conditions can be joint together so to have a grouping dependent on more than one quantity.

It became clear after using the first grouping method that it completely neglects the shape of the profile. Luminosity profiles of long accelerator runs feature both long technical breaks as well as short breaks between bursts of luminosity. Averaging over technical breaks gave long periods of low luminosity rates instead of short bursts of high luminosity rates divided by long pauses. Thus first I group the bins with zero luminosity so to see long breaks. Then I impose a condition on the length of the time intervals so that long pauses aren't combined with the data. The second condition is on the rolling average over two bins. This ensures that periods of similar bursts divided by short breaks are grouped together. Tolerance functions are set to decay exponentially over the profile and then tuned so to give a reasonable number of bins and a reasonable accuracy for the activity of chosen radioisotopes.

Once the profiles are created the python module \cite{RE} and a modification of the jupyter notebook found in \cite{LP} are used to calculate the induced activities for each profile from the Bateman equation. The results are then divided by the activities calculated from the original profile.

For this report I created 6 profiles, each one containing less than 25 bins. I used the second method, the first method with equal bins and with exponentially decreasing bins with exponents 1.25, 1.5, 1.75 and 2. The code can be found in the project's GitLab repository \cite{LHC-BS}.


%         \bf GitLab & \small{\href{https://gitlab.cern.ch/rp-operation/codes/lhc-binning-strategies}{rp-operation/codes/lhc-binning-strategies}} \\ [+0.5em]
% ~\cite{bib:2102041} 	


\section{Results}
\label{results}

The activities relative to the original luminosity profile are presented in table \ref{table}. All of the profiles failed to represent accurately the end of the run which resulted in a very significant difference in activity relative to the original profile for short-lived radioisotopes.

The second method was parametrised to give 23 bins and its effects can be seen in figure \ref{second}. It achieves the best precision for half-lives from 50 to 100 days as the method preserves more details in that part of the profile than the other ones. It performs reasonably well for Mn-52, P-32 and V-48 but fails for shorter half-lives. It also struggles with long half-lives as the back of the profile is grouped into a single bin.

The profiles generated using the first method capture with varying success different aspects of the original profile which can be seen in figures \ref{equal}, \ref{exp1.25}, \ref{exp1.5}, \ref{exp1.75} and \ref{exp2}. Different exponents achieve the best precision at different half-lives. The lower exponents manage to represent the technical breaks in the accelerator run, although they don't have enough precision in the end of the run. Higher exponents average over pauses but in turn give a better approximation for the end of the run. All of the profiles generated using the first method perform better than the second one for half-lives longer than 100 days.



\section{Conclusions}
\label{conclusions}

Despite automating the binning, finding a suitable binning strategy still requires considerable human involvement. The activities are strongly dependent on the shape of the luminosity profile. This causes binning strategies of the first method to have a varied performance for different half-lives. The second method, which should be more sensitive to the profile's shape, performs better only for some of the radioisotopes. It requires more tuning and it is difficult to find the right parameters so to achieve a good performance for a wider range of half-lives.

On the other hand, the framework that I developed allows for testing many more strategies. It can take both multiple parameters as well as impose conditions  on various aspects of the profile. It could be that with the right conditions, the right parameters and some human supervision one could achieve better results than I did.


 	
%\section*{Acknowledgments}
%\addcontentsline{toc}{section}{Acknowledgments}

%	 We would like to show our gratitude to XXX for the excellent collaboration.
	 
%\clearpage
\addcontentsline{toc}{section}{References}
\bibliography{Refs}
\bibliographystyle{unsrt}
\clearpage


\begin{landscape}
\begin{table}
\begin{tabular}{l | r | r | r r r r r}
Radioisotope & Half-life & 2nd Method & Equal & Exp. 1.25 & Exp. 1.5 & Exp. 1.75 & Exp. 2 \\
\hline
Ar-41 & 1.827h & 1.398e+110 & 3.157e+113 & 9.601e+108 & 5.471e+109 & 5.559e+109 & 5.607e+109\\
Sc-44    &   3.97h     &       1.029   &    46.29  &     1.002  &     1.006    &   1.005 &      1.003\\
Na-24   &    14.96h    &   6.413e+14 &  5.905e+17 &  2.096e+13 &  3.204e+13 &  5.897e+13 &  3.537e+13\\
Mn-52    &   5.595d  &    32.28   &    68.09    &   32.49   &     30.6   &    31.26  &      34.8\\
P-32   & 14.27d     &       3.925   &    4.226   &    3.883   &    3.778  &     3.789   &     4.22\\
V-48   &  15.97d    &  3.388    &    3.54   &    3.358   &    3.276   &    3.281  &     3.637\\
Be-7    &  53.22d      &      1.347  &     1.397   &     1.43   &    1.445    &   1.378  &      1.44\\
Co-58    &   70.86d         &  1.198    &   1.282 & 1.304 & 1.327 & 1.266 & 1.287\\
Co-56 &  77.31d &  1.161 &  1.255 & 1.274 & 1.298 & 1.241 & 1.25\\
Sc-46 &  83.79d & 1.129 & 1.233 & 1.249 & 1.275 & 1.22 & 1.218\\
S-35 & 87.32d & 1.114 & 1.222 & 1.237 & 1.263 & 1.21 & 1.203\\
Zn-65 & 244.2d & 0.905 & 1.075 & 1.074 & 1.098 & 1.058 & 0.9958\\
Co-57 & 271.8d & 0.8988 & 1.067 & 1.066 & 1.088 & 1.048 & 0.9876\\
Mn-54 & 312.1d & 0.8941 & 1.059 & 1.057 & 1.078 & 1.038 & 0.9795\\
Na-22 & 2.603y & 0.9275 & 1.019 & 1.018 & 1.027 & 1 & 0.9724\\
Fe-55 & 2.735y & 0.9299 & 1.018 & 1.017 & 1.026 & 0.9997 & 0.9731\\
Co-60 & 5.271y & 0.9578 & 1.009 & 1.009 & 1.013 & 0.9975 & 0.9828\\
Ti-44 & 60y & 0.9957 & 1.001 & 1.001 & 1.001 & 0.9995 & 0.9982\\


\end{tabular}
\caption{Activities of the 6 profiles relative to the original profile. The first one was generated with the second method and the last 5 with the first method using equal intervals and exponentially decreasing intervals with exponents 1.25, 1.5, 1.75 and 2.}
\label{table}
\end{table}
\end{landscape}


\begin{figure}
\centering
\includegraphics[scale=0.7]{figures/"2nd method.png"}
\caption{Profile generated with the second method.}
\label{second}
\end{figure}

\begin{figure}
\centering
\includegraphics[scale=0.7]{figures/equal.png}
\caption{Profile generated with the first method with equal size bins.}
\label{equal}
\end{figure}



\begin{figure}
\centering
\includegraphics[scale=0.7]{figures/"exponent 1.25.png"}
\caption{Profile generated with first method with exponentially decreasing bins and\\ exponent 1.25.}
\label{exp1.25}
\end{figure}

\begin{figure}
\centering
\includegraphics[scale=0.7]{figures/"exponent 1.5.png"}
\caption{Profile generated with the first method with exponentially decreasing bins and\\ exponent 1.5.}
\label{exp1.5}
\end{figure}



\begin{figure}
\centering
\includegraphics[scale=0.7]{figures/"exponent 1.75.png"}
\caption{Profile generated with first method with exponentially decreasing bins and\\ exponent 1.75.}
\label{exp1.75}
\end{figure}

\begin{figure}
\centering
\includegraphics[scale=0.7]{figures/"exponent 2.png"}
\caption{Profile generated with the first method with exponentially decreasing bins and\\ exponent 2.}
\label{exp2}
\end{figure}

\end{document}



