JetObjectCollectionMaker.cxx 40 KB
Newer Older
1
/*
Tomas Dado's avatar
Tomas Dado committed
2
   Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
4
*/

Tomas Dado's avatar
Tomas Dado committed
5
// $Id: JetObjectCollectionMaker.cxx 809674 2017-08-23 14:10:24Z iconnell $
6
7
#include "TopSystematicObjectMaker/JetObjectCollectionMaker.h"
#include "TopConfiguration/TopConfig.h"
Tomas Dado's avatar
Tomas Dado committed
8
#include "TopConfiguration/TreeFilter.h"
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "TopEvent/EventTools.h"

#include "xAODJet/JetContainer.h"
#include "xAODJet/JetAuxContainer.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODCore/ShallowCopy.h"
#include "xAODBase/IParticleHelpers.h"
#include "xAODMissingET/MissingETContainer.h"
#include "PATInterfaces/SystematicsUtil.h"

#include "TopJetSubstructure/TopJetSubstructure.h"
#include "TopJetSubstructure/LargeJetTrimmer.h"
#include "TopJetSubstructure/SubjetMaker.h"

Tomas Dado's avatar
Tomas Dado committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
namespace top {
  JetObjectCollectionMaker::JetObjectCollectionMaker(const std::string& name) :
    asg::AsgTool(name),
    m_config(nullptr),
    m_doJER(false),
    m_doFull_JER(false),
    m_doFull_JER_Pseudodata(false),
    m_isMC(false),
    m_doMultipleJES(false),

    m_specifiedSystematics(),
    m_specifiedSystematicsLargeR(),
    m_specifiedSystematicsTrackJets(),
    m_recommendedSystematics(),
    m_nominalSystematicSet(),

    m_jetCalibrationTool("JetCalibrationTool"),
    m_jetCalibrationToolLargeR("JetCalibrationToolLargeR"),

    m_jetUncertaintiesTool("JetUncertaintiesTool"),
    m_jetUncertaintiesToolFrozenJMS("JetUncertaintiesToolFrozenJMS"),
    m_jetUncertaintiesToolReducedNPScenario1("JetUncertaintiesToolReducedNPScenario1"),
    m_jetUncertaintiesToolReducedNPScenario2("JetUncertaintiesToolReducedNPScenario2"),
    m_jetUncertaintiesToolReducedNPScenario3("JetUncertaintiesToolReducedNPScenario3"),
    m_jetUncertaintiesToolReducedNPScenario4("JetUncertaintiesToolReducedNPScenario4"),
    m_jetUncertaintiesToolLargeR("JetUncertaintiesToolLargeR"),

    m_jetUpdateJvtTool("JetUpdateJvtTool"),
    m_jetSelectfJvtTool("JetSelectfJvtTool"),

    m_jetSubstructure(nullptr),

