ATLAS Offline Software
Public Member Functions | Public Attributes | Private Attributes | List of all members
MuonTriggerSFTester Class Reference
Collaboration diagram for MuonTriggerSFTester:

Public Member Functions

 MuonTriggerSFTester (const char *appName, const std::string &trigger)
 
int initialiseTools (const std::string &customFileName, const std::string &customInputFolder, int year, const std::string &period)
 
int processEvent (xAOD::TEvent &event, int year, const std::string &period)
 
int checkASymDiMuonTrigger (const xAOD::EventInfo *ei, const xAOD::Muon &muon, unsigned int iquality, unsigned int ibin, unsigned int isystematic)
 
int checkSymDiMuonTrigger (const xAOD::EventInfo *ei, const xAOD::MuonContainer *muons, unsigned int iquality, unsigned int ibin, unsigned int isystematic)
 
int checkSingleMuonTrigger (const xAOD::EventInfo *ei, const xAOD::MuonContainer *muons, unsigned int iquality, unsigned int ibin, unsigned int isystematic)
 

Public Attributes

int m_errorsCount = 0
 
int m_warningsCount = 0
 

Private Attributes

std::vector< std::vector< CP::MuonTriggerScaleFactors * > > m_triggerSFTools
 
std::vector< CP::SystematicSetm_systematics
 
const char * m_appName
 
std::string m_trigger
 

Detailed Description

Definition at line 62 of file MuonTriggerSFRootCoreTest.cxx.

Constructor & Destructor Documentation

◆ MuonTriggerSFTester()

MuonTriggerSFTester::MuonTriggerSFTester ( const char *  appName,
const std::string &  trigger 
)
inline

Definition at line 65 of file MuonTriggerSFRootCoreTest.cxx.

65  :
66  m_errorsCount (0),
67  m_warningsCount (0),
69  m_appName (appName),
70  m_trigger (trigger)
71  {
72  }

Member Function Documentation

◆ checkASymDiMuonTrigger()

int MuonTriggerSFTester::checkASymDiMuonTrigger ( const xAOD::EventInfo ei,
const xAOD::Muon muon,
unsigned int  iquality,
unsigned int  ibin,
unsigned int  isystematic 
)
inline

Definition at line 132 of file MuonTriggerSFRootCoreTest.cxx.

132  {
133  CHECK_CPSys(m_triggerSFTools[iquality][ibin]->applySystematicVariation(m_systematics[isystematic]));
134 
135  Int_t threshold = 0;
138  Error("MuonTriggerSFRootCoreTest", "Could not extract threshold for trigger %s", m_trigger.c_str());
139  return 1;
140  }
141  if (muon.pt() < threshold or std::abs(muon.eta()) > 2.5)
142  return 1;
143 
144  bool displayWarning = false;
145 
146 
147 
148  double efficiencyMC = 0.;
149  double efficiencyData = 0.;
150 
151  result = m_triggerSFTools[iquality][ibin]->getTriggerEfficiency(muon,
152  efficiencyMC,
153  m_trigger,
154  false);
156  Error(m_appName, "Could not retrieve MC efficeincy. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
157  m_errorsCount++;
158  }
159 
160  result = m_triggerSFTools[iquality][ibin]->getTriggerEfficiency(muon,
161  efficiencyData,
162  m_trigger,
163  true);
165  Error(m_appName, "Could not retrieve data efficeincy. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
166  m_errorsCount++;
167  }
168  auto triggerSF = efficiencyMC/efficiencyData;
169  if (triggerSF < 0.2 || triggerSF > 1.2) {
170  if (displayWarning) {
171  Warning(m_appName, "Retrieved trigger scale factor %.3f is outside of expected range from 0.2 to 1.2. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", triggerSF, static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
172  m_warningsCount++;
173  }
174  }
175  return 0;
176  }

◆ checkSingleMuonTrigger()

