ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SCT_ModuleVetoTool Class Reference

#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...) More...
 
virtual bool isGood (const Identifier &elementId, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
 Is the detector element good? More...
 
virtual bool isGood (const Identifier &elementId, const EventContext &ctx, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
 
virtual bool isGood (const IdentifierHash &hashId) const override
 is it good?, using wafer hash More...
 
virtual bool isGood (const IdentifierHash &hashId, const EventContext &ctx) const override
 
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.

93  {
95 }

◆ fillData()

StatusCode SCT_ModuleVetoTool::fillData ( )
private

Definition at line 164 of file SCT_ModuleVetoTool.cxx.

164  {
165  // Reset SCT_ModuleVetoCondData
167 
168  // @TODO: This part should be changed to use PathResolver before using in production.
169 
170  //Read bad module IDs from json file.
171  if(!m_JsonLocation.empty())
172  {
173  std::ifstream json_file(m_JsonLocation);
174  if (!json_file.is_open()) {
175  ATH_MSG_FATAL("Failed to open the json file.");
176  return StatusCode::FAILURE;
177  }
178 
179  json data = json::parse(json_file);
180 
181  for(const auto& i:data)
182  {
183  std::string id_mod = i["Decimal_ID"];
184  unsigned long long id_cstring = std::stoull(id_mod);
186  ATH_MSG_DEBUG("Masking Module ID: " << id_cstring << ".");
187  }
188  return StatusCode::SUCCESS;
189  }
190 
191 
192  // Fill data based on properties
193  StatusCode sc{StatusCode::SUCCESS};
194  if ((m_badElements.value().size() - static_cast<int>(m_useDatabase)) == 0 and (not m_maskLayers)) {
195  ATH_MSG_INFO("No bad modules in job options.");
196  return sc;
197  }
198 
199 
200  bool success{true};
201  std::vector<std::string>::const_iterator pId{m_badElements.value().begin()};
202  std::vector<std::string>::const_iterator last{m_badElements.value().end()};
203  for(; pId not_eq last;++pId) {
204  unsigned long long idToWrite{static_cast<unsigned long long>(atoll(pId->c_str()))};
205  if (*pId != databaseSignature) success &= m_localCondData.setBadWaferId(Identifier(idToWrite));
206  }
207 
208 
209 
210  if (m_maskLayers) {
211  ATH_MSG_INFO("Masking " << m_layersToMask.size() << " SCT Layers");
212  ATH_MSG_INFO("Masking " << m_disksToMask.size() << " SCT Disks");
213  for(unsigned int i{0}; i < m_pHelper->wafer_hash_max(); i++) {
215  int bec{m_pHelper->barrel_ec(mID)};
216  int side{m_pHelper->side(mID)};
217  int layer_disk{m_pHelper->layer_disk(mID)};
218 
219  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
220  (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
221  (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()))) {
222  ATH_MSG_DEBUG("Masking ID Hash " << i);
224  }
225  }
226  }
227 
228  ATH_MSG_INFO(m_localCondData.size() << " bad wafers are defined via properties.");
229 
231  ATH_MSG_DEBUG("Successfully filled bad SCT identifiers list");
232  return (success ? sc : StatusCode::FAILURE);
233 }

◆ 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 236 of file SCT_ModuleVetoTool.cxx.

236  {
238  return condData.retrieve();
239 }

◆ getDetectorElementStatus()

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

Definition at line 135 of file SCT_ModuleVetoTool.cxx.

136  {
137  std::vector<bool> &status = element_status.getElementStatus();
138  if (status.empty()) {
139  status.resize(m_pHelper->wafer_hash_max(),true);
140  }
141  for (const Identifier &wafer_id: m_localCondData.badWaferIds()) {
142  status.at( m_pHelper->wafer_hash(wafer_id) ) = false;
143  }
144  if (m_useDatabase) {
146  if (not condDataHandle.isValid()) {
147  ATH_MSG_ERROR("Failed to get " << m_condKey.key());
148  return;
149  }
150  const SCT_ModuleVetoCondData* condData{ condDataHandle.cptr() };
151  if (whandle) {
152  whandle->addDependency (condDataHandle);
153  }
154  if (condData) {
155  for (const Identifier &wafer_id: condData->badWaferIds()) {
156  status.at( m_pHelper->wafer_hash(wafer_id) ) = false;
157  }
158  }
159  }
160 }

◆ 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 }

◆ isGood() [1/4]

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

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 }

◆ isGood() [2/4]

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

Is the detector element good?

Definition at line 117 of file SCT_ModuleVetoTool.cxx.

117  {
118  const EventContext& ctx{Gaudi::Hive::currentContext()};
119  return isGood(elementId, ctx, h);
120 }

◆ isGood() [3/4]

bool SCT_ModuleVetoTool::isGood ( const IdentifierHash hashId) const
overridevirtual

is it good?, using wafer hash

Definition at line 129 of file SCT_ModuleVetoTool.cxx.

129  {
130  const EventContext& ctx{Gaudi::Hive::currentContext()};
131  return isGood(hashId, ctx);
132 }

◆ isGood() [4/4]

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

Definition at line 123 of file SCT_ModuleVetoTool.cxx.

123  {
124  Identifier elementId{m_pHelper->wafer_id(hashId)};
125  return isGood(elementId, ctx, InDetConditions::SCT_SIDE);
126 }

Member Data Documentation

◆ m_badElements

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

