#include "opticaldetectormodules.fcl"
#include "sspmodules.fcl"

BEGIN_PROLOG

dunefd_opdigi_unganged:
{
   module_type:          "OpDetDigitizerDUNE"
   InputModules:         ["largeant"] # Module that created simphotons

   # Assume 25 V bias with Sensl C-series SiPMs
   # Gain at this voltage is 4e6 -- that this corresponds to
   # the MaxAmplitude and VoltageToADC below has not been confirmed.
   
   VoltageToADC:         151.5      # Converting mV to ADC counts (counts in 1 mV)
   LineNoiseRMS:           2.6      # Pedestal RMS in ADC counts, likely an underestimate
   DarkNoiseRate:         10.0      # In Hz, Ranges 2-50 depending on Vbias
   CrossTalk:              0.20     # Probability of producing 2 PE for 1 incident photon
   # Afterpulsing:         0.006    # Afterpulsing is not yet simulated
   Pedestal:            1500        # in ADC counts
   DefaultSimWindow:    true        # Use -1*drift window as the start time and
                                    # the TPC readout window end time as the end time
   FullWaveformOutput: false        # Output full waveform. Be careful with this option:
                                    # setting it to "true" can result in large output files
   TimeBegin:              0        # In us (not used if DefaultSimWindow is set to true)
   TimeEnd:             1600        # In us (not used if DefaultSimWindow is set to true)
   PreTrigger:           100        # In ticks
   ReadoutWindow:       1000        # In ticks
   algo_threshold: @local::standard_algo_sspleadingedge

   Padding:              100        # In ticks

   PulseLength:		         5.2
   PeakTime:		           0.260
   MaxAmplitude:	         0.12
   FrontTime:		           0.009
   BackTime:		           0.476
   SSP_LED_DigiTree:    false	    #To create a SSP LED trigger Ttree
   
   # readout window in optical ticks
   # buffer before waveform
   # see SSP manual, dune-doc-9928, p. 58
   #
   # IU waveform window
   # ReadoutWindow:       700
   # ReadoutPretrigger:   100
   #
   # SSP Maximum window
   # ReadoutWindow:      2046
   # ReadoutPretrigger:   100
   
   # SaturationScale:         16383 # 2^14 - 1, based on SSP Data
}

dunefd_opdigi_threegang:	                            @local::dunefd_opdigi_unganged
dunefd_opdigi_threegang.PulseLength:	                5.2
dunefd_opdigi_threegang.PeakTime:	                    0.028
dunefd_opdigi_threegang.MaxAmplitude:	                0.0594 # * VoltageToADC = 9 ADC/PE
dunefd_opdigi_threegang.FrontTime:	                  0.013
dunefd_opdigi_threegang.BackTime:	                    0.386
dunefd_opdigi_threegang.algo_threshold.ADCThreshold: 15.000 # "2 PE" threshold = 1.7 PE

dunefd_opdigi_threegang_refactor: @local::dunefd_opdigi_threegang
dunefd_opdigi_threegang_refactor.InputModules: ["PDFastSim"]

dunefd_opdigi: @local::dunefd_opdigi_threegang



protodune_opdigi: @local::dunefd_opdigi_threegang
protodune_opdigi.algo_threshold: @local::standard_algo_sspleadingedge

protodune_opdigi_refactor: @local::protodune_opdigi
protodune_opdigi_refactor.InputModules: ["PDFastSim"]

#New protodune-sp digitizer
protodune_opdigitizer:
{
   module_type:          "OpDetDigitizerProtoDUNE"
   InputModules:         ["largeant"] # Module that created simphotons

   # Assume 25 V bias with Sensl C-series SiPMs
   # Gain at this voltage is 4e6 -- that this corresponds to
   # the MaxAmplitude and VoltageToADC below has not been confirmed.
  
   VoltageToADC:         151.5    # Converting mV to ADC counts (counts in 1 mV)
   LineNoiseRMS:         2.6      # Pedestal RMS in ADC counts, likely an underestimate
   DarkNoiseRate:        10.0     # In Hz, Ranges 2-50 depending on Vbias
   CrossTalk:            0.20     # Probability of producing 2 PE for 1 incident photon
   # Afterpulsing:       0.006    # Afterpulsing is not yet simulated
   Pedestal:             1500     # in ADC counts
   DefaultSimWindow:     true     # Use -1*drift window as the start time and
                                  # the TPC readout window end time as the end time
   FullWaveformOutput: false      # Output full waveform. Be careful with this option:
                                  # setting it to "true" can result in large output files
   TimeBegin:            0        # In us (not used if DefaultSimWindow is set to true)
   TimeEnd:              1600     # In us (not used if DefaultSimWindow is set to true)
   PreTrigger:           100      # In ticks
   ReadoutWindow:        1000     # In ticks
   algo_threshold: @local::standard_algo_sspleadingedge
   Padding:              100      # In ticks
   PulseLength:          5.2
   PeakTime:             0.028
   MaxAmplitude:         0.0594   # * VoltageToADC = 9 ADC/PE
   FrontTime:            0.013
   BackTime:             0.386
   SSP_LED_DigiTree:     false    # To create a SSP LED trigger Ttree
}