    m_systMap_AllNP(),
    m_systMap_AllNP_FrozenJMS(),
    m_systMap_ReducedNPScenario1(),
    m_systMap_ReducedNPScenario2(),
    m_systMap_ReducedNPScenario3(),
    m_systMap_ReducedNPScenario4(),
    m_systMap_LargeR() {
    declareProperty("config", m_config);

    declareProperty("JetCalibrationTool", m_jetCalibrationTool);
    declareProperty("JetCalibrationToolLargeR", m_jetCalibrationToolLargeR);

    declareProperty("JetUncertaintiesTool", m_jetUncertaintiesTool);
    declareProperty("JetUncertaintiesToolFrozenJMS", m_jetUncertaintiesToolFrozenJMS);
    declareProperty("JetUncertaintiesToolReducedNPScenario1", m_jetUncertaintiesToolReducedNPScenario1);
    declareProperty("JetUncertaintiesToolReducedNPScenario2", m_jetUncertaintiesToolReducedNPScenario2);
    declareProperty("JetUncertaintiesToolReducedNPScenario3", m_jetUncertaintiesToolReducedNPScenario3);
    declareProperty("JetUncertaintiesToolReducedNPScenario4", m_jetUncertaintiesToolReducedNPScenario4);
    declareProperty("JetUncertaintiesToolLargeR", m_jetUncertaintiesToolLargeR);

    declareProperty("JetUpdateJvtTool", m_jetUpdateJvtTool);

    declareProperty("TruthJetCollectionForHSTagging", m_truthJetCollForHS = "AntiKt4TruthJets");
78
79
  }

Tomas Dado's avatar
Tomas Dado committed
80
81
  StatusCode JetObjectCollectionMaker::initialize() {
    ATH_MSG_INFO(" top::JetObjectCollectionMaker initialize");
82

Tomas Dado's avatar
Tomas Dado committed
83
84
85
86
87
88
    ///-- Lets do the nominal systematics --///
    ///-- JetObjectCollectionMaker is a little different from the others --///
    m_specifiedSystematics.push_back(CP::SystematicSet());
    m_specifiedSystematicsLargeR.push_back(CP::SystematicSet());
    m_specifiedSystematicsTrackJets.push_back(CP::SystematicSet());
    m_recommendedSystematics.push_back(CP::SystematicSet());
89
90


Tomas Dado's avatar
Tomas Dado committed
91
92
93
94
95
96
    top::check(m_jetCalibrationTool.retrieve(), "Failed to retrieve JetCalibrationTool");
    if (m_config->useLargeRJets()) {
      top::check(m_jetCalibrationToolLargeR.retrieve(),
                 "Failed to retrieve JetCalibrationToolLargeR");
      top::check(m_jetUncertaintiesToolLargeR.retrieve(),
                 "Failed to retrieve JetUncertaintiesToolLargeR");
97
98
    }

Tomas Dado's avatar
Tomas Dado committed
99
100
101
    if (m_config->getDerivationStream() == "PHYS") {
      m_truthJetCollForHS = "AntiKt4TruthDressedWZJets";
    }
102

Tomas Dado's avatar
Tomas Dado committed
103
104
105
106
107
108
    ///-- JER uncertainties model --///
    if (m_config->jetJERSmearingModel() == "Full" || m_config->jetJERSmearingModel() == "All") m_doFull_JER = true;
    if (m_config->jetJERSmearingModel() == "Simple") m_doFull_JER = false;
    if (m_config->jetJERSmearingModel() == "Full_PseudoData" ||
        m_config->jetJERSmearingModel() == "All_PseudoData") m_doFull_JER_Pseudodata = true;
    else m_doFull_JER_Pseudodata = false;
109
110


Tomas Dado's avatar
Tomas Dado committed
111
112
    m_isMC = m_config->isMC();
    m_doMultipleJES = m_config->doMultipleJES();
113

Tomas Dado's avatar
Tomas Dado committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
    ///-- Are we doing JER? Let's not repeat this logic over and over --///
    if (m_isMC) m_doJER = true;
    if (!m_isMC && m_doFull_JER) m_doJER = true;
    /// NB: for "Full_PseudoData", no need to smear the data, so m_doJER is false on data unless it's "Full"

    if (m_isMC || m_doFull_JER) {
      if (!m_doMultipleJES) {
        top::check(m_jetUncertaintiesTool.retrieve(), "Failed to retrieve JetUncertaintiesTool");
        if (m_config->jetCalibSequence() == "JMS") {
          top::check(m_jetUncertaintiesToolFrozenJMS.retrieve(), "Failed to retrieve JetUncertaintiesTool (FrozenJMS)");
        }
      } else {
        top::check(
          m_jetUncertaintiesToolReducedNPScenario1.retrieve(),
          "Failed to retrieve JetUncertaintiesToolReducedNPScenario1");
        top::check(
          m_jetUncertaintiesToolReducedNPScenario2.retrieve(),
          "Failed to retrieve JetUncertaintiesToolReducedNPScenario2");
        top::check(
          m_jetUncertaintiesToolReducedNPScenario3.retrieve(),
          "Failed to retrieve JetUncertaintiesToolReducedNPScenario3");
        top::check(
          m_jetUncertaintiesToolReducedNPScenario4.retrieve(),
          "Failed to retrieve JetUncertaintiesToolReducedNPScenario4");
138
139
140
141
142
143
144
145
      }
    }






Tomas Dado's avatar
Tomas Dado committed
146
147
148
149
150
151
152
    top::check(m_jetUpdateJvtTool.retrieve(), "Failed to retrieve JetUpdateJvtTool");
    //fJVT tool isn't setup unless requested
    if (m_config->doForwardJVTinMET() || m_config->getfJVTWP() != "None") {
      top::check(m_jetSelectfJvtTool.retrieve(), "Failed to retrieve JetSelectfJvtTool");
    }
    // Take this from the TopConfiguration
    // A blank vector will setup all systematics
153

Tomas Dado's avatar
Tomas Dado committed
154
155
    const std:: string& syststr = m_config->systematics();
    std::set<std::string> syst, systLargeR;
156

Tomas Dado's avatar
Tomas Dado committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
    if (!m_config->isSystNominal(syststr) && !m_config->isSystAll(syststr)) {
      bool ok = m_config->getSystematicsList(syststr, syst);
      bool okLargeR = m_config->getSystematicsList(syststr, systLargeR);
      if (!ok || !okLargeR) {
        ATH_MSG_ERROR(" top::JetObjectCollectionMaker could not determine systematic list");
        return StatusCode::FAILURE;
      }
      //here the idea is that if the user specifies AllXXX, we leave syst as an empty string, so that all recommended CP
      // systematics are then used
      if (m_config->contains(syst, "AllJets")) {
        syst.clear();
        systLargeR.clear();
      }
      if (m_config->contains(syst, "AllSmallRJets")) {
        syst.clear();
      }
      if (m_config->contains(systLargeR, "AllLargeRJets")) {
        systLargeR.clear();
      }
    }
177
178


Tomas Dado's avatar
Tomas Dado committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
    ///-- JES systematics --///
    if (m_isMC || m_doFull_JER) {
      std::string allNP(m_config->jetUncertainties_NPModel() + "_"),
      np1("SR_Scenario1_"), np2("SR_Scenario2_"), np3("SR_Scenario3_"), np4("SR_Scenario4_");
      std::string allNP_FrozenJMS(m_config->jetUncertainties_NPModel() + "_FrozenJMS_");

      bool onlyJER = ((!m_isMC) && m_doFull_JER) || (m_isMC && m_doFull_JER_Pseudodata);

      if (!m_doMultipleJES) {
        addSystematics(syst, m_jetUncertaintiesTool->recommendedSystematics(), m_systMap_AllNP, allNP, false, onlyJER);
        if (m_config->jetCalibSequence() == "JMS") {
          addSystematics(syst,
                         m_jetUncertaintiesToolFrozenJMS->recommendedSystematics(), m_systMap_AllNP_FrozenJMS, allNP_FrozenJMS, false,
                         onlyJER);
        }
      } else {
        addSystematics(syst,
                       m_jetUncertaintiesToolReducedNPScenario1->recommendedSystematics(), m_systMap_ReducedNPScenario1, np1, false,
                       onlyJER);
        addSystematics(syst,
                       m_jetUncertaintiesToolReducedNPScenario2->recommendedSystematics(), m_systMap_ReducedNPScenario2, np2, false,
                       onlyJER);
        addSystematics(syst,
                       m_jetUncertaintiesToolReducedNPScenario3->recommendedSystematics(), m_systMap_ReducedNPScenario3, np3, false,
                       onlyJER);
        addSystematics(syst,
                       m_jetUncertaintiesToolReducedNPScenario4->recommendedSystematics(), m_systMap_ReducedNPScenario4, np4, false,
                       onlyJER);
207
      }
Tomas Dado's avatar
Tomas Dado committed
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
    }
    ///-- Large-R JES systematics --///
    std::string largeRModName = getLargeRModName(m_config->largeRJetUncertainties_NPModel());
    CP::SystematicSet largeRsysts;
    if (m_config->useLargeRJets() && m_config->isMC()) { //No JES uncertainties for Data at the moment
      if ((m_config->largeRJESJMSConfig() == "CombMass") || (m_config->largeRJESJMSConfig() == "TCCMass")) { //TA mass
                                                                                                             // and
                                                                                                             // combined
                                                                                                             // mass not
                                                                                                             // supported
                                                                                                             // for
                                                                                                             // JMS/JMR
                                                                                                             // for now
        largeRsysts.insert(m_jetUncertaintiesToolLargeR->recommendedSystematics());
      } else {
        ATH_MSG_WARNING(
224
          "TA Mass & Calo Mass & UFO SD Mass are not supported for large-R jet uncertainties at the moment. Large-R jet systemtatics skipped!");
225
226
227
      }
    }

Tomas Dado's avatar
Tomas Dado committed
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    ///-- Large R jet tagger scale factor uncertainties -- ///
    if (m_config->isMC() && m_config->useLargeRJets()) {
      for (const std::pair<std::string, std::string>& name : m_config->boostedTaggerSFnames()) {
        ToolHandle<ICPJetUncertaintiesTool> tmp_SF_uncert_tool("JetSFuncert_" + name.first);
        if (tmp_SF_uncert_tool.retrieve()) {
          largeRsysts.insert(tmp_SF_uncert_tool->recommendedSystematics());
          m_tagSFuncertTool[name.first] = tmp_SF_uncert_tool;
        }
      }
    }

    // add the merged set of systematics for large-R jets including the tagging SF systs
    addSystematics(systLargeR, largeRsysts, m_systMap_LargeR, largeRModName, true);

    ///-- Large R jet substructure --///
    if (m_config->jetSubstructureName() == "Trimmer") m_jetSubstructure.reset(new top::LargeJetTrimmer);

    if (m_config->jetSubstructureName() == "SubjetMaker") m_jetSubstructure.reset(new top::SubjetMaker);

    ///-- Large R jet truth labeling --///
//    m_jetTruthLabelingTool = nullptr;
//    if (m_config->isMC() && m_config->useLargeRJets()) {
//      m_jetTruthLabelingTool = std::unique_ptr<JetTruthLabelingTool>(new JetTruthLabelingTool("JetTruthLabeling"));
//      // For DAOD_PHYS we need to pass few more arguments as it uses TRUTH3
//      if (m_config->getDerivationStream() == "PHYS") {
//        top::check(m_jetTruthLabelingTool->setProperty("UseTRUTH3", true), "Failed to set UseTRUTH3 for m_jetTruthLabelingTool");
//        top::check(m_jetTruthLabelingTool->setProperty("TruthBosonContainerName", "TruthBoson"), "Failed to set truth container name for m_jetTruthLabelingTool");
//        top::check(m_jetTruthLabelingTool->setProperty("TruthTopQuarkContainerName", "TruthTop"), "Failed to set truth container name for m_jetTruthLabelingTool");
//      }
//      top::check(m_jetTruthLabelingTool->initialize(), "Failed to initialize m_jetTruthLabelingTool");
//    }

    // set the systematics list
    m_config->systematicsJets(specifiedSystematics());
    m_config->systematicsLargeRJets(specifiedSystematicsLargeR());
    m_config->systematicsTrackJets(m_specifiedSystematicsTrackJets);

    ///-- DL1 Decoration --///
    for (const std::pair<std::string, std::string>& algo : m_config->bTagAlgo_selToolNames()) {
      m_btagSelToolsDL1Decor[algo.first] = algo.second;
      top::check(m_btagSelToolsDL1Decor[algo.first].retrieve(), "Failed to retrieve " + algo.first + " btagging selector for " + m_config->sgKeyJets() + ". This is required for b-tagging score decorations in EventSaver!");
      if (DLx.count(algo.first) == 0) {
        DLx.emplace(algo.first, SG::AuxElement::Decorator<float>("AnalysisTop_" + algo.first));
      }
272
273
    }

Tomas Dado's avatar
Tomas Dado committed
274
275
276
277
278
279
280
281
282
    if (m_config->useTrackJets()) {
      for (const std::pair<std::string, std::string>& algo : m_config->bTagAlgo_selToolNames_trkJet()) {
        m_btagSelToolsDL1Decor_trkJet[algo.first] = algo.second;
        top::check(m_btagSelToolsDL1Decor_trkJet[algo.first].retrieve(), "Failed to retrieve " + algo.first + " btagging selector for " + m_config->sgKeyTrackJets() + ". This is required for b-tagging score decorations in EventSaver!");
        if (DLx.count(algo.first) == 0) {
          DLx.emplace(algo.first, SG::AuxElement::Decorator<float>("AnalysisTop_" + algo.first));
        }
      }
    }
283

Tomas Dado's avatar
Tomas Dado committed
284
285
286
287
288
289
290
291
292
    // initialize boosted jet taggers -- we have to do it here instead pf TopObjectSelectionTools
    // because we have to apply tagger inbetween JES uncertainty tool and the tagging SF tool
    if (m_config->useLargeRJets()) {
      for (const std::pair<std::string, std::string>& name : m_config->boostedJetTaggers()) {
        std::string fullName = name.first + "_" + name.second;
        m_boostedJetTaggers[fullName] = ToolHandle<IJetSelectorTool>(fullName);
        top::check(m_boostedJetTaggers[fullName].retrieve(), "Failed to retrieve " + fullName);
      }
    }
293

Tomas Dado's avatar
Tomas Dado committed
294
295
    return StatusCode::SUCCESS;
  }
296

Tomas Dado's avatar
Tomas Dado committed
297
298
  StatusCode JetObjectCollectionMaker::executeJets(bool executeNominal) {
    bool isLargeR(false);
299

Tomas Dado's avatar
Tomas Dado committed
300
301
    return execute(isLargeR, executeNominal);
  }
302

Tomas Dado's avatar
Tomas Dado committed
303
304
  StatusCode JetObjectCollectionMaker::executeLargeRJets(bool executeNominal) {
    bool isLargeR(true);
305

Tomas Dado's avatar
Tomas Dado committed
306
307
    return execute(isLargeR, executeNominal);
  }
308

Tomas Dado's avatar
Tomas Dado committed
309
310
311
312
313
314
315
316
317
318
  StatusCode JetObjectCollectionMaker::execute(const bool isLargeR, bool executeNominal) {
    ///-- Run nominal first, if executing nominal
    if (executeNominal) {
      // decorating the HS jets with truth info on which are HS jets
      if (!isLargeR & m_isMC) {
        top::check(
          decorateHSJets(),
          "Failed to decorate jets with truth info of which are HS - this is needed for JVT scale-factors!");
        if (m_isMC && m_config->jetResponseMatchingDeltaR() > 0) {
          top::check(decorateMatchedTruth(), "Failed to decorate matched jet");
319
320
321
        }
      }

Tomas Dado's avatar
Tomas Dado committed
322
323
      // Decorate the DL1 variable
      top::check(decorateDL1(), "Failed to decorate jets with DL1 b-tagging discriminant");
324

Tomas Dado's avatar
Tomas Dado committed
325
326
327
328
329
330
      ///-- First calibrate the nominal jets, everything else comes from this, so let's only do it once not 3000 times
      // --///
      top::check(calibrate(isLargeR), "Failed to calibrate jets");

      ///-- Return after calibrating the nominal --///
      return StatusCode::SUCCESS;
331
332
    }

Tomas Dado's avatar
Tomas Dado committed
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
    ///-- Systematics from here --///

    ///-- JES, JER regular atk4 for now --///
    if (!isLargeR) {
      ///-- JES --///
      if (m_isMC || m_doFull_JER) {
        if (!m_doMultipleJES) {
          top::check(applySystematic(m_jetUncertaintiesTool, m_systMap_AllNP), "Failed to apply JES");
          if (m_config->jetCalibSequence() == "JMS") {
            top::check(applySystematic(m_jetUncertaintiesToolFrozenJMS,
                                       m_systMap_AllNP_FrozenJMS), "Failed to apply JES Frozen JMS");
          }
        }
        if (m_doMultipleJES) {
          top::check(applySystematic(m_jetUncertaintiesToolReducedNPScenario1,
                                     m_systMap_ReducedNPScenario1), "Failed to apply JES");
          top::check(applySystematic(m_jetUncertaintiesToolReducedNPScenario2,
                                     m_systMap_ReducedNPScenario2), "Failed to apply JES");
          top::check(applySystematic(m_jetUncertaintiesToolReducedNPScenario3,
                                     m_systMap_ReducedNPScenario3), "Failed to apply JES");
          top::check(applySystematic(m_jetUncertaintiesToolReducedNPScenario4,
                                     m_systMap_ReducedNPScenario4), "Failed to apply JES");
        }
      }
    } else {
      // tag calibrated (nominal) jets -- the tagging information will be available
      // for systematically-shifted shallow copies as well
      top::check(tagNominalLargeRJets(), "Failed to tag large-R jets");
      if (m_config->isMC()) {
        top::check(applySystematic(m_jetUncertaintiesToolLargeR, m_systMap_LargeR,
                                   true), "Failed to apply large-R syst.");
      }
365
366
    }

Tomas Dado's avatar
Tomas Dado committed
367
368
    return StatusCode::SUCCESS;
  }
369

Tomas Dado's avatar
Tomas Dado committed
370
371
372
  StatusCode JetObjectCollectionMaker::calibrate(const bool isLargeR) {
    ///-- Get base jets from xAOD --///
    std::string sgKey = isLargeR ? m_config->sgKeyLargeRJets() : m_config->sgKeyJets();
373

Tomas Dado's avatar
Tomas Dado committed
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
    const xAOD::JetContainer* xaod(nullptr);
    top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve Jets");

    ///-- Shallow copy of the xAOD --///
    std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > shallow_xaod_copy = xAOD::shallowCopyContainer(*xaod);

    ///-- Loop over the xAOD Container --///
//    for (const auto jet : *(shallow_xaod_copy.first)) {
//      if (!isLargeR) { ///-- small-R jets used in most analyses --///
//        ///-- Calibrate jet --///
//
//        top::check(m_jetCalibrationTool->applyCalibration(*jet), "Failed to applyCalibration");
//
//        // only multiply by JSF and bJSF if one of them != 1.0 (used by top mass analysis)
//        float JSF = m_config->JSF();
//        float bJSF = m_config->bJSF();
//
//        if (JSF != 1.0 || bJSF != 1.0) {
//          int truthflav = -1;
//          if (jet->isAvailable<int>("PartonTruthLabelID")) {
//            jet->getAttribute("PartonTruthLabelID", truthflav);
//          }
//
//          xAOD::JetFourMom_t jet_p4 = jet->jetP4() * JSF;
//          if (truthflav == 5) jet_p4 = jet_p4 * bJSF;
//
//          jet->setJetP4(jet_p4);
//        }
//        // end application JSF/bJSF
//
//
//        top::check(decorateBJets(*jet), "Failed to decorate if b-jet");
//      }
//
//      if (isLargeR && m_jetSubstructure.get() != nullptr) {
//        m_jetSubstructure->correctJet(*jet);
//      }
//
//      if (isLargeR) {
//        ///-- Calibrate jet --///
//
//        float tau3 = jet->getAttribute<float>("Tau3_wta");
//        float tau2 = jet->getAttribute<float>("Tau2_wta");
//        float tau1 = jet->getAttribute<float>("Tau1_wta");
//        float ECF1 = jet->getAttribute<float>("ECF1");
//        float ECF2 = jet->getAttribute<float>("ECF2");
//        float ECF3 = jet->getAttribute<float>("ECF3");
//
//        jet->auxdecor<float>("Tau32_wta") = fabs(tau2) > 1.e-6 ? (tau3 / tau2) : -999;  // 999 to match
//                                                                                        // JetSubStructureMomentTools/NSubjettinessRatiosTool
//        jet->auxdecor<float>("Tau21_wta") = fabs(tau1) > 1.e-6 ? (tau2 / tau1) : -999;  // 999 to match
//                                                                                        // JetSubStructureMomentTools/NSubjettinessRatiosTool
//        // Same definition as in JetSubStructureMomentTools/Root/EnergyCorrelatorRatiosTool.cxx
//        jet->auxdecor<float>("D2") = (ECF2 > 1e-8) ? (ECF3*ECF1*ECF1*ECF1) / (ECF2*ECF2*ECF2) : -999;
//        jet->auxdecor<float>("C2") = (ECF2 > 1e-8) ? (ECF3*ECF1) / (ECF2*ECF2) : -999;
//        jet->auxdecor<float>("E3") = (ECF1 > 1e-8) ? ECF3 / (ECF1*ECF1*ECF1) : -999;
//                                                                                      
//
//        top::check(m_jetCalibrationToolLargeR->applyCalibration(*jet), "Failed to applyCalibration");
//
//        ///-- for TA mass or calo mass, the calibrated mass or pt needs special treatment --///
//        const std::string calibChoice = m_config->largeRJESJMSConfig();
//        if (m_config->isMC()) {
//          ///-- Truth labeling required by the large-R jet uncertainties --///
////          top::check(m_jetTruthLabelingTool->modifyJet(*jet), "Failed to do truth labeling for large-R jet");
//          if (calibChoice == "TAMass") {
//            xAOD::JetFourMom_t jet_calib_p4;
//            jet->getAttribute<xAOD::JetFourMom_t>("JetJMSScaleMomentumTA", jet_calib_p4);
//            jet->setJetP4(jet_calib_p4);
//          }
//        } else { //For data, there's only one config file so special method is required for TA mass and Calos mass
//          if (calibChoice == "CaloMass") {
//            xAOD::JetFourMom_t jetInsituP4_calo;
//            jet->getAttribute<xAOD::JetFourMom_t>("JetInsituScaleMomentumCalo", jetInsituP4_calo);
//            jet->setJetP4(jetInsituP4_calo);
//          } else if (calibChoice == "TAMass") {
//            xAOD::JetFourMom_t jetInsituP4_ta;
//            jet->getAttribute<xAOD::JetFourMom_t>("JetInsituScaleMomentumTA", jetInsituP4_ta);
//            jet->setJetP4(jetInsituP4_ta);
//          }
//        }
//      }
//
//      ///-- Update JVT --///
//      if (!isLargeR) {
//        jet->auxdecor<float>("AnalysisTop_JVT") = m_jetUpdateJvtTool->updateJvt(*jet);
//      }
//    }

    // Check if the derivation we are running on contains
    // MET_Track (once), if so apply the fJVT decoration
    // if not then don't
    if (!isLargeR && (m_config->doForwardJVTinMET() || m_config->getfJVTWP() != "None")) {
      static bool checked_track_MET = false;
      if (!checked_track_MET) {
	if (evtStore()->contains<xAOD::MissingETContainer>("MET_Track")) {
	  m_do_fjvt = true;
	} else {
	  ATH_MSG_ERROR(" Cannot retrieve MET_Track, fJVT values can't be calculated correctly!!"); 
	  return StatusCode::FAILURE; 
	}
	checked_track_MET = true;
      }
    }
    if (m_do_fjvt) {
      top::check(!m_jetSelectfJvtTool->modify(*shallow_xaod_copy.first),
                 "Failed to apply fJVT decoration");
    }
482

Tomas Dado's avatar
Tomas Dado committed
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
    if (!isLargeR) {
      ///-- Save calibrated jet to TStore --///
      ///-- set links to original objects- needed for MET calculation --///
      // NOTE, if we use one of the b-tagging re-trained collections, we need to load
      // the original uncalibrated jet container to which the b-tagging shallow-copy is pointing to
      const xAOD::JetContainer* xaod_original(nullptr);
      // for small-R jet collections, set links to uncalibrated *original* jets (not BTagging shallow-copy)
      if (m_config->sgKeyJets() != m_config->sgKeyJetsType()) {
        top::check(evtStore()->retrieve(xaod_original,
                                        m_config->sgKeyJetsType()),
                   "Failed to retrieve uncalibrated Jets for METMaker!");
      } else {
        xaod_original = xaod;
      }
      bool setLinks = xAOD::setOriginalObjectLink(*xaod_original, *shallow_xaod_copy.first);
      if (!setLinks) ATH_MSG_ERROR(" Cannot set original object links for jets, MET recalculation may struggle");
499
500
    }

Tomas Dado's avatar
Tomas Dado committed
501
502
    ///-- Save corrected xAOD Container to StoreGate / TStore --///
    std::string outputSGKey;
503
    if (!isLargeR) {
Tomas Dado's avatar
Tomas Dado committed
504
      outputSGKey = m_config->sgKeyJetsStandAlone(m_nominalSystematicSet.hash());
505
    }
Tomas Dado's avatar
Tomas Dado committed
506
507
    if (isLargeR) {
      outputSGKey = m_config->sgKeyLargeRJets(m_nominalSystematicSet.hash());
508
    }
Tomas Dado's avatar
Tomas Dado committed
509
510
511
512
513
514
515

    std::string outputSGKeyAux = outputSGKey + "Aux.";

    xAOD::TReturnCode save = evtStore()->tds()->record(shallow_xaod_copy.first, outputSGKey);
    xAOD::TReturnCode saveAux = evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux);
    if (!save || !saveAux) {
      return StatusCode::FAILURE;
516
517
    }

Tomas Dado's avatar
Tomas Dado committed
518
    return StatusCode::SUCCESS;
519
520
  }

