ATLAS Offline Software
SCT_CalibHitmapTool.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_CalibHitmapTool.h"
12 #include "SCT_CalibUtilities.h"
13 #include "SCT_CalibNumbers.h"
14 
15 // RAW data access
18 #include "StoreGate/ReadHandle.h"
19 
20 #include "Identifier/Identifier.h"
22 
23 #include "GaudiKernel/ITHistSvc.h"
24 
25 #include "TH1I.h"
26 #include "TH1F.h"
27 #include "TFile.h"
28 #include "TFileCollection.h"
29 #include "THashList.h"
30 
31 using namespace SCT_CalibAlgs;
32 static const std::string pathRoot{"/HitMaps/"};
33 static const std::string detectorNames[] {"negativeEndcap", "barrel", "positiveEndcap"};
34 static const std::string detectorPaths[] {"SCTEC/", "SCTB/","SCTEA/"};
35 
36 SCT_CalibHitmapTool::SCT_CalibHitmapTool(const std::string& type, const std::string& name, const IInterface* parent):
37  base_class(type, name, parent)
38 {
39 }
40 
43  if ( service( "THistSvc", m_thistSvc ).isFailure() ) ATH_MSG_ERROR("Unable to retrieve pointer to THistSvc");
44 
45  ATH_CHECK(detStore()->retrieve(m_pSCTHelper, "SCT_ID"));
46  //
49  //
50 
51  // Read Handle Key
52  ATH_CHECK(m_rdoContainerKey.initialize());
53 
54  return StatusCode::SUCCESS;
55 }
56 
59  ATH_MSG_VERBOSE("SCT_CalibHitmapTool::finalize()");
60 
61  return StatusCode::SUCCESS;
62 }
63 
64 bool
66  bool result{true};
67  //pointers to the histos are deleted by m_thistSvc methods
68  m_phistoVector.clear();
69  std::string histoName{pathRoot + "GENERAL/"};
70  //histogram for numbers of events
71  m_numberOfEventsHisto = new TH1I{"events", "Events", 1, 0.5, 1.5};
72  if (m_thistSvc->regHist(histoName.c_str(), m_numberOfEventsHisto).isFailure()) {
73  ATH_MSG_ERROR("Error in booking EventNumber histogram");
74  }
75  //histograms for each wafer
77  std::string hitmapPaths[3];
78  for (int i{0}; i<3; ++i) {
79  hitmapPaths[i]=pathRoot+detectorPaths[i];
80  }
81  for (; waferItr not_eq m_waferItrEnd; ++waferItr) {
82  const Identifier& waferId{*waferItr};
83  const int bec{m_pSCTHelper->barrel_ec(waferId)};
84  const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)};
85  std::string histotitle{std::string{"SCT "} + detectorNames[bec2Index(bec)] + std::string{" Hitmap: plane "} + formattedPosition};
86  std::string name{hitmapPaths[bec2Index(m_pSCTHelper->barrel_ec(waferId))] + formattedPosition};
87  TH1F* hitmapHisto_tmp{new TH1F{TString{formattedPosition}, TString{histotitle}, nbins, firstStrip-0.5, lastStrip+0.5}};
88 
89  if (m_thistSvc->regHist( name.c_str(), hitmapHisto_tmp ).isFailure()) {
90  ATH_MSG_ERROR("Error in booking Hitmap histogram");
91  } else {
92  m_phistoVector.push_back(hitmapHisto_tmp);
93  }
94 
95  }
96  return result;
97 }
98 
99 bool
100 SCT_CalibHitmapTool::read(const std::string& fileName) {
101  bool result{true};
102  //pointers to the histos are deleted by m_thistSvc methods
103  m_phistoVector.clear();
104  TFile* fileHitmap{TFile::Open(fileName.c_str())};
105  ATH_MSG_INFO("opening Hitmap file : " << fileName.c_str());
106 
107  if (fileHitmap==nullptr) {
108  ATH_MSG_ERROR("can not open Hitmap file : " << fileName.c_str());
109  return result;
110  }
111  //histogram for numbers of events
112  m_numberOfEventsHisto = static_cast<TH1I*>(fileHitmap->Get("GENERAL/events"));
113  if (m_numberOfEventsHisto==nullptr) {
114  ATH_MSG_ERROR("Error in reading EventNumber histogram");
115  }
116  //histograms for each wafer
118  for (; waferItr not_eq m_waferItrEnd; ++waferItr) {
119  const Identifier& waferId{*waferItr};
120  const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)};
121  std::string name{detectorPaths[bec2Index(m_pSCTHelper->barrel_ec(waferId))] + formattedPosition};
122  TH1F* hitmapHisto_tmp{static_cast<TH1F*>(fileHitmap->Get(name.c_str()))};
123  if (hitmapHisto_tmp==nullptr) {
124  ATH_MSG_ERROR("Error in reading Hitmap histogram");
125  } else {
126  m_phistoVector.push_back(hitmapHisto_tmp);
127  }
128  }
129  return result;
130 }
131 
132 bool
133 SCT_CalibHitmapTool::fill(const bool fromData) {
134  //cout<<"fromData "<<fromData<<endl;
135  if (fromData) {
136  return fillFromData();
137  }
138  bool result{true};
139  //--- Number of events
140  m_numberOfEventsHisto->Fill(1);
141 
142  //--- Fill hitmap
143  const int MaxEntry{static_cast<int>(m_sct_waferHash.size())};
144  for (int i{0}; i != MaxEntry; ++i) {
145  const int theFirstStrip{m_sct_firstStrip[i]};
146  const int endStrip{m_sct_rdoGroupSize[i] + theFirstStrip};
147  const int index{m_sct_waferHash[i]};
148  TH1F* pThisHisto{m_phistoVector[index]};
149  for (int strip{theFirstStrip}; strip!=endStrip; ++strip) {
150  pThisHisto->Fill(strip);
151  }
152  }
153  return result;
154 }
155 
156 bool
158  bool result{true};
159  m_numberOfEventsHisto->Fill(1);
161  if (not prdoContainer.isValid()) ATH_MSG_ERROR("Failed to retrieve the SCT RDO container");
162  SCT_RDO_Container::const_iterator itr{prdoContainer->begin()};
163  const SCT_RDO_Container::const_iterator end{prdoContainer->end()};
164  for (; itr !=end; ++itr) {
165  const InDetRawDataCollection<SCT_RDORawData>* SCT_Collection{*itr};
166  if (not SCT_Collection) continue;
167  const Identifier waferId{SCT_Collection->identify()};
168  const IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
169  TH1F* pThisHisto{m_phistoVector[static_cast<int>(waferHash)]};
170  DataVector<SCT_RDORawData>::const_iterator rdoItr{SCT_Collection->begin()};
171  const DataVector<SCT_RDORawData>::const_iterator rdoEnd{SCT_Collection->end()};
172  for (; rdoItr != rdoEnd; ++rdoItr) {
173  int strip{m_pSCTHelper->strip((*rdoItr)->identify())};
174  const int endStrip{(*rdoItr)->getGroupSize() + strip};
175  for (; strip != endStrip; ++strip) {
176  pThisHisto->Fill(strip);
177  }
178  }
179  }
180  return result;
181 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCT_CalibHitmapTool::m_sct_rdoGroupSize
VecInt m_sct_rdoGroupSize
Definition: SCT_CalibHitmapTool.h:61
SCT_CalibAlgs::bec2Index
unsigned int bec2Index(const int bec)
Definition: SCT_CalibUtilities.cxx:60
SCT_CalibHitmapTool::SCT_CalibHitmapTool
SCT_CalibHitmapTool(const std::string &, const std::string &, const IInterface *)
Definition: SCT_CalibHitmapTool.cxx:36
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
get_generator_info.result
result
Definition: get_generator_info.py:21
SiliconTech::strip
@ strip
SCT_CalibHitmapTool::finalize
virtual StatusCode finalize()
Definition: SCT_CalibHitmapTool.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
SCT_CalibHitmapTool::m_sct_firstStrip
VecInt m_sct_firstStrip
Definition: SCT_CalibHitmapTool.h:60
InDetRawDataCollection::identify
virtual Identifier identify() const override final
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_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
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SCT_CalibHitmapTool::read
virtual bool read(const std::string &fileName)
Definition: SCT_CalibHitmapTool.cxx:100
SCT_CalibHitmapTool::m_waferItrBegin
SCT_ID::const_id_iterator m_waferItrBegin
Definition: SCT_CalibHitmapTool.h:56
SCT_CalibHitmapTool::fill
virtual bool fill(const bool fromData=false)
Definition: SCT_CalibHitmapTool.cxx:133
SCT_CalibAlgs::lastStrip
@ lastStrip
Definition: SCT_CalibNumbers.h:10
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SCT_CalibHitmapTool::initialize
virtual StatusCode initialize()
Definition: SCT_CalibHitmapTool.cxx:42
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
SCT_CalibHitmapTool::fillFromData
virtual bool fillFromData()
Definition: SCT_CalibHitmapTool.cxx:157
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SCT3_RawData.h
SCT_CalibHitmapTool::m_pSCTHelper
const SCT_ID * m_pSCTHelper
Definition: SCT_CalibHitmapTool.h:55
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
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
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
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
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:82
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
SCT_CalibNumbers.h
SCT_CalibHitmapTool::m_sct_waferHash
VecInt m_sct_waferHash
Definition: SCT_CalibHitmapTool.h:59
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
IdentifierHash.h
DeMoScan.index
string index
Definition: DeMoScan.py:362
SCT_ID::strip
int strip(const Identifier &id) const
Definition: SCT_ID.h:764
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_CalibHitmapTool::m_rdoContainerKey
SG::ReadHandleKey< SCT_RDO_Container > m_rdoContainerKey
Definition: SCT_CalibHitmapTool.h:63
SCT_ID::wafer_end
const_id_iterator wafer_end(void) const
Definition: SCT_ID.cxx:652
SCT_CalibAlgs::firstStrip
@ firstStrip
Definition: SCT_CalibNumbers.h:10
SCT_CalibHitmapTool.h
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
ReadHandle.h
Handle class for reading from StoreGate.
InDetRawDataCLASS_DEF.h
SCT_CalibUtilities.h
SCT_CalibHitmapTool::m_waferItrEnd
SCT_ID::const_id_iterator m_waferItrEnd
Definition: SCT_CalibHitmapTool.h:57
SCT_CalibHitmapTool::book
virtual bool book()
Definition: SCT_CalibHitmapTool.cxx:65