MuonSelectionAlg.cxx 2.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
/*
  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/

/// @author Tadej Novak

//
// includes
//

#include <MuonAnalysisAlgorithms/MuonSelectionAlg.h>
#include <PATCore/IAsgSelectionTool.h>

//
// method implementations
//

namespace CP
{
  MuonSelectionAlgV2 ::
  MuonSelectionAlgV2 (const std::string& name, 
                      ISvcLocator* pSvcLocator)
    : AnaAlgorithm (name, pSvcLocator)
    , m_selectionTool ("", this)
  {
    declareProperty ("selectionTool", m_selectionTool, "the selection tool we apply");
    declareProperty ("selectionDecoration", m_selectionDecoration, "the decoration for the quality selection");
    declareProperty ("badMuonVetoDecoration", m_badMuonVetoDecoration, "the decoration for the bad muon veto");
  }



  StatusCode MuonSelectionAlgV2 ::
  initialize ()
  {
    if (m_selectionDecoration.empty())
    {
      ANA_MSG_ERROR ("no selection decoration name set");
      return StatusCode::FAILURE;
    }
    ANA_CHECK (makeSelectionAccessor (m_selectionDecoration, m_selectionAccessor));
    ANA_CHECK (m_selectionTool.retrieve());

    if (!m_badMuonVetoDecoration.empty())
    {
      ANA_CHECK (makeSelectionAccessor (m_badMuonVetoDecoration, m_badMuonVetoAccessor));
      ANA_CHECK (m_selectionTool.retrieve());
    }

50
    ANA_CHECK (m_muonsHandle.initialize (m_systematicsList));
51
52
53
54
    ANA_CHECK (m_systematicsList.initialize());
    ANA_CHECK (m_preselection.initialize());

    auto *selectionTool = dynamic_cast<IAsgSelectionTool *>(&*m_selectionTool);
55
    asg::AcceptData blankAccept {&selectionTool->getAcceptInfo()};
56
57
58
59
60
61
62
63
64
65
    m_setOnFail = selectionFromAccept(blankAccept);

    return StatusCode::SUCCESS;
  }



  StatusCode MuonSelectionAlgV2 ::
  execute ()
  {
66
    for (const auto& sys : m_systematicsList.systematicsVector())
67
    {
68
69
70
      const xAOD::MuonContainer *muons = nullptr;
      ANA_CHECK (m_muonsHandle.retrieve (muons, sys));
      for (const xAOD::Muon *muon : *muons)
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
      {
        if (m_preselection.getBool (*muon))
        {
          m_selectionAccessor->setBits
            (*muon, selectionFromAccept (m_selectionTool->accept (*muon)));
          
          if (m_badMuonVetoAccessor != nullptr)
          {
            m_badMuonVetoAccessor->setBool (*muon, m_selectionTool->isBadMuon (*muon));
          }
        } else {
          m_selectionAccessor->setBits (*muon, m_setOnFail);

          if (m_badMuonVetoAccessor != nullptr)
          {
            m_badMuonVetoAccessor->setBool (*muon, false);
          }
        }
      }
90
91
    }
    return StatusCode::SUCCESS;
92
93
  }
}