ATLAS Offline Software
Loading...
Searching...
No Matches
SuperCellVsCaloCellTestAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// LArROD includes
7
9
10#include "TFile.h"
11#include "TProfile.h"
12#include "TGraph.h"
13#include "TH1F.h"
14#include "TH2F.h"
15
16#include "TTree.h"
17#include "GaudiKernel/ITHistSvc.h"
18
20#include <cmath>
21
22//needed for linker ...
23//constexpr double SuperCellVsCaloCellTestAlg::eBins[SuperCellVsCaloCellTestAlg::nBinsE+1];
24//constexpr double SuperCellVsCaloCellTestAlg::etaBins[SuperCellVsCaloCellTestAlg::nBinsEta+1];
25
26SuperCellVsCaloCellTestAlg::SuperCellVsCaloCellTestAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
27 AthAlgorithm( name, pSvcLocator ),
28 m_sc2ccMappingTool("CaloSuperCellIDTool"),
29 m_ccIdHelper(nullptr),
30 m_treeDigits(nullptr),
31 m_tree(nullptr)
32{
33
34 declareProperty("SuperCellContainer",m_scKey="SCell");
35 declareProperty("CaloCellContainer",m_ccKey="AllCalo");
36 declareProperty("TruthSuperCellContainer",m_tscKey="SCellTruth");
37 declareProperty("DigitContainer",m_digitKey="LArDigitSCL1","Only used for suspicious supercells");
38
39 declareProperty("OutputStream",m_stream="SUPERCELLTEST");
40
41}
42
43
45
46
48
49 //get the mapping tool
50 CHECK( m_sc2ccMappingTool.retrieve() );
51 //and the id helper (used for making id hashes)
52 CHECK( detStore()->retrieve (m_ccIdHelper, "CaloCell_ID") );
53
54 double etBins[11] = {0.1,0.25,0.5,0.75,1.,1.5,2.,3.,4.,5.,10.}; //in GeV
56 if(!m_ccKey.empty()) {
57 m_etReso.push_back(new TProfile(TString::Format("%s_calocell",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s;CaloCell E_{T} [GeV];SuperCell E_{T} / CaloCell E_{T}",CaloSampling::getSamplingName(i).c_str()),10,etBins,"s"/* standard deviation for error*/));
58 m_etReso.back()->SetDirectory(nullptr);
59 m_Reso_et.push_back(new TH1F(TString::Format("%s_SuperCellResolution",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s;(SuperCell E_{T} - CaloCell E_{T}) / CaloCell E_{T} (%%)",CaloSampling::getSamplingName(i).c_str()),80,-40,40) );
60 m_Reso_et_vs_et.push_back(new TH2F(TString::Format("%s_SuperCellResolution_versus_et",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s; E_{T}[GeV] ; (SuperCell E_{T} - CaloCell E_{T}) / CaloCell E_{T} (%%)",CaloSampling::getSamplingName(i).c_str()),60,-10,50,80,-40,40) );
61 m_Reso_et_vs_eta.push_back(new TH2F(TString::Format("%s_SuperCellResolution_versus_eta",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s; #eta ; (SuperCell E_{T} - CaloCell E_{T}) / CaloCell E_{T} (%%)",CaloSampling::getSamplingName(i).c_str()),50,-2.5,2.5,80,-40,40) );
62 m_Linear_SCet_vs_et.push_back(new TH2F(TString::Format("%s_Linearity",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s; CaloCell Sum E_{T}[GeV] ; SuperCell E_{T}",CaloSampling::getSamplingName(i).c_str()),60,-10,50,60,-10,50) );
63 }
64 if(!m_tscKey.empty()) {
65 m_etResoTruth.push_back(new TProfile(TString::Format("%s_truth",CaloSampling::getSamplingName(i).c_str()),TString::Format("%s;Truth SuperCell E_{T} [GeV];SuperCell E_{T} / Truth SuperCell E_{T}",CaloSampling::getSamplingName(i).c_str()),10,etBins,"s"/* standard deviation for error*/));
66 m_etResoTruth.back()->SetDirectory(nullptr);
67 }
68 }
69
70 m_tree = new TTree("debug","debug");
71
72 m_treeDigits= new std::vector<short int>;
73
74 m_tree->Branch("EventNumber",&m_eventNumber);
75 m_tree->Branch("Channel",&m_treeChannel);
76 m_tree->Branch("Sampling",&m_treeSampling);
77 m_tree->Branch("eta",&m_treeEta);
78 m_tree->Branch("scET",&m_treeSCET);
79 m_tree->Branch("truthET",&m_treeTruthET);
80 m_tree->Branch("digits",&m_treeDigits);
81
82 ServiceHandle<ITHistSvc> histSvc("THistSvc",name());
83 CHECK( histSvc->regTree(TString::Format("/%s/debug",m_stream.c_str()).Data(),m_tree) );
84
85 ATH_CHECK( m_cablingKey.initialize() );
86
87
88 return StatusCode::SUCCESS;
89}
90
92
93 ServiceHandle<ITHistSvc> histSvc("THistSvc",name());
94
95 for(uint i=0;i<CaloSampling::getNumberOfSamplings();i++) { //don't bother writing empty hists
96 if(m_etReso[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_etReso[i]->GetName()).Data(),m_etReso[i]) );
97 if(m_Reso_et[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_Reso_et[i]->GetName()).Data(), m_Reso_et[i]) );
98 if(m_Reso_et_vs_eta[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_Reso_et_vs_eta[i]->GetName()).Data(), m_Reso_et_vs_eta[i]) );
99 if(m_Reso_et_vs_et[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_Reso_et_vs_et[i]->GetName()).Data(), m_Reso_et_vs_et[i]) );
100 if(m_Linear_SCet_vs_et[i]->GetEntries()) CHECK( histSvc->regHist(TString::Format("/%s/SuperCellValidation/%s",m_stream.c_str(),m_Linear_SCet_vs_et[i]->GetName()).Data(), m_Linear_SCet_vs_et[i]) );
101
102
103 if(!m_tscKey.empty()) {
104 if(m_etResoTruth[i]->GetEntries())CHECK( histSvc->regHist(TString::Format("/%s/%s",m_stream.c_str(),m_etResoTruth[i]->GetName()).Data(),m_etResoTruth[i]) );
105 }
106 }
107
108 //also write any graphs
109 for(auto graphPointsX : m_graphsX) {
110 TGraph* g = new TGraph(graphPointsX.second.size(),&graphPointsX.second[0],&m_graphsY[graphPointsX.first][0]);
111 g->SetTitle(graphPointsX.first);
112 g->SetMarkerStyle(6);
113 CHECK( histSvc->regGraph(TString::Format("/%s/%s",m_stream.c_str(),graphPointsX.first.Data()).Data(),g) );
114 }
115
116
117 return StatusCode::SUCCESS;
118}
119
121 //get the supercells, calocells
122 const CaloCellContainer* scells=nullptr;CHECK( evtStore()->retrieve(scells, m_scKey) );
123
124 const CaloCellContainer* ccells=nullptr;if(!m_ccKey.empty()) CHECK( evtStore()->retrieve(ccells, m_ccKey) );
125
126 const CaloCellContainer* tscells=nullptr;if(!m_tscKey.empty()) CHECK( evtStore()->retrieve(tscells,m_tscKey) );
127
129 const LArOnOffIdMapping* cabling{*cablingHdl};
130 if(!cabling) {
131 ATH_MSG_ERROR("Do not have SC mapping object " << m_cablingKey.key() );
132 return StatusCode::FAILURE;
133 }
134
135 //iterate over supercells, and build up a histogram of the resolution
136 for(const auto *scell : *scells) {
137 //bool passPeakFinder( (scell->provenance()&0x40) );
138 //if(!passPeakFinder) continue; //skip non maxima?
139
140 int samplingEnum = m_ccIdHelper->calo_sample(scell->ID());
141
142 double scellEt = scell->e()*scell->sinTh()*1e-3;
143
144 if(ccells) {
145 std::vector<Identifier> ccellIds = m_sc2ccMappingTool->superCellToOfflineID( scell->ID() );
146 double cellEt(0.);
147 //use findCell function of CaloCellContainer, which takes an identifier hash
148 for(auto& ccellId : ccellIds) {
149 const CaloCell* ccell = ccells->findCell(m_ccIdHelper->calo_cell_hash(ccellId));
150 if(!ccell) { ATH_MSG_WARNING("Could not find cell"); continue; }
151 if(ccell->e()>0) cellEt += ccell->e()*ccell->sinTh();
152 }
153 if(cellEt>0) m_etReso[samplingEnum]->Fill(cellEt*1e-3,scellEt*1000./cellEt);
154 float resolution = 0.0;
155 if ( std::abs(cellEt)>1 ) resolution = 100*(scellEt - cellEt*1e-3 ) / (cellEt*1e-3);
156 if ( std::abs(cellEt)>150 ) {
157 m_Reso_et[samplingEnum]->Fill( resolution );
158 m_Reso_et_vs_et[samplingEnum]->Fill( cellEt*1e-3, resolution );
159 m_Reso_et_vs_eta[samplingEnum]->Fill( scell->eta(), resolution );
160 m_Linear_SCet_vs_et[samplingEnum]->Fill( cellEt*1e-3 , scellEt );
161 }
162 }
163
164 if(tscells) {
165 const CaloCell* tscell = tscells->findCell(scell->caloDDE()->calo_hash());
166 double tscellEt = tscell->e()*tscell->sinTh()*1e-3;
167 if(tscellEt>0) m_etResoTruth[samplingEnum]->Fill(tscellEt,scellEt/tscellEt);
168
169 //detect suspicious supercells .. where truth energy is greater than 1GeV and we measure less than 25% of it, or super cell ET is greater than 1GeV and truth ET < 25% of that
170 if( (tscellEt>1. && scellEt/tscellEt<0.25) || (scellEt>1. && tscellEt/scellEt<0.25) ) {
171 m_eventNumber = getContext().eventID().event_number();
172
173 HWIdentifier hwid = cabling->createSignalChannelID(scell->ID());
175 m_treeSampling = samplingEnum;
176 m_treeEta = scell->caloDDE()->eta();
177 m_treeSCET = scellEt;
178 m_treeTruthET = tscellEt;
179 if(!m_digitKey.empty()) {
180 const LArDigitContainer* digits=nullptr;CHECK( evtStore()->retrieve(digits, m_digitKey) );
181 for(const auto *digit : *digits) { if(digit->hardwareID()==hwid) *m_treeDigits = digit->samples(); }
182 }
183 m_tree->Fill();
184 }
185
186 }
187
188
189
190
191 }
192
193
194 return StatusCode::SUCCESS;
195}
196
197
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define CHECK(...)
Evaluate an expression and check for errors.
unsigned int uint
TGraphErrors * GetEntries(TH2F *histo)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Container class for CaloCell.
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
virtual double e() const override final
get energy (data member) (synonym to method energy()
Definition CaloCell.h:333
virtual double sinTh() const override final
get sin(theta) (through CaloDetDescrElement)
Definition CaloCell.h:389
static std::string getSamplingName(CaloSample theSample)
Returns a string (name) for each CaloSampling.
static constexpr unsigned int getNumberOfSamplings()
Get number of available samplings.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Container class for LArDigit.
virtual ~SuperCellVsCaloCellTestAlg()
ToolHandle< ICaloSuperCellIDTool > m_sc2ccMappingTool
std::vector< short int > * m_treeDigits
std::vector< TProfile * > m_etResoTruth
std::vector< TH2F * > m_Linear_SCet_vs_et
SuperCellVsCaloCellTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::map< TString, std::vector< float > > m_graphsX
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
std::vector< TProfile * > m_etReso
std::map< TString, std::vector< float > > m_graphsY