48int main(
int argc,
char* argv[]) {
54 Error(
APP_NAME,
"No file name received!");
62 Error(
APP_NAME,
"Failed to do xAOD::Init!" );
71 const TString fileName = argv[1];
72 Info(
APP_NAME,
"Opening file: %s", fileName.Data());
73 std::unique_ptr<TFile> ifile(TFile::Open(fileName,
"READ"));
75 Error(
APP_NAME,
"Failed to open input file!" );
80 if ( event.readFrom( ifile.get() ).isFailure() ) {
81 Error(
APP_NAME,
"Failed to read from input file!" );
84 Info(
APP_NAME,
"Number of events in the file: %i",
static_cast<int>(event.getEntries()));
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 +=
" ";
113 padding.push_back(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;
135 std::string typeNames[Ntype];
137 if (
type == xAOD::Muon::Combined)
138 typeNames[
type] =
"combined";
139 else if (
type == xAOD::Muon::MuonStandAlone)
140 typeNames[
type] =
"stand-alone";
141 else if (
type == xAOD::Muon::SegmentTagged)
142 typeNames[
type] =
"segment-tagged";
143 else if (
type == xAOD::Muon::CaloTagged)
144 typeNames[
type] =
"calo-tagged";
145 else if (
type == xAOD::Muon::SiliconAssociatedForwardMuon)
146 typeNames[
type] =
"forward";
148 typeNames[
type] =
"unknown";
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;
166 const int Nauthor = xAOD::Muon::NumberOfMuonAuthors;
168 std::string authorNames[Nauthor];
169 for (
int author = 0; author < Nauthor; author++) {
170 if (author == xAOD::Muon::MuidCo)
171 authorNames[author] =
"MuidCo";
172 else if (author == xAOD::Muon::STACO)
173 authorNames[author] =
"STACO";
174 else if (author == xAOD::Muon::MuTag)
175 authorNames[author] =
"MuTag";
176 else if (author == xAOD::Muon::MuTagIMO)
177 authorNames[author] =
"MuTagIMO";
178 else if (author == xAOD::Muon::MuidSA)
179 authorNames[author] =
"MuidSA";
180 else if (author == xAOD::Muon::MuGirl)
181 authorNames[author] =
"MuGirl";
182 else if (author == xAOD::Muon::MuGirlLowBeta)
183 authorNames[author] =
"MuGirlLowBeta";
184 else if (author == xAOD::Muon::CaloTag)
185 authorNames[author] =
"CaloTag";
186 else if (author == xAOD::Muon::CaloLikelihood)
187 authorNames[author] =
"CaloLikelihood";
188 else if (author == xAOD::Muon::CaloScore)
189 authorNames[author] =
"CaloScore";
190 else if (author == xAOD::Muon::ExtrapolateMuonToIP)
191 authorNames[author] =
"ExtrapolateMuonToIP";
193 authorNames[author] =
"unknown";
197 int allMuonsAuthor[Nauthor];
198 for (
int author = 0; author < Nauthor; author++) allMuonsAuthor[author] = 0;
201 int selectedMuonsAuthor[Nauthor][Nwp];
202 for (
int author = 0; author < Nauthor; author++)
203 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsAuthor[author][wp] = 0;
205 int selectedMuonsAuthorNotBad[Nauthor][Nwp];
206 for (
int author = 0; author < Nauthor; author++)
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];
236 for (
int truthType = 0; truthType < NtruthType; truthType++) allMuonsTruthType[truthType] = 0;
239 int selectedMuonsTruthType[NtruthType][Nwp];
240 for (
int truthType = 0; truthType < NtruthType; truthType++)
241 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsTruthType[truthType][wp] = 0;
243 int selectedMuonsTruthTypeNotBad[NtruthType][Nwp];
244 for (
int truthType = 0; truthType < NtruthType; truthType++)
245 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsTruthTypeNotBad[truthType][wp] = 0;
250 std::vector<std::unique_ptr<CP::MuonSelectionTool> > selectorTools;
251 selectorTools.clear();
254 for (Long64_t entry = 0; entry <
entries; ++entry) {
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;
267 if ( event.retrieve( ei,
"EventInfo" ).isFailure() ) {
268 Error(
APP_NAME,
"Failed to read EventInfo!" );
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 <<<===",
312 static_cast<int>(ei->
eventNumber()),
static_cast<int>(ei->
runNumber()),
static_cast<int>(entry));
316 if ( event.retrieve( muons,
"Muons" ).isFailure() ) {
317 Error(
APP_NAME,
"Failed to read Muons container!" );
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;
364 allMuonsTruthType[truthType]++;
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);
376 if (isMC) Info(
APP_NAME,
"Muon truthType: %d (%s)", truthClass, truthTypeNames[truthType].c_str());
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]++;
397 selectedMuonsTruthType[truthType][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]++;
406 selectedMuonsTruthTypeNotBad[truthType][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++) {
429 NselectedString += std::to_string(selectedMuonsEvent[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 <<<===",
442 static_cast<int>(ei->
eventNumber()),
static_cast<int>(ei->
runNumber()),
static_cast<int>(entry + 1));
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;
474 ss << std::left << std::setw(16) << std::to_string(allMuonsType[
type]);
479 line += WPnames[wp] +
":" + padding[wp] +
" ";
481 std::stringstream
ss;
482 ss << std::left << std::setw(16)
483 << (std::to_string(selectedMuonsType[
type][wp]) +
" (" + std::to_string(selectedMuonsTypeNotBad[
type][wp]) +
")");
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 =
"";
500 for (
int author = 0; author < Nauthor; author++) {
503 if (allMuonsAuthor[author] == 0)
continue;
505 std::stringstream
ss;
506 ss << std::left << std::setw(16);
507 ss << authorNames[author];
511 line +=
"All muons: ";
512 for (
int author = 0; author < Nauthor; author++) {
514 if (allMuonsAuthor[author] == 0)
continue;
516 std::stringstream
ss;
517 ss << std::left << std::setw(16);
518 ss << std::to_string(allMuonsAuthor[author]);
523 line += WPnames[wp] +
":" + padding[wp] +
" ";
524 for (
int author = 0; author < Nauthor; author++) {
526 if (allMuonsAuthor[author] == 0)
continue;
528 std::stringstream
ss;
529 ss << std::left << std::setw(16);
530 ss << (std::to_string(selectedMuonsAuthor[author][wp]) +
" (" + std::to_string(selectedMuonsAuthorNotBad[author][wp]) +
")");
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;
552 ss << std::left << std::setw(20) << std::to_string(allMuonsEta[
eta]);
557 line += WPnames[wp] +
":" + padding[wp] +
" ";
559 std::stringstream
ss;
560 ss << std::left << std::setw(20)
561 << (std::to_string(selectedMuonsEta[
eta][wp]) +
" (" + std::to_string(selectedMuonsEtaNotBad[
eta][wp]) +
")");
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 =
"";
578 for (
int truthType = 0; truthType < NtruthType; truthType++) line += truthTypeNames[truthType] +
" ";
580 line +=
"All muons: ";
581 for (
int truthType = 0; truthType < NtruthType; truthType++) {
582 std::stringstream
ss;
583 ss << std::left << std::setw(16) << std::to_string(allMuonsTruthType[truthType]);
588 line += WPnames[wp] +
":" + padding[wp] +
" ";
589 for (
int truthType = 0; truthType < NtruthType; truthType++) {
590 std::stringstream
ss;
591 ss << std::left << std::setw(16)
592 << (std::to_string(selectedMuonsTruthType[truthType][wp]) +
" (" +
593 std::to_string(selectedMuonsTruthTypeNotBad[truthType][wp]) +
")");
600 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");