# standard_reco_dune35tdata.fcl
#
# David Adams
# August 2016
#
# Modified to use DataPrep.

#include "services_dune.fcl"
#include "hitfindermodules_dune.fcl"
#include "clusterfinder_dune.fcl"
#include "trackfindermodules_dune.fcl"
#include "calorimetry_dune35t.fcl"
#include "t0reco.fcl"
#include "opticaldetectormodules_dune.fcl"
#include "photoncountert0matching.fcl"
#include "trackshowerhits.fcl"
#include "showerfindermodules_dune.fcl"
#include "emshower3d.fcl"
#include "tools_dune.fcl"

process_name: Reco

services:
{
  # Load the service that manages root files for histograms.
  TFileService: { fileName: "reco_hist.root" }
  TimeTracker:       {}
  MemoryTracker:         { } # default is one
  RandomNumberGenerator: {} #ART native random number generator
  message:      @local::dune_message_services_prod_debug
  FileCatalogMetadata:  @local::art_file_catalog_data
  @table::dune35tdata_reco_services
}
#source is now a root file
source:
{
  module_type: RootInput
  maxEvents:  10        # Number of events to create
}

# 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:
 {
# random number saver
  rns:                 { module_type: RandomNumberSaver }
# convert raw::RawDigit to recob::wire
  caldata:            @local::producer_adcprep
# actual hit finder
  gaushit:            @local::dune35t_gaushitfinder
  fasthit:            @local::dune35t_fasthitfinder
  cchit:              @local::dune35t_clustercrawlerhit

# actual disambiguation
  hit35t:             @local::dune35t_hitfinder35t
#  hit35tcc:           @local::dune35t_hitfinder35t
  handscan:           @local::dune35t_handscan
# disambiguation using the counters
  counterhit:         @local::dune35t_hitfindercounters
# reconstruction using disambiguated hits
#  fuzzy:              @local::dune35t_fuzzycluster
  dbcluster:          @local::dune35t_dbcluster
  linecluster:        @local::dune35tdata_linecluster
  lineclusterch:      @local::dune35tdata_linecluster
  costrk:             @local::dune35t_cosmictracker
#  stitch:             @local::dune35t_trackstitcher
  calo:               @local::dune35t_calomc
  pmtrack:             @local::dune35t_pmalgtrackmaker
  pmtrackcalo:         @local::dune35t_calomc
  pmtrackch:             @local::dune35t_pmalgtrackmaker
  
#  kalmanhit:         @local::dune35t_track3Dkalmanhit
# Photon counter T0
  photont0costrk:    @local::lbne35t_photoncountert0matching
  photont0costrkdc:  @local::lbne35t_photoncountert0matching
  photont0pmtrack:   @local::lbne35t_photoncountert0matching
  photont0pmtrackdc: @local::lbne35t_photoncountert0matching
# Muon Counter T0
  t0counter:          @local::dune35t_t0counter
# photon detector reconstruction
  ophit:              @local::dune35t_ophit_splitdata
  opflash:            @local::dune35t_opflash_splitdata
# track shower splitter
  trkshowersplit:     @local::standard_trackshowerhits
# shower reconstruction
  blurredcluster:        @local::dune35t_blurredcluster
  emshower:              @local::dune35tdata_emshower
  emshower3d:            @local::dune35t_emshower3d
  mergeemshower3d:       @local::dune35t_mergeemshower3d
 }

 #define the producer and filter modules for this path, order matters, 
 #filters reject all following items.  see lines starting physics.producers below
 reco: [ rns
         #optical hit reco, flash, counter, TPC wire signals
         #ophit, opflash
         , t0counter 
         , caldata
         #hit reco with cheated disambiguation
         ,gaushit #, fasthit
         #real disambiguation
         , hit35t
         #manual real-from-noise hit selection
         #, handscan
	 # disambiguation using the counters.
	 , counterhit
         #cluster reco
         #, dbcluster
	 , linecluster, lineclusterch
         #pmatrack
         , pmtrack, pmtrackch
         #, photont0pmtrack, pmtrackcalo
	 #shower reconstruction
	 #, blurredcluster, emshower, emshower3d, mergeemshower3d
]

 #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: [reco] 

 #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:     [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:    "%ifb_%tc_reco.root"
   dataTier:    "full-reconstructed"
   compressionLevel: 1
 }
}
### Here, we overwrite ALL module labels with the ones defined above.
physics.producers.caldata.DigitLabel:                  "SplitterInput:TPC"
physics.producers.t0counter.TriggerModuleLabel:        "SplitterInput:TRIGGER"

physics.producers.gaushit.CalDataModuleLabel:          "caldata"
#physics.producers.gaushit.MinSig:                      [100,100,100]
#physics.producers.gaushit.MinWidth:                    [5,5,5]
#physics.producers.hit35tcc.ChanHitLabel:              "gaushit"
physics.producers.lineclusterch.HitFinderModuleLabel:  "counterhit"
physics.producers.trkshowersplit.HitModuleLabel:       "linecluster"
physics.producers.pmtrack.HitModuleLabel:               "linecluster"
physics.producers.pmtrackcalo.TrackModuleLabel:       "pmtrack"
physics.producers.pmtrackcalo.SpacePointModuleLabel:  "pmtrack"
physics.producers.pmtrackcalo.T0ModuleLabel:          "photont0pmtrack"
physics.producers.photont0pmtrack.TrackModuleLabel:   "pmtrack"
physics.producers.photont0pmtrack.HitsModuleLabel:    "linecluster"
physics.producers.photont0pmtrack.ShowerModuleLabel:  ""
physics.producers.photont0pmtrack.TruthT0ModuleLabel: "mctrutht0pmtrack"

