From 577007fcfff7deaa9f5f850e8ccd95a1130539b2 Mon Sep 17 00:00:00 2001
From: Yero1990 <cyero002@fiu.edu>
Date: Sun, 11 Mar 2018 10:00:28 -0400
Subject: [PATCH] SHMS/HMS DC Calibrations Fixes and Clean-up Commits (#422)

* added optional flag to require single hit per event per plane for calibration :: re-define cuts for pid_hadron/pid_elec flags

* changed calorimeter leaf from X.cal.etotnorm to X.cal.etot

* added capability to created HMS/SHMS DC Calib Log directories to store the calibration information produced by the calibration script

* clean-up of SHMS DC Calibration Dir
---
 CALIBRATION/shms_dc_calib/scripts/DC_calib.C  | 188 ++++++++++++------
 CALIBRATION/shms_dc_calib/scripts/DC_calib.h  |  19 +-
 .../shms_dc_calib/scripts/input_RUN.txt       |   1 -
 .../shms_dc_calib/scripts/main_calib.C        |  11 +-
 .../{ => old_scripts}/get_LookUp_Values.C     |   0
 .../{ => old_scripts}/get_pdc_time_histo.C    |   0
 .../get_pdc_time_histo_tzero_corrected.C      |   0
 .../{ => old_scripts}/get_tzero_param.C       |   0
 .../get_tzero_per_wire_param.C                |   0
 .../{ => old_scripts}/get_wire_tzero.C        |   0
 .../{ => old_scripts}/update_pdcparam.C       |   0
 .../{ => old_scripts}/wire_drift_times.C      |   0
 .../{ => old_scripts}/wire_drift_times.h      |   0
 13 files changed, 146 insertions(+), 73 deletions(-)
 delete mode 100644 CALIBRATION/shms_dc_calib/scripts/input_RUN.txt
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/get_LookUp_Values.C (100%)
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/get_pdc_time_histo.C (100%)
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/get_pdc_time_histo_tzero_corrected.C (100%)
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/get_tzero_param.C (100%)
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/get_tzero_per_wire_param.C (100%)
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/get_wire_tzero.C (100%)
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/update_pdcparam.C (100%)
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/wire_drift_times.C (100%)
 rename CALIBRATION/shms_dc_calib/scripts/{ => old_scripts}/wire_drift_times.h (100%)

diff --git a/CALIBRATION/shms_dc_calib/scripts/DC_calib.C b/CALIBRATION/shms_dc_calib/scripts/DC_calib.C
index 33de7e77..83da094c 100644
--- a/CALIBRATION/shms_dc_calib/scripts/DC_calib.C
+++ b/CALIBRATION/shms_dc_calib/scripts/DC_calib.C
@@ -5,7 +5,7 @@
 using namespace std;
 
 //_____________________________________________________________
-DC_calib::DC_calib(TString a, TString b, const int c, Long64_t d, TString e)
+DC_calib::DC_calib(string a, TString b, const int c, Long64_t d, TString e)
 
   :spec(a),          //set spectrometer to 'HMS', or 'SHMS'  ex. DC_Calib(HMS, pdc_replay.C, 488, 50000)
    ifile_name(b),    //initialization list
@@ -14,6 +14,8 @@ DC_calib::DC_calib(TString a, TString b, const int c, Long64_t d, TString e)
    pid(e)
 {
   //Initialize pointers
+  dir_log    = NULL;
+  dir_log_name = NULL;
   tree       = NULL;
   in_file    = NULL;
   out_file   = NULL;
@@ -50,7 +52,8 @@ DC_calib::DC_calib(TString a, TString b, const int c, Long64_t d, TString e)
 DC_calib::~DC_calib()
 {
   cout << "calling the destructor " << endl;  
-  
+  delete dir_log;  dir_log = NULL;
+  delete dir_log_name;  dir_log_name = NULL;
   delete in_file;  in_file  = NULL;
   delete out_file; out_file = NULL;             
   delete graph;    graph    = NULL;
@@ -94,6 +97,44 @@ DC_calib::~DC_calib()
   
 }
 
+//____________________________________________________________
+void DC_calib::setup_Directory()
+{
+
+  
+  if (spec == "HMS")
+    {
+     
+      dir_log = Form("mkdir -p ./%s_DC_Log_%d/", spec.c_str(), run_NUM);
+
+      //Check if directory exists
+      if (system(dir_log) != 0) 
+	{
+	  cout << "Creating Directory to store HMS Calibration Results . . ." << endl; 
+	  system(dir_log);  //create directory to log calibration results
+	}
+
+
+    }
+
+  else if (spec == "SHMS")
+    {
+      
+      dir_log = Form("mkdir -p ./%s_DC_Log_%d/", spec.c_str(), run_NUM);
+
+      //Check if directory exists
+      if (system(dir_log) != 0) 
+	{
+	  cout << "Creating Directory to store SHMS Calibration Results . . ." << endl; 
+	  system(dir_log);  //create directory to log calibration results
+	}
+      
+      
+    }
+
+}
+
+
 //____________________________________________________________
 void DC_calib::printInitVar()
 {
@@ -121,18 +162,18 @@ void DC_calib::SetPlaneNames()
       SPECTROMETER = "P";
       spectre = "p";
    
-      plane_names[0]="1u1",  nwires[0] = 107;  
-      plane_names[1]="1u2",  nwires[1] = 107;
-      plane_names[2]="1x1",  nwires[2] = 79;
-      plane_names[3]="1x2",  nwires[3] = 79; 
-      plane_names[4]="1v1",  nwires[4] = 107;
-      plane_names[5]="1v2",  nwires[5] = 107;
-      plane_names[6]="2v2",  nwires[6] = 107;
-      plane_names[7]="2v1",  nwires[7] = 107;
-      plane_names[8]="2x2",  nwires[8] = 79;
-      plane_names[9]="2x1",  nwires[9] = 79;
-      plane_names[10]="2u2", nwires[10] = 107;
-      plane_names[11]="2u1", nwires[11] = 107;
+      planes[0] = plane_names[0]="1u1",  nwires[0] = 107; 
+      planes[1] = plane_names[1]="1u2",  nwires[1] = 107; 
+      planes[2] = plane_names[2]="1x1",  nwires[2] = 79;
+      planes[3] = plane_names[3]="1x2",  nwires[3] = 79; 
+      planes[4] = plane_names[4]="1v1",  nwires[4] = 107; 
+      planes[5] = plane_names[5]="1v2",  nwires[5] = 107; 
+      planes[6] = plane_names[6]="2v2",  nwires[6] = 107;
+      planes[7] = plane_names[7]="2v1",  nwires[7] = 107;
+      planes[8] = plane_names[8]="2x2",  nwires[8] = 79;
+      planes[9] = plane_names[9]="2x1",  nwires[9] = 79;
+      planes[10] = plane_names[10]="2u2", nwires[10] = 107;
+      planes[11] = plane_names[11]="2u1", nwires[11] = 107;
    
     }
       
@@ -145,18 +186,18 @@ void DC_calib::SetPlaneNames()
       SPECTROMETER = "H";
       spectre="h";
       
-      plane_names[0]="1u1",  nwires[0] = 96;  
-      plane_names[1]="1u2",  nwires[1] = 96;
-      plane_names[2]="1x1",  nwires[2] = 102;
-      plane_names[3]="1x2",  nwires[3] = 102; 
-      plane_names[4]="1v2",  nwires[4] = 96;
-      plane_names[5]="1v1",  nwires[5] = 96;
-      plane_names[6]="2v1",  nwires[6] = 96;
-      plane_names[7]="2v2",  nwires[7] = 96;
-      plane_names[8]="2x2",  nwires[8] = 102;
-      plane_names[9]="2x1",  nwires[9] = 102;
-      plane_names[10]="2u2", nwires[10] = 96;
-      plane_names[11]="2u1", nwires[11] = 96;
+      planes[0] = plane_names[0]="1u1",  nwires[0] = 96;  
+      planes[1] = plane_names[1]="1u2",  nwires[1] = 96;
+      planes[2] = plane_names[2]="1x1",  nwires[2] = 102;
+      planes[3] = plane_names[3]="1x2",  nwires[3] = 102; 
+      planes[4] = plane_names[4]="1v2",  nwires[4] = 96;
+      planes[5] = plane_names[5]="1v1",  nwires[5] = 96;
+      planes[6] = plane_names[6]="2v1",  nwires[6] = 96;
+      planes[7] = plane_names[7]="2v2",  nwires[7] = 96;
+      planes[8] = plane_names[8]="2x2",  nwires[8] = 102;
+      planes[9] = plane_names[9]="2x1",  nwires[9] = 102;
+      planes[10] = plane_names[10]="2u2", nwires[10] = 96;
+      planes[11] = plane_names[11]="2u1", nwires[11] = 96;
     }
   
 }
