From d496e1e35838befae2b0e5167fcef2ac513f2790 Mon Sep 17 00:00:00 2001
From: Jonathan Stelzleni <jon@ifarm1101.jlab.org>
Date: Wed, 30 Jul 2014 10:03:37 -0400
Subject: [PATCH] Created two new variables for THcDC, fNthits and
 fN_True_RawHits. In tree they are called tnhit and trawhit. Created two new
 variables for THcDriftChamber, fNthits and fN_True_RawHits. In tree they are
 called tnhit and trawhit. THcDC defined subdetector THcDriftChamber to have
 name Ch1 and Ch2 to do used in the tree. THcDriftChamberPlane defined new
 method GetNRawhits to return fNRawhits for each plane. Added member fNRawhits
 to THcDriftChamberPlane

---
 src/THcDC.cxx                | 20 +++++++++++++++-----
 src/THcDC.h                  |  2 ++
 src/THcDriftChamber.cxx      | 13 +++++++------
 src/THcDriftChamber.h        |  2 ++
 src/THcDriftChamberPlane.cxx |  3 ++-
 src/THcDriftChamberPlane.h   |  2 ++
 6 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/src/THcDC.cxx b/src/THcDC.cxx
index fceb359..02c8646 100644
--- a/src/THcDC.cxx
+++ b/src/THcDC.cxx
@@ -124,6 +124,7 @@ void THcDC::Setup(const char* name, const char* description)
   }
 
   char *desc = new char[strlen(description)+100];
+  char *desc1= new char[strlen(description)+100];
   fPlanes.clear();
 
   for(Int_t i=0;i<fNPlanes;i++) {
@@ -145,12 +146,12 @@ void THcDC::Setup(const char* name, const char* description)
 
   fChambers.clear();
   for(Int_t i=0;i<fNChambers;i++) {
-    sprintf(desc,"%s Chamber %d",description, i+1);
+    sprintf(desc1,"Ch%d",i+1);
 
     // Should construct a better chamber name
-    THcDriftChamber* newchamber = new THcDriftChamber(desc, desc, i+1, this);
+    THcDriftChamber* newchamber = new THcDriftChamber(desc1, desc, i+1, this);
     fChambers.push_back(newchamber);
-    cout << "Created Drift Chamber " << i+1 << ", " << desc << endl;
+    cout << "Created Drift Chamber " << i+1 << ", " << desc1 << endl;
     newchamber->SetHMSStyleFlag(fHMSStyleChambers); // Tell the chamber its style
   }
 }
