Skip to content

Commit

Permalink
Add CRP all-plane FEMB channel groups. DUNE/dunedataprep#28
Browse files Browse the repository at this point in the history
  • Loading branch information
dladams committed Sep 6, 2023
1 parent edc0ed9 commit 45436c3
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 52 deletions.
10 changes: 8 additions & 2 deletions duneprototypes/Coldbox/vd/Tools/CrpChannelGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
//
// Returns groups for the vertical drift CRPs used in the late 2022
// coldbox tests (CRP2+), ProtoDUNE-VD and maybe FD-VD.
// At present, single ranges from channelranges are returned.
// All ranges from CrpChannelRanges are included and teh following are added:
// fembTFF - FEMB FF for volume T bottom
// Indices ar as for CrpChannelRanges:
// T = TPC label: C for coldbox, {A,B} for ProtoDUNE, presumably {00, 01, ..., ??} for DUNE FD2.
// FF = FEMB number in range [00, 15]

#ifndef CrpChannelGroups_H
#define CrpChannelGroups_H
Expand Down Expand Up @@ -37,11 +41,13 @@ class CrpChannelGroups : public IndexRangeGroupTool {

// Derived paramters.
IndexRangeTool* m_pcrt =nullptr;
using GroupMap = std::map<Name, IndexRangeGroup>;
GroupMap m_grps;

// Create a group from range names.
using Name = std::string;
using NameVector = std::vector<Name>;
IndexRangeGroup makeGroup(Name nam, NameVector rnams, Name lab) const;
IndexRangeGroup makeGroup(Name nam, NameVector rnams, Name lab, bool ignoreBadRanges =false);

};

Expand Down
53 changes: 42 additions & 11 deletions duneprototypes/Coldbox/vd/Tools/CrpChannelGroups_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using std::string;
using std::cout;
using std::endl;
using Index = IndexRange::Index;

//**********************************************************************

Expand Down Expand Up @@ -38,8 +39,21 @@ CrpChannelGroups::CrpChannelGroups(fhicl::ParameterSet const& ps)
cout << myname << "ERROR: Invalid range detector name: " << sdet << endl;
return;
}
//for ( Index icru=0; icru<ncru; ++icru ) {:q

if ( cch.usefembs ) {
for ( Index icru=0; icru<cch.ncru; ++icru ) {
if ( ! cch.cruHasFembs(icru) ) break;
for ( Index ifmb=1; ifmb<=cch.nfc; ++ifmb ) {
NameVector rnams;
for ( Index ipla=0; ipla<3; ++ipla ) {
string rnam = cch.fembPlaneName(icru, ifmb, ipla);
rnams.push_back(rnam);
}
string gnam = cch.fembName(icru, ifmb);
string glab = cch.fembLabel(icru, ifmb);
IndexRangeGroup grp = makeGroup(gnam, rnams, glab, true);
}
}
}
}
}

Expand All @@ -51,25 +65,42 @@ IndexRangeGroup CrpChannelGroups::get(std::string gnam) const {
cout << myname << "ERROR: Channel range tool was not found." << endl;
return IndexRangeGroup();
}
// No groups yet defined. Try range instead.
// First try local groups.
GroupMap::const_iterator igrp = m_grps.find(gnam);
if ( igrp != m_grps.end() ) {
return igrp->second;
}
// Next see if there is range with the name.
IndexRange ran = m_pcrt->get(gnam);
if ( ! ran.isValid() ) {
if ( m_LogLevel >= 2 ) cout << myname << "Range not found: " << gnam << endl;
return IndexRangeGroup();
if ( ran.isValid() ) {
return IndexRangeGroup(ran);
}
return IndexRangeGroup(ran);
if ( m_LogLevel >= 2 ) cout << myname << "Group not found: " << gnam << endl;
return IndexRangeGroup();
}

//**********************************************************************

