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}
36StatusCode NswGeoPlottingAlg::execute(const EventContext& ctx) {
37 const ActsTrk::GeometryContext* gctx{nullptr};
38 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
39
40 std::vector<const MmReadoutElement*> micromegas = m_detMgr->getAllMmReadoutElements();
41 for (const MmReadoutElement* mm : micromegas) {
42 if (!m_plotMm) {
43 ATH_MSG_DEBUG("Skipping plotting of MM readout elements");
44 break;
45 }
46 ATH_MSG_INFO("plotting active areas for "<< m_idHelperSvc->toString(mm->identify()));
47 for (int gasGap = 1; gasGap <= 4; ++ gasGap) {
48 const IdentifierHash hash = MmReadoutElement::createHash(gasGap, (mm->stationEta() > 0 ? 1 : 2) +
49 10 * mm->multilayer());
50 auto histo = m_mmActiveAreas[hash];
51 const StripDesign& design{mm->stripLayer(hash).design()};
52 const Acts::Surface& plane{mm->surface(mm->layerHash(hash))};
53 const double halfY = 2.*design.longHalfHeight();
54 const double halfX = 2.*design.halfWidth();
55 for (double x = -halfX; x <= halfX; x+= 1.*Gaudi::Units::mm){
56 for (double y = -halfY; y<= halfY; y+=1.*Gaudi::Units::mm) {
57 const Amg::Vector3D locPos{x,y,0};
58 if (!m_testActsSurf && !design.insideTrapezoid(locPos.block<2,1>(0,0))) {
59 continue;
60 } else if (m_testActsSurf && !plane.insideBounds(locPos.block<2,1>(0,0))) {
61 continue;
62 }
63
64 const Amg::Vector3D globPos = plane. localToGlobalTransform(gctx->context()) * locPos;
65 histo->Fill(globPos.x(), globPos.y());
66 }
67 }
68 }
69 }
70
71 std::vector<const sTgcReadoutElement*> sTgcs = m_detMgr->getAllsTgcReadoutElements();
72 for (const sTgcReadoutElement* sTgc : sTgcs) {
73 if( !m_plotStgc ) {
74 ATH_MSG_DEBUG("Skipping plotting of sTGC readout elements");
75 break;
76 }
77 ATH_MSG_INFO("plotting active areas for sTGC "<< m_idHelperSvc->toString(sTgc->identify()));
78 for (int chanType : {chType::Strip, chType::Pad, chType::Wire}){
79 for (int gasGap = 1; gasGap <= 4; ++ gasGap) {
80 const IdentifierHash hash = sTgcReadoutElement::createHash(gasGap, chanType, (sTgc->stationEta() > 0 ? 1 : 2) +
81 10 * sTgc->multilayer());
82 auto histo = m_stgcActiveAreas[hash];
83
84 const StripDesign& design{ chanType == chType::Strip? sTgc->stripDesign(hash) :
85 chanType == chType::Wire ? static_cast<const StripDesign&>(sTgc->wireDesign(hash))
86 : static_cast<const StripDesign&>(sTgc->padDesign(hash))};
87 const Acts::Surface& plane{sTgc->surface(sTgc->layerHash(hash))};
88 const double halfY = 2.*design.longHalfHeight();
89 const double halfX = 2.*design.halfWidth();
90 for (double x = -halfX; x <= halfX; x+= 1.*Gaudi::Units::mm){
91 for (double y = -halfY; y<= halfY; y+=1.*Gaudi::Units::mm) {
92 const Amg::Vector3D locPos{x,y,0};
93 if (!m_testActsSurf && !design.insideTrapezoid(locPos.block<2,1>(0,0))) {
94 continue;
95 } else if (m_testActsSurf && !plane.insideBounds(locPos.block<2,1>(0,0))) {
96 continue;
97 }
98
99 const Amg::Vector3D globPos = plane. localToGlobalTransform(gctx->context()) * locPos;
100 histo->Fill(globPos.x(), globPos.y());
101 }
102 }
103 }
104 }
105 }
106
107 std::vector<const TgcReadoutElement*> tgcs = m_detMgr->getAllTgcReadoutElements();
108 for (const TgcReadoutElement* tgc : tgcs) {
109 if (!m_plotTgc) {
110 ATH_MSG_DEBUG("Skipping plotting of TGC readout elements");
111 break;
112 }
113 ATH_MSG_INFO("plotting active areas for TGC "<< m_idHelperSvc->toString(tgc->identify()));
114 for (unsigned int gasGap = 1; gasGap <= tgc->nGasGaps(); ++gasGap){
115 for (bool isStrip : {false, true}) {
116 int stationNameIndex = std::stoi(m_idHelperSvc->stationNameString(tgc->identify()).substr(1,1));
117 const IdentifierHash hash = TgcReadoutElement::constructHash(stationNameIndex, gasGap, isStrip);
118 if(!tgc->numChannels(hash)) { // for some gas gaps we do not read the strips
119 continue;
120 }
121 auto histo = m_tgcActiveAreas[hash];
122 const StripDesign& design {isStrip? static_cast<const StripDesign&>(tgc->stripLayout(hash)) :
123 static_cast<const StripDesign&>(tgc->wireGangLayout(hash))};
124
125 const Acts::Surface& plane{tgc->surface(tgc->layerHash(hash))};
126 const double halfY = 1.5*design.longHalfHeight();
127 const double halfX = 1.5*design.halfWidth();
128 for (double x = -halfX; x <= halfX; x+= 2.*Gaudi::Units::mm){
129 for (double y = -halfY; y<= halfY; y+=2.*Gaudi::Units::mm) {
130 const Amg::Vector3D locPos{x,y,0};
131 if (!m_testActsSurf && !design.insideTrapezoid(locPos.block<2,1>(0,0))) {
132 continue;
133 } else if (m_testActsSurf && !plane.insideBounds(locPos.block<2,1>(0,0))) {
134 continue;
135 }
136
137 const Amg::Vector3D globPos = plane. localToGlobalTransform(gctx->context()) * locPos;
138 histo->Fill(globPos.x(), globPos.y());
139 }
140 }
141 }
142 }
143 }
144
145
146
147
148 return StatusCode::SUCCESS;
149}
151 for (unsigned int ml =1 ; ml <= 2; ++ml) {
152 for(unsigned int active =1 ; active <= 2; ++active){
153 for (int chanType : {chType::Strip, chType::Pad, chType::Wire}){
154 for (unsigned int gasGap =1; gasGap <= 4; ++gasGap) {
155 std::string histoName = "STGC_"+std::string(active == 1? "A" : "C") + "M" +
156 std::to_string(ml) + "G" + std::to_string(gasGap) +
157 + (chanType == chType::Strip? "S" :
158 chanType == chType::Wire ? "W" : "P");
159
160 auto newHisto = std::make_unique<TH2I>(histoName.c_str(),
161 "ActiveNSW;x [mm]; y [mm]", 1000, -5001, 5001., 1000,
162 -5001., 5001.);
163 m_stgcActiveAreas[sTgcReadoutElement::createHash(gasGap, chanType, active + 10 * ml)] = newHisto.get();
164 ATH_CHECK(histSvc()->regHist("/GEOMODELTESTER/ActiveSurfaces/"+ histoName,std::move(newHisto)));
165 }
166 }
167 }
168 }
169 return StatusCode::SUCCESS;
170}
172
173 for (unsigned int ml = 1; ml <= 2; ++ml) {
174 for (unsigned int active = 1; active <= 2; ++ active) {
175 for (unsigned int gasGap = 1; gasGap <= 4; ++gasGap) {
176 std::string histoName = "MM_"+std::string(active == 1? "A" : "C") + "M" +
177 std::to_string(ml) + "G" + std::to_string(gasGap);
178 auto newHisto = std::make_unique<TH2I>(histoName.c_str(),
179 "ActiveNSW;x [mm]; y [mm]", 1000, -5001, 5001., 1000,
180 -5001., 5001.);
181 m_mmActiveAreas[MmReadoutElement::createHash(gasGap, active + 10 * ml)] = newHisto.get();
182 ATH_CHECK(histSvc()->regHist("/GEOMODELTESTER/ActiveSurfaces/"+ histoName,std::move(newHisto)));
183 }
184 }
185 }
186 return StatusCode::SUCCESS;
187}
188
189
191 std::set<std::string> tgcNames;
192 for(const TgcReadoutElement* tgc : m_detMgr->getAllTgcReadoutElements()) {
193 tgcNames.insert(m_idHelperSvc->stationNameString(tgc->identify()));
194 }
195 for (unsigned int gasGap = 1; gasGap <= 3; ++gasGap){
196 for (bool isStrip : {false, true}) {
197 for (uint station: {1,2,3,4} ){
198 std::string histoName = "TGC_T:"+ std::to_string(station) + "G:" + std::to_string(gasGap) + (isStrip ? "S" : "W");
199 auto newHisto = std::make_unique<TH2I>(histoName.c_str(),
200 "ActiveTGC;x [mm]; y [mm]", 3000, -15001, 15001., 3000,
201 -15001., 15001.);
202 m_tgcActiveAreas[TgcReadoutElement::constructHash(station, gasGap, isStrip)] = newHisto.get();
203 ATH_CHECK(histSvc()->regHist("/GEOMODELTESTER/ActiveSurfaces/"+ histoName,std::move(newHisto)));
204 }
205 }
206 }
207 return StatusCode::SUCCESS;
208}
209}
#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
virtual StatusCode execute()
Execute method without EventContext (deprecated).
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 gasGap, const unsigned channelType, const unsigned channel, const unsigned 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.