Skip to content

Commit

Permalink
Improved & consistent debug output from standard detector classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hansenjo committed Jan 10, 2018
1 parent 1a06df8 commit 0bfcc11
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 47 deletions.
9 changes: 4 additions & 5 deletions OldVDC/OldVDCPlane.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,10 @@ Int_t OldVDCPlane::DoReadDatabase( FILE* file, const TDatime& date )
{ "Number of wires", &fNelem, kInt },
{ "Detector position", pos, kDouble, 3 },
{ "Detector size", fSize, kFloat, 3 },
{ "Wire angle (deg)", &angle, },
{ "Wire start pos (m)", &fWBeg, },
{ "Wire spacing (m)", &fWSpac, },
{ "Wire angle (deg)", &angle, },
{ "TDC resolution (s/chan)", &fTDCRes, },
{ "Wire angle (deg)", &angle },
{ "Wire start pos (m)", &fWBeg },
{ "Wire spacing (m)", &fWSpac },
{ "TDC resolution (s/chan)", &fTDCRes },
{ "Drift Velocity (m/s) ", &fDriftVel },
{ "Max gap in cluster", &fNMaxGap, kInt },
{ "Min TDC raw time", &fMinTime, kInt },
Expand Down
24 changes: 23 additions & 1 deletion src/THaAnalysisObject.C
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,8 @@ vector<string> THaAnalysisObject::vsplit(const string& s)
return ret;
}

//-----------------------------------------------------------------------------
#ifdef WITH_DEBUG
//_____________________________________________________________________________
void THaAnalysisObject::DebugPrint( const DBRequest* list )
{
// Print values of database parameters given in 'list'
Expand All @@ -1792,6 +1793,8 @@ void THaAnalysisObject::DebugPrint( const DBRequest* list )
cout << " " << std::left << setw(maxw) << it->name;
UInt_t maxc = it->nelem;
if( maxc == 0 ) maxc = 1;
if( it->type == kDoubleV )
maxc = static_cast<UInt_t>( ((vector<Double_t>*)it->var)->size() );
for (UInt_t i=0; i<maxc; i++) {
cout << " ";
switch( it->type ) {
Expand All @@ -1804,6 +1807,8 @@ void THaAnalysisObject::DebugPrint( const DBRequest* list )
case kInt:
cout << ((Int_t*)it->var)[i];
break;
case kDoubleV:
cout << ((vector<Double_t>*)it->var)->at(i);
default:
break;
}
Expand All @@ -1812,6 +1817,23 @@ void THaAnalysisObject::DebugPrint( const DBRequest* list )
}
}

//_____________________________________________________________________________
template <typename T>
void THaAnalysisObject::WriteValue( T val, int p, int w )
{
// Helper function for printing debug information
if( val < kBig )
cout << fixed << setprecision(p) << setw(w) << val;
else
cout << " --- ";
}

// Explicit instantiations
template void THaAnalysisObject::WriteValue<Double_t>( Double_t val, int p=0, int w=5 );
template void THaAnalysisObject::WriteValue<Float_t>( Float_t val, int p=0, int w=5 );

#endif

//_____________________________________________________________________________
TString& THaAnalysisObject::GetObjArrayString( const TObjArray* array, Int_t i )
{
Expand Down
9 changes: 7 additions & 2 deletions src/THaAnalysisObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <vector>
#include <string>
#include <cstdio>
#include <stdarg.h>
//#include <stdarg.h>

class THaEvData; //needed by derived classes
class TList;
Expand Down Expand Up @@ -180,7 +180,12 @@ class THaAnalysisObject : public TNamed {

static char* ReadComment( FILE* fp, char* buf, const int len );

void DebugPrint( const DBRequest* list );
#ifdef WITH_DEBUG
void DebugPrint( const DBRequest* list );

template <typename T> // available for double and float
static void WriteValue( T val, int p=0, int w=5 );
#endif

// Only derived classes may construct
THaAnalysisObject( const char* name, const char* description );
Expand Down
40 changes: 33 additions & 7 deletions src/THaCherenkov.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cassert>
#include <iostream>
#include <iomanip>

using namespace std;

Expand Down Expand Up @@ -151,6 +152,25 @@ Int_t THaCherenkov::ReadDatabase( const TDatime& date )
if( err )
return err;

#ifdef WITH_DEBUG
// Debug printout
if ( fDebug > 2 ) {
const UInt_t N = static_cast<UInt_t>(fNelem);
Double_t pos[3]; fOrigin.GetXYZ(pos);
DBRequest list[] = {
{ "Number of mirrors", &fNelem, kInt },
{ "Detector position", pos, kDouble, 3 },
{ "Detector size", fSize, kDouble, 3 },
{ "Detector angle", &angle },
{ "TDC offsets", fOff, kFloat, N },
{ "ADC pedestals", fPed, kFloat, N },
{ "ADC gains", fGain, kFloat, N },
{ 0 }
};
DebugPrint( list );
}
#endif

return kOK;
}

Expand Down Expand Up @@ -272,27 +292,33 @@ Int_t THaCherenkov::Decode( const THaEvData& evdata )
}
}