IndexRangeGroup CrpChannelGroups::
makeGroup(Name nam, NameVector rnams, Name lab) const {
IndexRangeGroup CrpChannelGroups::makeGroup(Name nam, NameVector rnams, Name lab, bool ignoreBadRanges) {
string myname = "CrpChannelGroups::makeGroup: ";
IndexRangeGroup::RangeVector rans;
for ( Name rnam : rnams ) {
rans.push_back(m_pcrt->get(rnam));
IndexRange ran = m_pcrt->get(rnam);
if ( ran.isValid() ) {
rans.push_back(ran);
} else {
if ( ! ignoreBadRanges ) {
cout << myname << "WARNING: Invalid range " << rnam << " requested for group " << nam << endl;
}
}
}
NameVector labs = {lab};
return IndexRangeGroup(nam, labs, rans);
IndexRangeGroup grp(nam, labs, rans);
if ( m_LogLevel >= 2 ) {
cout << myname << "Adding group " << grp << endl;
}
m_grps[nam] = grp;
return grp;
}


Expand Down
34 changes: 31 additions & 3 deletions duneprototypes/Coldbox/vd/Tools/CrpChannelHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,42 @@ class CrpChannelHelper {
using Name = std::string;
using NameVector = std::vector<Name>;

// Number of strips in each plane
const Index nsu = 952;
const Index nsv = 952;
const Index nsz = 1168;
IndexVector nPlaneStrips = {nsu, nsv, nsz};

// Number of strips in a CRU.
const Index nsc = nsu + nsv + nsz;

// Number of FEMBs in a CRU.
const Index nfc = 24;

// Number of strips in the detector.
Index nsdet = 0;

// Number of CRUs.
Index ncru = 0;

// Number of TPC volumes.
// For DUNE and ProtoDUNE, each has both top and bottom readout.
Index nvol = 0;

// Number of planes in CRU.
Index npla = 3;

// Names and labels.
Name detname;
NameVector plaLabs = {"u", "v", "z"};
NameVector volumeNames;
NameVector cruLabs;

Name detname;
// Flag indicating if FEMB ranges are defined.
bool usefembs =false;

// Flag indicating if FEMB adapters are defined.
bool useadaps =false;
Index nsdet = 0;


// Ctor from detector name.
Expand All @@ -50,7 +70,7 @@ class CrpChannelHelper {
return scr;
}

// Name of the volume for a CRU.
// Name of the volume for a CRU: C, A, B, 01, 02, ...
Name cruVolumeName(Index icru) const {
if ( icru >= ncru ) return "";
return volumeNames[icru%nvol];
Expand Down Expand Up @@ -78,6 +98,14 @@ class CrpChannelHelper {
return cruLabel(icru) + plaLabs[ipla];
}

// Return if a CRU has FEMBs.
// For two-ended detectors, this is the first half of the range.
bool cruHasFembs(Index icru) const {
if ( ! usefembs ) return false;
if ( ncru == 1 ) return true;
return icru < ncru/2;
}

// Name of a CRU FEMB.
Name fembName(Index icru, Index ifmb) const {
Name sfmb = std::to_string(ifmb);
Expand Down
2 changes: 1 addition & 1 deletion duneprototypes/Coldbox/vd/Tools/CrpChannelRanges_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CrpChannelRanges::CrpChannelRanges(fhicl::ParameterSet const& ps)
Index jps = ips + nps;
insert(cch.cruPlaneName(icru, ipla), ips, jps, cch.cruPlaneLabel(icru, ipla));
// FEMB views.
if ( cch.usefembs ) {
if ( cch.cruHasFembs(icru) ) {
Index icha = ips;
Index ifmb = pcrpChannelFemb->get(icha%cch.nsc);
for ( Index jcha=icha+1; jcha<=jps; ++jcha ) {
Expand Down
72 changes: 46 additions & 26 deletions duneprototypes/Coldbox/vd/Tools/test/crpChannelRangeTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// CRP channel ranges are present and cover the expected ranges.

#include <string>
#include <set>
#include "dunecore/DuneInterface/Tool/IndexRangeTool.h"
#include "dunecore/DuneInterface/Tool/IndexRangeGroupTool.h"
#include "dunecore/DuneCommon/Utility/StringManipulator.h"
Expand All @@ -15,6 +16,8 @@ using std::string;
using std::cout;
using std::endl;
using std::to_string;
using NameVector = std::vector<string>;
using NameSet = std::set<string>;
using Index = IndexRange::Index;

// Check a range.
Expand Down Expand Up @@ -64,28 +67,58 @@ IndexRange get_only_range(const IndexRangeGroup& grp) {
return grp.range(0);
}

IndexRangeGroup get_group(const IndexRangeTool& rt, string) {
assert(false);
return IndexRangeGroup();
}

IndexRangeGroup get_group(const IndexRangeGroupTool& rt, string gnam) {
return rt.get(gnam);
}

template<class T>
void check_femb_ranges(const T& rt) {
void check_femb_ranges(const T& rt, const NameVector& svols, bool doGroups) {
const string myname = "check_femb_ranges: ";
Index nran = 0;
for ( string stpc : {"A", "B"} ) {
for ( Index ifmb=1; ifmb<=16; ++ifmb ) {
Index nch_femb = 0;
for ( string svol : svols ) {
for ( Index ifmb=1; ifmb<=24; ++ifmb ) {
string sfmb = std::to_string(ifmb);
while ( sfmb.size() < 2 ) sfmb = "0" + sfmb;
cout << myname << " ================== FEMB " << svol << sfmb << " ===================" << endl;
Index nch_femb = 0;
Index nfran = 0;
NameSet rrnams;
for ( string svie : {"u", "v", "z"} ) {
string sran = "femb" + stpc + sfmb + svie;
string sran = "femb" + svol + sfmb + svie;
IndexRange ran = get_only_range(rt.get(sran));
if ( ran.isValid() ) {
cout << myname << " " << ran << endl;
Index nch_view = ran.size();
nch_femb += nch_view;
++nran;
++nfran;
rrnams.insert(ran.name);
} else {
cout << myname << " Range " << sran << " not found." << endl;
cout << myname << " " << sran << ": *** Not found ***" << endl;
}
}
cout << myname << "FEMB " << stpc << sfmb << " has " << nch_femb << " channels.";
if ( doGroups ) {
string gnam = "femb" + svol + sfmb;
IndexRangeGroup grp = get_group(rt, gnam);
if ( ! grp.isValid() ) {
cout << myname << "Group " << gnam << " not found." << endl;
assert(false);
} else {
cout << myname << " " << grp << endl;
assert( grp.size() == nfran );
NameSet grnams;
for ( Index iran=0; iran<grp.size(); ++iran ) {
grnams.insert(grp.range(iran).name);
}
assert( grnams == rrnams );
}
}
cout << myname << "FEMB " << svol << sfmb << " has " << nch_femb << " channels.";
if ( nch_femb == 128 ) {
cout << " Good." << endl;
} else {
Expand All @@ -94,19 +127,14 @@ void check_femb_ranges(const T& rt) {
}
}
}
cout << myname << " ===============================================" << endl;
cout << myname << "Good range FEMB count is " << nran << endl;
}

//void check_femb_ranges(const IndexRangeGroupTool& rt) {
// const string myname = "check_femb_ranges: ";
// cout << myname << "Test is disabled for IndexRangeGroupTool." << endl;
// assert(false); //for now
//}

// ****** Check all ranges ******

template<class T>
int checkChannelRanges(string callname, string sdet, const T& rt, string line) {
int checkChannelRanges(string callname, string sdet, const T& rt, string line, bool doGroups =false) {
string myname = callname + "checkChannelRanges: ";
std::vector<string> svals = StringManipulator(sdet).split(":");
assert( svals.size() > 0 );
Expand Down Expand Up @@ -134,17 +162,8 @@ int checkChannelRanges(string callname, string sdet, const T& rt, string line) {
checkran(rt, "cruCv", 952, 952);
checkran(rt, "cruCz", 1904, 1168);
if ( check_fembs ) {
cout << myname << "Checking FEMB ranges. Sorta." << endl;
for ( Index ifmb=0; ifmb<=16; ++ifmb ) {
string sfmb = std::to_string(ifmb);
if ( sfmb.size() < 2 ) sfmb = "0" + sfmb;
for ( string sori : {"u", "v", "z"} ) {
string sran = "fembC" + sfmb + sori;
// IndexRange or IndexRangeGroup
auto ran = rt.get(sran);
cout << " " << sran << ": " << ran << endl;
}
}
NameVector svols = {"C"};
check_femb_ranges(rt, svols, doGroups);
}
} else if ( detname == "pdvd" ) {
checkran(rt, "crdet", 0, 2*6144);
Expand All @@ -166,7 +185,8 @@ int checkChannelRanges(string callname, string sdet, const T& rt, string line) {
if ( check_fembs ) {
cout << myname << line << endl;
cout << myname << "Check FEMB ranges." << endl;
check_femb_ranges(rt);
NameVector svols = {"A", "B"};
check_femb_ranges(rt, svols, doGroups);
}
if ( check_adas ) {
cout << myname << line << endl;
Expand Down
19 changes: 12 additions & 7 deletions duneprototypes/Coldbox/vd/Tools/test/test_CrpChannelGroups.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using IndexVector = std::vector<Index>;

//**********************************************************************

int test_CrpChannelGroups(bool useExistingFcl, string sdet) {
int test_CrpChannelGroups(bool useExistingFcl, string sdet, Index loglev) {
const string myname = "test_CrpChannelGroups: ";
#ifdef NDEBUG
cout << myname << "NDEBUG must be off." << endl;
Expand All @@ -52,12 +52,12 @@ int test_CrpChannelGroups(bool useExistingFcl, string sdet) {
fout << " crpChannelFemb: @local::save" << endl;
fout << " channelRanges: {" << endl;
fout << " tool_type: CrpChannelRanges" << endl;
fout << " LogLevel: 1" << endl;
fout << " LogLevel: 0" << endl;
fout << " Detector: \"" << sdet << "\"" << endl;
fout << " }" << endl;
fout << " mytool: {" << endl;
fout << " tool_type: CrpChannelGroups" << endl;
fout << " LogLevel: 1" << endl;
fout << " LogLevel: " << loglev << endl;
fout << " }" << endl;
fout << "}" << endl;
fout.close();
Expand All @@ -77,7 +77,7 @@ int test_CrpChannelGroups(bool useExistingFcl, string sdet) {
auto cma = tm.getPrivate<IndexRangeGroupTool>("mytool");
assert( cma != nullptr );

checkChannelRanges(myname, sdet, *cma, line);
checkChannelRanges(myname, sdet, *cma, line, true);

cout << myname << line << endl;
cout << myname << "Done." << endl;
Expand All @@ -89,32 +89,37 @@ int test_CrpChannelGroups(bool useExistingFcl, string sdet) {
int main(int argc, char* argv[]) {
string ssdet = "cb2022:nofembs,pdvd:nofembs,cb2022,pdvd";
bool useExistingFcl = false;
string sloglev = "1";
if ( argc > 1 ) {
string sarg(argv[1]);
if ( sarg == "-h" ) {
cout << "Usage: " << argv[0] << "[cb2022 | pdvd | -h]" << endl;
cout << "Usage: " << argv[0] << "keepFcl [DETS [LOGLEV]]]" << endl;
return 0;
}
ssdet = sarg;
useExistingFcl = sarg == "true" || sarg == "1";
if ( argc > 2 ) {
ssdet = argv[2];
if ( argc > 3 ) {
sloglev = argv[3];
}
}
}
Index loglev = std::stoi(sloglev);
vector<string> sdets = StringManipulator(ssdet).split(",");
if ( sdets.size() == 0 ) {
cout << "Empty detector string." << endl;
return 1;
}
if ( sdets.size() == 1 ) {
return test_CrpChannelGroups(useExistingFcl, ssdet);
return test_CrpChannelGroups(useExistingFcl, ssdet, loglev);
}
string line = "=======================================================";
cout << line << endl;
Index rc = 99;
for ( string sdet : sdets ) {
cout << "Testing detector " << sdet << endl;
string com = string(argv[0]) + " " + std::to_string(useExistingFcl) + " " + sdet;
string com = string(argv[0]) + " " + std::to_string(useExistingFcl) + " " + sdet + " " + sloglev;
cout << "Command: " << com << endl;
rc = system(com.c_str());
if ( rc ) return rc;
Expand Down
Loading

0 comments on commit 45436c3

Please sign in to comment.