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     addPythia8,
0010     ParticleSelectorConfig,
0011     addGenParticleSelection,
0012     addFatras,
0013     addDigitization,
0014     addDigiParticleSelection,
0015 )
0016 from acts.examples.reconstruction import (
0017     addSeeding,
0018     SeedFinderConfigArg,
0019     SeedFinderOptionsArg,
0020     SeedingAlgorithm,
0021     CkfConfig,
0022     addCKFTracks,
0023     addAmbiguityResolution,
0024     addAmbiguityResolutionML,
0025     AmbiguityResolutionConfig,
0026     AmbiguityResolutionMLConfig,
0027     addVertexFitting,
0028     VertexFinder,
0029     TrackSelectorConfig,
0030 )
0031 
0032 from physmon_common import makeSetup
0033 
0034 u = acts.UnitConstants
0035 
0036 setup = makeSetup()
0037 
0038 
0039 with tempfile.TemporaryDirectory() as temp:
0040     # Running with a single thread to avoid rance conditions with Pythia8, see https://github.com/acts-project/acts/issues/3963
0041     s = acts.examples.Sequencer(
0042         events=3,
0043         numThreads=1,  # run with single thread
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     addPythia8(
0055         s,
0056         hardProcess=["Top:qqbar2ttbar=on"],
0057         npileup=200,
0058         vtxGen=acts.examples.GaussianVertexGenerator(
0059             mean=acts.Vector4(0, 0, 0, 0),
0060             stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns),
0061         ),
0062         rnd=rnd,
0063         outputDirRoot=tp,
0064     )
0065 
0066     addGenParticleSelection(
0067         s,
0068         ParticleSelectorConfig(
0069             rho=(0.0, 24 * u.mm),
0070             absZ=(0.0, 1.0 * u.m),
0071         ),
0072     )
0073 
0074     addFatras(
0075         s,
0076         setup.trackingGeometry,
0077         setup.field,
0078         rnd=rnd,
0079     )
0080 
0081     addDigitization(
0082         s,
0083         setup.trackingGeometry,
0084         setup.field,
0085         digiConfigFile=setup.digiConfig,
0086         rnd=rnd,
0087     )
0088 
0089     addDigiParticleSelection(
0090         s,
0091         ParticleSelectorConfig(
0092             pt=(0.5 * u.GeV, None),
0093             measurements=(9, None),
0094             removeNeutral=True,
0095         ),
0096     )
0097 
0098     addSeeding(
0099         s,
0100         setup.trackingGeometry,
0101         setup.field,
0102         SeedFinderConfigArg(
0103             r=(33 * u.mm, 200 * u.mm),
0104             deltaR=(1 * u.mm, 60 * u.mm),
0105             collisionRegion=(-250 * u.mm, 250 * u.mm),
0106             z=(-2000 * u.mm, 2000 * u.mm),
0107             maxSeedsPerSpM=1,
0108             sigmaScattering=5,
0109             radLengthPerSeed=0.1,
0110             minPt=0.5 * u.GeV,
0111             impactMax=3 * u.mm,
0112         ),
0113         SeedFinderOptionsArg(bFieldInZ=2 * u.T, beamPos=(0.0, 0.0)),
0114         seedingAlgorithm=SeedingAlgorithm.Default,
0115         initialSigmas=[
0116             1 * u.mm,
0117             1 * u.mm,
0118             1 * u.degree,
0119             1 * u.degree,
0120             0.1 * u.e / u.GeV,
0121             1 * u.ns,
0122         ],
0123         initialSigmaPtRel=0.01,
0124         initialVarInflation=[1.0] * 6,
0125         geoSelectionConfigFile=setup.geoSel,
0126         outputDirRoot=tp,
0127     )
0128 
0129     addCKFTracks(
0130         s,
0131         setup.trackingGeometry,
0132         setup.field,
0133         TrackSelectorConfig(
0134             pt=(0.5 * u.GeV, None),
0135             loc0=(-4.0 * u.mm, 4.0 * u.mm),
0136             nMeasurementsMin=6,
0137             maxHoles=2,
0138             maxOutliers=2,
0139         ),
0140         CkfConfig(
0141             chi2CutOffMeasurement=15.0,
0142             chi2CutOffOutlier=25.0,
0143             numMeasurementsCutOff=10,
0144             seedDeduplication=True,
0145             stayOnSeed=True,
0146         ),
0147         outputDirRoot=tp,
0148     )
0149 
0150     addAmbiguityResolutionML(
0151         s,
0152         AmbiguityResolutionMLConfig(
0153             maximumSharedHits=3, maximumIterations=1000000, nMeasurementsMin=6
0154         ),
0155         tracks="ckf_tracks",
0156         outputDirRoot=tp,
0157         onnxModelFile=Path(__file__).resolve().parent.parent.parent.parent
0158         / "thirdparty/OpenDataDetector/data/duplicateClassifier.onnx",
0159     )
0160 
0161     addAmbiguityResolution(
0162         s,
0163         AmbiguityResolutionConfig(
0164             maximumSharedHits=3,
0165             maximumIterations=100000,
0166             nMeasurementsMin=6,
0167         ),
0168         tracks="ckf_tracks",
0169         outputDirRoot=tp,
0170     )
0171 
0172     s.addAlgorithm(
0173         acts.examples.TracksToParameters(
0174             level=acts.logging.INFO,
0175             inputTracks="tracks",
0176             outputTrackParameters="trackParameters",
0177         )
0178     )
0179 
0180     addVertexFitting(
0181         s,
0182         setup.field,
0183         tracks="tracks",
0184         trackParameters="trackParameters",
0185         outputProtoVertices="amvf_gauss_notime_protovertices",
0186         outputVertices="amvf_gauss_notime_fittedVertices",
0187         seeder=acts.VertexSeedFinder.GaussianSeeder,
0188         vertexFinder=VertexFinder.AMVF,
0189         outputDirRoot=tp / "amvf_gauss_notime",
0190     )
0191 
0192     addVertexFitting(
0193         s,
0194         setup.field,
0195         tracks="tracks",
0196         trackParameters="trackParameters",
0197         outputProtoVertices="amvf_grid_time_protovertices",
0198         outputVertices="amvf_grid_time_fittedVertices",
0199         seeder=acts.VertexSeedFinder.AdaptiveGridSeeder,
0200         useTime=True,
0201         vertexFinder=VertexFinder.AMVF,
0202         outputDirRoot=tp / "amvf_grid_time",
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 
0216     shutil.move(
0217         tp / "performance_finding_ambiML.root",
0218         tp / "performance_finding_ckf_ml_solver.root",
0219     )
0220 
0221     shutil.move(
0222         tp / "performance_fitting_ambiML.root",
0223         tp / "performance_fitting_ckf_ml_solver.root",
0224     )
0225 
0226     for vertexing in ["amvf_gauss_notime", "amvf_grid_time"]:
0227         shutil.move(
0228             tp / f"{vertexing}/performance_vertexing.root",
0229             tp / f"performance_vertexing_{vertexing}.root",
0230         )
0231 
0232     for file in [
0233         "performance_seeding.root",
0234         "tracksummary_ckf.root",
0235         "performance_finding_ckf.root",
0236         "performance_fitting_ckf.root",
0237         "performance_finding_ckf_ambi.root",
0238         "performance_fitting_ckf_ambi.root",
0239         "performance_finding_ckf_ml_solver.root",
0240         "performance_fitting_ckf_ml_solver.root",
0241         "performance_vertexing_amvf_gauss_notime.root",
0242         "performance_vertexing_amvf_grid_time.root",
0243     ]:
0244         perf_file = tp / file
0245         assert perf_file.exists(), f"Performance file not found {perf_file}"
0246         shutil.copy(perf_file, setup.outdir / file)