From 36c76b278895d0a67cefbbb6b3a6f9ace3e9e1f6 Mon Sep 17 00:00:00 2001
From: hallc-online <hallc-online@jlab.org>
Date: Mon, 1 May 2017 07:28:57 -0400
Subject: [PATCH] Modify THcDC and THcDriftChamberPlane to calculate per wire
 efficiency

Main purpose is to calculate the DC efficiency per wire
using the track information of the golden track.


THcDC.h
-----------
1) add method EfficiciencyPerWire
2) Add variables fWire_hit_did and fWire_hit_should

THcDC.cxx
------------
1) fWire_hit_did and fWire_hit_should are fixed length arrays
   the size of NPlanes that in set in method Init
2) Add variables wireHitDid and wireHitShould to the tree
3) In method SetFocalPlaneBestTrack add call to EfficiencyPerWire method
4) added EfficiencyPerWire method which loops over the hits
    and compares the wire number for the hit to the the track
    position at the plane (convert back to wire number).
    Then fills fWire_hit_did with the wire number if
    equal to the wire position of the hit equals the track.
    Also does loop over all planes and fills fWire_hit_should
    with the wire number of the track in each plane.

THcDriftChamberPlane.h and cxx
---------------------
1) Added method CalcWireFromPos
---
 src/THcDC.cxx                | 27 +++++++++++++++++++++++++++
 src/THcDC.h                  |  4 +++-
 src/THcDriftChamberPlane.cxx |  8 +++++++-
 src/THcDriftChamberPlane.h   |  4 ++--
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/THcDC.cxx b/src/THcDC.cxx
index 0b56793..dc8003b 100644
--- a/src/THcDC.cxx
+++ b/src/THcDC.cxx
@@ -217,6 +217,9 @@ THaAnalysisObject::EStatus THcDC::Init( const TDatime& date )
   }
 
   fResiduals = new Double_t [fNPlanes];
+  fWire_hit_did = new Double_t [fNPlanes];
+  fWire_hit_should = new Double_t [fNPlanes];
+
 
   // Replace with what we need for Hall C
   //  const DataDest tmp[NDEST] = {
@@ -345,6 +348,8 @@ Int_t THcDC::DefineVariables( EMode mode )
     { "xp_fp", "XP at focal plane (best chi2 track)", "fXp_fp_best"},
     { "yp_fp", "YP at focal plane(best chi2 track) ", "fYp_fp_best"},
     { "residual", "Residuals", "fResiduals"},
+    { "wireHitDid","Wire did have  matched track hit", "fWire_hit_did"},
+    { "wireHitShould", "Wire should have matched track hit", "fWire_hit_should"},
     { 0 }
   };
   return DefineVarsFromList( vars, mode );
@@ -426,6 +431,8 @@ void THcDC::ClearEvent()
 
   for(Int_t i=0;i<fNPlanes;i++) {
     fResiduals[i] = 1000.0;
+    fWire_hit_did[i] = 1000.0;
+    fWire_hit_should[i] = 1000.0;
   }
 
   //  fTrackProj->Clear();
@@ -561,6 +568,26 @@ void THcDC::SetFocalPlaneBestTrack(Int_t golden_track_index)
 	Int_t plane = hit->GetPlaneNum() - 1;
         fResiduals[plane] = tr1->GetResidual(plane);
 	 } 
+	 EfficiencyPerWire(golden_track_index);
+}
+//
+void THcDC::EfficiencyPerWire(Int_t golden_track_index)
+{
+      THcDCTrack *tr1 = static_cast<THcDCTrack*>( fDCTracks->At(golden_track_index));
+      Double_t track_pos;
+      for (UInt_t ihit = 0; ihit < UInt_t (tr1->GetNHits()); ihit++) {
+	THcDCHit *hit = tr1->GetHit(ihit);
+	Int_t plane = hit->GetPlaneNum() - 1;
+	track_pos=tr1->GetCoord(plane);
+	Int_t wire_num = hit->GetWireNum();
+	Int_t wire_track_num=round(fPlanes[plane]->CalcWireFromPos(track_pos));
+        if ( (wire_num-wire_track_num) ==0) fWire_hit_did[plane]=wire_num;
+      } 
+      for(Int_t ip=0; ip<fNPlanes;ip++) {
+	track_pos=tr1->GetCoord(ip);
+	Int_t wire_should = round(fPlanes[ip]->CalcWireFromPos(track_pos));
+        fWire_hit_should[ip]=wire_should;
+      }
 }
 //
 void THcDC::PrintSpacePoints()
diff --git a/src/THcDC.h b/src/THcDC.h
index 3398af8..5bea4f0 100644
--- a/src/THcDC.h
+++ b/src/THcDC.h
@@ -110,6 +110,8 @@ protected:
   Int_t fN_True_RawHits;
   Int_t fNSp;                   // Number of space points
   Double_t* fResiduals;         //[fNPlanes] Array of residuals
+  Double_t* fWire_hit_did;      //[fNPlanes]
+  Double_t* fWire_hit_should;   //[fNPlanes]
 
   Double_t fNSperChan;		/* TDC bin size */
   Double_t fWireVelocity;
@@ -183,7 +185,7 @@ protected:
   void Setup(const char* name, const char* description);
   void PrintSpacePoints();
   void PrintStubs();
-
+  void EfficiencyPerWire(Int_t golden_track_index);
   ClassDef(THcDC,0)   // Set of Drift Chambers detector
 };
 
diff --git a/src/THcDriftChamberPlane.cxx b/src/THcDriftChamberPlane.cxx
index 28c4ddf..e69bf13 100644
--- a/src/THcDriftChamberPlane.cxx
+++ b/src/THcDriftChamberPlane.cxx
@@ -299,7 +299,13 @@ Int_t THcDriftChamberPlane::CoarseProcess( TClonesArray& tracks )
 
  return 0;
 }
-
+//
+Double_t THcDriftChamberPlane::CalcWireFromPos(Double_t pos) {
+  Double_t wire_num_calc=-1000;
+  if (fWireOrder==0) wire_num_calc = (pos+fCenter)/(fPitch)+fCentralWire;
+  if (fWireOrder==1) wire_num_calc = 1-((pos+fCenter)/(fPitch)+fCentralWire-fNWires);
+  return(wire_num_calc);
+}
 //_____________________________________________________________________________
 Int_t THcDriftChamberPlane::FineProcess( TClonesArray& tracks )
 {
diff --git a/src/THcDriftChamberPlane.h b/src/THcDriftChamberPlane.h
index 78b9b22..805ecce 100644
--- a/src/THcDriftChamberPlane.h
+++ b/src/THcDriftChamberPlane.h
@@ -67,8 +67,8 @@ public:
   Double_t     GetPsi0() { return fPsi0; }
   Double_t*    GetStubCoef() { return fStubCoef; }
   Double_t*    GetPlaneCoef() { return fPlaneCoef; }
-
   THcDriftChamberPlane(); // for ROOT I/O
+  Double_t     CalcWireFromPos(Double_t pos);
 protected:
 
   TClonesArray* fParentHitList;
@@ -76,13 +76,13 @@ protected:
   TClonesArray* fHits;
   TClonesArray* fWires;
 
+  Int_t fWireOrder;
   Int_t fPlaneNum;
   Int_t fPlaneIndex;		/* Index of this plane within it's chamber */
   Int_t fChamberNum;
   Int_t fUsingTzeroPerWire;
   Int_t fNRawhits;
   Int_t fNWires;
-  Int_t fWireOrder;
   Int_t fTdcWinMin;
   Int_t fTdcWinMax;
   Double_t fPitch;
-- 
GitLab