Tomas Dado's avatar
Tomas Dado committed
521
522
523
524
525
526
  StatusCode JetObjectCollectionMaker::applySystematic(ToolHandle<ICPJetUncertaintiesTool>& tool,
                                                       const std::unordered_map<CP::SystematicSet,
                                                                                CP::SystematicSet>& map,
                                                       bool isLargeR) {
    ///-- Get calibrated jets --///
    const xAOD::JetContainer* xaod(nullptr);
527

Tomas Dado's avatar
Tomas Dado committed
528
529
530
531
532
533
534
    if (!isLargeR) {
      top::check(evtStore()->retrieve(xaod, m_config->sgKeyJetsStandAlone(
                                        m_nominalSystematicSet.hash())), "Failed to retrieve Jets");
    } else {
      top::check(evtStore()->retrieve(xaod, m_config->sgKeyLargeRJets(
                                        m_nominalSystematicSet.hash())), "Failed to retrieve Jets");
    }
535

Tomas Dado's avatar
Tomas Dado committed
536
    ///-- Loop over the systematics --///
537

Tomas Dado's avatar
Tomas Dado committed
538
539
540
541
542
543
544
    for (Itr syst = map.begin(); syst != map.end(); ++syst) {
      ///-- Don't do the nominal, we've already done that --///
      if ((*syst).second.hash() != m_nominalSystematicSet.hash()) {
        ///-- Tell the tool which systematic to use --///
        ///-- Here we use the second, original CP::SystematicSet --///
        top::check(tool->applySystematicVariation((*syst).second),
                   "Failed to applySystematicVariation");
545

Tomas Dado's avatar
Tomas Dado committed
546
547
548
549
550
551
        if (isLargeR && m_config->isMC()) {
          // for boosted tagging SFs, apply syst variation for all initialized WPs
          for (std::pair<const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF : m_tagSFuncertTool) {
            top::check(tagSF.second->applySystematicVariation((*syst).second), "Failed to applySystematicVariation");
          }
        }
552

Tomas Dado's avatar
Tomas Dado committed
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
        ///-- Shallow copy of the xAOD --///
        std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* >
        shallow_xaod_copy = xAOD::shallowCopyContainer(*xaod);

        ///-- Loop over the xAOD Container --///
        for (auto jet : *(shallow_xaod_copy.first)) {
          if (isLargeR && m_config->isMC()) { //JES for large-R jets only exist for MC
            ///-- Only large R jets with the following properties can be calibrated.--///
            bool calibratable_jet = (std::fabs(jet->eta()) <= 2.0
                                     && jet->pt() > 175e3); //lower than 200e3 to allow studying on migration
            std::string jetCalibrationNameLargeR = m_config->sgKeyLargeRJets();
            if (jetCalibrationNameLargeR.find("TrackCaloCluster") != std::string::npos) { //TCC jet
              calibratable_jet = (jet->m() / jet->pt() <= 1.
                                  && jet->m() / jet->pt() >= 0.
                                  && std::fabs(jet->eta()) <= 2.0
                                  && jet->pt() > 150e3
                                  && jet->pt() < 3000e3);
            }
            if (!calibratable_jet) continue;
          }
          ///-- Apply Corrrection --///
          if (!(isLargeR && !m_config->isMC())) { //Large-R jet uncertainties don't apply to Data
            top::check(tool->applyCorrection(*jet), "Failed to applyCorrection");
          }
          ///-- Update JVT --///
          if (!isLargeR) jet->auxdecor<float>("AnalysisTop_JVT") = m_jetUpdateJvtTool->updateJvt(*jet);
	  
          ///-- Decorate fJVT for systematics too --///
	  // Check if the derivation we are running on contains
	  // MET_Track (once) before applying the fJVT decoration
	  if (!isLargeR && (m_config->doForwardJVTinMET() || m_config->getfJVTWP() != "None")) {
	    static bool checked_track_MET = false;
	    if (!checked_track_MET) {
	      if (evtStore()->contains<xAOD::MissingETContainer>("MET_Track")) {
		m_do_fjvt = true;
	      } else {
		ATH_MSG_ERROR(" Cannot retrieve MET_Track, fJVT values can't be calculated correctly!!"); 
		return StatusCode::FAILURE;
	      }
	      checked_track_MET = true;
	    }
	  }
	  if (m_do_fjvt) {
	    top::check(!m_jetSelectfJvtTool->modify(*shallow_xaod_copy.first),
		       "Failed to apply fJVT decoration");
	  }


          ///-- Apply large-R jet tagging SF uncertainties --///
          if (isLargeR && m_config->isMC()) {
            for (std::pair<const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF : m_tagSFuncertTool) {
              top::check(tagSF.second->applyCorrection(*jet), "Failed to applyCorrection");
            }
          }
        }
608

Tomas Dado's avatar
Tomas Dado committed
609
610
611
612
613
        ///-- set links to original objects- needed for MET calculation --///
        bool setLinks = xAOD::setOriginalObjectLink(*xaod,
                                                    *shallow_xaod_copy.first);
        if (!setLinks) ATH_MSG_ERROR(" Cannot set original object links"
                                     " for jets, MET recalculation may struggle");
614

Tomas Dado's avatar
Tomas Dado committed
615
616
617
618
        ///-- Save corrected xAOD Container to StoreGate / TStore --///
        ///-- Here we use the first, AnalysisTop modified CP::SystematicSer --///
        ///-- This allows us to run multiple JES scenarios, which all have the same hash values --///
        std::string outputSGKey;
619
        if (isLargeR) {
Tomas Dado's avatar
Tomas Dado committed
620
621
622
          outputSGKey = m_config->sgKeyLargeRJets((*syst).first.hash());
        } else {
          outputSGKey = m_config->sgKeyJetsStandAlone((*syst).first.hash());
623
        }
Tomas Dado's avatar
Tomas Dado committed
624
        std::string outputSGKeyAux = outputSGKey + "Aux.";
625

Tomas Dado's avatar
Tomas Dado committed
626
627
628
629
630
        xAOD::TReturnCode save = evtStore()->tds()->record(shallow_xaod_copy.first, outputSGKey);
        xAOD::TReturnCode saveAux = evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux);
        if (!save || !saveAux) {
          return StatusCode::FAILURE;
        }
631
632
633
      }
    }

