From 49e63e9553d98b3aab92359821acda49ed899dea Mon Sep 17 00:00:00 2001
From: Vardan Tadevosyan <tadevosn@jlab.org>
Date: Thu, 26 Sep 2013 14:55:43 -0400
Subject: [PATCH] Added more calorimeter debug flags

---
 src/THcShower.cxx      | 100 ++++++++++++++++++++++++++---------------
 src/THcShower.h        |   8 +++-
 src/THcShowerPlane.cxx |  45 ++++++++++++++-----
 3 files changed, 104 insertions(+), 49 deletions(-)

diff --git a/src/THcShower.cxx b/src/THcShower.cxx
index 78c2fe9..5db0cc6 100644
--- a/src/THcShower.cxx
+++ b/src/THcShower.cxx
@@ -74,7 +74,9 @@ void THcShower::Setup(const char* name, const char* description)
   vector<string> layer_names = vsplit(layernamelist);
 
   if(layer_names.size() != (UInt_t) fNLayers) {
-    cout << "ERROR: Number of layers " << fNLayers << " doesn't agree with number of layer names " << layer_names.size() << endl;
+    cout << "ERROR: Number of layers " << fNLayers 
+	 << " doesn't agree with number of layer names "
+	 << layer_names.size() << endl;
     // Should quit.  Is there an official way to quit?
   }
 
@@ -167,7 +169,10 @@ Int_t THcShower::ReadDatabase( const TDatime& date )
       {"cal_slop", &fSlop, kDouble},
       {"cal_fv_test", &fvTest, kInt},
       {"cal_fv_delta", &fvDelta, kDouble},
+      {"dbg_decoded_cal", &fdbg_decoded_cal, kInt},
+      {"dbg_sparsified_cal", &fdbg_sparsified_cal, kInt},
       {"dbg_clusters_cal", &fdbg_clusters_cal, kInt},
+      {"dbg_tracks_cal", &fdbg_tracks_cal, kInt},
       {0}
     };
     gHcParms->LoadParmValues((DBRequest*)&list, prefix);
@@ -177,7 +182,10 @@ Int_t THcShower::ReadDatabase( const TDatime& date )
   cout << "Slop parameter              = " << fSlop << endl;
   cout << "Fiducial volume test flag   = " << fvTest << endl;
   cout << "Fiducial volume excl. width = " << fvDelta << endl;
+  cout << "Decode debug flag           = " << fdbg_decoded_cal  << endl;
+  cout << "Sparsify debug flag         = " << fdbg_sparsified_cal  << endl;
   cout << "Cluster debug flag          = " << fdbg_clusters_cal  << endl;
+  cout << "Tracking debug flag         = " << fdbg_tracks_cal  << endl;
 
   BlockThick = new Double_t [fNLayers];
   fNBlocks = new Int_t [fNLayers];
@@ -522,7 +530,9 @@ Int_t THcShower::Decode( const THaEvData& evdata )
     Int_t nexthit = 0;
     for(Int_t ip=0;ip<fNLayers;ip++) {
       nexthit = fPlanes[ip]->AccumulatePedestals(fRawHitList, nexthit);
-      //cout << "nexthit = " << nexthit << endl;
+      if (fdbg_decoded_cal) {
+	cout << "THcShower::Decode: nexthit = " << nexthit << endl;
+      }
     }
     fAnalyzePedestals = 1;	// Analyze pedestals first normal events
     return(0);
@@ -541,13 +551,16 @@ Int_t THcShower::Decode( const THaEvData& evdata )
   }
 
   //   fRawHitList is TClones array of THcRawShowerHit objects
-  //  cout << "THcShower::Decode: Shower raw hit list:" << endl;
-  //  for(Int_t ihit = 0; ihit < fNRawHits ; ihit++) {
-  //    THcRawShowerHit* hit = (THcRawShowerHit *) fRawHitList->At(ihit);
-  //    cout << ihit << " : " << hit->fPlane << ":" << hit->fCounter << " : "
-  //	 << hit->fADC_pos << " " << hit->fADC_neg << " "  << endl;
+
+  //  if (fdbg_decoded_cal) {
+  //    cout << "THcShower::Decode: Shower raw hit list:" << endl;
+  //    for(Int_t ihit = 0; ihit < fNRawHits ; ihit++) {
+  //      THcRawShowerHit* hit = (THcRawShowerHit *) fRawHitList->At(ihit);
+  //      cout << ihit << " : " << hit->fPlane << ":" << hit->fCounter << " : "
+  //	   << hit->fADC_pos << " " << hit->fADC_neg << " "  << endl;
+  //    }
+  //    cout << endl;
   //  }
