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