Definition at line 60 of file SCT_ModuleVetoTool.h.

◆ m_condKey

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

Definition at line 71 of file SCT_ModuleVetoTool.h.

◆ 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 68 of file SCT_ModuleVetoTool.h.

◆ 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 64 of file SCT_ModuleVetoTool.h.

◆ 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 67 of file SCT_ModuleVetoTool.h.

◆ m_localCondData

SCT_ModuleVetoCondData SCT_ModuleVetoTool::m_localCondData {}
private

Definition at line 61 of file SCT_ModuleVetoTool.h.

◆ m_maskLayers

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

Definition at line 65 of file SCT_ModuleVetoTool.h.

◆ m_maskSide

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

Definition at line 66 of file SCT_ModuleVetoTool.h.

◆ m_pHelper

const SCT_ID* SCT_ModuleVetoTool::m_pHelper {nullptr}
private

Definition at line 62 of file SCT_ModuleVetoTool.h.

◆ m_useDatabase

bool SCT_ModuleVetoTool::m_useDatabase {false}
private

Definition at line 63 of file SCT_ModuleVetoTool.h.


The documentation for this class was generated from the following files:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
SCT_ModuleVetoTool::m_JsonLocation
StringProperty m_JsonLocation
Definition: SCT_ModuleVetoTool.h:64
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCT_ModuleVetoTool::isGood
virtual bool isGood(const Identifier &elementId, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
Is the detector element good?
Definition: SCT_ModuleVetoTool.cxx:117
InDet::SiDetectorElementStatus::getElementStatus
const std::vector< bool > & getElementStatus() const
Definition: SiDetectorElementStatus.h:116
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
json
nlohmann::json json
Definition: HistogramDef.cxx:9
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
SCT_ModuleVetoCondData::setFilled
void setFilled()
Set data filled.
Definition: SCT_ModuleVetoCondData.cxx:37
SCT_ModuleVetoTool::canReportAbout
virtual bool canReportAbout(InDetConditions::Hierarchy h) const override
Can the service report about the given component? (chip, module...)
Definition: SCT_ModuleVetoTool.cxx:93
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
SCT_ModuleVetoCondData::clear
void clear()
Clear.
Definition: SCT_ModuleVetoCondData.cxx:30
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SCT_ModuleVetoTool::m_pHelper
const SCT_ID * m_pHelper
Definition: SCT_ModuleVetoTool.h:62
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TRT::Hit::side
@ side
Definition: HitInfo.h:83
SCT_ModuleVetoCondData
Class for data object used in SCT_ModuleVetoCondAlg, SCT_LinkMaskingCondAlg, SCT_ModuleVetoTool,...
Definition: SCT_ModuleVetoCondData.h:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
SCT_ModuleVetoTool::m_badElements
StringArrayProperty m_badElements
Definition: SCT_ModuleVetoTool.h:60
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SCT_ModuleVetoTool::fillData
StatusCode fillData()
Definition: SCT_ModuleVetoTool.cxx:164
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_ModuleVetoTool::m_disksToMask
IntegerArrayProperty m_disksToMask
Definition: SCT_ModuleVetoTool.h:68
SCT_ID::wafer_hash
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition: SCT_ID.h:492
SCT_ModuleVetoCondData::size
long unsigned int size() const
Get the number of bad wafers.
Definition: SCT_ModuleVetoCondData.cxx:49
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
SCT_ModuleVetoTool::m_maskLayers
BooleanProperty m_maskLayers
Definition: SCT_ModuleVetoTool.h:65
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:636
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SCT_ModuleVetoCondData::badWaferIds
const std::set< Identifier > & badWaferIds() const
Definition: SCT_ModuleVetoCondData.h:46
SCT_ModuleVetoCondData::isBadWaferId
bool isBadWaferId(const Identifier waferId) const
Check if a wafer ID is bad or not.
Definition: SCT_ModuleVetoCondData.cxx:23
SCT_ModuleVetoTool::m_maskSide
IntegerProperty m_maskSide
Definition: SCT_ModuleVetoTool.h:66
h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SCT_ModuleVetoTool::getCondData
const SCT_ModuleVetoCondData * getCondData(const EventContext &ctx) const
Definition: SCT_ModuleVetoTool.cxx:236
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
SCT_ModuleVetoTool::m_layersToMask
IntegerArrayProperty m_layersToMask
Definition: SCT_ModuleVetoTool.h:67
merge.status
status
Definition: merge.py:17
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
InDetConditions::SCT_SIDE
@ SCT_SIDE
Definition: InDetHierarchy.h:14
InDetConditions::DEFAULT
@ DEFAULT
Definition: InDetHierarchy.h:14
SCT_ModuleVetoTool::m_condKey
SG::ReadCondHandleKey< SCT_ModuleVetoCondData > m_condKey
Definition: SCT_ModuleVetoTool.h:71
SCT_ModuleVetoTool::m_useDatabase
bool m_useDatabase
Definition: SCT_ModuleVetoTool.h:63
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition: WriteCondHandle.h:275
SCT_ModuleVetoTool::m_localCondData
SCT_ModuleVetoCondData m_localCondData
Definition: SCT_ModuleVetoTool.h:61
Identifier
Definition: IdentifierFieldParser.cxx:14
SCT_ModuleVetoCondData::setBadWaferId
bool setBadWaferId(const Identifier waferId)
Set a bad wafer ID.
Definition: SCT_ModuleVetoCondData.cxx:17