From d68f46f91b4d7736a06e0c21b7684512ad2d0bbc Mon Sep 17 00:00:00 2001
From: Yero1990 <cyero002@fiu.edu>
Date: Mon, 12 Mar 2018 09:41:24 -0400
Subject: [PATCH] Added setup_Directory() method to main_calib.C :: Added
 README for DC Calibration :: changed directory named from shms_dc_calib to
 dc_calib (#424)

* added HMS/SHMS DC Calib README :: changed directory name from shms_dc_calib to dc_calib

* added setup_Directpry() method in main_calib.C
---
 .../scripts/DC_calib.C                        |  0
 .../scripts/DC_calib.h                        |  0
 CALIBRATION/dc_calib/scripts/README.md        | 99 +++++++++++++++++++
 .../scripts/alignDC.py                        |  0
 .../scripts/main_calib.C                      |  6 +-
 .../scripts/makeAlignmentPlots.C              |  0
 .../scripts/old_scripts/get_LookUp_Values.C   |  0
 .../scripts/old_scripts/get_pdc_time_histo.C  |  0
 .../get_pdc_time_histo_tzero_corrected.C      |  0
 .../scripts/old_scripts/get_tzero_param.C     |  0
 .../old_scripts/get_tzero_per_wire_param.C    |  0
 .../scripts/old_scripts/get_wire_tzero.C      |  0
 .../scripts/old_scripts}/run_Cal.C            |  0
 .../scripts/old_scripts/update_pdcparam.C     |  0
 .../scripts/old_scripts/wire_drift_times.C    |  0
 .../scripts/old_scripts/wire_drift_times.h    |  0
 .../scripts/replay_aligndc_shms.C             |  0
 CALIBRATION/shms_dc_calib/README.md           | 88 -----------------
 18 files changed, 102 insertions(+), 91 deletions(-)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/DC_calib.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/DC_calib.h (100%)
 create mode 100644 CALIBRATION/dc_calib/scripts/README.md
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/alignDC.py (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/main_calib.C (87%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/makeAlignmentPlots.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/get_LookUp_Values.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/get_pdc_time_histo.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/get_pdc_time_histo_tzero_corrected.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/get_tzero_param.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/get_tzero_per_wire_param.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/get_wire_tzero.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib/scripts/old_scripts}/run_Cal.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/update_pdcparam.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/wire_drift_times.C (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/old_scripts/wire_drift_times.h (100%)
 rename CALIBRATION/{shms_dc_calib => dc_calib}/scripts/replay_aligndc_shms.C (100%)
 delete mode 100644 CALIBRATION/shms_dc_calib/README.md

diff --git a/CALIBRATION/shms_dc_calib/scripts/DC_calib.C b/CALIBRATION/dc_calib/scripts/DC_calib.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/DC_calib.C
rename to CALIBRATION/dc_calib/scripts/DC_calib.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/DC_calib.h b/CALIBRATION/dc_calib/scripts/DC_calib.h
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/DC_calib.h
rename to CALIBRATION/dc_calib/scripts/DC_calib.h
diff --git a/CALIBRATION/dc_calib/scripts/README.md b/CALIBRATION/dc_calib/scripts/README.md
new file mode 100644
index 00000000..676b6146
--- /dev/null
+++ b/CALIBRATION/dc_calib/scripts/README.md
@@ -0,0 +1,99 @@
+HMS/SHMS Drift Chambers Calibration
+============================================
+This directory contains the code for calibrating the pair of HMS/SHMS drift chambers.
+
+
+
+Directory structure
+----------------------
+* hallc_replay/CALIBRATION/dc_calib/scripts/main_calib.C   : steering C++ code that executes the methods in DC_Calib.C
+* hallc_replay/CALIBRATION/dc_calib/scripts/DC_Calib.C  : Calibration Code where all the class  methods are defined
+* hallc_replay/CALIBRATION/dc_calib/scripts/DC_Calib.h  : Header file containing the variable definitions used in the methods
+
+
+
+Running code
+---------------
+NOTE: p: SHMS,  h: HMS,  <spec>: HMS, or SHMS
+
+* First set the parameter 'p(h)_using_tzero_per_wire = 0' in the 
+  parameter file located in: hallc_replay/PARAM/<spec>/DC/p(h)dc_cuts.param
+
+* Replay the data to produce the uncalibrated root file to be used as input in the calibration
+  NOTE: Make sure to include the necessary leafs if you want to make any pid cuts.
+  The leafs are:
+
+      SHMS:
+      P.ngcer.npeSum, P.cal.etot, T.shms.pEL_CLEAN_tdcTime (the P.cal.etot is currently commented out until further discussion)
+
+      HMS:
+      H.cer.npeSum, H.cal.etot, T.hms.hEL_CLEAN_tdcTime (the H.cal.etot is currently commented out until further discussion)
+      
+
+  * From the hallc_replay execute: ./hcana SCRIPTS/<spec>/PRODUCTION/<replay_script.C>
+
+* From the directory where this README file is:
+  -Open and modify 'DC_Calib obj()' line. This line has the following format:
+
+  -------------------------------------------------------------------------------------------------
+  	DC_calib obj("<spec_flag>", "/path/to/ROOTfile/", run_NUM, event_NUM, "<pid_flag>");
+
+	**The <spec_flag> and <pid_flag> have the possible arguments:
+
+	    <spec_flag>: HMS, SHMS
+
+	    <pid_flag>: pid_elec, pid_hadron, dc_1hit, pid_kFLASE
+
+	    When the <pid_flag> is selected, the calibration script applies the following cuts:
+
+	    	 1) pid_elec:  P.ngcer.npeSum > 1.0 && T.shms.pEL_CLEAN_tdcTime > 0.0   (for HMS:  H.cer.npeSum > 1.0 && T.hms.hEL_CLEAN_tdcTime > 0.0 )
+		 2) pid_hadron: P.ngcer.npeSum < 1.0  (for HMS:  H.cer.npeSum < 1.0 )
+		 3) dc_1hit: Ndata.P(H).dc.plane.time == 1 && Ndata.P(H).dc.plane.wirenum == 1,  where plane-> 1u1, 1u2, ...
+		    NOTE: The Ndata cut, requires a single hit in each chamber per plane per event
+		 4) pid_kFALSE: No cuts are applied.
+  -------------------------------------------------------------------------------------------------
+	    		
+
+* Once the arguments are specified, execute: root -l main_calib.C
+
+When the calibration is completed, a directory will be created under the name: <spec_flag>_DC_Log_runNUM/
+
+     In this directory, the calibration output files are stored automatically, once the calibration is completed:
+
+     	     1)  <spec_flag>_DC_driftimes.root
+	     2) t_zero_values_plane.dat
+	     3) p(h)dc_calib_runNUM.param
+	     4) p(h)dc_tzero_per_wire_runNUM.param
+
+	     	Each file contains the following:
+		     1) uncalibrated/calibrated drift times, fitted drift times, tzero_v_wire graphs
+		     2) data files containing four columns: wire, tzero, tzero_error,  entries
+		     3) parameter file containing time-to-distance look-up values
+		     4) parameter file containing per-wire tzero corrections
+
+
+* The parameter files must be copied to the following location:
+
+      -> /hallc_replay/PARAM/<spec>/DC/hdc_calib.param
+      -> /hallc_replay/PARAM/<spec>/DC/hdc_tzero_per_wire.param
+
+* Set the parameter 'p(h)_using_tzero_per_wire = 1' in the 
+  parameter file located in: hallc_replay/PARAM/<spec>/DC/p(h)dc_cuts.param
+
+
+* From the hallc_replay execute: ./hcana SCRIPTS/SHMS/PRODUCTION/<replay_script.C> once again.
+
+NOTE: An indication that the calibration worked is by looking a the drift distances, which should appear
+      relatively flat. There may be a high number of counts at the extremes of the drift distance, for which
+      the additional cuts may need to be applied.
+
+* The recommended cuts when looking at drift distances are:
+
+      1) P(H).dc.plane.time > 0   (drift time > 0)
+      2) PID cuts that were applied based on the <pid_flag> selected
+	     
+
+
+
+
+
diff --git a/CALIBRATION/shms_dc_calib/scripts/alignDC.py b/CALIBRATION/dc_calib/scripts/alignDC.py
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/alignDC.py
rename to CALIBRATION/dc_calib/scripts/alignDC.py
diff --git a/CALIBRATION/shms_dc_calib/scripts/main_calib.C b/CALIBRATION/dc_calib/scripts/main_calib.C
similarity index 87%
rename from CALIBRATION/shms_dc_calib/scripts/main_calib.C
rename to CALIBRATION/dc_calib/scripts/main_calib.C
index 7adfc971..cce4eaba 100644
--- a/CALIBRATION/shms_dc_calib/scripts/main_calib.C
+++ b/CALIBRATION/dc_calib/scripts/main_calib.C
@@ -19,11 +19,11 @@ int main_calib()
                                                                                                         //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("HMS", "../../../ROOTfiles/hms_replay_production_all_1856_dcuncal.root", 1856,200, "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");