protodune_opdigitizer.algo_threshold.ADCThreshold: 15.000 # "2 PE" threshold = 1.7 PE
protodune_opdigitizer_refactor: @local::protodune_opdigitizer
protodune_opdigitizer_refactor.InputModules: ["PDFastSim"]


dunefd_simphotoncounter:
{
  module_type:            "SimPhotonCounter"
  Verbosity:               0
  InputModule:            "largeant"
  MakeAllPhotonsTree:      true
  MakeDetectedPhotonsTree: true
  MakeOpDetsTree:          true
  MakeOpDetEventsTree:     true
}

dunefd_tracktimeassoc:           @local::standard_tracktimeassoc
dunefd_ophit_single:             @local::standard_ophit
dunefd_ophit_single.InputModule: "opdigi"
dunefd_ophit_single.HitAlgoPset: @local::standard_algo_sipm
dunefd_ophit_single.AreaToPE:    true
dunefd_ophit_single.SPEArea:     1106
dunefd_ophit_single.SPEShift:    0.304

dunefd_ophit_threegang:          @local::dunefd_ophit_single
dunefd_ophit_threegang.SPEArea:  264
dunefd_ophit_threegang.SPEShift: 0.430
dunefd_ophit_threegang.HitAlgoPset.ADCThreshold: 6

dunefd_ophit: @local::dunefd_ophit_threegang

dunefd_opflash:                 @local::standard_opflash
dunefd_opflash.FlashThreshold:  3.5


# These calib values would be for MC only
protodune_ophit: @local::dunefd_ophit
protodune_ophit.SPEArea: 410
protodune_ophit.SPESize: 0.451
protodune_opflash: @local::dunefd_opflash

# For real data set the input module and label
# Use the PD Calibrator service for calibration 
# instead of above values.
protodune_ophit_data_unsplit: @local::protodune_ophit
protodune_ophit_data_unsplit.InputModule:  ssprawdecoder
protodune_ophit_data_unsplit.InputLabels: [ "daq" ]
protodune_ophit_data_unsplit.UseCalibrator: true
protodune_ophit_data_unsplit.HitAlgoPset.ADCThreshold: 10

# Make variants for internal/external split waveforms
protodune_ophit_data_internal: @local::protodune_ophit_data_unsplit
protodune_ophit_data_external: @local::protodune_ophit_data_unsplit
protodune_ophit_data_both:     @local::protodune_ophit_data_unsplit
protodune_ophit_data_internal.InputLabels: [ "internal" ]
protodune_ophit_data_external.InputLabels: [ "external" ]
protodune_ophit_data_both.InputLabels:     [ "internal", "external" ]

protodune_opflash_data_internal: @local::protodune_opflash
protodune_opflash_data_internal.InputModule: "ophitInternal"
protodune_opflash_data_external: @local::protodune_opflash
protodune_opflash_data_external.InputModule: "ophitExternal"


dunefd_opdigiana:
{
   module_type:      "OpDetDigiAnaDUNE"
   InputModule:      "opdigi"  # Module that created raw::OpDetWaveforms
   InstanceName:     ""    
   SSP_LED_AnaTree:  false 
}
dunefd_opflashana:       @local::standard_opflashana
dunefd_opflashana.MakePerEventFlashTree: true


dunefd_averagewaveform:
{
   module_type:  "AverageWaveform"
   InputModule:  "opdigi"  # Module that created raw::OpDetWaveforms
   InstanceName: ""     
}

dunefd_calibrationanalysis:
{
   module_type:  "CalibrationAnalysis"
   InputModule:  "opdigi"  # Module that created raw::OpDetWaveforms
   OpHitModule:  "ophit"   # Module that created recob::OpHits
   InstanceName: ""     
}

dune35t_simphotoncounter: @local::standard_simphotoncounter

dune35t_opdigi:         @local::dunefd_opdigi
dune35t_tracktimeassoc: @local::standard_tracktimeassoc

dune35t_ophit:   @local::dunefd_ophit
dune35t_opflash: @local::dunefd_opflash

dune35t_ophit_data:             @local::dune35t_ophit
dune35t_ophit_data.InputModule:  ssptooffline
dune35t_ophit_data.InputLabels: [ "offlinePhoton" ]
dune35t_opflash_data:           @local::dune35t_opflash

dune35t_ophit_splitdata:             @local::dune35t_ophit
dune35t_ophit_splitdata.InputModule:  SplitterInput
dune35t_ophit_splitdata.InputLabels: [ "PHOTON" ]
dune35t_opflash_splitdata:           @local::dune35t_opflash

