1 Introduction

It was suggested 3 decades ago that quark-gluon plasma (QGP) formation would suppress the yield of \(\mathrm{J}/{\psi }\) mesons in high-energy heavy ion collisions, relative to that in proton–proton (\(\mathrm {p}\mathrm {p}\)) collisions, as a consequence of Debye screening of the heavy-quark potential at finite temperature [1]. This QGP signature triggered intense research activity, both experimental and theoretical, on the topic of heavy quarkonium production in nuclear collisions. Experiments at SPS [2, 3], RHIC [4, 5], and the CERN LHC [6, 7] have reported a significant \(\mathrm{J}/{\psi }\) suppression in heavy ion collisions compared to the expectation based on \(\mathrm {p}\mathrm {p}\) data. This suppression is found to be larger for more central collisions over a wide range in rapidity (y) and transverse momentum (\(p_{\mathrm {T}}\)). In addition, a suppression of different bottomonium states \([{\varUpsilon \mathrm{(1S)}},\,{\varUpsilon \mathrm{(2S)}},\,{\varUpsilon \mathrm{(3S)}}]\) has been observed at the LHC in lead–lead (\(\mathrm {PbPb}\)) collisions at a center-of-mass energy per nucleon pair of \(\sqrt{s_{\mathrm {NN}}} =2.76\,\text {TeV} \) [8,9,10], which appears to be consistent with the suggested picture of quarkonium suppression in the QGP [11, 12].

In order to interpret these results unambiguously, it is necessary to constrain the so-called cold nuclear matter effects on quarkonium production, through, e.g., baseline measurements in \(\mathrm {p}\mathrm {Pb}\) collisions. Among these effects, parton distribution functions in nuclei (nPDF) are known to differ from those in a free proton and thus influence the quarkonium yields in nuclear collisions. The expected depletion of nuclear gluon density at small values of the momentum fraction (x), an effect known as shadowing, would suppress \(\mathrm{J}/{\psi }\) production at forward y, corresponding to the \(\mathrm {p}\)-going direction in \(\mathrm {p}\mathrm {Pb}\) collisions [13, 14]. It has been also suggested that gluon radiation induced by parton multiple scattering in the nucleus can lead to \(p_{\mathrm {T}}\) broadening and coherent energy loss, resulting in a significant forward \(\mathrm{J}/{\psi }\) suppression in \(\mathrm {p}\mathrm {Pb}\) collisions at all available energies [15, 16]. These phenomena can be quantified by the nuclear modification factor, \(R_{\mathrm {p}\mathrm {Pb}}\), defined as the ratio of \(\mathrm{J}/{\psi }\) cross sections in \(\mathrm {p}\mathrm {Pb}\) collisions over those in \(\mathrm {p}\mathrm {p}\) collisions scaled by the number of nucleons in the \(\mathrm {Pb}\) ion (\(\mathrm {A}=208\)), and by the \(R_{\mathrm {FB}}\) ratio of \(\mathrm{J}/{\psi }\) cross sections at forward (\(\mathrm {p}\)-going direction) over those at backward (\(\mathrm {Pb}\)-going direction) rapidities.

In addition to prompt \(\mathrm{J}/{\psi }\) mesons, directly produced in the primary interaction or from the decay of heavier charmonium states such as \(\mathrm {\psi (2S)}\) and \(\chi _\text {c}\), the production of \(\mathrm{J}/{\psi }\) mesons includes a nonprompt contribution coming from the later decay of \({\mathrm {B}}\) hadrons, whose production rates are also expected to be affected by cold nuclear matter effects [17, 18]. However, neither high-\(p_{\mathrm {T}}\) \({\mathrm {B}}\) mesons nor b quark jets show clear evidence of their cross sections being modified in \(\mathrm {p}\mathrm {Pb}\) collisions [19, 20]. In this respect, the nonprompt component of \(\mathrm{J}/{\psi }\) production can shed light on the nature of nuclear effects (if any) on bottom-quark production at low \(p_{\mathrm {T}}\).

At the LHC, \(\mathrm{J}/{\psi }\) meson production in \(\mathrm {p}\mathrm {Pb}\) collisions at \(\sqrt{s_{\mathrm {NN}}} =5.02\,\text {TeV} \) has been measured by the ALICE [21, 22], ATLAS [23], and LHCb [24] collaborations. The \(R_{\mathrm {FB}}\) ratio has been determined as functions of rapidity in the center-of-mass frame, \(y_{\mathrm {CM}}\), and \(p_{\mathrm {T}}\). Using an interpolation of the \(\mathrm {p}\mathrm {p}\) production cross sections at the same collision energy, \(R_{\mathrm {p}\mathrm {Pb}}\) has also been estimated in Refs. [21, 22, 24] as functions of \(y_{\mathrm {CM}}\) and \(p_{\mathrm {T}}\). A significant suppression of the prompt \(\mathrm{J}/{\psi }\) production in \(\mathrm {p}\mathrm {Pb}\) collisions has been observed at forward \(y_{\mathrm {CM}}\) and low \(p_{\mathrm {T}}\), while no strong nuclear effects are observed at backward \(y_{\mathrm {CM}}\).

This paper reports an analysis of \(\mathrm{J}/{\psi }\) production in \(\mathrm {p}\mathrm {p}\) and \(\mathrm {p}\mathrm {Pb}\) collisions at \(\sqrt{s_{\mathrm {NN}}} =5.02\,\text {TeV} \), using data collected with the CMS detector in 2013 (\(\mathrm {p}\mathrm {Pb}\)) and in 2015 (\(\mathrm {p}\mathrm {p}\)). The \(\mathrm{J}/{\psi }\) mesons with \(2<p_{\mathrm {T}} <30{\,\text {GeV}/{c}} \) are measured via their dimuon decay channels in ranges of \(|y_{\mathrm {CM}} |<2.4\) in \(\mathrm {p}\mathrm {p}\) and \(-2.87<y_{\mathrm {CM}} <1.93\) in \(\mathrm {p}\mathrm {Pb}\) collisions. The corresponding values of x range from \(10^{-4}\), at forward \(y_{\mathrm {CM}}\) and low \(p_{\mathrm {T}}\), to \(10^{-2}\), at backward \(y_{\mathrm {CM}}\) and higher \(p_{\mathrm {T}}\). Both \(R_{\mathrm {p}\mathrm {Pb}}\) and \(R_{\mathrm {FB}}\) are measured as functions of \(y_{\mathrm {CM}}\) and \(p_{\mathrm {T}}\). The latter ratio is also studied as a function of the event activity in \(\mathrm {p}\mathrm {Pb}\) collisions, as characterized by the transverse energy deposited in the CMS detector at large pseudorapidities.

