#include "services_dune.fcl"
#include "singles_dune.fcl"
#include "largeantmodules_dune.fcl"
#include "detsimmodules_dune.fcl"
#include "mccheatermodules.fcl"
#include "photpropservices_dune.fcl"
#include "opticaldetectormodules_dune.fcl"



process_name: SinglesGen

services:
{
  # Load the service that manages root files for histograms.
  TFileService: { fileName: "protodune_optical_tutorial_sim_hist.root" }
  TimeTracker:       {}
  RandomNumberGenerator: {} #ART native random number generator
  message:      @local::standard_info
  @table::protodune_simulation_services
}



#Start each new event with an empty event.
source:
{
  module_type: EmptyEvent
  timestampPlugin: { plugin_type: "GeneratedEventTimestamp" }
  maxEvents:   1           # Number of events to create
  firstRun:    1           # Run number to use for this file
  firstEvent:  1           # number of first event in the file
}

# Define and configure some modules to do work on each event.
# First modules are defined; they are scheduled later.
# Modules are grouped by type.
physics:
{

 producers:
 {
   generator: @local::dunefd_singlep
   largeant:  @local::dunefd_largeant	  
   rns:       { module_type: "RandomNumberSaver" }
 }

 analyzers:
 {
   pmtresponse: @local::dunefd_simphotoncounter

      
   # This name defines a job step below, and will appear as a directory 
   # in the output histogram file. 
   AnalysisExample: 
   {
      # The "module_type" tells us which module to run. The name here
      # matches the name supplied to DEFINE_ART_MODULE near the end of
      # AnalysisExample_module.cc.

      module_type:     "AnalysisExample"

      # The input parameters for our AnalysisExample module. Compare
      # the names you see here with the reconfigure method in
      # AnalysisExample.cxx. You will want to add/remove/rename the
      # example parameters below to suit your task.

      # If you are reading any objects created by the simulation, then
      # don't change the value of this parameter. This is the name of
      # the 'producer' that ran the simulation module in a previous
      # job. An example of a job file that runs the simulation is
      # ${LARSIM_DIR}/job/prodsingle.fcl; look for "largeant:". It's
      # unlikely that anyone would change the name of this producer.

      SimulationLabel: "largeant"

      # Hits can be created by more than one module in
      # ${LARRECO_DIR}/source/HitFinder. For this example, I picked
      # the one that's usually run first.

      HitLabel:        "gaushit"

      # The same for clusters:

      ClusterLabel:    "fuzzycluster"

      # In this example, which primary particle(s) we'll focus on in an event.
      # PDG code 13 = mu-.
      PDGcode:          13

      # dx used for the dE/dx calculation; units are cm. 
      BinSize:          0.3
   }
 }


 #define the producer and filter modules for this path, order matters, 
 #filters reject all following items.  see lines starting physics.producers below
 # simulate: [ generator, largeant, daq, rns ] 
 simulate: [ generator, largeant, rns ] 
 analyzeIt:  [ AnalysisExample, pmtresponse]
 
 #define the output stream, there could be more than one if using filters 
 stream1:  [ out1 ]

 #trigger_paths is a keyword and contains the paths that modify the art::event, 
 #ie filters and producers
 trigger_paths: [simulate] 

 #end_paths is a keyword and contains the paths that do not modify the art::Event, 
 #ie analyzers and output streams.  these all run simultaneously
 end_paths:     [analyzeIt, stream1]  
}

#block to define where the output goes.  if you defined a filter in the physics
#block and put it in the trigger_paths then you need to put a SelectEvents: {SelectEvents: [XXX]}
#entry in the output stream you want those to go to, where XXX is the label of the filter module(s)
outputs:
{
 out1:
 {
   module_type: RootOutput
   fileName:    "protodune_optical_tutorial_sim_gen.root" #default file name, can override from command line with -o or --output
 }
}


#
# Change the properties of the generated singles
#

physics.producers.generator.Theta0XZ: [ 0 ]
physics.producers.generator.Theta0YZ: [ 0 ]
#physics.producers.generator.SigmaThetaXZ: [ 0 ]
#physics.producers.generator.SigmaThetaYZ: [ 0 ]

physics.producers.generator.X0:     [ 120.0 ] # 120 cm from wire plan
#physics.producers.generator.SigmaX: [  1.0 ] # fraction with uniform
physics.producers.generator.Y0:     [  50.0 ] # slightly above center in y
#physics.producers.generator.SigmaY: [ 50.0 ] # fraction with uniform
physics.producers.generator.Z0:     [   0.0 ] # 1 m into the cryostat
#physics.producers.generator.SigmaZ: [  0.0 ]
#physics.producers.generator.PDist:     0 # uniform
#physics.producers.generator.PosDist:   0 # uniform
#physics.producers.generator.ThetaDist: 0 # uniform