#ifdef WITH_DEBUG
if ( fDebug > 3 ) {
printf("\nCherenkov %s:\n",GetPrefix());
cout << endl << "Cherenkov " << GetPrefix() << ":" << endl;
int ncol=3;
for (int i=0; i<ncol; i++) {
printf(" Mirror TDC ADC ADC_p ");
cout << " Mirror TDC ADC ADC_p ";
}
printf("\n");
cout << endl;

for (int i=0; i<(fNelem+ncol-1)/ncol; i++ ) {
for (int c=0; c<ncol; c++) {
int ind = c*fNelem/ncol+i;
if (ind < fNelem) {
printf(" %3d %5.0f %5.0f %5.0f ",ind+1,fT[ind],fA[ind],fA_p[ind]);
cout << " " << setw(3) << ind+1;
cout << " "; WriteValue(fT[ind]);
cout << " "; WriteValue(fA[ind]);
cout << " "; WriteValue(fA_p[ind]);
cout << " ";
} else {
// printf("\n");
// cout << endl;
break;
}
}
printf("\n");
cout << endl;
}
}
#endif

return fNThit;
}
Expand Down
65 changes: 46 additions & 19 deletions src/THaScintillator.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "TMath.h"

#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cassert>
#include <iomanip>

using namespace std;

Expand Down Expand Up @@ -219,20 +219,35 @@ Int_t THaScintillator::ReadDatabase( const TDatime& date )
if( fResolution == kBig )
fResolution = fTdc2T;

// If doing debugging, print the calibration parameters we've just read
if ( fDebug > 1 ) {
cout << '\n' << GetPrefix() << " calibration parameters: " << endl;;
for ( DBRequest *li = calib_request; li->name; li++ ) {
cout << " " << li->name;
UInt_t maxc = li->nelem;
if (maxc==0)maxc=1;
for (UInt_t i=0; i<maxc; i++) {
if (li->type==kDouble) cout << " " << ((Double_t*)li->var)[i];
if (li->type==kInt) cout << " " << ((Int_t*)li->var)[i];
}
cout << endl;
}
#ifdef WITH_DEBUG
// Debug printout
if ( fDebug > 2 ) {
const UInt_t N = static_cast<UInt_t>(fNelem);
Double_t pos[3]; fOrigin.GetXYZ(pos);
DBRequest list[] = {
{ "Number of paddles", &fNelem, kInt },
{ "Detector position", pos, kDouble, 3 },
{ "Detector size", fSize, kDouble, 3 },
{ "Detector angle", &angle, },
{ "TDC offsets Left", fLOff, kDouble, N },
{ "TDC offsets Right", fROff, kDouble, N },
{ "ADC pedestals Left", fLPed, kDouble, N },
{ "ADC pedestals Right", fRPed, kDouble, N },
{ "ADC gains Left", fLGain, kDouble, N },
{ "ADC gains Right", fRGain, kDouble, N },
{ "TDC resolution", &fTdc2T },
{ "Light propag. speed", &fCn },
{ "ADC MIP", &fAdcMIP },
{ "Num timewalk params", &fNTWalkPar, kInt },
{ "Timewalk params", fTWalkPar, kDouble, 2*N },
{ "Trigger time offsets", fTrigOff, kDouble, N },
{ "Time resolution", &fResolution },
{ "Attenuation", &fAttenuation },
{ 0 }
};
DebugPrint( list );
}
#endif

return kOK;
}
Expand Down Expand Up @@ -400,15 +415,27 @@ Int_t THaScintillator::Decode( const THaEvData& evdata )
}
}
}