2 Experimental setup and event selection

The main feature of the CMS detector is a superconducting solenoid with an internal diameter of 6 m, providing a magnetic field of 3.8 T. Within the field volume are the silicon pixel and strip tracker, the crystal electromagnetic calorimeter, and the brass and scintillator hadronic calorimeter. The silicon pixel and strip tracker measures charged particle trajectories in the pseudorapidity range of \(|\eta |<2.5\). It consists of 66 M pixel and 10 M strip sensor elements. Muons are detected in the range of \(|\eta |<2.4\), with detection planes based on three technologies: drift tubes, cathode strip chambers, and resistive plate chambers. The CMS apparatus also has extensive forward calorimetry, including two steel and quartz-fiber Cherenkov hadron forward (HF) calorimeters, which cover \(2.9<|\eta |<5.2\). These detectors are used for online event selection and the impact parameter characterization of the events in \(\mathrm {p}\mathrm {Pb}\) collisions, where the term impact parameter refers to the transverse distance between the two centers of the colliding hadrons. A more detailed description of the CMS detector, together with a definition of the coordinate system used and the relevant kinematic variables, can be found in Ref. [25].

The \(\mathrm {p}\mathrm {Pb}\) data set used in this analysis corresponds to an integrated luminosity of 34.6\(\,\text {nb}^{-1}\). The beam energies are 4\(\,\text {TeV}\) for \(\mathrm {p}\), and 1.58\(\,\text {TeV}\) per nucleon for the \(\mathrm {Pb}\) nuclei, resulting in \(\sqrt{s_{\mathrm {NN}}} =5.02\,\text {TeV} \). The direction of the higher-energy \(\mathrm {p}\) beam was initially set up to be clockwise, and was reversed after 20.7\(\,\text {nb}^{-1}\). As a result of the beam energy difference, the nucleon–nucleon center-of-mass in \(\mathrm {p}\mathrm {Pb}\) collisions is not at rest with respect to the laboratory frame. Massless particles emitted at \(|\eta _{\mathrm {CM}} |=0\) in the nucleon–nucleon center-of-mass frame are detected at \(\eta _{\text {lab}}=-0.465\) for the first run period (clockwise \(\mathrm {p}\) beam) and \(+0.465\) for the second run period (counterclockwise \(\mathrm {p}\) beam) in the laboratory frame; the region \(-2.87<y_{\mathrm {CM}} <1.93\) is thus probed by flipping the \(\eta \) of one data set so that the \(\mathrm {p}\)-going direction is always toward positive \(y_{\mathrm {CM}}\). The \(\mathrm {p}\mathrm {p}\) data set is also collected at the same collision energy with an integrated luminosity of 28.0\(\,\text {pb}^{-1}\). In this sample, \(\mathrm{J}/{\psi }\) mesons are measured over \(|y_{\mathrm {CM}} |<2.4\).

In order to remove beam-related background such as beam-gas interactions, inelastic hadronic collisions are selected by requiring a coincidence of at least one of the HF calorimeter towers with more than 3\(\,\text {GeV}\) of total energy on each side of the interaction point. This requirement is not present in \(\mathrm {p}\mathrm {p}\) collisions which suffer less from photon-induced interactions compared to \(\mathrm {p}\mathrm {Pb}\) collisions. The \(\mathrm {p}\mathrm {p}\) and \(\mathrm {p}\mathrm {Pb}\) events are further selected to have at least one reconstructed primary vertex composed of two or more associated tracks, excluding the two muons from the \(\mathrm{J}/{\psi }\) candidates, within 25\(\,\text {cm}\) from the nominal interaction point along the beam axis and within 2\(\,\text {cm}\) in its transverse plane. To reject beam-scraping events, the fraction of good-quality tracks associated with the primary vertex is required to be larger than 25% when there are more than 10 tracks per event.

In \(\mathrm {p}\mathrm {Pb}\) collisions, an additional filter [26] is applied to remove events containing multiple interactions per bunch crossing (pileup). After the selection, the residual fraction of pileup events is reduced from 3% to less than 0.2%. This pileup rejection results in a 4.1% signal loss, which is corrected for in the cross section measurements. Since pileup only affects the event activity dependence in \(\mathrm {p}\mathrm {Pb}\) results, no filter is applied in \(\mathrm {p}\mathrm {p}\) results.

Dimuon events are selected by the level-1 trigger, a hardware-based trigger system requiring two muon candidates in the muon detectors with no explicit limitations in \(p_{\mathrm {T}}\) or y. In the offline analysis, muons are required to be within the following kinematic regions, which ensure single-muon reconstruction efficiencies above 10%:

$$\begin{aligned} \begin{array}{lll} &{}p_{\mathrm {T}} ^{\mu }>3.3{\,\text {GeV}/{c}} &{} \text { for }|\eta _{\text {lab}}^{\mu } |<1.2,\\ &{}p_{\mathrm {T}} ^{\mu }>(4.0-1.1|\eta _{\text {lab}}^{\mu } |){\,\text {GeV}/{c}} &{} \text { for }1.2\le |\eta _{\text {lab}}^{\mu } |<2.1,\\ &{}p_{\mathrm {T}} ^{\mu }>1.3{\,\text {GeV}/{c}} &{}\text { for }2.1\le |\eta _{\text {lab}}^{\mu } |<2.4.\\ \end{array} \end{aligned}$$
(1)

The muon pairs are further selected to be of opposite charge, to originate from a common vertex with a \(\chi ^2\) probability greater than 1%, and to match standard identification criteria [27].

Simulated events are used to obtain the correction factors for acceptance and efficiency. The Monte Carlo (MC) samples of \(\mathrm{J}/{\psi }\) mesons are generated using pythia 8.209 [28] for \(\mathrm {p}\mathrm {p}\) and pythia 6.424 [29] for \(\mathrm {p}\mathrm {Pb}\) collisions. Generated particles in the \(\mathrm {p}\mathrm {Pb}\) simulation are boosted by \(\Delta y=\pm 0.465\) to account for the asymmetry of \(\mathrm {p}\) and \(\mathrm {Pb}\) beams in the laboratory frame. Samples for prompt and nonprompt \(\mathrm{J}/{\psi }\) mesons are independently produced using the D6T [30] and Z2 [31] tunes, respectively. In the absence of experimental information on quarkonium polarization in \(\mathrm {p}\mathrm {p}\) and \(\mathrm {p}\mathrm {Pb}\) collisions at \(\sqrt{s} =5.02\,\text {TeV} \), it is assumed that prompt \(\mathrm{J}/{\psi }\) mesons are produced unpolarized, as observed in \(\mathrm {p}\mathrm {p}\) collisions at \(\sqrt{s} =7\,\text {TeV} \) [32,33,34]. The nonprompt \(\mathrm{J}/{\psi }\) sample includes the polarization (\(\lambda _{\theta }\approx -0.4\)) determined from a measurement of the exclusive \({\mathrm {B}}\) hadron decays (\({\mathrm {B}^{+}}, {\mathrm {B}^0}\), and \(\mathrm{B}^0_\mathrm{s} \)) as implemented in evtgen 9.1 [35]. The \(\mathrm {p}\mathrm {Pb}\) measurements might be affected by physics processes with strong kinematic dependence within an analysis bin, e.g., polarization or energy loss. Such possible physics effects on the final cross sections are not included in the systematic uncertainties, as was done in the previous analyses [8, 9]. The QED final-state radiation from muons is simulated with photos 215.5 [36]. Finally, the CMS detector response is simulated using Geant4  [37].

