ATLAS Offline Software
egammaMonToolBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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  m_storeGate = nullptr;
54 }
55 
57 {
58  ATH_MSG_DEBUG("egammaMonToolBase::~egammaMonToolBase()");
59 }
60 
62 {
64  if(sc.isFailure()) {
65  ATH_MSG_FATAL( "ManagedMonitorToolBase::initialize() - Failed" );
66  }
67 
68  sc = service("StoreGateSvc", m_storeGate);
69  if(sc.isFailure()) {
70  ATH_MSG_FATAL( "Unable to locate Service StoreGateSvc" );
71  }
72 
73  if (m_UseTrigger) {
74  sc = m_trigdec.retrieve();
75  if (!sc.isFailure()){
76  ATH_MSG_DEBUG("TriggerTool found");
77  }
78  else {
79  ATH_MSG_FATAL("Unable to retrieve TriggerTool" );
80  }
81  }
82 
84 
85  return sc;
86 }
87 
89 {
91  if (evtInfo.isValid()) {
92  return evtInfo->lumiBlock();
93  }
94  ATH_MSG_ERROR("couldn't retrieve event info");
95  return -1;
96 
97 }
98 
100 {
101  ATH_MSG_DEBUG("egammaMonToolBase::bookHistograms()");
102 
103  return StatusCode::SUCCESS;
104 }
105 
106 void egammaMonToolBase::bookTH1F(TH1* &h, MonGroup& mygroup, const std::string& hname, const std::string& htitle, int nbins, float low, float high)
107 {
108  h = new TH1F(hname.c_str(),htitle.c_str(),nbins,low,high);
109  regHist(h,mygroup).ignore();
110 }
111 
112 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)
113 {
114  std::string hname = hname_prefix + nameOfEgammaType;
115  std::string htitle = htitle_prefix + " (" + nameOfEgammaType + ")";
116  bookTH1F(h, mygroup, hname, htitle, nbins, low, high);
117 }
118 
119 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)
120 {
121  h = new TH2F(hname.c_str(),htitle.c_str(),nbinsx,xlow,xhigh,nbinsy,ylow,yhigh);
122  regHist(h,mygroup).ignore();
123 }
124 
125 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)
126 {
127  std::string hname = hname_prefix + nameOfEgammaType;
128  std::string htitle = htitle_prefix + " (" + nameOfEgammaType + ")";
129  bookTH2F(h, mygroup, hname, htitle, nbinsx, xlow, xhigh, nbinsy, ylow, yhigh);
130 }
131 
132 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)
133 {
134  h = new TProfile(hname.c_str(),htitle.c_str(),nbins,xlow,xhigh,ylow,yhigh);
135  regHist(h,mygroup).ignore();
136 }
137 
138 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)
139 {
140  std::string name;
141  std::string title;
142 
143  vhist.resize(NREGION,nullptr);
144  for(unsigned int ir=min_region;ir<=max_region;ir++) {
145  // Create histograms
146  name = hname+"_"+m_region[ir];
147  title = htitle+" "+m_region[ir];
148  TH1 *h = new TH1F(name.c_str(),title.c_str(),nbins,low,high);
149  vhist[ir] = h;
150  regHist(h,mygroup).ignore();
151  }
152 }
153 
154 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)
155 {
156  std::string hname = hname_prefix + nameOfEgammaType;
157  std::string htitle = htitle_prefix + " (" + nameOfEgammaType + ")";
158  bookTH1FperRegion(vhist, mygroup, hname, htitle, nbins, low, high, min_region, max_region);
159 }
160 
161 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)
162 {
163  std::string name;
164  std::string title;
165 
166  vhist.resize(NREGION,nullptr);
167  for(unsigned int ir=min_region;ir<=max_region;ir++) {
168  // Create histograms
169  name = hname+"_"+m_region[ir];
170  title = htitle+" "+m_region[ir];
171  TH2 *h = new TH2F(name.c_str(),title.c_str(),nbinsx,xlow,xhigh,nbinsy,ylow,yhigh);
172  vhist[ir] = h;
173  regHist(h,mygroup).ignore();
174  }
175 }
176 
177 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)
178 {
179  std::string hname = hname_prefix + nameOfEgammaType;
180  std::string htitle = htitle_prefix + " (" + nameOfEgammaType + ")";
181  bookTH2FperRegion(vhist, mygroup, hname, htitle, nbinsx, xlow, xhigh, nbinsy, ylow, yhigh, min_region, max_region);
182 }
183 
184 void egammaMonToolBase::fillTH1FperRegion(std::vector<TH1*> &vhist, unsigned int ir, float x)
185 {
186  unsigned int size = vhist.size();
187  if(ir>=size) return;
188  TH1 *h = vhist[ir];
189  if(h) h->Fill(x);
190  }
191 
192 void egammaMonToolBase::fillTH2FperRegion(std::vector<TH2*> &vhist, unsigned int ir, float x, float y)
193 {
194  unsigned int size = vhist.size();
195  if(ir>=size) return;
196  TH2 *h = vhist[ir];
197  if(h) h->Fill(x,y);
198 }
199 
201 {
202  float aeta = fabs(eta);
203  if( aeta < 3.2 ) return ENDCAP;
204  return FORWARD;
205 }
206 
208 {
209  float aeta = fabs(eta);
210  // check if object is in barrel
211  if( aeta < 1.37 ) return BARREL;
212  // check if object is in end-caps
213  if( aeta > 1.52) /* && aeta < 2.47 ) */ return ENDCAP;
214  // check if object is in crack region
215  //if( aeta > 1.37 && aeta < 1.52 )
216  return CRACK;
217  // Forward region not checked here! See GetForwardRegion()
218 }
219 
221 {
222  ATH_MSG_DEBUG("egammaMonToolBase::fillHistograms()");
223 
224  return StatusCode::SUCCESS;
225 }
226 
227 //GYS. In the case the event is flagged bad due to LAr noise or LAr data error this is true
229 {
230  const xAOD::EventInfo* event_info = nullptr;
231  StatusCode sc = m_storeGate->retrieve( event_info );
232  if (sc.isFailure()) {
233  ATH_MSG_WARNING("Could not get LAr event info!");
234  }
235 
237 
238  // Only removing events with Error not with Warning
239  //if (error_state==xAOD::EventInfo::Warning)
240  // {
241  // ATH_MSG_DEBUG("LAr event noisy");
242  // return true;
243  // }
244 
245  if (error_state==xAOD::EventInfo::Error)
246  {
247  ATH_MSG_DEBUG("LAr event data integrity error");
248  return true;
249  }
250 
251  ATH_MSG_DEBUG("No LAr noise");
252  return false;
253 }
254 
256 {
257  if(endOfRunFlag()) {
258  // Extra work to be done at end of run
259  }
260 
261  return StatusCode::SUCCESS;
262 }
263 
265 {
266  int nbins = h->GetNbinsX();
267  if(href->GetNbinsX()!=nbins) {
268  ATH_MSG_WARNING("egammaMonToolBase::FillEfficiencies(): histograms have different number of bins, can not divide!");
269  return;
270  }
271 
272  ATH_MSG_DEBUG("egammaMonToolBase::FillEfficiencies(): start new computation");
273 
274  for(int i=1;i<nbins+1;++i){
275  double eps = 0.;
276  double err = 0.;
277  double Yref = href->GetBinContent(i);
278  if(Yref>0) {
279  double A = h->GetBinContent(i);
280  eps = A/Yref;
281  err = sqrt(eps*(1-eps)/Yref);
282 
283  // convert to percent
284  eps *= 100.;
285  err *= 100.;
286 
287  }
288 
289  h->SetBinContent(i,eps);
290  h->SetBinError(i,err);
291  }
292  }
293 
295 
296  if (!m_UseTrigger) {
297  ATH_MSG_DEBUG("No Trigger request for that monitoring tool");
298  return true; // return true if no trigger selection is expected
299  }
300 
301  ATH_MSG_DEBUG( "Size of " << comment << " Trigger vector = "<< m_Trigger.size() );
302  bool triggerfound = false;
303  for (const auto & i : m_Trigger){
304  ATH_MSG_DEBUG(comment << " Trigger " << i << " for that event ?");
305  if (m_trigdec->isPassed(i))
306  {
307  triggerfound=true;
308  ATH_MSG_DEBUG(comment << " Trigger " << i << " found for that event");
309  }
310  }
311 
312  if (!triggerfound) ATH_MSG_DEBUG("No " << comment << " Trigger found for that event");
313 
314  // Alternative code if we need to get a list of avalaible triggers in the stream
315  if (!m_trigdec.retrieve().isFailure()){
316  const std::vector<std::string>& vec = m_trigdec->getListOfTriggers();
317  ATH_MSG_DEBUG( "Size of Trigger vector in xAOD file = "<< vec.size());
318  for (const auto & i : vec) {
319  if (m_trigdec->isPassed(i)) {
320  ATH_MSG_DEBUG("Active Trigger found : " << i );
321  }
322  // else {
323  // ATH_MSG_DEBUG("Passive Trigger found : " << vec[i] );
324  // }
325  }
326  }
327  else {
328  ATH_MSG_DEBUG("Trigger m_trigdec is null !!!");
329  }
330 
331  // only fill histograms if the event has been correctly triggered or if no trigger is expected.
332  return triggerfound;
333 }
egammaMonToolBase::procHistograms
virtual StatusCode procHistograms() override
An inheriting class should either override this function or finalHists().
Definition: egammaMonToolBase.cxx:255
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
egammaMonToolBase::~egammaMonToolBase
virtual ~egammaMonToolBase()
Definition: egammaMonToolBase.cxx:56
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:132
egammaMonToolBase::m_Trigger
std::vector< std::string > m_Trigger
Definition: egammaMonToolBase.h:109
egammaMonToolBase::fillEfficiencies
void fillEfficiencies(TH1 *h, TH1 *href)
Definition: egammaMonToolBase.cxx:264
egammaMonToolBase::initialize
virtual StatusCode initialize() override
Definition: egammaMonToolBase.cxx:61
ManagedMonitorToolBase
Provides functionality for users to implement and save histograms, ntuples, and summary data,...
Definition: ManagedMonitorToolBase.h:74
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:272
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
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
TrigDecisionTool.h
egammaMonToolBase::CRACK
@ CRACK
Definition: egammaMonToolBase.h:86
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
egammaMonToolBase::NREGION
@ NREGION
Definition: egammaMonToolBase.h:86
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:161
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:106
egammaMonToolBase::fillTH1FperRegion
static void fillTH1FperRegion(std::vector< TH1 * > &vhist, unsigned int ir, float x)
Definition: egammaMonToolBase.cxx:184
egammaMonToolBase::m_EventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Definition: egammaMonToolBase.h:116
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:138
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
xAOD::EventInfo_v1::Error
@ Error
The sub-detector issued an error.
Definition: EventInfo_v1.h:349
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
dqt_zlumi_alleff_HIST.A
A
Definition: dqt_zlumi_alleff_HIST.py:110
egammaMonToolBase::BARREL
@ BARREL
Definition: egammaMonToolBase.h:86
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
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:192
egammaMonToolBase::bookHistograms
virtual StatusCode bookHistograms() override
An inheriting class should either override this function or bookHists().
Definition: egammaMonToolBase.cxx:99
ManagedMonitorToolBase::MonGroup
A container of information describing a monitoring object.
Definition: ManagedMonitorToolBase.h:138
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ManagedMonitorToolBase::initialize
virtual StatusCode initialize()
Definition: ManagedMonitorToolBase.cxx:669
egammaMonToolBase::GetRegion
static int GetRegion(float eta)
Definition: egammaMonToolBase.cxx:207
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:113
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
TH2
Definition: rootspy.cxx:373
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
egammaMonToolBase::m_storeGate
StoreGateSvc * m_storeGate
Definition: egammaMonToolBase.h:107
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
egammaMonToolBase::m_trigdec
ToolHandle< Trig::TrigDecisionTool > m_trigdec
Definition: egammaMonToolBase.h:110
TProfile
Definition: rootspy.cxx:515
TH1::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:298
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
egammaMonToolBase::fillHistograms
virtual StatusCode fillHistograms() override
An inheriting class should either override this function or fillHists().
Definition: egammaMonToolBase.cxx:220
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:111
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ManagedMonitorToolBase::endOfRunFlag
bool endOfRunFlag() const
Definition: ManagedMonitorToolBase.h:859
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TH1
Definition: rootspy.cxx:268
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:115
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
egammaMonToolBase::ENDCAP
@ ENDCAP
Definition: egammaMonToolBase.h:86
egammaMonToolBase::m_region
std::vector< std::string > m_region
Definition: egammaMonToolBase.h:119
egammaMonToolBase::getCurrentLB
unsigned int getCurrentLB()
Definition: egammaMonToolBase.cxx:88
egammaMonToolBase::hasBadLar
bool hasBadLar()
Definition: egammaMonToolBase.cxx:228
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:119
egammaMonToolBase::hasGoodTrigger
bool hasGoodTrigger(const std::string &comment)
Definition: egammaMonToolBase.cxx:294
StoreGateSvc.h
egammaMonToolBase::FORWARD
@ FORWARD
Definition: egammaMonToolBase.h:86
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:1454
egammaMonToolBase::GetForwardRegion
static int GetForwardRegion(float eta)
Definition: egammaMonToolBase.cxx:200