Skip to content

Commit

Permalink
Set sign of correlation bewteen time and raw TDC data based on TDC mode
Browse files Browse the repository at this point in the history
Add TDC resolution parameter to THaCherenkov.

Historically, a negative TDC resolution has been set in the scintillator
database to indicate common stop TDC mode. The new code tries to be
backward compatible: If the TDC mode is not explicitly set (old database),
the sign of the TDC resolution is kept. If the mode is set, the TDC
resolution is taken as positive, and the sign is applied based on
the TDC mode.
  • Loading branch information
hansenjo committed Mar 8, 2018
1 parent 744cb11 commit 2cbd01b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 30 deletions.
43 changes: 30 additions & 13 deletions src/THaCherenkov.C
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ Int_t THaCherenkov::ReadDatabase( const TDatime& date )

vector<Int_t> detmap;
Int_t nelem;
Int_t tdc_mode = 0;
Int_t tdc_mode = -255; // indicates unset
fTdc2T = 0.5e-9; // TDC resolution (s/channel)

// Read configuration parameters
DBRequest config_request[] = {
{ "detmap", &detmap, kIntV },
{ "npmt", &nelem, kInt },
{ "tdc.res", &fTdc2T, kDouble, 0, 1 }, // optional to support old DBs
{ "tdc.cmnstart", &tdc_mode, kInt, 0, 1 },
{ 0 }
};
Expand Down Expand Up @@ -109,14 +111,26 @@ Int_t THaCherenkov::ReadDatabase( const TDatime& date )
"inconsistent with 2*number of PMTs (%d)", nelem, 2*fNelem );
err = kInitError;
}

