18 #include <TStopwatch.h>
22 #ifdef XAOD_STANDALONE
60 #ifdef XAOD_STANDALONE
87 Long64_t
entries =
event.getEntries();
89 const Long64_t
e = atoll(
argv[2]);
95 std::vector<std::string> WPnames = {
"Tight",
"Medium",
"Loose",
"VeryLoose",
"HighPt",
"LowPt",
"LowPtMVA"};
102 std::vector<std::string>
padding;
105 unsigned int maxNameLength = 0;
106 for (
int wp = 0;
wp < Nwp;
wp++)
107 if (WPnames[
wp].
size() > maxNameLength) maxNameLength = WPnames[
wp].size();
109 for (
int wp = 0;
wp < Nwp;
wp++) {
110 std::string pad =
"";
111 for (
unsigned int i = 0;
i < maxNameLength - WPnames[
wp].size();
i++) pad +=
" ";
117 std::string namesString =
" ";
118 for (
int wp = 0;
wp < Nwp;
wp++) namesString += WPnames[
wp] +
" ";
126 int selectedMuons[Nwp];
127 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuons[
wp] = 0;
129 int selectedMuonsNotBad[Nwp];
130 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsNotBad[
wp] = 0;
139 else if (
type == xAOD::Muon::MuonStandAlone)
141 else if (
type == xAOD::Muon::SegmentTagged)
143 else if (
type == xAOD::Muon::CaloTagged)
145 else if (
type == xAOD::Muon::SiliconAssociatedForwardMuon)
152 int allMuonsType[Ntype];
156 int selectedMuonsType[Ntype][Nwp];
158 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsType[
type][
wp] = 0;
160 int selectedMuonsTypeNotBad[Ntype][Nwp];
162 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsTypeNotBad[
type][
wp] = 0;
168 std::string authorNames[Nauthor];
171 authorNames[
author] =
"MuidCo";
173 authorNames[
author] =
"STACO";
175 authorNames[
author] =
"MuTag";
177 authorNames[
author] =
"MuTagIMO";
179 authorNames[
author] =
"MuidSA";
181 authorNames[
author] =
"MuGirl";
183 authorNames[
author] =
"MuGirlLowBeta";
185 authorNames[
author] =
"CaloTag";
187 authorNames[
author] =
"CaloLikelihood";
188 else if (
author == xAOD::Muon::CaloScore)
189 authorNames[
author] =
"CaloScore";
191 authorNames[
author] =
"ExtrapolateMuonToIP";
193 authorNames[
author] =
"unknown";
197 int allMuonsAuthor[Nauthor];
201 int selectedMuonsAuthor[Nauthor][Nwp];
203 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsAuthor[
author][
wp] = 0;
205 int selectedMuonsAuthorNotBad[Nauthor][Nwp];
207 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsAuthorNotBad[
author][
wp] = 0;
212 double etaCuts[Neta - 1] = {1.0, 2.0, 2.5};
214 std::string etaRegions =
"|eta| < 1.0 1.0 < |eta| < 2.0 2.0 < |eta| < 2.5 |eta| > 2.5";
217 int allMuonsEta[Neta];
218 for (
int eta = 0;
eta < Neta;
eta++) allMuonsEta[
eta] = 0;
221 int selectedMuonsEta[Neta][Nwp];
223 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsEta[
eta][
wp] = 0;
225 int selectedMuonsEtaNotBad[Neta][Nwp];
227 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsEtaNotBad[
eta][
wp] = 0;
230 const int NtruthType = 5;
232 std::string truthTypeNames[NtruthType] = {
"Prompt",
"Non-isolated",
"Hadron",
"Background",
"Other"};
235 int allMuonsTruthType[NtruthType];
239 int selectedMuonsTruthType[NtruthType][Nwp];
243 int selectedMuonsTruthTypeNotBad[NtruthType][Nwp];
245 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsTruthTypeNotBad[
truthType][
wp] = 0;
250 std::vector<std::unique_ptr<CP::MuonSelectionTool> > selectorTools;
251 selectorTools.clear();
256 event.getEntry(
entry);
259 int selectedMuonsEvent[Nwp];
260 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsEvent[
wp] = 0;
262 int selectedMuonsEventNotBad[Nwp];
263 for (
int wp = 0;
wp < Nwp;
wp++) selectedMuonsEventNotBad[
wp] = 0;
278 if(isRun3) Info(
APP_NAME,
"setting up muon selection tools for Run3 geometry");
279 else Info(
APP_NAME,
"setting up muon selection tools for Run2 geometry");
281 for (
int wp = 0;
wp < Nwp;
wp++) {
282 Info(
APP_NAME,
"Creating selector tool for working point: %s ...", WPnames[
wp].c_str());
285 muonSelection->
msg().setLevel(MSG::INFO);
288 failed = failed || muonSelection->setProperty(
"IsRun3Geo",isRun3).isFailure();
289 failed = failed || muonSelection->setProperty(
"MaxEta", 2.7).isFailure();
290 if (WPnames[
wp] ==
"LowPtMVA") {
291 failed = failed || muonSelection->setProperty(
"MuQuality", 5).isFailure();
292 failed = failed || muonSelection->setProperty(
"UseMVALowPt",
true).isFailure();
295 failed = failed || muonSelection->setProperty(
"MuQuality",
wp).isFailure();
297 failed = failed || muonSelection->setProperty(
"TurnOffMomCorr",
true).isFailure();
298 failed = failed || muonSelection->
initialize().isFailure();
301 Error(
APP_NAME,
"Failed to set up MuonSelectorTool for working point: %s !", WPnames[
wp].c_str() );
305 selectorTools.emplace_back(muonSelection);
310 "===>>> start processing event #%i, "
311 "run #%i %i events processed so far <<<===",
320 Info(
APP_NAME,
"Number of muons: %i",
static_cast<int>(muons->
size()));
322 xAOD::Muon::Quality my_quality;
323 bool passesIDRequirements;
324 bool passesPreselectionCuts;
331 for (; mu_itr != mu_end; ++mu_itr) {
332 int etaIndex = Neta - 1;
334 if (std::abs((*mu_itr)->eta()) < etaCuts[
eta]) {
340 allMuonsType[(*mu_itr)->muonType()]++;
341 allMuonsAuthor[(*mu_itr)->author()]++;
342 allMuonsEta[etaIndex]++;
345 Info(
APP_NAME,
"===== Muon number: %i",
static_cast<int>(muCounter));
350 int truthClass =
isMC ? truthTypeAcc (**mu_itr) : -999;
366 if ((*mu_itr)->charge() > 0)
371 passesIDRequirements = selectorTools[0]->passedIDCuts(**mu_itr);
372 passesPreselectionCuts = selectorTools[0]->passedMuonCuts(**mu_itr);
373 my_quality = selectorTools[0]->getQuality(**mu_itr);
377 Info(
APP_NAME,
"Muon pT [GeV]: %g ", std::abs((*mu_itr)->pt()) / 1000.);
378 Info(
APP_NAME,
"Muon eta, phi: %g, %g ", (*mu_itr)->eta(), (*mu_itr)->phi());
379 Info(
APP_NAME,
"Muon muonType: %d (%s)", (*mu_itr)->muonType(),
typeNames[(*mu_itr)->muonType()].c_str());
380 Info(
APP_NAME,
"Muon primary author: %d (%s)", (*mu_itr)->author(), authorNames[(*mu_itr)->author()].c_str());
382 Info(
APP_NAME,
"Muon quality (from tool, from xAOD): %d, %d", my_quality, (*mu_itr)->quality());
383 Info(
APP_NAME,
"Muon passes cuts (ID hits, preselection): %d, %d", passesIDRequirements, passesPreselectionCuts);
388 std::string selectionResults =
"Muon selection acceptance: ";
389 std::string badMuonResults =
"Bad muon flag: ";
391 for (
int wp = 0;
wp < Nwp;
wp++) {
392 if (selectorTools[
wp]->
accept(*mu_itr)) {
394 selectedMuonsEvent[
wp]++;
395 selectedMuonsType[(*mu_itr)->muonType()][
wp]++;
396 selectedMuonsAuthor[(*mu_itr)->author()][
wp]++;
398 selectedMuonsEta[etaIndex][
wp]++;
399 selectionResults +=
"pass ";
401 if (!selectorTools[
wp]->isBadMuon(**mu_itr)) {
402 selectedMuonsNotBad[
wp]++;
403 selectedMuonsEventNotBad[
wp]++;
404 selectedMuonsTypeNotBad[(*mu_itr)->muonType()][
wp]++;
405 selectedMuonsAuthorNotBad[(*mu_itr)->author()][
wp]++;
407 selectedMuonsEtaNotBad[etaIndex][
wp]++;
410 selectionResults +=
"fail ";
412 if (!selectorTools[
wp]->isBadMuon(**mu_itr))
413 badMuonResults +=
"good ";
415 badMuonResults +=
"bad ";
419 Info(
APP_NAME,
"%s", namesString.c_str());
420 Info(
APP_NAME,
"%s", selectionResults.c_str());
421 Info(
APP_NAME,
"%s", badMuonResults.c_str());
426 std::string NselectedString =
"Number of selected muons: ";
427 std::string NselectedStringNotBad =
"Including bad muon veto: ";
428 for (
int wp = 0;
wp < Nwp;
wp++) {
430 NselectedStringNotBad +=
std::to_string(selectedMuonsEventNotBad[
wp]) +
" ";
433 Info(
APP_NAME,
"===== Event summary:");
434 Info(
APP_NAME,
"%s", namesString.c_str());
435 Info(
APP_NAME,
"%s", NselectedString.c_str());
436 Info(
APP_NAME,
"%s", NselectedStringNotBad.c_str());
440 "===>>> done processing event #%i, "
441 "run #%i %i events processed so far <<<===",
448 Info(
APP_NAME,
"======================================");
449 Info(
APP_NAME,
"========= Full run summary ===========");
450 Info(
APP_NAME,
"======================================");
452 Info(
APP_NAME,
"Processed %i events and %i muons",
static_cast<int>(
entries), allMuons);
454 Info(
APP_NAME,
"%i positive and %i negative muons", nPositive, nNegative);
456 Info(
APP_NAME,
"Selected muons by working point (numbers in parenthesis include bad muon veto):");
457 Info(
APP_NAME,
"--------------------------");
458 for (
int wp = 0;
wp < Nwp;
wp++)
459 Info(
APP_NAME,
"%s: %s %i (%i)", WPnames[
wp].c_str(),
padding[
wp].c_str(), selectedMuons[
wp], selectedMuonsNotBad[
wp]);
460 Info(
APP_NAME,
"--------------------------");
463 Info(
APP_NAME,
"Selected muons by type and working point (numbers in parenthesis include bad muon veto):");
464 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
465 for (
int l = 0;
l < Nwp + 2;
l++) {
466 std::string
line =
"";
471 line +=
"All muons: ";
473 std::stringstream
ss;
481 std::stringstream
ss;
482 ss << std::left << std::setw(16)
490 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
494 Info(
APP_NAME,
"Selected muons by primary author and working point (numbers in parenthesis include bad muon veto):");
495 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
496 for (
int l = 0;
l < Nwp + 2;
l++) {
497 std::string
line =
"";
503 if (allMuonsAuthor[
author] == 0)
continue;
505 std::stringstream
ss;
506 ss << std::left << std::setw(16);
511 line +=
"All muons: ";
514 if (allMuonsAuthor[
author] == 0)
continue;
516 std::stringstream
ss;
517 ss << std::left << std::setw(16);
526 if (allMuonsAuthor[
author] == 0)
continue;
528 std::stringstream
ss;
529 ss << std::left << std::setw(16);
537 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
541 Info(
APP_NAME,
"Selected muons by |eta| and working point (numbers in parenthesis include bad muon veto):");
542 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
543 for (
int l = 0;
l < Nwp + 2;
l++) {
544 std::string
line =
"";
549 line +=
"All muons: ";
551 std::stringstream
ss;
559 std::stringstream
ss;
560 ss << std::left << std::setw(20)
568 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
572 Info(
APP_NAME,
"Selected muons by truth classification and working point (numbers in parenthesis include bad muon veto):");
573 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
574 for (
int l = 0;
l < Nwp + 2;
l++) {
575 std::string
line =
"";
580 line +=
"All muons: ";
582 std::stringstream
ss;
590 std::stringstream
ss;
591 ss << std::left << std::setw(16)
600 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");