Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:43

0001 #include "DD4hep/Segmentations.h"
0002 #include "DD4hep/CartesianGridXY.h"
0003 #include "DD4hep/CartesianGridYZ.h"
0004 #include "DD4hep/CartesianGridXZ.h"
0005 #include "DD4hep/CartesianGridXYZ.h"
0006 #include "DD4hep/DDTest.h"
0007 
0008 #include <iostream>
0009 #include <iomanip>
0010 #include <vector>
0011 #include <algorithm>
0012 #include <exception>
0013 #include <cmath>
0014 
0015 
0016 using namespace dd4hep;
0017 using namespace dd4hep::detail;
0018 //using dd4hep::DDSegmentation::BitFieldCoder;
0019 
0020 int main() {
0021 
0022   dd4hep::DDTest test( "CellDimensions" );
0023 
0024   try{
0025     BitFieldCoder bf("system:8,barrel:3,layer:8,slice:5,x:16,y:16");
0026     Segmentation base("CartesianGridXY","Test",&bf);
0027     CartesianGridXY seg(base);
0028     const double xSize=12343.43243;
0029     const double ySize=M_PI;
0030 
0031     test( seg.isValid(), " Assignment from Segmentation -> "+typeName(typeid(seg))+" worked" );
0032 
0033     seg.setGridSizeX(xSize);
0034     seg.setGridSizeY(ySize);
0035 
0036     dd4hep::DDSegmentation::VolumeID volID = 0;
0037 
0038     test( fabs(seg.cellDimensions(volID)[0] - xSize )  < 1e-11, " CG_XY: Dimension for X" );
0039     test( fabs(seg.cellDimensions(volID)[1] - ySize )  < 1e-11, " CG_XY: Dimension for Y" );
0040 
0041   } catch( std::exception &e ){
0042     test.log( e.what() );
0043     test.error( "exception occurred" );
0044   }
0045 
0046   try{
0047     BitFieldCoder bf("system:8,barrel:3,layer:8,slice:5,x:16,z:16");
0048     Segmentation base("CartesianGridXZ","Test",&bf);
0049     CartesianGridXZ seg(base);
0050 
0051     const double xSize=12343.43243;
0052     const double zSize=M_PI;
0053 
0054     test( seg.isValid(), " Assignment from Segmentation -> "+typeName(typeid(seg))+" worked" );
0055 
0056     seg.setGridSizeX(xSize);
0057     seg.setGridSizeZ(zSize);
0058 
0059     VolumeID volID = 0;
0060 
0061     test( fabs(seg.cellDimensions(volID)[0] - xSize )  < 1e-11, " CG_XZ: Dimension for X" );
0062     test( fabs(seg.cellDimensions(volID)[1] - zSize )  < 1e-11, " CG_XZ: Dimension for Z" );
0063 
0064   } catch( std::exception &e ){
0065     test.log( e.what() );
0066     test.error( "exception occurred" );
0067   }
0068 
0069   try{
0070     BitFieldCoder bf("system:8,barrel:3,layer:8,slice:5,y:16,z:16");
0071     Segmentation base("CartesianGridYZ","Test",&bf);
0072     CartesianGridYZ seg = base;
0073 
0074     test( seg.isValid(), " Assignment from Segmentation -> "+typeName(typeid(seg))+" worked" );
0075 
0076     const double ySize=12343.43243;
0077     const double zSize=M_PI;
0078 
0079     seg.setGridSizeY(ySize);
0080     seg.setGridSizeZ(zSize);
0081 
0082     dd4hep::DDSegmentation::VolumeID volID = 0;
0083 
0084     test( fabs(seg.cellDimensions(volID)[0] - ySize )  < 1e-11, " CG_YZ: Dimension for Y" );
0085     test( fabs(seg.cellDimensions(volID)[1] - zSize )  < 1e-11, " CG_YZ: Dimension for Z" );
0086 
0087   } catch( std::exception &e ){
0088     test.log( e.what() );
0089     test.error( "exception occurred" );
0090   }
0091 
0092   try{
0093     BitFieldCoder bf("system:8,barrel:3,layer:8,slice:7,x:10,y:10,z:10");
0094     Segmentation base("CartesianGridXYZ","Test",&bf);
0095     CartesianGridXYZ seg = base;
0096 
0097     test( seg.isValid(), " Assignment from Segmentation -> "+typeName(typeid(seg))+" worked" );
0098 
0099     const double xSize=42.24;
0100     const double ySize=12343.43243;
0101     const double zSize=M_PI;
0102 
0103     seg.setGridSizeX(xSize);
0104     seg.setGridSizeY(ySize);
0105     seg.setGridSizeZ(zSize);
0106 
0107     dd4hep::DDSegmentation::VolumeID volID = 0;
0108 
0109     test( fabs(seg.cellDimensions(volID)[0] - xSize )  < 1e-11, " CG_XYZ: Dimension for X" );
0110     test( fabs(seg.cellDimensions(volID)[1] - ySize )  < 1e-11, " CG_XYZ: Dimension for Y" );
0111     test( fabs(seg.cellDimensions(volID)[2] - zSize )  < 1e-11, " CG_XYZ: Dimension for Z" );
0112 
0113   } catch( std::exception &e ){
0114     test.log( e.what() );
0115     test.error( "exception occurred" );
0116   }
0117   return 0;
0118 }