From cfc166a9df748012bb84f8c47a29da3cda94d63b Mon Sep 17 00:00:00 2001 From: David Adams Date: Tue, 9 May 2023 14:13:47 +0000 Subject: [PATCH] Add tool config crpChannelFemb with test. #28 --- dunedataprep/DataPrep/fcl/CMakeLists.txt | 1 + dunedataprep/DataPrep/fcl/test/CMakeLists.txt | 21 +++++ .../fcl/test/test_tool_crpChannelFemb | 61 +++++++++++++++ .../fcl/test/test_tool_crpChannelFemb.cxx | 73 ++++++++++++++++++ dunedataprep/DataPrep/fcl/vdcb2_tools.fcl | 76 ++++++++++++++++--- 5 files changed, 220 insertions(+), 12 deletions(-) create mode 100644 dunedataprep/DataPrep/fcl/test/CMakeLists.txt create mode 100755 dunedataprep/DataPrep/fcl/test/test_tool_crpChannelFemb create mode 100644 dunedataprep/DataPrep/fcl/test/test_tool_crpChannelFemb.cxx diff --git a/dunedataprep/DataPrep/fcl/CMakeLists.txt b/dunedataprep/DataPrep/fcl/CMakeLists.txt index d7c870ea..a25f48c4 100644 --- a/dunedataprep/DataPrep/fcl/CMakeLists.txt +++ b/dunedataprep/DataPrep/fcl/CMakeLists.txt @@ -4,3 +4,4 @@ # August 2016 install_fhicl() +add_subdirectory(test) diff --git a/dunedataprep/DataPrep/fcl/test/CMakeLists.txt b/dunedataprep/DataPrep/fcl/test/CMakeLists.txt new file mode 100644 index 00000000..9475b0bf --- /dev/null +++ b/dunedataprep/DataPrep/fcl/test/CMakeLists.txt @@ -0,0 +1,21 @@ +# dunedataprep/dunedataprep/DataPrep/fcl/test +# +# David Adams +# May 2023 + +#cet_test(test_tool_crpChannelFemb_root HANDBUILT TEST_EXEC root.exe DATAFILES test_tool_crpChannelFemb) + +cet_test(test_tool_crpChannelFemb + SOURCES + test_tool_crpChannelFemb.cxx + LIBRARIES + dunecore_ArtSupport + art::Utilities + canvas::canvas + fhiclcpp + cetlib::cetlib cetlib_except + cetlib_except::cetlib_except + SQLITE3 + Boost::filesystem + ROOT_BASIC_LIB_LIST +) diff --git a/dunedataprep/DataPrep/fcl/test/test_tool_crpChannelFemb b/dunedataprep/DataPrep/fcl/test/test_tool_crpChannelFemb new file mode 100755 index 00000000..7554d1ed --- /dev/null +++ b/dunedataprep/DataPrep/fcl/test/test_tool_crpChannelFemb @@ -0,0 +1,61 @@ +//usr/bin/env root.exe -l -q $0; exit $? + +// test_tool_crpChannelFemb +// +// David Adams +// May 2023 +// +// This is an example of a Root script that can be excuted directly +// from the command line. + +#include "dunecore/DuneInterface/Tool/IndexMapTool.h" +#include "dunecore/ArtSupport/DuneToolManager.h" + +using Index = unsigned int; + +int test_tool_crpChannelFemb() { + + string line = "-------------------------------------------------------"; + string fclnam = "vdcb2_tools.fcl"; + string tnam = "crpChannelFemb"; + cout << "Testing tool " << tnam << " in fcl file " << fclnam << endl; + + cout << line << endl; + cout << "Creating tool manager from fcl " << fclnam << endl; + DuneToolManager* ptm = DuneToolManager::instance(fclnam); + + cout << line << endl; + cout << "Fetching tool " << tnam << " from tool manager." << endl; + auto ptoo = ptm->getPrivate(tnam); + if ( ptoo == nullptr ) return 1; + + cout << line << endl; + cout << "Looping over channels." << endl; + Index nchan = 3072; + map fembChanCount; + Index fmin = 1; + Index fmax = 24; + for ( Index icha=0; ichaget(icha); + if ( fembChanCount.count(ifmb) == 0 ) { + cout << "Adding FEMB " << ifmb << endl; + fembChanCount[ifmb] = 0; + } + if ( ifmb < fmin ) return 2; + if ( ifmb > fmax ) return 3; + ++fembChanCount[ifmb]; + } + + cout << line << endl; + cout << "Checking FEMB channel counts." << endl; + for ( auto ent : fembChanCount ) { + Index ifmb = ent.first; + Index count = ent.second; + cout << "FEMB " << ifmb << " has " << count << " channels." << endl; + if ( count != 128 ) return 4; + } + + cout << line << endl; + cout << "All tests pass." << endl; + return 0; +} diff --git a/dunedataprep/DataPrep/fcl/test/test_tool_crpChannelFemb.cxx b/dunedataprep/DataPrep/fcl/test/test_tool_crpChannelFemb.cxx new file mode 100644 index 00000000..a5e45cde --- /dev/null +++ b/dunedataprep/DataPrep/fcl/test/test_tool_crpChannelFemb.cxx @@ -0,0 +1,73 @@ +// test_tool_crpChannelFemb.cxx + +// David Adams +// May 2023 +// +// Test for tool instance crpChannelFemb. + +#include "dunecore/DuneInterface/Tool/IndexMapTool.h" +#include "dunecore/ArtSupport/DuneToolManager.h" +#include +#include +#include + +using std::string; +using std::cout; +using std::endl; +using std::map; + +using Index = unsigned int; + +#undef NDEBUG +#include + +int test_tool_crpChannelFemb() { + + string line = "-------------------------------------------------------"; + string fclnam = "vdcb2_tools.fcl"; + string tnam = "crpChannelFemb"; + cout << "Testing tool " << tnam << " in fcl file " << fclnam << endl; + + cout << line << endl; + cout << "Creating tool manager from fcl " << fclnam << endl; + DuneToolManager* ptm = DuneToolManager::instance(fclnam); + + cout << line << endl; + cout << "Fetching tool " << tnam << " from tool manager." << endl; + auto ptoo = ptm->getPrivate(tnam); + assert( ptoo != nullptr ); + + cout << line << endl; + cout << "Looping over channels." << endl; + Index nchan = 3072; + map fembChanCount; + Index fmin = 1; + Index fmax = 24; + for ( Index icha=0; ichaget(icha); + if ( fembChanCount.count(ifmb) == 0 ) { + cout << "Adding FEMB " << ifmb << endl; + fembChanCount[ifmb] = 0; + } + assert( ifmb >= fmin ); + assert( ifmb <= fmax ); + ++fembChanCount[ifmb]; + } + + cout << line << endl; + cout << "Checking FEMB channel counts." << endl; + for ( auto ent : fembChanCount ) { + Index ifmb = ent.first; + Index count = ent.second; + cout << "FEMB " << ifmb << " has " << count << " channels." << endl; + assert( count == 128 ); + } + + cout << line << endl; + cout << "All tests pass." << endl; + return 0; +} + +int main() { + return test_tool_crpChannelFemb(); +} diff --git a/dunedataprep/DataPrep/fcl/vdcb2_tools.fcl b/dunedataprep/DataPrep/fcl/vdcb2_tools.fcl index 5921b686..07f69bfe 100644 --- a/dunedataprep/DataPrep/fcl/vdcb2_tools.fcl +++ b/dunedataprep/DataPrep/fcl/vdcb2_tools.fcl @@ -113,24 +113,54 @@ tools.onlineChannelMapVdcb: { tools.channelRanges: @local::tools.channelRangesVdcb2 tools.channelGroups: @local::tools.channelGroupsVdcb2 +# Return FEMB index (1-16) for a bottom offline relative channel (0-3071). +# See https://github.com/DUNE/dunedataprep/issues/28 +tools.crpChannelFemb: { + tool_type: TextIndexMapTool + LogLevel: 1 + FileName: "$DUNEPROTOTYPES_DIR/config_data/vdcbce_chanmap_v4.txt" + FieldSeparators: " " + IndexIndex: 0 + ValueIndex: 9 + DefaultValue: 999999 +} + ################################################################################ # Reco tools. ################################################################################ ############## Charge calibration ################### -# Scale samples from ke to ADC count for bottom CRU -tools.vdbcb_adcScaleAdcToKe: @local::tools.adcScaleAdcToKe -tools.vdbcb_adcScaleAdcToKe.ScaleFactor: 0.025 -tools.vdbcb_adcScaleKeToAdc: @local::tools.adcScaleKeToAdc -tools.vdbcb_adcScaleKeToAdc.ScaleFactor: 40.0 +# Scale samples from ke to ADC count. +tmp.adcScaleKeToAdc: { + tool_type: AdcSampleScaler + LogLevel: 1 + ScaleFactor: 40.0 + InputUnit: "ke/tick" + OutputUnit: "ADC count" +} +tmp.adcScaleAdcToKe: { + tool_type: AdcSampleScaler + LogLevel: 1 + ScaleFactor: 0.025 + InputUnit: "ADC count" + OutputUnit: "ke/tick" +} + +# Scale samples from ke to ADC count for bottom CRP1 +tools.vdbcb_adcScaleAdcToKe: @local::tmp.adcScaleAdcToKe +tools.vdbcb_adcScaleKeToAdc: @local::tmp.adcScaleKeToAdc -# scale samples from ke to ADC count for Top CRP2/3 -tools.vdtcb2_adcScaleAdcToKe: @local::tools.adcScaleAdcToKe +# scale samples from ke to ADC count for Top CRP2,3 +tools.vdtcb2_adcScaleAdcToKe: @local::tmp.adcScaleAdcToKe tools.vdtcb2_adcScaleAdcToKe.ScaleFactor: 0.0319 -tools.vdtcb2_adcScaleKeToAdc: @local::tools.adcScaleKeToAdc +tools.vdtcb2_adcScaleKeToAdc: @local::tmp.adcScaleKeToAdc tools.vdtcb2_adcScaleKeToAdc.ScaleFactor: 31.35 +# Scale samples from ke to ADC count for CRP4,5 +tools.vdbcb4_adcScaleAdcToKe: @local::tmp.adcScaleAdcToKe +tools.vdbcb4_adcScaleKeToAdc: @local::tmp.adcScaleKeToAdc + ################# Noise removal. #################### # Raw RMS for each TPS channel. @@ -157,11 +187,31 @@ tools.vdtcb2_cnrw: { ################# Signal finder #################### -tools.vdc_thresholdSignalFinder: @local::tools.adcThresholdSignalFinder -tools.vdc_thresholdSignalFinder.Threshold: 1.0 +# Find ADC signals with simple threshold algorithm. +tools.vdc_thresholdSignalFinder: { + tool_type: AdcThresholdSignalFinder + LogLevel: 1 + Threshold: 1.0 + BinsBefore: 10 + BinsAfter: 20 + FlagPositive: true + FlagNegative: true +} -tools.vdcb_noiseSignalFinder: @local::tools.adcNoiseSignalFinder -tools.vdcb_noiseSignalFinder.ThresholdMin: 0.2 +# Dynamic signal finder. +tools.vdcb_noiseSignalFinder: { + tool_type: AdcNoiseSignalFinder + LogLevel: 1 + SigFracMax: 0.80 + ThresholdMin: 0.2 + ThresholdRatio: 4.0 + ThresholdRatioTol: 0.1 + MaxLoop: 20.0 + BinsBefore: 10 + BinsAfter: 20 + FlagPositive: true + FlagNegative: true +} ################################################################################ # Performance tools. @@ -396,3 +446,5 @@ tools.vdcb2_isoDepRoiMatcher: { ##### write matched ROIs to TTree in specified output file tools.vdcb2_isoDepRoiMatcherWithOutput : @local::tools.vdcb2_isoDepRoiMatcher tools.vdcb2_isoDepRoiMatcherWithOutput.OutFile: "isorois.root" + +tmp: @erase