Tomas Dado's avatar
Tomas Dado committed
634
635
    return StatusCode::SUCCESS;
  }
636

Tomas Dado's avatar
Tomas Dado committed
637
638
639
640
  StatusCode JetObjectCollectionMaker::executeTrackJets(bool executeNominal) {
    ///-- No calibrations or systematics yet --///
    ///-- Only run this on the nominal execution --///
    if (!executeNominal) return StatusCode::SUCCESS;
641

Tomas Dado's avatar
Tomas Dado committed
642
    top::check(decorateDL1(true), "Failed to decorate track jets with DL1 b-tagging discriminant");
643
644


Tomas Dado's avatar
Tomas Dado committed
645
    ///-- Just make a shallow copy to keep these in line with everything else --///
646

Tomas Dado's avatar
Tomas Dado committed
647
648
    const xAOD::JetContainer* xaod(nullptr);
    top::check(evtStore()->retrieve(xaod, m_config->sgKeyTrackJets()), "Failed to retrieve Jets");
649

Tomas Dado's avatar
Tomas Dado committed
650
651
    ///-- Shallow copy of the xAOD --///
    std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > shallow_xaod_copy = xAOD::shallowCopyContainer(*xaod);
652

Tomas Dado's avatar
Tomas Dado committed
653
654
655
    ///-- set links to original objects --///
    bool setLinks = xAOD::setOriginalObjectLink(*xaod, *shallow_xaod_copy.first);
    if (!setLinks) ATH_MSG_ERROR(" Cannot set original object links for track jets");
656

Tomas Dado's avatar
Tomas Dado committed
657
658
659
    ///-- Save corrected xAOD Container to StoreGate / TStore --///
    std::string outputSGKey = m_config->sgKeyTrackJets(m_config->nominalHashValue());
    std::string outputSGKeyAux = outputSGKey + "Aux.";
660

Tomas Dado's avatar
Tomas Dado committed
661
662
663
664
    xAOD::TReturnCode save = evtStore()->tds()->record(shallow_xaod_copy.first, outputSGKey);
    xAOD::TReturnCode saveAux = evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux);
    if (!save || !saveAux) {
      return StatusCode::FAILURE;
665
    }
