ATLAS Offline Software
Loading...
Searching...
No Matches
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"
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
24namespace MuonGMR4 {
25
27 ATH_CHECK(m_geoCtxKey.initialize());
28 ATH_CHECK(m_idHelperSvc.retrieve());
29 ATH_CHECK(detStore()->retrieve(m_detMgr));
30 ATH_MSG_INFO("Check Acts surface "<<m_testActsSurf);
34 return StatusCode::SUCCESS;
35}
37 const EventContext& ctx = Gaudi::Hive::currentContext();
38 const ActsTrk::GeometryContext* 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());
83 auto histo = m_stgcActiveAreas[hash];
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));
118 const IdentifierHash hash = TgcReadoutElement::constructHash(stationNameIndex, gasGap, isStrip);
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.);
203 m_tgcActiveAreas[TgcReadoutElement::constructHash(station, gasGap, isStrip)] = newHisto.get();
204 ATH_CHECK(histSvc()->regHist("/GEOMODELTESTER/ActiveSurfaces/"+ histoName,std::move(newHisto)));
205 }
206 }
207 }
208 return StatusCode::SUCCESS;
209}
210}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
unsigned int uint
Handle class for reading from StoreGate.
#define y
#define x
Acts::GeometryContext context() const
const ServiceHandle< StoreGateSvc > & detStore() const
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
hash_t hash(const std::string &histName) const
Method to calculate a 32-bit hash from a string.
This is a "hash" representation of an Identifier.
static IdentifierHash createHash(const int gasGap, const int strip)
std::map< IdentifierHash, TH1 * > m_mmActiveAreas
Map showing the active areas of the NSW to show the passivation.
double halfWidth() const
Returns the half height of the strip panel.
bool insideTrapezoid(const Amg::Vector2D &extPos) const
Checks whether an external point is inside the trapezoidal area.
double longHalfHeight() const
Returns the longer half height of the panel.
static IdentifierHash constructHash(unsigned measCh, unsigned gasGap, const bool isStrip)
Constructs the Hash out of the Identifier fields (channel, gasGap, isStrip)
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.
Eigen::Matrix< double, 3, 1 > Vector3D
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
double halfY(const Acts::VolumeBounds &bounds)
Returns the half-Y length for the parsed volume bounds (Trapezoid/ Cuboid)
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.