@@ -339,6 +340,8 @@ Int_t THcDC::DefineVariables( EMode mode )
 
   RVarDef vars[] = {
     { "nhit", "Number of DC hits",  "fNhits" },
+    { "tnhit", "Number of good DC hits",  "fNthits" },
+    { "trawhit", "Number of true raw DC hits", "fN_True_RawHits" },
     { "ntrack", "Number of Tracks", "fNDCTracks" },
     { "nsp", "Number of Space Points", "fNSp" },
     { "x", "X at focal plane", "fDCTracks.THcDCTrack.GetX()"},
@@ -409,6 +412,8 @@ void THcDC::ClearEvent()
 {
   // Reset per-event data.
   fNhits = 0;
+  fNthits = 0;
+  fN_True_RawHits=0;
 
   for(Int_t i=0;i<fNChambers;i++) {
     fChambers[i]->Clear();
@@ -435,20 +440,25 @@ Int_t THcDC::Decode( const THaEvData& evdata )
   Int_t nexthit = 0;
   for(Int_t ip=0;ip<fNPlanes;ip++) {
     nexthit = fPlanes[ip]->ProcessHits(fRawHitList, nexthit);
+    fN_True_RawHits += fPlanes[ip]->GetNRawhits();
+      
   }
 
   // Let each chamber get its hits
   for(Int_t ic=0;ic<fNChambers;ic++) {
     fChambers[ic]->ProcessHits();
+    fNthits += fChambers[ic]->GetNHits();
   }
   // fRawHitList is TClones array of THcRawDCHit objects
+  Int_t counter=0;
   if (fdebugprintrawdc) {
     cout << " RAW_TOT_HITS = " <<  fNRawHits << endl;
     cout << " Hit #  " << "Plane  " << " Wire " <<  " Raw TDC " << endl; 
     for(Int_t ihit = 0; ihit < fNRawHits ; ihit++) {
     THcRawDCHit* hit = (THcRawDCHit *) fRawHitList->At(ihit);
-      for(Int_t imhit = 0; imhit < hit->fNHits; imhit++) {
-    cout << ihit+imhit+1 << "      " << hit->fPlane << "     " << hit->fCounter << "     " << hit->fTDC[imhit]	   << endl;
+    for(Int_t imhit = 0; imhit < hit->fNHits; imhit++) {
+      counter++;
+      cout << counter << "      " << hit->fPlane << "     " << hit->fCounter << "     " << hit->fTDC[imhit]	   << endl;
       }
   }
     cout << endl;
diff --git a/src/THcDC.h b/src/THcDC.h
index 703f84d..2aa47cb 100644
--- a/src/THcDC.h
+++ b/src/THcDC.h
@@ -104,6 +104,8 @@ protected:
 
   // Per-event data
   Int_t fNhits;
+  Int_t fNthits;
+  Int_t fN_True_RawHits;
   Int_t fNSp;                   // Number of space points
   Double_t* fResiduals;         //[fNPlanes] Array of residuals
 
diff --git a/src/THcDriftChamber.cxx b/src/THcDriftChamber.cxx
index c1fc995..2dc7b06 100644
--- a/src/THcDriftChamber.cxx
+++ b/src/THcDriftChamber.cxx
@@ -221,12 +221,13 @@ Int_t THcDriftChamber::DefineVariables( EMode mode )
   fIsSetup = ( mode == kDefine );
   // Register variables in global list
 
-  //  RVarDef vars[] = {
-  //    { "nhit", "Number of DC hits",  "fNhits" },
-  //    { 0 }
-  //  };
-  //  return DefineVarsFromList( vars, mode );
-  return kOK;
+   RVarDef vars[] = {
+     { "nhit", "Number of DC hits",  "fNhits" },
+     { "trawhit", "Number of True Raw hits", "fN_True_RawHits" },
+     { 0 }
+   };
+   return DefineVarsFromList( vars, mode );
+  //return kOK;
 
 }
 void THcDriftChamber::ProcessHits( void)
diff --git a/src/THcDriftChamber.h b/src/THcDriftChamber.h
index a788446..0fc6116 100644
--- a/src/THcDriftChamber.h
+++ b/src/THcDriftChamber.h
@@ -63,6 +63,8 @@ protected:
 
   // Per-event data
   Int_t fNhits;
+  Int_t fNthits;
+  Int_t fN_True_RawHits;
 
   Int_t fNPlanes;		// Number of planes in the chamber
 
diff --git a/src/THcDriftChamberPlane.cxx b/src/THcDriftChamberPlane.cxx
index a4be700..ec36cf9 100644
--- a/src/THcDriftChamberPlane.cxx
+++ b/src/THcDriftChamberPlane.cxx
@@ -290,7 +290,7 @@ Int_t THcDriftChamberPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
 
   Int_t nrawhits = rawhits->GetLast()+1;
   // cout << "THcDriftChamberPlane::ProcessHits " << fPlaneNum << " " << nexthit << "/" << nrawhits << endl;
-
+  fNRawhits=0;
   Int_t ihit = nexthit;
   Int_t nextHit = 0;
   while(ihit < nrawhits) {
@@ -302,6 +302,7 @@ Int_t THcDriftChamberPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
     THcDCWire* wire = GetWire(wireNum);
     Int_t wire_last = -1;
     for(Int_t mhit=0; mhit<hit->fNHits; mhit++) {
+      fNRawhits++;
       /* Sort into early, late and ontime */
       Int_t rawtdc = hit->fTDC[mhit];
       if(rawtdc < fTdcWinMin) {
diff --git a/src/THcDriftChamberPlane.h b/src/THcDriftChamberPlane.h
index b7aac91..95c793c 100644
--- a/src/THcDriftChamberPlane.h
+++ b/src/THcDriftChamberPlane.h
@@ -49,6 +49,7 @@ public:
     return (THcDCWire*)fWires->UncheckedAt(i-1); }
 
   Int_t         GetNHits() const { return fHits->GetLast()+1; }
+  Int_t         GetNRawhits() const {return fNRawhits; }
   TClonesArray* GetHits()  const { return fHits; }
 
   Int_t        GetPlaneNum() const { return fPlaneNum; }
@@ -78,6 +79,7 @@ protected:
   Int_t fPlaneNum;
   Int_t fPlaneIndex;		/* Index of this plane within it's chamber */
   Int_t fChamberNum;
+  Int_t fNRawhits;
   Int_t fNWires;
   Int_t fWireOrder;
   Int_t fTdcWinMin;
-- 
GitLab