6 #include "GaudiKernel/SystemOfUnits.h"
13 #include "GeoModelHelpers/throwExcept.h"
28 ISvcLocator* pSvcLocator)
44 m_allCan = std::make_unique<TCanvas>(
"AllDisplays",
"AllDisplays", 800, 600);
47 return StatusCode::SUCCESS;
53 return StatusCode::SUCCESS;
69 const EventContext & ctx = Gaudi::Hive::currentContext();
86 std::set<const MuonR4::HoughSegmentSeed*> matchedSeeds{};
89 std::map<std::pair<const MuonGMR4::MuonChamber*, HepMC::ConstGenParticlePtr>, std::vector<const xAOD::MuonSimHit*>> simHitMap{};
90 for (
auto & collection : simHitCollections){
95 auto genLink = simHit->genParticleLink();
97 if (genLink.isValid()){
98 genParticle = genLink.cptr();
101 if (genParticle ==
nullptr)
continue;
102 simHitMap[std::make_pair(
id,genParticle)].push_back(simHit);
106 std::map<const MuonGMR4::MuonChamber*, std::vector<MuonR4::HoughSegmentSeed>> houghPeakMap{};
108 houghPeakMap.emplace(
max.chamber(),
max.getMaxima());
111 for (
auto & [stationAndParticle,
hits] : simHitMap){
122 const std::optional<double> lambda = Amg::intersect<3>(localPos, chamberDir, Amg::Vector3D::UnitZ(), 0.);
133 unsigned int nMdt{0}, nRpc{0}, nTgc{0}, nMm{0}, nsTgc{0};
147 m_out_gen_tantheta = (std::abs(chamberDir.z()) > 1.e-8 ? chamberDir.y()/chamberDir.z() : 1.e10);
148 m_out_gen_tanphi = (std::abs(chamberDir.z()) > 1.e-8 ? chamberDir.x()/chamberDir.z() : 1.e10);
152 const std::vector<MuonR4::HoughSegmentSeed>& houghMaxima = houghPeakMap[
chamber];
153 if (houghMaxima.empty()){
155 return StatusCode::FAILURE;
164 size_t max_hits{0}, max_etaHits{0}, max_phiHits{0};
171 hitOnMax->identify() == simHit->
identify()){
179 if (hitOnMax->measuresEta()) ++
nEta;
180 if (hitOnMax->measuresPhi()) ++
nPhi;
184 if (nFound > max_hits){
192 if (foundMax !=
nullptr){
193 matchedSeeds.insert(foundMax);
199 bool foundSegment =
false;
201 max_hits = max_etaHits = max_phiHits;
220 if (nFound > max_hits){
249 if (!
m_tree.
fill(ctx))
return StatusCode::FAILURE;
252 return StatusCode::SUCCESS;
255 if (!foundMax)
return;
264 unsigned int nMdtMax{0}, nRpcMax{0}, nTgcMax{0}, nMmMax{0}, nsTgcMax{0};
269 switch (meas->
type()) {
312 <<
" not yet implemented");
324 const std::set<const MuonR4::HoughSegmentSeed*>& matchedSeeds) {
326 return StatusCode::SUCCESS;
328 for (
const auto& maxInStation : seedContainer) {
332 if (matchedSeeds.count(&dumpMeMayBe)) {
345 if (!
m_tree.
fill(ctx))
return StatusCode::FAILURE;
348 return StatusCode::SUCCESS;
351 const std::vector<const xAOD::MuonSimHit*>& simHits,
354 if (simHits.size() < 4)
return StatusCode::SUCCESS;
364 std::vector<std::pair<double,double>> shPos{}, shDir{};
369 const Identifier thisID = thisHit->identify();
372 const Amg::Vector3D localPos{toChamber * xAOD::toEigen(thisHit->localPosition())};
373 const Amg::Vector3D chamberDir = toChamber.linear() * xAOD::toEigen(thisHit->localDirection());
375 shPos.push_back(std::make_pair(localPos.y(), localPos.z()));
376 shDir.push_back(std::make_pair(chamberDir.y(), chamberDir.z()));
383 TCanvas myCanvas(
"can",
"can",800,600);
392 double z0 = 0.5 * (
zmax +
zmin) - 0.5 * height;
394 double z1 = 0.5 * (
zmax +
zmin) + 0.5 * height;
395 auto frame = myCanvas.DrawFrame(y0,
z0,
y1,z1);
396 double frameWidth = frame->GetXaxis()->GetXmax() - frame->GetXaxis()->GetXmin();
398 std::vector<std::unique_ptr<TObject>> primitives;
399 for (
size_t h = 0;
h < shPos.size(); ++
h){
400 auto l = std::make_unique<TArrow>(shPos.at(
h).first, shPos.at(
h).second,shPos.at(
h).first + 0.3 * frameWidth * shDir.at(
h).first, shPos.at(
h).second + 0.3 * frameWidth * shDir.at(
h).second);
401 l->SetLineStyle(kDotted);
403 primitives.emplace_back(std::move(
l));
404 auto m = std::make_unique<TMarker>(shPos.at(
h).first, shPos.at(
h).second,kFullDotLarge);
406 primitives.emplace_back(std::move(
m));
409 for (
auto spbucket : *readSpacePoints) {
410 if (spbucket->muonChamber() != refChamber)
continue;
411 std::set<MuonR4::HoughHitType> hitsOnMax{};
415 for (
auto & hit : *spbucket){
418 if (hit->driftRadius() > 1
e-6) {
419 auto ell = std::make_unique<TEllipse>(hit->positionInChamber().y(),
420 hit->positionInChamber().z(),
422 ell->SetLineColor(kRed);
423 ell->SetFillColor(kRed);
424 if (hitsOnMax.count(hit)) {
425 ell->SetFillStyle(1001);
426 ell->SetFillColorAlpha(ell->GetFillColor(), 0.8);
428 ell->SetFillStyle(0);
431 primitives.emplace_back(std::move(ell));
433 auto m = std::make_unique<TEllipse>(hit->positionInChamber().y(),
434 hit->positionInChamber().z(),
435 hit->uncertainty().y());
436 m->SetLineColor(kBlue);
437 m->SetFillColor(kBlue);
440 if (hit->measuresPhi() && hit->measuresEta()) {
441 m->SetLineColor(kViolet);
442 m->SetFillColor(kViolet);
443 }
else if (hit->measuresPhi()) {
444 m->SetLineColor(kGreen);
445 m->SetFillColor(kGreen);
448 if (hitsOnMax.count(hit)) {
449 m->SetFillStyle(1001);
450 m->SetFillColorAlpha(
m->GetFillColor(), 0.8);
453 primitives.emplace_back(std::move(
m));
458 std::stringstream legendLabel{};
459 legendLabel<<
"Evt "<<ctx.evt()<<
" station: "<<
m_idHelperSvc->mdtIdHelper().stationNameString(refChamber->
stationName());
461 legendLabel<<
", found maximum: "<<( foundMax ?
"si" :
"no");
464 TLatex
tl( 0.15,0.8,legendLabel.str().c_str());
470 auto mrk = std::make_unique<TMarker>( foundMax->
interceptY(), 0., kFullTriangleUp);
471 mrk->SetMarkerSize(1);
472 mrk->SetMarkerColor(kOrange-3);
474 primitives.emplace_back(std::move(mrk));
475 auto trajectory = std::make_unique<TArrow>( foundMax->
interceptY(), 0., foundMax->
interceptY() + 0.3 * frameWidth * foundMax->
tanTheta(), 0.3 * frameWidth);
476 trajectory->SetLineColor(kOrange-3);
478 primitives.push_back(std::move(trajectory));
480 static std::atomic<unsigned int> pdfCounter{0};
482 pdfName<<
"HoughEvt_"<<ctx.evt()<<
"_"<<(++pdfCounter)
486 myCanvas.SaveAs(
pdfName.str().c_str());
489 return StatusCode::SUCCESS;
495 #define XXX std::cout << __LINE__ << std::endl;
497 const std::vector<const xAOD::MuonSimHit*>& simHits,
500 const std::string &
label)
const{
502 if (simHits.size() < 4)
return StatusCode::SUCCESS;
503 std::vector<std::pair<double,double>> shPos{}, shDir{};
506 std::cout <<
" ref chamber = "<<refChamber<<std::endl;
513 TCanvas myCanvas(
"can",
"can",800,600);
517 TH2D hChi2(
"chi2",
"chi2;y0;tan(theta)",200,true_y0 - 100,true_y0 + 100 , 200,true_tanTheta - 0.2,true_tanTheta + 0.2);
519 std::vector<double>
pars(4,0.);
520 std::vector<double> chi2PerLayer(foundMax->
getHitsInMax().size());
525 for (
int bx =1 ;
bx < hChi2.GetXaxis()->GetNbins()+1; ++
bx){
526 for (
int by =1 ;
by < hChi2.GetYaxis()->GetNbins()+1; ++
by){
527 double y = hChi2.GetXaxis()->GetBinCenter(
bx);
528 double t = hChi2.GetYaxis()->GetBinCenter(
by);
535 auto mbin = hChi2.GetMinimumBin(
mx,
my,
mz);
537 double ygx2 = hChi2.GetXaxis()->GetBinCenter(
mx);
538 double tgx2 = hChi2.GetYaxis()->GetBinCenter(
my);
539 std::vector<double> contourLevels{minChi2 + 0.1,minChi2 + 1.0,minChi2 + 4.0,minChi2 + 9.0,minChi2 + 50.};
541 hChi2.SetMinimum(1.
e-1);
542 hChi2.SetContour(100000);
543 hChi2.GetXaxis()->SetTitle(
"y0[mm]");
544 hChi2.GetYaxis()->SetTitle(
"tan #Theta");
546 std::shared_ptr<TH2D> hClone (
dynamic_cast<TH2D*
>(hChi2.Clone(
"leeeeeak")));
547 hClone->SetContour(5, contourLevels.data());
548 hClone->SetFillStyle(0);
549 hClone->Draw(
"CONT2SAME");
551 TMarker mark(true_y0, true_tanTheta, kFullDotLarge);
552 mark.SetMarkerColor(kAzure+10);
553 mark.SetMarkerSize(1);
558 houghMin.SetMarkerColor(kOrange-3);
559 houghMin.SetMarkerSize(1);
563 TMarker th2min(ygx2, tgx2, kOpenDiamond);
564 th2min.SetMarkerColor(kGray+1);
565 th2min.SetMarkerSize(1);
567 TMarker gx2Min(-99999,-9999999, kFullDiamond);
568 gx2Min.SetMarkerColor(kRed+1);
569 gx2Min.SetMarkerSize(1);
571 gx2Min.SetX(foundSegment->
y0());
572 gx2Min.SetY(foundSegment->
tanTheta());
576 std::stringstream legendLabel{};
579 legendLabel<<
", found maximum: "<<( foundMax ?
"si" :
"no");
582 TLatex
tl( 0.15,0.8,legendLabel.str().c_str());
587 static std::atomic<unsigned int> pdfCounter{0};
589 pdfName<<
"Chi2_Eta_"<<
label<<
"_"<<ctx.evt()<<
"_"<<(++pdfCounter)
593 std::cout <<
"try to save "<<
pdfName.str()<<
", this might go poof"<<std::endl;
594 myCanvas.SaveAs(
pdfName.str().c_str());
599 TH2D hChi3(
"chi3",
"chi2;x0;tan(phi)",500,true_x0 - 200,true_x0 + 200 , 500,true_tanPhi - 0.3,true_tanPhi + 0.3);
604 for (
int bx =1 ;
bx < hChi3.GetXaxis()->GetNbins()+1; ++
bx){
605 for (
int by =1 ;
by < hChi3.GetYaxis()->GetNbins()+1; ++
by){
606 double y = hChi3.GetXaxis()->GetBinCenter(
bx);
607 double t = hChi3.GetYaxis()->GetBinCenter(
by);
613 mbin = hChi3.GetMinimumBin(
mx,
my,
mz);
615 ygx2 = hChi3.GetXaxis()->GetBinCenter(
mx);
616 tgx2 = hChi3.GetYaxis()->GetBinCenter(
my);
618 hChi3.SetMinimum(1.
e-1);
619 hChi3.GetXaxis()->SetTitle(
"x0[mm]");
620 hChi3.GetYaxis()->SetTitle(
"tan #Phi");
621 hChi3.SetContour(100000);
623 hClone.reset (
dynamic_cast<TH2D*
>(hChi3.Clone(
"leeeeeak")));
624 hClone->SetContour(5, contourLevels.data());
625 hClone->SetFillStyle(0);
626 hClone->Draw(
"CONT2SAME");
628 TMarker mark2(true_x0, true_tanPhi, kFullDotLarge);
629 mark2.SetMarkerColor(kAzure+10);
630 mark2.SetMarkerSize(1);
635 houghMin2.SetMarkerColor(kOrange-3);
636 houghMin2.SetMarkerSize(1);
640 TMarker th2min2(ygx2, tgx2, kOpenDiamond);
641 th2min2.SetMarkerColor(kGray+1);
642 th2min2.SetMarkerSize(1);
644 TMarker gx2Min2(-99999,-9999999, kFullDiamond);
645 gx2Min2.SetMarkerColor(kRed+1);
646 gx2Min2.SetMarkerSize(1);
648 gx2Min2.SetX(foundSegment->
x0());
649 gx2Min2.SetY(foundSegment->
tanPhi());
653 std::stringstream legendLabel2{};
656 legendLabel2<<
", found maximum: "<<( foundMax ?
"si" :
"no");
659 TLatex tl2( 0.15,0.8,legendLabel2.str().c_str());
664 std::stringstream pdfName2{};
665 pdfName2<<
"Chi2_Phi_"<<
label<<
"_"<<ctx.evt()<<
"_"<<(++pdfCounter)
669 std::cout <<
"try to save "<<pdfName2.str()<<
", this might go poof"<<std::endl;
670 myCanvas.SaveAs(pdfName2.str().c_str());
674 return StatusCode::SUCCESS;