ATLAS Offline Software
SCT_CalibHitmapTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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  m_thistSvc = service("THistSvc");
44  ATH_CHECK( m_thistSvc.isValid() );
45 
46  ATH_CHECK(detStore()->retrieve(m_pSCTHelper, "SCT_ID"));
47  //
50  //
51 
52  // Read Handle Key
53  ATH_CHECK(m_rdoContainerKey.initialize());
54 
55  return StatusCode::SUCCESS;
56 }
57 
60  ATH_MSG_VERBOSE("SCT_CalibHitmapTool::finalize()");
61 
62  return StatusCode::SUCCESS;
63 }
64 
65 bool
67  bool result{true};
68  //pointers to the histos are deleted by m_thistSvc methods
69  m_phistoVector.clear();
70  std::string histoName{pathRoot + "GENERAL/"};
71  //histogram for numbers of events
72  m_numberOfEventsHisto = new TH1I{"events", "Events", 1, 0.5, 1.5};
73  if (m_thistSvc->regHist(histoName.c_str(), m_numberOfEventsHisto).isFailure()) {
74  ATH_MSG_ERROR("Error in booking EventNumber histogram");
75  }
76  //histograms for each wafer
78  std::string hitmapPaths[3];
79  for (int i{0}; i<3; ++i) {
80  hitmapPaths[i]=pathRoot+detectorPaths[i];
81  }
82  for (; waferItr not_eq m_waferItrEnd; ++waferItr) {
83  const Identifier& waferId{*waferItr};
84  const int bec{m_pSCTHelper->barrel_ec(waferId)};
85  const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)};
86  std::string histotitle{std::string{"SCT "} + detectorNames[bec2Index(bec)] + std::string{" Hitmap: plane "} + formattedPosition};
87  std::string name{hitmapPaths[bec2Index(m_pSCTHelper->barrel_ec(waferId))] + formattedPosition};
88  TH1F* hitmapHisto_tmp{new TH1F{TString{formattedPosition}, TString{histotitle}, nbins, firstStrip-0.5, lastStrip+0.5}};
89 
90  if (m_thistSvc->regHist( name.c_str(), hitmapHisto_tmp ).isFailure()) {
91  ATH_MSG_ERROR("Error in booking Hitmap histogram");
92  } else {
93  m_phistoVector.push_back(hitmapHisto_tmp);
94  }
95 
96  }
97  return result;
98 }
99 
100 bool
101 SCT_CalibHitmapTool::read(const std::string& fileName) {
102  bool result{true};
103  //pointers to the histos are deleted by m_thistSvc methods
104  m_phistoVector.clear();
105  TFile* fileHitmap{TFile::Open(fileName.c_str())};
106  ATH_MSG_INFO("opening Hitmap file : " << fileName.c_str());
107 
108  if (fileHitmap==nullptr) {
109  ATH_MSG_ERROR("can not open Hitmap file : " << fileName.c_str());
110  return result;
111  }
112  //histogram for numbers of events
113  m_numberOfEventsHisto = static_cast<TH1I*>(fileHitmap->Get("GENERAL/events"));
114  if (m_numberOfEventsHisto==nullptr) {
115  ATH_MSG_ERROR("Error in reading EventNumber histogram");
116  }
117  //histograms for each wafer
119  for (; waferItr not_eq m_waferItrEnd; ++waferItr) {
120  const Identifier& waferId{*waferItr};
121  const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)};
122  std::string name{detectorPaths[bec2Index(m_pSCTHelper->barrel_ec(waferId))] + formattedPosition};
123  TH1F* hitmapHisto_tmp{static_cast<TH1F*>(fileHitmap->Get(name.c_str()))};
124  if (hitmapHisto_tmp==nullptr) {
125  ATH_MSG_ERROR("Error in reading Hitmap histogram");
126  } else {
127  m_phistoVector.push_back(hitmapHisto_tmp);
128  }
129  }
130  return result;
131 }
132 
133 bool
134 SCT_CalibHitmapTool::fill(const bool fromData) {
135  //cout<<"fromData "<<fromData<<endl;
136  if (fromData) {
137  return fillFromData();
138  }
139  bool result{true};
140  //--- Number of events
141  m_numberOfEventsHisto->Fill(1);
142 
143  //--- Fill hitmap
144  const int MaxEntry{static_cast<int>(m_sct_waferHash.size())};
145  for (int i{0}; i != MaxEntry; ++i) {
146  const int theFirstStrip{m_sct_firstStrip[i]};
147  const int endStrip{m_sct_rdoGroupSize[i] + theFirstStrip};
148  const int index{m_sct_waferHash[i]};
149  TH1F* pThisHisto{m_phistoVector[index]};
150  for (int strip{theFirstStrip}; strip!=endStrip; ++strip) {
151  pThisHisto->Fill(strip);
152  }
153  }
154  return result;
155 }
156 
157 bool
159  bool result{true};
160  m_numberOfEventsHisto->Fill(1);
162  if (not prdoContainer.isValid()) ATH_MSG_ERROR("Failed to retrieve the SCT RDO container");
163  SCT_RDO_Container::const_iterator itr{prdoContainer->begin()};
164  const SCT_RDO_Container::const_iterator end{prdoContainer->end()};
165  for (; itr !=end; ++itr) {
166  const InDetRawDataCollection<SCT_RDORawData>* SCT_Collection{*itr};
167  if (not SCT_Collection) continue;
168  const Identifier waferId{SCT_Collection->identify()};
169  const IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
170  TH1F* pThisHisto{m_phistoVector[static_cast<int>(waferHash)]};
171  DataVector<SCT_RDORawData>::const_iterator rdoItr{SCT_Collection->begin()};
172  const DataVector<SCT_RDORawData>::const_iterator rdoEnd{SCT_Collection->end()};
173  for (; rdoItr != rdoEnd; ++rdoItr) {
174  int strip{m_pSCTHelper->strip((*rdoItr)->identify())};
175  const int endStrip{(*rdoItr)->getGroupSize() + strip};
176  for (; strip != endStrip; ++strip) {
177  pThisHisto->Fill(strip);
178  }
179  }
180  }
181  return result;
182 }
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:59
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
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:645
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:101
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
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:134
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SCT_CalibAlgs::lastStrip
@ lastStrip
Definition: SCT_CalibNumbers.h:10
SCT_CalibAlgs::firstStrip
@ firstStrip
Definition: SCT_CalibNumbers.h:10
SCT_CalibHitmapTool::initialize
virtual StatusCode initialize()
Definition: SCT_CalibHitmapTool.cxx:42
SCT_CalibHitmapTool::fillFromData
virtual bool fillFromData()
Definition: SCT_CalibHitmapTool.cxx:158
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:85
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:221
IdentifierHash.h
DeMoScan.index
string index
Definition: DeMoScan.py:364
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:649
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:66
Identifier
Definition: IdentifierFieldParser.cxx:14