int MuonTriggerSFTester::checkSingleMuonTrigger ( const xAOD::EventInfo ei,
const xAOD::MuonContainer muons,
unsigned int  iquality,
unsigned int  ibin,
unsigned int  isystematic 
)
inline

Definition at line 211 of file MuonTriggerSFRootCoreTest.cxx.

211  {
212 
213  CHECK_CPSys(m_triggerSFTools[iquality][ibin]->applySystematicVariation(m_systematics[isystematic]));
215  xAOD::MuonContainer::const_iterator mu_end = muons->end();
216  for (xAOD::MuonContainer::const_iterator mu_itr = muons->begin(); mu_itr != mu_end; ++mu_itr) {
217  for (size_t l = 0; l < types.size(); l++) {
218  if (types[l] != "data" || m_systematics[isystematic].name().find("TrigSystUncertainty") == std::string::npos) {
219  Double_t eff;
220  auto binNumber = m_triggerSFTools[iquality][ibin]->getBinNumber(**mu_itr, m_trigger);
221  result = m_triggerSFTools[iquality][ibin]->getTriggerEfficiency(**mu_itr, eff, m_trigger, types[l] == "data");
223  Error(m_appName, "Could not retrieve trigger efficiency. Paramaters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s,\n Type = %s ", static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str(), types[l].c_str());
224  m_errorsCount++;
225  }
226  if (eff < 0 || eff > 1) {
227  Warning(m_appName, "Retrieved trigger efficiency %.3f is outside of expected range from 0 to 1. Paramaters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", eff, static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
228  m_warningsCount++;
229  }
230  if (binNumber < 0 || binNumber > 238) {
231  Warning(m_appName, "Retrieved bin number %.i is outside of expected range from 0 to 238. Paramaters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", binNumber, static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
232  m_warningsCount++;
233  }
234 
235  }
236  }
237  }
238 
239  double triggerSF = 0.;
240  result = m_triggerSFTools[iquality][ibin]->getTriggerScaleFactor(*muons, triggerSF, m_trigger);
242  Error(m_appName, "Could not retrieve trigger scale factors. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
243  m_errorsCount++;
244  }
245  if (triggerSF < 0.2 || triggerSF > 1.2) {
246  // Allow scale factor to be outside of this range in case all the muons are below the threshold
247  Int_t threshold = 0;
250  Error("MuonTriggerSFRootCoreTest", "Could not extract threshold for trigger %s", m_trigger.c_str());
251  return 1;
252  }
253  bool displayWarning = false;
254  xAOD::MuonContainer::const_iterator mu_end = muons->end();
255  for (xAOD::MuonContainer::const_iterator mu_itr = muons->begin(); mu_itr != mu_end; ++mu_itr) {
256  if ((**mu_itr).pt() >= threshold and std::abs((**mu_itr).eta()) < 2.5) displayWarning = true;
257  }
258 
259  if (displayWarning) {
260  Warning(m_appName, "Retrieved trigger scale factor %.3f is outside of expected range from 0.2 to 1.2. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", triggerSF, static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
261  m_warningsCount++;
262  }
263  }
264  double tmpEffData = 1.;
265  double tmpEffMC = 1.;
266  for (auto muon: *muons) {
267  double effData = 0.;
268  double effMC = 0.;
269  double scaleFactor = 0.;
270  if (m_triggerSFTools[iquality][ibin]->getTriggerEfficiency(*muon, effData, m_trigger, true) != CP::CorrectionCode::Ok) {
271  Error("MuonTriggerSFRootCoreTest", "Could not extract data trigger efficiency for %s which is %f. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s \n muon pt: %f \n eta: %f \n phi: %f", m_trigger.c_str(), scaleFactor, static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str(), muon->pt(), muon->eta(), muon->phi());
272  return 1;
273  }
274  if (m_triggerSFTools[iquality][ibin]->getTriggerEfficiency(*muon, effMC, m_trigger, false) != CP::CorrectionCode::Ok) {
275  Error("MuonTriggerSFRootCoreTest", "Could not extract MC trigger efficiency for %s", m_trigger.c_str());
276  return 1;
277  }
278  if (m_triggerSFTools[iquality][ibin]->getTriggerScaleFactor(*muon, scaleFactor, m_trigger) != CP::CorrectionCode::Ok) {
279  Error("MuonTriggerSFRootCoreTest", "Could not extract MC trigger efficiency for %s", m_trigger.c_str());
280  return 1;
281  }
282  if (scaleFactor < 0.2 || scaleFactor > 1.2 ) {
283  Int_t threshold = 0;
285  Error("MuonTriggerSFRootCoreTest", "Could not extract threshold for trigger %s", m_trigger.c_str());
286  return 1;
287  }
288  if(muon->pt() >= threshold and std::abs(muon->eta()) < 2.5)
289  Warning(m_appName, "Retrieved single muon trigger scale factor %.3f is outside of expected range from 0.2 to 1.2. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s \n muon pt: %f \n eta: %f \n phi: %f", scaleFactor, static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str(), muon->pt(), muon->eta(), muon->phi());
290  }
291  tmpEffData *= 1.-effData;
292  tmpEffMC *= 1.-effMC;
293  }
294  auto sfSingleCalc = (1. - tmpEffData)/(1. - tmpEffMC);
295  if ( triggerSF > 0.2 && (sfSingleCalc - triggerSF) / triggerSF > 0.02) {
296 
297  // Warning(m_appName, "Invalid single muon SF result. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s \n Systematic = %s \n single SF: %f \n combined SF %f \n ", static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), systematics[isystematic].name().c_str(), sfSingleCalc, triggerSFrSF);
298  m_warningsCount++;
299  }
300  return 0;
301  }