+  DC_calib obj("HMS", "../../../ROOTfiles/hms_coin_replay_production_1866_1000000.root", 1866, 1000, "pid_kFALSE");
 
- 
+  obj.setup_Directory();
   obj.printInitVar();
   obj.SetPlaneNames();
   obj.GetDCLeafs();
diff --git a/CALIBRATION/shms_dc_calib/scripts/makeAlignmentPlots.C b/CALIBRATION/dc_calib/scripts/makeAlignmentPlots.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/makeAlignmentPlots.C
rename to CALIBRATION/dc_calib/scripts/makeAlignmentPlots.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_LookUp_Values.C b/CALIBRATION/dc_calib/scripts/old_scripts/get_LookUp_Values.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/get_LookUp_Values.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/get_LookUp_Values.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_pdc_time_histo.C b/CALIBRATION/dc_calib/scripts/old_scripts/get_pdc_time_histo.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/get_pdc_time_histo.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/get_pdc_time_histo.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_pdc_time_histo_tzero_corrected.C b/CALIBRATION/dc_calib/scripts/old_scripts/get_pdc_time_histo_tzero_corrected.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/get_pdc_time_histo_tzero_corrected.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/get_pdc_time_histo_tzero_corrected.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_tzero_param.C b/CALIBRATION/dc_calib/scripts/old_scripts/get_tzero_param.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/get_tzero_param.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/get_tzero_param.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_tzero_per_wire_param.C b/CALIBRATION/dc_calib/scripts/old_scripts/get_tzero_per_wire_param.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/get_tzero_per_wire_param.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/get_tzero_per_wire_param.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/get_wire_tzero.C b/CALIBRATION/dc_calib/scripts/old_scripts/get_wire_tzero.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/get_wire_tzero.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/get_wire_tzero.C
diff --git a/CALIBRATION/shms_dc_calib/run_Cal.C b/CALIBRATION/dc_calib/scripts/old_scripts/run_Cal.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/run_Cal.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/run_Cal.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/update_pdcparam.C b/CALIBRATION/dc_calib/scripts/old_scripts/update_pdcparam.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/update_pdcparam.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/update_pdcparam.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/wire_drift_times.C b/CALIBRATION/dc_calib/scripts/old_scripts/wire_drift_times.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/wire_drift_times.C
rename to CALIBRATION/dc_calib/scripts/old_scripts/wire_drift_times.C
diff --git a/CALIBRATION/shms_dc_calib/scripts/old_scripts/wire_drift_times.h b/CALIBRATION/dc_calib/scripts/old_scripts/wire_drift_times.h
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/old_scripts/wire_drift_times.h
rename to CALIBRATION/dc_calib/scripts/old_scripts/wire_drift_times.h
diff --git a/CALIBRATION/shms_dc_calib/scripts/replay_aligndc_shms.C b/CALIBRATION/dc_calib/scripts/replay_aligndc_shms.C
similarity index 100%
rename from CALIBRATION/shms_dc_calib/scripts/replay_aligndc_shms.C
rename to CALIBRATION/dc_calib/scripts/replay_aligndc_shms.C
diff --git a/CALIBRATION/shms_dc_calib/README.md b/CALIBRATION/shms_dc_calib/README.md
deleted file mode 100644
index 8315ac68..00000000
--- a/CALIBRATION/shms_dc_calib/README.md
+++ /dev/null
@@ -1,88 +0,0 @@
-SHMS Drift Chambers Calibration
-============================================
-This directory contains the code for calibrating the pair of SHMS drift chambers.
-
-
-
-Directory structure
-----------------------
-* hallc_replay/CALIBRATION/shms_dc_calib/run_Cal.C   : steering C++ code that executes all codes in the 'scripts' directory
-* hallc_replay/CALIBRATION/shms_dc_calib/scripts  : all scripts necessary to do calibration lie in this directory
-* hallc_replay/CALIBRATION/shms_dc_calib/root_files : all root files produced by the calibration are in this directory
-* hallc_replay/CALIBRATION/shms_dc_calib/data_files : all data files produced by the calibration are in this directory
-
-
-
-
-Running code
----------------
-* First set the parameter 'p_using_tzero_per_wire = 0' in the 
-  parameter file located at: hallc_replay/PARAM/SHMS/DC/CUTS/pdc_cuts.param
-
-* Replay the data to produce the uncalibrated root file to be used as input in the calibration
-  * From the hallc_replay execute: ./hcana SCRIPTS/SHMS/STACK/replay_shms.C
-
-* From the directory where this README file is: execute: root -l run_Cal.C
-
-* From the calibration results, two parameter files will be produced in:
-  * hallc_replay/PARAM/SHMS/DC/CALIB/pdc_tzero_per_wire_run#.param
-  * hallc_replay/PARAM/SHMS/DC/CALIB/pdc_calib_run#.param
-
-* Rename the new parameter files as follows:
-  * copy: pdc_tzero_per_wire_run#.param to pdc_tzero_per_wire.param
-  * copy: pdc_calib_run#.param to pdc_calib.param
-
-* Before replaying the data again, set the parameter 'p_using_tzero_per_wire = 1' to 
-  allow the source code (hcana) to read the parameter values during the replay.
-
-* Replay the data with the updated parameters to produce the new calibrated root files
-  with the corrected drift times and drift distances.
-
-* Compare the calibrated and uncalibrated root files to verify the calibration was done properly.
-
-
-
-Brief decription of code
-------------------------
-* Overview: The code determines the tzero offsets on a wire-by-wire basis. These offsets are 
-            corrections by which each wire drift time spectrum must be shifted to align it with a 
-            drift time of "0 ns". This time corresponds to when the electrons from the ionized gas inside
-            the chamber are in contact with the sense wire, hence a drift time of "0 ns". 
-
-* Brief Description of the scripts in the '/scripts' directory
-  *** to run the scripts independenlty, open the input_RUN.txt files and write the filen_ame, run_number and number of events in this order: root_file.root   run_number   events 
-
-  	** get_pdc_time_histo.C : 
-	  	-- outputs root_file: 'shms_dc_time_%d.root', (%d=run_number)
-		-- contains re-binned per-plane drift time histograms
-	
-	** wire_drift_times.C (and wire_drift_times.h) - See instructions in wire_drift_times.C on how to execute independently 
-	   	-- outputs root_file: 'shms_DC_plane_%d_wire_histos.root' 
-		-- contains a 2-D histo of "drift time vs. Wire Number" and drift time spectra for all wires in the plane
-
-	** get_wire_tzero.C 
-	        -- outputs root_file: 'shms_DC_plane_%d_fitted_histos.root'
-		-- contains line-fitted wire drift time histos. The extrapolation of the fit to the x-axis is defined as "tzero" 
-		   Also contains two "tzero vs. wirenumber" plots: one for all wires, and the other is after setting tzero=0 for
-                   wires that did not have enough statistics for a good quality fit, a weighted average was calculated for the latter.  
-		   
-		-- outputs data_file: 'shms_dc_planetzero_run%d.dat'         -> contains list of "tzero" values for all wires  (plane e.g. 2u1, 1x2, ...) 	
-		   	   	      'shms_dc_planetzero_run%d_updated.dat' -> contains list of "tzero" values for all wires that
-				      					     	had a good fit. The remaining tzeros are set to 0.
-				      'tzero_weighted_avg_run%d.dat          -> contains weighted tzero values per plane 
-
-	** get_tzero_per_wire_param.C
-		-- outputs data_file: 'tzero_values_per_wire.dat'
-		-- contains list of tzero values for all wires in all planes 
-
-		-- outputs param_file: /hallc_replay/PARAM/SHMS/DC/CALIB/pdc_tzero_per_wire_run#.param
-                -- contains tzero values for all wires in all planes, but the file is formatted so that the values may be read by the source code (hcana)
-	  
-	** get_pdc_time_histo_tzero_corrected.C  	  	
-	   	-- outputs root_file: 'shms_tzero_corr_histo.root'
-		-- contains list of "t0-corrected" wire drift times, and their respective plane drift times.
-
-	** get_LookUp_Values.C
-	        -- outputs param_file: /hallc_replay/PARAM/SHMS/DC/CALIB/pdc_calib_run#.param
- 		-- contains scaling factors calculated from the corrected plane drift times on a bin-by-in basis. These values get read by the source code
-		   which will be used to scale the drift distance histograms. 
-- 
GitLab