Back to home page

EIC code displayed by LXR

 
 

    


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/epic_ip6_extended.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     shell:
0019         """
0020         python {input.script} --outFile {output} --inFile {params.events}
0021         """
0022 
0023 # Run pythia6 Low-Q2 events through the simulation
0024 rule lowq2_training_sim:
0025     input:
0026         warmup="warmup/epic_ip6_extended.edm4hep.root",  
0027         events=SIMOUTDIR+"Low-Q2_Training_Events.hepmc3.tree.root",      
0028     output:
0029         SIMOUTDIR+"Low-Q2_Training_SimEvents_{CAMPAIGN}.edm4hep.root",
0030     shell:
0031         """
0032             exec npsim \
0033             --runType run \
0034             --random.seed 1 \
0035             --inputFiles {input.events} \
0036             --numberOfEvents 1000000 \
0037             --compactFile $DETECTOR_PATH/epic_ip6_extended.xml \
0038             --printLevel WARNING \
0039             --outputFile {output} \
0040             --physics.rangecut 100*m 
0041         """
0042 
0043 # Run EICrecon to create TaggerTrackerReconstructedParticles
0044 rule lowq2_reconstruction_particles_eicrecon:
0045     params:
0046         xml=os.getenv("DETECTOR_PATH")+"/epic_ip6_extended.xml",
0047         output_collections="TaggerTrackerReconstructedParticles,MCParticles,EventHeader",
0048         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"
0049     input:
0050         data=SIMOUTDIR+"Low-Q2_Training_SimEvents_{CAMPAIGN}.edm4hep.root",
0051     output:
0052         eicreconfile=ANALYSISDIR+"Low-Q2_test_Particles_{CAMPAIGN}.eicrecon.edm4hep.root",
0053     shell:
0054         """
0055         eicrecon -Ppodio:output_file={output.eicreconfile} -PLOWQ2:TaggerTrackerTransportationPreML:beamE=18.0 -PLOWQ2:TaggerTrackerTransportationPostML:beamE=18.0 -Pdd4hep:xml_files={params.xml} \
0056         -Pjana:nevents=500000 \
0057         -Ppodio:output_collections={params.output_collections} -Pplugins_to_ignore={params.ignore_plugins}  {input.data} 
0058         """
0059 
0060 
0061 ##########################################################################################
0062 ### Rules for training new onnx reconstruction neural network
0063 ##########################################################################################
0064 
0065 # Run EICrecon and create input tensors for reconstruction.
0066 rule lowq2_reconstruction_tensors_eicrecon:
0067     params:
0068         xml=os.getenv("DETECTOR_PATH")+"/epic_ip6_extended.xml",
0069         output_collections="BackwardsBeamlineHits,TaggerTrackerFeatureTensor,TaggerTrackerTargetTensor,MCParticles,EventHeader",
0070         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"
0071     input:
0072         data=SIMOUTDIR+"Low-Q2_Training_SimEvents_{CAMPAIGN}.edm4hep.root",
0073     output:
0074         eicreconfile=ANALYSISDIR+"Low-Q2_Training_Tensors_{CAMPAIGN}.eicrecon.edm4hep.root",
0075     shell:
0076         """
0077         eicrecon -Ppodio:output_file={output.eicreconfile} -PLOWQ2:TaggerTrackerTransportationPreML:beamE=18.0 -Pdd4hep:xml_files={params.xml} \
0078         -Pjana:nevents=500000 -Pjana:nskip=500000 \
0079         -Ppodio:output_collections={params.output_collections} -Pplugins_to_ignore={params.ignore_plugins}  {input.data} 
0080         """
0081 
0082 # Processes the simulation output data for training
0083 rule lowq2_steering_reconstruction_preparation:
0084     input:
0085         script=workflow.source_path("cleanData.C"),
0086         data=ANALYSISDIR+"Low-Q2_Training_Tensors_{CAMPAIGN}.eicrecon.edm4hep.root",
0087     output:
0088         rootfile=ANALYSISDIR+"Low-Q2_Steering_Reconstruction_Data{CAMPAIGN}.root",
0089     shell:
0090         """
0091         root -l -b -q '{input.script}("{input.data}", "{output.rootfile}",18.0)'
0092         """
0093 
0094 # Trains a regression model to predict the MCParticle momentum from the lowq2 tagger tracker hits.
0095 rule lowq2_steering_reconstruction_training:
0096     input:
0097         script=workflow.source_path("SteeringRegression.py"),
0098         scriptdata=workflow.source_path("LoadData.py"),
0099         scriptmodel=workflow.source_path("RegressionModel.py"),
0100         data=ANALYSISDIR+"Low-Q2_Steering_Reconstruction_Data{CAMPAIGN}.root",
0101     output:
0102         onnxfile=ANALYSISDIR+"Low-Q2_Steering_Reconstruction_Test_{CAMPAIGN}.onnx",
0103     shell:
0104         """
0105         python {input.script} --dataFiles {input.data} --outModelFile {output.onnxfile} --epochs 1000
0106         """
0107 
0108 # Run eicrecon with the newly trained neural network
0109 rule lowq2_steering_reconstruction_particles_trained_eicrecon:
0110     params:
0111         xml=os.getenv("DETECTOR_PATH")+"/epic_ip6_extended.xml",
0112         output_collections="TaggerTrackerReconstructedParticles,MCParticles,EventHeader",
0113         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"
0114     input:
0115         data=SIMOUTDIR+"Low-Q2_Training_SimEvents_{CAMPAIGN}.edm4hep.root",
0116         onnxfile=ANALYSISDIR+"Low-Q2_Steering_Reconstruction_Test_{CAMPAIGN}.onnx",
0117     output:
0118         eicreconfile=ANALYSISDIR+"Low-Q2_retrained_Particles_{CAMPAIGN}.eicrecon.edm4hep.root",
0119     shell:
0120         """
0121         eicrecon -Ppodio:output_file={output.eicreconfile}  -Pjana:nevents=500000 -PLOWQ2:TaggerTrackerTransportationPreML:beamE=18.0 -PLOWQ2:TaggerTrackerTransportationPostML:beamE=18.0 -Pdd4hep:xml_files={params.xml} \
0122         -PLOWQ2:TaggerTrackerTransportationInference:modelPath={input.onnxfile} -Ppodio:output_collections={params.output_collections} -Pplugins_to_ignore={params.ignore_plugins}  {input.data} 
0123         """
0124 
0125 ##########################################################################################
0126 # Test and check resolutions
0127 ##########################################################################################
0128 
0129 # Produce hitsograms of th resolution of TaggerTrackerReconstructedParticles compared to their MCParticles
0130 rule lowq2_reconstruction_particles_test:
0131     input:
0132         script=workflow.source_path("reconstructionAnalysis.C"),
0133         data=ANALYSISDIR+"Low-Q2_{STAGE}_Particles_{CAMPAIGN}.eicrecon.edm4hep.root",
0134     output:
0135         rootfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.root",
0136         momentumCanvas=ANALYSISDIR+"{STAGE}_momentum_resolution_{CAMPAIGN}.png",
0137         energyThetaPhiCanvas=ANALYSISDIR+"{STAGE}_energy_theta_phi_resolution_{CAMPAIGN}.png",
0138         relationCanvas=ANALYSISDIR+"{STAGE}_relation_resolution_{CAMPAIGN}.png",
0139         resolutionGraphsCanvas=ANALYSISDIR+"{STAGE}_resolution_graphs_{CAMPAIGN}.png",
0140     shell:
0141         """
0142         root -l -b -q '{input.script}("{input.data}", 18, "{output.rootfile}", "{output.momentumCanvas}", "{output.energyThetaPhiCanvas}", "{output.relationCanvas}", "{output.resolutionGraphsCanvas}")'
0143         """
0144 
0145 # Check the resloutions and offsets are within tollerance
0146 rule lowq2_reconstruction_particles_check:
0147     input:
0148         script=workflow.source_path("checkResolutions.C"),
0149         rootfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.root"
0150     output:
0151         jsonfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.json"
0152     shell:
0153         """
0154         root -l -b -q '{input.script}("{input.rootfile}", "{output.jsonfile}")'
0155         """
0156 
0157 
0158 ##########################################################################################
0159 # Combine results
0160 ##########################################################################################
0161 def get_onnx_input(wildcards):
0162     if wildcards.STAGE == "retrained":
0163         return ANALYSISDIR + f"Low-Q2_Steering_Reconstruction_Test_{wildcards.CAMPAIGN}.onnx"
0164     else:
0165         return []
0166 
0167 rule lowq2_reconstruction:
0168     input: 
0169         rootfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.root",
0170         momentumCanvas=ANALYSISDIR+"{STAGE}_momentum_resolution_{CAMPAIGN}.png",
0171         energyThetaPhiCanvas=ANALYSISDIR+"{STAGE}_energy_theta_phi_resolution_{CAMPAIGN}.png",
0172         relationCanvas=ANALYSISDIR+"{STAGE}_relation_resolution_{CAMPAIGN}.png",
0173         resolutionGraphsCanvas=ANALYSISDIR+"{STAGE}_resolution_graphs_{CAMPAIGN}.png",
0174         jsonfile=ANALYSISDIR+"Low-Q2_{STAGE}_Resolution_Results_{CAMPAIGN}.json",
0175         onnxfile=get_onnx_input,
0176     output:
0177         directory("results/lowq2_reconstruction/{STAGE}_{CAMPAIGN}/")
0178     shell:
0179         """
0180             mkdir {output}        
0181             cp -r {input} {output}
0182         """
0183 
0184 ##########################################################################################
0185 # Defualt running
0186 ##########################################################################################
0187 rule lowq2_reconstruction_local:
0188     input:
0189         "results/lowq2_reconstruction/test_local/"
0190 
0191 rule lowq2_reconstruction_retrained:
0192     input:
0193         "results/lowq2_reconstruction/retrained_local/"