void loon_reco_job() {

//Based on macro for R1.10 production far_det data reconstruction.

// Should be used as:
// loon -bq loon_reco_job.C <data_file>

  int lastPlane=485;
  int runNumber=18143;

  //Link dynamic libraries
  gSystem->Load("libDataUtil");
  gSystem->Load("libRecoBase");
  gSystem->Load("libNoiseFilter");
  gSystem->Load("libFilterDigitSR");
  gSystem->Load("libBField");
  gSystem->Load("libNumericalMethods");
  gSystem->Load("libSwimmer");
  gSystem->Load("libDeMux");
  gSystem->Load("libCandStripSR");
  gSystem->Load("libCandSliceSR");
  gSystem->Load("libCandTrackSR");
  gSystem->Load("libCandClusterSR");
  gSystem->Load("libMCNtuple");
  gSystem->Load("libCandNtupleSR");
  gSystem->Load("libTruthHelperNtuple");
  gSystem->Load("libStandardNtuple");
  gSystem->Load("libCandSubShowerSR");
  gSystem->Load("libCandShowerSR");
  gSystem->Load("libCandFitTrackSR");
  gSystem->Load("libCandEventSR");
  gSystem->Load("libVertexFinder");
  gSystem->Load("libTimeCalibratorSR");
  gSystem->Load("libAstroUtil");
  gSystem->Load("libCandShield");
  gSystem->Load("libCandMorgue");
  gSystem->Load("libCandNtupleSRModule");

  JobC jc;

  //Create path
  jc.Path.Create("Reco",
		 "NoiseFilterModule::Ana "		 
		 "RecordSetupModule::Get "
		 "DigitListModule::Get "
		 "DigitListModule::Reco "
		 "FilterDigitListModule::Reco "
		 "FilterLIModule::Ana "
		 "DeMuxDigitListModule::Reco "
		 "DeMuxModule::Ana "
		 "DeMuxCosmicsModule::Ana "
		 "StripSRListModule::Reco "
		 "SliceSRListModule::Reco "
		 "ClusterSRListModule::Reco "
		 "ShowerSRListModule::Reco "
		 "TrackSRListModule::Reco "
		 "FitTrackSRListModule::Reco "
		 "EventSRListModule::Reco "
		 "RecordSetupModule::Reco "
		 "Output::Put");
  

  //Input Parameters
  jc.Input.Set("Format=input");

  jc.Path("Reco").SetAllFilters(1);

  //Set the output mode
  jc.Path("Reco").Mod("Output").Cmd("DefineStream Config ConfigRecord");
  jc.Path("Reco").Mod("Output").Set("Streams=Cand,Config,DaqSnarl");

  //Set B=0 for SM2 if runNumber < 17566
  if (runNumber < 17566) {
    BfldLoanPool* bfldpool = BfldLoanPool::Instance();
    bfldpool->Set("NoFieldBeyondZ=15.3797");
    bfldpool->Update();
  }

  //Configure LIFilter
  //jc.Path("Reco").Mod("FilterLIModule").Set("LIFinderName=FancyPatternFinder");
  //jc.Path("Reco").Mod("FilterLIModule").Set("FractionalChargeThreshold=0.8");
  jc.Path("Reco").Mod("FilterLIModule").Set("LIFinderName=SimplePatternFinder");
  
  //////////////////////////////////////
  //Configure Reconstruction Software for Far Det Cosmics data .
  jc.Path("Reco").Mod("SliceSRListModule").Set("SliceListAlgConfig=FarCosmic");
  jc.Path("Reco").Mod("ClusterSRListModule").Set("ClusterListAlgConfig=FarCosmic");  
  jc.Path("Reco").Mod("ShowerSRListModule").Set("ShowerListAlgConfig=FarCosmic");
  jc.Path("Reco").Mod("TrackSRListModule").Set("TrackListAlgConfig=FarCosmic");
  jc.Path("Reco").Mod("FitTrackSRListModule").Set("FitTrackListAlgConfig=FarCosmic");
  jc.Path("Reco").Mod("EventSRListModule").Set("EventListAlgConfig=FarCosmic");  
  //////////////////////////////////////


  // Get the AlgFactory
  AlgFactory &af = AlgFactory::GetInstance();

  
  // AlgDeMuxDigitList AlgConfig parameters
  AlgHandle ah = af.GetAlgHandle("AlgDeMuxDigitList", "default");
  AlgConfig &acd = ah.GetAlgConfig();
  acd.UnLockValues();
  acd.Set("DeMuxAlgConfig", "default");
  acd.Set("NormalizeWeights", 1); // Normalize weights to 1 if non-zero
  acd.Set("TrimHyps", 1);    // Drop "0" weights if neg., or keep top N
  acd.LockValues();
  
  //DigitListModule parameters
  jc.Path("Reco").Mod("DigitListModule").Set("ListsToMake=1"); 
  jc.Path("Reco").Mod("StripSRListModule").Set("ListIn=canddigitlist");

  //Reco's filter parameters
  jc.Path("Reco").Mod("FilterDigitListModule").Set("FilterDigitListAlgorithm=AlgFilterDigitListSR");
  jc.Path("Reco").Mod("FilterDigitListModule").Set("SwitchPersToTemp=1"); //Don't write out original CandDigitList.
  
  //BegPlane and EndPlane are now Registry keys.
  AlgHandle alh = af.GetAlgHandle("AlgStripSRList","default");
  AlgConfig &alg = alh.GetAlgConfig();
  
  alg.UnLockValues();
  alg.Set("BegPlane",1);  
  alg.Set("EndPlane",lastPlane); //Set the last plane to the script argument
  alg.LockValues();
  
  //Pass lastPlane argument to Track Fitter.
  AlgHandle alf = af.GetAlgHandle("AlgFitTrackSR","default");
  AlgConfig &algf = alf.GetAlgConfig();
  
  algf.UnLockValues();
  algf.Set("LastPlane",lastPlane); //Set the last plane to the script argument
  algf.LockValues();
  
  //Ntuple record has its own output file so needs its own output module
  jc.Path.Create("NtpSR",
                 "NtpSRModule::Reco "
		 "Output::Put ");
  jc.Path("NtpSR").Mod("Output").Set("Streams=NtpSR");
  jc.Path("NtpSR").Mod("Output").Set("FileName=ntupleSR.root");
  jc.Path.Attach("Reco","NtpSR");
  
  // Ntuple abridged record
  jc.Path.Create("NtpSRFilter",
		 "NtpSRFilterModule::Reco "
		 "Output::Put ");
  jc.Path("NtpSRFilter").Mod("Output").Set("Streams=NtpSR");
  jc.Path("NtpSRFilter").Mod("Output").Set("FileName=ntupleSR.sub.root");
  jc.Path.Attach("Reco","NtpSRFilter");
  
  //Configuring Calibrator to use the new Muon Calibration tables (d'apr`es Nathaniel)
  Calibrator::Instance().Set("StripCalibrator=StripToStripCalScheme ");
  Calibrator::Instance().Set("AttenCalibrator=StripAttenCalScheme ");
  
  //Configuration of modules
  jc.Path("Reco").Mod("FilterDigitListModule").Report(); 
  jc.Path("Reco").Mod("DeMuxDigitListModule").Report();
  
  //Configure the message service
  jc.Msg.SetLevel("Cand","Error");
  jc.Msg.SetLevel("Calibrator","Fatal");
  jc.Msg.SetLevel("Dbi","Fatal");
  jc.Msg.SetLevel("SigCor Calibrator","Fatal");
  jc.Msg.SetLevel("Time Calibrator","Fatal");
  jc.Msg.SetLevel("MuonCalibrator","Fatal");
  jc.Msg.SetLevel("PE Calibrator","Fatal");
  jc.Msg.SetLevel("MapperCalibrator","Fatal");
  jc.Msg.SetLevel("Per","Fatal");
  jc.Msg.SetLevel("Io", "Fatal");
  jc.Msg.SetLevel("DeMuxDigitListModule","Error");
  jc.Msg.SetLevel("FilterLI", "Fatal");
  jc.Msg.SetLevel("LIPatternFinder","Fatal");
  jc.Msg.SetLevel("Plex","Error");
  
	
  jc.Path("Reco").Run(200);

  //Job Report
  jc.Path("Reco").Report();
  
  //Get Message Statistics
  jc.Msg.Stats();


}
