ATLAS Offline Software
PFOMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "PFOMonitorAlgorithm.h"
6 #include "xAODPFlow/FEHelpers.h"
7 #include "AthenaKernel/Units.h"
9 
10 PFOMonitorAlgorithm::PFOMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
11 :AthMonitorAlgorithm(name,pSvcLocator)
12 {}
13 
14 
16 
17 
19  // initialize superclass
21 
22  ATH_CHECK( m_ChargedPFOContainerKey.initialize() );
23  ATH_CHECK( m_NeutralPFOContainerKey.initialize() );
24 
25  // release 21 containters
26  //ATH_CHECK( m_oldChargedPFOContainerKey.initialize() );
27  //ATH_CHECK( m_oldNeutralPFOContainerKey.initialize() );
28  return StatusCode::SUCCESS;
29 }
30 
31 
32 StatusCode PFOMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
33  using namespace Monitored;
34 
35  // Declare the quantities which should be monitored
36  auto nPFOs = Monitored::Scalar<int>("nPFOs",0.0);
37  auto pT = Monitored::Scalar<float>("pfopT",0.0);
38  auto eta = Monitored::Scalar<float>("pfoEta",0.0);
39  auto phi = Monitored::Scalar<float>("pfoPhi",0.0);
40  auto mass = Monitored::Scalar<float>("pfoMass",0.0);
41  auto E = Monitored::Scalar<float>("pfoE",0.0);
42  auto y = Monitored::Scalar<float>("pfoRapidity",0.0);
43 
44  auto nChPFOs = Monitored::Scalar<int>("nChPFOs",0.0);
45  auto ChpT = Monitored::Scalar<float>("ChpfopT",0.0);
46  auto Cheta = Monitored::Scalar<float>("ChpfoEta",0.0);
47  auto Chphi = Monitored::Scalar<float>("ChpfoPhi",0.0);
48  auto Chmass = Monitored::Scalar<float>("ChpfoMass",0.0);
49  auto ChE = Monitored::Scalar<float>("ChpfoE",0.0);
50  auto Chy = Monitored::Scalar<float>("ChpfoRapidity",0.0);
51  auto ChExpE = Monitored::Scalar<float>("ChpfoExpE",0.0);
52  auto ChDenseEnv = Monitored::Scalar<int>("ChpfoDenseEnv",0.0);
53 
54 // Declare cutmasks for dense environment
55  auto DenseEnvFlag = Monitored::Scalar<bool>("DenseEnvFlag",false);
56 
57  auto nNuPFOs = Monitored::Scalar<int>("nNuPFOs",0.0);
58  auto NupT = Monitored::Scalar<float>("NupfopT",0.0);
59  auto Nueta = Monitored::Scalar<float>("NupfoEta",0.0);
60  auto Nuphi = Monitored::Scalar<float>("NupfoPhi",0.0);
61  auto Numass = Monitored::Scalar<float>("NupfoMass",0.0);
62  auto NuE = Monitored::Scalar<float>("NupfoE",0.0);
63  auto Nuy = Monitored::Scalar<float>("NupfoRapidity",0.0);
64  auto NuSecondR = Monitored::Scalar<float>("NupfoSecondR",0.0);
65  auto NuSecondLambda = Monitored::Scalar<float>("NupfoSecondLambda",0.0);
66  auto NuCenterLambda = Monitored::Scalar<float>("NupfoCenterLambda",0.0);
67  auto NuNBadCells = Monitored::Scalar<float>("NupfoNBadCells",0.0);
68  auto NuEBadCells = Monitored::Scalar<float>("NupfoEBadCells",0.0);
69  auto NuBadLarQFrac= Monitored::Scalar<float>("NupfoBadLarQFrac",0.0);
70  auto NuIso = Monitored::Scalar<float>("NupfoIsolation",0.0);
71  auto NuEPos = Monitored::Scalar<float>("NupfoEPos",0.0);
72  auto NuNBadC = Monitored::Scalar<int>("NupfoNBadCells",0);
73  auto NuAvgLarQ= Monitored::Scalar<float>("NupfoAvgLarQ",0.0);
74  auto NuAvgTileQ= Monitored::Scalar<float>("NupfoAvgTileQ",0.0);
75  auto NuEMProb= Monitored::Scalar<float>("NupfoEMProb",0.0);
76  // Not currently filled in the xAOD
77  //auto NuSignif = Monitored::Scalar<float>("NupfoSignificance",0.0);
78  //auto NuEFracMX= Monitored::Scalar<float>("NupfoEFracMax",0.0);
79 
80  // Access the Particle Flow Objects via StoreGate
82  if (! chpfos.isValid() ) {
83  ATH_MSG_WARNING("evtStore() does not contain PFO Collection with name "<< m_ChargedPFOContainerKey);
84  return StatusCode::SUCCESS; //Return SUCCESS so processing proceeds
85  }
86 
88  if (! nupfos.isValid() ) {
89  ATH_MSG_WARNING("evtStore() does not contain PFO Collection with name "<< m_NeutralPFOContainerKey);
90  return StatusCode::SUCCESS; //Return SUCCESS so processing proceeds
91  }
92 
93  // Set monitored variables for this event
94  nPFOs = chpfos->size() + nupfos->size();
95  nChPFOs = chpfos->size();
96  nNuPFOs = nupfos->size();
97 
98  fill("PFOMonitorAllPFOs",nPFOs);
99  fill("PFOMonitorChargedPFOs",nChPFOs);
100  fill("PFOMonitorNeutralPFOs",nNuPFOs);
101 
102  // Accessors for neutral PFO moments
103  const static SG::AuxElement::ConstAccessor<float> acc_SECOND_R("SECOND_R");
104  const static SG::AuxElement::ConstAccessor<float> acc_CENTER_LAMBDA("CENTER_LAMBDA");
105  const static SG::AuxElement::ConstAccessor<float> acc_ISOLATION("ISOLATION");
106  const static SG::AuxElement::ConstAccessor<float> acc_N_BAD_CELLS("N_BAD_CELLS");
107  const static SG::AuxElement::ConstAccessor<float> acc_ENG_BAD_CELLS("ENG_BAD_CELLS");
108  const static SG::AuxElement::ConstAccessor<float> acc_BADLARQ_FRAC("BADLARQ_FRAC");
109  const static SG::AuxElement::ConstAccessor<float> acc_ENG_POS("ENG_POS");
110  const static SG::AuxElement::ConstAccessor<float> acc_AVG_LAR_Q("AVG_LAR_Q");
111  const static SG::AuxElement::ConstAccessor<float> acc_AVG_TILE_Q("AVG_TILE_Q");
112  const static SG::AuxElement::ConstAccessor<float> acc_EM_PROBABILITY("EM_PROBABILITY");
113  const static SG::AuxElement::ConstAccessor<float> acc_SECOND_LAMBDA("SECOND_LAMBDA");
114  // Not currently filled in the xAOD
115  //const static SG::AuxElement::ConstAccessor<float> acc_SIGNIFICANCE("SIGNIFICANCE");
116  //const static SG::AuxElement::ConstAccessor<float> acc_ENG_FRAC_MAX("ENG_FRAC_MAX");
117 
118  // Accessors for charged PFO moments
119  const static SG::AuxElement::ConstAccessor<int> acc_IsInDenseEnvironment("IsInDenseEnvironment");
120  const static SG::AuxElement::ConstAccessor<float> acc_tracksExpectedEnergyDeposit("TracksExpectedEnergyDeposit");
121 
122  for (const auto& pfo : *chpfos) {
123  pT = pfo->pt()/GeV;
124  eta = pfo->eta();
125  phi = pfo->phi();
126  mass= pfo->m()/GeV;
127  E = pfo->e()/GeV;
128  y = pfo->rapidity();
129  //float score = bdtPi0Score();
130 
131  int denseEnv = 0;
132  float expectedEnergy = -1.0;
133 
134  // Fill moments associated with tracks and track association
135  if(acc_IsInDenseEnvironment.isAvailable(*pfo)) {denseEnv = acc_IsInDenseEnvironment(*pfo);}
136  else {ATH_MSG_DEBUG("This charged PFO did not have IsInDenseEnvironment set");}
137 
138  if(acc_tracksExpectedEnergyDeposit.isAvailable(*pfo)) {expectedEnergy = acc_tracksExpectedEnergyDeposit(*pfo);}
139  else {ATH_MSG_DEBUG("This charged PFO did not have TracksExpectedEnergyDeposit set");}
140 
141  ChpT = pfo->pt()/GeV;
142  Cheta = pfo->eta();
143  Chphi = pfo->phi();
144  Chmass= pfo->m()/GeV;
145  ChE = pfo->e()/GeV;
146  Chy = pfo->rapidity();
147  ChDenseEnv = denseEnv;
148  ChExpE= expectedEnergy;
149 
150  // Fill. First argument is the tool name, all others are the variables to be saved.
151  fill("PFOMonitorAllPFOs",pT,eta,phi,mass,E,y);
152  DenseEnvFlag = denseEnv;
153  fill("PFOMonitorChargedPFOs",ChpT,Cheta,Chphi,Chmass,ChE,Chy,ChDenseEnv,ChExpE,DenseEnvFlag);
154 
155  }
156 
157  for (const auto& pfo : *nupfos) {
158  E = pfo->e()/GeV;
159  //some neutral particle flow FlowELement can have their energy set to exactly zero. Will get FPE if
160  //try to calculate rapidity, so skip these.
161  if (0 == E) continue;
162  pT = pfo->pt()/GeV;
163  eta = pfo->eta();
164  phi = pfo->phi();
165  mass= pfo->m()/GeV;
166  y = pfo->rapidity();
167 
168  NupT = pfo->pt()/GeV;
169  Nueta = pfo->eta();
170  Nuphi = pfo->phi();
171  Numass= pfo->m()/GeV;
172  NuE = pfo->e()/GeV;
173  Nuy = pfo->rapidity();
174 
175  if (acc_ISOLATION.isAvailable(*pfo)) {NuIso = acc_ISOLATION(*pfo);}
176  else {ATH_MSG_DEBUG("This neutral PFO did not have ISOLATION set");}
177 
178  if (acc_ENG_POS.isAvailable(*pfo)) {NuEPos= acc_ENG_POS(*pfo);}
179  else {ATH_MSG_DEBUG("This neutral PFO did not have ENG_POS set");}
180 
181  if (acc_N_BAD_CELLS.isAvailable(*pfo)) {NuNBadCells = acc_N_BAD_CELLS(*pfo);}
182  else {ATH_MSG_DEBUG("This neutral PFO did not have N_BAD_CELLS set");}
183 
184  if (acc_ENG_BAD_CELLS.isAvailable(*pfo)) {NuEBadCells = acc_ENG_BAD_CELLS(*pfo);}
185  else {ATH_MSG_DEBUG("This neutral PFO did not have ENG_BAD_CELLS set");}
186 
187  if (acc_AVG_LAR_Q.isAvailable(*pfo)) {NuAvgLarQ = acc_AVG_LAR_Q(*pfo);}
188  else {ATH_MSG_DEBUG("This neutral PFO did not have AVG_LAR_Q set");}
189 
190  if (acc_AVG_TILE_Q.isAvailable(*pfo)) {NuAvgTileQ = acc_AVG_TILE_Q(*pfo);}
191  else {ATH_MSG_DEBUG("This neutral PFO did not have AVG_TILE_Q set");}
192 
193  if (acc_SECOND_R.isAvailable(*pfo)) {NuSecondR = acc_SECOND_R(*pfo);}
194  else {ATH_MSG_DEBUG("This neutral PFO did not have SECOND_R set");}
195 
196  if (acc_SECOND_LAMBDA.isAvailable(*pfo)) {NuSecondLambda = acc_SECOND_LAMBDA(*pfo);}
197  else {ATH_MSG_DEBUG("This neutral PFO did not have SECOND_LAMBDA set");}
198 
199  if (acc_CENTER_LAMBDA.isAvailable(*pfo)) {NuCenterLambda = acc_CENTER_LAMBDA(*pfo);}
200  else {ATH_MSG_DEBUG("This neutral PFO did not have CENTER_LAMBDA set");}
201 
202  if (acc_BADLARQ_FRAC.isAvailable(*pfo)) {NuBadLarQFrac = acc_BADLARQ_FRAC(*pfo);}
203  else {ATH_MSG_DEBUG("This neutral PFO did not have BAD_LARQ_FRAC set");}
204 
205  if (acc_EM_PROBABILITY.isAvailable(*pfo)) {NuEMProb = acc_EM_PROBABILITY(*pfo);}
206  else {ATH_MSG_DEBUG("This neutral PFO did not have BAD_LARQ_FRAC set");}
207 
208  // These moments do not appear to be filled currently in the xAOD, but leave commented out
209  // in case they are turned on later.
210  //if (acc_SIGNIFICANCE.isAvailable(*pfo)) {NuSignif = acc_SIGNIFICANCE(*pfo);}
211  //else {ATH_MSG_DEBUG("This charged PFO did not have SIGNIFICANCE set");}
212  //if (acc_ENG_FRAC_MAX.isAvailable(*pfo)) {NuEFracMAX = acc_ENG_FRAC_MAX(*pfo);}
213  //else {ATH_MSG_DEBUG("This neutral PFO did not have ENG_FRAC_MAX set");}
214 
215  // Fill. First argument is the tool name, all others are the variables to be saved.
216  fill("PFOMonitorAllPFOs",pT,eta,phi,mass,E,y);
217  fill("PFOMonitorNeutralPFOs",NupT,Nueta,Nuphi,Numass,NuE,Nuy,NuIso,NuEPos,NuNBadC,NuEBadCells,NuAvgLarQ,NuSecondR,NuCenterLambda,NuSecondLambda,NuBadLarQFrac,NuEMProb);
218  }
219 
220  return StatusCode::SUCCESS;
221 }
PFOMonitorAlgorithm::m_NeutralPFOContainerKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_NeutralPFOContainerKey
Definition: PFOMonitorAlgorithm.h:25
PFOMonitorAlgorithm.h
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
PFOMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: PFOMonitorAlgorithm.cxx:18
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
PFOMonitorAlgorithm::PFOMonitorAlgorithm
PFOMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PFOMonitorAlgorithm.cxx:10
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
PFOMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: PFOMonitorAlgorithm.cxx:32
FEHelpers.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
PFOMonitorAlgorithm::~PFOMonitorAlgorithm
virtual ~PFOMonitorAlgorithm()
Units.h
Wrapper to avoid constant divisions when using units.
PFOMonitorAlgorithm::m_ChargedPFOContainerKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_ChargedPFOContainerKey
Definition: PFOMonitorAlgorithm.h:24
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
y
#define y
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.