physics.producers.pmtrackch.HitModuleLabel:               "lineclusterch"
physics.producers.pmtrackch.ClusterModuleLabel:           "lineclusterch"
#physics.producers.fuzzy.HitsModuleLabel:            "hit35t"

physics.producers.costrk.ClusterModuleLabel:         "linecluster"
#physics.producers.stitch.TrackModuleLabel:          "costrk"
#physics.producers.stitch.SpptModuleLabel:           "costrk"
physics.producers.photont0costrk.TrackModuleLabel:   "costrk"
physics.producers.photont0costrk.HitsModuleLabel:    "linecluster"
physics.producers.photont0costrk.ShowerModuleLabel:  ""
physics.producers.photont0costrk.TruthT0ModuleLabel: "mctrutht0"
physics.producers.calo.TrackModuleLabel:             "costrk"
physics.producers.calo.SpacePointModuleLabel:        "costrk"
physics.producers.calo.T0ModuleLabel:                "photont0costrk"
#physics.producers.kalmanhit.HitModuleLabel:         "hit35t"
#physics.producers.kalmanhit.ClusterModuleLabel:     "fuzzy"

#Optical detector configuration
#defined in opticaldetectormodules_dune.fcl
#don't want to overwrite in case standard opdet data config changes

#physics.producers.linecluster.ClusterCrawlerAlg.TimeDelta:    [2,3,3]
#shower configuration
physics.producers.blurredcluster.HitsModuleLabel: "linecluster"
physics.producers.blurredcluster.TrackModuleLabel: "pmtrack"
physics.producers.blurredcluster.CreateDebugPDF:  false
physics.producers.blurredcluster.MergeClusters:   false
physics.producers.blurredcluster.GlobalTPCRecon:  true
physics.producers.blurredcluster.ShowerReconOnly: false
physics.producers.blurredcluster.VertexModuleLabel: "linecluster"

physics.producers.emshower.ClusterModuleLabel: "blurredcluster"
physics.producers.emshower.HitsModuleLabel: "linecluster"
physics.producers.emshower.TrackModuleLabel: "pmtrack"

physics.producers.emshower3d.HitsModuleLabel: "linecluster"
physics.producers.emshower3d.ClustersModuleLabel: "blurredcluster"
physics.producers.emshower3d.Trk3DModuleLabel: "pmtrack"

physics.producers.mergeemshower3d.HitsModuleLabel: "linecluster"
physics.producers.mergeemshower3d.ClustersModuleLabel: "blurredcluster"
physics.producers.mergeemshower3d.Trk3DModuleLabel: "emshower3d"
physics.producers.mergeemshower3d.VtxModuleLabel: "emshower3d"
physics.producers.mergeemshower3d.WideConeAngle: 20

services.DetectorPropertiesService.NumberTimeSamples: 15000
services.DetectorPropertiesService.ReadOutWindowSize: 15000
services.DetectorPropertiesService.Efield: [0.25, 0.782, 1.734]

#services.SignalShapingServiceDUNE.DebugFieldShape: true
services.SignalShapingServiceDUNE.ASICGainInMVPerFC: [14, 14, 14]
services.SignalShapingServiceDUNE.ShapeTimeConst: [3, 3, 3]

services.SignalShapingServiceDUNE.NoiseFactVec:  [[ 1.12, 0.86, 6.0, 0.55 ],
							  [ 1.12, 0.86, 6.0, 0.55 ],
							  [ 0.89, 0.66, 4.8, 0.43 ]]

##############   The standard parameters -----------------------
#services.SignalShapingServiceDUNE35t.ColFilter: "(x>0.0)*[0]*exp(-0.5*(((x-[1])/[2])^2)^[3])"
#services.SignalShapingServiceDUNE35t.IndUFilter: "(x>0.0)*gaus(0)*exp(-0.5*pow(x/[3],[4]))"
#services.SignalShapingServiceDUNE35t.IndVFilter: "(x>0.0)*gaus(0)*exp(-0.5*pow(x/[3],[4]))"

##############   My new  parameters -----------------------

services.SignalShapingServiceDUNE.ColFilter:       "(x>0.001)*[0]*(1-1/(1+exp(-(x-[1])/[2])))"
services.SignalShapingServiceDUNE.ColFilterParams: [ 1, 0.150, 0.025 ]

services.SignalShapingServiceDUNE.IndUFilter:       "(x>0.03)*[0]*(1-1/(1+exp(-(x-[1])/[2])))*(1/(1+exp(-(x-[3])/[4])))"
services.SignalShapingServiceDUNE.IndUFilterParams: [ 1.0, 0.105, 0.019, 0.018, 0.010 ]
services.SignalShapingServiceDUNE.IndVFilter:       "(x>0.03)*[0]*(1-1/(1+exp(-(x-[1])/[2])))*(1/(1+exp(-(x-[3])/[4])))"
services.SignalShapingServiceDUNE.IndVFilterParams: [ 0.95, 0.125, 0.019, 0.010, 0.0109 ]

#physics.producers.gaushit.MinSig:   [ 5, 5, 10 ]
physics.producers.gaushit.HitFinderToolVec.CandidateHitsPlane0.RoiThreshold: 5.0
physics.producers.gaushit.HitFinderToolVec.CandidateHitsPlane1.RoiThreshold: 5.0
physics.producers.gaushit.HitFinderToolVec.CandidateHitsPlane2.RoiThreshold: 10.0
#physics.producers.gaushit.MinWidth: [ 1, 1, 1 ]

physics.producers.fasthit.MinSigCol: 80
physics.producers.fasthit.MinSigInd: 80
