From 104e25697f7e4130355eb7e012cd7c607157e7bd Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Mon, 27 Nov 2017 10:08:57 -0500
Subject: [PATCH] Add a time offset to hodoscope FADC pulse times so that it
 stays positive.

---
 src/THcHodoscope.cxx         |  3 +++
 src/THcHodoscope.h           |  2 ++
 src/THcScintillatorPlane.cxx | 13 ++++++++-----
 src/THcScintillatorPlane.h   |  1 +
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx
index fb46e9f..e214e82 100644
--- a/src/THcHodoscope.cxx
+++ b/src/THcHodoscope.cxx
@@ -277,12 +277,14 @@ Int_t THcHodoscope::ReadDatabase( const TDatime& date )
   fyHiScin = new Int_t [fNHodoscopes];
   fHodoSlop = new Double_t [fNPlanes];
   fTdcOffset = new Int_t [fNPlanes];
+  fAdcTdcOffset = new Int_t [fNPlanes];
   fAdcTimeWindowMin = new Double_t [fNPlanes];
   fAdcTimeWindowMax = new Double_t [fNPlanes];
 
 
   for(Int_t ip=0;ip<fNPlanes;ip++) { // Set a large default window
    fTdcOffset[ip] = 0 ;
+   fAdcTdcOffset[ip] = 0 ;
   }
 
   DBRequest list[]={
@@ -310,6 +312,7 @@ Int_t THcHodoscope::ReadDatabase( const TDatime& date )
     {"hodo_slop",                        fHodoSlop,               kDouble,  (UInt_t) fNPlanes},
     {"debugprintscinraw",                &fdebugprintscinraw,               kInt,  0,1},
     {"hodo_tdc_offset",                  fTdcOffset,              kInt,     (UInt_t) fNPlanes, 1},
+    {"hodo_adc_tdc_offset",              fAdcTdcOffset,           kInt,     (UInt_t) fNPlanes, 1},
     {"hodo_AdcTimeWindowMin",            fAdcTimeWindowMin,       kDouble,  (UInt_t) fNPlanes},
     {"hodo_AdcTimeWindowMax",            fAdcTimeWindowMax,       kDouble,  (UInt_t) fNPlanes},
     {"dumptof",                          &fDumpTOF,               kInt,    0, 1},
diff --git a/src/THcHodoscope.h b/src/THcHodoscope.h
index bbff333..f4b5abf 100644
--- a/src/THcHodoscope.h
+++ b/src/THcHodoscope.h
@@ -89,6 +89,7 @@ public:
   Double_t GetPlaneCenter(Int_t ip) { return fPlaneCenter[ip];}
   Double_t GetPlaneSpacing(Int_t ip) { return fPlaneSpacing[ip];}
   Int_t GetTdcOffset(Int_t ip) const { return fTdcOffset[ip];}
+  Int_t GetAdcTdcOffset(Int_t ip) const { return fAdcTdcOffset[ip];}
 
   Double_t GetAdcTimeWindowMin(Int_t ip) { return fAdcTimeWindowMin[ip];}
   Double_t GetAdcTimeWindowMax(Int_t ip) { return fAdcTimeWindowMax[ip];}
@@ -198,6 +199,7 @@ protected:
   Double_t     fNCerNPE;
   Double_t*    fHodoSlop;
   Int_t        *fTdcOffset;
+  Int_t        *fAdcTdcOffset;
   Int_t        fdebugprintscinraw;
   Int_t        fTestSum;
   Int_t        fTrackEffTestNScinPlanes;
diff --git a/src/THcScintillatorPlane.cxx b/src/THcScintillatorPlane.cxx
index 3038937..1625aca 100644
--- a/src/THcScintillatorPlane.cxx
+++ b/src/THcScintillatorPlane.cxx
@@ -240,6 +240,7 @@ Int_t THcScintillatorPlane::ReadDatabase( const TDatime& date )
 
   fHodoSlop= ((THcHodoscope*) GetParent())->GetHodoSlop(fPlaneNum-1);
   fTdcOffset= ((THcHodoscope*) GetParent())->GetTdcOffset(fPlaneNum-1);
+  fAdcTdcOffset= ((THcHodoscope*) GetParent())->GetAdcTdcOffset(fPlaneNum-1);
   fScinTdcMin=((THcHodoscope *)GetParent())->GetTdcMin();
   fScinTdcMax=((THcHodoscope *)GetParent())->GetTdcMax();
   fScinTdcToTime=((THcHodoscope *)GetParent())->GetTdcToTime();
@@ -562,7 +563,7 @@ Int_t THcScintillatorPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
    * - Loops through "rawhits" array  starting at index of "nexthit"
    * - Assumes that the hit list is sorted by plane and looping ends when plane number of hit doesn't match fPlaneNum
    * - Fills THcSignalHit objects frPosTDCHits and frNegTDCHits when TDC > 0
-   * - Fills THcSignalHit objects frPosADCHits and frNegaDCHit with pedestal subtracted ADC when value larger than 50
+   * - Fills THcSignalHit objects frPosADCHits and frNegADCHit with pedestal subtracted ADC when value larger than 50
    * - For hits that have TDC value for either positive or negative PMT within  fScinTdcMin and fScinTdcMax
    *  + Creates new  fHodoHits[fNScinHits] =  THcHodoHit
    *  + Calculates pulse height correction to the positive and negative PMT times
@@ -689,7 +690,7 @@ Int_t THcScintillatorPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
       ((THcSignalHit*) frPosAdcPulseAmp->ConstructedAt(nrPosAdcHits))->Set(padnum, rawPosAdcHit.GetPulseAmp(thit));
 
       ((THcSignalHit*) frPosAdcPulseTimeRaw->ConstructedAt(nrPosAdcHits))->Set(padnum, rawPosAdcHit.GetPulseTimeRaw(thit));
-      ((THcSignalHit*) frPosAdcPulseTime->ConstructedAt(nrPosAdcHits))->Set(padnum, rawPosAdcHit.GetPulseTime(thit));
+      ((THcSignalHit*) frPosAdcPulseTime->ConstructedAt(nrPosAdcHits))->Set(padnum, rawPosAdcHit.GetPulseTime(thit)+fAdcTdcOffset);
 
       if (rawPosAdcHit.GetPulseAmpRaw(thit) > 0)  ((THcSignalHit*) frPosAdcErrorFlag->ConstructedAt(nrPosAdcHits))->Set(padnum, 0);
       if (rawPosAdcHit.GetPulseAmpRaw(thit) <= 0) ((THcSignalHit*) frPosAdcErrorFlag->ConstructedAt(nrPosAdcHits))->Set(padnum, 1);
@@ -709,7 +710,7 @@ Int_t THcScintillatorPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
       ((THcSignalHit*) frNegAdcPulseAmpRaw->ConstructedAt(nrNegAdcHits))->Set(padnum, rawNegAdcHit.GetPulseAmpRaw(thit));
       ((THcSignalHit*) frNegAdcPulseAmp->ConstructedAt(nrNegAdcHits))->Set(padnum, rawNegAdcHit.GetPulseAmp(thit));
       ((THcSignalHit*) frNegAdcPulseTimeRaw->ConstructedAt(nrNegAdcHits))->Set(padnum, rawNegAdcHit.GetPulseTimeRaw(thit));
-      ((THcSignalHit*) frNegAdcPulseTime->ConstructedAt(nrNegAdcHits))->Set(padnum, rawNegAdcHit.GetPulseTime(thit));
+      ((THcSignalHit*) frNegAdcPulseTime->ConstructedAt(nrNegAdcHits))->Set(padnum, rawNegAdcHit.GetPulseTime(thit)+fAdcTdcOffset);
 
       if (rawNegAdcHit.GetPulseAmpRaw(thit) > 0)  ((THcSignalHit*) frNegAdcErrorFlag->ConstructedAt(nrNegAdcHits))->Set(padnum, 0);
       if (rawNegAdcHit.GetPulseAmpRaw(thit) <= 0) ((THcSignalHit*) frNegAdcErrorFlag->ConstructedAt(nrNegAdcHits))->Set(padnum, 1);
@@ -724,6 +725,8 @@ Int_t THcScintillatorPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
       ((THcSignalHit*) frPosTDCHits->ConstructedAt(nrPosTDCHits++))->Set(padnum, hit->GetRawTdcHitPos().GetTime()+fTdcOffset);
     if (hit->GetRawTdcHitNeg().GetNHits() > 0)
       ((THcSignalHit*) frNegTDCHits->ConstructedAt(nrNegTDCHits++))->Set(padnum, hit->GetRawTdcHitNeg().GetTime()+fTdcOffset);
+    // Should we make lists of offset corrected ADC Pulse times here too?  For now
+    // the frNegAdcPulseTime frPosAdcPulseTime have that offset correction.
     //
     Bool_t badcraw_pos=kFALSE;
     Bool_t badcraw_neg=kFALSE;
@@ -746,7 +749,7 @@ Int_t THcScintillatorPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
        	Int_t pulsePed     = rawNegAdcHit.GetPed();
        	Double_t pulseInt     = rawNegAdcHit.GetPulseInt(ielem);
        	Double_t pulseAmp     = rawNegAdcHit.GetPulseAmp(ielem);
-	Double_t pulseTime    = rawNegAdcHit.GetPulseTime(ielem);
+	Double_t pulseTime    = rawNegAdcHit.GetPulseTime(ielem)+fAdcTdcOffset;
 	Bool_t   errorflag = 0   ;
         if (rawNegAdcHit.GetPulseAmpRaw(ielem) <= 0) errorflag=1;
 	Bool_t   pulseTimeCut = (pulseTime > fAdcTimeWindowMin) &&  (pulseTime < fAdcTimeWindowMax);
@@ -765,7 +768,7 @@ Int_t THcScintillatorPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
        	Int_t pulsePed     = rawPosAdcHit.GetPed();
        	Double_t pulseInt     = rawPosAdcHit.GetPulseInt(ielem);
        	Double_t pulseAmp     = rawPosAdcHit.GetPulseAmp(ielem);
-	Double_t pulseTime    = rawPosAdcHit.GetPulseTime(ielem);
+	Double_t pulseTime    = rawPosAdcHit.GetPulseTime(ielem)+fAdcTdcOffset;
 	Bool_t   errorflag = 0   ;
         if (rawPosAdcHit.GetPulseAmpRaw(ielem) <= 0) errorflag=1;
 	Bool_t   pulseTimeCut = (pulseTime > fAdcTimeWindowMin) &&  (pulseTime < fAdcTimeWindowMax);
diff --git a/src/THcScintillatorPlane.h b/src/THcScintillatorPlane.h
index 866c9f0..eaecab0 100644
--- a/src/THcScintillatorPlane.h
+++ b/src/THcScintillatorPlane.h
@@ -179,6 +179,7 @@ class THcScintillatorPlane : public THaSubDetector {
   Double_t fADCPedScaleFactor;	// Multiply dynamic pedestal by this before subtracting
   Int_t fADCDiagCut;		// Cut for ADC in hit maps.  Defaults to 50
   Int_t fTdcOffset;		/* Overall offset to raw tdc */
+  Int_t fAdcTdcOffset;		/* Overall offset to raw adc times */
   Int_t fMaxHits;               /* maximum number of hits to be considered - useful for dimensioning arrays */
   Double_t fSpacing;            /* paddle spacing */
   Double_t fSize;               /* paddle size */
-- 
GitLab