Repository navigation
Conversation
…h for lookup bins
oksuzian
left a comment
There was a problem hiding this comment.
PR Review Summary — #2145
Reviewed at head c8575b8d15f20bc4cd14e38947e957aa8e68d331. First pass.
Decision
-
🟡 comment now, approve when green. I would approve this code.
- The binomial draw is exact: it matches the binomial distribution in every case I tested.
- The binary search returns exactly what the linear scan returned.
- With
binomialArrivals: falsethe output is bit-identical tomain. - With the default, the CRV response on 10,000 off-spill cosmics agrees with
mainas closely asmainagrees with itself under a new seed, andCrvPhotonsruns 8 times faster.
Two small items do not block (finding 1). FNALbuild has not run on this PR: there is no status and no FNALbuild comment at this head (checked 17:47 UTC). I am triggering it and will approve once the build at
c8575b8dis green.
Scope understood
MakeCrvPhotons::MakePhotonsdraws, for each sub-step, photon type and SiPM, the number of arriving photons from a binomial distribution (MakeCrvPhotons.cc:396-411). It then gives only the arriving photons their times, in the newAddArrivingPhoton, which uses the same draws as before.GetNumberOfArrivals(:522-539) samples by inversion. It falls back toCLHEP::RandBinomialonly where(1-p)^nwould underflow.- The new
CrvPhotonGeneratorparameterbinomialArrivals(defaulttrue,CrvPhotonGenerator_module.cc:78) switches this on.
LookupBinDefinitions::findBinusesstd::lower_bound(:121-130). This part is always on.
Findings
- ⚪ [S3] Small items.
- The default lives only in C++ (
fhicl::Atom<bool> binomialArrivals{..., true},:78), and no prolog sets it.- Every versioned configuration therefore switches algorithm with no fcl change:
prolog_v03toprolog_v12and theepilog_extracted_v0*files. - A job that reproduces an older production with its matching prolog now gets different, statistically equivalent, CRV output.
- Setting
binomialArrivals : trueinprolog_v12.fcl, with no C++ default, would keep the choice in the configuration, as the module's other parameters are.
- Every versioned configuration therefore switches algorithm with no fcl change:
- The description still has a placeholder: "In the mixed sample all non-CRV products are identical. [mixed CRV digi result]".
- The default lives only in C++ (
Checked, no action needed
-
🟢 The binomial draw is the same distribution as one draw per photon.
- Within one sub-step and type, every created photon has the same bin and therefore the same probability. The count of arrivals is then Binomial(N, p).
- Each arriving photon gets its time from the same code as before.
- The order is unchanged: scintillation photons first, then Cherenkov.
- p ≥ 1 and p ≤ 0 give N and 0 arrivals, as before.
- The flag reaches shared
MakeCrvPhotonsinstances too: it is set on each new instance before sectors share it.
-
🟢 The sampler is exact. I copied
GetNumberOfArrivalsand drew 4M times each on CLHEPMixMaxRng, against the exact Binomial(n, p) probabilities:(n, p) χ²/ndf mean pull (10, 1e-4) 3.0/2 −1.2 (50, 1e-4) 0.8/3 +0.7 (200, 1e-4) 1.2/4 +0.4 (500, 1e-3) 9.8/7 −2.0 (2000, 3e-4) 3.6/8 −0.5 (300, 0.01) 11.5/15 +0.9 (40, 0.2) 21.7/22 −1.4 (20, 0.7) 11.1/17 −0.8 Your note on
CLHEP::RandBinomialis right. In the same test it never returned a non-zero value at (10, 1e-4) or (50, 1e-4), and it is 2.2 % low at (200, 1e-4) (pull −5.8). Keeping it only for n p above about 700 is the right choice. Nothing else in Offline calls it. -
🟢
findBinis exact.- All 14
CRVConditions/v6_0lookup tables load into a check program. These are the only tablesprolog_v12,epilog_run1a_v01andepilog_extracted_v05load, andLoadLookupTablerejects anything but version 6. - All 98 bin-edge vectors are strictly ascending.
- On 19.6M probes, the old linear scan and the new search give the same bin and the same not-found flag every time. The probes are every edge, each edge ±1 ulp, every bin centre, 200k random values per vector extending 10 % beyond the range, and NaN.
- All 14
-
🟢 With
binomialArrivals: false, bit-identical tomain.mainis the CI build152833a9. The PR is this head merged on152833a9together with #2142. Products were dumped withPrintModule.- Off-spill cosmics: Production
digitize/OffSpill.fclplus CRV reco, 10,000CosmicCRYAllMDC2025ap events.CrvDigis,CrvDigiMCs,CrvRecoPulses,CrvCoincidenceClustersandCaloDigisare identical in every event. - On-spill CE, 1,000 events, and FNALbuild's
ceMixandceDigi: all products identical.
- Off-spill cosmics: Production
-
🟢 With the default, statistically equal to
main. Same 10,000 cosmic events, paired per event. The control ismainagainstmainwith only the seed changed (baseSeed9 instead of 8):this PR vs maincontrol reco pulses per event z −0.37 z +0.72 pulse PE per event +0.12 ± 0.33 (z +0.38) z −0.32 digis per event z +0.85 z −0.74 ADC sum per event z +0.83 z −0.61 coincidence clusters per event z −0.59 z +0.88 cluster PE per event z +0.20 z +0.07 events with a coincidence z −0.75 z +0.75 pulse PE spectrum, χ²/ndf (KS p) 184/195 (0.69) 200/195 (0.96) pulse height spectrum 161/194 (0.85) 173/194 (0.63) pulse times after the first pulse 154/130 (0.15) 136/129 (0.58) cluster PE spectrum 120/121 (0.82) 98/123 (0.97) mean PE per pulse, per channel (≥ 20 pulses) 1.0047 ± 0.0013 1.0023 ± 0.0013 - The per-channel ratio of means is biased slightly above 1 for any two independent samples, as the control shows. The difference between the two columns is 1.3σ.
- On FNALbuild's
ceMix, the calorimeter and all straw-digi collections stay identical. The CRV digis differ in the one event that has any.
-
🟢 Timing.
mainand this PR ran at the same time on the same node, 3,000 cosmic events; TimeTracker means:mainfalsedefault CrvPhotons14.1 ms 13.9 ms 1.76 ms full event (digitisation + CRV reco) 24.2 ms 23.5 ms 11.5 ms
Validation check
- Build/tests run: yes. A
muse buildof this head merged with #2142 on152833a9(p110) exited with status 0 and no warnings. All the jobs above exited with status 0. - Config contract check: pass. The new parameter is validated; see finding 1 for where its default lives.
- Cross-repo consistency: pass. No Production or other repository sets the parameter. This PR merges cleanly with #2142.
Residual risk
- My cosmic sample has the off-spill configuration, which turns CRV thermal noise off, and its clusters are all sector type 1. I did not run the extracted geometry; your validation covers it. I did not run on-spill with real CRV activity: the CE sample has no CRV digis, and
ceMixhas 3 in 53 events. - When
(1-p)^nis just above the underflow limit, the inversion stops as soon as a term underflows. The mass this can misplace is at most about 1e-15 per draw.
Author follow-ups
- Optional: finding 1.
|
@FNALbuild run build test |
|
☀️ The build tests passed at c8575b8.
N.B. These results were obtained from a build of this Pull Request at c8575b8 after being merged into the base branch at fb72055. For more information, please check the job page here. |
|
@FNALbuild run build test |
1 similar comment
|
@FNALbuild run build test |
…e in prolog_v12 Older CRVResponse prologs keep the per-photon draw, bit-identical to main; current configurations, which include prolog_v12, get the binomial arrivals.
oksuzian
left a comment
There was a problem hiding this comment.
PR Review Summary — #2145
Reviewed at head 67228d5358fe9306b4924b5dd2d5445585940c4c. Re-review of c8575b8.
Decision
- 🟡 comment now, approve when green. The new commit settles my nit about where the default lives, and current jobs behave exactly as at
c8575b8d. FNALbuild has not built this head (nomu2e/buildtestresult at 03:20 UTC), so I am requesting a build and will approve once it is green.
What changed since c8575b8
- One commit,
67228d5"CRVResponse: binomialArrivals defaults to false in C++ and is set true in prolog_v12" (+2 −1). Not a rebase.CrvPhotonGenerator_module.cc:78: thebinomialArrivalsdefault goes fromtruetofalse.prolog_v12.fcl:94setsbinomialArrivals : trueinside theCrvPhotonstable.
Prior findings (from my review at c8575b8d)
- 🟢 [was ⚪ S3, first item] The default lived only in C++, so every versioned prolog switched algorithm with no fcl change. ADDRESSED.
prolog_v03toprolog_v11now keep the per-photon draws, so a job that reproduces an older production with its matching prolog gets the old CRV output again.prolog.fclincludesprolog_v12.fcl, so every current job still runs the binomial draw. That covers Production's digitization, mixing and cosmic jobs, which only override otherCrvPhotonsparameters. Current output is therefore what I validated atc8575b8d.- I had suggested no C++ default at all. With
falseas the default, the old prologs need no edits, which is a fair choice.
- 🟢 [was ⚪ S3, second item] The placeholder in the description is filled: the mixed-sample CRV digis change by −0.02 ± 0.07 per event (z −0.25), and TrigReport is identical.
Validation check
- Build/tests run: no new jobs. The commit moves a default and sets it in the current prolog, which I checked by reading the diff and
prolog_v12.fclat this head. My runs atc8575b8dcover both settings: the default distribution study withtrue, and bit-identity tomainwithfalse. - Config contract check: pass.
- Cross-repo consistency: pass. No Production config includes an older
CRVResponseprolog, and none setsbinomialArrivals.
|
@FNALbuild run build test |
1 similar comment
|
@FNALbuild run build test |
|
⌛ The following tests have been triggered for 67228d5: build (already triggered: build) (Build queue - API unavailable) |
|
☀️ The build tests passed at 67228d5.
N.B. These results were obtained from a build of this Pull Request at 67228d5 after being merged into the base branch at 30088f3. For more information, please check the job page here. |
oksuzian
left a comment
There was a problem hiding this comment.
PR Review Summary — #2145
Reviewed at head 67228d5358fe9306b4924b5dd2d5445585940c4c. Follow-up to my comment review at the same head.
Decision
- 🟢 approve. FNALbuild build 3602 has now built this head, merged on
main30088f39, and every test passed: the prof build, all eleven validation jobs,rootOverlaps,g4surfaceCheck,trigger,check_cmakeand the whitespace check. The FIXME/TODO count and clang-tidy rows are informational; the one clang-tidy error is in cetlib'sLibraryManager.h, not in this PR. This is the approval my comment review promised once the build was green.
|
Closing this as redundant with #2150 |
Background
These optimizations were first implemented as part of the GPU-accelerated fastsim project (https://github.com/RobMina/mu2e-fastsim). The same ideas work on CPU, as shown below.
This PR does not preserve bit-identical output when binomialArrivals: true is set (which is the default). Reviewers, please double check that the CRV response simulation outputs are equivalent with and without binomialArrivals. The validation procedure I used is described below.
What
MakeCrvPhotons::MakePhotonscreates N photons per 0.1 mm sub-step and photon type. It then draws one uniform percreated photon and keeps the photon with the bin's arrival probability p. A bar crossing creates of order 10^5
photons, and only tens arrive, so almost every draw rejects a photon.
CrvPhotonsis most of the CRV response CPU.This PR makes two changes.
CrvPhotonGeneratorparameterbinomialArrivals, defaulttrue). Per sub-step,photon type and SiPM, the number of arriving photons is drawn as Binomial(N, p). That is the same distribution as
N Bernoulli trials. Only the photons that arrive then get their arrival times, through the same code as before,
now factored into
AddArrivingPhoton. p ≥ 1 gives N arrivals and p ≤ 0 gives none, as before.MakeCrvPhotons::GetNumberOfArrivals, an inversion sampler using one uniform per draw. It is exactat any n p and takes about n p + 1 steps.
CLHEP::RandBinomialis not used in the CRV regime. In CLHEP 2.4.7.1 it is biased low at small n p. Over 1Mdraws it returns exactly 0 at (n, p) = (10, 1e-4) and (50, 1e-4), and is 1-2 % low at (200, 1e-4). A first
version of this PR that used it gave 0.5 % fewer PE on cosmics.
RandBinomialremains only as a fallback where the probability of no arrival would underflow (n p above about700); it is accurate there.
LookupBinDefinitions::findBin(always on). It usesstd::lower_boundover the ascending binedges. A value on an inner edge goes to the lower bin, and a value outside [front, back] (or NaN) is "not found",
as with the linear scan it replaces. This change is exact.
With
binomialArrivals: false, the per-photon loop and its random sequence are those of main.Files:
CRVResponse/inc/MakeCrvPhotons.hh,CRVResponse/src/MakeCrvPhotons.cc,CRVResponse/src/CrvPhotonGenerator_module.cc.Validation
The reference is Offline main
ca7b6580(the CI build), with the same Production and mu2e-trig-config commits in botharms.
binomialArrivals: false: bitwise identical to main.CeMLeadingLog.MDC2025apevents with the four pileup streams: identical in everyevent, and TrigReport is identical.
CosmicCRYExtracted.MDC2025asevents: CRV digis,digi MC, reco pulses and coincidence clusters are identical.
binomialArrivals: true(default): statistically equal to main. The test sample is the same 10,000 cosmic events,paired per event. The control is main against main with only the seed changed. The PR's values:
Coincidence counts agree for all four sector types (|z| ≤ 0.05). In the mixed sample all non-CRV products are
identical. CRV digis per event change by -0.02 ± 0.07 (z -0.25), and TrigReport is identical. With
binomialArrivals: false, after the final build, the 10,000 cosmic events are again bitwise identical to main.Performance
Both arms ran on the same host, in two repeats alternating base and PR. Times are art TimeTracker means.
CrvPhotons, cosmic (10,000 events)CrvPhotons, Mix1BB (1,000 events)The binary search alone (
binomialArrivals: false) givesCrvPhotons0.97 on cosmics.🤖 Generated with Claude Code