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
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}
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 with parameters:
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
Gaudi::Property< float > m_minFCalET
virtual StatusCode execute() override
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:739