◆ checkSymDiMuonTrigger()

int MuonTriggerSFTester::checkSymDiMuonTrigger ( const xAOD::EventInfo ei,
const xAOD::MuonContainer muons,
unsigned int  iquality,
unsigned int  ibin,
unsigned int  isystematic 
)
inline

Definition at line 178 of file MuonTriggerSFRootCoreTest.cxx.

178  {
179  CHECK_CPSys(m_triggerSFTools[iquality][ibin]->applySystematicVariation(m_systematics[isystematic]));
180  double triggerSF = 0.;
182  result = m_triggerSFTools[iquality][ibin]->getTriggerScaleFactor(*muons, triggerSF, m_trigger);
184  Error(m_appName, "Could not retrieve trigger scale factors. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
185  m_errorsCount++;
186  }
187  if (triggerSF < 0.2 || triggerSF > 1.2) {
188  // Allow scale factor to be outside of this range in case all the muons are below the threshold
189  Int_t threshold = 0;
192  Error("MuonTriggerSFRootCoreTest", "Could not extract threshold for trigger %s", m_trigger.c_str());
193  return 1;
194  }
195  bool displayWarning = false;
196  xAOD::MuonContainer::const_iterator mu_end = muons->end();
197  for (xAOD::MuonContainer::const_iterator mu_itr = muons->begin(); mu_itr != mu_end; ++mu_itr) {
198  if ((**mu_itr).pt() >= threshold and std::abs((**mu_itr).eta()) < 2.5) displayWarning = true;
199  }
200 
201  if (displayWarning) {
202  Warning(m_appName, "Retrieved trigger scale factor %.3f is outside of expected range from 0.2 to 1.2. Parameters:\n Event number = %i,\n Quality = %s,\n Binning = %s,\n Systematic = %s", triggerSF, static_cast<int>(ei->eventNumber()), qualities[iquality].c_str(), binnings[ibin].c_str(), m_systematics[isystematic].name().c_str());
203  m_warningsCount++;
204  }
205  }
206 
207  return 0;
208  }

◆ initialiseTools()

int MuonTriggerSFTester::initialiseTools ( const std::string &  customFileName,
const std::string &  customInputFolder,
int  year,
const std::string &  period 
)
inline

