MC2DummyParticle.cpp 2.4 KB
Newer Older
1
2
3
4
5
6
#include <algorithm>
#include <cmath>
#include "GaudiAlg/Transformer.h"
#include "GaudiAlg/Producer.h"
#include "GaudiAlg/GaudiTool.h"
#include "Gaudi/Algorithm.h"
Whitney Armstrong's avatar
Whitney Armstrong committed
7
#include "GaudiKernel/RndmGenerators.h"
8
9
10
11
12
13
14
15
16
17
18
19
20
21

// FCCSW
#include "JugBase/DataHandle.h"

// Event Model related classes
#include "dd4pod/Geant4ParticleCollection.h"
#include "eicd/ReconstructedParticleCollection.h"


namespace Jug {
  namespace Base {

    class MC2DummyParticle : public GaudiAlgorithm {
    public:
22
23
      DataHandle<dd4pod::Geant4ParticleCollection>     m_inputHitCollection{"mcparticles", Gaudi::DataHandle::Reader, this};
      DataHandle<eic::ReconstructedParticleCollection> m_outputHitCollection{"DummyReconstructedParticles", Gaudi::DataHandle::Writer, this};
Whitney Armstrong's avatar
Whitney Armstrong committed
24
25
      Rndm::Numbers           m_gaussDist;
      Gaudi::Property<double> m_smearing{this, "smearing", 0.01 /* 1 percent*/};
26

27
28
29
30
31
32
33
34
35
      MC2DummyParticle(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc)
      {
        declareProperty("inputCollection", m_inputHitCollection, "mcparticles");
        declareProperty("outputCollection", m_outputHitCollection, "DummyReconstructedParticles");
      }
      StatusCode initialize() override
      {
        if (GaudiAlgorithm::initialize().isFailure())
          return StatusCode::FAILURE;
Whitney Armstrong's avatar
Whitney Armstrong committed
36
37
38
39
40
41

        IRndmGenSvc* randSvc = svc<IRndmGenSvc>("RndmGenSvc", true);
        StatusCode   sc      = m_gaussDist.initialize(randSvc, Rndm::Gauss(0.0, m_smearing.value()));
        if (!sc.isSuccess()) {
          return StatusCode::FAILURE;
        }
42
43
44
45
46
47
48
49
50
        return StatusCode::SUCCESS;
      }
      StatusCode execute() override
      {
        // input collection
        const dd4pod::Geant4ParticleCollection* parts = m_inputHitCollection.get();
        // output collection
        auto out_parts = m_outputHitCollection.createAndPut();
        for (const auto& p : *parts) {
51
52
53
          if (p.genStatus() != 1) {
            continue;
          }
Whitney Armstrong's avatar
Whitney Armstrong committed
54
          
55
56
          double momentum = std::hypot(p.psx(), p.psy(), p.psz());
          double energy   = std::hypot(momentum, p.mass());
Whitney Armstrong's avatar
Whitney Armstrong committed
57
          eic::ReconstructedParticle rec_part(p.pdgID(), energy*m_gaussDist(), {p.psx()*m_gaussDist(),p.psy()*m_gaussDist(),p.psz()*m_gaussDist()}, (double)p.charge(), p.mass());
58
          out_parts->push_back(rec_part);
59
60
61
62
63
64
65
66
67
68
        }
        return StatusCode::SUCCESS;
      }
    };

    DECLARE_COMPONENT(MC2DummyParticle)

  } // namespace Base
} // namespace Gaudi