From 6bd30070291ba44532aabc57e76006bfed4c020a Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Mon, 19 Aug 2013 16:58:01 -0400
Subject: [PATCH] Put residuals in an RVarDef and make a script to histogram
 them.

---
 examples/dcresiduals.C | 33 +++++++++++++++++++++++++++++++++
 src/THcDC.cxx          | 13 ++++++++++++-
 src/THcDC.h            | 11 ++++++-----
 3 files changed, 51 insertions(+), 6 deletions(-)
 create mode 100644 examples/dcresiduals.C

diff --git a/examples/dcresiduals.C b/examples/dcresiduals.C
new file mode 100644
index 0000000..a5759b9
--- /dev/null
+++ b/examples/dcresiduals.C
@@ -0,0 +1,33 @@
+{
+  TFile* f = new TFile("hodtest.root");
+  TTree *T=(TTree*)f->Get("T");
+  TCanvas *c1 = new TCanvas("c1", "Drift Chamber Residuals", 800, 1000); 
+  c1->Divide(2,6);
+
+  TH1F* h=new TH1F("h", "Residual", 100, -1.0, 1.0);
+
+  c1->cd(1);
+  T->Draw("H.dc.residual[0]","H.dc.residual[0] < 999");
+  c1->cd(2);
+  T->Draw("H.dc.residual[1]","H.dc.residual[1] < 999");
+  c1->cd(3);
+  T->Draw("H.dc.residual[2]","H.dc.residual[2] < 999");
+  c1->cd(4);
+  T->Draw("H.dc.residual[3]","H.dc.residual[3] < 999");
+  c1->cd(5);
+  T->Draw("H.dc.residual[4]","H.dc.residual[4] < 999");
+  c1->cd(6);
+  T->Draw("H.dc.residual[5]","H.dc.residual[5] < 999");
+  c1->cd(7);
+  T->Draw("H.dc.residual[6]","H.dc.residual[6] < 999");
+  c1->cd(8);
+  T->Draw("H.dc.residual[7]","H.dc.residual[7] < 999");
+  c1->cd(9);
+  T->Draw("H.dc.residual[8]","H.dc.residual[8] < 999");
+  c1->cd(10);
+  T->Draw("H.dc.residual[9]","H.dc.residual[9] < 999");
+  c1->cd(11);
+  T->Draw("H.dc.residual[10]","H.dc.residual[10] < 999");
+  c1->cd(12);
+  T->Draw("H.dc.residual[11]","H.dc.residual[11] < 999");
+}
diff --git a/src/THcDC.cxx b/src/THcDC.cxx
index fc4b46a..9db5723 100644
--- a/src/THcDC.cxx
+++ b/src/THcDC.cxx
@@ -191,6 +191,8 @@ THaAnalysisObject::EStatus THcDC::Init( const TDatime& date )
     fPlaneCoeffs[ip] = fPlanes[ip]->GetPlaneCoef();
   }
 
+  fResiduals = new Double_t [fNPlanes];
+
   // Replace with what we need for Hall C
   //  const DataDest tmp[NDEST] = {
   //    { &fRTNhit, &fRANhit, fRT, fRT_c, fRA, fRA_p, fRA_c, fROff, fRPed, fRGain },
@@ -333,7 +335,7 @@ Int_t THcDC::DefineVariables( EMode mode )
     { "y", "Y at focal plane", "fDCTracks.THcDCTrack.GetY()"},
     { "xp", "YP at focal plane", "fDCTracks.THcDCTrack.GetXP()"},
     { "yp", "YP at focal plane", "fDCTracks.THcDCTrack.GetYP()"},
-    { "p1residual", "Plane 1 Residual", "fDCTracks.THcDCTrack.GetResidual1()"},
+    { "residual", "Residuals", "fResiduals"},
     { 0 }
   };
   return DefineVarsFromList( vars, mode );
@@ -406,6 +408,9 @@ void THcDC::ClearEvent()
     fChambers[i]->Clear();
   }
 
+  for(Int_t i=0;i<fNPlanes;i++) {
+    fResiduals[i] = 1000.0;
+  }
   
   //  fTrackProj->Clear();
 }
@@ -859,6 +864,12 @@ void THcDC::TrackFit()
       }
     }
   }
+  if(fNDCTracks>0) {
+    for(Int_t ip=0;ip<fNPlanes;ip++) {
+      THcDCTrack *theDCTrack = static_cast<THcDCTrack*>( fDCTracks->At(0));
+      fResiduals[ip] = theDCTrack->GetResidual(ip);
+    }
+  }
   // print tracks if hdebugtrackprint is on
 }
 Double_t THcDC::DpsiFun(Double_t ray[4], Int_t plane)
diff --git a/src/THcDC.h b/src/THcDC.h
index 2f68470..097a68e 100644
--- a/src/THcDC.h
+++ b/src/THcDC.h
@@ -80,14 +80,15 @@ protected:
   TClonesArray* fDCTracks;     // Tracks found from stubs (THcDCTrack obj)
   // Calibration
 
+  // Hall C Parameters
+  Int_t fNPlanes;              // Total number of DC planes
+  char** fPlaneNames;
+  Int_t fNChambers;
+
   // Per-event data
   Int_t fNhits;
   Int_t ntracks_fp;		/* Change this to fN something */
-
-  // Potential Hall C parameters.  Mostly here for demonstration
-  Int_t fNPlanes;
-  char** fPlaneNames;
-  Int_t fNChambers;
+  Double_t* fResiduals;         //[fNPlanes] Array of residuals
 
   Double_t fNSperChan;		/* TDC bin size */
   Double_t fWireVelocity;
-- 
GitLab