#ifdef WITH_DEBUG
if ( fDebug > 3 ) {
printf("\n\nEvent %d Trigger %d Scintillator %s\n:",
evdata.GetEvNum(), evdata.GetEvType(), GetPrefix() );
printf(" paddle Left(TDC ADC ADC_p) Right(TDC ADC ADC_p)\n");
cout << endl << endl;
cout << "Event " << evdata.GetEvNum() << " Trigger " << evdata.GetEvType()
<< " Scintillator " << GetPrefix() << endl;
cout << " paddle Left(TDC ADC ADC_p) Right(TDC ADC ADC_p)" << endl;
cout << right;
for ( int i=0; i<fNelem; i++ ) {
printf(" %2d %5.0f %5.0f %5.0f %5.0f %5.0f %5.0f\n",
i+1,fLT[i],fLA[i],fLA_p[i],fRT[i],fRA[i],fRA_p[i]);
cout << " " << setw(2) << i+1;
cout << " "; WriteValue(fLT[i]);
cout << " "; WriteValue(fLA[i]);
cout << " "; WriteValue(fLA_p[i]);
cout << " "; WriteValue(fRT[i]);
cout << " "; WriteValue(fRA[i]);
cout << " "; WriteValue(fRA_p[i]);
cout << endl;
}
cout << left;
}
#endif

return fLTNhit+fRTNhit;
}
Expand Down
39 changes: 33 additions & 6 deletions src/THaShower.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <cstring>
#include <iostream>
#include <iomanip>
#include <cassert>

using namespace std;
Expand Down Expand Up @@ -211,6 +212,29 @@ Int_t THaShower::ReadDatabase( const TDatime& date )
if( err )
return err;

#ifdef WITH_DEBUG
// Debug printout
if ( fDebug > 2 ) {
const UInt_t N = static_cast<UInt_t>(fNelem);
Double_t pos[3]; fOrigin.GetXYZ(pos);
DBRequest list[] = {
{ "Number of blocks", &fNelem, kInt },
{ "Detector center", pos, kDouble, 3 },
{ "Detector size", fSize, kDouble, 3 },
{ "Detector angle", &angle },
{ "Channel map", &chanmap[0], kInt, N },
{ "Position of block 1", &xy, kDoubleV },
{ "Block x/y spacings", &dxy, kDoubleV },
{ "Minimum cluster energy", &fEmin, kFloat, 1 },
{ "ADC pedestals", fPed, kFloat, N },
{ "ADC pedestals", fPed, kFloat, N },
{ "ADC gains", fGain, kFloat, N },
{ 0 }
};
DebugPrint( list );
}
#endif

return kOK;
}

Expand Down Expand Up @@ -348,24 +372,27 @@ Int_t THaShower::Decode( const THaEvData& evdata )

#ifdef WITH_DEBUG
if ( fDebug > 3 ) {
printf("\nShower Detector %s:\n",GetPrefix());
cout << endl << "Shower Detector " << GetPrefix() << ":" << endl;
int ncol=3;
for (int i=0; i<ncol; i++) {
printf(" Block ADC ADC_p ");
cout << " Block ADC ADC_p ";
}
printf("\n");
cout << endl;

for (int i=0; i<(fNelem+ncol-1)/ncol; i++ ) {
for (int c=0; c<ncol; c++) {
int ind = c*fNelem/ncol+i;
if (ind < fNelem) {
printf(" %3d %5.0f %5.0f ",ind+1,fA[ind],fA_p[ind]);
cout << " " << setw(3) << ind+1;
cout << " "; WriteValue(fA[ind]);
cout << " "; WriteValue(fA_p[ind]);
cout << " ";
} else {
// printf("\n");
// cout << endl;
break;
}
}
printf("\n");
cout << endl;
}
}
#endif
Expand Down
Loading

0 comments on commit 0bfcc11

Please sign in to comment.