3 Analysis procedure

3.1 Differential cross section, \(R_{\mathrm {p}\mathrm {Pb}}\), and \(R_{\mathrm {FB}}\)

In this paper, three observables analyzed in \(\mathrm{J}/{\psi }\) meson decays to muon pairs are reported. First, the cross sections are determined based on

$$\begin{aligned} \mathcal {B}(\mathrm{J}/{\psi } \rightarrow \mu ^+ \mu ^- )\frac{\mathrm{d}^2\sigma }{\mathrm{d}p_{\mathrm {T}} \,\mathrm{d}y_{\mathrm {CM}}} = \frac{N^{\mathrm{J}/{\psi }}_{\text {Fit}}/(\text {Acc}\,\varepsilon )}{\mathcal {L}_{\text {int}}\,\Delta p_{\mathrm {T}} \,\Delta y_{\mathrm {CM}}}, \end{aligned}$$
(2)

where \(\mathcal {B}(\mathrm{J}/{\psi } \rightarrow \mu ^+ \mu ^- )\) is the branching fraction to the \(\mu ^+ \mu ^- \) channel [38], \(N^{\mathrm{J}/{\psi }}_{\text {Fit}}\) is the extracted raw yield of \(\mathrm{J}/{\psi }\) mesons in a given \((p_{\mathrm {T}},y_{\mathrm {CM}})\) bin, \((\text {Acc}\,\varepsilon )\) represents the dimuon acceptance times efficiency described in Sect. 3.3, and \(\mathcal {L}_{\text {int}}\) is the integrated luminosity with the values of \((28.0\pm 0.6)\) \(\,\text {pb}^{-1}\) for \(\mathrm {p}\mathrm {p}\)  [39] and \((34.6\pm 1.2)\) \(\,\text {nb}^{-1}\) for \(\mathrm {p}\mathrm {Pb}\)  [40] collisions.

The cross sections are measured in up to nine bins in \(p_{\mathrm {T}}\) ([2,3], [3,4] [4,5], [5,6.5], [6.5,7.5], [7.5,8.5], [8.5,10], [10,14], [14,30]\({\,\text {GeV}/{c}} \)), with the minimum \(p_{\mathrm {T}}\) values varying with \(y_{\mathrm {CM}}\) ranges as shown in Table 1.

Table 1 Rapidity intervals and associated minimum \(p_{\mathrm {T}}\) values for the \(\mathrm{J}/{\psi }\) cross section measurements in \(\mathrm {p}\mathrm {p}\) and \(\mathrm {p}\mathrm {Pb}\) collisions

The second observable considered is the nuclear modification factor, calculated as

$$\begin{aligned} R_{\mathrm {p}\mathrm {Pb}} (p_{\mathrm {T}},y_{\mathrm {CM}}) = \frac{({\mathrm{d}^2\sigma }/{\mathrm{d}p_{\mathrm {T}} \,\mathrm{d}y_{\mathrm {CM}}})_{\mathrm {p}\mathrm {Pb}}}{\mathrm {A}({\mathrm{d}^2\sigma }/{\mathrm{d}p_{\mathrm {T}} \,\mathrm{d}y_{\mathrm {CM}}})_{{\mathrm {p}\mathrm {p}}}}, \end{aligned}$$
(3)

where \(\mathrm {A}=208\) is the number of nucleons in the \(\mathrm {Pb}\) nucleus.

The third measurement is the forward-to-backward production ratio for \(\mathrm {p}\mathrm {Pb}\) collisions, defined for positive \(y_{\mathrm {CM}}\) by

$$\begin{aligned} R_{\mathrm {FB}} (p_{\mathrm {T}},y_{\mathrm {CM}} >0) = \frac{\mathrm{d}^2\sigma (p_{\mathrm {T}},y_{\mathrm {CM}})/\mathrm{d}p_{\mathrm {T}} \mathrm{d}y_{\mathrm {CM}}}{\mathrm{d}^2\sigma (p_{\mathrm {T}},-y_{\mathrm {CM}})/\mathrm{d}p_{\mathrm {T}} \mathrm{d}y_{\mathrm {CM}}}. \end{aligned}$$
(4)

This variable is a sensitive probe of the dynamics of \(\mathrm{J}/{\psi }\) production by comparing nuclear effects in the forward and the backward \(y_{\mathrm {CM}}\) hemispheres, since \(R_{\mathrm {FB}} (p_{\mathrm {T}},y_{\mathrm {CM}})\) is equivalent to \(R_{\mathrm {p}\mathrm {Pb}} (p_{\mathrm {T}},y_{\mathrm {CM}})/R_{\mathrm {p}\mathrm {Pb}} (p_{\mathrm {T}},-y_{\mathrm {CM}})\). In addition, several uncertainties cancel in the \(R_{\mathrm {FB}}\) ratio, such as those from the integrated luminosity determination. The minimum \(p_{\mathrm {T}}\) values for the \(R_{\mathrm {FB}}\) measurement are 5\({\,\text {GeV}/{c}} \) for \(1.5<|y_{\mathrm {CM}} |<1.93\), and 6.5\({\,\text {GeV}/{c}} \) for \(|y_{\mathrm {CM}} |<1.5\). The ratio \(R_{\mathrm {FB}}\) is also analyzed as a function of \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\), the transverse energy deposited on both sides of the collisions in the HF calorimeters within the \(4<|\eta |<5.2\) range. This energy is related to the impact parameter of the collision. In Table 2, the mean value of \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\) and the fraction of events for each bin used in the analysis are computed from minimum bias \(\mathrm {p}\mathrm {Pb}\) events.

