// FileName: reco_near_spill_daikon04_base_dogwood0.C
// Created 12 Feb 2008

// Usage
// loon -bq add_to_path(<path>) reco_near_spill_daikon04_base_dogwood0.C <data_file>

/////////////////////////////////////////////////////////
// Output:                                             //
// Output Files:                                       //
//  CandS.root - candidate output file                 //
//  ntupleStS.root - NtpSt ntuple output               //
//  ntupleMRNT.root - MRCC removed ntuple              //
/////////////////////////////////////////////////////////

#include "headers/aclic.h"
#include "headers/test_filename.h"

class JobC;

#include "headers/io/set_input_mc.h"
#include "headers/io/attach_output_mc_srsafitter.h"

#include "headers/reroot/reroot_create_path.h"
#include "headers/reroot/reroot_configure.h"
#include "headers/reroot/reroot_do_report.h"

#include "headers/near_mc/near_mc_create_path.h"
#include "headers/near_mc/near_mc_configure.h"
#include "headers/near_mc/near_mc_do_report.h"
#include "headers/near_mc/near_mc_set_msg_levels.h"

#include "headers/near/near_configure_shower.h"

#include "headers/util/run.h"

#include "headers/configure_ugli.h"
#include "headers/near_mc/near_mc_set_calibrator.h"
#include "headers/apply_spectrometer_fudge.h"
#include "headers/attach_mrcc_path_near.h"

void reco_near_spill_daikon04_base_dogwood0(int nSkip = 0, int nRun = 100000)
{
  test_filename('n');

  gROOT->Macro("macros/load_libs.C");

  RecJobRecord::SetGlobalProdName("Dogwood");

  JobC jc;

  JobCPath& reroot = reroot_create_path(jc, "Reco");

  JobCPath& near_mc = near_mc_create_path(jc, "Reco1");

  reroot.Attach(&near_mc);

  set_input_mc(jc);

  reroot_configure(reroot, Detector::kNear);

  near_mc_configure(near_mc);

  near_configure_shower(near_mc, false);

  configure_ugli();

  near_mc_set_calibrator(0);

  //SpectrometerFudge added April 23,2007
  //this should be removed after database entry is updated
  apply_spectrometer_fudge();

  reroot_do_report(reroot);
  near_mc_do_report(near_mc);

  attach_output_mc_srsafitter(jc, near_mc, "CandS.root", true);

  attach_mrcc_path_near(jc, near_mc, 1, "NearBeam", false, SimFlag::kMC);

  near_mc_set_msg_levels(jc);

  // Attempt to debug database problem. If this turns out to be
  // the solution it should be moved elsewhere and used in all scripts.
  DbiTableProxyRegistry& dbiCfg = DbiTableProxyRegistry::Instance();
  dbiCfg.Set("MakeConnectionsPermanent = -1");
  dbiCfg.Update();

  run(jc, reroot, nSkip, nRun);
}
