Back to home page

EIC code displayed by LXR

 
 

    


Warning, /irt/log/MEMO-v00.txt is written in an unsupported language. File is not indexed.

0001 ================================================================================
0002 MEMO-v00  --  fresh measurement protocol for the PFRICH benchmark
0003 ================================================================================
0004 Replaces TAGS.txt as the working ledger (TAGS.txt is abandoned, left on disk
0005 untouched). Every number quoted in this file names the IRT ref it came from.
0006 
0007 --------------------------------------------------------------------------------
0008 1. WHAT IS BEING MEASURED
0009 --------------------------------------------------------------------------------
0010 Performance (wall time) and PID quality of the PFRICH IRT reconstruction as a
0011 function of
0012   (a) the IRT version: v2.2.3 (upstream) and the local milestones
0013       v2.2.3a1 ... v2.2.3a8,
0014   (b) the number of charged tracks per event: 1, 2, 3, 5.
0015 
0016 THE RADIX BUG IS FIXED IN EVERY VERSION BEFORE MEASUREMENT (see section 4), so
0017 all numbers are comparable and none of them is contaminated by the wrong
0018 [particle -> hypothesis] combination index. Each version is therefore measured
0019 as "fix/<tag>", a branch created at that tag with only the fix on top.
0020 
0021 --------------------------------------------------------------------------------
0022 2. SAMPLES (generated with the macro as it is NOW)
0023 --------------------------------------------------------------------------------
0024 Generator: hepmc-writer-multiple-tracks.C, current signature
0025   hepmc_writer_multiple_tracks(fname, n_events, n_tracks,
0026                                pmin, pmax, etamin, etamax, phimin, phimax)
0027 PDG per track is drawn at random: particles[rdmn_gen->Integer(_PDIM_)] with
0028 particles = {211 pi+-, 321 K+-, 2212 proton} (the earlier deterministic
0029 `itrack%2` line is commented out), TRandom seed 0x12345678, p uniform,
0030 phi uniform.
0031 
0032   root -l -q 'hepmc-writer-multiple-tracks.C("benchN.hepmc", 1000, N,
0033                                              7.0, 7.0, -2.5, -2.5, 0, M_PI/6)'
0034   N = 1, 2, 3, 5   ->  bench1.hepmc bench2.hepmc bench3.hepmc bench5.hepmc
0035   (1000 events generated; 500 are simulated and reconstructed)
0036 
0037 --------------------------------------------------------------------------------
0038 3. SIMULATION AND RECONSTRUCTION COMMANDS (exactly as in BUG.txt)
0039 --------------------------------------------------------------------------------
0040 npsim:
0041   npsim --runType run \
0042         --compactFile $EIC_SHELL_PREFIX/share/epic/epic_tracking_and_pfrich.xml \
0043         --outputFile ./sim.benchN.root --part.userParticleHandler= \
0044         --inputFiles ./benchN.hepmc -N 500
0045 
0046 eicrecon:
0047   $EIC_SHELL_PREFIX/bin/eicrecon -Pplugins="janadot" \
0048     -Pdd4hep:xml_files=$EIC_SHELL_PREFIX/share/epic/epic.xml \
0049     -Ppodio:output_collections="PFRICHHits,MCParticles,PFRICHTracks,PFRICHIrtRadiatorInfo,PFRICHIrtParticles" \
0050     -Peicrecon:LogLevel="info" -Pjana:timeout=180 -Pjana:warmup_timeout=180 \
0051     -Pjana:nevents="500" -Pjana:debug_plugin_loading="1" \
0052     -Pacts:MaterialMap="calibrations/materials-map.cbor" \
0053     -Pplugins_to_ignore=LUMISPECCAL,LOWQ2,FOFFMTRK,RPOTS,B0TRK,ZDC,B0ECAL,FHCAL,BHCAL,EHCAL,FEMC,BEMC,EEMC,PFRICH,DIRC \
0054     -Ppodio:output_file="rec_<ref>_<N>tr.root" sim.benchN.root \
0055     -PPFRICH:config=pfrich-reco.json
0056 
0057 Difference from BUG.txt: -Pjana:nevents="500" instead of "0" (which there means
0058 "all 1000 generated"); fixed at 500 per run as required. Everything else
0059 verbatim, single-threaded, ONE measured run per setting, no averaging.
0060 
0061 WARM-UP (added 2026-11-15, mandatory for every future benchmark): before each
0062 measured run there is a one-event warm-up run of the same command
0063 (-Pjana:nevents="1", output warm_<ref>_<N>tr.root and its log, both discarded
0064 afterwards; the pfrich.root it writes is discarded too). It exists only to put
0065 every ref in the same cache state (DD4hep/GField/ACTS lookups, file pages); it
0066 is NOT part of any measured number. Implemented in runbench.sh.
0067 
0068 --------------------------------------------------------------------------------
0069 4. THE RADIX BUG AND ITS FIX (applied to every measured ref)
0070 --------------------------------------------------------------------------------
0071 Symptom (BUG.txt): reordering "IdentifiedParticles" from ["pi+","proton","K+"]
0072 to ["pi+","K+","proton"] destroyed PID for ~50% of tracks, although a
0073 reordering must be a pure relabeling.
0074 
0075 Cause: the [particle -> hypothesis] combination index is ENCODED with radix
0076 hdim (`for(...) cdim *= hdim;` i.e. cdim = hdim^pdim) but DECODED with radix
0077 = number of particles:
0078       unsigned hypo = id%hdim;  ...  id /= Event()->ChargedParticles().size();
0079 Correct only when hdim == pdim (or pdim == 1). Otherwise the scan evaluates a
0080 subset of the hdim^pdim assignments, several times over, and never considers
0081 the rest -- possibly including the true one:
0082       pdim=2 hdim=3 : 9 iterations -> 6 distinct, missing (0,2),(1,1),(2,0)
0083       pdim=3 hdim=2 : 8 -> 4 ; pdim=5 hdim=3 : 243 -> 54 ; pdim=5 hdim=2 : 32 -> 8
0084 Secondary effect: the calibration-pass filter (`goto _next_combination`) can
0085 never find the truth-matching combination when it is one of the missing ones,
0086 so that pass is silently skipped.
0087 
0088 Fix: divide by hdim.
0089   source/ReconstructionFactory.cc
0090     qid /= hdim;                      (calibration-pass filter)
0091     id  /= hdim;                      (the combination scan)
0092     id  /= hdim;                      (final PID decode)
0093     id  /= hdim;                      (v2.2.3a4 only: MixtureLnL decode of ic)
0094     id  /= hdim;                      (v2.2.3a5+: hypoBest decode for the
0095                                        chi^2 branch)
0096 
0097 Refs measured: fix/v2.2.3, fix/a1 ... fix/a8 -- branch created at the tag, the
0098 fix applied on top, nothing else. Commit ids are recorded next to the numbers.
0099 
0100 --------------------------------------------------------------------------------
0101 5. BASELINE CONFIGURATION (pfrich-reco.json exactly as on disk)
0102 --------------------------------------------------------------------------------
0103   Calibration                       pfrich-calibration.json
0104   OutputRootFile                    pfrich.root
0105   WriteOutputTree                   no
0106   UsePoissonTermInChiSquare         yes        <- Poisson yield term ON
0107   UseTimingInChiSquare              yes
0108   DefaultSinglePhotonThetaResolution 0.005
0109   SinglePhotonTimingResolution      0.050 ps
0110   SingleHitCCDFcut                  0.001
0111   RemoveAmbiguousHits               no         <- ownership resolved, hits kept
0112   SensorActiveAreaPixellation       32
0113   UseMcTruthPhotonDirectionSeed     yes        <- truth photon seeds ON
0114   MinHitCountCutoff                 5
0115   IdentifiedParticles               ["pi+","K+","proton"]   (hdim = 3)
0116   CombinedEvaluationPlots           store      (was "display" until 15:33)
0117   Acceptance eta                    [-3.51, -1.49]
0118   Radiators: Aerogel imaging yes (acts-planes 5, evaluation-plots "store",
0119              cherenkov-angle-range [200,290], photon-vertex-range
0120              [-1275,-1240], refractive-index-range [1.035,1.045]);
0121              Acrylic imaging no
0122   Re-read 2026-11-15 15:33: the only changes vs the previous baseline are
0123   CombinedEvaluationPlots and Aerogel evaluation-plots, both now "store".
0124   No physics effect (visualization only), but it means every run now writes
0125   the same "pfrich.root" (OutputRootFile) -- runbench.sh therefore archives
0126   it per (ref,N) as pfrich_<ref>_<N>tr.root, otherwise the plots of earlier
0127   runs are silently clobbered. The 2-track run recorded in section 10 was
0128   done under "display", so it left no plot file.
0129   Photosensor: QE table 160-660 nm, rescaling factor 0.81
0130 
0131 Note: ["pi+","K+","proton"] is one of the two orders the radix bug broke, so
0132 the unfixed numbers are the bad ones; with the fix applied the order of
0133 IdentifiedParticles must not matter.
0134 
0135 --------------------------------------------------------------------------------
0136 6. WHAT IS RECORDED FOR EVERY (ref, N) RUN
0137 --------------------------------------------------------------------------------
0138   - wall time [s] and jana's "Final report: N events at X Hz"
0139   - number of PFRICHIrtParticles, PDG content, pion efficiency, kaon mis-ID
0140   - mean npe and mean nhits per IRT particle, sum npe / sum nhits
0141   - number of PFRICHHits in the event (pool size)
0142   - run log file name and rec file name
0143 ================================================================================
0144 
0145 --------------------------------------------------------------------------------
0146 7. EXTRA PATCHES NOW PART OF EVERY BENCHMARK BUILD  (added 2026-11-15)
0147 --------------------------------------------------------------------------------
0148 On top of the radix fix, every measured ref carries the two experimental
0149 changes that used to live only in v2.2.3a8, applied by
0150   apply-bench-patches.py  (idempotent; aborts if an anchor is missing)
0151   1) #define _EXPECTED_BG_PHOTON_COUNT_  ( 0.1 )
0152      -> the event chi^2 gets a Poisson term for hits that no track
0153         hypothesis claims (nbg, +1 degree of freedom), active when hdim >= 2
0154         (hdim = 3 here, so it is ACTIVE).
0155   2) the photon yield coefficient of the Aerogel radiator, now a CONFIG option
0156      (see section 11): pfrich-calibration.json carries
0157          "Radiators": { "Aerogel": { "YieldCff": 160.0, ... } }
0158      and ReconstructionFactory::JsonParser() assigns
0159          radiator->m_YieldCff = YieldCff;  and  m_DetectedToCalibrationPhotonRatio = 1.0;
0160      in the same per-radiator clause that reads "theta-bins". ACTIVE because the
0161      baseline config has "UsePoissonTermInChiSquare": "yes". Caveat: a calibration
0162      pass re-derives both quantities in Calibration::UpdateYields(), so the key
0163      pins them for the reconstruction proper; and under "Estimator":"ml" the chi^2
0164      Poisson term (where the yield is used) is not evaluated at all -- the ML
0165      lambda uses m_YieldCff times the per-event fitted scale s_r (a7 up).
0166 
0167 --------------------------------------------------------------------------------
0168 8. MEASURED REFS: branch = tag + radix fix + the two patches above
0169    (the commit ids below are SUPERSEDED by section 11 -- head commits are there)
0170 --------------------------------------------------------------------------------
0171   (branch created at the tag, one commit on top; each compiled with
0172    cmake --build -j 24 against the local IRT2 build tree; the EICrecon
0173    RICH-IRT plugin is rebuilt + reinstalled per ref at run time)
0174 
0175   ref                commit     radix sites fixed        patches present
0176   bench/v2.2.3       e9c4ead    qid/=hdim x1, id/=hdim x3   define + yield
0177   bench/v2.2.3a1     d8e54ab    qid/=hdim x1, id/=hdim x3   define + yield
0178   bench/v2.2.3a2     a6e28f0    + ic decode (MixtureLnL)    define + yield
0179   bench/v2.2.3a3     a14507e    + ic decode (MixtureLnL)    define + yield
0180   bench/v2.2.3a4     b7197f7    + ic decode (MixtureLnL)    define + yield
0181   bench/v2.2.3a5     6954924    + hypoBest decode          define + yield
0182   bench/v2.2.3a6     d7a3eb1    + hypoBest decode          define + yield
0183   bench/v2.2.3a7     e701541    + hypoBest decode          define + yield
0184   bench/v2.2.3a8     05698d0    + hypoBest decode          (already in tag)
0185 
0186   Verified for all nine: 0 remaining occurrences of
0187   `/= Event()->ChargedParticles().size();` and of `id /= pdim;`.
0188 
0189 --------------------------------------------------------------------------------
0190 9. STATUS (2026-11-15)
0191 --------------------------------------------------------------------------------
0192   Samples are generated and simulated (500 events each):
0193      bench{1,2,3,5}.hepmc -> sim.bench{1,2,3,5}.root
0194      npsim wall: 1tr 24.97 s, 2tr 35.49 s, 3tr 43.45 s, 5tr 66.12 s
0195      (PDG mix per track: random over {211, 321, 2212}, from the current macro)
0196   All nine benchmark refs are patched and compile.
0197   NO eicrecon runs have been performed yet -- the benchmark matrix (9 refs x
0198   4 samples, one run per setting, 500 events) is pending, on request.
0199   Helper scripts in the sandbox root: apply-bench-patches.py, runbench.sh
0200   (4 runs + collect), collect.py (IRT observables from a rec file).
0201   Installed stack right now: install/lib/libIRT2.so from bench/v2.2.3
0202   (installed before the ref sweep); the sweep only built, did not install.
0203 ================================================================================
0204 
0205 --------------------------------------------------------------------------------
0206 10. RESULTS
0207 --------------------------------------------------------------------------------
0208 ref = bench/v2.2.3 (upstream v2.2.3 + radix fix + the two patches), baseline
0209 pfrich-reco.json, 500 events, single-threaded, one run, no averaging.
0210 Installed at 15:19 (libIRT2.so + RICH-IRT.so), log eicrecon_v223_2tr.log,
0211 output rec_v223_2tr.root.
0212 
0213   ref            Ntr  wall [s]  jana Hz   IRT parts  PFRICHHits/ev
0214   bench/v2.2.3    2     64.48     23.4        969        570.1
0215 
0216   ref            reco PDG mix                       truth PDG mix
0217   bench/v2.2.3    {211:318, 321:301, 2212:323, 0:27}  {211:341, 321:306, 2212:353}
0218 
0219   ref            mean npe  mean nhits  sum npe  sum nhits  attached
0220   bench/v2.2.3    12.186    10.472     11808    10147     0.8593
0221 
0222   index-wise PDG agreement 390/744 = 52.4%  (approximate metric: IRT particles
0223   are matched to the truth charged primaries in eta by order of appearance,
0224   because the rec file does not carry the IRT->track->MC link; treat it as an
0225   indicator, not as the PID efficiency. The PDG *composition* above is exact.)
0226 
0227   Notes: 969 IRT particles vs 1000 truth tracks (31 tracks dropped: no reco
0228   link or below the eta acceptance); 27 IRT particles with PDG = 0 (no ID).
0229   attached = 0.859 is high because the baseline config has
0230   "UseMcTruthPhotonDirectionSeed": "yes".
0231   The baseline now uses "cherenkov-angle-range": [200, 290]. Expected aerogel
0232   Cherenkov angles at 7 GeV for n = 1.04 (cos t = 1/(n*beta)): pi 278.2 mrad,
0233   K 269.4 mrad, p 245.2 mrad. So the pi/K separation is only ~9 mrad,
0234   comparable to DefaultSinglePhotonThetaResolution = 5 mrad -- near-random
0235   pi<->K assignment at this momentum is physically expected, while p vs
0236   (pi,K) differs by ~30 mrad and should be resolvable. That is consistent
0237   with the reco PDG composition tracking the truth composition while the
0238   index-wise agreement stays around one half.
0239 ================================================================================
0240 
0241 --------------------------------------------------------------------------------
0242 11. RECIPE CHANGE 2026-11-15: yield coefficient via the calibration file
0243 --------------------------------------------------------------------------------
0244 Replaces the hard-coded override with a configuration option:
0245 
0246   a) pfrich-calibration.json (NOT under version control -- recorded here):
0247         "Radiators": { "Aerogel": { "YieldCff": 160.0, "theta-bins": { ... } }, ... }
0248      Other radiators (Acrylic, GasVolume, QuartzWindow) have no such key, so
0249      their yield coefficient stays whatever the calibration/UpdateYields path
0250      produces. IRT never writes this file (no JSON writer in Calibration.cc),
0251      so the key survives reruns.
0252 
0253   b) ReconstructionFactory::JsonParser(), inside the per-radiator clause that
0254      reads the calibration file's "theta-bins":
0255         if (rrconfig.find("YieldCff") != rrconfig.end()) {
0256           radiator->m_YieldCff = rrconfig["YieldCff"].template get<double>();
0257           radiator->m_DetectedToCalibrationPhotonRatio = 1.0;
0258         }
0259      i.e. the ratio is pinned to 1.0 in the same clause, exactly as requested.
0260 
0261   c) the hard-coded `radiator->m_YieldCff = 160.0; ... = 1.0;` line in
0262      LaunchRingFinder() is REMOVED (and with it the commented-out debug
0263      printf in the refs that had one).
0264 
0265   Tooling: apply-bench-patches.py now (i) fixes the radix, (ii) adds the
0266   _EXPECTED_BG_PHOTON_COUNT_ (0.1) define, (iii) removes any hard-coded
0267   m_YieldCff override, (iv) inserts the JsonParser YieldCff clause. Idempotent
0268   (a no-op re-run reports "applied: 0").
0269 
0270   Head commits of all nine benchmark refs after this change (each = tag +
0271   radix/experiment commit + this recipe commit; all compile):
0272 
0273     bench/v2.2.3    de2afd0    bench/v2.2.3a5   aeb3925
0274     bench/v2.2.3a1  113fa67    bench/v2.2.3a6   c58c53e
0275     bench/v2.2.3a2  c68e564    bench/v2.2.3a7   01bd1af
0276     bench/v2.2.3a3  ac48538    bench/v2.2.3a8   4543a24
0277     bench/v2.2.3a4  f71b015
0278 
0279   Verified identical structure across all nine refs:
0280     hard-coded m_YieldCff = 160.0 : 0 occurrences
0281     JsonParser YieldCff clause    : 1
0282     _EXPECTED_BG_PHOTON_COUNT_    : 1 define
0283     buggy radix patterns          : 0
0284     (qid|id) /= hdim              : 3 (4 for a2, a3, a4, which decode ic in
0285                                      MixtureLnL)
0286 
0287   IMPORTANT for the numbers already recorded: the section 10 measurement
0288   (bench/v2.2.3, 2 tracks, 64.48 s) was taken with the hard-coded override,
0289   before this change. The effective values are the same (160.0, ratio 1.0),
0290   so it is expected to reproduce, but it is formally superseded -- rerun it
0291   with the current head commit de2afd0 when the benchmark campaign starts.
0292   Also note the installed stack is now bench/v2.2.3 head (de2afd0), built and
0293   installed at 15:28 (libIRT2.so + RICH-IRT.so); every ref is installed right
0294   before its own runs.
0295 ================================================================================
0296 
0297   RE-RUN of the same setting with the config-driven yield (section 11),
0298   bench/v2.2.3 @ de2afd0, installed 15:28, log eicrecon_v223_2tr.log,
0299   output rec_v223_2tr.root (the previous artifacts were kept as *.hardcode.*):
0300 
0301     wall 46.70 s   jana 23.2 Hz   IRT particles 969   PFRICHHits/ev 570.1
0302     reco PDG {211:318, 321:301, 2212:323, 0:27}   truth {211:341, 321:306, 2212:353}
0303     mean npe 12.186  mean nhits 10.472  sum npe 11808  sum nhits 10147  attached 0.8593
0304     index-wise PDG agreement 390/744 = 52.42%
0305 
0306   Physics is identical to the previous run, as expected: the calibration key
0307   supplies the same values the hard-coded line did (160.0, ratio 1.0). The
0308   effective recipe is therefore unchanged.
0309 
0310   TIMING CAVEAT, important for the whole campaign: the same configuration ran
0311   in 64.48 s (15:20, right after install/checkout) and 46.70 s (15:31). The
0312   physics output was identical, so the difference is machine/cache state
0313   (cold DD4hep/ACTS/field-map and file-page caches on the first run after a
0314   checkout+rebuild), not the code. Consequences for the benchmark:
0315     - one run per setting, no averaging, is kept;
0316     - but every ref must be run in the same, warm state: install + a first
0317       throwaway run to warm the caches is NOT allowed (that would be a second
0318       run), so instead the caches are already warm from the ref that ran
0319       before, and refs are measured in a fixed order (v2.2.3, a1..a8) with
0320       only the install step in between;
0321     - wall times below ~60 s for this sample should be read as warm-cache
0322       numbers; the 64.48 s figure above is a cold-cache number and is kept
0323       only as the record of that first run.
0324 ================================================================================
0325 
0326   PROTOCOL-CONSISTENT RE-RUN (1-event warm-up + measured run), bench/v2.2.3 @
0327   de2afd0, 2 tracks, log eicrecon_v223_2tr.log, warm-up log warm_v223_2tr.log,
0328   plots archived as pfrich_v223_2tr.root:
0329 
0330     wall 39.84 s   jana 22.6 Hz   IRT particles 969   PFRICHHits/ev 570.1
0331     reco PDG {211:318, 321:301, 2212:323, 0:27}   truth {211:341, 321:306, 2212:353}
0332     mean npe 12.186  mean nhits 10.472  sum npe 11808  sum nhits 10147  attached 0.8593
0333     index-wise PDG agreement 390/744 = 52.42%
0334 
0335   Same configuration, three measurements, to calibrate expectations for the
0336   campaign: 64.48 s (cold, no warm-up) | 46.70 s (warm, no warm-up) |
0337   39.84 s (with the 1-event warm-up). Physics identical in all three, bit for
0338   bit, so the spread is purely machine state. The warm-up number is the one
0339   the campaign will use from now on; the two earlier figures are kept as the
0340   history of this setting only.
0341 ================================================================================
0342 
0343   Config fingerprints at the start of the campaign (so drift is detectable;
0344   both files are NOT under version control):
0345     pfrich-reco.json      (1899 B, mtime 2026-11-15 15:33)  md5 see below
0346     pfrich-calibration.json (Aerogel "YieldCff": 160.0 at line 13)
0347   Re-check these md5 lines before comparing numbers across sessions:
0348     a90056d9c0c6cd151f0e80444e1f85d4  pfrich-reco.json
0349     bcfd930e07f8a66ef0f59b857e79aec9  pfrich-calibration.json
0350 EOF
0351 
0352 ================================================================================
0353 12. SWEEP RESULTS 2026-11-15 -- 9 refs x {1,2,3,5} tracks
0354 ================================================================================
0355 Protocol: BUG.txt commands, 500 events, single-threaded, 1-event warm-up then
0356 ONE measured run per setting, no averaging. Baseline = on-disk
0357 pfrich-reco.json (md5 a90056d9c0c6cd151f0e80444e1f85d4, "store" plots) and
0358 pfrich-calibration.json (md5 bcfd930e07f8a66ef0f59b857e79aec9, Aerogel
0359 "YieldCff": 160.0). Refs = bench/<tag>, each = tag + radix fix + the two
0360 benchmark patches. Raw log: sweep.tsv.
0361 
0362  Wall time [s] for 500 events
0363  ref      1 tr       2 tr       3 tr        5 tr
0364  main    29.12      39.80      93.07     1365.91     (bench/v2.2.3  @ de2afd0)
0365  a1      28.59      31.32      35.71       65.44
0366  a2      28.55      31.16      36.03       65.88
0367  a3      28.66      31.21      35.07       46.71
0368  a4      28.62      31.05      34.67       46.27
0369  a5      28.42      31.21      35.09       45.73
0370  a6      28.87      30.83      35.15       46.67
0371  a7      28.96      31.15      34.68       46.07
0372  a8      28.46      31.27      35.23       46.75
0373 
0374  Speedup vs main:  1 tr x1.0   2 tr x1.27   3 tr x2.61   5 tr x20.9 (a1) -> x29.2 (a3+)
0375  Scaling with N:  main 29 -> 40 -> 93 -> 1366 s (combinatorial);
0376                   a3+   29 -> 31 -> 35 ->  47 s (~linear, ~4.5 s per extra track)
0377 
0378  PHYSICS: identical across all nine refs for every sample. For each of
0379  N = 1, 2, 3, 5 there is exactly ONE distinct physics signature over the nine
0380  refs (IRT particle count, PDG content, mean npe, mean nhits, sum npe, sum
0381  nhits, attached fraction, index-wise agreement). The chi^2 reference path is
0382  therefore unchanged by a1..a8, and the ML/EM code (present in a2, a4..a8)
0383  is inert under the baseline config, as intended.
0384 
0385  Per-sample numbers (same for all nine refs):
0386    1 tr: PFRICHHits/ev 275.7  IRT parts 488  PDG {0:2, 211:165, 321:140, 2212:181}
0387          truth {211:171, 321:141, 2212:188}  npe 12.654 nhits 10.855 attached 0.8578
0388          index-wise 205/422 = 48.6%
0389    2 tr: 570.1 hits/ev  969 parts  {0:27, 211:318, 321:301, 2212:323}
0390          truth {341, 306, 353}  npe 12.186 nhits 10.472 attached 0.8593  52.4%
0391    3 tr: 855.8 hits/ev 1472 parts  {0:70, 211:471, 321:452, 2212:479}
0392          truth {520, 473, 507}  npe 12.166 nhits 10.596 attached 0.8710  37.5%
0393    5 tr: 1434.3 hits/ev 2432 parts {0:221, 211:746, 321:722, 2212:743}
0394          truth {853, 818, 829}  npe 12.083 nhits 10.412 attached 0.8617  38.0%
0395 
0396  Why main is so much slower now than in the old TAGS.txt ledger: the radix fix
0397  makes the scan enumerate 3^5 = 243 DISTINCT assignments (before the fix the
0398  same 243 iterations collapsed to 54 distinct ones, and hdim was 2 in the old
0399  config, i.e. 32 iterations). So the fixed baseline is legitimately ~7-20x
0400  more expensive than the buggy one, and the patched refs buy it back.
0401 
0402  Artifacts per (ref,N): rec_<ref>_<N>tr.root (physics), eicrecon_<ref>_<N>tr.log
0403  (timing + jana report), pfrich_<ref>_<N>tr.root (evaluation plots, "store"),
0404  warm_<ref>_<N>tr.log (warm-up, output file deleted), plus sweep.tsv.
0405  Cross-check: bench/v2.2.3a7 and bench/v2.2.3a8 have an EMPTY source diff
0406  after the YieldCff propagation, and their numbers agree -- as expected.
0407 ================================================================================
0408 
0409 ================================================================================
0410 13. ML MATRIX 2026-11-15 -- "Estimator":"ml", same refs/samples/protocol
0411 ================================================================================
0412 Config pfrich-reco-ml.json = baseline + "Estimator":"ml" + "BackgroundFraction":
0413 0.1 + "BackgroundWindow": 0.02 (the two background values are the code
0414 defaults, so making them explicit changes nothing). Only refs that contain the
0415 mixture estimator were run: a2, a4, a5, a6, a7, a8 (main/a1/a3 have no ML code).
0416 
0417  Wall time [s]      1tr    2tr    3tr    5tr     attached (sum nhits / sum npe)
0418  a2ml              28.32  31.10  35.28  61.06   0.8513 0.8354 0.8008 0.7130
0419  a4ml              28.51  31.27  34.72  47.01   0.8513 0.8354 0.8008 0.7130
0420  a5ml              28.45  31.20  34.95  45.81   0.8544 0.8462 0.7799 0.6056
0421  a6ml              28.36  31.02  34.96  45.65   0.8549 0.8534 0.8189 0.6985
0422  a7ml              28.98  31.00  34.90  46.10   0.7252 0.4482 0.1330 0.0023
0423  a8ml              28.52  31.32  35.43  46.09   0.7252 0.4482 0.1330 0.0023
0424  chi^2 reference   28.42  30.83  34.67  45.73   0.8578 0.8593 0.8710 0.8617
0425  (chi^2 row = best of the patched refs; all nine refs identical in physics)
0426 
0427  Index-wise PDG agreement (chi^2 reference: 48.58 / 52.42 / 37.49 / 38.04 %)
0428  a2ml, a4ml    48.58  52.82  37.34  38.49
0429  a5ml          48.34  54.03  36.68  36.60
0430  a6ml          48.34  53.90  36.83  37.49
0431  a7ml, a8ml    48.10  54.17  37.12  36.55
0432 
0433  FINDINGS
0434  1. Stage B1 is exactly output-preserving: a4ml physics == a2ml physics for all
0435     four samples, and it is 23% faster at 5 tracks (47.0 s vs 61.1 s).
0436  2. Stage B2 (scan removed) costs nothing further in time (45.8 s) and changes
0437     physics: better at 2 tracks (54.03 vs 52.82), worse at 5 (36.60 vs 38.49),
0438     with attached dropping to 0.6056.
0439  3. Stage B3 (EM to convergence) recovers most of it: attached 0.6985,
0440     agreement 37.49 at 5 tracks.
0441  4. v2.2.3a7 (the per-event background-fraction and yield-scale M-steps)
0442     BREAKS the attachment: attached collapses with multiplicity
0443     0.7252 / 0.4482 / 0.1330 / 0.0023 -- at 5 tracks essentially no hit is
0444     attached (sum nhits 68 of 29386), while the PDG composition and agreement
0445     barely move. Attribution, by running the same setting with one M-step at a
0446     time switched off (5 tracks, a7):
0447         EmFitBackground "no"  -> attached 0.6887  (recovered)
0448         EmFitYields     "no"  -> attached 0.0023  (still broken)
0449     so the BACKGROUND-FRACTION M-step is the culprit: (beta, s_r) has a
0450     degenerate direction, beta runs to the 0.999 clamp as the number of
0451     ambiguous hits grows, the signal weights (1-beta)/pdim * pi become tiny,
0452     no track reaches the posterior > 0.5 needed for MAP attachment, and the
0453     mixture explains everything as background. The yield-scale M-step alone is
0454     mild (0.6887 vs 0.6985 with it on/off at fixed beta).
0455  5. Timing is now flat across a4..a8 (~28 / 31 / 35 / 46 s) and in ML as well
0456     as chi^2 -- the estimator is no longer the cost driver. The unpatched
0457     reference at 5 tracks is 1365.91 s.
0458  6. Diagnostic gap confirmed at runtime: EM iteration counts and lnL are
0459     invisible under EICrecon, because IrtInterface.cc:95 calls
0460     SetQuietMode() and RunEM's printf is gated on BeVerbose(). Only
0461     "ReconstructionFactory: estimator = ml" reaches the log. Making lnL /
0462     iterations / beta / s_r observable needs a plot or an unconditional
0463     diagnostic (still the top unimplemented item).
0464 
0465  RECOMMENDATION (not yet applied): default EmFitBackground to OFF (or fit beta
0466  globally over the run rather than per event, or bound it far tighter than
0467  0.999 / give it a prior); keep EmFitYields. With beta fixed, a7 behaves like
0468  a6 (attached 0.6887 vs 0.6985 at 5 tracks).
0469 
0470  Extra configs introduced: pfrich-reco-ml.json, pfrich-reco-ml-nobg.json,
0471  pfrich-reco-ml-noyld.json. runbench.sh now honours CFG=<config>.
0472 ================================================================================
0473 
0474 ================================================================================
0475 14. FIX TO THE MIXTURE PARAMETERS (ref bench/v2.2.3a8 @ 1eaf12a) + a8ml repeat
0476 ================================================================================
0477 Per instruction, the mixture now has ONE fitted set of parameters (the
0478 hypothesis weights pi_{p,h}) and nothing else is estimated:
0479 
0480   * Background is never estimated. It is a fixed, small expected *count* of
0481     background photon hits per event -- the same meaning as the chi^2 define
0482     _EXPECTED_BG_PHOTON_COUNT_ -- given by the new config key
0483         "ExpectedBackgroundPhotons": 0.1
0484     and used as a fixed mixture weight beta = ExpectedBackgroundPhotons / nhits
0485     (clamped at 0.5), so the expected number of hits attributed to the
0486     background component is exactly that count. The background M-step and the
0487     EmFitBackground / BackgroundFraction keys are REMOVED from the code.
0488   * Yields are never varied. lambda_p is built directly from the calibration
0489     file: radiator->m_YieldCff (the "YieldCff" key, i.e. the average number of
0490     detected photons per track at a saturated Cherenkov angle) times
0491     m_DetectedToCalibrationPhotonRatio (pinned to 1.0 by JsonParser) times
0492     sin^2(theta_p). The per-event yield scales s_r and the EmFitYields key are
0493     REMOVED; EmParameters now holds pi_{p,h} only.
0494   * EM iteration printout is now unconditional (RunEM), because EICrecon puts
0495     the factory in quiet mode (IrtInterface.cc:95 SetQuietMode) and the previous
0496     BeVerbose()-gated message never reached a log:
0497       "ReconstructionFactory: EM N iteration(s), lnL = ..., beta = ...,
0498        hits = ..., tracks = ..."
0499     Two lines per event (calibration pass + reconstruction pass), so ~950-1000
0500     lines per 500-event log.
0501 
0502  CONFIGS: pfrich-reco-ml.json now carries "Estimator":"ml",
0503  "ExpectedBackgroundPhotons": 0.1, "BackgroundWindow": 0.02 (BackgroundFraction
0504  and the two EmFit* keys deleted). pfrich-reco-ml-nobg.json / -noyld.json
0505  (diagnostic, obsolete) deleted. New: pfrich-reco-ml-it60.json (+ EmMaxIterations
0506  60).
0507 
0508  REPEAT OF THE 5-TRACK-CLASS ML MATRIX, ref bench/v2.2.3a8 @ 1eaf12a (label
0509  a8mlv2), same samples/protocol/500 events, one measured run each:
0510 
0511   setting      wall [s]   attached   index-wise PDG agreement
0512   a8mlv2 1tr   28.33      0.8617     48.82%   (chi^2: 28.42 s, 0.8578, 48.58%)
0513   a8mlv2 2tr   31.08      0.8861     53.63%   (chi^2: 30.83 s, 0.8593, 52.42%)
0514   a8mlv2 3tr   35.05      0.8883     37.27%   (chi^2: 34.67 s, 0.8710, 37.49%)
0515   a8mlv2 5tr   46.14      0.8120     37.64%   (chi^2: 45.73 s, 0.8617, 38.04%)
0516 
0517   The collapse of section 13 is gone: attached went
0518      0.7252 / 0.4482 / 0.1330 / 0.0023   (a7ml, a8ml with fitted beta)
0519   back to
0520      0.8617 / 0.8861 / 0.8883 / 0.8120   (a8mlv2, fixed background + fixed yields)
0521   i.e. at or above the chi^2 reference for 1-3 tracks and slightly below at 5.
0522   PDG composition: {211:164, 321:140, 2212:182} / {319, 296, 327} /
0523   {473, 450, 479} / {738, 713, 760} vs truth {171,141,188} / {341,306,353} /
0524   {520,473,507} / {853,818,829}; no-ID (PDG 0) counts identical to chi^2.
0525   Timing unchanged: 28 / 31 / 35 / 46 s.
0526 
0527  EM CONVERGENCE (from the new printout):
0528    cap 20 (default, EmTolerance 1e-6): iterations min/median/max
0529       1tr 4/19/20   2tr 4/20/20   3tr 8/20/20   5tr 20/20/20
0530    -> the cap binds for essentially every event, i.e. the tolerance is not
0531       reached; lnL ~ 61 / 97 / 138 / 218 (median) so an absolute 1e-6 is very
0532       strict; beta = 0.00526 / 0.00270 / 0.00182 / 0.00114 (= 0.1/nhits, as
0533       intended).
0534    cap 60 probe (a8mlv2it60, 5 tr): iterations 20/60/60, wall 47.26 s
0535       (+1.1 s), attached 0.8171 vs 0.8120 -- three extra iterations' worth of
0536       gain. So the default cap of 20 is operationally adequate; the sensible
0537       change is a looser/relative tolerance rather than more iterations.
0538 
0539  RECOMMENDED NEXT STEPS (not applied): relax EmTolerance (relative, e.g.
0540  1e-6*|lnL|, or absolute ~1e-4) so the loop stops on convergence instead of on
0541  the cap; add lnL / iteration count / beta as histograms so the ML path has
0542  goodness-of-fit diagnostics; consider propagating this parameter treatment to
0543  bench/v2.2.3a7 (a5/a6 never fitted beta or yields, so they are unaffected).
0544 ================================================================================
0545 
0546 ================================================================================
0547 15. PLURALITY ATTACHMENT RULE (bench/v2.2.3a8 @ 0bb8638) + 5-track check
0548 ================================================================================
0549 What changed (ML path only; the chi^2 ownership logic is untouched):
0550 
0551   * a posteriori attachment criterion, previously hard-coded as
0552         rbest > 0.5
0553     is now policy-switchable:
0554         plurality : rbest > rbg      (the hit is more likely signal than background;
0555                                      ambiguity between tracks no longer throws the hit
0556                                      away)                          <-- new DEFAULT
0557         majority  : rbest > 0.5      (v2.2.3a5..a7 behaviour)
0558     rbg = exp(lnbg - lnorm) is the hit's background posterior.
0559   * JSON key in the PFRICH config:  "AssignmentMode": "plurality" | "majority"
0560     (default plurality when the key is absent).
0561   * Header: enum AssignmentMode {kAssignMajority, kAssignPlurality},
0562     member m_AssignmentMode, Set/GetAssignmentMode.
0563   * Commit: 0bb8638 (branch bench/v2.2.3a8). Configs used: pfrich-reco-ml.json
0564     (plurality, default) and pfrich-reco-ml-maj.json (explicit majority).
0565 
0566 5-track sample, 500 events, one measured run each after a 1-event warm-up:
0567 
0568   setting                 wall [s]  sum npe  sum nhits  attached  index-wise PDG
0569   chi^2 baseline (a8)      46.75     29386     25323     0.8617     38.04%
0570   ML, majority (a8mlv2)    46.09     29386     23860     0.8120     37.64%
0571   ML, majority (a8mlv3maj) 45.62     29386     23860     0.8120     37.64%   <- exact
0572   ML, plurality (a8mlv3)   46.21     29386     26676     0.9078     37.64%      repro
0573 
0574   reco PDG composition, ML (both modes): {0:221, 211:738, 321:713, 2212:760}
0575                                          (chi^2: {0:221, 211:746, 321:722, 2212:743})
0576   truth: {211:853, 321:818, 2212:829}; mean npe 12.083 in all cases.
0577 
0578  Conclusions:
0579   * the switch is a pure policy change: majority reproduces the recorded a8mlv2
0580     numbers exactly (sum nhits 23860, attached 0.8120, match 37.64%), so nothing
0581     else moved;
0582   * plurality recovers +11.8% of attached photons vs majority (23860 -> 26676) and
0583     also beats the chi^2 reference by +5.3%, while leaving PID quality unchanged
0584     (composition and index-wise agreement identical between the two ML modes) --
0585     as expected, since the weights/theta_bar that drive PID use the soft
0586     responsibilities, not the hard attachment;
0587   * timing is unaffected (45.6-46.2 s);
0588   * caveat: hits attached under plurality can have modest posterior (anything above
0589     rbg qualifies). The posterior is already stored per hit via
0590     AssignVariables(..., rbest) in the (reused) CCDF slot, so it can be dumped with
0591     "WriteOutputTree": "yes" and used to sort attached hits by confidence -- and it
0592     is the quantity a ring-level / joint-assignment upgrade should consume.
0593 
0594  Follow-ups this opens (not yet done):
0595   * export the expected (fractional) counts sum_i r_ip and the effective sample
0596     size (sum r)^2/sum r^2 per track -- edm4eic npe/nhits are uint16_t, so this
0597     goes into IRT's own output tree and/or evaluation histograms;
0598   * joint assignment with the Poisson count constraint (max-weight matching with a
0599     background slot) to replace per-hit argmax entirely;
0600   * ring-level statistic on theta_bar with sigma/sqrt(n_stat) -- the 6.1-sigma
0601     pi/K separation estimate depends on using n_stat, not sum r.
0602 ================================================================================
0603 
0604 ================================================================================
0605 16. TAG REGISTRY (irt repo, all local-only -- nothing pushed)
0606 ================================================================================
0607   v2.2.3      1479e60  upstream base (== origin/main)
0608   v2.2.3a1    fd112fa  Stage A: ProcessHits combinatorial overhead
0609   v2.2.3a2    402409f  global mixture log-likelihood (flagged)
0610   v2.2.3a3    4878d0a  Stage A per-hit hypothesis cache
0611   v2.2.3a4    074265d  Stage B1 separable mixture objective
0612   v2.2.3a5    224795f  Stage B2 hypothesis marginalised, cdim -> 1
0613   v2.2.3a6    a139245  Stage B3 EM iterations
0614   v2.2.3a7    d4ab0d8  M-steps for background fraction + yield scales
0615   v2.2.3a8    9326e29  EXPERIMENT: ExpectedBackgroundPhotons + hard-coded yields
0616   v2.2.3a9    0bb8638  radix BUGFIX + YieldCff from calibration file + fixed
0617                        background/yields + unconditional EM printout + plurality
0618                        attachment rule ("AssignmentMode" key). Lineage:
0619                        9326e29 -> 05698d0 -> 4543a24 -> 1eaf12a -> 0bb8638,
0620                        on branch bench/v2.2.3a8.
0621 
0622   Benchmark refs (branch = tag + benchmark patches, one commit each unless noted):
0623     bench/v2.2.3   de2afd0  radix fix + define + YieldCff recipe
0624     bench/v2.2.3a1 113fa67  "
0625     bench/v2.2.3a2 c68e564  "
0626     bench/v2.2.3a3 ac48538  "
0627     bench/v2.2.3a4 f71b015  "
0628     bench/v2.2.3a5 aeb3925  "
0629     bench/v2.2.3a6 c58c53e  "
0630     bench/v2.2.3a7 01bd1af  "
0631     bench/v2.2.3a8 0bb8638  = tag v2.2.3a9 (adds 1eaf12a parameter treatment and
0632                              0bb8638 plurality rule on top of the recipe)
0633 
0634   NOT yet propagated: the parameter treatment (1eaf12a) and the plurality rule
0635   (0bb8638) exist only on the v2.2.3a8 lineage. bench/v2.2.3a7 (and a5/a6) still
0636   carry the fitted-background M-step; for a5/a6 that M-step never existed, so
0637   they are unaffected in practice, but bench/v2.2.3a7 does and should be updated
0638   before it is measured again.
0639 ================================================================================
0640 
0641 ================================================================================
0642 17. CALIBRATION FILE CORRECTED (pfrich-calibration.json)
0643 ================================================================================
0644 Change: in the "Aerogel" section (the only section actually consumed, since
0645 only Aerogel has imaging: "yes"), the 4th effective-index column
0646 (QuartzWindow) was 1.000290 -- air-like, instead of the material value. Now
0647 set to 1.460000 in all five theta-bins (31-35). Other fields untouched
0648 (stat, AverageZvtx -1258.3..-1258.5, Coffset -1.62..-1.29, Csigma 4.69..5.20,
0649 YieldCff 160.0).
0650 
0651 Aerogel bin 31 columns now: acrylic 1.501700 (table value, exact), aerogel
0652 1.040493 (table 1.0399; fitted average, fine), gas 1.000330 (N2, exact),
0653 quartz window 1.460000 (table RINDEX__QuartzOptical, constant 243-1240 nm).
0654 
0655 File fingerprint: md5 was bcfd930e07f8a66ef0f59b857e79aec9 (sections 10-16
0656 measurements), now 348498b0f76e1d0d0e255c5867663b89. The file is NOT under
0657 version control, so every number recorded earlier belongs to the OLD file.
0658 
0659 Consequences of the fix (model-level, not cosmetic):
0660   * optical path / timing: excess optical length along a nominal 450 mm
0661     aerogel-photon path rises 2.11 mm -> 3.86 mm, i.e. delay 7.1 ps -> 12.9 ps,
0662     against the GEANT-truth residual dt - L/c = 14.0 ps. The remaining ~1 ps is
0663     Rayleigh kinks in aerogel; the "first segment weighted by 1.0" bug in
0664     IRT::Transport (prev ? prev->GetRadiator() : 0) still costs ~1.6 ps and is
0665     a code fix, not a file value.
0666   * Snell refraction at the window boundaries is now applied (previously
0667     n1 = n2 ~ 1, so the window was optically invisible). Lateral displacement
0668     through 3.8 mm: 0.21 mm at 10 deg incidence, 0.46 mm at 20 deg, 0.67 mm at
0669     27 deg -> theta bias up to 0.67/450 ~ 1.5 mrad, i.e. ~0.3 of Csigma (5 mrad).
0670     Therefore the ring solutions shift measurably: the sweep numbers in sections
0671     12/15 must be re-measured under the corrected file before being compared.
0672 
0673 Remaining inconsistency (harmless today, a trap later): the other three
0674 sections still carry the old bad values -- last column 1.000290 everywhere, and
0675 columns 3/4 are unphysical (n = 0.949..0.986 < 1) in the Acrylic and GasVolume
0676 sections. They are never read (only the processed imaging radiator's section
0677 supplies the index list), but if another radiator is ever set imaging: "yes",
0678 it would silently use those. Keep all four columns in every section (the parser
0679 validates rnum == number of radiators, and columns are positional in map order
0680 Acrylic, Aerogel, GasVolume, QuartzWindow) and set them to the material values.
0681 ================================================================================
0682 
0683 ================================================================================
0684 18. IRT::Transport() first-segment weighting fixed (bench/v2.2.3a8 @ c05c9c0)
0685 ================================================================================
0686 Code change:
0687   include/IRT.h        new member CherenkovRadiator *m_EmissionRadiator (init 0) and
0688                        public SetEmissionRadiator(); declared last to keep the
0689                        constructor's initialiser list in declaration order;
0690   source/IRT.cc        Transport():
0691                          auto *radiator = prev ? prev->GetRadiator() : m_EmissionRadiator;
0692                        (was: : 0  ->  segment weighted by n = 1);
0693   source/ReconstructionFactory.cc
0694                        ProcessHits() calls irt->SetEmissionRadiator(radiator) right
0695                        before each Solve(), since that is where the radiator the photon
0696                        is attributed to is known.
0697 
0698 Honest assessment of the numerical impact: for the present PFRICH boundary ordering
0699 the list is [Aerogel, Acrylic, mirrors..., QuartzWindow, sensor], and for a photon
0700 emitted inside the aerogel the surfaces behind it are skipped (no crossing) but remain
0701 in the list -- so the first *crossed* boundary always has prev != 0 and is preceded by
0702 the Aerogel surface, meaning that segment was already weighted by the aerogel index.
0703 Hence this is a robustness/explicitness fix (correct behaviour when the estimated
0704 emission point lies upstream of the first registered surface), not a numerical change
0705 for this detector. Consistent with the accounting: after the calibration-file fix the
0706 model delay is 12.9 ps against the GEANT-truth residual 14.0 ps; had the emission
0707 segment been unweighted the model would have been ~1.6 ps lower, and that hole was not
0708 there. The remaining ~1 ps is attributed to Rayleigh kinks in the aerogel.
0709 
0710 Placement and follow-ups:
0711   * the fix is on branch bench/v2.2.3a8 only; the tag v2.2.3a9 points at 0bb8638, i.e.
0712     one commit earlier. Add a new tag (e.g. v2.2.3a10) if this state must be pinned;
0713   * IRT.h/IRT.cc are shared files: the change can be cherry-picked onto the other
0714     bench/* refs, but it is numerically neutral for PFRICH, so this is optional;
0715   * ABI note: the IRT object gained a member, so libIRT2.so and EICrecon's RICH-IRT.so
0716     were both rebuilt and reinstalled;
0717   * stray file noticed: irt/source/ReconstructionFactory.cc.save (editor backup). It is
0718     not matched by the *.cc sources list, so it is not compiled, but it is confusing
0719     and should be removed.
0720 ================================================================================
0721 
0722 --------------------------------------------------------------------------------
0723 18b. REVERT of section 18 (2026-11-17)
0724 --------------------------------------------------------------------------------
0725 The change described in section 18 was reverted: branch bench/v2.2.3a8 was reset
0726 back to 0bb8638 (== tag v2.2.3a9), so c05c9c0 is no longer in the branch history
0727 (local-only branch, nothing pushed, so no dangling published commit).
0728 Verified after reset: source/IRT.cc:40 is back to
0729     auto *radiator = prev ? prev->GetRadiator() : 0;
0730 and there are zero references to SetEmissionRadiator/m_EmissionRadiator in
0731 include/IRT.h, source/IRT.cc, source/ReconstructionFactory.cc.
0732 libIRT2.so and EICrecon/plugins/RICH-IRT.so were rebuilt and reinstalled from the
0733 reverted tree (2026-11-17 20:01), so the installed stack matches the source again.
0734 Rationale: as established in section 18, the change is numerically neutral for the
0735 present PFRICH boundary ordering (prev is index-based and the skipped surfaces stay
0736 in the list), so it was not worth carrying.
0737 ================================================================================
0738 
0739 ================================================================================
0740 19. EM PRINTOUT REMOVED (bench/v2.2.3a8 @ 88a9bd6)
0741 ================================================================================
0742 Removed from ReconstructionFactory::RunEM the unconditional diagnostic added in
0743 1eaf12a:
0744 
0745   printf("ReconstructionFactory: EM %u iteration(s), lnL = %.4f, beta = %.6f, "
0746          "hits = %u, tracks = %u\n", ...);
0747   plus the local "beta" computed only for it.
0748 
0749 Still in place: m_EmIterationsUsed is tracked and exposed via GetEmIterationsUsed(),
0750 so re-adding an (optionally gated) printout is one line.
0751 Remaining printf's in this file are the two config echoes, both gated on
0752 BeVerbose() -- which EICrecon disables via IrtInterface's SetQuietMode(), so they
0753 never reach production logs:
0754   :249  "ReconstructionFactory: estimator = %s"          (pre-existing)
0755   :266  "ReconstructionFactory: assignment mode = %s"    (added with the
0756                                                          AssignmentMode key)
0757 Build: libIRT2.so rebuilt and reinstalled; no header changed, so no ABI change and
0758 EICrecon's RICH-IRT.so needed no rebuild. Tag v2.2.3a9 still points at 0bb8638,
0759 i.e. one commit before this removal; 88a9bd6 is currently untagged.
0760 ================================================================================
0761 
0762 ================================================================================
0763 20. "Estimator" restricted to two values (bench/v2.2.3a8 @ 5e66511)
0764 ================================================================================
0765 Behaviour now (JsonParser):
0766   key absent          -> "chi2"  (default; m_UseMixtureLikelihood = false)
0767   "chi2"              -> chi^2 scan path
0768   "ml"                -> mixture log-likelihood + EM path
0769   anything else       -> prints (unconditionally, because EICrecon runs the factory in
0770                           quiet mode) 'unsupported "Estimator" value "..." -- only
0771                           "chi2" (default) and "ml" are recognised, falling back to
0772                           "chi2"' and selects chi^2.
0773   Matching is case-insensitive (ToLower), but exact: the old aliases "mixture",
0774   "likelihood" and "maximum likelihood" are GONE and now count as unsupported.
0775 Checked: every config in the sandbox already used "ml", so nothing breaks --
0776 pfrich-reco.json, pfrich-reco-ml.json, pfrich-reco-ml-maj.json,
0777 pfrich-reco-ml-it60.json, drich-reco.json.
0778 Also restored the misplaced "// Outlier hit selection;" comment (it belongs to
0779 SingleHitCCDFcut, not to Estimator). libIRT2.so rebuilt + reinstalled; no header
0780 change, so RICH-IRT.so needed no rebuild.
0781 
0782 CONFIG DRIFT NOTED (found while doing this): the nominal baseline pfrich-reco.json
0783 is no longer the configuration described in section 5 -- it now also contains
0784     "Estimator": "ml", "ExpectedBackgroundPhotons": 0.1,
0785     "AssignmentMode": "plurality", "BackgroundWindow": 0.02
0786 and "CombinedEvaluationPlots": "display". Its fingerprint is now
0787 md5 4a1f0e61cc8853d84844f4bd2959ccfd (section 5 describes the earlier
0788 a90056d9c0c6cd151f0e80444e1f85d4, which had no Estimator key and therefore ran
0789 the chi^2 path). In other words "the baseline" today means the ML path with the
0790 plurality attachment rule; a chi^2 comparison run needs either that key removed
0791 or "Estimator": "chi2" set explicitly.
0792 ================================================================================
0793 
0794 ================================================================================
0795 21. Background re-parameterised as one DarkHitRate (bench/v2.2.3a8 @ ae11f64)
0796 ================================================================================
0797 What changed in the code:
0798   REMOVED: the _EXPECTED_BG_PHOTON_COUNT_ define, the "ExpectedBackgroundPhotons"
0799            config key, and the "BackgroundWindow" normalisation;
0800   ADDED:   "DarkHitRate" [hits mm^-2 s^-1] (default 0) and "SensitiveArea" [mm^2]
0801            (default 7.93e5 = 68 HRPPDs x 108 x 108 mm);
0802   NEW:     ReconstructionFactory::AccumulateAccidentals(mcparticle, ibin), called once
0803            per particle per pass. It scales the rate by the acceptance a candidate
0804            photon must satisfy:
0805              annulus  = 2*pi*L*tan(theta_C) x (2 n_sigma sigma_theta L)
0806              dt_gate  = 2 n_sigma sigma_t   (ns -> s)
0807              rings    = distinct hypothesis rings (merged within 2 n_sigma sigma_theta)
0808            with n_sigma = _ACCIDENTAL_N_SIGMA_ = 3.0, sigma_theta from the calibration
0809            (Csigma, per radiator and theta bin), sigma_t from
0810            SinglePhotonTimingResolution, L the mean solved photon path length.
0811            Result m_ExpectedAccidentals feeds BOTH estimators: the chi^2 unclaimed-hits
0812            Poisson term (bexp) and the mixture weight beta = M/nhits, whose density in
0813            [rad] is (1/A_eff) dA/dtheta.
0814 
0815 5-track check (500 events, one measured run each after a 1-event warm-up):
0816 
0817   recipe                                   sum nhits  attached   wall
0818   a8 chi^2, _EXPECTED_BG_PHOTON_COUNT_=0.1 (sec.12)   25323   0.8617   46.75 s
0819   a8 ML plurality                        (sec.15)     26676   0.9078   46.21 s
0820   now  chi^2, DarkHitRate = 0                          22456   0.7642   45.50 s
0821   now  ML,    DarkHitRate = 0                          40199   1.3680   62.87 s
0822   now  ML,    DarkHitRate = 3e6 (stress)               40199   1.3680   47.02 s
0823   (sum npe is 29386 in all cases; ML, chi2 and npe are otherwise unchanged)
0824 
0825 Three findings, two of them defects this check exposed:
0826 
0827  1. With DarkHitRate = 0 the mixture has no background, so the plurality attachment
0828     rule ("best track beats the background posterior") degenerates into "attach every
0829     hit to its best track": attached = 1.368 > 1, i.e. more hits attached than there
0830     are detected signal photons, because the quartz-window/gas population is now
0831     absorbed as signal. The ML path has no absolute single-hit quality criterion
0832     comparable to the chi^2 path's SingleHitCCDFcut -- with beta -> 0 one is needed.
0833  2. The chi^2 attached fraction changed 0.8617 -> 0.7642 purely because the
0834     _EXPECTED_BG_PHOTON_COUNT_ term is gone. That term added 2*(0.1 - nbg +
0835     nbg ln(nbg/0.1)) to the event chi^2 -- of order 10^4 when nbg was nonzero, with
0836     only +1 degree of freedom -- which flattened the event-level CCDF ranking. So the
0837     chi^2 numbers in sections 12 and 15 were partly an artifact of that term, and the
0838     0.7642 figure is the honest one.
0839  3. beta is no longer bounded: M > nhits would make log(1-beta) undefined. Needs a
0840     clamp/renormalisation before large rates are used. Also, the stress value 3e6
0841     produced no measurable change (beta x shape ~ 0.03/rad versus signal densities
0842     ~5/rad), so the mechanism is only weakly exercised at that level.
0843 
0844 Suggested follow-up (not done yet): clamp beta; add an absolute per-hit consistency
0845 cut in the ML attachment, reusing the existing SingleHitCCDFcut on the winning
0846 component; then re-measure both estimators at 1/2/3/5 tracks and correct sections 12
0847 and 15, whose chi^2 rows carry the artifact of the removed term.
0848 ================================================================================
0849 
0850 ================================================================================
0851 22. ROLLBACK: the background re-parameterisation and the track-shadow veto
0852     (2026-11-17)
0853 ================================================================================
0854 Rolled back everything from the "_BG_ elimination" onward:
0855 
0856   git reset --hard 5e66511   (branch bench/v2.2.3a8)
0857   Dropped commits:
0858     ae11f64 "background: single DarkHitRate input scaled by angular+timing acceptance"
0859   Discarded uncommitted work:
0860     the TrackShadowVetoRadius parameter, DigitizedHit::m_Excluded and
0861     FlagTrackShadowHits().
0862   Current head is 5e66511 "JsonParser: restrict Estimator to exactly chi2 and ml";
0863   tag v2.2.3a9 still points at 0bb8638, two commits back.
0864 
0865 State after the rollback (verified):
0866   * no trace of DarkHitRate / SensitiveArea / AccumulateAccidentals /
0867     TrackShadowVetoRadius / m_Excluded in the source or in the installed library;
0868   * _EXPECTED_BG_PHOTON_COUNT_ (0.1), m_ExpectedBackgroundPhotons and
0869     m_BackgroundWindow are back;
0870   * configs pfrich-reco.json, pfrich-reco-ml.json, pfrich-reco-chi2.json restored
0871     ("ExpectedBackgroundPhotons": 0.1, "BackgroundWindow": 0.02); the derived
0872     veto/noise configs were deleted;
0873   * libIRT2.so and RICH-IRT.so rebuilt and reinstalled from the reverted tree.
0874 
0875 Runs to consider VOID (they exercised the reverted code, listed in section 21 and
0876 below): a9ml0/a9chi2/a9mlstr (5 tr), a9ml0_1tr, a9mlv50_1tr, a9mlv30, a9mlv50.
0877 
0878 Observations worth keeping (as diagnosis, not as behaviour of the current stack):
0879  1. The chi^2 rows of sections 12 and 15 are affected by the
0880     _EXPECTED_BG_PHOTON_COUNT_ term, which is present in the CURRENT stack: it adds
0881     2*(0.1 - nbg + nbg ln(nbg/0.1)) to the event chi^2 -- ~10^4 when nbg is nonzero,
0882     for one extra degree of freedom -- which flattens the event-level CCDF ranking.
0883     A run without that term gave attached 0.7642 versus 0.8617 with it, at 5 tracks.
0884  2. If the background weight is removed altogether, the plurality attachment rule
0885     degenerates ("attach everything"): attached reached 1.368 at 5 tracks and 1.506
0886     at 1 track, i.e. nhits exceeds npe. The mixture needs either a background
0887     component or an absolute per-hit quality criterion.
0888  3. The track-shadow veto was measured before being rolled back (ML, 5 tracks):
0889     attached 1.368 (no veto) -> 0.920 with a 30 mm veto, index-wise PDG agreement
0890     37.64% -> 38.14%, wall 46-49 s. The effect is large because ~88% of the noise
0891     population lies within 20 mm of the track projection, while a genuine ring sits
0892     at L*tan(theta_C) ~ 130 mm. Kept here as evidence; the code is not in the stack.
0893 
0894 Also noted during this episode: several config variants were missing the keys the
0895 tests assumed (pfrich-reco-ml.json had no AssignmentMode/DarkHitRate), which made
0896 two "stress" runs identical by construction rather than by physics. Config contents
0897 should be printed/echoed in the run logs before any comparison is trusted.
0898 ================================================================================
0899 
0900 --------------------------------------------------------------------------------
0901 23b. A posteriori CCDF plots implemented WITHOUT adding new histograms
0902      (bench/v2.2.3a8 @ 2767789)
0903 --------------------------------------------------------------------------------
0904 Final form (simplified after review -- no new plots):
0905   * DigitizedHitSolution gained m_chi2 and m_ndf of the winning [radiator, optical
0906     path] component, and the mixture posterior moved into its own slot m_posterior,
0907     so m_ccdf now holds the actual CCDF in both estimators;
0908   * FillPosteriorCCDFPlots() walks the attached hits of every track and fills the
0909     EXISTING histograms: ccdfph (per radiator) per photon, ccdftr per track,
0910     ccdfev per event, with the usual ndf convention (1, or 2 when timing is used);
0911   * the scan-time fills are gated off when this is on, so nothing is double-counted;
0912   * config key "PosteriorCCDFPlots" (default yes; "no" restores the old scan-time
0913     fills).
0914 
0915 5-track ML check (500 events, one run each after a 1-event warm-up):
0916 
0917   PosteriorCCDFPlots            sum nhits  attached   index-wise PID   wall
0918   yes (a10ml)                     26706     0.9088       37.09%         46.42 s
0919   no  (a10mlnp)                   26706     0.9088       37.09%         46.25 s
0920   -> bit-identical: the change is confirmed physics-neutral, and the a posteriori
0921      fill replaces the scan-time one rather than adding to it.
0922 
0923 Two open observations, not chased down:
0924   * section 15 recorded 26676 / 37.64% for what should be the same configuration.
0925     Since the on/off A/B above is identical, the 30-hit and 0.5-pp difference is NOT
0926     caused by this patch; it comes from the state of the stack at that time (that run
0927     predates the printout removal, the Estimator restriction and the rollback). The
0928     section-15 chi^2/ML rows should be re-measured on the current head before being
0929     compared with anything else.
0930   * "pfrich.root" (the OutputRootFile with the evaluation plots) was NOT produced in
0931     these runs, with CombinedEvaluationPlots either "store" or "display" -- nothing
0932     about it appears in the run logs. Needs a separate look, because without it the
0933     CCDF histograms above cannot be inspected.
0934 ================================================================================
0935 
0936 --------------------------------------------------------------------------------
0937 TAG v2.2.3a10 (created 2026-11-18, at 2767789 on branch bench/v2.2.3a8)
0938 --------------------------------------------------------------------------------
0939   Annotated tag for the current state. Between v2.2.3a9 (0bb8638, plurality
0940   attachment rule) and v2.2.3a10:
0941     88a9bd6  RunEM: drop the unconditional iteration/lnL printout
0942     5e66511  JsonParser: restrict "Estimator" to exactly "chi2" (default) and "ml"
0943     2767789  CCDF plots: fill the existing histograms a posteriori (section 23b)
0944   Milestone tags now: v2.2.3a1 .. v2.2.3a10, all local-only (nothing pushed).
0945   irt-2.2a still ends at v2.2.3a8; bench/v2.2.3a8 is the up-to-date branch.
0946 ================================================================================
0947 
0948 --------------------------------------------------------------------------------
0949 LOG LOCATION (2026-11-18)
0950 --------------------------------------------------------------------------------
0951 BUG.txt (the bug report), TAGS.txt (abandoned ledger) and MEMO-v00.txt (this file)
0952 moved from the sandbox root into the repository under log/, together with
0953 log/README.md describing each. This makes the reasoning behind the measurements
0954 travel with the branches; the PFRICH reco configs (pfrich-reco*.json), the run
0955 scripts (runbench.sh, apply-bench-patches.py, collect.py) and the sim/recon/root
0956 outputs remain in the sandbox root, so paths quoted elsewhere in this file refer
0957 to that directory.
0958 ================================================================================
0959 
0960 --------------------------------------------------------------------------------
0961 PHOTON DIRECTION SEEDING: new option (commit 5e23b1f, branch bench/v2.2.3a8)
0962 --------------------------------------------------------------------------------
0963 "UseMcTruthPhotonDirectionSeed" is replaced by one string option
0964 "PhotonDirectionSeed" with four values:
0965   "mc-truth"        the old "yes"  - truth photon direction at the photocathode; an
0966                     upper bound for convergence studies, not a reconstruction option
0967   "track-direction" the old "no"   - unseeded Newton iteration
0968   "plane-tangent"   NEW - seed taken from the specular point of the first mirror of the
0969                     optical path: Fermat's stationary point of |x_emit - P| + |P - x_det|,
0970                     solved by iterating the tangent-plane reflection (4 steps, chord
0971                     start). Works for any mirror shape, so dRICH (spherical mirrors) too
0972   "unrolled-cone"   NEW - the same iteration started from 24 windings of the development
0973                     of the cone, so the extra specular (and multi-bounce) solutions of a
0974                     conical mirror become reachable. Requires conical mirror surfaces;
0975                     IRT::MirrorsAreConical() checks it, and for a detector with non-conical
0976                     mirrors (dRICH) it warns once and falls back to "plane-tangent". A path
0977                     with no mirrors at all (the direct one) gets no seed by design.
0978 
0979 Implementation notes:
0980   * IRT::BuildDirectionSeeds(x_emit, x_det, mode, &dirs) returns up to 8 distinct
0981     emitted-ray directions (deduplicated within 1 mrad); each satisfies the law of
0982     reflection at its converged impact point, and the impact point must lie inside the
0983     mirror surface;
0984   * these directions are fed into the existing multi-seed loop in ProcessHits, exactly
0985     like the truth seeds (first converged root wins), so nothing else in the estimator
0986     changed;
0987   * ProcessHits no longer takes a bool; the deprecated JSON key is still accepted
0988     (yes -> mc-truth, no -> track-direction) with a warning; an unrecognised value of the
0989     new key is reported and falls back to "track-direction";
0990   * all reco configs in the sandbox root were migrated to the new key; new variants
0991     pfrich-reco-ml-pt.json (plane-tangent) and pfrich-reco-ml-uc.json (unrolled-cone) sit
0992     next to the mc-truth reference pfrich-reco-ml.json.
0993 
0994 STATUS: compiles and installs; NOT yet validated. The comparison to run, on the existing
0995 samples with the usual protocol (ML, 500 events, one run per setting), is
0996   track-direction (today's failure mode) vs plane-tangent vs unrolled-cone vs mc-truth
0997   (upper bound: attached 0.9088 at 5 tracks),
0998 looking at sum nhits / npe, index-wise PID agreement and the wall-time cost of the extra
0999 seeded solves.
1000 ================================================================================
1001 
1002 ================================================================================
1003 APPENDED 2026-11-19 -- eta = -1.9 single-track test of the photon direction seeds
1004 (commit 43b6743)
1005 ================================================================================
1006 Sample: fresh, recipe-consistent. HepMC electron-going-endcap-eta19.hepmc (pi+, 7.0 GeV/c,
1007 eta = -1.9, phi = 90 deg, 1000 events) -> sim.bench1e19.root via
1008   npsim --compactFile $EIC_SHELL_PREFIX/share/epic/epic_tracking_and_pfrich.xml -N 500
1009 At this angle the track crosses the photosensor plane at r ~ 515 mm, so the direct ring
1010 (ring radius ~ 128 mm) falls largely off the sensors: what is detected is dominated by
1011 partial reflection off the outer cone -- exactly the case that unseeded fitting misses.
1012 
1013 Configuration: ML estimator, "store" for the evaluation plots (changed from "display" in
1014 pfrich-reco.json and drich-reco.json, and in all pfrich-reco*.json variants; plots are now
1015 archived as pfrich_e19f-<mode>.root), 500 events, one run per setting, single-threaded.
1016 Configs: pfrich-reco-19-{trackdirection,planetangent,unrolledcone,mctruth}.json
1017 
1018   mode              sum npe  sum nhits  attached  PID composition agreement   wall
1019   track-direction     6345      3826     0.6030   96.52%                      29.3 s
1020   plane-tangent       6345      5134     0.8091   99.39%                      31.1 s
1021   unrolled-cone       6345      5146     0.8110   99.39%                      32.5 s
1022   mc-truth (bound)    6345      5272     0.8309   99.39%                      29.3 s
1023 
1024 So the geometry-only seeds recover 97.4% (plane-tangent) / 97.6% (unrolled-cone) of the
1025 truth-seeded gain in attached photons and reach the truth-seeded PID quality, at 6-11%
1026 extra wall time.
1027 
1028 Three defects had to be fixed for the seeds to work at all (see commit 43b6743):
1029   1. ParametricSurface::IsInside() cannot be used with these surfaces: GetV() returns the
1030      azimuth UNWRAPPED (e.g. -64.2 or 46.3 against [0, 2pi]), so every candidate specular
1031      point was rejected as "outside". Worked around in IRT::BuildDirectionSeeds by applying
1032      the periodicity before the range check. The proper fix belongs in the surface classes
1033      (or in IsInside itself) - candidate follow-up;
1034   2. the tangent-plane iteration oscillates on a cone; damping P -> (P + Pn)/2 fixes it;
1035   3. a single chord-based starting point never reaches the reflected solutions; the search
1036      now starts from a grid over the mirror (2 x 12, and 3 x 24 for unrolled-cone),
1037      handing up to 8 distinct seeds to Solve(), which decides.
1038 
1039 Also noted: "estimator = ml" appears twice per run, i.e. two ReconstructionFactory
1040 instances are constructed in a PFRICH job - relevant for any future per-job statistics.
1041 
1042 Open follow-ups: re-measure the eta = -2.5 benchmark matrix (bench{1,2,3,5}) with
1043 plane-tangent instead of mc-truth, since every earlier number in this file was taken with
1044 truth seeding; and fix IsInside()/GetV() at the source.
1045 ================================================================================
1046 
1047 --------------------------------------------------------------------------------
1048 TAG v2.2.3a11 (created 2026-11-19, at this commit on bench/v2.2.3a8)
1049 --------------------------------------------------------------------------------
1050   Between v2.2.3a10 (d2fbace) and v2.2.3a11:
1051     5e23b1f  PhotonDirectionSeed: one option with four values, replacing
1052              UseMcTruthPhotonDirectionSeed
1053     41cb9ab  log: record the PhotonDirectionSeed option and the seeding modes
1054     43b6743  IRT: geometry-based photon direction seeds now actually find the
1055              specular points (azimuth wrap, damping, multi-start, soft acceptance)
1056     fa6e36b  log: eta=-1.9 seed comparison results and the three defects found
1057   Headline result at this tag (500 single-track 7 GeV/c pi+ events at eta=-1.9, ML,
1058   one run per setting): attached 0.6030 (track-direction) -> 0.8091 (plane-tangent) /
1059   0.8110 (unrolled-cone), against the mc-truth bound 0.8309; PID composition agreement
1060   96.52% -> 99.39%, i.e. the bound. Cost +6-11% wall time.
1061 ================================================================================