ATLAS Offline Software
MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "NSWGeoPlottingAlg.h"
5 
6 #include <cmath>
7 
8 #include "GaudiKernel/SystemOfUnits.h"
12 #include "StoreGate/ReadHandle.h"
13 #include "TFile.h"
14 #include "TGraph.h"
15 #include "TH1.h"
16 #include "TH2I.h"
17 
18 #include "Acts/Surfaces/Surface.hpp"
19 #include "Acts/Surfaces/SurfaceBounds.hpp"
20 
22 
23 
24 namespace MuonGMR4 {
25 
28  ATH_CHECK(m_idHelperSvc.retrieve());
30  ATH_MSG_INFO("Check Acts surface "<<m_testActsSurf);
31  if(m_plotMm) ATH_CHECK(initMm());
34  return StatusCode::SUCCESS;
35 }
37  const EventContext& ctx = Gaudi::Hive::currentContext();
38  const ActsGeometryContext* gctx{nullptr};
39  ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
40 
41  std::vector<const MmReadoutElement*> micromegas = m_detMgr->getAllMmReadoutElements();
42  for (const MmReadoutElement* mm : micromegas) {
43  if (!m_plotMm) {
44  ATH_MSG_DEBUG("Skipping plotting of MM readout elements");
45  break;
46  }
47  ATH_MSG_INFO("plotting active areas for "<< m_idHelperSvc->toString(mm->identify()));
48  for (int gasGap = 1; gasGap <= 4; ++ gasGap) {
49  const IdentifierHash hash = MmReadoutElement::createHash(gasGap, (mm->stationEta() > 0 ? 1 : 2) +
50  10 * mm->multilayer());
51  auto histo = m_mmActiveAreas[hash];
52  const StripDesign& design{mm->stripLayer(hash).design()};
53  const Acts::Surface& plane{mm->surface(mm->layerHash(hash))};
54  const double halfY = 2.*design.longHalfHeight();
55  const double halfX = 2.*design.halfWidth();
56  for (double x = -halfX; x <= halfX; x+= 1.*Gaudi::Units::mm){
57  for (double y = -halfY; y<= halfY; y+=1.*Gaudi::Units::mm) {
58  const Amg::Vector3D locPos{x,y,0};
59  if (!m_testActsSurf && !design.insideTrapezoid(locPos.block<2,1>(0,0))) {
60  continue;
61  } else if (m_testActsSurf && !plane.insideBounds(locPos.block<2,1>(0,0))) {
62  continue;
63  }
64 
65  const Amg::Vector3D globPos = plane.transform(gctx->context()) * locPos;
66  histo->Fill(globPos.x(), globPos.y());
67  }
68  }
69  }
70  }
71 
72  std::vector<const sTgcReadoutElement*> sTgcs = m_detMgr->getAllsTgcReadoutElements();
73  for (const sTgcReadoutElement* sTgc : sTgcs) {
74  if( !m_plotStgc ) {
75  ATH_MSG_DEBUG("Skipping plotting of sTGC readout elements");
76  break;
77  }
78  ATH_MSG_INFO("plotting active areas for sTGC "<< m_idHelperSvc->toString(sTgc->identify()));
79  for (int chanType : {chType::Strip, chType::Pad, chType::Wire}){
80  for (int gasGap = 1; gasGap <= 4; ++ gasGap) {
81  const IdentifierHash hash = sTgcReadoutElement::createHash(gasGap, chanType, (sTgc->stationEta() > 0 ? 1 : 2) +
82  10 * sTgc->multilayer());
84 
85  const StripDesign& design{ chanType == chType::Strip? sTgc->stripDesign(hash) :
86  chanType == chType::Wire ? static_cast<const StripDesign&>(sTgc->wireDesign(hash))
87  : static_cast<const StripDesign&>(sTgc->padDesign(hash))};
88  const Acts::Surface& plane{sTgc->surface(sTgc->layerHash(hash))};
89  const double halfY = 2.*design.longHalfHeight();
90  const double halfX = 2.*design.halfWidth();
91  for (double x = -halfX; x <= halfX; x+= 1.*Gaudi::Units::mm){
92  for (double y = -halfY; y<= halfY; y+=1.*Gaudi::Units::mm) {
93  const Amg::Vector3D locPos{x,y,0};
94  if (!m_testActsSurf && !design.insideTrapezoid(locPos.block<2,1>(0,0))) {
95  continue;
96  } else if (m_testActsSurf && !plane.insideBounds(locPos.block<2,1>(0,0))) {
97  continue;
98  }
99 
100  const Amg::Vector3D globPos = plane.transform(gctx->context()) * locPos;
101  histo->Fill(globPos.x(), globPos.y());
102  }
103  }
104  }
105  }
106  }
107 
108  std::vector<const TgcReadoutElement*> tgcs = m_detMgr->getAllTgcReadoutElements();
109  for (const TgcReadoutElement* tgc : tgcs) {
110  if (!m_plotTgc) {
111  ATH_MSG_DEBUG("Skipping plotting of TGC readout elements");
112  break;
113  }
114  ATH_MSG_INFO("plotting active areas for TGC "<< m_idHelperSvc->toString(tgc->identify()));
115  for (unsigned int gasGap = 1; gasGap <= tgc->nGasGaps(); ++gasGap){
116  for (bool isStrip : {false, true}) {
117  int stationNameIndex = std::stoi(m_idHelperSvc->stationNameString(tgc->identify()).substr(1,1));
119  if(!tgc->numChannels(hash)) { // for some gas gaps we do not read the strips
120  continue;
121  }
122  auto histo = m_tgcActiveAreas[hash];
123  const StripDesign& design {isStrip? static_cast<const StripDesign&>(tgc->stripLayout(hash)) :
124  static_cast<const StripDesign&>(tgc->wireGangLayout(hash))};
125 
126  const Acts::Surface& plane{tgc->surface(tgc->layerHash(hash))};
127  const double halfY = 1.5*design.longHalfHeight();
128  const double halfX = 1.5*design.halfWidth();
129  for (double x = -halfX; x <= halfX; x+= 2.*Gaudi::Units::mm){
130  for (double y = -halfY; y<= halfY; y+=2.*Gaudi::Units::mm) {
131  const Amg::Vector3D locPos{x,y,0};
132  if (!m_testActsSurf && !design.insideTrapezoid(locPos.block<2,1>(0,0))) {
133  continue;
134  } else if (m_testActsSurf && !plane.insideBounds(locPos.block<2,1>(0,0))) {
135  continue;
136  }
137 
138  const Amg::Vector3D globPos = plane.transform(gctx->context()) * locPos;
139  histo->Fill(globPos.x(), globPos.y());
140  }
141  }
142  }
143  }
144  }
145 
146 
147 
148 
149  return StatusCode::SUCCESS;
150 }
152  for (unsigned int ml =1 ; ml <= 2; ++ml) {
153  for(unsigned int active =1 ; active <= 2; ++active){
154  for (int chanType : {chType::Strip, chType::Pad, chType::Wire}){
155  for (unsigned int gasGap =1; gasGap <= 4; ++gasGap) {
156  std::string histoName = "STGC_"+std::string(active == 1? "A" : "C") + "M" +
157  std::to_string(ml) + "G" + std::to_string(gasGap) +
158  + (chanType == chType::Strip? "S" :
159  chanType == chType::Wire ? "W" : "P");
160 
161  auto newHisto = std::make_unique<TH2I>(histoName.c_str(),
162  "ActiveNSW;x [mm]; y [mm]", 1000, -5001, 5001., 1000,
163  -5001., 5001.);
164  m_stgcActiveAreas[sTgcReadoutElement::createHash(gasGap, chanType, active + 10 * ml)] = newHisto.get();
165  ATH_CHECK(histSvc()->regHist("/GEOMODELTESTER/ActiveSurfaces/"+ histoName,std::move(newHisto)));
166  }
167  }
168  }
169  }
170  return StatusCode::SUCCESS;
171 }
173 
174  for (unsigned int ml = 1; ml <= 2; ++ml) {
175  for (unsigned int active = 1; active <= 2; ++ active) {
176  for (unsigned int gasGap = 1; gasGap <= 4; ++gasGap) {
177  std::string histoName = "MM_"+std::string(active == 1? "A" : "C") + "M" +
178  std::to_string(ml) + "G" + std::to_string(gasGap);
179  auto newHisto = std::make_unique<TH2I>(histoName.c_str(),
180  "ActiveNSW;x [mm]; y [mm]", 1000, -5001, 5001., 1000,
181  -5001., 5001.);
182  m_mmActiveAreas[MmReadoutElement::createHash(gasGap, active + 10 * ml)] = newHisto.get();
183  ATH_CHECK(histSvc()->regHist("/GEOMODELTESTER/ActiveSurfaces/"+ histoName,std::move(newHisto)));
184  }
185  }
186  }
187  return StatusCode::SUCCESS;
188 }
189 
190 
192  std::set<std::string> tgcNames;
193  for(const TgcReadoutElement* tgc : m_detMgr->getAllTgcReadoutElements()) {
194  tgcNames.insert(m_idHelperSvc->stationNameString(tgc->identify()));
195  }
196  for (unsigned int gasGap = 1; gasGap <= 3; ++gasGap){
197  for (bool isStrip : {false, true}) {
198  for (uint station: {1,2,3,4} ){
199  std::string histoName = "TGC_T:"+ std::to_string(station) + "G:" + std::to_string(gasGap) + (isStrip ? "S" : "W");
200  auto newHisto = std::make_unique<TH2I>(histoName.c_str(),
201  "ActiveTGC;x [mm]; y [mm]", 3000, -15001, 15001., 3000,
202  -15001., 15001.);
204  ATH_CHECK(histSvc()->regHist("/GEOMODELTESTER/ActiveSurfaces/"+ histoName,std::move(newHisto)));
205  }
206  }
207  }
208  return StatusCode::SUCCESS;
209 }
210 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AthHistogramAlgorithm::histSvc
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
Definition: AthHistogramAlgorithm.h:113
MuonGMR4::NswGeoPlottingAlg::m_detMgr
const MuonDetectorManager * m_detMgr
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:40
MuonGMR4::MmReadoutElement
Definition: MmReadoutElement.h:18
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
MuonGMR4::StripDesign
Definition: StripDesign.h:30
MuonGMR4::MmReadoutElement::createHash
static IdentifierHash createHash(const int gasGap, const int strip)
python.SystemOfUnits.mm
float mm
Definition: SystemOfUnits.py:98
MuonGMR4::NswGeoPlottingAlg::m_tgcActiveAreas
std::map< IdentifierHash, TH1 * > m_tgcActiveAreas
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:50
MuonGMR4::NswGeoPlottingAlg::initMm
StatusCode initMm()
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.cxx:172
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
sTgcIdHelper::sTgcChannelTypes
sTgcChannelTypes
Definition: sTgcIdHelper.h:190
x
#define x
MuonGMR4::StripDesign::longHalfHeight
double longHalfHeight() const
Returns the longer half height of the panel.
MuonGMR4::NswGeoPlottingAlg::initialize
StatusCode initialize() override
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.cxx:26
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
MuonGMR4::NswGeoPlottingAlg::m_plotMm
Gaudi::Property< bool > m_plotMm
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:44
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
MuonGMR4::sTgcReadoutElement::createHash
static IdentifierHash createHash(const unsigned int gasGap, const unsigned int channelType, const unsigned int channel, const unsigned int wireInGrp=0)
Create a measurement hash from the Identifier fields.
MuonGMR4::NswGeoPlottingAlg::m_plotTgc
Gaudi::Property< bool > m_plotTgc
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:46
MuonGMR4::NswGeoPlottingAlg::initTgc
StatusCode initTgc()
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.cxx:191
MuonGMR4
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
Definition: MdtCalibInput.h:19
Trk::active
@ active
Definition: Layer.h:47
MuonGMR4::NswGeoPlottingAlg::execute
StatusCode execute() override
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.cxx:36
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
NSWGeoPlottingAlg.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonDetectorManager.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonGMR4::NswGeoPlottingAlg::m_mmActiveAreas
std::map< IdentifierHash, TH1 * > m_mmActiveAreas
Map showing the active areas of the NSW to show the passivation.
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:48
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MuonGMR4::NswGeoPlottingAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:35
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
dumpTgcDigiThreshold.isStrip
list isStrip
Definition: dumpTgcDigiThreshold.py:33
MuonGMR4::NswGeoPlottingAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:38
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
AthHistogramming::hash
hash_t hash(const std::string &histName) const
Method to calculate a 32-bit hash from a string.
Definition: AthHistogramming.h:428
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonGMR4::sTgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/sTgcReadoutElement.h:20
MuonGMR4::NswGeoPlottingAlg::m_stgcActiveAreas
std::map< IdentifierHash, TH1 * > m_stgcActiveAreas
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:49
y
#define y
MuonGMR4::TgcReadoutElement::constructHash
static IdentifierHash constructHash(unsigned measCh, unsigned gasGap, const bool isStrip)
Constructs the Hash out of the Identifier fields (channel, gasGap, isStrip)
ReadHandle.h
Handle class for reading from StoreGate.
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
plotBeamSpotCompare.histo
histo
Definition: plotBeamSpotCompare.py:414
TgcReadoutElement.h
MuonGMR4::NswGeoPlottingAlg::initStgc
StatusCode initStgc()
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.cxx:151
MuonGMR4::NswGeoPlottingAlg::m_testActsSurf
Gaudi::Property< bool > m_testActsSurf
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:42
MuonGMR4::NswGeoPlottingAlg::m_plotStgc
Gaudi::Property< bool > m_plotStgc
Definition: MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.h:45
MuonGMR4::TgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:19
MmReadoutElement.h