ATLAS Offline Software
SCT_CalibBsErrorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "SCT_CalibBsErrorTool.h"
12 #include "SCT_CalibUtilities.h"
13 #include "SCT_CalibNumbers.h"
14 
15 #include "Identifier/Identifier.h"
17 
18 // RAW data access
21 
22 #include "GaudiKernel/ITHistSvc.h"
23 
24 #include "TFile.h"
25 #include "TH1I.h"
26 
27 #include <set>
28 
29 using namespace SCT_CalibAlgs;
30 
31 static const std::string pathRoot{"/BSErrors/"};
32 static const std::string detectorPaths[] {"SCTEC/", "SCTB/","SCTEA/"};
33 static const std::string detectorNames[] {"negativeEndcap", "barrel", "positiveEndcap"};
34 static const int n_BSErrorType{15};
35 static const int firstBSErrorType{0};
36 static const int lastBSErrorType{14};
37 
38 SCT_CalibBsErrorTool::SCT_CalibBsErrorTool(const std::string& type, const std::string& name, const IInterface* parent) :
39  base_class(type, name, parent)
40 {
41 }
42 
45  ATH_CHECK(service("THistSvc", m_thistSvc));
46  ATH_CHECK(detStore()->retrieve(m_pSCTHelper, "SCT_ID"));
48 
52 
53  return StatusCode::SUCCESS;
54 }
55 
58  ATH_MSG_INFO("Finalize of SCT_CalibBsErrorTool");
59 
60  return StatusCode::SUCCESS;
61 }
62 
63 bool
65  bool result{true};
66  m_phistoVector.clear();
67  std::string histoName{pathRoot+"GENERAL/"};
68  //histogram for numbers of events
69  m_numberOfEventsHisto = new TH1I{"events", "Events", 1, 0.5, 1.5};
70  if (m_thistSvc->regHist(histoName.c_str(), m_numberOfEventsHisto ).isFailure()) {
71  ATH_MSG_ERROR("Error in booking BSErrors histogram");
72  }
73  //--- BSErrors for each wafer
76  for (; waferItr not_eq waferItrE; ++waferItr) {
77  Identifier waferId{*waferItr};
78  const int bec{m_pSCTHelper->barrel_ec(waferId)};
79  const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)};
80  std::string histotitle{std::string{"SCT "} + detectorNames[bec2Index(bec)] + std::string{" BSErrors : plane "} + formattedPosition};
81  const std::string name{pathRoot+detectorPaths[bec2Index(m_pSCTHelper->barrel_ec(waferId))] + formattedPosition};
82  TH1F* hitmapHisto_tmp{new TH1F{TString{formattedPosition}, TString{histotitle}, n_BSErrorType, firstBSErrorType-0.5, lastBSErrorType+0.5}};
83  if (m_thistSvc->regHist(name.c_str(), hitmapHisto_tmp).isFailure()) {
84  ATH_MSG_ERROR("Error in booking BSErrors histogram");
85  }
86  m_phistoVector.push_back(hitmapHisto_tmp);
87  }
88  return result;
89 }
90 
91 bool
92 SCT_CalibBsErrorTool::read(const std::string& fileName) {
93  bool result{true};
94  //pointers to the histos are deleted by m_thistSvc methods
95  m_phistoVector.clear();
96  TFile* fileHitmap{TFile::Open(fileName.c_str())};
97  ATH_MSG_INFO("opening Hitmap file : " << fileName.c_str());
98 
99  if (fileHitmap==nullptr) {
100  ATH_MSG_ERROR("can not open Hitmap file : " << fileName.c_str());
101  return result;
102  }
103  //histogram for numbers of events
104  m_numberOfEventsHisto = static_cast<TH1I*>(fileHitmap->Get("GENERAL/events"));
105  if (m_numberOfEventsHisto==nullptr) {
106  ATH_MSG_ERROR("Error in reading EventNumber histogram");
107  }
108  //histograms for each wafer
110  for (; waferItr not_eq m_waferItrEnd; ++waferItr) {
111  const Identifier& waferId{*waferItr};
112  const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)};
113  std::string name{detectorPaths[bec2Index(m_pSCTHelper->barrel_ec(waferId))] + formattedPosition};
114  TH1F* hitmapHisto_tmp{static_cast<TH1F*>(fileHitmap->Get(name.c_str()))};
115  if (hitmapHisto_tmp==nullptr) {
116  ATH_MSG_ERROR("Error in reading BSErrors histogram");
117  } else {
118  m_phistoVector.push_back(hitmapHisto_tmp);
119  }
120  }
121  return result;
122 }
123 
124 /*
125 bool
126 SCT_CalibBsErrorTool::read(const std::string& fileName) {
127  ATH_MSG_ERROR("Reading BsError histograms from " << fileName.c_str() << " is not supported!");
128  return false;
129 }
130 */
131 
132 bool
133 SCT_CalibBsErrorTool::fill(const bool fromData) {
134  if (fromData) {
135  return fillFromData();
136  }
137  bool result{true};
138  //--- Number of event
139  m_numberOfEventsHisto->Fill( 1 );
140  //--- Fill BSErrors
141  const int maxEntry{static_cast<int>(m_scterr_type->size())};
142  for (int i{0}; i != maxEntry; ++i ) {
143  int bec{(*m_scterr_bec)[i]};
144  int layer{(*m_scterr_layer)[i]};
145  int phi{(*m_scterr_phi)[i]};
146  int eta{(*m_scterr_eta)[i]};
147  int side{(*m_scterr_side)[i]};
148  int type{(*m_scterr_type)[i]};
149  Identifier waferId{m_pSCTHelper->wafer_id( bec, layer, phi, eta, side )};
150  fillBsErrorsForWafer(waferId, type);
151  }
152  return result;
153 }
154 
155 bool
157  bool result{true};
158  //--- Number of event
159  m_numberOfEventsHisto->Fill( 1 );
160  //--- Loop over BSErrors
161  const EventContext& ctx{Gaudi::Hive::currentContext()};
163  const std::set<IdentifierHash> errorSet{m_bytestreamErrorsTool->getErrorSet(type, ctx)};
164  for(const auto& idHash : errorSet) {
165  Identifier waferId{m_pSCTHelper->wafer_id(idHash)};
166  fillBsErrorsForWafer(waferId, type);
167  }
168  }
169  return result;
170 }
171 
172 void
173 SCT_CalibBsErrorTool::fillBsErrorsForWafer(const Identifier& waferId, const int type) {
174  int iWaferHash{static_cast<int>(m_pSCTHelper->wafer_hash(waferId))};
175  const std::string osWafer{formatPosition(waferId, m_pSCTHelper,".")};
176  //--- Protection for wrong waferID
177  if ( iWaferHash < 0 || iWaferHash >= m_maxHash ) {
178  ATH_MSG_WARNING("WaferHash " << iWaferHash << " is out of range : [ bec.layer.eta.phi.side, BSErrorType ] = [ " << osWafer << ", " << type << " ]");
179  } else {
180  ATH_MSG_DEBUG("BSError : [ bec.layer.eta.phi.side, Type ] = [ " << osWafer<< ", " << type << " ]");
181  m_phistoVector[ iWaferHash ]->Fill( type );
182  }
183 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCT_CalibBsErrorTool::read
virtual bool read(const std::string &fileName)
Definition: SCT_CalibBsErrorTool.cxx:92
SCT_CalibAlgs::bec2Index
unsigned int bec2Index(const int bec)
Definition: SCT_CalibUtilities.cxx:60
get_generator_info.result
result
Definition: get_generator_info.py:21
SCT_CalibBsErrorTool::fill
virtual bool fill(const bool fromData=false)
Definition: SCT_CalibBsErrorTool.cxx:133
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SCT_CalibBsErrorTool::m_waferItrBegin
SCT_ID::const_id_iterator m_waferItrBegin
Definition: SCT_CalibBsErrorTool.h:55
SCT_ID::wafer_begin
const_id_iterator wafer_begin(void) const
Iterators over full set of ids. Wafer iterator is sorted.
Definition: SCT_ID.cxx:648
SCT_ID::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: SCT_ID.h:73
SCT_CalibBsErrorTool.h
SCT_CalibAlgs
Definition: IElementStreamer.cxx:13
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
SCT_CalibBsErrorTool::m_waferItrEnd
SCT_ID::const_id_iterator m_waferItrEnd
Definition: SCT_CalibBsErrorTool.h:56
SCT_CalibBsErrorTool::finalize
virtual StatusCode finalize()
Definition: SCT_CalibBsErrorTool.cxx:57
SCT_CalibBsErrorTool::m_bytestreamErrorsTool
ToolHandle< ISCT_ByteStreamErrorsTool > m_bytestreamErrorsTool
Definition: SCT_CalibBsErrorTool.h:51
TRT::Hit::side
@ side
Definition: HitInfo.h:83
SCT_CalibBsErrorTool::m_pSCTHelper
const SCT_ID * m_pSCTHelper
Definition: SCT_CalibBsErrorTool.h:52
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SCT3_RawData.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
SCT_CalibAlgs::formatPosition
std::string formatPosition(const Identifier &waferId, const SCT_ID *helper, const std::string &delimiter, const bool includeSide)
Definition: SCT_CalibUtilities.cxx:36
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_ID::wafer_hash
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition: SCT_ID.h:492
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
SCT_CalibNumbers.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:639
IdentifierHash.h
SCT_CalibBsErrorTool::SCT_CalibBsErrorTool
SCT_CalibBsErrorTool(const std::string &, const std::string &, const IInterface *)
Definition: SCT_CalibBsErrorTool.cxx:38
SCT_CalibBsErrorTool::fillBsErrorsForWafer
void fillBsErrorsForWafer(const Identifier &waferId, const int type)
Definition: SCT_CalibBsErrorTool.cxx:173
SCT_CalibBsErrorTool::initialize
virtual StatusCode initialize()
Definition: SCT_CalibBsErrorTool.cxx:44
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SCT_FlaggedCondEnum::NUM_ERROR_TYPES
@ NUM_ERROR_TYPES
Definition: SCT_FlaggedCondEnum.h:28
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_CalibBsErrorTool::m_scterr_type
VecInt * m_scterr_type
Definition: SCT_CalibBsErrorTool.h:63
SCT_ID::wafer_end
const_id_iterator wafer_end(void) const
Definition: SCT_ID.cxx:652
SCT_CalibBsErrorTool::m_maxHash
int m_maxHash
Definition: SCT_CalibBsErrorTool.h:64
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
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
InDetRawDataCLASS_DEF.h
SCT_CalibBsErrorTool::fillFromData
virtual bool fillFromData()
Definition: SCT_CalibBsErrorTool.cxx:156
SCT_CalibUtilities.h
SCT_CalibBsErrorTool::book
virtual bool book()
Definition: SCT_CalibBsErrorTool.cxx:64