47int main(
int argc,
char* argv[]) {
53 Error(
APP_NAME,
"No file name received!");
61 Error(
APP_NAME,
"Failed to do xAOD::Init!" );
70 const TString fileName = argv[1];
71 Info(
APP_NAME,
"Opening file: %s", fileName.Data());
72 std::unique_ptr<TFile> ifile(TFile::Open(fileName,
"READ"));
74 Error(
APP_NAME,
"Failed to open input file!" );
79 if ( event.readFrom( ifile.get() ).isFailure() ) {
80 Error(
APP_NAME,
"Failed to read from input file!" );
83 Info(
APP_NAME,
"Number of events in the file: %i",
static_cast<int>(event.getEntries()));
86 Long64_t
entries =
event.getEntries();
88 const Long64_t e = atoll(argv[2]);
94 std::vector<std::string> WPnames = {
"Tight",
"Medium",
"Loose",
"VeryLoose",
"HighPt",
"LowPt",
"LowPtMVA"};
101 std::vector<std::string> padding;
104 unsigned int maxNameLength = 0;
105 for (
int wp = 0; wp < Nwp; wp++)
106 if (WPnames[wp].
size() > maxNameLength) maxNameLength = WPnames[wp].size();
108 for (
int wp = 0; wp < Nwp; wp++) {
109 std::string pad =
"";
110 for (
unsigned int i = 0; i < maxNameLength - WPnames[wp].size(); i++) pad +=
" ";
112 padding.push_back(pad);
116 std::string namesString =
" ";
117 for (
int wp = 0; wp < Nwp; wp++) namesString += WPnames[wp] +
" ";
125 int selectedMuons[Nwp];
126 for (
int wp = 0; wp < Nwp; wp++) selectedMuons[wp] = 0;
128 int selectedMuonsNotBad[Nwp];
129 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsNotBad[wp] = 0;
136 int allMuonsType[Ntype];
140 int selectedMuonsType[Ntype][Nwp];
142 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsType[
type][wp] = 0;
144 int selectedMuonsTypeNotBad[Ntype][Nwp];
146 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsTypeNotBad[
type][wp] = 0;
150 constexpr std::size_t nAuthor =
static_cast<int>(xAOD::Muon::Author::NumberOfMuonAuthors);
151 std::array<int, nAuthor> allMuonsAuthor{};
154 std::array<std::array<int, Nwp>, nAuthor> selectedMuonsAuthor{}, selectedMuonsAuthorNotBad{};
159 double etaCuts[Neta - 1] = {1.0, 2.0, 2.5};
161 std::string etaRegions =
"|eta| < 1.0 1.0 < |eta| < 2.0 2.0 < |eta| < 2.5 |eta| > 2.5";
164 int allMuonsEta[Neta];
165 for (
int eta = 0;
eta < Neta;
eta++) allMuonsEta[
eta] = 0;
168 int selectedMuonsEta[Neta][Nwp];
170 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsEta[
eta][wp] = 0;
172 int selectedMuonsEtaNotBad[Neta][Nwp];
174 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsEtaNotBad[
eta][wp] = 0;
177 const int NtruthType = 5;
179 std::string truthTypeNames[NtruthType] = {
"Prompt",
"Non-isolated",
"Hadron",
"Background",
"Other"};
182 int allMuonsTruthType[NtruthType];
183 for (
int truthType = 0; truthType < NtruthType; truthType++) allMuonsTruthType[truthType] = 0;
186 int selectedMuonsTruthType[NtruthType][Nwp];
187 for (
int truthType = 0; truthType < NtruthType; truthType++)
188 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsTruthType[truthType][wp] = 0;
190 int selectedMuonsTruthTypeNotBad[NtruthType][Nwp];
191 for (
int truthType = 0; truthType < NtruthType; truthType++)
192 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsTruthTypeNotBad[truthType][wp] = 0;
197 std::vector<std::unique_ptr<CP::MuonSelectionTool> > selectorTools;
198 selectorTools.clear();
201 for (Long64_t entry = 0; entry <
entries; ++entry) {
203 event.getEntry(entry);
206 int selectedMuonsEvent[Nwp];
207 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsEvent[wp] = 0;
209 int selectedMuonsEventNotBad[Nwp];
210 for (
int wp = 0; wp < Nwp; wp++) selectedMuonsEventNotBad[wp] = 0;
214 if ( event.retrieve( ei,
"EventInfo" ).isFailure() ) {
215 Error(
APP_NAME,
"Failed to read EventInfo!" );
225 if(isRun3) Info(
APP_NAME,
"setting up muon selection tools for Run3 geometry");
226 else Info(
APP_NAME,
"setting up muon selection tools for Run2 geometry");
228 for (
int wp = 0; wp < Nwp; wp++) {
229 Info(
APP_NAME,
"Creating selector tool for working point: %s ...", WPnames[wp].c_str());
232 muonSelection->
msg().setLevel(MSG::INFO);
235 failed = failed || muonSelection->setProperty(
"IsRun3Geo",isRun3).isFailure();
236 failed = failed || muonSelection->setProperty(
"MaxEta", 2.7).isFailure();
237 if (WPnames[wp] ==
"LowPtMVA") {
238 failed = failed || muonSelection->setProperty(
"MuQuality", 5).isFailure();
239 failed = failed || muonSelection->setProperty(
"UseMVALowPt",
true).isFailure();
242 failed = failed || muonSelection->setProperty(
"MuQuality", wp).isFailure();
244 failed = failed || muonSelection->setProperty(
"TurnOffMomCorr",
true).isFailure();
245 failed = failed || muonSelection->
initialize().isFailure();
248 Error(
APP_NAME,
"Failed to set up MuonSelectorTool for working point: %s !", WPnames[wp].c_str() );
252 selectorTools.emplace_back(muonSelection);
257 "===>>> start processing event #%i, "
258 "run #%i %i events processed so far <<<===",
259 static_cast<int>(ei->
eventNumber()),
static_cast<int>(ei->
runNumber()),
static_cast<int>(entry));
263 if ( event.retrieve( muons,
"Muons" ).isFailure() ) {
264 Error(
APP_NAME,
"Failed to read Muons container!" );
267 Info(
APP_NAME,
"Number of muons: %i",
static_cast<int>(muons->
size()));
269 xAOD::Muon::Quality my_quality;
270 bool passesIDRequirements;
271 bool passesPreselectionCuts;
278 for (; mu_itr != mu_end; ++mu_itr) {
279 int etaIndex = Neta - 1;
281 if (std::abs((*mu_itr)->eta()) < etaCuts[
eta]) {
287 allMuonsType[
static_cast<int>((*mu_itr)->muonType())]++;
288 allMuonsAuthor[
static_cast<int>((*mu_itr)->author())]++;
289 allMuonsEta[etaIndex]++;
292 Info(
APP_NAME,
"===== Muon number: %i",
static_cast<int>(muCounter));
297 int truthClass = isMC ? truthTypeAcc (**mu_itr) : -999;
311 allMuonsTruthType[truthType]++;
313 if ((*mu_itr)->charge() > 0)
318 passesIDRequirements = selectorTools[0]->passedIDCuts(**mu_itr);
319 passesPreselectionCuts = selectorTools[0]->passedMuonCuts(**mu_itr);
320 my_quality = selectorTools[0]->getQuality(**mu_itr);
323 if (isMC) Info(
APP_NAME,
"Muon truthType: %d (%s)", truthClass, truthTypeNames[truthType].c_str());
324 Info(
APP_NAME,
"Muon pT [GeV]: %g ", std::abs((*mu_itr)->pt()) / 1000.);
325 Info(
APP_NAME,
"Muon eta, phi: %g, %g ", (*mu_itr)->eta(), (*mu_itr)->phi());
327 std::stringstream sstr{};
328 sstr<<
"Muon muonType: "<<(*mu_itr)->muonType();
329 Info(
APP_NAME,
"%s", sstr.str().c_str());
332 std::stringstream sstr{};
333 sstr<<
"Muon primary author: "<<(*mu_itr)->author();
334 Info(
APP_NAME,
"%s", sstr.str().c_str());
336 std::stringstream sstr{};
337 sstr<<
"Muon quality (from tool, from xAOD): "<<my_quality<<
", "<<(*mu_itr)->quality();
338 Info(
APP_NAME,
"%s", sstr.str().c_str());
340 Info(
APP_NAME,
"Muon passes cuts (ID hits, preselection): %d, %d", passesIDRequirements, passesPreselectionCuts);
345 std::string selectionResults =
"Muon selection acceptance: ";
346 std::string badMuonResults =
"Bad muon flag: ";
348 for (
int wp = 0; wp < Nwp; wp++) {
349 if (selectorTools[wp]->accept(*mu_itr)) {
351 selectedMuonsEvent[wp]++;
352 selectedMuonsType[(*mu_itr)->muonType()][wp]++;
353 selectedMuonsAuthor[(*mu_itr)->author()][wp]++;
354 selectedMuonsTruthType[truthType][wp]++;
355 selectedMuonsEta[etaIndex][wp]++;
356 selectionResults +=
"pass ";
358 if (!selectorTools[wp]->isBadMuon(**mu_itr)) {
359 selectedMuonsNotBad[wp]++;
360 selectedMuonsEventNotBad[wp]++;
361 selectedMuonsTypeNotBad[(*mu_itr)->muonType()][wp]++;
362 selectedMuonsAuthorNotBad[(*mu_itr)->author()][wp]++;
363 selectedMuonsTruthTypeNotBad[truthType][wp]++;
364 selectedMuonsEtaNotBad[etaIndex][wp]++;
367 selectionResults +=
"fail ";
369 if (!selectorTools[wp]->isBadMuon(**mu_itr))
370 badMuonResults +=
"good ";
372 badMuonResults +=
"bad ";
376 Info(
APP_NAME,
"%s", namesString.c_str());
377 Info(
APP_NAME,
"%s", selectionResults.c_str());
378 Info(
APP_NAME,
"%s", badMuonResults.c_str());
383 std::string NselectedString =
"Number of selected muons: ";
384 std::string NselectedStringNotBad =
"Including bad muon veto: ";
385 for (
int wp = 0; wp < Nwp; wp++) {
386 NselectedString += std::to_string(selectedMuonsEvent[wp]) +
" ";
387 NselectedStringNotBad += std::to_string(selectedMuonsEventNotBad[wp]) +
" ";
390 Info(
APP_NAME,
"===== Event summary:");
391 Info(
APP_NAME,
"%s", namesString.c_str());
392 Info(
APP_NAME,
"%s", NselectedString.c_str());
393 Info(
APP_NAME,
"%s", NselectedStringNotBad.c_str());
397 "===>>> done processing event #%i, "
398 "run #%i %i events processed so far <<<===",
399 static_cast<int>(ei->
eventNumber()),
static_cast<int>(ei->
runNumber()),
static_cast<int>(entry + 1));
405 Info(
APP_NAME,
"======================================");
406 Info(
APP_NAME,
"========= Full run summary ===========");
407 Info(
APP_NAME,
"======================================");
409 Info(
APP_NAME,
"Processed %i events and %i muons",
static_cast<int>(
entries), allMuons);
411 Info(
APP_NAME,
"%i positive and %i negative muons", nPositive, nNegative);
413 Info(
APP_NAME,
"Selected muons by working point (numbers in parenthesis include bad muon veto):");
414 Info(
APP_NAME,
"--------------------------");
415 for (
int wp = 0; wp < Nwp; wp++)
416 Info(
APP_NAME,
"%s: %s %i (%i)", WPnames[wp].c_str(), padding[wp].c_str(), selectedMuons[wp], selectedMuonsNotBad[wp]);
417 Info(
APP_NAME,
"--------------------------");
420 Info(
APP_NAME,
"Selected muons by type and working point (numbers in parenthesis include bad muon veto):");
421 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
422 for (
int l = 0; l < Nwp + 2; l++) {
423 std::stringstream line{};
426 for (
int type = 0; type < Ntype; type++) line <<static_cast<xAOD::Muon::MuonType>(
type) <<
" ";
428 line <<
"All muons: ";
430 line << std::left << std::setw(16) << allMuonsType[
type];
434 line << WPnames[wp] <<
":" << padding[wp] <<
" ";
436 line << std::left << std::setw(16)
437 << selectedMuonsType[
type][wp]<<
" ("<<selectedMuonsTypeNotBad[
type][wp] <<
")";
441 Info(
APP_NAME,
"%s", line.str().c_str());
443 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
447 Info(
APP_NAME,
"Selected muons by primary author and working point (numbers in parenthesis include bad muon veto):");
448 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
449 for (
int l = 0; l < Nwp + 2; l++) {
450 std::stringstream line{};
453 for (
unsigned author = 0; author < nAuthor; author++) {
456 if (allMuonsAuthor[author] == 0)
continue;
458 line << static_cast<xAOD::Muon::Author>(author);
461 line <<
"All muons: ";
462 for (
unsigned author = 0; author < nAuthor; author++) {
464 if (allMuonsAuthor[author] == 0)
continue;
466 line << std::left << std::setw(16)<<allMuonsAuthor[author];
470 line << WPnames[wp] <<
":"<< padding[wp] <<
" ";
471 for (
unsigned author = 0; author < nAuthor; author++) {
473 if (allMuonsAuthor[author] == 0)
continue;
475 line << std::left << std::setw(16);
476 line << selectedMuonsAuthor[author][wp]<<
" ("
477 << selectedMuonsAuthorNotBad[author][wp]<<
")";
481 Info(
APP_NAME,
"%s", line.str().c_str());
483 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
487 Info(
APP_NAME,
"Selected muons by |eta| and working point (numbers in parenthesis include bad muon veto):");
488 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
489 for (
int l = 0; l < Nwp + 2; l++) {
490 std::string line =
"";
495 line +=
"All muons: ";
497 std::stringstream
ss;
498 ss << std::left << std::setw(20) << std::to_string(allMuonsEta[
eta]);
503 line += WPnames[wp] +
":" + padding[wp] +
" ";
505 std::stringstream
ss;
506 ss << std::left << std::setw(20)
507 << (std::to_string(selectedMuonsEta[
eta][wp]) +
" (" + std::to_string(selectedMuonsEtaNotBad[
eta][wp]) +
")");
514 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
518 Info(
APP_NAME,
"Selected muons by truth classification and working point (numbers in parenthesis include bad muon veto):");
519 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");
520 for (
int l = 0; l < Nwp + 2; l++) {
521 std::string line =
"";
524 for (
int truthType = 0; truthType < NtruthType; truthType++) line += truthTypeNames[truthType] +
" ";
526 line +=
"All muons: ";
527 for (
int truthType = 0; truthType < NtruthType; truthType++) {
528 std::stringstream
ss;
529 ss << std::left << std::setw(16) << std::to_string(allMuonsTruthType[truthType]);
534 line += WPnames[wp] +
":" + padding[wp] +
" ";
535 for (
int truthType = 0; truthType < NtruthType; truthType++) {
536 std::stringstream
ss;
537 ss << std::left << std::setw(16)
538 << (std::to_string(selectedMuonsTruthType[truthType][wp]) +
" (" +
539 std::to_string(selectedMuonsTruthTypeNotBad[truthType][wp]) +
")");
546 Info(
APP_NAME,
"---------------------------------------------------------------------------------------");