def test_root_particle_writer(tmp_path, conf_const, ptcl_gun, assert_root_hash): s = Sequencer(numThreads=1, events=10) evGen = ptcl_gun(s) file = tmp_path / "particles.root" assert not file.exists() s.addWriter( conf_const( RootParticleWriter, acts.logging.INFO, inputParticles=evGen.config.outputParticles, filePath=str(file), )) s.run() assert file.exists() assert file.stat().st_size > 1024 * 10 assert_root_hash(file.name, file)
def addParticleGun( s: Sequencer, outputDirCsv: Optional[Union[Path, str]] = None, outputDirRoot: Optional[Union[Path, str]] = None, momentumConfig: MomentumConfig = MomentumConfig(), etaConfig: EtaConfig = EtaConfig(), phiConfig: PhiConfig = PhiConfig(), particleConfig: ParticleConfig = ParticleConfig(), multiplicity: int = 1, vtxGen: Optional[EventGenerator.VertexGenerator] = None, printParticles: bool = False, rnd: Optional[RandomNumbers] = None, ) -> Sequencer: """This function steers the particle generation using the particle gun Parameters ---------- s: Sequencer the sequencer module to which we add the particle gun steps (returned from addParticleGun) outputDirCsv : Path|str, path, None the output folder for the Csv output, None triggers no output outputDirRoot : Path|str, path, None the output folder for the Root output, None triggers no output momentumConfig : MomentumConfig(min, max, transverse) momentum configuration: minimum momentum, maximum momentum, transverse etaConfig : EtaConfig(min, max, uniform) pseudorapidity configuration: eta min, eta max, uniform phiConfig : PhiConfig(min, max) azimuthal angle configuration: phi min, phi max particleConfig : ParticleConfig(num, pdg, randomizeCharge) partilce configuration: number of particles, particle type, charge flip multiplicity : int, 1 number of generated vertices vtxGen : VertexGenerator, None vertex generator module printParticles : bool, False print generated particles rnd : RandomNumbers, None random number generator """ if int(s.config.logLevel) <= int(acts.logging.DEBUG): acts.examples.dump_args_calls(locals()) # Preliminaries rnd = rnd or RandomNumbers(seed=228) # Input evGen = EventGenerator( level=s.config.logLevel, generators=[ EventGenerator.Generator( multiplicity=FixedMultiplicityGenerator(n=multiplicity), vertex=vtxGen or acts.examples.GaussianVertexGenerator( stddev=acts.Vector4(0, 0, 0, 0), mean=acts.Vector4(0, 0, 0, 0) ), particles=acts.examples.ParametricParticleGenerator( **acts.examples.defaultKWArgs( p=(momentumConfig.min, momentumConfig.max), pTransverse=momentumConfig.transverse, eta=(etaConfig.min, etaConfig.max), phi=(phiConfig.min, phiConfig.max), etaUniform=etaConfig.uniform, numParticles=particleConfig.num, pdg=particleConfig.pdg, randomizeCharge=particleConfig.randomizeCharge, ) ), ) ], outputParticles="particles_input", randomNumbers=rnd, ) s.addReader(evGen) if printParticles: s.addAlgorithm( ParticlesPrinter( level=s.config.logLevel, inputParticles=evGen.config.outputParticles ) ) if outputDirCsv is not None: outputDirCsv = Path(outputDirCsv) if not outputDirCsv.exists(): outputDirCsv.mkdir() s.addWriter( CsvParticleWriter( level=s.config.logLevel, inputParticles=evGen.config.outputParticles, outputDir=str(outputDirCsv), outputStem="particles", ) ) if outputDirRoot is not None: outputDirRoot = Path(outputDirRoot) if not outputDirRoot.exists(): outputDirRoot.mkdir() s.addWriter( RootParticleWriter( level=s.config.logLevel, inputParticles=evGen.config.outputParticles, filePath=str(outputDirRoot / "particles.root"), ) ) return s