Definition at line 74 of file MuonTriggerSFRootCoreTest.cxx.

74  {
75  for (size_t i = 0; i < qualities.size(); i++) {
76  std::vector<CP::MuonTriggerScaleFactors*> tools{};
77  for (size_t j = 0; j < binnings.size(); j++) {
78  CP::MuonTriggerScaleFactors* tool = new CP::MuonTriggerScaleFactors("TrigSF_" + qualities[i] + "_" + binnings[j]);
79  ASG_CHECK_SA(m_appName, tool->setProperty("MuonQuality", qualities[i]));
80  ASG_CHECK_SA(m_appName, tool->setProperty("Binning", binnings[j]));
81  ASG_CHECK_SA(m_appName, tool->setProperty("filename", customFileName));
82  ASG_CHECK_SA(m_appName, tool->setProperty("CustomInputFolder", customInputFolder));
83  ASG_CHECK_SA(m_appName, tool->setProperty("UseExperimental", true));
84  ASG_CHECK_SA(m_appName, tool->setProperty("AllowZeroSF", true));
85  ASG_CHECK_SA(m_appName, tool->setProperty("forceYear", year));
86  ASG_CHECK_SA(m_appName, tool->setProperty("forcePeriod", period));
87 
88  tool->msg().setLevel( MSG::WARNING );
89  ASG_CHECK_SA(m_appName, tool->initialize());
90  //CP::CorrectionCode result = tool->setRunNumber(atoi(runNumber));
91  //if (result != CP::CorrectionCode::Ok){
92  // Error(m_appName, "Could not set run number");
93  // return 1;
94  //}
95  tools.push_back(tool);
96  }
97  m_triggerSFTools.push_back(tools);
98  }
99  return 0;
100  }

◆ processEvent()

int MuonTriggerSFTester::processEvent ( xAOD::TEvent event,
int  year,
const std::string &  period 
)
inline

Definition at line 102 of file MuonTriggerSFRootCoreTest.cxx.

102  {
103  const xAOD::EventInfo* ei = nullptr;
104  RETURN_CHECK(m_appName, event.retrieve(ei, "EventInfo"));
105 
106  const xAOD::MuonContainer* muons = nullptr;
107  RETURN_CHECK(m_appName, event.retrieve(muons, "Muons"));
108  if(year == -1 && period == "")
109  static const SG::AuxElement::ConstAccessor<unsigned int> acc_rnd("RandomRunNumber");
110  for (size_t i = 0; i < qualities.size(); i++) {
111  for (size_t j = 0; j < binnings.size(); j++) {
112  for (size_t k = 0; k < m_systematics.size(); k++) {
113  if(m_trigger == "HLT_mu26_ivarmedium" || m_trigger == "HLT_mu50" || m_trigger == "HLT_mu26_ivarmedium_OR_HLT_mu50")
114  checkSingleMuonTrigger(ei, muons, i, j, k);
115  if(muons->size() != 2)
116  continue;
117  if(binnings[j] == "coarse")
118  continue; // not supported right now
119  if(m_trigger == "HLT_2mu14" || m_trigger == "HLT_2mu10"){
120  checkSymDiMuonTrigger(ei, muons, i, j, k);
121  }
122  else{
123  for(auto muon : *muons)
124  checkASymDiMuonTrigger(ei, *muon, i, j, k);
125  }
126  }
127  }
128  }
129  return 0;
130  }

Member Data Documentation

◆ m_appName

const char* MuonTriggerSFTester::m_appName
private

Definition at line 311 of file MuonTriggerSFRootCoreTest.cxx.

◆ m_errorsCount

int MuonTriggerSFTester::m_errorsCount = 0

Definition at line 305 of file MuonTriggerSFRootCoreTest.cxx.

◆ m_systematics

std::vector<CP::SystematicSet> MuonTriggerSFTester::m_systematics
private

Definition at line 310 of file MuonTriggerSFRootCoreTest.cxx.