Table 2 Ranges of forward transverse energy, \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\), their mean values, and associated fractions of \(\mathrm {p}\mathrm {Pb}\) events that fall into each category

3.2 Signal extraction

The signal extraction procedure is similar to that in previous CMS analyses of \(\mathrm {p}\mathrm {p}\)  [41, 42] and \(\mathrm {PbPb}\)  [6] collisions. The prompt \(\mathrm{J}/{\psi }\) mesons are separated from those coming from \({\mathrm {B}}\) hadron decays by virtue of the pseudo-proper decay length, \(\ell _{\mathrm{J}/{\psi }} =L_{xy}\,m_{\mathrm{J}/{\psi }}/p_{\mathrm {T}} \), where \(L_{xy}\) is the transverse distance between the primary and secondary dimuon vertices in the laboratory frame, \(m_{\mathrm{J}/{\psi }}\) is the mass of the \(\mathrm{J}/{\psi }\) meson, and \(p_{\mathrm {T}}\) is the dimuon transverse momentum. For each \(p_{\mathrm {T}}\), \(y_{\mathrm {CM}} \), and event activity bin, the fraction of nonprompt \(\mathrm{J}/{\psi }\) mesons (b fraction) is evaluated through an extended unbinned maximum likelihood fit to the invariant mass spectrum and \(\ell _{\mathrm{J}/{\psi }}\) distributions of \(\mu ^+ \mu ^- \) pairs, sequentially. The invariant mass spectrum is fitted first, and some parameters are initialized and/or fixed. Then, the \(\ell _{\mathrm{J}/{\psi }}\) distribution is fitted.

Fig. 1
figure 1

Examples of the invariant mass (left) and pseudo-proper decay length (right) distributions of \(\mu ^+ \mu ^- \) pairs for \(\mathrm {p}\mathrm {p}\) (upper) and \(\mathrm {p}\mathrm {Pb}\) (lower) collisions. The bin widths of \(\ell _{\mathrm{J}/{\psi }}\) distributions vary from 15 to 500 \(\upmu \)m, with the averaged value of 83 \(\upmu \)m. The projections of the 2D fit function onto the respective axes are overlaid as solid lines. The long-dashed lines show the fitted contribution of nonprompt \(\mathrm{J}/{\psi }\) mesons. The fitted background contributions are shown by short-dashed lines

For the dimuon invariant mass distributions, the shape of the \(\mathrm{J}/{\psi }\) signal is modeled by the sum of a Gaussian function and a Crystal Ball (CB) function [43], with common mean values and independent widths, in order to accommodate the rapidity-dependent mass resolution. The CB function combines a Gaussian core with a power-law tail using two parameters \(n_{\mathrm {CB}}\) and \(\alpha _{\mathrm {CB}} \), to describe final-state QED radiation of muons. Because the two parameters are strongly correlated, the value of \(n_{\mathrm {CB}}\) is fixed at 2.1, while the \(\alpha _{\mathrm {CB}} \) is a free parameter of the fit. This configuration gives the highest fit probability for data, in every \((p_{\mathrm {T}},y_{\mathrm {CM}})\) bin, when various settings of \(\alpha _{\mathrm {CB}} \) and \(n_{\mathrm {CB}}\) are tested. The invariant mass distribution of the underlying continuum background is represented by an exponential function.

For the \(\ell _{\mathrm{J}/{\psi }}\) distributions, the prompt signal component is represented by a resolution function, which depends on the per-event uncertainty in the \(\ell _{\mathrm{J}/{\psi }}\) provided by the reconstruction algorithm of primary and secondary vertices. The resolution function is composed of the sum of two Gaussian functions. A Gaussian with a narrower width (\(\sigma _{\text {narrow}}\)) describes the core of the signal component, while another with a greater width (\(\sigma _{\text {wide}}\)) accounts for the effect of uncertainties in the primary vertex determination and has a fixed value based on MC simulations. The \(\ell _{\mathrm{J}/{\psi }}\) distribution of the nonprompt component is modeled by an exponential decay function convolved with a resolution function. The continuum background component is modeled by the sum of three exponential decay functions, a normal one on one side \(\ell _{\mathrm{J}/{\psi }} >0\), a flipped one on the other side \(\ell _{\mathrm{J}/{\psi }} <0\), and a double-sided one, which are also convolved with a resolution function. The parameters describing the \(\ell _{\mathrm{J}/{\psi }}\) distributions of the background are determined from sidebands in the invariant mass distribution \(2.6<m_{\mu \mu }<2.9{\,\text {GeV}/c^{2}} \) and \(3.3<m_{\mu \mu }<3.5{\,\text {GeV}/c^{2}} \). The results are insensitive to the selection of sideband ranges.

For \(\mathrm {p}\mathrm {Pb}\) analysis, two data sets corresponding to each beam direction are merged and fitted together, after it is determined that the results are compatible with those from a separate analysis, performed over each data set. Figure 1 shows examples of fit projections onto the mass (left) and \(\ell _{\mathrm{J}/{\psi }}\) (right) axes for muon pairs with \(2<p_{\mathrm {T}} <3{\,\text {GeV}/{c}} \) in \(-2.4<y_{\mathrm {CM}} <-1.93\) from \(\mathrm {p}\mathrm {p}\) (upper), and in \(1.5<y_{\mathrm {CM}} <1.93\) from \(\mathrm {p}\mathrm {Pb}\) (lower) collisions.

3.3 Corrections

The acceptance and reconstruction, identification, and trigger efficiency corrections are evaluated from the MC simulation described in Sect. 2. The acceptance is estimated by the fraction of generated \(\mathrm{J}/{\psi }\) mesons in each \((p_{\mathrm {T}},y_{\mathrm {CM}})\) bin, decaying into two muons, each within the fiducial phase space defined in Eq. (1).

In order to compensate for imperfections in the simulation-based efficiencies, an additional scaling factor is applied, calculated with a tag-and-probe (T&P) method [44]. The tag muons require tight identification, and the probe muons are selected with and without satisfying the selection criteria relevant to the efficiency being measured. Then, invariant mass distributions of tag and probe pairs in the \(\mathrm{J}/{\psi }\) mass range are fitted to count the number of signals in the two groups. The single-muon efficiencies are deduced from the ratio of \(\mathrm{J}/{\psi }\) mesons in the passing-probe over all-probe group. The data-to-simulation ratios of single-muon efficiencies are used to correct the dimuon efficiencies, taking the kinematic distributions of decayed muons into account. The dimuon efficiency weights evaluated by the T&P method are similar for \(\mathrm {p}\mathrm {p}\) and \(\mathrm {p}\mathrm {Pb}\) events and range from 0.98 to 1.90, with the largest one coming from the lowest \(p_{\mathrm {T}}\) bin. The efficiencies are independent of the event activity, as verified by \(\mathrm {p}\mathrm {Pb}\) data and in a pythia sample embedded in simulated \(\mathrm {p}\mathrm {Pb}\) events generated by hijing 1.383 [45].

