ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_ModuleVetoTool Class Reference

Tool allowing one to manually declare detector elements as 'bad' in the joboptions file. More...

#include <SCT_ModuleVetoTool.h>

Inheritance diagram for SCT_ModuleVetoTool:
Collaboration diagram for SCT_ModuleVetoTool:

Public Member Functions

 SCT_ModuleVetoTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~SCT_ModuleVetoTool ()=default
virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual bool canReportAbout (InDetConditions::Hierarchy h) const override
 Can the service report about the given component? (chip, module...).
virtual bool isGood (const Identifier &elementId, const EventContext &ctx, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
 Is the detector element good?
virtual bool isGood (const IdentifierHash &hashId, const EventContext &ctx) const override
 is it good?, using wafer hash
virtual void getDetectorElementStatus (const EventContext &ctx, InDet::SiDetectorElementStatus &element_status, SG::WriteCondHandle< InDet::SiDetectorElementStatus > *whandle) const override

Private Member Functions

StatusCode fillData ()
const SCT_ModuleVetoCondDatagetCondData (const EventContext &ctx) const

Private Attributes

StringArrayProperty m_badElements {this, "BadModuleIdentifiers", {}, "list of bad detector elements (= module sides)"}
SCT_ModuleVetoCondData m_localCondData {}
const SCT_IDm_pHelper {nullptr}
bool m_useDatabase {false}
StringProperty m_JsonLocation {this, "JsonPath", "", "Path to the JSON file containing list of modules to be masked."}
BooleanProperty m_maskLayers {this, "MaskLayers", false, "Mask full layers/disks in overlay"}
IntegerProperty m_maskSide {this, "MaskSide", -1, "Mask full modules (-1), inner (0) or outer (1) sides"}
IntegerArrayProperty m_layersToMask {this, "LayersToMask", {}, "Which barrel layers to mask out, goes from 0 to N-1"}
IntegerArrayProperty m_disksToMask {this, "DisksToMask", {}, "Which endcap disks to mask out, goes from -N+1 to N+1 , skipping zero"}
SG::ReadCondHandleKey< SCT_ModuleVetoCondDatam_condKey {this, "CondKey", "SCT_ModuleVetoCondData", "SCT modules to be vetoed"}

Detailed Description

Tool allowing one to manually declare detector elements as 'bad' in the joboptions file.

Definition at line 36 of file SCT_ModuleVetoTool.h.

Constructor & Destructor Documentation

◆ SCT_ModuleVetoTool()

SCT_ModuleVetoTool::SCT_ModuleVetoTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 32 of file SCT_ModuleVetoTool.cxx.

32 :
33 base_class(type, name, parent)
34{
35}

◆ ~SCT_ModuleVetoTool()

virtual SCT_ModuleVetoTool::~SCT_ModuleVetoTool ( )
virtualdefault

Member Function Documentation

◆ canReportAbout()

bool SCT_ModuleVetoTool::canReportAbout ( InDetConditions::Hierarchy h) const
overridevirtual

Can the service report about the given component? (chip, module...).

Definition at line 93 of file SCT_ModuleVetoTool.cxx.

◆ fillData()

StatusCode SCT_ModuleVetoTool::fillData ( )
private

Definition at line 152 of file SCT_ModuleVetoTool.cxx.

152 {
153 // Reset SCT_ModuleVetoCondData
154 m_localCondData.clear();
155
156 // @TODO: This part should be changed to use PathResolver before using in production.
157
158 //Read bad module IDs from json file.
159 if(!m_JsonLocation.empty())
160 {
161 std::ifstream json_file(m_JsonLocation);
162 if (!json_file.is_open()) {
163 ATH_MSG_FATAL("Failed to open the json file.");
164 return StatusCode::FAILURE;
165 }
166
167 json data = json::parse(json_file);
168
169 for(const auto& i:data)
170 {
171 std::string id_mod = i["Decimal_ID"];
172 unsigned long long id_cstring = std::stoull(id_mod);
173 m_localCondData.setBadWaferId(Identifier(id_cstring));
174 ATH_MSG_DEBUG("Masking Module ID: " << id_cstring << ".");
175 }
176 return StatusCode::SUCCESS;
177 }
178
179
180 // Fill data based on properties
181 StatusCode sc{StatusCode::SUCCESS};
182 if ((m_badElements.value().size() - static_cast<int>(m_useDatabase)) == 0 and (not m_maskLayers)) {
183 ATH_MSG_INFO("No bad modules in job options.");
184 return sc;
185 }
186
187
188 bool success{true};
189 std::vector<std::string>::const_iterator pId{m_badElements.value().begin()};
190 std::vector<std::string>::const_iterator last{m_badElements.value().end()};
191 for(; pId not_eq last;++pId) {
192 unsigned long long idToWrite{static_cast<unsigned long long>(atoll(pId->c_str()))};
193 if (*pId != databaseSignature) success &= m_localCondData.setBadWaferId(Identifier(idToWrite));
194 }
195
196
197
198 if (m_maskLayers) {
199 ATH_MSG_INFO("Masking " << m_layersToMask.size() << " SCT Layers");
200 ATH_MSG_INFO("Masking " << m_disksToMask.size() << " SCT Disks");
201 for(unsigned int i{0}; i < m_pHelper->wafer_hash_max(); i++) {
202 Identifier mID{m_pHelper->wafer_id(i)};
203 int bec{m_pHelper->barrel_ec(mID)};
204 int side{m_pHelper->side(mID)};
205 int layer_disk{m_pHelper->layer_disk(mID)};
206
207 if ((bec == 0 and (m_maskSide==-1 or side==m_maskSide) and (std::find(m_layersToMask.begin(), m_layersToMask.end(), layer_disk ) != m_layersToMask.end())) or
208 (bec == 2 and (m_maskSide==-1 or side==m_maskSide) and (std::find(m_disksToMask.begin(), m_disksToMask.end(), (layer_disk + 1)) != m_disksToMask.end())) or
209 (bec == -2 and (m_maskSide==-1 or side==m_maskSide) and (std::find(m_disksToMask.begin(), m_disksToMask.end(), -1*(layer_disk + 1)) != m_disksToMask.end()))) {
210 ATH_MSG_DEBUG("Masking ID Hash " << i);
211 m_localCondData.setBadWaferId(mID);
212 }
213 }
214 }
215
216 ATH_MSG_INFO(m_localCondData.size() << " bad wafers are defined via properties.");
217
218 m_localCondData.setFilled();
219 ATH_MSG_DEBUG("Successfully filled bad SCT identifiers list");
220 return (success ? sc : StatusCode::FAILURE);
221}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
nlohmann::json json
static Double_t sc
static const std::string databaseSignature
IntegerProperty m_maskSide
StringProperty m_JsonLocation
IntegerArrayProperty m_disksToMask
StringArrayProperty m_badElements
const SCT_ID * m_pHelper
SCT_ModuleVetoCondData m_localCondData
IntegerArrayProperty m_layersToMask
BooleanProperty m_maskLayers
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ finalize()

StatusCode SCT_ModuleVetoTool::finalize ( )
overridevirtual

Definition at line 88 of file SCT_ModuleVetoTool.cxx.

88 {
89 return StatusCode::SUCCESS;
90}

◆ getCondData()

const SCT_ModuleVetoCondData * SCT_ModuleVetoTool::getCondData ( const EventContext & ctx) const
private

Definition at line 224 of file SCT_ModuleVetoTool.cxx.

224 {
225 SG::ReadCondHandle<SCT_ModuleVetoCondData> condData{m_condKey, ctx};
226 return condData.retrieve();
227}
SG::ReadCondHandleKey< SCT_ModuleVetoCondData > m_condKey
const_pointer_type retrieve()

◆ getDetectorElementStatus()

void SCT_ModuleVetoTool::getDetectorElementStatus ( const EventContext & ctx,
InDet::SiDetectorElementStatus & element_status,
SG::WriteCondHandle< InDet::SiDetectorElementStatus > * whandle ) const
overridevirtual

Definition at line 123 of file SCT_ModuleVetoTool.cxx.

124 {
125 std::vector<bool> &status = element_status.getElementStatus();
126 if (status.empty()) {
127 status.resize(m_pHelper->wafer_hash_max(),true);
128 }
129 for (const Identifier &wafer_id: m_localCondData.badWaferIds()) {
130 status.at( m_pHelper->wafer_hash(wafer_id) ) = false;
131 }
132 if (m_useDatabase) {
133 SG::ReadCondHandle<SCT_ModuleVetoCondData> condDataHandle{m_condKey, ctx};
134 if (not condDataHandle.isValid()) {
135 ATH_MSG_ERROR("Failed to get " << m_condKey.key());
136 return;
137 }
138 const SCT_ModuleVetoCondData* condData{ condDataHandle.cptr() };
139 if (whandle) {
140 whandle->addDependency (condDataHandle);
141 }
142 if (condData) {
143 for (const Identifier &wafer_id: condData->badWaferIds()) {
144 status.at( m_pHelper->wafer_hash(wafer_id) ) = false;
145 }
146 }
147 }
148}
#define ATH_MSG_ERROR(x)
const std::vector< bool > & getElementStatus() const
const std::set< Identifier > & badWaferIds() const
const_pointer_type cptr()
void addDependency(const EventIDRange &range)
status
Definition merge.py:16

◆ initialize()

StatusCode SCT_ModuleVetoTool::initialize ( )
overridevirtual

Definition at line 39 of file SCT_ModuleVetoTool.cxx.

39 {
40 if (m_maskLayers and m_layersToMask.size()==0 and m_disksToMask.size()==0) {
41 ATH_MSG_INFO("Layer/Disk masking enabled, but no layer/disk specified!");
42 m_maskLayers = false;
43 }
44
45 if ((not m_maskLayers) and (m_layersToMask.size() or m_disksToMask.size())) {
46 ATH_MSG_INFO("Layer/Disk to mask specified, but masking is disabled!");
47 }
48
49 if ((not m_maskLayers) and m_maskSide!=-1) {
50 ATH_MSG_INFO("Layer/Disk side to mask specified, but masking is disabled!");
51 }
52
53 if (m_maskLayers and m_disksToMask.size() and (std::find(m_disksToMask.begin(), m_disksToMask.end(),0)!=m_disksToMask.end())) {
54 ATH_MSG_WARNING("0th Disk not defined (-N to N) - check your setup!");
55 }
56
57 if (detStore()->retrieve(m_pHelper, "SCT_ID").isFailure()) {
58 ATH_MSG_FATAL("SCT helper failed to retrieve");
59 return StatusCode::FAILURE;
60 } else {
61 ATH_MSG_INFO("Successfully retrieved SCT_ID helper");
62 }
63
64 // If "database" is found in m_badElements, COOL database is used.
65 m_useDatabase=(std::find(m_badElements.value().begin(), m_badElements.value().end(), databaseSignature) != m_badElements.value().end());
66 ATH_MSG_INFO("m_useDatabase is " << m_useDatabase);
67
68 if (not m_useDatabase) {
69 if (fillData().isFailure()) {
70 ATH_MSG_FATAL("Failed to fill data");
71 return StatusCode::FAILURE;
72 }
73 }
74
75 // Read Cond Handle
77
78 const std::string databaseUseString{m_useDatabase ? "" : "not "};
79 ATH_MSG_INFO("Initialized veto service with data, "
80 << (m_badElements.value().size() - static_cast<long unsigned int>(m_useDatabase))
81 << " elements declared bad. Database will " << databaseUseString << "be used.");
82
83 return StatusCode::SUCCESS;
84}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)

