![Logo](../../ATLAS-Logo-Square-Blue-RGB.png) |
ATLAS Offline Software
|
Go to the documentation of this file.
43 using namespace TopAnalysis;
48 throw std::runtime_error(
"Failed xAOD::Init - no idea what to do, exiting");
56 if (failOnUnchecked) {
57 StatusCode::enableFailure();
63 TTree* metaData =
dynamic_cast<TTree*
> (
inputFile->Get(
"MetaData"));
66 metaData->LoadTree(0);
68 TObjArray* ar = metaData->GetListOfBranches();
69 for (
int i = 0;
i < ar->GetEntries(); ++
i) {
70 TBranch*
b = (TBranch*) ar->At(
i);
71 std::string
name = std::string(
b->GetName());
74 if (
name.find(
"Stream") != std::string::npos) {
81 throw std::runtime_error(
"getDerivationStream: MetaData tree"
82 " missing from input file.");
86 throw std::runtime_error(
"Cannot determine the derivation stream. Please report.");
90 std::vector<std::string> &
names, std::vector<float>& sumW) {
93 const std::size_t modifiedSize = (
size == 0) ? 1 :
size;
95 std::vector<int> maxCycle;
97 for (std::size_t icbk = 0; icbk < modifiedSize; ++icbk) {
98 const std::string cbkName = (icbk == 0) ?
"CutBookkeepers" :
"CutBookkeepers_weight_" +
std::to_string(icbk);
106 if ((cbk->inputStream() !=
"StreamAOD"))
108 if (cbk->name() !=
"AllExecutedEvents")
continue;
113 if (pos_name ==
names.end()) {
115 maxCycle.push_back(cbk->cycle());
116 sumW.push_back(cbk->sumOfEventWeights());
117 }
else if (cbk->cycle() > maxCycle.at(pos_name -
names.begin())) {
118 maxCycle.at(pos_name -
names.begin()) = cbk->cycle();
119 sumW.at(pos_name -
names.begin()) = cbk->sumOfEventWeights();
127 ULong64_t rawEntries = 0;
130 if ((cbk->inputStream() !=
"StreamAOD"))
132 if (cbk->name() !=
"AllExecutedEvents")
134 if (cbk->cycle() > maxCycle) {
135 rawEntries = cbk->nAcceptedEvents();
136 maxCycle = cbk->cycle();
144 const std::vector<std::string>& pmg_weight_names) {
147 static const std::string name_prefix =
"AllExecutedEvents_weight_";
150 if (pmg_weight_names.size() > 1) {
151 if (bookkeeper_names.size() != pmg_weight_names.size()) {
154 throw std::runtime_error(
"ERROR: The number of CutBookkeepers does not match the number of MC generator weights in metadata! Cannot match nominal MC weight to nominal sum of weights!");
159 for (std::string &
name : bookkeeper_names) {
161 int index = std::stoi(
name.erase(0, name_prefix.size()));
166 if (bookkeeper_names.size() == 1) {
167 bookkeeper_names[0] =
"nominal";
169 ATH_MSG_INFO(
"WARNING: PMGTruthWeightTool reports no extra MC generator weight variations, "
170 <<
"but this sample does not have exactly one AllExecutedEvents* bookkeeper!\n"
171 <<
"This means we can't guarantee that the correct CutBookkeeper "
172 <<
"is used for the sum of weights!");
178 std::vector<std::string>
v;
183 throw std::runtime_error(
"Problem opening " +
filename);
187 while (std::getline(in,
str)) {
188 std::string newstring(
str);
190 if (
str.find(
'#') != std::string::npos) newstring =
str.substr(0,
str.find(
'#'));
193 while (std::isspace(*newstring.begin()))
194 newstring.erase(newstring.begin());
196 while (std::isspace(*newstring.rbegin()))
197 newstring.erase(newstring.length() - 1);
200 if (newstring.size() > 0)
v.push_back(newstring);
209 size_t totalYield = 0;
212 std::unique_ptr<TFile>
f(TFile::Open(
filename.c_str()));
216 throw std::runtime_error(
"Did not manage to open " +
filename);
219 const TTree*
const t =
dynamic_cast<TTree*
> (
f->Get(
"CollectionTree"));
228 else note =
" (No CollectionTree)";
240 std::ifstream ifs(
filename.c_str());
243 throw std::runtime_error(
"File does not exist " +
filename
244 +
"\nThis should contain a list - comma separated list of input files.");
248 std::stringstream wholefile;
255 std::getline(ifs,
line);
256 wholefile <<
line <<
',';
264 while (std::getline(wholefile,
to,
',')) {
269 throw std::runtime_error(
"Could not get a list of input files from " +
filename);
276 std::vector<std::string>
tokens;
278 std::stringstream
ss(libraryNames);
281 while (std::getline(
ss,
item, delim))
284 std::vector<std::unique_ptr<top::ToolLoaderBase> > toolLoaders;
285 for (
const auto& toolLoaderName :
tokens) {
286 ATH_MSG_INFO(
"Attempting to load library: " << toolLoaderName <<
".so");
287 gSystem->Load((toolLoaderName +
".so").c_str());
292 ATH_MSG_INFO(
"Attempting to load ObjectSelection: " <<
config->objectSelectionName());
293 TClass*
c = ::TClass::GetClass(
config->objectSelectionName().c_str());
296 throw std::runtime_error(
"Didn't manage to load " +
config->objectSelectionName());
302 throw std::runtime_error(
"Didn't manage to cast it to top::ObjectLoaderBase");
307 if (objectSelection ==
nullptr) {
308 throw std::runtime_error(
"Didn't manage to make a top::ObjectSelection class");
311 return objectSelection;
316 TClass*
c = ::TClass::GetClass(
config->outputFormat().c_str());
319 throw std::runtime_error(
"Didn't manage to load " +
config->outputFormat());
325 throw std::runtime_error(
"Didn't manage to cast it to top::EventSaverBase ");
348 "Failed to retrieve metadata from AsgMetadataTool");
352 ATH_MSG_ERROR(
"Could not read FileMetaData inside MetaData tree.");
361 std::string
dataType=
"?", simFlavour=
"?";
363 bool isDataOverlay =
false;
368 if (
dataType.find(
"StreamDAOD") != std::string::npos) {
372 config->setIsTruthDxAOD((
stream.find(
"TRUTH") != std::string::npos));
375 <<
" does not appear to be a StreamDAOD_*, so we cannot determine derivation type.");
380 config->setIsDataOverlay(isDataOverlay);
392 if (simFlavour ==
"FullG4") {
394 }
else if (simFlavour ==
"FullG4_QS") {
396 }
else if (simFlavour ==
"FullG4_LongLived") {
398 }
else if (simFlavour ==
"ATLFASTII") {
400 }
else if (simFlavour ==
"ATLFAST3_QS") {
402 }
else if (
config->isTruthDxAOD()) {
405 ATH_MSG_ERROR(
"Unsupported simFlavour detected in xAOD::FileMetaData: " << simFlavour);
406 throw std::runtime_error(
"Unsupported simFlavour detected, exiting");
411 ATH_MSG_INFO(
"Reading the following options from FileMetaData:\n"
412 <<
"dataType -> " <<
dataType <<
"\n"
414 <<
"isMC -> " <<
isMC <<
"\n"
415 <<
"simFlavour -> " << simFlavour <<
"\n"
416 <<
"isDataOverlay -> " << isDataOverlay);
void readMetaData(const xAOD::FileMetaData *FMD, const std::shared_ptr< top::TopConfig > &config)
Retrieve metadata from xAOD::FileMetaData object, to be stored in the TopConfig instance.
void loadLibraries(const std::string &libraryNames)
So that we can load external libraries with (1) extra event selection tools in, (2) user defined obje...
TopConfig A simple configuration that is NOT a singleton.
std::string find(const std::string &s)
return a remapped string
People seem to want to be able to configure the objects used in their anaysis for some reason.
static void enableFailure() noexcept
Description of the class that is used to keep track of event counts.
std::vector< std::string > loadCuts(const std::string &filename)
Load the file and make a vector of the cuts to pass on to the selection tool.
virtual top::TopObjectSelection * init(std::shared_ptr< top::TopConfig > topConfig)=0
Must implement this to load your own object selection.
size_t checkFiles(const std::vector< std::string > &filenames)
Open each file in the vector and get the number of events in it.
top::TopObjectSelection * loadObjectSelection(const std::shared_ptr< top::TopConfig > &config)
Users may want to define (and load!) their own object selection.
@ kClassAccess
Access auxiliary data using the aux containers.
std::vector< std::string > fileList(const std::string &filename)
Given a filename for a text file, parse it and extract a list of root files.
std::string getDerivationStream(TFile *inputFile)
Function to determine the derivation type using string manipulation.
Configure the object selection used in the analysis.
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)
Function loading a given entry of the input TTree.
void xAODInit(bool failOnUnchecked)
A little wrapper for the xAOD tools.
A base class so users can write their own event saving stuff.
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
void parseCutBookkeepers(xAOD::TEvent &xaodEvent, const std::size_t size, std::vector< std::string > &names, std::vector< float > &sumW)
Search bookkeepers for ones matching AllExecutedEvents, and which originate from AOD before skimming.
Container that holds the Container of all CutBookkeepers.
ULong64_t getRawEventsBookkeeper(const xAOD::CutBookkeeperContainer *cutBookKeepers)
Get raw number of events before skimming from "AllExecutedEvents" bookkeeper.
std::string to_string(const DetectorType &type)
StatusCode retrieveMetaInput(const T *&obj, const std::string &key)
Retrieve an input metadata object.
#define ATH_MSG_WARNING(x)
void renameCutBookkeepers(std::vector< std::string > &bookkeeper_names, const std::vector< std::string > &pmg_weight_names)
Rename CutBookkeeper names according to MC generator weight names reported by PMGTruthWeightTool.
StatusCode readFrom(::TFile *file, Bool_t useTreeCache=kTRUE, const char *treeName=EVENT_TREE_NAME)
Connect the object to a new input file.
top::EventSaverBase * loadEventSaver(const std::shared_ptr< top::TopConfig > &config)
Users may also want to write out custom ntuples / xAODs.
Tool for accessing xAOD files outside of Athena.
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.