13 #include <TStopwatch.h>
38 #define CHECK_CPSys(Arg) \
39 if (Arg.isFailure()){ \
40 Warning(#Arg,"Unsupported systematic (in line %i) ",__LINE__); \
43 static const std::vector<std::string> qualities {
"HighPt",
"Tight",
"Medium",
"Loose",
"LowPt" };
44 static const std::vector<std::string> binnings {
"coarse",
"fine" };
45 static const std::vector<std::string> types {
"data",
"mc" };
49 std::size_t
index = trigger.find(
"HLT_mu");
50 if (
index != std::string::npos) {
51 std::string rawNumber = trigger.substr(
index + 6);
52 if (!rawNumber.empty() && isdigit(rawNumber[0])) {
53 std::stringstream(rawNumber) >>
threshold;
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++) {
88 tool->msg().setLevel( MSG::WARNING );
110 for (
size_t i = 0;
i < qualities.size();
i++) {
111 for (
size_t j = 0; j < binnings.size(); j++) {
115 if(muons->
size() != 2)
117 if(binnings[j] ==
"coarse")
123 for(
auto muon : *muons)
138 Error(
"MuonTriggerSFRootCoreTest",
"Could not extract threshold for trigger %s",
m_trigger.c_str());
144 bool displayWarning =
false;
148 double efficiencyMC = 0.;
149 double efficiencyData = 0.;
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());
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());
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());
180 double triggerSF = 0.;
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());
187 if (triggerSF < 0.2 || triggerSF > 1.2) {
192 Error(
"MuonTriggerSFRootCoreTest",
"Could not extract threshold for trigger %s",
m_trigger.c_str());
195 bool displayWarning =
false;
198 if ((**mu_itr).pt() >=
threshold and std::abs((**mu_itr).eta()) < 2.5) displayWarning =
true;
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());
217 for (
size_t l = 0;
l < types.size();
l++) {
218 if (types[
l] !=
"data" ||
m_systematics[isystematic].
name().
find(
"TrigSystUncertainty") == std::string::npos) {
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());
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());
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());
239 double triggerSF = 0.;
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());
245 if (triggerSF < 0.2 || triggerSF > 1.2) {
250 Error(
"MuonTriggerSFRootCoreTest",
"Could not extract threshold for trigger %s",
m_trigger.c_str());
253 bool displayWarning =
false;
256 if ((**mu_itr).pt() >=
threshold and std::abs((**mu_itr).eta()) < 2.5) displayWarning =
true;
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());
264 double tmpEffData = 1.;
265 double tmpEffMC = 1.;
266 for (
auto muon: *muons) {
269 double scaleFactor = 0.;
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());
275 Error(
"MuonTriggerSFRootCoreTest",
"Could not extract MC trigger efficiency for %s",
m_trigger.c_str());
279 Error(
"MuonTriggerSFRootCoreTest",
"Could not extract MC trigger efficiency for %s",
m_trigger.c_str());
282 if (scaleFactor < 0.2 || scaleFactor > 1.2 ) {
285 Error(
"MuonTriggerSFRootCoreTest",
"Could not extract threshold for trigger %s",
m_trigger.c_str());
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());
291 tmpEffData *= 1.-effData;
292 tmpEffMC *= 1.-effMC;
294 auto sfSingleCalc = (1. - tmpEffData)/(1. - tmpEffMC);
295 if ( triggerSF > 0.2 && (sfSingleCalc - triggerSF) / triggerSF > 0.02) {
322 const char* xAODFileName =
"";
323 std::string customInputFolder =
"";
324 std::string customFileName =
"";
325 const char* nrOfEntries =
"";
326 std::string trigger =
"";
329 for (
int i = 1;
i <
argc - 1;
i++) {
330 std::string
arg = std::string(
argv[
i]);
332 xAODFileName =
argv[
i + 1];
334 else if (
arg ==
"-d")
335 customInputFolder =
argv[
i + 1];
336 else if (
arg ==
"-f")
337 customFileName =
argv[
i + 1];
338 else if (
arg ==
"-e")
339 nrOfEntries =
argv[
i + 1];
340 else if (
arg ==
"-t")
341 trigger =
argv[
i + 1];
342 else if (
arg ==
"-y")
344 else if (
arg ==
"-p")
349 if (xAODFileName[0] ==
'\0') {
358 Error(
APP_NAME,
" Usage: %s -x [xAOD file name] -y [year] -p [period] -t [trigger] -d [custom input folder] -f [custom file name] -e [number of events to process]",
APP_NAME);
364 Info(
APP_NAME,
"Opening file: %s", xAODFileName);
365 std::unique_ptr<TFile>
ifile(TFile::Open(xAODFileName,
"READ"));
376 int nrOfEntriesToRunOver = 1000;
377 if (!std::string(nrOfEntries).
empty()) {
378 int e = atoll(nrOfEntries);
379 if (
e < nrOfEntriesToRunOver) {
380 nrOfEntriesToRunOver =
e;
389 event.getEntry(
entry);