From b630d415a9c0c249dc279982d428d02b5867394e Mon Sep 17 00:00:00 2001
From: Cdaq Account <cdaq@cdaql1.jlab.org>
Date: Tue, 7 Feb 2017 09:39:39 -0500
Subject: [PATCH] Add fCosmicFlag to Hodoscope class The fCosmicFlag is used in
 EstimateFocalPlaneTime The start time for the drift chamber is determined as
 an average of the focal plane times for each hodo plane. Need to account for
 the TOF from the hodoscope to the focal plane (z=0). For cosmic data need to
 add this TOF to the corrected scintillator time, while usually one needs to
 subtract this TOF. Add a flag as parameter to switch between these modes.

---
 src/THcHodoscope.cxx | 16 ++++++++++++++--
 src/THcHodoscope.h   |  1 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx
index 228b969..abac4d8 100644
--- a/src/THcHodoscope.cxx
+++ b/src/THcHodoscope.cxx
@@ -312,6 +312,7 @@ Int_t THcHodoscope::ReadDatabase( const TDatime& date )
   }
 
   DBRequest list[]={
+    {"cosmicflag",                &fCosmicFlag,                      kInt},
     {"start_time_center",                &fStartTimeCenter,                      kDouble},
     {"start_time_slop",                  &fStartTimeSlop,                        kDouble},
     {"scin_tdc_to_time",                 &fScinTdcToTime,                        kDouble},
@@ -348,11 +349,13 @@ Int_t THcHodoscope::ReadDatabase( const TDatime& date )
   fTofTolerance = 3.0;
   fNCerNPE = 2.0;
   fNormETot = 0.7;
+  fCosmicFlag=0;
   // Gets added to each reference time corrected raw TDC value
   // to make sure valid range is all positive.
 
   gHcParms->LoadParmValues((DBRequest*)&list,prefix);
-
+  if (fCosmicFlag==1) cout << " setup for cosmics in TOF"<< endl;
+  cout << " cosmic flag = " << fCosmicFlag << endl;
   if(fDumpTOF) {
     fDumpOut.open(fTOFDumpFile.c_str());
     if(fDumpOut.is_open()) {
@@ -718,9 +721,16 @@ void THcHodoscope::EstimateFocalPlaneTime( void )
 	// Both tubes fired
 	Int_t index=hit->GetPaddleNumber()-1;
 	// Need to put this in a multihit histo
-	Double_t fptime = hit->GetScinCorrectedTime()
+        Double_t fptime;
+        if(fCosmicFlag==1) {
+	   fptime = hit->GetScinCorrectedTime()
+	  + (fPlanes[ip]->GetZpos()+(index%2)*fPlanes[ip]->GetDzpos())
+	  / (29.979 * fBetaNominal);
+	}else{
+	   fptime = hit->GetScinCorrectedTime()
 	  - (fPlanes[ip]->GetZpos()+(index%2)*fPlanes[ip]->GetDzpos())
 	  / (29.979 * fBetaNominal);
+	}
 	if(TMath::Abs(fptime-fStartTimeCenter)<=fStartTimeSlop) {
           Ngood_hits_plane++;
 	  Plane_fptime_sum+=fptime;
@@ -741,9 +751,11 @@ void THcHodoscope::EstimateFocalPlaneTime( void )
   if(fNfptimes>0) {
     fStartTime = fpTimeSum/fNfptimes;
     fGoodStartTime=kTRUE;
+      fFPTimeAll = fStartTime ;
   } else {
     fStartTime = fStartTimeCenter;
     fGoodStartTime=kFALSE;
+    fFPTimeAll = fStartTime ;
   }
   if((goodplanetime[0]||goodplanetime[1])
      &&(goodplanetime[2]||goodplanetime[3])) {
diff --git a/src/THcHodoscope.h b/src/THcHodoscope.h
index 19b3865..24037be 100644
--- a/src/THcHodoscope.h
+++ b/src/THcHodoscope.h
@@ -142,6 +142,7 @@ protected:
   UInt_t fMaxScinPerPlane,fMaxHodoScin; // max number of scin/plane; product of the first two
   Double_t fStartTimeCenter, fStartTimeSlop, fScinTdcToTime;
   Double_t fTofTolerance;
+  Int_t fCosmicFlag; //
   Double_t fPathLengthCentral;
   Double_t fScinTdcMin, fScinTdcMax; // min and max TDC values
   char** fPlaneNames;
-- 
GitLab