-  //  cout << endl;
 
   return nhits;
 }
@@ -585,7 +598,7 @@ Int_t THcShower::CoarseProcess( TClonesArray& tracks)
   // Clustering of hits.
   //
 
-  THcShowerHitList HitList;                    //list of unclusterd hits
+  THcShowerHitList HitList;                    //list of unclustered hits
 
   for(Int_t j=0; j < fNLayers; j++) {
 
@@ -693,25 +706,31 @@ Int_t THcShower::CoarseProcess( TClonesArray& tracks)
   }
 
   if (fdbg_clusters_cal)
-    cout << fEpr << " " << fE << " " << fX << " PrSh" << endl;
+    cout << "Max.cluster: fEpr = " << fEpr << " fE = " << fE << " fX = " << fX
+	 << endl;
 
   // Track-to-cluster  matching.
   //
 
   Int_t Ntracks = tracks.GetLast()+1;   // Number of reconstructed tracks
 
-  cout << "Number of reconstructed tracks = " << Ntracks << endl;
+  if (fdbg_tracks_cal) {
+    cout << endl;
+    cout << "Number of reconstructed tracks = " << Ntracks << endl;
+  }
 
   for (Int_t i=0; i<Ntracks; i++) {
 
     THaTrack* theTrack = static_cast<THaTrack*>( tracks[i] );
 
-    //    cout << "   Track " << i << ": "
-    //	 << "  X = " << theTrack->GetX()
-    //	 << "  Y = " << theTrack->GetY()
-    //	 << "  Theta = " << theTrack->GetTheta()
-    //	 << "  Phi = " << theTrack->GetPhi()
-    //	 << endl;
+    if (fdbg_tracks_cal) {
+      cout << "   Track " << i << ": "
+	   << "  X = " << theTrack->GetX()
+	   << "  Y = " << theTrack->GetY()
+	   << "  Theta = " << theTrack->GetTheta()
+	   << "  Phi = " << theTrack->GetPhi()
+	   << endl;
+    }
 
     Double_t Xtr;
     Double_t Ytr;
@@ -730,7 +749,9 @@ Int_t THcShower::CoarseProcess( TClonesArray& tracks)
 
   }
 
-  cout << "   fTRX = " << fTRX << "  fTRY = " << fTRY << endl;
+  if (fdbg_tracks_cal)
+    cout << "1st track cluster:  fTRX = " << fTRX << "  fTRY = " << fTRY 
+	 << endl;
 
   if (fdbg_clusters_cal)
   cout << "THcShower::CoarseProcess return ---------------------------" <<endl;
