ATLAS Offline Software
Loading...
Searching...
No Matches
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
7HIClusterGeo_HistoFiller::HIClusterGeo_HistoFiller(const std::string& name, ISvcLocator* pSvcLocator) :
8 AthAlgorithm(name, pSvcLocator), m_etaPhiMapping(nullptr)
9{
10}
11
12TH1 * 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{
31 ATH_CHECK( m_eventInfoKey.initialize() );
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
49StatusCode HIClusterGeo_HistoFiller::execute(const EventContext& ctx)
50{
51
53 if (!eventInfo.isValid())
54 {
55 ATH_MSG_WARNING("Cannot get EventInfo with key " << m_eventInfoKey.key());
56 return StatusCode::SUCCESS;
57 }
58
59 if((eventInfo->errorState(xAOD::EventInfo::LAr) == xAOD::EventInfo::Error) ||
60 (eventInfo->errorState(xAOD::EventInfo::Tile) == xAOD::EventInfo::Error) ||
61 (eventInfo->isEventFlagBitSet(xAOD::EventInfo::Core, 18)) )
62 {
63 return StatusCode::SUCCESS;
64 }
65
66 // GRL selection will be done later by "makeHIResponse",
67 // here, we just save everything into separate histograms for each LB
68
69 // trigger decision tool is not needed if we use CC and PC streams
70
72 if(!vertices.isValid())
73 {
74 ATH_MSG_WARNING("Cannot get VertexContainer with key " << m_vertexContainerKey.key());
75 return StatusCode::SUCCESS;
76 }
77 if(vertices->size() <= 1)
78 {
79 // no vertex
80 return StatusCode::SUCCESS;
81 }
82
84 if (!caloClusters.isValid())
85 {
86 ATH_MSG_WARNING("Cannot get CaloClusterContainer with key " << m_caloClusterContainerKey.key());
87 return StatusCode::SUCCESS;
88 }
89
91 if (!hiEventShape.isValid())
92 {
93 ATH_MSG_WARNING("Cannot get HIEventShapeContainer with key " << m_hiEventShapeKey.key());
94 return StatusCode::SUCCESS;
95 }
96
97 int currentLB = eventInfo->lumiBlock();
98 int currentRun = eventInfo->runNumber();
99
100 if (auto search = m_histTileWeights.find(currentLB); search == m_histTileWeights.end())
101 {
102 // if m_histTileWeights does not already have histogram forthis LB, allocate a new TH2F
103 // bins in Y: sum FCalET, sum ClusterET, sum FCalET^2, sum ClusterET^2, sum FCalET*ClusterET, number of events
104 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));
105 if (newHistTileWeights == nullptr)
106 {
107 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);
108 return StatusCode::SUCCESS;
109 }
110
111 m_histTileWeights[currentLB] = std::move(newHistTileWeights);
112 }
113
114 auto currentHistTileWeights = m_histTileWeights.at(currentLB);
115
116 float fcalEt = hiEventShape->at(5)->et()*1e-6;
117 if(fcalEt<m_minFCalET || m_maxFCalET<fcalEt)
118 {
119 // remove in-time and out-of-time pile-up
120 return StatusCode::SUCCESS;
121 }
122
123 for(const auto* cluster : *caloClusters)
124 {
125 float eta = cluster->eta();
126 float phi = cluster->phi();
127 int binID = m_etaPhiMapping->FindBin(eta, phi);
128 float ET = cluster->e() * 1e-3 / std::cosh(eta);
129
130 currentHistTileWeights->Fill(binID, 1, fcalEt);
131 currentHistTileWeights->Fill(binID, 2, ET);
132 currentHistTileWeights->Fill(binID, 3, fcalEt*fcalEt);
133 currentHistTileWeights->Fill(binID, 4, ET*ET);
134 currentHistTileWeights->Fill(binID, 5, fcalEt*ET);
135 currentHistTileWeights->Fill(binID, 6, 1.);
136 }
137
138 return StatusCode::SUCCESS;
139}
140
142{
143 return StatusCode::SUCCESS;
144}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
HIClusterGeo_HistoFiller(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::HIEventShapeContainer > m_hiEventShapeKey
TH1 * regAndGetTHF(const std::string &histName, const std::string &histTitle, int numBinsX, double xMin, double xMax, int numBinsY, double yMin, double yMax)
ServiceHandle< ITHistSvc > m_thistSvc
Gaudi::Property< std::string > m_histStream
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Gaudi::Property< float > m_minFCalET
virtual StatusCode finalize() override
Gaudi::Property< float > m_maxFCalET
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClusterContainerKey
std::unordered_map< int, TH2F * > m_histTileWeights
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
@ Tile
The Tile calorimeter.
@ Core
Core flags describing the event.
@ LAr
The LAr calorimeter.
@ Error
The sub-detector issued an error.
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:743