ATLAS Offline Software
testEgEfficiencyCorrWithoutFile.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // System include(s):
6 #include <memory>
7 #include <string>
8 // ROOT include(s):
9 #include <TFile.h>
10 #include <TString.h>
11 // Infrastructure include(s):
12 #ifdef XAOD_STANDALONE
13 #include "xAODRootAccess/Init.h"
14 #include "xAODRootAccess/TEvent.h"
15 #include "xAODRootAccess/TStore.h"
16 #endif // XAOD_STANDALONE
17 // Asg includes
19 // Local includes
20 #include "CreateDummyEl.h"
21 #include "SFHelpers.h"
22 //
23 #include <boost/program_options.hpp>
24 
26 #include "AsgMessaging/MsgStream.h"
28 
29 namespace asg {
30 ANA_MSG_HEADER(msgSelectorCheck)
31 ANA_MSG_SOURCE(msgSelectorCheck, "")
32 }
33 
34 int
35 main(int argc, char* argv[])
36 {
37  StatusCode::enableFailure();
38  using namespace asg::msgSelectorCheck;
39  ANA_CHECK_SET_TYPE(int);
40  setMsgLevel(MSG::INFO);
41  /*
42  * Parse the input from the command line
43  */
44  std::string fileName{};
45  std::string mapfileName{};
46  std::string idkey{};
47  std::string recokey{};
48  std::string isokey{};
49  std::string triggerkey{};
50  std::string model{};
51  int runno{};
52  float eta{};
53  float pt{};
54  std::string type{};
55  int inputlevel{};
56 
57  using namespace boost::program_options;
58  options_description desc{ "Options" };
59  desc.add_options()("help,h", "Help screen")(
60  "msgLevel,l",
61  value<int>(&inputlevel)->default_value(static_cast<int>(MSG::INFO)),
62  "message level")("file,f",
63  value<std::string>(&fileName)->default_value(""),
64  "scale factor file")(
65  "runno,r", value<int>(&runno)->required(), "run number: Required")(
66  "eta,e", value<float>(&eta)->required(), "eta: Required")(
67  "pt,p", value<float>(&pt)->required(), "pt: Required")(
68  "type,t",
69  value<std::string>(&type)->required(),
70  "Simulation type: Required")(
71  "correlation,c",
72  value<std::string>(&model)->default_value("FULL"),
73  "Correlation Model FULL (default),SIMPLIFIED,TOTAL,COMBMCTOYS")(
74  "keyreco,k",
75  value<std::string>(&recokey)->default_value(""),
76  "Reco working point Key")(
77  "mapfile,m",
78  value<std::string>(&mapfileName)->default_value(""),
79  "Map file name")("keyid,d",
80  value<std::string>(&idkey)->default_value(""),
81  "Identification working point Key")(
82  "keyiso,i",
83  value<std::string>(&isokey)->default_value(""),
84  "Isolation working point Key")(
85  "keytrigger,g",
86  value<std::string>(&triggerkey)->default_value(""),
87  "Trigger working point Key");
88  variables_map vm;
89  try {
90  store(parse_command_line(argc, argv, desc), vm);
91  if (vm.count("help")) {
92  ANA_MSG_INFO(desc << '\n');
93  return 0;
94  }
95  notify(vm);
96  } catch (const boost::program_options::error& ex) {
97  ANA_MSG_ERROR(ex.what() << '\n');
98  ANA_MSG_ERROR(desc << '\n');
99  return 0;
100  }
101 
102  if (!(type == "FullSim" || type == "AtlFast2")) {
103  ANA_MSG_ERROR("No valid type given (FullSim or AtlFast2)");
104  ANA_MSG_ERROR(desc << '\n');
105  return 0;
106  }
108  (type == "FullSim" ? PATCore::ParticleDataType::Full
110  if (!(model == "COMBMCTOYS" || model == "FULL" || model == "SIMPLIFIED" ||
111  model == "TOTAL")) {
112  ANA_MSG_ERROR("No valid correlation model");
113  ANA_MSG_ERROR(desc << '\n');
114  return 0;
115  }
116 
117  // Initialize the xAOD application
118  const char* APP_NAME = argv[0];
119  msg().setName(APP_NAME);
120  MSG::Level mylevel = static_cast<MSG::Level>(inputlevel);
121  setMsgLevel(mylevel);
122  msg().setName(APP_NAME);
124 
125  // Initialize the store
128 
129  // Configure the tool based on the inputs
131  ElEffCorrectionTool(
132  "AsgElectronEfficiencyCorrectionTool/ElEffCorrectionTool");
133  if (!fileName.empty()) {
134  std::vector<std::string> inputFiles{ fileName };
135  ANA_CHECK(
136  ElEffCorrectionTool.setProperty("CorrectionFileNameList", inputFiles));
137  }
138  if (!mapfileName.empty()) {
139  ANA_CHECK(ElEffCorrectionTool.setProperty("MapFilePath", mapfileName));
140  }
141  if (!recokey.empty()) {
142  ANA_CHECK(ElEffCorrectionTool.setProperty("RecoKey", recokey));
143  }
144  if (!idkey.empty()) {
145  ANA_CHECK(ElEffCorrectionTool.setProperty("IdKey", idkey));
146  }
147  if (!isokey.empty()) {
148  ANA_CHECK(ElEffCorrectionTool.setProperty("IsoKey", isokey));
149  }
150  if (!triggerkey.empty()) {
151  ANA_CHECK(ElEffCorrectionTool.setProperty("TriggerKey", triggerkey));
152  }
153  ANA_CHECK(ElEffCorrectionTool.setProperty("ForceDataType", (int)SimType));
154  ANA_CHECK(ElEffCorrectionTool.setProperty("OutputLevel", mylevel));
155  ANA_CHECK(ElEffCorrectionTool.setProperty("CorrelationModel", model));
156  ANA_CHECK(ElEffCorrectionTool.initialize());
157  if (mylevel < MSG::INFO) {
158  asg::ToolStore::dumpToolConfig();
159  }
160  /*
161  * create and then retrieve the dummy electrons (in this case is 1)
162  * This also setups the store,so for done before the tool init
163  * it really is a pseudo "reconstruction"
164  */
165  std::vector<std::pair<double, double>> pt_eta{ { pt, eta } };
166  ANA_CHECK(getElectrons(pt_eta, runno, store).isSuccess());
167  const xAOD::ElectronContainer* electrons(nullptr);
168  ANA_CHECK(store.retrieve(electrons, "MyElectrons").isSuccess());
169  // Loop over electrons , here it is one
170  xAOD::Electron el = *(electrons->at(0));
171  /*
172  * Potentiallly we can make this part more clever, for now since it is an
173  * util I did not try to optimise too much.
174  */
175  int index = ElEffCorrectionTool->systUncorrVariationIndex(el);
176  /*
177  * Set up the systematic variations
178  * 2 cases one for "continuous" one for "toys"
179  */
180  bool isToys = model.find("TOY") != std::string::npos;
181  double nominalSF{};
182  double totalNeg{};
183  double totalPos{};
185  ElEffCorrectionTool, el, nominalSF, totalPos, totalNeg, isToys) ==
186  0);
187 
188  ANA_MSG_INFO("===> Model : " << model << "| electron : Pt = " << el.pt()
189  << " : eta = " << el.eta() << " : Bin index = "
190  << index << " : SF = " << nominalSF << " + "
191  << totalPos << " - " << totalNeg << " <===");
192 
193  return 0;
194 }
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
index
Definition: index.py:1
Epos_Base_Fragment.inputFiles
string inputFiles
Definition: Epos_Base_Fragment.py:18
PATCore::ParticleDataType::Fast
@ Fast
Definition: PATCoreEnums.h:22
SFHelpers::result
int result(asg::StandaloneToolHandle< IAsgElectronEfficiencyCorrectionTool > &tool, const xAOD::Electron &el, double &nominalSF, double &totalPos, double &totalNeg, const bool isToys)
Definition: SFHelpers.cxx:20
asg
Definition: DataHandleTestTool.h:28
test_pyathena.pt
pt
Definition: test_pyathena.py:11
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
AsgElectronEfficiencyCorrectionTool.h
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
main
int main(int argc, char *argv[])
Definition: testEgEfficiencyCorrWithoutFile.cxx:35
PATCore::ParticleDataType::DataType
DataType
Definition: PATCoreEnums.h:22
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
PATCore::ParticleDataType::Full
@ Full
Definition: PATCoreEnums.h:22
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
asg::StandaloneToolHandle::initialize
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
Definition: StandaloneToolHandle.h:158
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition: StandaloneToolHandle.h:105
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
MessageCheck.h
macros for messaging and checking status codes
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
Init.h
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
asg::ANA_MSG_HEADER
ANA_MSG_HEADER(msgSTT) ANA_MSG_SOURCE(msgSTT
ANA_MSG_SOURCE
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:133
getElectrons
StatusCode getElectrons(const std::vector< std::pair< double, double >> &pt_eta, int runNumber, xAOD::TStore &store)
Definition: CreateDummyEl.cxx:71
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
CreateDummyEl.h
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
IAsgElectronEfficiencyCorrectionTool::systUncorrVariationIndex
virtual int systUncorrVariationIndex(const xAOD::Electron &inputObject) const =0
correlationModel::model
model
Definition: AsgElectronEfficiencyCorrectionTool.cxx:46
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
PURW_create_actual_mu_profile.runno
runno
Definition: PURW_create_actual_mu_profile.py:59
StandaloneToolHandle.h
get_generator_info.error
error
Definition: get_generator_info.py:40
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TStore.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31
SFHelpers.h
MsgStream.h