151 std::set<RpcChamber> to_ret{};
152 std::cout<<
"Read the Rpc geometry tree dump from "<<inputFile<<std::endl;
153 std::unique_ptr<TFile> inFile{TFile::Open(inputFile.c_str())};
154 if (!inFile || !inFile->IsOpen()) {
155 std::cerr<<__FILE__<<
":"<<__LINE__<<
" Failed to open "<<inputFile<<std::endl;
158 TTreeReader treeReader(
"RpcGeoModelTree", inFile.get());
159 if (treeReader.IsInvalid()){
160 std::cerr<<__FILE__<<
":"<<__LINE__<<
" The file "<<inputFile<<
" does not contain the 'RpcGeoModelTree'"<<std::endl;
164 TTreeReaderValue<unsigned short> stationIndex{treeReader,
"stationIndex"};
165 TTreeReaderValue<short> stationEta{treeReader,
"stationEta"};
166 TTreeReaderValue<short> stationPhi{treeReader,
"stationPhi"};
167 TTreeReaderValue<uint8_t> stationDoubletR{treeReader,
"stationDoubletR"};
168 TTreeReaderValue<uint8_t> stationDoubletZ{treeReader,
"stationDoubletZ"};
169 TTreeReaderValue<uint8_t> stationDoubletPhi{treeReader,
"stationDoubletPhi"};
170 TTreeReaderValue<std::string> chamberDesign{treeReader,
"chamberDesign"};
174 TTreeReaderValue<uint8_t> numStripsEta{treeReader,
"numEtaStrips"};
175 TTreeReaderValue<uint8_t> numStripsPhi{treeReader,
"numPhiStrips"};
178 TTreeReaderValue<uint8_t> numPhiPanels{treeReader,
"numPhiPanels"};
179 TTreeReaderValue<uint8_t> numLayers{treeReader,
"numRpcLayers"};
182 TTreeReaderValue<float> stripEtaPitch{treeReader,
"stripEtaPitch"};
183 TTreeReaderValue<float> stripPhiPitch{treeReader,
"stripPhiPitch"};
184 TTreeReaderValue<float> stripEtaWidth{treeReader,
"stripEtaWidth"};
185 TTreeReaderValue<float> stripPhiWidth{treeReader,
"stripPhiWidth"};
186 TTreeReaderValue<float> stripEtaLength{treeReader,
"stripEtaLength"};
187 TTreeReaderValue<float> stripPhiLength{treeReader,
"stripPhiLength"};
190 TTreeReaderValue<std::vector<float>> geoModelTransformX{treeReader,
"GeoModelTransformX"};
191 TTreeReaderValue<std::vector<float>> geoModelTransformY{treeReader,
"GeoModelTransformY"};
192 TTreeReaderValue<std::vector<float>> geoModelTransformZ{treeReader,
"GeoModelTransformZ"};
194 TTreeReaderValue<std::vector<float>> alignableNodeX{treeReader,
"AlignableNodeX"};
195 TTreeReaderValue<std::vector<float>> alignableNodeY{treeReader,
"AlignableNodeY"};
196 TTreeReaderValue<std::vector<float>> alignableNodeZ{treeReader,
"AlignableNodeZ"};
200 TTreeReaderValue<std::vector<float>> stripRotTranslationX{treeReader,
"stripRotTranslationX"};
201 TTreeReaderValue<std::vector<float>> stripRotTranslationY{treeReader,
"stripRotTranslationY"};
202 TTreeReaderValue<std::vector<float>> stripRotTranslationZ{treeReader,
"stripRotTranslationZ"};
204 TTreeReaderValue<std::vector<float>> stripRotCol0Theta{treeReader,
"stripRotLinearCol0Theta"};
205 TTreeReaderValue<std::vector<float>> stripRotCol0Phi{treeReader,
"stripRotLinearCol0Phi"};
207 TTreeReaderValue<std::vector<float>> stripRotCol1Theta{treeReader,
"stripRotLinearCol1Theta"};
208 TTreeReaderValue<std::vector<float>> stripRotCol1Phi{treeReader,
"stripRotLinearCol1Phi"};
210 TTreeReaderValue<std::vector<float>> stripRotCol2Theta{treeReader,
"stripRotLinearCol2Theta"};
211 TTreeReaderValue<std::vector<float>> stripRotCol2Phi{treeReader,
"stripRotLinearCol2Phi"};
213 TTreeReaderValue<std::vector<uint8_t>> stripRotGasGap{treeReader,
"stripRotGasGap"};
214 TTreeReaderValue<std::vector<uint8_t>> stripRotDblPhi{treeReader,
"stripRotDoubletPhi"};
215 TTreeReaderValue<std::vector<bool>> stripRotMeasPhi{treeReader,
"stripRotMeasPhi"};
217 TTreeReaderValue<std::vector<float>> stripPosX{treeReader,
"stripPosX"};
218 TTreeReaderValue<std::vector<float>> stripPosY{treeReader,
"stripPosY"};
219 TTreeReaderValue<std::vector<float>> stripPosZ{treeReader,
"stripPosZ"};
221 TTreeReaderValue<std::vector<float>> stripLocPosX{treeReader,
"stripLocPosX"};
222 TTreeReaderValue<std::vector<float>> stripLocPosY{treeReader,
"stripLocPosY"};
225 TTreeReaderValue<std::vector<bool>> stripPosMeasPhi{treeReader,
"stripPosMeasPhi"};
226 TTreeReaderValue<std::vector<uint8_t>> stripPosGasGap{treeReader,
"stripPosGasGap"};
227 TTreeReaderValue<std::vector<uint8_t>> stripPosNum{treeReader,
"stripPosNum"};
228 TTreeReaderValue<std::vector<uint8_t>> stripDblPhi{treeReader,
"stripPosDoubletPhi"};
230 while (treeReader.Next()) {
234 newchamber.
design = (*chamberDesign);
235 newchamber.
id.
eta = (*stationEta);
236 newchamber.
id.
phi = (*stationPhi);
255 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
257 geoRot.col(0) =
Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
258 geoRot.col(1) =
Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
259 geoRot.col(2) =
Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
262 geoRot.col(0) =
Amg::Vector3D((*alignableNodeX)[1], (*alignableNodeY)[1], (*alignableNodeZ)[1]);
263 geoRot.col(1) =
Amg::Vector3D((*alignableNodeX)[2], (*alignableNodeY)[2], (*alignableNodeZ)[2]);
264 geoRot.col(2) =
Amg::Vector3D((*alignableNodeX)[3], (*alignableNodeY)[3], (*alignableNodeZ)[3]);
265 geoTrans =
Amg::Vector3D{(*alignableNodeX)[0], (*alignableNodeY)[0], (*alignableNodeZ)[0]};
269 for (
size_t s = 0; s < stripPosX->size(); ++s){
274 newStrip.
gasGap = (*stripPosGasGap)[s];
276 newStrip.
measPhi = (*stripPosMeasPhi)[s];
277 newStrip.
strip = (*stripPosNum)[s];
278 newchamber.
strips.insert(std::move(newStrip));
280 for (
size_t l = 0; l < stripRotMeasPhi->size(); ++l){
282 newLayer.
measPhi = (*stripRotMeasPhi)[l];
283 newLayer.
gasGap = (*stripRotGasGap)[l];
286 Amg::Vector3D translation{(*stripRotTranslationX)[l],(*stripRotTranslationY)[l],(*stripRotTranslationZ)[l]};
287 stripRot.col(0) =
makeDir((*stripRotCol0Theta)[l], (*stripRotCol0Phi)[l]);
288 stripRot.col(1) =
makeDir((*stripRotCol1Theta)[l], (*stripRotCol1Phi)[l]);
289 stripRot.col(2) =
makeDir((*stripRotCol2Theta)[l], (*stripRotCol2Phi)[l]);
291 newchamber.
layers.insert(std::move(newLayer));
294 auto insert_itr = to_ret.insert(std::move(newchamber));
295 if (!insert_itr.second) {
296 std::stringstream err{};
297 err<<__FILE__<<
":"<<__LINE__<<
" The chamber "<<(*insert_itr.first).
id
298 <<
" has already been inserted. "<<std::endl;
299 throw std::runtime_error(err.str());
302 std::cout<<
"File parsing is finished. Found in total "<<to_ret.size()<<
" readout element dumps "<<std::endl;
315 std::string refFile{}, testFile{};
317 for (
int arg = 1; arg < argc; ++arg) {
318 std::string the_arg{argv[arg]};
319 if (the_arg ==
"--refFile" && arg +1 < argc) {
320 refFile = std::string{argv[arg+1]};
322 }
else if (the_arg ==
"--testFile" && arg + 1 < argc) {
323 testFile = std::string{argv[arg+1]};
327 if (refFile.empty()) {
328 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
331 if (testFile.empty()) {
332 std::cerr<<
"Please parse the path of the test file via --testFile "<<std::endl;
339 std::set<RpcChamber> refChambers =
readTreeDump(refFile);
340 if (refChambers.empty()) {
341 std::cerr<<
"The file "<<refFile<<
" should contain at least one chamber "<<std::endl;
344 std::set<RpcChamber> testChambers =
readTreeDump(testFile);
345 if (testChambers.empty()) {
346 std::cerr<<
"The file "<<testFile<<
" should contain at least one chamber "<<std::endl;
349 std::cout<<
"Read "<<refChambers.size()<<
" chambers from reference: "<<refFile
350 <<
" & "<<testChambers.size()<<
" from "<<testFile<<std::endl;
351 int return_code = EXIT_SUCCESS;
352 unsigned int goodChambers{0};
355 std::set<RpcChamber>::const_iterator test_itr = testChambers.find(
reference);
357 if (test_itr == testChambers.end()) {
358 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": The chamber "<<
reference<<
" is not part of the testing "<<std::endl;
359 return_code = EXIT_FAILURE;
362 bool chamberOkay =
true;
381 if (!chamberOkay)
continue;
384 test.geoModelTransform;
387 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<test<<
" is displaced by "
394 for (
const RpcLayer& refLayer :
reference.layers) {
396 std::set<RpcLayer>::const_iterator lay_itr = test.layers.find(refLayer);
397 if (lay_itr == test.layers.end()) {
398 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<test<<
" "
399 <<refLayer<<
" is not found. "<<std::endl;
404 const RpcLayer& testLayer{*lay_itr};
407 if (layAlignment.translation().mag() >
tolerance) {
408 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<test<<
" "
409 <<
"the layer "<<testLayer<<
" is misplaced w.r.t. reference by "
411 <<
Amg::toString(refLayer.transform.translation()) <<
" delta : "
413 <<
", perp: "<<layAlignment.translation().perp()
414 <<
", mag: "<<layAlignment.translation().mag()<<std::endl;
420 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<test<<
" "
421 <<
"the layer "<<testLayer<<
" is misaligned w.r.t. reference by "
422 <<GeoTrf::toString(layAlignment,
true)<<std::endl;
427 if (!chamberOkay)
continue;
428 unsigned int failedEta{0}, failedPhi{0};
429 for (
const RpcStrip& refStrip :
reference.strips) {
430 std::set<RpcStrip>::const_iterator strip_itr = test.strips.find(refStrip);
431 if (strip_itr == test.strips.end()) {
432 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<test<<
" "
433 <<refStrip<<
" is not found. "<<std::endl;
437 const RpcStrip& testStrip{*strip_itr};
438 const Amg::Vector3D diffStrip{testStrip.position - refStrip.position};
440 constexpr unsigned int maxFail = 3;
441 if ( (!refStrip.measPhi && ( (++failedEta) <= maxFail || refStrip.strip <= 3)) ||
442 (refStrip.measPhi && ( (++failedPhi) <= maxFail || refStrip.strip <= 3)) ) {
443 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<test<<
" "
444 <<testStrip<<
" should be located at "<<
Amg::toString(refStrip.position, 2)
446 <<diffStrip.perp()<<
", mag: "<<diffStrip.mag()<<std::endl;
447 }
else if (failedEta > maxFail && failedPhi > maxFail) {
453 const Amg::Vector2D diffLocStrip{testStrip.locPos - refStrip.locPos};
455 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<test<<
" "
456 <<testStrip<<
" should be located at "<<
Amg::toString(refStrip.locPos, 2)
457 <<
" displacement: "<<
Amg::toString(diffLocStrip,2)<<
", mag: "<<diffLocStrip.mag()<<std::endl;
462 return_code = EXIT_FAILURE;
468 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": The alignable nodes are at differnt places for "
469 <<test<<
". " <<
Amg::toString(alignableDistort,
true)<<std::endl;
470 return_code = EXIT_FAILURE;
477 if (refChambers.find(test) == refChambers.end()) {
478 std::cerr<<
"runRpcGeoComparison() "<<__LINE__<<
": The chamber "<<test<<
" is not in the references."<<std::endl;
479 return_code = EXIT_FAILURE;
482 std::cout<<
"runRpcGeoComparison() "<<__LINE__<<
": "<<
483 goodChambers<<
"/"<<refChambers.size()<<
" chambers are in complete agreement. "<<std::endl;