@@ -746,12 +767,14 @@ Int_t THcShower::MatchCluster(THaTrack* Track,
 {
   // Match a cluster to a given track.
 
-  cout << "Track at DC:"
-       << "  X = " << Track->GetX()
-       << "  Y = " << Track->GetY()
-       << "  Theta = " << Track->GetTheta()
-       << "  Phi = " << Track->GetPhi()
-       << endl;
+  if (fdbg_tracks_cal) {
+    cout << "THcShower::MatchCluster: Track at DC:"
+	 << "  X = " << Track->GetX()
+	 << "  Y = " << Track->GetY()
+	 << "  Theta = " << Track->GetTheta()
+	 << "  Phi = " << Track->GetPhi()
+	 << endl;
+  }
 
   XTrFront = kBig;
   YTrFront = kBig;
@@ -769,11 +792,12 @@ Int_t THcShower::MatchCluster(THaTrack* Track,
   XTrFront += GetOrigin().X();
   YTrFront += GetOrigin().Y();
 
-  cout << "Track at the front of Calorimeter:"
-       << "  X = " << XTrFront
-       << "  Y = " << YTrFront
-       << "  Pathl = " << pathl
-       << endl;
+  if (fdbg_tracks_cal)
+    cout << "  Track at the front of Calorimeter:"
+	 << "  X = " << XTrFront
+	 << "  Y = " << YTrFront
+	 << "  Pathl = " << pathl
+	 << endl;
 
   Bool_t inFidVol = true;
 
@@ -789,18 +813,20 @@ Int_t THcShower::MatchCluster(THaTrack* Track,
     XTrBack += GetOrigin().X();
     YTrBack += GetOrigin().Y();
 
-    cout << "Track at the back of Calorimeter:"
-	 << "  X = " << XTrBack
-	 << "  Y = " << YTrBack
-	 << "  Pathl = " << pathl
-	 << endl;
+    if (fdbg_tracks_cal)
+      cout << "  Track at the back of Calorimeter:"
+	   << "  X = " << XTrBack
+	   << "  Y = " << YTrBack
+	   << "  Pathl = " << pathl
+	   << endl;
 
     inFidVol = (XTrFront < fvXmax) && (XTrFront > fvXmin) &&
                (YTrFront < fvYmax) && (YTrFront > fvYmin) &&
                (XTrBack < fvXmax) && (XTrBack > fvXmin) &&
                (YTrBack < fvYmax) && (YTrBack > fvYmin);
 
-    cout << "Fiducial volume test: inFidVol = " << inFidVol << endl;
+    if (fdbg_tracks_cal) 
+      cout << "  Fiducial volume test: inFidVol = " << inFidVol << endl;
   }
 
   // Match a cluster to the track.
@@ -826,7 +852,9 @@ Int_t THcShower::MatchCluster(THaTrack* Track,
     }
   }
 
-  cout << "MatchCluster: mclust= " << mclust << "  delatX= " << deltaX << endl;
+  if (fdbg_tracks_cal)
+    cout << "MatchCluster: mclust= " << mclust << "  delatX= " << deltaX 
+	 << endl;
 
   return mclust;
 }
diff --git a/src/THcShower.h b/src/THcShower.h
index 14ca900..76ae8fd 100644
--- a/src/THcShower.h
+++ b/src/THcShower.h
@@ -135,7 +135,11 @@ public:
   Double_t fvYmin;
   Double_t fvYmax;
 
-  Int_t fdbg_clusters_cal;      // Shower debug flag
+
+  Int_t fdbg_decoded_cal;      // Shower debug flags
+  Int_t fdbg_sparsified_cal;
+  Int_t fdbg_clusters_cal;
+  Int_t fdbg_tracks_cal;
 
   THcShowerPlane** fPlanes;     // [fNLayers] Shower Plane objects
 
@@ -150,6 +154,8 @@ public:
 
   Int_t MatchCluster(THaTrack*, THcShowerClusterList*, Double_t&, Double_t&);
 
+  friend class THcShowerPlane;
+
   ClassDef(THcShower,0)         // Generic class
 };
 
diff --git a/src/THcShowerPlane.cxx b/src/THcShowerPlane.cxx
index 66cec1e..509ff3a 100644
--- a/src/THcShowerPlane.cxx
+++ b/src/THcShowerPlane.cxx
@@ -240,13 +240,15 @@ Int_t THcShowerPlane::CoarseProcess( TClonesArray& tracks )
  
   //  HitCount();
 
