3 #ifndef test_GeometryDune_CXX 4 #define test_GeometryDune_CXX 37 using std::istringstream;
38 using std::ostringstream;
67 template<
class T,
class V>
72 template<
class T,
class V>
80 template<
class T,
class V>
95 SpacePoint(
double ax,
double ay,
double az) : x(ax), y(ay), z(az) { }
106 cout << name <<
": " << val <<
endl;
109 template<
class T,
class V>
110 void check(
string name,
T val, V checkval,
bool print =
true,
bool doAssert =
true) {
111 if ( print )
check(name, val);
114 cout << val <<
" != " << checkval <<
endl;
116 cout <<
"************** Assertion not made!!! *************" <<
endl;
120 template<
class T,
class V>
121 void checkval(
string name,
T val, V chkval) {
124 cout <<
endl <<
"---------------------------------" <<
endl;
125 cout << name <<
": " << val <<
" != " << chkval <<
endl;
126 cout <<
"---------------------------------" <<
endl;
131 void checkfloat(
double x1,
double x2,
double tol =1.
e-5) {
132 double den =
abs(x1) +
abs(x2);
133 double num =
abs(x2 - x1);
134 if ( num/den >
tol ) {
135 cout <<
endl <<
"---------------------------------" <<
endl;
136 cout <<
"checkfloat: " << x1 <<
" != " << x2 <<
endl;
137 cout <<
"---------------------------------" <<
endl;
146 struct ExpectedValues {
157 Index nchaPerApa = 0;
169 FunPtr pfun =
nullptr;
180 Index nopchaHardware = 0;
205 bool useExistingFcl) {
206 const string myname =
"test_GeometryDune: ";
207 cout << myname <<
"Starting test" <<
endl;
209 cout << myname <<
"NDEBUG must be off." <<
endl;
212 string line =
"-----------------------------";
214 cout << myname << line <<
endl;
215 cout << myname <<
" Geometry: " << ev.gname <<
endl;
216 cout << myname <<
"Channel map: " << ev.chanmap <<
endl;
217 cout << myname <<
" Sorter: " << ev.sorter <<
endl;
218 cout << myname <<
" Do ROP: " << dorop <<
endl;
220 cout << myname << line <<
endl;
221 cout << myname <<
"Create configuration." <<
endl;
222 if (useExistingFcl) {
227 config <<
"#include \"geometry_dune.fcl\"" <<
endl;
228 config <<
"services.Geometry: @local::" << ev.gname <<
endl;
229 config <<
"services.ExptGeoHelperInterface: @local::dune_geometry_helper" <<
endl;
230 if ( ev.chanmap.size() ) {
231 config <<
"services.ExptGeoHelperInterface.ChannelMapClass: " << ev.chanmap <<
endl;
237 cout << myname << line <<
endl;
238 cout << myname <<
"Get Geometry service." <<
endl;
241 cout << myname << line <<
endl;
244 cout << myname <<
"ROOT name: " << pgeo->
ROOTFile() <<
endl;
245 cout << myname <<
"GDML name: " << pgeo->
GDMLFile() <<
endl;
247 cout << myname << line <<
endl;
248 double xlo, ylo, zlo;
249 double xhi, yhi, zhi;
250 cout << myname <<
"World box" <<
endl;
251 pgeo->
WorldBox(&xlo, &ylo, &zlo, &xhi, &yhi, &zhi);
259 cout << myname << line <<
endl;
262 cout << myname << line <<
endl;
266 cout << myname << line <<
endl;
272 cout << myname << line <<
endl;
274 check(
"Ncryostats", ncry, ev.ncry);
281 cout << myname << line <<
endl;
282 cout <<
"Check TPC wire plane counts." <<
endl;
283 for (
Index icry=0; icry<ncry; ++icry ) {
285 cout <<
" Cryostat " << icry <<
" has " << ntpc <<
" TPCs" <<
endl;
286 for (
Index itpc=0; itpc<ntpc; ++itpc ) {
288 cout <<
" TPC " << itpc <<
" has " << npla <<
" planes" <<
endl;
290 for (
Index ipla=0; ipla<npla; ++ipla ) {
294 for (
Index iwir=0; iwir<nwir; ++iwir ) {
296 if ( ich < ich1 ) ich1 = ich;
297 if ( ich > ich2 ) ich2 = ich;
299 cout <<
" Plane " << ipla <<
" has " <<
setw(4) << nwir <<
" wires" 300 <<
" readout on channels [" << ich1 <<
", " << ich2 <<
"]" 302 assert( nwir == ev.nwirPerPlane[itpc][ipla] );
307 cout << myname << line <<
endl;
308 cout <<
"Check wire planes." <<
endl;
309 const double piOver2 = 0.5*acos(-1.0);
312 cout <<
" Plane " << plaid <<
endl;
314 cout <<
" View: " << pgeo->
View(plaid) <<
endl;
315 cout <<
" Wire angle: " << gpla.
ThetaZ() - piOver2 <<
endl;
316 assert( pgeo->
SignalType(plaid) == ev.sigType[plaid.Cryostat][plaid.TPC][plaid.Plane] );
317 assert( pgeo->
View(plaid) == ev.view[plaid.Cryostat][plaid.TPC][plaid.Plane] );
320 cout << myname << line <<
endl;
321 cout <<
"Check channel-wire mapping." <<
endl;
322 Index itpc1Last = TPCID::InvalidID;
323 Index ipla1Last = WireID::InvalidID;
326 resize(lastwire, ev.ntpc, ev.npla, 0);
327 for (
Index itpc=0; itpc<ev.ntpc; ++itpc )
328 for (
Index ipla=0; ipla<ev.npla; ++ipla )
329 lastwire[itpc][ipla] = 0;
330 for (
Index icha=0; icha<ev.nchatot; ++icha ) {
332 assert( wirids.size() > 0 );
333 WireID wirid1 = wirids[0];
334 Index itpc1 = wirid1.TPC;
335 Index iapa1 = itpc1/2;
336 Index ipla1 = wirid1.Plane;
337 if ( itpc1 != itpc1Last || ipla1 != ipla1Last ) nprint = 0;
340 bool print = nprint < maxchanprint;
341 if ( print ) ++nprint;
342 if ( print ) cout <<
" Channel " <<
setw(4) << icha <<
" has " << wirids.size() <<
" wires:";
345 for (
WireID wirid : wirids ) {
346 Index itpc = wirid.TPC;
348 Index ipla = wirid.Plane;
349 Index iwir = wirid.Wire;
350 if ( print ) cout <<
" " << itpc <<
"-" << ipla <<
"-" <<
setw(3) << iwir;
351 if ( iwir > lastwire[itpc][ipla] ) lastwire[itpc][ipla] = iwir;
352 assert( iapa == iapa1 );
353 assert( ipla == ipla1 );
355 assert( pgeo->
SignalType(icha) == ev.sigType[wirid.Cryostat][wirid.TPC][wirid.Plane] );
356 checkval(
"View", pgeo->
View(icha), ev.view[wirid.Cryostat][wirid.TPC][wirid.Plane]);
359 TVector3 p2 = pwg->GetEnd();
360 if ( sposs.str().size() ) sposs <<
", ";
361 sposs <<
"(" <<
setw(7) << std::fixed << p1.x() <<
", " 362 <<
setw(7) << std::fixed << p1.y() <<
", " 363 <<
setw(7) << std::fixed << p1.z() <<
") - ";
364 sposs <<
"(" <<
setw(7) << std::fixed << p2.x() <<
", " 365 <<
setw(7) << std::fixed << p2.y() <<
", " 366 <<
setw(7) << std::fixed << p2.z() <<
")";
368 if ( print ) cout <<
" " << sposs.str() <<
endl;
370 for (
Index itpc=0; itpc<ev.ntpc; ++itpc ) {
371 for (
Index ipla=0; ipla<ev.npla; ++ipla ) {
372 Index nwir = lastwire[itpc][ipla] + 1;
373 cout <<
" TPC-plane " << itpc <<
"-" << ipla <<
" has " <<
setw(3) << nwir <<
" wires" <<
endl;
374 assert( nwir == ev.nwirPerPlane[itpc][ipla] );
379 cout << myname << line <<
endl;
380 cout <<
"Check ROP counts and channels." <<
endl;
385 cout <<
" Cryostat " << icry <<
" has " << napa <<
" APAs" <<
endl;
386 assert( napa == ev.napa );
387 for (
Index iapa=0; iapa<napa; ++iapa ) {
388 APAID apaid(cryid, iapa);
390 cout <<
" APA " << iapa <<
" has " << nrop <<
" ROPs" <<
endl;
391 assert( nrop == ev.nrop );
392 for (
Index irop=0; irop<nrop; ++irop ) {
393 ROPID ropid(apaid, irop);
396 Index icha2 = icha1 + ncha - 1;
397 cout <<
" ROP " << irop <<
" has " << ncha <<
" channels: [" 398 << icha1 <<
", " << icha2 <<
"]" <<
endl;
399 assert( ncha == ev.nchaPerRop[irop] );
400 assert( icha1 == ev.firstchan[icry][iapa][irop] );
405 assert( icry == ncry );
406 cout << myname << line <<
endl;
407 cout <<
"Check channel-ROP mapping." <<
endl;
409 for (
Index icha=0; icha<ev.nchatot; ++icha ) {
414 assert( icry == ev.chacry[icha] );
415 assert( iapa == ev.chaapa[icha] );
416 assert( irop == ev.charop[icha] );
418 cout << myname << line <<
endl;
419 cout <<
"Check ROP-TPC mapping." <<
endl;
422 cout <<
" Cryostat " << icry <<
" has " << napa <<
" APAs" <<
endl;
423 assert( napa == ev.napa );
424 for (
Index iapa=0; iapa<napa; ++iapa ) {
425 APAID apaid(cryid, iapa);
427 cout <<
" APA " << iapa <<
" has " << nrop <<
" ROPs" <<
endl;
428 assert( nrop == ev.nrop );
429 for (
Index irop=0; irop<nrop; ++irop ) {
430 ROPID ropid(apaid, irop);
431 std::vector<geo::TPCID> rtpcs = pgeo->
ROPtoTPCs(ropid);
432 Index nrtpc = rtpcs.size();
434 cout <<
" ROP " << irop <<
" TPCs:";
435 for (
Index irtpc=0; irtpc<nrtpc; ++irtpc ) {
436 assert(rtpcs[irtpc].Cryostat == icry);
437 cout << (irtpc > 0 ?
"," :
"") <<
" " << rtpcs[irtpc].
TPC;
444 cout << myname << line <<
endl;
445 cout <<
"Skipped APA and ROP tests." <<
endl;
448 cout << myname << line <<
endl;
449 Index nspt = ev.posXyz.size();
451 cout << myname <<
"No space points found." <<
endl;
452 cout << myname <<
"Creating space points." <<
endl;
455 cout << myname <<
"Check " << nspt <<
" space points." <<
endl;
456 assert( ev.posPla.size() == ev.posTpc.size() );
457 assert( ev.posWco.size() == ev.posTpc.size() );
460 for (
Index ispt=0; ispt<nspt; ++ispt ) {
461 double x = ev.posXyz[ispt].x;
462 double y = ev.posXyz[ispt].y;
463 double z = ev.posXyz[ispt].z;
464 double xyz[3] = {
x,
y, z};
466 cout <<
" (" <<
setw(w) << x <<
"," <<
setw(w) << y <<
"," <<
setw(w) << z <<
"): " << tpcid <<
endl;
467 assert( tpcid.
Cryostat != CryostatID::InvalidID );
468 unsigned int itpc = tpcid.
TPC;
469 assert( itpc != TPCID::InvalidID );
471 unsigned int npla = tpcgeo.
Nplanes();
472 assert( npla == ev.npla );
474 for (
unsigned int ipla=0; ipla<npla; ++ipla ) {
475 assert( ires < ev.posTpc.size() );
481 cerr <<
"ERROR (non-fatal):\n" <<
e;
482 wirid = e.suggestedWireID();
485 cout <<
" TPC " <<
setw(2) << itpc <<
" plane " << ipla
486 <<
" nearest wire is " <<
setw(3) << wirid.
Wire 487 <<
" and coordinate is " << xwire <<
endl;
488 assert( itpc == ev.posTpc[ires] );
489 assert( ipla == ev.posPla[ires] );
490 checkfloat(xwire, ev.posWco[ires], 2.e-4);
494 cout <<
" # checked planes: " << ires <<
endl;
498 bool doAssert =
true;
501 check(
"# Optical detectors expected", nopt, ev.nopdet,
true, doAssert);
502 Index nopchaReadout = ev.nopcha;
503 Index nopchaHardware = ev.nopchaHardware ? ev.nopchaHardware : nopchaReadout;
504 cout <<
" Expected optical readout channel count: " << nopchaReadout <<
endl;
505 cout <<
"Expected optical hardware channel count: " << nopchaHardware <<
endl;
506 cout <<
" Geometry optical channel count: " << pgeo->
NOpChannels() <<
endl;
507 check(
"# Optical channels", pgeo->
NOpChannels(), nopchaHardware,
true, doAssert);
508 cout <<
"Per-detector optical channel counts:" <<
endl;
509 assert( ev.nopdetcha.size() == nopt );
510 bool doAssert =
true;
511 for (
Index iopt=0; iopt<nopt; ++iopt ) {
513 sslab <<
" # channels for optical detector " << iopt;
518 cout <<
" Opdet channels:" <<
endl;
519 for (
Index iopt=0; iopt<nopt; ++iopt ) {
521 for (
Index ioch=0; ioch<noch; ++ioch ) {
523 sslab <<
" Det " << iopt <<
", chan " << ioch;
525 check(sslab.str() +
" (channel)", icha, ev.opdetcha[iopt][ioch],
true, doAssert);
526 if ( nopchaHardware == nopchaReadout ) {
534 cout << myname << line <<
endl;
535 cout << myname <<
"Done." <<
endl;
545 Index maxchanprint = 10;
546 bool useExistingFcl =
false;
548 string sarg = argv[1];
549 if ( sarg ==
"-h" ) {
550 cout << argv[0] <<
": . [dorop] [maxchan] [usefcl]" <<
endl;
551 cout << argv[0] <<
": [ChannelMapClass] [dorop] [maxchan] [usefcl]" <<
endl;
552 cout << argv[0] <<
": [Geometry/ChannelMapClass/sorter] [dorop] [maxchan] [usefcl]" <<
endl;
553 cout <<
" dorop: If true ROP mapping methods are tested [true]" <<
endl;
554 cout <<
" maxchan: Max # channels displayed for each ROP [10]" <<
endl;
555 cout <<
" usefcl: Take top-level fcl from current directory [false]" <<
endl;
558 string::size_type ipos = sarg.find(
"/");
559 if ( ipos == string ::npos ) {
560 if ( sarg !=
"." ) ev.chanmap = sarg;
562 ev.gname = sarg.substr(0, ipos);
563 string::size_type jpos = sarg.find(
"/", ipos+1);
564 if ( jpos == string::npos ) {
565 ev.chanmap = sarg.substr(ipos+1);
567 ev.chanmap = sarg.substr(ipos+1, jpos-ipos-1);
568 ev.sorter = sarg.substr(jpos+1);
573 string sarg = argv[2];
574 dorop = sarg ==
"1" || sarg ==
"true" || sarg ==
".";
577 istringstream ssarg(argv[3]);
578 ssarg >> maxchanprint;
581 string sarg = argv[4];
582 useExistingFcl = sarg ==
"1" || sarg ==
"true";
585 cout <<
"Tests concluded." <<
endl;
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
void GetStart(double *xyz) const
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const
Returns a list of ID of TPCs the specified ROP spans.
IDparameter< geo::CryostatID > CryostatID
Member type of validated geo::CryostatID parameter.
geo::Length_t CryostatHalfHeight(geo::CryostatID const &cid) const
Returns the height of the cryostat (y direction)
int main(int argc, const char *argv[])
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
unsigned int TotalNTPC() const
Returns the total number of TPCs in the detector.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
unsigned int Nplanes() const
Number of planes in this tpc.
void WorldBox(double *xlo, double *xhi, double *ylo, double *yhi, double *zlo, double *zhi) const
Fills the arguments with the boundaries of the world.
static constexpr FileOnPath_t FileOnPath
The data type to uniquely identify a Plane.
Geometry information for a single TPC.
unsigned int MaxROPs() const
Returns the largest number of ROPs a TPC set in the detector has.
void setExpectedValuesSpacePoints(Geometry *)
Class identifying a set of TPC sharing readout channels.
const std::string GetWorldVolumeName() const
Return the name of the world volume (needed by Geant4 simulation)
unsigned int NOpHardwareChannels(int opDet) const
unsigned int NTPCsets(readout::CryostatID const &cryoid) const
Returns the total number of TPC sets in the specified cryostat.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
CryostatID_t Cryostat
Index of cryostat.
WireID_t Wire
Index of the wire within its plane.
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
Geometry information for a single cryostat.
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
unsigned int NOpChannels() const
Number of electronics channels for all the optical detectors.
void resize(Vector< T > &vec1, Index n1, const V &val)
static void load_services(std::string const &config)
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
bool check(const std::vector< std::vector< float > > &outputs)
art framework interface to geometry description
std::string ROOTFile() const
Returns the full directory path to the geometry file source.
unsigned int OpDetFromOpChannel(int opChannel) const
Convert unique channel to detector number.
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
double ThetaZ() const
Angle of the wires from positive z axis; .
double TotalMass() const
Returns the total mass [kg] of the specified volume (default: world).
IteratorBox< plane_id_iterator,&GeometryCore::begin_plane_id,&GeometryCore::end_plane_id > IteratePlaneIDs() const
Enables ranged-for loops on all plane IDs of the detector.
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
std::string GDMLFile() const
Returns the full directory path to the GDML file source.
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
ROPID_t ROP
Index of the readout plane within its TPC set.
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
void setExpectedValues(ExpectedValues &ev)
Collection of exceptions for Geometry system.
raw::ChannelID_t FirstChannelInROP(readout::ROPID const &ropid) const
Returns the ID of the first channel in the specified readout plane.
unsigned int HardwareChannelFromOpChannel(int opChannel) const
Convert unique channel to hardware channel.
enum geo::_plane_sigtype SigType_t
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
SpacePoint(double ax, double ay, double az)
geo::Length_t SurfaceY() const
The position of the detector respect to earth surface.
static int max(int a, int b)
The geometry of one entire detector, as served by art.
The data type to uniquely identify a TPC.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
double DefaultWiggle() const
Returns the tolerance used in looking for positions.
Class identifying a set of planes sharing readout channels.
unsigned int NOpDets() const
Number of OpDets in the whole detector.
TPCsetID_t TPCset
Index of the TPC set within its cryostat.
Q_EXPORT QTSManip setw(int w)
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
readout::ROPID ChannelToROP(raw::ChannelID_t channel) const
unsigned int OpChannel(int detNum, int hardwareChannel) const
Convert detector number and hardware channel to unique channel.
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
geo::Length_t CryostatHalfWidth(geo::CryostatID const &cid) const
Returns the half width of the cryostat (x direction)
IteratorBox< cryostat_id_iterator,&GeometryCore::begin_cryostat_id,&GeometryCore::end_cryostat_id > IterateCryostatIDs() const
Enables ranged-for loops on all cryostat IDs of the detector.
void line(double t, double *p, double &x, double &y, double &z)
Exception thrown on invalid wire number.
geo::Length_t CryostatLength(geo::CryostatID const &cid) const
Returns the length of the cryostat (z direction)
geo::WireID NearestWireID(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the ID of wire closest to position in the specified TPC.
detail::Node< FrameID, bool > PlaneID
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
IDparameter< geo::TPCID > TPCID
Member type of validated geo::TPCID parameter.
unsigned int NROPs(readout::TPCsetID const &tpcsetid) const
Returns the total number of ROP in the specified TPC set.
unsigned int Nviews() const
Returns the number of views (different wire orientations)
TPCID_t TPC
Index of the TPC within its cryostat.
int test_GeometryDune(const ExpectedValues &ev, bool dorop, Index maxchanprint, bool useExistingFcl)
bool hasSuggestedWire() const
Returns whether we known a better wire number.
unsigned int MaxTPCs() const
Returns the largest number of TPCs a cryostat in the detector has.
QTextStream & endl(QTextStream &s)
The data type to uniquely identify a cryostat.
WireGeo const * WirePtr(geo::WireID const &wireid) const
Returns the specified wire.