ATLAS Offline Software
sTgcPadPlottingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "sTgcPadPlottingAlg.h"
5 
6 #include <cmath>
7 #include <sstream>
8 #include "GaudiKernel/SystemOfUnits.h"
13 
14 #include <TFile.h>
15 #include <TGraph.h>
16 #include <TH2F.h>
17 
20 
22  ISvcLocator* pSvcLocator)
23  : AthHistogramAlgorithm(name, pSvcLocator) {}
24 
26  std::unique_ptr<TFile> out_file =
27  std::make_unique<TFile>(m_outFile.value().c_str(), "RECREATE");
28  if (!out_file || !out_file->IsOpen() || out_file->IsZombie()) {
29 
30  ATH_MSG_FATAL("Failed to create the output file " << m_outFile);
31  return StatusCode::FAILURE;
32  }
33  out_file->mkdir("SinglePads");
34  TDirectory* dir = out_file->GetDirectory("SinglePads");
35  for (auto& [id, grObj] : m_nswPads) {
36  std::stringstream ch_name{};
37  dir->WriteObject(grObj.get(), padName(id).c_str());
38  }
39  m_nswPads.clear();
40  out_file->mkdir("PadScanning");
41  dir = out_file->GetDirectory("PadScanning");
42  for (auto& [id, grObj] : m_nswPadDist) {
43  std::stringstream ch_name{};
44  dir->WriteObject(grObj.get(), padName(id).c_str());
45  }
46  m_nswPads.clear();
47 
48  return StatusCode::SUCCESS;
49 }
50 std::string sTgcPadPlottingAlg::padName(const Identifier& id) const {
51  const sTgcIdHelper& st_helper = m_idHelperSvc->stgcIdHelper();
52  std::stringstream ch_name{};
53  const int stEta = m_idHelperSvc->stationEta(id);
54  ch_name << m_idHelperSvc->stationNameString(id);
55  ch_name << std::abs(stEta)<< (stEta > 0 ? "A" : "C");
56  ch_name << m_idHelperSvc->stationPhi(id);
57  ch_name <<"W" << st_helper.multilayer(id);
58  ch_name <<"L" << st_helper.gasGap(id);
59  ch_name <<"PAD"<<st_helper.padEta(id)<<"P"<<st_helper.padPhi(id);
60  return ch_name.str();
61 }
62 
65  ATH_CHECK(m_idHelperSvc.retrieve());
67  return StatusCode::SUCCESS;
68 }
69 
71  if (m_alg_run)
72  return StatusCode::SUCCESS;
73  const EventContext& ctx = Gaudi::Hive::currentContext();
75  ctx};
76  if (!detMgr.isValid()) {
77  ATH_MSG_FATAL("Failed to retrieve the detector manager ");
78  return StatusCode::FAILURE;
79  }
80  for (auto & [id, grObj] : m_nswPads) {
81  const MuonGM::sTgcReadoutElement* roElement = detMgr->getsTgcReadoutElement(id);
82  std::array<Amg::Vector2D, 4> corners{};
83  if (!roElement->padCorners(id, corners)) {
84  ATH_MSG_WARNING("Corners could not be extracted for pad "<<m_idHelperSvc->toString(id));
85  continue;
86  }
87  for (const Amg::Vector2D& corner : corners) {
88  grObj->SetPoint(grObj->GetN(), corner.x(), corner.y());
89  }
90  }
91  for (auto& [id, padObj]: m_nswPadDist) {
92  const MuonGM::sTgcReadoutElement* re = detMgr->getsTgcReadoutElement(id);
93  const MuonGM::MuonPadDesign* design = re->getPadDesign(id);
94  const int ch = m_idHelperSvc->stgcIdHelper().channel(id);
95  for (int binX = 1 ; binX <= padObj->GetNbinsX(); ++binX) {
96  for (int binY = 1; binY <= padObj->GetNbinsY(); ++binY) {
97  const Amg::Vector2D pos{padObj->GetXaxis()->GetBinCenter(binX),
98  padObj->GetYaxis()->GetBinCenter(binY)};
99  const Amg::Vector2D distVec = design->distanceToPad(pos, ch);
100  padObj->SetBinContent(binX, binY, std::hypot(distVec.x(), distVec.y()));
101  }
102  }
103  }
104 
105 
106  return StatusCode::SUCCESS;
107 }
108 
110  const MuonGM::MuonDetectorManager* detMgr{nullptr};
111  ATH_CHECK(detStore()->retrieve(detMgr));
112  const sTgcIdHelper& id_helper = m_idHelperSvc->stgcIdHelper();
113  for (const std::string station : {"STS", "STL"}) {
114  for (int eta = id_helper.stationEtaMin(); eta <= id_helper.stationEtaMax(); ++eta) {
115  if (eta == 0) continue;
116  for (int phi = id_helper.stationPhiMin(); phi <= id_helper.stationPhiMax(); ++phi) {
117  for (int ml = id_helper.multilayerMin(); ml <= id_helper.multilayerMax(); ++ml) {
118  bool is_valid{false};
119  Identifier station_id = id_helper.elementID(station, eta, phi, is_valid);
120  if (!is_valid) continue;
121  const Identifier module_id = id_helper.multilayerID(station_id, ml);
122  const MuonGM::sTgcReadoutElement* re = detMgr->getsTgcReadoutElement(module_id);
123  if (!re) continue;
124 
125  for (int lay = 1; lay <= 4; ++lay) {
126  for (int padPhi = id_helper.padPhiMin(); padPhi <= id_helper.padPhiMax(); ++padPhi){
127  for (int padEta = id_helper.padEtaMin(); padEta <= id_helper.padEtaMax(); ++padEta) {
128  bool isValid{false};
129  const Identifier padId = id_helper.padID(module_id, ml, lay, sTgcIdHelper::sTgcChannelTypes::Pad, padEta, padPhi, isValid);
130  if (!isValid) continue;
131  m_nswPads[padId] = std::make_unique<TGraph>();
132  const MuonGM::MuonPadDesign* design = re->getPadDesign(padId);
133  CornerArray padEdges{};
134  design->channelCorners(id_helper.channel(padId), padEdges);
135  const double padMinX = std::min(padEdges[padCorners::botLeft].x(), padEdges[padCorners::topLeft].x());
136  const double padMaxX = std::max(padEdges[padCorners::botRight].x(), padEdges[padCorners::topRight].x());
137  const double padMinY = padEdges[padCorners::botLeft].y();
138  const double padMaxY = padEdges[padCorners::topLeft].y();
139  const double dX = padMaxX - padMinX;
140  const double dY = padMaxY - padMinY;
141  std::unique_ptr<TH2> padH = std::make_unique<TH2D>(padName(padId).c_str(),
142  "dummy; pad x[mm];pad y[mm];pad distance [mm]",
143  800, padMinX - 0.25*dX, padMaxX + 0.25*dX,
144  800, padMinY - 0.25*dY, padMaxY + 0.25*dY);
145  ATH_MSG_DEBUG("Dimensions "<<padName(padId)<<" "<<padMinX<<" "<<padMaxX<<" -- "<<padMinY<<" "<<padMaxY);
146  m_nswPadDist[padId] = std::move(padH);
147  }
148  }
149  }
150  }
151  }
152  }
153  }
154  return StatusCode::SUCCESS;
155 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MuonGM::sTgcReadoutElement::padCorners
bool padCorners(const Identifier &id, std::array< Amg::Vector2D, 4 > &corners) const
pad corners
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/sTgcReadoutElement.h:358
sTgcIdHelper::multilayer
int multilayer(const Identifier &id) const
Definition: sTgcIdHelper.cxx:1017
MuonGM::MuonPadDesign
Parameters defining the design of the readout sTGC pads.
Definition: MuonPadDesign.h:40
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
MuonGM::MuonPadDesign::CornerArray
std::array< Amg::Vector2D, 4 > CornerArray
calculate local channel corners for a given channel number
Definition: MuonPadDesign.h:104
sTgcPadPlottingAlg::m_nswPadDist
std::map< Identifier, std::unique_ptr< TH2 > > m_nswPadDist
Definition: sTgcPadPlottingAlg.h:46
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
sTgcReadoutElement.h
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
sTgcIdHelper::stationPhiMin
static int stationPhiMin()
Definition: sTgcIdHelper.cxx:1034
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
sTgcPadPlottingAlg::m_nswPads
std::map< Identifier, std::unique_ptr< TGraph > > m_nswPads
Map containing each PCB of the NSW seperately.
Definition: sTgcPadPlottingAlg.h:45
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
sTgcPadPlottingAlg::initialize
StatusCode initialize() override
Definition: sTgcPadPlottingAlg.cxx:63
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CornerArray
MuonGM::MuonPadDesign::CornerArray CornerArray
Definition: sTgcPadPlottingAlg.cxx:19
sTgcPadPlottingAlg::m_DetectorManagerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
Definition: sTgcPadPlottingAlg.h:36
sTgcIdHelper::multilayerMin
static int multilayerMin()
Definition: sTgcIdHelper.cxx:1038
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:620
x
#define x
sTgcPadPlottingAlg::m_alg_run
bool m_alg_run
Definition: sTgcPadPlottingAlg.h:47
sTgcPadPlottingAlg::sTgcPadPlottingAlg
sTgcPadPlottingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: sTgcPadPlottingAlg.cxx:21
ReadCondHandle.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
sTgcPadPlottingAlg::m_outFile
Gaudi::Property< std::string > m_outFile
Definition: sTgcPadPlottingAlg.h:42
sTgcPadPlottingAlg::initSTgcs
StatusCode initSTgcs()
Definition: sTgcPadPlottingAlg.cxx:109
Trk::binY
@ binY
Definition: BinningType.h:48
MMReadoutElement.h
sTgcIdHelper::stationEtaMin
static int stationEtaMin()
Definition: sTgcIdHelper.cxx:1030
sTgcPadPlottingAlg.h
sTgcIdHelper::channel
int channel(const Identifier &id) const override
Definition: sTgcIdHelper.cxx:1027
sTgcIdHelper::stationPhiMax
static int stationPhiMax()
Definition: sTgcIdHelper.cxx:1036
sTgcIdHelper::padPhiMax
static int padPhiMax()
Definition: sTgcIdHelper.cxx:1060
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonGM::sTgcReadoutElement
An sTgcReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station c...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/sTgcReadoutElement.h:30
sTgcPadPlottingAlg::finalize
StatusCode finalize() override
Definition: sTgcPadPlottingAlg.cxx:25
sTgcIdHelper::gasGap
int gasGap(const Identifier &id) const override
get the hashes
Definition: sTgcIdHelper.cxx:1020
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
sTgcIdHelper::stationEtaMax
static int stationEtaMax()
Definition: sTgcIdHelper.cxx:1032
Trk::binX
@ binX
Definition: BinningType.h:47
AthHistogramAlgorithm
Definition: AthHistogramAlgorithm.h:32
sTgcPadPlottingAlg::padName
std::string padName(const Identifier &padId) const
Definition: sTgcPadPlottingAlg.cxx:50
sTgcIdHelper::padEtaMin
static int padEtaMin()
Definition: sTgcIdHelper.cxx:1054
beamspotman.dir
string dir
Definition: beamspotman.py:623
sTgcIdHelper::padPhiMin
static int padPhiMin()
Definition: sTgcIdHelper.cxx:1058
sTgcIdHelper::multilayerMax
static int multilayerMax()
Definition: sTgcIdHelper.cxx:1040
sTgcIdHelper::padEtaMax
static int padEtaMax()
Definition: sTgcIdHelper.cxx:1056
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
sTgcIdHelper::padID
Identifier padID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType, int padEta, int padPhi) const
Definition: sTgcIdHelper.cxx:939
MuonGM::MuonPadDesign::padCorners
padCorners
Definition: MuonPadDesign.h:105
sTgcIdHelper
Definition: sTgcIdHelper.h:55
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
MuonDetectorManager.h
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
sTgcIdHelper::elementID
Identifier elementID(int stationName, int stationEta, int stationPhi) const
Definition: sTgcIdHelper.cxx:856
sTgcIdHelper::padPhi
int padPhi(const Identifier &id) const
Definition: sTgcIdHelper.cxx:679
MuonGM::MuonPadDesign::channelCorners
bool channelCorners(const std::pair< int, int > &pad, CornerArray &corners) const
Definition: MuonPadDesign.cxx:157
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:50
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
sTgcPadPlottingAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: sTgcPadPlottingAlg.h:40
re
const boost::regex re(r_e)
sTgcIdHelper::multilayerID
Identifier multilayerID(const Identifier &channeldID) const
Definition: sTgcIdHelper.cxx:297
sTgcIdHelper::padEta
int padEta(const Identifier &id) const
Definition: sTgcIdHelper.cxx:669
sTgcPadPlottingAlg::execute
StatusCode execute() override
Definition: sTgcPadPlottingAlg.cxx:70
MuonGM::MuonPadDesign::distanceToPad
Amg::Vector2D distanceToPad(const Amg::Vector2D &pos, int channel) const
Definition: MuonPadDesign.cxx:118
Identifier
Definition: IdentifierFieldParser.cxx:14