// Set TDCs to common start mode, if set
if( tdc_mode != 0 ) {
Int_t nmodules = fDetMap->GetSize();
for( Int_t i = 0; i < nmodules; i++ ) {
THaDetMap::Module* d = fDetMap->GetModule(i);
if( d->IsTDC() )
d->SetTDCMode(tdc_mode);
if( tdc_mode != -255 ) {
// TDC mode was specified
if( tdc_mode != 0 ) {
// Database indicates common start mode
Int_t nmodules = fDetMap->GetSize();
for( Int_t i = 0; i < nmodules; i++ ) {
THaDetMap::Module* d = fDetMap->GetModule(i);
if( d->model ? d->IsTDC() : i>=nmodules/2 ) {
if( !d->model ) d->MakeTDC();
d->SetTDCMode(tdc_mode);
}
}
}
// If the TDC mode was set explicitly, assume that negative TDC
// resolutions are database errors
Warning( Here(here), "Negative TDC resolution = %lf converted to "
"positive since TDC mode explicitly set.", fTdc2T );
fTdc2T = TMath::Abs(fTdc2T);
}

if( err ) {
Expand Down Expand Up @@ -146,9 +160,6 @@ Int_t THaCherenkov::ReadDatabase( const TDatime& date )
// Read calibration parameters

// Set DEFAULT values here
// TDC resolution (s/channel)
// fTdc2T = 0.1e-9; // seconds/channel

// Default TDC offsets (0), ADC pedestals (0) and ADC gains (1)
memset( fOff, 0, nval*sizeof(fOff[0]) );
memset( fPed, 0, nval*sizeof(fPed[0]) );
Expand All @@ -160,7 +171,6 @@ Int_t THaCherenkov::ReadDatabase( const TDatime& date )
{ "tdc.offsets", fOff, kFloat, nval, 1 },
{ "adc.pedestals", fPed, kFloat, nval, 1 },
{ "adc.gains", fGain, kFloat, nval, 1 },
// { "tdc.res", &fTdc2T, kDouble },
{ 0 }
};
err = LoadDB( file, date, calib_request, fPrefix );
Expand Down Expand Up @@ -201,7 +211,7 @@ Int_t THaCherenkov::DefineVariables( EMode mode )
{ "nthit", "Number of PMTs with valid TDC", "fNThit" },
{ "nahit", "Number of PMTs with ADC signal", "fNAhit" },
{ "t", "Raw TDC values", "fT" },
{ "t_c", "Offset-corrected TDC values", "fT_c" },
{ "t_c", "Calibrated TDC times (s)", "fT_c" },
{ "a", "Raw ADC values", "fA" },
{ "a_p", "Pedestal-subtracted ADC values ", "fA_p" },
{ "a_c", "Gain-corrected ADC values", "fA_c" },
Expand Down Expand Up @@ -327,7 +337,14 @@ Int_t THaCherenkov::Decode( const THaEvData& evdata )
fNAhit++;
} else {
fT[k] = data;
fT_c[k] = data - fOff[k];
fT_c[k] = (data - fOff[k]) * fTdc2T;
if( fTdc2T > 0.0 && !not_common_stop_tdc ) {
// For common stop TDCs, time is negatively correlated to raw data
// time = (offset-data)*res, so reverse the sign.
// Assume that a negative TDC resolution indicates common stop mode
// as well, so the sign flip has already been applied.
fT_c[k] *= -1.0;
}
fNThit++;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/THaCherenkov.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class THaCherenkov : public THaPidDetector {

protected:

// Configuration
Double_t fTdc2T; // Conversion coefficient from raw TDC to time (s/ch)

// Calibration
Float_t* fOff; // [fNelem] TDC offsets (chan)
Float_t* fPed; // [fNelem] ADC pedestals (chan)
Expand Down
54 changes: 37 additions & 17 deletions src/THaScintillator.C
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ Int_t THaScintillator::ReadDatabase( const TDatime& date )

vector<Int_t> detmap;
Int_t nelem;
Int_t tdc_mode = 0;
Int_t tdc_mode = -255; // indicates unset
fTdc2T = 5e-10; // TDC resolution (s/channel), for reference, required anyway

// Read configuration parameters
DBRequest config_request[] = {
{ "detmap", &detmap, kIntV },
{ "npaddles", &nelem, kInt },
{ "tdc.res", &fTdc2T, kDouble },
{ "tdc.cmnstart", &tdc_mode, kInt, 0, 1 },
{ 0 }
};
Expand Down Expand Up @@ -130,14 +132,27 @@ Int_t THaScintillator::ReadDatabase( const TDatime& date )
"inconsistent with 4*number of paddles (%d)", nelem, 4*fNelem );
err = kInitError;
}

// Set TDCs to common start mode, if set
if( tdc_mode != 0 ) {
Int_t nmodules = fDetMap->GetSize();
for( Int_t i = 0; i < nmodules; i++ ) {
THaDetMap::Module* d = fDetMap->GetModule(i);
if( d->IsTDC() )
d->SetTDCMode(tdc_mode);
if( tdc_mode != -255 ) {
// TDC mode was specified
if( tdc_mode != 0 ) {
// Database indicates common start mode
Int_t nmodules = fDetMap->GetSize();
for( Int_t i = 0; i < nmodules; i++ ) {
THaDetMap::Module* d = fDetMap->GetModule(i);
if( d->model ? d->IsTDC() : i>=nmodules/2 ) {
if( !d->model ) d->MakeTDC();
d->SetTDCMode(tdc_mode);
}
}
}
// If the TDC mode was set explicitly, override negative TDC
// resolutions that historically have indicated the TDC mode
if( fDebug > 0 )
Warning( Here(here), "Negative TDC resolution = %lf converted to "
"positive since TDC mode explicitly set.", fTdc2T );
fTdc2T = TMath::Abs(fTdc2T);
}

if( err ) {
Expand Down Expand Up @@ -188,15 +203,13 @@ Int_t THaScintillator::ReadDatabase( const TDatime& date )
// Read calibration parameters

// Set DEFAULT values here
// TDC resolution (s/channel)
fTdc2T = 0.1e-9; // seconds/channel
fResolution = kBig; // actual timing resolution
// Speed of light in the scintillator material
fCn = 1.7e+8; // meters/second
fCn = 1.7e+8; // meters/second (for reference, required anyway)
// Attenuation length
fAttenuation = 0.7; // inverse meters
fAttenuation = 0.7; // inverse meters
// Time-walk correction parameters
fAdcMIP = 1.e10; // large number for offset, so reference is effectively disabled
fAdcMIP = 1.e10; // large number for offset, so reference is effectively disabled
// timewalk coefficients for tw = coeff*(1./sqrt(ADC-Ped)-1./sqrt(ADCMip))
memset( fTWalkPar, 0, nval_twalk*sizeof(fTWalkPar[0]) );
// trigger-timing offsets (s)
Expand All @@ -219,7 +232,6 @@ Int_t THaScintillator::ReadDatabase( const TDatime& date )
{ "R.ped", fRPed, kDouble, nval, 1 },
{ "L.gain", fLGain, kDouble, nval, 1 },
{ "R.gain", fRGain, kDouble, nval, 1 },
{ "tdc.res", &fTdc2T, kDouble },
{ "Cn", &fCn, kDouble },
{ "MIP", &fAdcMIP, kDouble, 0, 1 },
{ "timewalk_params", fTWalkPar, kDouble, nval_twalk, 1 },
Expand Down Expand Up @@ -284,14 +296,14 @@ Int_t THaScintillator::DefineVariables( EMode mode )
{ "nlahit", "Number of Left paddles ADCs amps", "fLANhit" },
{ "nrahit", "Number of Right paddles ADCs amps", "fRANhit" },
{ "lt", "TDC values left side", "fLT" },
{ "lt_c", "Corrected times left side", "fLT_c" },
{ "lt_c", "Calibrated times left side (s)", "fLT_c" },
{ "rt", "TDC values right side", "fRT" },
{ "rt_c", "Corrected times right side", "fRT_c" },
{ "rt_c", "Calibrated times right side (s)", "fRT_c" },
{ "la", "ADC values left side", "fLA" },
{ "la_p", "Corrected ADC values left side", "fLA_p" },
{ "la_p", "Ped-sub ADC values left side", "fLA_p" },
{ "la_c", "Corrected ADC values left side", "fLA_c" },
{ "ra", "ADC values right side", "fRA" },
{ "ra_p", "Corrected ADC values right side", "fRA_p" },
{ "ra_p", "Ped-sub ADC values right side", "fRA_p" },
{ "ra_c", "Corrected ADC values right side", "fRA_c" },
{ "nthit", "Number of paddles with l&r TDCs", "fNhit" },
{ "t_pads", "Paddles with l&r coincidence TDCs", "fHitPad" },
Expand Down Expand Up @@ -447,6 +459,14 @@ Int_t THaScintillator::Decode( const THaEvData& evdata )
} else {
dest->tdc[k] = static_cast<Double_t>( data );
dest->tdc_c[k] = (data - dest->offset[k])*fTdc2T;
if( fTdc2T > 0.0 && !not_common_stop_tdc ) {
// For common stop TDCs, time is negatively correlated to raw data
// time = (offset-data)*res, so reverse the sign.
// However, historically, people have been using negative TDC
// resolutions to indicate common stop mode, so in that case
// the sign flip has already been applied.
dest->tdc_c[k] *= -1.0;
}
(*dest->nthit)++;
}
}
Expand Down

0 comments on commit 2cbd01b

Please sign in to comment.