Tomas Dado's avatar
Tomas Dado committed
666
    return StatusCode::SUCCESS;
667
668
  }

Tomas Dado's avatar
Tomas Dado committed
669
670
  StatusCode JetObjectCollectionMaker::printoutJets() {
    bool isLargeR(false);
671

Tomas Dado's avatar
Tomas Dado committed
672
673
    return this->printout(isLargeR);
  }
674

Tomas Dado's avatar
Tomas Dado committed
675
676
  StatusCode JetObjectCollectionMaker::printoutLargeRJets() {
    bool isLargeR(true);
677

Tomas Dado's avatar
Tomas Dado committed
678
    return this->printout(isLargeR);
679
680
  }

Tomas Dado's avatar
Tomas Dado committed
681
682
683
684
  StatusCode JetObjectCollectionMaker::printout(const bool isLargeR) {
    ///-- Loop over all systematics --///
    for (auto s : m_specifiedSystematics) {
      std::string sgKey = isLargeR ? m_config->sgKeyLargeRJets() : m_config->sgKeyJets();
685

Tomas Dado's avatar
Tomas Dado committed
686
687
      const xAOD::JetContainer* xaod(nullptr);
      top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve Jets");
688

Tomas Dado's avatar
Tomas Dado committed
689
690
691
692
693
      ATH_MSG_INFO(" Jets with sgKey = " << sgKey);
      for (auto x : *xaod) {
        ATH_MSG_INFO("   Jet pT , eta  = " << x->pt() << " , " << x->eta());
      }
    }
694

Tomas Dado's avatar
Tomas Dado committed
695
696
    return StatusCode::SUCCESS;
  }
697

Tomas Dado's avatar
Tomas Dado committed
698
699
700
701
  std::string JetObjectCollectionMaker::getLargeRModName(const std::string& NPModel) const {
    if (NPModel.find("CategoryReduction")!=std::string::npos) return "CategoryReduction_";
    return NPModel+"_"; 
  }
702

Tomas Dado's avatar
Tomas Dado committed
703
704
705
706
  void JetObjectCollectionMaker::addSystematics(const std::set<std::string>& specifiedSystematics,
                                                const CP::SystematicSet& recommendedSysts,
                                                std::unordered_map<CP::SystematicSet, CP::SystematicSet>& map,
                                                const std::string& modName, bool isLargeR, bool onlyJER) {
707
    ///-- Get the recommended systematics from the tool, in std::vector format --///
Tomas Dado's avatar
Tomas Dado committed
708
709
    const std::vector<CP::SystematicSet> systList = CP::make_systematics_vector(recommendedSysts);
    
710

Tomas Dado's avatar
Tomas Dado committed
711
    for (const CP::SystematicSet& s : systList) {
712
713
      if (s.size() == 1) {
        CP::SystematicSet::const_iterator ss = s.begin();
Tomas Dado's avatar
Tomas Dado committed
714
715
716
717
718
	if(!m_config->getTreeFilter()->filterTree(modName + ss->name())) continue; // Applying tree filter

        if (onlyJER && ss->name().find("JER") == std::string::npos) continue;

        CP::SystematicSet modSet(modName + ss->name());
719
720

        m_recommendedSystematics.push_back(modSet);
Tomas Dado's avatar
Tomas Dado committed
721
        if (!m_config->isSystNominal(m_config->systematics())) {
722
          if (specifiedSystematics.size() == 0) {
Tomas Dado's avatar
Tomas Dado committed
723
724
725
726
727
728
729
730
731
732
            if (!isLargeR) m_specifiedSystematics.push_back(modSet);
            else m_specifiedSystematicsLargeR.push_back(modSet);
            map.insert(std::make_pair(modSet, s));
          } else if (specifiedSystematics.size() > 0) {
            for (std::string i : specifiedSystematics) {
	      TreeFilter filter(i);
              if (!filter.filterTree(modSet.name())) {
                if (!isLargeR) m_specifiedSystematics.push_back(modSet);
                else m_specifiedSystematicsLargeR.push_back(modSet);
                map.insert(std::make_pair(modSet, s));
733
734
735
736
737
738
739
              }
            }
          } // User has specified a systematic
        } // Don't do anything if the user requests nominal only
      } // size() == 1 -- this means that there is a CP::SystematicVariation
    } // Loop over systList

Tomas Dado's avatar
Tomas Dado committed
740
741
    m_recommendedSystematics.sort();
    m_recommendedSystematics.unique();
742

Tomas Dado's avatar
Tomas Dado committed
743
744
    m_specifiedSystematics.sort();
    m_specifiedSystematics.unique();
745

Tomas Dado's avatar
Tomas Dado committed
746
747
748
    m_specifiedSystematicsLargeR.sort();
    m_specifiedSystematicsLargeR.unique();
  }
749

Tomas Dado's avatar
Tomas Dado committed
750
751
  StatusCode JetObjectCollectionMaker::tagNominalLargeRJets() {
    const xAOD::JetContainer* xaod_calibrated_jets(nullptr);
752

Tomas Dado's avatar
Tomas Dado committed
753
754
755
756
757
758
759
760
    top::check(evtStore()->retrieve(xaod_calibrated_jets, m_config->sgKeyLargeRJets(
                                      m_nominalSystematicSet.hash())),
               "Failed to retrieve nominal calibrated large-R jets");
    for (const xAOD::Jet* jet : *xaod_calibrated_jets) {
      top::check(tagLargeRJet(*jet), "Failed to tag large-R jet");
    }
    return StatusCode::SUCCESS;
  }
761

Tomas Dado's avatar
Tomas Dado committed
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
  StatusCode JetObjectCollectionMaker::tagLargeRJet(const xAOD::Jet& jet) {
    //decorate with boosted-tagging flags
    for (const std::pair<std::string, std::string>& name : m_config->boostedJetTaggers()) {
      std::string fullName = name.first + "_" + name.second;
//      const Root::TAccept& result = m_boostedJetTaggers[fullName]->tag(jet);
      // TAccept has bool operator overloaded, but let's be more explicit in the output to char
//      jet.auxdecor<char>("isTagged_" + fullName) = (result ? 1 : 0);
      jet.auxdecor<char>("isTagged_" + fullName) = 0;
      // for users to extract more detailed tagging result information in custom event saver
      //jet.auxdecor<unsigned long>("TAccept_bitmap_" + fullName) = result.getCutResultBitSet().to_ulong();
    }
    return StatusCode::SUCCESS;
  }

  StatusCode JetObjectCollectionMaker::decorateBJets(xAOD::Jet& jet) {
    // initialise decorator and accessor
    static SG::AuxElement::Decorator<char> isbjet("IsBjet");
    static const std::string labelB = "PartonTruthLabelID";
    static SG::AuxElement::Accessor<int> truth_label(labelB);

    // Is b-jet if truth label == 5 and pT > 15 GeV
    isbjet(jet) = (jet.pt() > 15000. && truth_label(jet) == 5);

    return StatusCode::SUCCESS;
  }

  StatusCode JetObjectCollectionMaker::decorateHSJets() {
    // initialise decorator
    static SG::AuxElement::Decorator<char> isHS("AnalysisTop_isHS");

    // retrieve small-R jets collection
    const xAOD::JetContainer* jets(nullptr);

    top::check(evtStore()->retrieve(jets,
                                    m_config->sgKeyJets()),
               "Failed to retrieve small-R jet collection" + m_config->sgKeyJets());

    // retrieve truth jet collection
    const xAOD::JetContainer* truthJets = nullptr;
    top::check(evtStore()->retrieve(truthJets,
                                    m_truthJetCollForHS),
               "Unable to retrieve truth jet container " + m_truthJetCollForHS +
               " - this is needed to define HS jets for application of JVT");

    for (const auto& jet : *jets) {
      bool ishs = false;
      for (const auto& tjet : *truthJets) {
        if (tjet->p4().DeltaR(jet->p4()) < 0.3 && tjet->pt() > 10e3) ishs = true;
810
      }
Tomas Dado's avatar
Tomas Dado committed
811
      isHS(*jet) = ishs;
812
    }
Tomas Dado's avatar
Tomas Dado committed
813
814

    return StatusCode::SUCCESS;
815
816
  }
  
Tomas Dado's avatar
Tomas Dado committed
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
  StatusCode JetObjectCollectionMaker::decorateMatchedTruth() {
    static const SG::AuxElement::Decorator<float> matchedPt("AnalysisTop_MatchedTruthJetPt");
    // retrieve small-R jets collection
    const xAOD::JetContainer* jets(nullptr);

    top::check(evtStore()->retrieve(jets,
                                    m_config->sgKeyJets()),
               "Failed to retrieve small-R jet collection" + m_config->sgKeyJets());

    const xAOD::JetContainer* truthJets = nullptr;
    top::check(asg::AsgTool::evtStore()->retrieve(truthJets, m_config->sgKeyTruthJets()), "Failed to retrieve the truth jets");

    const xAOD::Jet* matchedTruthJet = nullptr;
    double deltaR(9999);
    
    for (const auto& jet : *jets) {
      // loop over truth jets
      for (const auto& iTruthJet : *truthJets) {
        TLorentzVector truthJetTLV;
        truthJetTLV.SetPtEtaPhiE(iTruthJet->pt(),iTruthJet->eta(),iTruthJet->phi(),iTruthJet->e());

        // do the matching
        if(!matchedTruthJet) {
          matchedTruthJet = iTruthJet;
        } else {
          const double newdR = jet->p4().DeltaR(iTruthJet->p4());
          if(newdR < deltaR) {
            deltaR = newdR;
            matchedTruthJet = iTruthJet;
          }
        }
      }
      if (deltaR > m_config->jetResponseMatchingDeltaR()) {
        matchedPt(*jet) = -9999;
        continue;
      }
      if (!matchedTruthJet) {
        matchedPt(*jet) = -9999;
        continue;
      }
      matchedPt(*jet) = matchedTruthJet->pt(); 
858
    }
Tomas Dado's avatar
Tomas Dado committed
859
860

    return StatusCode::SUCCESS;
861
862
  }

Tomas Dado's avatar
Tomas Dado committed
863
864
865
866
867
868
869
870
871
872
873
874
875
  StatusCode JetObjectCollectionMaker::decorateDL1(bool trackJets) {
    // retrieve small-R jets collection -- either calo or track jets
    const xAOD::JetContainer* jets(nullptr);

    if (trackJets) {
      top::check(evtStore()->retrieve(jets,
                                      m_config->sgKeyTrackJets()),
                 "Failed to retrieve track jet collection" + m_config->sgKeyTrackJets());
    } else {
      top::check(evtStore()->retrieve(jets,
                                      m_config->sgKeyJets()),
                 "Failed to retrieve small-R jet collection" + m_config->sgKeyJets());
    }
876

Tomas Dado's avatar
Tomas Dado committed
877
878
879
880
881
    for (const auto& jet : *jets) {
      // loop over either calo or track jet btag selection tools to calculate the DL1x scores
      const std::unordered_map<std::string, ToolHandle<IBTaggingSelectionTool>>& m_btagDecorTools \
        = (trackJets ? m_btagSelToolsDL1Decor_trkJet : m_btagSelToolsDL1Decor);
      for (std::pair<std::string, ToolHandle<IBTaggingSelectionTool>> algo : m_btagDecorTools) {
882
883
884
885
886
887
888
889
890
891
892
893
894
        double DL1_weight = -999.;
        //double dl1_pb = -10.;
        //double dl1_pc = -10.;
        //double dl1_pu = -10.;
        //if (jet->btagging()->pb(algo.first, dl1_pb)
        //    && jet->btagging()->pc(algo.first, dl1_pc)
        //    && jet->btagging()->pu(algo.first, dl1_pu)) {
        //  if (!algo.second->getTaggerWeight(dl1_pb, dl1_pc, dl1_pu, DL1_weight)) {
        //    DL1_weight = -999.; // value for errors from retrieving DL1x weight
        //  }
        //} else {
        //  DL1_weight = -100.; // value for errors from nonexistence of probabilities
        //}
Tomas Dado's avatar
Tomas Dado committed
895
896
897
        DLx.at(algo.first)(*jet) = DL1_weight;
      }
    }
898

Tomas Dado's avatar
Tomas Dado committed
899
900
    return StatusCode::SUCCESS;
  }
901
}  // namespace top