143 std::set<RpcChamber> to_ret{};
144 std::cout<<
"Read the Rpc geometry tree dump from "<<inputFile<<std::endl;
145 std::unique_ptr<TFile> inFile{TFile::Open(inputFile.c_str())};
146 if (!inFile || !inFile->IsOpen()) {
147 std::cerr<<__FILE__<<
":"<<__LINE__<<
" Failed to open "<<inputFile<<std::endl;
150 TTreeReader treeReader(
"RpcGeoModelTree", inFile.get());
151 if (treeReader.IsInvalid()){
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"};
171 TTreeReaderValue<uint8_t> numLayers{treeReader,
"numRpcLayers"};
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"};
226 while (treeReader.Next()) {
230 newchamber.
design = (*chamberDesign);
231 newchamber.
id.
eta = (*stationEta);
232 newchamber.
id.
phi = (*stationPhi);
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){
270 newStrip.
gasGap = (*stripPosGasGap)[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];
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;
310int main(
int argc,
char** argv ) {
311 std::string refFile{}, testFile{};
313 for (
int arg = 1; arg < argc; ++arg) {
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) {
319 testFile = std::string{argv[arg+1]};
323 if (refFile.empty()) {
324 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
327 if (testFile.empty()) {
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;
340 std::set<RpcChamber> testChambers =
readTreeDump(testFile);
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 "
418 <<GeoTrf::toString(layAlignment,
true)<<std::endl;
423 if (!chamberOkay)
continue;
424 unsigned int failedEta{0}, failedPhi{0};
425 for (
const RpcStrip& refStrip :
reference.strips) {
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 || refStrip.strip <= 3)) ||
438 (refStrip.measPhi && ( (++failedPhi) <= maxFail || refStrip.strip <= 3)) ) {
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 "
465 <<test<<
". " <<
Amg::toString(alignableDistort,
true)<<std::endl;
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;