ATLAS Offline Software
JetHistoAttributeFiller.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
6 
8 
9 
10 namespace {
11 
12 
13  //***********************************************
14  // A set of helper functions to implement the details of filling
15  // the jet variable in histograms.
16  // The details depend if we fill 1D or 2D histograms and if some of the
17  // variables are of type <vector>
18 
19  int processX(ToolHandle<GenericMonitoringTool> &grpT, const JetVar::Variable *vX, const xAOD::JetContainer & jets) {
20  Monitored::Scalar<float> sX(vX->name());
21  Monitored::Group gr( grpT, sX);
22  gr.setAutoFill(false); // important in case there are 0 jets
23 
24  int nfill=0;
25  //std::cout<< grpT->name() << " "<< vX->name() << " ffffffffff " << vX->m_index << std::endl;
26  for(const xAOD::Jet* j:jets){
27  //std::cout<< " ----> " << vX->value(*j) << " "<< vX->m_index << std::endl;
28  sX = vX->value(*j);
29  gr.fill(); nfill++;
30  }
31  return nfill;
32  }
33 
34  void processXVec(ToolHandle<GenericMonitoringTool> &grpT, const JetVar::Variable *vX, const xAOD::JetContainer & jets) {
35  Monitored::Scalar<float> sX(vX->name());
36  Monitored::Group gr( grpT, sX);
37  gr.setAutoFill(false);
38 
39  for(const xAOD::Jet* j:jets){
40  auto vec = vX->vector(*j);
41  size_t N= vec.size();
42  for(size_t i=0;i<N;i++) {sX=vec[i]; gr.fill(); }
43  }
44  }
45 
46  void processXY(ToolHandle<GenericMonitoringTool> &grpT, const JetVar::Variable *vX, const JetVar::Variable *vY, const xAOD::JetContainer & jets) {
47  Monitored::Scalar<float> sX(vX->name());
48  Monitored::Scalar<float> sY(vY->name());
49  Monitored::Group gr( grpT, sX, sY);
50  gr.setAutoFill(false);
51 
52  for(const xAOD::Jet* j:jets){
53  sX = vX->value(*j);
54  sY = vY->value(*j);
55  gr.fill();
56  }
57  }
58 
59  void processXVecY(ToolHandle<GenericMonitoringTool> &grpT, const JetVar::Variable *vX, const JetVar::Variable *vY, const xAOD::JetContainer & jets) {
60  Monitored::Scalar<float> sX(vX->name());
61  Monitored::Scalar<float> sY(vY->name());
62  Monitored::Group gr( grpT, sX, sY);
63  gr.setAutoFill(false);
64 
65  for(const xAOD::Jet* j:jets){
66  sY = vY->value(*j);
67  auto vec = vX->vector(*j);
68  size_t N= vec.size();
69  for(size_t i=0;i<N;i++) {sX=vec[i]; gr.fill(); }
70  }
71  }
72 
73 
74  void processXYVec(ToolHandle<GenericMonitoringTool> &grpT, const JetVar::Variable *vX, const JetVar::Variable *vY, const xAOD::JetContainer & jets) {
75  Monitored::Scalar<float> sX(vX->name());
76  Monitored::Scalar<float> sY(vY->name());
77  Monitored::Group gr( grpT, sX, sY);
78  gr.setAutoFill(false);
79 
80  for(const xAOD::Jet* j:jets){
81  sX = vX->value(*j);
82  auto vec = vY->vector(*j);
83  size_t N= vec.size();
84  for(size_t i=0;i<N;i++) {sY=vec[i]; gr.fill(); }
85  }
86  }
87 
88  void processXVecYVec(ToolHandle<GenericMonitoringTool> &grpT, const JetVar::Variable *vX, const JetVar::Variable *vY, const xAOD::JetContainer & jets) {
89  Monitored::Scalar<float> sX(vX->name());
90  Monitored::Scalar<float> sY(vY->name());
91  Monitored::Group gr( grpT, sX, sY);
92  gr.setAutoFill(false);
93 
94  for(const xAOD::Jet* j:jets){
95  auto vecX = vX->vector(*j);
96  auto vecY = vY->vector(*j);
97  size_t Nx= vecX.size();
98  size_t Ny= vecY.size();
99  size_t N = Nx<Ny ? Nx : Ny;
100  for(size_t i=0;i<N;i++) {sX=vecX[i];sY=vecY[i]; gr.fill(); }
101  }
102  }
103 
104 
105  void processXYZ(ToolHandle<GenericMonitoringTool> &grpT, const JetVar::Variable *vX, const JetVar::Variable *vY, const JetVar::Variable *vZ, const xAOD::JetContainer & jets) {
106  Monitored::Scalar<float> sX(vX->name());
107  Monitored::Scalar<float> sY(vY->name());
108  Monitored::Scalar<float> sZ(vZ->name());
109  Monitored::Group gr( grpT, sX, sY, sZ);
110  gr.setAutoFill(false);
111 
112  for(const xAOD::Jet* j:jets){
113  sX = vX->value(*j);
114  sY = vY->value(*j);
115  sZ = vZ->value(*j);
116  gr.fill();
117  }
118  }
119 
120 
121 }
122 
123 
124 
125 
126 JetHistoAttributeFiller::JetHistoAttributeFiller( const std::string& type, const std::string & name ,const IInterface* parent):
128  , m_varX(this)
129  , m_varY(this)
130  , m_varZ(this)
131 
132 {
133  declareInterface<IJetHistoFiller>(this);
134 
135  declareProperty("VarX",m_varX);
136  declareProperty("VarY",m_varY);
137  declareProperty("VarZ",m_varZ);
138 
139 }
140 
141 
143  ATH_CHECK(m_varX.retrieve() );
144  m_nVar = 1;
145  if( ! m_varY.isEnabled() ){
146  ATH_MSG_DEBUG( "Filling 1 var X=("<< m_varX->describe() << ")");
147  }else { // has Y variable
148  ATH_CHECK(m_varY.retrieve() );
149  m_nVar = 2;
150  if ( ! m_varZ.isEnabled()) {
151  ATH_MSG_DEBUG( "Filling 2 vars X=("<< m_varX->describe() << ") Y=("<<m_varY->describe() << ")");
152  }else{
153  ATH_CHECK(m_varZ.retrieve() );
154  m_nVar = 3;
155  ATH_MSG_DEBUG( "Filling 3 vars X=("<< m_varX->describe() << ") Y=("<<m_varY->describe() << ") Z=("<<m_varZ->describe() << ")");
156  }
157 
158  }
159 
160  return StatusCode::SUCCESS;
161 }
162 
163 
165  if(jets.empty()) return StatusCode::SUCCESS;
166  const JetVar::Variable * vX = m_varX->variable();
167  ToolHandle<GenericMonitoringTool> grpT = parentAlg.getGroup(m_group);
168 
169  if(m_nVar==1){
170  if( vX->isVector() ) processXVec(grpT, vX, jets) ;
171  else processX(grpT, vX, jets) ;
172 
173  }else if(m_nVar==2) { //
174 
175  const JetVar::Variable * vY = m_varY->variable();
176 
177  int c = int(vX->isVector() | vY->isVector()<<1) ; // encode what to do so we can use a switch()
178  switch( c ){
179  case 0: processXY(grpT, vX,vY, jets) ; break ;
180  case 1: processXVecY(grpT, vX,vY, jets) ; break ;
181  case 2: processXYVec(grpT, vX,vY, jets) ; break ;
182  case 3: processXVecYVec(grpT, vX,vY, jets) ; break ;
183 
184  }
185  } else { // then m_nVar == 3
186  const JetVar::Variable * vY = m_varY->variable();
187  const JetVar::Variable * vZ = m_varZ->variable();
188  processXYZ(grpT, vX,vY, vZ, jets) ;
189  }
190 
191 
192  return StatusCode::SUCCESS;
193 }
194 
195 
JetHistoAttributeFiller::processJetContainer
virtual StatusCode processJetContainer(const JetMonitoringAlg &parentAlg, const xAOD::JetContainer &jets, const EventContext &ctx) const
Definition: JetHistoAttributeFiller.cxx:164
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JetVar::Variable::isVector
virtual bool isVector() const
return true if the underlying variable is of type vector<X>
Definition: JetVariable.h:59
Monitored::Group
Group of local monitoring quantities and retain correlation when filling histograms
Definition: MonitoredGroup.h:54
gr
#define gr
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
GenericMonitoringTool.h
JetVar::Variable
Definition: JetVariable.h:51
lumiFormat.i
int i
Definition: lumiFormat.py:85
JetHistoAttributeFiller::m_nVar
int m_nVar
Definition: JetHistoAttributeFiller.h:50
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
JetHistoAttributeFiller::m_varY
ToolHandle< IJetHistoVarTool > m_varY
Definition: JetHistoAttributeFiller.h:46
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
JetHistoAttributeFiller::JetHistoAttributeFiller
JetHistoAttributeFiller(const std::string &type, const std::string &name, const IInterface *parent)
Definition: JetHistoAttributeFiller.cxx:126
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
JetVar::Variable::name
virtual std::string name() const
Definition: JetVariable.h:65
JetHistoAttributeFiller::initialize
virtual StatusCode initialize()
Definition: JetHistoAttributeFiller.cxx:142
JetMonitoringAlg
Definition: JetMonitoringAlg.h:26
JetVar::Variable::value
virtual float value(const xAOD::Jet &) const =0
JetHistoAttributeFiller::m_varX
ToolHandle< IJetHistoVarTool > m_varX
Definition: JetHistoAttributeFiller.h:45
JetHistoAttributeFiller::m_group
Gaudi::Property< std::string > m_group
Definition: JetHistoAttributeFiller.h:44
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetMonitoringAlg.h
JetHistoAttributeFiller::m_varZ
ToolHandle< IJetHistoVarTool > m_varZ
Definition: JetHistoAttributeFiller.h:48
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
JetVar::VectorValue::size
size_t size() const
Definition: JetVariable.h:45
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
AthAlgTool
Definition: AthAlgTool.h:26
JetHistoAttributeFiller.h
python.compressB64.c
def c
Definition: compressB64.py:93
JetVar::Variable::vector
virtual VectorValue vector(const xAOD::Jet &) const
return a helper object allowing to iterate over the underlying vector. !!! use only if isVector()==tr...
Definition: JetVariable.h:62
AthMonitorAlgorithm::getGroup
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
Definition: AthMonitorAlgorithm.cxx:164