ATLAS Offline Software
CovarianceFillerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: CovarianceFillerTool.cxx 281348 2010-02-24 23:15:11Z zaidan $
14 #include "CovarianceFillerTool.h"
15 //#include "TrkEventPrimitives/ErrorMatrix.h"
19 
20 #include <sstream>
21 
22 namespace D3PD {
23 
24 
32  (const std::string& type,
33  const std::string& name,
34  const IInterface* parent)
36 {
37  declareProperty ("Error", m_writeError=true);
38  declareProperty ("DiagCovariance", m_writeDiagCovariance=false);
39  declareProperty ("OffDiagCovariance", m_writeOffDiagCovariance=false);
40  declareProperty ("IsPosition", m_isPosition=false);
41  declareProperty ("IsTrackPerigee", m_isTrackPerigee=false);
42  declareProperty ("NParameters", m_nParameters=0);
43 }
44 
45 
50 {
51 
53  REPORT_MESSAGE (MSG::WARNING) << "CovarianceFillerTool is configured as a position and a track perigee error matrix filler"
54  << " ===> Filling a generic covariance matrix";
55  m_isPosition = false;
56  m_isTrackPerigee = false;
57  }
58 
59  if( m_isPosition ){
60  m_nParameters = 3;
61  }else if( m_isTrackPerigee ){
62  m_nParameters = 5;
63  }else{
64  //REPORT_MESSAGE (MSG::DEBUG) << "CovarianceFillerTool is filling a generic covariance matrix";
65  }
66 
67  if(m_nParameters<=0){
68  REPORT_MESSAGE (MSG::WARNING) << "CovarianceFillerTool is configured to fill a generic covariance matrix of size <= 0";
69  return StatusCode::SUCCESS;
70  }
71 
72  if( m_writeError )
73  m_err.resize (m_nParameters);
74 
75  int ncov = 0;
77  ncov = m_nParameters;
79  ncov += m_nParameters * (m_nParameters - 1) / 2;
80  m_cov.resize (ncov);
81 
82  if( m_isPosition ){
83  if( m_writeError ){
84  CHECK( addVariable ("err_x", m_err[0]) );
85  CHECK( addVariable ("err_y", m_err[1]) );
86  CHECK( addVariable ("err_z", m_err[2]) );
87  }
88  size_t icov = 0;
90  CHECK( addVariable ("cov_x", m_cov[icov++]) );
91  CHECK( addVariable ("cov_y", m_cov[icov++]) );
92  CHECK( addVariable ("cov_z", m_cov[icov++]) );
93  }
95  CHECK( addVariable ("cov_xy", m_cov[icov++]) );
96  CHECK( addVariable ("cov_xz", m_cov[icov++]) );
97  CHECK( addVariable ("cov_yz", m_cov[icov++]) );
98  }
99  }else if( m_isTrackPerigee ){
100  if( m_writeError ) {
101  CHECK( addVariable ("err_d0", m_err[0]) );
102  CHECK( addVariable ("err_z0", m_err[1]) );
103  CHECK( addVariable ("err_phi", m_err[2]) );
104  CHECK( addVariable ("err_theta", m_err[3]) );
105  CHECK( addVariable ("err_qoverp",m_err[4]) );
106  }
107 
108  size_t icov = 0;
109  if( m_writeDiagCovariance ){
110  CHECK( addVariable ("cov_d0", m_cov[icov++]) );
111  CHECK( addVariable ("cov_z0", m_cov[icov++]) );
112  CHECK( addVariable ("cov_phi", m_cov[icov++]) );
113  CHECK( addVariable ("cov_theta", m_cov[icov++]) );
114  CHECK( addVariable ("cov_qoverp", m_cov[icov++]) );
115  }
117  CHECK( addVariable ("cov_d0_z0", m_cov[icov++]) );
118  CHECK( addVariable ("cov_d0_phi", m_cov[icov++]) );
119  CHECK( addVariable ("cov_d0_theta", m_cov[icov++]) );
120  CHECK( addVariable ("cov_d0_qoverp", m_cov[icov++]) );
121  CHECK( addVariable ("cov_z0_phi", m_cov[icov++]) );
122  CHECK( addVariable ("cov_z0_theta", m_cov[icov++]) );
123  CHECK( addVariable ("cov_z0_qoverp", m_cov[icov++]) );
124  CHECK( addVariable ("cov_phi_theta", m_cov[icov++]) );
125  CHECK( addVariable ("cov_phi_qoverp", m_cov[icov++]) );
126  CHECK( addVariable ("cov_theta_qoverp",m_cov[icov++]) );
127  }
128  }else{
129  std::ostringstream str;
130  if( m_writeError ) {
131  for(int i=0; i<m_nParameters; i++){
132  str.str("");
133  str << "err_par" << i;
134  CHECK( addVariable (str.str().c_str(), m_err[i]) );
135  }
136  }
137  size_t icov = 0;
138  if( m_writeDiagCovariance) {
139  for(int i=0; i<m_nParameters; i++){
140  str.str("");
141  str << "cov_par" << i << "_par" << i;
142  CHECK( addVariable (str.str().c_str(), m_cov[icov++]) );
143  }
144  }
146  for(int i=0; i<m_nParameters; i++){
147  for(int j=i+1; j<m_nParameters; j++){
148  str.str("");
149  str << "cov_par" << i << "_par" << j;
150  CHECK( addVariable (str.str().c_str(), m_cov[icov++]) );
151  }
152  }
153  }
154  assert (icov == m_cov.size());
155  }
156 
157  return StatusCode::SUCCESS;
158 }
159 
160 
170 {
171 
172  if(m_nParameters<=0){
173  return StatusCode::SUCCESS;
174  }
175 
176  if( m_isTrackPerigee ) {
177  if (m.rows() > 0) {
178  if( m_writeError ) {
179  *m_err[0] = Amg::error(m,Trk::d0);
180  *m_err[1] = Amg::error(m,Trk::z0);
181  *m_err[2] = Amg::error(m,Trk::phi0);
182  *m_err[3] = Amg::error(m,Trk::theta);
183  *m_err[4] = Amg::error(m,Trk::qOverP);
184  }
185  size_t icov = 0;
186  if( m_writeDiagCovariance ) {
187  *m_cov[icov++] = m(Trk::d0,Trk::d0);
188  *m_cov[icov++] = m(Trk::z0,Trk::z0);
189  *m_cov[icov++] = m(Trk::phi0,Trk::phi0);
190  *m_cov[icov++] = m(Trk::theta,Trk::theta);
191  *m_cov[icov++] = m(Trk::qOverP,Trk::qOverP);
192  }
194  *m_cov[icov++] = m(Trk::d0,Trk::z0);
195  *m_cov[icov++] = m(Trk::d0,Trk::phi0);
196  *m_cov[icov++] = m(Trk::d0,Trk::theta);
197  *m_cov[icov++] = m(Trk::d0,Trk::qOverP);
198  *m_cov[icov++] = m(Trk::z0,Trk::phi0);
199  *m_cov[icov++] = m(Trk::z0,Trk::theta);
200  *m_cov[icov++] = m(Trk::z0,Trk::qOverP);
201  *m_cov[icov++] = m(Trk::phi0,Trk::theta);
202  *m_cov[icov++] = m(Trk::phi0,Trk::qOverP);
203  *m_cov[icov++] = m(Trk::theta,Trk::qOverP);
204  }
205  assert (icov == m_cov.size());
206  }
207  }
208  else{
209  if( m_writeError ) {
210  for(int i=0; i<m_nParameters; i++){
212  }
213  }
214 
215  size_t icov = 0;
216  if( m_writeDiagCovariance ) {
217  for(int i=0; i<m_nParameters; i++)
218  *m_cov[icov++] = m((Trk::ParamDefs)i,(Trk::ParamDefs)i);
219  }
221  for(int i=0; i<m_nParameters; i++) {
222  for(int j=i+1; j<m_nParameters; j++)
223  *m_cov[icov++] = m((Trk::ParamDefs)i,(Trk::ParamDefs)j);
224  }
225  }
226  assert (icov == m_cov.size());
227  }
228 
229  return StatusCode::SUCCESS;
230 }
231 
233 {
234 
235  if(m_nParameters<=0){
236  return StatusCode::SUCCESS;
237  }
238 
239  if( m_isPosition ){
240  if( m_writeError ) {
241  *m_err[0] = sqrt(m(Trk::x,Trk::x));
242  *m_err[1] = sqrt(m(Trk::y,Trk::y));
243  *m_err[2] = sqrt(m(Trk::z,Trk::z));
244  }
245 
246  size_t icov = 0;
247  if( m_writeDiagCovariance ) {
248  *m_cov[icov++] = m(Trk::x,Trk::x);
249  *m_cov[icov++] = m(Trk::y,Trk::y);
250  *m_cov[icov++] = m(Trk::z,Trk::z);
251  }
253  *m_cov[icov++] = m(Trk::x,Trk::y);
254  *m_cov[icov++] = m(Trk::x,Trk::z);
255  *m_cov[icov++] = m(Trk::y,Trk::z);
256  }
257  assert (icov == m_cov.size());
258  }else{
259  if( m_writeError ) {
260  for(int i=0; i<m_nParameters; i++){
261  *m_err[i] = sqrt(m((Trk::ParamDefs)i,(Trk::ParamDefs)i));
262  }
263  }
264 
265  size_t icov = 0;
266  if( m_writeDiagCovariance ) {
267  for(int i=0; i<m_nParameters; i++)
268  *m_cov[icov++] = m((Trk::ParamDefs)i,(Trk::ParamDefs)i);
269  }
271  for(int i=0; i<m_nParameters; i++) {
272  for(int j=i+1; j<m_nParameters; j++)
273  *m_cov[icov++] = m((Trk::ParamDefs)i,(Trk::ParamDefs)j);
274  }
275  }
276  assert (icov == m_cov.size());
277  }
278 
279  return StatusCode::SUCCESS;
280 }
281 
283 {
284 
285  if(m_nParameters<=0){
286  return StatusCode::SUCCESS;
287  }
288 
289  if( m_isTrackPerigee ) {
290  if (m.rows() > 0) {
291  if( m_writeError ) {
292  *m_err[0] = Amg::error(m,Trk::d0);
293  *m_err[1] = Amg::error(m,Trk::z0);
294  *m_err[2] = Amg::error(m,Trk::phi0);
295  *m_err[3] = Amg::error(m,Trk::theta);
296  *m_err[4] = Amg::error(m,Trk::qOverP);
297  }
298  size_t icov = 0;
299  if( m_writeDiagCovariance ) {
300  *m_cov[icov++] = m(Trk::d0,Trk::d0);
301  *m_cov[icov++] = m(Trk::z0,Trk::z0);
302  *m_cov[icov++] = m(Trk::phi0,Trk::phi0);
303  *m_cov[icov++] = m(Trk::theta,Trk::theta);
304  *m_cov[icov++] = m(Trk::qOverP,Trk::qOverP);
305  }
307  *m_cov[icov++] = m(Trk::d0,Trk::z0);
308  *m_cov[icov++] = m(Trk::d0,Trk::phi0);
309  *m_cov[icov++] = m(Trk::d0,Trk::theta);
310  *m_cov[icov++] = m(Trk::d0,Trk::qOverP);
311  *m_cov[icov++] = m(Trk::z0,Trk::phi0);
312  *m_cov[icov++] = m(Trk::z0,Trk::theta);
313  *m_cov[icov++] = m(Trk::z0,Trk::qOverP);
314  *m_cov[icov++] = m(Trk::phi0,Trk::theta);
315  *m_cov[icov++] = m(Trk::phi0,Trk::qOverP);
316  *m_cov[icov++] = m(Trk::theta,Trk::qOverP);
317  }
318  assert (icov == m_cov.size());
319  }
320  } else if( m_isPosition ){
321  if( m_writeError ) {
322  *m_err[0] = Amg::error(m,Trk::x);
323  *m_err[1] = Amg::error(m,Trk::y);
324  *m_err[2] = Amg::error(m,Trk::z);
325  }
326 
327  size_t icov = 0;
328  if( m_writeDiagCovariance ) {
329  *m_cov[icov++] = m(Trk::x,Trk::x);
330  *m_cov[icov++] = m(Trk::y,Trk::y);
331  *m_cov[icov++] = m(Trk::z,Trk::z);
332  }
334  *m_cov[icov++] = m(Trk::x,Trk::y);
335  *m_cov[icov++] = m(Trk::x,Trk::z);
336  *m_cov[icov++] = m(Trk::y,Trk::z);
337  }
338  assert (icov == m_cov.size());
339  }else{
340  if( m_writeError ) {
341  for(int i=0; i<m_nParameters; i++){
343  }
344  }
345 
346  size_t icov = 0;
347  if( m_writeDiagCovariance ) {
348  for(int i=0; i<m_nParameters; i++)
349  *m_cov[icov++] = m((Trk::ParamDefs)i,(Trk::ParamDefs)i);
350  }
352  for(int i=0; i<m_nParameters; i++) {
353  for(int j=i+1; j<m_nParameters; j++)
354  *m_cov[icov++] = m((Trk::ParamDefs)i,(Trk::ParamDefs)j);
355  }
356  }
357  assert (icov == m_cov.size());
358  }
359 
360  return StatusCode::SUCCESS;
361 }
362 
363 } // namespace D3PD
Trk::y
@ y
Definition: ParamDefs.h:56
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
D3PD::CovarianceFillerTool::m_writeError
bool m_writeError
parameters
Definition: CovarianceFillerTool.h:65
Trk::z
@ z
global position (cartesian)
Definition: ParamDefs.h:57
D3PD::CovarianceFillerTool::m_err
std::vector< float * > m_err
Variables: uncertainty.
Definition: CovarianceFillerTool.h:73
Trk::ParamDefs
ParamDefs
Definition: ParamDefs.h:32
EventPrimitivesHelpers.h
D3PD::CovarianceFillerTool::m_writeOffDiagCovariance
bool m_writeOffDiagCovariance
Definition: CovarianceFillerTool.h:67
Trk::z0
@ z0
Definition: ParamDefs.h:64
D3PD::AddVariable::addVariable
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
Add a variable to the tuple.
Definition: AddVariable.cxx:85
D3PD::CovarianceFillerTool::book
virtual StatusCode book()
Book variables for this block.
Definition: CovarianceFillerTool.cxx:49
ParamDefs.h
D3PD::Types
std::tuple< WrapType< TYPES >... > Types
A simple tuple of multiple types.
Definition: PhysicsAnalysis/D3PDMaker/D3PDMakerUtils/D3PDMakerUtils/Types.h:61
D3PD::CovarianceFillerTool::CovarianceFillerTool
CovarianceFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: CovarianceFillerTool.cxx:32
D3PD::AmgSymMatrix
const AmgSymMatrix(5) *PerigeeCovarianceAssociationTool
Return the target object.
Definition: PerigeeCovarianceAssociationTool.cxx:43
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::theta
@ theta
Definition: ParamDefs.h:66
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
D3PD::BlockFillerTool
Type-safe wrapper for block filler tools.
Definition: BlockFillerTool.h:68
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
CovarianceFillerTool.h
Block filler tool for error and covariance matrix.
D3PD::CovarianceFillerTool::m_nParameters
int m_nParameters
Definition: CovarianceFillerTool.h:70
Amg
Definition of ATLAS Math & Geometry primitives (Amg)
Definition: AmgStringHelpers.h:19
D3PD::CovarianceFillerTool::m_writeDiagCovariance
bool m_writeDiagCovariance
Definition: CovarianceFillerTool.h:66
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Trk::d0
@ d0
Definition: ParamDefs.h:63
Amg::error
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Definition: EventPrimitivesHelpers.h:40
errorcheck.h
Helpers for checking error return status codes and reporting errors.
D3PD::CovarianceFillerTool::m_cov
std::vector< float * > m_cov
Variables: covariance matrix.
Definition: CovarianceFillerTool.h:76
D3PD::CovarianceFillerTool::fill
virtual StatusCode fill(const AmgSymMatrix(5) &p)
Fill one block — type-safe version.
Definition: CovarianceFillerTool.cxx:169
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
D3PD::CovarianceFillerTool::m_isTrackPerigee
bool m_isTrackPerigee
Definition: CovarianceFillerTool.h:69
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:67
str
Definition: BTagTrackIpAccessor.cxx:11
D3PD::CovarianceFillerTool::m_isPosition
bool m_isPosition
Definition: CovarianceFillerTool.h:68
Trk::x
@ x
Definition: ParamDefs.h:55
Trk::phi0
@ phi0
Definition: ParamDefs.h:65