◆ m_trigger

std::string MuonTriggerSFTester::m_trigger
private

Definition at line 312 of file MuonTriggerSFRootCoreTest.cxx.

◆ m_triggerSFTools

std::vector<std::vector<CP::MuonTriggerScaleFactors*> > MuonTriggerSFTester::m_triggerSFTools
private

Definition at line 309 of file MuonTriggerSFRootCoreTest.cxx.

◆ m_warningsCount

int MuonTriggerSFTester::m_warningsCount = 0

Definition at line 306 of file MuonTriggerSFRootCoreTest.cxx.


The documentation for this class was generated from the following file:
python.AtlRunQueryAMI.period
period
Definition: AtlRunQueryAMI.py:225
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
RETURN_CHECK
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition: ReturnCheck.h:26
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
get_generator_info.result
result
Definition: get_generator_info.py:21
CP::make_systematics_vector
std::vector< CP::SystematicSet > make_systematics_vector(const SystematicSet &systematics)
utility functions for working with systematics
Definition: SystematicsUtil.cxx:25
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
MuonTriggerSFTester::m_errorsCount
int m_errorsCount
Definition: MuonTriggerSFRootCoreTest.cxx:305
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
python.AtlRunQueryAMI.year
year
Definition: AtlRunQueryAMI.py:226
MuonTriggerSFTester::m_warningsCount
int m_warningsCount
Definition: MuonTriggerSFRootCoreTest.cxx:306
MuonTriggerSFTester::m_trigger
std::string m_trigger
Definition: MuonTriggerSFRootCoreTest.cxx:312
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
MuonTriggerSFTester::checkSymDiMuonTrigger
int checkSymDiMuonTrigger(const xAOD::EventInfo *ei, const xAOD::MuonContainer *muons, unsigned int iquality, unsigned int ibin, unsigned int isystematic)
Definition: MuonTriggerSFRootCoreTest.cxx:178
lumiFormat.i
int i
Definition: lumiFormat.py:85
MuonTriggerSFTester::m_appName
const char * m_appName
Definition: MuonTriggerSFRootCoreTest.cxx:311
MuonTriggerSFTester::checkSingleMuonTrigger
int checkSingleMuonTrigger(const xAOD::EventInfo *ei, const xAOD::MuonContainer *muons, unsigned int iquality, unsigned int ibin, unsigned int isystematic)
Definition: MuonTriggerSFRootCoreTest.cxx:211
MuonTriggerSFTester::checkASymDiMuonTrigger
int checkASymDiMuonTrigger(const xAOD::EventInfo *ei, const xAOD::Muon &muon, unsigned int iquality, unsigned int ibin, unsigned int isystematic)
Definition: MuonTriggerSFRootCoreTest.cxx:132
MuonTriggerSFTester::m_systematics
std::vector< CP::SystematicSet > m_systematics
Definition: MuonTriggerSFRootCoreTest.cxx:310
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CHECK_CPSys
#define CHECK_CPSys(Arg)
Definition: MuonTriggerSFRootCoreTest.cxx:38
tools
Definition: DataQuality/ZLumiScripts/python/tools/__init__.py:1
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
threshold
Definition: chainparser.cxx:74
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
MuonTriggerSFTester::m_triggerSFTools
std::vector< std::vector< CP::MuonTriggerScaleFactors * > > m_triggerSFTools
Definition: MuonTriggerSFRootCoreTest.cxx:309
ASG_CHECK_SA
#define ASG_CHECK_SA(SOURCE, EXP)
Helper macro for checking the status code of a call outside of an ASG tool.
Definition: Check.h:69
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
CP::MuonTriggerScaleFactors
Definition: MuonTriggerScaleFactors.h:30
getThreshold
CP::CorrectionCode getThreshold(Int_t &threshold, const std::string &trigger)
Definition: MuonTriggerSFRootCoreTest.cxx:48
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
fitman.k
k
Definition: fitman.py:528
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25