In addition, the shape of the uncorrected distributions of \(\mathrm{J}/{\psi }\) yield versus \(p_{\mathrm {T}}\) in data and MC samples are observed to be different. To resolve the possible bias in acceptance and efficiency corrections, the data-to-simulation ratios are fitted by empirical functions and used to reweight the \(p_{\mathrm {T}}\) spectra in MC samples for each \(y_{\mathrm {CM}}\) bin. The effect of reweighting on the acceptance and efficiency is detailed in the next Section.

3.4 Systematic uncertainties

The following sources of systematic uncertainties are considered: fitting procedure, acceptance and efficiency corrections, and integrated luminosities.

To estimate the systematic uncertainty due to the fitting procedure, variations of the parameters or alternative fit functions have been considered for the invariant mass and \(\ell _{\mathrm{J}/{\psi }}\) distributions. For the signal shape in the invariant mass distributions, three alternative parameter settings are tested: (1) \(\alpha _{\mathrm {CB}} \) is set to 1.7, averaged from the default fit, and \(n_{\mathrm {CB}}\) free, (2) both \(\alpha _{\mathrm {CB}} \) and \(n_{\mathrm {CB}}\) are left free, and (3) both are obtained from a MC template and then fixed when fit to the data. The maximum deviation of yields among these three variations is quoted as the uncertainty. For the background fit of the invariant mass distributions, a first-order polynomial is used as an alternative. For the shape of \(\ell _{\mathrm{J}/{\psi }}\) distribution of prompt \(\mathrm{J}/{\psi }\) mesons, two alternatives are studied: (1) both \(\sigma _{\text {wide}}\) and \(\sigma _{\text {narrow}}\) are left free, and (2) both parameters are fixed to the MC templates. The maximum deviation of yields is taken as the uncertainty. Finally, for the \(\ell _{\mathrm{J}/{\psi }}\) distribution shape of nonprompt \(\mathrm{J}/{\psi }\) mesons, the template shape is directly taken from reconstructed MC events. The uncertainties from the previously mentioned methods are 0.7–5.0% for prompt and 1.1–36.3% for nonprompt \(\mathrm{J}/{\psi }\) mesons. They are larger for the shape variations in the \(\ell _{\mathrm{J}/{\psi }}\) than in the invariant mass distributions, especially for nonprompt \(\mathrm{J}/{\psi }\) mesons.

For the uncertainties from acceptance and efficiency correction factors, the effect of reweighting the \(p_{\mathrm {T}}\) spectrum of events generated by pythia generator as described in Sect. 3.3 is considered. The deviation of the correction factors obtained from the default pythia spectra and those from data-based weighted spectra is less than 2.9% across all kinematic ranges. The full deviation values are quoted as the systematic uncertainties. The determination of uncertainties for T&P corrections is performed by propagating the uncertainties in single-muon efficiencies to the dimuon efficiency values. The systematic uncertainties are evaluated by varying the fit conditions in the T&P procedure, and the statistical uncertainties are estimated using a fast parametric simulation. The total uncertainty from T&P corrections is obtained by the quadratic sum of two sources. Uncertainties from the efficiency correction, including the T&P uncertainties, range from 2.4 to 6.1%, and tend to be larger for lower \(p_{\mathrm {T}}\). The uncertainty in the integrated luminosities (2.3% for \(\mathrm {p}\mathrm {p}\)  [39] and 3.5% for \(\mathrm {p}\mathrm {Pb}\)  [40]) is correlated across all data points and affects only the production cross sections and \(R_{\mathrm {p}\mathrm {Pb}}\), while it cancels out in the \(R_{\mathrm {FB}}\) measurements.

Table 3 summarizes systematic uncertainties considered in this analysis. The range refers to different \((p_{\mathrm {T}},y_{\mathrm {CM}})\) bins; the uncertainties tend to be lower at high \(p_{\mathrm {T}}\) and midrapidity, and higher at low \(p_{\mathrm {T}}\) and forward or backward \(y_{\mathrm {CM}}\). The larger uncertainties of the nonprompt \(\mathrm{J}/{\psi }\) yields come from the signal extraction in their lowest \(p_{\mathrm {T}}\) bin, 2–3\({\,\text {GeV}/{c}} \). In the case of the \(R_{\mathrm {p}\mathrm {Pb}}\) measurements with a \(p_{\mathrm {T}}\) limit of 4\({\,\text {GeV}/{c}} \), maximum uncertainties for nonprompt \(\mathrm{J}/{\psi }\) mesons are 12.7% for \(\mathrm {p}\mathrm {p}\) and 12.8% for \(\mathrm {p}\mathrm {Pb}\) collisions. The total systematic uncertainty is evaluated as the quadratic sum of the uncertainties from all sources in each kinematic bin, except for those from the integrated luminosity determination.

Table 3 Summary of the relative systematic uncertainties for the cross section measurements, given in percentages, for prompt and nonprompt \(\mathrm{J}/{\psi }\) mesons in \(\mathrm {p}\mathrm {p}\) and \(\mathrm {p}\mathrm {Pb}\) collisions

4 Results

4.1 Prompt \(\mathrm{J}/{\psi }\) mesons

Fig. 2
figure 2

Differential cross section (multiplied by the dimuon branching fraction) of prompt \(\mathrm{J}/{\psi }\) mesons in \(\mathrm {p}\mathrm {p}\) (left) and \(\mathrm {p}\mathrm {Pb}\) (right) collisions at forward (upper) and backward (lower) \(y_{\mathrm {CM}}\). The vertical bars (smaller than the symbols in most cases) represent the statistical uncertainties and the shaded boxes show the systematic uncertainties. The fully correlated global uncertainty from the integrated luminosity determination, 2.3% for \(\mathrm {p}\mathrm {p}\) and 3.5% for \(\mathrm {p}\mathrm {Pb}\) collisions, is not included in the point-by-point uncertainties

Fig. 3
figure 3