◆ isGood() [1/2]

bool SCT_ModuleVetoTool::isGood ( const Identifier & elementId,
const EventContext & ctx,
InDetConditions::Hierarchy h = InDetConditions::DEFAULT ) const
overridevirtual

Is the detector element good?

Definition at line 98 of file SCT_ModuleVetoTool.cxx.

98 {
99 if (not canReportAbout(h)) return true;
100
101 const Identifier waferId{m_pHelper->wafer_id(elementId)};
102
103 // Bad wafer in properties
104 if (m_localCondData.isBadWaferId(waferId)) return false;
105 // If database is not used, all wafer IDs here should be good.
106 if (not m_useDatabase) return true;
107
108 const SCT_ModuleVetoCondData* condData{getCondData(ctx)};
109 // If database cannot be retrieved, all wafer IDs are good.
110 if (condData==nullptr) return true;
111
112 // Return the result of database
113 return (not condData->isBadWaferId(waferId));
114}
bool isBadWaferId(const Identifier waferId) const
Check if a wafer ID is bad or not.
virtual bool canReportAbout(InDetConditions::Hierarchy h) const override
Can the service report about the given component? (chip, module...).
const SCT_ModuleVetoCondData * getCondData(const EventContext &ctx) const

◆ isGood() [2/2]

