14 #include <GaudiKernel/SystemOfUnits.h>
25 #include <TTreeReader.h>
46 if (stationIndex !=
other.stationIndex)
return stationIndex <
other.stationIndex;
47 if (stationEta !=
other.stationEta)
return stationEta <
other.stationEta;
48 if (stationPhi !=
other.stationPhi)
return stationPhi <
other.stationPhi;
49 return multilayer <
other.multilayer;
56 unsigned int nGasGaps{0};
59 double ActiveWidthS{0.};
60 double ActiveWidthL{0.};
61 double ActiveHeightR{0.};
62 double stripPitch{0.};
115 static const std::map<int, std::string> stationDict{
116 {55,
"MMS"}, {56,
"MML"}
124 ostr<<
"channel (gasGap/number): ";
126 ostr<<std::setfill(
'0')<<std::setw(4)<<
channel.channel<<
", ";
133 ostr<<
"Mmlayer (gasGap): ";
134 ostr<<
layer.gasGap<<
", ";
140 std::set<MmChamber> to_ret{};
141 std::cout<<
"Read the MicroMegas 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 'MmGeoModelTree'"<<std::endl;
154 TTreeReaderValue<unsigned short> stationIndex{
treeReader,
"stationIndex"};
155 TTreeReaderValue<short> stationEta{
treeReader,
"stationEta"};
156 TTreeReaderValue<short> stationPhi{
treeReader,
"stationPhi"};
157 TTreeReaderValue<short> multilayer{
treeReader,
"multilayer"};
162 TTreeReaderValue<std::vector<float>> stripLength{
treeReader,
"stripLength"};
164 TTreeReaderValue<std::vector<bool>> isStereo{
treeReader,
"isStereo"};
165 TTreeReaderValue<std::vector<float>> locStripCenterX{
treeReader,
"locStripCenterX"};
166 TTreeReaderValue<std::vector<float>> locStripCenterY{
treeReader,
"locStripCenterY"};
168 TTreeReaderValue<std::vector<float>> stripCenterX{
treeReader,
"stripCenterX"};
169 TTreeReaderValue<std::vector<float>> stripCenterY{
treeReader,
"stripCenterY"};
170 TTreeReaderValue<std::vector<float>> stripCenterZ{
treeReader,
"stripCenterZ"};
171 TTreeReaderValue<std::vector<float>> stripLeftEdgeX{
treeReader,
"stripLeftEdgeX"};
172 TTreeReaderValue<std::vector<float>> stripLeftEdgeY{
treeReader,
"stripLeftEdgeY"};
173 TTreeReaderValue<std::vector<float>> stripLeftEdgeZ{
treeReader,
"stripLeftEdgeZ"};
174 TTreeReaderValue<std::vector<float>> stripRightEdgeX{
treeReader,
"stripRightEdgeX"};
175 TTreeReaderValue<std::vector<float>> stripRightEdgeY{
treeReader,
"stripRightEdgeY"};
176 TTreeReaderValue<std::vector<float>> stripRightEdgeZ{
treeReader,
"stripRightEdgeZ"};
179 TTreeReaderValue<float> ActiveHeightR{
treeReader,
"ActiveHeightR"};
180 TTreeReaderValue<float> ActiveWidthS{
treeReader,
"ActiveWidthS"};
181 TTreeReaderValue<float> ActiveWidthL{
treeReader,
"ActiveWidthL"};
182 TTreeReaderValue<float> stripPitch{
treeReader,
"stripPitch"};
185 TTreeReaderValue<std::vector<float>> geoModelTransformX{
treeReader,
"GeoModelTransformX"};
186 TTreeReaderValue<std::vector<float>> geoModelTransformY{
treeReader,
"GeoModelTransformY"};
187 TTreeReaderValue<std::vector<float>> geoModelTransformZ{
treeReader,
"GeoModelTransformZ"};
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<float>> stripRotTransX{
treeReader,
"stripRotTranslationX"};
202 TTreeReaderValue<std::vector<float>> stripRotTransY{
treeReader,
"stripRotTranslationY"};
203 TTreeReaderValue<std::vector<float>> stripRotTransZ{
treeReader,
"stripRotTranslationZ"};
205 TTreeReaderValue<std::vector<uint8_t>> stripRotGasGap{
treeReader,
"stripRotGasGap"};
207 TTreeReaderValue<std::vector<float>> firstStripPosX{
treeReader,
"firstStripPosX"};
208 TTreeReaderValue<std::vector<float>> firstStripPosY{
treeReader,
"firstStripPosY"};
210 TTreeReaderValue<std::vector<int>> readoutSide{
treeReader,
"stripReadoutSide"};
211 TTreeReaderValue<std::vector<unsigned int>> firstStripNum{
treeReader,
"stripFirstStrip"};
219 newchamber.stationEta = (*stationEta);
220 newchamber.stationPhi = (*stationPhi);
221 newchamber.multilayer = (*multilayer);
224 newchamber.ActiveHeightR = (*ActiveHeightR);
225 newchamber.ActiveWidthS = (*ActiveWidthS);
226 newchamber.ActiveWidthL = (*ActiveWidthL);
227 newchamber.stripPitch = (*stripPitch);
229 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
231 geoRot.col(0) =
Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
232 geoRot.col(1) =
Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
233 geoRot.col(2) =
Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
237 for (
size_t s = 0;
s < stripCenterX->size(); ++
s){
240 newStrip.locCenter =
Amg::Vector2D{(*locStripCenterX)[
s], (*locStripCenterY)[
s]};
241 newStrip.leftEdge =
Amg::Vector3D{(*stripLeftEdgeX)[
s], (*stripLeftEdgeY)[
s], (*stripLeftEdgeZ)[
s]};
242 newStrip.rightEdge =
Amg::Vector3D{(*stripRightEdgeX)[
s], (*stripRightEdgeY)[
s], (*stripRightEdgeZ)[
s]};
244 newStrip.gasGap = (*gasGap)[
s];
245 newStrip.channel = (*channel)[
s];
246 newStrip.isStereo = (*isStereo)[
s];
247 newchamber.channels.insert(std::move(newStrip));
250 for (
size_t l = 0;
l < stripRotGasGap->size(); ++
l){
252 newLayer.
gasGap = (*stripRotGasGap)[
l];
254 stripRot.col(0) =
Amg::Vector3D((*stripRotCol1X)[
l],(*stripRotCol1Y)[
l], (*stripRotCol1Z)[
l]);
255 stripRot.col(1) =
Amg::Vector3D((*stripRotCol2X)[
l],(*stripRotCol2Y)[
l], (*stripRotCol2Z)[
l]);
256 stripRot.col(2) =
Amg::Vector3D((*stripRotCol3X)[
l],(*stripRotCol3Y)[
l], (*stripRotCol3Z)[
l]);
257 Amg::Vector3D layTrans{(*stripRotTransX)[
l], (*stripRotTransY)[
l], (*stripRotTransZ)[
l]};
259 newLayer.firstStripPos =
Amg::Vector2D{(*firstStripPosX)[
l], (*firstStripPosY)[
l]};
260 newLayer.readoutSide = (*readoutSide)[
l];
261 newLayer.firstStrip = (*firstStripNum)[
l];
262 newchamber.layers.insert(std::move(newLayer));
265 auto insert_itr = to_ret.insert(std::move(newchamber));
266 if (!insert_itr.second) {
267 std::stringstream
err{};
268 err<<__FILE__<<
":"<<__LINE__<<
" The chamber "<<(*insert_itr.first).stationIndex
269 <<
" has already been inserted. "<<std::endl;
270 throw std::runtime_error(
err.str());
273 std::cout<<
"File parsing is finished. Found in total "<<to_ret.size()<<
" readout element dumps "<<std::endl;
277 #define TEST_BASICPROP(attribute, propName) \
278 if (std::abs(1.*test.attribute - 1.*reference.attribute) > tolerance) { \
279 std::cerr<<"runMmGeoComparison() "<<__LINE__<<": The chamber "<<reference \
280 <<" differs w.r.t "<<propName<<" "<< reference.attribute \
281 <<" (ref) vs. " <<test.attribute << " (test)" << std::endl; \
282 chamberOkay = false; \
289 std::string the_arg{
argv[
arg]};
290 if (the_arg ==
"--refFile" &&
arg +1 <
argc) {
291 refFile = std::string{
argv[
arg+1]};
293 }
else if (the_arg ==
"--testFile" &&
arg + 1 <
argc) {
298 if (refFile.empty()) {
299 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
303 std::cerr<<
"Please parse the path of the test file via --testFile "<<std::endl;
310 std::set<MmChamber> refChambers =
readTreeDump(refFile);
311 if (refChambers.empty()) {
312 std::cerr<<
"The file "<<refFile<<
" should contain at least one chamber "<<std::endl;
316 if (testChambers.empty()) {
317 std::cerr<<
"The file "<<
testFile<<
" should contain at least one chamber "<<std::endl;
320 int return_code = EXIT_SUCCESS;
323 std::set<MmChamber>::const_iterator test_itr = testChambers.find(
reference);
325 if (test_itr == testChambers.end()) {
326 std::cerr<<
"The chamber "<<
reference<<
" is not part of the testing "<<std::endl;
327 return_code = EXIT_FAILURE;
330 bool chamberOkay{
true};
340 for (
const MmLayer& refLayer :
reference.layers) {
342 std::set<MmLayer>::const_iterator lay_itr =
test.layers.find(refLayer);
343 if (lay_itr ==
test.layers.end()) {
344 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<
test<<
" "
345 <<refLayer<<
" is not found. "<<std::endl;
349 const MmLayer& testLayer{*lay_itr};
350 if ( (refLayer.firstStripPos- testLayer.firstStripPos).mag() >
tolerance) {
351 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<
test<<
" "
352 <<testLayer.gasGap<<
" has different starting position "
355 <<
"difference: "<<
Amg::toString(refLayer.firstStripPos- testLayer.firstStripPos, 2)
356 <<
" / "<<(refLayer.firstStripPos- testLayer.firstStripPos).
mag()/
reference.stripPitch
360 if (refLayer.firstStrip != testLayer.firstStrip) {
361 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<
test<<
" "
362 <<testLayer.gasGap<<
" starts from different strip "<<refLayer.firstStrip<<
" vs. "
363 <<testLayer.firstStrip<<std::endl;
369 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<
test<<
" "
370 <<testLayer<<
" differs w.r.t. reference "<<
Amg::toString(refLayer.transform)<<
". vs. "
371 <<
Amg::toString(refLayer.transform.inverse()*testLayer.transform)<<std::endl;
375 unsigned int failedEta{0}, failedStereo{0};
377 std::set<MmChamber::MmChannel>::const_iterator strip_itr =
test.channels.find(refStrip);
378 if (strip_itr ==
test.channels.end()) {
379 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": in "<<
test<<
" "
380 <<refStrip<<
" is not found. "<<std::endl;
388 if (!refStrip.
isStereo && (failedEta <=10)) {
391 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": In "
395 <<
" displacement: "<<
Amg::toString(diffStrip, 2)<<
" "<<diffStrip.mag()<<std::endl;
406 else if (failedStereo <= 10) {
410 (testStrip.rightEdge - testStrip.leftEdge).
unit()};
411 const double centerDist = stripDir.dot(testStrip.globCenter - refStrip.
globCenter);
412 const double leftDist = stripDir.dot(testStrip.leftEdge -refStrip.
globCenter);
413 const double rightDist = stripDir.dot(testStrip.rightEdge - refStrip.
globCenter);
415 std::cerr<<
"runMmGeoComparison() "<<__LINE__<<
": In "
418 <<
" does not describe the same stereo strip as "
420 <<
". Distances to the left-edge/center/right-edge: "
421 <<leftDist<<
"/"<<centerDist<<
"/"<<rightDist<<
", dot: "
422 <<std::acos(std::clamp(stripDir.dot(testDir),- 1., 1.)) /
Gaudi::Units::deg<<std::endl;
430 return_code = EXIT_FAILURE;