Warning, /detector_benchmarks/benchmarks/lowq2_reconstruction/Snakefile is written in an unsupported language. File is not indexed.
0001 SIMOUTDIR="sim_output/lowq2_reconstruction/"
0002 ANALYSISDIR=SIMOUTDIR+"analysis/"
0003
0004 ##########################################################################################
0005 ### Rules for checking the reconstruction of the electron momentum
0006 ##########################################################################################
0007
0008 # Filter LowQ2 events from xrootd server - Using the acceptance events didn't work
0009 # ToDo: Do a proper investigation into how the feature to target mapping isn't unique
0010 rule filter_hepmc_for_training:
0011 input:
0012 warmup="warmup.edm4hep.root",
0013 script=workflow.source_path("filterHEPMC3.py"),
0014 output:
0015 SIMOUTDIR+"Low-Q2_Training_Events.hepmc3.tree.root",
0016 params:
0017 events="root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/SIDIS/pythia6-eic/1.0.0/18x275/q2_0to1/pythia_ep_noradcor_18x275_q2_0.000000001_1.0_run1.ab.hepmc3.tree.root",
0018 singularity: EIC_SINGULARITY_CONTAINER,
0019 shell:
0020 """
0021 python {input.script} --outFile {output} --inFile {params.events}
0022 """
0023
0024 # Run pythia6 Low-Q2 events through the simulation
0025 rule lowq2_training_sim:
0026 input:
0027 warmup="warmup.edm4hep.root",
0028 events=SIMOUTDIR+"Low-Q2_Training_Events.hepmc3.tree.root",
0029 geometry_lib=find_epic_libraries(),
0030 output:
0031 SIMOUTDIR+"Low-Q2_Training_SimEvents_{CAMPAIGN}.edm4hep.root",
0032 params:
0033 DD4HEP_HASH=get_spack_package_hash("dd4hep"),
0034 NPSIM_HASH=get_spack_package_hash("npsim"),
0035 cache: True
0036 singularity: EIC_SINGULARITY_CONTAINER,
0037 shell:
0038 """
0039 exec npsim \
0040 --runType run \
0041 --random.seed 1 \
0042 --inputFiles {input.events} \
0043 --numberOfEvents 1000000 \
0044 --compactFile $DETECTOR_PATH/epic_ip6_extended.xml \
0045 --printLevel WARNING \
0046 --outputFile {output} \
0047 --physics.rangecut 100*m
0048 """
0049
0050 # Run EICrecon to create TaggerTrackerReconstructedParticles
0051 rule lowq2_reconstruction_particles_eicrecon:
0052 params:
0053 xml=os.getenv("DETECTOR_PATH")+"/epic_ip6_extended.xml",
0054 output_collections="TaggerTrackerReconstructedParticles,MCParticles,EventHeader",
0055 ignore_plugins="janatop,LUMISPECCAL,ECTOF,BTOF,FOFFMTRK,RPOTS,B0TRK,MPGD,ECTRK,DRICH,DIRC,pid,tracking,EEMC,BEMC,FEMC,EHCAL,BHCAL,FHCAL,B0ECAL,ZDC,BTRK,BVTX,PFRICH,richgeo,evaluator,pid_lut,reco,rootfile",
0056 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0057 input:
0058 data=SIMOUTDIR+"Low-Q2_Training_SimEvents_{CAMPAIGN}.edm4hep.root",
0059 output:
0060 eicreconfile=ANALYSISDIR+"Low-Q2_test_Particles_{CAMPAIGN}.eicrecon.edm4hep.root",
0061 cache: True
0062 singularity: EIC_SINGULARITY_CONTAINER,
0063 shell:
0064 """
0065 eicrecon -Ppodio:output_file={output.eicreconfile} -PLOWQ2:TaggerTrackerTransportationPreML:beamE=18.0 -PLOWQ2:TaggerTrackerTransportationPostML:beamE=18.0 -Pdd4hep:xml_files={params.xml} \
0066 -Pjana:nevents=500000 \
0067 -Ppodio:output_collections={params.output_collections} -Pplugins_to_ignore={params.ignore_plugins} {input.data}
0068 """
0069
0070
0071 ##########################################################################################
0072 ### Rules for training new onnx reconstruction neural network
0073 ##########################################################################################
0074
0075 # Run EICrecon and create input tensors for reconstruction.
0076 rule lowq2_reconstruction_tensors_eicrecon:
0077 params:
0078 xml=os.getenv("DETECTOR_PATH")+"/epic_ip6_extended.xml",
0079 output_collections="BackwardsBeamlineHits,TaggerTrackerFeatureTensor,TaggerTrackerTargetTensor,MCParticles,EventHeader",
0080 ignore_plugins="janatop,LUMISPECCAL,ECTOF,BTOF,FOFFMTRK,RPOTS,B0TRK,MPGD,ECTRK,DRICH,DIRC,pid,tracking,EEMC,BEMC,FEMC,EHCAL,BHCAL,FHCAL,B0ECAL,ZDC,BTRK,BVTX,PFRICH,richgeo,evaluator,pid_lut,reco,rootfile",
0081 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0082 input:
0083 data=SIMOUTDIR+"Low-Q2_Training_SimEvents_{CAMPAIGN}.edm4hep.root",
0084 output:
0085 eicreconfile=ANALYSISDIR+"Low-Q2_Training_Tensors_{CAMPAIGN}.eicrecon.edm4hep.root",
0086 cache: True
0087 singularity: EIC_SINGULARITY_CONTAINER,
0088 shell:
0089 """
0090 eicrecon -Ppodio:output_file={output.eicreconfile} -PLOWQ2:TaggerTrackerTransportationPreML:beamE=18.0 -Pdd4hep:xml_files={params.xml} \
0091 -Pjana:nevents=500000 -Pjana:nskip=500000 \
0092 -Ppodio:output_collections={params.output_collections} -Pplugins_to_ignore={params.ignore_plugins} {input.data}
0093 """
0094
0095 # Processes the simulation output data for training
0096 rule lowq2_steering_reconstruction_preparation:
0097 input:
0098 script=workflow.source_path("cleanData.C"),
0099 data=ANALYSISDIR+"Low-Q2_Training_Tensors_{CAMPAIGN}.eicrecon.edm4hep.root",
0100 output:
0101 rootfile=ANALYSISDIR+"Low-Q2_Steering_Reconstruction_Data{CAMPAIGN}.root",
0102 singularity: EIC_SINGULARITY_CONTAINER,
0103 shell:
0104 """
0105 root -l -b -q '{input.script}+("{input.data}", "{output.rootfile}",18.0)'
0106 """
0107
0108 # Trains a regression model to predict the MCParticle momentum from the lowq2 tagger tracker hits.
0109 rule lowq2_steering_reconstruction_training:
0110 input:
0111 script=workflow.source_path("SteeringRegression.py"),
0112 scriptdata=workflow.source_path("LoadData.py"),
0113 scriptmodel=workflow.source_path("RegressionModel.py"),
0114 data=ANALYSISDIR+"Low-Q2_Steering_Reconstruction_Data{CAMPAIGN}.root",
0115 output:
0116 onnxfile=ANALYSISDIR+"Low-Q2_Steering_Reconstruction_Test_{CAMPAIGN}.onnx",
0117 singularity: EIC_SINGULARITY_CONTAINER,
0118 shell:
0119 """
0120 python {input.script} --dataFiles {input.data} --outModelFile {output.onnxfile} --epochs 1000
0121 """
0122
0123 # Run eicrecon with the newly trained neural network
0124 rule lowq2_steering_reconstruction_particles_trained_eicrecon:
0125 params:
0126 xml=os.getenv("DETECTOR_PATH")+"/epic_ip6_extended.xml",
0127 output_collections="TaggerTrackerReconstructedParticles,MCParticles,EventHeader",
0128 ignore_plugins="janatop,LUMISPECCAL,ECTOF,BTOF,FOFFMTRK,RPOTS,B0TRK,MPGD,ECTRK,DRICH,DIRC,pid,tracking,EEMC,BEMC,FEMC,EHCAL,BHCAL,FHCAL,B0ECAL,ZDC,BTRK,BVTX,PFRICH,richgeo,evaluator,pid_lut,reco,rootfile",
0129 EICRECON_HASH=get_spack_package_hash("eicrecon"),
0130 input:
0131 data=SIMOUTDIR+"Low-Q2_Training_SimEvents_{CAMPAIGN}.edm4hep.root",
0132 onnxfile=ANALYSISDIR+"Low-Q2_Steering_Reconstruction_Test_{CAMPAIGN}.onnx",
0133 output:
0134 eicreconfile=ANALYSISDIR+"Low-Q2_retrained_Particles_{CAMPAIGN}.eicrecon.edm4hep.root",
0135 cache: True
0136 singularity: EIC_SINGULARITY_CONTAINER,
0137 shell:
0138 """
0139 eicrecon -Ppodio:output_file={output.eicreconfile} -Pjana:nevents=500000 -PLOWQ2:TaggerTrackerTransportationPreML:beamE=18.0 -PLOWQ2:TaggerTrackerTransportationPostML:beamE=18.0 -Pdd4hep:xml_files={params.xml} \
0140 -PLOWQ2:TaggerTrackerTransportationInference:modelPath={input.onnxfile} -Ppodio:output_collections={params.output_collections} -Pplugins_to_ignore={params.ignore_plugins} {input.data}
0141 """
0142
0143 ##########################################################################################
0144 # Test and check resolutions
0145 ##########################################################################################
0146
0147 # Produce hitsograms of th resolution of TaggerTrackerReconstructedParticles compared to their MCParticles
0148 rule lowq2_reconstruction_particles_test:
0149 input:
0150 script=workflow.source_path("reconstructionAnalysis.C"),
0151 data=ANALYSISDIR+"Low-Q2_{STAGE}_Particles_{CAMPAIGN}.eicrecon.edm4hep.root",
0152 output:
0153 rootfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.root",
0154 momentumCanvas=ANALYSISDIR+"{STAGE}_momentum_resolution_{CAMPAIGN}.png",
0155 energyThetaPhiCanvas=ANALYSISDIR+"{STAGE}_energy_theta_phi_resolution_{CAMPAIGN}.png",
0156 relationCanvas=ANALYSISDIR+"{STAGE}_relation_resolution_{CAMPAIGN}.png",
0157 resolutionGraphsCanvas=ANALYSISDIR+"{STAGE}_resolution_graphs_{CAMPAIGN}.png",
0158 singularity: EIC_SINGULARITY_CONTAINER,
0159 shell:
0160 """
0161 root -l -b -q '{input.script}+("{input.data}", 18, "{output.rootfile}", "{output.momentumCanvas}", "{output.energyThetaPhiCanvas}", "{output.relationCanvas}", "{output.resolutionGraphsCanvas}")'
0162 """
0163
0164 # Check the resloutions and offsets are within tollerance
0165 rule lowq2_reconstruction_particles_check:
0166 input:
0167 script=workflow.source_path("checkResolutions.C"),
0168 rootfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.root"
0169 output:
0170 jsonfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.json"
0171 singularity: EIC_SINGULARITY_CONTAINER,
0172 shell:
0173 """
0174 root -l -b -q '{input.script}+("{input.rootfile}", "{output.jsonfile}")'
0175 """
0176
0177
0178 ##########################################################################################
0179 # Combine results
0180 ##########################################################################################
0181 def get_onnx_input(wildcards):
0182 if wildcards.STAGE == "retrained":
0183 return ANALYSISDIR + f"Low-Q2_Steering_Reconstruction_Test_{wildcards.CAMPAIGN}.onnx"
0184 else:
0185 return []
0186
0187 rule lowq2_reconstruction:
0188 input:
0189 rootfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.root",
0190 momentumCanvas=ANALYSISDIR+"{STAGE}_momentum_resolution_{CAMPAIGN}.png",
0191 energyThetaPhiCanvas=ANALYSISDIR+"{STAGE}_energy_theta_phi_resolution_{CAMPAIGN}.png",
0192 relationCanvas=ANALYSISDIR+"{STAGE}_relation_resolution_{CAMPAIGN}.png",
0193 resolutionGraphsCanvas=ANALYSISDIR+"{STAGE}_resolution_graphs_{CAMPAIGN}.png",
0194 jsonfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.json",
0195 onnxfile=get_onnx_input,
0196 output:
0197 directory("results/lowq2_reconstruction/{STAGE}_{CAMPAIGN}/")
0198 singularity: EIC_SINGULARITY_CONTAINER,
0199 shell:
0200 """
0201 mkdir {output}
0202 cp -r {input} {output}
0203 """
0204
0205 ##########################################################################################
0206 # Defualt running
0207 ##########################################################################################
0208 rule lowq2_reconstruction_local:
0209 input:
0210 "results/lowq2_reconstruction/test_local/"
0211
0212 rule lowq2_reconstruction_retrained:
0213 input:
0214 "results/lowq2_reconstruction/retrained_local/"