ATLAS Offline Software
SCT_CalibLbTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
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 
26 #include "StoreGate/ReadHandle.h"
27 
28 #include "GaudiKernel/ITHistSvc.h"
29 
30 #include "TH1I.h"
31 #include "TH1F.h"
32 #include "TH2F.h"
33 #include "TFile.h"
34 #include "TMath.h"
35 
36 using namespace SCT_CalibAlgs;
37 
38 static const std::string pathRoot{"/LB/"};
39 static const int n_chipsPerSide{6};
40 static const int n_stripsPerChip{128};
41 static const std::string detectorNames[] {"negativeEndcap", "barrel", "positiveEndcap"};
42 static const std::string detectorPaths[] {"SCTEC/", "SCTB/","SCTEA/"};
43 
44 SCT_CalibLbTool::SCT_CalibLbTool(const std::string& type, const std::string& name, const IInterface* parent):
45  base_class(type, name, parent)
46 {
47 }
48 
51 
52  ATH_MSG_INFO("Initializing");
53  ATH_CHECK(service("THistSvc", m_thistSvc));
54 
55  ATH_CHECK(detStore()->retrieve(m_pSCTHelper, "SCT_ID"));
57 
58  const InDetDD::SCT_DetectorManager* manager{nullptr};
59  ATH_CHECK(detStore()->retrieve(manager, "SCT"));
60  const InDetDD::SiDetectorElementCollection* sctDetElementColl{manager->getDetectorElementCollection()};
61  for (const InDetDD::SiDetectorElement* element: *sctDetElementColl) {
62  if (element->swapPhiReadoutDirection()) {
63  m_swapPhiReadoutDirection[element->identifyHash()] = true;
64  }
65  }
66 
67  std::pair<std::string, bool> msgCode{retrievedTool(m_evtInfo)};
68  if (not msgCode.second) {
69  ATH_MSG_ERROR(msgCode.first);
70  return StatusCode::FAILURE;
71  }
72  //
75 
76  m_LbRange = numberOfLb();
77 
78  // Read Handle Key
79  ATH_CHECK(m_rdoContainerKey.initialize());
80 
81  return StatusCode::SUCCESS;
82 }
83 
84 bool
86  ATH_MSG_INFO("book()");
87  bool result{true};
88  //pointers to the histos are deleted by m_thistSvc methods
89  m_phistoVector.clear();
90  m_phistoVector2D.clear();
91  std::string histoName{pathRoot+"GENERAL/"};
92  m_LbRange = numberOfLb();
93  m_numberOfEventsHisto = new TH1I{"events", "Events", m_LbRange, 0.5, m_LbRange+0.5};
94 
95  m_LbsToMerge = LbToMerge();
96  int yAxisBins{static_cast<int>(TMath::Ceil(1.0*m_LbRange/m_LbsToMerge))};
97 
98  if (m_thistSvc->regHist( histoName.c_str(), m_numberOfEventsHisto ).isFailure()) {
99  ATH_MSG_ERROR("Error in booking EventNumber histogram");
100  }
101  //histograms for each wafer
104  std::string hitmapPaths[3];
105  for (int i{0}; i<3; ++i) {
106  hitmapPaths[i] = pathRoot+detectorPaths[i];
107  }
109  for (; waferItr !=m_waferItrEnd; ++waferItr) {
110  const Identifier& waferId{*waferItr};
111  const int bec{m_pSCTHelper->barrel_ec(waferId)};
112  const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)+"_"};
114  std::string histotitle{std::string{"SCT "} + detectorNames[bec2Index(bec)] + std::string{" Hitmap: plane "} + formattedPosition};
115  std::string formattedPosition2D{formattedPosition + "_2D"};
116  std::string name2D{hitmapPaths[bec2Index(m_pSCTHelper->barrel_ec(waferId))] + formattedPosition + "_2D"};
117  TH2F* hitmapHistoLB_tmp2D{new TH2F{TString{formattedPosition2D}, TString{histotitle}, nbins, firstStrip-0.5, lastStrip+0.5, yAxisBins, 0.5, m_LbsToMerge*yAxisBins+0.5}};
118  if (m_thistSvc->regHist(name2D.c_str(), hitmapHistoLB_tmp2D).isFailure()) {
119  ATH_MSG_ERROR("Error in booking 2D Hitmap histogram");
120  } else {
121  m_phistoVector2D.push_back(hitmapHistoLB_tmp2D);
122  }
124  for (int iChip(0); iChip!=n_chipsPerSide; ++iChip) {
125  int chipId{m_pSCTHelper->side(waferId)==0 ? iChip:iChip+n_chipsPerSide};
126  const std::string formattedChipPosition{formattedPosition + std::to_string(chipId)};
127  const std::string hname{pathRoot + detectorPaths[bec2Index(bec)] + "/" + formattedChipPosition};
128  const std::string histTitle{std::string{"SCT"} + detectorNames[bec2Index(bec)] + std::string{" LB: chip "} + formattedChipPosition};
129  TH1F* hist_tmp{new TH1F{TString{formattedChipPosition}, TString{histTitle}, m_LbRange, 0.5, m_LbRange+0.5}};
130  if (m_thistSvc->regHist(hname.c_str(), hist_tmp).isFailure()) ATH_MSG_ERROR("Error in booking LB histogram");
131  m_phistoVector.push_back(hist_tmp);
132  }
133  }
134  return result;
135 }
136 
137 bool
138 SCT_CalibLbTool::read(const std::string& fileName) {
139  ATH_MSG_INFO("read()");
140  bool result{true};
141  m_LbRange = numberOfLb();
142  //pointers to the histos are deleted by m_thistSvc methods
143  m_phistoVector.clear();
144  m_phistoVector2D.clear();
145  TFile* fileLB{TFile::Open(fileName.c_str())};
146  ATH_MSG_INFO("opening LB file : " << fileName.c_str());
147 
148  if (fileLB) {
149  m_numberOfEventsHisto = static_cast<TH1I*>(fileLB->Get("GENERAL/events"));
150  } else {
151  ATH_MSG_ERROR("can not open LB file : " << fileName.c_str());
152  return result;
153  }
154 
155  if (m_numberOfEventsHisto==nullptr) {
156  ATH_MSG_ERROR("Error in reading EventNumber histogram");
157  }
158  //histograms for each wafer
160  for (; waferItr !=m_waferItrEnd; ++waferItr) {
161  const Identifier& waferId{*waferItr};
162  const int bec{m_pSCTHelper->barrel_ec(waferId)};
163  const std::string formattedPosition{formatPosition(waferId, m_pSCTHelper)+"_"};
165  std::string name2D=detectorPaths[bec2Index(m_pSCTHelper->barrel_ec( waferId ))] + formattedPosition + "_2D";
166  TH2F* hitmapHistoLB_tmp2D = (TH2F*) fileLB->Get(name2D.c_str());
167 
168  if (hitmapHistoLB_tmp2D==nullptr) {
169  ATH_MSG_ERROR("Error in reading Hitmap histogram");
170  } else {
171  m_phistoVector2D.push_back(hitmapHistoLB_tmp2D);
172  }
174  for (int iChip{0}; iChip!=n_chipsPerSide; ++iChip) {
175  int chipId{m_pSCTHelper->side(waferId)==0 ? iChip : iChip+n_chipsPerSide};
176  const std::string hname{detectorPaths[bec2Index(bec)] + "/" + formattedPosition + std::to_string(chipId)};
177  TH1F* hist_tmp{static_cast<TH1F*>(fileLB->Get(hname.c_str()))};
178  if (hist_tmp==nullptr) {
179  ATH_MSG_ERROR("Error in reading LB histogram");
180  } else {
181  m_phistoVector.push_back(hist_tmp);
182  }
183  }
184  }
185  return result;
186 }
187 
188 bool
189 SCT_CalibLbTool::fill(const bool fromData) {
190  if (fromData) {
191  return fillFromData();
192  }
193  m_numberOfEventsHisto->Fill(m_lumiBlock);
194  bool result{true};
195  int maxEntry{static_cast<int>(m_sct_waferHash->size())};
196  for (int i{0}; i != maxEntry; ++i) {
197  int theFirstStrip{(*m_sct_firstStrip)[i]};
198  //
199  int endStrip{(*m_sct_rdoGroupSize)[i] + theFirstStrip};
200  int index{(*m_sct_waferHash)[i]};
201  TH2F* pThisHisto2D{m_phistoVector2D[index]};
202 
203  for (int strip{theFirstStrip}; strip !=endStrip; ++strip) {
204  pThisHisto2D->Fill(strip, m_lumiBlock);
205  }
206  //
207  int rdoGroupSize{(*m_sct_rdoGroupSize)[i]};
208  IdentifierHash waferHash{static_cast<unsigned int>((*m_sct_waferHash)[i])};
209  fillLbForWafer(waferHash, theFirstStrip, rdoGroupSize);
210  }
211 
212  return result;
213 }
214 
215 bool
217  if (!m_evtInfo) {
218  ATH_MSG_ERROR("The evtInfo pointer is nullptr");
219  return false;
220  }
221  m_numberOfEventsHisto->Fill(m_lumiBlock);
222  bool result{true};
223  //--- Retrieve the RDO container
224  using SCTRawDataType = SCT_RDORawData;
226  if (not p_rdoContainer.isValid()) {
227  ATH_MSG_ERROR("Failed to retrieve SCT RDO container");
228  }
229 
230  SCT_RDO_Container::const_iterator itr{p_rdoContainer->begin()};
231  SCT_RDO_Container::const_iterator itrE{p_rdoContainer->end()};
232  for (; itr != itrE; ++itr) {
233  const InDetRawDataCollection<SCTRawDataType>* SCT_Collection{*itr};
234  if (SCT_Collection==nullptr) continue;// select only SCT RDOs
235  Identifier waferId{SCT_Collection->identify()};
236  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
238  TH2F* pThisHisto2D{m_phistoVector2D[static_cast<int>(waferHash)]};
240  DataVector<SCTRawDataType>::const_iterator rdoItr{SCT_Collection->begin()};
241  DataVector<SCTRawDataType>::const_iterator rdoItrE{SCT_Collection->end()};
242  for (; rdoItr != rdoItrE; ++rdoItr ) {
243  int theFirstStrip{m_pSCTHelper->strip((*rdoItr)->identify())};
245  int strip{m_pSCTHelper->strip((*rdoItr)->identify())};
246  const int endStrip{(*rdoItr)->getGroupSize() + strip};
247  for (; strip != endStrip; ++strip) {
248  pThisHisto2D->Fill( strip, m_lumiBlock );
249  }
251  int rdoGroupSize{(*rdoItr)->getGroupSize()};
252  fillLbForWafer(waferHash, theFirstStrip, rdoGroupSize);
253  }
254  }
255 
256  return result;
257 }
258 
259 void
260 SCT_CalibLbTool::fillLbForWafer(const IdentifierHash& waferHash, const int theFirstStrip, const int groupSize) {
261  int stripNumber{m_swapPhiReadoutDirection[waferHash] ? lastStrip - theFirstStrip : theFirstStrip};
262  int index{static_cast<int>(waferHash)*n_chipsPerSide + stripNumber/n_stripsPerChip};
263  //--- Fill LB histograms
264  for (int j{0}; j != groupSize; ++j) {
265  m_phistoVector[index]->Fill(m_lumiBlock);
266  }
267 
268 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCT_CalibAlgs::bec2Index
unsigned int bec2Index(const int bec)
Definition: SCT_CalibUtilities.cxx:60
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
InDetDD::SCT_DetectorManager
Definition: SCT_DetectorManager.h:49
SCT_CalibLbTool::m_pSCTHelper
const SCT_ID * m_pSCTHelper
Definition: SCT_CalibLbTool.h:59
SCT_CalibLbTool::fill
virtual bool fill(const bool fromData=false)
Definition: SCT_CalibLbTool.cxx:189
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:272
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
SCT_CalibLbTool::SCT_CalibLbTool
SCT_CalibLbTool(const std::string &, const std::string &, const IInterface *)
Definition: SCT_CalibLbTool.cxx:44
SCT_CalibLbTool::m_LbsToMerge
int m_LbsToMerge
Definition: SCT_CalibLbTool.h:69
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_CalibLbTool::book
virtual bool book()
Definition: SCT_CalibLbTool.cxx:85
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_RDORawData
Definition: SCT_RDORawData.h:24
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
SCT_CalibAlgs::lastStrip
@ lastStrip
Definition: SCT_CalibNumbers.h:10
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
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
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
SCT_CalibEventInfo.h
SCT_CalibLbTool::m_rdoContainerKey
SG::ReadHandleKey< SCT_RDO_Container > m_rdoContainerKey
Definition: SCT_CalibLbTool.h:74
SCT_CalibLbTool::m_sct_waferHash
VecInt * m_sct_waferHash
Definition: SCT_CalibLbTool.h:63
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
SCT_CalibLbTool::fillLbForWafer
void fillLbForWafer(const IdentifierHash &waferHash, const int theFirstStrip, const int groupSize)
Definition: SCT_CalibLbTool.cxx:260
SCT_CalibLbTool::m_LbRange
int m_LbRange
Definition: SCT_CalibLbTool.h:68
SCT_CalibLbTool::initialize
virtual StatusCode initialize()
Definition: SCT_CalibLbTool.cxx:50
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
SCT_CalibNumbers.h
SCT_CalibLbTool::m_waferItrBegin
SCT_ID::const_id_iterator m_waferItrBegin
Definition: SCT_CalibLbTool.h:60
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
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
IdentifierHash.h
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SCT_CalibLbTool::m_swapPhiReadoutDirection
std::vector< bool > m_swapPhiReadoutDirection
Swap phi readout direction.
Definition: SCT_CalibLbTool.h:72
SiDetectorElement.h
SCT_CalibLbTool::fillFromData
virtual bool fillFromData()
Definition: SCT_CalibLbTool.cxx:216
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_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
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
python.Logging.manager
manager
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/Logging.py:92
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
SCT_CalibLbTool::m_waferItrEnd
SCT_ID::const_id_iterator m_waferItrEnd
Definition: SCT_CalibLbTool.h:61
SCT_CalibLbTool::m_evtInfo
ToolHandle< ISCT_CalibEvtInfo > m_evtInfo
Definition: SCT_CalibLbTool.h:57
SCT_CalibLbTool.h
ReadHandle.h
Handle class for reading from StoreGate.
SCT_DetectorManager.h
InDetRawDataCLASS_DEF.h
SCT_CalibLbTool::read
virtual bool read(const std::string &fileName)
Definition: SCT_CalibLbTool.cxx:138
SCT_CalibUtilities.h