ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_CalibLbTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
11
12#include "SCT_CalibLbTool.h"
13#include "SCT_CalibUtilities.h"
14#include "SCT_CalibNumbers.h"
15#include "SCT_CalibEventInfo.h"
16
17//InnerDetector
22
23#include "Identifier/Identifier.h"
25
27
28#include "TH1I.h"
29#include "TH1F.h"
30#include "TH2F.h"
31#include "TFile.h"
32#include "TMath.h"
33
34using namespace SCT_CalibAlgs;
35
36static const std::string pathRoot{"/LB/"};
37static const int n_chipsPerSide{6};
38static const int n_stripsPerChip{128};
39static const std::string detectorNames[] {"negativeEndcap", "barrel", "positiveEndcap"};
40static const std::string detectorPaths[] {"SCTEC/", "SCTB/","SCTEA/"};
41
42SCT_CalibLbTool::SCT_CalibLbTool(const std::string& type, const std::string& name, const IInterface* parent):
43 base_class(type, name, parent)
44{
45}
46
47StatusCode
49
50 ATH_MSG_INFO("Initializing");
51 ATH_CHECK( (m_thistSvc = service("THistSvc")).isValid() );
52
53 ATH_CHECK(detStore()->retrieve(m_pSCTHelper, "SCT_ID"));
54 m_swapPhiReadoutDirection.resize(m_pSCTHelper->wafer_hash_max(), false);
55
56 const InDetDD::SCT_DetectorManager* manager{nullptr};
57 ATH_CHECK(detStore()->retrieve(manager, "SCT"));
58 const InDetDD::SiDetectorElementCollection* sctDetElementColl{manager->getDetectorElementCollection()};
59 for (const InDetDD::SiDetectorElement* element: *sctDetElementColl) {
60 if (element->swapPhiReadoutDirection()) {
61 m_swapPhiReadoutDirection[element->identifyHash()] = true;
62 }
63 }
64
65 std::pair<std::string, bool> msgCode{retrievedTool(m_evtInfo)};
66 if (not msgCode.second) {
67 ATH_MSG_ERROR(msgCode.first);
68 return StatusCode::FAILURE;
69 }
70 //
71 m_waferItrBegin = m_pSCTHelper->wafer_begin();
72 m_waferItrEnd = m_pSCTHelper->wafer_end();
73
74 m_LbRange = numberOfLb();
75
76 // Read Handle Key
77 ATH_CHECK(m_rdoContainerKey.initialize());
78
79 return StatusCode::SUCCESS;
80}
81
82bool
84 ATH_MSG_INFO("book()");
85 bool result{true};
86 //pointers to the histos are deleted by m_thistSvc methods
87 m_phistoVector.clear();
88 m_phistoVector2D.clear();
89 std::string histoName{pathRoot+"GENERAL/"};
90 m_LbRange = numberOfLb();
91 m_numberOfEventsHisto = new TH1I{"events", "Events", m_LbRange, 0.5, m_LbRange+0.5};
92
93 m_LbsToMerge = LbToMerge();
94 int yAxisBins{static_cast<int>(TMath::Ceil(1.0*m_LbRange/m_LbsToMerge))};
95
96 if (m_thistSvc->regHist( histoName.c_str(), m_numberOfEventsHisto ).isFailure()) {
97 ATH_MSG_ERROR("Error in booking EventNumber histogram");
98 }
99 //histograms for each wafer
102 std::string hitmapPaths[3];
103 for (int i{0}; i<3; ++i) {
104 hitmapPaths[i] = pathRoot+detectorPaths[i];
105 }
107 for (; waferItr !=m_waferItrEnd; ++waferItr) {
108 const Identifier& waferId{*waferItr};
109 const int bec{m_pSCTHelper->barrel_ec(waferId)};
110 const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)+"_"};
112 std::string histotitle{std::string{"SCT "} + detectorNames[bec2Index(bec)] + std::string{" Hitmap: plane "} + formattedPosition};
113 std::string formattedPosition2D{formattedPosition + "_2D"};
114 std::string name2D{hitmapPaths[bec2Index(m_pSCTHelper->barrel_ec(waferId))] + formattedPosition + "_2D"};
115 TH2F* hitmapHistoLB_tmp2D{new TH2F{TString{formattedPosition2D}, TString{histotitle}, nbins, firstStrip-0.5, lastStrip+0.5, yAxisBins, 0.5, m_LbsToMerge*yAxisBins+0.5}};
116 if (m_thistSvc->regHist(name2D.c_str(), hitmapHistoLB_tmp2D).isFailure()) {
117 ATH_MSG_ERROR("Error in booking 2D Hitmap histogram");
118 } else {
119 m_phistoVector2D.push_back(hitmapHistoLB_tmp2D);
120 }
122 for (int iChip(0); iChip!=n_chipsPerSide; ++iChip) {
123 int chipId{m_pSCTHelper->side(waferId)==0 ? iChip:iChip+n_chipsPerSide};
124 const std::string formattedChipPosition{formattedPosition + std::to_string(chipId)};
125 const std::string hname{pathRoot + detectorPaths[bec2Index(bec)] + "/" + formattedChipPosition};
126 const std::string histTitle{std::string{"SCT"} + detectorNames[bec2Index(bec)] + std::string{" LB: chip "} + formattedChipPosition};
127 TH1F* hist_tmp{new TH1F{TString{formattedChipPosition}, TString{histTitle}, m_LbRange, 0.5, m_LbRange+0.5}};
128 if (m_thistSvc->regHist(hname.c_str(), hist_tmp).isFailure()) ATH_MSG_ERROR("Error in booking LB histogram");
129 m_phistoVector.push_back(hist_tmp);
130 }
131 }
132 return result;
133}
134
135bool
136SCT_CalibLbTool::read(const std::string& fileName) {
137 ATH_MSG_INFO("read()");
138 bool result{true};
139 m_LbRange = numberOfLb();
140 //pointers to the histos are deleted by m_thistSvc methods
141 m_phistoVector.clear();
142 m_phistoVector2D.clear();
143 TFile* fileLB{TFile::Open(fileName.c_str())};
144 ATH_MSG_INFO("opening LB file : " << fileName.c_str());
145
146 if (fileLB) {
147 m_numberOfEventsHisto = static_cast<TH1I*>(fileLB->Get("GENERAL/events"));
148 } else {
149 ATH_MSG_ERROR("can not open LB file : " << fileName.c_str());
150 return result;
151 }
152
153 if (m_numberOfEventsHisto==nullptr) {
154 ATH_MSG_ERROR("Error in reading EventNumber histogram");
155 }
156 //histograms for each wafer
158 for (; waferItr !=m_waferItrEnd; ++waferItr) {
159 const Identifier& waferId{*waferItr};
160 const int bec{m_pSCTHelper->barrel_ec(waferId)};
161 const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)+"_"};
163 std::string name2D=detectorPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition + "_2D";
164 TH2F* hitmapHistoLB_tmp2D = (TH2F*) fileLB->Get(name2D.c_str());
165
166 if (hitmapHistoLB_tmp2D==nullptr) {
167 ATH_MSG_ERROR("Error in reading Hitmap histogram");
168 } else {
169 m_phistoVector2D.push_back(hitmapHistoLB_tmp2D);
170 }
172 for (int iChip{0}; iChip!=n_chipsPerSide; ++iChip) {
173 int chipId{m_pSCTHelper->side(waferId)==0 ? iChip : iChip+n_chipsPerSide};
174 const std::string hname{detectorPaths[bec2Index(bec)] + "/" + formattedPosition + std::to_string(chipId)};
175 TH1F* hist_tmp{static_cast<TH1F*>(fileLB->Get(hname.c_str()))};
176 if (hist_tmp==nullptr) {
177 ATH_MSG_ERROR("Error in reading LB histogram");
178 } else {
179 m_phistoVector.push_back(hist_tmp);
180 }
181 }
182 }
183 return result;
184}
185
186bool
187SCT_CalibLbTool::fill(const bool fromData) {
188 if (fromData) {
189 return fillFromData();
190 }
191 m_numberOfEventsHisto->Fill(m_lumiBlock);
192 bool result{true};
193 int maxEntry{static_cast<int>(m_sct_waferHash->size())};
194 for (int i{0}; i != maxEntry; ++i) {
195 int theFirstStrip{(*m_sct_firstStrip)[i]};
196 //
197 int endStrip{(*m_sct_rdoGroupSize)[i] + theFirstStrip};
198 int index{(*m_sct_waferHash)[i]};
199 TH2F* pThisHisto2D{m_phistoVector2D[index]};
200
201 for (int strip{theFirstStrip}; strip !=endStrip; ++strip) {
202 pThisHisto2D->Fill(strip, m_lumiBlock);
203 }
204 //
205 int rdoGroupSize{(*m_sct_rdoGroupSize)[i]};
206 IdentifierHash waferHash{static_cast<unsigned int>((*m_sct_waferHash)[i])};
207 fillLbForWafer(waferHash, theFirstStrip, rdoGroupSize);
208 }
209
210 return result;
211}
212
213bool
215 if (!m_evtInfo) {
216 ATH_MSG_ERROR("The evtInfo pointer is nullptr");
217 return false;
218 }
219 m_numberOfEventsHisto->Fill(m_lumiBlock);
220 bool result{true};
221 //--- Retrieve the RDO container
222 using SCTRawDataType = SCT_RDORawData;
224 if (not p_rdoContainer.isValid()) {
225 ATH_MSG_ERROR("Failed to retrieve SCT RDO container");
226 }
227
228 SCT_RDO_Container::const_iterator itr{p_rdoContainer->begin()};
229 SCT_RDO_Container::const_iterator itrE{p_rdoContainer->end()};
230 for (; itr != itrE; ++itr) {
231 const InDetRawDataCollection<SCTRawDataType>* SCT_Collection{*itr};
232 if (SCT_Collection==nullptr) continue;// select only SCT RDOs
233 Identifier waferId{SCT_Collection->identify()};
234 IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
236 TH2F* pThisHisto2D{m_phistoVector2D[static_cast<int>(waferHash)]};
238 DataVector<SCTRawDataType>::const_iterator rdoItr{SCT_Collection->begin()};
239 DataVector<SCTRawDataType>::const_iterator rdoItrE{SCT_Collection->end()};
240 for (; rdoItr != rdoItrE; ++rdoItr ) {
241 int theFirstStrip{m_pSCTHelper->strip((*rdoItr)->identify())};
243 int strip{m_pSCTHelper->strip((*rdoItr)->identify())};
244 const int endStrip{(*rdoItr)->getGroupSize() + strip};
245 for (; strip != endStrip; ++strip) {
246 pThisHisto2D->Fill( strip, m_lumiBlock );
247 }
249 int rdoGroupSize{(*rdoItr)->getGroupSize()};
250 fillLbForWafer(waferHash, theFirstStrip, rdoGroupSize);
251 }
252 }
253
254 return result;
255}
256
257void
258SCT_CalibLbTool::fillLbForWafer(const IdentifierHash& waferHash, const int theFirstStrip, const int groupSize) {
259 int stripNumber{m_swapPhiReadoutDirection[waferHash] ? lastStrip - theFirstStrip : theFirstStrip};
260 int index{static_cast<int>(waferHash)*n_chipsPerSide + stripNumber/n_stripsPerChip};
261 //--- Fill LB histograms
262 for (int j{0}; j != groupSize; ++j) {
263 m_phistoVector[index]->Fill(m_lumiBlock);
264 }
265
266}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
static const std::string detectorPaths[]
static const std::string pathRoot
static const std::string detectorNames[]
Implementation file for the SCT_CalibEventInfo class.
static const int n_chipsPerSide
static const int n_stripsPerChip
Header file for the SCT_CalibLbTool class.
header file for the SCTCalibUtilities
Handle class for reading from StoreGate.
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
This is a "hash" representation of an Identifier.
Dedicated detector manager extending the functionality of the SiDetectorManager with dedicated SCT in...
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
virtual Identifier identify() const override final
virtual bool read(const std::string &fileName)
const SCT_ID * m_pSCTHelper
SG::ReadHandleKey< SCT_RDO_Container > m_rdoContainerKey
virtual bool book()
ToolHandle< ISCT_CalibEvtInfo > m_evtInfo
SCT_ID::const_id_iterator m_waferItrBegin
SCT_ID::const_id_iterator m_waferItrEnd
virtual StatusCode initialize()
std::vector< bool > m_swapPhiReadoutDirection
Swap phi readout direction.
VecInt * m_sct_waferHash
SCT_CalibLbTool(const std::string &, const std::string &, const IInterface *)
virtual bool fill(const bool fromData=false)
void fillLbForWafer(const IdentifierHash &waferHash, const int theFirstStrip, const int groupSize)
virtual bool fillFromData()
std::vector< Identifier >::const_iterator const_id_iterator
Definition SCT_ID.h:73
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string formatPosition(const Identifier &waferId, const SCT_ID *helper, const std::string &delimiter, const bool includeSide)
unsigned int bec2Index(const int bec)
Definition index.py:1