dune35t_opdigiana:        @local::dunefd_opdigiana
dune35t_opflashana:       @local::standard_opflashana
dune35t_opdigiana.MakeUnipolarHist: false

dune35t_opdigiana_data:   @local::dune35t_opdigiana
dune35t_opdigiana_data.InputModule: ssptooffline
dune35t_opdigiana_data.InstanceName: offlinePhoton

dune35t_opdigiana_splitdata:   @local::dune35t_opdigiana
dune35t_opdigiana_splitdata.InputModule: SplitterInput
dune35t_opdigiana_splitdata.InstanceName: PHOTON


dune35t_averagewaveform: @local::dunefd_averagewaveform
dune35t_averagewaveform_data: @local::dune35t_averagewaveform
dune35t_averagewaveform_data.InputModule: ssptooffline
dune35t_averagewaveform_data.InstanceName: offlinePhoton

dune35t_averagewaveform_splitdata: @local::dune35t_averagewaveform
dune35t_averagewaveform_splitdata.InputModule: SplitterInput
dune35t_averagewaveform_splitdata.InstanceName: Photon

dune35t_calibrationanalysis: @local::dunefd_calibrationanalysis
dune35t_calibrationanalysis_data: @local::dune35t_calibrationanalysis
dune35t_calibrationanalysis_data.InputModule: ssptooffline
dune35t_calibrationanalysis_data.OpHitModule: ophit
dune35t_calibrationanalysis_data.InstanceName: offlinePhoton



dunedphase3x1x1_opdigi:
{
   module_type:          "OpDetDigitizerDUNEDP"
#  InputModule:          ["largeant","photPropS2"] # Module that created simphotons - Use this when simulating S2 light
   InputModule:          ["largeant"] # Module that created simphotons
   VoltageToADC:         2.048      # Converting mV to ADC counts (counts in 1 mV)
   LineNoiseRMS:         0.8      # Pedestal RMS in ADC counts, likely an underestimate
   CrossTalk:            0#0.20     # Probability of producing 2 PE for 1 incident photon
   Pedestal:             100        # in ADC counts
   Gain:                 4.1        # in ADC counts
   DefaultSimWindow:     false        # Use -1*drift window as the start time and
                                     # the TPC readout window end time as the end time
   FullWaveformOutput:   true        # Output full waveform. Be careful with this option:
                                    # setting it to "true" can result in large output files
   NegativeSignal:       false
   PreTrigger:           0        # In ticks This must be zero, otherwise we won't find hits in the pretrigger.
   ReadoutWindow:        25e4        # In ticks
   algo_threshold: @local::standard_algo_sspleadingedge

   Padding:              4000        # In ticks
   SSP_LED_DigiTree:     false	    #To create a SSP LED trigger Ttree
}

dunedphase3x1x1_opdigiana: @local::dunefd_opdigiana

protodunedphase_opdigi: @local::dunedphase3x1x1_opdigi
protodunedphase_opdigi.FullWaveformOutput: false
protodunedphase_opdigi.Gain:            10.25        # in ADC counts x ticks
protodunedphase_opdigi.DefaultSimWindow: false
protodunedphase_opdigi.PreTrigger: 0
protodunedphase_opdigi.ReadoutWindow: 5e5
protodunedphase_opdigi.Padding: 4000
protodunedphase_opdigi.CustomQEperOpDet: true
protodunedphase_opdigi.QEVector:
[0.036,0.036,0.120,0.036,0.036,0.036,0.036,0.036,0.036,0.036,
 0.120,0.036,0.036,0.036,0.036,0.120,0.036,0.036,0.036,0.036,
 0.036,0.120,0.036,0.036,0.036,0.036,0.120,0.036,0.036,0.036,
 0.036,0.036,0.036,0.036,0.120,0.036]
protodunedphase_opdigi.algo_threshold: #algorith used to split the waveforms when FullWaveformOutput: false
{
    Name:            "SSP_LED"
    ADCThreshold:    4
    Pedestal:        100
    DWindow:         10
    ReadoutWd:       4000
    PreTrg:          300
}

protodunedphase_opdigiana: @local::dunefd_opdigiana

dunefddphase_opdigi: @local::dunedphase3x1x1_opdigi
dunefddphase_opdigi.FullWaveformOutput: false
dunefddphase_opdigi.Gain:            41        # in ADC counts x ticks
dunefddphase_opdigi.DefaultSimWindow: true
dunefddphase_opdigi.PreTrigger: 0
dunefddphase_opdigi.Padding: 4000
dunefddphase_opdigi.algo_threshold: #algorith used to split the waveforms when FullWaveformOutput: false
{
    Name:            "SSP_LED"
    ADCThreshold:    10
    Pedestal:        100
    DWindow:         10
    ReadoutWd:       4000
    PreTrg:          300
}

dunefddphase_opdigiana: @local::dunefd_opdigiana


END_PROLOG
