ATLAS Offline Software
Loading...
Searching...
No Matches
egammaMonToolBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6//
7// 2014-05-21 Author: Remi Lafaye (Annecy)
8// 2015-02-28 Author: Bertrand LAFORGE (LPNHE Paris)
9// NAME: egammaMonToolBase.cxx
10// PACKAGE: offline/Reconstruction/egamma/egammaPerformance
11// PURPOSE: Provides basic functionalities to egammaMonTool clsees
12//
14
15
16#include "egammaMonToolBase.h"
17#include "GaudiKernel/MsgStream.h"
18#include "GaudiKernel/StatusCode.h"
22#include "TH1F.h"
23#include "TH2F.h"
24#include "TProfile.h"
25
27#include <string>
28
29egammaMonToolBase::egammaMonToolBase(const std::string & type, const std::string & name, const IInterface* parent)
30 : ManagedMonitorToolBase(type,name,parent), m_trigdec("Trig::TrigDecisionTool/TrigDecisionTool"), m_UseTrigger(false)
31{
32
33 // trigger tool
34
35 declareProperty("EgUseTrigger", m_UseTrigger);
36 declareProperty("EgTrigDecisionTool", m_trigdec);
37
38 // Name of trigger (automatic configuration)
39
40 declareProperty("EgTrigger", m_Trigger, "Name of Trigger in express stream");
41
42 // mutiple usage of the tool requires a configurable name for Groups
43
44 declareProperty("EgGroupExtension", m_GroupExtension="", "Name of Group Extension");
45
46 m_region.resize(NREGION,"");
47 m_region[BARREL]="BARREL";
48 m_region[CRACK]="CRACK";
49 m_region[ENDCAP]="ENDCAP";
50 m_region[FORWARD]="FORWARD";
51
52 m_currentLB = 0;
53}
54
56{
57 ATH_MSG_DEBUG("egammaMonToolBase::~egammaMonToolBase()");
58}
59
61{
63 if(sc.isFailure()) {
64 ATH_MSG_FATAL( "ManagedMonitorToolBase::initialize() - Failed" );
65 }
66
67 if (m_UseTrigger) {
68 sc = m_trigdec.retrieve();
69 if (!sc.isFailure()){
70 ATH_MSG_DEBUG("TriggerTool found");
71 }
72 else {
73 ATH_MSG_FATAL("Unable to retrieve TriggerTool" );
74 }
75 }
76
77 ATH_CHECK( m_EventInfoKey.initialize() );
78
79 return sc;
80}
81
82unsigned int egammaMonToolBase::getCurrentLB(const EventContext& ctx)
83{
85 if (evtInfo.isValid()) {
86 return evtInfo->lumiBlock();
87 }
88 ATH_MSG_ERROR("couldn't retrieve event info");
89 return -1;
90
91}
92
94{
95 ATH_MSG_DEBUG("egammaMonToolBase::bookHistograms()");
96
97 return StatusCode::SUCCESS;
98}
99
100void egammaMonToolBase::bookTH1F(TH1* &h, MonGroup& mygroup, const std::string& hname, const std::string& htitle, int nbins, float low, float high)
101{
102 h = new TH1F(hname.c_str(),htitle.c_str(),nbins,low,high);
103 regHist(h,mygroup).ignore();
104}
105
106void egammaMonToolBase::bookTH1F(TH1* &h, MonGroup& mygroup, const std::string& hname_prefix, const std::string& htitle_prefix, int nbins, float low, float high, std::string &nameOfEgammaType)
107{
108 std::string hname = hname_prefix + nameOfEgammaType;
109 std::string htitle = htitle_prefix + " (" + nameOfEgammaType + ")";
110 bookTH1F(h, mygroup, hname, htitle, nbins, low, high);
111}
112
113void egammaMonToolBase::bookTH2F(TH2* &h, MonGroup& mygroup, const std::string& hname, const std::string& htitle, int nbinsx, float xlow, float xhigh, int nbinsy, float ylow, float yhigh)
114{
115 h = new TH2F(hname.c_str(),htitle.c_str(),nbinsx,xlow,xhigh,nbinsy,ylow,yhigh);
116 regHist(h,mygroup).ignore();
117}
118
119void egammaMonToolBase::bookTH2F(TH2* &h, MonGroup& mygroup, const std::string& hname_prefix, const std::string& htitle_prefix, int nbinsx, float xlow, float xhigh, int nbinsy, float ylow, float yhigh, std::string &nameOfEgammaType)
120{
121 std::string hname = hname_prefix + nameOfEgammaType;
122 std::string htitle = htitle_prefix + " (" + nameOfEgammaType + ")";
123 bookTH2F(h, mygroup, hname, htitle, nbinsx, xlow, xhigh, nbinsy, ylow, yhigh);
124}
125
126void egammaMonToolBase::bookTProfile(TProfile* &h, MonGroup& mygroup, const std::string& hname, const std::string& htitle, int nbins, float xlow, float xhigh, float ylow, float yhigh)
127{
128 h = new TProfile(hname.c_str(),htitle.c_str(),nbins,xlow,xhigh,ylow,yhigh);
129 regHist(h,mygroup).ignore();
130}
131
132void egammaMonToolBase::bookTH1FperRegion(std::vector<TH1*> &vhist, MonGroup& mygroup, const std::string& hname, const std::string& htitle, int nbins, float low, float high, unsigned int min_region, unsigned int max_region)
133{
134 std::string name;
135 std::string title;
136
137 vhist.resize(NREGION,nullptr);
138 for(unsigned int ir=min_region;ir<=max_region;ir++) {
139 // Create histograms
140 name = hname+"_"+m_region[ir];
141 title = htitle+" "+m_region[ir];
142 TH1 *h = new TH1F(name.c_str(),title.c_str(),nbins,low,high);
143 vhist[ir] = h;
144 regHist(h,mygroup).ignore();
145 }
146}
147
148void egammaMonToolBase::bookTH1FperRegion(std::vector<TH1*> &vhist, MonGroup& mygroup, const std::string& hname_prefix, const std::string& htitle_prefix, int nbins, float low, float high, unsigned int min_region, unsigned int max_region, std::string &nameOfEgammaType)
149{
150 std::string hname = hname_prefix + nameOfEgammaType;
151 std::string htitle = htitle_prefix + " (" + nameOfEgammaType + ")";
152 bookTH1FperRegion(vhist, mygroup, hname, htitle, nbins, low, high, min_region, max_region);
153}
154
155void egammaMonToolBase::bookTH2FperRegion(std::vector<TH2*> &vhist, MonGroup& mygroup, const std::string& hname, const std::string& htitle, int nbinsx, float xlow, float xhigh, int nbinsy, float ylow, float yhigh, unsigned int min_region, unsigned int max_region)
156{
157 std::string name;
158 std::string title;
159
160 vhist.resize(NREGION,nullptr);
161 for(unsigned int ir=min_region;ir<=max_region;ir++) {
162 // Create histograms
163 name = hname+"_"+m_region[ir];
164 title = htitle+" "+m_region[ir];
165 TH2 *h = new TH2F(name.c_str(),title.c_str(),nbinsx,xlow,xhigh,nbinsy,ylow,yhigh);
166 vhist[ir] = h;
167 regHist(h,mygroup).ignore();
168 }
169}
170
171void egammaMonToolBase::bookTH2FperRegion(std::vector<TH2*> &vhist, MonGroup& mygroup, const std::string& hname_prefix, const std::string& htitle_prefix, int nbinsx, float xlow, float xhigh, int nbinsy, float ylow, float yhigh, unsigned int min_region, unsigned int max_region, std::string &nameOfEgammaType)
172{
173 std::string hname = hname_prefix + nameOfEgammaType;
174 std::string htitle = htitle_prefix + " (" + nameOfEgammaType + ")";
175 bookTH2FperRegion(vhist, mygroup, hname, htitle, nbinsx, xlow, xhigh, nbinsy, ylow, yhigh, min_region, max_region);
176}
177
178void egammaMonToolBase::fillTH1FperRegion(std::vector<TH1*> &vhist, unsigned int ir, float x)
179{
180 unsigned int size = vhist.size();
181 if(ir>=size) return;
182 TH1 *h = vhist[ir];
183 if(h) h->Fill(x);
184 }
185
186void egammaMonToolBase::fillTH2FperRegion(std::vector<TH2*> &vhist, unsigned int ir, float x, float y)
187{
188 unsigned int size = vhist.size();
189 if(ir>=size) return;
190 TH2 *h = vhist[ir];
191 if(h) h->Fill(x,y);
192}
193
195{
196 float aeta = fabs(eta);
197 if( aeta < 3.2 ) return ENDCAP;
198 return FORWARD;
199}
200
202{
203 float aeta = fabs(eta);
204 // check if object is in barrel
205 if( aeta < 1.37 ) return BARREL;
206 // check if object is in end-caps
207 if( aeta > 1.52) /* && aeta < 2.47 ) */ return ENDCAP;
208 // check if object is in crack region
209 //if( aeta > 1.37 && aeta < 1.52 )
210 return CRACK;
211 // Forward region not checked here! See GetForwardRegion()
212}
213
215{
216 ATH_MSG_DEBUG("egammaMonToolBase::fillHistograms()");
217
218 return StatusCode::SUCCESS;
219}
220
221//GYS. In the case the event is flagged bad due to LAr noise or LAr data error this is true
222bool egammaMonToolBase::hasBadLar(const EventContext& ctx)
223{
225 if (!eventInfo.isValid()) {
226 ATH_MSG_ERROR("Could not get LAr event info!");
227 return false;
228 }
229
230 xAOD::EventInfo::EventFlagErrorState error_state = eventInfo->errorState(xAOD::EventInfo::LAr);
231
232 // Only removing events with Error not with Warning
233 //if (error_state==xAOD::EventInfo::Warning)
234 // {
235 // ATH_MSG_DEBUG("LAr event noisy");
236 // return true;
237 // }
238
239 if (error_state==xAOD::EventInfo::Error)
240 {
241 ATH_MSG_DEBUG("LAr event data integrity error");
242 return true;
243 }
244
245 ATH_MSG_DEBUG("No LAr noise");
246 return false;
247}
248
250{
251 if(endOfRunFlag()) {
252 // Extra work to be done at end of run
253 }
254
255 return StatusCode::SUCCESS;
256}
257
259{
260 int nbins = h->GetNbinsX();
261 if(href->GetNbinsX()!=nbins) {
262 ATH_MSG_WARNING("egammaMonToolBase::FillEfficiencies(): histograms have different number of bins, can not divide!");
263 return;
264 }
265
266 ATH_MSG_DEBUG("egammaMonToolBase::FillEfficiencies(): start new computation");
267
268 for(int i=1;i<nbins+1;++i){
269 double eps = 0.;
270 double err = 0.;
271 double Yref = href->GetBinContent(i);
272 if(Yref>0) {
273 double A = h->GetBinContent(i);
274 eps = A/Yref;
275 err = sqrt(eps*(1-eps)/Yref);
276
277 // convert to percent
278 eps *= 100.;
279 err *= 100.;
280
281 }
282
283 h->SetBinContent(i,eps);
284 h->SetBinError(i,err);
285 }
286 }
287
288bool egammaMonToolBase::hasGoodTrigger(const std::string& comment){
289
290 if (!m_UseTrigger) {
291 ATH_MSG_DEBUG("No Trigger request for that monitoring tool");
292 return true; // return true if no trigger selection is expected
293 }
294
295 ATH_MSG_DEBUG( "Size of " << comment << " Trigger vector = "<< m_Trigger.size() );
296 bool triggerfound = false;
297 for (const auto & i : m_Trigger){
298 ATH_MSG_DEBUG(comment << " Trigger " << i << " for that event ?");
299 if (m_trigdec->isPassed(i))
300 {
301 triggerfound=true;
302 ATH_MSG_DEBUG(comment << " Trigger " << i << " found for that event");
303 }
304 }
305
306 if (!triggerfound) ATH_MSG_DEBUG("No " << comment << " Trigger found for that event");
307
308 // Alternative code if we need to get a list of avalaible triggers in the stream
309 if (!m_trigdec.retrieve().isFailure()){
310 const std::vector<std::string>& vec = m_trigdec->getListOfTriggers();
311 ATH_MSG_DEBUG( "Size of Trigger vector in xAOD file = "<< vec.size());
312 for (const auto & i : vec) {
313 if (m_trigdec->isPassed(i)) {
314 ATH_MSG_DEBUG("Active Trigger found : " << i );
315 }
316 // else {
317 // ATH_MSG_DEBUG("Passive Trigger found : " << vec[i] );
318 // }
319 }
320 }
321 else {
322 ATH_MSG_DEBUG("Trigger m_trigdec is null !!!");
323 }
324
325 // only fill histograms if the event has been correctly triggered or if no trigger is expected.
326 return triggerfound;
327}
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
static Double_t sc
#define y
#define x
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Header file for AthHistogramAlgorithm.
A container of information describing a monitoring object.
virtual StatusCode regHist(TH1 *h, const std::string &system, Interval_t interval, MgmtAttr_t histo_mgmt=ATTRIB_MANAGED, const std::string &chain="", const std::string &merge="")
Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream using logical ...
ManagedMonitorToolBase(const std::string &type, const std::string &name, const IInterface *parent)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual StatusCode initialize() override
std::string m_GroupExtension
void bookTH1FperRegion(std::vector< TH1 * > &vhist, MonGroup &mygroup, const std::string &hname, const std::string &htitle, int nbins, float low, float high, unsigned int min_region, unsigned int max_region)
void bookTProfile(TProfile *&h, MonGroup &mygroup, const std::string &hname, const std::string &htitle, int nbins, float xlow, float xhigh, float ylow, float yhigh)
unsigned int getCurrentLB(const EventContext &ctx)
bool hasBadLar(const EventContext &ctx)
void bookTH2FperRegion(std::vector< TH2 * > &vhist, MonGroup &mygroup, const std::string &hname, const std::string &htitle, int nbinsx, float xlow, float xhigh, int nbinsy, float ylow, float yhigh, unsigned int min_region, unsigned int max_region)
bool hasGoodTrigger(const std::string &comment)
void bookTH2F(TH2 *&h, MonGroup &mygroup, const std::string &hname, const std::string &htitle, int nbinsx, float xlow, float xhigh, int nbinsy, float ylow, float yhigh)
static void fillTH2FperRegion(std::vector< TH2 * > &vhist, unsigned int ir, float x, float y)
virtual StatusCode procHistograms() override
An inheriting class should either override this function or finalHists().
egammaMonToolBase(const std::string &type, const std::string &name, const IInterface *parent)
static int GetForwardRegion(float eta)
std::vector< std::string > m_Trigger
virtual StatusCode bookHistograms() override
An inheriting class should either override this function or bookHists().
ToolHandle< Trig::TrigDecisionTool > m_trigdec
static void fillTH1FperRegion(std::vector< TH1 * > &vhist, unsigned int ir, float x)
static int GetRegion(float eta)
virtual StatusCode fillHistograms() override
An inheriting class should either override this function or fillHists().
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
void bookTH1F(TH1 *&h, MonGroup &mygroup, const std::string &hname, const std::string &htitle, int nbins, float low, float high)
void fillEfficiencies(TH1 *h, TH1 *href)
std::vector< std::string > m_region
@ LAr
The LAr calorimeter.
EventFlagErrorState
States that a given sub-detector could be in.
@ Error
The sub-detector issued an error.
int ir
counter of the current depth
Definition fastadd.cxx:49
hold the test vectors and ease the comparison