ATLAS Offline Software
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 
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 "TH1I.h"
29 #include "TH1F.h"
30 #include "TH2F.h"
31 #include "TFile.h"
32 #include "TMath.h"
33 
34 using namespace SCT_CalibAlgs;
35 
36 static const std::string pathRoot{"/LB/"};
37 static const int n_chipsPerSide{6};
38 static const int n_stripsPerChip{128};
39 static const std::string detectorNames[] {"negativeEndcap", "barrel", "positiveEndcap"};
40 static const std::string detectorPaths[] {"SCTEC/", "SCTB/","SCTEA/"};
41 
42 SCT_CalibLbTool::SCT_CalibLbTool(const std::string& type, const std::string& name, const IInterface* parent):
43  base_class(type, name, parent)
44 {
45 }
46 
49 
50  ATH_MSG_INFO("Initializing");
51  ATH_CHECK( (m_thistSvc = service("THistSvc")).isValid() );
52 
53  ATH_CHECK(detStore()->retrieve(m_pSCTHelper, "SCT_ID"));
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  //
73 
74  m_LbRange = numberOfLb();
75 
76  // Read Handle Key
77  ATH_CHECK(m_rdoContainerKey.initialize());
78 
79  return StatusCode::SUCCESS;
80 }
81 
82 bool
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 
135 bool
136 SCT_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 
186 bool
187 SCT_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 
213 bool
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 
257 void
258 SCT_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 }
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:187
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:279
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:42
SCT_CalibLbTool::m_LbsToMerge
int m_LbsToMerge
Definition: SCT_CalibLbTool.h:69
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:654
SCT_CalibLbTool::book
virtual bool book()
Definition: SCT_CalibLbTool.cxx:83
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
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:620
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
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SCT3_RawData.h
SCT_CalibAlgs::firstStrip
@ firstStrip
Definition: SCT_CalibNumbers.h:10
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
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:79
SCT_CalibLbTool::fillLbForWafer
void fillLbForWafer(const IdentifierHash &waferHash, const int theFirstStrip, const int groupSize)
Definition: SCT_CalibLbTool.cxx:258
SCT_CalibLbTool::m_LbRange
int m_LbRange
Definition: SCT_CalibLbTool.h:68
SCT_CalibLbTool::initialize
virtual StatusCode initialize()
Definition: SCT_CalibLbTool.cxx:48
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:228
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:645
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
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
SiDetectorElement.h
SCT_CalibLbTool::fillFromData
virtual bool fillFromData()
Definition: SCT_CalibLbTool.cxx:214
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_CalibAlgs::lastStrip
@ lastStrip
Definition: SCT_CalibNumbers.h:10
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:658
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:136
SCT_CalibUtilities.h
Identifier
Definition: IdentifierFieldParser.cxx:14