AsgEventScaleFactorAlg.cxx 2.03 KB
Newer Older
1
/*
2
  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
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
*/

/// @author Tadej Novak


//
// includes
//

#include <AsgAnalysisAlgorithms/AsgEventScaleFactorAlg.h>

//
// method implementations
//

namespace CP
{
  AsgEventScaleFactorAlg ::
  AsgEventScaleFactorAlg (const std::string& name, 
                          ISvcLocator* pSvcLocator)
    : AnaAlgorithm (name, pSvcLocator)
  {
  }



  StatusCode AsgEventScaleFactorAlg ::
  initialize ()
  {
    if (m_scaleFactorInputDecoration.empty() || m_scaleFactorOutputDecoration.empty())
    {
      ANA_MSG_ERROR ("no scale factor decoration name set");
      return StatusCode::FAILURE;
    }

38
39
    ANA_CHECK (m_eventInfoHandle.initialize (m_systematicsList));
    ANA_CHECK (m_particleHandle.initialize (m_systematicsList));
40
    ANA_CHECK (m_inputSelectionDecoration.initialize (m_systematicsList, m_particleHandle, SG::AllowEmpty));
41
42
    ANA_CHECK (m_scaleFactorInputDecoration.initialize (m_systematicsList, m_particleHandle));
    ANA_CHECK (m_scaleFactorOutputDecoration.initialize (m_systematicsList, m_eventInfoHandle));
43
44
45
46
47
48
49
50
51
52
53
    ANA_CHECK (m_systematicsList.initialize());
    ANA_CHECK (m_preselection.initialize());

    return StatusCode::SUCCESS;
  }



  StatusCode AsgEventScaleFactorAlg ::
  execute ()
  {
54
55
    for (const auto& sys : m_systematicsList.systematicsVector())
    {
56
57
      const xAOD::EventInfo *eventInfo = nullptr;
      ANA_CHECK (m_eventInfoHandle.retrieve (eventInfo, sys));
58

59
60
      const xAOD::IParticleContainer *particles = nullptr;
      ANA_CHECK (m_particleHandle.retrieve (particles, sys));
61
62

      float scaleFactor = 1;
63
      for (const xAOD::IParticle *particle : *particles)
64
65
66
      {
        if (m_preselection.getBool (*particle))
        {
67
68
69
          if (m_inputSelectionDecoration && m_inputSelectionDecoration.get (*particle, sys) == 0)
            continue;

70
71
72
73
74
          scaleFactor *= m_scaleFactorInputDecoration.get (*particle, sys);
        }
      }

      m_scaleFactorOutputDecoration.set (*eventInfo, scaleFactor, sys);
75
    }
76

77
    return StatusCode::SUCCESS;
78
79
  }
}