Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10: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     outputDir: Path,
0016     digiConfigFile: Path,
0017     s: acts.examples.Sequencer = None,
0018     inputParticlePath: Optional[Path] = None,
0019 ):
0020     from acts.examples.simulation import (
0021         addParticleGun,
0022         MomentumConfig,
0023         EtaConfig,
0024         ParticleConfig,
0025         addFatras,
0026         addDigitization,
0027     )
0028     from acts.examples.reconstruction import (
0029         addSeeding,
0030         SeedingAlgorithm,
0031         TruthSeedRanges,
0032         addGx2fTracks,
0033     )
0034 
0035     s = s or acts.examples.Sequencer(
0036         events=10000, numThreads=-1, logLevel=acts.logging.INFO
0037     )
0038 
0039     rnd = acts.examples.RandomNumbers()
0040     outputDir = Path(outputDir)
0041 
0042     if inputParticlePath is None:
0043         addParticleGun(
0044             s,
0045             MomentumConfig(100.0 * u.GeV, 100.0 * u.GeV, transverse=True),
0046             EtaConfig(-2.0, 2.0),
0047             ParticleConfig(2, acts.PdgParticle.eMuon, False),
0048             multiplicity=1,
0049             rnd=rnd,
0050             outputDirRoot=outputDir,
0051         )
0052     else:
0053         acts.logging.getLogger("Truth tracking example").info(
0054             "Reading particles from %s", inputParticlePath.resolve()
0055         )
0056         assert inputParticlePath.exists()
0057         s.addReader(
0058             acts.examples.RootParticleReader(
0059                 level=acts.logging.INFO,
0060                 filePath=str(inputParticlePath.resolve()),
0061                 outputParticles="particles_input",
0062             )
0063         )
0064 
0065     addFatras(
0066         s,
0067         trackingGeometry,
0068         field,
0069         rnd=rnd,
0070         enableInteractions=True,
0071     )
0072 
0073     addDigitization(
0074         s,
0075         trackingGeometry,
0076         field,
0077         digiConfigFile=digiConfigFile,
0078         rnd=rnd,
0079     )
0080 
0081     addSeeding(
0082         s,
0083         trackingGeometry,
0084         field,
0085         seedingAlgorithm=SeedingAlgorithm.TruthSmeared,
0086         rnd=rnd,
0087         truthSeedRanges=TruthSeedRanges(
0088             pt=(1 * u.GeV, None),
0089             nHits=(9, None),
0090         ),
0091     )
0092 
0093     addGx2fTracks(
0094         s,
0095         trackingGeometry,
0096         field,
0097         nUpdateMax=17,
0098         relChi2changeCutOff=1e-7,
0099     )
0100 
0101     # Output
0102     s.addWriter(
0103         acts.examples.RootTrackStatesWriter(
0104             level=acts.logging.INFO,
0105             inputTracks="tracks",
0106             inputParticles="truth_seeds_selected",
0107             inputTrackParticleMatching="track_particle_matching",
0108             inputSimHits="simhits",
0109             inputMeasurementSimHitsMap="measurement_simhits_map",
0110             filePath=str(outputDir / "trackstates_gx2f.root"),
0111         )
0112     )
0113 
0114     s.addWriter(
0115         acts.examples.RootTrackSummaryWriter(
0116             level=acts.logging.INFO,
0117             inputTracks="tracks",
0118             inputParticles="truth_seeds_selected",
0119             inputTrackParticleMatching="track_particle_matching",
0120             filePath=str(outputDir / "tracksummary_gx2f.root"),
0121             writeGx2fSpecific=True,
0122         )
0123     )
0124 
0125     s.addWriter(
0126         acts.examples.TrackFitterPerformanceWriter(
0127             level=acts.logging.INFO,
0128             inputTracks="tracks",
0129             inputParticles="truth_seeds_selected",
0130             inputTrackParticleMatching="track_particle_matching",
0131             filePath=str(outputDir / "performance_gx2f.root"),
0132         )
0133     )
0134 
0135     return s
0136 
0137 
0138 if "__main__" == __name__:
0139     srcdir = Path(__file__).resolve().parent.parent.parent.parent
0140 
0141     # detector, trackingGeometry, _ = getOpenDataDetector()
0142     detector, trackingGeometry, decorators = acts.examples.GenericDetector.create()
0143 
0144     field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
0145 
0146     runTruthTrackingGx2f(
0147         trackingGeometry=trackingGeometry,
0148         # decorators=decorators,
0149         field=field,
0150         digiConfigFile=srcdir
0151         / "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json",
0152         # "thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json",
0153         # outputCsv=True,
0154         # inputParticlePath=inputParticlePath,
0155         outputDir=Path.cwd(),
0156     ).run()