Rapidity dependence of the cross section (multiplied by the dimuon branching fraction) for prompt \(\mathrm{J}/{\psi }\) mesons in the \(p_{\mathrm {T}}\) intervals of \(6.5<p_{\mathrm {T}} <10{\,\text {GeV}/{c}} \) (circles) and \(10<p_{\mathrm {T}} <30{\,\text {GeV}/{c}} \) (squares) in \(\mathrm {p}\mathrm {p}\) (upper) and \(\mathrm {p}\mathrm {Pb}\) (lower) collisions. The vertical dashed line indicates \(y_{\mathrm {CM}} =0\). The vertical bars (smaller than the symbols in most cases) represent the statistical uncertainties and the shaded boxes show the systematic uncertainties. The fully correlated global uncertainty from the integrated luminosity determination, 2.3% for \(\mathrm {p}\mathrm {p}\) and 3.5% for \(\mathrm {p}\mathrm {Pb}\) collisions, is not included in the point-by-point uncertainties

Figure 2 shows the double-differential prompt \(\mathrm{J}/{\psi }\) production cross sections multiplied by the dimuon branching fraction in \(\mathrm {p}\mathrm {p}\) (left) and \(\mathrm {p}\mathrm {Pb}\) (right) collisions, with data points plotted at the center of each bin. Statistical uncertainties are displayed as vertical bars, while boxes that span the \(p_{\mathrm {T}}\) bin width represent systematic uncertainties. Not shown is a global normalization uncertainty of 2.3% in \(\mathrm {p}\mathrm {p}\) and 3.5% in \(\mathrm {p}\mathrm {Pb}\) collisions arising from the integrated luminosity determination.

Prompt \(\mathrm{J}/{\psi }\) \(y_{\mathrm {CM}}\) distributions are shown in Fig. 3 in \(\mathrm {p}\mathrm {p}\) (upper) and \(\mathrm {p}\mathrm {Pb}\) (lower) collisions. The measurements are integrated over two \(p_{\mathrm {T}}\) intervals, \(6.5<p_{\mathrm {T}} <10{\,\text {GeV}/{c}} \) (low \(p_{\mathrm {T}}\)) and \(10<p_{\mathrm {T}} <30{\,\text {GeV}/{c}} \) (high \(p_{\mathrm {T}}\)).

The \(p_{\mathrm {T}}\) dependence of prompt \(\mathrm{J}/{\psi }\) \(R_{\mathrm {p}\mathrm {Pb}}\) is shown in Fig. 4, in seven \(y_{\mathrm {CM}}\) ranges for which \(\mathrm {p}\mathrm {p}\) and \(\mathrm {p}\mathrm {Pb}\) measurements overlap. Around midrapidity (\(|y_{\mathrm {CM}} |<0.9\)) and in the three backward \(y_{\mathrm {CM}}\) bins (lower panels), \(R_{\mathrm {p}\mathrm {Pb}}\) is slightly above unity without a clear dependence on \(p_{\mathrm {T}}\). In the most forward bin (\(1.5<y_{\mathrm {CM}} <1.93\)), suppression at low \(p_{\mathrm {T}}\) (\({\lesssim }7.5{\,\text {GeV}/{c}} \)) is observed, followed by a weak increase of \(R_{\mathrm {p}\mathrm {Pb}}\) at higher \(p_{\mathrm {T}}\). The results are compared to three model calculations. One is based on the next-to-leading order (NLO) Color Evaporation Model [14] using the EPS09 [46] nPDF set. The other two are calculated from the nPDF sets of EPS09 and nCTEQ15 [47], respectively, with the parameterization of \(2\rightarrow 2\) partonic scattering process based on data, as described in Ref. [48]. All three \(R_{\mathrm {p}\mathrm {Pb}}\) calculations are marginally lower than the measured values across all \(y_{\mathrm {CM}}\) bins. The calculations based on coherent energy loss are not yet available to describe quarkonium production at large \(p_{\mathrm {T}}\) (\({\gtrsim } m_{\mathrm{J}/{\psi }}\)); therefore, no comparison of the present data with the model [15] is performed.

It is worth noting that the \(R_{\mathrm {p}\mathrm {Pb}}\) values measured in the most forward (\(1.5<y_{\mathrm {CM}} <1.93\)) and backward (\(-2.4<y_{\mathrm {CM}} <-1.93\)) regions are consistent, in the overlapping \(p_{\mathrm {T}}\) intervals (\(4<p_{\mathrm {T}} <8{\,\text {GeV}/{c}} \)), with the inclusive \(\mathrm{J}/{\psi }\) results of the ALICE collaboration [21, 22] over \(2.03<y_{\mathrm {CM}} <3.53\) and \(-4.46<y_{\mathrm {CM}} <-2.96\), obtained using an interpolated \(\mathrm {p}\mathrm {p}\) cross section reference. Although the ALICE results are for inclusive \(\mathrm{J}/{\psi }\) mesons, the nonprompt contribution is expected to be relatively small (\({<}20\%\)) in the domain \(p_{\mathrm {T}} <8{\,\text {GeV}/{c}} \).

Fig. 4
figure 4

Transverse momentum dependence of \(R_{\mathrm {p}\mathrm {Pb}}\) for prompt \(\mathrm{J}/{\psi }\) mesons in seven \(y_{\mathrm {CM}}\) ranges. The vertical bars represent the statistical uncertainties and the shaded boxes show the systematic uncertainties. The fully correlated global uncertainty of 4.2% is displayed as a gray box at \(R_{\mathrm {p}\mathrm {Pb}} =1\) next to the left axis. The predictions of shadowing models based on the parameterizations EPS09 and nCTEQ15 [14, 46,47,48] are also shown

Fig. 5
figure 5

Rapidity dependence of \(R_{\mathrm {p}\mathrm {Pb}}\) for prompt \(\mathrm{J}/{\psi }\) mesons in two \(p_{\mathrm {T}}\) ranges: \(6.5<p_{\mathrm {T}} <10{\,\text {GeV}/{c}} \) (upper) and \(10<p_{\mathrm {T}} <30{\,\text {GeV}/{c}} \) (lower). The vertical bars represent the statistical uncertainties and the shaded boxes show the systematic uncertainties. The fully correlated global uncertainty of 4.2% is displayed as a gray box at \(R_{\mathrm {p}\mathrm {Pb}} =1\) next to the left axis. The predictions of shadowing models based on the parameterizations EPS09 and nCTEQ15 [14, 46,47,48] are also shown

