Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:49:40

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 from acts.examples.reconstruction import (
0020     addSeeding,
0021     SeedFinderConfigArg,
0022     SeedFinderOptionsArg,
0023     SeedingAlgorithm,
0024     CkfConfig,
0025     addCKFTracks,
0026     addAmbiguityResolution,
0027     AmbiguityResolutionConfig,
0028     addVertexFitting,
0029     VertexFinder,
0030     TrackSelectorConfig,
0031 )
0032 
0033 from physmon_common import makeSetup
0034 
0035 u = acts.UnitConstants
0036 
0037 setup = makeSetup()
0038 
0039 
0040 with tempfile.TemporaryDirectory() as temp:
0041     s = acts.examples.Sequencer(
0042         events=3,
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(10, acts.PdgParticle.eMuon, randomizeCharge=True),
0060         vtxGen=acts.examples.GaussianVertexGenerator(
0061             mean=acts.Vector4(0, 0, 0, 0),
0062             stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 1.0 * u.ns),
0063         ),
0064         multiplicity=50,
0065         rnd=rnd,
0066     )
0067 
0068     addFatras(
0069         s,
0070         setup.trackingGeometry,
0071         setup.field,
0072         rnd=rnd,
0073     )
0074 
0075     addDigitization(
0076         s,
0077         setup.trackingGeometry,
0078         setup.field,
0079         digiConfigFile=setup.digiConfig,
0080         rnd=rnd,
0081     )
0082 
0083     addDigiParticleSelection(
0084         s,
0085         ParticleSelectorConfig(
0086             pt=(0.9 * u.GeV, None),
0087             measurements=(9, None),
0088             removeNeutral=True,
0089         ),
0090     )
0091 
0092     addSeeding(
0093         s,
0094         setup.trackingGeometry,
0095         setup.field,
0096         SeedFinderConfigArg(
0097             r=(33 * u.mm, 200 * u.mm),
0098             deltaR=(1 * u.mm, 300 * u.mm),
0099             collisionRegion=(-250 * u.mm, 250 * u.mm),
0100             z=(-2000 * u.mm, 2000 * u.mm),
0101             maxSeedsPerSpM=1,
0102             sigmaScattering=5,
0103             radLengthPerSeed=0.1,
0104             minPt=0.5 * u.GeV,
0105             impactMax=3 * u.mm,
0106         ),
0107         SeedFinderOptionsArg(bFieldInZ=2 * u.T, beamPos=(0.0, 0.0)),
0108         seedingAlgorithm=SeedingAlgorithm.GridTriplet,
0109         initialSigmas=[
0110             1 * u.mm,
0111             1 * u.mm,
0112             1 * u.degree,
0113             1 * u.degree,
0114             0 * u.e / u.GeV,
0115             1 * u.ns,
0116         ],
0117         initialSigmaQoverPt=0.1 * u.e / u.GeV,
0118         initialSigmaPtRel=0.1,
0119         initialVarInflation=[1.0] * 6,
0120         geoSelectionConfigFile=setup.geoSel,
0121         outputDirRoot=tp,
0122     )
0123 
0124     addCKFTracks(
0125         s,
0126         setup.trackingGeometry,
0127         setup.field,
0128         TrackSelectorConfig(
0129             pt=(0.9 * u.GeV, None),
0130             loc0=(-4.0 * u.mm, 4.0 * u.mm),
0131             nMeasurementsMin=6,
0132             maxHoles=2,
0133             maxOutliers=2,
0134         ),
0135         CkfConfig(
0136             chi2CutOffMeasurement=15.0,
0137             chi2CutOffOutlier=25.0,
0138             numMeasurementsCutOff=10,
0139             seedDeduplication=True,
0140             stayOnSeed=True,
0141         ),
0142         outputDirRoot=tp,
0143     )
0144 
0145     addAmbiguityResolution(
0146         s,
0147         AmbiguityResolutionConfig(
0148             maximumSharedHits=3,
0149             maximumIterations=100000,
0150             nMeasurementsMin=6,
0151         ),
0152         outputDirRoot=tp,
0153     )
0154 
0155     s.addAlgorithm(
0156         acts.examples.TracksToParameters(
0157             level=acts.logging.INFO,
0158             inputTracks="tracks",
0159             outputTrackParameters="trackParameters",
0160         )
0161     )
0162 
0163     # Choosing a seeder only has an effect on VertexFinder.AMVF. For
0164     # VertexFinder.IVF we always use acts.VertexSeedFinder.GaussianSeeder
0165     # (Python binding is not implemented).
0166     # Setting useTime also only has an effect on VertexFinder.AMVF due to
0167     # the same reason.
0168     addVertexFitting(
0169         s,
0170         setup.field,
0171         trackParameters="trackParameters",
0172         outputProtoVertices="ivf_notime_protovertices",
0173         outputVertices="ivf_notime_fittedVertices",
0174         vertexFinder=VertexFinder.Iterative,
0175         outputDirRoot=tp / "ivf_notime",
0176         writeTrackInfo=True,
0177     )
0178 
0179     addVertexFitting(
0180         s,
0181         setup.field,
0182         trackParameters="trackParameters",
0183         outputProtoVertices="amvf_gauss_notime_protovertices",
0184         outputVertices="amvf_gauss_notime_fittedVertices",
0185         seeder=acts.VertexSeedFinder.GaussianSeeder,
0186         useTime=False,  # Time seeding not implemented for the Gaussian seeder
0187         vertexFinder=VertexFinder.AMVF,
0188         outputDirRoot=tp / "amvf_gauss_notime",
0189         writeTrackInfo=True,
0190     )
0191 
0192     addVertexFitting(
0193         s,
0194         setup.field,
0195         trackParameters="trackParameters",
0196         outputProtoVertices="amvf_grid_time_protovertices",
0197         outputVertices="amvf_grid_time_fittedVertices",
0198         seeder=acts.VertexSeedFinder.AdaptiveGridSeeder,
0199         useTime=True,
0200         vertexFinder=VertexFinder.AMVF,
0201         outputDirRoot=tp / "amvf_grid_time",
0202         writeTrackInfo=True,
0203     )
0204 
0205     s.run()
0206 
0207     shutil.move(
0208         tp / "performance_finding_ambi.root",
0209         tp / "performance_finding_ckf_ambi.root",
0210     )
0211     shutil.move(
0212         tp / "performance_fitting_ambi.root",
0213         tp / "performance_fitting_ckf_ambi.root",
0214     )
0215     for vertexing in ["ivf_notime", "amvf_gauss_notime", "amvf_grid_time"]:
0216         shutil.move(
0217             tp / f"{vertexing}/performance_vertexing.root",
0218             tp / f"performance_vertexing_{vertexing}.root",
0219         )
0220 
0221     for file in [
0222         "performance_seeding.root",
0223         "tracksummary_ckf.root",
0224         "performance_finding_ckf.root",
0225         "performance_fitting_ckf.root",
0226         "performance_finding_ckf_ambi.root",
0227         "performance_fitting_ckf_ambi.root",
0228         "performance_vertexing_ivf_notime.root",
0229         "performance_vertexing_amvf_gauss_notime.root",
0230         "performance_vertexing_amvf_grid_time.root",
0231     ]:
0232         perf_file = tp / file
0233         assert perf_file.exists(), f"Performance file not found {perf_file}"
0234         shutil.copy(perf_file, setup.outdir / file)