Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:09

0001 #!/usr/bin/env python3
0002 
0003 from pathlib import Path
0004 from typing import Optional
0005 
0006 import acts
0007 import acts.examples
0008 
0009 u = acts.UnitConstants
0010 
0011 
0012 def runTruthTrackingGx2f(
0013     trackingGeometry: acts.TrackingGeometry,
0014     field: acts.MagneticFieldProvider,
0015     digiConfigFile: Path,
0016     outputDir: Path,
0017     inputParticlePath: Optional[Path] = None,
0018     s: acts.examples.Sequencer = None,
0019 ):
0020     from acts.examples.simulation import (
0021         addParticleGun,
0022         ParticleConfig,
0023         EtaConfig,
0024         PhiConfig,
0025         MomentumConfig,
0026         ParticleSelectorConfig,
0027         addFatras,
0028         addDigitization,
0029     )
0030     from acts.examples.reconstruction import (
0031         addSeeding,
0032         SeedingAlgorithm,
0033         addGx2fTracks,
0034     )
0035 
0036     s = s or acts.examples.Sequencer(
0037         events=100, numThreads=-1, logLevel=acts.logging.INFO
0038     )
0039 
0040     rnd = acts.examples.RandomNumbers(seed=42)
0041     outputDir = Path(outputDir)
0042 
0043     if inputParticlePath is None:
0044         addParticleGun(
0045             s,
0046             ParticleConfig(num=1, pdg=acts.PdgParticle.eMuon, randomizeCharge=True),
0047             EtaConfig(-3.0, 3.0, uniform=True),
0048             MomentumConfig(1.0 * u.GeV, 100.0 * u.GeV, transverse=True),
0049             PhiConfig(0.0, 360.0 * u.degree),
0050             vtxGen=acts.examples.GaussianVertexGenerator(
0051                 mean=acts.Vector4(0, 0, 0, 0),
0052                 stddev=acts.Vector4(0, 0, 0, 0),
0053             ),
0054             multiplicity=1,
0055             rnd=rnd,
0056             outputDirRoot=outputDir,
0057         )
0058     else:
0059         acts.logging.getLogger("Truth tracking example").info(
0060             "Reading particles from %s", inputParticlePath.resolve()
0061         )
0062         assert inputParticlePath.exists()
0063         s.addReader(
0064             acts.examples.RootParticleReader(
0065                 level=acts.logging.INFO,
0066                 filePath=str(inputParticlePath.resolve()),
0067                 outputParticles="particles_input",
0068             )
0069         )
0070 
0071     addFatras(
0072         s,
0073         trackingGeometry,
0074         field,
0075         rnd=rnd,
0076         enableInteractions=True,
0077         postSelectParticles=ParticleSelectorConfig(
0078             pt=(0.9 * u.GeV, None),
0079             hits=(7, None),
0080             removeNeutral=True,
0081             removeSecondaries=True,
0082         ),
0083     )
0084 
0085     addDigitization(
0086         s,
0087         trackingGeometry,
0088         field,
0089         digiConfigFile=digiConfigFile,
0090         rnd=rnd,
0091     )
0092 
0093     addSeeding(
0094         s,
0095         trackingGeometry,
0096         field,
0097         rnd=rnd,
0098         inputParticles="particles_input",
0099         seedingAlgorithm=SeedingAlgorithm.TruthSmeared,
0100         particleHypothesis=acts.ParticleHypothesis.muon,
0101     )
0102 
0103     addGx2fTracks(
0104         s,
0105         trackingGeometry,
0106         field,
0107         nUpdateMax=17,
0108         relChi2changeCutOff=1e-7,
0109         multipleScattering=True,
0110     )
0111 
0112     s.addAlgorithm(
0113         acts.examples.TrackSelectorAlgorithm(
0114             level=acts.logging.INFO,
0115             inputTracks="tracks",
0116             outputTracks="selected-tracks",
0117             selectorConfig=acts.TrackSelector.Config(
0118                 minMeasurements=7,
0119             ),
0120         )
0121     )
0122     s.addWhiteboardAlias("tracks", "selected-tracks")
0123 
0124     s.addWriter(
0125         acts.examples.RootTrackStatesWriter(
0126             level=acts.logging.INFO,
0127             inputTracks="tracks",
0128             inputParticles="particles_selected",
0129             inputTrackParticleMatching="track_particle_matching",
0130             inputSimHits="simhits",
0131             inputMeasurementSimHitsMap="measurement_simhits_map",
0132             filePath=str(outputDir / "trackstates_gx2f.root"),
0133         )
0134     )
0135 
0136     s.addWriter(
0137         acts.examples.RootTrackSummaryWriter(
0138             level=acts.logging.INFO,
0139             inputTracks="tracks",
0140             inputParticles="particles_selected",
0141             inputTrackParticleMatching="track_particle_matching",
0142             filePath=str(outputDir / "tracksummary_gx2f.root"),
0143             writeGx2fSpecific=True,
0144         )
0145     )
0146 
0147     s.addWriter(
0148         acts.examples.TrackFitterPerformanceWriter(
0149             level=acts.logging.INFO,
0150             inputTracks="tracks",
0151             inputParticles="particles_selected",
0152             inputTrackParticleMatching="track_particle_matching",
0153             filePath=str(outputDir / "performance_gx2f.root"),
0154         )
0155     )
0156 
0157     return s
0158 
0159 
0160 if "__main__" == __name__:
0161     srcdir = Path(__file__).resolve().parent.parent.parent.parent
0162 
0163     # ODD
0164     from acts.examples.odd import getOpenDataDetector
0165 
0166     detector = getOpenDataDetector()
0167     trackingGeometry = detector.trackingGeometry()
0168     digiConfigFile = (
0169         srcdir / "thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json"
0170     )
0171 
0172     ## GenericDetector
0173     # detector = acts.examples.GenericDetector()
0174     # trackingGeometry = detector.trackingGeometry()
0175     # digiConfigFile = (
0176     #     srcdir
0177     #     / "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
0178     # )
0179 
0180     field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
0181 
0182     runTruthTrackingGx2f(
0183         trackingGeometry=trackingGeometry,
0184         field=field,
0185         digiConfigFile=digiConfigFile,
0186         outputDir=Path.cwd(),
0187     ).run()