Figure 5 displays the \(y_{\mathrm {CM}}\) dependence of prompt \(\mathrm{J}/{\psi }\) \(R_{\mathrm {p}\mathrm {Pb}}\) in the low-\(p_{\mathrm {T}}\) (upper) and the high-\(p_{\mathrm {T}}\) (lower) regions corresponding to the same \(p_{\mathrm {T}}\) bins used in Fig. 3. In the high-\(p_{\mathrm {T}}\) region, \(R_{\mathrm {p}\mathrm {Pb}}\) is above unity over the whole \(y_{\mathrm {CM}}\) range. In the lower-\(p_{\mathrm {T}}\) region, a decrease of \(R_{\mathrm {p}\mathrm {Pb}}\) for increasing \(y_{\mathrm {CM}} \) is suggested. The same theoretical predictions shown in Fig. 4 are overlaid. In contrast to the measurement of \(\mathrm{J}/{\psi }\) mesons in \(\mathrm {PbPb}\) collisions [6], no significant deviation from unity is observed in the \(p_{\mathrm {T}}\) and \(y_{\mathrm {CM}}\) ranges studied here. This suggests that the strong suppression of \(\mathrm{J}/{\psi }\) production in \(\mathrm {PbPb}\) collisions is an effect of QGP formation.

The forward-to-backward ratio of \(\mathrm {p}\mathrm {Pb}\) cross sections, \(R_{\mathrm {FB}}\), in three \(y_{\mathrm {CM}}\) ranges is displayed as a function of \(p_{\mathrm {T}}\) for prompt \(\mathrm{J}/{\psi }\) mesons in Fig. 6. The \(R_{\mathrm {FB}}\) tends to be below unity at low \(p_{\mathrm {T}} \lesssim 7.5{\,\text {GeV}/{c}} \) and forward \(|y_{\mathrm {CM}} |>0.9\). In the \(6.5<p_{\mathrm {T}} <10{\,\text {GeV}/{c}} \) bin, an indication of decrease of \(R_{\mathrm {FB}}\) with increasing \(y_{\mathrm {CM}}\) is observed. The results are in agreement with the measurements from the ATLAS [23], ALICE [21, 22], and LHCb [24] collaborations.

Figure 7 shows \(R_{\mathrm {FB}}\) as a function of \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\) for prompt \(\mathrm{J}/{\psi }\) mesons in three \(y_{\mathrm {CM}}\) ranges. The data are integrated over \(6.5<p_{\mathrm {T}} <30{\,\text {GeV}/{c}} \); a lower-\(p_{\mathrm {T}}\) bin, \(5<p_{\mathrm {T}} <6.5{\,\text {GeV}/{c}} \), is shown in addition for the most forward-backward interval, \(1.5<|y_{\mathrm {CM}} |<1.93\). The value of \(R_{\mathrm {FB}}\) decreases as a function of \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\), suggesting that the effects that cause the asymmetry between the forward-to-backward production are larger in events with more hadronic activity.

Fig. 6
figure 6

Transverse momentum dependence of \(R_{\mathrm {FB}}\) for prompt \(\mathrm{J}/{\psi }\) mesons in three \(y_{\mathrm {CM}}\) regions. The vertical bars represent the statistical uncertainties and the shaded boxes show the systematic uncertainties

Fig. 7
figure 7

Dependence of \(R_{\mathrm {FB}}\) for prompt \(\mathrm{J}/{\psi }\) mesons on the hadronic activity in the event, given by the transverse energy deposited in the CMS detector at large pseudorapidities \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\). Data points are slightly shifted horizontally so that they do not overlap. The vertical bars represent the statistical uncertainties and the shaded boxes show the systematic uncertainties

4.2 Nonprompt \(\mathrm{J}/{\psi }\) mesons

Fig. 8
figure 8

Differential cross section (multiplied by the dimuon branching fraction) of nonprompt \(\mathrm{J}/{\psi }\) mesons in \(\mathrm {p}\mathrm {p}\) (left) and \(\mathrm {p}\mathrm {Pb}\) (right) collisions at forward (upper) and backward (lower) \(y_{\mathrm {CM}}\). The vertical bars (smaller than the symbols in most cases) represent the statistical uncertainties and the shaded boxes show the systematic uncertainties. The fully correlated global uncertainty from the integrated luminosity determination, 2.3% for \(\mathrm {p}\mathrm {p}\) and 3.5% for \(\mathrm {p}\mathrm {Pb}\) collisions, is not included in the point-by-point uncertainties

Fig. 9
figure 9

Rapidity dependence of the cross section (multiplied by the dimuon branching fraction) for nonprompt \(\mathrm{J}/{\psi }\) mesons in the \(p_{\mathrm {T}}\) intervals of \(6.5<p_{\mathrm {T}} <10{\,\text {GeV}/{c}} \) (circles) and \(10<p_{\mathrm {T}} <30{\,\text {GeV}/{c}} \) (squares) in \(\mathrm {p}\mathrm {p}\) (upper) and \(\mathrm {p}\mathrm {Pb}\) (lower) collisions. The vertical dashed line indicates \(y_{\mathrm {CM}} =0\). The vertical bars (smaller than the symbols in most cases) represent the statistical uncertainties and the shaded boxes show the systematic uncertainties. The fully correlated global uncertainty from the integrated luminosity determination, 2.3% for \(\mathrm {p}\mathrm {p}\) and 3.5% for \(\mathrm {p}\mathrm {Pb}\) collisions, is not included in the point-by-point uncertainties

Fig. 10
figure 10

Transverse momentum dependence of \(R_{\mathrm {p}\mathrm {Pb}}\) for nonprompt \(\mathrm{J}/{\psi }\) mesons in seven \(y_{\mathrm {CM}}\) ranges. The vertical bars represent the statistical uncertainties and the shaded boxes show the systematic uncertainties. The fully correlated global uncertainty of 4.2% is displayed as a gray box at \(R_{\mathrm {p}\mathrm {Pb}} =1\) next to the left axis

Fig. 11
figure 11

Rapidity dependence of \(R_{\mathrm {p}\mathrm {Pb}}\) for nonprompt \(\mathrm{J}/{\psi }\) mesons in two \(p_{\mathrm {T}}\) ranges: \(6.5<p_{\mathrm {T}} <10{\,\text {GeV}/{c}} \) (upper) and \(10<p_{\mathrm {T}} <30{\,\text {GeV}/{c}} \) (lower). The vertical bars represent the statistical uncertainties and the shaded boxes show the systematic uncertainties. The fully correlated global uncertainty of 4.2% is displayed as a gray box at \(R_{\mathrm {p}\mathrm {Pb}} =1\) next to the left axis

Fig. 12
figure 12

Transverse momentum dependence of \(R_{\mathrm {FB}}\) for nonprompt \(\mathrm{J}/{\psi }\) mesons in three \(y_{\mathrm {CM}}\) regions. The vertical bars represent the statistical uncertainties and the shaded boxes show the systematic uncertainties

Fig. 13
figure 13

