% EJC papers *must* begin with the following two lines. 
\documentclass[12pt]{article}
\usepackage{e-jc}
\specs{P1.71}{25(1)}{2018}

% Please remove all other commands that change parameters such as
% margins or pagesizes.

% only use standard LaTeX packages
% only include packages that you actually need

% we recommend these ams packages
\usepackage{amsthm,amsmath,amssymb}

% we recommend the graphicx package for importing figures
\usepackage{graphicx}

% use this command to create hyperlinks (optional and recommended)
\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

% use these commands for typesetting doi and arXiv references in the bibliography
\newcommand{\doi}[1]{\href{http://dx.doi.org/#1}{\texttt{doi:#1}}}
\newcommand{\arxiv}[1]{\href{http://arxiv.org/abs/#1}{\texttt{arXiv:#1}}}

% all overfull boxes must be fixed; 
% i.e. there must be no text protruding into the margins


% declare theorem-like environments
\theoremstyle{plain}
\newtheorem{prop}{Proposition}[section]
\newtheorem{theorem}[prop]{Theorem}
\newtheorem{definition}[prop]{Definition}
\newtheorem{proposition}[prop]{Proposition}
\newtheorem{corollary}[prop]{Corollary}
\newtheorem{result}[prop]{Result}
\newtheorem{lemma}[prop]{Lemma}
\newtheorem{property}[prop]{Property}
\theoremstyle{definition}
\newtheorem{remark}[prop]{Remark}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% if needed include a line break (\\) at an appropriate place in the title

\title{\bf A characterization of  Hermitian \\varieties as codewords}

% input author, affilliation, address and support information as follows;
% the address should include the country, and does not have to include
% the street address 

\author{Angela Aguglia\\
\small Dipartimento di Meccanica, Matematica e Management\\[-0.8ex]
\small Politecnico di Bari\\[-0.8ex] 
\small Bari, Italy\\
\small\tt angela.aguglia@poliba.it\\
\and
Daniele Bartoli \\
\small Dipartimento di Matematica e Informatica\\[-0.8ex]
\small Universit\`a degli Studi di Perugia\\[-0.8ex]
\small Perugia, Italy\\
\small\tt daniele.bartoli@unipg.it
\and
Leo Storme \\
\small Department of Mathematics\\[-0.8ex]
\small Ghent University\\[-0.8ex]
\small Ghent, Belgium\\
\small\tt leo.storme@ugent.be
\and
Zsuzsa  Weiner\\
\small MTA--ELTE Geometric and Algebraic Combinatorics Research Group\\[-0.8ex]
\small and Department of Computer Science\\[-0.8ex]
\small ELTE E\"otv\"os Lor\'and University\\[-0.8ex]
\small Budapest, Hungary\\
\small\tt weiner@cs.elte.hu 
}



\date{\dateline{Jun 17, 2017}{Mar 6, 2018}{Mar 29, 2018}\\
\small Mathematics Subject Classifications: 51E20, 94B05}

\begin{document}

\maketitle


\begin{abstract}
It is known that the Hermitian varieties are codewords in the code defined by the points and hyperplanes of the projective spaces $\mathrm{PG}(r,q^2)$. In finite geometry, also quasi-Hermitian varieties are defined. These are sets of points of $\mathrm{PG}(r,q^2)$ of the same size as a non-singular Hermitian variety of $\mathrm{PG}(r,q^2)$,  having the same intersection sizes with the hyperplanes of $\mathrm{PG}(r,q^2)$.
In the planar case, this reduces to the definition of a unital. A famous result of Blokhuis, Brouwer, and Wilbrink states that every unital in the code of the points and lines of $\mathrm{PG}(2,q^2)$ is a Hermitian curve. We prove a similar result for the quasi-Hermitian varieties in $\mathrm{PG}(3,q^2)$, $q=p^{h}$,  as well as in  $\mathrm{PG}(r,q^2)$, $q=p$ prime, or $q=p^2$, $p$ prime, and $r\geq 4$.

  % keywords are optional
  \bigskip\noindent \textbf{Keywords:} Hermitian variety; incidence vector; codes of projective spaces; quasi-Hermitian variety
\end{abstract}



\section{Introduction}
Consider the non-singular Hermitian varieties ${\mathcal H}(r,q^2)$ in ${\mathcal H}(r,q^2)$. A non-singular Hermitian variety ${\mathcal H}(r,q^2)$ in ${\mathcal H}(r,q^2)$ is the set of absolute points of a Hermitian polarity of ${\mathcal H}(r,q^2)$. Many properties of a non-singular Hermitian variety ${\mathcal H}(r,q^2)$ in ${\mathcal H}(r,q^2)$ are known. In particular, its size is $(q^{r+1}+(-1)^r)(q^{r}-(-1)^r)/(q^2-1)$, and its intersection numbers with the hyperplanes of ${\mathcal H}(r,q^2)$ are equal to $(q^{r}+(-1)^{r-1})(q^{r-1}-(-1)^{r-1})/(q^2-1)$, in case the hyperplane is a non-tangent hyperplane to ${\mathcal H}(r,q^2)$, and equal to $1+q^2(q^{r-1}+(-1)^r)(q^{r-2}-(-1)^r)/(q^2-1)$ in case the hyperplane is a tangent hyperplane to ${\mathcal H}(r,q^2)$; see~\cite{S}.


Quasi-Hermitian varieties ${\mathcal V}$ in ${\mathcal H}(r,q^2)$ are  generalizations of the non-singular Hermitian variety ${\mathcal H}(r,q^2)$ so that ${\mathcal V}$ and ${\mathcal H}(r,q^2)$ have the same size and the same intersection numbers with hyperplanes.

Obviously, a Hermitian variety ${\mathcal H}(r,q^2)$   can be viewed as a trivial quasi--Hermitian variety and we call ${\mathcal H}(r,q^2)$ the \emph{classical
quasi--Hermitian variety of ${\mathcal H}(r,q^2)$}.
In the 2-dimensional case, ${\mathcal H}(r,q^2)$ is also known as the classical example of a {\em unital} of the projective plane ${\mathcal H}(2,q^2)$.


As far as we know, the only known non-classical quasi-Hermitian
varieties of ${\mathcal H}(r,q^2)$ were constructed in \cite{AA,ACK,B,DS,M,FP}.


In \cite{BBW}, it is shown that a unital in ${\mathcal H}(2,q^2)$ is  a Hermitian curve if and only if it is in the $\mathbb{F}_p$-code spanned by the lines of ${\mathcal H}(2,q^2)$, with $q=p^h$, $p$ prime and $h\in \mathbb{N}$.

In this article, we prove the following result.
%in Section \ref{qHv}
\begin{theorem}\label{mainth}
A quasi-Hermitian variety ${\mathcal V}$ of ${\mathcal H}(r,q^2)$, with $r=3$ and $q=p^h \neq 4$, $p$ prime, or $ r\geq 4$, $q=p\geq 5$, or $ r\geq 4$, $q=p^2$, $p \neq 2$ prime, is classical if and only if it is in the $\mathbb{F}_p$-code spanned by the hyperplanes of ${\mathcal H}(r,q^2)$.
\end{theorem}
Furthermore we consider  {\em singular quasi-Hermitian varieties}, that is point sets having the same number of points as a singular Hermitian variety ${\mathcal S}$
  and for which the intersection numbers with respect to hyperplanes are also the intersection numbers of ${\mathcal S}$ with respect to hyperplanes.
%In Section \ref{sqHv}
We  show that Theorem \ref{mainth} also holds in the case in which ${\mathcal V}$ is assumed to be a singular quasi-Hermitian variety of ${\mathcal H}(r,q^2)$.

\section{Preliminaries}
A subset ${\mathcal K}$ of ${\mathcal H}(r,q^2)$ is a $k_{n,r,q^2}$ if $n$ is a fixed integer, with $1\leq n\leq q^2$, such that:
\begin{itemize}
\item [(i)] $|{\mathcal K}|=k$;
\item [(ii)] $|\ell \cap {\mathcal K}|=1$, $n$, or $q^2+1$ for each line $\ell$;
\item [(iii)]  $|\ell \cap {\mathcal K}|=n$ for some line $\ell$.
\end{itemize}

A point $P$ of ${\mathcal K}$ is {\em singular} if every line through $P$ is either a unisecant or a line of ${\mathcal K}$. The set ${\mathcal K}$ is called {\em singular} or {\em non-singular} according as it has singular points or not.

Furthermore, a subset ${\mathcal K}$ of ${\mathcal H}(r,q^2)$ is called {\em regular} if
\begin{itemize}
\item [(a)] ${\mathcal K}$ is a $k_{n,r,q^2}$;
\item [(b)] $3\leq n \leq q^2-1$;
\item [(c)] no planar section of ${\mathcal K}$ is the complement of a set of type $(0, q^2+1-n)$.
\end{itemize}


\begin{theorem}\cite[Theorem 19.5.13]{JH} \label{main1}
Let ${\mathcal K}$ be a $k_{n,3,q^2}$ in ${\mathcal H}(3,q^2)$,  where $q$ is any prime power and $n \neq \frac{1}{2}q^2+1$.  Suppose furthermore that every point in ${\mathcal K}$ lies on at least one $n$-secant. Then  $n=q+1$ and ${\mathcal K}$ is a non-singular Hermitian surface.
\end{theorem}

\begin{theorem} \cite[Theorem 23.5.19]{HT} \label{main2}
If ${\mathcal K}$ is a regular, non-singular $k_{n,r,q^2}$, with $r\geq 4$ and $q>2$, then ${\mathcal K}$ is a non-singular Hermitian variety.
\end{theorem}

\begin{theorem}{ \cite[ Th. 23.5.1]{HT}}\label{th:singularcase1}
If $\mathcal{K}$ is a singular $k_{n,3,q^2}$ in ${\mathcal H}(3,q^2)$,  with $3\leq n\leq q^2-1$, $q>2$, then  the following holds:
$\mathcal{K}$ is $n$ planes through a line or a cone with vertex a point and base $\mathcal{K}^{\prime}$
a plane section  of type
\begin{itemize}
\item[\rm I.] a unital;
\item[\rm II.] a subplane ${\mathcal H}(2,q)$;
\item[\rm III.] a set of type $(0,n-1)$ plus an external line;
\item[\rm IV.] the complement of a set of type $(0,q^2+1-n)$.
\end{itemize}
\end{theorem}



\begin{theorem}{\cite[Lemma 23.5.2 and Th. 25.5.3]{HT}}\label{th:singularcase}
If $\mathcal{K}$ is a singular $k_{n,r,q}$ with $r\geq4$,  then the singular points of $\mathcal{K}$ form a subspace $\Pi_d$ of dimension $d$ and one of the following possibilities holds:
\begin{enumerate}
\item $d=r-1$ and $\mathcal{K}$ is a hyperplane;
\item $d=r-2$ and $\mathcal{K}$ consists of  $n>1$ hyperplanes through $\Pi_d$;
\item $d\leq r-3$ and $\mathcal{K}$ is equal to a cone $\Pi_d \mathcal{K}^{\prime}$, with $\pi_d$ as vertex and with $\mathcal{K}$ as base, where $\mathcal{K}^{\prime}$ is a non singular $k_{n,r-d-1,q}$.
\end{enumerate}
\end{theorem}
A \emph{multiset} in  ${\rm {\mathcal H}}(r,q)$ is a set in which multiple instances of the elements are allowed.
%\textcolor{red}{\begin{result}
%Let ${\cal M}$ be a multiset, in ${\rm {\mathcal H}}(2,q)$, $q=p^h$, $17<q$,
%so that the number of lines intersecting it in not $k\pmod{p}$
%points is $\delta$. Then the following holds
%\[qs - s(s - 1) \leq \delta\]
%where $s$ is the number of non $k\pmod{p}$ secants through any point.
%\end{result}}


\begin{result}{\cite[Remark 2.4 and Lemma 2.5]{SzW}} \label{bmost}
  Let $\cal M$ be a multiset in ${\rm
{\mathcal H}}(2,q)$, $17< q$, $q=p^h$, where $p$ is prime.
Assume that the number of lines intersecting $\cal M$ in not
$k\pmod{p}$ points is $\delta$. Then, the number $s$  of non $k\pmod{p}$ secants through any point of $\cal M$ satisfies $qs - s(s - 1) \leq \delta$.
In particular, if $\delta <  \frac{3}{16} (q+1)^2$, then the number of non $k\pmod{p}$ secants through any point is at most
$\frac{\delta}{q+1} + \frac{2\delta ^2}{(q+1)^3}$ or at least $q + 1-(\frac{\delta}{q+1} + \frac{2\delta ^2}{(q+1)^3})$.
\end{result}



\begin{property} [\cite{SzW}]
\label{most}
Let $\cal M$ be a multiset in ${\rm
{\mathcal H}}(2,q)$, $q=p^h$, where $p$ is prime. Assume that there are $\delta$
lines that intersect $\cal M$ in not $k\pmod{p}$ points.
If through a point there are more than $q / 2$ lines intersecting
 $\cal M$ in not $k\pmod{p}$ points, then there exists a value $r$ such that
 the intersection multiplicity of at least $2\frac{\delta}{ q + 1} + 5$ of these lines with $\cal M$
 is $r$.
 \end{property}

 \medskip




\begin{result} [\cite{SzW}]
\label{general}
Let $\cal M$ be a multiset in ${\rm
{\mathcal H}}(2,q)$, $17< q$, $q=p^h$, where $p$ is prime.
Assume that the number of lines intersecting $\cal M$ in not
$k\pmod{p}$ points is $\delta$, where $\delta <
(\lfloor \sqrt q \rfloor +1)(q+1-\lfloor \sqrt q \rfloor )$.
Assume furthermore that Property \ref{most} holds.
Then there
exists a multiset $\cal{M}'$ with the property that it intersects every
line in $k\pmod{p}$ points and the number of different points in
 $({\cal M}\cup {\cal M}')\setminus ({\cal M}\cap {\cal M}')$ is
exactly $\lceil \frac{\delta}{q+1}\rceil$.
\end{result}

\medskip
\begin{result}[\cite{SzW}]
\label{codewords}
Let $B$ be a proper point set in ${\rm {\mathcal H}}(2, q)$, $17< q$. Suppose that $B$ is a codeword of the lines of ${\rm {\mathcal H}}(2, q)$. Assume also that $|B| < (\lfloor \sqrt q \rfloor +1)(q+1-\lfloor \sqrt q \rfloor )$.
Then $B$ is a linear combination of at most $\lceil \frac{|B| }{ q+1} \rceil$ lines. \qed
\end{result}



\section{Proof of Theorem \ref{mainth}}\label{qHv}
Let $V$ be the vector space of dimension $q^{2r}+q^{2(r-1)}+\cdots+q^2+1$ over the prime field $\mathbb{F}_p$,  where the coordinate positions for the vectors in $V$ correspond to the points of ${\mathcal H}(r,q^2)$ in some fixed order.
 If $S$ is a subset of points in ${\mathcal H}(r,q^2)$, then let $v^{S}$ denote the vector in $V$ with coordinate 1 in the positions corresponding to the points in $S$ and with coordinate $0$ in all other positions; that is $v^S$ is the {\em characteristic vector} of $S$.
Let $\mathcal C_p$ denote the subspace of $V$ spanned by the characteristic vectors of all the hyperplanes in ${\mathcal H}(r,q^2)$. This code $C_p$ is called   {\em the linear code of ${\mathcal H}(r,q^2)$}.


From
   \cite[Theorem 1]{JK}, we know that the  characteristic vector $v^{{\mathcal V}}$ of a Hermitian variety ${\mathcal V} \in {\mathcal H}(r,q^2)$ is in $ \mathcal C_p$.
So from now on, we will assume that  ${\mathcal V}$ is a quasi-Hermitian variety in ${\mathcal H}(r,q^2)$ and
$v^{{\mathcal V}} \in {\mathcal C}_p$. In the remainder of this section, we will show that ${\mathcal V}$ is a classical Hermitian variety for specific values of $q$.

\bigskip
The next lemmas hold for $r\geq 3$ and for  any $q = p^h$, $p$ prime, $h\geq 1$.

\begin{lemma}\label{Lemma:rette}
Every line of ${\mathcal H}(r,q^2)$, $q = p^h$, $p$ prime, $h\geq 1$,  meets ${\mathcal V}$ in $1 \pmod{p}$ points.
\end{lemma}

\begin{proof}
We may express \[v^{{\mathcal V}}=v^{H_1}+\cdots+v^{H_t},\] where $H_1,\ldots, H_t$ are (not necessarily distinct) hyperplanes of ${\mathcal H}(r,q^2)$.
Denote by  $\cdot$ the usual dot product. We get $v^{{\mathcal V}}\cdot v^{{\mathcal V}}=|{\mathcal V}|\equiv 1$ (mod $p$).
On the other hand,
\[v^{{\mathcal V}}\cdot v^{{\mathcal V}}=v^{{\mathcal V}}\cdot (v^{H_1}+\cdots+v^{H_t})\equiv t  \pmod{p},\]
since every hyperplane of ${\mathcal H}(r,q^2)$ meets ${\mathcal V}$ in $1\pmod{p}$ points.
Hence, we have $t\equiv 1$ (mod $p$).
Finally, for a line $\ell$ of ${\mathcal H}(r,q^2)$,
\[v^{\ell} \cdot v^{{\mathcal V}}= v^{\ell}\cdot (v^{H_1}+\cdots+v^{H_t}) \equiv t  \pmod{p},\]
as every line of ${\mathcal H}(r,q^2)$ meets a hyperplane in $1$ or $q^2+1$ points.
That is, $|\ell \cap {\mathcal V}|\equiv 1$ (mod $p$) and in particular no lines of ${\mathcal H}(r,q^2)$ are external to ${\mathcal V}$.
\end{proof}

\begin{remark}
The preceding proof also shows that ${\mathcal V}$ is a linear combination of $1\pmod{p}$ (not necessarily distinct) hyperplanes, all having coefficient one.
\end{remark}

\begin{lemma}\label{CDS}
For every hyperplane $H$ of ${\mathcal H}(r,q^2)$, $q = p^h$, $p$ prime, $h\geq 1$, the intersection $H \cap {\mathcal V}$ is in the code of points and hyperplanes of $H$ itself.
\end{lemma}
\begin{proof}
Let $\Sigma$ denote the set of all hyperplanes of ${\mathcal H}(r,q^2)$.
By assumption, \begin{equation}\label{car}
v^{{\mathcal V}}=\sum_{H_i \in \Sigma} \lambda_i v^{H_i}.
\end{equation}
For every $H\in \Sigma$, let
$\pi$ denote a hyperplane of $H$; then $\pi=H_{j_1} \cap \cdots \cap H_{j_{q^2+1}}$, where $H_{j_1},\ldots,H_{j_{q^2+1}}$  are the hyperplanes of ${\mathcal H}(r,q^2)$ through $\pi$.  We assume $H=H_{j_{q^2+1}}$.
For every hyperplane $\pi$ of $H$, we set \[\lambda_{\pi}= \sum_{k=1, \ldots, q^2+1} \lambda_{j_k},\] where  $\lambda_{j_k}$ is the coefficient in \eqref{car} of $v^{H_{j_k}}$ and $H_{j_k}$  is one of the $q^2+1$ hyperplanes through $\pi$.


Now, consider \begin{equation}\label{eq6} T=\sum_{\pi\in \Sigma' } \lambda_{\pi}v^{\pi},
\end{equation} where $\Sigma'$ is the set of all hyperplanes in $H$.
We are going to show that \[T=v^{{\mathcal V}\cap H}.\]

In fact, it is clear that at the positions belonging to the points outside of $H$ we see zeros. At a position belonging to a point in $H$, we see
the original coefficients of $v^{{\mathcal V}}$ plus $(|\Sigma'|-1) \lambda_{j_{q^2+1}}$. Note that this last term is $0\pmod{p}$, hence
$T=v^{{\mathcal V}\cap H}$.
\end{proof}
%In fact, in \eqref{eq6} at  the positions of the points of $H$, we see the following:
%\[ \sum_{i=1, \ldots, |\Sigma| } \lambda_i,+(|\Sigma|-1)\lambda_{j_{q^2+1}};\]
%thus in these positions, we see the original coefficients of $v^{{\mathcal V}}$ that is, $1$ if the point belongs to ${\mathcal V}\cap H$ and $0$ otherwise. Therefore,
%${\mathcal V}\cap H$ is in the code of points and hyperplanes of $H$.




\begin{corollary}
\label{subgeocodes}
For every subspace $S$ of ${\mathcal H}(r,q^2)$, $q = p^h$, $p$ prime, $h\geq 1$, the intersection $S \cap {\mathcal V}$ is in the code of points and hyperplanes of $S$ itself. \qed
\end{corollary}

\begin{remark}
\label{1modpremark}
Lemma \ref{CDS}  and Corollary \ref{subgeocodes} are valid for  ${\mathcal V}$  any  set of  points in ${\mathcal H}(r,q^2)$ whose incidence vector belongs to  the code of points and hyperplanes of ${\mathcal H}(r,q^2)$.
In particular, it follows that for every plane $\pi$ the intersection $\pi \cap {\mathcal V}$ is a codeword of the points and lines of $\pi$,  $\pi \cap {\mathcal V}$ has size $1\pmod{p}$ and so it is a linear combination
of $ 1\pmod{p}$ not necessarily distinct lines.
\end{remark}
\begin{lemma} \label{lemma1}
Let $\ell$ be a line of ${\mathcal H}(r,q^2)$. Then there exists at least one plane through $\ell$ meeting ${\mathcal V}$ in  $\delta$ points, with $\delta \leq q^3 + q^2 +q +1$.
\end{lemma}
\begin{proof}
By way of contradiction, assume that all planes through $\ell$ meet ${\mathcal V}$ in more than  $q^3 + q^2+q+1$ points. Set $x=|\ell \cap {\mathcal V}|$.
We get
\begin{equation}\label{eq7}
\frac{(q^{r+1}+(-1)^{r})(q^{r}-(-1)^{r})}{q^2-1}> m (q^3+q^2+q+1-x)+x,
\end{equation}
where $m=q^{2(r-2)}+q^{2(r-3)}+ \cdots +q^2+1$ is the number of planes in ${\mathcal H}(r,q^2)$ through $\ell$.
From \eqref{eq7}, we obtain $x>q^2+1$, a contradiction.
\end{proof}

\begin{lemma}
\label{maxindex}
 For each line $\ell$ of ${\mathcal H}(r,q^2)$, $q>4$ and $q = p^h$, $p$ odd prime, $h\geq 1$,  either  $|\ell \cap {\mathcal V}| \leq q+1$ or  $|\ell \cap {\mathcal V}| \geq q^2-q+1$.
\end{lemma}
\begin{proof}
 Let $\ell$ be a line of ${\mathcal H}(r,q^2)$ and let
 $\pi$ be a plane through $\ell$ such that $|\pi \cap {\mathcal V}|\leq q^3+q^2+q+1$; Lemma \ref{lemma1} shows that such a plane exists. Set $B=\pi \cap {\mathcal V}$.
By Corollary \ref{subgeocodes}, $B$ is a codeword of the code of the lines of $\pi$, so we can write it as a linear combination of some lines of  $\pi$, that is
$\sum_i \lambda_iv^{e_i}$, where $v^{e_i}$ are the characteristic vectors of the lines $e_i$ in  $\pi$.

Let  $B^*$ be the multiset  consisting of the lines $e_i$, with multiplicity $\lambda_i$, in the dual plane of $\pi$.
The weight of the codeword $B$ is  at most $q^3 + q^2 +q+1 $, hence in the dual plane this is the number of  lines intersecting $B^*$ in not $0\pmod{p}$ points.
Actually, as $B$ is a proper set, we know that each non $0\pmod{p}$ secant of $B^*$ must be a $1\pmod{p}$ secant.
Using Result \ref{bmost}, with $\delta=q^3 + q^2 +q+1$, in ${\mathcal H}(2,q^2)$,
the number  of non $0\pmod{p}$ secants through any point is at most
$$\frac{\delta}{q^2+1}+2\frac{\delta^2}{(q^2+1)^3}=q+1+2\frac{(q+1)^2}{q^2+1}<q+4$$
or at least
$$q^2+1-\left(\frac{\delta}{q^2+1}+2\frac{\delta^2}{(q^2+1)^3}\right)>q^2-q-3.$$
In the original plane $\pi$, this means that each line intersects $B$ in either at most $q+3$ or in at least $q^2-q-2$ points. Since such lines must be $1\pmod{p}$ secants and $p>2$, then each line intersects $B$ in either at most $q+1$ or in at least $q^2-q+1$ points.
\end{proof}


\begin{proposition}
\label{charplanes1}
Assume that $\pi$ is a plane of ${\mathcal H}(r,q^2)$, $q>4$, and $q = p^h$, $p$ odd prime, $h\geq 1$, such that  $|\pi \cap {\mathcal V}|\leq q^3+2q^2$. Furthermore, suppose also
that there exists a line $\ell$ meeting $\pi \cap {\mathcal V}$ in at least $q^2-q+1$ points, when $q^3 +1 \leq |\pi \cap {\mathcal V}|$.
Then $\pi \cap {\mathcal V}$ is a linear combination of  at most $q+1$  lines, each with weight $1$.
\end{proposition}




\begin{proof}
Let $B$ be the point set $\pi \cap {\mathcal V}$.  By Corollary \ref{subgeocodes}, $B$ is the corresponding point set of a codeword $c$ of lines of $\pi$, that is  $c = \sum_i \lambda_iv^{e_i}$, where  lines of $\pi$ are denoted by $e_i$.
Let $C^*$ be the multiset in the dual plane containing the dual of each line $e_i$ with multiplicity $\lambda_i$. Clearly the number of lines intersecting $C^*$ in not $0\pmod{p}$ points
is $w(c )=|B|$. Note also, that every line that is not a $0\pmod{p}$ secant is a $1\pmod{p}$ secant, as $B$ is a proper point set.

Our very first aim is to show that $c$ is a linear combination of at most $q+3$ different lines.
When $|B| < q^3+1$, then, by Result \ref{codewords}, it is a linear combination of at most $q$ different lines.
%Assume first that $|B| < q^3+1$.
%The dual of Result \ref{general} yields that there are exactly
 %$\lceil {|B|\over q^2+1}\rceil$ lines $m_j$ with some multiplicity $\mu_j$, such that
 %if we add the lines $m_j$ with multiplicity $\mu_j$ to $B$ then through any point of   PG$(2, q^2)$,
% we see $0\pmod{p}$ lines (counted with multiplicity).

 %In other words, we get that
%$c + \sum_{j = 1}^{\lceil {|B|\over q^2+1}\rceil }\mu_j m_j  =  \sum_i \lambda_i e_i + \sum_{j = 1}^{\lceil {w(c)\over q^2+1}\rceil }\mu_j m_j $ is the \underline 0 codeword.%
%Hence, $c = \sum_{j = 1}^{\lceil {|B|\over q^2+1}\rceil }(p-\mu_j) m_j $. That is, $c$ is a linear combination of at most $q$ different lines.

Next assume that $|B| \geq q^3+1$. From the assumption of the proposition, we know that  there exists a line $\ell$ meeting $\pi \cap {\mathcal V}$ in at least $q^2-q+1$ points and from Lemma \ref{maxindex}, we also know that  each line intersects $B$ in either at most $q+1$ or in at least $q^2-q+1$ points.
Hence, if we add the line $\ell$ to $c$ with multiplicity $-1$, we reduce the weight by at least $q^2-q+1-q$ and by at most  $q^2+1$.
%Hence $q^3-q^2\leq w(c) - (q^2+1) \leq w(c+v^l) \leq w(c) - q^2+q+p$.
If $w(c-v^\ell) < q^3+1$, then from the above we know that $c -v^\ell$ is a linear combination of  $\lceil \frac{w(c-v^\ell)}{ q^2+1}\rceil$ lines. Hence, $c$ is a linear combination of at most $q+1$ lines. If $w(c-v^\ell) \geq q^3+1$, then $w(c) \geq q^3+q^2-2q-2$ (see above) and so it follows that through any point of $B$, there passes at least one line intersecting $B$ in at least  $q^2-q+1$ points. This means that we easily find three lines $\ell_1$, $\ell_2$, and $\ell_3$ intersecting $B$ in at least  $q^2-q+1$ points. Since $w(c) \leq q^3+2q^2$, we get that $w(c - v^{\ell_1}- v^{\ell_2} - v^{\ell_3}) \leq q^3+2q^2 -3 \cdot( q^2-2q -2) < q^3+1$. Hence, similarly as before, we get that $c$ is a linear combination of at most $q+3$ lines.

Next we show that each line in the linear combination (that constructs $c$) has weight $1$. Take a line $\ell$ which is in the linear combination with coefficient $\lambda \not = 0$. Then there are at least $q^2+1-(q+2)$ positions, such that the corresponding point is in $\ell$ and the value at that position is $\lambda$. As $B$ is a proper set, this yields that $\lambda = 1$. By Remark \ref{1modpremark}, the number of lines with non-zero multiplicity in the linear combination of $c$ must be $1\pmod{p}$; hence it can be at most $q+1$.
\end{proof}

\begin{proposition}
\label{charplanes2}
Assume that $\pi$ is a plane of ${\mathcal H}(r,q^2)$, $q>4$, and  $q = p^h$, $p$ odd prime, $h\geq 1$, such that  $|\pi \cap {\mathcal V}|\leq q^3+2q^2$. Furthermore, suppose that
every line meets $ \pi\cap {\mathcal V}$ in at most $q+1$ points.
Then $\pi \cap {\mathcal V}$ is a classical unital.
\end{proposition}

\begin{proof}
Again let $B = \pi \cap {\mathcal V}$ and first  assume that $|B| < q^3+1$. Proposition \ref{charplanes1} shows that $B$ is a linear combination of at most $q+1$ lines, each with weight $1$. But this yields that these lines intersect $B$ in at least $q^2+1-q$ points. So this case cannot occur.

Hence, $q^3+1\leq |B|\leq q^3+2q^2$.
We are going to prove that  there exists at least a tangent line to $B$ in $\pi$. Let $t_i$ be the number of lines meeting $B$ in $i$ points. Set $x=|B|$.  Then  double counting arguments give the following equations for  the integers $t_i$.

\begin{equation} \label{tg1}
\left\{\begin{array}{l}
    \sum_{i=1}^{q+1}t_i=q^4+q^2+1 \\
    \\
          \sum_{i=1}^{q+1}it_i=x(q^2+1)\\
     \\
     \sum_{i=1}^{q+1}i(i-1)t_i=x(x-1).
   \end{array}  \right.
  \end{equation}
Consider  $f(x)=\sum_{i=1}^{q+1}(i-2)(q+1-i)t_i$. From \eqref{tg1}, we get
\[f(x)=-x^2+x[(q^2+1)(q+2)+1]-2(q+1)(q^4+q^2+1).\]
Since $f(q^3/2)>0$, whereas $f(q^3+1)<0$ and $f(q^3+2q^2)<0$, it follows that
if $q^3+1\leq x\leq q^3+2q^2$, then $f(x)<0$ and thus  $t_1$ must be different from zero.
Consider now the quantity $\sum_{i=1}^{q+1}(i-1)(q+1-i)t_i$. We have that
$$\sum_{i=1}^{q+1}(i-1)(q+1-i)t_i=f(x)+\sum_{i=1}^{q+1}(q+1-i)t_i=f(x)+(q+1)\sum_{i=1}^{q+1}t_i-\sum_{i=1}^{q+1}it_i$$
$$=f(x)+(q+1)(q^4+q^2+1)-x(q^2+1)=-x^2+x[(q^2+1)(q+1)+1]-(q+1)(q^4+q^2+1).$$
Since $\sum_{i=1}^{q+1}(i-1)(q+1-i)t_i\geq 0$, we have that $x\leq\frac{(q^2+1)(q+1)+1+(q^3-q^2-q)}{2}=q^3+1$.
Therefore, $x=q^3+1$ and $\sum_{i=1}^{q+1}(i-1)(q+1-i)t_i=0$.

Since $(i-1)(q+1-i)> 0$, for $2\leq i\leq q$, we obtain $t_2=t_3=\cdots=t_q=0$, that is, $B$ is a set of $q^3+1$ points such that each line is a 1-secant or a $(q+1)$-secant of $B$.  Namely, $B$ is a unital and precisely a classical unital  since $B$ is a codeword of $\pi$ \cite{BBW}.
\end{proof}

The above two propositions and Lemma \ref{maxindex} imply the following corollary.

\begin{corollary}
\label{charunital}
Assume that $\pi$ is a plane of ${\mathcal H}(r,q^2), q>4$ and  $q = p^h$, $p$ odd prime, $h\geq 1$, such that  $|\pi \cap {\mathcal V}|\leq q^3+2q^2$.
Then $\pi \cap {\mathcal V}$ is a linear combination of  at most $q+1$  lines, each with weight $1$, or it is a classical unital. \qed
\end{corollary}


\begin{corollary}
\label{charunitalbis}
Suppose that $\pi$ is a plane of ${\mathcal H}(r,q^2), q>4$ and  $q = p^h$, $p$ odd prime, $h\geq 1$, containing exactly $q^3+1$ points of ${\mathcal V}$.
Then $\pi \cap {\mathcal V}$ is a classical unital.
\end{corollary}

\begin{proof}
Let $B$ be the point set $\pi \cap {\mathcal V}$. We know that $B$ is the support of a codeword of lines of $\pi$.
By Proposition \ref{charplanes1}, if there is a line intersecting $B$ in at least  $q^2-q+1$ points, then $B$ is
a linear combination of at most $q+1$ lines, each with multiplicity $1$.
First of all note that a codeword that is a linear combination of $q+1$ lines has weight at least
$(q^2+1)(q+1) - 2\binom{q+1}{2}$, that is exactly $q^3+1$. In fact, in a linear combination of $q+1$ lines the minimum number of points is obtained  if there is a hole at the intersection of any two lines. There are $\binom{q+1}{2}$ intersections and each intersection is counted twice, therefore we have to subtract $2  \binom{q+1}{2}$. To achieve this, we need that the intersection points of any two lines from such a linear combination are all different and the sum of the coefficients of any two lines is zero; which is clearly not the case (as all the coefficients are $1$).
From Remark \ref{1modpremark}, in this case $B$ would be a linear combination of at most $q+1-p$ lines and so its weight would be less than $q^3+1$, a contradiction.
%Hence, $B$, as a codeword,  is a linear combination of at most $q$ lines.
%Note that at most $q$ lines can cover at most $q^3+1$ points and to achieve  this we need exactly $q$ concurrent lines. But, from
%Proposition \ref{charplanes1}, we also know that these lines have weight $1$, which implies that the common point of the lines has weight $0$, so the overall weight  is $q^3$ only.
Hence, there is no line intersecting $B$ in at least  $q^2-q+1$ points, so Proposition \ref{charplanes2} finishes the proof.
\end{proof}



\subsection{Case \texorpdfstring{$r=3$}{Lg}}
 In ${\mathcal H}(3,q^2)$, each plane intersects ${\mathcal V}$ in either $q^3+1$  or $q^3+q^2+1$ points since these are the intersection numbers of a quasi-Hermitian variety with a plane of ${\mathcal H}(3,q^2)$.

\subsubsection{\texorpdfstring{$q=p$}{Lg}}
Let ${\mathcal V}$ be a quasi-Hermitian variety of ${\mathcal H}(3,p^2)$, $p$ prime.
\begin{lemma} \label{lem1bis}
Every plane $\pi$ of ${\mathcal H}(3,p^2)$ sharing $p^3+1$ points with ${\mathcal V}$ intersects ${\mathcal V}$ in a unital of $\pi$.
\end{lemma}
\begin{proof} Set $U=\pi \cap {\mathcal V}$.
Let $P$ be a point in $U$. Assume that  every line $\ell$ in $\pi$ through the point $P$ meets  $U$ in at least $p+1$ points. We get
$|\pi \cap {\mathcal V}|=p^3+1\geq (p^2+1)p+1=p^3+p+1$, which is impossible.

Thus, $P$ lies on at least one tangent line to $U$ and this implies that $U$ is a minimal blocking set in $\pi$ of size $p^3+1$. From a result obtained by Bruen and Thas, see \cite{BT},  it follows that $U$ is a unital of $\pi$ and hence every line in $\pi$ meets $U$ in either $1$ or $p+1$ points.
\end{proof}
\begin{lemma}\label{lem2bis}
Let $\pi$ be a plane in ${\mathcal H}(3,p^2)$ such that $|\pi \cap {\mathcal V}|=p^3+p^2+1$, then every line in $\pi$ meets $\pi \cap {\mathcal V}$ in either $1$ or $p+1$ or $p^2+1$ points.
\end{lemma}
\begin{proof}
Set $C=\pi \cap {\mathcal V}$ and
Let $m$ be  a line in $\pi$ such that $|m \cap C|=s$ with $s\neq 1$ and $s\neq p+1$. Thus, from Lemma \ref{lem1bis}, every plane through $m$ has to meet ${\mathcal V}$ in $p^3+p^2+1$ points and thus
\[|{\mathcal V}|=(p^2+1)(p^3+p^2+1-s)+s,\]
which gives $s=p^2+1$.
\end{proof}

From Lemmas \ref{lem1bis} and \ref{lem2bis}, it follows that every line in ${\mathcal H}(3,p^2)$ meets ${\mathcal V}$ in either $1$ or, $p+1$ or, $p^2+1$ points.


%\begin{lemma} \label{lem11}
%Every plane $\pi$ of PG$(3,p^2)$, $p\in \{3,5\}$ sharing $p^3+1$ points with ${\mathcal V}$ intersects ${\mathcal V}$ in a unital of $\pi$.
%\end{lemma}
%\begin{proof} Set $U=\pi \cap {\mathcal V}$.
%Let $P$ be a point in $U$. Assume that  every line $\ell$ in $\pi$ through the point $P$ meets  $U$ is at least $p+1$ points. We get
%$|\pi \cap {\mathcal V}|=p^3+1\geq (p^2+1)p+1=p^3+p+1$, which is impossible.
%Thus, $P$ lies on at least one tangent line to $U$ and this implies the $U$ is a minimal blocking set in $\pi$ of size $p^3+1$. From a result due %to Bruen and Thas, see \cite{BT},  it follows that $U$ is a unital of $\pi$ and hence every line in $\pi$ meets $U$ in either $1$ or $p+1$ points.
%\end{proof}



\subsubsection{\texorpdfstring{$q=p^h$}{Lg},  \texorpdfstring{$q\geq 5$}{Lg} odd}

Let ${\mathcal V}$ be a quasi-Hermitian variety of ${\mathcal H}(3,q^2)$, $q\geq 5$ odd.

\begin{lemma}\label{lem2}
Let $\pi$ be a plane in ${\mathcal H}(3,q^2)$ such that $|\pi \cap {\mathcal V}|=q^3+q^2+1$, then every line in $\pi$ meets $\pi \cap {\mathcal V}$ in either $1$, $q+1$ or $q^2+1$ points.
\end{lemma}
\begin{proof}
Set $C=\pi \cap {\mathcal V}$ and
let $m$ be  a line in $\pi$ such that $|m \cap C|=s$, with $s\neq 1$ and $s\neq q+1$. Thus, from Corollary \ref{charunitalbis},  every plane  through $m$ has to meet ${\mathcal V}$ in $q^3+q^2+1$ points and thus
\[|{\mathcal V}|=(q^2+1)(q^3+q^2+1-s)+s,\]
which gives $s=q^2+1$.
\end{proof}
 From Corollary \ref{charunitalbis}  and Lemma \ref{lem2},  it follows that every line in ${\mathcal H}(3,q^2)$ meets ${\mathcal V}$ in either $1$, $q+1$, or $q^2+1$ points.




\subsubsection{\texorpdfstring{$q=2^{h}$}{Lg}, \texorpdfstring{$h>2$}{Lg}}
Let ${\mathcal V}$ be a quasi-Hermitian variety of ${\mathcal H}(3,2^{2h})$, $h > 2$.

\begin{lemma}\label{3.7bis}
For each line $\ell$ of ${\mathcal H}(3,2^{2h})$, $h>2$,  either  $|\ell \cap {\mathcal V}| \leq q+1$ or  $|\ell \cap {\mathcal V}| \geq q^2-q-1$.
\end{lemma}
\begin{proof}
Let $\ell$ be a line of ${\mathcal H}(3,2^{2h})$. Since $\ell$ is at least a tangent to ${\mathcal V}$, there exists  a plane through $\ell$ meeting ${\mathcal V}$ in $q^3+q^2+1$ points.
Let $\pi$ be a plane through $\ell$ such that $|\pi \cap {\mathcal V}|=q^3+q^2+1$.  Set $B=\pi \cap {\mathcal V}$.
As before, by Corollary \ref{subgeocodes}, $B$ is a codeword of the code of the lines of $\pi$, so we can write it as a linear combination of some lines of  $\pi$, that is
$\sum_i \lambda_iv^{e_i}$, where $v^{e_i}$ are the characteristic vectors of the lines $e_i$ in  $\pi$.

Let  $B^*$ be the multiset  consisting of the lines $e_i$, with multiplicity $\lambda_i$, in the dual plane of $\pi$.
The weight of the codeword $B$ is $q^3 + q^2+1 $, hence in the dual plane this is the number of  lines intersecting $B^*$ in not $0\pmod{p}$ points.
Actually, as $B$ is a proper set, we know that each non $0\pmod{p}$ secant of $B^*$ must be a $1\pmod{p}$ secant.
Using Result \ref{bmost}, with $\delta=q^3 + q^2 +1$ in ${\mathcal H}(2,2^{2h})$,
the number $s$ of non $0\pmod{p}$ secants through any point of $B$ satisfies  the inequality
 $s^2-(q^2+1)s-(q^3+q^2+1)\geq 0$. Since  the determinant, $(q^2+1)^2+4(q^3+q^2+1)>((q^2+1)-2(q+3))^2$, we get $s<q+3$ or $s>q^2-q-2$


In the original plane $\pi$, this means that each line intersects $B$ in either at most $q+2$ or in at least $q^2-q-1$ points. Since such lines must be $1\pmod{p}$ secants and $p=2$, then each line intersects $B$ in either at most $q+1$ or in at least $q^2-q-1$ points.
\end{proof}

 Let  $\alpha$ be a plane  meeting ${\mathcal V}$ in a point set $B'$ of size $q^3+q^2+1$ points. We want to prove that $\alpha$ contains some $s$-secant, with $s$ at least $q^2-q-1$. Assume on the contrary that each line in $\alpha$ meets ${\mathcal V}$ in at most $q+1$ points.
Let $P$ be a point of $B'$ and consider the $q^2+1$ lines through $P$. We get
$q^3+q^2+1\leq (q^2+1)q+1$, a contradiction.
Therefore, there exists a line $\ell$ in $\alpha$ meeting $B'$ in at least $q^2-q-1$ points. We are going to show that  $B'$ is a linear combination of exactly $q+1$ lines each with weight 1.

Again, by Corollary \ref{subgeocodes}, $B'$ is the corresponding point set of a codeword $c'$ of lines of $\pi$, that is  $c' = \sum_i \lambda_iv^{e_i}$, where  lines of $\pi$ are denoted by $e_i$.
Let $C'^*$ be the multiset in the dual plane containing the dual of each line $e_i$ with multiplicity $\lambda_i$.
 As before, the number of lines intersecting $C'^*$ in not $0\pmod{p}$ points
is $w(c' )=|B'|=q^3+q^2+1$ and  every line that is not a $0\pmod{p}$ secant is a $1\pmod{p}$ secant, as $B'$ is a proper point set.


Hence, if we add the line $\ell$ to $c$ with multiplicity $1$, we reduce the weight by at least $q^2-q-1-q-2=q^2-2q-3$ and at most by $q^2+1$. Now, through any point of $B'$, there passes at least one line intersecting $B'$ in at least  $q^2-q-1$ points. Thus, we easily find two lines $\ell_1$ and $\ell_2$ intersecting $B$ in at least  $q^2-q-1$ points. We get that $w(c' - v^{\ell_1}- v^{\ell_2} ) < q^3+1$. Hence, similarly as before, we get that  $c' -v^{\ell_1}-v^{\ell_2}$ is a linear combination of  $\lceil \frac{w(c'-v^{\ell_1}-v^{\ell_2})}{ q^2+1}\rceil$ lines. Hence, $c'$ is a linear combination of at most $q+2$ lines.
  By Remark \ref{1modpremark}, the number of lines with non-zero multiplicity in the linear combination of $c'$ must be $1$  $\pmod{p}$; hence, as $p=2$ it can be at most $q+1$.
 For $p=2$,  a codeword that is a linear combination of  at most $q+1$ lines each with weight 1, has  weight at most $q^3+q^2+1$ and this is achieved when the $q+1$ lines are concurrent.
This implies that each line in $\alpha$ is either a $1$ or $q+1$ or $q^2+1$-secant to ${\mathcal V}$.
Now consider a line $m'$ that  is an $s$-secant to ${\mathcal V}$ with $s$ different from $1,q+1$, and also different from $q^2+1$. Each plane through $m'$ has to meet ${\mathcal V}$ in $q^3+1$ points.
From $|V|=q^5+q^3+q^2+1=(q^2+1)(q^3+1-s)+s$ we get $s=0$, a contradiction.


Thus each line of ${\mathcal H}(3,2^{2h})$ meets ${\mathcal V}$  in either $1$ or $q+1$ or $q^2+1$ points.







\vspace*{0.5 cm}

\noindent {\bf Proof of Theorem \ref{mainth} (case $r = 3$): }
From all previous lemmas of this section, it follows that every line in ${\mathcal H}(3,q^2)$, with  $q=p^h \neq 4$ and $p$
 any prime,  meets ${\mathcal V}$ in either $1$, $q+1$, or $q^2+1$ points.
Now, suppose on the contrary that  there exists a singular point $P$ on ${\mathcal V}$; this means that all lines through $P$ are either tangents or $(q^2+1)$-secants to ${\mathcal V}$. Take a plane $\pi$ which does not contain $P$. Then $|{\mathcal V}|=q^2|\pi \cap {\mathcal V}|+1$ and since the two possible  sizes of the planar sections are $q^3+1$  or $q^3+q^2+1$, we get a contradiction.
Thus, every point in ${\mathcal V}$ lies on at least one $(q+1)$-secant and,  from Theorem \ref{main1}, we obtain that  ${\mathcal V}$ is a Hermitian surface. \qed

\subsection{Case \texorpdfstring{$r\geq4$}{Lg} and \texorpdfstring{$q=p\geq 5$}{Lg}}

We first  prove the following result.
\begin{lemma}
If $\pi$ is a plane of ${\mathcal H}(r,p^2)$, which is not contained in ${\mathcal V}$, then either
\[|\pi \cap {\mathcal V}|= p^2+1 \mbox{ or } \ |\pi \cap {\mathcal V}| \geq p^3+1.\]

\end{lemma}
\begin{proof}
Let  $\pi$ be a plane of ${\mathcal H}(r,p^2)$ and set $B= \pi \cap {\mathcal V}$. By Remark \ref{1modpremark}, $B$ is a linear combination of $1\pmod{p}$ not necessarily distinct lines.

If $|B|< p^3+1$, then by Result \ref{codewords}, $B$ is a linear combination of at most $p$ distinct lines. This and the previous observation yield that when
$|B|< p^3+1$, then it is the scalar multiple of one line; hence $|B|=p^2+1$.
\end{proof}


\begin{proposition}
\label{concurrent}
Let $\pi$ be a plane of ${\mathcal H}(r,p^2)$, such that   $ |\pi \cap {\mathcal V}| \leq p^3+p^2+p+1$.
Then $B=\pi \cap {\mathcal V}$ is either a classical unital or a linear combination of $p+1$ concurrent lines or just one line, each with weight $1$.
\end{proposition}
\begin{proof}
 From Corollary \ref{charunital},  we have   that
$B$ is either a linear combination of at most $p+1$ lines or a classical unital.
In the first case, since $B$ intersects every line in $1\pmod{p}$ points and $B$ is a proper point set, the only possibilities are that $B$ is a linear combination of $p+1$ concurrent lines or just one line, each with weight $1$.
\end{proof}




\noindent {\bf Proof of Theorem \ref{mainth} (case $r\geq 4$, $q = p$): }
Consider a line $\ell$ of ${\mathcal H}(r,p^2)$ which is not contained in ${\mathcal V}$.
By Lemma \ref{lemma1}, there is a plane $\pi$ through $\ell$ such that $|\pi \cap {\mathcal V}|\leq q^3+q^2+q+1$.   From Proposition \ref{concurrent}, we have that $\ell$ is either a unisecant or a $(p+1)$-secant of ${\mathcal V}$ and we also have that ${\mathcal V}$ has  no plane section of  size $(p+1)(p^2+1)$.   Finally, it is  easy to see  like in the  previous case $r=3$, that ${\mathcal V}$ has no singular points, thus ${\mathcal V}$ turns out to be a Hermitian variety of ${\mathcal H}(r,p^2)$ (Theorem \ref{main2}).



\subsection{Case \texorpdfstring{$r\geq 4$}{Lg} and \texorpdfstring{$q=p^2$}{Lg}, \texorpdfstring{$p$}{Lg} odd}\label{alsin0}
Assume now that  ${\mathcal V}$ is a quasi-Hermitian variety of ${\mathcal H}(r,p^4)$, with $r\geq 4$.

Lemma \ref{maxindex} states that every line contains at most $p^2+1$ points of ${\mathcal V}$ or at least $p^4-p^2+1$ points of ${\mathcal V}$.
\begin{lemma}
\label{lem31} If $\ell$ is a line of ${\mathcal H}(r,p^4)$, such that $|\ell \cap {\mathcal V}|\geq p^4-p^2+1$, then $|\ell \cap {\mathcal V}|\geq p^4-p+1$.
\end{lemma}
\begin{proof}
Set $|\ell \cap {\mathcal V}|= p^4-x+1$, where $x\leq p^2$.  It suffices to prove that $x<p+2$. Let $\pi$ be a plane through $\ell$ and $B=\pi \cap {\mathcal V}$. Choose  $\pi$  such that $|B|=|\pi \cap {\mathcal V}|\leq  p^6+p^4+p^2+1$ (Lemma \ref{lemma1}).
Then,  by Proposition \ref{charplanes1}, $B$ is a linear combination of at most $p^2+1$ lines, each with weight 1.  Let $c$ be the codeword corresponding to $B$. We observe that  $\ell$ must be one of the lines of $c$,  otherwise $|B\cap \ell|\leq p^2+1$,  which is impossible.
Thus if $P$ is a point in $\ell \setminus B$, then through $P$ there pass at least  $p-1$ other lines of $c$.  If $x\geq p+2$, then the number of lines necessary to define the codeword $c$  would be at least $(p+2)(p-1)+1$, a contradiction.
\end{proof}
%\begin{lemma}
%If $\ell$ is a $p^4-p+1$ secant of ${\mathcal V}$, then for  each plane $\pi$ through $\ell$,  the codeword $\pi \cap {\mathcal V}$ consists of the lines of PG$(2,p^2)$ minus $p$ concurrent lines.
%\end{lemma}

\begin{lemma}\label{lem32}
For each plane $\pi$ of ${\mathcal H}(r,p^4)$, either $|\pi \cap  {\mathcal V}|\leq p^6+2p^4-p^2-p+1$ or $ |\pi \cap  {\mathcal V}|\geq p^8-p^5+p^4-p+1$.
\end{lemma}
\begin{proof}
Let $B=\pi \cap  {\mathcal V}$,  $x=|B|$, and let $t_i$ be the number of lines in $\pi$ meeting $B$ in $i$ points. Then, in this case, Equations \eqref{tg1} read

\begin{equation} \label{tg2}
\left\{\begin{array}{l}
    \sum_{i=1}^{p^4+1}t_i=p^8+p^4+1 \\
    \\
          \sum_{i=1}^{p^4+1}it_i=x(p^4+1)\\
     \\
     \sum_{i=1}^{p^4+1}i(i-1)t_i=x(x-1).
   \end{array}  \right.
  \end{equation}


Set   $f(x)=\sum_{i=1}^{p^4+1}(p^2+1-i)(i-(p^4-p+1))t_i$. From \eqref{tg2} we obtain
\[f(x)=-x^2+[(p^4+1)(p^4+p^2-p+1)+1]x-(p^8+p^4+1)(p^2+1)(p^4-p+1). \]
 Because of Lemma \ref{lem31}, we get  $f(x)\leq 0$, while $f(p^6+2p^4-p^2+1)>0$, $f(p^8-p^5+p^4-p)>0$. This finishes the proof of the  lemma.
\end{proof}
\begin{lemma}\label{lem33}
If $\pi$ is a plane of ${\mathcal H}(r,p^4)$, such that $ |\pi \cap  {\mathcal V}|\geq p^8-p^5+p^4-p+1$, then  either $\pi$ is entirely contained in ${\mathcal V}$ or
$ \pi \cap  {\mathcal V}$ consists of $p^8-p^5+p^4+1$ points and it only contains $i$-secants, with $i\in \{1, p^4-p+1,p^4+1\}$.
\end{lemma}
\begin{proof}
Set $S=\pi \setminus {\mathcal V}$.
Suppose that there exists some point $P \in S$. We have the following two possibilities: either each line of the pencil with center at  $P$ is a
$(p^4-p+1)$-secant or only one line through $P$ is an $i$-secant, with  $1\leq i\leq p^2+1$, whereas the other $p^4$ lines through $P$ are $(p^4-p+1)$-secants. In the former case, when there are no $i$-secants, $1\leq i\leq p^2+1$, each line  $\ell$  in $\pi$ either is disjoint from $S$ or it meets $S$ in $p$ points since  $\ell$ is a $(p^4-p+1)$-secant. This implies that $S$ is a maximal arc and this is impossible for $p\neq 2$ \cite{BB,BBM}.

In the latter case, we observe that the size of $\pi\cap {\mathcal V}$ must be $p^8-p^5+p^4+i$, where $1\leq i\leq p^2+1$. Next, we denote by $t_s$ the number of $s$-secants in $\pi$, where $s\in \{i,p^4-p+1,p^4+1 \}$. We have that

\begin{equation} \label{tg3}
\left\{\begin{array}{l}
    \sum_{s}t_s=p^8+p^4+1 \\
    \\
          \sum_{s}st_s=(p^4+1)(p^8-p^5+p^4+i)\\
     \\
     \sum_{s}s(s-1)t_s=(p^8-p^5+p^4+i)(p^8-p^5+p^4+i-1).
   \end{array}  \right.
  \end{equation}
  From \eqref{tg3} we get
  \begin{equation} \label{tg3.1}
  t_i=\frac{p(p^4-p-i+1)(p^5-i+1)}{p(p^4-p-i+1)(p^4-i+1)}=\frac{p^5-i+1}{p^4-i+1},
  \end{equation}
and  we can see that
the only possibility for $t_i$ to be  an integer is $ip-p-i+1=0$, that is $i=1$.
For $i=1$, we get $|B|=p^8-p^5+p^4+1$.
\end{proof}

\begin{lemma}\label{lem4}
If $\pi$ is a plane of ${\mathcal H}(r,p^4)$,  not contained in ${\mathcal V}$ and  which does not  contain any  $(p^4-p+1)$-secant,  then  $\pi \cap  {\mathcal V}$ is either a classical  unital or the union of $i$ concurrent lines, with $1\leq i\leq p^2+1$.
\end{lemma}
\begin{proof}
Because of Lemmas \ref{lem31}, \ref{lem32} and \ref{lem33}, the plane $\pi$  meets ${\mathcal V}$ in at most $p^6+2p^4-p^2-p+1$ points. Furthermore,  each line of $\pi$ which is not contained in ${\mathcal V}$ is an $i$-secant, with $1\leq i\leq p^2+1$ (Lemma \ref{lem31} and the sentence preceding Lemma \ref{lem31}). Set $B=\pi \cap {\mathcal V}$. If in $\pi$ there are no $(p^4+1)$-secants to $B$, then $|B|\leq p^6+p^2+1$ and by Proposition \ref{charplanes2} it follows that  $B$ is a classical unital.

 If there is a $(p^4+1)$-secant to $B$ in $\pi$, then arguing as in the proof of Proposition \ref{charplanes1}, we  get that $B$ is  still a linear combination of $m$ lines, with  $m\leq p^2+1$. Each of these $m$ lines is a  $(p^4+1)$-secant to ${\mathcal V}$. In fact if one of these lines, say $v$, was an $s$-secant, with $1\leq s\leq p^2+1$, then through each point $P\in v \setminus B$, there would pass at least $p$ lines of the codeword corresponding to $B$ and hence $B$ would be a linear combination of at least $(p^4+1-s)(p-1)+1>p^2+1$ lines, which is impossible.

We are going to prove that these $m$ lines, say $\ell_1,\ldots, \ell_m$,  are concurrent. Assume on the contrary that they are not. We can assume that through a point $P\in \ell_n$, there pass at least $p+1$ lines of our codeword but there is a line $\ell_j$ which does not pass through $P$. Thus through at least $p+1$ points on $\ell_j$, there are at least $p+1$ lines of our codeword and thus  we find at least $(p+1)p+1>m$  lines of $B$, a contradiction.
\end{proof}


\begin{lemma}\label{lem5}
A plane $\pi$ of ${\mathcal H}(r,p^4)$  meeting ${\mathcal V}$ in at most $p^6+2p^4-p^2-p+1$ points and  containing a $(p^4-p+1)$-secant  to ${\mathcal V}$ has at most $(p^2+1)( p^4-p+1)$ points of ${\mathcal V}$.
\end{lemma}
\begin{proof} Let $\ell$ be a line of $\pi$  which is  a $(p^4-p+1)$-secant to ${\mathcal V}$. In this case, $\pi \cap {\mathcal V}$ is a linear combination of at most $p^2+1$ lines, each with weight 1 (Proposition \ref{charplanes1}). A line not in the codeword can contain at most $p^2+1$ points. In particular, since $\ell$ contains more than $p^4-p^2+1$ points of ${\mathcal V}$, $\ell$ is a line of the codeword and hence through each of the missing points of $\ell$ there are at least $p$ lines of the codeword corresponding to $B$. On these $p$ lines we can see at most $p^4-p+1$ points of ${\mathcal V}$.

So let $\ell_1, \ell_2, \ldots, \ell_p$ be $p$ lines of the codeword through a point of $\ell \setminus {\mathcal V}$. Each of these lines contains at most $p^4-p+1$ points of ${\mathcal V}$. Thus these $p$ lines contain together at most $ p(p^4-p+1)$ points of ${\mathcal V}$.  Now take any other line of the codeword, say $e$. If $e$ goes through the common point of the lines $\ell_i$, then there is already one point missing from $e$, so adding $e$ to our set, we can add at most $p^4-p+1$ points. If $e$ does not go through the common point, then it intersects $\ell_i$ in $p$  different points. These points  either do not belong to the set $\pi\cap {\mathcal V}$ or they belong to the set $\pi\cap {\mathcal V}$, but we have already counted them when we counted the points of $\ell_i$, so again $e$ can add at most  $p^4-p+1$ points to the set $\pi\cap {\mathcal V}$.
 Thus adding the lines of the codewords one by one to $\ell_i$ and counting the number of points, each time we add only at most $p^4-p+1$ points to the set $\pi\cap {\mathcal V}$.
Hence, the plane $\pi$ contains at most $(p^2+1)(p^4-p+1)$ points of ${\mathcal V}$.
\end{proof}

\begin{lemma}\label{lem51}
Let $\pi$  be a plane of ${\mathcal H}(r,p^4)$, containing  an $i$-secant, $1< i < p^2 + 1$,  to ${\mathcal V}$. Then
$\pi \cap {\mathcal V}$ is either the union of $i$ concurrent lines or it is a linear combination of $p^2+1$ lines (each with weight 1) so that they form a subplane of order $p$, minus $p$ concurrent lines.
\end{lemma}
\begin{proof}
 By Lemmas \ref{lem32}, \ref{lem33} and \ref{lem4},
 $\pi$  meets ${\mathcal V}$ in  at most $p^6 +2p^4 -p^2 -p+1$ points and must contain a $(p^4-p+1)$-secant  to ${\mathcal V}$ or $\pi \cap {\mathcal V}$ is the union of $i$ concurrent lines. Hence, from now on, we assume that $\pi$ contains a  $(p^4 -p+1)$-secant. By Result \ref{codewords}, such a plane is a linear combination of at most $p^2+1$ lines.
As before each line from the linear combination has weight $1$.
Note that the above two statements imply that a line of the linear combination will be either a $(p^4 +1)$-secant or a $(p^4 -p+1)$-secant.

As we have  at most $p^2+ 1$ lines in the combination, a $(p^4- p + 1)$-secant must be one of these lines. This also means that through each of the $p$ missing points of this line, there must pass at least $p-1$ other lines from the linear combination. Hence, we already get $(p-1)p +1$ lines.

In the case in which  the linear combination contains exactly $p^2-p+1$ lines, then from each of these lines there are exactly $p$ points missing and through each missing point there are exactly $p$ lines from the linear combination. Hence, the missing points and these lines form a projective plane of order $p-1$, a contradiction as $p>3$.


Therefore, as the number of the lines of the linear combination must be $1$ $\pmod{p}$ and at most $p^2+1$, we can assume that  the linear combination contains  $p^2 +1$ lines.
We are going to prove that through each point of the plane there pass either $0$, $1$, $p$ or $p+1$ lines from the linear combination. From earlier arguments, we know that the number of lines through one point $P$ is $0$ or $1 \pmod{p}$. Assume to the contrary that through $P$ there pass at least $p+2$ of such lines. These $p^2+1$ lines forming the linear combination are not concurrent, so there is a line $\ell$ not through $P$. Through each of the intersection points of $\ell$ and a line through $P$, there pass at least $p-1$ more other lines of the linear combination, so in total we get at least $(p-1)(p+2)+1$ lines forming the linear combination, a contradiction.

Since there are $p^2 +1$ lines forming the linear combination and through each point of the plane there pass either $0$, $1$, $p$ or $p+1$ of these lines, we obtain that on a $(p^4-p+1)$-secant there is exactly one point, say $P$,  through which there pass exactly $p+1$ lines from the linear combination and $p$ points, not in the quasi Hermitian variety, through each of which there pass exactly $p$ lines.


If all the $p^2+1$ lines forming the linear combination,  were $(p^4-p+1)$-secants then the number of points through which there pass exactly $p$ lines would be $(p^2+1)p / p$. On the other hand, through $P$ there pass $p+1$  $(p^4-p+1)$-secants, hence we already get $(p+1)p$ such points, a contradiction.
 Thus, there exists a line $m$ of the linear combination that is a $(p^4+1)$-secant. From the above arguments, on this line there are exactly $p$ points through each of which there pass exactly $p+1$ lines, whereas through the rest of the points of the line $m$ there pass no other lines of the linear combination.

 Assume that there is a line $m' \neq m$ of the linear combination that is also a $(p^4+1)$-secant. Then there is a point $Q$ on $m'$ but not on $m$ through which there pass $p+1$ lines. This would mean that there are at least $p+1$ points on $m$, through which there pass more than $2$ lines of the linear combination, a contradiction.


 Hence, there is exactly one line $m$ of the linear combination that is a $(p^4+1)$-secant and all the other lines of the linear combination are $(p^4-p+1)$-secants.
It is easy to check  that the points through which there are more than $2$ lines plus the $(p^4-p+1)$-secants form a dual affine plane.
% There are p^2 points not on l, through which there pass at least 2 lines from the lin. combination. This is so, because there are p^2 (p^4-p+1)-secants, on each we see p such points and each such point was calculated exactly p times.
%Hence there are $p^2+p$  ``lines'' (in the dual setting) and $p^2$ ``points''. Through each``point'' there are $(p+1)$ ``lines'', on each ``line'' there are p ``points'' (obvious from above).)
Hence our lemma follows.
\end{proof}





\begin{lemma}\label{lem35}
There are no $i$-secants to ${\mathcal V}$, with $1<i<p^2+1$.
\end{lemma}

\begin{proof}
By Lemma \ref{lem51},
if a plane $\pi$ contains an $i$-secant, $1 < i < p^2 +1$, then $\pi \cap {\mathcal V}$ is a linear combination of either  $i$ concurrent lines or lines of an embedded subplane of order $p$ minus $p$ concurrent lines. In the latter case, if $i>1$ then  an $i$-secant is at least a $(p^2-p+1)$-secant. In fact, since the $p^2+1$ lines of the linear combination  do not intersect outside of ${\mathcal H}(2,p)$, each of the $p^2+1$ lines of the linear combination is at least a $(p^4-p+1)$-secant, whereas the $p$ concurrent lines are $1$-secants. Also, all the other lines of ${\mathcal H}(2,p^4)$ intersect ${\mathcal H}(2,p)$ in either $1$ or zero points. If they intersect ${\mathcal H}(2,p)$ in zero points they are $(p^2+1)$-secants to ${\mathcal V}$. If they intersect ${\mathcal H}(2,p)$ in a unique point $P$, then they are at least $(p^2-p+1)$-secants since $P$ lies on $p$ or $p+1$ lines of  the linear combination and each line intersects ${\mathcal V}$ in $1\pmod p$ points.


%In fact a line $\ell$ in a plane of order $p^4$ which is external with the respect to a subplane $\sigma$ of order $p$ intersects $\sigma$ in a unique point $P$ and there are at most $p+1$ lines among the $p^2+1$ passing through $P$: all the other $p^2-p$ lines intersect $\ell$ in other $p^2-p$ pairwise distinct points.
Hence, if there  is  an $i$-secant with $1<i<p^2-p+1$, say $\ell$, we get that  for each plane $\alpha$  through $\ell$,  $\alpha \cap {\mathcal V}$ is a linear combination of $i$ concurrent lines.
 Therefore
  \begin{equation}\label{eq17}
|{\mathcal V}|= m(ip^4+1-i)+i,
\end{equation}
where $m=p^{4(r-2)}+p^{4(r-3)}+ \ldots +p^4+1$ is the number of planes in ${\mathcal H}(r,p^4)$ through $\ell$.


Setting $r=2\sigma+\epsilon$, where $\epsilon=0 $ or $\epsilon=1$ according to $r$ is even or odd, we can write
\[|{\mathcal V}|=1+p^4+\cdots+p^{4(r-\sigma-1)}+(p^{4(r-\sigma-\epsilon)}+p^{4((r-\sigma-\epsilon+1)}+\cdots+p^{4(r-1)})p^2\]


Hence, \eqref{eq17} becomes
   \begin{equation}
   \begin{array}{l}\label{eq18}
1+p^4+\cdots+p^{4(r-\sigma-1)}+(p^{4(r-\sigma-\epsilon)}+p^{4((r-\sigma-\epsilon+1)}+\cdots+p^{4(r-1)})p^2\\
-(p^{4(r-2)}+p^{4(r-3)}+ \cdots +p^4+1)=ip^{4(r-1)}.
\end{array}
\end{equation}
Since $\sigma \geq 2$, we see that  $p^{4(r-1)}$ does not divide the left hand side of (\ref{eq18}),
  a contradiction.

Thus, there can only  be  $1$-, $(p^2-p+1)$-, $(p^2+1)$-, $(p^4-p+1)$- or $(p^4+1)$-secants to ${\mathcal V}$.
Now, suppose  that $\ell$ is a $(p^2-p+1)$-secant to ${\mathcal V}$. Again by Lemma  \ref{lem51},
 each plane through $\ell$  either  has $x=(p^2-p+1)p^4+1$ or  $y=p^2(p^4-p)+p^4+1$ points of ${\mathcal V}$.
 Next, denote by $t_j$ the number of $j$-secant planes through $\ell$  to  ${\mathcal V}$.
 We get
 \begin{equation} \label{2c}
\left\{\begin{array}{l}
    t_{x}+t_{y}=m \\
    t_{x}(x-p^2+p-1)+t_{y}(y-p^2+p-1)+p^2-p+1=|{\mathcal V}|.
   \end{array}  \right.
  \end{equation}
Recover the value of $t_y$ from the first
equation and substitute it in the second.
 We obtain
 \[(m-t_y)(p^6-p^5+p^4-p^2+p)+t_y(p^6+p^4-p^3-p^2+p)+p^2-p+1=|{\mathcal V}|,\]
 that is,
\[p^3(p^2-1)t_y=|{\mathcal V}|-m(p^6-p^5+p^4-p^2+p)-p^2+p-1.\]
The case $t_y=0$ must be excluded, since by direct computations $|{\mathcal V}|\neq m(p^6-p^5+p^4-p^2+p)+p^2-p+1$. It is easy to check that $|{\mathcal V}|-m(p^6-p^5+p^4-p^2+p)-p^2+p-1$ is not divisible by $p+1$ and hence, $t_y$  turns out not to be  an integer, which is impossible.
 \end{proof}


\begin{lemma} \label{3.20}No plane meeting ${\mathcal V}$ in at most $p^6+2p^4-p^2-p+1$ points contains a $(p^4-p+1)$-secant.
\end{lemma}

\begin{proof} Let $\pi$ be a plane of ${\mathcal H}(r,p^4)$ such that $|\pi \cap {\mathcal V}|\leq p^6+2p^4-p^2-p+1$. It can contain only $1$-, $(p^2+1)$-, $(p^4-p+1)$-, $(p^4+1)$-secants (Lemma \ref{lem31} and Lemma \ref{lem35}).
If $\pi\cap {\mathcal V}$ contains a $(p^4-p+1)$-secant, we know from Proposition \ref{charplanes1} that it is
a linear combination of at most $p^2+1$ lines, each with weight 1. Suppose that  $e$  is a $(p^4-p+1)$-secant to $\pi \cap {\mathcal V}$.
Let $P$ and $Q$ be two missing points of $e$. We know that there must be at least $p-1$ other lines of the codeword through $P$ and $Q$. Let $f$ and $g$ be two such lines through $Q$. The number of lines of the codeword through $P$ is at most $2p$ and since the lines $f$ and $g$ are lines of the codeword through $Q$, they are $(p^4-p+1)$-secants. There exist at most $(p-1)^2$ lines through $P$ distinct from $e$ intersecting $f$ or $g$ in a point not in ${\mathcal V}$. Therefore we can find a line, say $m$, of the plane through $P$, that intersects $f$ and $g$ in a point of ${\mathcal V}$ and that is not a line of the codeword. Then $|m \cap {\mathcal V}| \geq 1+p$ since $|m \cap {\mathcal V}| \equiv 1 \pmod{p}$.
Recall that $m$ is not a line of the codeword and the total number of lines of the codeword is at most $p^2+1$. Also, $m$ meets in $P$  at least $p$ lines of the codeword and therefore it can intersect all the remaining lines  in at most $p^2-p+1$ pairwise distinct points. This means that the line $m$ satisfies  $p+1\leq |m\cap {\mathcal V}|\leq p^2-p+1$, and this contradicts Lemma \ref{lem35}.
\end{proof}

\begin{lemma}\label{lem34}
There are no $(p^4-p+1)$-secants to ${\mathcal V}$.
\end{lemma}
\begin{proof} If there was a $(p^4-p+1)$-secant to ${\mathcal V}$, say $\ell$, then, by Lemma \ref{3.20}, all the planes through $\ell$  would contain at least $p^8-p^5+p^4+1$ points of ${\mathcal V}$, and thus
\begin{equation}\label{alsin}|{\mathcal V}|\geq (p^{4(r-2)}+p^{4(r-3)}+ \cdots +p^4+1)(p^8-p^5+p)+p^4-p+1,
\end{equation} a contradiction.
\end{proof}

\noindent {\bf Proof of Theorem \ref{mainth} (case $r \geq 4$ and $q = p^2$): }
Consider a line $\ell$ which is not contained in ${\mathcal V}$. From the preceding lemmas we have that $\ell$ is either a 1-secant or a $(p^2+1)$-secant of ${\mathcal V}$. Furthermore, ${\mathcal V}$ has  no plane section of  size $(p^2+1)(p^4+1)$ because of Lemma \ref{lem4}.   Finally, as in the case $r=3$,  it is  easy to see that ${\mathcal V}$ has no singular points, thus, by Theorem \ref{main2}, ${\mathcal V}$ turns out to be a Hermitian variety of ${\mathcal H}(r,p^4)$.




\section{Singular quasi-Hermitian varieties}\label{sqHv}
In this section, we consider sets having the same behavior with respect to hyperplanes as singular Hermitian varieties.
\begin{definition}
A {\em $d$-singular quasi-Hermitian variety} is a subset of points of ${\mathcal H}(r,q^2)$ having the same number of points and the same intersection sizes with hyperplanes as a singular Hermitian variety with a singular space of dimension $d$.
\end{definition}

We prove the following result.
\begin{theorem}
Let $\mathcal{S}$ be a $d$-singular quasi-Hermitian variety in ${\mathcal H}(r,q^2)$.
Suppose that either
\begin{itemize}
\item  $r=3$, $d=0$, $q=p^{h}\neq  4$, $h\geq 1$, $p$ any prime, or
\item $r\geq 4$, $d\leq r-3$, $q=p\geq5$, or
\item  $r\geq 4$, $d\leq r-3$, $q=p^2$, $p$ odd prime.
\end{itemize}
Then $\mathcal{S}$ is a singular Hermitian variety with a singular space of dimension $d$ if and only if its incidence vector  is in the $\mathbb{F}_p$-code spanned by the hyperplanes of ${\mathcal H}(r,q^2)$.
\end{theorem}
\begin{proof}
Let $\mathcal{S}$ be  a singular Hermitian variety of ${\mathcal H}(r,q^2)$. The  characteristic vector $v^{{\mathcal S}}$ of ${\mathcal S}$  is in $ \mathcal C_p$ since
   \cite[Theorem 1]{JK} also holds for singular Hermitian varieties.
 Now assume that ${\mathcal S}$ is a $d$-singular quasi-Hermitian variety. As in the non-singular case, by Lemma \ref{Lemma:rette}, each line of ${\mathcal H}(r,q^2)$ intersects $\mathcal{S}$ in $1\pmod{p}$ points.

\subsection{Case \texorpdfstring{$r=3$}{Lg}}

Suppose that $r=3$ and therefore $d=0$. Then ${\mathcal S}$ has $q^5+q^2+1$ points.  Let $\pi$   be a plane  of ${\mathcal H}(3,q^2)$.
In this case,  $\pi$   meets $\mathcal{S}$ in either $q^2+1$, or $q^3+1$ or  $q^3+q^2+1$ points. In particular, a  planar section of $\mathcal{S}$ with $q^2+1$ points is a line since it is a blocking set with respect to lines of a projective plane.

In the case in which $q$ is a prime $p$, Lemma \ref{lem1bis}  and Lemma \ref{lem2bis} are still valid in the singular case for ${\mathcal V} = {\mathcal S}$ and thus, the planar sections of $\mathcal{S}$
with $p^3+1$ or $p^3+p^2+1$ points have to be unitals or pencils of $p+1$ lines, respectively.
Hence, each line of ${\mathcal H}(3,p^2)$ meets $\mathcal{S}$ in $1$, $p+1$ or $p^2+1$ points.



When $q\geq5$ is  an odd prime power, Lemma \ref{lemma1},
Lemma   \ref{maxindex},
Proposition \ref{charplanes1},  and Corollary \ref{charunital} are still valid in the singular case for $r=3$.


Thus, if $|\pi \cap \mathcal{S}|=q^2+1$, then Proposition \ref{charplanes1} implies that $\pi \cap \mathcal{S}$ is a line of $\pi$,  whereas if $|\pi \cap \mathcal{S}|=q^3+1$, then Corollary \ref{charunitalbis} gives that $\pi \cap \mathcal{S}$  is a classical unital of $\pi$.
Now suppose that $|\pi \cap \mathcal{S}|=q^3+q^2+1$. Let $\ell$ be a line of $\pi$ such that $|\ell \cap \mathcal{S}|=s$ with $s\neq 1, q+1,q^2+1$.

 Each plane through $\ell$ must meet $\mathcal{S}$ in
$ q^3+q^2+1$ points and this gives
\[(q^3+q^2+1-s)(q^2+1)+s=q^5+q^2+1,\]
that is, $ s=q^2+q+1$, which is impossible.

Thus in ${\mathcal H}(3,q^2)$, where $q$ is an  odd prime power,  each line intersects $\mathcal{S}$
in  either $1$, or $q+1$ or $q^2+1$ points.


Next, assume $q=2^{h}$, $h > 2$. Arguing as in the corresponding  non-singular case, it turns out that a  $(q^3+q^2+1)$-plane meets $\mathcal S$ in a pencil of $q+1$ lines.
Now, assume that there is an $i$-secant line to ${\mathcal S}$, say $m$, with  $2< i< q$.
Then, each plane through $m$ has to be a $(q^3+1)$-plane of ${\mathcal S}$.
 Counting the number  of points of ${\mathcal S}$ by using all  planes through $m$ we obtain
 $q^5+q^2+1=q^5+q^3+q^2-iq^2+1$, hence $i=q$, a contradiction since every line contains $1\pmod 2$ points of ${\mathcal V}$.
 
  
Therefore, each line of ${\mathcal H}(3,2^{2h})$, $h\neq 2$ meets $\mathcal{S}$ in $1$, $q+1$ or $q^2+1$ points.
 Finally, $\mathcal{S}$ is a $k_{q+1,3,q^2}$ for all $q \neq 4$.
 Also, $\mathcal{S}$ cannot be non-singular by assumption. When $q\neq 2$,  Theorem \ref{th:singularcase1} applies and ${\mathcal S}$ turns out to be a cone $\Pi_0\mathcal{S}^{\prime}$ with $\mathcal{S}^{\prime}$ of type {I}, {II}, {III} or {IV } as   the possible intersection sizes with planes are $q^2+1,q^3+1,q^3+q^2+1$.

 Possibilities {II}, {III}, and {IV} must be excluded, since their sizes cannot be possible. This implies that $ \mathcal{S}=\Pi_0\mathcal{H}$, where $\mathcal{H}$ is a non-singular Hermitian curve.

For $q=2$, there is  just one point set in ${\mathcal H}(3,4)$ up to equivalence, meeting each line in $1$, $3$ or $5$ points and each plane in $5$, $9$ or $13$ points, that is the Hermitian cone,  see \cite[Theorem 19.6.8]{JH2}.









\subsection{Case \texorpdfstring{$r\geq 4$}{Lg}}
 Let  $\ell$ be a line of ${\mathcal H}(r,q^2)$  containing $x<q^2+1$ points of $\mathcal{S}$. We are going to prove that there exists at least one plane through $\ell$  containing less than $q^3+q^2+q+1$ points of $\mathcal{S}$.
If we suppose that all the planes through $\ell$ contain at least $q^3+q^2+q+1$ points of $\mathcal{S}$, then
$$
q^{2(d+1)}\frac{(q^{r-d}+(-1)^{r-d-1})(q^{r-d-1}-(-1)^{r-d-1})}{q^2-1} + q^{2d}+q^{2(d-1)}+\cdots+q^2+1 \geq$$
$$ m (q^3+q^2+q+1-x)+x,
$$
where $m=q^{2(r-2)}+q^{2(r-3)}+\cdots+q^2+1$  is the number of planes through $\ell$ in ${\mathcal H}(r,q^2)$. We obtain  $x>q^2+1$, a contradiction.

Therefore, there exists at least one plane through $\ell$ having less than $q^3+q^2+q+1$ points of $\mathcal{S}$ and hence Lemma \ref{lemma1}, Lemma   \ref{maxindex},
Proposition \ref{charplanes1},  and Corollary \ref{charunital}, are still valid in this singular case for any odd $q>4$.

Next, we are going to prove that ${\mathcal S}$ is a $k_{q+1,r,q^2}$, with $q=p^{h}>4$, $h=1,2$.

\medskip
\noindent{\bf Case $q = p\geq 5$: }
Let $\ell$ be a line of ${\mathcal H}(r,p^2)$. As we have seen, there is a plane $\pi$ through $\ell$ such that $|\pi \cap {\mathcal V}|< p^3+p^2+p+1$.   Proposition \ref{concurrent} is still valid in this case and thus we have that $\ell$ is either a unisecant or a $(p+1)$-secant of ${\mathcal S}$. Furthermore, we also have that ${\mathcal S}$ has  no plane section of  size $(p+1)(p^2+1)$ and hence ${\mathcal S}$ is a regular $k_{p+1,r,p^2}$.

\medskip
\noindent{\bf Case $q = p^2$, $p$ odd: }
We first observe that \eqref{eq17} and \eqref{alsin} hold true  in the case in which ${\mathcal V}$ is assumed to be a singular quasi-Hermitian variety. This implies that all lemmas stated in the subparagraph \ref{alsin0}  are valid in our case. Thus,
 we obtain that $\mathcal{S}$ is a $k_{p^2+1,r,p^4}$ and
  it is straightforward to check that $\mathcal{S}$ is also  regular.



 Finally,  in both cases $q=p$ or $q=p^2$,  we have that ${\mathcal S}$ is  a singular $k_{q+1,r,q^2}$ because  if $\mathcal{S}$ were a non-singular $k_{q+1,r,q^2}$, then, from Theorem \ref{main2}, $\mathcal{S}$ would be  a non-singular Hermitian variety and this is not possible by our assumptions.

 Therefore, by Theorem \ref{th:singularcase}, the only possibility is that $\mathcal{S}$ is a cone $\Pi_d \mathcal{S}^\prime$, with $\mathcal{S}^{\prime}$ a non-singular $k_{q+1,r-d-1,q^2}$. By Lemma \ref{CDS}, $\mathcal{S}^{\prime}$ belongs to the code of points and hyperplanes of ${\mathcal H}(r-d-1,q^2)$. Since $r-d-1\geq 2$, then, by \cite{BBW} and Theorem \ref{mainth}, $\mathcal{S}^{\prime}$ is a non-singular Hermitian variety and, therefore, $\mathcal{S}$ is a singular Hermitian variety with a vertex of dimension $d$.
\end{proof}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection*{Acknowledgements}
The research of the  first two authors  was partially supported by Ministry for Education, University and Research of Italy (MIUR) (Project PRIN 2012 ``Geometrie di Galois e strutture di incidenza'' - Prot. N. 2012XZE22K\_005) and by the Italian National Group for Algebraic and Geometric Structures and their Applications (GNSAGA - INdAM). The third and fourth author acknowledge the financial support of the Fund for Scientific Research - Flanders (FWO) and the Hungarian Academy of Sciences (HAS) project: Substructures of projective spaces (VS.073.16N). The fourth author was also partially supported by OTKA Grant K124950.



\begin{thebibliography}{10}


\bibitem{AA} A.~Aguglia.
\newblock Quasi-Hermitian varieties in $\mathrm{PG}(r,q^2)$, $q$  even.
\newblock {\em  Contrib. Discrete Math.}, 8(1):31--37, 2013. 


\bibitem{ACK} 
A.~Aguglia, A.~Cossidente, and G.~Korchm\'{a}ros.
\newblock On quasi-Hermitian varieties.
\newblock {\em J. Combin. Des.}, 20(10):433--447, 2012.


\bibitem{AK} 
E.~F. Assmus and  J.~D. Key. 
\newblock {\em Designs and their codes}.
\newblock Cambridge Tracts in Mathematics, Cambridge University Press, Cambridge, 1992.


\bibitem{BB} 
S.~Ball and  A.~Blokhuis. 
\newblock An easier proof of the maximal arcs conjecture.
\newblock {\em Proc. Amer. Math. Soc.},  126(11):3377--3380, 1998.


\bibitem{BBM} 
S.~Ball, A.~Blokhuis, and F.~Mazzocca.
\newblock Maximal arcs in Desarguesian planes of odd order do not exist.
\newblock {\em Combinatorica}, 17(1):31--41, 1997.


\bibitem{BBW} 
A.~Blokhuis, A.~E. Brouwer, and H.~Wilbrink.
\newblock Hermitian unitals are code words.
\newblock {\em Discrete Math.}, 97:63--68, 1991.


\bibitem{BT} 
A.~A. Bruen and J.~A. Thas.
\newblock Blocking sets.
\newblock {\em Geom. Dedicata}, 6:193--203, 1977.


\bibitem{B} F.~Buekenhout.
\newblock Existence of unitals in finite translation planes of order $q^2$ with a kernel of order $q$.
\newblock {\em Geom. Dedicata}, 5:189--194, 1976.

\bibitem{DS} 
S.~De Winter and J.~Schillewaert.
\newblock A note on quasi-Hermitian varieties and singular quasi-quadrics.
\newblock {\em Bull. Belg. Math. Soc. Simon Stevin}, 17(5):911--918, 2010.


\bibitem{JH} 
J.~W.~P. Hirschfeld. 
\newblock {\em Finite Projective Spaces of Three Dimensions.} \newblock Oxford Mathematical Monographs, Oxford University Press, Oxford, 1985.
  
  
\bibitem{JH2} 
J.~W.~P. Hirschfeld. 
\newblock {\em Projective Geometries over Finite Fields, 2nd edn.}  \newblock Oxford Mathematical Monographs, Oxford University Press, Oxford, 1998.


\bibitem{HT} 
J.~W.~P. Hirschfeld and  J.~A.  Thas.
\newblock {\em General Galois Geometries}.
\newblock Oxford Mathematical Monographs, Oxford University Press, Oxford, 1991.


\bibitem{JK} 
J.~D. Key.
\newblock Hermitian varieties as Codewords.
\newblock {\em Des. Codes Cryptogr.}, 1:255--259, 1991.


\bibitem{M} 
R.~Metz.
\newblock On a class of unitals.
\newblock {\em Geom. Dedicata}, 8:125--126, 1979.


\bibitem{FP} 
F.~Pavese.
\newblock Geometric constructions of two-character sets.
\newblock {\em Discrete Math.}, 338(3):202--208, 2015.


\bibitem{S} 
B.~Segre.
\newblock Forme e geometrie Hermitiane, con particolare riguardo al caso finito.
\newblock {\em Ann. Mat. Pura Appl. (4)}, 70:1--201, 1965.


\bibitem{SzW} 
T.~Sz\H onyi and Zs.~Weiner.
\newblock Stability of $k$ mod $p$ multisets and small weight codewords of the code generated by the lines of PG$(2, q)$.
\newblock  {\em J. Combin. Theory Ser. A}, 157:321--333, 2018.






\end{thebibliography}

\end{document}
