ATLAS Offline Software
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"
19 #include "StoreGate/StoreGateSvc.h"
22 #include "TH1F.h"
23 #include "TH2F.h"
24 #include "TProfile.h"
25 
27 #include <string>
28 
29 egammaMonToolBase::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 
78 
79  return sc;
80 }
81 
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 
100 void 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 
106 void 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 
113 void 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 
119 void 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 
126 void 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 
132 void 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 
148 void 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 
155 void 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 
171 void 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 
178 void 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 
186 void 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
223 {
224  const xAOD::EventInfo* event_info = nullptr;
225  StatusCode sc = evtStore()->retrieve( event_info );
226  if (sc.isFailure()) {
227  ATH_MSG_WARNING("Could not get LAr event info!");
228  }
229 
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 
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 }
egammaMonToolBase::procHistograms
virtual StatusCode procHistograms() override
An inheriting class should either override this function or finalHists().
Definition: egammaMonToolBase.cxx:249
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
egammaMonToolBase::~egammaMonToolBase
virtual ~egammaMonToolBase()
Definition: egammaMonToolBase.cxx:55
egammaMonToolBase::bookTProfile
void bookTProfile(TProfile *&h, MonGroup &mygroup, const std::string &hname, const std::string &htitle, int nbins, float xlow, float xhigh, float ylow, float yhigh)
Definition: egammaMonToolBase.cxx:126
egammaMonToolBase::m_Trigger
std::vector< std::string > m_Trigger
Definition: egammaMonToolBase.h:106
egammaMonToolBase::fillEfficiencies
void fillEfficiencies(TH1 *h, TH1 *href)
Definition: egammaMonToolBase.cxx:258
egammaMonToolBase::CRACK
@ CRACK
Definition: egammaMonToolBase.h:86
egammaMonToolBase::initialize
virtual StatusCode initialize() override
Definition: egammaMonToolBase.cxx:60
ManagedMonitorToolBase
Provides functionality for users to implement and save histograms, ntuples, and summary data,...
Definition: ManagedMonitorToolBase.h:73
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:279
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
egammaMonToolBase.h
egammaMonToolBase::ENDCAP
@ ENDCAP
Definition: egammaMonToolBase.h:86
TrigDecisionTool.h
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
egammaMonToolBase::bookTH2FperRegion
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)
Definition: egammaMonToolBase.cxx:155
egammaMonToolBase::bookTH1F
void bookTH1F(TH1 *&h, MonGroup &mygroup, const std::string &hname, const std::string &htitle, int nbins, float low, float high)
Definition: egammaMonToolBase.cxx:100
egammaMonToolBase::fillTH1FperRegion
static void fillTH1FperRegion(std::vector< TH1 * > &vhist, unsigned int ir, float x)
Definition: egammaMonToolBase.cxx:178
egammaMonToolBase::m_EventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Definition: egammaMonToolBase.h:113
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
x
#define x
xAOD::EventInfo_v1::LAr
@ LAr
The LAr calorimeter.
Definition: EventInfo_v1.h:335
egammaMonToolBase::bookTH1FperRegion
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)
Definition: egammaMonToolBase.cxx:132
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
IDTPMcnv.href
href
Definition: IDTPMcnv.py:30
xAOD::EventInfo_v1::Error
@ Error
The sub-detector issued an error.
Definition: EventInfo_v1.h:349
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
egammaMonToolBase::fillTH2FperRegion
static void fillTH2FperRegion(std::vector< TH2 * > &vhist, unsigned int ir, float x, float y)
Definition: egammaMonToolBase.cxx:186
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
egammaMonToolBase::bookHistograms
virtual StatusCode bookHistograms() override
An inheriting class should either override this function or bookHists().
Definition: egammaMonToolBase.cxx:93
ManagedMonitorToolBase::MonGroup
A container of information describing a monitoring object.
Definition: ManagedMonitorToolBase.h:137
A
egammaMonToolBase::FORWARD
@ FORWARD
Definition: egammaMonToolBase.h:86
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ManagedMonitorToolBase::initialize
virtual StatusCode initialize()
Definition: ManagedMonitorToolBase.cxx:617
egammaMonToolBase::GetRegion
static int GetRegion(float eta)
Definition: egammaMonToolBase.cxx:201
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
extractSporadic.h
list h
Definition: extractSporadic.py:97
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
covarianceTool.title
title
Definition: covarianceTool.py:542
egammaMonToolBase::m_GroupExtension
std::string m_GroupExtension
Definition: egammaMonToolBase.h:110
test_pyathena.parent
parent
Definition: test_pyathena.py:15
AthenaMonManager.h
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
xAOD::EventInfo_v1::EventFlagErrorState
EventFlagErrorState
States that a given sub-detector could be in.
Definition: EventInfo_v1.h:346
CaloCondBlobAlgs_fillNoiseFromASCII.comment
string comment
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
egammaMonToolBase::m_trigdec
ToolHandle< Trig::TrigDecisionTool > m_trigdec
Definition: egammaMonToolBase.h:107
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
egammaMonToolBase::NREGION
@ NREGION
Definition: egammaMonToolBase.h:86
egammaMonToolBase::fillHistograms
virtual StatusCode fillHistograms() override
An inheriting class should either override this function or fillHists().
Definition: egammaMonToolBase.cxx:214
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
y
#define y
h
egammaMonToolBase::egammaMonToolBase
egammaMonToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Definition: egammaMonToolBase.cxx:29
egammaMonToolBase::m_UseTrigger
bool m_UseTrigger
Definition: egammaMonToolBase.h:108
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ManagedMonitorToolBase::endOfRunFlag
bool endOfRunFlag() const
Definition: ManagedMonitorToolBase.h:797
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::EventInfo_v1::errorState
EventFlagErrorState errorState(EventFlagSubDet subDet) const
Get the error state for a particular sub-detector.
Definition: EventInfo_v1.cxx:817
egammaMonToolBase::m_currentLB
unsigned int m_currentLB
Definition: egammaMonToolBase.h:112
egammaMonToolBase::BARREL
@ BARREL
Definition: egammaMonToolBase.h:86
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
egammaMonToolBase::m_region
std::vector< std::string > m_region
Definition: egammaMonToolBase.h:116
egammaMonToolBase::getCurrentLB
unsigned int getCurrentLB()
Definition: egammaMonToolBase.cxx:82
egammaMonToolBase::hasBadLar
bool hasBadLar()
Definition: egammaMonToolBase.cxx:222
egammaMonToolBase::bookTH2F
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)
Definition: egammaMonToolBase.cxx:113
egammaMonToolBase::hasGoodTrigger
bool hasGoodTrigger(const std::string &comment)
Definition: egammaMonToolBase.cxx:288
StoreGateSvc.h
ManagedMonitorToolBase::regHist
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 ...
Definition: ManagedMonitorToolBase.cxx:1346
egammaMonToolBase::GetForwardRegion
static int GetForwardRegion(float eta)
Definition: egammaMonToolBase.cxx:194