ATLAS Offline Software
HIClusterGeo_HistoFiller.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 HIClusterGeo_HistoFiller::HIClusterGeo_HistoFiller(const std::string& name, ISvcLocator* pSvcLocator) :
8  AthAlgorithm(name, pSvcLocator), m_etaPhiMapping(nullptr)
9 {
10 }
11 
12 TH1 * HIClusterGeo_HistoFiller::regAndGetTHF(const std::string& histName, const std::string& histTitle, int numBinsX, double xMin, double xMax, int numBinsY, double yMin, double yMax)
13 {
14  auto hist = std::make_unique<TH2F>(histName.c_str(), histTitle.c_str(), numBinsX, xMin, xMax, numBinsY, yMin, yMax);
15  if(m_thistSvc->regHist("/" + m_histStream + "/" + histName, std::unique_ptr<TH1>(std::move(hist))).isFailure())
16  {
17  return nullptr;
18  }
19 
20  TH1 * tmpHist = nullptr;
21  if(m_thistSvc->getHist("/" + m_histStream + "/" + histName, tmpHist).isFailure())
22  {
23  return nullptr;
24  }
25 
26  return static_cast<TH1*>(tmpHist);
27 }
28 
30 {
32  ATH_CHECK( m_vertexContainerKey.initialize() );
34  ATH_CHECK( m_hiEventShapeKey.initialize() );
35 
36  ATH_CHECK( m_thistSvc.retrieve() );
37 
38  m_histTileWeights.clear();
39 
40  m_etaPhiMapping = static_cast<TH2F*>(regAndGetTHF("h_etaPhiMapping", ";eta;phi", m_etaBins, -5, 5, m_phiBins, -TMath::Pi(), TMath::Pi()));
41  if(m_etaPhiMapping==nullptr)
42  {
43  return StatusCode::FAILURE;
44  }
45 
46  return StatusCode::SUCCESS;
47 }
48 
50 {
51  const EventContext& ctx = Gaudi::Hive::currentContext();
52 
54  if (!eventInfo.isValid())
55  {
56  ATH_MSG_WARNING("Cannot get EventInfo with key " << m_eventInfoKey.key());
57  return StatusCode::SUCCESS;
58  }
59 
60  if((eventInfo->errorState(xAOD::EventInfo::LAr) == xAOD::EventInfo::Error) ||
61  (eventInfo->errorState(xAOD::EventInfo::Tile) == xAOD::EventInfo::Error) ||
62  (eventInfo->isEventFlagBitSet(xAOD::EventInfo::Core, 18)) )
63  {
64  return StatusCode::SUCCESS;
65  }
66 
67  // GRL selection will be done later by "makeHIResponse",
68  // here, we just save everything into separate histograms for each LB
69 
70  // trigger decision tool is not needed if we use CC and PC streams
71 
73  if(!vertices.isValid())
74  {
75  ATH_MSG_WARNING("Cannot get VertexContainer with key " << m_vertexContainerKey.key());
76  return StatusCode::SUCCESS;
77  }
78  if(vertices->size() <= 1)
79  {
80  // no vertex
81  return StatusCode::SUCCESS;
82  }
83 
85  if (!caloClusters.isValid())
86  {
87  ATH_MSG_WARNING("Cannot get CaloClusterContainer with key " << m_caloClusterContainerKey.key());
88  return StatusCode::SUCCESS;
89  }
90 
92  if (!hiEventShape.isValid())
93  {
94  ATH_MSG_WARNING("Cannot get HIEventShapeContainer with key " << m_hiEventShapeKey.key());
95  return StatusCode::SUCCESS;
96  }
97 
98  int currentLB = eventInfo->lumiBlock();
99  int currentRun = eventInfo->runNumber();
100 
101  if (auto search = m_histTileWeights.find(currentLB); search == m_histTileWeights.end())
102  {
103  // if m_histTileWeights does not already have histogram forthis LB, allocate a new TH2F
104  // bins in Y: sum FCalET, sum ClusterET, sum FCalET^2, sum ClusterET^2, sum FCalET*ClusterET, number of events
105  TH2F * newHistTileWeights = static_cast<TH2F*>(regAndGetTHF(Form("h_clusterET_fcalET_%d_%d",currentRun,currentLB), ";bin ID;sum FCalET/clusterET/FCalET^2/clusterET^2/FCalET*clusterET/n_{events}", m_totalBins, -0.5, m_totalBins-0.5, 6,0.5,6.5));
106  if (newHistTileWeights == nullptr)
107  {
108  ATH_MSG_WARNING("Could not create histogram "<<Form("h_clusterET_fcalET_%d_%d",currentRun,currentLB)<<" that was supposed to be used for Run "<<currentRun<<" LB "<<currentLB);
109  return StatusCode::SUCCESS;
110  }
111 
112  m_histTileWeights[currentLB] = std::move(newHistTileWeights);
113  }
114 
115  auto currentHistTileWeights = m_histTileWeights.at(currentLB);
116 
117  float fcalEt = hiEventShape->at(5)->et()*1e-6;
118  if(fcalEt<m_minFCalET || m_maxFCalET<fcalEt)
119  {
120  // remove in-time and out-of-time pile-up
121  return StatusCode::SUCCESS;
122  }
123 
124  for(const auto* cluster : *caloClusters)
125  {
126  float eta = cluster->eta();
127  float phi = cluster->phi();
128  int binID = m_etaPhiMapping->FindBin(eta, phi);
129  float ET = cluster->e() * 1e-3 / std::cosh(eta);
130 
131  currentHistTileWeights->Fill(binID, 1, fcalEt);
132  currentHistTileWeights->Fill(binID, 2, ET);
133  currentHistTileWeights->Fill(binID, 3, fcalEt*fcalEt);
134  currentHistTileWeights->Fill(binID, 4, ET*ET);
135  currentHistTileWeights->Fill(binID, 5, fcalEt*ET);
136  currentHistTileWeights->Fill(binID, 6, 1.);
137  }
138 
139  return StatusCode::SUCCESS;
140 }
141 
143 {
144  return StatusCode::SUCCESS;
145 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
HIClusterGeo_HistoFiller::m_caloClusterContainerKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClusterContainerKey
Definition: HIClusterGeo_HistoFiller.h:44
AddEmptyComponent.histName
string histName
Definition: AddEmptyComponent.py:64
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
HIClusterGeo_HistoFiller::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: HIClusterGeo_HistoFiller.h:37
HIClusterGeo_HistoFiller::m_hiEventShapeKey
SG::ReadHandleKey< xAOD::HIEventShapeContainer > m_hiEventShapeKey
Definition: HIClusterGeo_HistoFiller.h:45
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
HIClusterGeo_HistoFiller::m_histStream
Gaudi::Property< std::string > m_histStream
Definition: HIClusterGeo_HistoFiller.h:38
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
plotmaker.hist
hist
Definition: plotmaker.py:148
HIClusterGeo_HistoFiller::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: HIClusterGeo_HistoFiller.h:42
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
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
xAOD::EventInfo_v1::LAr
@ LAr
The LAr calorimeter.
Definition: EventInfo_v1.h:335
search
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Definition: hcg.cxx:738
HIClusterGeo_HistoFiller::m_vertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
Definition: HIClusterGeo_HistoFiller.h:43
HIClusterGeo_HistoFiller::m_minFCalET
Gaudi::Property< float > m_minFCalET
Definition: HIClusterGeo_HistoFiller.h:39
xAOD::EventInfo_v1::Error
@ Error
The sub-detector issued an error.
Definition: EventInfo_v1.h:349
HIClusterGeo_HistoFiller::m_totalBins
const int m_totalBins
Definition: HIClusterGeo_HistoFiller.h:49
HIClusterGeo_HistoFiller::m_etaPhiMapping
TH2F * m_etaPhiMapping
Definition: HIClusterGeo_HistoFiller.h:50
HIClusterGeo_HistoFiller.h
fitman.tmpHist
def tmpHist(what, wmin=-1e10, wmax=+1e10)
Definition: fitman.py:146
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
HIClusterGeo_HistoFiller::regAndGetTHF
TH1 * regAndGetTHF(const std::string &histName, const std::string &histTitle, int numBinsX, double xMin, double xMax, int numBinsY, double yMin, double yMax)
Definition: HIClusterGeo_HistoFiller.cxx:12
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
HIClusterGeo_HistoFiller::finalize
virtual StatusCode finalize() override
Definition: HIClusterGeo_HistoFiller.cxx:142
HIClusterGeo_HistoFiller::HIClusterGeo_HistoFiller
HIClusterGeo_HistoFiller(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HIClusterGeo_HistoFiller.cxx:7
HIClusterGeo_HistoFiller::execute
virtual StatusCode execute() override
Definition: HIClusterGeo_HistoFiller.cxx:49
HIClusterGeo_HistoFiller::initialize
virtual StatusCode initialize() override
Definition: HIClusterGeo_HistoFiller.cxx:29
xAOD::EventInfo_v1::Tile
@ Tile
The Tile calorimeter.
Definition: EventInfo_v1.h:336
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
HIClusterGeo_HistoFiller::m_histTileWeights
std::unordered_map< int, TH2F * > m_histTileWeights
Definition: HIClusterGeo_HistoFiller.h:47
HIClusterGeo_HistoFiller::m_maxFCalET
Gaudi::Property< float > m_maxFCalET
Definition: HIClusterGeo_HistoFiller.h:40
HIClusterGeo_HistoFiller::m_etaBins
const int m_etaBins
Definition: HIClusterGeo_HistoFiller.h:48
xAOD::EventInfo_v1::Core
@ Core
Core flags describing the event.
Definition: EventInfo_v1.h:339
HIClusterGeo_HistoFiller::m_phiBins
const int m_phiBins
Definition: HIClusterGeo_HistoFiller.h:48