+  /*
+    if (THcShower::fdbg_tracks_cal)
   cout << "THcShowerPlane::CoarseProcess called ---------------------" << endl;
 
   Int_t Ntracks = tracks.GetLast()+1;   // Number of reconstructed tracks
 
+  if (THcShower::fdbg_tracks_cal)
   cout << "   Number of reconstructed tracks = " << Ntracks << endl;
 
-  /*
   for (Int_t i=0; i<Ntracks; i++) {
 
     THaTrack* theTrack = static_cast<THaTrack*>( tracks[i] );
@@ -273,6 +275,12 @@ Int_t THcShowerPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
   // Assumes that the hit list is sorted by layer, so we stop when the
   // plane doesn't agree and return the index for the next hit.
 
+  THcShower* fParent;
+  fParent = (THcShower*) GetParent();
+
+  if (fParent->fdbg_decoded_cal)
+    cout << "THcShowerPlane::ProcessHits called ----" << endl;
+
   Int_t nPosADCHits=0;
   Int_t nNegADCHits=0;
   fPosADCHits->Clear();
@@ -293,12 +301,19 @@ Int_t THcShowerPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
   Int_t nrawhits = rawhits->GetLast()+1;
 
   Int_t ihit = nexthit;
-  //cout << "nrawhits =  " << nrawhits << endl;
-  //cout << "nexthit =  " << nexthit << endl;
+
+  if (fParent->fdbg_decoded_cal)
+ {
+    cout << "   nrawhits =  " << nrawhits << endl;
+    cout << "   nexthit =  " << nexthit << endl;
+  }
+
   while(ihit < nrawhits) {
     THcRawShowerHit* hit = (THcRawShowerHit *) rawhits->At(ihit);
 
-    //cout << "fplane =  " << hit->fPlane << " Num = " << fLayerNum << endl;
+    if (fParent->fdbg_decoded_cal)
+      cout << "   fplane =  " << hit->fPlane << " Num = " << fLayerNum << endl;
+
     if(hit->fPlane > fLayerNum) {
       break;
     }
@@ -310,13 +325,11 @@ Int_t THcShowerPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
     fA_Pos_p[hit->fCounter-1] = hit->fADC_pos - fPosPed[hit->fCounter -1];
     fA_Neg_p[hit->fCounter-1] = hit->fADC_neg - fNegPed[hit->fCounter -1];
 
-    THcShower* fParent;
-    fParent = (THcShower*) GetParent();
-
     Double_t thresh_pos = fPosThresh[hit->fCounter -1];
     if(hit->fADC_pos >  thresh_pos) {
 
-      THcSignalHit *sighit = (THcSignalHit*) fPosADCHits->ConstructedAt(nPosADCHits++);
+      THcSignalHit *sighit =
+	(THcSignalHit*) fPosADCHits->ConstructedAt(nPosADCHits++);
       sighit->Set(hit->fCounter, hit->fADC_pos);
 
       fEpos[hit->fCounter-1] += fA_Pos_p[hit->fCounter-1]*
@@ -326,7 +339,8 @@ Int_t THcShowerPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
     Double_t thresh_neg = fNegThresh[hit->fCounter -1];
     if(hit->fADC_neg >  thresh_neg) {
 
-      THcSignalHit *sighit = (THcSignalHit*) fNegADCHits->ConstructedAt(nNegADCHits++);
+      THcSignalHit *sighit = 
+	(THcSignalHit*) fNegADCHits->ConstructedAt(nNegADCHits++);
       sighit->Set(hit->fCounter, hit->fADC_neg);
 
       fEneg[hit->fCounter-1] += fA_Neg_p[hit->fCounter-1]*
@@ -338,6 +352,10 @@ Int_t THcShowerPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
 
     ihit++;
   }
+
+  if (fParent->fdbg_decoded_cal) 
+    cout << "THcShowerPlane::ProcessHits return ----" << endl;
+
   return(ihit);
 }
 
@@ -348,7 +366,10 @@ Int_t THcShowerPlane::AccumulatePedestals(TClonesArray* rawhits, Int_t nexthit)
   // arrays for calculating pedestals.
 
   Int_t nrawhits = rawhits->GetLast()+1;
-  //  cout << "THcScintillatorPlane::AcculatePedestals " << fLayerNum << " " << nexthit << "/" << nrawhits << endl;
+
+  //  cout << "THcScintillatorPlane::AcculatePedestals " << fLayerNum << " " 
+  //  << nexthit << "/" << nrawhits << endl;
+
   Int_t ihit = nexthit;
   while(ihit < nrawhits) {
     THcRawShowerHit* hit = (THcRawShowerHit *) rawhits->At(ihit);
@@ -404,8 +425,8 @@ void THcShowerPlane::CalculatePedestals( )
 		      - fNegPed[i]*fNegPed[i]);
     fNegThresh[i] = fNegPed[i] + TMath::Min(50., TMath::Max(10., 3.*fNegSig[i]));
 
-    cout << "Ped&Thr: " << fPosPed[i] << " " << fPosThresh[i] << " " <<
-      fNegPed[i] << " " << fNegThresh[i] << " " << i+1 << endl;
+    //    cout << "Ped&Thr: " << fPosPed[i] << " " << fPosThresh[i] << " " <<
+    //      fNegPed[i] << " " << fNegThresh[i] << " " << i+1 << endl;
   }
   //  cout << " " << endl;
   
-- 
GitLab