17 #include <GaudiKernel/SystemOfUnits.h>
22 #include <TTreeReader.h>
47 float stripPitchEta{0.f};
48 float stripPitchPhi{0.f};
49 float stripWidthEta{0.f};
50 float stripWidthPhi{0.f};
52 float stripLengthEta{0.f};
53 float stripLengthPhi{0.f};
55 unsigned int numStripsEta{0};
56 unsigned int numStripsPhi{0};
60 unsigned int numGasGapsPhi{0};
62 unsigned int numPhiPanels{0};
70 unsigned int strip{0};
80 if (measPhi !=
other.measPhi)
return !measPhi;
83 return strip <
other.strip;
98 if (measPhi !=
other.measPhi)
return !measPhi;
103 std::set<RpcStrip> strips{};
111 static const std::map<int, std::string> stationDict{
112 {0,
"BIL"}, {1,
"BIS"}, {7,
"BIR"},
113 {2,
"BML"}, {3,
"BMS"}, {8,
"BMF"}, {53,
"BME"}, {54,
"BMG"}, {52,
"BIM"},
114 {4,
"BOL"}, {5,
"BOS"}, {9,
"BOF"}, {10,
"BOG"},
115 {6,
"BEE"}, {14,
"EEL"}, {15,
"EES"},
117 {17,
"EML"}, {18,
"EMS"},
118 {20,
"EOL"}, {21,
"EOS"}
125 ostr<<
"strip (gasGap/phiPanel/isPhiStrip/number): ";
126 ostr<<strip.gasGap<<
"/"<<strip.doubletPhi<<
"/";
127 ostr<<(strip.measPhi ?
"si" :
"no")<<
"/"<<strip.strip<<
", ";
132 ostr<<
"rpclayer (gasGap/phiPanel/isPhiLayer): ";
133 ostr<<
layer.gasGap<<
"/"<<
layer.doubletPhi<<
"/";
134 ostr<<(
layer.measPhi ?
"si" :
"no")<<
", ";
140 std::set<RpcChamber> to_ret{};
141 std::cout<<
"Read the Rpc geometry tree dump from "<<
inputFile<<std::endl;
144 std::cerr<<__FILE__<<
":"<<__LINE__<<
" Failed to open "<<
inputFile<<std::endl;
149 std::cerr<<__FILE__<<
":"<<__LINE__<<
" The file "<<
inputFile<<
" does not contain the 'RpcGeoModelTree'"<<std::endl;
153 TTreeReaderValue<unsigned short> stationIndex{
treeReader,
"stationIndex"};
154 TTreeReaderValue<short> stationEta{
treeReader,
"stationEta"};
155 TTreeReaderValue<short> stationPhi{
treeReader,
"stationPhi"};
156 TTreeReaderValue<uint8_t> stationDoubletR{
treeReader,
"stationDoubletR"};
157 TTreeReaderValue<uint8_t> stationDoubletZ{
treeReader,
"stationDoubletZ"};
158 TTreeReaderValue<uint8_t> stationDoubletPhi{
treeReader,
"stationDoubletPhi"};
159 TTreeReaderValue<std::string> chamberDesign{
treeReader,
"chamberDesign"};
163 TTreeReaderValue<uint8_t> numStripsEta{
treeReader,
"numEtaStrips"};
164 TTreeReaderValue<uint8_t> numStripsPhi{
treeReader,
"numPhiStrips"};
167 TTreeReaderValue<uint8_t> numPhiPanels{
treeReader,
"numPhiPanels"};
171 TTreeReaderValue<float> stripEtaPitch{
treeReader,
"stripEtaPitch"};
172 TTreeReaderValue<float> stripPhiPitch{
treeReader,
"stripPhiPitch"};
173 TTreeReaderValue<float> stripEtaWidth{
treeReader,
"stripEtaWidth"};
174 TTreeReaderValue<float> stripPhiWidth{
treeReader,
"stripPhiWidth"};
175 TTreeReaderValue<float> stripEtaLength{
treeReader,
"stripEtaLength"};
176 TTreeReaderValue<float> stripPhiLength{
treeReader,
"stripPhiLength"};
179 TTreeReaderValue<std::vector<float>> geoModelTransformX{
treeReader,
"GeoModelTransformX"};
180 TTreeReaderValue<std::vector<float>> geoModelTransformY{
treeReader,
"GeoModelTransformY"};
181 TTreeReaderValue<std::vector<float>> geoModelTransformZ{
treeReader,
"GeoModelTransformZ"};
184 TTreeReaderValue<std::vector<float>> stripRotTranslationX{
treeReader,
"stripRotTranslationX"};
185 TTreeReaderValue<std::vector<float>> stripRotTranslationY{
treeReader,
"stripRotTranslationY"};
186 TTreeReaderValue<std::vector<float>> stripRotTranslationZ{
treeReader,
"stripRotTranslationZ"};
189 TTreeReaderValue<std::vector<float>> stripRotCol1X{
treeReader,
"stripRotLinearCol1X"};
190 TTreeReaderValue<std::vector<float>> stripRotCol1Y{
treeReader,
"stripRotLinearCol1Y"};
191 TTreeReaderValue<std::vector<float>> stripRotCol1Z{
treeReader,
"stripRotLinearCol1Z"};
193 TTreeReaderValue<std::vector<float>> stripRotCol2X{
treeReader,
"stripRotLinearCol2X"};
194 TTreeReaderValue<std::vector<float>> stripRotCol2Y{
treeReader,
"stripRotLinearCol2Y"};
195 TTreeReaderValue<std::vector<float>> stripRotCol2Z{
treeReader,
"stripRotLinearCol2Z"};
197 TTreeReaderValue<std::vector<float>> stripRotCol3X{
treeReader,
"stripRotLinearCol3X"};
198 TTreeReaderValue<std::vector<float>> stripRotCol3Y{
treeReader,
"stripRotLinearCol3Y"};
199 TTreeReaderValue<std::vector<float>> stripRotCol3Z{
treeReader,
"stripRotLinearCol3Z"};
201 TTreeReaderValue<std::vector<uint8_t>> stripRotGasGap{
treeReader,
"stripRotGasGap"};
202 TTreeReaderValue<std::vector<uint8_t>> stripRotDblPhi{
treeReader,
"stripRotDoubletPhi"};
203 TTreeReaderValue<std::vector<bool>> stripRotMeasPhi{
treeReader,
"stripRotMeasPhi"};
205 TTreeReaderValue<std::vector<float>> stripPosX{
treeReader,
"stripPosX"};
206 TTreeReaderValue<std::vector<float>> stripPosY{
treeReader,
"stripPosY"};
207 TTreeReaderValue<std::vector<float>> stripPosZ{
treeReader,
"stripPosZ"};
209 TTreeReaderValue<std::vector<float>> stripLocPosX{
treeReader,
"stripLocPosX"};
210 TTreeReaderValue<std::vector<float>> stripLocPosY{
treeReader,
"stripLocPosY"};
213 TTreeReaderValue<std::vector<bool>> stripPosMeasPhi{
treeReader,
"stripPosMeasPhi"};
214 TTreeReaderValue<std::vector<uint8_t>> stripPosGasGap{
treeReader,
"stripPosGasGap"};
215 TTreeReaderValue<std::vector<uint8_t>> stripPosNum{
treeReader,
"stripPosNum"};
216 TTreeReaderValue<std::vector<uint8_t>> stripDblPhi{
treeReader,
"stripPosDoubletPhi"};
222 newchamber.design = (*chamberDesign);
223 newchamber.id.eta = (*stationEta);
224 newchamber.id.phi = (*stationPhi);
225 newchamber.id.doubletPhi = (*stationDoubletPhi);
226 newchamber.id.doubletR = (*stationDoubletR);
227 newchamber.id.doubletZ = (*stationDoubletZ);
229 newchamber.stripPitchEta = (*stripEtaPitch);
230 newchamber.stripPitchPhi = (*stripPhiPitch);
231 newchamber.stripWidthEta = (*stripEtaWidth);
232 newchamber.stripWidthPhi = (*stripPhiWidth);
233 newchamber.stripLengthEta = (*stripEtaLength);
234 newchamber.stripLengthPhi = (*stripPhiLength);
236 newchamber.numStripsEta = (*numStripsEta);
237 newchamber.numStripsPhi = (*numStripsPhi);
239 newchamber.numPhiPanels = (*numPhiPanels);
240 newchamber.numLayers = (*numLayers);
243 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
245 geoRot.col(0) =
Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
246 geoRot.col(1) =
Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
247 geoRot.col(2) =
Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
251 for (
size_t s = 0;
s < stripPosX->size(); ++
s){
254 newStrip.locPos =
Amg::Vector2D{(*stripLocPosX)[
s], (*stripLocPosY)[
s]};
256 newStrip.gasGap = (*stripPosGasGap)[
s];
257 newStrip.doubletPhi = (*stripDblPhi)[
s];
258 newStrip.measPhi = (*stripPosMeasPhi)[
s];
259 newStrip.strip = (*stripPosNum)[
s];
260 newchamber.strips.insert(std::move(newStrip));
262 for (
size_t l = 0;
l < stripRotMeasPhi->size(); ++
l){
264 newLayer.
measPhi = (*stripRotMeasPhi)[
l];
265 newLayer.gasGap = (*stripRotGasGap)[
l];
266 newLayer.doubletPhi = (*stripRotDblPhi)[
l];
268 Amg::Vector3D translation{(*stripRotTranslationX)[
l],(*stripRotTranslationY)[
l],(*stripRotTranslationZ)[
l]};
269 stripRot.col(0) =
Amg::Vector3D((*stripRotCol1X)[
l],(*stripRotCol1Y)[
l], (*stripRotCol1Z)[
l]);
270 stripRot.col(1) =
Amg::Vector3D((*stripRotCol2X)[
l],(*stripRotCol2Y)[
l], (*stripRotCol2Z)[
l]);
271 stripRot.col(2) =
Amg::Vector3D((*stripRotCol3X)[
l],(*stripRotCol3Y)[
l], (*stripRotCol3Z)[
l]);
273 newchamber.layers.insert(std::move(newLayer));
276 auto insert_itr = to_ret.insert(std::move(newchamber));
277 if (!insert_itr.second) {
278 std::stringstream
err{};
279 err<<__FILE__<<
":"<<__LINE__<<
" The chamber "<<(*insert_itr.first).
id
280 <<
" has already been inserted. "<<std::endl;
281 throw std::runtime_error(
err.str());
284 std::cout<<
"File parsing is finished. Found in total "<<to_ret.size()<<
" readout element dumps "<<std::endl;
288 #define TEST_BASICPROP(attribute, propName) \
289 if (std::abs(1.*test.attribute - 1.*reference.attribute) > tolerance) { \
290 std::cerr<<"RpcGeoModelComparison() "<<__LINE__<<": The chamber "<<test \
291 <<" differs w.r.t "<<propName<<" "<< reference.attribute \
292 <<" (ref) vs. " <<test.attribute << " (test)" << std::endl; \
293 chamberOkay = false; \
300 std::string the_arg{
argv[
arg]};
301 if (the_arg ==
"--refFile" &&
arg +1 <
argc) {
302 refFile = std::string{
argv[
arg+1]};
304 }
else if (the_arg ==
"--testFile" &&
arg + 1 <
argc) {
309 if (refFile.empty()) {
310 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
314 std::cerr<<
"Please parse the path of the test file via --testFile "<<std::endl;
321 std::set<RpcChamber> refChambers =
readTreeDump(refFile);
322 if (refChambers.empty()) {
323 std::cerr<<
"The file "<<refFile<<
" should contain at least one chamber "<<std::endl;
327 if (testChambers.empty()) {
328 std::cerr<<
"The file "<<
testFile<<
" should contain at least one chamber "<<std::endl;
331 std::cout<<
"Read "<<refChambers.size()<<
" chambers from reference: "<<refFile
332 <<
" & "<<testChambers.size()<<
" from "<<
testFile<<std::endl;
333 int return_code = EXIT_SUCCESS;
334 unsigned int goodChambers{0};
337 std::set<RpcChamber>::const_iterator test_itr = testChambers.find(
reference);
339 if (test_itr == testChambers.end()) {
340 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": The chamber "<<
reference<<
" is not part of the testing "<<std::endl;
341 return_code = EXIT_FAILURE;
344 bool chamberOkay =
true;
363 if (!chamberOkay)
continue;
366 test.geoModelTransform;
369 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" is displaced by "
376 for (
const RpcLayer& refLayer :
reference.layers) {
378 std::set<RpcLayer>::const_iterator lay_itr =
test.layers.find(refLayer);
379 if (lay_itr ==
test.layers.end()) {
380 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
381 <<refLayer<<
" is not found. "<<std::endl;
386 const RpcLayer& testLayer{*lay_itr};
389 if (layAlignment.translation().mag() >
tolerance) {
390 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
391 <<
"the layer "<<testLayer<<
" is misplaced w.r.t. reference by "
393 <<
Amg::toString(refLayer.transform.translation()) <<
" delta : "
395 <<
", perp: "<<layAlignment.translation().perp()
396 <<
", mag: "<<layAlignment.translation().mag()<<std::endl;
402 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
403 <<
"the layer "<<testLayer<<
" is misaligned w.r.t. reference by "
409 if (!chamberOkay)
continue;
410 unsigned int failedEta{0}, failedPhi{0};
412 std::set<RpcStrip>::const_iterator strip_itr =
test.strips.find(refStrip);
413 if (strip_itr ==
test.strips.end()) {
414 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
415 <<refStrip<<
" is not found. "<<std::endl;
419 const RpcStrip& testStrip{*strip_itr};
420 const Amg::Vector3D diffStrip{testStrip.position - refStrip.position};
422 constexpr
unsigned int maxFail = 3;
423 if ( (!refStrip.measPhi && (++failedEta) <= maxFail) ||
424 (refStrip.measPhi && (++failedPhi) <= maxFail) ) {
425 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
426 <<testStrip<<
" should be located at "<<
Amg::toString(refStrip.position, 2)
428 <<diffStrip.perp()<<
", mag: "<<diffStrip.mag()<<std::endl;
429 }
else if (failedEta > maxFail && failedPhi > maxFail) {
435 const Amg::Vector2D diffLocStrip{testStrip.locPos - refStrip.locPos};
437 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
test<<
" "
438 <<testStrip<<
" should be located at "<<
Amg::toString(refStrip.locPos, 2)
439 <<
" displacement: "<<
Amg::toString(diffLocStrip,2)<<
", mag: "<<diffLocStrip.mag()<<std::endl;
444 return_code = EXIT_FAILURE;
450 if (refChambers.find(
test) == refChambers.end()) {
451 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": The chamber "<<
test<<
" is not in the references."<<std::endl;
452 return_code = EXIT_FAILURE;
455 std::cout<<goodChambers<<
"/"<<refChambers.size()<<
" are in complete agreement. "<<std::endl;