15 #include <GeoModelHelpers/TransformToStringConverter.h>
18 #include <GaudiKernel/SystemOfUnits.h>
22 #include <TTreeReader.h>
50 float stripPitchEta{0.f};
51 float stripPitchPhi{0.f};
52 float stripWidthEta{0.f};
53 float stripWidthPhi{0.f};
55 float stripLengthEta{0.f};
56 float stripLengthPhi{0.f};
58 unsigned int numStripsEta{0};
59 unsigned int numStripsPhi{0};
63 unsigned int numGasGapsPhi{0};
65 unsigned int numPhiPanels{0};
73 unsigned int strip{0};
83 if (measPhi !=
other.measPhi)
return !measPhi;
86 return strip <
other.strip;
101 if (measPhi !=
other.measPhi)
return !measPhi;
106 std::set<RpcStrip> strips{};
114 static const std::map<int, std::string> stationDict{
115 {0,
"BIL"}, {1,
"BIS"}, {7,
"BIR"},
116 {2,
"BML"}, {3,
"BMS"}, {8,
"BMF"}, {53,
"BME"}, {54,
"BMG"}, {52,
"BIM"},
117 {4,
"BOL"}, {5,
"BOS"}, {9,
"BOF"}, {10,
"BOG"},
118 {6,
"BEE"}, {14,
"EEL"}, {15,
"EES"},
120 {17,
"EML"}, {18,
"EMS"},
121 {20,
"EOL"}, {21,
"EOS"}
128 ostr<<
"strip (gasGap/phiPanel/isPhiStrip/number): ";
129 ostr<<strip.gasGap<<
"/"<<strip.doubletPhi<<
"/";
130 ostr<<(strip.measPhi ?
"si" :
"no")<<
"/"<<strip.strip<<
", ";
135 ostr<<
"rpclayer (gasGap/phiPanel/isPhiLayer): ";
136 ostr<<
layer.gasGap<<
"/"<<
layer.doubletPhi<<
"/";
137 ostr<<(
layer.measPhi ?
"si" :
"no")<<
", ";
143 std::set<RpcChamber> to_ret{};
144 std::cout<<
"Read the Rpc geometry tree dump from "<<
inputFile<<std::endl;
147 std::cerr<<__FILE__<<
":"<<__LINE__<<
" Failed to open "<<
inputFile<<std::endl;
152 std::cerr<<__FILE__<<
":"<<__LINE__<<
" The file "<<
inputFile<<
" does not contain the 'RpcGeoModelTree'"<<std::endl;
156 TTreeReaderValue<unsigned short> stationIndex{
treeReader,
"stationIndex"};
157 TTreeReaderValue<short> stationEta{
treeReader,
"stationEta"};
158 TTreeReaderValue<short> stationPhi{
treeReader,
"stationPhi"};
159 TTreeReaderValue<uint8_t> stationDoubletR{
treeReader,
"stationDoubletR"};
160 TTreeReaderValue<uint8_t> stationDoubletZ{
treeReader,
"stationDoubletZ"};
161 TTreeReaderValue<uint8_t> stationDoubletPhi{
treeReader,
"stationDoubletPhi"};
162 TTreeReaderValue<std::string> chamberDesign{
treeReader,
"chamberDesign"};
166 TTreeReaderValue<uint8_t> numStripsEta{
treeReader,
"numEtaStrips"};
167 TTreeReaderValue<uint8_t> numStripsPhi{
treeReader,
"numPhiStrips"};
170 TTreeReaderValue<uint8_t> numPhiPanels{
treeReader,
"numPhiPanels"};
174 TTreeReaderValue<float> stripEtaPitch{
treeReader,
"stripEtaPitch"};
175 TTreeReaderValue<float> stripPhiPitch{
treeReader,
"stripPhiPitch"};
176 TTreeReaderValue<float> stripEtaWidth{
treeReader,
"stripEtaWidth"};
177 TTreeReaderValue<float> stripPhiWidth{
treeReader,
"stripPhiWidth"};
178 TTreeReaderValue<float> stripEtaLength{
treeReader,
"stripEtaLength"};
179 TTreeReaderValue<float> stripPhiLength{
treeReader,
"stripPhiLength"};
182 TTreeReaderValue<std::vector<float>> geoModelTransformX{
treeReader,
"GeoModelTransformX"};
183 TTreeReaderValue<std::vector<float>> geoModelTransformY{
treeReader,
"GeoModelTransformY"};
184 TTreeReaderValue<std::vector<float>> geoModelTransformZ{
treeReader,
"GeoModelTransformZ"};
186 TTreeReaderValue<std::vector<float>> alignableNodeX{
treeReader,
"AlignableNodeX"};
187 TTreeReaderValue<std::vector<float>> alignableNodeY{
treeReader,
"AlignableNodeY"};
188 TTreeReaderValue<std::vector<float>> alignableNodeZ{
treeReader,
"AlignableNodeZ"};
192 TTreeReaderValue<std::vector<float>> stripRotTranslationX{
treeReader,
"stripRotTranslationX"};
193 TTreeReaderValue<std::vector<float>> stripRotTranslationY{
treeReader,
"stripRotTranslationY"};
194 TTreeReaderValue<std::vector<float>> stripRotTranslationZ{
treeReader,
"stripRotTranslationZ"};
197 TTreeReaderValue<std::vector<float>> stripRotCol1X{
treeReader,
"stripRotLinearCol1X"};
198 TTreeReaderValue<std::vector<float>> stripRotCol1Y{
treeReader,
"stripRotLinearCol1Y"};
199 TTreeReaderValue<std::vector<float>> stripRotCol1Z{
treeReader,
"stripRotLinearCol1Z"};
201 TTreeReaderValue<std::vector<float>> stripRotCol2X{
treeReader,
"stripRotLinearCol2X"};
202 TTreeReaderValue<std::vector<float>> stripRotCol2Y{
treeReader,
"stripRotLinearCol2Y"};
203 TTreeReaderValue<std::vector<float>> stripRotCol2Z{
treeReader,
"stripRotLinearCol2Z"};
205 TTreeReaderValue<std::vector<float>> stripRotCol3X{
treeReader,
"stripRotLinearCol3X"};
206 TTreeReaderValue<std::vector<float>> stripRotCol3Y{
treeReader,
"stripRotLinearCol3Y"};
207 TTreeReaderValue<std::vector<float>> stripRotCol3Z{
treeReader,
"stripRotLinearCol3Z"};
209 TTreeReaderValue<std::vector<uint8_t>> stripRotGasGap{
treeReader,
"stripRotGasGap"};
210 TTreeReaderValue<std::vector<uint8_t>> stripRotDblPhi{
treeReader,
"stripRotDoubletPhi"};
211 TTreeReaderValue<std::vector<bool>> stripRotMeasPhi{
treeReader,
"stripRotMeasPhi"};
213 TTreeReaderValue<std::vector<float>> stripPosX{
treeReader,
"stripPosX"};
214 TTreeReaderValue<std::vector<float>> stripPosY{
treeReader,
"stripPosY"};
215 TTreeReaderValue<std::vector<float>> stripPosZ{
treeReader,
"stripPosZ"};
217 TTreeReaderValue<std::vector<float>> stripLocPosX{
treeReader,
"stripLocPosX"};
218 TTreeReaderValue<std::vector<float>> stripLocPosY{
treeReader,
"stripLocPosY"};
221 TTreeReaderValue<std::vector<bool>> stripPosMeasPhi{
treeReader,
"stripPosMeasPhi"};
222 TTreeReaderValue<std::vector<uint8_t>> stripPosGasGap{
treeReader,
"stripPosGasGap"};
223 TTreeReaderValue<std::vector<uint8_t>> stripPosNum{
treeReader,
"stripPosNum"};
224 TTreeReaderValue<std::vector<uint8_t>> stripDblPhi{
treeReader,
"stripPosDoubletPhi"};
230 newchamber.design = (*chamberDesign);
231 newchamber.id.eta = (*stationEta);
232 newchamber.id.phi = (*stationPhi);
233 newchamber.id.doubletPhi = (*stationDoubletPhi);
234 newchamber.id.doubletR = (*stationDoubletR);
235 newchamber.id.doubletZ = (*stationDoubletZ);
237 newchamber.stripPitchEta = (*stripEtaPitch);
238 newchamber.stripPitchPhi = (*stripPhiPitch);
239 newchamber.stripWidthEta = (*stripEtaWidth);
240 newchamber.stripWidthPhi = (*stripPhiWidth);
241 newchamber.stripLengthEta = (*stripEtaLength);
242 newchamber.stripLengthPhi = (*stripPhiLength);
244 newchamber.numStripsEta = (*numStripsEta);
245 newchamber.numStripsPhi = (*numStripsPhi);
247 newchamber.numPhiPanels = (*numPhiPanels);
248 newchamber.numLayers = (*numLayers);
251 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
253 geoRot.col(0) =
Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
254 geoRot.col(1) =
Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
255 geoRot.col(2) =
Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
258 geoRot.col(0) =
Amg::Vector3D((*alignableNodeX)[1], (*alignableNodeY)[1], (*alignableNodeZ)[1]);
259 geoRot.col(1) =
Amg::Vector3D((*alignableNodeX)[2], (*alignableNodeY)[2], (*alignableNodeZ)[2]);
260 geoRot.col(2) =
Amg::Vector3D((*alignableNodeX)[3], (*alignableNodeY)[3], (*alignableNodeZ)[3]);
261 geoTrans =
Amg::Vector3D{(*alignableNodeX)[0], (*alignableNodeY)[0], (*alignableNodeZ)[0]};
265 for (
size_t s = 0;
s < stripPosX->size(); ++
s){
268 newStrip.locPos =
Amg::Vector2D{(*stripLocPosX)[
s], (*stripLocPosY)[
s]};
270 newStrip.gasGap = (*stripPosGasGap)[
s];
271 newStrip.doubletPhi = (*stripDblPhi)[
s];
272 newStrip.measPhi = (*stripPosMeasPhi)[
s];
273 newStrip.strip = (*stripPosNum)[
s];
274 newchamber.strips.insert(std::move(newStrip));
276 for (
size_t l = 0;
l < stripRotMeasPhi->size(); ++
l){
278 newLayer.
measPhi = (*stripRotMeasPhi)[
l];
279 newLayer.gasGap = (*stripRotGasGap)[
l];
280 newLayer.doubletPhi = (*stripRotDblPhi)[
l];
282 Amg::Vector3D translation{(*stripRotTranslationX)[
l],(*stripRotTranslationY)[
l],(*stripRotTranslationZ)[
l]};
283 stripRot.col(0) =
Amg::Vector3D((*stripRotCol1X)[
l],(*stripRotCol1Y)[
l], (*stripRotCol1Z)[
l]);
284 stripRot.col(1) =
Amg::Vector3D((*stripRotCol2X)[
l],(*stripRotCol2Y)[
l], (*stripRotCol2Z)[
l]);
285 stripRot.col(2) =
Amg::Vector3D((*stripRotCol3X)[
l],(*stripRotCol3Y)[
l], (*stripRotCol3Z)[
l]);
287 newchamber.layers.insert(std::move(newLayer));
290 auto insert_itr = to_ret.insert(std::move(newchamber));
291 if (!insert_itr.second) {
292 std::stringstream
err{};
293 err<<__FILE__<<
":"<<__LINE__<<
" The chamber "<<(*insert_itr.first).
id
294 <<
" has already been inserted. "<<std::endl;
295 throw std::runtime_error(
err.str());
298 std::cout<<
"File parsing is finished. Found in total "<<to_ret.size()<<
" readout element dumps "<<std::endl;
302 #define TEST_BASICPROP(attribute, propName) \
303 if (std::abs(1.*test.attribute - 1.*reference.attribute) > tolerance) { \
304 std::cerr<<"RpcGeoModelComparison() "<<__LINE__<<": The chamber "<<test \
305 <<" differs w.r.t "<<propName<<" "<< reference.attribute \
306 <<" (ref) vs. " <<test.attribute << " (test)" << std::endl; \
307 chamberOkay = false; \
314 std::string the_arg{
argv[
arg]};
315 if (the_arg ==
"--refFile" &&
arg +1 <
argc) {
316 refFile = std::string{
argv[
arg+1]};
318 }
else if (the_arg ==
"--testFile" &&
arg + 1 <
argc) {
323 if (refFile.empty()) {
324 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
328 std::cerr<<
"Please parse the path of the test file via --testFile "<<std::endl;
335 std::set<RpcChamber> refChambers =
readTreeDump(refFile);
336 if (refChambers.empty()) {
337 std::cerr<<
"The file "<<refFile<<
" should contain at least one chamber "<<std::endl;
341 if (testChambers.empty()) {
342 std::cerr<<
"The file "<<
testFile<<
" should contain at least one chamber "<<std::endl;
345 std::cout<<
"Read "<<refChambers.size()<<
" chambers from reference: "<<refFile
346 <<
" & "<<testChambers.size()<<
" from "<<
testFile<<std::endl;
347 int return_code = EXIT_SUCCESS;
348 unsigned int goodChambers{0};
351 std::set<RpcChamber>::const_iterator test_itr = testChambers.find(
reference);
353 if (test_itr == testChambers.end()) {
354 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": The chamber "<<
reference<<
" is not part of the testing "<<std::endl;
355 return_code = EXIT_FAILURE;
358 bool chamberOkay =
true;
377 if (!chamberOkay)
continue;
380 test.geoModelTransform;
383 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" is displaced by "
390 for (
const RpcLayer& refLayer :
reference.layers) {
392 std::set<RpcLayer>::const_iterator lay_itr =
test.layers.find(refLayer);
393 if (lay_itr ==
test.layers.end()) {
394 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
395 <<refLayer<<
" is not found. "<<std::endl;
400 const RpcLayer& testLayer{*lay_itr};
403 if (layAlignment.translation().mag() >
tolerance) {
404 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
405 <<
"the layer "<<testLayer<<
" is misplaced w.r.t. reference by "
407 <<
Amg::toString(refLayer.transform.translation()) <<
" delta : "
409 <<
", perp: "<<layAlignment.translation().perp()
410 <<
", mag: "<<layAlignment.translation().mag()<<std::endl;
416 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
417 <<
"the layer "<<testLayer<<
" is misaligned w.r.t. reference by "
423 if (!chamberOkay)
continue;
424 unsigned int failedEta{0}, failedPhi{0};
426 std::set<RpcStrip>::const_iterator strip_itr =
test.strips.find(refStrip);
427 if (strip_itr ==
test.strips.end()) {
428 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
429 <<refStrip<<
" is not found. "<<std::endl;
433 const RpcStrip& testStrip{*strip_itr};
434 const Amg::Vector3D diffStrip{testStrip.position - refStrip.position};
436 constexpr
unsigned int maxFail = 3;
437 if ( (!refStrip.measPhi && (++failedEta) <= maxFail) ||
438 (refStrip.measPhi && (++failedPhi) <= maxFail) ) {
439 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
440 <<testStrip<<
" should be located at "<<
Amg::toString(refStrip.position, 2)
442 <<diffStrip.perp()<<
", mag: "<<diffStrip.mag()<<std::endl;
443 }
else if (failedEta > maxFail && failedPhi > maxFail) {
449 const Amg::Vector2D diffLocStrip{testStrip.locPos - refStrip.locPos};
451 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
452 <<testStrip<<
" should be located at "<<
Amg::toString(refStrip.locPos, 2)
453 <<
" displacement: "<<
Amg::toString(diffLocStrip,2)<<
", mag: "<<diffLocStrip.mag()<<std::endl;
458 return_code = EXIT_FAILURE;
464 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": The alignable nodes are at differnt places for "
466 return_code = EXIT_FAILURE;
473 if (refChambers.find(
test) == refChambers.end()) {
474 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": The chamber "<<
test<<
" is not in the references."<<std::endl;
475 return_code = EXIT_FAILURE;
478 std::cout<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
479 goodChambers<<
"/"<<refChambers.size()<<
" chambers are in complete agreement. "<<std::endl;