Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:13:26

0001 #!/usr/bin/env python3
0002 
0003 import tempfile
0004 from pathlib import Path
0005 import shutil
0006 
0007 import acts
0008 from acts.examples.simulation import (
0009     addParticleGun,
0010     MomentumConfig,
0011     EtaConfig,
0012     PhiConfig,
0013     ParticleConfig,
0014     addFatras,
0015     addDigitization,
0016     ParticleSelectorConfig,
0017     addDigiParticleSelection,
0018 )
0019 
0020 from acts.examples.reconstruction import (
0021     addSeeding,
0022     TrackSmearingSigmas,
0023     SeedFinderConfigArg,
0024     SeedFinderOptionsArg,
0025     SeedingAlgorithm,
0026     TruthEstimatedSeedingAlgorithmConfigArg,
0027     CkfConfig,
0028     addCKFTracks,
0029     TrackSelectorConfig,
0030 )
0031 
0032 from physmon_common import makeSetup
0033 
0034 u = acts.UnitConstants
0035 
0036 setup = makeSetup()
0037 
0038 
0039 def run_ckf_tracking(label, seeding):
0040     with tempfile.TemporaryDirectory() as temp:
0041         s = acts.examples.Sequencer(
0042             events=10000,
0043             numThreads=-1,
0044             logLevel=acts.logging.INFO,
0045         )
0046 
0047         tp = Path(temp)
0048 
0049         for d in setup.decorators:
0050             s.addContextDecorator(d)
0051 
0052         rnd = acts.examples.RandomNumbers(seed=42)
0053 
0054         addParticleGun(
0055             s,
0056             MomentumConfig(1.0 * u.GeV, 10.0 * u.GeV, transverse=True),
0057             EtaConfig(-3.0, 3.0, uniform=True),
0058             PhiConfig(0.0, 360.0 * u.degree),
0059             ParticleConfig(1, acts.PdgParticle.eMuon, randomizeCharge=True),
0060             vtxGen=acts.examples.GaussianVertexGenerator(
0061                 mean=acts.Vector4(0, 0, 0, 0),
0062                 stddev=acts.Vector4(
0063                     0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 1.0 * u.ns
0064                 ),
0065             ),
0066             multiplicity=1,
0067             rnd=rnd,
0068         )
0069 
0070         addFatras(
0071             s,
0072             setup.trackingGeometry,
0073             setup.field,
0074             enableInteractions=True,
0075             rnd=rnd,
0076         )
0077 
0078         addDigitization(
0079             s,
0080             setup.trackingGeometry,
0081             setup.field,
0082             digiConfigFile=setup.digiConfig,
0083             rnd=rnd,
0084         )
0085 
0086         addDigiParticleSelection(
0087             s,
0088             ParticleSelectorConfig(
0089                 pt=(0.9 * u.GeV, None),
0090                 measurements=(9, None),
0091                 removeNeutral=True,
0092             ),
0093         )
0094 
0095         addSeeding(
0096             s,
0097             setup.trackingGeometry,
0098             setup.field,
0099             TrackSmearingSigmas(  # only used by SeedingAlgorithm.TruthSmeared
0100                 # zero eveything so the CKF has a chance to find the measurements
0101                 loc0=0,
0102                 loc0PtA=0,
0103                 loc0PtB=0,
0104                 loc1=0,
0105                 loc1PtA=0,
0106                 loc1PtB=0,
0107                 time=0,
0108                 phi=0,
0109                 theta=0,
0110                 ptRel=0,
0111             ),
0112             SeedFinderConfigArg(
0113                 r=(33 * u.mm, 200 * u.mm),
0114                 deltaR=(1 * u.mm, 60 * u.mm),
0115                 collisionRegion=(-250 * u.mm, 250 * u.mm),
0116                 z=(-2000 * u.mm, 2000 * u.mm),
0117                 maxSeedsPerSpM=1,
0118                 sigmaScattering=5,
0119                 radLengthPerSeed=0.1,
0120                 minPt=0.5 * u.GeV,
0121                 impactMax=3 * u.mm,
0122             ),
0123             SeedFinderOptionsArg(bFieldInZ=2 * u.T),
0124             TruthEstimatedSeedingAlgorithmConfigArg(deltaR=(10.0 * u.mm, None)),
0125             seedingAlgorithm=seeding,
0126             initialSigmas=[
0127                 1 * u.mm,
0128                 1 * u.mm,
0129                 1 * u.degree,
0130                 1 * u.degree,
0131                 0.1 * u.e / u.GeV,
0132                 1 * u.ns,
0133             ],
0134             initialSigmaPtRel=0.01,
0135             initialVarInflation=[1.0] * 6,
0136             geoSelectionConfigFile=setup.geoSel,
0137             rnd=rnd,  # only used by SeedingAlgorithm.TruthSmeared
0138             outputDirRoot=tp,
0139         )
0140 
0141         addCKFTracks(
0142             s,
0143             setup.trackingGeometry,
0144             setup.field,
0145             TrackSelectorConfig(
0146                 pt=(0.9 * u.GeV, None),
0147                 loc0=(-4.0 * u.mm, 4.0 * u.mm),
0148                 nMeasurementsMin=6,
0149                 maxHoles=2,
0150                 maxOutliers=2,
0151             ),
0152             CkfConfig(
0153                 chi2CutOffMeasurement=15.0,
0154                 chi2CutOffOutlier=25.0,
0155                 numMeasurementsCutOff=10,
0156                 seedDeduplication=(
0157                     True if seeding != SeedingAlgorithm.TruthSmeared else False
0158                 ),
0159                 stayOnSeed=True if seeding != SeedingAlgorithm.TruthSmeared else False,
0160             ),
0161             outputDirRoot=tp,
0162         )
0163 
0164         s.run()
0165 
0166         for file in (
0167             ["performance_seeding.root"]
0168             if seeding != SeedingAlgorithm.TruthSmeared
0169             else []
0170         ) + [
0171             "tracksummary_ckf.root",
0172             "performance_finding_ckf.root",
0173             "performance_fitting_ckf.root",
0174         ]:
0175             perf_file = tp / file
0176             assert perf_file.exists(), f"Performance file not found {perf_file}"
0177             (setup.outdir / label).mkdir(parents=True, exist_ok=True)
0178             shutil.copy(perf_file, setup.outdir / label / file)
0179 
0180 
0181 for label, seeding in [
0182     ("truth_smeared", SeedingAlgorithm.TruthSmeared),
0183     ("truth_estimated", SeedingAlgorithm.TruthEstimated),
0184     ("seeded", SeedingAlgorithm.Default),
0185     ("orthogonal", SeedingAlgorithm.Orthogonal),
0186 ]:
0187     run_ckf_tracking(label, seeding)