bool SCT_ModuleVetoTool::isGood ( const IdentifierHash & hashId,
const EventContext & ctx ) const
overridevirtual

is it good?, using wafer hash

Definition at line 117 of file SCT_ModuleVetoTool.cxx.

117 {
118 Identifier elementId{m_pHelper->wafer_id(hashId)};
119 return isGood(elementId, ctx, InDetConditions::SCT_SIDE);
120}
virtual bool isGood(const Identifier &elementId, const EventContext &ctx, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
Is the detector element good?

Member Data Documentation

◆ m_badElements

StringArrayProperty SCT_ModuleVetoTool::m_badElements {this, "BadModuleIdentifiers", {}, "list of bad detector elements (= module sides)"}
private

Definition at line 58 of file SCT_ModuleVetoTool.h.

58{this, "BadModuleIdentifiers", {}, "list of bad detector elements (= module sides)"};

◆ m_condKey

SG::ReadCondHandleKey<SCT_ModuleVetoCondData> SCT_ModuleVetoTool::m_condKey {this, "CondKey", "SCT_ModuleVetoCondData", "SCT modules to be vetoed"}
private

Definition at line 69 of file SCT_ModuleVetoTool.h.

69{this, "CondKey", "SCT_ModuleVetoCondData", "SCT modules to be vetoed"};

◆ m_disksToMask

IntegerArrayProperty SCT_ModuleVetoTool::m_disksToMask {this, "DisksToMask", {}, "Which endcap disks to mask out, goes from -N+1 to N+1 , skipping zero"}
private

Definition at line 66 of file SCT_ModuleVetoTool.h.

66{this, "DisksToMask", {}, "Which endcap disks to mask out, goes from -N+1 to N+1 , skipping zero"};

◆ m_JsonLocation

StringProperty SCT_ModuleVetoTool::m_JsonLocation {this, "JsonPath", "", "Path to the JSON file containing list of modules to be masked."}
private

Definition at line 62 of file SCT_ModuleVetoTool.h.

62{this, "JsonPath", "", "Path to the JSON file containing list of modules to be masked."};

◆ m_layersToMask

IntegerArrayProperty SCT_ModuleVetoTool::m_layersToMask {this, "LayersToMask", {}, "Which barrel layers to mask out, goes from 0 to N-1"}
private

Definition at line 65 of file SCT_ModuleVetoTool.h.

65{this, "LayersToMask", {}, "Which barrel layers to mask out, goes from 0 to N-1"};

◆ m_localCondData

SCT_ModuleVetoCondData SCT_ModuleVetoTool::m_localCondData {}
private

Definition at line 59 of file SCT_ModuleVetoTool.h.

59{};

◆ m_maskLayers

BooleanProperty SCT_ModuleVetoTool::m_maskLayers {this, "MaskLayers", false, "Mask full layers/disks in overlay"}
private

Definition at line 63 of file SCT_ModuleVetoTool.h.

63{this, "MaskLayers", false, "Mask full layers/disks in overlay"};

◆ m_maskSide

IntegerProperty SCT_ModuleVetoTool::m_maskSide {this, "MaskSide", -1, "Mask full modules (-1), inner (0) or outer (1) sides"}
private

Definition at line 64 of file SCT_ModuleVetoTool.h.

64{this, "MaskSide", -1, "Mask full modules (-1), inner (0) or outer (1) sides"};

◆ m_pHelper

const SCT_ID* SCT_ModuleVetoTool::m_pHelper {nullptr}
private

Definition at line 60 of file SCT_ModuleVetoTool.h.

60{nullptr};

◆ m_useDatabase

bool SCT_ModuleVetoTool::m_useDatabase {false}
private

Definition at line 61 of file SCT_ModuleVetoTool.h.

61{false};

The documentation for this class was generated from the following files: