30 asg::AsgMetadataTool(
"top::EventSaverxAODNext"),
32 m_outputFile(nullptr),
33 m_saveAllObjects(false) {
40 const std::vector<std::string>& extraBranches) {
47 m_config->createPersistentSettings(),
"TopPersistentSettings"),
48 "Failed to save TopPersistentSettings");
52 std::string eventInfoList = settings->value(
"EventVariableSaveList");
53 if (
config->isMC()) eventInfoList +=
".mcChannelNumber.mcEventWeights";
56 for (
const auto& branchName : extraBranches)
57 eventInfoList +=
"." + branchName;
59 evtStore()->event()->setAuxItemList(
"EventInfoAux.", eventInfoList);
63 std::string photonVariableSaveList = settings->value(
"PhotonVariableSaveList");
65 photonVariableSaveList +=
".truthType.truthOrigin";
68 for (
const auto& currentSystematic : *
m_config->systSgKeyMapPhotons()) {
69 std::string sgKey = currentSystematic.second;
70 evtStore()->event()->setAuxItemList(sgKey +
"Aux.", photonVariableSaveList);
76 std::string electronVariableSaveList = settings->value(
"ElectronVariableSaveList");
78 electronVariableSaveList +=
".truthType.truthOrigin";
81 for (
const auto& currentSystematic : *
m_config->systSgKeyMapElectrons()) {
82 std::string sgKey = currentSystematic.second;
83 evtStore()->event()->setAuxItemList(sgKey +
"Aux.", electronVariableSaveList);
89 std::string muonVariableSaveList = settings->value(
"MuonVariableSaveList");
96 for (
const auto& currentSystematic : *
m_config->systSgKeyMapMuons()) {
97 std::string sgKey = currentSystematic.second;
98 evtStore()->event()->setAuxItemList(sgKey +
"Aux.", muonVariableSaveList);
104 std::string tauVariableSaveList = settings->value(
"TauVariableSaveList");
106 for (
const auto& currentSystematic : *
m_config->systSgKeyMapTaus()) {
107 std::string sgKey = currentSystematic.second;
108 evtStore()->event()->setAuxItemList(sgKey +
"Aux.", tauVariableSaveList);
115 std::string jetVariableSaveList = settings->value(
"JetVariableSaveList");
117 for (
const auto& currentSystematic : *
m_config->systSgKeyMapJets(
false)) {
118 std::string sgKey = currentSystematic.second;
119 evtStore()->event()->setAuxItemList(sgKey +
"Aux.", jetVariableSaveList);
124 std::string jetVariableSaveList = settings->value(
"JetVariableSaveList");
126 for (
const auto& currentSystematic : *
m_config->systSgKeyMapLargeRJets()) {
127 std::string sgKey = currentSystematic.second;
128 evtStore()->event()->setAuxItemList(sgKey +
"Aux.", jetVariableSaveList);
133 std::string jetVariableSaveList = settings->value(
"JetVariableSaveList");
135 for (
const auto& currentSystematic : *
m_config->systSgKeyMapTrackJets()) {
136 std::string sgKey = currentSystematic.second;
137 evtStore()->event()->setAuxItemList(sgKey +
"Aux.", jetVariableSaveList);
143 std::string bTagVariableSaveList = settings->value(
"BTagVariableSaveList");
144 evtStore()->event()->setAuxItemList(
"BTagging_AntiKt4EMTopoAux.", bTagVariableSaveList);
153 m_config->sgKeyTopSystematicEvents()),
154 "Failed to retrieve xAOD::SystematicEventContainer");
159 bool saveEvent(
false), saveEventObjects(
false);
160 if (!
m_config->saveOnlySelectedEvents()) {
163 if (
m_config->saveOnlySelectedEvents()) {
164 for (
const auto *
x : *allSystematics) {
165 if (
x->auxdataConst<
char>(
m_config->passEventSelectionDecoration()) == 1) {
167 saveEventObjects =
true;
184 std::shared_ptr<ThinningMap_t> photonThinningMap =
savePhotons(saveEventObjects);
185 std::shared_ptr<ThinningMap_t> electronThinningMap =
saveElectrons(saveEventObjects);
186 std::shared_ptr<ThinningMap_t> muonThinningMap =
saveMuons(saveEventObjects);
187 std::shared_ptr<ThinningMap_t> tauThinningMap =
saveTaus(saveEventObjects);
188 std::shared_ptr<ThinningMap_t> jetThinningMap =
saveJets(saveEventObjects);
189 std::shared_ptr<ThinningMap_t> largeRJetThinningMap =
saveLargeRJets(saveEventObjects);
190 std::shared_ptr<ThinningMap_t> trackJetThinningMap =
saveTrackJets(saveEventObjects);
195 m_config->sgKeyTopSystematicEvents() +
"Aux.");
196 allSystematics_output->setStore(allSystematics_output_aux);
197 if (saveEventObjects) {
198 for (
const auto *systematicPtr : *allSystematics) {
199 if (!(systematicPtr->hashValue() ==
m_config->nominalHashValue() ||
m_config->doTightSysts() ||
200 m_config->doLooseSysts()))
continue;
202 out->makePrivateStore(*systematicPtr);
206 electronThinningMap));
209 out->setGoodTaus(
thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodTaus(), tauThinningMap));
210 out->setGoodJets(
thinObjectSelection(systematicPtr->hashValue(), systematicPtr->goodJets(), jetThinningMap));
212 largeRJetThinningMap));
214 trackJetThinningMap));
220 systematicPtr->hashValue())),
"Failed to retrieve MET");
224 evtStore()->event()->recordAux(
m_config->sgKeyMissingEt(systematicPtr->hashValue()) +
"Aux.");
225 output_met->setStore(output_met_aux);
226 for (
auto x : *
met) {
228 out->makePrivateStore(*
x);
232 systematicPtr->hashValue())),
"Failed to save MET");
236 m_config->sgKeyTopSystematicEvents()),
237 "Failed to record xAOD::SystematicEventContainer");
245 const std::vector<unsigned int>& objectList,
246 const std::shared_ptr<ThinningMap_t>& thinningMap)
249 std::vector<unsigned int>
out;
255 if (Itr == thinningMap->end()) {
256 Itr = thinningMap->find(
m_config->nominalHashValue());
260 if (Itr != thinningMap->end()) {
262 std::map<unsigned int, unsigned int> currentSystematicThinningMap = (*Itr).second;
266 for (
auto i : objectList) {
267 std::map<unsigned int, unsigned int>::const_iterator Itr2 = currentSystematicThinningMap.find(
i);
268 if (Itr2 != currentSystematicThinningMap.end()) {
269 out.push_back((*Itr2).second);
298 const bool saveEventObjects) {
299 std::shared_ptr<ThinningMap_t> thinningMap(
new ThinningMap_t);
301 for (
const auto& currentSystematic : *
m_config->systSgKeyMapPhotons()) {
302 std::map<unsigned int, unsigned int> currentSystematicThinningMap;
303 std::string sgKey = currentSystematic.second;
309 output->setStore(output_aux);
311 if (saveEventObjects) {
312 unsigned int index(0), indexReduced(0);
313 for (
const auto *
x : *xaod) {
315 if (
x->isAvailable<
char>(
"passPreORSelection")) {
316 if (
x->auxdataConst<
char>(
"passPreORSelection") == 1) {
320 if (
x->isAvailable<
char>(
"passPreORSelectionLoose")) {
321 if (
x->auxdataConst<
char>(
"passPreORSelectionLoose") == 1) {
327 currentSystematicThinningMap.insert(std::make_pair(
index, indexReduced));
329 out->makePrivateStore(*
x);
337 thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
345 const bool saveEventObjects) {
346 std::shared_ptr<ThinningMap_t> thinningMap(
new ThinningMap_t);
348 for (
const auto& currentSystematic : *
m_config->systSgKeyMapElectrons()) {
349 std::map<unsigned int, unsigned int> currentSystematicThinningMap;
350 std::string sgKey = currentSystematic.second;
356 output->setStore(output_aux);
358 if (saveEventObjects) {
359 unsigned int index(0), indexReduced(0);
360 for (
const auto *
x : *xaod) {
362 if (
x->isAvailable<
char>(
"passPreORSelection")) {
363 if (
x->auxdataConst<
char>(
"passPreORSelection") == 1) {
367 if (
x->isAvailable<
char>(
"passPreORSelectionLoose")) {
368 if (
x->auxdataConst<
char>(
"passPreORSelectionLoose") == 1) {
374 currentSystematicThinningMap.insert(std::make_pair(
index, indexReduced));
376 out->makePrivateStore(*
x);
383 for (std::map<unsigned int, unsigned int>::const_iterator
i = currentSystematicThinningMap.begin();
384 i != currentSystematicThinningMap.end(); ++
i) {
385 output->at((*i).second)->setCaloClusterLinks(xaod->at((*i).first)->caloClusterLinks());
389 thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
397 const bool saveEventObjects) {
398 std::shared_ptr<ThinningMap_t> thinningMap(
new ThinningMap_t);
400 for (
const auto& currentSystematic : *
m_config->systSgKeyMapMuons()) {
401 std::map<unsigned int, unsigned int> currentSystematicThinningMap;
402 std::string sgKey = currentSystematic.second;
408 output->setStore(output_aux);
410 if (saveEventObjects) {
411 unsigned int index(0), indexReduced(0);
412 for (
const auto *
x : *xaod) {
414 if (
x->isAvailable<
char>(
"passPreORSelection")) {
415 if (
x->auxdataConst<
char>(
"passPreORSelection") == 1) {
419 if (
x->isAvailable<
char>(
"passPreORSelectionLoose")) {
420 if (
x->auxdataConst<
char>(
"passPreORSelectionLoose") == 1) {
426 currentSystematicThinningMap.insert(std::make_pair(
index, indexReduced));
428 out->makePrivateStore(*
x);
436 thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
444 const bool saveEventObjects) {
445 std::shared_ptr<ThinningMap_t> thinningMap(
new ThinningMap_t);
447 for (
const auto& currentSystematic : *
m_config->systSgKeyMapTaus()) {
448 std::map<unsigned int, unsigned int> currentSystematicThinningMap;
449 std::string sgKey = currentSystematic.second;
455 output->setStore(output_aux);
457 if (saveEventObjects) {
458 unsigned int index(0), indexReduced(0);
459 for (
const auto *
x : *xaod) {
461 if (
x->isAvailable<
char>(
"passPreORSelection")) {
462 if (
x->auxdataConst<
char>(
"passPreORSelection") == 1) {
466 if (
x->isAvailable<
char>(
"passPreORSelectionLoose")) {
467 if (
x->auxdataConst<
char>(
"passPreORSelectionLoose") == 1) {
473 currentSystematicThinningMap.insert(std::make_pair(
index, indexReduced));
475 out->makePrivateStore(*
x);
483 thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
491 const bool saveEventObjects) {
492 std::shared_ptr<ThinningMap_t> thinningMap(
new ThinningMap_t);
494 for (
const auto& currentSystematic : *
m_config->systSgKeyMapJets(
false)) {
495 std::map<unsigned int, unsigned int> currentSystematicThinningMap;
496 std::string sgKey = currentSystematic.second;
502 output->setStore(output_aux);
504 if (saveEventObjects) {
505 unsigned int index(0), indexReduced(0);
506 for (
const auto *
x : *xaod) {
508 if (
x->isAvailable<
char>(
"passPreORSelection")) {
509 if (
x->auxdataConst<
char>(
"passPreORSelection") == 1) {
513 if (
x->isAvailable<
char>(
"passPreORSelectionLoose")) {
514 if (
x->auxdataConst<
char>(
"passPreORSelectionLoose") == 1) {
520 currentSystematicThinningMap.insert(std::make_pair(
index, indexReduced));
522 out->makePrivateStore(*
x);
530 for (
auto i : currentSystematicThinningMap) {
538 thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
546 const bool saveEventObjects) {
547 std::shared_ptr<ThinningMap_t> thinningMap(
new ThinningMap_t);
549 for (
const auto& currentSystematic : *
m_config->systSgKeyMapLargeRJets()) {
550 std::map<unsigned int, unsigned int> currentSystematicThinningMap;
551 std::string sgKey = currentSystematic.second;
557 output->setStore(output_aux);
559 if (saveEventObjects) {
560 unsigned int index(0), indexReduced(0);
561 for (
const auto *
x : *xaod) {
563 if (
x->isAvailable<
char>(
"passPreORSelection")) {
564 if (
x->auxdataConst<
char>(
"passPreORSelection") == 1) {
568 if (
x->isAvailable<
char>(
"passPreORSelectionLoose")) {
569 if (
x->auxdataConst<
char>(
"passPreORSelectionLoose") == 1) {
575 currentSystematicThinningMap.insert(std::make_pair(
index, indexReduced));
577 out->makePrivateStore(*
x);
585 for (
auto i : currentSystematicThinningMap) {
592 thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
600 const bool saveEventObjects) {
601 std::shared_ptr<ThinningMap_t> thinningMap(
new ThinningMap_t);
603 for (
const auto& currentSystematic : *
m_config->systSgKeyMapTrackJets()) {
604 std::map<unsigned int, unsigned int> currentSystematicThinningMap;
605 std::string sgKey = currentSystematic.second;
611 output->setStore(output_aux);
613 if (saveEventObjects) {
614 unsigned int index(0), indexReduced(0);
615 for (
const auto *
x : *xaod) {
617 if (
x->isAvailable<
char>(
"passPreORSelection")) {
618 if (
x->auxdataConst<
char>(
"passPreORSelection") == 1) {
622 if (
x->isAvailable<
char>(
"passPreORSelectionLoose")) {
623 if (
x->auxdataConst<
char>(
"passPreORSelectionLoose") == 1) {
629 currentSystematicThinningMap.insert(std::make_pair(
index, indexReduced));
631 out->makePrivateStore(*
x);
639 for (
auto i : currentSystematicThinningMap) {
646 thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap));
656 m_outputFile),
"EventSaverxAODNext::finalise trying to call finishWritingTo");