@@ -206,24 +247,24 @@ void DC_calib::GetDCLeafs()
   
   if (spec=="SHMS")
     {
-      cal_etotnorm_leaf = "P.cal.etotnorm";
+      cal_etot_leaf = "P.cal.etot";
       cer_npe_leaf = "P.ngcer.npeSum";  
       EL_CLEAN_leaf = "T.shms.pEL_CLEAN_tdcTime";
       //EL_CLEAN_leaf = "T.coin.pEL_CLEAN_ROC2_tdcTime";
       
       //Check Branch Status
-      status_cal = tree->GetBranchStatus(cal_etotnorm_leaf);
+      status_cal = tree->GetBranchStatus(cal_etot_leaf);
       status_cer = tree->GetBranchStatus(cer_npe_leaf); 
       status_EL_clean = tree->GetBranchStatus(EL_CLEAN_leaf);
 
       
-      if ((!status_cal || !status_cer || !status_EL_clean) && (pid=="pid_elec" || pid=="pid_prot" || pid=="bkg_cut"))
+      if ((!status_cal || !status_cer || !status_EL_clean) && (pid=="pid_elec" || pid=="pid_hadron"))
 	{
 	  cout << "*************ATTENTION!**************" << endl;
 	  cout << "" << endl;
 	  cout << " One or more of the following leafs " << endl;
 	  cout << " is *NOT* present in current ROOTfile. " << endl;
-	  cout << "1) " << cal_etotnorm_leaf<< endl;
+	  cout << "1) " << cal_etot_leaf<< endl;
 	  cout << "2) " << cer_npe_leaf << endl;
 	  cout << "3) " << EL_CLEAN_leaf << endl;
 	  cout << "" << endl;
@@ -240,7 +281,7 @@ void DC_calib::GetDCLeafs()
     
       else
 	{
-	  tree->SetBranchAddress(cal_etotnorm_leaf, &cal_etot_norm);
+	  tree->SetBranchAddress(cal_etot_leaf, &cal_etot);
 	  tree->SetBranchAddress(cer_npe_leaf, &cer_npe);   
 	  tree->SetBranchAddress(EL_CLEAN_leaf, &EL_CLEAN);
 	}
@@ -249,23 +290,23 @@ void DC_calib::GetDCLeafs()
 
   else if (spec=="HMS")
     {
-      cal_etotnorm_leaf = "H.cal.etotnorm";
+      cal_etot_leaf = "H.cal.etot";
       cer_npe_leaf = "H.cer.npeSum";  
       EL_CLEAN_leaf = "T.hms.hEL_CLEAN_tdcTime";
       //EL_CLEAN_leaf = "T.coin.hEL_CLEAN_ROC2_tdcTime";
 
       //Check Branch Status with Boolean
-      status_cal = tree->GetBranchStatus(cal_etotnorm_leaf);
+      status_cal = tree->GetBranchStatus(cal_etot_leaf);
       status_cer = tree->GetBranchStatus(cer_npe_leaf); 
       status_EL_clean = tree->GetBranchStatus(EL_CLEAN_leaf);
 
-      if ((!status_cal || !status_cer || !status_EL_clean) && (pid=="pid_elec" || pid=="pid_prot" || pid=="bkg_cut"))
+      if ((!status_cal || !status_cer || !status_EL_clean) && (pid=="pid_elec" || pid=="pid_hadron"))
 	{
 	  cout << "*************ATTENTION!**************" << endl;
 	  cout << "" << endl;
 	  cout << " One or more of the following leafs " << endl;
 	  cout << " is *NOT* present in current ROOTfile. " << endl;
-	  cout << "1) " << cal_etotnorm_leaf<< endl;
+	  cout << "1) " << cal_etot_leaf<< endl;
 	  cout << "2) " << cer_npe_leaf << endl;
 	  cout << "3) " << EL_CLEAN_leaf << endl;
 	  cout << "" << endl;
@@ -281,7 +322,7 @@ void DC_calib::GetDCLeafs()
 
       else
 	{
-	  tree->SetBranchAddress(cal_etotnorm_leaf, &cal_etot_norm);
+	  tree->SetBranchAddress(cal_etot_leaf, &cal_etot);
 	  tree->SetBranchAddress(cer_npe_leaf, &cer_npe);   
 	  tree->SetBranchAddress(EL_CLEAN_leaf, &EL_CLEAN);
 	}
@@ -296,6 +337,9 @@ void DC_calib::AllocateDynamicArrays()
 {
  
 
+  dir_log = new char();
+  dir_log_name = new char();
+  
   //Allocate 1D dynamic arrays
   plane_dt      = new TH1F[NPLANES];       //create plane drift time histo 1Darray ( get_pdc_time_histo.C )
   plane_dt_corr = new TH1F[NPLANES];      //create plane drift times to store after applying tzero correction
@@ -441,7 +485,7 @@ void DC_calib::EventLoop()
       //PID Cut, Set Bool_t to actual leaf value, and see if it passes cut
       else if (pid=="pid_elec")
 	{
-	  //cal_elec = cal_etot_norm>0.1;  //normalize energy > 0.1 (bkg cleanup)
+	  //cal_elec = cal_etot>0.1;  //normalize energy > 0.1 (bkg cleanup)
 	  cer_elec = cer_npe>1.0;     //number of photoelec. > 1 (electrons)
 	  elec_clean = EL_CLEAN>0;    //tdcTime>0 (reduce bkg events)
 	}
@@ -449,28 +493,32 @@ void DC_calib::EventLoop()
       //PID Cut, hadron, Set Bool_t to actual value, and see if it passes cut
       else if (pid=="pid_hadron")
 	{
-	  //cal_elec = cal_etot_norm>0.1;  //normalize energy > 0.1 (bkg cleanup)
+	  //cal_elec = cal_etot>0.1;  //normalize energy > 0.1 (bkg cleanup)
 	  cer_elec = cer_npe<1.0;      //number of photoelec. < 1 (hadrons)
-	  elec_clean = EL_CLEAN>0;    //tdcTime>0 (reduce bkg events)
+	  elec_clean = 1;    //set always to true (NOT use e-_clean trigger cut)
 	}
 
       //PID Cut, BACKGROUND, Set Bool_t to actual value, and see if it passes cut
-      else if (pid=="pid_bkg")
+      else if (pid=="dc_1hit")
 	{
-	  //cal_elec = cal_etot_norm>0.1;  //normalize energy > 0.1 (bkg cleanup)
+
+	  //Do NOT apply any pid cuts
 	  cer_elec = 1;      //Set to always true
-	  elec_clean = EL_CLEAN>0;    //tdcTime>0 (reduce bkg events)
+	  elec_clean = 1;    //Set to always true
+	  
 	}
 
       
 
       else 
 	{
-	  cout << "Enter which particle to calibrate: " << endl;
+	  cout << "Enter which particle to calibrate in main_calib.C: " << endl;
 	  cout << "For electrons: 'pid_elec' " << endl;
 	  cout << "For hadrons: 'pid_hadron' " << endl;	  
-	  cout << "For background cut (Only EL-CLEAN trigger): 'pid_bkg' " << endl;
+	  cout << "For background cut (ndata==1): 'dc_1hit' " << endl;
 	  cout << "NO PID Cuts: 'pid_KFALSE' " << endl;
+	  cout << "Exiting NOW!" << endl;
+	  exit (EXIT_SUCCESS);
 	}
 
       //----------------------------------------------------------------------------
@@ -481,12 +529,20 @@ void DC_calib::EventLoop()
 	  for(Int_t ip=0; ip<NPLANES; ip++)
 	    {
 	      // cout << "PLANE: " << ip << endl;
+
+	      //Require single hit in chamber / event / plane
+	      if (pid=="dc_1hit")
+		{ 
+		  single_hit = (ndata_time[ip]==1 && ndata_wirenum[ip]==1);
+		}
 	      
 	      //-----------------------------------------------------------------------------------------	  
 	      
 	      //Require number of chamber hits per event per plane to be UNITY.
-	      if (ndata_time[ip]==1 && ndata_wirenum[ip]==1)
+	      if (single_hit)
 		{
+
+        
 		  //Loop over number of hits for each trigger in each DC plane 
 		  for(Int_t j = 0, k = 0; j < ndata_time[ip], k < ndata_wirenum[ip]; j++, k++)    
 		    {
@@ -812,7 +868,7 @@ void DC_calib::WriteToFile(Int_t debug = 0)
 
   
   //create output ROOT file to write UnCALIB./CALIB. histos
-  ofile_name = spec+"_DC_driftimes.root";
+  ofile_name = "./"+spec+"_DC_Log_"+std::to_string(run_NUM) +"/"+spec+"_DC_driftimes.root";
   out_file   = new TFile(ofile_name, "RECREATE"); 
 
   
@@ -916,10 +972,11 @@ void DC_calib::WriteToFile(Int_t debug = 0)
     //-----Write 'tzero' values to a TEXT FILE--------------------
     
     //open a text FILE to write
-   
     for (int ip = 0; ip < NPLANES; ip++) 
       {
-	otxtfile_name = "t_zero_values_"+plane_names[ip]+".dat";
+
+	otxtfile_name = Form("./%s_DC_Log_%d/t_zero_values_%s.dat", spec.c_str(), run_NUM, planes[ip].c_str());
+	cout << "*******FILENAME:******* " << otxtfile_name << endl;
 	out_txtFILE.open(otxtfile_name);
 	out_txtFILE << "#Plane_" + plane_names[ip] << endl;
 	out_txtFILE << "#Wire " << setw(12) << "tzero " << setw(12) << "t_zero_err " << setw(12) << "entries" << endl;
@@ -945,7 +1002,7 @@ void DC_calib::WriteToFile(Int_t debug = 0)
 	gr1_canv = new TCanvas("gr1", "", 2000, 500);
 	gr1_canv->SetGrid();
 	//write TGraph: tzero v. wire number to root file
-	itxtfile_name = "t_zero_values_"+plane_names[ip]+".dat";
+	itxtfile_name =  "./"+spec+"_DC_Log_"+ std::to_string(run_NUM) +"/"+"t_zero_values_"+plane_names[ip]+".dat";
 	graph = new TGraphErrors(itxtfile_name, "%lg %lg %lg");
 	graph->SetName("graph");
 	
@@ -977,7 +1034,7 @@ void DC_calib::WriteToFile(Int_t debug = 0)
 //__________________________________________________________________________
 void DC_calib::WriteTZeroParam()
 {
-  otxtfile_name =  "./"+spectre+"dc_tzero_per_wire_"+std::to_string(run_NUM)+".param";
+  otxtfile_name =  "./"+spec+"_DC_Log_"+ std::to_string(run_NUM) +"/"+spectre+"dc_tzero_per_wire_"+std::to_string(run_NUM)+".param";
   out_txtFILE.open(otxtfile_name);
   
   for (int ip=0; ip<NPLANES; ip++) { 
@@ -1039,7 +1096,7 @@ void DC_calib::ApplyTZeroCorrection()
       //PID Cut, Set Bool_t to actual value, and see if it passes cut
       else if (pid=="pid_elec")
 	{
-	  //cal_elec = cal_etot_norm>0.1;   //normalize energy > 0.1 (reduce bkg events)
+	  //cal_elec = cal_etot>0.1;   //normalize energy > 0.1 (reduce bkg events)
 	  cer_elec = cer_npe>1.0;          //number of photoelec. > 1 (electrons)
 	  elec_clean = EL_CLEAN>0.;    //tdcTime>0 (reduce bkg events)
 
@@ -1048,29 +1105,32 @@ void DC_calib::ApplyTZeroCorrection()
       //PID Cut, hadron, Set Bool_t to actual value, and see if it passes cut
       else if (pid=="pid_hadron")
 	{
-	  //cal_elec = cal_etot_norm>0.1;   //normalize energy > 0.1 (reduce bkg events)
+	  //cal_elec = cal_etot>0.1;   //normalize energy > 0.1 (reduce bkg events)
 	  cer_elec = cer_npe<1.0;       //number of photoelec. < 1 (hadrons)
-	  elec_clean = EL_CLEAN>0.;    //tdcTime>0 (reduce bkg events)
+	  elec_clean = 1;    //Set always to true (do NOT make el-clean trigger cuts)
 	  
 	}
 
       //PID Cut, hadron, Set Bool_t to actual value, and see if it passes cut
-      else if (pid=="pid_bkg")
+      else if (pid=="dc_1hit")
 	{
-	  //cal_elec = cal_etot_norm>0.1;   //normalize energy > 0.1 (reduce bkg events)
+	  //cal_elec = cal_etot>0.1;   //normalize energy > 0.1 (reduce bkg events)
 	  cer_elec = 1;       //set to always true
-	  elec_clean = EL_CLEAN>0.;    //tdcTime>0 (reduce bkg events)
+	  elec_clean = 1;    //tdcTime>0 (reduce bkg events)//set always to true
 	  
 	}
       
 
       else 
 	{
-	  cout << "Enter which particle to calibrate: " << endl;
+	  cout << "Enter which particle to calibrate in main_calib.C: " << endl;
 	  cout << "For electrons: 'pid_elec' " << endl;
 	  cout << "For hadrons: 'pid_hadron' " << endl;	  
-	  cout << "For background cut (Only EL-CLEAN trigger): 'pid_bkg' " << endl;
+	  cout << "For background cut (Only ndata==1): 'dc_1hit' " << endl;
 	  cout << "NO PID Cuts: 'pid_KFALSE' " << endl;
+	  cout << "Exiting NOW!" << endl;
+	  exit (EXIT_SUCCESS);
+		  
 	}
 
       //--------------------------------------------------------------------------------------
@@ -1084,8 +1144,16 @@ void DC_calib::ApplyTZeroCorrection()
 	      //cout << "ApplyTZeroCorr: " << weighted_avg[ip] << endl;
 	      //Loop over number of hits for each trigger in each DC plane 
 
+	      //Require single hit in chamber / event / plane
+	      if (pid=="dc_1hit")
+		{ 
+		  single_hit = (ndata_time[ip]==1 && ndata_wirenum[ip]==1);
+		}
+	      
+	      //-----------------------------------------------------------------------------------------	  
+	      
 	      //Require number of chamber hits per event per plane to be UNITY.
-	      if (ndata_time[ip]==1 && ndata_wirenum[ip]==1)
+	      if (single_hit)
 		{
 		  for(Int_t j = 0, k = 0; j < ndata_time[ip], k < ndata_wirenum[ip]; j++, k++)    
 		    {
@@ -1295,7 +1363,7 @@ void DC_calib::ApplyTZeroCorrection()
 //_________________________________________________________________________________
 void DC_calib::WriteLookUpTable()
 {
-  otxtfile_name = "./"+spectre+"dc_calib_"+std::to_string(run_NUM)+".param";
+  otxtfile_name = "./"+spec+"_DC_Log_"+std::to_string(run_NUM)+"/"+spectre+"dc_calib_"+std::to_string(run_NUM)+".param";
   out_txtFILE.open(otxtfile_name);
   Double_t t_offset_firstbin = 0.0;
   //Set headers for subsequent columns of data
diff --git a/CALIBRATION/shms_dc_calib/scripts/DC_calib.h b/CALIBRATION/shms_dc_calib/scripts/DC_calib.h
index 2ed5e01a..3967cb2e 100644
--- a/CALIBRATION/shms_dc_calib/scripts/DC_calib.h
+++ b/CALIBRATION/shms_dc_calib/scripts/DC_calib.h
@@ -12,11 +12,12 @@ class DC_calib
  public:
   
   //consructor and destructor
-  DC_calib(TString a, TString b, const Int_t c, Long64_t d, TString e);
+  DC_calib(string a, TString b, const Int_t c, Long64_t d, TString e);
   ~DC_calib();
 
 
   //Define Functions
+  void setup_Directory();
   void printInitVar();
   void SetPlaneNames();
   void GetDCLeafs();
@@ -45,10 +46,11 @@ class DC_calib
   
   TString SPECTROMETER;
   TString spectre;
-  TString spec;
+  string spec;
   TString DETECTOR;
   TString plane_names[NPLANES];
-
+  string planes[NPLANES];
+  
   TString base_name;
   TString ndatatime;
   TString ndatawirenum;
@@ -56,11 +58,11 @@ class DC_calib
   TString drifttime;
   TString wirenum;
 
-  TString cal_etotnorm_leaf;   
+  TString cal_etot_leaf;   
   TString cer_npe_leaf;
   TString EL_CLEAN_leaf;
  
-  Double_t cal_etot_norm;   //calorimeter normalized energy
+  Double_t cal_etot;   //calorimeter normalized energy
   Double_t cer_npe;       //cerenkon photoelectron Sum
   Double_t EL_CLEAN;     //electron clean trigger
 
@@ -75,10 +77,13 @@ class DC_calib
   Bool_t cal_elec;     //calorimeter normalized energy cut
   Bool_t cer_elec;     //cerenkov cut
   Bool_t elec_clean;    //e- clean trigger tdctime cut
-
+  Bool_t single_hit;    //single hit / event / plane to clean background
  
 
-
+  //Variables for setting up a run_directory to keep track of calibration files
+  const char* dir_log;
+  const char* dir_log_name;
+  
   Int_t wire;
   
   Int_t ndata_time[NPLANES];
diff --git a/CALIBRATION/shms_dc_calib/scripts/input_RUN.txt b/CALIBRATION/shms_dc_calib/scripts/input_RUN.txt
deleted file mode 100644
index ce9cd490..00000000
--- a/CALIBRATION/shms_dc_calib/scripts/input_RUN.txt
+++ /dev/null
@@ -1 +0,0 @@
-437
diff --git a/CALIBRATION/shms_dc_calib/scripts/main_calib.C b/CALIBRATION/shms_dc_calib/scripts/main_calib.C
index 47d3ced1..7adfc971 100644
--- a/CALIBRATION/shms_dc_calib/scripts/main_calib.C
+++ b/CALIBRATION/shms_dc_calib/scripts/main_calib.C
@@ -16,11 +16,12 @@ int main_calib()
   clock_t cl;
   cl = clock();
                                                                                                   
-                                                                                                  //pid_elec, pid_hadron, pid_bkg pid_kFALSE (no PID cuts) 
-                                                                                                  // |
-                                                                                                  // v
-  DC_calib obj("HMS", "../../../ROOTfiles/hms_replay_production_all_1856_dcuncal.root", 1856,2000000, "pid_kFALSE");
-// DC_calib obj("SHMS", "../../../ROOTfiles/shms_replay_production_all_2071_-1_dcuncalib.root", 2071, 3000000, "pid_bkg"); 
+                                                                                                        //pid_elec, pid_hadron, dc_1hit,  pid_kFALSE (no PID cuts) 
+                                                                                                        // |
+                                                                                                        // v
+  //DC_calib obj("HMS", "../../../ROOTfiles/hms_replay_production_all_1856_dcuncal.root", 1856,2000000, "pid_kFALSE");
+  //DC_calib obj("SHMS", "../../../ROOTfiles/shms_replay_production_all_2071_-1_dcuncalib.root", 2071, 3000000, "pid_bkg"); 
+  DC_calib obj("HMS", "../../../ROOTfiles/hms_coin_replay_production_1866_1000000.root", 1866, 1000000, "dc_1hit");
 
  
   obj.printInitVar();
diff --git a/CALIBRATION/shms_dc_calib/scripts/get_LookUp_Values.C b/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_LookUp_Values.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/get_LookUp_Values.C
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/get_LookUp_Values.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/get_pdc_time_histo.C b/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_pdc_time_histo.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/get_pdc_time_histo.C
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/get_pdc_time_histo.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/get_pdc_time_histo_tzero_corrected.C b/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_pdc_time_histo_tzero_corrected.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/get_pdc_time_histo_tzero_corrected.C
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/get_pdc_time_histo_tzero_corrected.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/get_tzero_param.C b/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_tzero_param.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/get_tzero_param.C
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/get_tzero_param.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/get_tzero_per_wire_param.C b/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_tzero_per_wire_param.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/get_tzero_per_wire_param.C
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/get_tzero_per_wire_param.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/get_wire_tzero.C b/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_wire_tzero.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/get_wire_tzero.C
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/get_wire_tzero.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/update_pdcparam.C b/CALIBRATION/shms_dc_calib/scripts/old_scripts/update_pdcparam.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/update_pdcparam.C
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/update_pdcparam.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/wire_drift_times.C b/CALIBRATION/shms_dc_calib/scripts/old_scripts/wire_drift_times.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/wire_drift_times.C
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/wire_drift_times.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/wire_drift_times.h b/CALIBRATION/shms_dc_calib/scripts/old_scripts/wire_drift_times.h
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/wire_drift_times.h
rename to CALIBRATION/shms_dc_calib/scripts/old_scripts/wire_drift_times.h
-- 
GitLab