Skip to content
Snippets Groups Projects
Commit d1aba1da authored by Nils Erik Krumnack's avatar Nils Erik Krumnack Committed by Magnar Kopangen Bugge
Browse files

Merge branch '21.2-truthClassifierInMSTT' into '21.2'

21.2 MC truth classifier in MuonSelectorToolsTester

See merge request atlas/athena!38341
parent 81511495
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ if( XAOD_STANDALONE ) ...@@ -33,7 +33,7 @@ if( XAOD_STANDALONE )
atlas_add_executable( MuonSelectorToolsTester atlas_add_executable( MuonSelectorToolsTester
util/MuonSelectorToolsTester.cxx util/MuonSelectorToolsTester.cxx
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} xAODRootAccess xAODEventInfo xAODMuon LINK_LIBRARIES ${ROOT_LIBRARIES} xAODRootAccess xAODEventInfo xAODMuon MCTruthClassifierLib
xAODTracking xAODCore MuonSelectorToolsLib ) xAODTracking xAODCore MuonSelectorToolsLib )
endif() endif()
......
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#include "xAODCore/tools/IOStats.h" #include "xAODCore/tools/IOStats.h"
#include "xAODCore/tools/ReadStats.h" #include "xAODCore/tools/ReadStats.h"
// Truth classification
#include "MCTruthClassifier/MCTruthClassifier.h"
#include "MCTruthClassifier/MCTruthClassifierDefs.h"
/// Example of how to run the MuonSelectorTools package to obtain information from muons /// Example of how to run the MuonSelectorTools package to obtain information from muons
int main( int argc, char* argv[] ) { int main( int argc, char* argv[] ) {
...@@ -143,6 +147,7 @@ int main( int argc, char* argv[] ) { ...@@ -143,6 +147,7 @@ int main( int argc, char* argv[] ) {
for (int wp = 0; wp < Nwp; wp++) for (int wp = 0; wp < Nwp; wp++)
selectedMuonsNotBad[wp] = 0; selectedMuonsNotBad[wp] = 0;
//Obtain summary information also split by muon type //Obtain summary information also split by muon type
const int Ntype = 5; const int Ntype = 5;
...@@ -163,7 +168,6 @@ int main( int argc, char* argv[] ) { ...@@ -163,7 +168,6 @@ int main( int argc, char* argv[] ) {
typeNames[type] = "unknown"; typeNames[type] = "unknown";
} }
//Muon counters for each type //Muon counters for each type
int allMuonsType[Ntype]; int allMuonsType[Ntype];
for (int type = 0; type < Ntype; type++) for (int type = 0; type < Ntype; type++)
...@@ -206,6 +210,35 @@ int main( int argc, char* argv[] ) { ...@@ -206,6 +210,35 @@ int main( int argc, char* argv[] ) {
//Obtain summary information also split by muon truth type
const int NtruthType = 5;
std::string truthTypeNames[NtruthType] = {"Prompt", "Non-isolated", "Hadron", "Background", "Other"};
//Muon counters for each truth type
int allMuonsTruthType[NtruthType];
for (int truthType = 0; truthType < NtruthType; truthType++)
allMuonsTruthType[truthType] = 0;
//Muon counters for muons of each type passing each working point
int selectedMuonsTruthType[NtruthType][Nwp];
for (int truthType = 0; truthType < NtruthType; truthType++)
for (int wp = 0; wp < Nwp; wp++)
selectedMuonsTruthType[truthType][wp] = 0;
int selectedMuonsTruthTypeNotBad[NtruthType][Nwp];
for (int truthType = 0; truthType < NtruthType; truthType++)
for (int wp = 0; wp < Nwp; wp++)
selectedMuonsTruthTypeNotBad[truthType][wp] = 0;
//Truth classifier
bool isMC = false;
MCTruthClassifier truthClassifier("truthClassifier");
CHECK( truthClassifier.initialize() );
// Loop over the events: // Loop over the events:
for( Long64_t entry = 0; entry < entries; ++entry ) { for( Long64_t entry = 0; entry < entries; ++entry ) {
...@@ -265,20 +298,39 @@ int main( int argc, char* argv[] ) { ...@@ -265,20 +298,39 @@ int main( int argc, char* argv[] ) {
static_cast< int >( muCounter ) ); static_cast< int >( muCounter ) );
//Check truth origin
isMC = ei->eventType(xAOD::EventInfo::IS_SIMULATION);
std::pair<MCTruthPartClassifier::ParticleType,MCTruthPartClassifier::ParticleOrigin> truthClassification = truthClassifier.particleTruthClassifier(*mu_itr);
int truthType;
if (truthClassification.first == MCTruthPartClassifier::IsoMuon)
truthType = 0;
else if (truthClassification.first == MCTruthPartClassifier::NonIsoMuon)
truthType = 1;
else if (truthClassification.first == MCTruthPartClassifier::Hadron)
truthType = 2;
else if (truthClassification.first == MCTruthPartClassifier::BkgMuon)
truthType = 3;
else
truthType = 4;
allMuonsTruthType[truthType]++;
if((*mu_itr)->charge() > 0) if((*mu_itr)->charge() > 0)
nPositive++; nPositive++;
else else
nNegative++; nNegative++;
passesIDRequirements = selectorTools[0]->passedIDCuts(**mu_itr); passesIDRequirements = selectorTools[0]->passedIDCuts(**mu_itr);
passesPreselectionCuts = selectorTools[0]->passedMuonCuts(**mu_itr); passesPreselectionCuts = selectorTools[0]->passedMuonCuts(**mu_itr);
my_quality = selectorTools[0]->getQuality(**mu_itr); my_quality = selectorTools[0]->getQuality(**mu_itr);
//Print some general information about the muon //Print some general information about the muon
Info( APP_NAME, "Muon pT [GeV]: %g ", std::abs((*mu_itr)->pt())/1000.); if (isMC)
Info( APP_NAME, "Muon eta, phi: %g, %g ", (*mu_itr)->eta(),(*mu_itr)->phi()); Info( APP_NAME, "Muon truthType: %d (%s)", truthClassification.first, truthTypeNames[truthType].c_str());
Info( APP_NAME, "Muon muonType: %d (%s)", (*mu_itr)->muonType(), typeNames[(*mu_itr)->muonType()].c_str()); Info( APP_NAME, "Muon pT [GeV]: %g ", std::abs((*mu_itr)->pt())/1000.);
Info( APP_NAME, "Muon eta, phi: %g, %g ", (*mu_itr)->eta(),(*mu_itr)->phi());
Info( APP_NAME, "Muon muonType: %d (%s)", (*mu_itr)->muonType(), typeNames[(*mu_itr)->muonType()].c_str());
Info( APP_NAME, "Muon quality (from tool, from xAOD): %d, %d", my_quality, (*mu_itr)->quality()); Info( APP_NAME, "Muon quality (from tool, from xAOD): %d, %d", my_quality, (*mu_itr)->quality());
Info( APP_NAME, "Muon passes cuts (ID hits, preselection): %d, %d", passesIDRequirements, passesPreselectionCuts); Info( APP_NAME, "Muon passes cuts (ID hits, preselection): %d, %d", passesIDRequirements, passesPreselectionCuts);
...@@ -333,6 +385,7 @@ int main( int argc, char* argv[] ) { ...@@ -333,6 +385,7 @@ int main( int argc, char* argv[] ) {
selectedMuons[wp]++; selectedMuons[wp]++;
selectedMuonsEvent[wp]++; selectedMuonsEvent[wp]++;
selectedMuonsType[(*mu_itr)->muonType()][wp]++; selectedMuonsType[(*mu_itr)->muonType()][wp]++;
selectedMuonsTruthType[truthType][wp]++;
selectedMuonsEta[etaIndex][wp]++; selectedMuonsEta[etaIndex][wp]++;
selectionResults += "pass "; selectionResults += "pass ";
...@@ -340,6 +393,7 @@ int main( int argc, char* argv[] ) { ...@@ -340,6 +393,7 @@ int main( int argc, char* argv[] ) {
selectedMuonsNotBad[wp]++; selectedMuonsNotBad[wp]++;
selectedMuonsEventNotBad[wp]++; selectedMuonsEventNotBad[wp]++;
selectedMuonsTypeNotBad[(*mu_itr)->muonType()][wp]++; selectedMuonsTypeNotBad[(*mu_itr)->muonType()][wp]++;
selectedMuonsTruthTypeNotBad[truthType][wp]++;
selectedMuonsEtaNotBad[etaIndex][wp]++; selectedMuonsEtaNotBad[etaIndex][wp]++;
} }
} }
...@@ -466,6 +520,43 @@ int main( int argc, char* argv[] ) { ...@@ -466,6 +520,43 @@ int main( int argc, char* argv[] ) {
} }
Info(APP_NAME, "---------------------------------------------------------------------------------------"); Info(APP_NAME, "---------------------------------------------------------------------------------------");
//Make table of selected muons by truth type and working point
if (isMC) {
Info(APP_NAME, "Selected muons by truth classification and working point (numbers in parenthesis include bad muon veto):");
Info(APP_NAME, "---------------------------------------------------------------------------------------");
for (int l = 0; l < Nwp+2; l++) {
std::string line = "";
if (l == 0) { //line with truth classification labels
line += " ";
for (int truthType = 0; truthType < NtruthType; truthType++)
line += truthTypeNames[truthType] + " ";
}
else if (l == 1) { //line for all muons inclusive
line += "All muons: ";
for (int truthType = 0; truthType < NtruthType; truthType++) {
std::stringstream ss;
ss << std::left << std::setw(16) << std::to_string(allMuonsTruthType[truthType]);
line += ss.str();
}
}
else { //lines for each of the working points
int wp = l - 2;
line += WPnames[wp] + ":" + padding[wp] + " ";
for (int truthType = 0; truthType < NtruthType; truthType++) {
std::stringstream ss;
ss << std::left << std::setw(16) << (std::to_string(selectedMuonsTruthType[truthType][wp]) + " (" + std::to_string(selectedMuonsTruthTypeNotBad[truthType][wp]) + ")");
line += ss.str();
}
}
Info(APP_NAME, "%s", line.c_str());
}
Info(APP_NAME, "---------------------------------------------------------------------------------------");
}
// Needed for Smart Slimming // Needed for Smart Slimming
xAOD::IOStats::instance().stats().printSmartSlimmingBranchList(); xAOD::IOStats::instance().stats().printSmartSlimmingBranchList();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment