MC2DummyParticle.cpp 3.98 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/Utilities/UniqueID.hpp"
11
12
13
14
15
16
17
18
19

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

namespace Jug {
  namespace Base {

    class MC2DummyParticle : public GaudiAlgorithm {
20
21
22
23
  private:
    // Unique identifier for this hit type, based on the algorithm name
    using PartClassificationType = decltype(eic::ReconstructedParticleData().type);
    const PartClassificationType m_type;
24
    public:
25
26
27
28
29
      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*/};
30

31
32
33
      MC2DummyParticle(const std::string& name, ISvcLocator* svcLoc) 
        : GaudiAlgorithm(name, svcLoc)
        , m_type{uniqueID<PartClassificationType>(name)}
34
35
36
37
38
39
40
41
      {
        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
42
43

        IRndmGenSvc* randSvc = svc<IRndmGenSvc>("RndmGenSvc", true);
Whitney Armstrong's avatar
Whitney Armstrong committed
44
        StatusCode   sc      = m_gaussDist.initialize(randSvc, Rndm::Gauss(1.0, m_smearing.value()));
Whitney Armstrong's avatar
Whitney Armstrong committed
45
46
47
        if (!sc.isSuccess()) {
          return StatusCode::FAILURE;
        }
48
49
50
51
52
53
54
55
        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
56
        int ID = 0;
57
        for (const auto& p : *parts) {
58
59
60
          if (p.genStatus() != 1) {
            continue;
          }
61
62
63
64

          // 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
65
66
67
68
69
70
71
72
73
74
          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;
75

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

90
          out_parts->push_back(rec_part);
91
92
93
94
95
96
97
98
        }
        return StatusCode::SUCCESS;
      }
    };

    DECLARE_COMPONENT(MC2DummyParticle)

  } // namespace Base
99
} // namespace Jug
100