Dependence of \(R_{\mathrm {FB}}\) for nonprompt \(\mathrm{J}/{\psi }\) mesons on the hadronic activity in the event, given by the transverse energy deposited in the CMS detector at large pseudorapidities \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\). Data points are slightly shifted horizontally so that they do not overlap. The vertical bars represent the statistical uncertainties and the shaded boxes show the systematic uncertainties

The same distributions and observables discussed in Sect. 4.1 have been investigated for the nonprompt \(\mathrm{J}/{\psi }\) meson samples. Differential cross sections are plotted as functions of \(p_{\mathrm {T}}\) and \(y_{\mathrm {CM}}\) in Figs. 8 and 9, respectively, using the same binning as for prompt \(\mathrm{J}/{\psi }\) mesons.

The measurement of \(R_{\mathrm {p}\mathrm {Pb}}\) for nonprompt \(\mathrm{J}/{\psi }\) mesons shown in Fig. 10 as a function of \(p_{\mathrm {T}}\) is compatible with unity in all \(y_{\mathrm {CM}}\) bins. The somewhat larger uncertainties, however, make it difficult to draw firm conclusions for the nonprompt \(\mathrm{J}/{\psi }\) production. The \(y_{\mathrm {CM}}\) dependence of nonprompt \(\mathrm{J}/{\psi }\) \(R_{\mathrm {p}\mathrm {Pb}}\) integrated in the low- and high-\(p_{\mathrm {T}}\) regions is shown in Fig. 11. In all \(y_{\mathrm {CM}}\) bins, \(R_{\mathrm {p}\mathrm {Pb}}\) is consistent with unity although the data hint at a rapidity dependence for \(R_{\mathrm {p}\mathrm {Pb}}\) in the low \(p_{\mathrm {T}}\) region, as found in the prompt \(\mathrm{J}/{\psi }\) meson production (Fig. 5).

Figures 12 and 13 show the \(p_{\mathrm {T}}\) and \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\) dependence of nonprompt \(\mathrm{J}/{\psi }\) \(R_{\mathrm {FB}}\), respectively. The \(R_{\mathrm {FB}}\) ratios seem to increase slightly with \(p_{\mathrm {T}}\) from \({\sim }0.8\pm 0.1\) to \({\sim }1.0\pm 0.1\) in all \(y_{\mathrm {CM}}\) bins. The results are consistent with those from the ATLAS [23] and LHCb [24] collaborations within uncertainties. As seen for prompt \(\mathrm{J}/{\psi }\) meson production, \(R_{\mathrm {FB}}\) for nonprompt \(\mathrm{J}/{\psi }\) meson production decreases with \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\), indicating the presence of different nuclear effects at forward than at backward \(y_{\mathrm {CM}}\) in the regions with the greatest event activity.

5 Summary

Proton–proton (\(\mathrm {p}\mathrm {p}\)) and proton–lead (\(\mathrm {p}\mathrm {Pb}\)) data at \(\sqrt{s_{\mathrm {NN}}} =5.02\,\text {TeV} \) collected with the CMS detector are used to investigate the production of prompt and nonprompt \(\mathrm{J}/{\psi }\) mesons and its possible modification due to cold nuclear matter effects. Double-differential cross sections, as well as the nuclear modification factor \(R_{\mathrm {p}\mathrm {Pb}}\) and forward-to-backward production ratio \(R_{\mathrm {FB}}\), are reported as functions of the \(\mathrm{J}/{\psi }\) \(p_{\mathrm {T}}\) and \(y_{\mathrm {CM}}\).

The \(R_{\mathrm {p}\mathrm {Pb}}\) values for prompt \(\mathrm{J}/{\psi }\) mesons are above unity in mid- and backward \(y_{\mathrm {CM}}\) intervals analyzed (\(-2.4<y_{\mathrm {CM}} <0.9\)), with a possible depletion in the most forward bin at low \(p_{\mathrm {T}} \lesssim 7.5{\,\text {GeV}/{c}} \). In the case of nonprompt \(\mathrm{J}/{\psi }\) meson production, \(R_{\mathrm {p}\mathrm {Pb}}\) is compatible with unity in all \(y_{\mathrm {CM}}\) bins. The prompt \(\mathrm{J}/{\psi }\) \(R_{\mathrm {FB}}\) is below unity for \(p_{\mathrm {T}} \lesssim 7.5{\,\text {GeV}/{c}} \) and forward \(|y_{\mathrm {CM}} |>0.9\), but is consistent with unity for \(p_{\mathrm {T}} \gtrsim 10{\,\text {GeV}/{c}} \). For nonprompt \(\mathrm{J}/{\psi }\) mesons, \(R_{\mathrm {FB}}\) tends to be below unity at \(p_{\mathrm {T}} \lesssim 7.5{\,\text {GeV}/{c}} \) and increases for higher \(p_{\mathrm {T}}\), but with slightly larger uncertainties. The dependence of \(R_{\mathrm {FB}}\) on the hadronic activity in \(\mathrm {p}\mathrm {Pb}\) events has been studied through the variable \(E_{\mathrm {T}}^{{\mathrm {HF}}|\eta |>4}\), characterizing the transverse energy deposited in the CMS detector at large pseudorapidities \(4<|\eta |<5.2\). The \(R_{\mathrm {FB}}\) ratio is observed to decrease with increasing event activity for both prompt and nonprompt \(\mathrm{J}/{\psi }\) mesons, indicating enhanced nuclear matter effects for increasingly central \(\mathrm {p}\mathrm {Pb}\) collisions.

A depletion of prompt \(\mathrm{J}/{\psi }\) mesons in \(\mathrm {p}\mathrm {Pb}\) collisions (as compared to \(\mathrm {p}\mathrm {p}\) collisions) is expected in the forward \(y_{\mathrm {CM}}\) region because of the shadowing of nuclear parton distributions and/or coherent energy loss effects. Such a suppression is observed in the measurements presented in this paper at \(y_{\mathrm {CM}} >1.5\) and \(p_{\mathrm {T}} \lesssim 7.5{\,\text {GeV}/{c}} \), but not at larger \(p_{\mathrm {T}}\), consistent with the expected reduced impact of nuclear parton distributions and coherent energy loss effects for increasing \(\mathrm{J}/{\psi }\) \(p_{\mathrm {T}}\). At negative \(y_{\mathrm {CM}}\), both shadowing and energy loss effects are known to lead to small nuclear modifications, as confirmed by the present measurements. Such processes are also expected to affect the nuclear dependence of \({\mathrm {B}}\) hadron production and thereby, through its decays, nonprompt \(\mathrm{J}/{\psi }\) production. The measurements presented here provide new constraints on cold nuclear matter effects on prompt and nonprompt \(\mathrm{J}/{\psi }\) production over a wide kinematic range.