a, Schematic of strategy for monitoring neuronal activity in mPFC–dPAG and mPFC–NAc neurons using in vivo calcium imaging. b, Representative confocal images of mPFC–NAc::GCaMP6m (left) and mPFC–dPAG::GCaMP6m neurons (right) underneath GRIN lenses (dashed lines). c, Dynamic calcium fluctuations were monitored during a 15-min recording session in which mice were allowed to self-administer sucrose via a sucrose lickometer or had random, unsignalled foot shocks delivered. d, As a population, mPFC–dPAG::GCaMP6m (n = 6 mice) were activated to foot shock (green, two-tailed paired t-test, t 5 = 2.616, *P = 0.0473) or inhibited by the initiation of a sucrose bout (purple, two-tailed paired t-test, t 5 = 6.982, ***P = 0.0009) as measured by the bulk fluorescence across the entire FOV (−3 to 0 s, pre-shock/sucrose; 0–3 s, shock/sucrose). e, As a population, mPFC–NAc::GCaMP6m (n = 5 mice) were not responsive to foot shock (green, two-tailed paired t-test, t 4 = 0.1520, P = 0.8866) or the initiation of a sucrose bout (purple, two-tailed paired t-test, t 4 = 0.2678, P = 0.8021) (−3 to 0 s, pre-shock/sucrose; 0–3 s, shock/sucrose). f, mPFC–dPAG::GCaMP6m and mPFC–NAc::GCaMP6m mice did not differ in the number of lick bouts initiated during the sucrose session. Two-tailed unpaired t-test, t 9 = 0.1666, P = 0.8714. g, Peak-to-noise heat map generated from a representative FOV with seed pixels overlaid (black X). h, mPFC–dPAG::GCaMP6m neurons (n = 118 ROIs) had more frequent calcium transients than mPFC–NAc::GCaMP6m neurons (n = 169 ROIs) during the shock session. Number of events difference score (shock − sucrose): dPAG Mdn, 51.5; NAc Mdn, −6. Two-tailed Mann–Whitney test, U = 5,840, ***P < 0.0001. i, mPFC–dPAG::GCaMP6m neurons had higher amplitude transients than mPFC–NAc::GCaMP6m neurons during the shock session. Amplitude of events difference score (shock − sucrose): dPAG Mdn, 0.9031; NAc Mdn, −0.3549. Mann–Whitney test, U = 6,672, ***P < 0.0001. j, Dendrogram of agglomerative hierarchical clustering. Different colours represent clusters based on average responses per ROI to footshock and sucrose. k, Histologically verified locations of GRIN lens implants. l–ac, In addition to using CNMF-E, imaging data were analysed using two other approaches: 1) a modified constrained CNMF-E algorithm considering calcium fluctuations can have negative transients, associated with a decrease in firing24,55 (for the approach, we did not constrain temporal components to >0) and 2) a ROI-based method (that is, ‘non-ROI’, r–ac). l, m, Calcium signals were extracted from individual ROIs and the average calcium traces per ROI were aligned to shock and sucrose bout onset for mPFC–NAc::GCaMP6m (l) and mPFC–dPAG::GCaMP6m recordings (m). n, The distribution of shock- and sucrose-excited cells for mPFC–dPAG::GCaMP6m neurons was different from mPFC–NAc::GCaMP6m neurons. χ2 = 10.95, **P = 0.0042. o, Representative calcium traces from a mPFC–dPAG::GCaMP6m neuron during shock (top) and sucrose (bottom) recording sessions. Individual calcium transients (yellow dots) were identified and quantified. p, mPFC–dPAG::GCaMP6m neurons (n = 118 ROIs) had more frequent calcium transients than mPFC–NAc::GCaMP6m neurons (n = 169 ROIs) during the shock session. Number of events difference score (shock − sucrose): dPAG Mdn, 43; NAc Mdn, −3. Two-tailed Mann–Whitney test, U = 4,373, ***P < 0.0001. q, mPFC–dPAG::GCaMP6m neurons had higher amplitude calcium transients compared to mPFC–NAc::GCaMP6m neurons during the shock session. Amplitude of events difference score (shock − sucrose): dPAG Mdn, 1.329; NAc Mdn, −0.2459. Two-tailed Mann–Whitney test, U = 7,164, ***P < 0.0001. r, Mean t-projection image of the entire FOV through the relay lens after image pre-processing. Recordings were converted to changes in fluorescence compared to background fluorescence (F − F 0 )/F 0 using the mean t-projection image as reference (F 0 ). s, Calcium signals arising from ROIs were identified using independent and principal component analyses (PCA/ICA). t, Identified PCA/ICA filters were thresholded at their half-maximum values to define possible ROIs and were screened for neuronal morphology. ROIs were only accepted if the threshold filters included only on contiguous region with an eccentricity of <0.85 and an area between 30–350 pixels. In this example, 61 ROIs (of the original 150 independent components (ICs)) met these criteria. u, Accepted ROI filters were then merged if their areas overlapped by more than 60%. In this example, 24 ROIs were merged for a remaining total of 37 valid ROIs. v, To acquire the non-ROI thresholded image for background subtraction, max z projections of individual recordings were created and thresholded to separate ROIs and their processes from the rest of the FOV. Average signal from the remaining pixels was used as a proxy for the whole-field changes in fluorescence, and regressed from the signal extracted from each ROI. w, x, Calcium transients (yellow dots) within individual mPFC–dPAG::GCaMP6m neurons (w) and mPFC–NAc::GCaMP6m neurons (x) were quantified (representative traces). y, mPFC–dPAG::GCaMP6m neurons (n = 113 of 118 ROIs) had more frequent calcium transients than mPFC–NAc::GCaMP6m neurons (n = 157 ROIs) during the shock session. Difference score (shock − sucrose): dPAG Mdn, 30; NAc Mdn, 6. Two-tailed Mann–Whitney test, U = 6,392, ***P < 0.0001. z, mPFC–dPAG::GCaMP6m neurons had calcium transients of larger amplitude than mPFC–NAc::GCaMP6m neurons during the shock session. Difference score (shock − sucrose): dPAG Mdn, 0.5158; NAc Mdn, −0.0615. Two-tailed Mann–Whitney test, U = 7,065, **P = 0.0044. aa, ab, Average calcium traces per cell for mPFC–dPAG::GCaMP6m neurons (aa) and mPFC–NAc::GCaMP6m neurons (ab) were aligned to shock (left) and sucrose bout (right). ac, The distribution of shock- and sucrose-excited cells for mPFC–dPAG::GCaMP6m (n = 118 ROIs) neurons was different from that for mPFC–NAc::GCaMP6m neurons (n = 157 ROIs). χ2 = 32.33, ***P < 0.0001. Error bars and ‘+’ indicate s.e.m. Scale bar, 100 μm. The mouse brains in this figure were reproduced with permission from Paxinos and Franklin, 200454.