Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
JetCalibrationTool.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // JetCalibrationTool.cxx
8 // Implementation file for class JetCalibrationTool
9 // Author: Joe Taenzer <joseph.taenzer@cern.ch>
11 
26 
28  : asg::AsgTool( name )
29 {
30  declareProperty( "JetCollection", m_jetAlgo = "AntiKt4LCTopo" );
31  declareProperty( "ConfigFile", m_config = "" );
32  declareProperty( "CalibSequence", m_calibSeq = "JetArea_Offset_AbsoluteEtaJES_Insitu" );
33  declareProperty( "IsData", m_isData = true );
34  declareProperty( "ConfigDir", m_dir = "JetCalibTools/CalibrationConfigs/" );
35  declareProperty( "EventInfoName", m_eInfoName = "EventInfo");
36  declareProperty( "DEVmode", m_devMode = false);
37  declareProperty( "OriginScale", m_originScale = "JetOriginConstitScaleMomentum");
38  declareProperty( "CalibArea", m_calibAreaTag = "00-04-82");
39  declareProperty( "GSCDepth", m_gscDepth);
40  declareProperty( "useOriginVertex", m_useOriginVertex = false);
41 }
42 
44  if(m_globalConfig) delete m_globalConfig;
45  for(TEnv* config : m_globalTimeDependentConfigs) delete config;
46  for(TEnv* config : m_globalInsituCombMassConfig) delete config;
47 }
48 
49 
51 // Public methods:
53 
55  ATH_MSG_INFO ("Initializing " << name() << " to calibrate " << m_jetAlgo << "jets");
56 
57  TString jetAlgo = m_jetAlgo;
58  TString calibSeq = m_calibSeq;
59  std::string dir = m_dir;
60 
61  //Make sure the necessary properties were set via the constructor or python configuration
62  if ( jetAlgo.EqualTo("") || calibSeq.EqualTo("") ) {
63  ATH_MSG_FATAL("JetCalibrationTool::initialize : At least one of your constructor arguments is not set. Did you use the copy constructor?");
64  return StatusCode::FAILURE;
65  }
66 
67  if ( m_config.empty() ) { ATH_MSG_FATAL("No configuration file specified."); return StatusCode::FAILURE; }
68  // The calibration area tag is a property of the tool
69  const std::string calibPath = "CalibArea-" + m_calibAreaTag + "/";
70  if(m_devMode){
71  ATH_MSG_WARNING("Dev Mode is ON!!!");
72  ATH_MSG_WARNING("Dev Mode is NOT RECOMMENDED!!!");
73  dir = "JetCalibTools/";
74  }
75  else{dir.insert(14,calibPath);} // Obtaining the path of the configuration file
76  std::string configPath=dir+m_config; // Full path
77  TString fn = PathResolverFindCalibFile(configPath);
78 
79  ATH_MSG_INFO("Reading global JES settings from: " << m_config);
80  ATH_MSG_INFO("resolved in: " << fn);
81 
82  m_globalConfig = new TEnv();
83  int status=m_globalConfig->ReadFile(fn ,EEnvLevel(0));
84  if (status!=0) { ATH_MSG_FATAL("Cannot read config file " << fn ); return StatusCode::FAILURE; }
85 
86  //Make sure that one of the standard jet collections is being used
87  if ( calibSeq.Contains("JetArea") ) {
88  if ( jetAlgo.Contains("PFlow") ) m_jetScale = PFLOW;
89  else if ( jetAlgo.Contains("EM") ) m_jetScale = EM;
90  else if ( jetAlgo.Contains("LC") ) m_jetScale = LC;
91  else { ATH_MSG_FATAL("jetAlgo " << jetAlgo << " not recognized."); return StatusCode::FAILURE; }
92  }
93 
94  // Settings for R21/2.5.X
95  m_originCorrectedClusters = m_globalConfig->GetValue("OriginCorrectedClusters",false);
96  m_doSetDetectorEta = m_globalConfig->GetValue("SetDetectorEta",true);
97 
98  // Rho key specified in the config file?
99  std::string rhoKey_config = m_globalConfig->GetValue("RhoKey", "None");
100 
101  bool requireRhoInput = false;
102 
103  //Make sure the residual correction is turned on if requested
104  if ( !calibSeq.Contains("JetArea") && !calibSeq.Contains("Residual") ) {
105  m_doJetArea = false;
106  m_doResidual = false;
107  } else if ( calibSeq.Contains("JetArea") ) {
108  if ( m_rhoKey.key().compare("auto") == 0 && rhoKey_config.compare("None") == 0) {
110  if ( m_jetScale == EM ) m_rhoKey = "Kt4EMTopoEventShape";
111  else if ( m_jetScale == LC ) m_rhoKey = "Kt4LCTopoEventShape";
112  else if ( m_jetScale == PFLOW ) m_rhoKey = "Kt4EMPFlowEventShape";
113  } else{
114  if ( m_jetScale == EM ) m_rhoKey = "Kt4EMTopoOriginEventShape";
115  else if ( m_jetScale == LC ) m_rhoKey = "Kt4LCTopoOriginEventShape";
116  else if ( m_jetScale == PFLOW ) m_rhoKey = "Kt4EMPFlowEventShape";
117  }
118  }
119  else if(rhoKey_config.compare("None") != 0 && m_rhoKey.key().compare("auto") == 0){
120  m_rhoKey = rhoKey_config;
121  }
122  requireRhoInput = true;
123  if ( !calibSeq.Contains("Residual") ) m_doResidual = false;
124  } else if ( !calibSeq.Contains("JetArea") && calibSeq.Contains("Residual") ) {
125  m_doJetArea = false;
126  ATH_MSG_INFO("ApplyOnlyResidual should be true if only Residual pile up correction wants to be applied. Need to specify pile up starting scale in the configuration file.");
127  }
128  // get nJet threshold and name
129  m_useNjetInResidual = m_globalConfig->GetValue("OffsetCorrection.UseNjet", false);
130  m_nJetThreshold = m_globalConfig->GetValue("OffsetCorrection.nJetThreshold", 20);
131  m_nJetContainerName = m_globalConfig->GetValue("OffsetCorrection.nJetContainerName",
132  "HLT_xAOD__JetContainer_a4tcemsubjesISFS");
133 
134  if ( !calibSeq.Contains("Origin") ) m_doOrigin = false;
135  if ( !calibSeq.Contains("GSC") && !calibSeq.Contains("GNNC")) m_doGSC = false;
136  if ( !calibSeq.Contains("Bcid") ) m_doBcid = false;
137  if ( calibSeq.Contains("DNN") ) m_doDNNCal = true;
138 
139  //Protect against the in-situ calibration being requested when isData is false
140  if ( calibSeq.Contains("Insitu") && !m_isData ) {
141  ATH_MSG_FATAL("JetCalibrationTool::initialize : calibSeq string contains Insitu with isData set to false. Can't apply in-situ correction to MC!!");
142  return StatusCode::FAILURE;
143  }
144 
145  // Time-Dependent Insitu Calibration
146  m_timeDependentCalib = m_globalConfig->GetValue("TimeDependentInsituCalibration",false);
147  if(m_timeDependentCalib && calibSeq.Contains("Insitu")){ // Read Insitu Configs
148  m_timeDependentInsituConfigs = JetCalibUtils::Vectorize( m_globalConfig->GetValue("InsituTimeDependentConfigs","") );
149  if(m_timeDependentInsituConfigs.empty()) ATH_MSG_ERROR("Please check there are at least two insitu configs");
150  m_runBins = JetCalibUtils::VectorizeD( m_globalConfig->GetValue("InsituRunBins","") );
151  if(m_runBins.size()!=m_timeDependentInsituConfigs.size()+1) ATH_MSG_ERROR("Please check the insitu run bins");
152  for(unsigned int i=0;i<m_timeDependentInsituConfigs.size();++i){
153 
154  std::string configPath_insitu = dir+m_timeDependentInsituConfigs.at(i).Data(); // Full path
155  TString fn_insitu = PathResolverFindCalibFile(configPath_insitu);
156 
157  ATH_MSG_INFO("Reading time-dependent insitu settings from: " << m_timeDependentInsituConfigs.at(i));
158  ATH_MSG_INFO("resolved in: " << fn_insitu);
159 
160  TEnv *globalConfig_insitu = new TEnv();
161  int status = globalConfig_insitu->ReadFile(fn_insitu ,EEnvLevel(0));
162  if (status!=0) { ATH_MSG_FATAL("Cannot read config file " << fn_insitu ); return StatusCode::FAILURE; }
163  m_globalTimeDependentConfigs.push_back(globalConfig_insitu);
164  }
165  }
166 
167  //Combined Mass Calibration:
168  m_insituCombMassCalib = m_globalConfig->GetValue("InsituCombinedMassCorrection",false);
169  if(m_insituCombMassCalib && calibSeq.Contains("InsituCombinedMass")){ // Read Combination Config
170  m_insituCombMassConfig = JetCalibUtils::Vectorize( m_globalConfig->GetValue("InsituCombinedMassCorrectionFile","") );
171  if(m_insituCombMassConfig.empty()) ATH_MSG_ERROR("Please check there is a combination config");
172  for(unsigned int i=0;i<m_insituCombMassConfig.size();++i){
173 
174  std::string configPath_comb = dir+m_insituCombMassConfig.at(i).Data(); // Full path
175  TString fn_comb = PathResolverFindCalibFile(configPath_comb);
176 
177  ATH_MSG_INFO("Reading combination settings from: " << m_insituCombMassConfig.at(i));
178  ATH_MSG_INFO("resolved in: " << fn_comb);
179 
180  TEnv *globalInsituCombMass = new TEnv();
181  int status = globalInsituCombMass->ReadFile(fn_comb ,EEnvLevel(0));
182  if (status!=0) { ATH_MSG_FATAL("Cannot read config file " << fn_comb ); return StatusCode::FAILURE; }
183  m_globalInsituCombMassConfig.push_back(globalInsituCombMass);
184  }
185  }
186 
187  //Loop over the request calib sequence
188  //Initialize derived classes for applying the requested calibrations and add them to a vector
189  std::vector<TString> vecCalibSeq = JetCalibUtils::Vectorize(calibSeq,"_");
190  for ( unsigned int i=0; i<vecCalibSeq.size(); ++i) {
191  if ( vecCalibSeq[i].EqualTo("Origin") || vecCalibSeq[i].EqualTo("DEV") ) continue;
192  if ( vecCalibSeq[i].EqualTo("Residual") && m_doJetArea ) continue;
193  ATH_CHECK( getCalibClass(vecCalibSeq[i] ));
194  }
195 
196  // Initialise ReadHandle(s)
198  ATH_CHECK( m_muKey.initialize() );
199  ATH_CHECK( m_actualMuKey.initialize() );
200  ATH_CHECK( m_rhoKey.initialize(requireRhoInput) );
201  if(m_pvKey.empty()) {
202  // No PV key: -- check if it is required
203  if(m_doResidual) {
204  // May require modification in case of residual that does not require NPV
205  ATH_MSG_ERROR("Residual calibration requested but no primary vertex container specified!");
206  return StatusCode::FAILURE;
207  }
208  else if(m_doGSC) {
209  if(m_jetAlgo.find("PFlow")!=std::string::npos) {
210  ATH_MSG_ERROR("GSC calibration for PFlow requested but no primary vertex container specified!");
211  return StatusCode::FAILURE;
212  }
213  else if((m_gscDepth!="Tile0" && m_gscDepth!="EM3")) {
214  ATH_MSG_ERROR("GSC calibration with tracks requested but no primary vertex container specified!");
215  return StatusCode::FAILURE;
216  }
217  }
218  } else {
219  // Received a PV key, declare the data dependency
220  ATH_CHECK( m_pvKey.initialize() );
221  }
222 
223  return StatusCode::SUCCESS;
224 }
225 
226 //Method for initializing the requested calibration derived classes
227 StatusCode JetCalibrationTool::getCalibClass(const TString& calibration) {
228  TString jetAlgo = m_jetAlgo;
229  const TString calibPath = "CalibArea-" + m_calibAreaTag + "/";
230  if ( calibration.EqualTo("Bcid") ){
231  m_globalConfig->SetValue("PileupStartingScale","JetBcidScaleMomentum");
232  std::unique_ptr<JetCalibrationStep> bcidCorr = std::make_unique<BcidOffsetCorrection>(this->name()+"_Bcid", m_globalConfig, jetAlgo, calibPath, m_isData);
233  ATH_CHECK(bcidCorr->initialize());
234  m_calibSteps.push_back(std::move(bcidCorr));
235  return StatusCode::SUCCESS;
236  }
237  else if ( calibration.EqualTo("JetArea") || calibration.EqualTo("Residual") ) {
238  std::unique_ptr<JetCalibrationStep> puCorr = std::make_unique<JetPileupCorrection>(this->name()+"_Pileup", m_globalConfig, jetAlgo, calibPath,
240  puCorr->msg().setLevel( this->msg().level() );
241  ATH_CHECK(puCorr->initialize());
242  m_calibSteps.push_back(std::move(puCorr));
243  return StatusCode::SUCCESS;
244  }
245  else if ( calibration.EqualTo("EtaJES") || calibration.EqualTo("AbsoluteEtaJES") ) {
246  std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+"_EtaJES", m_globalConfig, jetAlgo, calibPath, false, m_devMode);
247  etaJESCorr->msg().setLevel( this->msg().level() );
248  ATH_CHECK(etaJESCorr->initialize());
249  m_calibSteps.push_back(std::move(etaJESCorr));
250  return StatusCode::SUCCESS;
251  }
252  else if ( calibration.EqualTo("EtaMassJES") ) {
253  std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+"_EtaMassJES", m_globalConfig, jetAlgo, calibPath, true, m_devMode);
254  etaJESCorr->msg().setLevel( this->msg().level() );
255  ATH_CHECK(etaJESCorr->initialize());
256  m_calibSteps.push_back(std::move(etaJESCorr));
257  return StatusCode::SUCCESS;
258  }
259  else if ( calibration.EqualTo("GSC") ) {
260  std::unique_ptr<JetCalibrationStep> gsc = std::make_unique<GlobalSequentialCorrection>(this->name()+"_GSC", m_globalConfig, jetAlgo, m_gscDepth, calibPath, m_useOriginVertex, m_devMode);
261  gsc->msg().setLevel( this->msg().level() );
262  ATH_CHECK(gsc->initialize());
263  m_calibSteps.push_back(std::move(gsc));
264  return StatusCode::SUCCESS;
265  }
266  else if ( calibration.EqualTo("GNNC") ) {
267  std::unique_ptr<JetCalibrationStep> gnnc = std::make_unique<GlobalNNCalibration>(this->name()+"_GNNC",m_globalConfig,jetAlgo,calibPath,m_devMode);
268  gnnc->msg().setLevel( this->msg().level() );
269  ATH_CHECK(gnnc->initialize());
270  m_calibSteps.push_back(std::move(gnnc));
271  return StatusCode::SUCCESS;
272  }
273  else if ( calibration.EqualTo("JMS") ) {
274  std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+"_JMS", m_globalConfig, jetAlgo, calibPath, m_devMode);
275  jetMassCorr->msg().setLevel( this->msg().level() );
276  ATH_CHECK(jetMassCorr->initialize());
277  m_calibSteps.push_back(std::move(jetMassCorr));
278  return StatusCode::SUCCESS;
279  }
280  else if ( calibration.EqualTo("InsituCombinedMass") ){
281  for(unsigned int i=0;i<m_insituCombMassConfig.size();++i){
282  std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+"_InsituCombinedMass", m_globalInsituCombMassConfig.at(i), jetAlgo, calibPath, m_devMode);
283  jetMassCorr->msg().setLevel( this->msg().level() );
284  ATH_CHECK(jetMassCorr->initialize());
285  m_calibSteps.push_back(std::move(jetMassCorr));
286  }
287  return StatusCode::SUCCESS;
288  }
289  else if ( calibration.EqualTo("Insitu") ) {
291  std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+"_Insitu", m_globalConfig, jetAlgo, calibPath, m_devMode);
292  insituDataCorr->msg().setLevel( this->msg().level() );
293  ATH_CHECK(insituDataCorr->initialize());
294  m_calibSteps.push_back(std::move(insituDataCorr));
295  return StatusCode::SUCCESS;
296  }
297  else{
298  ATH_MSG_INFO("Initializing Time-Dependent Insitu Corrections");
299  for(unsigned int i=0;i<m_timeDependentInsituConfigs.size();++i){
300  // Add 0.5 before casting to avoid floating-point precision issues
301  unsigned int firstRun = static_cast<unsigned int>(m_runBins.at(i)+1.5);
302  unsigned int lastRun = static_cast<unsigned int>(m_runBins.at(i+1)+0.5);
303  std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+"_Insitu_"+std::to_string(i), m_globalTimeDependentConfigs.at(i), jetAlgo,
304  calibPath, m_devMode, firstRun, lastRun);
305  insituDataCorr->msg().setLevel( this->msg().level() );
306  ATH_CHECK(insituDataCorr->initialize());
307  m_calibSteps.push_back(std::move(insituDataCorr));
308  }
309  return StatusCode::SUCCESS;
310  }
311  }
312  else if ( calibration.EqualTo("Smear") ) {
313  if(m_isData){
314  ATH_MSG_FATAL("Asked for smearing of data, which is not supported. Aborting.");
315  return StatusCode::FAILURE;
316  }
317  std::unique_ptr<JetCalibrationStep> jetSmearCorr = std::make_unique<JetSmearingCorrection>(this->name()+"_Smear", m_globalConfig,jetAlgo,calibPath,m_devMode);
318  jetSmearCorr->msg().setLevel(this->msg().level());
319  ATH_CHECK(jetSmearCorr->initialize());
320  m_calibSteps.push_back(std::move(jetSmearCorr));
321  m_smearIndex = m_calibSteps.size() - 1;
322  return StatusCode::SUCCESS;
323  }
324  else if ( calibration.EqualTo("LargeRDNN") ) {
325  std::unique_ptr<JetCalibrationStep> largeR_dnn = std::make_unique<GlobalLargeRDNNCalibration>(this->name()+"_R10DNN", m_globalConfig,calibPath,m_devMode);
326  largeR_dnn->msg().setLevel(this->msg().level());
327  ATH_CHECK(largeR_dnn->initialize());
328  m_calibSteps.push_back(std::move(largeR_dnn));
329  return StatusCode::SUCCESS;
330  }
331  ATH_MSG_FATAL("Calibration string not recognized: " << calibration << ", aborting.");
332  return StatusCode::FAILURE;
333 }
334 
336  //Grab necessary event info for pile up correction and store it in a JetEventInfo class object
337  ATH_MSG_VERBOSE("Modifying jet collection.");
338  JetEventInfo jetEventInfo;
339  ATH_CHECK( initializeEvent(jetEventInfo) );
340  for (xAOD::Jet* jet : jets) ATH_CHECK( calibrate(*jet, jetEventInfo) );
341  return StatusCode::SUCCESS;
342 }
343 
344 // Private/Protected Methods
346 
348 
349  // Check if the tool was initialized
350  if( m_calibSteps.empty() ){
351  ATH_MSG_FATAL(" JetCalibrationTool::initializeEvent : The tool was not initialized.");
352  return StatusCode::FAILURE;
353  }
354 
355  // static accessor for PV index access
356  static const SG::AuxElement::ConstAccessor<int> PVIndexAccessor("PVIndex");
357 
358  ATH_MSG_VERBOSE("Initializing event.");
359 
360  if( m_doJetArea ) {
361  //Determine the rho value to use for the jet area subtraction
362  //Should be determined using EventShape object, use hard coded values if EventShape doesn't exist
363  double rho=0;
364  const xAOD::EventShape * eventShape = nullptr;
365 
367 
368  if ( rhRhoKey.isValid() ) {
369  ATH_MSG_VERBOSE(" Found event density container " << m_rhoKey.key());
370  eventShape = rhRhoKey.cptr();
371  if ( !rhRhoKey.isValid() ) {
372  ATH_MSG_VERBOSE(" Event shape container not found.");
373  ATH_MSG_FATAL("Could not retrieve the xAOD::EventShape container " << m_rhoKey.key() << " from the input file");
374  return StatusCode::FAILURE;
375  } else if ( !eventShape->getDensity( xAOD::EventShape::Density, rho ) ) {
376  ATH_MSG_VERBOSE(" Event density not found in container.");
377  ATH_MSG_FATAL("Could not retrieve the xAOD::EventShape::Density variable from " << m_rhoKey.key());
378  return StatusCode::FAILURE;
379  } else {
380  ATH_MSG_VERBOSE(" Event density retrieved.");
381  }
382  } else if ( m_doJetArea && !rhRhoKey.isValid() ) {
383  ATH_MSG_VERBOSE(" Rho container not found: " << m_rhoKey.key());
384  ATH_MSG_FATAL("Could not retrieve xAOD::EventShape container " << m_rhoKey.key() << " from the input file");
385  return StatusCode::FAILURE;
386  }
387  jetEventInfo.setRho(rho);
388  ATH_MSG_VERBOSE(" Rho = " << 0.001*rho << " GeV");
389 
390  // Necessary retrieval and calculation for use of nJetX instead of NPV
391  if(m_useNjetInResidual) {
392  // retrieve the container
393  const xAOD::JetContainer * jets = nullptr;
394  if (evtStore()->contains<xAOD::JetContainer>(m_nJetContainerName) ) {
395  ATH_MSG_VERBOSE(" Found jet container " << m_nJetContainerName);
396  if ( evtStore()->retrieve(jets, m_nJetContainerName).isFailure() || !jets ) {
397  ATH_MSG_FATAL("Could not retrieve xAOD::JetContainer " << m_nJetContainerName << " from evtStore");
398  return StatusCode::FAILURE;
399  }
400  } else {
401  ATH_MSG_FATAL("Could not find jet container " << m_nJetContainerName << " in the evtStore");
402  return StatusCode::FAILURE;
403  }
404 
405  // count jets above threshold
406  int nJets = 0;
407  for (const auto *jet : *jets) {
408  if(jet->pt()/1000. > m_nJetThreshold)
409  nJets += 1;
410  }
411  jetEventInfo.setNjet(nJets);
412  }
413  }
414 
415  // Retrieve EventInfo object, which now has multiple uses
417  const xAOD::EventInfo * eventObj = nullptr;
418  static std::atomic<unsigned int> eventInfoWarnings = 0;
420  if ( rhEvtInfo.isValid() ) {
421  eventObj = rhEvtInfo.cptr();
422  } else {
423  ++eventInfoWarnings;
424  if ( eventInfoWarnings < 20 )
425  ATH_MSG_ERROR(" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
426  jetEventInfo.setMu(0); //Hard coded value mu = 0 in case of failure (to prevent seg faults later).
427  jetEventInfo.setPVIndex(0);
428  return StatusCode::SUCCESS; //error is recoverable, so return SUCCESS
429  }
430  jetEventInfo.setRunNumber( eventObj->runNumber() );
431 
432  // If we are applying the reisdual, then store mu
433  if (m_doResidual || m_doBcid) {
435  if(!eventInfoDecor.isPresent()) {
436  ATH_MSG_ERROR("EventInfo decoration not available!");
437  return StatusCode::FAILURE;
438  }
439  jetEventInfo.setMu( eventInfoDecor(0) );
440  }
441 
442  // If this is GSC, we need EventInfo to determine the PV to use
443  // This is support for groups where PV0 is not the vertex of interest (H->gamgam, etc)
444  if (m_doGSC)
445  {
446  // First retrieve the PVIndex if specified
447  // Default is to not specify this, so no warning if it doesn't exist
448  // However, if specified, it should be a sane value - fail if not
449  if ( m_doGSC && PVIndexAccessor.isAvailable(*eventObj) )
450  jetEventInfo.setPVIndex( PVIndexAccessor(*eventObj) );
451  else{
452  if(!m_pvKey.empty()){
453  const xAOD::VertexContainer * vertices = nullptr;
455  if (rhPV.isValid()) {
456  vertices = rhPV.cptr();
457  xAOD::VertexContainer::const_iterator vtx_itr = vertices->begin();
458  xAOD::VertexContainer::const_iterator vtx_end = vertices->end();
459  for ( ; vtx_itr != vtx_end; ++vtx_itr ){
460  if ( (*vtx_itr)->vertexType() == xAOD::VxType::PriVtx ){
461  jetEventInfo.setPVIndex((*vtx_itr)->index());
462  break;
463  }
464  }
465  }
466  else{
467  jetEventInfo.setPVIndex(0);
468  }
469  }
470  else{
471  jetEventInfo.setPVIndex(0);
472  }
473  }
474  }
475 
476  // Extract the BCID information for the BCID correction
477  if (m_doBcid)
478  {
479  static const SG::ConstAccessor<int> BCIDDistanceFromFrontAcc ("DFCommonJets_BCIDDistanceFromFront");
480  static const SG::ConstAccessor<int> BCIDGapBeforeTrainAcc ("DFCommonJets_BCIDGapBeforeTrain");
481  static const SG::ConstAccessor<int> BCIDGapBeforeTrainMinus12Acc ("DFCommonJets_BCIDGapBeforeTrainMinus12");
482 
483  jetEventInfo.setBcidDistanceFromFront( BCIDDistanceFromFrontAcc (*eventObj) );
484  jetEventInfo.setBcidGapBeforeTrain( BCIDGapBeforeTrainAcc (*eventObj) );
485  jetEventInfo.setBcidGapBeforeTrainMinus12( BCIDGapBeforeTrainMinus12Acc (*eventObj) );
486  }
487 
488  // If PV index is not zero, we need to confirm it's a reasonable value
489  // To do this, we need the primary vertices
490  // However, other users of the GSC may not have the PV collection (in particular: trigger GSC in 2016)
491  // So only retrieve vertices if needed for NPV (residual) or a non-zero PV index was specified (GSC)
492  if ((m_doResidual && !m_useNjetInResidual) || (m_doGSC && jetEventInfo.PVIndex()))
493  {
494  //Retrieve VertexContainer object, use it to obtain NPV for the residual correction or check validity of GSC non-PV0 usage
495  const xAOD::VertexContainer * vertices = nullptr;
496 
498  if (rhPV.isValid()) {
499  vertices = rhPV.cptr();
500  } else {
501  ATH_MSG_WARNING(" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
502  jetEventInfo.setNPV(0); //Hard coded value NPV = 0 in case of failure (to prevent seg faults later).
503  return StatusCode::SUCCESS; //error is recoverable, so return SUCCESS
504  }
505 
506  // Calculate and set NPV if this is residual
507  if (m_doResidual)
508  {
509  int eventNPV = 0;
510  eventNPV = std::count_if(vertices->begin(), vertices->end(), [](const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
511  jetEventInfo.setNPV(eventNPV);
512  }
513 
514  // Validate value of non-standard PV index usage
515  if (m_doGSC && jetEventInfo.PVIndex())
516  {
517  static std::atomic<unsigned int> vertexIndexWarnings = 0;
518  if (jetEventInfo.PVIndex() < 0 || static_cast<size_t>(jetEventInfo.PVIndex()) >= vertices->size())
519  {
520  ++vertexIndexWarnings;
521  if (vertexIndexWarnings < 20)
522  ATH_MSG_WARNING(" JetCalibrationTool::initializeEvent : PV index is out of bounds.");
523  jetEventInfo.setPVIndex(0); // Hard coded value PVIndex = 0 in case of failure (to prevent seg faults later).
524  return StatusCode::SUCCESS; // error is recoverable, so return SUCCESS
525  }
526  }
527  }
528  } else if (m_doDNNCal) {
529  // retrieve mu and NPV only from eventInfo
530  static std::atomic<unsigned int> eventInfoWarningsMu = 0;
532  if ( rhEvtInfo.isValid() ) {
534  jetEventInfo.setMu(eventInfoDecor(0));
535  } else {
536  ++eventInfoWarningsMu;
537  if ( eventInfoWarningsMu < 20 ) ATH_MSG_WARNING(" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
538  jetEventInfo.setMu(0); //Hard coded value mu = 0 in case of failure (to prevent seg faults later).
539  }
540 
541  static std::atomic<unsigned int> eventInfoWarningsPV = 0;
542  const xAOD::VertexContainer * vertices = nullptr;
544  if (rhPV.isValid()) {
545  vertices = rhPV.cptr();
546  int eventNPV = 0;
547  eventNPV = std::count_if(vertices->begin(), vertices->end(), [](const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
548  jetEventInfo.setNPV(eventNPV);
549  } else {
550  ++eventInfoWarningsPV;
551  if ( eventInfoWarningsPV < 20 ) ATH_MSG_WARNING(" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
552  jetEventInfo.setNPV(0); //Hard coded value NPV = 0 in case of failure (to prevent seg faults later).
553  }
554  }
555  return StatusCode::SUCCESS;
556 }
557 
559 
560  //Check for OriginCorrected and PileupCorrected attributes, assume they are false if not found
561  int tmp = 0; //temporary int for checking getAttribute
562  if ( !jet.getAttribute<int>("OriginCorrected",tmp) )
563  jet.setAttribute<int>("OriginCorrected",false);
564  if ( !jet.getAttribute<int>("PileupCorrected",tmp) )
565  jet.setAttribute<int>("PileupCorrected",false);
566 
567  ATH_MSG_VERBOSE("Calibrating jet " << jet.index());
568  if(m_doSetDetectorEta) {
569  xAOD::JetFourMom_t jetconstitP4 = jet.getAttribute<xAOD::JetFourMom_t>("JetConstitScaleMomentum");
570  jet.setAttribute<float>("DetectorEta",jetconstitP4.eta()); //saving constituent scale eta for later use
571  }
572 
573  for (unsigned int i=0; i<m_calibSteps.size(); ++i) ATH_CHECK(m_calibSteps[i]->calibrate(jet, jetEventInfo));
574 
575  return StatusCode::SUCCESS;
576 }
577 
578 
580 
581  if(m_smearIndex < 0){
582  ATH_MSG_ERROR("Cannot retrieve the nominal data resolution - smearing was not configured during initialization");
583  return StatusCode::FAILURE;
584  }
585  return m_calibSteps.at(m_smearIndex)->getNominalResolutionData(jet, resolution);
586 }
587 
589 
590  if(m_smearIndex < 0){
591  ATH_MSG_ERROR("Cannot retrieve the nominal MC resolution - smearing was not configured during initialization");
592  return StatusCode::FAILURE;
593  }
594  return m_calibSteps.at(m_smearIndex)->getNominalResolutionMC(jet, resolution);
595 }
596 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::EventShape_v1::getDensity
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
Definition: EventShape_v1.cxx:135
JetEventInfo::setBcidDistanceFromFront
void setBcidDistanceFromFront(Int_t BcidDistanceFromFront)
Definition: JetEventInfo.h:21
JetCalibrationTool::m_doResidual
bool m_doResidual
Definition: JetCalibrationTool.h:102
JMSCorrection.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
JetCalibrationTool::m_smearIndex
int m_smearIndex
Definition: JetCalibrationTool.h:110
GlobalSequentialCorrection.h
JetCalibrationTool::m_originCorrectedClusters
bool m_originCorrectedClusters
Definition: JetCalibrationTool.h:81
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetEventInfo::PVIndex
int PVIndex()
Definition: JetEventInfo.h:30
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
JetCalibrationTool::m_jetAlgo
std::string m_jetAlgo
Definition: JetCalibrationTool.h:73
JetCalibrationTool::LC
@ LC
Definition: JetCalibrationTool.h:45
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
JetCalibrationTool::m_timeDependentInsituConfigs
std::vector< TString > m_timeDependentInsituConfigs
Definition: JetCalibrationTool.h:87
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JetCalibrationTool::m_muKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_muKey
Definition: JetCalibrationTool.h:67
JetCalibrationTool::m_isData
bool m_isData
Definition: JetCalibrationTool.h:79
GlobalNNCalibration.h
python.base_data.config
config
Definition: base_data.py:21
JetCalibrationTool::EM
@ EM
Definition: JetCalibrationTool.h:45
asg
Definition: DataHandleTestTool.h:28
SG::ReadDecorHandle::isPresent
bool isPresent() const
Is the referenced container present in SG?
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
JetEventInfo::setRho
void setRho(double rho)
Definition: JetEventInfo.h:15
JetCalibrationTool::m_gscDepth
std::string m_gscDepth
Definition: JetCalibrationTool.h:107
JetCalibrationTool::initialize
StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetCalibrationTool.cxx:54
JetCalibrationTool::getCalibClass
StatusCode getCalibClass(const TString &calibration)
Definition: JetCalibrationTool.cxx:227
JetCalibrationTool::m_rhoKey
SG::ReadHandleKey< xAOD::EventShape > m_rhoKey
Definition: JetCalibrationTool.h:65
JetCalibrationTool::calibrate
StatusCode calibrate(xAOD::Jet &jet, JetEventInfo &jetEventInfo) const
Definition: JetCalibrationTool.cxx:558
GlobalLargeRDNNCalibration.h
JetCalibrationTool::m_devMode
bool m_devMode
Definition: JetCalibrationTool.h:78
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
JetEventInfo::setBcidGapBeforeTrain
void setBcidGapBeforeTrain(Int_t BcidGapBeforeTrain)
Definition: JetEventInfo.h:22
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Dedxcorrection::resolution
double resolution[nGasTypes][nParametersResolution]
Definition: TRT_ToT_Corrections.h:46
JetCalibrationTool::m_runBins
std::vector< double > m_runBins
Definition: JetCalibrationTool.h:88
JetCalibUtils::Vectorize
StrV Vectorize(const TString &str, const TString &sep=" ")
Definition: JetCalibUtils.cxx:14
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
JetSmearingCorrection.h
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
JetCalibrationTool::m_doJetArea
bool m_doJetArea
Definition: JetCalibrationTool.h:101
JetCalibrationStep::initialize
virtual StatusCode initialize()=0
JetCalibrationTool::m_pvKey
SG::ReadHandleKey< xAOD::VertexContainer > m_pvKey
Definition: JetCalibrationTool.h:66
JetEventInfo::setBcidGapBeforeTrainMinus12
void setBcidGapBeforeTrainMinus12(Int_t BcidGapBeforeTrainMinus12)
Definition: JetEventInfo.h:23
JetCalibrationTool::initializeEvent
StatusCode initializeEvent(JetEventInfo &jetEventInfo) const
Definition: JetCalibrationTool.cxx:347
JetCalibrationTool::m_globalConfig
TEnv * m_globalConfig
Definition: JetCalibrationTool.h:94
BcidOffsetCorrection.h
JetCalibrationTool::m_insituCombMassConfig
std::vector< TString > m_insituCombMassConfig
Definition: JetCalibrationTool.h:91
xAOD::EventShape_v1::Density
@ Density
Definition: EventShape_v1.h:47
JetEventInfo::setNjet
void setNjet(double nJet)
Definition: JetEventInfo.h:18
JetEventInfo
Definition: JetEventInfo.h:8
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
JetCalibrationTool::PFLOW
@ PFLOW
Definition: JetCalibrationTool.h:45
JetCalibrationTool::m_nJetThreshold
float m_nJetThreshold
Definition: JetCalibrationTool.h:83
JetCalibrationTool::getNominalResolutionMC
StatusCode getNominalResolutionMC(const xAOD::Jet &jet, double &resolution) const override
Definition: JetCalibrationTool.cxx:588
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
python.getCurrentFolderTag.fn
fn
Definition: getCurrentFolderTag.py:65
JetCalibrationTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
JetCalibrationTool::m_dir
std::string m_dir
Definition: JetCalibrationTool.h:85
lumiFormat.i
int i
Definition: lumiFormat.py:85
JetCalibrationTool::m_calibAreaTag
std::string m_calibAreaTag
Definition: JetCalibrationTool.h:76
JetCalibrationTool::m_eInfoName
std::string m_eInfoName
Definition: JetCalibrationTool.h:86
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JetCalibrationTool::m_nJetContainerName
std::string m_nJetContainerName
Definition: JetCalibrationTool.h:84
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
JetCalibrationTool::m_evtInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
Definition: JetCalibrationTool.h:64
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JetCalibrationTool::m_doSetDetectorEta
bool m_doSetDetectorEta
Definition: JetCalibrationTool.h:89
JetCalibrationTool::m_originScale
std::string m_originScale
Definition: JetCalibrationTool.h:77
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
JetEventInfo::setNPV
void setNPV(double NPV)
Definition: JetEventInfo.h:17
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::EventShape_v1
Data class for event shapes.
Definition: EventShape_v1.h:28
beamspotman.dir
string dir
Definition: beamspotman.py:623
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
JetEventInfo::setPVIndex
void setPVIndex(int PVindex)
Definition: JetEventInfo.h:19
PathResolver.h
InsituDataCorrection.h
JetCalibrationTool::m_actualMuKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_actualMuKey
Definition: JetCalibrationTool.h:69
JetCalibrationTool::m_jetScale
jetScale m_jetScale
Definition: JetCalibrationTool.h:99
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
JetCalibrationTool::JetCalibrationTool
JetCalibrationTool(const std::string &name="JetCalibrationTool")
Constructor with parameters:
Definition: JetCalibrationTool.cxx:27
JetCalibrationTool::m_config
std::string m_config
Definition: JetCalibrationTool.h:74
JetCalibrationTool::getNominalResolutionData
StatusCode getNominalResolutionData(const xAOD::Jet &jet, double &resolution) const override
Definition: JetCalibrationTool.cxx:579
JetCalibrationTool::m_globalTimeDependentConfigs
std::vector< TEnv * > m_globalTimeDependentConfigs
Definition: JetCalibrationTool.h:95
JetCalibrationTool::applyCalibration
StatusCode applyCalibration(xAOD::JetContainer &) const override
Apply calibration to a jet container.
Definition: JetCalibrationTool.cxx:335
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
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
JetCalibrationTool::m_globalInsituCombMassConfig
std::vector< TEnv * > m_globalInsituCombMassConfig
Definition: JetCalibrationTool.h:96
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
EtaJESCorrection.h
JetCalibrationTool::m_doGSC
bool m_doGSC
Definition: JetCalibrationTool.h:104
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
JetCalibrationTool::m_doBcid
bool m_doBcid
Definition: JetCalibrationTool.h:100
ReadDecorHandle.h
Handle class for reading a decoration on an object.
JetCalibrationTool::m_timeDependentCalib
bool m_timeDependentCalib
Definition: JetCalibrationTool.h:80
ReadBchFromCool.lastRun
lastRun
Definition: ReadBchFromCool.py:278
ResidualOffsetCorrection.h
JetPileupCorrection.h
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
JetCalibrationTool::m_calibSeq
std::string m_calibSeq
Definition: JetCalibrationTool.h:75
merge.status
status
Definition: merge.py:17
JetCalibUtils::VectorizeD
VecD VectorizeD(const TString &str, const TString &sep=" ")
Definition: JetCalibUtils.cxx:25
JetEventInfo::setRunNumber
void setRunNumber(UInt_t RunNumber)
Definition: JetEventInfo.h:20
JetCalibrationTool::m_useNjetInResidual
bool m_useNjetInResidual
Definition: JetCalibrationTool.h:82
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
JetCalibrationTool::m_useOriginVertex
bool m_useOriginVertex
Definition: JetCalibrationTool.h:113
JetCalibrationTool::m_doDNNCal
bool m_doDNNCal
Definition: JetCalibrationTool.h:105
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
JetCalibrationTool::m_doOrigin
bool m_doOrigin
Definition: JetCalibrationTool.h:103
JetEventInfo::setMu
void setMu(double mu)
Definition: JetEventInfo.h:16
JetCalibrationTool::~JetCalibrationTool
~JetCalibrationTool()
Destructor:
Definition: JetCalibrationTool.cxx:43
fitman.rho
rho
Definition: fitman.py:532
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
JetCalibrationTool::m_calibSteps
std::vector< std::unique_ptr< JetCalibrationStep > > m_calibSteps
Definition: JetCalibrationTool.h:109
JetCalibrationTool::m_insituCombMassCalib
bool m_insituCombMassCalib
Definition: JetCalibrationTool.h:90