#include #include #include #include #include #include #include #include #include #include //#include #include "tutTestGeom.hxx" #include "IGeomInfo.hxx" #include namespace tut { struct baseCDCGeomInfo { baseCDCGeomInfo() { // Run before each test. TestGeom::LoadGeometry("$OAGEOMINFOROOT/test/geometries/Phase_I_CyDet_Geom.mac"); } ~baseCDCGeomInfo() { // Run after each test. TestGeom::ResetGeometry(); } }; // Declare the test typedef test_group::object testCDCGeomInfo; test_group groupCDCGeomInfo("CDCGeomInfo"); // Test the default constructor and destructor. template<> template<> void testCDCGeomInfo::test<1> () { COMET::IGeomInfo::CDC(); } // Check the number of wires and layers template<> template<> void testCDCGeomInfo::test<2> () { // Number of layers in total ensure_equals("CDC has correct number of layers", COMET::IGeomInfo::CDC().GetNumberOfLayers(), 20); // Number of wires in total ensure_equals("CDC has correct number of sense wires", COMET::IGeomInfo::CDC().GetNumberOfWires(), 4986); } // Check each layer has the correct number of wires template<> template<> void testCDCGeomInfo::test<3> () { // Map of known values std::map nWireLay; TestGeom::GetNWiresInLayers(nWireLay); // Check each layer has the correct number of wires and first wire int nLayers = COMET::IGeomInfo::CDC().GetNumberOfLayers(); int wire0 = 0; for (int iLy = 0; iLy < nLayers; iLy++){ std::stringstream errMes; // Check the number of wires in each layer errMes << "Layer " << iLy << " has the correct number of sense wires"; ensure_equals(errMes.str().c_str(), nWireLay[iLy], COMET::IGeomInfo::CDC().GetNumberOfWiresPerLayer(iLy)); // Check the first wire on each layer is correct errMes.str(""); errMes << "Layer " << iLy << " has the correct first wire index"; ensure_equals(errMes.str().c_str(), wire0, COMET::IGeomInfo::CDC().GetFirstWireIndexAt(iLy)); // Check the wire indexes returned are correct std::vector aWires, bWires; // Fill the correct wires bool yes = COMET::IGeomInfo::CDC().GetWiresInLayer(iLy, bWires); ensure("Getter function for wires works in correct range", yes); for (int iCl=0; iCl < nWireLay[iLy]; iCl++) { aWires.push_back(wire0 + iCl); }; ensure("Getter function for wires gets correct indexes", aWires == bWires); // Incriment the first wire wire0 += nWireLay[iLy]; } } // Check each wire is indexed correctly template<> template<> void testCDCGeomInfo::test<4> () { // Maps of known values std::map nWireLay; TestGeom::GetNWiresInLayers(nWireLay); std::map wireLenLay; TestGeom::GetWireLengthByLayer(wireLenLay); // Number of layers const COMET::ICDCGeom& cdcGeom = COMET::IGeomInfo::CDC(); int nLayers = cdcGeom.GetNumberOfLayers(); // Store a running index int wireIdx = 0; for (int iLy=0; iLy < nLayers; iLy++){ for (int iCl=0; iCl < nWireLay[iLy]; iCl++){ // Check the layer ID and layer ID mappings are correct ensure_equals("Wires have the correct layer ID", cdcGeom.GetLayer(wireIdx), iLy); // Check the cell ID and layer ID mappings are correct ensure_equals("Wires have the correct cell ID", cdcGeom.GetCellId(wireIdx), iCl); // Ensure the reverse mapping is also working ensure_equals("Layer ID, Cell ID -> Wire ID mapping correct", cdcGeom.GetWireId(iLy, iCl), wireIdx); // Check the wire length in each layer ensure_lessthan("Wire length is correct within 1 cm", fabs(cdcGeom.GetWireLength(wireIdx) - wireLenLay[iLy]), 1.*unit::cm); ++wireIdx; } } } // Check the "distance from wire" functionality template<> template<> void testCDCGeomInfo::test<5> () { // Get the CDC Geom Info reference const COMET::ICDCGeom& cdcGeom = COMET::IGeomInfo::CDC(); // Loop over all wires for (int iWr=0; iWr < cdcGeom.GetNumberOfWires(); iWr++){ // Get the wire position TVector3 wirePos = cdcGeom.GetWirePosition(iWr); // Displace this some distance TVector3 dPos = TVector3(0., gRandom->Uniform(-10., 10.), 0.); TVector3 newPos = dPos + wirePos; // Check this is given back TVector3 retVal; bool yes = cdcGeom.GetDistanceFromWire(newPos, iWr, retVal); // Ensure this is the original displacement ensure_lessthan("Distance from wire functionality working within 1 mm", (retVal - dPos).Mag(), 1.*unit::mm); } } // Check the wire TGeoNode names template<> template<> void testCDCGeomInfo::test<6> () { // Get the CDC Geom Info reference const COMET::ICDCGeom& cdcGeom = COMET::IGeomInfo::CDC(); // Loop over all wires for (int iWr=0; iWr < cdcGeom.GetNumberOfWires(); iWr++){ // Get the wire position const TGeoNode* wireNode = cdcGeom.GetSenseWire(iWr); // Displace this some distance std::string wireName = wireNode->GetName(); // Get the integer number from the string size_t firstNum = wireName.find("_", 0) + 1; size_t lastNum = wireName.find("_", firstNum); if (firstNum == std::string::npos || lastNum == std::string::npos){ failure("Naming not as expected.\n" "Expected __0.\n" "Found " + wireName); } int parsedIndex = std::atoi(wireName.substr(firstNum, lastNum - firstNum).c_str()); // Ensure the sense wires are named consistently ensure_equals("Sense wire nodes named by correct index", parsedIndex, iWr); } } // Compare all sense wire information with that in the parameter ROOT file template<> template<> void testCDCGeomInfo::test<7> () { // Set the parameter file std::string paramFile = "$OAGEOMINFOROOT/parameters/chanmap_20180416.root"; // Get the CDC Geom Info reference COMET::ICDCGeom cdcGeom; cdcGeom.Fill(); // Compare the entries in the CDCGeom to that in the parameter file TestGeom::WireInfo cdcGeomWires, paramFileWires; COMETLog("Filling from cdcGeom"); TestGeom::FillSenseWires(cdcGeom, cdcGeomWires); COMETLog("Filling from paramFile"); TestGeom::FillParamWires(cdcGeom, paramFile, true, paramFileWires); // Ensure the number of sense wires are the same ensure_equals("The number of sense wires in ICDCGeom matches the number" " in the parameter file", cdcGeomWires.size(), paramFileWires.size()); // Check if they contain the same information ensure("Sense wire information matches the parameter file", TestGeom::CompareWires(paramFileWires, cdcGeomWires)); } // Compare all field wire information with that in the parameter ROOT file template<> template<> void testCDCGeomInfo::test<8> () { // Set the parameter file std::string paramFile = "$OAGEOMINFOROOT/parameters/chanmap_20180416.root"; // Get the CDC Geom Info reference COMET::ICDCGeom cdcGeom; cdcGeom.Fill(); // Compare the entries in the CDCGeom to that in the parameter file TestGeom::WireInfo cdcGeomWires, paramFileWires; COMETLog("Filling from cdcGeom"); TestGeom::FillFieldWires(cdcGeom, cdcGeomWires); COMETLog("Filling from paramFile"); TestGeom::FillParamWires(cdcGeom, paramFile, false, paramFileWires); // Ensure the number of sense wires are the same ensure_equals("The number of field wires in ICDCGeom matches the number" " in the parameter file", cdcGeomWires.size(), paramFileWires.size()); bool agree = TestGeom::CompareWires(paramFileWires, cdcGeomWires); // Check if they contain the same information ensure("Field wire information matches the parameter file", agree); } };