MC2DummyParticle.cpp 3.77 KB
Newer Older
1
#include "Gaudi/Algorithm.h"
2
3
4
#include "GaudiAlg/GaudiTool.h"
#include "GaudiAlg/Producer.h"
#include "GaudiAlg/Transformer.h"
Whitney Armstrong's avatar
Whitney Armstrong committed
5
#include "GaudiKernel/RndmGenerators.h"
6
7
#include <algorithm>
#include <cmath>
8
9

#include "JugBase/DataHandle.h"
10
#include "JugBase/UniqueID.h"
11
12
13
14
15
16
17
18

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

namespace Jug {
  namespace Base {

19
    class MC2DummyParticle : public GaudiAlgorithm, AlgorithmIDMixin<int32_t> {
20
    public:
21
22
23
24
25
      DataHandle<dd4pod::Geant4ParticleCollection> m_inputHitCollection{"mcparticles", Gaudi::DataHandle::Reader, this};
      DataHandle<eic::ReconstructedParticleCollection> m_outputHitCollection{"DummyReconstructedParticles",
                                                                             Gaudi::DataHandle::Writer, this};
      Rndm::Numbers                                    m_gaussDist;
      Gaudi::Property<double>                          m_smearing{this, "smearing", 0.01 /* 1 percent*/};
26

27
28
      MC2DummyParticle(const std::string& name, ISvcLocator* svcLoc) 
        : GaudiAlgorithm(name, svcLoc)
29
        , AlgorithmIDMixin(name, info())
30
31
32
33
34
35
36
37
      {
        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
38
39

        IRndmGenSvc* randSvc = svc<IRndmGenSvc>("RndmGenSvc", true);
Whitney Armstrong's avatar
Whitney Armstrong committed
40
        StatusCode   sc      = m_gaussDist.initialize(randSvc, Rndm::Gauss(1.0, m_smearing.value()));
Whitney Armstrong's avatar
Whitney Armstrong committed
41
42
43
        if (!sc.isSuccess()) {
          return StatusCode::FAILURE;
        }
44
45
46
47
48
49
50
51
        return StatusCode::SUCCESS;
      }
      StatusCode execute() override
      {
        // input collection
        const dd4pod::Geant4ParticleCollection* parts = m_inputHitCollection.get();
        // output collection
        auto out_parts = m_outputHitCollection.createAndPut();
Sylvester Joosten's avatar
Sylvester Joosten committed
52
        int ID = 0;
53
        for (const auto& p : *parts) {
54
55
56
          if (p.genStatus() != 1) {
            continue;
          }
57
58
59
60

          // for now just use total momentum smearing as this is the largest effect,
          // ideally we should also smear the angles but this should be good enough
          // for now.
Sylvester Joosten's avatar
Sylvester Joosten committed
61
62
63
64
65
66
67
68
69
70
          const double pgen     = p.ps().mag();
          const float momentum = pgen * m_gaussDist();
          const float energy   = p.energy();
          const float px       = p.ps().x * momentum / pgen;
          const float py       = p.ps().y * momentum / pgen;
          const float pz       = p.ps().z * momentum / pgen;
          // @TODO: vertex smearing
          const float vx       = p.vs().x;
          const float vy       = p.vs().y;
          const float vz       = p.vs().z;
71

Sylvester Joosten's avatar
Sylvester Joosten committed
72
          eic::ReconstructedParticle rec_part{
Sylvester Joosten's avatar
Sylvester Joosten committed
73
74
75
            ID++,                             // Unique index
            {px, py, pz},                     // 3-momentum [GeV]
            {vx, vy, vz},                     // Vertex [mm]
76
            static_cast<float>(p.time()),     // time [ns]
Sylvester Joosten's avatar
Sylvester Joosten committed
77
78
79
            p.pdgID(),                        // PDG type
            static_cast<int16_t>(p.status()), // Status
            static_cast<int16_t>(p.charge()), // Charge
80
81
            algorithmID(),                    // Algorithm type
            1.,                               // particle weight
Sylvester Joosten's avatar
Sylvester Joosten committed
82
83
            momentum,                         // 3-momentum magnitude [GeV]
            energy,                           // energy [GeV]
84
            static_cast<float>(p.mass())};    // mass [GeV]
Sylvester Joosten's avatar
Sylvester Joosten committed
85

86
          out_parts->push_back(rec_part);
87
88
89
90
91
92
93
94
        }
        return StatusCode::SUCCESS;
      }
    };

    DECLARE_COMPONENT(MC2DummyParticle)

  } // namespace Base
95
} // namespace Jug
96