ATLAS Offline Software
InDetTrackBiasingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <math.h>
8 
10 
11 #include <TH2.h>
12 #include <TFile.h>
13 
14 namespace {
16 }
17 
18 namespace InDet {
19 
21  {
25  };
26 
27  InDetTrackBiasingTool::InDetTrackBiasingTool(const std::string& name) :
28  InDetTrackSystematicsTool(name)
29  {
30 
31 #ifndef XAOD_STANDALONE
32  declareInterface<IInDetTrackBiasingTool>(this);
33 #endif
34 
35  declareProperty("biasD0", m_biasD0);
36  declareProperty("biasZ0", m_biasZ0);
37  declareProperty("biasQoverPsagitta", m_biasQoverPsagitta);
38  declareProperty("runNumber", m_runNumber);
39  declareProperty("isData", m_isData);
40  declareProperty("isSimulation", m_isSimulation);
41 
42  declareProperty("calibFileData15", m_calibFileData15 = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2015.root");
43  declareProperty("calibFileData16_1stPart", m_calibFileData16_1stPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2016_1stPart.root");
44  declareProperty("calibFileData16_2ndPart", m_calibFileData16_2ndPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2016_2ndPart.root");
45  declareProperty("calibFileData17_1stPart", m_calibFileData17_1stPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2017_1stPart.root");
46  declareProperty("calibFileData17_2ndPart", m_calibFileData17_2ndPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2017_2ndPart.root");
47  declareProperty("calibFileData18_1stPart", m_calibFileData18_1stPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2018_1stPart.root");
48  declareProperty("calibFileData18_2stPart", m_calibFileData18_2ndPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2018_2ndPart.root");
49 
50 
51  }
52 
54  {
55 
56  if (m_isData && m_isSimulation) {
57  ATH_MSG_ERROR( "Cannot manually set for both data and simulation!" );
58  return StatusCode::FAILURE;
59  }
60 
61  if (m_biasD0 != 0.) {
62  ATH_MSG_INFO( "overall d0 bias added = " << m_biasD0
63  << " mm (not part of an official recommendation)" );
64  }
65  if (m_biasZ0 != 0.) {
66  ATH_MSG_INFO( "overall z0 bias added = " << m_biasZ0
67  << " mm (not part of an official recommendation)" );
68  }
69  if (m_biasQoverPsagitta != 0.) {
70  ATH_MSG_INFO( "overall QoverP sagitta bias added = " << m_biasQoverPsagitta
71  << " TeV^-1 (not part of an official recommendation)" );
72  }
73 
74  if (m_runNumber > 0) {
75  ATH_MSG_WARNING( "Using manually-set run number (" << m_runNumber << ") to determine which calibration file to use." );
76  }
77 
78  ATH_CHECK( initHistograms() );
79 
81 
82  return StatusCode::SUCCESS;
83  }
84 
85  InDetTrackBiasingTool::~InDetTrackBiasingTool() {
86  m_runNumber = -1;
87  }
88 
89  CP::CorrectionCode InDetTrackBiasingTool::applyCorrection(xAOD::TrackParticle& track) {
90 
91  [[maybe_unused]] static const bool firstTime = [&]() {
92  if ( ! firstCall().isSuccess() ) { // this will check data vs. MC and run number.
93  throw std::runtime_error("Error calling InDetTrackBiasingTool::firstCall");
94  }
95  return false;
96  }();
97 
98  // specific histograms to be used based on the run number
99  TH2* biasD0Histogram = nullptr;
100  TH2* biasZ0Histogram = nullptr;
101  TH2* biasQoverPsagittaHistogram = nullptr;
102  TH2* biasD0HistError = nullptr;
103  TH2* biasZ0HistError = nullptr;
104  TH2* biasQoverPsagittaHistError = nullptr;
105 
106  // determine which run number to use
107  const xAOD::EventInfo* eventInfo = evtStore()->retrieve<const xAOD::EventInfo>("EventInfo");
108  if (!eventInfo) {
109  ATH_MSG_ERROR("Could not retrieve EventInfo object!");
111  }
112  auto runNumber = eventInfo->runNumber(); // start with run number stored in event info
113  static const SG::AuxElement::Accessor<unsigned int> randomRunNumber("RandomRunNumber");
114  if (m_runNumber > 0) { // if manually-set run number is provided, use it
115  runNumber = m_runNumber;
116  } else if (m_isSimulation && randomRunNumber.isAvailable(*eventInfo)) { // use RandomRunNumber for simulation if available
117  runNumber = randomRunNumber(*(eventInfo));
118  }
119 
120  // figure out which "IOV" the run number corresponds to
121  // TODO: replace StatusCodes with CP::CorrectionCodes
122  if (runNumber <= 0) {
123  ATH_MSG_WARNING( "Run number not set." );
124  }
125  if (runNumber >= 286282 && runNumber <= 287931) {
126  ATH_MSG_INFO( "Calibrating for 2015 HI and 5 TeV pp runs (286282 to 287931)." );
127  ATH_MSG_ERROR( "The 5 TeV and heavy ion runs do not have biasing maps for release 22. "
128  "Contact the tracking CP group to discuss the derivation of these maps." );
130  } else if (runNumber <= 364485) {
131  if (runNumber < 296939) { // data15 (before 296939)
132  biasD0Histogram = m_data15_biasD0Histogram.get();
133  biasZ0Histogram = m_data15_biasZ0Histogram.get();
134  biasQoverPsagittaHistogram = m_data15_biasQoverPsagittaHistogram.get();
135  biasD0HistError = m_data15_biasD0HistError.get();
136  biasZ0HistError = m_data15_biasZ0HistError.get();
137  biasQoverPsagittaHistError = m_data15_biasQoverPsagittaHistError.get();
138  } else if (runNumber <= 301912) { // data16 part 1/2 (296939 to 301912)
139  biasD0Histogram = m_data16_1stPart_biasD0Histogram.get();
140  biasZ0Histogram = m_data16_1stPart_biasZ0Histogram.get();
141  biasQoverPsagittaHistogram = m_data16_1stPart_biasQoverPsagittaHistogram.get();
142  biasD0HistError = m_data16_1stPart_biasD0HistError.get();
143  biasZ0HistError = m_data16_1stPart_biasZ0HistError.get();
144  biasQoverPsagittaHistError = m_data16_1stPart_biasQoverPsagittaHistError.get();
145  } else if (runNumber <= 312649) { // data16 part 2/2 (301912 to 312649)
146  biasD0Histogram = m_data16_2ndPart_biasD0Histogram.get();
147  biasZ0Histogram = m_data16_2ndPart_biasZ0Histogram.get();
148  biasQoverPsagittaHistogram = m_data16_2ndPart_biasQoverPsagittaHistogram.get();
149  biasD0HistError = m_data16_2ndPart_biasD0HistError.get();
150  biasZ0HistError = m_data16_2ndPart_biasZ0HistError.get();
151  biasQoverPsagittaHistError = m_data16_2ndPart_biasQoverPsagittaHistError.get();
152  } else if (runNumber <= 334842) { // data17 part 1/2 (324320 to 334842)
153  biasD0Histogram = m_data17_1stPart_biasD0Histogram.get();
154  biasZ0Histogram = m_data17_1stPart_biasZ0Histogram.get();
155  biasQoverPsagittaHistogram = m_data17_1stPart_biasQoverPsagittaHistogram.get();
156  biasD0HistError = m_data17_1stPart_biasD0HistError.get();
157  biasZ0HistError = m_data17_1stPart_biasZ0HistError.get();
158  biasQoverPsagittaHistError = m_data17_1stPart_biasQoverPsagittaHistError.get();
159  } else if (runNumber <= 348197) { // data17 (part 2/2 (334842 to 348197)
160  biasD0Histogram = m_data17_2ndPart_biasD0Histogram.get();
161  biasZ0Histogram = m_data17_2ndPart_biasZ0Histogram.get();
162  biasQoverPsagittaHistogram = m_data17_2ndPart_biasQoverPsagittaHistogram.get();
163  biasD0HistError = m_data17_2ndPart_biasD0HistError.get();
164  biasZ0HistError = m_data17_2ndPart_biasZ0HistError.get();
165  biasQoverPsagittaHistError = m_data17_2ndPart_biasQoverPsagittaHistError.get();
166  } else if (runNumber <= 353000) { // data18 (part 1/2 (348197 to 353000)
167  biasD0Histogram = m_data18_1stPart_biasD0Histogram.get();
168  biasZ0Histogram = m_data18_1stPart_biasZ0Histogram.get();
169  biasQoverPsagittaHistogram = m_data18_1stPart_biasQoverPsagittaHistogram.get();
170  biasD0HistError = m_data18_1stPart_biasD0HistError.get();
171  biasZ0HistError = m_data18_1stPart_biasZ0HistError.get();
172  biasQoverPsagittaHistError = m_data18_1stPart_biasQoverPsagittaHistError.get();
173  } else { // data18 (part 2/2 (353000 to 364485)
174  biasD0Histogram = m_data18_2ndPart_biasD0Histogram.get();
175  biasZ0Histogram = m_data18_2ndPart_biasZ0Histogram.get();
176  biasQoverPsagittaHistogram = m_data18_2ndPart_biasQoverPsagittaHistogram.get();
177  biasD0HistError = m_data18_2ndPart_biasD0HistError.get();
178  biasZ0HistError = m_data18_2ndPart_biasZ0HistError.get();
179  biasQoverPsagittaHistError = m_data18_2ndPart_biasQoverPsagittaHistError.get();
180  }
181  } else {
182  ATH_MSG_ERROR( "Run number = " << runNumber << " not in recognized range (< 364485)." );
184  }
185 
186  // don't do the biasing if the histograms are null
187  m_doD0Bias = biasD0Histogram != nullptr;
188  m_doZ0Bias = biasZ0Histogram != nullptr;
189  m_doQoverPBias = biasQoverPsagittaHistogram != nullptr;
190 
191  if (!m_doD0Bias) ATH_MSG_WARNING( "Will not perform d0 bias." );
192  if (!m_doZ0Bias) ATH_MSG_WARNING( "Will not perform z0 bias." );
193  if (!m_doQoverPBias) ATH_MSG_WARNING( "Will not perform q/p sagitta bias." );
194 
195  // declare static accessors to avoid repeating string lookups
196  static const SG::AuxElement::Accessor< float > accD0( "d0" );
197  static const SG::AuxElement::Accessor< float > accZ0( "z0" );
198  static const SG::AuxElement::Accessor< float > accQOverP( "qOverP" );
199 
200  const float phi = track.phi0();
201  const float eta = track.eta();
202 
203  // do the biasing
204  if ( m_doD0Bias ) {
205  bool d0WmActive = isActive( TRK_BIAS_D0_WM );
206  if ( m_isData || d0WmActive ) {
207  accD0( track ) += readHistogram(m_biasD0, biasD0Histogram, phi, eta);
208  if ( m_isData && d0WmActive ) {
209  accD0( track ) += readHistogram(0., biasD0HistError, phi, eta);
210  }
211  }
212  }
213  if ( m_doZ0Bias ) {
214  bool z0WmActive = isActive( TRK_BIAS_Z0_WM );
215  if ( m_isData || z0WmActive ) {
216  accZ0( track ) += readHistogram(m_biasZ0, biasZ0Histogram, phi, eta);
217  if ( m_isData && z0WmActive ) {
218  accZ0( track ) += readHistogram(0., biasZ0HistError, phi, eta);
219  }
220  }
221  }
222  if ( m_doQoverPBias ) {
223  bool qOverPWmActive = isActive( TRK_BIAS_QOVERP_SAGITTA_WM );
224  if ( m_isData || qOverPWmActive ) {
225  auto sinTheta = 1.0/cosh(eta);
226  // readHistogram flips the sign of the correction if m_isSimulation is true
227  accQOverP( track ) += 1.e-6*sinTheta*readHistogram(m_biasQoverPsagitta, biasQoverPsagittaHistogram, phi, eta);
228  if ( m_isData && qOverPWmActive ) {
229  accQOverP( track ) += 1.e-6*sinTheta*readHistogram(0., biasQoverPsagittaHistError, phi, eta);
230  }
231  }
232  }
233 
234  return CP::CorrectionCode::Ok;
235  }
236 
237  StatusCode InDetTrackBiasingTool::initHistograms()
238  {
239 
240  TH2* data15_biasD0Histogram_tmp = nullptr;
241  TH2* data15_biasZ0Histogram_tmp = nullptr;
242  TH2* data15_biasQoverPsagittaHistogram_tmp = nullptr;
243  TH2* data15_biasD0HistError_tmp = nullptr;
244  TH2* data15_biasZ0HistError_tmp = nullptr;
245  TH2* data15_biasQoverPsagittaHistError_tmp = nullptr;
246 
247  TH2* data16_1stPart_biasD0Histogram_tmp = nullptr;
248  TH2* data16_1stPart_biasZ0Histogram_tmp = nullptr;
249  TH2* data16_1stPart_biasQoverPsagittaHistogram_tmp = nullptr;
250  TH2* data16_1stPart_biasD0HistError_tmp = nullptr;
251  TH2* data16_1stPart_biasZ0HistError_tmp = nullptr;
252  TH2* data16_1stPart_biasQoverPsagittaHistError_tmp = nullptr;
253 
254  TH2* data16_2ndPart_biasD0Histogram_tmp = nullptr;
255  TH2* data16_2ndPart_biasZ0Histogram_tmp = nullptr;
256  TH2* data16_2ndPart_biasQoverPsagittaHistogram_tmp = nullptr;
257  TH2* data16_2ndPart_biasD0HistError_tmp = nullptr;
258  TH2* data16_2ndPart_biasZ0HistError_tmp = nullptr;
259  TH2* data16_2ndPart_biasQoverPsagittaHistError_tmp = nullptr;
260 
261  TH2* data17_1stPart_biasD0Histogram_tmp = nullptr;
262  TH2* data17_1stPart_biasZ0Histogram_tmp = nullptr;
263  TH2* data17_1stPart_biasQoverPsagittaHistogram_tmp = nullptr;
264  TH2* data17_1stPart_biasD0HistError_tmp = nullptr;
265  TH2* data17_1stPart_biasZ0HistError_tmp = nullptr;
266  TH2* data17_1stPart_biasQoverPsagittaHistError_tmp = nullptr;
267 
268  TH2* data17_2ndPart_biasD0Histogram_tmp = nullptr;
269  TH2* data17_2ndPart_biasZ0Histogram_tmp = nullptr;
270  TH2* data17_2ndPart_biasQoverPsagittaHistogram_tmp = nullptr;
271  TH2* data17_2ndPart_biasD0HistError_tmp = nullptr;
272  TH2* data17_2ndPart_biasZ0HistError_tmp = nullptr;
273  TH2* data17_2ndPart_biasQoverPsagittaHistError_tmp = nullptr;
274 
275  TH2* data18_1stPart_biasD0Histogram_tmp = nullptr;
276  TH2* data18_1stPart_biasZ0Histogram_tmp = nullptr;
277  TH2* data18_1stPart_biasQoverPsagittaHistogram_tmp = nullptr;
278  TH2* data18_1stPart_biasD0HistError_tmp = nullptr;
279  TH2* data18_1stPart_biasZ0HistError_tmp = nullptr;
280  TH2* data18_1stPart_biasQoverPsagittaHistError_tmp = nullptr;
281 
282  TH2* data18_2ndPart_biasD0Histogram_tmp = nullptr;
283  TH2* data18_2ndPart_biasZ0Histogram_tmp = nullptr;
284  TH2* data18_2ndPart_biasQoverPsagittaHistogram_tmp = nullptr;
285  TH2* data18_2ndPart_biasD0HistError_tmp = nullptr;
286  TH2* data18_2ndPart_biasZ0HistError_tmp = nullptr;
287  TH2* data18_2ndPart_biasQoverPsagittaHistError_tmp = nullptr;
288 
289  ATH_MSG_INFO( "Using for data15 (before 296939) the calibration file " << PathResolverFindCalibFile(m_calibFileData15) );
290  ATH_CHECK ( initObject<TH2>(data15_biasD0Histogram_tmp, m_calibFileData15, m_d0_nominal_histName) );
291  ATH_CHECK ( initObject<TH2>(data15_biasZ0Histogram_tmp, m_calibFileData15, m_z0_nominal_histName) );
292  ATH_CHECK ( initObject<TH2>(data15_biasQoverPsagittaHistogram_tmp, m_calibFileData15, m_sagitta_nominal_histName) );
293  ATH_CHECK ( initObject<TH2>(data15_biasD0HistError_tmp, m_calibFileData15, m_d0_uncertainty_histName) );
294  ATH_CHECK ( initObject<TH2>(data15_biasZ0HistError_tmp, m_calibFileData15, m_z0_uncertainty_histName) );
295  ATH_CHECK ( initObject<TH2>(data15_biasQoverPsagittaHistError_tmp, m_calibFileData15, m_sagitta_uncertainty_histName) );
296 
297  ATH_MSG_INFO( "Using for data16 part 1/2 (296939 to 301912) the calibration file " << PathResolverFindCalibFile(m_calibFileData16_1stPart) );
298  ATH_CHECK ( initObject<TH2>(data16_1stPart_biasD0Histogram_tmp, m_calibFileData16_1stPart, m_d0_nominal_histName) );
299  ATH_CHECK ( initObject<TH2>(data16_1stPart_biasZ0Histogram_tmp, m_calibFileData16_1stPart, m_z0_nominal_histName) );
300  ATH_CHECK ( initObject<TH2>(data16_1stPart_biasQoverPsagittaHistogram_tmp, m_calibFileData16_1stPart, m_sagitta_nominal_histName) );
301  ATH_CHECK ( initObject<TH2>(data16_1stPart_biasD0HistError_tmp, m_calibFileData16_1stPart, m_d0_uncertainty_histName) );
302  ATH_CHECK ( initObject<TH2>(data16_1stPart_biasZ0HistError_tmp, m_calibFileData16_1stPart, m_z0_uncertainty_histName) );
303  ATH_CHECK ( initObject<TH2>(data16_1stPart_biasQoverPsagittaHistError_tmp, m_calibFileData16_1stPart, m_sagitta_uncertainty_histName) );
304 
305  ATH_MSG_INFO( "Using for data16 part 2/2 (301912 to 312649) the calibration file " << PathResolverFindCalibFile(m_calibFileData16_2ndPart) );
306  ATH_CHECK ( initObject<TH2>(data16_2ndPart_biasD0Histogram_tmp, m_calibFileData16_2ndPart, m_d0_nominal_histName) );
307  ATH_CHECK ( initObject<TH2>(data16_2ndPart_biasZ0Histogram_tmp, m_calibFileData16_2ndPart, m_z0_nominal_histName) );
308  ATH_CHECK ( initObject<TH2>(data16_2ndPart_biasQoverPsagittaHistogram_tmp, m_calibFileData16_2ndPart, m_sagitta_nominal_histName) );
309  ATH_CHECK ( initObject<TH2>(data16_2ndPart_biasD0HistError_tmp, m_calibFileData16_2ndPart, m_d0_uncertainty_histName) );
310  ATH_CHECK ( initObject<TH2>(data16_2ndPart_biasZ0HistError_tmp, m_calibFileData16_2ndPart, m_z0_uncertainty_histName) );
311  ATH_CHECK ( initObject<TH2>(data16_2ndPart_biasQoverPsagittaHistError_tmp, m_calibFileData16_2ndPart, m_sagitta_uncertainty_histName) );
312 
313  ATH_MSG_INFO( "Using for data17 part 1/2 (324320 to 334842) the calibration file " << PathResolverFindCalibFile(m_calibFileData17_1stPart) );
314  ATH_CHECK ( initObject<TH2>(data17_1stPart_biasD0Histogram_tmp, m_calibFileData17_1stPart, m_d0_nominal_histName) );
315  ATH_CHECK ( initObject<TH2>(data17_1stPart_biasZ0Histogram_tmp, m_calibFileData17_1stPart, m_z0_nominal_histName) );
316  ATH_CHECK ( initObject<TH2>(data17_1stPart_biasQoverPsagittaHistogram_tmp, m_calibFileData17_1stPart, m_sagitta_nominal_histName) );
317  ATH_CHECK ( initObject<TH2>(data17_1stPart_biasD0HistError_tmp, m_calibFileData17_1stPart, m_d0_uncertainty_histName) );
318  ATH_CHECK ( initObject<TH2>(data17_1stPart_biasZ0HistError_tmp, m_calibFileData17_1stPart, m_z0_uncertainty_histName) );
319  ATH_CHECK ( initObject<TH2>(data17_1stPart_biasQoverPsagittaHistError_tmp, m_calibFileData17_1stPart, m_sagitta_uncertainty_histName) );
320 
321  ATH_MSG_INFO( "Using for data17 (part 2/2 (334842 to 348197) the calibration file " << PathResolverFindCalibFile(m_calibFileData17_2ndPart) );
322  ATH_CHECK ( initObject<TH2>(data17_2ndPart_biasD0Histogram_tmp, m_calibFileData17_2ndPart, m_d0_nominal_histName) );
323  ATH_CHECK ( initObject<TH2>(data17_2ndPart_biasZ0Histogram_tmp, m_calibFileData17_2ndPart, m_z0_nominal_histName) );
324  ATH_CHECK ( initObject<TH2>(data17_2ndPart_biasQoverPsagittaHistogram_tmp, m_calibFileData17_2ndPart, m_sagitta_nominal_histName) );
325  ATH_CHECK ( initObject<TH2>(data17_2ndPart_biasD0HistError_tmp, m_calibFileData17_2ndPart, m_d0_uncertainty_histName) );
326  ATH_CHECK ( initObject<TH2>(data17_2ndPart_biasZ0HistError_tmp, m_calibFileData17_2ndPart, m_z0_uncertainty_histName) );
327  ATH_CHECK ( initObject<TH2>(data17_2ndPart_biasQoverPsagittaHistError_tmp, m_calibFileData17_2ndPart, m_sagitta_uncertainty_histName) );
328 
329  ATH_MSG_INFO( "Using for data18 (part 1/2 (348197 to 353000) the calibration file " << PathResolverFindCalibFile(m_calibFileData18_1stPart) );
330  ATH_CHECK ( initObject<TH2>(data18_1stPart_biasD0Histogram_tmp, m_calibFileData18_1stPart, m_d0_nominal_histName) );
331  ATH_CHECK ( initObject<TH2>(data18_1stPart_biasZ0Histogram_tmp, m_calibFileData18_1stPart, m_z0_nominal_histName) );
332  ATH_CHECK ( initObject<TH2>(data18_1stPart_biasQoverPsagittaHistogram_tmp, m_calibFileData18_1stPart, m_sagitta_nominal_histName) );
333  ATH_CHECK ( initObject<TH2>(data18_1stPart_biasD0HistError_tmp, m_calibFileData18_1stPart, m_d0_uncertainty_histName) );
334  ATH_CHECK ( initObject<TH2>(data18_1stPart_biasZ0HistError_tmp, m_calibFileData18_1stPart, m_z0_uncertainty_histName) );
335  ATH_CHECK ( initObject<TH2>(data18_1stPart_biasQoverPsagittaHistError_tmp, m_calibFileData18_1stPart, m_sagitta_uncertainty_histName) );
336 
337  ATH_MSG_INFO( "Using for data18 (part 2/2 (353000 to 364485) the calibration file " << PathResolverFindCalibFile(m_calibFileData18_2ndPart) );
338  ATH_CHECK ( initObject<TH2>(data18_2ndPart_biasD0Histogram_tmp, m_calibFileData18_2ndPart, m_d0_nominal_histName) );
339  ATH_CHECK ( initObject<TH2>(data18_2ndPart_biasZ0Histogram_tmp, m_calibFileData18_2ndPart, m_z0_nominal_histName) );
340  ATH_CHECK ( initObject<TH2>(data18_2ndPart_biasQoverPsagittaHistogram_tmp, m_calibFileData18_2ndPart, m_sagitta_nominal_histName) );
341  ATH_CHECK ( initObject<TH2>(data18_2ndPart_biasD0HistError_tmp, m_calibFileData18_2ndPart, m_d0_uncertainty_histName) );
342  ATH_CHECK ( initObject<TH2>(data18_2ndPart_biasZ0HistError_tmp, m_calibFileData18_2ndPart, m_z0_uncertainty_histName) );
343  ATH_CHECK ( initObject<TH2>(data18_2ndPart_biasQoverPsagittaHistError_tmp, m_calibFileData18_2ndPart, m_sagitta_uncertainty_histName) );
344 
345  // m_trkLRTEff = std::unique_ptr<TH2>(trkLRTEff_tmp);
346 
347  m_data15_biasD0Histogram = std::unique_ptr<TH2>(data15_biasD0Histogram_tmp);
348  m_data15_biasZ0Histogram = std::unique_ptr<TH2>(data15_biasZ0Histogram_tmp);
349  m_data15_biasQoverPsagittaHistogram = std::unique_ptr<TH2>(data15_biasQoverPsagittaHistogram_tmp);
350  m_data15_biasD0HistError = std::unique_ptr<TH2>(data15_biasD0HistError_tmp);
351  m_data15_biasZ0HistError = std::unique_ptr<TH2>(data15_biasZ0HistError_tmp);
352  m_data15_biasQoverPsagittaHistError = std::unique_ptr<TH2>(data15_biasQoverPsagittaHistError_tmp);
353 
354  m_data16_1stPart_biasD0Histogram = std::unique_ptr<TH2>(data16_1stPart_biasD0Histogram_tmp);
355  m_data16_1stPart_biasZ0Histogram = std::unique_ptr<TH2>(data16_1stPart_biasZ0Histogram_tmp);
356  m_data16_1stPart_biasQoverPsagittaHistogram = std::unique_ptr<TH2>(data16_1stPart_biasQoverPsagittaHistogram_tmp);
357  m_data16_1stPart_biasD0HistError = std::unique_ptr<TH2>(data16_1stPart_biasD0HistError_tmp);
358  m_data16_1stPart_biasZ0HistError = std::unique_ptr<TH2>(data16_1stPart_biasZ0HistError_tmp);
359  m_data16_1stPart_biasQoverPsagittaHistError = std::unique_ptr<TH2>(data16_1stPart_biasQoverPsagittaHistError_tmp);
360 
361  m_data16_2ndPart_biasD0Histogram = std::unique_ptr<TH2>(data16_2ndPart_biasD0Histogram_tmp);
362  m_data16_2ndPart_biasZ0Histogram = std::unique_ptr<TH2>(data16_2ndPart_biasZ0Histogram_tmp);
363  m_data16_2ndPart_biasQoverPsagittaHistogram = std::unique_ptr<TH2>(data16_2ndPart_biasQoverPsagittaHistogram_tmp);
364  m_data16_2ndPart_biasD0HistError = std::unique_ptr<TH2>(data16_2ndPart_biasD0HistError_tmp);
365  m_data16_2ndPart_biasZ0HistError = std::unique_ptr<TH2>(data16_2ndPart_biasZ0HistError_tmp);
366  m_data16_2ndPart_biasQoverPsagittaHistError = std::unique_ptr<TH2>(data16_2ndPart_biasQoverPsagittaHistError_tmp);
367 
368  m_data17_1stPart_biasD0Histogram = std::unique_ptr<TH2>(data17_1stPart_biasD0Histogram_tmp);
369  m_data17_1stPart_biasZ0Histogram = std::unique_ptr<TH2>(data17_1stPart_biasZ0Histogram_tmp);
370  m_data17_1stPart_biasQoverPsagittaHistogram = std::unique_ptr<TH2>(data17_1stPart_biasQoverPsagittaHistogram_tmp);
371  m_data17_1stPart_biasD0HistError = std::unique_ptr<TH2>(data17_1stPart_biasD0HistError_tmp);
372  m_data17_1stPart_biasZ0HistError = std::unique_ptr<TH2>(data17_1stPart_biasZ0HistError_tmp);
373  m_data17_1stPart_biasQoverPsagittaHistError = std::unique_ptr<TH2>(data17_1stPart_biasQoverPsagittaHistError_tmp);
374 
375  m_data17_2ndPart_biasD0Histogram = std::unique_ptr<TH2>(data17_2ndPart_biasD0Histogram_tmp);
376  m_data17_2ndPart_biasZ0Histogram = std::unique_ptr<TH2>(data17_2ndPart_biasZ0Histogram_tmp);
377  m_data17_2ndPart_biasQoverPsagittaHistogram = std::unique_ptr<TH2>(data17_2ndPart_biasQoverPsagittaHistogram_tmp);
378  m_data17_2ndPart_biasD0HistError = std::unique_ptr<TH2>(data17_2ndPart_biasD0HistError_tmp);
379  m_data17_2ndPart_biasZ0HistError = std::unique_ptr<TH2>(data17_2ndPart_biasZ0HistError_tmp);
380  m_data17_2ndPart_biasQoverPsagittaHistError = std::unique_ptr<TH2>(data17_2ndPart_biasQoverPsagittaHistError_tmp);
381 
382  m_data18_1stPart_biasD0Histogram = std::unique_ptr<TH2>(data18_1stPart_biasD0Histogram_tmp);
383  m_data18_1stPart_biasZ0Histogram = std::unique_ptr<TH2>(data18_1stPart_biasZ0Histogram_tmp);
384  m_data18_1stPart_biasQoverPsagittaHistogram = std::unique_ptr<TH2>(data18_1stPart_biasQoverPsagittaHistogram_tmp);
385  m_data18_1stPart_biasD0HistError = std::unique_ptr<TH2>(data18_1stPart_biasD0HistError_tmp);
386  m_data18_1stPart_biasZ0HistError = std::unique_ptr<TH2>(data18_1stPart_biasZ0HistError_tmp);
387  m_data18_1stPart_biasQoverPsagittaHistError = std::unique_ptr<TH2>(data18_1stPart_biasQoverPsagittaHistError_tmp);
388 
389  m_data18_2ndPart_biasD0Histogram = std::unique_ptr<TH2>(data18_2ndPart_biasD0Histogram_tmp);
390  m_data18_2ndPart_biasZ0Histogram = std::unique_ptr<TH2>(data18_2ndPart_biasZ0Histogram_tmp);
391  m_data18_2ndPart_biasQoverPsagittaHistogram = std::unique_ptr<TH2>(data18_2ndPart_biasQoverPsagittaHistogram_tmp);
392  m_data18_2ndPart_biasD0HistError = std::unique_ptr<TH2>(data18_2ndPart_biasD0HistError_tmp);
393  m_data18_2ndPart_biasZ0HistError = std::unique_ptr<TH2>(data18_2ndPart_biasZ0HistError_tmp);
394  m_data18_2ndPart_biasQoverPsagittaHistError = std::unique_ptr<TH2>(data18_2ndPart_biasQoverPsagittaHistError_tmp);
395 
396  return StatusCode::SUCCESS;
397  }
398 
399  StatusCode InDetTrackBiasingTool::firstCall()
400  {
401  assert( ! (m_isData && m_isSimulation) );
402 
403  const xAOD::EventInfo* ei = nullptr;
404  auto sc = evtStore()->retrieve( ei, "EventInfo" );
405  if ( ! sc.isSuccess() ) {
406  if (m_runNumber <= 0 || !(m_isData||m_isSimulation)) {
407  ATH_MSG_ERROR( "Unable to retrieve from event store. Manually set data/simulation and/or run number." );
408  return StatusCode::FAILURE;
409  }
410  }
411  bool isSim = ei->eventType( xAOD::EventInfo::IS_SIMULATION );
412  if (isSim) {
413  if ( m_isData ) {
414  ATH_MSG_WARNING( "Manually set to data setting, but the type is detected as simulation." );
415  ATH_MSG_WARNING( "Ensure that this behaviour is desired." );
416  } else {
417  m_isSimulation = true;
418  }
419  } else {
420  if ( m_isSimulation ) {
421  ATH_MSG_WARNING( "Manually set to simulation setting, but the type is detected as data." );
422  ATH_MSG_WARNING( "Ensure that this behaviour is desired." );
423  } else {
424  m_isData = true;
425  }
426  }
427  assert( m_isData != m_isSimulation ); // one must be true and the other false
428  if (m_isData) ATH_MSG_INFO( "Set to data. Will apply biases to correct those observed in data." );
429  if (m_isSimulation) ATH_MSG_INFO( "Set to simulation. Will apply biases in direction that is observed in data." );
430 
431  // warn if set to simulation but RandomRunNumber not found and no run number provided (will use run number set in event info)
432  static const SG::AuxElement::Accessor<unsigned int> randomRunNumber("RandomRunNumber");
433  if (m_isSimulation && !randomRunNumber.isAvailable(*ei) && m_runNumber <= 0) {
434  ATH_MSG_WARNING("Set to simulation with no run number provided, but RandomRunNumber not available. Will use default run number from EventInfo, "
435  "but biasing won't accurately reflect intervals of validity throughout the year. Run PileupReweightingTool first to pick up RandomRunNumber decorations.");
436  }
437  return StatusCode::SUCCESS;
438  }
439 
440  float InDetTrackBiasingTool::readHistogram(float fDefault, TH2* histogram, float phi, float eta) const {
441  if (histogram == nullptr) {
442  ATH_MSG_ERROR( "Configuration histogram is invalid. Check the run number and systematic configuration combination.");
443  throw std::runtime_error( "invalid configuration" );
444  }
445 
446  // safety measure:
447  if( eta>2.499 ) eta= 2.499;
448  if( eta<-2.499 ) eta=-2.499;
449 
450  // the sign assumes that we apply a correction opposite to what the maps give
451  float f = histogram->GetBinContent(histogram->FindBin(eta, phi));
452  if (m_isSimulation) f = -f;
453  f += fDefault; // should be zero unless a manual override is provided
454 
455  return f;
456  }
457 
458  CP::CorrectionCode InDetTrackBiasingTool::correctedCopy( const xAOD::TrackParticle& in,
460  {
461  return TrackCorrTool_t::correctedCopy(in, out);
462  }
463 
464  CP::CorrectionCode InDetTrackBiasingTool::applyContainerCorrection( xAOD::TrackParticleContainer& cont )
465  {
466  return TrackCorrTool_t::applyContainerCorrection(cont);
467  }
468 
469  bool InDetTrackBiasingTool::isAffectedBySystematic( const CP::SystematicVariation& syst ) const
470  {
471  return InDetTrackSystematicsTool::isAffectedBySystematic( syst );
472  }
473 
474  CP::SystematicSet InDetTrackBiasingTool::affectingSystematics() const
475  {
476  return BiasSystematics;
477  }
478 
479  CP::SystematicSet InDetTrackBiasingTool::recommendedSystematics() const
480  {
481  return InDetTrackSystematicsTool::recommendedSystematics();
482  }
483 
484  StatusCode InDetTrackBiasingTool::applySystematicVariation( const CP::SystematicSet& systs )
485  {
486  return InDetTrackSystematicsTool::applySystematicVariation(systs);
487  }
488 
489 
490 }
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::TRK_BIAS_QOVERP_SAGITTA_WM
@ TRK_BIAS_QOVERP_SAGITTA_WM
Definition: InDetTrackSystematics.h:27
initialize
void initialize()
Definition: run_EoverP.cxx:894
InDet::TRK_BIAS_D0_WM
@ TRK_BIAS_D0_WM
Definition: InDetTrackSystematics.h:25
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::SystematicVariation
Definition: SystematicVariation.h:47
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InDet::TrackSystematicMap
static const std::unordered_map< InDet::TrackSystematic, CP::SystematicVariation, std::hash< int > > TrackSystematicMap
Definition: InDetTrackSystematics.h:56
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:135
InDetTrackBiasingTool.h
InDet::TRK_BIAS_Z0_WM
@ TRK_BIAS_Z0_WM
Definition: InDetTrackSystematics.h:26
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CP::CorrectionTool< xAOD::TrackParticleContainer >
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
InDet::BiasSystematics
static const CP::SystematicSet BiasSystematics
Definition: InDetTrackBiasingTool.cxx:20
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
histogram
std::string histogram
Definition: chains.cxx:52
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.