ATLAS Offline Software
Loading...
Searching...
No Matches
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
10namespace {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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
126JetHistoAttributeFiller::JetHistoAttributeFiller( const std::string& type, const std::string & name ,const IInterface* parent):
127 AthAlgTool( type, name, 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
164StatusCode JetHistoAttributeFiller::processJetContainer(const JetMonitoringAlg& parentAlg, const xAOD::JetContainer & jets, const EventContext& ) const {
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
#define gr
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
ToolHandle< IJetHistoVarTool > m_varY
ToolHandle< IJetHistoVarTool > m_varZ
Gaudi::Property< std::string > m_group
JetHistoAttributeFiller(const std::string &type, const std::string &name, const IInterface *parent)
ToolHandle< IJetHistoVarTool > m_varX
virtual StatusCode processJetContainer(const JetMonitoringAlg &parentAlg, const xAOD::JetContainer &jets, const EventContext &ctx) const
A monitoring algorithm in charge of filling histogram for a JetContainer.
The goal of this class is to define a common way to access any "jet variable".
Definition JetVariable.h:51
virtual std::string name() const
Definition JetVariable.h:65
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
virtual float value(const xAOD::Jet &) const =0
virtual bool isVector() const
return true if the underlying variable is of type vector<X>
Definition JetVariable.h:59
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".
size_t size() const
Definition JetVariable.h:45