158 std::set<MmChamber> to_ret{};
159 std::cout<<
"Read the MicroMegas geometry tree dump from "<<inputFile<<std::endl;
160 std::unique_ptr<TFile> inFile{TFile::Open(inputFile.c_str())};
161 if (!inFile || !inFile->IsOpen()) {
162 std::cerr<<__FILE__<<
":"<<__LINE__<<
" Failed to open "<<inputFile<<std::endl;
165 TTreeReader treeReader(
"MmGeoModelTree", inFile.get());
166 if (treeReader.IsInvalid()){
167 std::cerr<<__FILE__<<
":"<<__LINE__<<
" The file "<<inputFile<<
" does not contain the 'MmGeoModelTree'"<<std::endl;
172 TTreeReaderValue<unsigned short> stationIndex{treeReader,
"stationIndex"};
173 TTreeReaderValue<short> stationEta{treeReader,
"stationEta"};
174 TTreeReaderValue<short> stationPhi{treeReader,
"stationPhi"};
175 TTreeReaderValue<short> multilayer{treeReader,
"multilayer"};
178 TTreeReaderValue<std::vector<uint>> channel{treeReader,
"channel"};
179 TTreeReaderValue<std::vector<short>> gasGap{treeReader,
"gasGap"};
180 TTreeReaderValue<std::vector<float>> stripLength{treeReader,
"stripLength"};
182 TTreeReaderValue<std::vector<bool>> isStereo{treeReader,
"isStereo"};
183 TTreeReaderValue<std::vector<float>> locStripCenterX{treeReader,
"locStripCenterX"};
184 TTreeReaderValue<std::vector<float>> locStripCenterY{treeReader,
"locStripCenterY"};
186 TTreeReaderValue<std::vector<float>> stripCenterX{treeReader,
"stripCenterX"};
187 TTreeReaderValue<std::vector<float>> stripCenterY{treeReader,
"stripCenterY"};
188 TTreeReaderValue<std::vector<float>> stripCenterZ{treeReader,
"stripCenterZ"};
189 TTreeReaderValue<std::vector<float>> stripLeftEdgeX{treeReader,
"stripLeftEdgeX"};
190 TTreeReaderValue<std::vector<float>> stripLeftEdgeY{treeReader,
"stripLeftEdgeY"};
191 TTreeReaderValue<std::vector<float>> stripLeftEdgeZ{treeReader,
"stripLeftEdgeZ"};
192 TTreeReaderValue<std::vector<float>> stripRightEdgeX{treeReader,
"stripRightEdgeX"};
193 TTreeReaderValue<std::vector<float>> stripRightEdgeY{treeReader,
"stripRightEdgeY"};
194 TTreeReaderValue<std::vector<float>> stripRightEdgeZ{treeReader,
"stripRightEdgeZ"};
197 TTreeReaderValue<float> ActiveHeightR{treeReader,
"ActiveHeightR"};
198 TTreeReaderValue<float> ActiveWidthS{treeReader,
"ActiveWidthS"};
199 TTreeReaderValue<float> ActiveWidthL{treeReader,
"ActiveWidthL"};
202 TTreeReaderValue<float> moduleHeight{treeReader,
"moduleHeight"};
203 TTreeReaderValue<float> moduleWidthS{treeReader,
"moduleWidthS"};
204 TTreeReaderValue<float> moduleWidthL{treeReader,
"moduleWidthL"};
206 TTreeReaderValue<float> stripPitch{treeReader,
"stripPitch"};
209 TTreeReaderValue<std::vector<float>> geoModelTransformX{treeReader,
"GeoModelTransformX"};
210 TTreeReaderValue<std::vector<float>> geoModelTransformY{treeReader,
"GeoModelTransformY"};
211 TTreeReaderValue<std::vector<float>> geoModelTransformZ{treeReader,
"GeoModelTransformZ"};
213 TTreeReaderValue<std::vector<float>> alignableNodeX{treeReader,
"AlignableNodeX"};
214 TTreeReaderValue<std::vector<float>> alignableNodeY{treeReader,
"AlignableNodeY"};
215 TTreeReaderValue<std::vector<float>> alignableNodeZ{treeReader,
"AlignableNodeZ"};
217 TTreeReaderValue<std::vector<float>> stripRotCol0Theta{treeReader,
"stripRotLinearCol0Theta"};
218 TTreeReaderValue<std::vector<float>> stripRotCol0Phi{treeReader,
"stripRotLinearCol0Phi"};
220 TTreeReaderValue<std::vector<float>> stripRotCol1Theta{treeReader,
"stripRotLinearCol1Theta"};
221 TTreeReaderValue<std::vector<float>> stripRotCol1Phi{treeReader,
"stripRotLinearCol1Phi"};
223 TTreeReaderValue<std::vector<float>> stripRotCol2Theta{treeReader,
"stripRotLinearCol2Theta"};
224 TTreeReaderValue<std::vector<float>> stripRotCol2Phi{treeReader,
"stripRotLinearCol2Phi"};
227 TTreeReaderValue<std::vector<float>> stripRotTransX{treeReader,
"stripRotTranslationX"};
228 TTreeReaderValue<std::vector<float>> stripRotTransY{treeReader,
"stripRotTranslationY"};
229 TTreeReaderValue<std::vector<float>> stripRotTransZ{treeReader,
"stripRotTranslationZ"};
231 TTreeReaderValue<std::vector<uint8_t>> stripRotGasGap{treeReader,
"stripRotGasGap"};
233 TTreeReaderValue<std::vector<float>> firstStripPosX{treeReader,
"firstStripPosX"};
234 TTreeReaderValue<std::vector<float>> firstStripPosY{treeReader,
"firstStripPosY"};
236 TTreeReaderValue<std::vector<int>> readoutSide{treeReader,
"stripReadoutSide"};
237 TTreeReaderValue<std::vector<unsigned int>> firstStrip{treeReader,
"firstStrip"};
238 TTreeReaderValue<std::vector<unsigned int>> nStrips{treeReader,
"nStrips"};
242 while (treeReader.Next()) {
260 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
262 geoRot.col(0) =
Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
263 geoRot.col(1) =
Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
264 geoRot.col(2) =
Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
267 geoRot.col(0) =
Amg::Vector3D((*alignableNodeX)[1], (*alignableNodeY)[1], (*alignableNodeZ)[1]);
268 geoRot.col(1) =
Amg::Vector3D((*alignableNodeX)[2], (*alignableNodeY)[2], (*alignableNodeZ)[2]);
269 geoRot.col(2) =
Amg::Vector3D((*alignableNodeX)[3], (*alignableNodeY)[3], (*alignableNodeZ)[3]);
270 geoTrans =
Amg::Vector3D{(*alignableNodeX)[0], (*alignableNodeY)[0], (*alignableNodeZ)[0]};
273 for (
size_t s = 0; s < stripCenterX->size(); ++s){
280 newStrip.
gasGap = (*gasGap)[s];
281 newStrip.
channel = (*channel)[s];
284 newchamber.
channels.insert(std::move(newStrip));
287 for (
size_t l = 0; l < stripRotGasGap->size(); ++l){
289 newLayer.
gasGap = (*stripRotGasGap)[l];
291 stripRot.col(0) =
makeDir((*stripRotCol0Theta)[l], (*stripRotCol0Phi)[l]);
292 stripRot.col(1) =
makeDir((*stripRotCol1Theta)[l], (*stripRotCol1Phi)[l]);
293 stripRot.col(2) =
makeDir((*stripRotCol2Theta)[l], (*stripRotCol2Phi)[l]);
294 Amg::Vector3D layTrans{(*stripRotTransX)[l], (*stripRotTransY)[l], (*stripRotTransZ)[l]};
299 newLayer.
nStrips = (*nStrips)[l];
301 newchamber.
layers.insert(std::move(newLayer));
304 auto insert_itr = to_ret.insert(std::move(newchamber));
305 if (!insert_itr.second) {
306 std::stringstream err{};
307 err<<__FILE__<<
":"<<__LINE__<<
" The chamber "<<(*insert_itr.first).stationIndex
308 <<
" has already been inserted. "<<std::endl;
309 throw std::runtime_error(err.str());
312 std::cout<<
"File parsing is finished. Found in total "<<to_ret.size()<<
" readout element dumps "<<std::endl;
326 std::string refFile{}, testFile{};
328 for (
int arg = 1; arg < argc; ++arg) {
329 std::string the_arg{argv[arg]};
330 if (the_arg ==
"--refFile" && arg +1 < argc) {
331 refFile = std::string{argv[arg+1]};
333 }
else if (the_arg ==
"--testFile" && arg + 1 < argc) {
334 testFile = std::string{argv[arg+1]};
338 if (refFile.empty()) {
339 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
342 if (testFile.empty()) {
343 std::cerr<<
"Please parse the path of the test file via --testFile "<<std::endl;
350 std::set<MmChamber> refChambers =
readTreeDump(refFile);
351 if (refChambers.empty()) {
352 std::cerr<<
"The file "<<refFile<<
" should contain at least one chamber "<<std::endl;
355 std::set<MmChamber> testChambers =
readTreeDump(testFile);
356 if (testChambers.empty()) {
357 std::cerr<<
"The file "<<testFile<<
" should contain at least one chamber "<<std::endl;
360 int return_code = EXIT_SUCCESS;
363 std::set<MmChamber>::const_iterator test_itr = testChambers.find(
reference);
365 if (test_itr == testChambers.end()) {
366 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": The chamber "<<
reference
367 <<
" is not part of the testing "<<std::endl;
368 return_code = EXIT_FAILURE;
371 bool chamberOkay{
true};
376 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": The alignable nodes are at differnt places for "
377 <<test<<
". " <<
Amg::toString(alignableDistort, 3)<<std::endl;
384 constexpr double tolerance = 3. * Gaudi::Units::mm;
397 for (
const MmLayer& refLayer :
reference.layers) {
398 std::set<MmLayer>::const_iterator lay_itr = test.layers.find(refLayer);
399 if (lay_itr == test.layers.end()) {
400 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<test<<
" "
401 <<refLayer<<
" is not found. "<<std::endl;
405 const MmLayer& testLayer{*lay_itr};
406 if (!
Amg::isIdentity(refLayer.transform.inverse()* testLayer.transform)){
407 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<test<<
" "
408 <<testLayer<<
" differs w.r.t. reference. delta: "
409 <<
Amg::toString(refLayer.transform.inverse()*testLayer.transform)<<std::endl;
412 if (refLayer.firstStrip != testLayer.firstStrip) {
413 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<test<<
" "
414 <<testLayer.gasGap<<
" starts from different strip "<<refLayer.firstStrip<<
" vs. "
415 <<testLayer.firstStrip<<std::endl;
418 if (refLayer.nStrips != testLayer.nStrips) {
419 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<test<<
" "
420 <<testLayer.gasGap<<
" has different number of strips "<<refLayer.nStrips<<
" vs. "
421 <<testLayer.nStrips<<std::endl;
425 if (
false && (refLayer.firstStripPos- testLayer.firstStripPos).mag() >
tolerance) {
426 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<test<<
" "
427 <<testLayer.gasGap<<
" has different starting position "
430 <<
"difference: "<<
Amg::toString(refLayer.firstStripPos- testLayer.firstStripPos, 2)
431 <<
" / "<<(refLayer.firstStripPos- testLayer.firstStripPos).
mag()/
reference.stripPitch
436 if (!chamberOkay)
continue;
437 unsigned int failedEta{0}, lastGap{0};
439 std::set<MmChamber::MmChannel>::const_iterator strip_itr = test.channels.find(refStrip);
440 if (strip_itr == test.channels.end()) {
441 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<test<<
" "
442 <<refStrip<<
" is not found. "<<std::endl;
446 if (lastGap != refStrip.
gasGap) {
447 lastGap = refStrip.
gasGap;
457 if (failedEta <= 10) {
466 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": In "
469 <<
" does not describe the same stereo strip as "
472 <<
". Distances to the left-edge/center/right-edge: "
473 <<leftDist<<
"/"<<centerDist<<
"/"<<rightDist<<
", dot: "
474 <<std::acos(std::clamp(stripDir.dot(testDir),- 1., 1.)) / Gaudi::Units::deg<<std::endl;
482 return_code = EXIT_FAILURE;