Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:30:57

0001 #!/usr/bin/env python3
0002 import os
0003 from typing import Optional
0004 import argparse
0005 from pathlib import Path
0006 
0007 from acts.examples import (
0008     Sequencer,
0009     ProcessCode,
0010     RootMaterialTrackWriter,
0011     JsonFormat,
0012 )
0013 
0014 import acts
0015 import acts.examples.dd4hep
0016 
0017 from acts import (
0018     Vector4,
0019     UnitConstants as u,
0020     SurfaceMaterialMapper,
0021     VolumeMaterialMapper,
0022     Navigator,
0023     Propagator,
0024     StraightLineStepper,
0025     MaterialMapJsonConverter,
0026 )
0027 
0028 
0029 import json
0030 import build_geometry_ePIC as geo
0031 
0032 
0033 def runMaterialValidation(
0034     trackingGeometry,
0035     decorators,
0036     outputDir,
0037     outputName,
0038     nevents=1000,
0039     ntests=1000,
0040     dumpPropagationSteps=False,
0041     s=None,
0042 ):
0043     s = s or Sequencer(events=nevents, numThreads=-1)
0044 
0045     for decorator in decorators:
0046         s.addContextDecorator(decorator)
0047         # for decorator in decorators:
0048         # assert decorator.decorate(context) == ProcessCode.SUCCESS
0049 
0050 
0051     nav = acts.Navigator(
0052         trackingGeometry=trackingGeometry,
0053         resolveSensitive=True,
0054         resolveMaterial=True,
0055         resolvePassive=True,
0056     )
0057 
0058     stepper = StraightLineStepper()
0059 
0060     # prop    = Propagator(stepper, nav)
0061         # mapper = SurfaceMaterialMapper(level=acts.logging.INFO, propagator=propagator)
0062         # mmAlgCfg.materialSurfaceMapper = mapper
0063 
0064     prop = acts.examples.ConcretePropagator(acts.Propagator(stepper, nav))
0065 
0066     alg = acts.examples.PropagationAlgorithm(
0067         propagatorImpl=prop,
0068         level=acts.logging.INFO,
0069         randomNumberSvc=acts.examples.RandomNumbers(),
0070         ntests=ntests,
0071         sterileLogger=False,
0072         recordMaterialInteractions=True,
0073         d0Sigma=0,
0074         z0Sigma=0,
0075     )
0076 
0077     s.addAlgorithm(alg)
0078 
0079     outpath = os.path.join(outputDir, outputName)
0080     s.addWriter(
0081         RootMaterialTrackWriter(
0082             level=acts.logging.INFO,
0083             collection=alg.config.propagationMaterialCollection,
0084             filePath=outpath,
0085             storeSurface=True,
0086             storeVolume=True,
0087         )
0088     )
0089     print("Done! Output at "+outpath)
0090     outpath = outputDir + "/propagation_steps.root"
0091     if dumpPropagationSteps:
0092         s.addWriter(
0093             acts.examples.RootPropagationStepsWriter(
0094                 level=acts.logging.INFO,
0095                 collection=alg.config.propagationStepCollection,
0096                 filePath=outpath,
0097             )
0098         )
0099     print("      Propogation steps dumped at "+outpath)
0100 
0101     return s
0102 
0103 # python material_validation_ePIC.py --xmlFile epic_craterlake_matmap.xml
0104 if "__main__" == __name__:
0105 
0106     p = argparse.ArgumentParser(
0107         description="Script to produce propogation validation for ePIC material mapping."
0108     )
0109     p.add_argument(
0110         "--xmlFile",
0111         default=os.environ.get("DETECTOR_PATH", "")+"epic_craterlake.xml",
0112         help="input xml file containing ePIC geometry",
0113     )
0114     p.add_argument(
0115         "--matFile",
0116         type=str,
0117         default="material-map.json",
0118         help="input material map file, can be either Json or Cbor",
0119     )
0120     p.add_argument(
0121         "--outputName",
0122         type=str,
0123         default="propagation-material.root",
0124         help="customized name of the output rootfile",
0125     )
0126     p.add_argument(
0127         "-n","--nevents",
0128         type=int,
0129         default=100,
0130         help="number of events to run",
0131     )
0132     p.add_argument(
0133         "-t","--ntests",
0134         type=int,
0135         default=100,
0136         help="number of tests per event",
0137     )
0138 
0139     args = p.parse_args()
0140     print(args)
0141     
0142     if 'json' in args.matFile:
0143         fmt = JsonFormat.Json
0144 
0145     elif 'cbor' in args.matFile:
0146         fmt = JsonFormat.Cbor
0147     else:
0148         print('ERROR(material_validation_ePIC.py): please provide a material map file in .json or .cbor format')
0149         exit()
0150 
0151 
0152     detector, trackingGeometry, decorators = geo.buildePICGeometry(args.xmlFile, args.matFile)
0153 
0154     runMaterialValidation(
0155         trackingGeometry, decorators, outputDir=os.getcwd(), outputName=args.outputName, nevents=args.nevents, ntests=args.ntests
0156         ).run()
0157